Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): one scale for the HUD, and a bar that leaves

Olcay Seygan43d7c96bb36d
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 32aeecf7e..c8b9c4501 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -888,11 +888,29 @@ public:
/// the whole panel, art included - this is what blocks a click from reaching the world
const IRegion2D *getPanelRect( Int which ) const { return &m_panelRect[ which ]; }
+ /** Where ControlBarParent stood when layoutPanels last ran. Everything the panels hold is a
+ * child of that window and travels with it - the minimise stage drops it a tenth of the
+ * screen, the intro slides it up from below - but the plate art is drawn from the design
+ * rectangles rather than from a window, so it has to be told by how much. Draw offset is
+ * the frame's screen position now, minus this. */
+ const ICoord2D *getPanelOrigin( void ) const { return &m_panelOrigin; }
+
/** Re-anchor the three panels at one uniform scale. Idempotent, and safe to call again after
* something else has moved a window - ControlBarScheme::init does, every time a scheme is
* set - because it remembers both the authored rectangle and the one it last handed out. */
void layoutPanels( void );
+ /** Send one whole panel off the bottom of the screen, or bring it back. It slides: the panel is
+ * a picture of a thing, and a thing that is going away should be seen going. 'immediate' puts
+ * it where it is going this instant, which is what a rebuild wants. */
+ void showPanel( Int panel, Bool show, Bool immediate = FALSE );
+
+ /// is that panel all the way off screen? the plate art asks before it paints
+ Bool isPanelHidden( Int panel ) const { return m_panelHidden[ panel ]; }
+
+ /// how far down that panel has slid, in pixels - the plate art travels with its windows
+ Int getPanelSlideOffset( Int panel ) const;
+
protected:
/// place one window and its descendants inside 'panel'; see layoutPanels
void placeInPanel( GameWindow *win, Int panel,
@@ -1038,6 +1056,14 @@ protected:
ControlBarStages m_currentControlBarStage;
IRegion2D m_panelRect[ CB_PANEL_COUNT ]; ///< screen rect of each panel, filled by layoutPanels()
+ ICoord2D m_panelOrigin; ///< where the frame was put, so the plates can follow it
+ Bool m_panelHidden[ CB_PANEL_COUNT ]; ///< minimised: the radar and the middle stand down
+ Real m_panelSlide[ CB_PANEL_COUNT ]; ///< 0 home, 1 clear of the bottom edge
+ Real m_panelSlideTo[ CB_PANEL_COUNT ]; ///< where each one is heading
+ UnsignedInt m_panelSlideMs; ///< wall clock of the last slide step
+
+ void updatePanelSlide( void ); ///< step the slide and put the windows where it says
+ void applyPanelSlide( void ); ///< the placing half of it, on its own so a rebuild can call it
Bool m_UIDirty; ///< the context UI must be re-evaluated
@@ -1247,6 +1273,11 @@ private:
Bool m_genStarFlash;
+
+ /** Is the promotion screen open? Not the same question as "is its window hidden": the fade it
+ * opens with drives that window's hidden flag itself, several frames either way, so the window
+ * answers no while the screen is opening and yes for a frame after it was told to close. */
+ Bool m_purchaseScienceOpen;
Int m_lastFlashedAtPointValue;
ICoord2D m_controlBarForegroundMarkerPos;
@@ -1301,6 +1332,27 @@ extern Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,
Int displayWidth, Int displayHeight,
IRegion2D *rectOut );
+/** The one scale the whole HUD is drawn at: the display over the 800x600 everything was authored
+ * at, the smaller of the two axes so nothing is distorted. The .wnd loader multiplies x and y
+ * separately, which on a 16:9 screen is a 1.33x horizontal smear; anything that wants to sit
+ * beside the command bar without being smeared measures itself with this instead. Never below
+ * 1 - nothing shrinks under 800 wide. */
+extern Real ControlBarUniformScale( void );
+extern Real ControlBarUniformScaleFor( Int displayWidth, Int displayHeight ); ///< ...for a screen you name
+
+/** Undo the .wnd loader's separate-axis stretch over a whole layout: every window under 'root' is
+ * recovered to its authored 800x600 rectangle and put back at ControlBarUniformScale(), anchored
+ * at the given fraction of the screen (0 = left/top edge, 1 = right/bottom, 0.5 = centred) with
+ * the matching fraction of the design space as its fixed point. This is layoutPanels for a
+ * layout that is one piece rather than three: the generals' power bar hangs off the right edge
+ * with (1,1) and the science screen is centred at the top with (0.5,0).
+ *
+ * Call it once, on a layout straight out of winCreateLayout. It reads the authored rectangle
+ * back out of where the loader put each window, so a second call would divide a scale out that
+ * is no longer there. layoutPanels is the idempotent one, and it is idempotent because the
+ * scheme rewrites the command bar's windows behind it; nothing rewrites these. */
+extern void ControlBarLayoutUniform( GameWindow *root, Real anchorFracX, Real anchorFracY );
+
//-------------------------------------------------------------------------------------------------
/** Logic frames as the whole seconds they will really take at the current logic rate, rounded up
* and never down to zero. Defined in ControlBarCommand.cpp; every countdown and build time the
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
index e6e234c79..33e0c05c6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
@@ -438,6 +438,7 @@ typedef struct _PushButtonData
Int drawCount; ///< when > 0, a small number badge drawn in the bottom right corner
Int drawSeconds; ///< when > 0, a seconds label drawn in the bottom left corner
Int drawCost; ///< when > 0, a price drawn in the top right corner
+ Int drawPower; ///< when != 0, a power figure in the bottom right; < 0 draws, > 0 supplies
Int barPercent; ///< when >= 0, a thin bar drawn along the bottom edge (experience)
Color barColor; ///< colour of that bar
void *userData; ///< random additional data we can set
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
index 5b0902a3a..3f0efddd3 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
@@ -85,6 +85,7 @@ void GadgetButtonSetBorder( GameWindow *g, Color color, Bool drawBorder = TRUE )
void GadgetButtonSetCount( GameWindow *g, Int count );
void GadgetButtonSetSeconds( GameWindow *g, Int seconds );
void GadgetButtonSetCost( GameWindow *g, Int cost );
+void GadgetButtonSetPower( GameWindow *g, Int power );
void GadgetButtonSetBar( GameWindow *g, Int percent, Color color );
void GadgetButtonSetData(GameWindow *g, void *data);
void *GadgetButtonGetData(GameWindow *g);
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index 79587ac4a..31883775b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -134,10 +134,11 @@ const OptionDef TheOptionCatalog[] =
// Fullscreen, borderless or windowed. The old Windowed flag in GameData.ini seeds this and is
// then derived back from it, so the device layer keeps reading the boolean it always read.
- // APPLY_RESTART is not laziness: the window style is settled by CreateWindow in WinMain, which
- // runs before the engine exists and reads this key itself through EarlyOptions.h.
+ // The window's style at startup is still settled by CreateWindow in WinMain, which runs before
+ // the engine exists and reads this key itself through EarlyOptions.h; changing it while the game
+ // is up restyles that window and rebuilds the device (W3DDisplay::setDisplayMode).
{ "WindowMode", OPT_WND( "ComboBoxWindowMode" ), "GUI:WindowMode",
- OPTION_ENUM, APPLY_RESTART, 0, WINDOW_MODE_COUNT - 1,
+ OPTION_ENUM, APPLY_DEVICE_RESET, 0, WINDOW_MODE_COUNT - 1,
get_m_windowMode, set_m_windowMode },
// Multisampling, as an index into 0/2/4/8/16 rather than a sample count - the device offers
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 0f2f8cac8..48a519d9d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -1098,6 +1098,7 @@ ControlBar::ControlBar( void )
m_currContext = CB_CONTEXT_NONE;
m_defaultControlBarPosition.x = m_defaultControlBarPosition.y = 0;
m_genStarFlash = FALSE;
+ m_purchaseScienceOpen = FALSE;
m_genStarOff = NULL;
m_genStarOn = NULL;
m_UIDirty = FALSE;
@@ -1111,7 +1112,12 @@ ControlBar::ControlBar( void )
{
m_panelRect[ i ].lo.x = m_panelRect[ i ].lo.y = 0;
m_panelRect[ i ].hi.x = m_panelRect[ i ].hi.y = 0;
+ m_panelHidden[ i ] = FALSE;
+ m_panelSlide[ i ] = 0.0f;
+ m_panelSlideTo[ i ] = 0.0f;
}
+ m_panelSlideMs = 0;
+ m_panelOrigin.x = m_panelOrigin.y = 0;
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
{
m_commandWindows[ i ] = NULL;
@@ -1324,6 +1330,106 @@ static const Real thePanelAnchorFraction[ ControlBar::CB_PANEL_COUNT ] = { 0.0f,
/// ...and which authored x that anchor is, so at 4:3 the three plates reassemble the shipped bar
static const Real thePanelAnchorDesignX[ ControlBar::CB_PANEL_COUNT ] = { 0.0f, 400.0f, 800.0f };
+//-------------------------------------------------------------------------------------------------
+/** One scale for both axes, the smaller of the two, so nothing anywhere in the HUD is distorted.
+ * Everything that used to work this out for itself now asks here. */
+//-------------------------------------------------------------------------------------------------
+Real ControlBarUniformScaleFor( Int displayWidth, Int displayHeight )
+{
+ if( displayWidth <= 0 || displayHeight <= 0 )
+ return 1.0f;
+
+ const Real loadScaleX = (Real)displayWidth / CONTROL_BAR_DESIGN_W;
+ const Real loadScaleY = (Real)displayHeight / CONTROL_BAR_DESIGN_H;
+ const Real s = loadScaleX < loadScaleY ? loadScaleX : loadScaleY;
+
+ return s < 1.0f ? 1.0f : s;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real ControlBarUniformScale( void )
+{
+ if( TheDisplay == NULL )
+ return 1.0f;
+
+ return ControlBarUniformScaleFor( TheDisplay->getWidth(), TheDisplay->getHeight() );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** One window of a layout being taken out of the loader's stretched space, and everything under it.
+ * Positions are relative to the parent, so both the parent's old and its new screen origin travel
+ * down the recursion - the same walk placeInPanel does, without the panels and the plate art. */
+//-------------------------------------------------------------------------------------------------
+static void layoutUniformWindow( GameWindow *win, Real originX, Real originY, Real s,
+ Real loadScaleX, Real loadScaleY,
+ Int oldParentX, Int oldParentY,
+ Int newParentX, Int newParentY )
+{
+ ICoord2D rel, size;
+ win->winGetPosition( &rel.x, &rel.y );
+ win->winGetSize( &size.x, &size.y );
+
+ const Int oldX = oldParentX + rel.x;
+ const Int oldY = oldParentY + rel.y;
+
+ // what the window was authored at, recovered by dividing the loader's own two scales back out
+ const Real designX = oldX / loadScaleX;
+ const Real designY = oldY / loadScaleY;
+ const Real designW = size.x / loadScaleX;
+ const Real designH = size.y / loadScaleY;
+
+ const Int newX = REAL_TO_INT_FLOOR( originX + designX * s );
+ const Int newY = REAL_TO_INT_FLOOR( originY + designY * s );
+
+ win->winSetPosition( newX - newParentX, newY - newParentY );
+ win->winSetSize( REAL_TO_INT_CEIL( designW * s ), REAL_TO_INT_CEIL( designH * s ) );
+
+ for( GameWindow *child = win->winGetChild(); child; child = child->winGetNext() )
+ layoutUniformWindow( child, originX, originY, s, loadScaleX, loadScaleY,
+ oldX, oldY, newX, newY );
+}
+
+//-------------------------------------------------------------------------------------------------
+void ControlBarLayoutUniform( GameWindow *root, Real anchorFracX, Real anchorFracY )
+{
+ if( root == NULL || TheDisplay == NULL )
+ return;
+
+ const Real dispW = (Real)TheDisplay->getWidth();
+ const Real dispH = (Real)TheDisplay->getHeight();
+ if( dispW <= 0.0f || dispH <= 0.0f )
+ return;
+
+ // what the loader already multiplied every coordinate by, so it can be divided back out
+ const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;
+ const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;
+ const Real s = ControlBarUniformScale();
+
+ //
+ // The anchor is a point that does not move: the same fraction of the screen and of the design
+ // space. (1,1) keeps the bottom right corner where it was however wide the screen is, which is
+ // what a bar hanging off the right edge above the command bar wants.
+ //
+ const Real originX = dispW * anchorFracX - CONTROL_BAR_DESIGN_W * anchorFracX * s;
+ const Real originY = dispH * anchorFracY - CONTROL_BAR_DESIGN_H * anchorFracY * s;
+
+ ICoord2D rootOrigin;
+ root->winGetScreenPosition( &rootOrigin.x, &rootOrigin.y );
+
+ //
+ // The root's own position is already absolute, so its "parent" is the screen at both ends of the
+ // walk - what it was, and what it becomes, are both the origin.
+ //
+ GameWindow *parent = root->winGetParent();
+ ICoord2D parentPos;
+ parentPos.x = parentPos.y = 0;
+ if( parent )
+ parent->winGetScreenPosition( &parentPos.x, &parentPos.y );
+
+ layoutUniformWindow( root, originX, originY, s, loadScaleX, loadScaleY,
+ parentPos.x, parentPos.y, parentPos.x, parentPos.y );
+}
+
//-------------------------------------------------------------------------------------------------
Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,
Int displayWidth, Int displayHeight, IRegion2D *rectOut )
@@ -1340,7 +1446,8 @@ Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,
// One scale for both axes, the smaller of the two so the three panels always fit side by side.
// At 4:3 that is exactly what the .wnd loader would have used and the panels still meet; at
// anything wider they shrink together and leave the middle of the screen bottom open instead of
- // stretching to fill it.
+ // stretching to fill it. ControlBarUniformScale() is this same number for the display that is
+ // actually up; here the size is a parameter, because the tests ask about screens we are not on.
//
const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;
const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;
@@ -1380,6 +1487,8 @@ Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,
struct ControlBarPanelPlacement
{
Bool known;
+ Int panel; ///< which of the three it was put in, so a panel can be hidden as a unit
+ Bool weHid; ///< TRUE while the minimised bar is what is hiding it, and not the context
Real designX, designY, designW, designH;
Int placedX, placedY, placedW, placedH;
};
@@ -1521,7 +1630,7 @@ void ControlBar::placeInPanel( GameWindow *win, Int panel,
const Real dispH = (Real)TheDisplay->getHeight();
const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;
const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;
- const Real s = loadScaleX < loadScaleY ? loadScaleX : loadScaleY;
+ const Real s = ControlBarUniformScale();
const Real originX = dispW * thePanelAnchorFraction[ panel ]
- thePanelAnchorDesignX[ panel ] * s;
@@ -1595,6 +1704,8 @@ void ControlBar::placeInPanel( GameWindow *win, Int panel,
win->winSetSize( newW, newH );
place.known = TRUE;
+ place.panel = panel;
+ place.weHid = FALSE;
place.placedX = newX;
place.placedY = newY;
place.placedW = newW;
@@ -1605,6 +1716,166 @@ void ControlBar::placeInPanel( GameWindow *win, Int panel,
} // end placeInPanel
+/// how long a panel takes to leave or return, in milliseconds
+static const Real PANEL_SLIDE_MS = 220.0f;
+
+//-------------------------------------------------------------------------------------------------
+/** The three marker windows draw nothing of their own - they are five pixels square and exist only
+ * to hang a draw callback on, and one of those callbacks paints all three plates. They are
+ * authored over the radar, so taking the left panel away by its windows would take the painting
+ * off the panel that is staying too. */
+//-------------------------------------------------------------------------------------------------
+static Bool isPlateMarker( GameWindow *win )
+{
+ const char *shortName = shortWindowName( win );
+ return strcmp( shortName, "BackgroundMarker" ) == 0 ||
+ strcmp( shortName, "ForegroundMarker" ) == 0 ||
+ strcmp( shortName, "OnTopDraw" ) == 0;
+}
+
+//-------------------------------------------------------------------------------------------------
+Int ControlBar::getPanelSlideOffset( Int panel ) const
+{
+ if( panel < 0 || panel >= CB_PANEL_COUNT || TheDisplay == NULL )
+ return 0;
+ if( m_panelSlide[ panel ] <= 0.0f )
+ return 0;
+
+ // far enough that the top edge of the frame is off the bottom of the screen, so everything is
+ const Real drop = (Real)( TheDisplay->getHeight() - m_panelOrigin.y );
+ return REAL_TO_INT_FLOOR( m_panelSlide[ panel ] * drop );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Put every window where its panel's slide says it should be.
+ *
+ * layoutPanels has already recorded which panel each direct child of the frame went into and the
+ * screen position it was given, so this is that position plus however far the panel has travelled.
+ * What is inside those children keeps whatever the context system last decided, and comes back
+ * saying the same thing - they move as one piece and are never individually touched. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::applyPanelSlide( void )
+{
+ GameWindow *parent = m_contextParent[ CP_MASTER ];
+ if( parent == NULL )
+ return;
+
+ Int offset[ CB_PANEL_COUNT ];
+ for( Int p = 0; p < CB_PANEL_COUNT; p++ )
+ offset[ p ] = getPanelSlideOffset( p );
+
+ for( GameWindow *child = parent->winGetChild(); child; child = child->winGetNext() )
+ {
+ ControlBarPanelPlacementMap::iterator it = theControlBarPlacement.find( child );
+ if( it == theControlBarPlacement.end() || it->second.known == FALSE )
+ continue;
+ if( isPlateMarker( child ) )
+ continue;
+
+ ControlBarPanelPlacement &place = it->second;
+ const Int panel = place.panel;
+ if( panel < 0 || panel >= CB_PANEL_COUNT )
+ continue;
+
+ //
+ // Clear of the bottom edge and staying there: stop drawing it at all. Only what we hid do
+ // we ever un-hide - the context system hides windows of its own all the time (the unused
+ // minimise buttons, a beacon pane, an empty portrait) and a blanket winHide(FALSE) over the
+ // panel put every one of them back on screen.
+ //
+ if( m_panelHidden[ panel ] )
+ {
+ if( !place.weHid )
+ {
+ child->winHide( TRUE );
+ place.weHid = TRUE;
+ }
+ continue;
+ }
+
+ if( place.weHid )
+ {
+ child->winHide( FALSE );
+ place.weHid = FALSE;
+ }
+
+ ICoord2D pos;
+ child->winGetPosition( &pos.x, &pos.y );
+ const Int wantY = place.placedY - m_panelOrigin.y + offset[ panel ];
+ if( pos.y != wantY )
+ child->winSetPosition( pos.x, wantY );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Step the slide. Wall clock rather than logic frames: this is a piece of the interface moving,
+ * and it should take the same quarter of a second whatever the game is doing. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::updatePanelSlide( void )
+{
+ const UnsignedInt now = timeGetTime();
+ const UnsignedInt sinceMs = ( m_panelSlideMs == 0 || now < m_panelSlideMs ) ? 0 : now - m_panelSlideMs;
+ m_panelSlideMs = now;
+
+ Bool moving = FALSE;
+ for( Int p = 0; p < CB_PANEL_COUNT; p++ )
+ if( m_panelSlide[ p ] != m_panelSlideTo[ p ] )
+ moving = TRUE;
+
+ if( !moving )
+ return;
+
+ const Real step = ( sinceMs > 0 ) ? (Real)sinceMs / PANEL_SLIDE_MS : 0.0f;
+
+ for( Int p = 0; p < CB_PANEL_COUNT; p++ )
+ {
+ if( m_panelSlide[ p ] < m_panelSlideTo[ p ] )
+ {
+ m_panelSlide[ p ] += step;
+ if( m_panelSlide[ p ] >= m_panelSlideTo[ p ] )
+ {
+ m_panelSlide[ p ] = m_panelSlideTo[ p ];
+ m_panelHidden[ p ] = TRUE; // arrived off screen
+ }
+ }
+ else if( m_panelSlide[ p ] > m_panelSlideTo[ p ] )
+ {
+ m_panelSlide[ p ] -= step;
+ if( m_panelSlide[ p ] <= m_panelSlideTo[ p ] )
+ m_panelSlide[ p ] = m_panelSlideTo[ p ];
+ }
+ }
+
+ applyPanelSlide();
+
+} // end updatePanelSlide
+
+//-------------------------------------------------------------------------------------------------
+/** Send one whole panel off the bottom of the screen, or bring it back. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::showPanel( Int panel, Bool show, Bool immediate )
+{
+ if( panel < 0 || panel >= CB_PANEL_COUNT )
+ return;
+
+ m_panelSlideTo[ panel ] = show ? 0.0f : 1.0f;
+
+ // coming back it is on screen from the first frame of the slide, going it is on screen until the
+ // last: only a panel that has arrived at the bottom is hidden
+ if( show )
+ m_panelHidden[ panel ] = FALSE;
+
+ if( immediate )
+ {
+ m_panelSlide[ panel ] = m_panelSlideTo[ panel ];
+ m_panelHidden[ panel ] = !show;
+ }
+
+ m_panelSlideMs = timeGetTime();
+ applyPanelSlide();
+
+} // end showPanel
+
//-------------------------------------------------------------------------------------------------
/** Re-anchor the control bar as three panels at one uniform scale. */
//-------------------------------------------------------------------------------------------------
@@ -1614,19 +1885,35 @@ void ControlBar::layoutPanels( void )
if( parent == NULL || TheDisplay == NULL )
return;
+ //
+ // A panel that is away, or on its way, is not where this function last put it - and this
+ // function reads a window's position to work out what it was authored at. So the slide is
+ // taken off first and put back at the end, and a bar that was minimised when the side changed
+ // is minimised again without the trip down.
+ //
+ Bool wasAway[ CB_PANEL_COUNT ];
+ Int q;
+ for( q = 0; q < CB_PANEL_COUNT; q++ )
+ {
+ wasAway[ q ] = ( m_panelSlideTo[ q ] > 0.0f );
+ m_panelSlide[ q ] = 0.0f;
+ m_panelSlideTo[ q ] = 0.0f;
+ m_panelHidden[ q ] = FALSE;
+ }
+ applyPanelSlide();
+
const Real dispW = (Real)TheDisplay->getWidth();
const Real dispH = (Real)TheDisplay->getHeight();
- // what the .wnd loader already multiplied every coordinate by, so we can divide it back out
+ // what the .wnd loader already multiplied every x coordinate by, so we can divide it back out
const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;
- const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;
//
// One scale for both axes, the smaller of the two so the three panels always fit side by side.
// At 4:3 that is exactly the old scale and the panels still meet; at anything wider they shrink
// together and leave the middle of the screen bottom open instead of stretching to fill it.
//
- const Real s = loadScaleX < loadScaleY ? loadScaleX : loadScaleY;
+ const Real s = ControlBarUniformScale();
Int p;
for( p = 0; p < CB_PANEL_COUNT; p++ )
@@ -1644,6 +1931,11 @@ void ControlBar::layoutPanels( void )
parent->winSetPosition( 0, parentTop );
parent->winSetSize( REAL_TO_INT_CEIL( dispW ), REAL_TO_INT_CEIL( dispH ) - parentTop );
+ // the plates are drawn from design rectangles rather than from a window, so they need to be told
+ // where the frame they belong to started out - see getPanelOrigin
+ m_panelOrigin.x = 0;
+ m_panelOrigin.y = parentTop;
+
for( GameWindow *child = parent->winGetChild(); child; child = child->winGetNext() )
{
// the nameless panes go by where they were authored, so ask the cache before it is rewritten
@@ -1663,6 +1955,11 @@ void ControlBar::layoutPanels( void )
barOrigin.x, barOrigin.y, 0, parentTop );
}
+ // whatever was away before is away again, without being watched leaving a second time
+ for( q = 0; q < CB_PANEL_COUNT; q++ )
+ if( wasAway[ q ] )
+ showPanel( q, FALSE, TRUE );
+
} // end layoutPanels
//-------------------------------------------------------------------------------------------------
@@ -1714,6 +2011,15 @@ void ControlBar::init( void )
m_scienceLayout = TheWindowManager->winCreateLayout("GeneralsExpPoints.wnd");
m_scienceLayout->hide(TRUE);
+
+ //
+ // The rank screen is one painting with the science cameos placed on it, authored at
+ // 210..604 x 3..434. Stretched separately in x and y it is a third too wide on a 16:9
+ // screen and every round rank badge on it is an oval. Centred at the top, at the command
+ // bar's own uniform scale, it is the picture that was drawn.
+ //
+ ControlBarLayoutUniform( m_scienceLayout->getFirstWindow(), 0.5f, 0.0f );
+
id = TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:GenExpParent" );
m_contextParent[ CP_PURCHASE_SCIENCE ] = TheWindowManager->winGetWindowFromId( NULL, id );//m_scienceLayout->getFirstWindow();
@@ -2106,6 +2412,9 @@ void ControlBar::update( void )
clearSpecialPowerShortcutRow();
}
+ // the minimised panels going or coming back
+ updatePanelSlide();
+
if(m_controlBarSchemeManager)
m_controlBarSchemeManager->update();
@@ -2221,7 +2530,7 @@ void ControlBar::update( void )
}
}
- if(!m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())
+ if( isPurchaseScienceVisible() )
{
updateContextPurchaseScience();
updatePurchaseScienceHotKeys();
@@ -2503,29 +2812,29 @@ void ControlBar::evaluateContextUI( void )
m_UIDirty = FALSE;
// if our purchase science window is up, we will want to update it by repopulating it.
- if(!m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())
- showPurchaseScience();
+ if( isPurchaseScienceVisible() )
+ populatePurchaseScience( ThePlayerList->getLocalPlayer() );
// erase any current state of the GUI by switching out to the empty context
switchToContext( CB_CONTEXT_NONE, NULL );
- m_standInBuilderID = INVALID_DRAWABLE_ID;
//
// nothing selected: one of the player's builders stands in and its command bar shows, so
// a structure can be placed without selecting a dozer first - the logic then sends the
- // idle builder nearest the site (MSG_DOZER_CONSTRUCT)
+ // idle builder nearest the site (MSG_DOZER_CONSTRUCT). m_standInBuilderID is not cleared
+ // first: findStandInBuilder reads it to keep the builder it is already showing.
//
if( TheInGameUI->getSelectCount() == 0 )
{
Drawable *builder = findStandInBuilder( FALSE );
+ m_standInBuilderID = builder ? builder->getID() : INVALID_DRAWABLE_ID;
if( builder )
- {
switchToContext( CB_CONTEXT_COMMAND, builder );
- m_standInBuilderID = builder->getID();
- }
return;
}
+ m_standInBuilderID = INVALID_DRAWABLE_ID;
+
// get the list of drawable IDs from the in game UI
const DrawableList *selectedDrawables = TheInGameUI->getAllSelectedDrawables();
@@ -3074,6 +3383,28 @@ Drawable *ControlBar::findStandInBuilder( Bool freeOnly )
if( player == NULL )
return NULL;
+ //
+ // The builder already standing in keeps the bar for as long as it is still a builder. The
+ // sweep below answers "the first idle one", and idleness changes on its own: a dozer somewhere
+ // across the base finishing a building goes idle and used to take the bar off the one you were
+ // working with. That drops a half-typed chord and takes the structure off your cursor, in the
+ // middle of placing it, because something happened somewhere else.
+ //
+ if( m_standInBuilderID != INVALID_DRAWABLE_ID && TheGameClient )
+ {
+ Drawable *held = TheGameClient->findDrawableByID( m_standInBuilderID );
+ Object *obj = held ? held->getObject() : NULL;
+ if( obj && obj->getControllingPlayer() == player )
+ {
+ StandInBuilderSearch check;
+ check.idle = NULL;
+ check.any = NULL;
+ findStandInBuilderProc( obj, &check );
+ if( check.any && ( !freeOnly || check.idle ) )
+ return held;
+ }
+ }
+
StandInBuilderSearch s;
s.idle = NULL;
s.any = NULL;
@@ -3234,6 +3565,10 @@ const ControlBar::BorrowedTray *ControlBar::borrowTray( const PlayerTemplate *pt
return NULL; // a mod naming a layout it does not ship: remembered as having no tray
layout->hide( TRUE );
+ // the size read off it below is the size the strips draw a tray at, so it has to come out of the
+ // same un-stretched space the bar itself is put in - see initSpecialPowershortcutBar
+ ControlBarLayoutUniform( layout->getFirstWindow(), 1.0f, 1.0f );
+
AsciiString parentName = layoutName;
parentName.concat( ":ButtonParent1" );
@@ -3863,6 +4198,7 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com
GadgetButtonSetCount( button, 0 );
GadgetButtonSetSeconds( button, 0 );
GadgetButtonSetCost( button, 0 );
+ GadgetButtonSetPower( button, 0 );
setCommandBarBorder(button, commandButton->getCommandButtonMappedBorderType());
@@ -4366,13 +4702,14 @@ void ControlBar::updatePurchaseScience( void )
void ControlBar::showPurchaseScience( void )
{
-
+
if(TheScriptEngine->isGameEnding())
return;
populatePurchaseScience(ThePlayerList->getLocalPlayer());
m_genStarFlash = FALSE;
- if(!m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())
+ if( m_purchaseScienceOpen )
return;
+ m_purchaseScienceOpen = TRUE;
//switchToContext(CB_CONTEXT_PURCHASE_SCIENCE, NULL);
m_contextParent[ CP_PURCHASE_SCIENCE ]->winHide(FALSE);
if (TheGlobalData->m_animateWindows)
@@ -4385,8 +4722,17 @@ void ControlBar::hidePurchaseScience( void )
{
clearPurchaseScienceColumn();
- if(m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())
- return;
+ m_purchaseScienceOpen = FALSE;
+
+ //
+ // The fade drives winHide on this window itself, frame by frame, and it holds the window hidden
+ // for its first few frames. So the screen's own hidden flag is not the question "is it open" -
+ // a second press of the key while the fade was still running read the window as hidden and
+ // opened it again, and a press after that was undone the moment the fade's next frame put the
+ // window back. We keep the answer ourselves, and the fade is taken off before we close.
+ //
+ if( TheTransitionHandler )
+ TheTransitionHandler->remove( "GenExpFade" );
if( m_contextParent[ CP_PURCHASE_SCIENCE ] )
{
@@ -4410,7 +4756,7 @@ void ControlBar::hidePurchaseScience( void )
Bool ControlBar::isPurchaseScienceVisible( void )
{
- return m_contextParent[ CP_PURCHASE_SCIENCE ] && !m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden();
+ return m_purchaseScienceOpen && m_contextParent[ CP_PURCHASE_SCIENCE ] != NULL;
}
//-------------------------------------------------------------------------------------------------
@@ -4618,10 +4964,10 @@ void ControlBar::pressPurchaseScienceColumn( Int column )
void ControlBar::togglePurchaseScience( void )
{
- if(m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())
- showPurchaseScience();
- else
+ if( isPurchaseScienceVisible() )
hidePurchaseScience();
+ else
+ showPurchaseScience();
}
void ControlBar::toggleControlBarStage( void )
@@ -4667,9 +5013,14 @@ void ControlBar::setDefaultControlBarConfig( void )
// bar - that shrank the viewport in the middle of a match and slid the picture, for good:
// nothing put the height back once ShowControlBar had run at the start of the game.
//
- TheTacticalView->setHeight((Int)(TheDisplay->getHeight()));
+ TheTacticalView->setHeight((Int)(TheDisplay->getHeight()));
m_contextParent[ CP_MASTER ]->winSetPosition(m_defaultControlBarPosition.x, m_defaultControlBarPosition.y);
m_contextParent[ CP_MASTER ]->winHide(FALSE);
+
+ // the two panels the minimised bar stands down
+ showPanel( CB_PANEL_LEFT, TRUE );
+ showPanel( CB_PANEL_CENTER, TRUE );
+
repopulateBuildTooltipLayout();
setUpDownImages();
@@ -4689,14 +5040,23 @@ void ControlBar::setSquishedControlBarConfig( void )
void ControlBar::setLowControlBarConfig( void )
{
-
+
m_currentControlBarStage = CONTROL_BAR_STAGE_LOW;
- ICoord2D pos;
- pos.x = m_defaultControlBarPosition.x;
- pos.y = TheDisplay->getHeight() - .1 * TheDisplay->getHeight();
- TheTacticalView->setHeight((Int)(TheDisplay->getHeight()));
- m_contextParent[ CP_MASTER ]->winSetPosition(pos.x, pos.y);
+
+ //
+ // Minimised is the radar and the middle gone, not the whole bar slid down a tenth of the screen
+ // with its top edge still showing. Sliding it left a strip of metal, a readable money box and
+ // the top of the radar dish lying along the bottom of the picture, which is neither the bar nor
+ // out of the way. The selection side stays where it is: it is where the button that puts the
+ // rest back lives, and it is the panel a minimising player is keeping.
+ //
+ TheTacticalView->setHeight((Int)(TheDisplay->getHeight()));
+ m_contextParent[ CP_MASTER ]->winSetPosition(m_defaultControlBarPosition.x, m_defaultControlBarPosition.y);
m_contextParent[ CP_MASTER ]->winHide(FALSE);
+
+ showPanel( CB_PANEL_LEFT, FALSE );
+ showPanel( CB_PANEL_CENTER, FALSE );
+
setUpDownImages();
}
@@ -4887,6 +5247,15 @@ void ControlBar::initSpecialPowershortcutBar( Player *player)
NameKeyType id = TheNameKeyGenerator->nameToKey( tempName );
m_specialPowerShortcutParent = TheWindowManager->winGetWindowFromId( NULL, id );//m_scienceLayout->getFirstWindow();
+ //
+ // The bar is authored at 752..800 x 3..429 and the loader stretches x and y by different
+ // amounts, so on a 16:9 screen every slot came out a third wider than it is tall - and both
+ // strips measure their cameos off these slots, so the whole HUD inherited the smear. Put it
+ // back at the command bar's own uniform scale, pinned to the bottom right corner, which is
+ // where it was authored and where the bar's right hand panel now sits.
+ //
+ ControlBarLayoutUniform( m_specialPowerShortcutParent, 1.0f, 1.0f );
+
tempName = layoutName;
tempName.concat(":ButtonCommand%d");
parentName = layoutName;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
index d7df01ca6..56eb60965 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
@@ -838,6 +838,16 @@ void ControlBar::updateContextCommand( void )
// price, so a faction discount or a general's promotion shows in it.
//
GadgetButtonSetCost( win, tmpl->calcCostToBuild( localPlayer ) );
+
+ //
+ // ... and what it does to the power grid, in the fourth corner. Money and time are
+ // the two numbers already on the button and power is the third thing a base spends;
+ // it was the only one you had to hover for, which is the wrong way round for the
+ // building you are putting up because the lights went out. Structures only - a unit
+ // has no power line, and the bottom right corner is the queue count's on a unit.
+ //
+ if( command->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT )
+ GadgetButtonSetPower( win, tmpl->getEnergyProduction() );
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
index 58e6669e1..c88b15d29 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
@@ -76,6 +76,9 @@ enum{
COMMAND_BAR_SIZE_OFFSET = 0
};
+/// where GeneralsExpPoints.wnd hangs its panel from, in the 800x600 the layout was authored at
+static const Real GEN_EXP_DESIGN_TOP = 3.0f;
+
const FieldParse ControlBarSchemeManager::m_controlBarSchemeFieldParseTable[] =
{
@@ -681,7 +684,23 @@ void ControlBarScheme::init(void)
win->winSetEnabledImage(0,m_powerPurchaseImage);
if( m_powerPurchaseImage )
{
- win->winSetSize(m_powerPurchaseImage->getImageWidth() * resMultiplier.x, m_powerPurchaseImage->getImageHeight() * resMultiplier.y);
+ //
+ // The rank screen is one painting, and this line is what decides how big it is drawn -
+ // which is why laying the screen out uniformly at startup was not enough: every side
+ // change put the painting back at the loader's two separate scales, a third wider than
+ // tall at 16:9, over children that had been placed squarely.
+ //
+ // One scale, and then the panel is centred on the screen by its own width rather than
+ // left hanging off the anchor its authored rectangle had. Its children are positioned
+ // relative to it, so the whole screen moves as one piece.
+ //
+ const Real s = ControlBarUniformScale();
+ const Int w = REAL_TO_INT_CEIL( m_powerPurchaseImage->getImageWidth() * s );
+ const Int h = REAL_TO_INT_CEIL( m_powerPurchaseImage->getImageHeight() * s );
+
+ win->winSetSize( w, h );
+ win->winSetPosition( ( TheDisplay->getWidth() - w ) / 2,
+ REAL_TO_INT_FLOOR( GEN_EXP_DESIGN_TOP * s ) );
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index d3ba54bb5..1ec6c1ec4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -230,6 +230,7 @@ WindowLayout *OptionsLayout = NULL;
// and the one function that decides which one you are looking at.
//-------------------------------------------------------------------------------------------------
enum { OPTIONS_PAGE_COUNT = 5 };
+enum { OPTIONS_PAGE_CONTROLS = 2 }; ///< the page the keyboard button is drawn over
static const char *TheOptionsPageNames[ OPTIONS_PAGE_COUNT ] =
{
@@ -272,6 +273,22 @@ static void showOptionsPage( Int which )
if( optionsTab[ i ] )
optionsTab[ i ]->winEnable( i != which );
}
+
+ //
+ // The keyboard button belongs on the controls page and is drawn over it, but it is not one of
+ // its children - it predates the pages and lives on the old flat panel with the rest of the
+ // leftovers - so it is shown and hidden by hand rather than with its page.
+ //
+ GameWindow *keys = TheWindowManager->winGetWindowFromId(
+ NULL, TheNameKeyGenerator->nameToKey( AsciiString( "OptionsMenu.wnd:ButtonKeyboardOptions" ) ) );
+ if( keys )
+ {
+ keys->winHide( which != OPTIONS_PAGE_CONTROLS );
+
+ // the page's own panel is painted over that old one, so the button has to come up through it
+ if( which == OPTIONS_PAGE_CONTROLS )
+ keys->winBringToTop();
+ }
}
enum Detail
@@ -1099,15 +1116,48 @@ static void readCatalogWidgets( void )
}
}
+//-------------------------------------------------------------------------------------------------
+/** Borderless fullscreen takes the desktop's resolution and nothing else, so while it is the
+ * selected mode the resolution list has no say and says so by going grey. Fullscreen and
+ * windowed both hand it back. Read off the control rather than off GlobalData, so it follows the
+ * dropdown while the screen is open instead of waiting for Accept. */
+//-------------------------------------------------------------------------------------------------
+static void updateResolutionEnabled( void )
+{
+ if( comboBoxResolution == NULL )
+ return;
+
+ const OptionDef *mode = findOptionDef( "WindowMode" );
+ GameWindow *modeWidget = mode ? findOptionWidget( *mode ) : NULL;
+
+ Int selected = -1;
+ if( modeWidget )
+ GadgetComboBoxGetSelectedPos( modeWidget, &selected );
+
+ const Int value = ( selected >= 0 && mode ) ? mode->lo + selected : TheGlobalData->m_windowMode;
+ comboBoxResolution->winEnable( value != WINDOW_MODE_BORDERLESS );
+}
+
static void saveOptions( void )
{
Int index;
Int val;
+ // which of the three the window is wearing right now, before the controls overwrite it
+ const Int oldWindowMode = TheGlobalData->m_windowMode;
+
//-------------------------------------------------------------------------------------------------
// The catalog's controls, read back into GlobalData before the pass below writes GlobalData out.
readCatalogWidgets();
+ //
+ // A catalog row writes its own GlobalData field and nothing else, so the window mode is a raw
+ // number until this runs: applyWindowMode is what turns it into the windowed flag the device
+ // layer reads, and into the desktop resolution and edge scrolling that borderless means. The
+ // resolution block further down then hands all of it to the display in one change.
+ //
+ applyWindowMode();
+
//-------------------------------------------------------------------------------------------------
// Everything in TheOptionCatalog, written back from GlobalData in one pass. A catalog setting
// with a widget has put its value into GlobalData by the time Accept runs; one without a widget
@@ -1249,40 +1299,66 @@ static void saveOptions( void )
(*pref)["StaticGameLOD"] = TheGameLODManager->getStaticGameLODLevelName(TheGameLODManager->getStaticLODLevel());
//-------------------------------------------------------------------------------------------------
- // Resolution
+ // Resolution and window mode.
+ //
+ // One device change rather than two: the mode decides whether the device is windowed, and
+ // borderless decides the resolution as well - applyWindowMode above has already put the desktop
+ // size in GlobalData, and the dropdown has no say over a window that covers the display.
+ //
GadgetComboBoxGetSelectedPos( comboBoxResolution, &index );
Int xres, yres, bitDepth;
-
+
oldDispSettings.xRes = TheDisplay->getWidth();
oldDispSettings.yRes = TheDisplay->getHeight();
oldDispSettings.bitDepth = TheDisplay->getBitDepth();
oldDispSettings.windowed = TheDisplay->getWindowed();
-
- if (index < TheDisplay->getDisplayModeCount() && index >= 0)
+
+ xres = TheGlobalData->m_xResolution;
+ yres = TheGlobalData->m_yResolution;
+ bitDepth = TheDisplay->getBitDepth();
+ if( TheGlobalData->m_windowMode != WINDOW_MODE_BORDERLESS
+ && index >= 0 && index < TheDisplay->getDisplayModeCount() )
+ TheDisplay->getDisplayModeDescription( index, &xres, &yres, &bitDepth );
+
+ //
+ // Not the windowed flag: borderless and windowed are both windowed devices, and a switch between
+ // those two is a change of frame with the same flag on both sides of it.
+ //
+ const Bool sizeChanged = ( oldDispSettings.xRes != xres || oldDispSettings.yRes != yres );
+ const Bool modeChanged = ( oldWindowMode != TheGlobalData->m_windowMode );
+
+ if( sizeChanged || modeChanged )
{
- TheDisplay->getDisplayModeDescription(index,&xres,&yres,&bitDepth);
- if (TheGlobalData->m_xResolution != xres || TheGlobalData->m_yResolution != yres)
+ if (TheDisplay->setDisplayMode(xres,yres,bitDepth,TheGlobalData->m_windowed))
{
-
- if (TheDisplay->setDisplayMode(xres,yres,bitDepth,TheDisplay->getWindowed()))
+ TheWritableGlobalData->m_xResolution = xres;
+ TheWritableGlobalData->m_yResolution = yres;
+
+ TheHeaderTemplateManager->headerNotifyResolutionChange();
+ TheMouse->mouseNotifyResolutionChange();
+
+ AsciiString prefString;
+ prefString.format("%d %d", xres, yres );
+ (*pref)["Resolution"] = prefString;
+
+ //
+ // Every window on screen was laid out against the old size, so the shell is rebuilt from
+ // the layouts. A mode change that keeps the resolution - fullscreen to borderless on a
+ // screen the game was already filling - changes no rectangle, so it does not pay for a
+ // trip back to the main menu.
+ //
+ if( sizeChanged )
{
+ // only a resolution change gets the "keep these settings?" dialog; the frame round a
+ // window is not something a player needs talking out of
dispChanged = TRUE;
- TheWritableGlobalData->m_xResolution = xres;
- TheWritableGlobalData->m_yResolution = yres;
- TheHeaderTemplateManager->headerNotifyResolutionChange();
- TheMouse->mouseNotifyResolutionChange();
-
//Save new settings for a dialog box confirmation after options are accepted
newDispSettings.xRes = xres;
newDispSettings.yRes = yres;
newDispSettings.bitDepth = bitDepth;
newDispSettings.windowed = TheDisplay->getWindowed();
- AsciiString prefString;
- prefString.format("%d %d", xres, yres );
- (*pref)["Resolution"] = prefString;
-
// delete the shell
delete TheShell;
TheShell = NULL;
@@ -1291,10 +1367,20 @@ static void saveOptions( void )
TheShell = MSGNEW("GameClientSubsystem") Shell;
if( TheShell )
TheShell->init();
-
+
TheInGameUI->recreateControlBar();
- TheShell->push( AsciiString("Menus/MainMenu.wnd") );
+ //
+ // Out of a match the shell is what you are looking at, so it opens on the main menu.
+ // In one, the menus were rebuilt for the next time you want them and the thing on
+ // screen is the battlefield: pushing the main menu over a running game is why the
+ // resolution list used to be greyed out in-game at all. The command bar has just been
+ // built from its layouts and comes up hidden, so it is put back.
+ //
+ if( TheGameLogic->isInGame() && !TheGameLogic->isInShellGame() )
+ ShowControlBar( TRUE );
+ else
+ TheShell->push( AsciiString("Menus/MainMenu.wnd") );
}
}
}
@@ -2007,9 +2093,11 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
if (comboBoxDetail)
comboBoxDetail->winEnable(FALSE);
-
- if (comboBoxResolution)
- comboBoxResolution->winEnable(FALSE);
+ //
+ // The resolution list used to be greyed out here too. It is not any more: changing it in a
+ // match rebuilds the menus and the command bar and leaves you looking at the battlefield -
+ // see the resolution block in saveOptions.
+ //
// if (checkAudioSurround)
// checkAudioSurround->winEnable(FALSE);
@@ -2019,6 +2107,9 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
}
+ // borderless owns the resolution; the list is grey while it is picked
+ updateResolutionEnabled();
+
TheWindowManager->winSetModal(parent);
ignoreSelected = FALSE;
} // end OptionsMenuInit
@@ -2174,6 +2265,9 @@ WindowMsgHandledType OptionsMenuSystem( GameWindow *window, UnsignedInt msg,
showAdvancedOptions();
}
+
+ // picking borderless greys the resolution list out, the other two hand it back
+ updateResolutionEnabled();
break;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp
index 87a368276..2791fa1ca 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp
@@ -606,6 +606,7 @@ PushButtonData * getNewPushButtonData( void )
p->drawCount = 0;
p->drawSeconds = 0;
p->drawCost = 0;
+ p->drawPower = 0;
p->barPercent = -1;
p->barColor = GAME_COLOR_UNDEFINED;
p->overlayImage = NULL;
@@ -758,6 +759,29 @@ void GadgetButtonSetCost( GameWindow *g, Int cost )
g->winSetUserData(pData);
}
+// GadgetButtonSetPower =======================================================
+/** Set the power figure drawn in the button's bottom right corner, 0 for none.
+ * Negative is what the structure draws off the grid, positive what it puts on
+ * it - the sign the game's own templates use. Money and time are already in
+ * the other three corners; power is the third thing a base has to spend and
+ * the only one you had to remember from the tooltip. */
+//=============================================================================
+void GadgetButtonSetPower( GameWindow *g, Int power )
+{
+ if( g == NULL )
+ return;
+
+ PushButtonData *pData = (PushButtonData *)g->winGetUserData();
+ if(!pData)
+ {
+ pData = getNewPushButtonData();
+ if(!pData)
+ return;
+ }
+ pData->drawPower = power;
+ g->winSetUserData(pData);
+}
+
// GadgetButtonSetBar =========================================================
/** Set a thin progress bar along the button's bottom edge, percent < 0 for none */
//=============================================================================
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
index 583bb23e9..aa7e301a5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
@@ -2467,9 +2467,19 @@ GameWindow *GameWindowManager::gogoGadgetComboBox( GameWindow *parent,
// intialize instData
winInstData.init();
- // size of button
- buttonWidth = 21;
- buttonHeight = 22;
+ //
+ // Size of button. It used to be a flat 21x22 - the pixels the arrow was drawn at on the
+ // 800x600 the layouts were made for - while the combo box around it is stretched to the running
+ // resolution. So the taller the screen, the taller and thinner the slot the arrow was squeezed
+ // into: at 1080 it is nearly twice as tall as it is wide and the arrow comes out stretched.
+ // The art is square, so take the width from the height the box actually has.
+ //
+ buttonHeight = height;
+ buttonWidth = height;
+ if( buttonWidth > width / 2 )
+ buttonWidth = width / 2; // a very narrow box keeps some room for its own text
+ if( buttonWidth < 8 )
+ buttonWidth = 8;
// ----------------------------------------------------------------------
// Create Drop Down Button
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 3a71fffbb..708992dea 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -124,13 +124,15 @@ enum
//-------------------------------------------------------------------------------------------------
/** Every number above is an 800x600 one, the resolution the command bar right below the strip was
- * drawn at - and that bar is stretched to the screen while these are not, so on a 2560 wide
- * screen the strip came out a third of the size of the row of buttons it belongs to. Every one
- * of them goes through here. */
+ * drawn at, so every one of them goes through here to become pixels.
+ *
+ * The scale is the command bar's own - one factor for both axes - and not the display over 800
+ * wide. The two are the same at 4:3 and a third apart at 16:9, and the strip stands on the bar:
+ * measured the wide way its gaps grew away from the trays they space out. */
//-------------------------------------------------------------------------------------------------
static Int stripPixels( Int nominal )
{
- return REAL_TO_INT_CEIL( nominal * TheUIScale() );
+ return REAL_TO_INT_CEIL( nominal * ControlBarUniformScale() );
}
//-------------------------------------------------------------------------------------------------
@@ -2208,8 +2210,17 @@ void InGameUI::update( void )
lastMoney = currentMoney;
} // end if
- moneyWin->winHide(FALSE);
- powerWin->winHide(FALSE);
+
+ //
+ // These two are put back on screen every frame, which is how they survive the context
+ // switching that hides everything else on the bar. It also used to beat the minimised bar:
+ // the radar and the whole middle panel went away and the money still sat there over the
+ // battlefield, plate and all gone from under it. The bar's own stage has the last word.
+ //
+ const Bool centreUp = ( TheControlBar == NULL ||
+ !TheControlBar->isPanelHidden( ControlBar::CB_PANEL_CENTER ) );
+ moneyWin->winHide( !centreUp );
+ powerWin->winHide( !centreUp );
}
else
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp
index 2b9de3e56..8f1f15fe5 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp
@@ -699,8 +699,30 @@ void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instData
if( man == NULL || TheDisplay == NULL )
return;
+ //
+ // The plates are drawn from the design rectangles rather than from a window, so on their own
+ // they stand still while the bar moves: minimising it drops the frame a tenth of the screen and
+ // the intro slides the frame up from below, and both left the painting hanging where it was.
+ // This window is a child of that frame, so the frame's screen position now against where
+ // layoutPanels put it is exactly how far the whole bar has travelled.
+ //
+ ICoord2D offset;
+ offset.x = offset.y = 0;
+ GameWindow *frame = window ? window->winGetParent() : NULL;
+ if( frame )
+ {
+ ICoord2D now;
+ frame->winGetScreenPosition( &now.x, &now.y );
+ offset.x = now.x - TheControlBar->getPanelOrigin()->x;
+ offset.y = now.y - TheControlBar->getPanelOrigin()->y;
+ }
+
for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ )
{
+ // a panel the minimised bar has stood down paints nothing at all
+ if( TheControlBar->isPanelHidden( p ) )
+ continue;
+
const ControlBarPlate *plate = ControlBarPlateForSide( man->getCurrentSide(), p );
if( plate == NULL )
plate = ControlBarPlateForSide( man->getCurrentArtTwinSide(), p );
@@ -712,9 +734,13 @@ void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instData
TheDisplay->getHeight(), &rect ) == FALSE )
continue;
+ // ... and a panel on its way off the bottom takes its painting down with it
+ const Int slide = TheControlBar->getPanelSlideOffset( p );
+
const Image *image = plateImage( plate );
if( image )
- TheDisplay->drawImage( image, rect.lo.x, rect.lo.y, rect.hi.x, rect.hi.y );
+ TheDisplay->drawImage( image, rect.lo.x + offset.x, rect.lo.y + offset.y + slide,
+ rect.hi.x + offset.x, rect.hi.y + offset.y + slide );
}
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
index ca9353696..eda847649 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
@@ -83,14 +83,29 @@ void W3DGadgetPushButtonImageDrawOne(GameWindow *window, WinInstanceData *instDa
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
+/** The command bar's own scale, from ControlBar.cpp. Declared rather than included: ControlBar.h
+ * drags in the whole command-set machinery for one function that takes nothing and returns a
+ * float. */
+extern Real ControlBarUniformScale( void );
+
+/** Point size a corner marking wears on a command button at 800x600, which is the resolution the
+ * command bar and its 50x44 buttons were drawn for. Everything else is this times the scale the
+ * bar itself is laid out at. */
+static const Real BADGE_DESIGN_POINTS = 7.0f;
+
// getBadgeFont ===============================================================
/** The font the corner markings wear.
*
- * A hotkey letter, a price, a countdown and a queue count are labels on a picture,
- * not text to be read at length: at the window's own point size four of them crowd
- * a button that is barely thirty pixels wide, and the button stops reading as its
- * own art. One step down from whatever font the button was given, so the markings
- * still follow the wnd file and the resolution exactly as the button does. */
+ * A hotkey letter, a price, a countdown and a queue count are labels on a picture, not text to
+ * be read at length: four of them crowd a button that is barely thirty pixels wide, and the
+ * button stops reading as its own art.
+ *
+ * They have to keep the same size against that picture at every resolution, and the window's own
+ * font does not do that. The layout loader sizes a font by the screen's *width* over 800 (damped
+ * by ResolutionFontAdjustment), while the command bar is laid out at the smaller of width over
+ * 800 and height over 600 - so the wider the screen against its height, the faster the lettering
+ * grew away from the buttons it sits on. At 2560x1080 the markings came out half again too big.
+ * One design size, times the bar's own scale, and a cameo looks the same on every monitor. */
//=============================================================================
static GameFont *getBadgeFont( GameWindow *window )
{
@@ -98,10 +113,11 @@ static GameFont *getBadgeFont( GameWindow *window )
if( font == NULL )
return NULL;
- Int pointSize = font->pointSize * 5 / 6;
+ Int pointSize = REAL_TO_INT_FLOOR( BADGE_DESIGN_POINTS * ControlBarUniformScale() );
if( pointSize < 6 )
pointSize = 6;
- if( pointSize >= font->pointSize )
+
+ if( pointSize == font->pointSize )
return font;
return TheFontLibrary->getFont( font->nameString, pointSize, font->bold );
@@ -309,6 +325,55 @@ static void drawCostBadge( GameWindow *window, Int cost )
} // end drawCostBadge
+// drawPowerBadge =============================================================
+/** Draw what this structure does to the power grid in the button's bottom right
+ * corner: "-5" for what it draws, "+10" for what a plant puts back. Money and
+ * build time are already in the other corners; power is the third thing a base
+ * spends, and it was the one figure you had to hover a button to find - which
+ * is exactly the wrong way round for the building you put up to fix a brownout. */
+//=============================================================================
+static void drawPowerBadge( GameWindow *window, Int power )
+{
+ static DisplayString *label = NULL;
+ ICoord2D origin, size, textPos;
+ Int width, height;
+
+ if( label == NULL )
+ {
+ label = TheDisplayStringManager->newDisplayString();
+ if( label == NULL )
+ return;
+ }
+
+ // the game's own sign: a template's EnergyProduction is negative when it consumes
+ const Int draws = -power;
+
+ UnicodeString text;
+ text.format( draws > 0 ? L"-%d" : L"+%d", draws > 0 ? draws : -draws );
+ label->setText( text );
+
+ GameFont *font = getBadgeFont( window );
+ if( font != NULL && label->getFont() != font )
+ label->setFont( font );
+
+ window->winGetScreenPosition( &origin.x, &origin.y );
+ window->winGetSize( &size.x, &size.y );
+ label->getSize( &width, &height );
+
+ const Int plateWidth = width + 4;
+ textPos.x = origin.x + size.x - plateWidth + 2;
+ textPos.y = origin.y + size.y - height;
+
+ // same translucent plate the other badges wear - button art can be any colour
+ TheDisplay->drawFillRect( textPos.x - 2, textPos.y, plateWidth, height,
+ GameMakeColor( 0, 0, 0, 160 ) );
+ label->draw( textPos.x, textPos.y,
+ draws > 0 ? GameMakeColor( 255, 170, 90, 255 ) // spends it
+ : GameMakeColor( 130, 220, 255, 255 ), // supplies it
+ GameMakeColor( 0, 0, 0, 255 ) );
+
+} // end drawPowerBadge
+
// drawButtonBar ==============================================================
/** Draw a thin progress bar along the button's bottom edge (experience) */
//=============================================================================
@@ -465,8 +530,11 @@ void W3DGadgetPushButtonDraw( GameWindow *window, WinInstanceData *instData )
TheDisplay->drawOpenRect(origin.x -1, origin.y - 1, size.x + 2, size.y + 2,1 , pData->colorBorder);
}
+ // both live in the bottom right corner; a queue count is about this one order and wins
if( pData->drawCount > 0 )
drawCountBadge( window, pData->drawCount );
+ else if( pData->drawPower != 0 )
+ drawPowerBadge( window, pData->drawPower );
if( pData->drawSeconds > 0 )
drawSecondsBadge( window, pData->drawSeconds );
@@ -650,8 +718,11 @@ void W3DGadgetPushButtonImageDrawOne( GameWindow *window,
}
+ // both live in the bottom right corner; a queue count is about this one order and wins
if( pData->drawCount > 0 )
drawCountBadge( window, pData->drawCount );
+ else if( pData->drawPower != 0 )
+ drawPowerBadge( window, pData->drawPower );
if( pData->drawSeconds > 0 )
drawSecondsBadge( window, pData->drawSeconds );
@@ -922,8 +993,11 @@ void W3DGadgetPushButtonImageDrawThree(GameWindow *window, WinInstanceData *inst
TheDisplay->drawOpenRect(start.x - 1, start.y - 1, size.x + 2, size.y + 2, 1, pData->colorBorder);
}
+ // both live in the bottom right corner; a queue count is about this one order and wins
if( pData->drawCount > 0 )
drawCountBadge( window, pData->drawCount );
+ else if( pData->drawPower != 0 )
+ drawPowerBadge( window, pData->drawPower );
if( pData->drawSeconds > 0 )
drawSecondsBadge( window, pData->drawSeconds );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index eac9e9aad..c7631164b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -586,10 +586,162 @@ void Reset_D3D_Device(bool active)
}
}
+//=============================================================================
+/** Dress the application window for one WindowModeType, while the game is running.
+ *
+ * WinMain picks this style once, before the engine exists, out of the command line and
+ * Options.ini - which is why changing the setting in the options screen only ever showed up on
+ * the next run. The rules are WinMain's own (initializeAppWindows): a frame and a caption for a
+ * plain window, neither for the two that own the screen, and a system menu on all of them so
+ * alt+F4 still closes it.
+ *
+ * ApplicationIsBorderless has to travel with it: WndProc reads it on every WM_SIZE to keep a
+ * borderless window pinned at the origin. */
+//=============================================================================
+static void applyWindowFrame( Int mode )
+{
+ extern HWND ApplicationHWnd;
+ extern Bool ApplicationIsBorderless;
+
+ // a headless run has no picture at all, so there is nothing for any of the three to mean
+ if( ApplicationHWnd == NULL || ( TheGlobalData && TheGlobalData->m_headless ) )
+ return;
+
+ ApplicationIsBorderless = ( mode == WINDOW_MODE_BORDERLESS );
+
+ DWORD style = WS_POPUP | WS_VISIBLE | WS_SYSMENU;
+ if( mode == WINDOW_MODE_WINDOWED )
+ style |= WS_DLGFRAME | WS_CAPTION;
+
+ ::SetWindowLong( ApplicationHWnd, GWL_STYLE, style );
+
+ //
+ // The resize that follows keeps the top left corner where it is (SWP_NOMOVE), so a window that
+ // is about to cover the display is put at the origin now - otherwise it hangs off the bottom
+ // right by however far down the screen it happened to be sitting.
+ //
+ const UINT move = ( mode == WINDOW_MODE_WINDOWED ) ? SWP_NOMOVE : 0;
+ ::SetWindowPos( ApplicationHWnd,
+ ( mode == WINDOW_MODE_WINDOWED ) ? HWND_TOP : HWND_TOPMOST,
+ 0, 0, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED | move );
+}
+
+//=============================================================================
+/** Give the window a client area exactly this big, wearing whatever frame it now has. A plain
+ * window goes back to the middle of the screen, where one is born; a borderless one covers the
+ * display from the origin. Fullscreen is not our business - D3D owns that window. */
+//=============================================================================
+static void sizeWindowToClient( Int mode, Int width, Int height )
+{
+ extern HWND ApplicationHWnd;
+
+ if( ApplicationHWnd == NULL || ( TheGlobalData && TheGlobalData->m_headless ) )
+ return;
+ if( mode == WINDOW_MODE_FULLSCREEN )
+ return;
+
+ RECT rect;
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = width;
+ rect.bottom = height;
+ ::AdjustWindowRect( &rect, ::GetWindowLong( ApplicationHWnd, GWL_STYLE ), FALSE );
+
+ const Int outerW = rect.right - rect.left;
+ const Int outerH = rect.bottom - rect.top;
+
+ Int x = 0, y = 0;
+ if( mode == WINDOW_MODE_WINDOWED )
+ {
+ x = ( ::GetSystemMetrics( SM_CXSCREEN ) - outerW ) / 2;
+ y = ( ::GetSystemMetrics( SM_CYSCREEN ) - outerH ) / 2;
+ }
+
+ ::SetWindowPos( ApplicationHWnd,
+ ( mode == WINDOW_MODE_WINDOWED ) ? HWND_TOP : HWND_TOPMOST,
+ x, y, outerW, outerH, SWP_NOACTIVATE );
+}
+
/** Set resolution of display */
//=============================================================================
Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt bitdepth, Bool windowed )
{
+ extern Bool ApplicationIsBorderless;
+
+ //
+ // Which of the three the window is wearing, and which it is being asked for. The test cannot be
+ // on the windowed flag alone: borderless and windowed are both windowed devices and differ only
+ // in the frame, so a switch between those two would look like no change at all and the caption
+ // would stay on a window covering the display.
+ //
+ const Bool wasWindowed = getWindowed();
+ const Int wasMode = wasWindowed
+ ? ( ApplicationIsBorderless ? WINDOW_MODE_BORDERLESS : WINDOW_MODE_WINDOWED )
+ : WINDOW_MODE_FULLSCREEN;
+ const Int mode = windowed
+ ? ( ( TheGlobalData && TheGlobalData->m_windowMode == WINDOW_MODE_BORDERLESS )
+ ? WINDOW_MODE_BORDERLESS : WINDOW_MODE_WINDOWED )
+ : WINDOW_MODE_FULLSCREEN;
+
+ //
+ // Windowed against fullscreen is a different device rather than a resize, and
+ // Set_Device_Resolution says so itself - "TODO: support changing windowed status" - by quietly
+ // resetting the old one and returning success. So the mode dropdown used to take a restart.
+ // Set_Render_Device with reset_device is the call that rebuilds the device, the same one the
+ // alt-tab handler above uses; the window's frame goes on first, because the resize inside it
+ // measures whatever frame the window is wearing.
+ //
+ if( mode != wasMode )
+ {
+ //
+ // Which way round the frame and the device go depends on which way we are travelling.
+ //
+ // Into fullscreen, the frame comes off first: the resize inside Set_Render_Device measures
+ // whatever frame the window is wearing. Coming *out* of fullscreen it is the other way
+ // round, and this is not a preference. While the device still owns the display, hanging a
+ // caption on its window loses the device, and Reset_Device answers a lost device by
+ // returning false without trying - so the switch failed, the fallback put fullscreen back,
+ // and the mode dropdown looked like it did nothing at all in that one direction.
+ //
+ const Bool leavingFullscreen = ( wasMode == WINDOW_MODE_FULLSCREEN );
+
+ if( !leavingFullscreen )
+ applyWindowFrame( mode );
+
+ Bool ok = ( WW3D_ERROR_OK == WW3D::Set_Render_Device( WW3D::Get_Render_Device(), xres, yres,
+ bitdepth, windowed, true, true, true ) );
+ if( ok == FALSE )
+ {
+ // a device that was lost for a moment cannot be reset until it is not; one more go
+ ok = ( WW3D_ERROR_OK == WW3D::Set_Render_Device( WW3D::Get_Render_Device(), xres, yres,
+ bitdepth, windowed, true, true, true ) );
+ }
+
+ if( ok )
+ {
+ if( leavingFullscreen )
+ applyWindowFrame( mode );
+
+ sizeWindowToClient( mode, xres, yres );
+
+ Render2DClass::Set_Screen_Resolution( RectClass( 0, 0, xres, yres ) );
+ Display::setDisplayMode( xres, yres, bitdepth, windowed );
+
+ DEBUG_LOG(( "Window mode %d -> %d at %dx%d\n", wasMode, mode, xres, yres ));
+ return TRUE;
+ }
+
+ // the device is still the old one, so put the frame back on the window that goes with it
+ DEBUG_LOG(( "Window mode %d -> %d refused by the device; staying put\n", wasMode, mode ));
+ applyWindowFrame( wasMode );
+ WW3D::Set_Render_Device( WW3D::Get_Render_Device(), getWidth(), getHeight(), getBitDepth(),
+ wasWindowed, true, true, true );
+ sizeWindowToClient( wasMode, getWidth(), getHeight() );
+ Render2DClass::Set_Screen_Resolution( RectClass( 0, 0, getWidth(), getHeight() ) );
+ Display::setDisplayMode( getWidth(), getHeight(), getBitDepth(), wasWindowed );
+ return FALSE;
+ }
+
if (WW3D_ERROR_OK == WW3D::Set_Device_Resolution(xres,yres,bitdepth,windowed,true))
{
Render2DClass::Set_Screen_Resolution(RectClass(0, 0, xres, yres));
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index e84620617..414b26395 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -7966,6 +7966,54 @@ TEST(every_plate_that_touches_a_design_edge_touches_the_screen_edge)
CHECK( rect.hi.x < 1920 );
}
+/* The command bar is drawn at one scale for both axes and the things that stand beside it - the
+ production queue, the superweapon countdowns, the generals' power bar and the rank screen - are
+ drawn at ControlBarUniformScale. They used to be measured the display's width over 800, which
+ is a third bigger at 16:9 than the bar they sit on, so a queue cameo came out bigger than the
+ command button it is a picture of. One scale, and it is the bar's own. */
+TEST(the_hud_is_measured_at_the_command_bars_own_scale)
+{
+ static const struct { Int w, h; } screens[] =
+ {
+ { 800, 600 }, { 1024, 768 }, { 1280, 720 }, { 1920, 1080 }, { 2560, 1080 }, { 3840, 2160 },
+ };
+
+ // a design rectangle 100 units wide and 100 tall, so the width and height of what comes back
+ // out of the panel transform *is* the scale it was put through
+ IRegion2D square;
+ square.lo.x = 300;
+ square.lo.y = 480;
+ square.hi.x = 400;
+ square.hi.y = 580;
+
+ for( Int i = 0; i < (Int)( sizeof( screens ) / sizeof( screens[ 0 ] ) ); i++ )
+ {
+ const Real s = ControlBarUniformScaleFor( screens[ i ].w, screens[ i ].h );
+
+ // never wider than either axis would allow: that is what "not stretched" means
+ CHECK( s <= (Real)screens[ i ].w / 800.0f + 0.001f );
+ CHECK( s <= (Real)screens[ i ].h / 600.0f + 0.001f );
+
+ // and it is the very number the command bar's own panels are laid out at
+ IRegion2D got;
+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_CENTER, &square,
+ screens[ i ].w, screens[ i ].h, &got ) );
+ CHECK_NEAR( (Real)got.width(), 100.0f * s, 2.0f );
+ CHECK_NEAR( (Real)got.height(), 100.0f * s, 2.0f );
+
+ // square in, square out, to the rounding - the loader's separate x and y scales are what made
+ // a cameo a third wider than it is tall
+ CHECK( abs( got.width() - got.height() ) <= 1 );
+ }
+
+ // 800x600 is the resolution everything was authored at, so nothing is scaled at all there
+ CHECK_NEAR( ControlBarUniformScaleFor( 800, 600 ), 1.0f, 0.001f );
+
+ // and nothing shrinks below it, however small a screen somebody asks for
+ CHECK_NEAR( ControlBarUniformScaleFor( 640, 480 ), 1.0f, 0.001f );
+ CHECK_NEAR( ControlBarUniformScaleFor( 0, 0 ), 1.0f, 0.001f );
+}
+
/* A build order is a message, and the structure it orders does not exist until the logic runs it -
on a network game, however long the link takes. Until then the client remembers the ground it
spent, so a shift-held run of clicks does not put two structures on the same square. What it
@@ -8270,7 +8318,9 @@ TEST(window_mode_survives_a_round_trip_through_options_ini)
const OptionDef *mode = findOptionDef( "WindowMode" );
CHECK( mode != NULL );
CHECK_EQ( (Int)mode->kind, (Int)OPTION_ENUM );
- CHECK_EQ( (Int)mode->apply, (Int)APPLY_RESTART );
+ // changing it while the game is up restyles the window and rebuilds the device; it is only the
+ // style the window is *born* with that WinMain reads out of Options.ini before the engine exists
+ CHECK_EQ( (Int)mode->apply, (Int)APPLY_DEVICE_RESET );
CHECK_EQ( mode->hi, (Int)WINDOW_MODE_COUNT - 1 );
mode->set( WINDOW_MODE_BORDERLESS );