zoomedit: Added grid.
This commit is contained in:
parent
6c9c0b8a29
commit
464a75f77b
1 changed files with 36 additions and 1 deletions
37
draw.c
37
draw.c
|
@ -1,6 +1,7 @@
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "level.h"
|
#include "level.h"
|
||||||
#include "geometry.h"
|
#include "geometry.h"
|
||||||
|
#include <math.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
|
|
||||||
|
@ -9,7 +10,39 @@ static double scale = 100.0;
|
||||||
static double xTranslate = 0.0, yTranslate = 0.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;
|
int i;
|
||||||
ROOM room2 = {0, NULL};
|
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_width(cr, 1.0/scale);
|
||||||
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
|
cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
|
||||||
|
|
||||||
|
drawGrid(cr, &rect);
|
||||||
|
|
||||||
for(i = 0; i < lvl.nRooms; i++)
|
for(i = 0; i < lvl.nRooms; i++)
|
||||||
room2path(cr, &lvl.rooms[i], &rect);
|
room2path(cr, &lvl.rooms[i], &rect);
|
||||||
|
|
||||||
|
|
Reference in a new issue