summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2005-08-31 23:58:28 +0000
committerSimon Howard2005-08-31 23:58:28 +0000
commit18db00e1c410b77426072720ad55d5117b457725 (patch)
tree1a208082eba812d379983c631bead410c50caac7 /src
parenta9fd2c72eb93708461c42dc623e5273c4895717a (diff)
downloadchocolate-doom-18db00e1c410b77426072720ad55d5117b457725.tar.gz
chocolate-doom-18db00e1c410b77426072720ad55d5117b457725.tar.bz2
chocolate-doom-18db00e1c410b77426072720ad55d5117b457725.zip
smarter mouse grabbing for windowed mode
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 63
Diffstat (limited to 'src')
-rw-r--r--src/i_video.c72
1 files changed, 61 insertions, 11 deletions
diff --git a/src/i_video.c b/src/i_video.c
index 64f2c449..4bc4a5f1 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