summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/basiccontainer.cpp7
-rw-r--r--src/gui/widgets/colorpage.cpp5
-rw-r--r--src/gui/widgets/colorpage.h2
-rw-r--r--src/gui/widgets/desktop.cpp5
-rw-r--r--src/gui/widgets/desktop.h2
-rw-r--r--src/gui/widgets/guitable.cpp103
-rw-r--r--src/gui/widgets/passwordfield.cpp5
-rw-r--r--src/gui/widgets/passwordfield.h2
-rw-r--r--src/gui/widgets/progressindicator.cpp10
-rw-r--r--src/gui/widgets/serverslistbox.h5
-rw-r--r--src/gui/widgets/shoplistbox.cpp5
-rw-r--r--src/gui/widgets/shoplistbox.h2
-rw-r--r--src/gui/widgets/skilllistbox.h5
-rw-r--r--src/gui/widgets/sliderlist.cpp13
-rw-r--r--src/gui/widgets/sliderlist.h2
15 files changed, 170 insertions, 3 deletions
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
index 2ab185a61..6d09cb64b 100644
--- a/src/gui/widgets/basiccontainer.cpp
+++ b/src/gui/widgets/basiccontainer.cpp
@@ -63,6 +63,8 @@
#include "gui/widgets/basiccontainer.h"
+#include "render/renderers.h"
+
#include <algorithm>
#include "debug.h"
@@ -322,7 +324,10 @@ void BasicContainer::drawChildren(Graphics* graphics)
graphics->pushClipArea(widget->mDimension);
BLOCK_START("BasicContainer::drawChildren 2")
- widget->draw(graphics);
+ if (isBatchDrawRenders(openGLMode))
+ widget->draw(graphics);
+ else
+ widget->safeDraw(graphics);
BLOCK_END("BasicContainer::drawChildren 2")
graphics->popClipArea();
}
diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp
index 7ecb323b4..6897399d5 100644
--- a/src/gui/widgets/colorpage.cpp
+++ b/src/gui/widgets/colorpage.cpp
@@ -99,6 +99,11 @@ void ColorPage::draw(Graphics *graphics)
BLOCK_END("ColorPage::draw")
}
+void ColorPage::safeDraw(Graphics *graphics)
+{
+ ColorPage::draw(graphics);
+}
+
void ColorPage::resetAction()
{
setSelected(-1);
diff --git a/src/gui/widgets/colorpage.h b/src/gui/widgets/colorpage.h
index 79e27cc45..4863aaa60 100644
--- a/src/gui/widgets/colorpage.h
+++ b/src/gui/widgets/colorpage.h
@@ -38,6 +38,8 @@ class ColorPage final : public ListBox
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
void resetAction();
void adjustSize() override final;
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index 291c77852..086854a73 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -155,6 +155,11 @@ void Desktop::draw(Graphics *graphics)
BLOCK_END("Desktop::draw")
}
+void Desktop::safeDraw(Graphics *graphics)
+{
+ Desktop::draw(graphics);
+}
+
void Desktop::setBestFittingWallpaper()
{
if (!mShowBackground || !config.getBoolValue("showBackground"))
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
index 7257311bd..da1c32c0b 100644
--- a/src/gui/widgets/desktop.h
+++ b/src/gui/widgets/desktop.h
@@ -67,6 +67,8 @@ class Desktop final : public Container,
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
void postInit();
void handleLink(const std::string &link,
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index 4f8b89027..c08170348 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -349,7 +349,108 @@ void GuiTable::draw(Graphics* graphics)
void GuiTable::safeDraw(Graphics* graphics)
{
- GuiTable::draw(graphics);
+ if (!mModel || !getRowHeight())
+ return;
+
+ BLOCK_START("GuiTable::draw")
+ if (settings.guiAlpha != mAlpha)
+ mAlpha = settings.guiAlpha;
+
+ const Rect &rect = mDimension;
+ const int width = rect.width;
+ const int height = rect.height;
+ const int y = rect.y;
+ if (mOpaque)
+ {
+ mBackgroundColor.a = static_cast<int>(mAlpha * 255.0F);
+ graphics->setColor(mBackgroundColor);
+ graphics->fillRectangle(Rect(0, 0, width, height));
+ }
+
+ // First, determine how many rows we need to draw,
+ // and where we should start.
+ int rHeight = getRowHeight();
+ if (!rHeight)
+ rHeight = 1;
+ int first_row = -(y / rHeight);
+
+ if (first_row < 0)
+ first_row = 0;
+
+ unsigned rows_nr = 1 + (height / rHeight); // May overestimate by one.
+ unsigned max_rows_nr;
+ if (mModel->getRows() < first_row)
+ max_rows_nr = 0;
+ else
+ max_rows_nr = mModel->getRows() - first_row; // clip if neccessary:
+ if (max_rows_nr < rows_nr)
+ rows_nr = max_rows_nr;
+
+ // Now determine the first and last column
+ // Take the easy way out; these are usually bounded and all visible.
+ const unsigned first_column = 0;
+ const unsigned last_column1 = mModel->getColumns();
+
+ int y_offset = first_row * rHeight;
+
+ for (unsigned r = first_row; r < first_row + rows_nr; ++r)
+ {
+ int x_offset = 0;
+
+ for (unsigned c = first_column; c + 1 <= last_column1; ++c)
+ {
+ Widget *const widget = mModel->getElementAt(r, c);
+ const int cWidth = getColumnWidth(c);
+ if (widget)
+ {
+ Rect bounds(x_offset, y_offset, cWidth, rHeight);
+
+ if (widget == mTopWidget)
+ {
+ bounds.height = widget->getHeight();
+ bounds.width = widget->getWidth();
+ }
+
+ widget->setDimension(bounds);
+
+ if (mSelectedRow > -1)
+ {
+ mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
+ graphics->setColor(mHighlightColor);
+
+ if (mLinewiseMode && r == static_cast<unsigned>(
+ mSelectedRow) && c == 0)
+ {
+ graphics->fillRectangle(Rect(0, y_offset,
+ width, rHeight));
+ }
+ else if (!mLinewiseMode && mSelectedColumn > 0
+ && c == static_cast<unsigned>(mSelectedColumn)
+ && r == static_cast<unsigned>(mSelectedRow))
+ {
+ graphics->fillRectangle(Rect(
+ x_offset, y_offset, cWidth, rHeight));
+ }
+ }
+ graphics->pushClipArea(bounds);
+ widget->safeDraw(graphics);
+ graphics->popClipArea();
+ }
+
+ x_offset += cWidth;
+ }
+
+ y_offset += rHeight;
+ }
+
+ if (mTopWidget)
+ {
+ const Rect &bounds = mTopWidget->getDimension();
+ graphics->pushClipArea(bounds);
+ mTopWidget->safeDraw(graphics);
+ graphics->popClipArea();
+ }
+ BLOCK_END("GuiTable::draw")
}
void GuiTable::moveToTop(Widget *widget)
diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp
index d9703b935..77094cd92 100644
--- a/src/gui/widgets/passwordfield.cpp
+++ b/src/gui/widgets/passwordfield.cpp
@@ -48,3 +48,8 @@ void PasswordField::draw(Graphics *graphics)
mText = original;
BLOCK_END("PasswordField::draw")
}
+
+void PasswordField::safeDraw(Graphics *graphics)
+{
+ PasswordField::draw(graphics);
+}
diff --git a/src/gui/widgets/passwordfield.h b/src/gui/widgets/passwordfield.h
index f997f1f51..0efce0dcf 100644
--- a/src/gui/widgets/passwordfield.h
+++ b/src/gui/widgets/passwordfield.h
@@ -46,6 +46,8 @@ class PasswordField final : public TextField
*/
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
protected:
unsigned char mPasswordChar;
};
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
index a3df73b8a..cdbbc7335 100644
--- a/src/gui/widgets/progressindicator.cpp
+++ b/src/gui/widgets/progressindicator.cpp
@@ -82,5 +82,13 @@ void ProgressIndicator::draw(Graphics *graphics)
void ProgressIndicator::safeDraw(Graphics *graphics)
{
- ProgressIndicator::draw(graphics);
+ BLOCK_START("ProgressIndicator::draw")
+ if (mIndicator)
+ {
+ // Draw the indicator centered on the widget
+ const int x = (mDimension.width - 32) / 2;
+ const int y = (mDimension.height - 32) / 2;
+ mIndicator->draw(graphics, x, y);
+ }
+ BLOCK_END("ProgressIndicator::draw")
}
diff --git a/src/gui/widgets/serverslistbox.h b/src/gui/widgets/serverslistbox.h
index cd94e10bc..b7129eb39 100644
--- a/src/gui/widgets/serverslistbox.h
+++ b/src/gui/widgets/serverslistbox.h
@@ -140,6 +140,11 @@ class ServersListBox final : public ListBox
}
}
+ void safeDraw(Graphics *graphics) override final
+ {
+ ServersListBox::draw(graphics);
+ }
+
unsigned int getRowHeight() const override final
{
return 2 * getFont()->getHeight() + 5;
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index b29951a73..63a295c1e 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -175,6 +175,11 @@ void ShopListBox::draw(Graphics *graphics)
BLOCK_END("ShopListBox::draw")
}
+void ShopListBox::safeDraw(Graphics *graphics)
+{
+ ShopListBox::draw(graphics);
+}
+
void ShopListBox::adjustSize()
{
BLOCK_START("ShopListBox::adjustSize")
diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h
index ee95cbb49..ff7835dd0 100644
--- a/src/gui/widgets/shoplistbox.h
+++ b/src/gui/widgets/shoplistbox.h
@@ -57,6 +57,8 @@ class ShopListBox final : public ListBox
*/
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
/**
* gives information about the current player's money
*/
diff --git a/src/gui/widgets/skilllistbox.h b/src/gui/widgets/skilllistbox.h
index e012aabd3..4b2db054c 100644
--- a/src/gui/widgets/skilllistbox.h
+++ b/src/gui/widgets/skilllistbox.h
@@ -174,6 +174,11 @@ class SkillListBox final : public ListBox
}
}
+ void safeDraw(Graphics *graphics) override final
+ {
+ SkillListBox::draw(graphics);
+ }
+
unsigned int getRowHeight() const override final
{ return mRowHeight; }
diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp
index 22fcb8956..3dc5df633 100644
--- a/src/gui/widgets/sliderlist.cpp
+++ b/src/gui/widgets/sliderlist.cpp
@@ -120,6 +120,19 @@ void SliderList::draw(Graphics *graphics)
BLOCK_END("SliderList::draw")
}
+void SliderList::safeDraw(Graphics *graphics)
+{
+ BLOCK_START("SliderList::draw")
+ const int width = mDimension.width;
+ if (mOldWidth != width)
+ {
+ resize();
+ mOldWidth = width;
+ }
+ Container::draw(graphics);
+ BLOCK_END("SliderList::draw")
+}
+
void SliderList::updateLabel()
{
if (!mListModel || mSelectedIndex < 0
diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h
index 52c4e7ea1..d2a4d8071 100644
--- a/src/gui/widgets/sliderlist.h
+++ b/src/gui/widgets/sliderlist.h
@@ -57,6 +57,8 @@ class SliderList final : public Container,
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
void action(const ActionEvent &event) override final;
void setSelectedString(const std::string &str);