From a87e0ede82e41b47ddb9ad7810a1266ec73d51ea Mon Sep 17 00:00:00 2001 From: neoraider Date: Wed, 16 Apr 2008 19:13:03 +0000 Subject: zoomedit: * Removed scrollbars, allowing endless movement now --- src/Gui/RenderArea.cpp | 82 ++++++-------------------------------------------- src/Gui/RenderArea.h | 11 +++---- src/Util/Xml.h | 6 ++-- src/View/TopView.h | 6 ++-- src/View/View.h | 6 ++-- zoomedit.glade | 41 ++----------------------- 6 files changed, 25 insertions(+), 127 deletions(-) diff --git a/src/Gui/RenderArea.cpp b/src/Gui/RenderArea.cpp index 8062b80..eb1f3eb 100644 --- a/src/Gui/RenderArea.cpp +++ b/src/Gui/RenderArea.cpp @@ -32,7 +32,7 @@ namespace Gui { GdkGLConfig *RenderArea::glconfig = 0; RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr &xml) -: Gtk::DrawingArea(cobject), view(0), xCenter(0), yCenter(0), zoomLevel(0), scale(100) { +: Gtk::DrawingArea(cobject), view(0), xCenter(0), yCenter(0), viewWidth(0), viewHeight(0), zoomLevel(0), scale(100) { if(!glconfig) { glconfig = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DOUBLE)); if(!glconfig) glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB); // Hmm, can't find double buffered config @@ -54,12 +54,6 @@ RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtrget_widget("ToolButtonZoomOut", button); button->signal_clicked().connect(sigc::bind(sigc::mem_fun(this, &RenderArea::zoom), -2, 0.5f, 0.5f)); - xml->get_widget("Hscrollbar", hScrollbar); - hScrollbar->signal_value_changed().connect(sigc::mem_fun(this, &RenderArea::updateScrolling)); - - xml->get_widget("Vscrollbar", vScrollbar); - vScrollbar->signal_value_changed().connect(sigc::mem_fun(this, &RenderArea::updateScrolling)); - gtk_widget_set_gl_capability(GTK_WIDGET(cobject), glconfig, 0, TRUE, GDK_GL_RGBA_TYPE); } @@ -127,7 +121,7 @@ void RenderArea::zoom(int zoom, float x, float y) { zoomLevel = std::max(std::min(zoomLevel + zoom, 50), -100); scale = 100*std::pow(1.1f, zoomLevel); - updateScrollbars(x, y); + updateScrolling(x, y); } void RenderArea::updateViewport() { @@ -144,75 +138,17 @@ void RenderArea::updateViewport() { gdkGLEnd(); - updateScrollbars(); -} - -void RenderArea::updateScrollbars(float x, float y) { - float minX, maxX, minY, maxY; - const gdouble width = getViewWidth(), height = getViewHeight(); - gdouble lower, upper, pageSize, value; - - if(!view) - return; - - view->getBounds(&minX, &maxX, &minY, &maxY); - float xVal = std::max(std::fabs(minX), std::fabs(maxX)); - float yVal = std::max(std::fabs(minY), std::fabs(maxY)); - - get_window()->freeze_updates(); - - lower = hScrollbar->get_adjustment()->get_lower(); - upper = hScrollbar->get_adjustment()->get_upper(); - pageSize = hScrollbar->get_adjustment()->get_page_size(); - - hScrollbar->get_adjustment()->set_lower(-xVal + width/2); - hScrollbar->get_adjustment()->set_upper(xVal + width/2); - hScrollbar->get_adjustment()->set_page_size(width); - - if(pageSize > (upper-lower) && width < 2*xVal) - value = 0; - else - value = hScrollbar->get_value() + (x-0.5)*(pageSize-width); - - hScrollbar->set_value(std::max(std::min(value, xVal - width/2), -xVal + width/2)); - - lower = vScrollbar->get_adjustment()->get_lower(); - upper = vScrollbar->get_adjustment()->get_upper(); - pageSize = vScrollbar->get_adjustment()->get_page_size(); - - vScrollbar->get_adjustment()->set_lower(-yVal + height/2); - vScrollbar->get_adjustment()->set_upper(yVal + height/2); - vScrollbar->get_adjustment()->set_page_size(height); - - if(pageSize > (upper-lower) && height < 2*yVal) - value = 0; - else - value = vScrollbar->get_value() + (y-0.5)*(pageSize-height); - - vScrollbar->set_value(std::max(std::min(value, yVal - height/2), -yVal + height/2)); - - get_window()->thaw_updates(); - updateScrolling(); } -void RenderArea::updateScrolling() { - const float imageWidth = hScrollbar->get_adjustment()->get_upper()-hScrollbar->get_adjustment()->get_lower(); - const float imageHeight = vScrollbar->get_adjustment()->get_upper()-vScrollbar->get_adjustment()->get_lower(); - - if(hScrollbar) { - if(imageWidth < getViewWidth()) - xCenter = 0; - else - xCenter = hScrollbar->get_value(); - } +void RenderArea::updateScrolling(float x, float y) { + const float newWidth = get_width()/scale, newHeight = get_height()/scale; - if(vScrollbar) { - if(imageHeight < getViewHeight()) - yCenter = 0; - else - yCenter = vScrollbar->get_value(); - } + xCenter += (x-0.5)*(viewWidth-newWidth); + yCenter += (y-0.5)*(viewHeight-newHeight); + + viewWidth = newWidth; + viewHeight = newHeight; queue_draw(); } diff --git a/src/Gui/RenderArea.h b/src/Gui/RenderArea.h index 59498d4..8ac72d7 100644 --- a/src/Gui/RenderArea.h +++ b/src/Gui/RenderArea.h @@ -44,11 +44,11 @@ class RenderArea : public Gtk::DrawingArea { } float getViewWidth() const { - return get_width()/scale; + return viewWidth; } float getViewHeight() const { - return get_height()/scale; + return viewHeight; } float getScale() const {return scale;} @@ -59,12 +59,10 @@ class RenderArea : public Gtk::DrawingArea { private: static GdkGLConfig *glconfig; - Gtk::HScrollbar *hScrollbar; - Gtk::VScrollbar *vScrollbar; - View::View *view; float xCenter, yCenter; + float viewWidth, viewHeight; int zoomLevel; float scale; @@ -77,8 +75,7 @@ class RenderArea : public Gtk::DrawingArea { void zoom(int zoom, float x = 0.5f, float y = 0.5f); void updateViewport(); - void updateScrollbars(float x = 0.5f, float y = 0.5f); - void updateScrolling(); + void updateScrolling(float x = 0.5f, float y = 0.5f); bool gdkGLBegin() { GtkWidget *widget = GTK_WIDGET(gobj()); diff --git a/src/Util/Xml.h b/src/Util/Xml.h index a956ae8..e71f653 100644 --- a/src/Util/Xml.h +++ b/src/Util/Xml.h @@ -17,8 +17,8 @@ * with this program. If not, see . */ -#ifndef ZOOMEDIT_DATA_XML_H_ -#define ZOOMEDIT_DATA_XML_H_ +#ifndef ZOOMEDIT_UTIL_XML_H_ +#define ZOOMEDIT_UTIL_XML_H_ #include @@ -36,4 +36,4 @@ class Xml { } } -#endif /*XML_H_*/ +#endif /*ZOOMEDIT_UTIL_XML_H_*/ diff --git a/src/View/TopView.h b/src/View/TopView.h index 0996ad3..952cd32 100644 --- a/src/View/TopView.h +++ b/src/View/TopView.h @@ -17,8 +17,8 @@ * with this program. If not, see . */ -#ifndef ZOOMEDIT_TOPVIEW_H_ -#define ZOOMEDIT_TOPVIEW_H_ +#ifndef ZOOMEDIT_VIEW_TOPVIEW_H_ +#define ZOOMEDIT_VIEW_TOPVIEW_H_ #include "View.h" @@ -64,4 +64,4 @@ class TopView : public View { } } -#endif /*ZOOMEDIT_TOPVIEW_H_*/ +#endif /*ZOOMEDIT_VIEW_TOPVIEW_H_*/ diff --git a/src/View/View.h b/src/View/View.h index bb52032..cd4d5f5 100644 --- a/src/View/View.h +++ b/src/View/View.h @@ -17,8 +17,8 @@ * with this program. If not, see . */ -#ifndef ZOOMEDIT_VIEW_H_ -#define ZOOMEDIT_VIEW_H_ +#ifndef ZOOMEDIT_VIEW_VIEW_H_ +#define ZOOMEDIT_VIEW_VIEW_H_ namespace ZoomEdit { @@ -39,4 +39,4 @@ class View { } } -#endif /*ZOOMEDIT_RENDERER_H_*/ +#endif /*ZOOMEDIT_VIEW_VIEW_H_*/ diff --git a/zoomedit.glade b/zoomedit.glade index 8efd02b..0edfb2e 100644 --- a/zoomedit.glade +++ b/zoomedit.glade @@ -1,6 +1,6 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -201,47 +201,12 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 2 - 2 - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 0 100 1 10 10 - - - 1 - 2 - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 0 100 1 10 10 - - - 1 - 2 - - - - False + True True -- cgit v1.2.3