diff options
Diffstat (limited to 'draw.c')
-rw-r--r-- | draw.c | 33 |
1 files changed, 19 insertions, 14 deletions
@@ -32,8 +32,6 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) { 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 @@ -47,8 +45,6 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) { 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 @@ -58,6 +54,8 @@ static void drawGrid(cairo_t *cr, const RECTANGLE *rect) { cairo_show_text(cr, buffer); } + cairo_stroke(cr); + step *= 10; } } @@ -90,7 +88,8 @@ static void room2path(cairo_t *cr, const ROOM *room, const RECTANGLE *rect) { gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_t *cr; - RECTANGLE rect = {-1, -1, widget->allocation.width+2, widget->allocation.height+2}; + VERTEX v1 = {-1, -1}, v2 = {widget->allocation.width+1, widget->allocation.height+1}; + RECTANGLE rect; static GdkPixmap *pixmap = NULL; static double lastImageWidth = 0.0, lastImageHeight = 0.0; static gint lastWidth = 0.0, lastHeight = 0.0; @@ -99,6 +98,14 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { if(getLevel() == NULL) return FALSE; + viewToImage(&v1); + viewToImage(&v2); + + rect.x = v1.x; + rect.y = v1.y; + rect.width = v2.x-v1.x; + rect.height = v2.y-v1.y; + if(pixmap == NULL || lastImageWidth != getImageWidth() || lastImageHeight != getImageHeight() || lastWidth != widget->allocation.width || lastHeight != widget->allocation.height || repaint) { @@ -115,19 +122,15 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cr = gdk_cairo_create(GDK_DRAWABLE(pixmap)); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_rectangle(cr, 0, 0, widget->allocation.width, widget->allocation.height); - cairo_fill(cr); - cairo_translate(cr, getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate); cairo_scale(cr, scale, scale); - cairo_device_to_user(cr, &rect.x, &rect.y); - cairo_device_to_user_distance(cr, &rect.width, &rect.height); - cairo_set_line_width(cr, 1.0/scale); cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_paint(cr); + drawGrid(cr, &rect); for(i = 0; i < getLevel()->nRooms; i++) { @@ -157,7 +160,9 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { gdk_draw_drawable(GDK_DRAWABLE(widget->window), widget->style->fg_gc[GTK_WIDGET_STATE(widget)], GDK_DRAWABLE(pixmap), 0, 0, 0, 0, -1, -1); - if(getHoveredRoom() != NULL && getHoveredRoom() != getActiveRoom()) { + if(getHoveredRoom() != NULL && getHoveredRoom() != getActiveRoom() && + (getEditMode() == EDIT_MODE_VIEW || getEditMode() == EDIT_MODE_SELECTED)) + { cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); cairo_translate(cr, getImageWidth()/2-xTranslate, getImageHeight()/2-yTranslate); @@ -166,7 +171,7 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_set_line_width(cr, 2.0/scale); cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER); - room2path(cr, getHoveredRoom(), NULL); + room2path(cr, getHoveredRoom(), &rect); cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.7); cairo_stroke(cr); |