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.

fix(gameclient): sit the command bar on the screen edges

Olcay Seygan2b0a72963746
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b51b8260..8839a6200 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -383,7 +383,7 @@ found and fixed — EA's own, not port damage.**
- The writing on screen grows with your monitor now. Every panel is stretched to your resolution and always was, but the text inside it stayed the size it was drawn at in 2003, and what growth there was stopped dead at twice - so on a 2560 wide screen a command bar three times its original size still wore eight point lettering. The keys on the build buttons, the prices and the build times were the worst of it: at 2K they were drawn, and unreadable.
- The strip of everything your base is building follows the screen too, instead of staying a row of postage stamps under a command bar three times its size.
-- On a widescreen monitor the command bar is three pieces instead of one stretched strip. It was drawn for a 4:3 screen and every measurement in it is multiplied by your resolution separately across and down, so at 16:9 the whole thing came out a third wider than it is tall: square build pictures as rectangles, and one slab of metal across the entire bottom edge. The radar now sits hard in the left corner, the build grid in the middle, the selected unit's panel hard in the right corner, each at the size it was drawn at, and the battlefield shows through the two gaps that opens. At 4:3 the three pieces meet and it is the bar it has always been.
+- On a widescreen monitor the command bar is three pieces instead of one stretched strip. It was drawn for a 4:3 screen and every measurement in it is multiplied by your resolution separately across and down, so at 16:9 the whole thing came out a third wider than it is tall: square build pictures as rectangles, and one slab of metal across the entire bottom edge. The radar now sits hard in the left corner, the build grid in the middle, the selected unit's panel hard in the right corner, each at the size it was drawn at, and the battlefield shows through the two gaps that opens. At 4:3 the three pieces meet and it is the bar it has always been. The three pieces reach the screen: the paintings stop a pixel or two inside their own edges, which left a hairline of ground down both sides and along the bottom, and anything that close to an edge is now that edge. The American middle piece stands on the bottom edge like the other two sides' do, instead of hanging ten units high with a band of battlefield under the build grid.
- Widescreen resolutions are back in the options menu.
- Borderless fullscreen: start with `-borderless` and the game fills the screen at your desktop resolution with no frame and no display mode change, so alt-tab is instant, nothing on the desktop gets shuffled around behind it, and a second monitor stays usable. Screen-edge scrolling works there, the way it does in fullscreen. The loading picture still opens as its own small window with your desktop around it, and the game only takes the screen once it has something to draw.
- Fullscreen, borderless and windowed are one saved setting now, so borderless no longer means adding a switch to your shortcut every time. `WindowMode` in `Options.ini` takes 0, 1 or 2 in that order; a switch on the command line still wins for that one run.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 68446a45f..55805835a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -1298,6 +1298,15 @@ static const Real CONTROL_BAR_DESIGN_W = 800.0f;
static const Real CONTROL_BAR_DESIGN_H = 600.0f;
static const Real CONTROL_BAR_DESIGN_TOP = 404.0f; ///< the highest any panel reaches
+//
+// Every rectangle below was measured off the artwork rather than off the screen, and the artwork
+// stops a pixel or two inside its own edges: two of the nine plates start at design x 1 rather than
+// 0, two more end at 798 rather than 800, and seven of the nine end at y 597 to 599 rather than 600.
+// Multiplied up that is a hairline of battlefield down both sides of the screen and along the
+// bottom. Anything this close to an edge is that edge.
+//
+static const Int CONTROL_BAR_EDGE_SNAP = 4; ///< design units
+
//
// The authored 800x600 rectangle each panel covers, art and all - the three plate rectangles below
// unioned over the three sides, run down to the bottom edge of the screen. It is what the panel's
@@ -1345,6 +1354,20 @@ Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,
rectOut->lo.y = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - design->lo.y ) * s );
rectOut->hi.y = REAL_TO_INT_CEIL ( dispH - ( CONTROL_BAR_DESIGN_H - design->hi.y ) * s );
+ //
+ // The screen has three edges the bar touches and each belongs to one panel: the left panel owns
+ // the left edge, the right panel the right, and all three stand on the bottom. The centre
+ // panel's own left and right are interior - at 4:3 they are where it meets the other two - so
+ // they are left where the arithmetic put them.
+ //
+ if( panel == ControlBar::CB_PANEL_LEFT && design->lo.x <= CONTROL_BAR_EDGE_SNAP )
+ rectOut->lo.x = 0;
+ if( panel == ControlBar::CB_PANEL_RIGHT &&
+ design->hi.x >= REAL_TO_INT( CONTROL_BAR_DESIGN_W ) - CONTROL_BAR_EDGE_SNAP )
+ rectOut->hi.x = displayWidth;
+ if( design->hi.y >= REAL_TO_INT( CONTROL_BAR_DESIGN_H ) - CONTROL_BAR_EDGE_SNAP )
+ rectOut->hi.y = displayHeight;
+
return TRUE;
}
@@ -1423,9 +1446,10 @@ static const ControlBarPlateSet thePlateSets[] =
{ "America",
{
{ "RebornBarAmericaLeft.tga", { { 0, 412 }, { 183, 599 } } },
- // this one ends at the bottom of the command grid rather than at the bottom of the screen,
- // which is where the painting ends it - it is a closed plate and the ground shows below it
- { "RebornBarAmericaCenter.tga", { { 180, 419 }, { 623, 589 } } },
+ // the drawing registers at its bottom edge, which is the bottom of the bar - hung from its
+ // top instead it sat ten units high, showing ground under the grid and starting higher
+ // than the Chinese (433) and GLA (437) centre pieces do
+ { "RebornBarAmericaCenter.tga", { { 180, 429 }, { 623, 599 } } },
{ "RebornBarAmericaRight.tga", { { 610, 433 }, { 800, 599 } } },
}
},
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 989150fe7..8b9074115 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -7818,8 +7818,7 @@ TEST(a_plate_covers_the_windows_its_panel_is_responsible_for)
{ "radar", ControlBar::CB_PANEL_LEFT, 7, 443, 174, 595, TRUE },
{ "money", ControlBar::CB_PANEL_CENTER, 360, 437, 439, 462, TRUE },
{ "power bar", ControlBar::CB_PANEL_CENTER, 259, 469, 538, 476, TRUE },
- // the American painting ends its centre plate three pixels above this column's last button
- { "toolbar column", ControlBar::CB_PANEL_CENTER, 184, 490, 220, 592, FALSE },
+ { "toolbar column", ControlBar::CB_PANEL_CENTER, 184, 490, 220, 592, TRUE },
{ "command grid", ControlBar::CB_PANEL_CENTER, 223, 494, 603, 589, TRUE },
{ "selection portrait", ControlBar::CB_PANEL_RIGHT, 621, 483, 760, 592, TRUE },
{ NULL, 0, 0, 0, 0, 0, FALSE }
@@ -7836,18 +7835,69 @@ TEST(a_plate_covers_the_windows_its_panel_is_responsible_for)
CHECK( plate->design.hi.x >= w->x1 );
CHECK( plate->design.lo.y <= w->y0 );
- /* And the bottom edge, for the windows the painting does close under. A plate does not
- have to run to the bottom of the screen - the American centre one is a closed plate
- that ends where the command grid does - but where it is meant to be underneath a
- window it has to reach that window's own bottom, or the battlefield shows through.
- The American centre plate had a strip of the painting spliced onto it to take it to
- the bottom of the screen, and that strip drew a second bar edge with a line of ground
- between the two. */
+ /* And the bottom edge. Where a plate is meant to be underneath a window it has to reach
+ that window's own bottom, or the battlefield shows through. The American centre plate
+ was hung from its top for a while and ended ten units short of the others, which put a
+ band of ground under the command grid. */
if( w->closedUnder )
CHECK( plate->design.hi.y >= w->y1 );
}
}
+TEST(every_plate_that_touches_a_design_edge_touches_the_screen_edge)
+{
+ /* The plate rectangles were measured against the paintings, and a painting stops a pixel or two
+ inside its own edge - so the left plates start at design x 0 or 1, the right ones end at 798,
+ 799 or 800, and the bottoms land anywhere from 597 to 599. Multiplied up by the display
+ scale that is a line of battlefield down the side of the screen and along the bottom, which
+ is what the snap in ControlBarPanelDesignToScreen is for. Nothing may be short of an edge it
+ is supposed to be standing on. */
+ static const char *sides[] = { "America", "China", "GLA", NULL };
+ struct Res { Int w, h; };
+ static const Res screens[] =
+ {
+ { 800, 600 }, { 1024, 768 }, { 1366, 768 }, { 1920, 1080 }, { 2560, 1080 }, { 0, 0 }
+ };
+
+ for( const char **s = sides; *s; s++ )
+ for( const Res *r = screens; r->w; r++ )
+ {
+ IRegion2D rect;
+
+ const ControlBarPlate *left = ControlBarPlateForSide( AsciiString( *s ), ControlBar::CB_PANEL_LEFT );
+ CHECK( left != NULL );
+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_LEFT, &left->design, r->w, r->h, &rect ) );
+ CHECK_EQ( rect.lo.x, 0 );
+ CHECK_EQ( rect.hi.y, r->h );
+
+ const ControlBarPlate *centre = ControlBarPlateForSide( AsciiString( *s ), ControlBar::CB_PANEL_CENTER );
+ CHECK( centre != NULL );
+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_CENTER, &centre->design, r->w, r->h, &rect ) );
+ CHECK_EQ( rect.hi.y, r->h );
+
+ const ControlBarPlate *right = ControlBarPlateForSide( AsciiString( *s ), ControlBar::CB_PANEL_RIGHT );
+ CHECK( right != NULL );
+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_RIGHT, &right->design, r->w, r->h, &rect ) );
+ CHECK_EQ( rect.hi.x, r->w );
+ CHECK_EQ( rect.hi.y, r->h );
+ }
+
+ /* the snap is for an edge a rectangle was meant to reach, not for one it deliberately stops
+ short of - the two gaps the three panels open at 16:9 are not edges and stay open */
+ IRegion2D middle;
+ middle.lo.x = 300;
+ middle.lo.y = 500;
+ middle.hi.x = 500;
+ middle.hi.y = 560;
+
+ IRegion2D rect;
+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_LEFT, &middle, 1920, 1080, &rect ) );
+ CHECK( rect.lo.x > 0 );
+ CHECK( rect.hi.y < 1080 );
+ CHECK( ControlBarPanelDesignToScreen( ControlBar::CB_PANEL_RIGHT, &middle, 1920, 1080, &rect ) );
+ CHECK( rect.hi.x < 1920 );
+}
+
/* 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