From a686a31daece494006e3ce841a5883472a0f412a Mon Sep 17 00:00:00 2001 From: neoraider Date: Sun, 24 Jun 2007 17:33:00 +0000 Subject: zoomedit: Added scales to grid. --- draw.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/draw.c b/draw.c index a39df7a..f68725b 100644 --- a/draw.c +++ b/draw.c @@ -3,6 +3,7 @@ #include "geometry.h" #include #include +#include #include @@ -14,31 +15,48 @@ 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; + double d; int i; + gchar buffer[10]; - 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_set_font_size(cr, 10.0/scale); + + for(i = 0; 0.2*(depth-depth2+i-1) < 0.3; i++) { + d = MIN(0.2*(depth-depth2+i), 0.3); + cairo_set_source_rgb(cr, d, d, d); + + for(d = rect->x - fmod(rect->x, step) - step; d <= rect->x+rect->width; d+=step) { + cairo_move_to(cr, d, rect->y); + cairo_line_to(cr, d, rect->y+rect->height); cairo_stroke(cr); + + if(step > 0.2) + g_snprintf(buffer, sizeof(buffer), "%i", (int)rint(d)); + else + g_snprintf(buffer, sizeof(buffer), "%.*f", -(int)floor(log10(step*1.1)), d+step/10); + buffer[sizeof(buffer)-1] = '\0'; + cairo_move_to(cr, d+1/scale, rect->y+11/scale); + cairo_show_text(cr, buffer); } - 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); + for(d = rect->y - fmod(rect->y, step) - step; d <= rect->y+rect->height; d+=step) { + cairo_move_to(cr, rect->x, d); + cairo_line_to(cr, rect->x+rect->width, d); cairo_stroke(cr); + + if(step > 0.5) + g_snprintf(buffer, sizeof(buffer), "%i", (int)rint(d)); + else + g_snprintf(buffer, sizeof(buffer), "%.*f", -(int)floor(log10(step*1.1)), d+step/10); + buffer[sizeof(buffer)-1] = '\0'; + cairo_move_to(cr, rect->x+3/scale, d+11/scale); + cairo_show_text(cr, buffer); } 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); } } @@ -73,7 +91,7 @@ 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}; + RECTANGLE rect = {-1, -1, widget->allocation.width+2, widget->allocation.height+2}; int i; -- cgit v1.2.3