Skip to content

bugfix(gui): implement resolution scaling for unit health and info - #1607

Open
Mauller wants to merge 2 commits into
TheSuperHackers:mainfrom
Mauller:fix-unit-info-res-scaling
Open

bugfix(gui): implement resolution scaling for unit health and info#1607
Mauller wants to merge 2 commits into
TheSuperHackers:mainfrom
Mauller:fix-unit-info-res-scaling

Conversation

@Mauller

@Mauller Mauller commented Sep 19, 2025

Copy link
Copy Markdown

This PR implements raw resolution and aspect ratio scaling for the unit health bar and other info icons.
This PR also adds functions to the display for calculating the display width and height relative to the default resolutions. And a function to calculate the diference in the current aspect ratio from the default.

Zoom based scaling to keep unit info scaled relative to units will be looked at in another PR.

There is also a small fix for the veterancy icon positioning as this was not implemented properly in the original code and broke when the health bar is scaled properly.

The only thing not scaled in this at the moment is the bombed icons, these will be dealt with in another PR.
This is due to icon placement changes being required so the icon is placed on the target instead of at the feet of the unit placing the bomb.

Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp Outdated

// do this so health bar doesn't get too skinny or fat after scaling
//healthBoxHeight = max(3.0f, healthBoxHeight);
healthBoxHeight = 3.0f;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retrieved health box height from the object is already 3.0f, at higher resoutions this code prevents the health box from scaling relative to the vehicles and looks wrong. Which is why i removed it.

I reinstated the clamp on the max size of the health bar to prevent it shrinking too much when the resolution is scaled. This will also come into play more when zoom scaling is added.

@Mauller Mauller self-assigned this Sep 19, 2025
@Mauller Mauller added Bug Something is not working right, typically is user facing GUI For graphical user interface Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Major Severity: Minor < Major < Critical < Blocker and removed Minor Severity: Minor < Major < Critical < Blocker labels Sep 19, 2025
@xezon

xezon commented Sep 20, 2025

Copy link
Copy Markdown

Is this a piece split off of #1573 ?

@Mauller

Mauller commented Sep 20, 2025

Copy link
Copy Markdown
Author

Is this a piece split off of #1573 ?

Yes, this only implements the resolution scaling of the UI elements and some small fixes to the veterancy icon and compute health region code.

I did not close the original as I will build the zoom scaling off this pr when finalised and merged.

Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp Outdated
Comment thread GeneralsMD/Code/GameEngine/Include/GameClient/Display.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Include/GameClient/Display.h Outdated
@@ -2959,8 +2954,8 @@ void Drawable::drawContained( const IRegion2D *healthBarRegion )
#else
Real scale = 1.0f;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like EA already tried to do some scaling here with TheGlobalData->m_ammoPipScaleFactor in SCALE_ICONS_WITH_ZOOM_ML. Does SCALE_ICONS_WITH_ZOOM_ML still have any relevance? What does it do? If it is not useful, can that be removed before we add a new scaling for it?

@Mauller Mauller Sep 20, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scale icons with zoom does not have any real relevance once I properly implement the zoom scaling.

But the idea was to rescale the info icons as you zoomed into units so their size was kept uniform relative to the health bar. Which is what I reimplemented.

We could still make use of the pipscale factor though.

Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp Outdated
Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp Outdated
@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 20904b1 to 09d6dae Compare September 20, 2025 16:17
@Mauller

Mauller commented Sep 20, 2025

Copy link
Copy Markdown
Author

Quick Rebase

@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 09d6dae to d068267 Compare September 20, 2025 17:11
@Mauller

Mauller commented Sep 20, 2025

Copy link
Copy Markdown
Author

Tweaked this now so the followup can implement user based options within InGameUI.

This version also reduces the overhead a little since the scaling factor is only calculated once at initialisation and when the resolution gets changed.

So with this, the unit info acts the same as with retail, but scales all the unit gui elements properly with resolution.

Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp Outdated
@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from d068267 to a64a7ee Compare September 21, 2025 09:45
@Mauller

Mauller commented Sep 21, 2025

Copy link
Copy Markdown
Author

Moved the scale variable into the SCALE_ICONS_WITH_ZOOM_ML for the draw veterancy function

@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from a64a7ee to c172cfe Compare September 21, 2025 10:00
@Mauller

Mauller commented Sep 21, 2025

Copy link
Copy Markdown
Author

Tweaked veterancy icon position, it should be in exactly the same place now, it might look slightly offset but that's actually the health bar being marginally shifted left due to the above mentioned change.

@xezon

xezon commented Sep 21, 2025

Copy link
Copy Markdown

Health bar size is not correct on higher solution.

In 800x600, health bar is 1 pixel high. In 1600x1200 it is 4 pixels high.

healthbar

@Mauller

Mauller commented Sep 21, 2025

Copy link
Copy Markdown
Author

Health bar size is not correct on higher solution.

In 800x600, health bar is 1 pixel high. In 1600x1200 it is 4 pixels high.

healthbar

