diff options
author | neoraider <devnull@localhost> | 2007-11-16 02:29:04 +0100 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-11-16 02:29:04 +0100 |
commit | 8cd0c8914da0ce59fea81e4ed78241fa574c75c3 (patch) | |
tree | 37870b41c989a8dac12e040f676f2be72e05790d /Drawer.cpp | |
parent | 96edb8f4908337d82e6523319e58b6ce46144cbb (diff) | |
download | zoomedit-8cd0c8914da0ce59fea81e4ed78241fa574c75c3.tar zoomedit-8cd0c8914da0ce59fea81e4ed78241fa574c75c3.zip |
zoomedit: Redesigned scroll-bar internals.
Diffstat (limited to 'Drawer.cpp')
-rw-r--r-- | Drawer.cpp | 63 |
1 files changed, 31 insertions, 32 deletions
@@ -86,54 +86,53 @@ void Drawer::updateViewport() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - if(getWidth() != 0 && getHeight() != 0) { - glTranslatef(-1, 1, 0); + if(getWidth() != 0 && getHeight() != 0) glScalef(2.0f/getWidth(), -2.0f/getHeight(), 1); - } gdk_gl_drawable_gl_end(drawable); } void Drawer::updateScrolling() { - if(getImageWidth() < getWidth()) - xTranslate = (getImageWidth()-getWidth())/2; + if(getImageWidth()*scale < getWidth()) + xCenter = 0; else - xTranslate = gtk_adjustment_get_value(hAdjustment); + xCenter = gtk_adjustment_get_value(hAdjustment); - if(getImageHeight() < getHeight()) - yTranslate = (getImageHeight()-getHeight())/2; + if(getImageHeight()*scale < getHeight()) + yCenter = 0; else - yTranslate = gtk_adjustment_get_value(vAdjustment); + yCenter = gtk_adjustment_get_value(vAdjustment); update(); } void Drawer::updateScrollbars(float x, float y) { const gdouble imageWidth = getImageWidth(), imageHeight = getImageHeight(); - const gdouble width = getWidth(), height = getHeight(); - gdouble upper, pageSize, value; + const gdouble width = getWidth()/scale, height = getHeight()/scale; + gdouble lower, upper, pageSize, value; + gdk_window_freeze_updates(drawingArea->window); - g_object_get(G_OBJECT(hAdjustment), "upper", &upper, "page_size", &pageSize, NULL); - g_object_set(G_OBJECT(hAdjustment), "upper", imageWidth, "page_size", width, NULL); + 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); gtk_adjustment_changed(hAdjustment); - if((pageSize > upper && width < imageWidth) || upper == 0) - value = (imageWidth-width)/2; + if((pageSize > (upper-lower) && width < imageWidth) || upper == lower) + value = 0; else - value = (gtk_adjustment_get_value(hAdjustment)+pageSize*x)/upper*imageWidth-width*x; - gtk_adjustment_set_value(hAdjustment, MAX(MIN(value, imageWidth-width), 0)); + 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)); - g_object_get(G_OBJECT(vAdjustment), "upper", &upper, "page_size", &pageSize, NULL); - g_object_set(G_OBJECT(vAdjustment), "upper", imageHeight, "page_size", height, NULL); + 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); gtk_adjustment_changed(vAdjustment); - if((pageSize > upper && height < imageHeight) || upper == 0) - value = (imageHeight-height)/2; + if((pageSize > upper && height < imageHeight) || upper == lower) + value = 0; else - value = (gtk_adjustment_get_value(vAdjustment)+pageSize*y)/upper*imageHeight-height*y; - gtk_adjustment_set_value(vAdjustment, MAX(MIN(value, imageHeight-height), 0)); + 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)); gdk_window_thaw_updates(drawingArea->window); @@ -161,8 +160,8 @@ void Drawer::render() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); - glTranslatef(getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate, 0); glScalef(scale, scale, 1); + glTranslatef(-xCenter, -yCenter, 0); renderer.render(window->getLevel(), rect, scale); @@ -179,8 +178,8 @@ Drawer::Drawer(Window *window, GdkGLConfig *glconfig) this->window = window; zoomExp = 0; scale = 100; - xTranslate = 0; - yTranslate = 0; + xCenter = 0; + yCenter = 0; drawer = gtk_table_new(2, 2, FALSE); g_object_ref_sink(G_OBJECT(drawer)); @@ -225,13 +224,13 @@ void Drawer::zoom(int zoom, float x, float y) { } void Drawer::imageToView(Vertex *v) const { - v->setX(v->getX()*scale+getImageWidth()/2-xTranslate); - v->setY(v->getY()*scale+getImageHeight()/2-yTranslate); + v->setX((v->getX()-xCenter)*scale + getWidth()/2); + v->setY((v->getY()-yCenter)*scale + getHeight()/2); } void Drawer::viewToImage(Vertex *v) const { - v->setX((v->getX()-getImageWidth()/2+xTranslate)/scale); - v->setY((v->getY()-getImageHeight()/2+yTranslate)/scale); + v->setX((v->getX()-getWidth()/2)/scale+xCenter); + v->setY((v->getY()-getHeight()/2)/scale+yCenter); } float Drawer::getImageWidth() const { @@ -244,7 +243,7 @@ float Drawer::getImageWidth() const { } } - return (max-min+10)*scale; + return (max-min+10); } float Drawer::getImageHeight() const { @@ -257,5 +256,5 @@ float Drawer::getImageHeight() const { } } - return (max-min+10)*scale; + return (max-min+10); } |