From 7b70cc94c7f2407f20786644141a097031b96e66 Mon Sep 17 00:00:00 2001 From: neoraider Date: Thu, 18 Oct 2007 23:38:05 +0000 Subject: zoomedit: Einige Funktionen von draw.c in den Drawer verschoben. --- draw.cpp | 113 +++++++++++---------------------------------------------------- 1 file changed, 20 insertions(+), 93 deletions(-) (limited to 'draw.cpp') diff --git a/draw.cpp b/draw.cpp index 7e36d99..708462f 100644 --- a/draw.cpp +++ b/draw.cpp @@ -6,11 +6,7 @@ #include -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; -} -- cgit v1.2.3