Skip to content

Commit 55cc183

Browse files
Merge pull request #532 from Hedgehogsoft/main
add RGFW_mouseMotion and return correct rect values for windowRefresh events
2 parents 832808a + b62f436 commit 55cc183

5 files changed

Lines changed: 45 additions & 36 deletions

File tree

RGFW.h

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ typedef RGFW_ENUM(u8, RGFW_eventType) {
674674
RGFW_mouseButtonPressed, /*!< a mouse button has been pressed (left,middle,right) */
675675
RGFW_mouseButtonReleased, /*!< a mouse button has been released (left,middle,right) */
676676
RGFW_mouseScroll, /*!< a mouse scroll event */
677-
RGFW_mousePosChanged, /*!< the position of the mouse has been changed */
677+
RGFW_mouseMotion, /*!< the position of the mouse has been changed / the mouse has moved */
678678
RGFW_mouseRawMotion, /*!< raw mouse motion */
679679
RGFW_mouseEnter, /*!< mouse entered the window */
680680
RGFW_mouseLeave, /*!< mouse left the window */
@@ -692,7 +692,8 @@ typedef RGFW_ENUM(u8, RGFW_eventType) {
692692
RGFW_scaleUpdated, /*!< content scale factor changed */
693693
RGFW_monitorConnected, /*!< a monitor has been connected */
694694
RGFW_monitorDisconnected, /*!< a monitor has been disconnected */
695-
RGFW_eventCount /*!< the number of event types there are */
695+
RGFW_eventCount, /*!< the number of event types there are */
696+
RGFW_mousePosChanged = RGFW_mouseMotion, /*!< alias for RGFW_mouseMotion (may be deleted at some point) */
696697
};
697698

698699
/*! @brief flags for toggling whether or not an event should be processed */
@@ -703,7 +704,7 @@ typedef RGFW_ENUM(u32, RGFW_eventFlag) {
703704
RGFW_mouseScrollFlag = RGFW_BIT(RGFW_mouseScroll),
704705
RGFW_mouseButtonPressedFlag = RGFW_BIT(RGFW_mouseButtonPressed),
705706
RGFW_mouseButtonReleasedFlag = RGFW_BIT(RGFW_mouseButtonReleased),
706-
RGFW_mousePosChangedFlag = RGFW_BIT(RGFW_mousePosChanged),
707+
RGFW_mouseMotionFlag = RGFW_BIT(RGFW_mouseMotion),
707708
RGFW_mouseRawMotionFlag = RGFW_BIT(RGFW_mouseRawMotion),
708709
RGFW_mouseEnterFlag = RGFW_BIT(RGFW_mouseEnter),
709710
RGFW_mouseLeaveFlag = RGFW_BIT(RGFW_mouseLeave),
@@ -721,9 +722,10 @@ typedef RGFW_ENUM(u32, RGFW_eventFlag) {
721722
RGFW_dataDragFlag = RGFW_BIT(RGFW_dataDrag),
722723
RGFW_monitorConnectedFlag = RGFW_BIT(RGFW_monitorConnected),
723724
RGFW_monitorDisconnectedFlag = RGFW_BIT(RGFW_monitorDisconnected),
725+
RGFW_mousePosChangedFlag = RGFW_mouseMotionFlag, /* alias for RGFW_mouseMotionFlag (may be deleted at some point) */
724726

725727
RGFW_keyEventsFlag = RGFW_keyPressedFlag | RGFW_keyReleasedFlag | RGFW_keyCharFlag,
726-
RGFW_mouseEventsFlag = RGFW_mouseButtonPressedFlag | RGFW_mouseButtonReleasedFlag | RGFW_mousePosChangedFlag | RGFW_mouseEnterFlag | RGFW_mouseLeaveFlag | RGFW_mouseScrollFlag | RGFW_mouseRawMotionFlag,
728+
RGFW_mouseEventsFlag = RGFW_mouseButtonPressedFlag | RGFW_mouseButtonReleasedFlag | RGFW_mouseMotionFlag | RGFW_mouseEnterFlag | RGFW_mouseLeaveFlag | RGFW_mouseScrollFlag | RGFW_mouseRawMotionFlag,
727729
RGFW_windowEventsFlag = RGFW_windowMovedFlag | RGFW_windowResizedFlag | RGFW_windowRefreshFlag | RGFW_windowMaximizedFlag | RGFW_windowMinimizedFlag | RGFW_windowRestoredFlag | RGFW_scaleUpdatedFlag,
728730
RGFW_windowFocusEventsFlag = RGFW_windowFocusInFlag | RGFW_windowFocusOutFlag,
729731
RGFW_dataDragDropEventsFlag = RGFW_dataDropFlag | RGFW_dataDragFlag,
@@ -761,13 +763,13 @@ typedef struct RGFW_mouseDeltaEvent {
761763
float x, y; /*!< the raw mouse scroll or motion delta value */
762764
} RGFW_mouseDeltaEvent;
763765

764-
/*! @brief event data for a mouse position event (RGFW_mousePosChanged) */
765-
typedef struct RGFW_mousePosEvent {
766+
/*! @brief event data for a mouse position event (RGFW_mouseMotion) */
767+
typedef struct RGFW_mouseMotionEvent {
766768
RGFW_eventType type; /*!< which event has been sent?*/
767769
RGFW_window* win; /*!< the window this event applies to (for event queue events) */
768770
i32 x, y; /*!< mouse x, y of event (or drop point) */
769771
RGFW_bool inWindow; /*!< if the mouse is in the window or not */
770-
} RGFW_mousePosEvent;
772+
} RGFW_mouseMotionEvent;
771773

772774
/*! @brief event data for a key press/release event */
773775
typedef struct RGFW_keyEvent {
@@ -835,7 +837,7 @@ typedef union RGFW_event {
835837
RGFW_windowUpdateEvent update; /*!< data for window update/move/resize/refresh events */
836838
RGFW_mouseButtonEvent button; /*!< data for a button press/release */
837839
RGFW_mouseDeltaEvent delta; /*!< data for a mouse scroll or raw motion */
838-
RGFW_mousePosEvent mouse; /*!< data for mouse motion events */
840+
RGFW_mouseMotionEvent mouse; /*!< data for mouse motion events */
839841
RGFW_keyEvent key; /*!< data for key press/release/hold events */
840842
RGFW_keyCharEvent keyChar; /*!< data for key character events */
841843
RGFW_dataDropEvent drop; /*!< data dropping events */
@@ -3254,7 +3256,7 @@ RGFWDEF void RGFW_windowRestoredCallback(RGFW_window* win, i32 x, i32 y, i32 w,
32543256
RGFWDEF void RGFW_windowMovedCallback(RGFW_window* win, i32 x, i32 y);
32553257
RGFWDEF void RGFW_windowResizedCallback(RGFW_window* win, i32 w, i32 h);
32563258
RGFWDEF void RGFW_windowCloseCallback(RGFW_window* win);
3257-
RGFWDEF void RGFW_mousePosCallback(RGFW_window* win, i32 x, i32 y);
3259+
RGFWDEF void RGFW_mouseMotionCallback(RGFW_window* win, i32 x, i32 y);
32583260
RGFWDEF void RGFW_rawMotionCallback(RGFW_window* win, float x, float y);
32593261
RGFWDEF void RGFW_windowRefreshCallback(RGFW_window* win, i32 x, i32 y, i32 w, i32 h);
32603262
RGFWDEF void RGFW_windowFocusCallback(RGFW_window* win, RGFW_bool inFocus);
@@ -3484,7 +3486,7 @@ void RGFW_windowMovedCallback(RGFW_window* win, i32 x, i32 y) {
34843486
RGFW_event event;
34853487
event.type = RGFW_windowMoved;
34863488
event.update.x = x;
3487-
event.update.x = y;
3489+
event.update.y = y;
34883490
event.update.w = win->w;
34893491
event.update.h = win->h;
34903492
event.common.win = win;
@@ -3515,14 +3517,14 @@ void RGFW_windowCloseCallback(RGFW_window* win) {
35153517
RGFW_eventQueuePushAndCall(&event);
35163518
}
35173519

3518-
void RGFW_mousePosCallback(RGFW_window* win, i32 x, i32 y) {
3520+
void RGFW_mouseMotionCallback(RGFW_window* win, i32 x, i32 y) {
35193521
win->internal.lastMouseX = x;
35203522
win->internal.lastMouseY = y;
35213523

3522-
if (!(win->internal.enabledEvents & RGFW_mousePosChangedFlag)) return;
3524+
if (!(win->internal.enabledEvents & RGFW_mouseMotionFlag)) return;
35233525

35243526
RGFW_event event;
3525-
event.type = RGFW_mousePosChanged;
3527+
event.type = RGFW_mouseMotion;
35263528
event.mouse.x = x;
35273529
event.mouse.y = y;
35283530
event.mouse.inWindow = win->internal.mouseInside;
@@ -6959,11 +6961,11 @@ void RGFW_XHandleEvent(void) {
69596961
break;
69606962
}
69616963
case MotionNotify:
6962-
RGFW_mousePosCallback(win, E.xmotion.x, E.xmotion.y);
6964+
RGFW_mouseMotionCallback(win, E.xmotion.x, E.xmotion.y);
69636965
break;
69646966

69656967
case Expose: {
6966-
RGFW_windowRefreshCallback(win, 0, 0, win->w, win->h);
6968+
RGFW_windowRefreshCallback(win, E.xexpose.x, E.xexpose.y, E.xexpose.width, E.xexpose.height);
69676969

69686970
#ifdef RGFW_ADVANCED_SMOOTH_RESIZE
69696971
XSyncValue value;
@@ -7084,7 +7086,7 @@ void RGFW_XHandleEvent(void) {
70847086
dragX = xpos;
70857087
dragY = ypos;
70867088

7087-
RGFW_mousePosCallback(win, xpos, ypos);
7089+
RGFW_mouseMotionCallback(win, xpos, ypos);
70887090
XEvent reply = { ClientMessage };
70897091
reply.xclient.window = _RGFW->x11Source;
70907092
reply.xclient.message_type = XdndStatus;
@@ -8897,7 +8899,7 @@ static void RGFW_wl_pointer_motion(void* data, struct wl_pointer *pointer, u32 t
88978899
i32 convertedX = (i32)wl_fixed_to_double(x);
88988900
i32 convertedY = (i32)wl_fixed_to_double(y);
88998901

8900-
RGFW_mousePosCallback(win, convertedX, convertedY);
8902+
RGFW_mouseMotionCallback(win, convertedX, convertedY);
89018903
}
89028904

89038905
static void RGFW_wl_pointer_button(void* data, struct wl_pointer *pointer, u32 serial, u32 time, u32 button, u32 state) {
@@ -10721,10 +10723,15 @@ LRESULT CALLBACK WndProcW(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1072110723
return DefWindowProcW(hWnd, message, wParam, lParam);
1072210724
}
1072310725
case WM_PAINT: {
10724-
PAINTSTRUCT ps;
10725-
BeginPaint(hWnd, &ps);
10726-
RGFW_windowRefreshCallback(win, 0, 0, win->w, win->h);
10727-
EndPaint(hWnd, &ps);
10726+
RECT rect;
10727+
if (GetUpdateRect(hWnd, &rect, FALSE)) {
10728+
RGFW_windowRefreshCallback(win, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
10729+
} else {
10730+
PAINTSTRUCT ps;
10731+
BeginPaint(hWnd, &ps);
10732+
RGFW_windowRefreshCallback(win, 0, 0, win->w, win->h);
10733+
EndPaint(hWnd, &ps);
10734+
}
1072810735

1072910736
return DefWindowProcW(hWnd, message, wParam, lParam);
1073010737
}
@@ -10861,7 +10868,7 @@ LRESULT CALLBACK WndProcW(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1086110868
RGFW_mouseNotifyCallback(win, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), RGFW_TRUE);
1086210869
}
1086310870

10864-
RGFW_mousePosCallback(win, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
10871+
RGFW_mouseMotionCallback(win, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1086510872
break;
1086610873
}
1086710874
case WM_INPUT: {
@@ -13249,7 +13256,9 @@ static void RGFW__osxDrawRect(id self, SEL _cmd, CGRect rect) {
1324913256
object_getInstanceVariable(self, "RGFW_window", (void**)&win);
1325013257
if (win == NULL) return;
1325113258

13252-
RGFW_windowRefreshCallback(win, 0, 0, win->w, win->h);
13259+
float y = RGFW_cocoaYTransform((float)(rect.size.height - 1));
13260+
13261+
RGFW_windowRefreshCallback(win, (i32)rect.origin.x, (i32)y, (i32)rect.size.width, (i32)rect.size.height);
1325313262
}
1325413263

1325513264
static void RGFW__osxMouseEntered(id self, SEL _cmd, id event) {
@@ -13361,7 +13370,7 @@ static void RGFW__osxMouseMoved(id self, SEL _cmd, id event) {
1336113370
CGFloat vecX = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(event, sel_registerName("deltaX"));
1336213371
CGFloat vecY = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(event, sel_registerName("deltaY"));
1336313372

13364-
RGFW_mousePosCallback(win, (i32)p.x, (i32)(win->h - p.y));
13373+
RGFW_mouseMotionCallback(win, (i32)p.x, (i32)(win->h - p.y));
1336513374
RGFW_rawMotionCallback(win, (float)vecX, (float)vecY);
1336613375
}
1336713376

@@ -14895,7 +14904,7 @@ EM_BOOL Emscripten_on_focusout(int eventType, const EmscriptenFocusEvent* E, voi
1489514904

1489614905
EM_BOOL Emscripten_on_mousemove(int eventType, const EmscriptenMouseEvent* E, void* userData) {
1489714906
RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
14898-
RGFW_mousePosCallback(_RGFW->root, E->targetX, E->targetY);
14907+
RGFW_mouseMotionCallback(_RGFW->root, E->targetX, E->targetY);
1489914908
RGFW_rawMotionCallback(_RGFW->root, E->movementX, E->movementY);
1490014909
return EM_TRUE;
1490114910
}
@@ -14937,7 +14946,7 @@ EM_BOOL Emscripten_on_touchstart(int eventType, const EmscriptenTouchEvent* E, v
1493714946

1493814947
size_t i;
1493914948
for (i = 0; i < (size_t)E->numTouches; i++) {
14940-
RGFW_mousePosCallback(_RGFW->root, E->touches[i].targetX, E->touches[i].targetY);
14949+
RGFW_mouseMotionCallback(_RGFW->root, E->touches[i].targetX, E->touches[i].targetY);
1494114950
RGFW_rawMotionCallback(_RGFW->root, 0, 0);
1494214951
RGFW_mouseButtonCallback(_RGFW->root, RGFW_mouseLeft, 1);
1494314952
}
@@ -14948,11 +14957,11 @@ EM_BOOL Emscripten_on_touchstart(int eventType, const EmscriptenTouchEvent* E, v
1494814957
EM_BOOL Emscripten_on_touchmove(int eventType, const EmscriptenTouchEvent* E, void* userData) {
1494914958
RGFW_UNUSED(eventType); RGFW_UNUSED(userData);
1495014959

14951-
if (!(_RGFW->root->internal.enabledEvents & RGFW_mousePosChangedFlag)) return EM_TRUE;
14960+
if (!(_RGFW->root->internal.enabledEvents & RGFW_mouseMotionFlag)) return EM_TRUE;
1495214961

1495314962
size_t i;
1495414963
for (i = 0; i < (size_t)E->numTouches; i++) {
14955-
RGFW_mousePosCallback(_RGFW->root, E->touches[i].targetX, E->touches[i].targetY);
14964+
RGFW_mouseMotionCallback(_RGFW->root, E->touches[i].targetX, E->touches[i].targetY);
1495614965
RGFW_rawMotionCallback(_RGFW->root, 0, 0);
1495714966
}
1495814967
return EM_TRUE;
@@ -14965,7 +14974,7 @@ EM_BOOL Emscripten_on_touchend(int eventType, const EmscriptenTouchEvent* E, voi
1496514974

1496614975
size_t i;
1496714976
for (i = 0; i < (size_t)E->numTouches; i++) {
14968-
RGFW_mousePosCallback(_RGFW->root, E->touches[i].targetX, E->touches[i].targetY);
14977+
RGFW_mouseMotionCallback(_RGFW->root, E->touches[i].targetX, E->touches[i].targetY);
1496914978
RGFW_rawMotionCallback(_RGFW->root, 0, 0);
1497014979
RGFW_mouseButtonCallback(_RGFW->root, RGFW_mouseLeft, 0);
1497114980
}

examples/callbacks/callbacks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void dragfunc(const RGFW_event* e) {
128128
static
129129
void windowrefreshfunc(const RGFW_event* e) {
130130
if (e->common.win != window) return;
131+
printf("refresh %i %i %i %i\n", e->update.x, e->update.y, e->update.w, e->update.h);
131132
}
132133

133134
static
@@ -186,7 +187,7 @@ int main(void) {
186187
RGFW_setEventCallback(RGFW_windowRestored, windowrestorefunc);
187188
RGFW_setEventCallback(RGFW_windowMaximized, windowmaximizefunc);
188189
RGFW_setEventCallback(RGFW_windowClose, windowclosefunc);
189-
RGFW_setEventCallback(RGFW_mousePosChanged, mouseposfunc);
190+
RGFW_setEventCallback(RGFW_mouseMotion, mouseposfunc);
190191
RGFW_setEventCallback(RGFW_mouseScroll, scrollfunc);
191192
RGFW_setEventCallback(RGFW_windowRefresh, windowrefreshfunc);
192193
RGFW_setEventCallback(RGFW_windowFocusIn, windowfocusfunc);

examples/event_queue/event_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(void) {
3838
case RGFW_mouseScroll:
3939
printf("Mouse Button scroll %f %f\n", (double)event.delta.x, (double)event.delta.y);
4040
break;
41-
case RGFW_mousePosChanged:
41+
case RGFW_mouseMotion:
4242
if (RGFW_window_isKeyPressed(win, RGFW_keyControlL))
4343
printf("Mouse pos changed %i %i\n", event.mouse.x, event.mouse.y);
4444
break;

examples/first-person-camera/camera.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(void) {
6060
break;
6161

6262
switch (event.type) {
63-
case RGFW_mousePosChanged:
63+
case RGFW_mouseMotion:
6464
break;
6565
case RGFW_mouseRawMotion: {
6666
int dev_x = event.delta.x;

examples/microui_demo/microui_demo.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
#undef _WIN32_WINNT
2-
#include <stdio.h>
3-
41
#define RGFW_DEBUG
52
#define GL_SILENCE_DEPRECATION
63
#define RGFW_OPENGL
74
#define RGFW_IMPLEMENTATION
85
#include "RGFW.h"
96

7+
#include <stdio.h>
8+
109
#ifdef RGFW_MACOS
1110
#include <OpenGL/gl.h>
1211
#else
@@ -284,7 +283,7 @@ int main(int argc, char **argv) {
284283

285284
switch (event.type) {
286285
case RGFW_windowClose: break;
287-
case RGFW_mousePosChanged: mu_input_mousemove(ctx, event.mouse.x, event.mouse.y); break;
286+
case RGFW_mouseMotion: mu_input_mousemove(ctx, event.mouse.x, event.mouse.y); break;
288287

289288
case RGFW_mouseScroll:
290289
mu_input_scroll(ctx, event.delta.x, event.delta.y);

0 commit comments

Comments
 (0)