From 72ed6f2349432e95a9e0702664e6dea962a27855 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 25 Oct 2009 17:09:32 +0000 Subject: [PATCH] Fix scissoring for too wide/high widgets --- include/gui2/RenderContext.hpp | 4 ++-- src/gui2/RenderContext.cpp | 27 ++++++++++++++++++++------- src/gui2/Window.cpp | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/gui2/RenderContext.hpp b/include/gui2/RenderContext.hpp index 7343cf2..4aaff21 100644 --- a/include/gui2/RenderContext.hpp +++ b/include/gui2/RenderContext.hpp @@ -36,7 +36,7 @@ namespace gui { RenderContext(); ~RenderContext(); - void push_origin(int x, int y); + void push_origin(const Widget* w); void pop_origin(); void scissor(Widget* w); @@ -53,7 +53,7 @@ namespace gui { Theme theme_; int origin_x, origin_y; - stack > origin_stack; + stack origin_stack; }; } diff --git a/src/gui2/RenderContext.cpp b/src/gui2/RenderContext.cpp index 78dfb54..2207180 100644 --- a/src/gui2/RenderContext.cpp +++ b/src/gui2/RenderContext.cpp @@ -45,16 +45,17 @@ RenderContext::~RenderContext() glPopAttrib(); } -void RenderContext::push_origin(int x, int y) +void RenderContext::push_origin(const Widget* w) { - origin_x = x; - origin_y = y; - origin_stack.push(make_pair(x, y)); + origin_x = w->x(); + origin_y = w->y(); + origin_stack.push(w); } void RenderContext::pop_origin() { - tie(origin_x, origin_y) = origin_stack.top(); + origin_x = origin_stack.top()->x(); + origin_y = origin_stack.top()->y(); origin_stack.pop(); } @@ -112,7 +113,16 @@ void RenderContext::print(IFontPtr font, int x, int y, const string& s) void RenderContext::scissor(Widget* w) { - static int wh = getGameWindow()->height(); + int wh = getGameWindow()->height(); + + const Widget* parent = origin_stack.empty() ? NULL : origin_stack.top(); + int max_w, max_h; + if (parent) { + max_w = parent->width() - w->x(); + max_h = parent->height() - w->y(); + } + else + max_w = max_h = 100000; int x = w->x() - 1; int y = w->y() - 1; @@ -120,5 +130,8 @@ void RenderContext::scissor(Widget* w) y = wh - y - w->height() - 1; - glScissor(x, y, w->width() + 1, w->height()); + int width = min(w->width() + 1, max_w); + int height = min(w->height(), max_h); + + glScissor(x, y, width, height); } diff --git a/src/gui2/Window.cpp b/src/gui2/Window.cpp index 849ed03..da8278f 100644 --- a/src/gui2/Window.cpp +++ b/src/gui2/Window.cpp @@ -34,7 +34,7 @@ void Window::render(RenderContext& rc) const rc.border(x(), y(), width(), height(), rc.theme().border()); - rc.push_origin(x(), y()); + rc.push_origin(this); ContainerWidget::render(rc); -- 2.39.2