summaryrefslogtreecommitdiffstats
path: root/src/Gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/Gui')
-rw-r--r--src/Gui/RenderArea.cpp82
-rw-r--r--src/Gui/RenderArea.h11
2 files changed, 13 insertions, 80 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<Gnome::Glade::Xml> &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::RefPtr<Gnome::Glade:
xml->get_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());