From 2f8d0391e93f723bd2d5836222aebf61b3962cdf Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 May 2015 18:28:08 +0300 Subject: Add safeDraw method into equipmentwindow. --- src/gui/windows/equipmentwindow.cpp | 125 +++++++++++++++++++++++++----------- src/gui/windows/equipmentwindow.h | 2 + 2 files changed, 91 insertions(+), 36 deletions(-) diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index 8da2e3071..c856433ba 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -187,54 +187,107 @@ void EquipmentWindow::draw(Graphics *graphics) const int fontHeight = font->getHeight(); const std::vector &boxes = mPages[mSelectedTab]->boxes; - if (isBatchDrawRenders(openGLMode)) + if (mLastRedraw) { - if (mLastRedraw) - { - mVertexes->clear(); - FOR_EACH (std::vector::const_iterator, it, boxes) - { - const EquipmentBox *const box = *it; - if (!box) - { - i ++; - continue; - } - if (i == mSelected) - { - graphics->calcTileCollection(mVertexes, - mSlotHighlightedBackground, - box->x, box->y); - } - else - { - graphics->calcTileCollection(mVertexes, - mSlotBackground, - box->x, box->y); - } - i ++; - } - graphics->finalize(mVertexes); - } - graphics->drawTileCollection(mVertexes); - } - else - { - for (std::vector::const_iterator it = boxes.begin(), - it_end = boxes.end(); it != it_end; ++ it, ++ i) + mVertexes->clear(); + FOR_EACH (std::vector::const_iterator, it, boxes) { const EquipmentBox *const box = *it; if (!box) + { + i ++; continue; + } if (i == mSelected) { - graphics->drawImage(mSlotHighlightedBackground, + graphics->calcTileCollection(mVertexes, + mSlotHighlightedBackground, box->x, box->y); } else { - graphics->drawImage(mSlotBackground, box->x, box->y); + graphics->calcTileCollection(mVertexes, + mSlotBackground, + box->x, box->y); } + i ++; + } + graphics->finalize(mVertexes); + } + graphics->drawTileCollection(mVertexes); + + if (!mEquipment) + { + BLOCK_END("EquipmentWindow::draw") + return; + } + + i = 0; + const int projSlot = inventoryHandler->getProjectileSlot(); + for (std::vector::const_iterator it = boxes.begin(), + it_end = boxes.end(); it != it_end; ++ it, ++ i) + { + const EquipmentBox *const box = *it; + if (!box) + continue; + const Item *const item = mEquipment->getEquipment(i); + if (item) + { + // Draw Item. + Image *const image = item->getImage(); + if (image) + { + image->setAlpha(1.0F); // Ensure the image is drawn + // with maximum opacity + graphics->drawImage(image, box->x + mItemPadding, + box->y + mItemPadding); + if (i == projSlot) + { + const std::string str = toString(item->getQuantity()); + font->drawString(graphics, + mLabelsColor, + mLabelsColor2, + str, + box->x + (mBoxSize - font->getWidth(str)) / 2, + box->y - fontHeight); + } + } + } + else if (box->image) + { + graphics->drawImage(box->image, + box->x + mItemPadding, + box->y + mItemPadding); + } + } + BLOCK_END("EquipmentWindow::draw") +} + +void EquipmentWindow::safeDraw(Graphics *graphics) +{ + BLOCK_START("EquipmentWindow::draw") + // Draw window graphics + Window::draw(graphics); + + int i = 0; + Font *const font = getFont(); + const int fontHeight = font->getHeight(); + const std::vector &boxes = mPages[mSelectedTab]->boxes; + + for (std::vector::const_iterator it = boxes.begin(), + it_end = boxes.end(); it != it_end; ++ it, ++ i) + { + const EquipmentBox *const box = *it; + if (!box) + continue; + if (i == mSelected) + { + graphics->drawImage(mSlotHighlightedBackground, + box->x, box->y); + } + else + { + graphics->drawImage(mSlotBackground, box->x, box->y); } } diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h index a8073b3c4..6ad9b2fd2 100644 --- a/src/gui/windows/equipmentwindow.h +++ b/src/gui/windows/equipmentwindow.h @@ -72,6 +72,8 @@ class EquipmentWindow final : public Window, */ void draw(Graphics *graphics) override final; + void safeDraw(Graphics *graphics) override final; + void action(const ActionEvent &event) override final; void mousePressed(MouseEvent& event) override final; -- cgit v1.2.3-70-g09d2