Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Generals/Code/GameEngine/Include/Common/UserPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//-----------------------------------------------------------------------------
#include "Common/STLTypedefs.h"

enum CursorCaptureMode CPP_11(: Int);
typedef UnsignedInt CursorCaptureMode;
typedef UnsignedInt ScreenEdgeScrollMode;

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -95,6 +95,10 @@ class OptionPreferences : public UserPreferences
Real getScrollFactor(void); // convenience function
Bool getDrawScrollAnchor(void);
Bool getMoveScrollAnchor(void);
Bool getCursorCaptureEnabledInWindowedGame() const;
Bool getCursorCaptureEnabledInWindowedMenu() const;
Bool getCursorCaptureEnabledInFullscreenGame() const;
Bool getCursorCaptureEnabledInFullscreenMenu() const;
CursorCaptureMode getCursorCaptureMode() const;
Bool getScreenEdgeScrollEnabledInWindowedApp() const;
Bool getScreenEdgeScrollEnabledInFullscreenApp() const;
Expand Down
22 changes: 11 additions & 11 deletions Generals/Code/GameEngine/Include/GameClient/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,20 @@ class CursorInfo
Int numDirections; //number of directions for cursors like scrolling/panning.
};

enum CursorCaptureMode CPP_11(: Int)
typedef UnsignedInt CursorCaptureMode;
enum CursorCaptureMode_ CPP_11(: CursorCaptureMode)
{
CursorCaptureMode_None, // Does not capture the cursor
CursorCaptureMode_InGame, // Captures the cursor when playing and observing
CursorCaptureMode_Always, // Captures the cursor always in menus and game
CursorCaptureMode_Auto, // Applies mode "InGame" when Windowed, "Always" when Fullscreen

CursorCaptureMode_Count,
CursorCaptureMode_Default = CursorCaptureMode_Auto,
CursorCaptureMode_EnabledInWindowedGame = 1<<0, // Captures the cursor when in game while the app is windowed
CursorCaptureMode_EnabledInWindowedMenu = 1<<1, // Captures the cursor when in menu while the app is windowed
CursorCaptureMode_EnabledInFullscreenGame = 1<<2, // Captures the cursor when in game while the app is fullscreen
CursorCaptureMode_EnabledInFullscreenMenu = 1<<3, // Captures the cursor when in menu while the app is fullscreen

CursorCaptureMode_Default =
CursorCaptureMode_EnabledInWindowedGame |
CursorCaptureMode_EnabledInFullscreenGame |
CursorCaptureMode_EnabledInFullscreenMenu,
};

extern const char* const TheCursorCaptureModeNames[];

// Mouse ----------------------------------------------------------------------
// Class interface for working with a mouse pointing device
//
Expand All @@ -170,7 +171,6 @@ class Mouse : public SubsystemInterface
enum CursorCaptureBlockReason
{
CursorCaptureBlockReason_NoInit,
CursorCaptureBlockReason_NoGame,
CursorCaptureBlockReason_Paused,
CursorCaptureBlockReason_Unfocused,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,21 +372,61 @@ Bool OptionPreferences::getMoveScrollAnchor(void)
return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInWindowedGame() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInWindowedGame");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInWindowedGame) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInWindowedMenu() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInWindowedMenu");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInWindowedMenu) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInFullscreenGame() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInFullscreenGame");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInFullscreenGame) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInFullscreenMenu() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInFullscreenMenu");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInFullscreenMenu) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

