implemented a laser pointer
[vrfileman] / src / main.cc
index 82454fd..d236a3b 100644 (file)
@@ -8,6 +8,7 @@ static void process_event(SDL_Event *ev);
 static SDL_Window *win;
 static SDL_GLContext ctx;
 static bool redraw_pending = true;
+static bool fullscreen, mouse_grabbed;
 static bool quit;
 
 static int scale_factor = 1;
@@ -96,6 +97,36 @@ void app_resize(int x, int y)
 void app_fullscreen(bool fs)
 {
        SDL_SetWindowFullscreen(win, fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+       fullscreen = fs;
+}
+
+void app_toggle_fullscreen()
+{
+       app_fullscreen(!fullscreen);
+}
+
+bool app_is_fullscreen()
+{
+       return fullscreen;
+}
+
+void app_grab_mouse(bool grab)
+{
+       /*SDL_SetWindowGrab(win, grab ? SDL_TRUE : SDL_FALSE);
+       SDL_ShowCursor(grab ? 1 : 0);
+       */
+       SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE);
+       mouse_grabbed = grab;
+}
+
+void app_toggle_grab_mouse()
+{
+       app_grab_mouse(!mouse_grabbed);
+}
+
+bool app_is_mouse_grabbed()
+{
+       return mouse_grabbed;
 }
 
 void app_quit()
@@ -137,7 +168,11 @@ static void process_event(SDL_Event *ev)
                break;
 
        case SDL_MOUSEMOTION:
-               app_mouse_motion(ev->motion.x * scale_factor, ev->motion.y * scale_factor);
+               if(mouse_grabbed) {
+                       app_mouse_delta(ev->motion.xrel, ev->motion.yrel);
+               } else {
+                       app_mouse_motion(ev->motion.x * scale_factor, ev->motion.y * scale_factor);
+               }
                break;
 
        case SDL_WINDOWEVENT: