Skip to content

Commit decd66c

Browse files
committed
Replicate in Generals
1 parent 20a1acd commit decd66c

File tree

4 files changed

+98
-9
lines changed

4 files changed

+98
-9
lines changed

Generals/Code/GameEngine/Include/Common/UserPreferences.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "Common/STLTypedefs.h"
4040

4141
enum CursorCaptureMode CPP_11(: Int);
42+
typedef UnsignedInt ScreenEdgeScrollMode;
4243

4344
//-----------------------------------------------------------------------------
4445
// PUBLIC TYPES ///////////////////////////////////////////////////////////////
@@ -95,6 +96,9 @@ class OptionPreferences : public UserPreferences
9596
Bool getDrawScrollAnchor(void);
9697
Bool getMoveScrollAnchor(void);
9798
CursorCaptureMode getCursorCaptureMode() const;
99+
Bool getScreenEdgeScrollEnabledInWindowedApp() const;
100+
Bool getScreenEdgeScrollEnabledInFullscreenApp() const;
101+
ScreenEdgeScrollMode getScreenEdgeScrollMode() const;
98102
Bool getSendDelay(void); // convenience function
99103
Int getFirewallBehavior(void); // convenience function
100104
Short getFirewallPortAllocationDelta(void); // convenience function

Generals/Code/GameEngine/Include/GameClient/LookAtXlat.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,28 @@
3232

3333
#include "GameClient/InGameUI.h"
3434

35+
//-----------------------------------------------------------------------------
36+
typedef UnsignedInt ScreenEdgeScrollMode;
37+
enum ScreenEdgeScrollMode_ CPP_11(: ScreenEdgeScrollMode)
38+
{
39+
ScreenEdgeScrollMode_EnabledInWindowedApp = 1<<0, // Scroll when touching the edge while the app is windowed
40+
ScreenEdgeScrollMode_EnabledInFullscreenApp = 1<<1, // Scroll when touching the edge while the app is fullscreen
41+
42+
ScreenEdgeScrollMode_Default = ScreenEdgeScrollMode_EnabledInFullscreenApp,
43+
};
44+
3545
//-----------------------------------------------------------------------------
3646
class LookAtTranslator : public GameMessageTranslator
3747
{
3848
public:
3949
LookAtTranslator();
4050
~LookAtTranslator();
51+
4152
virtual GameMessageDisposition translateGameMessage(const GameMessage *msg);
4253
virtual const ICoord2D* getRMBScrollAnchor(void); // get m_anchor ICoord2D if we're RMB scrolling
4354
Bool hasMouseMovedRecently( void );
4455
void setCurrentPos( const ICoord2D& pos );
56+
void setScreenEdgeScrollMode(ScreenEdgeScrollMode mode);
4557

4658
void resetModes(); //Used when disabling input, so when we reenable it we aren't stuck in a mode.
4759

@@ -50,7 +62,7 @@ class LookAtTranslator : public GameMessageTranslator
5062
{
5163
MAX_VIEW_LOCS = 8
5264
};
53-
enum
65+
enum ScrollType
5466
{
5567
SCROLL_NONE = 0,
5668
SCROLL_RMB,
@@ -67,10 +79,13 @@ class LookAtTranslator : public GameMessageTranslator
6779
UnsignedInt m_timestamp; // set when button goes down
6880
DrawableID m_lastPlaneID;
6981
ViewLocation m_viewLocation[ MAX_VIEW_LOCS ];
70-
Int m_scrollType;
71-
void setScrolling( Int );
72-
void stopScrolling( void );
82+
ScrollType m_scrollType;
83+
ScreenEdgeScrollMode m_screenEdgeScrollMode;
7384
UnsignedInt m_lastMouseMoveFrame;
85+
86+
void setScrolling( ScrollType scrollType );
87+
void stopScrolling( void );
88+
Bool canScrollAtScreenEdge() const;
7489
};
7590

7691
extern LookAtTranslator *TheLookAtTranslator;

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "GameClient/ClientInstance.h"
4545
#include "GameClient/GameClient.h"
4646
#include "GameClient/InGameUI.h"
47+
#include "GameClient/LookAtXlat.h"
4748
#include "GameClient/WindowLayout.h"
4849
#include "GameClient/Gadget.h"
4950
#include "GameClient/GadgetCheckBox.h"
@@ -390,6 +391,38 @@ CursorCaptureMode OptionPreferences::getCursorCaptureMode() const
390391
return mode;
391392
}
392393

394+
Bool OptionPreferences::getScreenEdgeScrollEnabledInWindowedApp() const
395+
{
396+
OptionPreferences::const_iterator it = find("ScreenEdgeScrollEnabledInWindowedApp");
397+
if (it == end())
398+
return (ScreenEdgeScrollMode_Default & ScreenEdgeScrollMode_EnabledInWindowedApp) != 0;
399+
400+
if (stricmp(it->second.str(), "yes") == 0)
401+
return TRUE;
402+
403+
return FALSE;
404+
}
405+
406+
Bool OptionPreferences::getScreenEdgeScrollEnabledInFullscreenApp() const
407+
{
408+
OptionPreferences::const_iterator it = find("ScreenEdgeScrollEnabledInFullscreenApp");
409+
if (it == end())
410+
return (ScreenEdgeScrollMode_Default & ScreenEdgeScrollMode_EnabledInFullscreenApp) != 0;
411+
412+
if (stricmp(it->second.str(), "yes") == 0)
413+
return TRUE;
414+
415+
return FALSE;
416+
}
417+
418+
ScreenEdgeScrollMode OptionPreferences::getScreenEdgeScrollMode() const
419+
{
420+
ScreenEdgeScrollMode mode = 0;
421+
mode |= getScreenEdgeScrollEnabledInWindowedApp() ? ScreenEdgeScrollMode_EnabledInWindowedApp : 0;
422+
mode |= getScreenEdgeScrollEnabledInFullscreenApp() ? ScreenEdgeScrollMode_EnabledInFullscreenApp : 0;
423+
return mode;
424+
}
425+
393426
Bool OptionPreferences::usesSystemMapDir(void)
394427
{
395428
OptionPreferences::const_iterator it = find("UseSystemMapDir");
@@ -1191,6 +1224,14 @@ static void saveOptions( void )
11911224
TheMouse->setCursorCaptureMode(mode);
11921225
}
11931226

1227+
// TheSuperHackers @todo Add combo box ?
1228+
{
1229+
ScreenEdgeScrollMode mode = pref->getScreenEdgeScrollMode();
1230+
(*pref)["ScreenEdgeScrollEnabledInWindowedApp"] = (mode & ScreenEdgeScrollMode_EnabledInWindowedApp) ? "yes" : "no";
1231+
(*pref)["ScreenEdgeScrollEnabledInFullscreenApp"] = (mode & ScreenEdgeScrollMode_EnabledInFullscreenApp) ? "yes" : "no";
1232+
TheLookAtTranslator->setScreenEdgeScrollMode(mode);
1233+
}
1234+
11941235
//-------------------------------------------------------------------------------------------------
11951236
// scroll speed val
11961237
val = GadgetSliderGetPosition(sliderScrollSpeed);

Generals/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "Common/PlayerList.h"
3636
#include "Common/Recorder.h"
3737
#include "Common/StatsCollector.h"
38+
#include "Common/UserPreferences.h"
3839
#include "GameLogic/Object.h"
3940
#include "GameLogic/PartitionManager.h"
4041
#include "GameClient/Display.h"
@@ -80,7 +81,7 @@ static const Int edgeScrollSize = 3;
8081
static Mouse::MouseCursor prevCursor = Mouse::ARROW;
8182

8283
//-----------------------------------------------------------------------------
83-
void LookAtTranslator::setScrolling(Int x)
84+
void LookAtTranslator::setScrolling(ScrollType scrollType)
8485
{
8586
if (!TheInGameUI->getInputEnabled())
8687
return;
@@ -89,7 +90,7 @@ void LookAtTranslator::setScrolling(Int x)
8990
m_isScrolling = true;
9091
TheInGameUI->setScrolling( TRUE );
9192
TheTacticalView->setMouseLock( TRUE );
92-
m_scrollType = x;
93+
m_scrollType = scrollType;
9394
if(TheStatsCollector)
9495
TheStatsCollector->startScrollTime();
9596
}
@@ -103,12 +104,32 @@ void LookAtTranslator::stopScrolling( void )
103104
TheMouse->setCursor(prevCursor);
104105
m_scrollType = SCROLL_NONE;
105106

106-
// if we have a stats collectore increment the stats
107+
// increment the stats if we have a stats collector
107108
if(TheStatsCollector)
108109
TheStatsCollector->endScrollTime();
109110

110111
}
111112

113+
//-----------------------------------------------------------------------------
114+
Bool LookAtTranslator::canScrollAtScreenEdge() const
115+
{
116+
if (!TheMouse->isCursorCaptured())
117+
return false;
118+
119+
if (TheDisplay->getWindowed())
120+
{
121+
if ((m_screenEdgeScrollMode & ScreenEdgeScrollMode_EnabledInWindowedApp) == 0)
122+
return false;
123+
}
124+
else
125+
{
126+
if ((m_screenEdgeScrollMode & ScreenEdgeScrollMode_EnabledInFullscreenApp) == 0)
127+
return false;
128+
}
129+
130+
return true;
131+
}
132+
112133
//-----------------------------------------------------------------------------
113134
LookAtTranslator::LookAtTranslator() :
114135
m_isScrolling(false),
@@ -121,12 +142,15 @@ LookAtTranslator::LookAtTranslator() :
121142
m_scrollType(SCROLL_NONE)
122143
{
123144
//Added By Sadullah Nader
124-
//Initializations misssing and needed
145+
//Initializations missing and needed
125146
m_anchor.x = m_anchor.y = 0;
126147
m_currentPos.x = m_currentPos.y = 0;
127148
m_originalAnchor.x = m_originalAnchor.y = 0;
128149
//
129150

151+
OptionPreferences prefs;
152+
m_screenEdgeScrollMode = prefs.getScreenEdgeScrollMode();
153+
130154
DEBUG_ASSERTCRASH(!TheLookAtTranslator, ("Already have a LookAtTranslator - why do you need two?"));
131155
TheLookAtTranslator = this;
132156
}
@@ -163,6 +187,11 @@ void LookAtTranslator::setCurrentPos( const ICoord2D& pos )
163187
m_currentPos = pos;
164188
}
165189

190+
void LookAtTranslator::setScreenEdgeScrollMode(ScreenEdgeScrollMode mode)
191+
{
192+
m_screenEdgeScrollMode = mode;
193+
}
194+
166195
//-----------------------------------------------------------------------------
167196
/**
168197
* The LookAt Translator is responsible for camera movements. It is directly responsible for
@@ -309,7 +338,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
309338
}
310339

311340
// TheSuperHackers @tweak Ayumi/xezon 26/07/2025 Enables edge scrolling in windowed mode.
312-
if (TheMouse->isCursorCaptured())
341+
if (canScrollAtScreenEdge())
313342
{
314343
if (m_isScrolling)
315344
{

0 commit comments

Comments
 (0)