summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-10-19 01:38:05 +0200
committerneoraider <devnull@localhost>2007-10-19 01:38:05 +0200
commit7b70cc94c7f2407f20786644141a097031b96e66 (patch)
treef691264c62d03c5fcda563694ddf13215ca54c55
parent9c732521732de895ec09ddb004877cd491067bf6 (diff)
downloadzoomedit-7b70cc94c7f2407f20786644141a097031b96e66.tar
zoomedit-7b70cc94c7f2407f20786644141a097031b96e66.zip
zoomedit: Einige Funktionen von draw.c in den Drawer verschoben.
-rw-r--r--Drawer.cpp59
-rw-r--r--Drawer.h23
-rw-r--r--draw.cpp113
-rw-r--r--draw.h20
4 files changed, 94 insertions, 121 deletions
diff --git a/Drawer.cpp b/Drawer.cpp
index 69aa261..1a80997 100644
--- a/Drawer.cpp
+++ b/Drawer.cpp
@@ -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;
+}
diff --git a/Drawer.h b/Drawer.h
index 4cc0e2b..8dbac47 100644
--- a/Drawer.h
+++ b/Drawer.h
@@ -3,7 +3,7 @@
#include <gtk/gtk.h>
#include <gtk/gtkgl.h>
-
+#include "Vertex.h"
class Window;
@@ -17,6 +17,9 @@ class Drawer {
Window *window;
+ float scale;
+ float xTranslate, yTranslate;
+
// prevent shallow copy
Drawer(const Drawer &w);
const Drawer& operator=(const Drawer &w);
@@ -45,6 +48,24 @@ class Drawer {
void zoom(int zoom, float x = 0.5f, float y = 0.5f);
+ void imageToView(Vertex *v);
+ void viewToImage(Vertex *v);
+
+ float getImageWidth();
+ float getImageHeight();
+
+ float getXTranslate() {
+ return xTranslate;
+ }
+
+ float getYTranslate() {
+ return yTranslate;
+ }
+
+ float getScale() {
+ return scale;
+ }
+
GtkWidget *getWidget() {
return drawer;
}
diff --git a/draw.cpp b/draw.cpp
index 7e36d99..708462f 100644
--- a/draw.cpp
+++ b/draw.cpp
@@ -6,11 +6,7 @@
#include <GL/gl.h>
-static float scale = 100.0;
-static float xTranslate = 0.0, yTranslate = 0.0;
-
-
-static void drawGrid(const Rectangle &rect) {
+static void drawGrid(const Rectangle &rect, float scale) {
float depth = log10f(scale)-0.75f;
float depth2 = floorf(depth);
float step = powf(0.1f, depth2);
@@ -96,17 +92,15 @@ static void drawPolygon(const Polygon &polygon, bool close) {
glEnd();
}
-gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, EditManager *editor) {
+gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Window *window, Drawer *drawer) {
GdkGLContext *context = gtk_widget_get_gl_context(widget);
GdkGLDrawable *drawable = gtk_widget_get_gl_drawable(widget);
Vertex v1(0, 0), v2(widget->allocation.width, widget->allocation.height);
Rectangle rect;
- if(level == NULL) return FALSE;
-
- viewToImage(level, &v1);
- viewToImage(level, &v2);
+ drawer->viewToImage(&v1);
+ drawer->viewToImage(&v2);
rect.setVertex1(v1);
rect.setVertex2(v2);
@@ -121,26 +115,26 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, Edi
glLineWidth(1.0f);
- glTranslatef(getImageWidth(level)/2-xTranslate, getImageHeight(level)/2-yTranslate, 0);
- glScalef(scale, scale, 1);
+ glTranslatef(drawer->getImageWidth()/2-drawer->getXTranslate(), drawer->getImageHeight()/2-drawer->getYTranslate(), 0);
+ glScalef(drawer->getScale(), drawer->getScale(), 1);
- drawGrid(rect);
+ drawGrid(rect, drawer->getScale());
- for(Level::const_iterator room = level->begin(); room != level->end(); room++) {
- if(&*room == editor->getActiveRoom() && editor->getMode() == EditManager::ADD) continue;
+ for(Level::const_iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) {
+ if(&*room == window->getEditManager().getActiveRoom() && window->getEditManager().getMode() == EditManager::ADD) continue;
- if(&*room == editor->getActiveRoom())
+ if(&*room == window->getEditManager().getActiveRoom())
glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
else
glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
fillPolygon(*room);
- if(&*room == editor->getActiveRoom()) {
+ if(&*room == window->getEditManager().getActiveRoom()) {
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
glLineWidth(2.0f);
}
- else if(&*room == editor->getHoveredRoom() && editor->getMode() == EditManager::VIEW) {
+ else if(&*room == window->getEditManager().getHoveredRoom() && window->getEditManager().getMode() == EditManager::VIEW) {
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
glLineWidth(2.0f);
}
@@ -152,26 +146,26 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, Edi
drawPolygon(*room, true);
}
- if(editor->getMode() == EditManager::ADD) {
- if(editor->polygonOk(*editor->getActiveRoom()))
+ if(window->getEditManager().getMode() == EditManager::ADD) {
+ if(window->getEditManager().polygonOk(*window->getEditManager().getActiveRoom()))
glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
else
glColor4f(1.0f, 0.3f, 0.3f, 0.2f);
- fillPolygon(*editor->getActiveRoom());
+ fillPolygon(*window->getEditManager().getActiveRoom());
glLineWidth(2.0f);
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
- drawPolygon(*editor->getActiveRoom(), false);
+ drawPolygon(*window->getEditManager().getActiveRoom(), false);
- if(!editor->getActiveRoom()->empty() && editor->getHoveredVertex()) {
- if(!editor->vertexOk(*editor->getHoveredVertex()))
+ if(!window->getEditManager().getActiveRoom()->empty() && window->getEditManager().getHoveredVertex()) {
+ if(!window->getEditManager().vertexOk(*window->getEditManager().getHoveredVertex()))
glColor4f(1.0f, 0.3f, 0.3f, 0.7f);
glBegin(GL_LINES);
- glVertex2d(editor->getActiveRoom()->back().getX(), editor->getActiveRoom()->back().getY());
- glVertex2d(editor->getHoveredVertex()->getX(), editor->getHoveredVertex()->getY());
+ glVertex2d(window->getEditManager().getActiveRoom()->back().getX(), window->getEditManager().getActiveRoom()->back().getY());
+ glVertex2d(window->getEditManager().getHoveredVertex()->getX(), window->getEditManager().getHoveredVertex()->getY());
glEnd();
}
@@ -185,70 +179,3 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, Edi
return TRUE;
}
-
-
-float getScale() {
- return scale;
-}
-
-void setScale(float s) {
- scale = s;
-}
-
-void imageToView(Level *level, Vertex *v) {
- v->setX(v->getX()*scale+getImageWidth(level)/2-xTranslate);
- v->setY(v->getY()*scale+getImageHeight(level)/2-yTranslate);
-}
-
-void viewToImage(Level *level, Vertex *v) {
- v->setX((v->getX()-getImageWidth(level)/2+xTranslate)/scale);
- v->setY((v->getY()-getImageHeight(level)/2+yTranslate)/scale);
-}
-
-float getImageWidth(Level *level) {
- float min = 0.0, max = 0.0;
-
-
- if(level) {
- for(Level::iterator room = level->begin(); room != level->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 getImageHeight(Level *level) {
- float min = 0.0, max = 0.0;
-
-
- if(level) {
- for(Level::iterator room = level->begin(); room != level->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;
-}
-
-float getXTranslate() {
- return xTranslate;
-}
-
-void setXTranslate(float x) {
- xTranslate = x;
-}
-
-float getYTranslate() {
- return yTranslate;
-}
-
-void setYTranslate(float y) {
- yTranslate = y;
-}
diff --git a/draw.h b/draw.h
index ddffc5f..9754cf5 100644
--- a/draw.h
+++ b/draw.h
@@ -3,24 +3,10 @@
#include <gtk/gtk.h>
#include "Vertex.h"
-#include "EditManager.h"
-#include "Level.h"
+#include "Window.h"
+#include "Drawer.h"
-gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, EditManager *editor);
-
-float getScale();
-void setScale(float s);
-
-void imageToView(Level *level, Vertex *v);
-void viewToImage(Level *level, Vertex *v);
-
-float getImageWidth(Level *level);
-float getImageHeight(Level *level);
-
-float getXTranslate();
-void setXTranslate(float x);
-float getYTranslate();
-void setYTranslate(float y);
+gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Window *window, Drawer *drawer);
#endif /*DRAW_H_*/