CursorCaptureMode OptionPreferences::getCursorCaptureMode() const
{
CursorCaptureMode mode = CursorCaptureMode_Default;
OptionPreferences::const_iterator it = find("CursorCaptureMode");
if (it != end())
{
for (Int i = 0; i < CursorCaptureMode_Count; ++i)
{
if (stricmp(it->second.str(), TheCursorCaptureModeNames[i]) == 0)
{
mode = static_cast<CursorCaptureMode>(i);
break;
}
}
}
CursorCaptureMode mode = 0;
mode |= getCursorCaptureEnabledInWindowedGame() ? CursorCaptureMode_EnabledInWindowedGame : 0;
mode |= getCursorCaptureEnabledInWindowedMenu() ? CursorCaptureMode_EnabledInWindowedMenu : 0;
mode |= getCursorCaptureEnabledInFullscreenGame() ? CursorCaptureMode_EnabledInFullscreenGame : 0;
mode |= getCursorCaptureEnabledInFullscreenMenu() ? CursorCaptureMode_EnabledInFullscreenMenu : 0;
return mode;
}

Expand Down Expand Up @@ -1233,7 +1273,10 @@ static void saveOptions( void )
// TheSuperHackers @todo Add combo box ?
{
CursorCaptureMode mode = pref->getCursorCaptureMode();
(*pref)["CursorCaptureMode"] = TheCursorCaptureModeNames[mode];
(*pref)["CursorCaptureEnabledInWindowedGame"] = (mode & CursorCaptureMode_EnabledInWindowedGame) ? "yes" : "no";
(*pref)["CursorCaptureEnabledInWindowedMenu"] = (mode & CursorCaptureMode_EnabledInWindowedMenu) ? "yes" : "no";
(*pref)["CursorCaptureEnabledInFullscreenGame"] = (mode & CursorCaptureMode_EnabledInFullscreenGame) ? "yes" : "no";
(*pref)["CursorCaptureEnabledInFullscreenMenu"] = (mode & CursorCaptureMode_EnabledInFullscreenMenu) ? "yes" : "no";
TheMouse->setCursorCaptureMode(mode);
}

Expand Down
68 changes: 33 additions & 35 deletions Generals/Code/GameEngine/Source/GameClient/Input/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@
// PUBLIC DATA ////////////////////////////////////////////////////////////////////////////////////
Mouse *TheMouse = NULL;

const char* const TheCursorCaptureModeNames[] = {
"None",
"InGame",
"Always",
"Auto",
};
static_assert(ARRAY_SIZE(TheCursorCaptureModeNames) == CursorCaptureMode_Count, "Incorrect array size");

