Enable native cursor via dvar.

This commit is contained in:
momo5502 2015-12-31 01:10:15 +01:00
parent b3e904115d
commit 8b81fe37ae
4 changed files with 21 additions and 5 deletions

View File

@ -3,6 +3,8 @@
namespace Components namespace Components
{ {
Dvar::Var Window::NoBorder; Dvar::Var Window::NoBorder;
Dvar::Var Window::NativeCursor;
HWND Window::MainWindow = 0; HWND Window::MainWindow = 0;
BOOL Window::CursorVisible = TRUE; BOOL Window::CursorVisible = TRUE;
@ -20,14 +22,21 @@ namespace Components
__asm retn __asm retn
} }
void Window::DrawCursorStub() void Window::DrawCursorStub(void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Game::Material *material)
{
if (Window::NativeCursor.Get<bool>())
{ {
Window::CursorVisible = TRUE; Window::CursorVisible = TRUE;
} }
else
{
Game::UI_DrawHandlePic(scrPlace, x, y, w, h, horzAlign, vertAlign, color, material);
}
}
int WINAPI Window::ShowCursorHook(BOOL show) int WINAPI Window::ShowCursorHook(BOOL show)
{ {
if (GetForegroundWindow() == Window::MainWindow) if (Window::NativeCursor.Get<bool>() && GetForegroundWindow() == Window::MainWindow)
{ {
static int count = 0; static int count = 0;
(show ? ++count : --count); (show ? ++count : --count);
@ -53,6 +62,8 @@ namespace Components
{ {
// Borderless window // Borderless window
Window::NoBorder = Dvar::Register<bool>("r_noborder", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Do not use a border in windowed mode"); Window::NoBorder = Dvar::Register<bool>("r_noborder", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Do not use a border in windowed mode");
Window::NativeCursor = Dvar::Register<bool>("ui_nativeCursor", false, Game::dvar_flag::DVAR_FLAG_SAVED, "Display native cursor");
Utils::Hook(0x507643, Window::StyleHookStub, HOOK_CALL).Install()->Quick(); Utils::Hook(0x507643, Window::StyleHookStub, HOOK_CALL).Install()->Quick();
// Main window creation // Main window creation
@ -65,7 +76,7 @@ namespace Components
// Draw the cursor if necessary // Draw the cursor if necessary
Renderer::OnFrame([] () Renderer::OnFrame([] ()
{ {
if (GetForegroundWindow() == Window::MainWindow) if (Window::NativeCursor.Get<bool>() && GetForegroundWindow() == Window::MainWindow)
{ {
int value = 0; int value = 0;

View File

@ -7,13 +7,14 @@ namespace Components
const char* GetName() { return "Window"; }; const char* GetName() { return "Window"; };
static Dvar::Var NoBorder; static Dvar::Var NoBorder;
static Dvar::Var NativeCursor;
static void Window::StyleHookStub(); static void Window::StyleHookStub();
private: private:
static BOOL CursorVisible; static BOOL CursorVisible;
static int WINAPI ShowCursorHook(BOOL show); static int WINAPI ShowCursorHook(BOOL show);
static void DrawCursorStub(); static void DrawCursorStub(void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Game::Material *material);
static HWND MainWindow; static HWND MainWindow;

View File

@ -87,6 +87,7 @@ namespace Game
Steam_JoinLobby_t Steam_JoinLobby = (Steam_JoinLobby_t)0x49CF70; Steam_JoinLobby_t Steam_JoinLobby = (Steam_JoinLobby_t)0x49CF70;
UI_AddMenuList_t UI_AddMenuList = (UI_AddMenuList_t)0x4533C0; UI_AddMenuList_t UI_AddMenuList = (UI_AddMenuList_t)0x4533C0;
UI_DrawHandlePic_t UI_DrawHandlePic = (UI_DrawHandlePic_t)0x4D0EA0;
Win_GetLanguage_t Win_GetLanguage = (Win_GetLanguage_t)0x45CBA0; Win_GetLanguage_t Win_GetLanguage = (Win_GetLanguage_t)0x45CBA0;

View File

@ -190,6 +190,9 @@ namespace Game
typedef void(__cdecl * UI_AddMenuList_t)(UiContext *dc, MenuList *menuList, int close); typedef void(__cdecl * UI_AddMenuList_t)(UiContext *dc, MenuList *menuList, int close);
extern UI_AddMenuList_t UI_AddMenuList; extern UI_AddMenuList_t UI_AddMenuList;
typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material);
extern UI_DrawHandlePic_t UI_DrawHandlePic;
typedef const char * (__cdecl * Win_GetLanguage_t)(); typedef const char * (__cdecl * Win_GetLanguage_t)();
extern Win_GetLanguage_t Win_GetLanguage; extern Win_GetLanguage_t Win_GetLanguage;