ref: 18db00e1c410b77426072720ad55d5117b457725
parent: a9fd2c72eb93708461c42dc623e5273c4895717a
author: Simon Howard <[email protected]>
date: Wed Aug 31 19:58:28 EDT 2005
smarter mouse grabbing for windowed mode Subversion-branch: /trunk/chocolate-doom Subversion-revision: 63
--- 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_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 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 @@
void I_ShutdownGraphics(void)
{
+ SDL_ShowCursor(1);
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
@@ -478,17 +505,41 @@
// 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 @@
// 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;
}
@@ -708,9 +761,6 @@
}
SetCaption();
-
- SDL_ShowCursor(0);
- SDL_WM_GrabInput(SDL_GRAB_ON);
if (multiply == 1)
screens[0] = (unsigned char *) (screen->pixels);