const char *const Mouse::RedrawModeName[] = {
"Mouse:Windows",
"Mouse:W3D",
Expand All @@ -70,7 +62,6 @@ const char *const Mouse::RedrawModeName[] = {

const char *const Mouse::CursorCaptureBlockReasonNames[] = {
"CursorCaptureBlockReason_NoInit",
"CursorCaptureBlockReason_NoGame",
"CursorCaptureBlockReason_Paused",
"CursorCaptureBlockReason_Unfocused",
};
Expand Down Expand Up @@ -552,8 +543,8 @@ Mouse::Mouse( void )

m_cursorCaptureMode = CursorCaptureMode_Default;

m_captureBlockReasonBits = (1 << CursorCaptureBlockReason_NoInit) | (1 << CursorCaptureBlockReason_NoGame);
DEBUG_LOG(("Mouse::Mouse: m_blockCaptureReason=CursorCaptureBlockReason_NoInit|CursorCaptureBlockReason_NoGame"));
m_captureBlockReasonBits = (1 << CursorCaptureBlockReason_NoInit);
DEBUG_LOG(("Mouse::Mouse: m_blockCaptureReason=CursorCaptureBlockReason_NoInit"));

}

Expand Down Expand Up @@ -653,17 +644,7 @@ void Mouse::mouseNotifyResolutionChange( void )
//-------------------------------------------------------------------------------------------------
void Mouse::onGameModeChanged(GameMode prev, GameMode next)
{
const Bool wasInteractiveGame = GameLogic::isInInteractiveGame(prev);
const Bool isInteractiveGame = GameLogic::isInInteractiveGame(next);

if (wasInteractiveGame && !isInteractiveGame)
{
blockCapture(CursorCaptureBlockReason_NoGame);
}
else if (!wasInteractiveGame && isInteractiveGame)
{
unblockCapture(CursorCaptureBlockReason_NoGame);
}
refreshCursorCapture();
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1072,23 +1053,40 @@ void Mouse::initCapture()
// ------------------------------------------------------------------------------------------------
Bool Mouse::canCapture() const
{
constexpr const CursorCaptureBlockReasonInt noGameBits = CursorCaptureBlockReason_NoGame | CursorCaptureBlockReason_Paused;
if (m_captureBlockReasonBits != 0)
return false;

DEBUG_ASSERTCRASH(TheDisplay != NULL, ("The Display is NULL"));
const Bool inInteractiveGame = TheGameLogic && TheGameLogic->isInInteractiveGame();

switch (m_cursorCaptureMode)
if (TheDisplay->getWindowed())
{
case CursorCaptureMode_None:
return false;
case CursorCaptureMode_InGame:
return (m_captureBlockReasonBits == 0);
case CursorCaptureMode_Always:
return (m_captureBlockReasonBits & ~noGameBits) == 0;
case CursorCaptureMode_Auto:
default:
if (TheDisplay == NULL || TheDisplay->getWindowed())
return (m_captureBlockReasonBits == 0);
if (inInteractiveGame)
{
if ((m_cursorCaptureMode & CursorCaptureMode_EnabledInWindowedGame) == 0)
return false;
}
else
return (m_captureBlockReasonBits & ~noGameBits) == 0;
{
if ((m_cursorCaptureMode & CursorCaptureMode_EnabledInWindowedMenu) == 0)
return false;
}
}
else
{
if (inInteractiveGame)
{
if ((m_cursorCaptureMode & CursorCaptureMode_EnabledInFullscreenGame) == 0)
return false;
}
else
{
if ((m_cursorCaptureMode & CursorCaptureMode_EnabledInFullscreenMenu) == 0)
return false;
}
}

return true;
}

// ------------------------------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "Common/STLTypedefs.h"

class Money;
enum CursorCaptureMode CPP_11(: Int);
typedef UnsignedInt CursorCaptureMode;
typedef UnsignedInt ScreenEdgeScrollMode;

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -98,6 +98,10 @@ class OptionPreferences : public UserPreferences
Real getScrollFactor(void); // convenience function
Bool getDrawScrollAnchor(void);
Bool getMoveScrollAnchor(void);
Bool getCursorCaptureEnabledInWindowedGame() const;
Bool getCursorCaptureEnabledInWindowedMenu() const;
Bool getCursorCaptureEnabledInFullscreenGame() const;
Bool getCursorCaptureEnabledInFullscreenMenu() const;
CursorCaptureMode getCursorCaptureMode() const;
Bool getScreenEdgeScrollEnabledInWindowedApp() const;
Bool getScreenEdgeScrollEnabledInFullscreenApp() const;
Expand Down
22 changes: 11 additions & 11 deletions GeneralsMD/Code/GameEngine/Include/GameClient/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,20 @@ class CursorInfo
Int numDirections; //number of directions for cursors like scrolling/panning.
};

enum CursorCaptureMode CPP_11(: Int)
typedef UnsignedInt CursorCaptureMode;
enum CursorCaptureMode_ CPP_11(: CursorCaptureMode)
{
CursorCaptureMode_None, // Does not capture the cursor
CursorCaptureMode_InGame, // Captures the cursor when playing and observing
CursorCaptureMode_Always, // Captures the cursor always in menus and game
CursorCaptureMode_Auto, // Applies mode "InGame" when Windowed, "Always" when Fullscreen

CursorCaptureMode_Count,
CursorCaptureMode_Default = CursorCaptureMode_Auto,
CursorCaptureMode_EnabledInWindowedGame = 1<<0, // Captures the cursor when in game while the app is windowed
CursorCaptureMode_EnabledInWindowedMenu = 1<<1, // Captures the cursor when in menu while the app is windowed
CursorCaptureMode_EnabledInFullscreenGame = 1<<2, // Captures the cursor when in game while the app is fullscreen
CursorCaptureMode_EnabledInFullscreenMenu = 1<<3, // Captures the cursor when in menu while the app is fullscreen

CursorCaptureMode_Default =
CursorCaptureMode_EnabledInWindowedGame |
CursorCaptureMode_EnabledInFullscreenGame |
CursorCaptureMode_EnabledInFullscreenMenu,
};

extern const char* const TheCursorCaptureModeNames[];

// Mouse ----------------------------------------------------------------------
// Class interface for working with a mouse pointing device
//
Expand All @@ -170,7 +171,6 @@ class Mouse : public SubsystemInterface
enum CursorCaptureBlockReason
{
CursorCaptureBlockReason_NoInit,
CursorCaptureBlockReason_NoGame,
CursorCaptureBlockReason_Paused,
CursorCaptureBlockReason_Unfocused,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,61 @@ Bool OptionPreferences::getMoveScrollAnchor(void)
return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInWindowedGame() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInWindowedGame");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInWindowedGame) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInWindowedMenu() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInWindowedMenu");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInWindowedMenu) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInFullscreenGame() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInFullscreenGame");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInFullscreenGame) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

