summaryrefslogtreecommitdiffstats
path: root/draw.c
diff options
context:
space:
mode:
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/draw.c b/draw.c
index 11840ee..f782ddd 100644
--- a/draw.c
+++ b/draw.c
@@ -1,5 +1,6 @@
#include "draw.h"
#include "level.h"
+#include "geometry.h"
#include <gtk/gtk.h>
#include <cairo/cairo.h>
@@ -7,18 +8,31 @@
static double scale = 100.0;
static double xTranslate = 0.0, yTranslate = 0.0;
-static void room2path(cairo_t *cr, ROOM *room) {
+
+static void room2path(cairo_t *cr, ROOM *room, RECTANGLE *rect) {
int i;
+ ROOM room2 = {0, NULL};
-
+ // no vertices
if(room->nVertices == 0) return;
- cairo_move_to(cr, room->vertices[0].x, room->vertices[0].y);
+ if(rect)
+ simplifyPolygon(room, rect, &room2);
+ else
+ room2 = *room;
+
+ if(room2.nVertices == 0) return;
- for(i = 1; i < room->nVertices; i++)
- cairo_line_to(cr, room->vertices[i].x, room->vertices[i].y);
+ cairo_new_sub_path(cr);
+
+ for(i = 0; i < room2.nVertices; i++) {
+ cairo_line_to(cr, room2.vertices[i].x, room2.vertices[i].y);
+ }
cairo_close_path(cr);
+
+ if(rect && room2.vertices)
+ free(room2.vertices);
}
gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
@@ -26,21 +40,26 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
ROOM room = {sizeof(vertices)/sizeof(vertices[0]), vertices};
LEVEL lvl = {1, &room};
cairo_t *cr;
+ RECTANGLE rect = {-5, -5, widget->allocation.width+10, widget->allocation.height+10};
int i;
cr = gdk_cairo_create(widget->window);
- cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height);
+ gdk_cairo_region(cr, event->region);
cairo_clip(cr);
cairo_translate(cr, getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate);
cairo_scale(cr, scale, scale);
+ cairo_device_to_user(cr, &rect.x, &rect.y);
+ cairo_device_to_user_distance(cr, &rect.width, &rect.height);
+
cairo_set_line_width(cr, 1.0/scale);
+ cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
for(i = 0; i < lvl.nRooms; i++)
- room2path(cr, &lvl.rooms[i]);
+ room2path(cr, &lvl.rooms[i], &rect);
cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.3);
cairo_fill_preserve(cr);