diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-08 18:27:27 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-05-08 18:29:54 +0200 |
commit | 8ee8ea70b5a32e1b8a5ad3e670cfe9ebee47bb4c (patch) | |
tree | 694cbbfbf0e191c8a3f245441a93cc027319a8f6 /src | |
parent | b4150856b56584b3922f2a9e2489ba472d2e864b (diff) | |
download | Mana-8ee8ea70b5a32e1b8a5ad3e670cfe9ebee47bb4c.tar.gz Mana-8ee8ea70b5a32e1b8a5ad3e670cfe9ebee47bb4c.tar.bz2 Mana-8ee8ea70b5a32e1b8a5ad3e670cfe9ebee47bb4c.tar.xz Mana-8ee8ea70b5a32e1b8a5ad3e670cfe9ebee47bb4c.zip |
Fixed one pixel missing from progress bars
Also fixed the progress bar during connecting to reset again when full,
by disabling the smooth updating there.
The ProgressBar now uses gcn::Color instead of three separate color
attributes.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/inventorywindow.cpp | 4 | ||||
-rw-r--r-- | src/gui/ministatus.cpp | 6 | ||||
-rw-r--r-- | src/gui/status.cpp | 8 | ||||
-rw-r--r-- | src/gui/storagewindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/progressbar.cpp | 71 | ||||
-rw-r--r-- | src/gui/widgets/progressbar.h | 41 | ||||
-rw-r--r-- | src/main.cpp | 4 |
8 files changed, 67 insertions, 71 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 08abaf92..a7be69b8 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -92,8 +92,8 @@ InventoryWindow::InventoryWindow(int invSize): mSlotsLabel = new Label(_("Slots:")); mWeightLabel = new Label(_("Weight:")); - mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); - mWeightBar = new ProgressBar(1.0f, 100, 20, 0, 0, 255); + mSlotsBar = new ProgressBar(1.0f, 100, 20, gcn::Color(225, 200, 25)); + mWeightBar = new ProgressBar(1.0f, 100, 20, gcn::Color(0, 0, 255)); place(0, 0, mWeightLabel).setPadding(3); place(1, 0, mWeightBar, 3); diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index b49ca051..b4bc29e9 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -36,10 +36,10 @@ MiniStatusWindow::MiniStatusWindow(): Popup("MiniStatus") { - mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34); + mHpBar = new ProgressBar(1.0f, 100, 20, gcn::Color(0, 171, 34)); #ifdef EATHENA_SUPPORT - mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230); - mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211); + mMpBar = new ProgressBar(1.0f, 100, 20, gcn::Color(26, 102, 230)); + mXpBar = new ProgressBar(1.0f, 100, 20, gcn::Color(143, 192, 211)); #endif mHpBar->setPosition(0, 3); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 48917ba0..c9681fa9 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -58,16 +58,16 @@ StatusWindow::StatusWindow(LocalPlayer *player): Units::formatCurrency(mCurrency).c_str())); mHpLabel = new Label(_("HP:")); - mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34); + mHpBar = new ProgressBar(1.0f, 80, 15, gcn::Color(0, 171, 34)); mXpLabel = new Label(_("Exp:")); - mXpBar = new ProgressBar(1.0f, 80, 15, 143, 192, 211); + mXpBar = new ProgressBar(1.0f, 80, 15, gcn::Color(143, 192, 211)); mMpLabel = new Label(_("MP:")); - mMpBar = new ProgressBar(1.0f, 80, 15, 26, 102, 230); + mMpBar = new ProgressBar(1.0f, 80, 15, gcn::Color(26, 102, 230)); mJobLabel = new Label(_("Job:")); - mJobBar = new ProgressBar(1.0f, 80, 15, 220, 135, 203); + mJobBar = new ProgressBar(1.0f, 80, 15, gcn::Color(220, 135, 203)); // ---------------------- // Stats Part diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 309fcafc..4804bdcb 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -75,7 +75,7 @@ StorageWindow::StorageWindow(int invSize): mSlotsLabel = new Label(_("Slots: ")); - mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); + mSlotsBar = new ProgressBar(1.0f, 100, 20, gcn::Color(225, 200, 25)); mSlotsBar->setText(strprintf("%d/%d", mUsedSlots, mMaxSlots)); mSlotsBar->setProgress((float) mUsedSlots / mMaxSlots); diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index f22c768a..21362630 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -108,7 +108,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mBrowserBox = new BrowserBox; mScrollArea = new ScrollArea(mBrowserBox); mLabel = new Label(_("Connecting...")); - mProgressBar = new ProgressBar(0.0, 310, 20, 168, 116, 31); + mProgressBar = new ProgressBar(0.0, 310, 20, gcn::Color(168, 116, 31)); mCancelButton = new Button(_("Cancel"), "cancel", this); mPlayButton = new Button(_("Play"), "play", this); diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index caeea5c6..58f24651 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -38,18 +38,18 @@ int ProgressBar::mInstances = 0; float ProgressBar::mAlpha = 1.0; ProgressBar::ProgressBar(float progress, - unsigned int width, unsigned int height, - Uint8 red, Uint8 green, Uint8 blue): + int width, int height, + const gcn::Color &color): gcn::Widget(), - mRed(red), mGreen(green), mBlue(blue), - mRedToGo(red), mGreenToGo(green), mBlueToGo(blue) + mProgress(0.0f), + mProgressToGo(0.0f), + mSmoothProgress(true), + mColor(color), + mColorToGo(color), + mSmoothColorChange(true) { - mProgressToGo = mProgress = 0.0f; - mSmoothProgress = mSmoothColorChange = true; - setProgress(progress); - setWidth(width); - setHeight(height); + setSize(width, height); if (mInstances == 0) { @@ -99,28 +99,28 @@ void ProgressBar::logic() if (mSmoothColorChange) { // Smoothly changing the color for a nicer effect. - if (mRedToGo > mRed) mRed++; - if (mRedToGo < mRed) mRed--; - if (mGreenToGo > mGreen) mGreen++; - if (mGreenToGo < mGreen) mGreen--; - if (mBlueToGo > mBlue) mBlue++; - if (mBlueToGo < mBlue) mBlue--; - } - else - { - mRed = mRedToGo; - mGreen = mGreenToGo; - mBlue = mBlueToGo; + if (mColorToGo.r > mColor.r) + mColor.r++; + if (mColorToGo.g > mColor.g) + mColor.g++; + if (mColorToGo.b > mColor.b) + mColor.b++; + if (mColorToGo.r < mColor.r) + mColor.r--; + if (mColorToGo.g < mColor.g) + mColor.g--; + if (mColorToGo.b < mColor.b) + mColor.b--; } if (mSmoothProgress) { // Smoothly showing the progressbar changes. - if (mProgressToGo > mProgress) mProgress = mProgress + 0.005f; - if (mProgressToGo < mProgress) mProgress = mProgress - 0.005f; + if (mProgressToGo > mProgress) + mProgress = std::min(1.0f, mProgress + 0.005f); + if (mProgressToGo < mProgress) + mProgress = std::max(0.0f, mProgress - 0.005f); } - else - mProgress = mProgressToGo; } void ProgressBar::draw(gcn::Graphics *graphics) @@ -137,12 +137,12 @@ void ProgressBar::draw(gcn::Graphics *graphics) static_cast<Graphics*>(graphics)-> drawImageRect(0, 0, getWidth(), getHeight(), mBorder); - const int alpha = (int)(mAlpha * 255.0f); + mColor.a = (int) (mAlpha * 255); // The bar if (mProgress > 0) { - graphics->setColor(gcn::Color(mRed, mGreen, mBlue, alpha)); + graphics->setColor(mColor); graphics->fillRectangle(gcn::Rectangle(4, 4, (int) (mProgress * (getWidth() - 8)), getHeight() - 8)); @@ -163,14 +163,17 @@ void ProgressBar::draw(gcn::Graphics *graphics) void ProgressBar::setProgress(float progress) { - if (progress < 0.0f) mProgressToGo = 0.0; - else if (progress > 1.0f) mProgressToGo = 1.0; - else mProgressToGo = progress; + const float p = std::min(1.0f, std::max(0.0f, progress)); + mProgressToGo = p; + + if (!mSmoothProgress) + mProgress = p; } -void ProgressBar::setColor(Uint8 red, Uint8 green, Uint8 blue) +void ProgressBar::setColor(const gcn::Color &color) { - mRedToGo = red; - mGreenToGo = green; - mBlueToGo = blue; + mColorToGo = color; + + if (!mSmoothColorChange) + mColor = color; } diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h index e75b1d44..77670f57 100644 --- a/src/gui/widgets/progressbar.h +++ b/src/gui/widgets/progressbar.h @@ -26,8 +26,6 @@ #include <guichan/widget.hpp> -#include <SDL_types.h> - class ImageRect; /** @@ -42,12 +40,9 @@ class ProgressBar : public gcn::Widget * Constructor, initializes the progress with the given value. */ ProgressBar(float progress = 0.0f, - unsigned int width = 40, unsigned int height = 7, - Uint8 red = 150, Uint8 green = 150, Uint8 blue = 150); + int width = 40, int height = 7, + const gcn::Color &color = gcn::Color(150, 150, 150)); - /** - * Destructor. - */ ~ProgressBar(); /** @@ -71,24 +66,22 @@ class ProgressBar : public gcn::Widget float getProgress() const { return mProgress; } /** - * Change the filling of the progress bar. - */ - void setColor(Uint8, Uint8 green, Uint8 blue); - - /** - * Returns the red value of color. + * Change the color of the progress bar. */ - Uint8 getRed() const { return mRed; } + void setColor(const gcn::Color &color); /** - * Returns the green value of color. + * Change the color of the progress bar. + * + * This is an overload provided for convenience. */ - Uint8 getGreen() const { return mGreen; } + inline void setColor(int r, int g, int b) + { setColor(gcn::Color(r, g, b)); } /** - * Returns the blue value of color. + * Returns the color of the progress bar. */ - Uint8 getBlue() const { return mBlue; } + const gcn::Color &getColor() const { return mColor; } /** * Sets the text shown on the progress bar. @@ -103,33 +96,31 @@ class ProgressBar : public gcn::Widget { return mText; } /** - * Set wether the progress is moved smoothly. + * Set whether the progress is moved smoothly. */ void setSmoothProgress(bool smoothProgress) { mSmoothProgress = smoothProgress; } /** - * Set wether the color changing is made smoothly. + * Set whether the color changing is made smoothly. */ void setSmoothColorChange(bool smoothColorChange) { mSmoothColorChange = smoothColorChange; } - private: float mProgress, mProgressToGo; bool mSmoothProgress; - Uint8 mRed, mGreen, mBlue; - Uint8 mRedToGo, mGreenToGo, mBlueToGo; + gcn::Color mColor; + gcn::Color mColorToGo; bool mSmoothColorChange; std::string mText; - bool mUpdated; static ImageRect mBorder; static int mInstances; static float mAlpha; - + static const gcn::Color TEXT_COLOR; }; diff --git a/src/main.cpp b/src/main.cpp index 5776341b..2d5899f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -922,7 +922,9 @@ int main(int argc, char *argv[]) gcn::Container *top = static_cast<gcn::Container*>(gui->getTop()); Desktop *desktop = new Desktop; top->add(desktop); - ProgressBar *progressBar = new ProgressBar(0.0f, 100, 20, 168, 116, 31); + ProgressBar *progressBar = new ProgressBar(0.0f, 100, 20, + gcn::Color(168, 116, 31)); + progressBar->setSmoothProgress(false); gcn::Label *progressLabel = new Label; top->add(progressBar, 5, top->getHeight() - 5 - progressBar->getHeight()); top->add(progressLabel, 15 + progressBar->getWidth(), |