X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=9526f198b7c3e228b4f13e1834eab148d07c4fd9;hp=bd82a609734afb1c06ebf95f52862a82594ab54c;hb=a59ebe8eb3a68db0a2ffcb8ce5127c767737d5ad;hpb=8e4eb47925648cd84d134dfe05ca7fb30727dc24 diff --git a/src/events.c b/src/events.c index bd82a609..9526f198 100644 --- a/src/events.c +++ b/src/events.c @@ -40,6 +40,7 @@ static unsigned int special_cursor_delay = 0; static unsigned int special_cursor_delay_value = 1000; static boolean virtual_button_pressed = FALSE; +static boolean stop_processing_events = FALSE; // forward declarations for internal use @@ -54,20 +55,13 @@ static void HandleEventActions(void); int FilterMouseMotionEvents(void *userdata, Event *event) { - if (event->type != EVENT_MOTIONNOTIFY) - return 1; - - int mouse_x = ((MotionEvent *)event)->x; - int mouse_y = ((MotionEvent *)event)->y; - - // mouse events do not contain logical screen size corrections at this stage - SDLCorrectMouseEventXY(&mouse_x, &mouse_y); - - mouse_x -= video.screen_xoffset; - mouse_y -= video.screen_yoffset; + if (event->type == EVENT_MOTIONNOTIFY) + { + int mouse_x = ((MotionEvent *)event)->x; + int mouse_y = ((MotionEvent *)event)->y; - gfx.mouse_x = mouse_x; - gfx.mouse_y = mouse_y; + UpdateRawMousePosition(mouse_x, mouse_y); + } return 1; } @@ -109,6 +103,15 @@ static int FilterEvents(const Event *event) cursor_inside_playfield = (motion->x >= SX && motion->x < SX + SXSIZE && motion->y >= SY && motion->y < SY + SYSIZE); + // set correct mouse x/y position (for pointer class global animations) + // (this is required in rare cases where the mouse x/y position calculated + // from raw values (to apply logical screen size scaling corrections) does + // not match the final mouse event x/y position -- this may happen because + // the SDL renderer's viewport position is internally represented as float, + // but only accessible as integer, which may lead to rounding errors) + gfx.mouse_x = motion->x; + gfx.mouse_y = motion->y; + // do no reset mouse cursor before all pending events have been processed if (gfx.cursor_mode == cursor_mode_last && ((game_status == GAME_MODE_TITLE && @@ -189,6 +192,11 @@ boolean NextValidEvent(Event *event) return FALSE; } +void StopProcessingEvents(void) +{ + stop_processing_events = TRUE; +} + static void HandleEvents(void) { Event event; @@ -197,6 +205,8 @@ static void HandleEvents(void) ResetDelayCounter(&event_frame_delay); + stop_processing_events = FALSE; + while (NextValidEvent(&event)) { switch (event.type) @@ -252,6 +262,10 @@ static void HandleEvents(void) // do not handle events for longer than standard frame delay period if (DelayReached(&event_frame_delay, event_frame_delay_value)) break; + + // do not handle any further events if triggered by a special flag + if (stop_processing_events) + break; } } @@ -593,6 +607,8 @@ void HandleWindowEvent(WindowEvent *event) if (game_status == GAME_MODE_SETUP) RedrawSetupScreenAfterFullscreenToggle(); + UpdateMousePosition(); + SetWindowTitle(); } } @@ -1894,6 +1910,13 @@ static void HandleKeysSpecial(Key key) { CopyClipboardToBrush(); } + else if (letter == 'z') // undo or redo last operation + { + if (GetKeyModState() & KMOD_Shift) + RedoLevelEditorOperation(); + else + UndoLevelEditorOperation(); + } } } @@ -2142,6 +2165,8 @@ void HandleKey(Key key, int key_status) if (game_status == GAME_MODE_SETUP) RedrawSetupScreenAfterFullscreenToggle(); + UpdateMousePosition(); + // set flag to ignore repeated "key pressed" events ignore_repeated_key = TRUE; @@ -2173,6 +2198,8 @@ void HandleKey(Key key, int key_status) if (game_status == GAME_MODE_SETUP) RedrawSetupScreenAfterFullscreenToggle(); + UpdateMousePosition(); + return; }