Bool OptionPreferences::getCursorCaptureEnabledInFullscreenMenu() const
{
OptionPreferences::const_iterator it = find("CursorCaptureEnabledInFullscreenMenu");
if (it == end())
return (CursorCaptureMode_Default & CursorCaptureMode_EnabledInFullscreenMenu) != 0;

if (stricmp(it->second.str(), "yes") == 0)
return TRUE;

return FALSE;
}

CursorCaptureMode OptionPreferences::getCursorCaptureMode() const
{
CursorCaptureMode mode = CursorCaptureMode_Default;
OptionPreferences::const_iterator it = find("CursorCaptureMode");
if (it != end())
{
for (Int i = 0; i < CursorCaptureMode_Count; ++i)
{
if (stricmp(it->second.str(), TheCursorCaptureModeNames[i]) == 0)
{
mode = static_cast<CursorCaptureMode>(i);
break;
}
}
}
CursorCaptureMode mode = 0;
mode |= getCursorCaptureEnabledInWindowedGame() ? CursorCaptureMode_EnabledInWindowedGame : 0;
mode |= getCursorCaptureEnabledInWindowedMenu() ? CursorCaptureMode_EnabledInWindowedMenu : 0;
mode |= getCursorCaptureEnabledInFullscreenGame() ? CursorCaptureMode_EnabledInFullscreenGame : 0;
mode |= getCursorCaptureEnabledInFullscreenMenu() ? CursorCaptureMode_EnabledInFullscreenMenu : 0;
return mode;
}

Expand Down Expand Up @@ -1293,7 +1333,10 @@ static void saveOptions( void )
// TheSuperHackers @todo Add combo box ?
{
CursorCaptureMode mode = pref->getCursorCaptureMode();
(*pref)["CursorCaptureMode"] = TheCursorCaptureModeNames[mode];
(*pref)["CursorCaptureEnabledInWindowedGame"] = (mode & CursorCaptureMode_EnabledInWindowedGame) ? "yes" : "no";
(*pref)["CursorCaptureEnabledInWindowedMenu"] = (mode & CursorCaptureMode_EnabledInWindowedMenu) ? "yes" : "no";
(*pref)["CursorCaptureEnabledInFullscreenGame"] = (mode & CursorCaptureMode_EnabledInFullscreenGame) ? "yes" : "no";
(*pref)["CursorCaptureEnabledInFullscreenMenu"] = (mode & CursorCaptureMode_EnabledInFullscreenMenu) ? "yes" : "no";
TheMouse->setCursorCaptureMode(mode);
}

Expand Down
Loading
Loading