mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
parent
a1ef18e059
commit
0d17665137
|
@ -895,6 +895,9 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *pScreen, int *pWid
|
|||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
|
||||
}
|
||||
|
||||
if(g_Config.m_InpMouseOld)
|
||||
SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1");
|
||||
|
||||
m_pWindow = SDL_CreateWindow(
|
||||
pName,
|
||||
SDL_WINDOWPOS_CENTERED_DISPLAY(*pScreen),
|
||||
|
@ -1214,9 +1217,4 @@ void CGraphicsBackend_SDL_OpenGL::NotifyWindow()
|
|||
#endif
|
||||
}
|
||||
|
||||
void CGraphicsBackend_SDL_OpenGL::WarpMouse(int MouseX, int MouseY)
|
||||
{
|
||||
SDL_WarpMouseInWindow(m_pWindow, MouseX, MouseY);
|
||||
}
|
||||
|
||||
IGraphicsBackend *CreateGraphicsBackend() { return new CGraphicsBackend_SDL_OpenGL; }
|
||||
|
|
|
@ -257,7 +257,6 @@ public:
|
|||
virtual void ResizeWindow(int w, int h, int RefreshRate);
|
||||
virtual void GetViewportSize(int &w, int &h);
|
||||
virtual void NotifyWindow();
|
||||
virtual void WarpMouse(int MouseX, int MouseY);
|
||||
|
||||
virtual void GetDriverVersion(EGraphicsDriverAgeType DriverAgeType, int &Major, int &Minor, int &Patch);
|
||||
virtual bool IsConfigModernAPI() { return IsModernAPI(m_BackendType); }
|
||||
|
|
|
@ -3254,6 +3254,7 @@ void CClient::Run()
|
|||
if(CtrlShiftKey(KEY_E, LastE))
|
||||
{
|
||||
g_Config.m_ClEditor = g_Config.m_ClEditor ^ 1;
|
||||
Input()->MouseModeRelative();
|
||||
Input()->SetIMEState(true);
|
||||
}
|
||||
|
||||
|
@ -3263,6 +3264,7 @@ void CClient::Run()
|
|||
{
|
||||
if(!m_EditorActive)
|
||||
{
|
||||
Input()->MouseModeRelative();
|
||||
GameClient()->OnActivateEditor();
|
||||
m_pEditor->ResetMentions();
|
||||
m_EditorActive = true;
|
||||
|
|
|
@ -2430,11 +2430,6 @@ void CGraphics_Threaded::NotifyWindow()
|
|||
return m_pBackend->NotifyWindow();
|
||||
}
|
||||
|
||||
void CGraphics_Threaded::WarpMouse(int MouseX, int MouseY)
|
||||
{
|
||||
return m_pBackend->WarpMouse(MouseX, MouseY);
|
||||
}
|
||||
|
||||
void CGraphics_Threaded::TakeScreenshot(const char *pFilename)
|
||||
{
|
||||
// TODO: screenshot support
|
||||
|
|
|
@ -678,7 +678,6 @@ public:
|
|||
virtual void ResizeWindow(int w, int h, int RefreshRate) = 0;
|
||||
virtual void GetViewportSize(int &w, int &h) = 0;
|
||||
virtual void NotifyWindow() = 0;
|
||||
virtual void WarpMouse(int MouseX, int MouseY) = 0;
|
||||
|
||||
virtual void RunBuffer(CCommandBuffer *pBuffer) = 0;
|
||||
virtual bool IsIdle() const = 0;
|
||||
|
@ -1179,7 +1178,6 @@ public:
|
|||
|
||||
void SetWindowGrab(bool Grab) override;
|
||||
void NotifyWindow() override;
|
||||
void WarpMouse(int MouseX, int MouseY) override;
|
||||
|
||||
int Init() override;
|
||||
void Shutdown() override;
|
||||
|
|
|
@ -162,8 +162,6 @@ public:
|
|||
void SetWindowGrab(bool Grab) override{};
|
||||
void NotifyWindow() override{};
|
||||
|
||||
void WarpMouse(int MouseX, int MouseY) override {}
|
||||
|
||||
int Init() override { return 0; };
|
||||
void Shutdown() override{};
|
||||
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
#include <engine/keys.h>
|
||||
#include <engine/shared/config.h>
|
||||
|
||||
#include "SDL_mouse.h"
|
||||
#include "SDL_video.h"
|
||||
|
||||
#include "input.h"
|
||||
|
||||
//print >>f, "int inp_key_code(const char *key_name) { int i; if (!strcmp(key_name, \"-?-\")) return -1; else for (i = 0; i < 512; i++) if (!strcmp(key_strings[i], key_name)) return i; return -1; }"
|
||||
|
@ -41,6 +38,7 @@ CInput::CInput()
|
|||
mem_zero(m_aInputState, sizeof(m_aInputState));
|
||||
|
||||
m_InputCounter = 1;
|
||||
m_InputGrabbed = 0;
|
||||
|
||||
m_LastRelease = 0;
|
||||
m_ReleaseDelta = -1;
|
||||
|
@ -54,6 +52,9 @@ CInput::CInput()
|
|||
m_NumTextInputInstances = 0;
|
||||
m_EditingTextLen = -1;
|
||||
m_aEditingText[0] = 0;
|
||||
|
||||
m_LastX = 0;
|
||||
m_LastY = 0;
|
||||
}
|
||||
|
||||
void CInput::Init()
|
||||
|
@ -65,10 +66,10 @@ void CInput::Init()
|
|||
MouseModeRelative();
|
||||
}
|
||||
|
||||
bool CInput::MouseRelative(float *x, float *y)
|
||||
void CInput::MouseRelative(float *x, float *y)
|
||||
{
|
||||
if(!m_MouseFocus || GetMouseMode() != INPUT_MOUSE_MODE_RELATIVE)
|
||||
return false;
|
||||
if(!m_MouseFocus || !m_InputGrabbed)
|
||||
return;
|
||||
|
||||
int nx = 0, ny = 0;
|
||||
float Sens = g_Config.m_InpMousesens / 100.0f;
|
||||
|
@ -88,142 +89,24 @@ bool CInput::MouseRelative(float *x, float *y)
|
|||
|
||||
*x = nx * Sens;
|
||||
*y = ny * Sens;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CInput::MouseDesktopRelative(int *x, int *y)
|
||||
void CInput::MouseModeAbsolute()
|
||||
{
|
||||
if(!m_MouseFocus || GetMouseMode() != INPUT_MOUSE_MODE_INGAME_RELATIVE)
|
||||
return false;
|
||||
|
||||
SDL_GetRelativeMouseState(x, y);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CInput::MouseAbsolute(int *x, int *y)
|
||||
{
|
||||
if(!m_MouseFocus || (GetMouseMode() != INPUT_MOUSE_MODE_INGAME && GetMouseMode() != INPUT_MOUSE_MODE_ABSOLUTE))
|
||||
return false;
|
||||
|
||||
SDL_GetMouseState(x, y);
|
||||
|
||||
m_DesktopX = *x;
|
||||
m_DesktopY = *y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CInput::MouseModeChange(EInputMouseMode OldState, EInputMouseMode NewState)
|
||||
{
|
||||
if(g_Config.m_InpMouseOld && (NewState == EInputMouseMode::INPUT_MOUSE_MODE_RELATIVE))
|
||||
SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE);
|
||||
else
|
||||
SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "0", SDL_HINT_OVERRIDE);
|
||||
}
|
||||
|
||||
bool CInput::MouseModeAbsolute()
|
||||
{
|
||||
if(GetMouseMode() != INPUT_MOUSE_MODE_ABSOLUTE)
|
||||
{
|
||||
MouseModeChange(GetMouseMode(), INPUT_MOUSE_MODE_ABSOLUTE);
|
||||
SetMouseMode(INPUT_MOUSE_MODE_ABSOLUTE);
|
||||
m_InputGrabbed = 0;
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
Graphics()->SetWindowGrab(false);
|
||||
|
||||
SDL_ShowCursor(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CInput::MouseModeRelative()
|
||||
void CInput::MouseModeRelative()
|
||||
{
|
||||
if(GetMouseMode() != INPUT_MOUSE_MODE_RELATIVE)
|
||||
{
|
||||
EInputMouseMode OldMode = GetMouseMode();
|
||||
MouseModeChange(OldMode, INPUT_MOUSE_MODE_RELATIVE);
|
||||
// turn off relative mouse to trigger the SDL hints
|
||||
// TODO: remove this once SDL fixes mouse grabbing in macos @see MouseModeInGame
|
||||
#ifdef CONF_PLATFORM_MACOS
|
||||
if(OldMode != INPUT_MOUSE_MODE_ABSOLUTE)
|
||||
#else
|
||||
if(OldMode == INPUT_MOUSE_MODE_INGAME_RELATIVE)
|
||||
#endif
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SetMouseMode(INPUT_MOUSE_MODE_RELATIVE);
|
||||
m_InputGrabbed = 1;
|
||||
#if !defined(CONF_PLATFORM_ANDROID) // No relative mouse on Android
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
#endif
|
||||
Graphics()->SetWindowGrab(true);
|
||||
// Clear pending relative mouse motion
|
||||
SDL_GetRelativeMouseState(0x0, 0x0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CInput::MouseModeInGameRelativeImpl()
|
||||
{
|
||||
SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE);
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
Graphics()->SetWindowGrab(true);
|
||||
SDL_GetRelativeMouseState(0x0, 0x0);
|
||||
}
|
||||
|
||||
bool CInput::MouseModeInGame(int *pDesiredX, int *pDesiredY)
|
||||
{
|
||||
if(GetMouseMode() != INPUT_MOUSE_MODE_INGAME)
|
||||
{
|
||||
EInputMouseMode OldMode = GetMouseMode();
|
||||
MouseModeChange(OldMode, INPUT_MOUSE_MODE_INGAME);
|
||||
SetMouseMode(INPUT_MOUSE_MODE_INGAME);
|
||||
|
||||
// TODO: remove this once SDL fixes mouse grabbing in macos (https://github.com/libsdl-org/SDL/commit/2fdbae22cb2f75643447c34d2dab7f15305e3567)
|
||||
#ifdef CONF_PLATFORM_MACOS
|
||||
// turn off relative mouse to trigger the SDL hints
|
||||
if(OldMode == INPUT_MOUSE_MODE_RELATIVE)
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
MouseModeInGameRelativeImpl();
|
||||
#else
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
Graphics()->SetWindowGrab(true);
|
||||
SDL_ShowCursor(false);
|
||||
#endif
|
||||
|
||||
if(OldMode == INPUT_MOUSE_MODE_RELATIVE || OldMode == INPUT_MOUSE_MODE_INGAME_RELATIVE)
|
||||
{
|
||||
int WarpX = pDesiredX ? *pDesiredX : m_DesktopX;
|
||||
int WarpY = pDesiredY ? *pDesiredY : m_DesktopY;
|
||||
Graphics()->WarpMouse(WarpX, WarpY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CInput::MouseModeInGameRelative()
|
||||
{
|
||||
if(GetMouseMode() != INPUT_MOUSE_MODE_INGAME_RELATIVE)
|
||||
{
|
||||
EInputMouseMode OldMode = GetMouseMode();
|
||||
MouseModeChange(OldMode, INPUT_MOUSE_MODE_INGAME_RELATIVE);
|
||||
// turn off relative mouse to trigger the SDL hints
|
||||
if(OldMode == INPUT_MOUSE_MODE_RELATIVE)
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SetMouseMode(INPUT_MOUSE_MODE_INGAME_RELATIVE);
|
||||
|
||||
MouseModeInGameRelativeImpl();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CInput::NativeMousePos(int *x, int *y) const
|
||||
|
@ -481,25 +364,29 @@ int CInput::Update()
|
|||
Graphics()->Resize(Event.window.data1, Event.window.data2, -1);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
if(GetMouseMode() != INPUT_MOUSE_MODE_ABSOLUTE)
|
||||
{
|
||||
SDL_ShowCursor(SDL_FALSE);
|
||||
}
|
||||
if(m_InputGrabbed)
|
||||
MouseModeRelative();
|
||||
m_MouseFocus = true;
|
||||
IgnoreKeys = true;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
m_MouseFocus = false;
|
||||
IgnoreKeys = true;
|
||||
if(GetMouseMode() != INPUT_MOUSE_MODE_ABSOLUTE)
|
||||
if(m_InputGrabbed)
|
||||
{
|
||||
SDL_ShowCursor(SDL_TRUE);
|
||||
MouseModeAbsolute();
|
||||
// Remember that we had relative mouse
|
||||
m_InputGrabbed = true;
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MINIMIZED:
|
||||
Graphics()->WindowDestroyNtf(Event.window.windowID);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
#if defined(CONF_PLATFORM_MACOS) // Todo: remove this when fixed in SDL
|
||||
MouseModeAbsolute();
|
||||
MouseModeRelative();
|
||||
#endif
|
||||
// fallthrough
|
||||
case SDL_WINDOWEVENT_RESTORED:
|
||||
Graphics()->WindowCreateNtf(Event.window.windowID);
|
||||
|
|
|
@ -12,6 +12,10 @@ class CInput : public IEngineInput
|
|||
{
|
||||
IEngineGraphics *m_pGraphics;
|
||||
|
||||
int m_LastX;
|
||||
int m_LastY;
|
||||
|
||||
int m_InputGrabbed;
|
||||
char *m_pClipboardText;
|
||||
|
||||
int64_t m_LastRelease;
|
||||
|
@ -35,15 +39,10 @@ class CInput : public IEngineInput
|
|||
int m_EditingTextLen;
|
||||
int m_EditingCursor;
|
||||
|
||||
int m_DesktopX = 0;
|
||||
int m_DesktopY = 0;
|
||||
|
||||
bool KeyState(int Key) const;
|
||||
|
||||
IEngineGraphics *Graphics() { return m_pGraphics; }
|
||||
|
||||
void MouseModeInGameRelativeImpl();
|
||||
|
||||
public:
|
||||
CInput();
|
||||
|
||||
|
@ -52,19 +51,11 @@ public:
|
|||
bool KeyIsPressed(int Key) const { return KeyState(Key); }
|
||||
bool KeyPress(int Key, bool CheckCounter) const { return CheckCounter ? (m_aInputCount[Key] == m_InputCounter) : m_aInputCount[Key]; }
|
||||
|
||||
virtual void MouseRelative(float *x, float *y);
|
||||
virtual void MouseModeAbsolute();
|
||||
virtual void MouseModeRelative();
|
||||
virtual void NativeMousePos(int *x, int *y) const;
|
||||
virtual bool NativeMousePressed(int index);
|
||||
virtual bool MouseRelative(float *x, float *y);
|
||||
virtual bool MouseDesktopRelative(int *x, int *y);
|
||||
virtual bool MouseAbsolute(int *x, int *y);
|
||||
|
||||
// return true if the mode was changed
|
||||
virtual void MouseModeChange(EInputMouseMode OldState, EInputMouseMode NewState);
|
||||
virtual bool MouseModeAbsolute();
|
||||
virtual bool MouseModeRelative();
|
||||
virtual bool MouseModeInGame(int *pDesiredX = NULL, int *pDesiredY = NULL);
|
||||
virtual bool MouseModeInGameRelative();
|
||||
|
||||
virtual int MouseDoubleClick();
|
||||
virtual const char *GetClipboardText();
|
||||
virtual void SetClipboardText(const char *Text);
|
||||
|
|
|
@ -410,8 +410,6 @@ public:
|
|||
virtual void SetWindowGrab(bool Grab) = 0;
|
||||
virtual void NotifyWindow() = 0;
|
||||
|
||||
virtual void WarpMouse(int MouseX, int MouseY) = 0;
|
||||
|
||||
virtual SWarning *GetCurWarning() = 0;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -8,18 +8,6 @@
|
|||
const int g_MaxKeys = 512;
|
||||
extern const char g_aaKeyStrings[g_MaxKeys][20];
|
||||
|
||||
enum EInputMouseMode
|
||||
{
|
||||
// Use absolute mouse mode, doesn't grab the mouse inside the window and uses desktop cursor coordinates
|
||||
INPUT_MOUSE_MODE_ABSOLUTE = 0,
|
||||
// Use relative mouse mode, does grab the mouse inside the window and uses mouse driver coordinates(except if mouse old)
|
||||
INPUT_MOUSE_MODE_RELATIVE,
|
||||
// Use ingame mouse mode, does grab the mouse inside the window, but uses uses desktop cursor coordinates
|
||||
INPUT_MOUSE_MODE_INGAME,
|
||||
// Use ingame mouse mode, does grab the mouse inside the window, but uses uses desktop cursor coordinates, but is relative
|
||||
INPUT_MOUSE_MODE_INGAME_RELATIVE,
|
||||
};
|
||||
|
||||
class IInput : public IInterface
|
||||
{
|
||||
MACRO_INTERFACE("input", 0)
|
||||
|
@ -48,8 +36,6 @@ protected:
|
|||
int m_NumEvents;
|
||||
IInput::CEvent m_aInputEvents[INPUT_BUFFER_SIZE];
|
||||
|
||||
EInputMouseMode m_MouseMode = INPUT_MOUSE_MODE_ABSOLUTE;
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
|
@ -59,9 +45,6 @@ public:
|
|||
FLAG_TEXT = 8,
|
||||
};
|
||||
|
||||
EInputMouseMode GetMouseMode() { return m_MouseMode; };
|
||||
void SetMouseMode(EInputMouseMode NewMode) { m_MouseMode = NewMode; };
|
||||
|
||||
// events
|
||||
int NumEvents() const { return m_NumEvents; }
|
||||
virtual bool IsEventValid(CEvent *pEvent) const = 0;
|
||||
|
@ -85,22 +68,15 @@ public:
|
|||
virtual void Clear() = 0;
|
||||
|
||||
//
|
||||
virtual void NativeMousePos(int *x, int *y) const = 0;
|
||||
virtual void NativeMousePos(int *mx, int *my) const = 0;
|
||||
virtual bool NativeMousePressed(int index) = 0;
|
||||
// return true if the mode was changed
|
||||
virtual bool MouseModeRelative() = 0;
|
||||
virtual bool MouseModeAbsolute() = 0;
|
||||
virtual bool MouseModeInGame(int *pDesiredX = NULL, int *pDesiredY = NULL) = 0;
|
||||
virtual bool MouseModeInGameRelative() = 0;
|
||||
|
||||
virtual void MouseModeRelative() = 0;
|
||||
virtual void MouseModeAbsolute() = 0;
|
||||
virtual int MouseDoubleClick() = 0;
|
||||
virtual const char *GetClipboardText() = 0;
|
||||
virtual void SetClipboardText(const char *Text) = 0;
|
||||
|
||||
// return true if there was a mouse input
|
||||
virtual bool MouseAbsolute(int *x, int *y) = 0;
|
||||
virtual bool MouseDesktopRelative(int *x, int *y) = 0;
|
||||
virtual bool MouseRelative(float *x, float *y) = 0;
|
||||
virtual void MouseRelative(float *x, float *y) = 0;
|
||||
|
||||
virtual bool GetIMEState() = 0;
|
||||
virtual void SetIMEState(bool Activate) = 0;
|
||||
|
|
|
@ -18,16 +18,6 @@
|
|||
|
||||
class CGameClient;
|
||||
|
||||
enum EComponentMouseMovementBlockMode
|
||||
{
|
||||
COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK = 0,
|
||||
COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK,
|
||||
COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME,
|
||||
COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME_RELATIVE,
|
||||
COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_RELATIVE,
|
||||
COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_ABSOLUTE,
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is inherited by all the client components.
|
||||
*
|
||||
|
@ -202,38 +192,12 @@ public:
|
|||
*/
|
||||
virtual void OnMessage(int Msg, void *pRawMsg) {}
|
||||
/**
|
||||
* Called on mouse movement, where the x and y values are the desktop cursor coordinates relative to the window rect.
|
||||
*
|
||||
* @param x The x relative coordinate of the desktop cursor inside the window rect.
|
||||
* @param y The y relative coordinate of the desktop cursor inside the window rect.
|
||||
* @return Returns how to block the mouse for components that are called after the current component. Can also be used to change the mouse mode to a desired mode.
|
||||
*/
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowPos(int X, int Y) { return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK; }
|
||||
/**
|
||||
* Called on absolute mouse movement, where the x and y values are the desktop cursor coordinates relative to the window rect.
|
||||
* It's similar to @see OnMouseInWindowPos, but does not grab the mouse inside the window and also shows the desktop cursor
|
||||
*
|
||||
* @param x The x relative coordinate of the desktop cursor inside the window rect.
|
||||
* @param y The y relative coordinate of the desktop cursor inside the window rect.
|
||||
* @return Returns how to block the mouse for components that are called after the current component. Can also be used to change the mouse mode to a desired mode.
|
||||
*/
|
||||
virtual EComponentMouseMovementBlockMode OnMouseAbsoluteInWindowPos(int X, int Y) { return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK; }
|
||||
/**
|
||||
* Called on relative mouse movement, where the x and y values are deltas of the desktop cursor.
|
||||
* Called on mouse movement, where the x and y values are deltas.
|
||||
*
|
||||
* @param x The amount of change in the x coordinate since the last call.
|
||||
* @param y The amount of change in the y coordinate since the last call.
|
||||
* @return Returns how to block the mouse for components that are called after the current component. Can also be used to change the mouse mode to a desired mode.
|
||||
*/
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowRelativeMove(int X, int Y) { return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK; }
|
||||
/**
|
||||
* Called on relative mouse movement, where the x and y values are deltas.
|
||||
*
|
||||
* @param x The amount of change in the x coordinate since the last call.
|
||||
* @param y The amount of change in the y coordinate since the last call.
|
||||
* @return Returns how to block the mouse for components that are called after the current component. Can also be used to change the mouse mode to a desired mode.
|
||||
*/
|
||||
virtual EComponentMouseMovementBlockMode OnMouseRelativeMove(float x, float y) { return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK; }
|
||||
virtual bool OnMouseMove(float x, float y) { return false; }
|
||||
/**
|
||||
* Called on a input event.
|
||||
* @param e The input event.
|
||||
|
|
|
@ -701,14 +701,14 @@ void CGameConsole::OnRender()
|
|||
{
|
||||
m_MouseIsPress = true;
|
||||
Input()->NativeMousePos(&m_MousePressX, &m_MousePressY);
|
||||
m_MousePressX = (m_MousePressX / (float)Graphics()->WindowWidth()) * Screen.w;
|
||||
m_MousePressY = (m_MousePressY / (float)Graphics()->WindowHeight()) * Screen.h;
|
||||
m_MousePressX = (m_MousePressX / (float)Graphics()->ScreenWidth()) * Screen.w;
|
||||
m_MousePressY = (m_MousePressY / (float)Graphics()->ScreenHeight()) * Screen.h;
|
||||
}
|
||||
if(m_MouseIsPress)
|
||||
{
|
||||
Input()->NativeMousePos(&m_MouseCurX, &m_MouseCurY);
|
||||
m_MouseCurX = (m_MouseCurX / (float)Graphics()->WindowWidth()) * Screen.w;
|
||||
m_MouseCurY = (m_MouseCurY / (float)Graphics()->WindowHeight()) * Screen.h;
|
||||
m_MouseCurX = (m_MouseCurX / (float)Graphics()->ScreenWidth()) * Screen.w;
|
||||
m_MouseCurY = (m_MouseCurY / (float)Graphics()->ScreenHeight()) * Screen.h;
|
||||
}
|
||||
if(m_MouseIsPress && !Input()->NativeMousePressed(1))
|
||||
{
|
||||
|
@ -839,6 +839,7 @@ void CGameConsole::Toggle(int Type)
|
|||
|
||||
if(m_ConsoleState == CONSOLE_CLOSED || m_ConsoleState == CONSOLE_CLOSING)
|
||||
{
|
||||
/*Input()->MouseModeAbsolute();*/
|
||||
m_pClient->m_Menus.UseMouseButtons(false);
|
||||
m_ConsoleState = CONSOLE_OPENING;
|
||||
/*// reset controls
|
||||
|
@ -848,6 +849,7 @@ void CGameConsole::Toggle(int Type)
|
|||
}
|
||||
else
|
||||
{
|
||||
Input()->MouseModeRelative();
|
||||
m_pClient->m_Menus.UseMouseButtons(true);
|
||||
m_pClient->OnRelease();
|
||||
m_ConsoleState = CONSOLE_CLOSING;
|
||||
|
|
|
@ -109,8 +109,6 @@ class CGameConsole : public CComponent
|
|||
static void ConConsolePageDown(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConchainConsoleOutputLevelUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||
|
||||
EComponentMouseMovementBlockMode OnConsoleMouseFeedback() { return m_ConsoleState == CONSOLE_OPEN ? COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK : COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK; }
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
|
@ -131,10 +129,5 @@ public:
|
|||
virtual bool OnInput(IInput::CEvent Events);
|
||||
|
||||
bool IsClosed() { return m_ConsoleState == CONSOLE_CLOSED; }
|
||||
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowPos(int X, int Y) { return OnConsoleMouseFeedback(); }
|
||||
virtual EComponentMouseMovementBlockMode OnMouseAbsoluteInWindowPos(int X, int Y) { return OnConsoleMouseFeedback(); }
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowRelativeMove(int X, int Y) { return OnConsoleMouseFeedback(); }
|
||||
virtual EComponentMouseMovementBlockMode OnMouseRelativeMove(float RelX, float RelY) { return OnConsoleMouseFeedback(); }
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -534,50 +534,27 @@ void CControls::OnRender()
|
|||
m_TargetPos[g_Config.m_ClDummy] = m_MousePos[g_Config.m_ClDummy];
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CControls::OnMouseWrongStateImpl()
|
||||
bool CControls::OnMouseMove(float x, float y)
|
||||
{
|
||||
if((m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED))
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_RELATIVE;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CControls::OnMouseInWindowPos(int X, int Y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CControls::OnMouseAbsoluteInWindowPos(int X, int Y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CControls::OnMouseInWindowRelativeMove(int X, int Y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CControls::OnMouseRelativeMove(float RelX, float RelY)
|
||||
{
|
||||
if((m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED))
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
return false;
|
||||
|
||||
if(g_Config.m_ClDyncam && g_Config.m_ClDyncamMousesens)
|
||||
{
|
||||
RelX = RelX * g_Config.m_ClDyncamMousesens / g_Config.m_InpMousesens;
|
||||
RelY = RelY * g_Config.m_ClDyncamMousesens / g_Config.m_InpMousesens;
|
||||
x = x * g_Config.m_ClDyncamMousesens / g_Config.m_InpMousesens;
|
||||
y = y * g_Config.m_ClDyncamMousesens / g_Config.m_InpMousesens;
|
||||
}
|
||||
|
||||
if(m_pClient->m_Snap.m_SpecInfo.m_Active && m_pClient->m_Snap.m_SpecInfo.m_SpectatorID < 0)
|
||||
{
|
||||
RelX = RelX * m_pClient->m_Camera.m_Zoom;
|
||||
RelY = RelY * m_pClient->m_Camera.m_Zoom;
|
||||
x = x * m_pClient->m_Camera.m_Zoom;
|
||||
y = y * m_pClient->m_Camera.m_Zoom;
|
||||
}
|
||||
|
||||
m_MousePos[g_Config.m_ClDummy] += vec2(RelX, RelY); // TODO: ugly
|
||||
m_MousePos[g_Config.m_ClDummy] += vec2(x, y); // TODO: ugly
|
||||
ClampMousePos();
|
||||
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CControls::ClampMousePos()
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
class CControls : public CComponent
|
||||
{
|
||||
EComponentMouseMovementBlockMode OnMouseWrongStateImpl();
|
||||
|
||||
public:
|
||||
vec2 m_MousePos[NUM_DUMMIES];
|
||||
vec2 m_TargetPos[NUM_DUMMIES];
|
||||
|
@ -42,12 +40,7 @@ public:
|
|||
virtual void OnRelease();
|
||||
virtual void OnRender();
|
||||
virtual void OnMessage(int MsgType, void *pRawMsg);
|
||||
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseAbsoluteInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowRelativeMove(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseRelativeMove(float RelX, float RelY);
|
||||
|
||||
virtual bool OnMouseMove(float x, float y);
|
||||
virtual void OnConsoleInit();
|
||||
virtual void OnPlayerDeath();
|
||||
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
|
||||
#include "chat.h"
|
||||
#include "emoticon.h"
|
||||
|
||||
#include <game/client/component.h>
|
||||
|
||||
#include <game/client/animstate.h>
|
||||
#include <game/client/render.h>
|
||||
#include <game/client/ui.h>
|
||||
|
@ -54,39 +51,14 @@ void CEmoticon::OnRelease()
|
|||
m_Active = false;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CEmoticon::OnMouseWrongStateImpl()
|
||||
bool CEmoticon::OnMouseMove(float x, float y)
|
||||
{
|
||||
if(!m_Active)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME_RELATIVE;
|
||||
}
|
||||
return false;
|
||||
|
||||
EComponentMouseMovementBlockMode CEmoticon::OnMouseInWindowPos(int X, int Y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CEmoticon::OnMouseAbsoluteInWindowPos(int X, int Y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CEmoticon::OnMouseInWindowRelativeMove(int X, int Y)
|
||||
{
|
||||
if(!m_Active)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
|
||||
CUIRect *pScreen = UI()->Screen();
|
||||
float TmpX = (X / (float)Graphics()->WindowWidth()) * pScreen->w;
|
||||
float TmpY = (Y / (float)Graphics()->WindowHeight()) * pScreen->h;
|
||||
m_SelectorMouse += vec2(TmpX, TmpY);
|
||||
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CEmoticon::OnMouseRelativeMove(float x, float y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
UI()->ConvertMouseMove(&x, &y);
|
||||
m_SelectorMouse += vec2(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEmoticon::DrawCircle(float x, float y, float r, int Segments)
|
||||
|
|
|
@ -19,8 +19,6 @@ class CEmoticon : public CComponent
|
|||
static void ConKeyEmoticon(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConEmote(IConsole::IResult *pResult, void *pUserData);
|
||||
|
||||
EComponentMouseMovementBlockMode OnMouseWrongStateImpl();
|
||||
|
||||
public:
|
||||
CEmoticon();
|
||||
|
||||
|
@ -28,11 +26,7 @@ public:
|
|||
virtual void OnConsoleInit();
|
||||
virtual void OnRender();
|
||||
virtual void OnRelease();
|
||||
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseAbsoluteInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowRelativeMove(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseRelativeMove(float x, float y);
|
||||
virtual bool OnMouseMove(float x, float y);
|
||||
|
||||
void Emote(int Emote);
|
||||
void EyeEmote(int EyeEmote);
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
#include <game/localization.h>
|
||||
#include <mastersrv/mastersrv.h>
|
||||
|
||||
#include <game/client/component.h>
|
||||
|
||||
#include "controls.h"
|
||||
#include "countryflags.h"
|
||||
#include "menus.h"
|
||||
|
@ -656,7 +654,7 @@ float CMenus::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
|
|||
UI()->SetActiveItem(0);
|
||||
|
||||
if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT))
|
||||
SetMouseSlow(true);
|
||||
m_MouseSlow = true;
|
||||
|
||||
float Min = pRect->y;
|
||||
float Max = pRect->h - Handle.h;
|
||||
|
@ -714,7 +712,7 @@ float CMenus::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current,
|
|||
UI()->SetActiveItem(0);
|
||||
|
||||
if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT))
|
||||
SetMouseSlow(true);
|
||||
m_MouseSlow = true;
|
||||
|
||||
float Min = pRect->x;
|
||||
float Max = pRect->w - Handle.w;
|
||||
|
@ -1455,8 +1453,7 @@ int CMenus::Render()
|
|||
CUIRect Screen = *UI()->Screen();
|
||||
UI()->MapScreen();
|
||||
|
||||
if((!Input()->KeyIsPressed(KEY_LSHIFT) && !Input()->KeyIsPressed(KEY_RSHIFT)) || UI()->ActiveItem() == nullptr)
|
||||
SetMouseSlow(false);
|
||||
m_MouseSlow = false;
|
||||
|
||||
static int s_Frame = 0;
|
||||
if(s_Frame == 0)
|
||||
|
@ -2553,59 +2550,26 @@ void CMenus::OnReset()
|
|||
{
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CMenus::OnMouseInWindowPos(int X, int Y)
|
||||
bool CMenus::OnMouseMove(float x, float y)
|
||||
{
|
||||
if(!m_MenuActive)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
return false;
|
||||
|
||||
UI()->ConvertMouseMove(&x, &y);
|
||||
if(m_MouseSlow)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME_RELATIVE;
|
||||
else
|
||||
{
|
||||
m_MousePos.x = clamp<float>(X, 0.f, (float)Graphics()->WindowWidth());
|
||||
m_MousePos.y = clamp<float>(Y, 0.f, (float)Graphics()->WindowHeight());
|
||||
}
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CMenus::OnMouseAbsoluteInWindowPos(int X, int Y)
|
||||
{
|
||||
if(!m_MenuActive)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
|
||||
if(!m_MouseSlow)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME;
|
||||
else
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME_RELATIVE;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CMenus::OnMouseInWindowRelativeMove(int X, int Y)
|
||||
{
|
||||
if(!m_MenuActive)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
|
||||
if(!m_MouseSlow)
|
||||
{
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME;
|
||||
m_MousePos.x += x * 0.05f;
|
||||
m_MousePos.y += y * 0.05f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_MousePos.x = clamp<float>(m_MousePos.x + X * 0.05f, 0.f, (float)Graphics()->WindowWidth());
|
||||
m_MousePos.y = clamp<float>(m_MousePos.y + Y * 0.05f, 0.f, (float)Graphics()->WindowHeight());
|
||||
m_MousePos.x += x;
|
||||
m_MousePos.y += y;
|
||||
}
|
||||
m_MousePos.x = clamp(m_MousePos.x, 0.f, (float)Graphics()->ScreenWidth());
|
||||
m_MousePos.y = clamp(m_MousePos.y, 0.f, (float)Graphics()->ScreenHeight());
|
||||
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CMenus::OnMouseRelativeMove(float x, float y)
|
||||
{
|
||||
if(!m_MenuActive)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
|
||||
if(!m_MouseSlow)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME;
|
||||
else
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME_RELATIVE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMenus::OnInput(IInput::CEvent e)
|
||||
|
@ -2681,24 +2645,6 @@ void CMenus::OnStateChange(int NewState, int OldState)
|
|||
}
|
||||
}
|
||||
|
||||
void CMenus::SetMouseSlow(bool SetVal)
|
||||
{
|
||||
if(m_MouseSlow != SetVal)
|
||||
{
|
||||
m_MouseSlow = SetVal;
|
||||
if(SetVal)
|
||||
{
|
||||
Input()->MouseModeInGameRelative();
|
||||
}
|
||||
else
|
||||
{
|
||||
int CursorX = (int)m_MousePos.x;
|
||||
int CursorY = (int)m_MousePos.y;
|
||||
Input()->MouseModeInGame(&CursorX, &CursorY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMenus::OnRender()
|
||||
{
|
||||
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
||||
|
@ -2752,8 +2698,8 @@ void CMenus::OnRender()
|
|||
|
||||
// update the ui
|
||||
CUIRect *pScreen = UI()->Screen();
|
||||
float mx = (m_MousePos.x / (float)Graphics()->WindowWidth()) * pScreen->w;
|
||||
float my = (m_MousePos.y / (float)Graphics()->WindowHeight()) * pScreen->h;
|
||||
float mx = (m_MousePos.x / (float)Graphics()->ScreenWidth()) * pScreen->w;
|
||||
float my = (m_MousePos.y / (float)Graphics()->ScreenHeight()) * pScreen->h;
|
||||
|
||||
int Buttons = 0;
|
||||
if(m_UseMouseButtons)
|
||||
|
|
|
@ -289,8 +289,6 @@ protected:
|
|||
vec2 m_MousePos;
|
||||
bool m_MouseSlow;
|
||||
|
||||
void SetMouseSlow(bool SetVal);
|
||||
|
||||
char m_aNextServer[256];
|
||||
|
||||
// images
|
||||
|
@ -553,10 +551,7 @@ public:
|
|||
virtual void OnReset();
|
||||
virtual void OnRender();
|
||||
virtual bool OnInput(IInput::CEvent Event);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseAbsoluteInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowRelativeMove(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseRelativeMove(float x, float y);
|
||||
virtual bool OnMouseMove(float x, float y);
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -935,6 +935,19 @@ void CMenus::RenderSettingsControls(CUIRect MainView)
|
|||
MovementSettings.HSplitTop(20.0f, 0, &MovementSettings);
|
||||
}
|
||||
|
||||
{
|
||||
CUIRect Button, Label;
|
||||
MovementSettings.HSplitTop(20.0f, &Button, &MovementSettings);
|
||||
Button.VSplitLeft(160.0f, &Label, &Button);
|
||||
str_format(aBuf, sizeof(aBuf), "%s: %i", Localize("UI mouse s."), g_Config.m_UiMousesens);
|
||||
UI()->DoLabel(&Label, aBuf, 14.0f * UI()->Scale(), -1);
|
||||
Button.HMargin(2.0f, &Button);
|
||||
int NewValue = (int)(DoScrollbarH(&g_Config.m_UiMousesens, &Button, (minimum(g_Config.m_UiMousesens, 500) - 1) / 500.0f) * 500.0f) + 1;
|
||||
if(g_Config.m_UiMousesens < 500 || NewValue < 500)
|
||||
g_Config.m_UiMousesens = minimum(NewValue, 500);
|
||||
MovementSettings.HSplitTop(20.0f, 0, &MovementSettings);
|
||||
}
|
||||
|
||||
UiDoGetButtons(0, 15, MovementSettings, MainView);
|
||||
}
|
||||
|
||||
|
@ -2365,6 +2378,9 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView)
|
|||
{
|
||||
CUIRect Button, Left, Right, LeftLeft, Demo, Gameplay, Miscellaneous, Label, Background;
|
||||
|
||||
bool CheckSettings = false;
|
||||
static int s_InpMouseOld = g_Config.m_InpMouseOld;
|
||||
|
||||
MainView.HSplitTop(100.0f, &Demo, &MainView);
|
||||
|
||||
Demo.HSplitTop(30.0f, &Label, &Demo);
|
||||
|
@ -2561,8 +2577,12 @@ void CMenus::RenderSettingsDDNet(CUIRect MainView)
|
|||
if(DoButton_CheckBox(&g_Config.m_InpMouseOld, Localize("Old mouse mode"), g_Config.m_InpMouseOld, &Button))
|
||||
{
|
||||
g_Config.m_InpMouseOld ^= 1;
|
||||
CheckSettings = true;
|
||||
}
|
||||
|
||||
if(CheckSettings)
|
||||
m_NeedRestartDDNet = s_InpMouseOld != g_Config.m_InpMouseOld;
|
||||
|
||||
Left.HSplitTop(5.0f, &Button, &Left);
|
||||
Right.HSplitTop(25.0f, &Button, &Right);
|
||||
Left.VSplitRight(10.0f, &Left, 0x0);
|
||||
|
|
|
@ -138,6 +138,7 @@ void CMenus::RenderStartMenu(CUIRect MainView)
|
|||
if(DoButton_Menu(&s_MapEditorButton, Localize("Editor"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "editor" : 0, CUI::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_pClient->Editor()->HasUnsavedData() ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (!EditorHotkeyWasPressed && Client()->LocalTime() - EditorHotKeyChecktime < 0.1f && CheckHotKey(KEY_E)))
|
||||
{
|
||||
g_Config.m_ClEditor = 1;
|
||||
Input()->MouseModeRelative();
|
||||
EditorHotkeyWasPressed = true;
|
||||
}
|
||||
if(!Input()->KeyIsPressed(KEY_E))
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
#include <game/client/animstate.h>
|
||||
#include <game/client/render.h>
|
||||
|
||||
#include <game/client/component.h>
|
||||
|
||||
#include "camera.h"
|
||||
#include "spectator.h"
|
||||
|
||||
|
@ -155,6 +153,7 @@ void CSpectator::ConSpectateClosest(IConsole::IResult *pResult, void *pUserData)
|
|||
CSpectator::CSpectator()
|
||||
{
|
||||
OnReset();
|
||||
m_OldMouseX = m_OldMouseY = 0.0f;
|
||||
}
|
||||
|
||||
void CSpectator::OnConsoleInit()
|
||||
|
@ -166,41 +165,14 @@ void CSpectator::OnConsoleInit()
|
|||
Console()->Register("spectate_closest", "", CFGFLAG_CLIENT, ConSpectateClosest, this, "Spectate the closest player");
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CSpectator::OnMouseWrongStateImpl()
|
||||
bool CSpectator::OnMouseMove(float x, float y)
|
||||
{
|
||||
if(!m_Active)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
return false;
|
||||
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME_RELATIVE;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CSpectator::OnMouseInWindowPos(int X, int Y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CSpectator::OnMouseAbsoluteInWindowPos(int X, int Y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CSpectator::OnMouseInWindowRelativeMove(int X, int Y)
|
||||
{
|
||||
if(!m_Active)
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
|
||||
float Width = 400 * 3.0f * Graphics()->ScreenAspect();
|
||||
float Height = 400 * 3.0f;
|
||||
|
||||
float TmpX = (X / (float)Graphics()->WindowWidth()) * Width;
|
||||
float TmpY = (Y / (float)Graphics()->WindowHeight()) * Height;
|
||||
m_SelectorMouse += vec2(TmpX, TmpY);
|
||||
return COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK;
|
||||
}
|
||||
|
||||
EComponentMouseMovementBlockMode CSpectator::OnMouseRelativeMove(float x, float y)
|
||||
{
|
||||
return OnMouseWrongStateImpl();
|
||||
UI()->ConvertMouseMove(&x, &y);
|
||||
m_SelectorMouse += vec2(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSpectator::OnRelease()
|
||||
|
|
|
@ -19,6 +19,9 @@ class CSpectator : public CComponent
|
|||
int m_SelectedSpectatorID;
|
||||
vec2 m_SelectorMouse;
|
||||
|
||||
float m_OldMouseX;
|
||||
float m_OldMouseY;
|
||||
|
||||
bool CanChangeSpectator();
|
||||
void SpectateNext(bool Reverse);
|
||||
|
||||
|
@ -28,16 +31,11 @@ class CSpectator : public CComponent
|
|||
static void ConSpectatePrevious(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConSpectateClosest(IConsole::IResult *pResult, void *pUserData);
|
||||
|
||||
EComponentMouseMovementBlockMode OnMouseWrongStateImpl();
|
||||
|
||||
public:
|
||||
CSpectator();
|
||||
|
||||
virtual void OnConsoleInit();
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseAbsoluteInWindowPos(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseInWindowRelativeMove(int X, int Y);
|
||||
virtual EComponentMouseMovementBlockMode OnMouseRelativeMove(float x, float y);
|
||||
virtual bool OnMouseMove(float x, float y);
|
||||
virtual void OnRender();
|
||||
virtual void OnRelease();
|
||||
virtual void OnReset();
|
||||
|
|
|
@ -24,10 +24,6 @@
|
|||
#include <base/math.h>
|
||||
#include <base/vmath.h>
|
||||
|
||||
#include <engine/input.h>
|
||||
|
||||
#include <game/client/component.h>
|
||||
|
||||
#include "race.h"
|
||||
#include "render.h"
|
||||
#include <game/localization.h>
|
||||
|
@ -330,54 +326,13 @@ void CGameClient::OnUpdate()
|
|||
{
|
||||
// handle mouse movement
|
||||
float x = 0.0f, y = 0.0f;
|
||||
int PosX = 0, PosY = 0;
|
||||
bool GotInput = false;
|
||||
if(Input()->GetMouseMode() == INPUT_MOUSE_MODE_RELATIVE)
|
||||
{
|
||||
GotInput = Input()->MouseRelative(&x, &y);
|
||||
}
|
||||
else if(Input()->GetMouseMode() == INPUT_MOUSE_MODE_INGAME_RELATIVE)
|
||||
{
|
||||
GotInput = Input()->MouseDesktopRelative(&PosX, &PosY);
|
||||
}
|
||||
else
|
||||
{
|
||||
GotInput = Input()->MouseAbsolute(&PosX, &PosY);
|
||||
}
|
||||
if(GotInput)
|
||||
Input()->MouseRelative(&x, &y);
|
||||
if(x != 0.0f || y != 0.0f)
|
||||
{
|
||||
for(int h = 0; h < m_Input.m_Num; h++)
|
||||
{
|
||||
EComponentMouseMovementBlockMode CompBreak = COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK;
|
||||
if(Input()->GetMouseMode() == INPUT_MOUSE_MODE_RELATIVE)
|
||||
CompBreak = m_Input.m_paComponents[h]->OnMouseRelativeMove(x, y);
|
||||
else if(Input()->GetMouseMode() == INPUT_MOUSE_MODE_INGAME_RELATIVE)
|
||||
CompBreak = m_Input.m_paComponents[h]->OnMouseInWindowRelativeMove(PosX, PosY);
|
||||
else if(Input()->GetMouseMode() == INPUT_MOUSE_MODE_INGAME)
|
||||
CompBreak = m_Input.m_paComponents[h]->OnMouseInWindowPos(PosX, PosY);
|
||||
else if(Input()->GetMouseMode() == INPUT_MOUSE_MODE_ABSOLUTE)
|
||||
CompBreak = m_Input.m_paComponents[h]->OnMouseAbsoluteInWindowPos(PosX, PosY);
|
||||
if(CompBreak != COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_DONT_BLOCK)
|
||||
{
|
||||
switch(CompBreak)
|
||||
{
|
||||
case COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME:
|
||||
Input()->MouseModeInGame();
|
||||
if(m_Input.m_paComponents[h]->OnMouseMove(x, y))
|
||||
break;
|
||||
case COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_INGAME_RELATIVE:
|
||||
Input()->MouseModeInGameRelative();
|
||||
break;
|
||||
case COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_RELATIVE:
|
||||
Input()->MouseModeRelative();
|
||||
break;
|
||||
case COMPONENT_MOUSE_MOVEMENT_BLOCK_MODE_BLOCK_AND_CHANGE_TO_ABSOLUTE:
|
||||
Input()->MouseModeAbsolute();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,6 +142,13 @@ int CUI::MouseInside(const CUIRect *r) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
void CUI::ConvertMouseMove(float *x, float *y) const
|
||||
{
|
||||
float Fac = (float)(g_Config.m_UiMousesens) / g_Config.m_InpMousesens;
|
||||
*x = *x * Fac;
|
||||
*y = *y * Fac;
|
||||
}
|
||||
|
||||
CUIRect *CUI::Screen()
|
||||
{
|
||||
float Aspect = Graphics()->ScreenAspect();
|
||||
|
|
|
@ -257,6 +257,7 @@ public:
|
|||
const void *LastActiveItem() const { return m_pLastActiveItem; }
|
||||
|
||||
int MouseInside(const CUIRect *pRect) const;
|
||||
void ConvertMouseMove(float *x, float *y) const;
|
||||
|
||||
CUIRect *Screen();
|
||||
void MapScreen();
|
||||
|
|
|
@ -634,7 +634,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
|
|||
{
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
UI()->SetActiveItem(0);
|
||||
s_TextMode = false;
|
||||
}
|
||||
|
@ -656,14 +656,14 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
|
|||
Current = clamp(str_toint_base(s_aNumStr, 16), Min, Max);
|
||||
else
|
||||
Current = clamp(str_toint(s_aNumStr), Min, Max);
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
UI()->SetActiveItem(0);
|
||||
s_TextMode = false;
|
||||
}
|
||||
|
||||
if(Input()->KeyIsPressed(KEY_ESCAPE))
|
||||
{
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
UI()->SetActiveItem(0);
|
||||
s_TextMode = false;
|
||||
}
|
||||
|
@ -700,7 +700,7 @@ int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, in
|
|||
{
|
||||
if(UI()->MouseButton(0))
|
||||
{
|
||||
SetLockMouse(true);
|
||||
m_LockMouse = true;
|
||||
s_Value = 0;
|
||||
UI()->SetActiveItem(pID);
|
||||
}
|
||||
|
@ -1378,7 +1378,7 @@ void CEditor::DoSoundSource(CSoundSource *pSource, int Index)
|
|||
|
||||
static int s_SourcePopupID = 0;
|
||||
UiInvokePopupMenu(&s_SourcePopupID, 0, UI()->MouseX(), UI()->MouseY(), 120, 200, PopupSource);
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
}
|
||||
s_Operation = OP_NONE;
|
||||
UI()->SetActiveItem(0);
|
||||
|
@ -1393,7 +1393,7 @@ void CEditor::DoSoundSource(CSoundSource *pSource, int Index)
|
|||
m_Map.m_UndoModified++;
|
||||
}
|
||||
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
s_Operation = OP_NONE;
|
||||
UI()->SetActiveItem(0);
|
||||
}
|
||||
|
@ -1583,7 +1583,7 @@ void CEditor::DoQuad(CQuad *q, int Index)
|
|||
|
||||
static int s_QuadPopupID = 0;
|
||||
UiInvokePopupMenu(&s_QuadPopupID, 0, UI()->MouseX(), UI()->MouseY(), 120, 180, PopupQuad);
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
}
|
||||
s_Operation = OP_NONE;
|
||||
UI()->SetActiveItem(0);
|
||||
|
@ -1596,7 +1596,7 @@ void CEditor::DoQuad(CQuad *q, int Index)
|
|||
if(m_lSelectedLayers.size() == 1)
|
||||
{
|
||||
m_Map.m_UndoModified++;
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
m_Map.m_Modified = true;
|
||||
DeleteSelectedQuads();
|
||||
}
|
||||
|
@ -1613,7 +1613,7 @@ void CEditor::DoQuad(CQuad *q, int Index)
|
|||
m_Map.m_UndoModified++;
|
||||
}
|
||||
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
s_Operation = OP_NONE;
|
||||
UI()->SetActiveItem(0);
|
||||
}
|
||||
|
@ -1638,7 +1638,7 @@ void CEditor::DoQuad(CQuad *q, int Index)
|
|||
}
|
||||
else if(Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL))
|
||||
{
|
||||
SetLockMouse(true);
|
||||
m_LockMouse = true;
|
||||
s_Operation = OP_ROTATE;
|
||||
s_RotateAngle = 0;
|
||||
|
||||
|
@ -1852,7 +1852,7 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
|
|||
if(s_Operation == OP_MOVEPOINT || s_Operation == OP_MOVEUV)
|
||||
m_Map.m_UndoModified++;
|
||||
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
UI()->SetActiveItem(0);
|
||||
}
|
||||
}
|
||||
|
@ -1873,7 +1873,7 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
|
|||
if(Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT))
|
||||
{
|
||||
s_Operation = OP_MOVEUV;
|
||||
SetLockMouse(true);
|
||||
m_LockMouse = true;
|
||||
}
|
||||
else
|
||||
s_Operation = OP_MOVEPOINT;
|
||||
|
@ -2101,7 +2101,7 @@ void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex)
|
|||
|
||||
if(!UI()->MouseButton(0))
|
||||
{
|
||||
SetLockMouse(false);
|
||||
m_LockMouse = false;
|
||||
s_Operation = OP_NONE;
|
||||
UI()->SetActiveItem(0);
|
||||
}
|
||||
|
@ -2119,7 +2119,7 @@ void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex)
|
|||
{
|
||||
if(Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL))
|
||||
{
|
||||
SetLockMouse(true);
|
||||
m_LockMouse = true;
|
||||
s_Operation = OP_ROTATE;
|
||||
|
||||
SelectQuad(QIndex);
|
||||
|
@ -6199,18 +6199,6 @@ void CEditorMap::CreateDefault(IGraphics::CTextureHandle EntitiesTexture)
|
|||
m_pTuneLayer = 0x0;
|
||||
}
|
||||
|
||||
void CEditor::SetLockMouse(bool SetVal)
|
||||
{
|
||||
if(m_LockMouse != SetVal)
|
||||
{
|
||||
m_LockMouse = SetVal;
|
||||
if(SetVal)
|
||||
Input()->MouseModeInGameRelative();
|
||||
else
|
||||
Input()->MouseModeInGame();
|
||||
}
|
||||
}
|
||||
|
||||
void CEditor::Init()
|
||||
{
|
||||
m_pInput = Kernel()->RequestInterface<IInput>();
|
||||
|
@ -6305,49 +6293,40 @@ void CEditor::CreateUndoStepThread(void *pUser)
|
|||
|
||||
void CEditor::UpdateAndRender()
|
||||
{
|
||||
static float s_MouseX = 0.0f;
|
||||
static float s_MouseY = 0.0f;
|
||||
|
||||
if(m_Animate)
|
||||
m_AnimateTime = (time_get() - m_AnimateStart) / (float)time_freq();
|
||||
else
|
||||
m_AnimateTime = 0;
|
||||
ms_pUiGotContext = 0;
|
||||
|
||||
float mx = 0, my = 0, Mwx = 0, Mwy = 0;
|
||||
int rx = 0, ry = 0;
|
||||
if(m_LockMouse)
|
||||
{
|
||||
// use relative mouse movement when locked
|
||||
Input()->MouseModeInGameRelative();
|
||||
int TmpDeltaX = 0;
|
||||
int TmpDeltaY = 0;
|
||||
Input()->MouseDesktopRelative(&TmpDeltaX, &TmpDeltaY);
|
||||
m_MouseDeltaX = TmpDeltaX;
|
||||
m_MouseDeltaY = TmpDeltaY;
|
||||
rx = m_LastX;
|
||||
ry = m_LastY;
|
||||
}
|
||||
else
|
||||
{
|
||||
// use desktop mouse movement when not locked
|
||||
Input()->MouseModeInGame();
|
||||
bool GotInput = Input()->MouseAbsolute(&rx, &ry);
|
||||
if(!GotInput)
|
||||
{
|
||||
rx = m_LastX;
|
||||
ry = m_LastY;
|
||||
}
|
||||
|
||||
m_MouseDeltaX = rx - m_LastX;
|
||||
m_MouseDeltaY = ry - m_LastY;
|
||||
|
||||
m_LastX = rx;
|
||||
m_LastY = ry;
|
||||
}
|
||||
|
||||
// handle mouse movement
|
||||
float mx, my, Mwx, Mwy;
|
||||
float rx = 0, ry = 0;
|
||||
{
|
||||
Input()->MouseRelative(&rx, &ry);
|
||||
UI()->ConvertMouseMove(&rx, &ry);
|
||||
|
||||
// TODO: Why do we have to halve this?
|
||||
rx /= 2;
|
||||
ry /= 2;
|
||||
|
||||
m_MouseDeltaX = rx;
|
||||
m_MouseDeltaY = ry;
|
||||
|
||||
if(!m_LockMouse)
|
||||
{
|
||||
s_MouseX = clamp(s_MouseX + rx, 0.0f, UI()->Screen()->w);
|
||||
s_MouseY = clamp(s_MouseY + ry, 0.0f, UI()->Screen()->h);
|
||||
}
|
||||
|
||||
// update the ui
|
||||
mx = UI()->Screen()->w * ((float)rx / Graphics()->WindowWidth());
|
||||
my = UI()->Screen()->h * ((float)ry / Graphics()->WindowHeight());
|
||||
mx = s_MouseX;
|
||||
my = s_MouseY;
|
||||
Mwx = 0;
|
||||
Mwy = 0;
|
||||
|
||||
// fix correct world x and y
|
||||
CLayerGroup *g = GetSelectedGroup();
|
||||
|
@ -6359,11 +6338,10 @@ void CEditor::UpdateAndRender()
|
|||
float WorldWidth = aPoints[2] - aPoints[0];
|
||||
float WorldHeight = aPoints[3] - aPoints[1];
|
||||
|
||||
Mwx = aPoints[0] + WorldWidth * ((float)rx / Graphics()->WindowWidth());
|
||||
Mwy = aPoints[1] + WorldHeight * ((float)ry / Graphics()->WindowHeight());
|
||||
|
||||
m_MouseDeltaWx = m_MouseDeltaX * (WorldWidth / Graphics()->ScreenWidth());
|
||||
m_MouseDeltaWy = m_MouseDeltaY * (WorldHeight / Graphics()->ScreenHeight());
|
||||
Mwx = aPoints[0] + WorldWidth * (s_MouseX / UI()->Screen()->w);
|
||||
Mwy = aPoints[1] + WorldHeight * (s_MouseY / UI()->Screen()->h);
|
||||
m_MouseDeltaWx = m_MouseDeltaX * (WorldWidth / UI()->Screen()->w);
|
||||
m_MouseDeltaWy = m_MouseDeltaY * (WorldHeight / UI()->Screen()->h);
|
||||
}
|
||||
|
||||
int Buttons = 0;
|
||||
|
|
|
@ -642,8 +642,6 @@ class CEditor : public IEditor
|
|||
CUI m_UI;
|
||||
CUIEx m_UIEx;
|
||||
|
||||
void SetLockMouse(bool SetVal);
|
||||
|
||||
public:
|
||||
class IInput *Input() { return m_pInput; };
|
||||
class IClient *Client() { return m_pClient; };
|
||||
|
@ -910,9 +908,6 @@ public:
|
|||
float m_MouseDeltaWx;
|
||||
float m_MouseDeltaWy;
|
||||
|
||||
int m_LastX = 0;
|
||||
int m_LastY = 0;
|
||||
|
||||
bool m_ShowTileInfo;
|
||||
bool m_ShowDetail;
|
||||
bool m_Animate;
|
||||
|
|
|
@ -111,6 +111,7 @@ MACRO_CONFIG_INT(UiSettingsPage, ui_settings_page, 0, 0, 9, CFGFLAG_CLIENT | CFG
|
|||
MACRO_CONFIG_INT(UiToolboxPage, ui_toolbox_page, 0, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Toolbox page")
|
||||
MACRO_CONFIG_STR(UiServerAddress, ui_server_address, 64, "localhost:8303", CFGFLAG_CLIENT | CFGFLAG_SAVE, "Interface server address")
|
||||
MACRO_CONFIG_INT(UiScale, ui_scale, 100, 50, 150, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Interface scale")
|
||||
MACRO_CONFIG_INT(UiMousesens, ui_mousesens, 200, 1, 100000, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Mouse sensitivity for menus/editor")
|
||||
|
||||
MACRO_CONFIG_COL(UiColor, ui_color, 0xE4A046AF, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_COLALPHA, "Interface color") // 160 70 175 228 hasalpha
|
||||
|
||||
|
|
Loading…
Reference in a new issue