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): svg signal icons, rising keys, exact gradient fills

Olcay Seygan933d640e00fe
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txt
index c6d270f98..57be7b1b8 100644
--- a/GeneralsMD/Code/CMakeLists.txt
+++ b/GeneralsMD/Code/CMakeLists.txt
@@ -31,7 +31,8 @@ foreach(vendored
${COMP}/LZHCompress/CompLibSource/Lzhl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/DirectX/Include/d3d8.h
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/GameSpy/CMakeLists.txt
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/litehtml/CMakeLists.txt)
+ ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/litehtml/CMakeLists.txt
+ ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/nanosvg/nanosvgrast.h)
if(NOT EXISTS ${vendored})
message(FATAL_ERROR
"${vendored} is missing. Run Tools\\vendor.ps1 (build.bat does it for you).")
@@ -532,7 +533,9 @@ target_include_directories(gameengine PUBLIC
# WW3D2 is here for d3dx9math.h alone: BezierSegment carries D3DXMATRIX, and
# DumbProjectileBehavior steers a shell with it. dinput.h now comes out of the
# Windows SDK like d3d9.h does.
- ${WW}/WW3D2)
+ ${WW}/WW3D2
+ # nanosvg's two headers, compiled into HtmlOverlay.cpp alone: the SVG pictures a page names.
+ ${LIBSRC}/nanosvg)
# _RELEASE/_DEBUG pick the game's own build flavour; IG_DEBUG_STACKTRACE and
# Z_PREFIX are what GameEngine.dsp sets.
target_compile_definitions(gameengine PUBLIC
diff --git a/GeneralsMD/Code/Data/Window/Html/ControlBar.html b/GeneralsMD/Code/Data/Window/Html/ControlBar.html
index 0cb8ef560..7f450af30 100644
--- a/GeneralsMD/Code/Data/Window/Html/ControlBar.html
+++ b/GeneralsMD/Code/Data/Window/Html/ControlBar.html
@@ -29,7 +29,9 @@
{{signals.x}} ... the column of smoke signal buttons against the left panel;
data-click="signal:attack", "signal:defend" or "signal:look" sends one
to the middle of the view, and {{signals}} is "disabled" where the keys
- would do nothing either
+ would do nothing either; {{signal0.drop}} to {{signal2.drop}} how far
+ below its place each button still is while they rise into the column
+ url(Name.svg) an SVG file under Window/Html, fitted whole into the box and centred
{{net.clock}} ... the network box: net.clock, net.game, net.real, net.hz, net.fps,
net.renderer and net.frame always; net.ready, net.runahead, net.room,
net.in and net.out with {{net.online}} "online" in a network game;
@@ -183,26 +185,33 @@
.skillcell { margin: 1px 0 0 1px; }
/* the smoke signals: a step of the radar's bezel on its right, the same steel carried on at the
- shade the bezel has at that height, with its own lit top edge and a joint over the bezel's dark
- right line so the two read as one piece. Three caps sit in it, each with a picture drawn in
- pixels: a crosshair to attack, a shield to defend, an eye to look. Greyed where the keys would
- do nothing either, outside a multiplayer game */
+ shade the bezel has at that height, with its own lit top edge, and a joint over the bezel's dark
+ right line so the two read as one piece. Three keys sunk in it like the radar is, each an SVG in one
+ colour, a crosshair to attack, a shield to defend, an eye to look. Under the pointer a key
+ comes up out of its well as lit steel with a gold rim. Veiled where the keys would do nothing
+ either, outside a multiplayer game */
.signals { background: linear-gradient(to bottom, #4f575f, #353c45); border-top: 1px solid #dde4ea; border-right: 1px solid #0c1114; }
.signals .joint { position: absolute; left: -1px; top: 0; bottom: 0; width: 1px; background: linear-gradient(to bottom, #4f575f, #353c45); }
.china .signals, .china .signals .joint { background: linear-gradient(to bottom, #6a2a1c, #3f160f); }
.china .signals { border-top-color: #f0b8a4; }
.gla .signals, .gla .signals .joint { background: linear-gradient(to bottom, #665b31, #3c3519); }
.gla .signals { border-top-color: #ebe2b4; }
- /* each cap stands at its own top: a relatively placed box inside an absolutely placed one is
- laid out from the screen's corner here, and the column came out in the top left */
- .signals .signal { position: absolute; left: 3px; width: 32px; height: 18px; }
- .signal .icon { position: absolute; }
- .signal .px { position: absolute; }
- .signal.attack .px { background-color: #ff6a50; }
- .signal.defend .px { background-color: #7ab8f5; }
- .signal.defend .px.inner { background-color: #2a5a90; }
- .signal.look .px { background-color: #f4dc78; }
- .signals.disabled .signal .px { background-color: #6f7782; }
+ /* each key stands at its own top, pushed down by {{signalN.drop}} while it rises: a relatively
+ placed box inside an absolutely placed one is laid out from the screen's corner here, and the
+ column came out in the top left */
+ .signals .signal { position: absolute; left: 3px; width: 32px; height: 18px; background-color: rgba(4, 8, 10, 0.9);
+ border: 1px solid #06090b; border-bottom-color: #9aa4ae; border-right-color: #9aa4ae; }
+ .signals .signal:hover { background: linear-gradient(to bottom, #b3bbc4, #5a626c); border-color: #e8d27a; }
+ .china .signals .signal:hover { background: linear-gradient(to bottom, #d58a70, #7a3120); }
+ .gla .signals .signal:hover { background: linear-gradient(to bottom, #cabe86, #766a3a); }
+ .signal .icon { position: absolute; left: 9px; top: 2px; width: 14px; height: 14px;
+ background-size: 100% 100%; background-repeat: no-repeat; }
+ .signal.attack .icon { background-image: url(Icons/SignalAttack.svg); }
+ .signal.defend .icon { background-image: url(Icons/SignalDefend.svg); }
+ .signal.look .icon { background-image: url(Icons/SignalLook.svg); }
+ .signal .veil { display: none; }
+ .signals.disabled .signal .veil { display: block; position: absolute; left: 0; top: 0; width: 32px; height: 18px;
+ background-color: rgba(4, 8, 10, 0.65); }
/* the network box: everything the corner readout had, flush in the screen's top right corner */
#net { right: 0; top: 0; padding: 3px 6px 3px 8px; border-right: 0; font-size: 7px; color: #c9d2d9; text-align: right; }
@@ -241,45 +250,9 @@
<div class="piece signals solid {{signals.shown}} {{signals}}" style="left: {{signals.x}}px; top: {{signals.y}}px; width: {{signals.w}}px; height: {{signals.h}}px">
<div class="joint"></div>
- <div class="button signal attack" data-click="signal:attack" style="top: 3px"><div class="icon" style="left: 10px; top: 3px">
- <div class="px" style="left: 5px; top: 0; width: 1px; height: 4px"></div>
- <div class="px" style="left: 5px; top: 7px; width: 1px; height: 4px"></div>
- <div class="px" style="left: 0; top: 5px; width: 4px; height: 1px"></div>
- <div class="px" style="left: 7px; top: 5px; width: 4px; height: 1px"></div>
- <div class="px" style="left: 5px; top: 5px; width: 1px; height: 1px"></div>
- <div class="px" style="left: 1px; top: 1px; width: 3px; height: 1px"></div>
- <div class="px" style="left: 1px; top: 1px; width: 1px; height: 3px"></div>
- <div class="px" style="left: 7px; top: 1px; width: 3px; height: 1px"></div>
- <div class="px" style="left: 9px; top: 1px; width: 1px; height: 3px"></div>
- <div class="px" style="left: 1px; top: 9px; width: 3px; height: 1px"></div>
- <div class="px" style="left: 1px; top: 7px; width: 1px; height: 3px"></div>
- <div class="px" style="left: 7px; top: 9px; width: 3px; height: 1px"></div>
- <div class="px" style="left: 9px; top: 7px; width: 1px; height: 3px"></div>
- </div></div>
- <div class="button signal defend" data-click="signal:defend" style="top: 27px"><div class="icon" style="left: 10px; top: 3px">
- <div class="px" style="left: 0; top: 0; width: 11px; height: 6px"></div>
- <div class="px" style="left: 1px; top: 6px; width: 9px; height: 1px"></div>
- <div class="px" style="left: 2px; top: 7px; width: 7px; height: 1px"></div>
- <div class="px" style="left: 3px; top: 8px; width: 5px; height: 1px"></div>
- <div class="px" style="left: 4px; top: 9px; width: 3px; height: 1px"></div>
- <div class="px" style="left: 5px; top: 10px; width: 1px; height: 1px"></div>
- <div class="px inner" style="left: 5px; top: 1px; width: 1px; height: 8px"></div>
- </div></div>
- <div class="button signal look" data-click="signal:look" style="top: 51px"><div class="icon" style="left: 9px; top: 5px">
- <div class="px" style="left: 4px; top: 0; width: 5px; height: 1px"></div>
- <div class="px" style="left: 2px; top: 1px; width: 2px; height: 1px"></div>
- <div class="px" style="left: 9px; top: 1px; width: 2px; height: 1px"></div>
- <div class="px" style="left: 1px; top: 2px; width: 1px; height: 1px"></div>
- <div class="px" style="left: 11px; top: 2px; width: 1px; height: 1px"></div>
- <div class="px" style="left: 0; top: 3px; width: 1px; height: 1px"></div>
- <div class="px" style="left: 12px; top: 3px; width: 1px; height: 1px"></div>
- <div class="px" style="left: 1px; top: 4px; width: 1px; height: 1px"></div>
- <div class="px" style="left: 11px; top: 4px; width: 1px; height: 1px"></div>
- <div class="px" style="left: 2px; top: 5px; width: 2px; height: 1px"></div>
- <div class="px" style="left: 9px; top: 5px; width: 2px; height: 1px"></div>
- <div class="px" style="left: 4px; top: 6px; width: 5px; height: 1px"></div>
- <div class="px" style="left: 5px; top: 2px; width: 3px; height: 3px"></div>
- </div></div>
+ <div class="signal attack" data-click="signal:attack" style="top: 3px; margin-top: {{signal0.drop}}px"><div class="icon"></div><div class="veil"></div></div>
+ <div class="signal defend" data-click="signal:defend" style="top: 27px; margin-top: {{signal1.drop}}px"><div class="icon"></div><div class="veil"></div></div>
+ <div class="signal look" data-click="signal:look" style="top: 51px; margin-top: {{signal2.drop}}px"><div class="icon"></div><div class="veil"></div></div>
</div>
<div class="piece skillcell well" data-each="skillcells" style="left: {{cell.x}}px; top: {{cell.y}}px; width: {{cell.w}}px; height: {{cell.h}}px"></div>
diff --git a/GeneralsMD/Code/Data/Window/Html/Icons/SignalAttack.svg b/GeneralsMD/Code/Data/Window/Html/Icons/SignalAttack.svg
new file mode 100644
index 000000000..5aef2c2dc
--- /dev/null
+++ b/GeneralsMD/Code/Data/Window/Html/Icons/SignalAttack.svg
@@ -0,0 +1,5 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <circle cx="12" cy="12" r="7" fill="none" stroke="#eef2f5" stroke-width="2.4"/>
+ <path d="M12 1v6.5M12 16.5V23M1 12h6.5M16.5 12H23" fill="none" stroke="#eef2f5" stroke-width="2.4"/>
+ <circle cx="12" cy="12" r="2" fill="#eef2f5"/>
+</svg>
diff --git a/GeneralsMD/Code/Data/Window/Html/Icons/SignalDefend.svg b/GeneralsMD/Code/Data/Window/Html/Icons/SignalDefend.svg
new file mode 100644
index 000000000..b56ebeb54
--- /dev/null
+++ b/GeneralsMD/Code/Data/Window/Html/Icons/SignalDefend.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <path d="M12 2.2 20.3 5.2V11.4C20.3 16.6 16.9 20.2 12 22 7.1 20.2 3.7 16.6 3.7 11.4V5.2Z" fill="none" stroke="#eef2f5" stroke-width="2.2" stroke-linejoin="round"/>
+ <path d="M12 6 7.2 7.7V11.6C7.2 14.9 9.2 17.2 12 18.5Z" fill="#eef2f5"/>
+</svg>
diff --git a/GeneralsMD/Code/Data/Window/Html/Icons/SignalLook.svg b/GeneralsMD/Code/Data/Window/Html/Icons/SignalLook.svg
new file mode 100644
index 000000000..12a310388
--- /dev/null
+++ b/GeneralsMD/Code/Data/Window/Html/Icons/SignalLook.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <path d="M1.5 12C4.5 6.8 8 4.8 12 4.8S19.5 6.8 22.5 12C19.5 17.2 16 19.2 12 19.2S4.5 17.2 1.5 12Z" fill="none" stroke="#eef2f5" stroke-width="2.2" stroke-linejoin="round"/>
+ <circle cx="12" cy="12" r="4" fill="#eef2f5"/>
+</svg>
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 778119010..766f56915 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -1210,6 +1210,8 @@ protected:
Bool m_controlBarPageShown; ///< drawn this frame, so its buttons can be clicked
std::set< std::string > m_controlBarFlipped; ///< names a data-click="flip:name" on that page has flipped
std::string m_controlBarPage;
+ Bool m_signalsWereShown; ///< the smoke signal column was up last frame
+ UnsignedInt m_signalsRiseStartMs; ///< when it last came up, the start of its buttons' rise
//
// The spectator's page over the battlefield, Window/Html/Spectator.html: the drop-down that
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cpp
index e2ad4abbd..9342bce7b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/HtmlOverlay.cpp
@@ -39,9 +39,15 @@
#include <litehtml.h>
+#define NANOSVG_IMPLEMENTATION
+#define NANOSVGRAST_IMPLEMENTATION
+#include <nanosvg.h>
+#include <nanosvgrast.h>
+
#include <algorithm>
#include <map>
#include <math.h>
+#include <vector>
namespace
{
@@ -54,6 +60,9 @@ const Int BOLD_WEIGHT = 600; ///< CSS font-weight from which the game's
const Real ASCENT_SHARE = 0.8f; ///< of the font's height; GameFont only knows the height
const Real X_HEIGHT_SHARE = 0.5f;
const char *const PAGE_FOLDER = "Window\\Html\\";
+const char *const SVG_EXTENSION = ".svg";
+const char *const SVG_UNITS = "px";
+const Int RGBA_BYTES = 4;
const char *const GENERIC_FAMILIES[] = { "serif", "sans-serif", "monospace", "cursive", "fantasy", "system-ui" };
Color gameColor( const litehtml::web_color &color )
@@ -78,6 +87,12 @@ Bool isGenericFamily( const std::string &family )
return FALSE;
}
+Bool isSvg( const std::string &source )
+{
+ const size_t extension = strlen( SVG_EXTENSION );
+ return source.size() > extension && _stricmp( source.c_str() + source.size() - extension, SVG_EXTENSION ) == 0;
+}
+
} // namespace
//-------------------------------------------------------------------------------------------------
@@ -143,6 +158,16 @@ private:
};
typedef std::map< std::pair< GameFont *, std::string >, CachedString > StringCache;
+ /** A row of pixels of one colour in a rasterised SVG, from the box's corner, in screen pixels. */
+ struct SvgRun
+ {
+ Int x;
+ Int y;
+ Int length;
+ Color color;
+ };
+ typedef std::vector< SvgRun > SvgRuns;
+
Int screen( litehtml::pixel_t pagePixels ) const { return (Int)floorf( pagePixels * m_scale + 0.5f ); }
litehtml::pixel_t page( Int screenPixels ) const { return screenPixels / m_scale; }
litehtml::pixel_t viewportWidth( void ) const { return page( m_screenWidth ); }
@@ -150,8 +175,13 @@ private:
DisplayString *displayString( GameFont *font, const char *text );
void freeStrings( Bool all );
void fillBox( const litehtml::position &box, const litehtml::web_color &color );
+ NSVGimage *svgImage( const std::string &source );
+ const SvgRuns &svgRuns( const std::string &source, Int width, Int height );
std::string m_defaultFont;
+ NSVGrasterizer * m_rasterizer;
+ std::map< std::string, NSVGimage * > m_svgImages; ///< by page path; NULL for a file missing or unreadable
+ std::map< std::string, SvgRuns > m_svgRuns; ///< by page path and screen size
std::string m_page;
litehtml::document::ptr m_document;
Real m_scale;
@@ -165,6 +195,7 @@ private:
//-------------------------------------------------------------------------------------------------
HtmlOverlayContainer::HtmlOverlayContainer( const AsciiString &defaultFont ) :
m_defaultFont( defaultFont.str() ),
+ m_rasterizer( nsvgCreateRasterizer() ),
m_scale( 1.0f ),
m_screenWidth( 0 ),
m_screenHeight( 0 ),
@@ -177,6 +208,10 @@ HtmlOverlayContainer::~HtmlOverlayContainer( void )
{
m_document = nullptr;
freeStrings( TRUE );
+ for( std::map< std::string, NSVGimage * >::iterator image = m_svgImages.begin(); image != m_svgImages.end(); ++image )
+ if( image->second )
+ nsvgDelete( image->second );
+ nsvgDeleteRasterizer( m_rasterizer );
}
//-------------------------------------------------------------------------------------------------
@@ -377,22 +412,116 @@ void HtmlOverlayContainer::draw_text( litehtml::uint_ptr hdc, const char *text,
//-------------------------------------------------------------------------------------------------
void HtmlOverlayContainer::get_image_size( const char *source, const char *baseUrl, litehtml::size &size )
{
+ if( isSvg( source ) )
+ {
+ const NSVGimage *picture = svgImage( source );
+ size.width = picture ? picture->width : 0;
+ size.height = picture ? picture->height : 0;
+ return;
+ }
+
const Image *image = TheMappedImageCollection->findImageByName( AsciiString( source ) );
size.width = image ? (litehtml::pixel_t)image->getImageWidth() : 0;
size.height = image ? (litehtml::pixel_t)image->getImageHeight() : 0;
}
//-------------------------------------------------------------------------------------------------
-/** An image source is the name of one of the game's mapped images, and it is stretched over the box. */
+/** An image source is the name of one of the game's mapped images, stretched over the box, or a .svg
+ * file beside the pages, fitted into the box whole and centred. */
void HtmlOverlayContainer::draw_image( litehtml::uint_ptr hdc, const litehtml::background_layer &layer,
const std::string &url, const std::string &baseUrl )
{
- const Image *image = TheMappedImageCollection->findImageByName( AsciiString( url.c_str() ) );
- if( image == NULL || layer.is_root )
+ if( layer.is_root )
return;
const litehtml::position &box = layer.origin_box;
- TheDisplay->drawImage( image, screen( box.x ), screen( box.y ), screen( box.x + box.width ), screen( box.y + box.height ) );
+ const Int left = screen( box.x );
+ const Int top = screen( box.y );
+ const Int right = screen( box.x + box.width );
+ const Int bottom = screen( box.y + box.height );
+ if( isSvg( url ) )
+ {
+ const SvgRuns &runs = svgRuns( url, right - left, bottom - top );
+ for( SvgRuns::const_iterator run = runs.begin(); run != runs.end(); ++run )
+ TheDisplay->drawFillRect( left + run->x, top + run->y, run->length, 1, run->color );
+ return;
+ }
+
+ const Image *image = TheMappedImageCollection->findImageByName( AsciiString( url.c_str() ) );
+ if( image )
+ TheDisplay->drawImage( image, left, top, right, bottom );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A .svg beside the pages, parsed once. */
+NSVGimage *HtmlOverlayContainer::svgImage( const std::string &source )
+{
+ std::map< std::string, NSVGimage * >::iterator found = m_svgImages.find( source );
+ if( found != m_svgImages.end() )
+ return found->second;
+
+ NSVGimage *picture = NULL;
+ const std::string path = std::string( PAGE_FOLDER ) + source;
+ File *file = TheFileSystem->openFile( path.c_str(), File::READ | File::BINARY );
+ if( file == NULL )
+ DEBUG_LOG(( "HtmlOverlay: the picture %s is missing\n", path.c_str() ));
+ else
+ {
+ const Int size = file->size();
+ char *contents = file->readEntireAndClose();
+ std::vector< char > text( contents, contents + size );
+ delete [] contents;
+ text.push_back( '\0' );
+ picture = nsvgParse( &text[ 0 ], SVG_UNITS, (float)BROWSER_DPI );
+ }
+ m_svgImages[ source ] = picture;
+ return picture;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** A .svg rasterised at `width` by `height` screen pixels, kept as rows of one colour so the game's
+ * rectangle fill can draw it; once per size, since the picture itself never changes. */
+const HtmlOverlayContainer::SvgRuns &HtmlOverlayContainer::svgRuns( const std::string &source, Int width, Int height )
+{
+ const std::string key = source + "@" + std::to_string( width ) + "x" + std::to_string( height );
+ std::map< std::string, SvgRuns >::iterator found = m_svgRuns.find( key );
+ if( found != m_svgRuns.end() )
+ return found->second;
+
+ SvgRuns &runs = m_svgRuns[ key ];
+ NSVGimage *picture = svgImage( source );
+ if( picture == NULL || width <= 0 || height <= 0 || picture->width <= 0 || picture->height <= 0 )
+ return runs;
+
+ const float scale = std::min( width / picture->width, height / picture->height );
+ const float offsetX = ( width - picture->width * scale ) / 2;
+ const float offsetY = ( height - picture->height * scale ) / 2;
+ std::vector< unsigned char > pixels( width * height * RGBA_BYTES );
+ nsvgRasterize( m_rasterizer, picture, offsetX, offsetY, scale, &pixels[ 0 ], width, height, width * RGBA_BYTES );
+
+ for( Int y = 0; y < height; y++ )
+ {
+ const unsigned char *row = &pixels[ y * width * RGBA_BYTES ];
+ Int x = 0;
+ while( x < width )
+ {
+ const unsigned char *pixel = row + x * RGBA_BYTES;
+ Int length = 1;
+ while( x + length < width && memcmp( pixel, row + ( x + length ) * RGBA_BYTES, RGBA_BYTES ) == 0 )
+ length++;
+ if( pixel[ 3 ] > 0 )
+ {
+ SvgRun run;
+ run.x = x;
+ run.y = y;
+ run.length = length;
+ run.color = GameMakeColor( pixel[ 0 ], pixel[ 1 ], pixel[ 2 ], pixel[ 3 ] );
+ runs.push_back( run );
+ }
+ x += length;
+ }
+ }
+ return runs;
}
//-------------------------------------------------------------------------------------------------
@@ -416,8 +545,10 @@ void HtmlOverlayContainer::draw_solid_fill( litehtml::uint_ptr hdc, const liteht
}
//-------------------------------------------------------------------------------------------------
-/** A line as thick as the box, run along whichever axis the gradient runs further on, one line per
- * pair of stops: the game's two-colour line blends between its ends. */
+/** One row or column of pixels at a time across the box, along whichever axis the gradient runs
+ * further on, each filled with the colour its stops blend to there. A line as thick as the box,
+ * blended between its ends, was the first way: the line takes whole-pixel centres, so a box an odd
+ * number of pixels wide came out a pixel short on one side and let what was under it show. */
void HtmlOverlayContainer::draw_linear_gradient( litehtml::uint_ptr hdc, const litehtml::background_layer &layer,
const litehtml::background_layer::linear_gradient &gradient )
{
@@ -434,27 +565,35 @@ void HtmlOverlayContainer::draw_linear_gradient( litehtml::uint_ptr hdc, const l
const Real runX = gradient.end.x - gradient.start.x;
const Real runY = gradient.end.y - gradient.start.y;
const Bool across = fabsf( runX ) >= fabsf( runY );
- const Int middle = across ? ( screen( box.y ) + screen( box.y + box.height ) ) / 2
- : ( screen( box.x ) + screen( box.x + box.width ) ) / 2;
- const Real thickness = across ? (Real)( screen( box.y + box.height ) - screen( box.y ) )
- : (Real)( screen( box.x + box.width ) - screen( box.x ) );
+ const Int left = screen( box.x );
+ const Int top = screen( box.y );
+ const Int right = screen( box.x + box.width );
+ const Int bottom = screen( box.y + box.height );
+ const Int first = across ? left : top;
+ const Int last = across ? right : bottom;
+ const Real start = across ? gradient.start.x : gradient.start.y;
+ const Real run = across ? runX : runY;
+ if( right <= left || bottom <= top || run == 0 )
+ return;
- for( size_t stop = 0; stop + 1 < stops.size(); stop++ )
+ size_t stop = 0;
+ for( Int pixel = first; pixel < last; pixel++ )
{
- const Color from = gameColor( stops[ stop ].color );
- const Color to = gameColor( stops[ stop + 1 ].color );
+ const Real offset = ( page( pixel ) + page( 1 ) / 2 - start ) / run;
+ while( stop + 2 < stops.size() && offset > stops[ stop + 1 ].offset )
+ stop++;
+ const litehtml::web_color &from = stops[ stop ].color;
+ const litehtml::web_color &to = stops[ stop + 1 ].color;
+ const Real span = stops[ stop + 1 ].offset - stops[ stop ].offset;
+ const Real share = span > 0 ? std::min( 1.0f, std::max( 0.0f, ( offset - stops[ stop ].offset ) / span ) ) : 0.0f;
+ const Color color = GameMakeColor( REAL_TO_INT( from.red + ( to.red - from.red ) * share ),
+ REAL_TO_INT( from.green + ( to.green - from.green ) * share ),
+ REAL_TO_INT( from.blue + ( to.blue - from.blue ) * share ),
+ REAL_TO_INT( from.alpha + ( to.alpha - from.alpha ) * share ) );
if( across )
- {
- const Int startX = screen( gradient.start.x + runX * stops[ stop ].offset );
- const Int endX = screen( gradient.start.x + runX * stops[ stop + 1 ].offset );
- TheDisplay->drawLine( startX, middle, endX, middle, thickness, from, to );
- }
+ TheDisplay->drawFillRect( pixel, top, 1, bottom - top, color );
else
- {
- const Int startY = screen( gradient.start.y + runY * stops[ stop ].offset );
- const Int endY = screen( gradient.start.y + runY * stops[ stop + 1 ].offset );
- TheDisplay->drawLine( middle, startY, middle, endY, thickness, from, to );
- }
+ TheDisplay->drawFillRect( left, pixel, right - left, 1, color );
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 16eeef3bf..a3b36daca 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1203,6 +1203,8 @@ InGameUI::InGameUI()
m_controlBarOverlay = NULL;
m_controlBarPageLoaded = FALSE;
m_controlBarPageShown = FALSE;
+ m_signalsWereShown = FALSE;
+ m_signalsRiseStartMs = 0;
for( Int stripSeconds = 0; stripSeconds < STRIP_SECONDS_STRINGS; stripSeconds++ )
m_stripSecondsString[ stripSeconds ] = NULL;
for( Int stripQuantity = 0; stripQuantity < STRIP_QUANTITY_STRINGS; stripQuantity++ )
@@ -3873,6 +3875,7 @@ void InGameUI::reset( void )
m_scoreboardPageLoaded = FALSE;
m_controlBarPageLoaded = FALSE;
m_controlBarFlipped.clear();
+ m_signalsWereShown = FALSE;
m_spectatorPageLoaded = FALSE;
m_spectatorFlipped.clear();
m_spectatorPicked.clear();
@@ -10262,7 +10265,7 @@ enum
SKILL_GRID_WIDTH = 150, ///< the general's powers, three to a row, against the screen's right edge
SKILL_GRID_GAP = 30, ///< between them and the skills button
SIGNAL_BUTTON_SIZE = 24, ///< each smoke signal button's height, a row of the column
- SIGNAL_BUTTON_WIDTH = 40, ///< and its width, room for its word in either language
+ SIGNAL_BUTTON_WIDTH = 40, ///< and its width, room for its picture
SIGNAL_BUTTONS = 3, ///< attack, defend, look
SKILL_GRID_ROWS = 3, ///< the empty places drawn behind the powers
SKILL_GRID_COLUMNS = 3,
@@ -10271,6 +10274,22 @@ enum
WORKER_TAB_WIDTH = 44 ///< the idle worker button, on the command grid panel's border
};
static const char *const SKILLS_FOLDED = "skills"; ///< the flip the skills button toggles; flipped is folded away
+static const UnsignedInt SIGNAL_RISE_MS = 360; ///< each smoke signal button's climb out of the screen's bottom edge
+static const UnsignedInt SIGNAL_RISE_STAGGER_MS = 90; ///< between one button starting and the next
+
+/** `signalN.drop`, N 0 to 2, how far below its place each smoke signal button still is, in page
+ * pixels, `elapsedMs` after the column came up: each starts a stagger after the one above it and
+ * slows as it arrives, the whole column's height to nothing. */
+static void putSignalRise( HtmlValues &values, UnsignedInt elapsedMs )
+{
+ for( Int button = 0; button < SIGNAL_BUTTONS; button++ )
+ {
+ const Real started = (Real)elapsedMs - (Real)( button * SIGNAL_RISE_STAGGER_MS );
+ const Real progress = min( 1.0f, max( 0.0f, started / SIGNAL_RISE_MS ) );
+ const Real remaining = ( 1.0f - progress ) * ( 1.0f - progress ) * ( 1.0f - progress );
+ values[ "signal" + std::to_string( button ) + ".drop" ] = std::to_string( REAL_TO_INT( remaining * SIGNAL_BUTTON_SIZE * SIGNAL_BUTTONS ) );
+ }
+}
static const char *const CORNER_BUTTONS[] = { "ButtonGeneral" };
static void drawNothing( GameWindow *window, WinInstanceData *instData )
@@ -10570,6 +10589,11 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, I
signalColumn.hi.y = TheDisplay->getHeight();
signalColumn.lo.y = signalColumn.hi.y - REAL_TO_INT( SIGNAL_BUTTON_SIZE * SIGNAL_BUTTONS * scale );
putPageRect( values, "signals", signalColumn, leftFound && leftShown );
+ const UnsignedInt nowMs = timeGetTime();
+ if( leftFound && leftShown && !m_signalsWereShown )
+ m_signalsRiseStartMs = nowMs;
+ m_signalsWereShown = leftFound && leftShown;
+ putSignalRise( values, nowMs - m_signalsRiseStartMs );
IRegion2D centreBox;
stackCentre( values, panelCount > 1 && shown[ 1 ], centreBox );
diff --git a/GeneralsMD/Code/Libraries/Source/nanosvg/.gitignore b/GeneralsMD/Code/Libraries/Source/nanosvg/.gitignore
new file mode 100644
index 000000000..5e7d2734c
--- /dev/null
+++ b/GeneralsMD/Code/Libraries/Source/nanosvg/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
diff --git a/GeneralsMD/Code/Tools/vendor.ps1 b/GeneralsMD/Code/Tools/vendor.ps1
index 98286f263..b3a9e53e6 100644
--- a/GeneralsMD/Code/Tools/vendor.ps1
+++ b/GeneralsMD/Code/Tools/vendor.ps1
@@ -132,6 +132,18 @@ function Install-Litehtml {
Step "litehtml 0.10 -> Libraries\Source\litehtml"
}
+# --- nanosvg, the two headers: parses and rasterises the SVG pictures a page names in url(), which
+# the game then draws pixel by pixel. Same .gitignore dance as litehtml.
+function Install-Nanosvg {
+ $destination = Join-Path $libraries 'Source\nanosvg'
+ if ((Test-Path (Join-Path $destination 'nanosvgrast.h')) -and -not $Force) { return }
+ $archive = Get-File 'https://github.com/memononen/nanosvg/archive/239e102ec2c691f2902e20ace2ed36ee4a35cfe6.zip' (Join-Path $work 'nanosvg.zip')
+ $source = Expand-Source $archive 'nanosvg'
+ Copy-Files (Get-TopLevel (Join-Path $source 'src') @('.h')) $destination
+ Copy-Item (Join-Path $source 'LICENSE.txt') $destination -Force
+ Step "nanosvg -> Libraries\Source\nanosvg"
+}
+
# --- The fork's own upscaled art: every 3D texture at twice its size, the normal maps the models
# are lit through, and the ground. Not in git - ReforgedTextures.big alone is a gigabyte, ten times
# what GitHub takes in a file, and LFS in a fork is billed to the parent repository.
@@ -235,5 +247,6 @@ Install-Lzhl
Install-DirectX
Install-GameSpy
Install-Litehtml
+Install-Nanosvg
Install-Art
Step 'everything the build needs is in place'