Description
- Relates To: Game cursors, unit health bars and similar UI elements do not scale well in higher resolutions #108
It appears that heatlh bars were only setup to scale with zoom level, but only on the horizontal.
I have managed to make the health bars scale across all resolutions and to appear approximately the same scale at every resolution.
Altering this in Drawable.cpp properly scales the health bar across all resolutions. The key point is that the health bar sizes are read in from INI data and were determined against the original 800x600 resolution. So i produce a horizontal and vertical scaling factor based on the tactical views width and height.
I also apply zoom scaling to the vertical aspect of the health bar as well. This was just fixed in the original code.
EDIT: This still needs testing with aspect ratios other than 4:3 such as 16:9, but it is a start to understanding the problem.
static Bool computeHealthRegion( const Drawable *draw, IRegion2D& region )
{
// sanity
if( draw == NULL )
return FALSE;
const Object *obj = draw->getObject();
if( obj == NULL )
return FALSE;
Coord3D p;
obj->getHealthBoxPosition(p);
ICoord2D screenCenter;
if( !TheTacticalView->worldToScreen( &p, &screenCenter ) )
return FALSE;
Real healthBoxWidth, healthBoxHeight;
if (!obj->getHealthBoxDimensions(healthBoxHeight, healthBoxWidth))
return FALSE;
// scale the health bars according to the resolution and zoom
Real zoom = TheTacticalView->getZoom();
Real resolutionWidthScale = TheTacticalView->getWidth() / 800.0f;
Real resolutionHeightScale = TheTacticalView->getHeight() / 600.0f;
Real widthZoomScale = 1.0f / zoom;
Real heightZoomScale = 1.0f / zoom;
Real resolutionScaledWidth = healthBoxWidth * resolutionWidthScale;
Real resolutionScaledHeight = healthBoxHeight * resolutionHeightScale;
healthBoxWidth = resolutionScaledWidth * widthZoomScale;
healthBoxHeight = resolutionScaledHeight * heightZoomScale;
// figure out the final region for the health box
region.lo.x = screenCenter.x - healthBoxWidth * 0.5f;
region.lo.y = screenCenter.y - healthBoxHeight * 0.5f;
region.hi.x = region.lo.x + healthBoxWidth;
region.hi.y = region.lo.y + healthBoxHeight;
return TRUE;
} // end computeHealthRegion