summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-06-24 02:35:04 +0200
committerneoraider <devnull@localhost>2007-06-24 02:35:04 +0200
commit464a75f77b55bca989e99bfd154f14cb66b8e51f (patch)
tree8fd41fc3db6a4220f79fafc035693f18b10116d6
parent6c9c0b8a29cd0eb64e3f1103ca3363ccff7b3eba (diff)
downloadzoomedit-464a75f77b55bca989e99bfd154f14cb66b8e51f.tar
zoomedit-464a75f77b55bca989e99bfd154f14cb66b8e51f.zip
zoomedit: Added grid.
-rw-r--r--draw.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/draw.c b/draw.c
index f782ddd..a39df7a 100644
--- a/draw.c
+++ b/draw.c
@@ -1,6 +1,7 @@
#include "draw.h"
#include "level.h"
#include "geometry.h"
+#include <math.h>
#include <gtk/gtk.h>
#include <cairo/cairo.h>
@@ -9,7 +10,39 @@ static double scale = 100.0;
static double xTranslate = 0.0, yTranslate = 0.0;
-static void room2path(cairo_t *cr, ROOM *room, RECTANGLE *rect) {
+static void drawGrid(cairo_t *cr, const RECTANGLE *rect) {
+ double depth = log10(scale)-0.75;
+ double depth2 = floor(depth);
+ double step = pow(0.1, depth2);
+ double x;
+ int i;
+
+ cairo_set_source_rgb(cr, 0.2*(depth-depth2), 0.2*(depth-depth2), 0.2*(depth-depth2));
+
+ for(i = 0; i < 3; i++) {
+ for(x = rect->x - fmod(rect->x, step); x <= rect->x+rect->width; x+=step) {
+ cairo_move_to(cr, x, rect->y);
+ cairo_line_to(cr, x, rect->y+rect->height);
+
+ cairo_stroke(cr);
+ }
+
+ for(x = rect->y - fmod(rect->y, step); x <= rect->y+rect->height; x+=step) {
+ cairo_move_to(cr, rect->x, x);
+ cairo_line_to(cr, rect->x+rect->width, x);
+
+ cairo_stroke(cr);
+ }
+
+ step *= 10;
+ if(i == 0 && 0.2*(depth-depth2+1) < 0.3)
+ cairo_set_source_rgb(cr, 0.2*(depth-depth2+1), 0.2*(depth-depth2+1), 0.2*(depth-depth2+1));
+ else
+ cairo_set_source_rgb(cr, 0.3, 0.3, 0.3);
+ }
+}
+
+static void room2path(cairo_t *cr, const ROOM *room, const RECTANGLE *rect) {
int i;
ROOM room2 = {0, NULL};
@@ -58,6 +91,8 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
cairo_set_line_width(cr, 1.0/scale);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
+ drawGrid(cr, &rect);
+
for(i = 0; i < lvl.nRooms; i++)
room2path(cr, &lvl.rooms[i], &rect);