diff options
author | neoraider <devnull@localhost> | 2007-10-18 21:18:01 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-10-18 21:18:01 +0200 |
commit | 2bc9bb15dcc9691f6946eaa7a03370814bad0b8e (patch) | |
tree | a0b45181788dd17bd580374fd4a3fdc04ae8bd17 /draw.cpp | |
parent | b660b965bcb679e53cc89e7b8903190d2d162ff6 (diff) | |
download | zoomedit-2bc9bb15dcc9691f6946eaa7a03370814bad0b8e.tar zoomedit-2bc9bb15dcc9691f6946eaa7a03370814bad0b8e.zip |
zoomedit: edit.c in den EditManager integriert
Diffstat (limited to 'draw.cpp')
-rw-r--r-- | draw.cpp | 61 |
1 files changed, 30 insertions, 31 deletions
@@ -1,5 +1,4 @@ #include "draw.h" -#include "edit.h" #include "Rectangle.h" #include <math.h> #include <gtk/gtk.h> @@ -97,17 +96,17 @@ static void drawPolygon(const Polygon &polygon, bool close) { glEnd(); } -gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { +gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, Level *level, EditManager *editor) { 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(getLevel() == NULL) return FALSE; + if(level == NULL) return FALSE; - viewToImage(&v1); - viewToImage(&v2); + viewToImage(level, &v1); + viewToImage(level, &v2); rect.setVertex1(v1); rect.setVertex2(v2); @@ -122,26 +121,26 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { glLineWidth(1.0f); - glTranslatef(getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate, 0); + glTranslatef(getImageWidth(level)/2-xTranslate, getImageHeight(level)/2-yTranslate, 0); glScalef(scale, scale, 1); drawGrid(rect); - for(Level::const_iterator room = getLevel()->begin(); room != getLevel()->end(); room++) { - if(&*room == getActiveRoom() && getEditMode() == EDIT_MODE_ADD) continue; + for(Level::const_iterator room = level->begin(); room != level->end(); room++) { + if(&*room == editor->getActiveRoom() && editor->getMode() == EditManager::ADD) continue; - if(&*room == getActiveRoom()) + if(&*room == editor->getActiveRoom()) glColor4f(0.0f, 0.7f, 1.0f, 0.2f); else glColor4f(0.0f, 0.7f, 1.0f, 0.3f); fillPolygon(*room); - if(&*room == getActiveRoom()) { + if(&*room == editor->getActiveRoom()) { glColor4f(1.0f, 1.0f, 1.0f, 0.9f); glLineWidth(2.0f); } - else if(&*room == getHoveredRoom() && getEditMode() != EDIT_MODE_ADD) { + else if(&*room == editor->getHoveredRoom() && editor->getMode() == EditManager::VIEW) { glColor4f(0.0f, 0.7f, 1.0f, 0.7f); glLineWidth(2.0f); } @@ -153,26 +152,26 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { drawPolygon(*room, true); } - if(getEditMode() == EDIT_MODE_ADD) { - if(isPolygonOk(getActiveRoom())) + if(editor->getMode() == EditManager::ADD) { + if(editor->polygonOk(*editor->getActiveRoom())) glColor4f(0.0f, 0.7f, 1.0f, 0.2f); else glColor4f(1.0f, 0.3f, 0.3f, 0.2f); - fillPolygon(*getActiveRoom()); + fillPolygon(*editor->getActiveRoom()); glLineWidth(2.0f); glColor4f(0.0f, 0.7f, 1.0f, 0.7f); - drawPolygon(*getActiveRoom(), false); + drawPolygon(*editor->getActiveRoom(), false); - if(!getActiveRoom()->empty() && getHoveredVertex()) { - if(!isVertexOk(getHoveredVertex())) + if(!editor->getActiveRoom()->empty() && editor->getHoveredVertex()) { + if(!editor->vertexOk(*editor->getHoveredVertex())) glColor4f(1.0f, 0.3f, 0.3f, 0.7f); glBegin(GL_LINES); - glVertex2d(getActiveRoom()->back().getX(), getActiveRoom()->back().getY()); - glVertex2d(getHoveredVertex()->getX(), getHoveredVertex()->getY()); + glVertex2d(editor->getActiveRoom()->back().getX(), editor->getActiveRoom()->back().getY()); + glVertex2d(editor->getHoveredVertex()->getX(), editor->getHoveredVertex()->getY()); glEnd(); } @@ -196,22 +195,22 @@ void setScale(float s) { scale = s; } -void imageToView(Vertex *v) { - v->setX(v->getX()*scale+getImageWidth()/2-xTranslate); - v->setY(v->getY()*scale+getImageHeight()/2-yTranslate); +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(Vertex *v) { - v->setX((v->getX()-getImageWidth()/2+xTranslate)/scale); - v->setY((v->getY()-getImageHeight()/2+yTranslate)/scale); +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() { +float getImageWidth(Level *level) { float min = 0.0, max = 0.0; - if(getLevel()) { - for(Level::iterator room = getLevel()->begin(); room != getLevel()->end(); room++) { + 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()); @@ -222,12 +221,12 @@ float getImageWidth() { return (max-min+10)*scale; } -float getImageHeight() { +float getImageHeight(Level *level) { float min = 0.0, max = 0.0; - if(getLevel()) { - for(Level::iterator room = getLevel()->begin(); room != getLevel()->end(); room++) { + 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()); |