diff options
-rw-r--r-- | display.h | 2 | ||||
-rw-r--r-- | gtk-gui.c | 13 | ||||
-rw-r--r-- | print.c | 3 | ||||
-rw-r--r-- | profile.c | 11 |
4 files changed, 15 insertions, 14 deletions
@@ -22,7 +22,7 @@ struct graphics_context { double topy, bottomy; }; -extern void plot(struct graphics_context *gc, int w, int h, struct dive *dive); +extern void plot(struct graphics_context *gc, cairo_rectangle_int_t *drawing_area, struct dive *dive); extern void set_source_rgb(struct graphics_context *gc, double r, double g, double b); #endif @@ -674,18 +674,21 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer { struct dive *dive = current_dive; struct graphics_context gc = { .printer = 0 }; - int w,h; + static cairo_rectangle_int_t drawing_area; - w = widget->allocation.width; - h = widget->allocation.height; + /* the drawing area gives TOTAL width * height - x,y is used as the topx/topy offset + * so effective drawing area is width-2x * height-2y */ + drawing_area.width = widget->allocation.width; + drawing_area.height = widget->allocation.height; + drawing_area.x = drawing_area.width / 20.0; + drawing_area.y = drawing_area.height / 20.0; gc.cr = gdk_cairo_create(widget->window); set_source_rgb(&gc, 0, 0, 0); cairo_paint(gc.cr); if (dive) - plot(&gc, w, h, dive); - + plot(&gc, &drawing_area, dive); cairo_destroy(gc.cr); return FALSE; @@ -127,12 +127,13 @@ static void show_dive_text(struct dive *dive, cairo_t *cr, double w, double h, P static void show_dive_profile(struct dive *dive, cairo_t *cr, double w, double h) { + cairo_rectangle_int_t drawing_area = { w/20.0, h/20.0, w, h}; struct graphics_context gc = { .printer = 1, .cr = cr }; cairo_save(cr); - plot(&gc, w, h, dive); + plot(&gc, &drawing_area, dive); cairo_restore(cr); } @@ -722,14 +722,11 @@ static struct plot_info *create_plot_info(struct dive *dive) return analyze_plot_info(pi); } -void plot(struct graphics_context *gc, int w, int h, struct dive *dive) +void plot(struct graphics_context *gc, cairo_rectangle_int_t *drawing_area, struct dive *dive) { - double topx, topy; struct plot_info *pi = create_plot_info(dive); - topx = w / 20.0; - topy = h / 20.0; - cairo_translate(gc->cr, topx, topy); + cairo_translate(gc->cr, drawing_area->x, drawing_area->y); cairo_set_line_width(gc->cr, 2); cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND); @@ -741,8 +738,8 @@ void plot(struct graphics_context *gc, int w, int h, struct dive *dive) * * Snif. What a pity. */ - gc->maxx = (w - 2*topx); - gc->maxy = (h - 2*topy); + gc->maxx = (drawing_area->width - 2*drawing_area->x); + gc->maxy = (drawing_area->height - 2*drawing_area->y); /* Temperature profile */ plot_temperature_profile(gc, pi); |