diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/status.cpp | 32 | ||||
-rw-r--r-- | src/gui/status.h | 5 |
2 files changed, 13 insertions, 24 deletions
diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 9d85a317..27269acf 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -34,6 +34,7 @@ #include "net/ea/playerhandler.h" #include "utils/gettext.h" +#include "utils/mathutils.h" #include "utils/strprintf.h" #include "utils/stringutils.h" @@ -308,22 +309,22 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) { r1 = 0xcc; g1 = 0x00; b1 = 0x00; r2 = 0xcc; g2 = 0xcc; b2 = 0x00; - weight = (float)(curHP-(thresholdLevel)) / (float)thresholdLevel; + weight = (float) (curHP - (thresholdLevel)) / (float) thresholdLevel; // Reddish Brown -> Red } else if (curHP < thresholdLevel*2) { r1 = 0xcc; g1 = 0xcc; b1 = 0x00; r2 = 0xff; g2 = 0xcc; b2 = 0x00; - weight = (float)(curHP-(thresholdLevel*2)) / (float)thresholdLevel; - // Orange->Reddish Brown + weight = (float) (curHP - (thresholdLevel * 2)) / (float) thresholdLevel; + // Orange -> Reddish Brown } else { r1 = 0xff; g1 = 0xcc; b1 = 0x00; r2 = 0x99; g2 = 0xff; b2 = 0x99; - weight = (float)(curHP-(thresholdLevel*3)) / (float)thresholdLevel; - // Green ->Orange + weight = (float) (curHP - (thresholdLevel * 3)) / (float) thresholdLevel; + // Green -> Orange } //safety checks @@ -331,27 +332,20 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) if (weight<0.0f) weight=0.0f; //Do the color blend - r1 = (int)weightedAverage(r1,r2,weight); - g1 = (int)weightedAverage(g1,g2,weight); - b1 = (int)weightedAverage(b1,b2,weight); + r1 = (int) weightedAverage(r1, r2, weight); + g1 = (int) weightedAverage(g1, g2, weight); + b1 = (int) weightedAverage(b1, b2, weight); //more safety checks - if (r1>255) r1=255; - if (g1>255) g1=255; - if (b1>255) b1=255; + if (r1 > 255) r1 = 255; + if (g1 > 255) g1 = 255; + if (b1 > 255) b1 = 255; - bar->setColor(r1,g1,b1); + bar->setColor(r1, g1, b1); bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp()); } -float StatusWindow::weightedAverage(float n1, float n2, float w) { - if (w<0.0f) return n1; - if (w>1.0f) return n2; - - return (w*n2 + (1.0f-w)*n1) / 2.0f; -} - void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) { if (showMax) diff --git a/src/gui/status.h b/src/gui/status.h index 78d35a32..403a7d59 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -62,11 +62,6 @@ class StatusWindow : public Window, public gcn::ActionListener static void updateXPBar(ProgressBar *bar, bool percent = true); static void updateJobBar(ProgressBar *bar, bool percent = true); - /** - * Used by updateHPBar to get the weighted average of two colors - */ - static float weightedAverage(float n1, float n2, float w); - private: LocalPlayer *mPlayer; |