Skip to content

Commit eccd798

Browse files
roymacdonaldofTheo
andauthored
Added GLFW window position change callback and ofEvent notification (#7565)
Co-authored-by: Theodore Watson <[email protected]>
1 parent 99b5995 commit eccd798

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

libs/openFrameworks/app/ofAppGLFWWindow.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ ofAppGLFWWindow::~ofAppGLFWWindow() {
6868
void ofAppGLFWWindow::close() {
6969
if (windowP) {
7070

71-
glfwSetMouseButtonCallback(windowP, nullptr);
72-
glfwSetCursorPosCallback(windowP, nullptr);
73-
glfwSetCursorEnterCallback(windowP, nullptr);
74-
glfwSetKeyCallback(windowP, nullptr);
75-
glfwSetWindowSizeCallback(windowP, nullptr);
76-
glfwSetFramebufferSizeCallback(windowP, nullptr);
77-
glfwSetWindowCloseCallback(windowP, nullptr);
78-
glfwSetScrollCallback(windowP, nullptr);
79-
glfwSetDropCallback(windowP, nullptr);
71+
glfwSetMouseButtonCallback( windowP, nullptr );
72+
glfwSetCursorPosCallback( windowP, nullptr );
73+
glfwSetCursorEnterCallback( windowP, nullptr );
74+
glfwSetKeyCallback( windowP, nullptr );
75+
glfwSetWindowSizeCallback( windowP, nullptr );
76+
glfwSetWindowPosCallback(windowP, nullptr);
77+
glfwSetFramebufferSizeCallback( windowP, nullptr);
78+
glfwSetWindowCloseCallback( windowP, nullptr );
79+
glfwSetScrollCallback( windowP, nullptr );
80+
glfwSetDropCallback( windowP, nullptr );
81+
glfwSetWindowRefreshCallback(windowP, nullptr);
8082

8183
//hide the window before we destroy it stops a flicker on OS X on exit.
8284
glfwHideWindow(windowP);
@@ -377,6 +379,7 @@ void ofAppGLFWWindow::setup(const ofGLFWWindowSettings & _settings) {
377379
glfwSetKeyCallback(windowP, keyboard_cb);
378380
glfwSetCharCallback(windowP, char_cb);
379381
glfwSetWindowSizeCallback(windowP, resize_cb);
382+
glfwSetWindowPosCallback(windowP,position_cb);
380383
glfwSetFramebufferSizeCallback(windowP, framebuffer_size_cb);
381384
glfwSetWindowCloseCallback(windowP, exit_cb);
382385
glfwSetScrollCallback(windowP, scroll_cb);
@@ -1569,6 +1572,15 @@ void ofAppGLFWWindow::char_cb(GLFWwindow * windowP_, uint32_t key) {
15691572
instance->events().charEvent.notify(key);
15701573
}
15711574

1575+
//------------------------------------------------------------
1576+
void ofAppGLFWWindow::position_cb(GLFWwindow* windowP_, int x, int y){
1577+
ofAppGLFWWindow * instance = setCurrent(windowP_);
1578+
1579+
x *= instance->pixelScreenCoordScale;
1580+
y *= instance->pixelScreenCoordScale;
1581+
instance->events().notifyWindowMoved(x,y);
1582+
}
1583+
15721584
//------------------------------------------------------------
15731585
void ofAppGLFWWindow::refresh_cb(GLFWwindow * windowP_) {
15741586
ofAppGLFWWindow * instance = setCurrent(windowP_);

libs/openFrameworks/app/ofAppGLFWWindow.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,20 @@ class ofAppGLFWWindow : public ofAppBaseGLWindow {
180180
#endif
181181

182182
private:
183-
static ofAppGLFWWindow * setCurrent(GLFWwindow * windowP);
184-
static void mouse_cb(GLFWwindow * windowP_, int button, int state, int mods);
185-
static void motion_cb(GLFWwindow * windowP_, double x, double y);
186-
static void entry_cb(GLFWwindow * windowP_, int entered);
187-
static void keyboard_cb(GLFWwindow * windowP_, int key, int scancode, int action, int mods);
188-
static void char_cb(GLFWwindow * windowP_, uint32_t key);
189-
static void resize_cb(GLFWwindow * windowP_, int w, int h);
190-
static void framebuffer_size_cb(GLFWwindow * windowP_, int w, int h);
191-
static void exit_cb(GLFWwindow * windowP_);
192-
static void scroll_cb(GLFWwindow * windowP_, double x, double y);
193-
static void drop_cb(GLFWwindow * windowP_, int numFiles, const char ** dropString);
194-
static void error_cb(int errorCode, const char * errorDescription);
195-
static void refresh_cb(GLFWwindow * windowP_);
183+
static ofAppGLFWWindow * setCurrent(GLFWwindow* windowP);
184+
static void mouse_cb(GLFWwindow* windowP_, int button, int state, int mods);
185+
static void motion_cb(GLFWwindow* windowP_, double x, double y);
186+
static void entry_cb(GLFWwindow* windowP_, int entered);
187+
static void keyboard_cb(GLFWwindow* windowP_, int key, int scancode, int action, int mods);
188+
static void char_cb(GLFWwindow* windowP_, uint32_t key);
189+
static void resize_cb(GLFWwindow* windowP_, int w, int h);
190+
static void position_cb(GLFWwindow* windowP_, int x, int y);
191+
static void framebuffer_size_cb(GLFWwindow* windowP_, int w, int h);
192+
static void exit_cb(GLFWwindow* windowP_);
193+
static void scroll_cb(GLFWwindow* windowP_, double x, double y);
194+
static void drop_cb(GLFWwindow* windowP_, int numFiles, const char** dropString);
195+
static void error_cb(int errorCode, const char* errorDescription);
196+
static void refresh_cb(GLFWwindow * windowP_);
196197

197198
void close();
198199

0 commit comments

Comments
 (0)