diff options
author | neoraider <devnull@localhost> | 2007-11-16 18:49:00 +0100 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-11-16 18:49:00 +0100 |
commit | 4afb308180c136f8135385ee7c05dd6c7ee326c5 (patch) | |
tree | 313ab4d56d3a35f7783fc24a16deda0d07595a8e | |
parent | 8cd0c8914da0ce59fea81e4ed78241fa574c75c3 (diff) | |
download | zoomedit-4afb308180c136f8135385ee7c05dd6c7ee326c5.tar zoomedit-4afb308180c136f8135385ee7c05dd6c7ee326c5.zip |
zoomedit: Fixed some scrolling bugs.
-rw-r--r-- | Drawer.cpp | 34 | ||||
-rw-r--r-- | Drawer.h | 2 |
2 files changed, 18 insertions, 18 deletions
@@ -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); } @@ -76,7 +76,7 @@ class Drawer { } void update() { - gtk_widget_queue_draw(drawingArea); + updateScrollbars(); } }; |