[chocolate-doom] 57/83: smarter mouse grabbing for windowed mode

Jonathan Dowland jmtd at moszumanska.debian.org
Mon Jan 30 15:06:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

jmtd pushed a commit to annotated tag chocolate-doom-0.0.1
in repository chocolate-doom.

commit 18db00e1c410b77426072720ad55d5117b457725
Author: Simon Howard <fraggle at gmail.com>
Date:   Wed Aug 31 23:58:28 2005 +0000

    smarter mouse grabbing for windowed mode
    
    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 63
---
 src/i_video.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 61 insertions(+), 11 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index 64f2c44..4bc4a5f 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_video.c 61 2005-08-31 21:35:42Z fraggle $
+// $Id: i_video.c 63 2005-08-31 23:58:28Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.20  2005/08/31 23:58:28  fraggle
+// smarter mouse grabbing for windowed mode
+//
 // Revision 1.19  2005/08/31 21:35:42  fraggle
 // Display the game name in the title bar.  Move game start code to later
 // in initialisation because of the IWAD detection changes.
@@ -91,7 +94,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_video.c 61 2005-08-31 21:35:42Z fraggle $";
+rcsid[] = "$Id: i_video.c 63 2005-08-31 23:58:28Z fraggle $";
 
 #include <ctype.h>
 #include <SDL.h>
@@ -116,10 +119,8 @@ static SDL_Surface *screen;
 static SDL_Color palette[256];
 static boolean palette_to_set;
 
-// Fake mouse handling.
-// This cannot work properly w/o DGA.
-// Needs an invisible mouse cursor at least.
-boolean		grabMouse;
+boolean fullscreen = 1;
+boolean grabmouse = 1;
 
 // Blocky mode,
 // replace each 320x200 pixel with multiply*multiply pixels.
@@ -134,6 +135,29 @@ static byte *disk_image = NULL;
 static int disk_image_w, disk_image_h;
 static byte *saved_background;
 
+static boolean mouse_should_be_grabbed()
+{
+    // always grab the mouse when full screen (dont want to 
+    // see the mouse pointer)
+
+    if (fullscreen)
+        return true;
+
+    // if we specify not to grab the mouse, never grab
+ 
+    if (!grabmouse)
+        return false;
+
+    // when menu is active or game is paused, release the mouse 
+ 
+    if (menuactive || paused)
+        return false;
+
+    // only grab mouse when playing levels (but not demos)
+
+    return (gamestate == GS_LEVEL) && !demoplayback;
+}
+
 void I_BeginRead(void)
 {
     int y;
@@ -293,6 +317,9 @@ int xlatekey(SDL_keysym *sym)
 
 void I_ShutdownGraphics(void)
 {
+    SDL_ShowCursor(1);
+    SDL_WM_GrabInput(SDL_GRAB_OFF);
+
     SDL_QuitSubSystem(SDL_INIT_VIDEO);
 }
 
@@ -478,17 +505,41 @@ void I_UpdateNoBlit (void)
     // what is this?
 }
 
+void UpdateGrab(void)
+{
+    static boolean currently_grabbed = false;
+    boolean grab;
+
+    grab = mouse_should_be_grabbed();
+
+    if (grab && !currently_grabbed)
+    {
+        SDL_ShowCursor(0);
+        SDL_WM_GrabInput(SDL_GRAB_ON);
+    }
+
+    if (!grab && currently_grabbed)
+    {
+        SDL_ShowCursor(1);
+        SDL_WM_GrabInput(SDL_GRAB_OFF);
+    }
+
+    currently_grabbed = grab;
+
+}
+
 //
 // I_FinishUpdate
 //
 void I_FinishUpdate (void)
 {
-
     static int	lasttic;
     int		tics;
     int		i;
     // UNUSED static unsigned char *bigscreen=0;
 
+    UpdateGrab();
+
     // draws little dots on the bottom of the screen
     if (devparm)
     {
@@ -688,7 +739,9 @@ void I_InitGraphics(void)
     // default to fullscreen mode, allow override with command line
     // nofullscreen because we love prboom
 
-    if (!M_CheckParm("-window") && !M_CheckParm("-nofullscreen"))
+    fullscreen = !M_CheckParm("-window") && !M_CheckParm("-nofullscreen");
+
+    if (fullscreen)
     {
         flags |= SDL_FULLSCREEN;
     }
@@ -709,9 +762,6 @@ void I_InitGraphics(void)
 
     SetCaption();
 
-    SDL_ShowCursor(0);
-    SDL_WM_GrabInput(SDL_GRAB_ON);
-
     if (multiply == 1)
 	screens[0] = (unsigned char *) (screen->pixels);
     else

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/chocolate-doom.git



More information about the Pkg-games-commits mailing list