Skip to content

Commit

Permalink
Encapsulated g_Mouse in CInputManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Paxxi committed Mar 2, 2015
1 parent d43c6c4 commit 80d6110
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 48 deletions.
5 changes: 2 additions & 3 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,7 @@ bool CApplication::Create()

// Create the Mouse, Keyboard, Remote, and Joystick devices
// Initialize after loading settings to get joystick deadzone setting
g_Mouse.Initialize();
g_Mouse.SetEnabled(CSettings::Get().GetBool("input.enablemouse"));


CInputManager::Get().InitializeInputs();

Expand Down Expand Up @@ -2097,7 +2096,7 @@ bool CApplication::OnAction(const CAction &action)
}

if (action.IsMouse())
g_Mouse.SetActive(true);
CInputManager::Get().SetMouseActive(true);


if (action.GetID() == ACTION_CREATE_EPISODE_BOOKMARK)
Expand Down
1 change: 0 additions & 1 deletion xbmc/SystemGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

CGUITextureManager g_TextureManager;
CGUILargeTextureManager g_largeTextureManager;
CMouseStat g_Mouse;

CGUIPassword g_passwordManager;
CGUIInfoManager g_infoManager;
Expand Down
5 changes: 3 additions & 2 deletions xbmc/guilib/GUIControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "GUIWindowManager.h"
#include "GUIControlProfiler.h"
#include "input/MouseStat.h"
#include "input/InputManager.h"
#include "Key.h"