Yes because it's scaling with the resolution, it's proportions are the same compared to 800x600

If the health bar remaind the same thickness as it is at 800x600 then you will barely see anything of it at higher resolutions.

@xezon

xezon commented Sep 21, 2025

Copy link
Copy Markdown

I think it is wrong. If health bar is 1px at 800x600, then it should be 2px at 1600x1200.

@Mauller

Mauller commented Sep 21, 2025

Copy link
Copy Markdown
Author

I think it is wrong. If health bar is 1px at 800x600, then it should be 2px at 1600x1200.

Its not wrong, it's because of the way the health bar is setup. The border does not scale with the health bar and remains at only 1 pixel in height.

The health bar region is 6 pixels high, which is double the default of 3 at 800x600, but there is always a 1 pixel border.

This means that at 800x600 there is only a single pixel for the health bar info itself while theres 4 at 1600x1200

So overall the health bar is scaled properly, it's just that relatively more of the health bar is taken up by the border at 800x600

@Mauller

Mauller commented Sep 21, 2025

Copy link
Copy Markdown
Author

The other way to work this would be to also scale the health bar border at higher resolutions, it would also make the health bar more visible when health is getting depleted and should keep the health info itself scaled similar to 800x600

Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp Outdated
Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp Outdated
@xezon

xezon commented Sep 21, 2025

Copy link
Copy Markdown

I think it is wrong. If health bar is 1px at 800x600, then it should be 2px at 1600x1200.

Its not wrong, it's because of the way the health bar is setup. The border does not scale with the health bar and remains at only 1 pixel in height.

The health bar region is 6 pixels high, which is double the default of 3 at 800x600, but there is always a 1 pixel border.

This means that at 800x600 there is only a single pixel for the health bar info itself while theres 4 at 1600x1200

So overall the health bar is scaled properly, it's just that relatively more of the health bar is taken up by the border at 800x600

I think visually it should look twice as big. Right now it looks 4 times as big.

@Mauller

Mauller commented Sep 21, 2025

Copy link
Copy Markdown
Author

I think it is wrong. If health bar is 1px at 800x600, then it should be 2px at 1600x1200.

Its not wrong, it's because of the way the health bar is setup. The border does not scale with the health bar and remains at only 1 pixel in height.
The health bar region is 6 pixels high, which is double the default of 3 at 800x600, but there is always a 1 pixel border.
This means that at 800x600 there is only a single pixel for the health bar info itself while theres 4 at 1600x1200
So overall the health bar is scaled properly, it's just that relatively more of the health bar is taken up by the border at 800x600

I think visually it should look twice as big. Right now it looks 4 times as big.

I am working on something that should do that, some of the functions aren't working quite right for drawing rectangles with outlines so just currently investigating that.

@xezon xezon added Enhancement Is new feature or request and removed Bug Something is not working right, typically is user facing labels Sep 23, 2025
@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 6ca0750 to bdca8c3 Compare September 23, 2025 19:23
@Mauller

Mauller commented Sep 23, 2025

Copy link
Copy Markdown
Author

Should be looking better now, ho ho ho.

@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch 3 times, most recently from 4b5bfae to 542f98b Compare September 26, 2025 17:17
@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 542f98b to f7f2ee4 Compare November 19, 2025 18:06
@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from d75242a to 33cdc71 Compare November 28, 2025 17:17
@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 33cdc71 to 58d6451 Compare December 12, 2025 14:36
@Mauller

Mauller commented Dec 12, 2025

Copy link
Copy Markdown
Author

Quick rebase to catch up with main

@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 58d6451 to 335f413 Compare December 12, 2025 17:22
@Mauller

Mauller commented Dec 12, 2025

Copy link
Copy Markdown
Author

Removed the changes from the extra commit and integer scale the health bar height now based on screen height scale.

@xezon

xezon commented Dec 13, 2025

Copy link
Copy Markdown

Is this ready for testing?


}

Real healthBoxWidth = healthBarRegion->width();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The health bar is significantly wider than originally - at 16:9 aspect. Maybe more than twice as wide.

In principle widening is ok, because the original bar indeed looks narrow, but it looks too much in comparison. I expect this will cause complaints from long time players. I see this is mainly as pronounced in Wide Screen, so it looks like something was fixed that disproportionally affects Wide Screen Resolution. Perhaps make the default width closer to the original at 4:3 aspect (currently is a bit wider at 4:3) and then provide a User Option to scale the width, from 0 to N. This way user can fine the width to his preference, which likely will be required to satisfy taste.

Also, the fixed health bar shows a proper outline on damage, whereas the original was just one color. But this means visibility on the right side is a bit reduced. Maybe fill the right side of the health bar side with less transparency to somewhat preserve the original look more, but still show the outline. You can also play with the opacity of the outline to fine tune and compensate for visibility changes.

Left side is Original 1920x1080
Right side in Patched 1920x1080

Compared at about the same height.

image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The health bar is wider because it is scaled to how it looks compared to 800x600

