c - GLFW how to drag undecorated window? -


i'm stuck trying make window dragable.

here code,

#include <stdio.h> #include <math.h> #include <gl/gl.h> #include "include/glfw/glfw3.h"  void cursor_position_callback(glfwwindow* window, double x, double y); void mouse_button_callback(glfwwindow *window, int button, int action, int mods);  int cp_x; int cp_y; int wrel_cpx; int wrel_cpy; int w_posx; int w_posy; int buttonevent;  int main(){     glfwinit();     glfwwindowhint(glfw_decorated, 0);     glfwwindow *window = glfwcreatewindow(640, 480, "undecorated resizable", 0, 0);      int w_width;     int w_height;     int ccp_x;     int ccp_y;      glfwsetcursorposcallback(window, cursor_position_callback);     glfwsetmousebuttoncallback(window, mouse_button_callback);      glfwmakecontextcurrent(window);       while(!glfwwindowshouldclose(window)){         if(buttonevent == 1){             glfwsetwindowpos(window, wrel_cpx - cp_x, wrel_cpy - cp_y);         }          glfwswapbuffers(window);          glfwwaitevents();     }      return 0; }  void cursor_position_callback(glfwwindow* window, double x, double y){     glfwgetwindowpos(window, &w_posx, &w_posy);     wrel_cpx = cp_x + w_posx;     wrel_cpy = cp_y + w_posy;     cp_x = floor(x);     cp_y = floor(y); }  void mouse_button_callback(glfwwindow* window, int button, int action, int mods){     if(button == glfw_mouse_button_left && action == glfw_press){         buttonevent = 1;     }     if(button == glfw_mouse_button_left && action == glfw_release){         buttonevent = 0;     } } 

when run program , try drag window, position of window remain position , absolutely nothing.

if change wrel_cpx - cp_x wrel_cpx + cp_x, window moves crazy.

can please me?

maybe answer useful someone. correct code drag of undecorated window:

#include <stdio.h> #include <math.h> #include <gl/gl.h> #include <glfw/glfw3.h>  void cursor_position_callback(glfwwindow* window, double x, double y); void mouse_button_callback(glfwwindow *window, int button, int action, int mods);  int cp_x; int cp_y; int offset_cpx; int offset_cpy; int w_posx; int w_posy; int buttonevent;  int main(){     glfwinit();     glfwwindowhint(glfw_decorated, 0);     glfwwindow *window = glfwcreatewindow(640, 480, "undecorated resizable", 0, 0);      int w_width;     int w_height;     int ccp_x;     int ccp_y;      glfwsetcursorposcallback(window, cursor_position_callback);     glfwsetmousebuttoncallback(window, mouse_button_callback);      glfwmakecontextcurrent(window);       while(!glfwwindowshouldclose(window)){         if(buttonevent == 1){             glfwgetwindowpos(window, &w_posx, &w_posy);             glfwsetwindowpos(window, w_posx + offset_cpx, w_posy + offset_cpy);             offset_cpx = 0;             offset_cpy = 0;             cp_x += offset_cpx;             cp_y += offset_cpy;          }          glfwswapbuffers(window);          glfwwaitevents();      }      return 0; }  void cursor_position_callback(glfwwindow* window, double x, double y){     if (buttonevent == 1) {         offset_cpx = x - cp_x;         offset_cpy = y - cp_y;     } }  void mouse_button_callback(glfwwindow* window, int button, int action, int mods){     if(button == glfw_mouse_button_left && action == glfw_press){         buttonevent = 1;         double x, y;         glfwgetcursorpos(window, &x, &y);         cp_x = floor(x);         cp_y = floor(y);     }     if(button == glfw_mouse_button_left && action == glfw_release){         buttonevent = 0;         cp_x = 0;         cp_y = 0;     } } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -