Skip to content

Commit

Permalink
Print distances and speeds in terms of tiles, not in 1/128ths of tiles.
Browse files Browse the repository at this point in the history
Changelog: Print distances and speeds in terms of tiles.
  • Loading branch information
Cyp committed Jan 17, 2011
1 parent baf63f1 commit e192e8a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/widget/bar.c
Expand Up @@ -121,6 +121,9 @@ W_BARGRAPH* barGraphCreate(const W_BARINIT* psInit)
psWidget->majorCol = psInit->sMinorCol;
}

psWidget->denominator = MAX(psInit->denominator, 1);
psWidget->precision = psInit->precision;

barGraphInitialise(psWidget);

return psWidget;
Expand Down
2 changes: 2 additions & 0 deletions lib/widget/bar.h
Expand Up @@ -37,6 +37,8 @@ typedef struct _w_bargraph
UWORD iRange; // Maximum range
UWORD iValue; // Current value
UWORD iOriginal; // hack to keep uncapped value around
int denominator; // Denominator, 1 by default.
int precision; // Number of places after the decimal point to display, 0 by default.
PIELIGHT majorCol; // Colour for the major bar
PIELIGHT minorCol; // Colour for the minor bar
const char *pTip; // The tool tip for the graph
Expand Down
2 changes: 2 additions & 0 deletions lib/widget/widget.h
Expand Up @@ -230,6 +230,8 @@ typedef struct
UWORD size; ///< Initial percentage of the graph that is filled
UWORD minorSize; ///< Percentage of second bar graph if there is one
UWORD iRange; ///< Maximum range
int denominator; ///< Denominator, 1 by default.
int precision; ///< Number of places after the decimal point to display, 0 by default.
PIELIGHT sCol; ///< Bar colour
PIELIGHT sMinorCol; ///< Minor bar colour
const char *pTip; ///< Tool tip text
Expand Down
21 changes: 21 additions & 0 deletions src/design.c
Expand Up @@ -1549,20 +1549,27 @@ static BOOL _intSetSystemForm(COMPONENT_STATS *psStats)
/* Add the bar graphs*/
sBarInit.id = IDDES_SENSORRANGE;
sBarInit.iRange = (UWORD)getMaxSensorRange();//DBAR_SENSORMAXRANGE;
sBarInit.pTip = _("Sensor Range");
sBarInit.denominator = TILE_UNITS;
sBarInit.precision = 1;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
sBarInit.denominator = 0;
sBarInit.precision = 0;
sBarInit.id = IDDES_SENSORPOWER;
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.iRange = (UWORD)getMaxSensorPower();//DBAR_SENSORMAXPOWER;
sBarInit.pTip = _("Sensor Power");
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
sBarInit.id = IDDES_SENSORWEIGHT;
sBarInit.y = DES_STATBAR_Y3; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.iRange = (UWORD)getMaxComponentWeight();//DBAR_MAXWEIGHT;
sBarInit.pTip = _("Weight");
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
Expand Down Expand Up @@ -1602,13 +1609,15 @@ static BOOL _intSetSystemForm(COMPONENT_STATS *psStats)
/* Add the bar graphs */
sBarInit.id = IDDES_ECMPOWER;
sBarInit.iRange = (UWORD)getMaxECMPower();//DBAR_ECMMAXPOWER;
sBarInit.pTip = _("ECM Power");
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
sBarInit.id = IDDES_ECMWEIGHT;
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.iRange = (UWORD)getMaxComponentWeight();//DBAR_MAXWEIGHT;
sBarInit.pTip = _("Weight");
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
Expand Down Expand Up @@ -1718,10 +1727,14 @@ static BOOL _intSetSystemForm(COMPONENT_STATS *psStats)
sBarInit.id = IDDES_WEAPRANGE;
sBarInit.iRange = (UWORD)getMaxWeaponRange();//DBAR_WEAPMAXRANGE;
sBarInit.pTip = _("Range");
sBarInit.denominator = TILE_UNITS;
sBarInit.precision = 1;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
sBarInit.denominator = 0;
sBarInit.precision = 0;
sBarInit.id = IDDES_WEAPDAMAGE;
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.iRange = (UWORD)getMaxWeaponDamage();//DBAR_WEAPMAXDAMAGE;
Expand Down Expand Up @@ -1904,10 +1917,14 @@ static BOOL intSetPropulsionForm(PROPULSION_STATS *psStats)
sBarInit.id = IDDES_PROPAIR;
sBarInit.iRange = (UWORD)getMaxPropulsionSpeed();//DBAR_PROPMAXSPEED;
sBarInit.pTip = _("Air Speed");
sBarInit.denominator = TILE_UNITS;
sBarInit.precision = 2;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
sBarInit.denominator = 0;
sBarInit.precision = 0;
sBarInit.id = IDDES_PROPWEIGHT;
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.iRange = (UWORD)getMaxComponentWeight();//DBAR_MAXWEIGHT;
Expand Down Expand Up @@ -1941,6 +1958,8 @@ static BOOL intSetPropulsionForm(PROPULSION_STATS *psStats)
sBarInit.id = IDDES_PROPROAD;
sBarInit.pTip = _("Road Speed");
sBarInit.iRange = (UWORD)getMaxPropulsionSpeed();//DBAR_PROPMAXSPEED;
sBarInit.denominator = TILE_UNITS;
sBarInit.precision = 2;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
Expand All @@ -1961,6 +1980,8 @@ static BOOL intSetPropulsionForm(PROPULSION_STATS *psStats)
{
return false;
}
sBarInit.denominator = 0;
sBarInit.precision = 0;
sBarInit.id = IDDES_PROPWEIGHT;
sBarInit.y = DES_STATBAR_Y4; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.pTip = _("Weight");
Expand Down
10 changes: 8 additions & 2 deletions src/intdisplay.c
Expand Up @@ -2908,13 +2908,14 @@ void StatGetResearchImage(BASE_STATS *psStat, SDWORD *Image, iIMDShape **Shape,
static void intDisplayBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, bool isPowerBar)
{
W_BARGRAPH *BarGraph = (W_BARGRAPH *)psWidget;
char szVal[6];
char szVal[30];
char const *szCheckWidth = "00000";
int x0 = xOffset + BarGraph->x;
int y0 = yOffset + BarGraph->y;
int arbitaryOffset = 3;
int iX, iY;
int barWidth = 100, width;
int i, precisionFactor = 1, value;

if (isPowerBar)
{
Expand Down Expand Up @@ -2942,7 +2943,12 @@ static void intDisplayBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, bool
iV_DrawImageRect(IntImages, IMAGE_DES_STATSCURR, iX, y0, width, iV_GetImageHeight(IntImages, IMAGE_DES_STATSCURR));

/* draw text value */
sprintf(szVal, "%d", BarGraph->iOriginal);
for (i = 0; i < BarGraph->precision; ++i)
{
precisionFactor *= 10;
}
value = (BarGraph->iOriginal * precisionFactor + BarGraph->denominator/2) / BarGraph->denominator;
sprintf(szVal, "%d%s%.*d", value/precisionFactor, precisionFactor == 1? "" : ".", BarGraph->precision, value%precisionFactor);
iV_SetTextColour(WZCOL_TEXT_BRIGHT);
#ifdef WZ_OS_MAC
iV_DrawText( szVal, x0, iY+2 );
Expand Down

0 comments on commit e192e8a

Please sign in to comment.