summaryrefslogtreecommitdiffstats
path: root/draw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'draw.cpp')
-rw-r--r--draw.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/draw.cpp b/draw.cpp
index 65cf13a..edb0657 100644
--- a/draw.cpp
+++ b/draw.cpp
@@ -13,13 +13,15 @@ static double xTranslate = 0.0, yTranslate = 0.0;
static gboolean repaint = FALSE;
-static void drawGrid(cairo_t *cr, const 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 d;
int i;
gchar *string;
+ double x1 = rect->getVertex1().getX(), y1 = rect->getVertex1().getY();
+ double x2 = rect->getVertex2().getX(), y2 = rect->getVertex2().getY();
cairo_set_font_size(cr, 10.0/scale);
@@ -28,9 +30,9 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) {
d = MIN(0.4*(depth-depth2+i), 0.5);
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);
+ for(d = x1 - fmod(x1, step) - step; d <= x2; d+=step) {
+ cairo_move_to(cr, d, y1);
+ cairo_line_to(cr, d, y2);
if(step > 0.005) {
if(step > 0.5)
@@ -38,16 +40,16 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) {
else
string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
- cairo_move_to(cr, d+1/scale, rect->y+11/scale);
+ cairo_move_to(cr, d+1/scale, y1+11/scale);
cairo_show_text(cr, string);
g_free(string);
}
}
- 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);
+ for(d = y1 - fmod(y1, step) - step; d <= y2; d+=step) {
+ cairo_move_to(cr, x1, d);
+ cairo_line_to(cr, x2, d);
if(step > 0.005) {
if(step > 0.5)
@@ -55,7 +57,7 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) {
else
string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
- cairo_move_to(cr, rect->x+3/scale, d+11/scale);
+ cairo_move_to(cr, x1+3/scale, d+11/scale);
cairo_show_text(cr, string);
g_free(string);
@@ -68,7 +70,7 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) {
}
}
-static void polygon2path(cairo_t *cr, const Polygon *polygon, const RECTANGLE *rect, gboolean close) {
+static void polygon2path(cairo_t *cr, const Polygon *polygon, const Rectangle *rect, gboolean close) {
Polygon polygon2;
// no vertices
@@ -94,7 +96,7 @@ static void polygon2path(cairo_t *cr, const Polygon *polygon, const RECTANGLE *r
gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
cairo_t *cr;
Vertex v1(-1, -1), v2(widget->allocation.width+1, widget->allocation.height+1);
- RECTANGLE rect;
+ Rectangle rect;
gboolean vertexOk;
static GdkPixmap *pixmap = NULL;
static double lastImageWidth = 0.0, lastImageHeight = 0.0;
@@ -108,10 +110,8 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
viewToImage(&v1);
viewToImage(&v2);
- rect.x = v1.getX();
- rect.y = v1.getY();
- rect.width = v2.getX()-v1.getX();
- rect.height = v2.getY()-v1.getY();
+ rect.setVertex1(v1);
+ rect.setVertex2(v2);
if(pixmap == NULL || fabs(lastImageWidth - getImageWidth()) >= 0.000001 || fabs(lastImageHeight - getImageHeight()) >= 0.000001 ||
lastWidth != widget->allocation.width || lastHeight != widget->allocation.height || lastEditMode != getEditMode() || repaint)