diff options
-rw-r--r-- | src/gui/shortcutwindow.cpp | 7 | ||||
-rw-r--r-- | src/gui/shortcutwindow.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/dropshortcutcontainer.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/emoteshortcutcontainer.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/itemshortcutcontainer.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/shortcutcontainer.cpp | 41 | ||||
-rw-r--r-- | src/gui/widgets/shortcutcontainer.h | 10 | ||||
-rw-r--r-- | src/gui/widgets/spellshortcutcontainer.cpp | 10 |
8 files changed, 63 insertions, 40 deletions
diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index e4e946931..28dcdd07e 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -216,3 +216,10 @@ void ShortcutWindow::mouseDragged(gcn::MouseEvent &event) setPosition(newX, newY); } } + +void ShortcutWindow::widgetMoved(const gcn::Event& event) +{ + Window::widgetMoved(event); + if (mItems) + mItems->setRedraw(true); +} diff --git a/src/gui/shortcutwindow.h b/src/gui/shortcutwindow.h index f5d0fbab3..c1bf26a38 100644 --- a/src/gui/shortcutwindow.h +++ b/src/gui/shortcutwindow.h @@ -61,6 +61,8 @@ class ShortcutWindow final : public Window void widgetHidden(const gcn::Event &event) override; + void widgetMoved(const gcn::Event& event) override; + void mousePressed(gcn::MouseEvent &event) override; void mouseDragged(gcn::MouseEvent &event) override; diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index 756738eb0..a1c7d2742 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -100,17 +100,8 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) } Graphics *const g = static_cast<Graphics*>(graphics); - graphics->setFont(getFont()); - - if (mBackgroundImg) - { - for (unsigned i = 0; i < mMaxItems; i++) - { - g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth, - (i / mGridWidth) * mBoxHeight); - } - } + drawBackground(g); const Inventory *const inv = PlayerInfo::getInventory(); if (!inv) diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 1d1a5a60b..dcd4fa08e 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -110,17 +110,8 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) mBackgroundImg->setAlpha(mAlpha); Graphics *const g = static_cast<Graphics *const>(graphics); - graphics->setFont(getFont()); - - if (mBackgroundImg) - { - for (unsigned i = 0; i < mMaxItems; i++) - { - g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth, - (i / mGridWidth) * mBoxHeight); - } - } + drawBackground(g); graphics->setColor(mForegroundColor); for (unsigned i = 0; i < mMaxItems; i++) diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 44248258c..c11d2a2e0 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -116,17 +116,8 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) } Graphics *const g = static_cast<Graphics*>(graphics); - graphics->setFont(getFont()); - - if (mBackgroundImg) - { - for (unsigned i = 0; i < mMaxItems; i++) - { - g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth, - (i / mGridWidth) * mBoxHeight); - } - } + drawBackground(g); const Inventory *const inv = PlayerInfo::getInventory(); if (!inv) diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp index ba3ad3325..245ec90b5 100644 --- a/src/gui/widgets/shortcutcontainer.cpp +++ b/src/gui/widgets/shortcutcontainer.cpp @@ -23,6 +23,7 @@ #include "gui/widgets/shortcutcontainer.h" #include "configuration.h" +#include "graphicsvertexes.h" #include "resources/image.h" @@ -42,7 +43,9 @@ ShortcutContainer::ShortcutContainer() : mCursorPosX(0), mCursorPosY(0), mGridWidth(1), - mGridHeight(1) + mGridHeight(1), + mVertexes(new ImageCollection), + mRedraw(true) { } @@ -59,6 +62,7 @@ void ShortcutContainer::widgetResized(const gcn::Event &event A_UNUSED) ++mGridHeight; setHeight(mGridHeight * mBoxHeight); + mRedraw = true; } int ShortcutContainer::getIndexFromGrid(const int pointX, @@ -77,3 +81,38 @@ int ShortcutContainer::getIndexFromGrid(const int pointX, return index; } + +void ShortcutContainer::drawBackground(Graphics *g) +{ + if (mBackgroundImg) + { + if (openGLMode != 2) + { + if (mRedraw) + { + mRedraw = false; + mVertexes->clear(); + for (unsigned i = 0; i < mMaxItems; i ++) + { + g->calcTile(mVertexes, mBackgroundImg, + (i % mGridWidth) * mBoxWidth, + (i / mGridWidth) * mBoxHeight); + } + } + g->drawTile(mVertexes); + } + else + { + for (unsigned i = 0; i < mMaxItems; i ++) + { + g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth, + (i / mGridWidth) * mBoxHeight); + } + } + } +} + +void ShortcutContainer::widgetMoved(const gcn::Event& event) +{ + mRedraw = true; +} diff --git a/src/gui/widgets/shortcutcontainer.h b/src/gui/widgets/shortcutcontainer.h index 7cb51cbc5..568dc451b 100644 --- a/src/gui/widgets/shortcutcontainer.h +++ b/src/gui/widgets/shortcutcontainer.h @@ -30,6 +30,7 @@ #include <guichan/widgetlistener.hpp> class Image; +class ImageCollection; /** * A generic shortcut container. @@ -66,6 +67,8 @@ class ShortcutContainer : public gcn::Widget, */ virtual void widgetResized(const gcn::Event &event) override; + virtual void widgetMoved(const gcn::Event& event) override; + /** * Handles mouse when dragged. */ @@ -90,6 +93,11 @@ class ShortcutContainer : public gcn::Widget, int getBoxHeight() const A_WARN_UNUSED { return mBoxHeight; } + void drawBackground(Graphics *g); + + void setRedraw(bool b) + { mRedraw = true; } + protected: /** * Gets the index from the grid provided the point is in an item box. @@ -109,6 +117,8 @@ class ShortcutContainer : public gcn::Widget, int mBoxHeight; int mCursorPosX, mCursorPosY; int mGridWidth, mGridHeight; + ImageCollection *mVertexes; + bool mRedraw; }; #endif diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 10e82676e..af9457078 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -107,15 +107,7 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics) const int selectedId = spellShortcut->getSelectedItem(); g->setColor(mForegroundColor); - - if (mBackgroundImg) - { - for (unsigned i = 0; i < mMaxItems; i++) - { - g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth, - (i / mGridWidth) * mBoxHeight); - } - } + drawBackground(g); for (unsigned i = 0; i < mMaxItems; i++) { |