From c217b7141df580b686a0eef085bd0eb0a8e6771a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 21 Sep 2012 01:27:20 +0300 Subject: Add to equipment window, background image theming. New theme file: equipment_background.xml --- src/gui/equipmentwindow.cpp | 44 ++++++++++++++++++++++++-------------------- src/gui/equipmentwindow.h | 2 ++ 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 1265d2119..a69343b77 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -65,7 +65,10 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment, mSelected(-1), mForing(foring), mImageSet(nullptr), - mBeing(being) + mBeing(being), + mHighlightColor(Theme::getThemeColor(Theme::HIGHLIGHT)), + mBorderColor(Theme::getThemeColor(Theme::BORDER)), + mLabelsColor(Theme::getThemeColor(Theme::LABEL)) { if (setupWindow) setupWindow->registerWindowForReset(this); @@ -99,12 +102,13 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment, area.height - mUnequip->getHeight() - buttonPadding); mUnequip->setEnabled(false); + ImageRect rect; + Theme::instance()->loadRect(rect, "equipment_background.xml", "", 0, 1); + mSlotBackground = rect.grid[0]; + mSlotHighlightedBackground = rect.grid[1]; add(mPlayerBox); add(mUnequip); - mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); - mBorderColor = Theme::getThemeColor(Theme::BORDER); - mLabelsColor = Theme::getThemeColor(Theme::LABEL); } EquipmentWindow::~EquipmentWindow() @@ -125,15 +129,17 @@ EquipmentWindow::~EquipmentWindow() mImageSet->decRef(); mImageSet = nullptr; } + if (mSlotBackground) + mSlotBackground->decRef(); + if (mSlotHighlightedBackground) + mSlotHighlightedBackground->decRef(); } void EquipmentWindow::draw(gcn::Graphics *graphics) { // Draw window graphics Window::draw(graphics); - Graphics *const g = static_cast(graphics); - Window::drawChildren(graphics); int i = 0; @@ -146,23 +152,21 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) if (!box) continue; if (i == mSelected) - { - mHighlightColor.a = getGuiAlpha(); - // Set color to the highlight color - g->setColor(mHighlightColor); - g->fillRectangle(gcn::Rectangle(box->x, box->y, - BOX_WIDTH, BOX_HEIGHT)); - } + g->drawImage(mSlotHighlightedBackground, box->x, box->y); + else + g->drawImage(mSlotBackground, box->x, box->y); + } - // Set color black - g->setColor(mBorderColor); - // Draw box border - g->drawRectangle(gcn::Rectangle(box->x, box->y, - BOX_WIDTH, BOX_HEIGHT)); + if (!mEquipment) + return; - if (!mEquipment) + i = 0; + for (std::vector::const_iterator it = mBoxes.begin(), + it_end = mBoxes.end(); it != it_end; ++ it, ++ i) + { + const EquipmentBox *const box = *it; + if (!box) continue; - const Item *const item = mEquipment->getEquipment(i); if (item) { diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index c30d04504..a2f87ca3c 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -136,6 +136,8 @@ class EquipmentWindow : public Window, public gcn::ActionListener gcn::Color mHighlightColor; gcn::Color mBorderColor; gcn::Color mLabelsColor; + Image *mSlotBackground; + Image *mSlotHighlightedBackground; }; extern EquipmentWindow *equipmentWindow; -- cgit v1.2.3-70-g09d2