summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-25 20:43:53 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-25 21:33:18 +0300
commitbea613d8ba11a64ccf36a01735f2839894ca9476 (patch)
tree8d5de8bf983f13aec50b3f1234db09b88dff26d3 /src
parent80b0caa35e4b84b745daef7e4102b428539cdee5 (diff)
downloadplus-bea613d8ba11a64ccf36a01735f2839894ca9476.tar.gz
plus-bea613d8ba11a64ccf36a01735f2839894ca9476.tar.bz2
plus-bea613d8ba11a64ccf36a01735f2839894ca9476.tar.xz
plus-bea613d8ba11a64ccf36a01735f2839894ca9476.zip
Fix some issues in safe OpenGL renderer after last changes.
Diffstat (limited to 'src')
-rw-r--r--src/gui/viewport.cpp5
-rw-r--r--src/gui/viewport.h2
-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
-rw-r--r--src/gui/windows/connectiondialog.cpp8
-rw-r--r--src/gui/windows/connectiondialog.h2
-rw-r--r--src/gui/windows/ministatuswindow.cpp7
-rw-r--r--src/gui/windows/ministatuswindow.h2
21 files changed, 196 insertions, 3 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 473f6614e..196ac5d1c 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -269,6 +269,11 @@ void Viewport::draw(Graphics *graphics)
BLOCK_END("Viewport::draw 1")
}
+void Viewport::safeDraw(Graphics *graphics)
+{
+ Viewport::draw(graphics);
+}
+
void Viewport::logic()
{
BLOCK_START("Viewport::logic")
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 691e02318..10a5b6643 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -74,6 +74,8 @@ class Viewport final : public WindowContainer,
*/
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
/**
* Implements player to keep following mouse.
*/
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);
diff --git a/src/gui/windows/connectiondialog.cpp b/src/gui/windows/connectiondialog.cpp
index bdbd6af69..a01d7e353 100644
--- a/src/gui/windows/connectiondialog.cpp
+++ b/src/gui/windows/connectiondialog.cpp
@@ -80,3 +80,11 @@ void ConnectionDialog::draw(Graphics *graphics)
drawChildren(graphics);
BLOCK_END("ConnectionDialog::draw")
}
+
+void ConnectionDialog::safeDraw(Graphics *graphics)
+{
+ BLOCK_START("ConnectionDialog::draw")
+ // Don't draw the window background, only draw the children
+ drawChildren(graphics);
+ BLOCK_END("ConnectionDialog::draw")
+}
diff --git a/src/gui/windows/connectiondialog.h b/src/gui/windows/connectiondialog.h
index 39c802c3a..6fdeeff00 100644
--- a/src/gui/windows/connectiondialog.h
+++ b/src/gui/windows/connectiondialog.h
@@ -60,6 +60,8 @@ class ConnectionDialog final : public Window,
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
private:
State mCancelState;
};
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index 27dfc3d75..7341094aa 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -319,6 +319,13 @@ void MiniStatusWindow::draw(Graphics *graphics)
BLOCK_END("MiniStatusWindow::draw")
}
+void MiniStatusWindow::safeDraw(Graphics *graphics)
+{
+ BLOCK_START("MiniStatusWindow::draw")
+ drawChildren(graphics);
+ BLOCK_END("MiniStatusWindow::draw")
+}
+
void MiniStatusWindow::mouseMoved(MouseEvent &event)
{
Window::mouseMoved(event);
diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h
index 923e74696..8d46fbdf9 100644
--- a/src/gui/windows/ministatuswindow.h
+++ b/src/gui/windows/ministatuswindow.h
@@ -71,6 +71,8 @@ class MiniStatusWindow final : public Window,
void draw(Graphics *graphics) override final;
+ void safeDraw(Graphics *graphics) override final;
+
void mouseMoved(MouseEvent &event) override final;
void mousePressed(MouseEvent &event) override final;