mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-17 18:40:02 +00:00
engine: platform: added Platform_SetCursorType
This commit is contained in:
parent
15eb6808c4
commit
26e09c240a
39
engine/cursor_type.h
Normal file
39
engine/cursor_type.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
cursor_type.h - enumeration of possible mouse cursor types
|
||||||
|
Copyright (C) 2022 FWGS Team
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef CURSOR_TYPE_H
|
||||||
|
#define CURSOR_TYPE_H
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CursorType_User,
|
||||||
|
CursorType_None,
|
||||||
|
CursorType_Arrow,
|
||||||
|
CursorType_Ibeam,
|
||||||
|
CursorType_Wait,
|
||||||
|
CursorType_Crosshair,
|
||||||
|
CursorType_Up,
|
||||||
|
CursorType_SizeNwSe,
|
||||||
|
CursorType_SizeNeSw,
|
||||||
|
CursorType_SizeWe,
|
||||||
|
CursorType_SizeNs,
|
||||||
|
CursorType_SizeAll,
|
||||||
|
CursorType_No,
|
||||||
|
CursorType_Hand,
|
||||||
|
CursorType_Last
|
||||||
|
} cursor_type_t;
|
||||||
|
|
||||||
|
#endif
|
@ -20,6 +20,7 @@ GNU General Public License for more details.
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "defaults.h"
|
#include "defaults.h"
|
||||||
|
#include "cursor_type.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
@ -79,6 +80,7 @@ void Platform_GetMousePos( int *x, int *y );
|
|||||||
void Platform_SetMousePos( int x, int y );
|
void Platform_SetMousePos( int x, int y );
|
||||||
void Platform_PreCreateMove( void );
|
void Platform_PreCreateMove( void );
|
||||||
void Platform_MouseMove( float *x, float *y );
|
void Platform_MouseMove( float *x, float *y );
|
||||||
|
void Platform_SetCursorType( cursor_type_t type );
|
||||||
// Clipboard
|
// Clipboard
|
||||||
int Platform_GetClipboardText( char *buffer, size_t size );
|
int Platform_GetClipboardText( char *buffer, size_t size );
|
||||||
void Platform_SetClipboardText( const char *buffer );
|
void Platform_SetClipboardText( const char *buffer );
|
||||||
|
@ -25,6 +25,7 @@ GNU General Public License for more details.
|
|||||||
#include "vid_common.h"
|
#include "vid_common.h"
|
||||||
|
|
||||||
SDL_Joystick *g_joy = NULL;
|
SDL_Joystick *g_joy = NULL;
|
||||||
|
static SDL_Cursor *g_pDefaultCursor[CursorType_Last];
|
||||||
#if !SDL_VERSION_ATLEAST( 2, 0, 0 )
|
#if !SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||||
#define SDL_WarpMouseInWindow( win, x, y ) SDL_WarpMouse( ( x ), ( y ) )
|
#define SDL_WarpMouseInWindow( win, x, y ) SDL_WarpMouse( ( x ), ( y ) )
|
||||||
#endif
|
#endif
|
||||||
@ -246,4 +247,80 @@ int Platform_JoyInit( int numjoy )
|
|||||||
return SDLash_JoyInit_Old(numjoy);
|
return SDLash_JoyInit_Old(numjoy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
SDLash_InitCursors
|
||||||
|
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
static void SDLash_InitCursors( void )
|
||||||
|
{
|
||||||
|
static qboolean initialized = false;
|
||||||
|
if( !initialized )
|
||||||
|
{
|
||||||
|
// load up all default cursors
|
||||||
|
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||||
|
g_pDefaultCursor[CursorType_None] = NULL;
|
||||||
|
g_pDefaultCursor[CursorType_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||||
|
g_pDefaultCursor[CursorType_Ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
|
||||||
|
g_pDefaultCursor[CursorType_Wait] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
|
||||||
|
g_pDefaultCursor[CursorType_Crosshair] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
|
||||||
|
g_pDefaultCursor[CursorType_Up] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||||
|
g_pDefaultCursor[CursorType_SizeNwSe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
||||||
|
g_pDefaultCursor[CursorType_SizeNeSw] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
||||||
|
g_pDefaultCursor[CursorType_SizeWe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
||||||
|
g_pDefaultCursor[CursorType_SizeNs] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
||||||
|
g_pDefaultCursor[CursorType_SizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
|
||||||
|
g_pDefaultCursor[CursorType_No] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
|
||||||
|
g_pDefaultCursor[CursorType_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
|
||||||
|
#endif
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Platform_SetCursorType
|
||||||
|
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
void Platform_SetCursorType( cursor_type_t type )
|
||||||
|
{
|
||||||
|
qboolean visible;
|
||||||
|
|
||||||
|
if (cls.key_dest != key_game || cl.paused)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SDLash_InitCursors();
|
||||||
|
|
||||||
|
switch( type )
|
||||||
|
{
|
||||||
|
case CursorType_User:
|
||||||
|
case CursorType_None:
|
||||||
|
visible = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
visible = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
|
||||||
|
if( CVAR_TO_BOOL( touch_emulate ))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (visible && !host.mouse_visible)
|
||||||
|
{
|
||||||
|
SDL_SetCursor( g_pDefaultCursor[type] );
|
||||||
|
SDL_ShowCursor( true );
|
||||||
|
Key_EnableTextInput( true, false );
|
||||||
|
}
|
||||||
|
else if (!visible && host.mouse_visible)
|
||||||
|
{
|
||||||
|
SDL_ShowCursor( false );
|
||||||
|
Key_EnableTextInput( false, false );
|
||||||
|
}
|
||||||
|
host.mouse_visible = visible;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif // XASH_DEDICATED
|
#endif // XASH_DEDICATED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user