From 7369332bb0a6d219cb2415a0b5e65bf2825da349 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 May 2015 18:45:59 +0300 Subject: Add missing safeDraw to some windows. Without it drawing code can mix safe and not safe drawing. --- src/gui/windows/chatwindow.cpp | 12 ++++++++ src/gui/windows/chatwindow.h | 2 ++ src/gui/windows/debugwindow.cpp | 18 ++++++++++++ src/gui/windows/debugwindow.h | 2 ++ src/gui/windows/equipmentwindow.cpp | 2 +- src/gui/windows/minimap.cpp | 13 +++++++++ src/gui/windows/minimap.h | 4 +++ src/gui/windows/outfitwindow.cpp | 56 +++++++++++++++++++++++++++++++++++++ src/gui/windows/outfitwindow.h | 2 ++ 9 files changed, 110 insertions(+), 1 deletion(-) diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index f4641670d..824ba4882 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -2081,6 +2081,18 @@ void ChatWindow::draw(Graphics* graphics) BLOCK_END("ChatWindow::draw") } +void ChatWindow::safeDraw(Graphics* graphics) +{ + BLOCK_START("ChatWindow::draw") + if (!mAutoHide || mHaveMouse) + { + GLDEBUG_START("ChatWindow::draw"); + Window::safeDraw(graphics); + GLDEBUG_END(); + } + BLOCK_END("ChatWindow::draw") +} + void ChatWindow::updateVisibility() { if (!gui) diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index 3077b9e8b..e8d920897 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -282,6 +282,8 @@ class ChatWindow final : public Window, void draw(Graphics* graphics) override final; + void safeDraw(Graphics* graphics) override final; + void updateVisibility(); void unHideWindow(); diff --git a/src/gui/windows/debugwindow.cpp b/src/gui/windows/debugwindow.cpp index e0d73249b..185e4adab 100644 --- a/src/gui/windows/debugwindow.cpp +++ b/src/gui/windows/debugwindow.cpp @@ -134,6 +134,24 @@ void DebugWindow::draw(Graphics *g) BLOCK_END("DebugWindow::draw") } +void DebugWindow::safeDraw(Graphics *g) +{ + BLOCK_START("DebugWindow::draw") + Window::safeDraw(g); + + if (localPlayer) + { + const Being *const target = localPlayer->getTarget(); + if (target) + { + target->draw(g, -target->getPixelX() + mapTileSize / 2 + + mDimension.width / 2, -target->getPixelY() + mapTileSize + + mDimension.height / 2); + } + } + BLOCK_END("DebugWindow::draw") +} + void DebugWindow::widgetResized(const Event &event) { Window::widgetResized(event); diff --git a/src/gui/windows/debugwindow.h b/src/gui/windows/debugwindow.h index 9a0b2fe5c..5496852f6 100644 --- a/src/gui/windows/debugwindow.h +++ b/src/gui/windows/debugwindow.h @@ -56,6 +56,8 @@ class DebugWindow final : public Window void draw(Graphics *g) override final; + void safeDraw(Graphics *g) override final; + void setPing(int pingTime); void widgetResized(const Event &event) override final; diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index c856433ba..d569c3cc2 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -267,7 +267,7 @@ void EquipmentWindow::safeDraw(Graphics *graphics) { BLOCK_START("EquipmentWindow::draw") // Draw window graphics - Window::draw(graphics); + Window::safeDraw(graphics); int i = 0; Font *const font = getFont(); diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index bdf9c37be..6b2a8547a 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -237,8 +237,21 @@ void Minimap::toggle() void Minimap::draw(Graphics *graphics) { BLOCK_START("Minimap::draw") + Window::draw(graphics); + draw2(graphics); +} + +void Minimap::safeDraw(Graphics *graphics) +{ + BLOCK_START("Minimap::draw") + + Window::safeDraw(graphics); + draw2(graphics); +} +void Minimap::draw2(Graphics *const graphics) +{ if (!userPalette || !localPlayer || !viewport) { BLOCK_END("Minimap::draw") diff --git a/src/gui/windows/minimap.h b/src/gui/windows/minimap.h index 8d7ffc2a8..8c7150080 100644 --- a/src/gui/windows/minimap.h +++ b/src/gui/windows/minimap.h @@ -61,6 +61,10 @@ class Minimap final : public Window, public ConfigListener */ void draw(Graphics *graphics) override final; + void safeDraw(Graphics *graphics) override final; + + void draw2(Graphics *const graphics); + void mouseMoved(MouseEvent &event) override final; void mouseReleased(MouseEvent &event) override final; diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index 896136bb3..e1f2c3b42 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -374,6 +374,62 @@ void OutfitWindow::draw(Graphics *graphics) BLOCK_END("OutfitWindow::draw") } +void OutfitWindow::safeDraw(Graphics *graphics) +{ + BLOCK_START("OutfitWindow::draw") + Window::safeDraw(graphics); + + if (mCurrentOutfit < 0 || mCurrentOutfit + >= static_cast(OUTFITS_COUNT)) + { + return; + } + + for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++) + { + const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth); + const int itemY = mPadding + mTitleBarHeight + + ((i / static_cast(mGridWidth)) * mBoxHeight); + + graphics->setColor(mBorderColor); + graphics->drawRectangle(Rect(itemX, itemY, 32, 32)); + graphics->setColor(mBackgroundColor); + graphics->fillRectangle(Rect(itemX, itemY, 32, 32)); + + if (mItems[mCurrentOutfit][i] < 0) + continue; + + bool foundItem = false; + const Inventory *const inv = PlayerInfo::getInventory(); + if (inv) + { + const Item *const item = inv->findItem(mItems[mCurrentOutfit][i], + mItemColors[mCurrentOutfit][i]); + if (item) + { + // Draw item icon. + const Image *const image = item->getImage(); + if (image) + { + graphics->drawImage(image, itemX, itemY); + foundItem = true; + } + } + } + if (!foundItem) + { + Image *const image = Item::getImage(mItems[mCurrentOutfit][i], + mItemColors[mCurrentOutfit][i]); + if (image) + { + graphics->drawImage(image, itemX, itemY); + image->decRef(); + } + } + } + BLOCK_END("OutfitWindow::draw") +} + void OutfitWindow::mouseDragged(MouseEvent &event) { if (event.getButton() == MouseButton::LEFT) diff --git a/src/gui/windows/outfitwindow.h b/src/gui/windows/outfitwindow.h index defaf4c4d..b27bd7d4a 100644 --- a/src/gui/windows/outfitwindow.h +++ b/src/gui/windows/outfitwindow.h @@ -54,6 +54,8 @@ class OutfitWindow final : public Window, void draw(Graphics *graphics) override final; + void safeDraw(Graphics *graphics) override final; + void mousePressed(MouseEvent &event) override final; void mouseDragged(MouseEvent &event) override final; -- cgit v1.2.3-70-g09d2