diff options
author | neoraider <devnull@localhost> | 2007-10-19 01:38:05 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-10-19 01:38:05 +0200 |
commit | 7b70cc94c7f2407f20786644141a097031b96e66 (patch) | |
tree | f691264c62d03c5fcda563694ddf13215ca54c55 /Drawer.cpp | |
parent | 9c732521732de895ec09ddb004877cd491067bf6 (diff) | |
download | zoomedit-7b70cc94c7f2407f20786644141a097031b96e66.tar zoomedit-7b70cc94c7f2407f20786644141a097031b96e66.zip |
zoomedit: Einige Funktionen von draw.c in den Drawer verschoben.
Diffstat (limited to 'Drawer.cpp')
-rw-r--r-- | Drawer.cpp | 59 |
1 files changed, 49 insertions, 10 deletions
@@ -33,7 +33,7 @@ gboolean Drawer::eventHandler(GtkWidget *widget, GdkEvent *event, Drawer *drawer return TRUE; case GDK_EXPOSE: - drawTopView(widget, &event->expose, &drawer->window->getLevel(), &drawer->window->getEditManager()); + drawTopView(widget, &event->expose, drawer->window, drawer); return TRUE; case GDK_MOTION_NOTIFY: @@ -96,21 +96,21 @@ void Drawer::updateViewport() { } void Drawer::updateScrolling() { - if(getImageWidth(&window->getLevel()) < getWidth()) - setXTranslate((getImageWidth(&window->getLevel())-getWidth())/2); + if(getImageWidth() < getWidth()) + xTranslate = (getImageWidth()-getWidth())/2; else - setXTranslate(gtk_adjustment_get_value(hAdjustment)); + xTranslate = gtk_adjustment_get_value(hAdjustment); - if(getImageHeight(&window->getLevel()) < getHeight()) - setYTranslate((getImageHeight(&window->getLevel())-getHeight())/2); + if(getImageHeight() < getHeight()) + yTranslate = (getImageHeight()-getHeight())/2; else - setYTranslate(gtk_adjustment_get_value(vAdjustment)); + yTranslate = gtk_adjustment_get_value(vAdjustment); update(); } void Drawer::updateScrollbars(float x, float y) { - const gdouble imageWidth = getImageWidth(&window->getLevel()), imageHeight = getImageHeight(&window->getLevel()); + const gdouble imageWidth = getImageWidth(), imageHeight = getImageHeight(); const gdouble width = getWidth(), height = getHeight(); gdouble upper, pageSize, value; @@ -143,13 +143,16 @@ void Drawer::updateScrollbars(float x, float y) { void Drawer::updateHoveredPoint(float x, float y) { Vertex v(x, y); - viewToImage(&window->getLevel(), &v); + viewToImage(&v); window->getEditManager().setHoveredVertex(&v); } Drawer::Drawer(Window *window, GdkGLConfig *glconfig) { this->window = window; zoomExp = 0; + scale = 100; + xTranslate = 0; + yTranslate = 0; drawer = gtk_table_new(2, 2, FALSE); g_object_ref_sink(G_OBJECT(drawer)); @@ -188,7 +191,43 @@ Drawer::~Drawer() { void Drawer::zoom(int zoom, float x, float y) { zoomExp = MAX(MIN(zoomExp + zoom, 50), -100); - setScale(100*powf(1.1f, zoomExp)); + scale = 100*powf(1.1f, zoomExp); updateScrollbars(x, y); } + +void Drawer::imageToView(Vertex *v) { + v->setX(v->getX()*scale+getImageWidth()/2-xTranslate); + v->setY(v->getY()*scale+getImageHeight()/2-yTranslate); +} + +void Drawer::viewToImage(Vertex *v) { + v->setX((v->getX()-getImageWidth()/2+xTranslate)/scale); + v->setY((v->getY()-getImageHeight()/2+yTranslate)/scale); +} + +float Drawer::getImageWidth() { + float min = 0, 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()); + } + } + + return (max-min+10)*scale; +} + +float Drawer::getImageHeight() { + float min = 0, 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()); + } + } + + return (max-min+10)*scale; +} |