using namespace std;
Expand Down Expand Up @@ -547,8 +548,8 @@ EVENT_RESULT CGUIControl::SendMouseEvent(const CPoint &point, const CMouseEvent
// override this function to implement custom mouse behaviour
bool CGUIControl::OnMouseOver(const CPoint &point)
{
if (g_Mouse.GetState() != MOUSE_STATE_DRAG)
g_Mouse.SetState(MOUSE_STATE_FOCUS);
if (CInputManager::Get().GetMouseState() != MOUSE_STATE_DRAG)
CInputManager::Get().SetMouseState(MOUSE_STATE_FOCUS);
if (!CanFocus()) return false;
if (!HasFocus())
{
Expand Down
4 changes: 2 additions & 2 deletions xbmc/guilib/GraphicContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "cores/VideoRenderers/RenderManager.h"
#include "windowing/WindowingFactory.h"
#include "TextureManager.h"
#include "input/MouseStat.h"
#include "input/InputManager.h"
#include "GUIWindowManager.h"
#include "utils/JobManager.h"
#include "video/VideoReferenceClock.h"
Expand Down Expand Up @@ -489,7 +489,7 @@ void CGraphicContext::SetVideoResolutionInternal(RESOLUTION res, bool forceUpdat

// update anyone that relies on sizing information
g_renderManager.Recover();
g_Mouse.SetResolution(info_org.iWidth, info_org.iHeight, 1, 1);
CInputManager::Get().SetMouseResolution(info_org.iWidth, info_org.iHeight, 1, 1);
g_windowManager.SendMessage(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_WINDOW_RESIZE);

Unlock();
Expand Down
70 changes: 54 additions & 16 deletions xbmc/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
#include "input/SDLJoystick.h"
#endif
#include "ButtonTranslator.h"
#include "input/MouseStat.h"
#include "peripherals/Peripherals.h"
#include "XBMC_vkeys.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "Util.h"
#include "settings/Settings.h"

#ifdef HAS_PERFORMANCE_SAMPLE
#include "utils/PerformanceSample.h"
Expand Down Expand Up @@ -89,6 +89,9 @@ void CInputManager::InitializeInputs()
#endif

m_Keyboard.Initialize();

m_Mouse.Initialize();
m_Mouse.SetEnabled(CSettings::Get().GetBool("input.enablemouse"));
}

void CInputManager::ReInitializeJoystick()
Expand Down Expand Up @@ -140,7 +143,7 @@ bool CInputManager::ProcessGamepad(int windowId)
if (CButtonTranslator::GetInstance().TranslateJoystickString(windowId, joyName, keymapId, JACTIVE_BUTTON, actionID, actionName, fullrange))
{
CAction action(actionID, 1.0f, 0.0f, actionName);
g_Mouse.SetActive(false);
m_Mouse.SetActive(false);
return ExecuteInputAction(action);
}
}
Expand All @@ -165,7 +168,7 @@ bool CInputManager::ProcessGamepad(int windowId)

float amount = m_Joystick.GetAmount(joyName, joyId);
CAction action(actionID, fullrange ? (amount + 1.0f) / 2.0f : fabs(amount), 0.0f, actionName);
g_Mouse.SetActive(false);
m_Mouse.SetActive(false);
return ExecuteInputAction(action);
}
}
Expand All @@ -192,7 +195,7 @@ bool CInputManager::ProcessGamepad(int windowId)
if (keymapId && CButtonTranslator::GetInstance().TranslateJoystickString(windowId, joyName, keymapId, JACTIVE_HAT, actionID, actionName, fullrange))
{
CAction action(actionID, 1.0f, 0.0f, actionName);
g_Mouse.SetActive(false);
m_Mouse.SetActive(false);
return ExecuteInputAction(action);
}
}
Expand Down Expand Up @@ -225,11 +228,11 @@ bool CInputManager::ProcessMouse(int windowId)
{
MEASURE_FUNCTION;

if (!g_Mouse.IsActive() || !g_application.IsAppFocused())
if (!m_Mouse.IsActive() || !g_application.IsAppFocused())
return false;

// Get the mouse command ID
uint32_t mousekey = g_Mouse.GetKey();
uint32_t mousekey = m_Mouse.GetKey();
if (mousekey == KEY_MOUSE_NOOP)
return true;

Expand All @@ -246,7 +249,7 @@ bool CInputManager::ProcessMouse(int windowId)

// Deactivate mouse if non-mouse action
if (!mouseaction.IsMouse())
g_Mouse.SetActive(false);
m_Mouse.SetActive(false);

// Consume ACTION_NOOP.
// Some views or dialogs gets closed after any ACTION and
Expand Down Expand Up @@ -274,11 +277,11 @@ bool CInputManager::ProcessMouse(int windowId)

// This is a mouse action so we need to record the mouse position
return g_application.OnAction(CAction(mouseaction.GetID(),
g_Mouse.GetHold(MOUSE_LEFT_BUTTON),
(float)g_Mouse.GetX(),
(float)g_Mouse.GetY(),
(float)g_Mouse.GetDX(),
(float)g_Mouse.GetDY(),
m_Mouse.GetHold(MOUSE_LEFT_BUTTON),
(float)m_Mouse.GetX(),
(float)m_Mouse.GetY(),
(float)m_Mouse.GetDX(),
(float)m_Mouse.GetDY(),
mouseaction.GetName()));
}

Expand Down Expand Up @@ -372,7 +375,7 @@ bool CInputManager::ProcessEventServer(int windowId, float frameTime)

