summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Drawer.cpp34
-rw-r--r--Drawer.h2
2 files changed, 18 insertions, 18 deletions
diff --git a/Drawer.cpp b/Drawer.cpp
index e3fe6e6..e1373a5 100644
--- a/Drawer.cpp
+++ b/Drawer.cpp
@@ -93,21 +93,23 @@ void Drawer::updateViewport() {
}
void Drawer::updateScrolling() {
- if(getImageWidth()*scale < getWidth())
+ if((getImageWidth())*scale < getWidth())
xCenter = 0;
else
xCenter = gtk_adjustment_get_value(hAdjustment);
- if(getImageHeight()*scale < getHeight())
+ if((getImageHeight())*scale < getHeight())
yCenter = 0;
else
yCenter = gtk_adjustment_get_value(vAdjustment);
- update();
+ gtk_widget_queue_draw(drawingArea);
}
void Drawer::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;
const gdouble width = getWidth()/scale, height = getHeight()/scale;
gdouble lower, upper, pageSize, value;
@@ -115,24 +117,24 @@ void Drawer::updateScrollbars(float x, float y) {
gdk_window_freeze_updates(drawingArea->window);
g_object_get(G_OBJECT(hAdjustment), "lower", &lower, "upper", &upper, "page_size", &pageSize, NULL);
- g_object_set(G_OBJECT(hAdjustment), "lower", (-imageWidth+width)/2, "upper", (imageWidth+width)/2, "page_size", width, NULL);
+ g_object_set(G_OBJECT(hAdjustment), "lower", minX + width/2, "upper", maxX + width/2, "page_size", width, NULL);
gtk_adjustment_changed(hAdjustment);
- if((pageSize > (upper-lower) && width < imageWidth) || upper == lower)
+ if(pageSize > (upper-lower) && width < imageWidth)
value = 0;
else
value = gtk_adjustment_get_value(hAdjustment) + (x-0.5)*pageSize*(pageSize/width-1);
- gtk_adjustment_set_value(hAdjustment, MAX(MIN(value, imageWidth/2), -imageWidth/2));
+ gtk_adjustment_set_value(hAdjustment, MAX(MIN(value, maxX - width/2), minX + width/2));
g_object_get(G_OBJECT(vAdjustment), "lower", &lower, "upper", &upper, "page_size", &pageSize, NULL);
- g_object_set(G_OBJECT(vAdjustment), "lower", (-imageHeight+height)/2, "upper", (imageHeight+height)/2, "page_size", height, NULL);
+ g_object_set(G_OBJECT(vAdjustment), "lower", minY + height/2, "upper", maxY + height/2, "page_size", height, NULL);
gtk_adjustment_changed(vAdjustment);
- if((pageSize > upper && height < imageHeight) || upper == lower)
+ if(pageSize > (upper-lower) && height < imageHeight)
value = 0;
else
value = gtk_adjustment_get_value(vAdjustment) + (y-0.5)*pageSize*(pageSize/height-1);
- gtk_adjustment_set_value(vAdjustment, MAX(MIN(value, imageHeight/2), -imageHeight/2));
+ gtk_adjustment_set_value(vAdjustment, MAX(MIN(value, maxY - height/2), minY + height/2));
gdk_window_thaw_updates(drawingArea->window);
@@ -234,27 +236,25 @@ void Drawer::viewToImage(Vertex *v) const {
}
float Drawer::getImageWidth() const {
- float min = 0, max = 0;
+ float max = 0;
for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
for(Room::iterator v = room->begin(); v != room->end(); v++) {
- min = fminf(min, v->getX());
- max = fmaxf(max, v->getX());
+ max = fmaxf(max, fabsf(v->getX()));
}
}
- return (max-min+10);
+ return (2*max+1);
}
float Drawer::getImageHeight() const {
- float min = 0, max = 0;
+ float max = 0;
for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
for(Room::iterator v = room->begin(); v != room->end(); v++) {
- min = fminf(min, v->getY());
- max = fmaxf(max, v->getY());
+ max = fmaxf(max, fabsf(v->getY()));
}
}
- return (max-min+10);
+ return (2*max+1);
}
diff --git a/Drawer.h b/Drawer.h
index 236c72a..b471f1f 100644
--- a/Drawer.h
+++ b/Drawer.h
@@ -76,7 +76,7 @@ class Drawer {
}
void update() {
- gtk_widget_queue_draw(drawingArea);
+ updateScrollbars();
}
};