Merge pull request #1790 from blackwc/guihealthbarhud-flip

GuitHealthBarHud flip fill
This commit is contained in:
Areloch 2016-11-02 22:28:21 -05:00 committed by GitHub
commit 00a4a21e3f

View file

@ -43,6 +43,7 @@ class GuiHealthBarHud : public GuiControl
bool mShowFrame; bool mShowFrame;
bool mShowFill; bool mShowFill;
bool mDisplayEnergy; bool mDisplayEnergy;
bool mFlip;
ColorF mFillColor; ColorF mFillColor;
ColorF mFrameColor; ColorF mFrameColor;
@ -105,6 +106,8 @@ GuiHealthBarHud::GuiHealthBarHud()
mPulseRate = 0; mPulseRate = 0;
mPulseThreshold = 0.3f; mPulseThreshold = 0.3f;
mValue = 0.2f; mValue = 0.2f;
mFlip = false;
} }
void GuiHealthBarHud::initPersistFields() void GuiHealthBarHud::initPersistFields()
@ -124,6 +127,7 @@ void GuiHealthBarHud::initPersistFields()
addField( "showFill", TypeBool, Offset( mShowFill, GuiHealthBarHud ), "If true, we draw the background color of the control." ); addField( "showFill", TypeBool, Offset( mShowFill, GuiHealthBarHud ), "If true, we draw the background color of the control." );
addField( "showFrame", TypeBool, Offset( mShowFrame, GuiHealthBarHud ), "If true, we draw the frame of the control." ); addField( "showFrame", TypeBool, Offset( mShowFrame, GuiHealthBarHud ), "If true, we draw the frame of the control." );
addField( "displayEnergy", TypeBool, Offset( mDisplayEnergy, GuiHealthBarHud ), "If true, display the energy value rather than the damage value." ); addField( "displayEnergy", TypeBool, Offset( mDisplayEnergy, GuiHealthBarHud ), "If true, display the energy value rather than the damage value." );
addField( "flip", TypeBool, Offset( mFlip, GuiHealthBarHud), "If true, will fill bar in opposite direction.");
endGroup("Misc"); endGroup("Misc");
Parent::initPersistFields(); Parent::initPersistFields();
@ -176,12 +180,21 @@ void GuiHealthBarHud::onRender(Point2I offset, const RectI &updateRect)
// Render damage fill % // Render damage fill %
RectI rect(updateRect); RectI rect(updateRect);
if(getWidth() > getHeight()) if(getWidth() > getHeight())
{
rect.extent.x = (S32)(rect.extent.x * mValue); rect.extent.x = (S32)(rect.extent.x * mValue);
if(mFlip)
rect.point.x = (S32)(updateRect.point.x + (updateRect.extent.x - rect.extent.x));
}
else else
{ {
S32 bottomY = rect.point.y + rect.extent.y; S32 bottomY = rect.point.y + rect.extent.y;
rect.extent.y = (S32)(rect.extent.y * mValue); rect.extent.y = (S32)(rect.extent.y * mValue);
rect.point.y = bottomY - rect.extent.y;
if(mFlip)
rect.extent.y = (S32)(updateRect.extent.y - (updateRect.extent.y - rect.extent.y));
else
rect.point.y = bottomY - rect.extent.y;
} }
GFX->getDrawUtil()->drawRectFill(rect, mDamageFillColor); GFX->getDrawUtil()->drawRectFill(rect, mDamageFillColor);