{
CPoint pos;
if (es->GetMousePos(pos.x, pos.y) && g_Mouse.IsEnabled())
if (es->GetMousePos(pos.x, pos.y) && m_Mouse.IsEnabled())
{
XBMC_Event newEvent;
newEvent.type = XBMC_MOUSEMOTION;
Expand All @@ -399,7 +402,7 @@ bool CInputManager::ProcessJoystickEvent(int windowId, const std::string& joysti
if (g_application.WakeUpScreenSaverAndDPMS())
return true;

g_Mouse.SetActive(false);
m_Mouse.SetActive(false);

int actionID;
std::string actionName;
Expand Down Expand Up @@ -428,7 +431,7 @@ bool CInputManager::OnEvent(XBMC_Event& newEvent)
case XBMC_MOUSEBUTTONDOWN:
case XBMC_MOUSEBUTTONUP:
case XBMC_MOUSEMOTION:
g_Mouse.HandleEvent(newEvent);
m_Mouse.HandleEvent(newEvent);
ProcessMouse(g_windowManager.GetActiveWindowID());
break;
case XBMC_TOUCH:
Expand Down Expand Up @@ -477,7 +480,7 @@ bool CInputManager::OnKey(const CKey& key)
{

// Turn the mouse off, as we've just got a keypress from controller or remote
g_Mouse.SetActive(false);
m_Mouse.SetActive(false);

// get the current active window
int iWin = g_windowManager.GetActiveWindowID();
Expand Down Expand Up @@ -662,3 +665,38 @@ bool CInputManager::ExecuteInputAction(const CAction &action)
}
return bResult;
}

void CInputManager::SetMouseActive(bool active /* = true */)
{
m_Mouse.SetActive(active);
}

void CInputManager::SetMouseEnabled(bool mouseEnabled /* = true */)
{
m_Mouse.SetEnabled(mouseEnabled);
}

bool CInputManager::IsMouseActive()
{
return m_Mouse.IsActive();
}

MOUSE_STATE CInputManager::GetMouseState()
{
return m_Mouse.GetState();
}

MousePosition CInputManager::GetMousePosition()
{
return m_Mouse.GetPosition();
}

void CInputManager::SetMouseResolution(int maxX, int maxY, float speedX, float speedY)
{
m_Mouse.SetResolution(maxX, maxY, speedX, speedY);
}

void CInputManager::SetMouseState(MOUSE_STATE mouseState)
{
m_Mouse.SetState(mouseState);
}
51 changes: 51 additions & 0 deletions xbmc/input/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "windowing/XBMC_events.h"
#include "guilib/Key.h"
#include "input/KeyboardStat.h"
#include "input/MouseStat.h"

class CInputManager
{
Expand Down Expand Up @@ -114,6 +115,55 @@ class CInputManager
*/
bool OnEvent(XBMC_Event& newEvent);

/*! \brief Control if the mouse is actively used or not
*
* \param[in] active sets mouse active or inactive
*/
void SetMouseActive(bool active = true);

/*! \brief Control if we should use a mouse or not
*
* \param[in] mouseEnabled sets mouse enabled or disabled
*/
void SetMouseEnabled(bool mouseEnabled = true);

/*! \brief Set the current state of the mouse such as click, drag operation
*
* \param[in] mouseState which state the mouse should be set to
* \sa MOUSE_STATE
*/
void SetMouseState(MOUSE_STATE mouseState);

/*! \brief Check if the mouse is currently active
*
* \return true if active, false otherwise
*/
bool IsMouseActive();

/*! \brief Get the current state of the mouse, such as click or drag operation
*
* \return the current state of the mouse as a value from MOUSE_STATE
* \sa MOUSE_STATE
*/
MOUSE_STATE GetMouseState();

/*! \brief Get the current mouse positions x and y coordinates
*
* \return a struct containing the x and y coordinates
* \sa MousePosition
*/
MousePosition GetMousePosition();

/*! \brief Set the current screen resolution and pointer speed
*
* \param[in] maxX screen width
* \param[in] maxY screen height
* \param[in] speedX mouse speed in x dimension
* \param[in] speedY mouse speed in y dimension
* \return
*/
void SetMouseResolution(int maxX, int maxY, float speedX, float speedY);

private:

/*! \brief Process keyboard event and translate into an action
Expand Down Expand Up @@ -143,6 +193,7 @@ class CInputManager
bool ExecuteInputAction(const CAction &action);

CKeyboardStat m_Keyboard;
CMouseStat m_Mouse;

#ifdef HAS_EVENT_SERVER
std::map<std::string, std::map<int, float> > m_lastAxisMap;
Expand Down
17 changes: 14 additions & 3 deletions xbmc/input/MouseStat.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@

#define MOUSE_MAX_BUTTON 5

enum MOUSE_STATE { MOUSE_STATE_NORMAL = 1, MOUSE_STATE_FOCUS, MOUSE_STATE_DRAG, MOUSE_STATE_CLICK };
enum MOUSE_STATE
{
MOUSE_STATE_NORMAL = 1, /*! < Normal state */
MOUSE_STATE_FOCUS, /*! < Control below the mouse is currently in focus */
MOUSE_STATE_DRAG, /*! < A drag operation is being performed */
MOUSE_STATE_CLICK /*! < A mousebutton is being clicked */
};
enum MOUSE_BUTTON { MOUSE_LEFT_BUTTON = 0, MOUSE_RIGHT_BUTTON, MOUSE_MIDDLE_BUTTON, MOUSE_EXTRA_BUTTON1, MOUSE_EXTRA_BUTTON2 };

// this holds everything we know about the current state of the mouse
Expand All @@ -59,6 +65,12 @@ struct MouseState
bool active; // true if the mouse is active
};

struct MousePosition
{
int x;
int y;
};

class CAction;

class CMouseStat : public ISettingCallback
Expand Down Expand Up @@ -86,6 +98,7 @@ class CMouseStat : public ISettingCallback
inline int GetY(void) const { return m_mouseState.y; }
inline int GetDX(void) const { return m_mouseState.dx; }
inline int GetDY(void) const { return m_mouseState.dy; }
MousePosition GetPosition() { return MousePosition{ m_mouseState.x, m_mouseState.y }; }

private:
/*! \brief Holds information regarding a particular mouse button state
Expand Down Expand Up @@ -175,8 +188,6 @@ class CMouseStat : public ISettingCallback
uint32_t m_Key;
};

extern CMouseStat g_Mouse;

#endif


Expand Down
7 changes: 4 additions & 3 deletions xbmc/music/dialogs/GUIDialogMusicOSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "GUIDialogMusicOSD.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/Key.h"
#include "input/MouseStat.h"
#include "input/InputManager.h"
#include "GUIUserMessages.h"
#include "settings/Settings.h"
#include "addons/GUIWindowAddonBrowser.h"
Expand Down Expand Up @@ -88,8 +88,9 @@ void CGUIDialogMusicOSD::FrameMove()
if (m_autoClosing)
{
// check for movement of mouse or a submenu open
if (g_Mouse.IsActive() || g_windowManager.IsWindowActive(WINDOW_DIALOG_VIS_SETTINGS)
|| g_windowManager.IsWindowActive(WINDOW_DIALOG_VIS_PRESET_LIST))
if (CInputManager::Get().IsMouseActive() ||
g_windowManager.IsWindowActive(WINDOW_DIALOG_VIS_SETTINGS) ||
g_windowManager.IsWindowActive(WINDOW_DIALOG_VIS_PRESET_LIST))
// extend show time by original value
SetAutoClose(m_showDuration);
}
Expand Down
3 changes: 2 additions & 1 deletion xbmc/music/dialogs/GUIDialogMusicOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "guilib/GUIWindowManager.h"
#include "guilib/Key.h"
#include "input/MouseStat.h"
#include "input/InputManager.h"

#define CONTROL_LOGO_PIC 1

Expand Down Expand Up @@ -58,7 +59,7 @@ EVENT_RESULT CGUIDialogMusicOverlay::OnMouseEvent(const CPoint &point, const CMo
if (pControl && pControl->HitTest(point))
{
// send highlight message
g_Mouse.SetState(MOUSE_STATE_FOCUS);
CInputManager::Get().SetMouseState(MOUSE_STATE_FOCUS);
if (event.m_id == ACTION_MOUSE_LEFT_CLICK)
{ // send mouse message
CGUIMessage message(GUI_MSG_FULLSCREEN, CONTROL_LOGO_PIC, GetID());
Expand Down
Loading

0 comments on commit 80d6110

Please sign in to comment.