summaryrefslogtreecommitdiffstats
path: root/src/Gui
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2008-04-15 22:43:02 +0200
committerneoraider <devnull@localhost>2008-04-15 22:43:02 +0200
commitcfd608527e167877d623bf5b9682b5c4b6130df9 (patch)
treed1f72729554e0f647d8028f006fa656f9af085c0 /src/Gui
parentbb09e9e703caceab0c5c5774509fb7167ead8d49 (diff)
downloadzoomedit-cfd608527e167877d623bf5b9682b5c4b6130df9.tar
zoomedit-cfd608527e167877d623bf5b9682b5c4b6130df9.zip
zoomedit:
* Calculate model dimensions
Diffstat (limited to 'src/Gui')
-rw-r--r--src/Gui/RenderArea.cpp96
-rw-r--r--src/Gui/RenderArea.h4
2 files changed, 50 insertions, 50 deletions
diff --git a/src/Gui/RenderArea.cpp b/src/Gui/RenderArea.cpp
index 6b6b8ed..4d250f8 100644
--- a/src/Gui/RenderArea.cpp
+++ b/src/Gui/RenderArea.cpp
@@ -49,20 +49,16 @@ RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade:
Gtk::ToolButton *button;
xml->get_widget("ToolButtonZoomIn", button);
- if(button)
- button->signal_clicked().connect(sigc::bind(sigc::mem_fun(this, &RenderArea::zoom), 2, 0.5f, 0.5f));
+ button->signal_clicked().connect(sigc::bind(sigc::mem_fun(this, &RenderArea::zoom), 2, 0.5f, 0.5f));
xml->get_widget("ToolButtonZoomOut", button);
- if(button)
- button->signal_clicked().connect(sigc::bind(sigc::mem_fun(this, &RenderArea::zoom), -2, 0.5f, 0.5f));
+ button->signal_clicked().connect(sigc::bind(sigc::mem_fun(this, &RenderArea::zoom), -2, 0.5f, 0.5f));
xml->get_widget("Hscrollbar", hScrollbar);
- if(hScrollbar)
- hScrollbar->signal_value_changed().connect(sigc::mem_fun(this, &RenderArea::updateScrolling));
+ hScrollbar->signal_value_changed().connect(sigc::mem_fun(this, &RenderArea::updateScrolling));
xml->get_widget("Vscrollbar", vScrollbar);
- if(vScrollbar)
- vScrollbar->signal_value_changed().connect(sigc::mem_fun(this, &RenderArea::updateScrolling));
+ 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);
}
@@ -152,63 +148,69 @@ void RenderArea::updateViewport() {
}
void RenderArea::updateScrollbars(float x, float y) {
- const gdouble imageWidth = getImageWidth(), imageHeight = getImageHeight();
- const gdouble minX = -imageWidth/2, maxX = imageWidth/2;
- const gdouble minY = -imageHeight/2, maxY = imageHeight/2;
+ 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();
- if(hScrollbar) {
- lower = hScrollbar->get_adjustment()->get_lower();
- upper = hScrollbar->get_adjustment()->get_upper();
- pageSize = hScrollbar->get_adjustment()->get_page_size();
-
- hScrollbar->get_adjustment()->set_lower(minX + width/2);
- hScrollbar->get_adjustment()->set_upper(maxX + width/2);
- hScrollbar->get_adjustment()->set_page_size(width);
-
- if(pageSize > (upper-lower) && width < imageWidth)
- value = 0;
- else
- value = hScrollbar->get_value() + (x-0.5)*(pageSize-width);
-
- hScrollbar->set_value(std::max(std::min(value, maxX - width/2), minX + width/2));
- }
+ lower = hScrollbar->get_adjustment()->get_lower();
+ upper = hScrollbar->get_adjustment()->get_upper();
+ pageSize = hScrollbar->get_adjustment()->get_page_size();
- if(vScrollbar) {
- lower = vScrollbar->get_adjustment()->get_lower();
- upper = vScrollbar->get_adjustment()->get_upper();
- pageSize = vScrollbar->get_adjustment()->get_page_size();
-
- vScrollbar->get_adjustment()->set_lower(minY + height/2);
- vScrollbar->get_adjustment()->set_upper(maxY + height/2);
- vScrollbar->get_adjustment()->set_page_size(height);
-
- if(pageSize > (upper-lower) && height < imageHeight)
- value = 0;
- else
- value = vScrollbar->get_value() + (y-0.5)*(pageSize-height);
-
- vScrollbar->set_value(std::max(std::min(value, maxY - height/2), minY + height/2));
- }
+ 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();
+ updateScrollingWithSize(2*xVal, 2*yVal);
}
void RenderArea::updateScrolling() {
+ updateScrollingWithSize(hScrollbar->get_adjustment()->get_upper()-hScrollbar->get_adjustment()->get_lower(),
+ vScrollbar->get_adjustment()->get_upper()-vScrollbar->get_adjustment()->get_lower());
+}
+
+void RenderArea::updateScrollingWithSize(float imageWidth, float imageHeight) {
if(hScrollbar) {
- if(getImageWidth() < getViewWidth())
+ if(imageWidth < getViewWidth())
xCenter = 0;
else
xCenter = hScrollbar->get_value();
}
if(vScrollbar) {
- if(getImageHeight() < getViewHeight())
+ if(imageHeight < getViewHeight())
yCenter = 0;
else
yCenter = vScrollbar->get_value();
diff --git a/src/Gui/RenderArea.h b/src/Gui/RenderArea.h
index c47c56d..61e5291 100644
--- a/src/Gui/RenderArea.h
+++ b/src/Gui/RenderArea.h
@@ -51,9 +51,6 @@ class RenderArea : public Gtk::DrawingArea {
return get_height()/scale;
}
- float getImageWidth() const {return 10;}
- float getImageHeight() const {return 10;}
-
float getScale() const {return scale;}
float getXCenter() const {return xCenter;}
@@ -82,6 +79,7 @@ class RenderArea : public Gtk::DrawingArea {
void updateViewport();
void updateScrollbars(float x = 0.5f, float y = 0.5f);
void updateScrolling();
+ void updateScrollingWithSize(float imageWidth, float imageHeight);
bool gdkGLBegin() {
GtkWidget *widget = GTK_WIDGET(gobj());