zoomedit: Added scales to grid.

This commit is contained in:
neoraider 2007-06-24 17:33:00 +00:00
parent 4e9abadc47
commit a686a31dae

46
draw.c
View file

@ -3,6 +3,7 @@
#include "geometry.h"
#include <math.h>
#include <gtk/gtk.h>
#include <glib/gprintf.h>
#include <cairo/cairo.h>
@ -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;