mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-31 05:40:44 +00:00
- Added cursor support for SDL.
SVN r3117 (trunk)
This commit is contained in:
parent
a5fb5c7fb4
commit
f942cd0bf3
4 changed files with 59 additions and 11 deletions
|
@ -21,7 +21,7 @@
|
|||
static void I_CheckGUICapture ();
|
||||
static void I_CheckNativeMouse ();
|
||||
|
||||
static bool GUICapture;
|
||||
bool GUICapture;
|
||||
static bool NativeMouse = true;
|
||||
|
||||
extern int paused;
|
||||
|
@ -36,6 +36,9 @@ EXTERN_CVAR (Bool, fullscreen)
|
|||
extern int WaitingForKey, chatmodeon;
|
||||
extern constate_e ConsoleState;
|
||||
|
||||
extern SDL_Surface *cursorSurface;
|
||||
extern SDL_Rect cursorBlit;
|
||||
|
||||
static BYTE KeySymToDIK[SDLK_LAST], DownState[SDLK_LAST];
|
||||
|
||||
static WORD DIKToKeySym[256] =
|
||||
|
@ -114,6 +117,11 @@ static void I_CheckGUICapture ()
|
|||
GUICapture = wantCapt;
|
||||
if (wantCapt)
|
||||
{
|
||||
int x, y;
|
||||
SDL_GetMouseState (&x, &y);
|
||||
cursorBlit.x = x;
|
||||
cursorBlit.y = y;
|
||||
|
||||
FlushDIKState ();
|
||||
memset (DownState, 0, sizeof(DownState));
|
||||
repeat = !sdl_nokeyrepeat;
|
||||
|
@ -260,15 +268,14 @@ static void I_CheckNativeMouse ()
|
|||
if (wantNative != NativeMouse)
|
||||
{
|
||||
NativeMouse = wantNative;
|
||||
SDL_ShowCursor (wantNative ? cursorSurface == NULL : 0);
|
||||
if (wantNative)
|
||||
{
|
||||
SDL_ShowCursor (1);
|
||||
SDL_WM_GrabInput (SDL_GRAB_OFF);
|
||||
FlushDIKState (KEY_MOUSE1, KEY_MOUSE8);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_ShowCursor (0);
|
||||
SDL_WM_GrabInput (SDL_GRAB_ON);
|
||||
CenterMouse ();
|
||||
}
|
||||
|
@ -347,8 +354,8 @@ void MessagePump (const SDL_Event &sev)
|
|||
int x, y;
|
||||
SDL_GetMouseState (&x, &y);
|
||||
|
||||
event.data1 = x;
|
||||
event.data2 = y;
|
||||
cursorBlit.x = event.data1 = x;
|
||||
cursorBlit.y = event.data2 = y;
|
||||
event.type = EV_GUI_Event;
|
||||
if(sev.type == SDL_MOUSEMOTION)
|
||||
event.subtype = EV_GUI_MouseMove;
|
||||
|
|
|
@ -60,6 +60,9 @@
|
|||
#include "i_system.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "templates.h"
|
||||
#include "v_palette.h"
|
||||
#include "textures.h"
|
||||
#include "bitmap.h"
|
||||
|
||||
#include "stats.h"
|
||||
#include "hardware.h"
|
||||
|
@ -830,7 +833,39 @@ unsigned int I_MakeRNGSeed()
|
|||
return seed;
|
||||
}
|
||||
|
||||
SDL_Surface *cursorSurface = NULL;
|
||||
SDL_Rect cursorBlit = {0, 0, 32, 32};
|
||||
bool I_SetCursor(FTexture *cursorpic)
|
||||
{
|
||||
return false;
|
||||
if (cursorpic != NULL && cursorpic->UseType != FTexture::TEX_Null)
|
||||
{
|
||||
// Must be no larger than 32x32.
|
||||
if (cursorpic->GetWidth() > 32 || cursorpic->GetHeight() > 32)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cursorSurface == NULL)
|
||||
cursorSurface = SDL_CreateRGBSurface (0, 32, 32, 32, MAKEARGB(0,255,0,0), MAKEARGB(0,0,255,0), MAKEARGB(0,0,0,255), MAKEARGB(255,0,0,0));
|
||||
|
||||
SDL_ShowCursor(0);
|
||||
SDL_LockSurface(cursorSurface);
|
||||
BYTE buffer[32*32*4];
|
||||
memset(buffer, 0, 32*32*4);
|
||||
FBitmap bmp(buffer, 32*4, 32, 32);
|
||||
cursorpic->CopyTrueColorPixels(&bmp, 0, 0);
|
||||
memcpy(cursorSurface->pixels, bmp.GetPixels(), 32*32*4);
|
||||
SDL_UnlockSurface(cursorSurface);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_ShowCursor(1);
|
||||
|
||||
if (cursorSurface != NULL)
|
||||
{
|
||||
SDL_FreeSurface(cursorSurface);
|
||||
cursorSurface = NULL;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -76,6 +76,9 @@ void DoBlending (const PalEntry *from, PalEntry *to, int count, int r, int g, in
|
|||
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
||||
|
||||
extern IVideo *Video;
|
||||
extern SDL_Surface *cursorSurface;
|
||||
extern SDL_Rect cursorBlit;
|
||||
extern bool GUICapture;
|
||||
|
||||
EXTERN_CVAR (Float, Gamma)
|
||||
|
||||
|
@ -404,7 +407,13 @@ void SDLFB::Update ()
|
|||
}
|
||||
|
||||
SDL_UnlockSurface (Screen);
|
||||
|
||||
|
||||
if (cursorSurface != NULL && GUICapture)
|
||||
{
|
||||
// SDL requires us to draw a surface to get true color cursors.
|
||||
SDL_BlitSurface(cursorSurface, NULL, Screen, &cursorBlit);
|
||||
}
|
||||
|
||||
SDLFlipCycles.Clock();
|
||||
SDL_Flip (Screen);
|
||||
SDLFlipCycles.Unclock();
|
||||
|
|
|
@ -528,10 +528,7 @@ OptionMenu "MouseOptions"
|
|||
Option "Enable mouse", "use_mouse", "YesNo"
|
||||
Option "Enable mouse in menus", "m_use_mouse", "MenuMouse", "use_mouse"
|
||||
Option "Show back button", "m_show_backbutton", "Corners", "use_mouse"
|
||||
IfOption(Windows) // No cursors on SDL right now.
|
||||
{
|
||||
Option "Cursor", "vid_cursor", "Cursors"
|
||||
}
|
||||
Option "Cursor", "vid_cursor", "Cursors"
|
||||
StaticText ""
|
||||
Slider "Overall sensitivity", "mouse_sensitivity", 0.5, 2.5, 0.1
|
||||
Option "Prescale mouse movement", "m_noprescale", "NoYes"
|
||||
|
|
Loading…
Reference in a new issue