From 20cc03c8c08c953c98a40c36e7350da289b7c1ee Mon Sep 17 00:00:00 2001 From: skyjake Date: Fri, 25 Oct 2013 11:17:09 +0300 Subject: [PATCH] LogWidget: Use normalized scissor for content clipping Widgets should always use a normalized scissor rather than specifying the window coordinates manually, as the root widget's size may not be the same as the window. Todo: LegacyWidget must use a normalized scissor, too. --- .../client/include/ui/framework/guiwidget.h | 1 + doomsday/client/src/ui/framework/guiwidget.cpp | 17 +++++++++++++---- doomsday/client/src/ui/widgets/logwidget.cpp | 4 +++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doomsday/client/include/ui/framework/guiwidget.h b/doomsday/client/include/ui/framework/guiwidget.h index ae692da97b..c79f785a19 100644 --- a/doomsday/client/include/ui/framework/guiwidget.h +++ b/doomsday/client/include/ui/framework/guiwidget.h @@ -187,6 +187,7 @@ class GuiWidget : public QObject, public de::Widget ui::Margins const &margins() const; de::Rectanglef normalizedRect() const; + de::Rectanglef normalizedRect(de::Rectanglei const &viewSpaceRect) const; /** * Normalized content rectangle. Same as normalizedRect() except margins diff --git a/doomsday/client/src/ui/framework/guiwidget.cpp b/doomsday/client/src/ui/framework/guiwidget.cpp index 5dcd79af8c..c7271d01ff 100644 --- a/doomsday/client/src/ui/framework/guiwidget.cpp +++ b/doomsday/client/src/ui/framework/guiwidget.cpp @@ -358,10 +358,19 @@ Rectanglef GuiWidget::normalizedRect() const { Rectanglef const rect = rule().rect(); GuiRootWidget::Size const &viewSize = root().viewSize(); - return Rectanglef(Vector2f(float(rect.left()) / float(viewSize.x), - float(rect.top()) / float(viewSize.y)), - Vector2f(float(rect.right()) / float(viewSize.x), - float(rect.bottom()) / float(viewSize.y))); + return Rectanglef(Vector2f(rect.left() / float(viewSize.x), + rect.top() / float(viewSize.y)), + Vector2f(rect.right() / float(viewSize.x), + rect.bottom() / float(viewSize.y))); +} + +Rectanglef GuiWidget::normalizedRect(Rectanglei const &viewSpaceRect) const +{ + GuiRootWidget::Size const &viewSize = root().viewSize(); + return Rectanglef(Vector2f(float(viewSpaceRect.left()) / float(viewSize.x), + float(viewSpaceRect.top()) / float(viewSize.y)), + Vector2f(float(viewSpaceRect.right()) / float(viewSize.x), + float(viewSpaceRect.bottom()) / float(viewSize.y))); } Rectanglef GuiWidget::normalizedContentRect() const diff --git a/doomsday/client/src/ui/widgets/logwidget.cpp b/doomsday/client/src/ui/widgets/logwidget.cpp index f4b9c1767a..804cfd646e 100644 --- a/doomsday/client/src/ui/widgets/logwidget.cpp +++ b/doomsday/client/src/ui/widgets/logwidget.cpp @@ -746,7 +746,9 @@ public Font::RichFormat::IStyle { GLState &st = GLState::push(); // Leave room for the indicator in the scissor. - st.setScissor(vp.adjusted(Vector2i(), Vector2i(self.margins().right().valuei(), 0))); + st.setNormalizedScissor( + self.normalizedRect(vp.adjusted(Vector2i(), + Vector2i(self.margins().right().valuei(), 0)))); // First draw the shadow of the text. uMvpMatrix = projMatrix * Matrix4f::translate(