From 285da0d05eb2e6b680a8dfc497cf4ecab75b7aa4 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 27 Sep 2007 14:54:09 +0000 Subject: Merged another bunch of changes from trunk to 0.0 to reduce the difference. --- src/gui/button.cpp | 60 ++++++++++++++++++++++++++++--------------- src/gui/button.h | 7 ++++- src/gui/checkbox.cpp | 6 ++--- src/gui/equipmentwindow.cpp | 4 +-- src/gui/itemcontainer.cpp | 4 +-- src/gui/linkhandler.h | 2 ++ src/gui/minimap.cpp | 4 +-- src/gui/radiobutton.cpp | 2 +- src/gui/scrollarea.cpp | 16 ++++++------ src/gui/slider.cpp | 12 ++++----- src/gui/textfield.cpp | 2 +- src/gui/updatewindow.cpp | 17 +++++------- src/gui/updatewindow.h | 5 ---- src/gui/viewport.cpp | 2 +- src/gui/windowlistener.h | 4 +-- src/logindata.h | 2 ++ src/particle.cpp | 2 ++ src/particle.h | 3 +-- src/resources/monsterdb.h | 2 +- src/resources/monsterinfo.cpp | 10 ++++---- src/sound.cpp | 16 +++++++----- src/sound.h | 5 ++-- src/utils/trim.h | 2 +- 23 files changed, 104 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/gui/button.cpp b/src/gui/button.cpp index a9212e83..0379ebc0 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -34,9 +34,32 @@ #include "../utils/dtor.h" -ImageRect Button::button[4]; int Button::mInstances = 0; +enum{ + BUTTON_STANDARD, // 0 + BUTTON_HIGHLIGHTED, // 1 + BUTTON_PRESSED, // 2 + BUTTON_DISABLED, // 3 + BUTTON_COUNT // 4 - Must be last. +}; + +struct ButtonData +{ + char const *file; + int gridX; + int gridY; +}; + +static ButtonData const data[BUTTON_COUNT] = { + {"graphics/gui/button.png", 0, 0}, + {"graphics/gui/buttonhi.png", 9, 4}, + {"graphics/gui/buttonpress.png", 16, 19}, + {"graphics/gui/button_disabled.png", 25, 23} +}; + +ImageRect Button::button[BUTTON_COUNT]; + Button::Button(): mIsLogged(false) { @@ -63,24 +86,20 @@ void Button::init() { // Load the skin ResourceManager *resman = ResourceManager::getInstance(); - Image *btn[4]; - btn[0] = resman->getImage("graphics/gui/button.png"); - btn[1] = resman->getImage("graphics/gui/buttonhi.png"); - btn[2] = resman->getImage("graphics/gui/buttonpress.png"); - btn[3] = resman->getImage("graphics/gui/button_disabled.png"); - int bgridx[4] = {0, 9, 16, 25}; - int bgridy[4] = {0, 4, 19, 24}; + Image *btn[BUTTON_COUNT]; + int a, x, y, mode; - for (mode = 0; mode < 4; mode++) + for (mode = 0; mode < BUTTON_COUNT; mode++) { + btn[mode] = resman->getImage(data[mode].file); a = 0; for (y = 0; y < 3; y++) { for (x = 0; x < 3; x++) { button[mode].grid[a] = btn[mode]->getSubImage( - bgridx[x], bgridy[y], - bgridx[x + 1] - bgridx[x] + 1, - bgridy[y + 1] - bgridy[y] + 1); + data[x].gridX, data[y].gridY, + data[x + 1].gridX - data[x].gridX + 1, + data[y + 1].gridY - data[y].gridY + 1); a++; } } @@ -96,7 +115,7 @@ Button::~Button() if (mInstances == 0) { - for (int mode = 0; mode < 4; mode++) + for (int mode = 0; mode < BUTTON_COUNT; mode++) { for_each(button[mode].grid, button[mode].grid + 9, dtor()); } @@ -109,21 +128,20 @@ Button::draw(gcn::Graphics *graphics) int mode; if (!isEnabled()) { - mode = 3; + mode = BUTTON_DISABLED; } else if (isPressed() || mIsLogged) { - mode = 2; + mode = BUTTON_PRESSED; } - else if (mHasMouse) { - mode = 1; + else if (mHasMouse || isFocused()) { + mode = BUTTON_HIGHLIGHTED; } else { - mode = 0; + mode = BUTTON_STANDARD; } - dynamic_cast(graphics)->drawImageRect(0, 0, - getWidth(), getHeight(), - button[mode]); + static_cast(graphics)-> + drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); graphics->setColor(getForegroundColor()); diff --git a/src/gui/button.h b/src/gui/button.h index 68831d5a..d12173b2 100644 --- a/src/gui/button.h +++ b/src/gui/button.h @@ -37,9 +37,14 @@ class ImageRect; */ class Button : public gcn::Button { public: + /** + * Default constructor. + */ Button(); + /** - * Constructor, sets the caption of the button to the given string. + * Constructor, sets the caption of the button to the given string and + * adds the given action listener. */ Button(const std::string& caption, const std::string &actionEventId, gcn::ActionListener *listener); diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index ec7eb578..fab4780c 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -66,7 +66,7 @@ CheckBox::~CheckBox() void CheckBox::drawBox(gcn::Graphics* graphics) { - Image *box = NULL; + Image *box; if (mMarked) { if (isEnabled()) { @@ -80,7 +80,5 @@ void CheckBox::drawBox(gcn::Graphics* graphics) box = checkBoxDisabled; } - if (box != NULL) { - dynamic_cast(graphics)->drawImage(box, 2, 2); - } + static_cast(graphics)->drawImage(box, 2, 2); } diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 78727ff8..4df18b19 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -66,7 +66,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) } image = item->getInfo().getImage(); - dynamic_cast(graphics)->drawImage( + static_cast(graphics)->drawImage( image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } @@ -78,7 +78,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) image = item->getInfo().getImage(); - dynamic_cast(graphics)->drawImage(image, 160, 25); + static_cast(graphics)->drawImage(image, 160, 25); graphics->drawText(toString(item->getQuantity()), 170, 62, gcn::Graphics::CENTER); } diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 43de8db3..0e203905 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -110,7 +110,7 @@ ItemContainer::draw(gcn::Graphics *graphics) // Draw selection image below selected item if (mSelectedItem == item) { - dynamic_cast(graphics)->drawImage( + static_cast(graphics)->drawImage( mSelImg, itemX, itemY); } @@ -118,7 +118,7 @@ ItemContainer::draw(gcn::Graphics *graphics) Image* image; if ((image = item->getInfo().getImage()) != NULL) { - dynamic_cast(graphics)->drawImage( + static_cast(graphics)->drawImage( image, itemX, itemY); } diff --git a/src/gui/linkhandler.h b/src/gui/linkhandler.h index 33416ec7..3a32f825 100644 --- a/src/gui/linkhandler.h +++ b/src/gui/linkhandler.h @@ -24,6 +24,8 @@ #ifndef _TMW_LINK_HANDLER_H_ #define _TMW_LINK_HANDLER_H_ +#include + /** * A simple interface to windows that need to handle links from BrowserBox * widget. diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 69c5eb6e..2720225d 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -72,8 +72,8 @@ void Minimap::draw(gcn::Graphics *graphics) if (mMapImage != NULL) { - dynamic_cast(graphics)->drawImage( - mMapImage, getPadding(), getTitleBarHeight()); + static_cast(graphics)-> + drawImage(mMapImage, getPadding(), getTitleBarHeight()); } Beings &beings = beingManager->getAll(); diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index bbebe48f..e318116a 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -80,6 +80,6 @@ void RadioButton::drawBox(gcn::Graphics* graphics) } if (box != NULL) { - dynamic_cast(graphics)->drawImage(box, 2, 2); + static_cast(graphics)->drawImage(box, 2, 2); } } diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 903ec95d..816f94a8 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -228,8 +228,8 @@ void ScrollArea::drawBorder(gcn::Graphics *graphics) int h = getHeight() + bs * 2; if (mOpaque) { - dynamic_cast(graphics)->drawImageRect(0, 0, w, h, - background); + static_cast(graphics)-> + drawImageRect(0, 0, w, h, background); } } @@ -269,8 +269,8 @@ void ScrollArea::drawButton(gcn::Graphics *graphics, BUTTON_DIR dir) break; } - dynamic_cast(graphics)->drawImage( - buttons[dir][state], dim.x, dim.y); + static_cast(graphics)-> + drawImage(buttons[dir][state], dim.x, dim.y); } void ScrollArea::drawUpButton(gcn::Graphics *graphics) @@ -313,14 +313,14 @@ void ScrollArea::drawVMarker(gcn::Graphics *graphics) { gcn::Rectangle dim = getVerticalMarkerDimension(); - dynamic_cast(graphics)->drawImageRect( - dim.x, dim.y, dim.width, dim.height, vMarker); + static_cast(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker); } void ScrollArea::drawHMarker(gcn::Graphics *graphics) { gcn::Rectangle dim = getHorizontalMarkerDimension(); - dynamic_cast(graphics)->drawImageRect( - dim.x, dim.y, dim.width, dim.height, vMarker); + static_cast(graphics)-> + drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker); } diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index 98efc409..f0170a1b 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -109,22 +109,22 @@ void Slider::draw(gcn::Graphics *graphics) int x = 0; int y = (h - hStart->getHeight()) / 2; - dynamic_cast(graphics)->drawImage(hStart, x, y); + static_cast(graphics)->drawImage(hStart, x, y); w -= hStart->getWidth() + hEnd->getWidth(); x += hStart->getWidth(); - dynamic_cast(graphics)->drawImagePattern( - hMid, x, y, w, hMid->getHeight()); + static_cast(graphics)-> + drawImagePattern(hMid, x, y, w, hMid->getHeight()); x += w; - dynamic_cast(graphics)->drawImage(hEnd, x, y); + static_cast(graphics)->drawImage(hEnd, x, y); drawMarker(graphics); } void Slider::drawMarker(gcn::Graphics *graphics) { - dynamic_cast(graphics)->drawImage(hGrip, - getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2); + static_cast(graphics)-> + drawImage(hGrip, getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2); } diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index adf41a9a..ce7f6d5f 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -98,5 +98,5 @@ void TextField::drawBorder(gcn::Graphics *graphics) w = getWidth() + bs * 2; h = getHeight() + bs * 2; - dynamic_cast(graphics)->drawImageRect(0, 0, w, h, skin); + static_cast(graphics)->drawImageRect(0, 0, w, h, skin); } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 183adc93..73dbd604 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -211,12 +211,6 @@ void UpdaterWindow::loadNews() mScrollArea->setVerticalScrollAmount(0); } -void UpdaterWindow::addRow(const std::string &row) -{ - mBrowserBox->addRow(row); - mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); -} - int UpdaterWindow::updateProgress(void *ptr, double dt, double dn, double ut, double un) { @@ -418,11 +412,12 @@ void UpdaterWindow::logic() } mThread = NULL; } - addRow(""); - addRow("##1 The update process is incomplete."); - addRow("##1 It is strongly recommended that"); - addRow("##1 you try again later"); - addRow(mCurlError); + mBrowserBox->addRow(""); + mBrowserBox->addRow("##1 The update process is incomplete."); + mBrowserBox->addRow("##1 It is strongly recommended that"); + mBrowserBox->addRow("##1 you try again later"); + mBrowserBox->addRow(mCurlError); + mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); mDownloadStatus = UPDATE_COMPLETE; break; case UPDATE_NEWS: diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index adc96078..b5f6a6df 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -81,11 +81,6 @@ class UpdaterWindow : public Window, public gcn::ActionListener void action(const gcn::ActionEvent &event); - /** - * Add a row to the message field. - */ - void addRow(const std::string &row); - void logic(); int updateState; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 4c64c627..a39db509 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -309,7 +309,7 @@ Viewport::drawTargetCursor(Graphics *graphics) int rangeY = abs(target->mY - player_node->mY); int attackRange = player_node->getAttackRange(); - // get the correct target cursors graphic + // Get the correct target cursors graphic Being::TargetCursorSize cursorSize = target->getTargetCursorSize(); Image* targetCursor; if (rangeX > attackRange || rangeY > attackRange) diff --git a/src/gui/windowlistener.h b/src/gui/windowlistener.h index 08aab71d..24f6a7b8 100644 --- a/src/gui/windowlistener.h +++ b/src/gui/windowlistener.h @@ -73,12 +73,12 @@ class WindowListener /** * Called whenever the window is moved. */ - virtual void windowMoved(const WindowEvent &event) {} + virtual void windowMoved(const WindowEvent &) {} /** * Called whenever the window is resized. */ - virtual void windowResized(const WindowEvent &event) {} + virtual void windowResized(const WindowEvent &) {} }; typedef std::list WindowListeners; diff --git a/src/logindata.h b/src/logindata.h index 1ee9927d..8513428f 100644 --- a/src/logindata.h +++ b/src/logindata.h @@ -24,6 +24,8 @@ #ifndef _TMW_LOGINDATA_H #define _TMW_LOGINDATA_H +#include + struct LoginData { std::string username; diff --git a/src/particle.cpp b/src/particle.cpp index 148bbf6f..cdd6af41 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -81,6 +81,8 @@ Particle::setupEngine() logger->log("Particle engine set up"); } +void Particle::draw(Graphics *, int, int) const {} + bool Particle::update() { diff --git a/src/particle.h b/src/particle.h index dd7c5ee2..045ab9b9 100644 --- a/src/particle.h +++ b/src/particle.h @@ -89,8 +89,7 @@ class Particle : public Sprite /** * Draws the particle image. */ - virtual void - draw(Graphics *graphics, int offsetX, int offsetY) const {} + virtual void draw(Graphics *graphics, int offsetX, int offsetY) const; /** * Necessary for sorting with the other sprites. diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h index f0cd7d08..46a33b06 100644 --- a/src/resources/monsterdb.h +++ b/src/resources/monsterdb.h @@ -18,7 +18,7 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: + * $Id$ */ #ifndef _TMW_MONSTER_DB_H diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index 7b7bad70..9b841058 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -33,15 +33,15 @@ MonsterInfo::MonsterInfo(): MonsterInfo::~MonsterInfo() { - //kill vectors in mSoundEffects - for_each ( mSounds.begin(), mSounds.end(), - make_dtor(mSounds)); + // kill vectors in mSoundEffects + for_each (mSounds.begin(), mSounds.end(), + make_dtor(mSounds)); mSounds.clear(); } void -MonsterInfo::addSound (MonsterSoundEvent event, std::string filename) +MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) { if (mSounds.find(event) == mSounds.end()) { @@ -53,7 +53,7 @@ MonsterInfo::addSound (MonsterSoundEvent event, std::string filename) std::string -MonsterInfo::getSound (MonsterSoundEvent event) const +MonsterInfo::getSound(MonsterSoundEvent event) const { std::map* >::const_iterator i; diff --git a/src/sound.cpp b/src/sound.cpp index 8ba8fe99..cf77cfab 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -126,7 +126,7 @@ void Sound::setSfxVolume(int volume) Mix_Volume(-1, volume); } -void Sound::playMusic(const char *path, int loop) +void Sound::playMusic(const std::string &path, int loop) { if (!mInstalled) return; @@ -134,9 +134,10 @@ void Sound::playMusic(const char *path, int loop) stopMusic(); } - logger->log("Sound::startMusic() Playing \"%s\" %i times", path, loop); + logger->log("Sound::startMusic() Playing \"%s\" %i times", path.c_str(), + loop); - mMusic = Mix_LoadMUS(path); + mMusic = Mix_LoadMUS(path.c_str()); if (mMusic) { Mix_PlayMusic(mMusic, loop); } @@ -158,7 +159,7 @@ void Sound::stopMusic() } } -void Sound::fadeInMusic(const char *path, int loop, int ms) +void Sound::fadeInMusic(const std::string &path, int loop, int ms) { if (!mInstalled) return; @@ -166,10 +167,11 @@ void Sound::fadeInMusic(const char *path, int loop, int ms) stopMusic(); } - logger->log("Sound::fadeInMusic() Fading \"%s\" %i times (%i ms)", path, - loop, ms); + logger->log("Sound::fadeInMusic() Fading \"%s\" %i times (%i ms)", + path.c_str(), + loop, ms); - mMusic = Mix_LoadMUS(path); + mMusic = Mix_LoadMUS(path.c_str()); if (mMusic) { Mix_FadeInMusic(mMusic, loop, ms); } diff --git a/src/sound.h b/src/sound.h index 34490d9a..ebcd6442 100644 --- a/src/sound.h +++ b/src/sound.h @@ -65,7 +65,7 @@ class Sound { * @param path The full path to the music file. * @param loop The number of times the song is played (-1 = infinite) */ - void playMusic(const char *path, int loop = -1); + void playMusic(const std::string &path, int loop = -1); /** * Stops currently running background music track. @@ -79,7 +79,8 @@ class Sound { * @param loop The number of times the song is played (-1 = infinite) * @param ms Duration of fade-in effect (ms) */ - void fadeInMusic(const char *path, int loop = -1, int ms = 2000); + void fadeInMusic(const std::string &path, int loop = -1, + int ms = 2000); /** * Fades out currently running background music track. diff --git a/src/utils/trim.h b/src/utils/trim.h index 1b5311e6..fec99100 100644 --- a/src/utils/trim.h +++ b/src/utils/trim.h @@ -31,7 +31,7 @@ * * @param str the string to trim spaces off */ -static void trim(std::string &str) +inline void trim(std::string &str) { std::string::size_type pos = str.find_last_not_of(' '); if (pos != std::string::npos) -- cgit v1.2.3-60-g2f50