From 34a718bbd2573477cb600cfa422c5669b1b9d6b2 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 10 May 2005 23:04:39 +0000 Subject: Fixed progress bars in OpenGL mode, now uses Guichan's fillRectangle. --- src/gui/progressbar.cpp | 40 +++++++++++----------------------- src/gui/progressbar.h | 13 +++-------- src/gui/status.cpp | 50 +++++++++++++++++++++---------------------- src/log.cpp | 2 +- src/resources/itemmanager.cpp | 6 +++--- 5 files changed, 45 insertions(+), 66 deletions(-) diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index d19ed52d..d939b3b5 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -26,7 +26,7 @@ #include "../resources/resourcemanager.h" ProgressBar::ProgressBar(float progress, int x, int y, int width, int height, - unsigned char red, unsigned green, unsigned char blue): + int red, int green, int blue): gcn::Widget(), red(red), green(green), blue(blue) { @@ -50,19 +50,10 @@ ProgressBar::ProgressBar(float progress, int x, int y, int width, int height, dTopRightBorder = dBorders->getSubImage(7, 0, 4, 4); dBottomRightBorder = dBorders->getSubImage(7, 15, 4, 4); dBottomLeftBorder = dBorders->getSubImage(0, 15, 4, 4); - - colorBar = Image::create(getWidth() - 8, getHeight() - 8); - if (colorBar) { - colorBar->fillWithColor(red, green, blue); - colorBar->setAlpha(0.7f); - } } ProgressBar::~ProgressBar() { - if (colorBar) { - delete colorBar; - } } void ProgressBar::draw(gcn::Graphics *graphics) @@ -70,7 +61,6 @@ void ProgressBar::draw(gcn::Graphics *graphics) int absx, absy; getAbsolutePosition(absx, absy); - // We're drawing the bar itself first // Background dBackground->drawPattern(screen, absx + 4, absy + 4, @@ -91,15 +81,19 @@ void ProgressBar::draw(gcn::Graphics *graphics) dRightBorder->drawPattern(screen, absx + getWidth() - 4, absy + 4, 4, getHeight() - 8); - if (colorBar) { - colorBar->draw(screen, 0, 0, absx + 4, absy + 4, - (int)(progress * float(getWidth() - 4)), getHeight() - 8); + // The bar + if (progress > 0) { + graphics->setColor(gcn::Color(red, green, blue, 200)); + graphics->fillRectangle(gcn::Rectangle(4, 4, + (int)(progress * (getWidth() - 8)), getHeight() - 8)); } } void ProgressBar::setProgress(float progress) { - this->progress = progress; + if (progress < 0.0f) this->progress = 0.0; + else if (progress > 1.0f) this->progress = 1.0; + else this->progress = progress; } float ProgressBar::getProgress() @@ -107,17 +101,9 @@ float ProgressBar::getProgress() return progress; } -void ProgressBar::setColor( - unsigned char newRed, unsigned char newGreen, unsigned char newBlue) +void ProgressBar::setColor(int red, int green, int blue) { - if (red != newRed || green != newGreen || blue != newBlue) - { - red = newRed; - green = newGreen; - blue = newBlue; - if (colorBar) { - colorBar->fillWithColor(red, green, blue); - colorBar->setAlpha(0.7f); - } - } + this->red = red; + this->green = green; + this->blue = blue; } diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h index c8bb22d6..b1f5bb1b 100644 --- a/src/gui/progressbar.h +++ b/src/gui/progressbar.h @@ -39,8 +39,7 @@ class ProgressBar : public gcn::Widget { */ ProgressBar(float progress = 0.0f, int x = 0, int y = 0, int width = 40, int height = 7, - unsigned char red = 150, unsigned green = 150, - unsigned char blue = 150); + int red = 150, int green = 150, int blue = 150); /** * Destructor. @@ -65,10 +64,7 @@ class ProgressBar : public gcn::Widget { /** * Change the filling of the progress bar. */ - void setColor( - unsigned char red, - unsigned char green, - unsigned char blue); + void setColor(int red, int green, int blue); /** * Get The red value of color @@ -96,16 +92,13 @@ class ProgressBar : public gcn::Widget { private: float progress; - unsigned char red, green, blue; + int red, green, blue; // Bar Images Image *dBackground; Image *dTopLeftBorder, *dTopRightBorder, *dBottomLeftBorder; Image *dBottomRightBorder; Image *dLeftBorder, *dRightBorder, *dTopBorder, *dBottomBorder; - - // Our color bar - Image *colorBar; }; #endif diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 24a63499..b571c724 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -26,12 +26,12 @@ #include "button.h" #include "../engine.h" +#define WIN_BORDER 5 +#define CONTROLS_SEPARATOR 4 + StatusWindow::StatusWindow(): Window("%s Lvl: % 2i Job: % 2i") { - #define WIN_BORDER 5 - #define CONTROLS_SEPARATOR 4 - hp = new gcn::Label("HP"); sp = new gcn::Label("SP"); hpValue = new gcn::Label(); @@ -39,19 +39,19 @@ StatusWindow::StatusWindow(): gp = new gcn::Label("GP"); expLabel = new gcn::Label("Exp"); jobExpLabel = new gcn::Label("Job"); - + statsButton = new Button("Stats"); statsButton->setEventId("Stats"); statsButton->addActionListener(this); - + skillsButton = new Button("Skills"); skillsButton->setEventId("Skills"); skillsButton->addActionListener(this); - + inventoryButton = new Button("Inventory"); inventoryButton->setEventId("Inventory"); inventoryButton->addActionListener(this); - + setupButton = new Button("Setup"); setupButton->setEventId("Setup"); setupButton->addActionListener(this); @@ -59,7 +59,7 @@ StatusWindow::StatusWindow(): equipmentButton = new Button("Equip."); equipmentButton->setEventId("Equipment"); equipmentButton->addActionListener(this); - + hp->setPosition(WIN_BORDER, WIN_BORDER); sp->setPosition(WIN_BORDER, hp->getY() + hp->getHeight() + CONTROLS_SEPARATOR); healthBar = new ProgressBar(1.0f, WIN_BORDER + hp->getWidth() + CONTROLS_SEPARATOR, WIN_BORDER, 80, 15, 0, 255, 0); @@ -70,18 +70,18 @@ StatusWindow::StatusWindow(): gp->setPosition(170, WIN_BORDER); expLabel->setPosition(WIN_BORDER, sp->getY() + sp->getHeight() + CONTROLS_SEPARATOR); jobExpLabel->setPosition(spValue->getX(), sp->getY() + sp->getHeight() + CONTROLS_SEPARATOR); - + xpBar = new ProgressBar(1.0f, WIN_BORDER, expLabel->getY() + expLabel->getHeight() + CONTROLS_SEPARATOR, 70, 15, 12, 194, 255); jobXpBar = new ProgressBar(1.0f, spValue->getX(), jobExpLabel->getY() + jobExpLabel->getHeight() + CONTROLS_SEPARATOR, 70, 15, 200, 0, 0); - + statsButton->setPosition(WIN_BORDER, xpBar->getY() + xpBar->getHeight() + 2*CONTROLS_SEPARATOR); skillsButton->setPosition(statsButton->getX() + statsButton->getWidth() + CONTROLS_SEPARATOR, statsButton->getY()); inventoryButton->setPosition(skillsButton->getX() + skillsButton->getWidth() + CONTROLS_SEPARATOR, statsButton->getY()); setupButton->setPosition(inventoryButton->getX() + inventoryButton->getWidth() + CONTROLS_SEPARATOR, statsButton->getY()); equipmentButton->setPosition(setupButton->getX() + setupButton->getWidth() + CONTROLS_SEPARATOR, statsButton->getY()); - + setContentSize(250, statsButton->getY() + statsButton->getHeight() + WIN_BORDER); - + add(hp); add(sp); add(healthBar); @@ -137,17 +137,17 @@ void StatusWindow::update() sprintf(tempstr, "%d / %d", char_info->sp, char_info->max_sp); spValue->setCaption(tempstr); spValue->adjustSize(); - + sprintf(tempstr, "Exp: %d / %d", (int)char_info->xp, (int)char_info->xpForNextLevel); expLabel->setCaption(tempstr); expLabel->adjustSize(); - + sprintf(tempstr, "Job Exp: %d / %d", (int)char_info->job_xp, (int)char_info->jobXpForNextLevel); jobExpLabel->setCaption(tempstr); jobExpLabel->adjustSize(); - + if (char_info->hp < int(char_info->max_hp / 3)) { healthBar->setColor(255, 0, 0); // Red @@ -163,10 +163,10 @@ void StatusWindow::update() healthBar->setColor(0, 255, 0); // Green } } - - + + healthBar->setProgress((float)char_info->hp / (float)char_info->max_hp); - + xpBar->setProgress((float)char_info->xp / (float)char_info->xpForNextLevel); jobXpBar->setProgress( (float)char_info->job_xp / (float)char_info->jobXpForNextLevel); @@ -174,26 +174,26 @@ void StatusWindow::update() delete[] tempstr; } -void StatusWindow::action(const std::string& eventId) { - +void StatusWindow::action(const std::string& eventId) +{ if (eventId == "Stats") { // Show / Hide the stats dialog - statsWindow->setVisible(!statsWindow->isVisible()); + statsWindow->setVisible(!statsWindow->isVisible()); } if (eventId == "Skills") { // Show / Hide the skills dialog - skillDialog->setVisible(!skillDialog->isVisible()); + skillDialog->setVisible(!skillDialog->isVisible()); } if (eventId == "Inventory") { // Show / Hide the inventory dialog - inventoryWindow->setVisible(!inventoryWindow->isVisible()); + inventoryWindow->setVisible(!inventoryWindow->isVisible()); } if (eventId == "Setup") { // Show / Hide the inventory dialog - setupWindow->setVisible(true); + setupWindow->setVisible(true); } if (eventId == "Equipment") { // Show / Hide the inventory dialog - equipmentWindow->setVisible(!equipmentWindow->isVisible()); + equipmentWindow->setVisible(!equipmentWindow->isVisible()); } } diff --git a/src/log.cpp b/src/log.cpp index d71c55d6..0ce91d2e 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -74,7 +74,7 @@ void Logger::log(const char *log_text, ...) timeStr << ((t % 60 < 10) ? "0" : ""); timeStr << (int)(t % 60); timeStr << "] "; - + logFile << timeStr.str() << buf << std::endl; // Delete temporary buffer diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index a3438241..05b0ff44 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -42,7 +42,7 @@ ItemManager::ItemManager() std::fstream dbFile; dbFile.open(TMW_DATADIR "data/items.xml", std::ios::in); if (!dbFile.is_open()) { - logger->log("Cannot find item database!"); + logger->error("Cannot find item database (items.xml)!"); return; } dbFile.close(); @@ -53,7 +53,7 @@ ItemManager::ItemManager() xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) { - logger->log("Warning: Not a valid database file!"); + logger->error("items.xml is not a valid database file!"); } else { for (node = node->xmlChildrenNode; node != NULL; node = node->next) { @@ -105,7 +105,7 @@ ItemManager::ItemManager() xmlFreeDoc(doc); } else { - logger->log("Error while parsing item database!"); + logger->error("Error while parsing item database (items.xml)!"); } unknown = new ItemInfo(); -- cgit v1.2.3-70-g09d2