From 0a27cfed1d2d28c8a5af7d00be1d1b14c31e204f Mon Sep 17 00:00:00 2001 From: Helge Norberg Date: Thu, 5 Nov 2015 17:15:44 +0100 Subject: [PATCH] Limit the scrolling (dragging or mouse wheel) in diag window so that the graphs are always within the viewport --- core/diagnostics/osd_graph.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/diagnostics/osd_graph.cpp b/core/diagnostics/osd_graph.cpp index f9b49c273..502a038cb 100644 --- a/core/diagnostics/osd_graph.cpp +++ b/core/diagnostics/osd_graph.cpp @@ -207,10 +207,18 @@ private: if (calculate_view_) { + int content_height = static_cast(RENDERING_HEIGHT * drawables_.size()); + int window_height = static_cast(window_->getSize().y); + int not_visible = std::max(0, content_height - window_height); + int min_scroll_position = -not_visible; + int max_scroll_position = 0; + + scroll_position_ = std::min(max_scroll_position, std::max(min_scroll_position, scroll_position_)); view_.setViewport(sf::FloatRect(0, 0, 1.0, 1.0)); - view_.setSize(RENDERING_WIDTH, window_->getSize().y); - view_.setCenter(RENDERING_WIDTH / 2, window_->getSize().y / 2 - scroll_position_); + view_.setSize(RENDERING_WIDTH, window_height); + view_.setCenter(RENDERING_WIDTH / 2, window_height / 2 - scroll_position_); window_->setView(view_); + calculate_view_ = false; } -- 2.39.2