diff options
Diffstat (limited to 'draw.cpp')
-rw-r--r-- | draw.cpp | 40 |
1 files changed, 18 insertions, 22 deletions
@@ -68,31 +68,27 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) { } } -static void polygon2path(cairo_t *cr, const POLYGON *polygon, const RECTANGLE *rect, gboolean close) { - int i; - POLYGON polygon2 = {0, NULL}; +static void polygon2path(cairo_t *cr, const Polygon *polygon, const RECTANGLE *rect, gboolean close) { + Polygon polygon2; // no vertices - if(polygon->nVertices == 0) return; + if(polygon->empty()) return; if(rect) simplifyPolygon(polygon, rect, &polygon2); else polygon2 = *polygon; - if(polygon2.nVertices == 0) return; + if(polygon2.empty()) return; cairo_new_sub_path(cr); - for(i = 0; i < polygon2.nVertices; i++) { - cairo_line_to(cr, polygon2.vertices[i].getX(), polygon2.vertices[i].getY()); + for(Polygon::iterator it = polygon2.begin(); it != polygon2.end(); it++) { + cairo_line_to(cr, it->getX(), it->getY()); } if(close) cairo_close_path(cr); - - if(rect && polygon2.vertices) - free(polygon2.vertices); } gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { @@ -201,7 +197,7 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_fill_preserve(cr); - if(getActiveRoom()->polygon.nVertices && getHoveredVertex()) { + if(!getActiveRoom()->polygon.empty() && getHoveredVertex()) { vertexOk = isVertexOk(getHoveredVertex()); if(vertexOk) @@ -214,11 +210,10 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.7); cairo_stroke(cr); - if(getActiveRoom()->polygon.nVertices && getHoveredVertex() && !vertexOk) { + if(!getActiveRoom()->polygon.empty() && getHoveredVertex() && !vertexOk) { cairo_set_source_rgba(cr, 1.0, 0.3, 0.3, 0.7); - i = getActiveRoom()->polygon.nVertices - 1; - cairo_move_to(cr, getActiveRoom()->polygon.vertices[i].getX(), getActiveRoom()->polygon.vertices[i].getY()); + cairo_move_to(cr, getActiveRoom()->polygon.back().getX(), getActiveRoom()->polygon.back().getY()); cairo_line_to(cr, getHoveredVertex()->getX(), getHoveredVertex()->getY()); cairo_stroke(cr); @@ -253,13 +248,14 @@ void viewToImage(Vertex *v) { double getImageWidth() { const LEVEL *level = getLevel(); double min = 0.0, max = 0.0; - int i, j; + int i; + if(level) { for(i = 0; i < level->nRooms; i++) { - for(j = 0; j < level->rooms[i].polygon.nVertices; j++) { - min = MIN(min, level->rooms[i].polygon.vertices[j].getX()); - max = MAX(max, level->rooms[i].polygon.vertices[j].getX()); + for(Polygon::iterator it = level->rooms[i].polygon.begin(); it != level->rooms[i].polygon.end(); it++) { + min = MIN(min, it->getX()); + max = MAX(max, it->getX()); } } } @@ -270,13 +266,13 @@ double getImageWidth() { double getImageHeight() { const LEVEL *level = getLevel(); double min = 0.0, max = 0.0; - int i, j; + int i; if(level) { for(i = 0; i < level->nRooms; i++) { - for(j = 0; j < level->rooms[i].polygon.nVertices; j++) { - min = MIN(min, level->rooms[i].polygon.vertices[j].getY()); - max = MAX(max, level->rooms[i].polygon.vertices[j].getY()); + for(Polygon::iterator it = level->rooms[i].polygon.begin(); it != level->rooms[i].polygon.end(); it++) { + min = MIN(min, it->getY()); + max = MAX(max, it->getY()); } } } |