In the original health bar, the drawOpenRect function was broken meaning it was not properly drawing a rectangular border when it should have been. This is shown by the weird extra pixels under the bottom of the health bar and it not being perfectly rectangular.

The fixed outline makes it easier to see the amount of damage taken and gives it a much cleaner look.

@xezon xezon Dec 14, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is fixed, which is good, but it is also now much different than the original in 16:9. And in 4:3 it is a bit wider than it used to be. This means we need to do something to give users the option to return to the original look, if they prefer it that way.

I say this, because this change would upset me to some degree and so I expect it can also cause upset for other players. And I am not even part of the super conservative group of people.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you compare 800x600 and 1600x1200 the width of the health bar is the same as retail compared to retail 800x600.

It is slightly shifted to the right due to fixes in the drawing of the health bar.

For scaling the UI elements, we were going to add the ability to change those in a followup PR, this PR was just to get things to scale up properly at higher resolutions in relation to 800x600 retail.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you force scale it to retail now and unlock rescale with option in follow up change?

@Mauller Mauller Jan 20, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep the scaling relative to what it was meant to look like at 800x600 in this change as originally discussed.
It would make the code awkward when trying to scale it to 1080p in this change.
I can add the user option to rescale things in one of the folloup PR's, that way users can adjust it and we can adjust the default scale value.

I still need to add zoom scaling and fix the bombed icon stuff after this PR as well as add the user scaling options.


Real InGameUI::getUnitHealthbarScaleFactor()
{
return m_healthResolutionScaleFactor;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These scale factors are the preliminary work for adding user based scaling options, but i might tweak them a bit further in a followup PR when implementing that.

@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 335f413 to a482938 Compare April 14, 2026 21:02
@Mauller

Mauller commented Apr 14, 2026

Copy link
Copy Markdown
Author

Just updated after recent zoom handling changes, had to tweak the zoom scaling factor to replicate the original health bar width values.

This is ready to go otherwise.

@greptile-apps

greptile-apps Bot commented Apr 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds resolution-aware scaling for unit health bars and status icons and recalculates scaling after display resolution changes.

  • Adds display width and height scale helpers.
  • Applies resolution scaling to health bars, veterancy markers, and unit-information icons.
  • Updates 2D outline geometry for scaled borders.
  • Fixes the previously reported null dereference by checking healthBarRegion before veterancy positioning and rendering.

Confidence Score: 5/5

The PR appears safe to merge; the previously reported veterancy null dereference is fully fixed and no new actionable failures remain.

The latest change checks healthBarRegion before using its dimensions and drawing the veterancy icon, fully addressing the previous finding without introducing a distinct failure.

Important Files Changed

Filename Overview
Core/GameEngine/Include/GameClient/Display.h Declares helpers for deriving display scaling from the default resolution.
Core/GameEngine/Source/GameClient/Display.cpp Implements width and height resolution scale calculations.
GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp Initializes, calculates, and exposes unit-information resolution scale factors.
GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp Applies scaling to unit health and information graphics and now safely guards veterancy rendering when its health region is unavailable.
GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp Adjusts outline line placement so scaled borders grow inward and meet at their corners.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Resolution[Current display resolution] --> Display[Display scale helpers]
    Display --> InGameUI[Cached unit-info scale]
    InGameUI --> Drawable[Unit icon and health-bar dimensions]
    Drawable --> Render2D[Scaled fills, images, and outlines]
    Options[Resolution change] --> InGameUI
Loading

Reviews (3): Last reviewed commit: "fix(gui): implement resolution scaling f..." | Re-trigger Greptile

Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp Outdated
anderote added a commit to anderote/GeneralsX that referenced this pull request Jul 11, 2026
The floating health box and veterancy XP readout are sized in raw screen
pixels, so at high resolutions (e.g. 3440x1440) they shrink relative to the
larger-rendered units (upstream fbraz3#108/TheSuperHackers#867/TheSuperHackers#1607). Derive a modest UI scale
factor from the display height vs a configurable baseline, clamped, and apply
it to the health-box width/height and the veterancy readout font.

New GlobalData/INI keys (GeneralsMD only, z_generals):
  UIFloatingScaleReferenceHeight (default 600) - baseline vertical resolution
  UIFloatingScaleMax             (default 2.5) - clamp on the scale factor
Set the reference height <= 0 to disable scaling. scale =
clamp(displayHeight / refHeight, 1.0, max); never shrinks below authored size.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Mauller

Mauller commented Sep 4, 2026

Copy link
Copy Markdown
Author

This one i can continue and finish off pretty quickly, needs a rebase and a quick update based on the AI feedback.

@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from a482938 to 059e866 Compare September 4, 2026 16:45
@Mauller
Mauller force-pushed the fix-unit-info-res-scaling branch from 059e866 to 59ece0e Compare September 4, 2026 16:49
@Mauller

Mauller commented Sep 4, 2026

Copy link
Copy Markdown
Author

fixed bots feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Is new feature or request Gen Relates to Generals GUI For graphical user interface Major Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants