Skip to main content
GameDev.net gamedev.net
🔒 Locked

Detecting mouse exiting window while button pressed

Started by robinei Aug 20, 2009 at 9:54 AM 4 replies 2k views
Original Post
robinei
robinei
I need to do this to get right behaviour for GUI widgets at or near the edge of the window. This seems impossible to to with SDL, because mouse coordinates are always within the window, and mouse focus is only lost when the button is released(outside the window). Are there any other lightweight cross-platform window and input handling frameworks that can handle this?
fcoelho
fcoelho
You can check for SDL_ACTIVEEVENT in the event loop. It is generated regardless of mouse button state.
robinei
robinei
That is exactly my problem. It is _not_ generated while the mouse button is down, on windows at least. When I release outside the window, the release event arrives, and _then_ the SDL_ACTIVEEVENT SDL_APPMOUSEFOCUS event arrives, telling me that mouse focus was lost.
fcoelho
fcoelho
Quote:
on windows at least
Well, I've tried this on Linux, so that might be the culprit..
#include <stdio.h>#include <SDL/SDL.h>int main(int argc, char *argv[]){       SDL_Surface *tela;        SDL_Init(SDL_INIT_EVERYTHING);        tela = SDL_SetVideoMode(400,300,32, SDL_HWSURFACE|SDL_DOUBLEBUF);       while (1)    {           SDL_Event event;        while (SDL_PollEvent(&event))        {               if (event.type == SDL_KEYDOWN)                if (event.key.keysym.sym == SDLK_ESCAPE)                    exit(0);            if (event.type == SDL_ACTIVEEVENT)                printf("gain %d\n", event.active.gain);        }    }}
robinei
robinei
Ah, then maybe a bug report should be in order.
fcoelho
fcoelho
About the "other lightweight cross-platform window and input handling frameworks", you can use SFML. There are a MouseEntered and MouseLeft events, which works on Windows also.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.