From 48dfed6a8235ceaf6031b4d08834d986a875ff1d Mon Sep 17 00:00:00 2001 From: Kevin Worth Date: Sat, 6 Jun 2009 10:31:36 -0400 Subject: [PATCH] Showing carl error with drawing the selection_box --- kub.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/kub.c b/kub.c index ba60924..2fdcd36 100644 --- a/kub.c +++ b/kub.c @@ -108,16 +108,12 @@ static void selection_box_init(selection_box_t *box) box->x2 = 0; box->y1 = 0; box->y2 = 0; - rect->visible = 0; + box->visible = 0; } static void selection_box_draw(selection_box_t *box, cairo_t *cr) { - int box_x = MIN(box->x1, box->x2); - int box_y = MIN(box->y1, box->y2); - int box_width = abs(box->x2 - box->x1); - int box_height = abs(box->y2 - box->y1); - cairo_rectangle (cr, box_x, box_y, box_width, box_height); + cairo_rectangle (cr, box->x1, box->y1, box->x2 -box->x1, box->y2 - box->y1); cairo_set_source_rgba(cr, 0.0, 0.1, 0.2, 0.5); cairo_fill (cr); } @@ -552,8 +548,13 @@ static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *even selection_box_t *box; box = &game->selection_box; + int x = MIN(box->x1, box->x2); + int y = MIN(box->y1, box->y2); + int width = abs(box->x2 - box->x1); + int height = abs(box->y2 - box->y1); + box->visible = 0; - gtk_widget_queue_draw_area (widget, box->x, box->y, box->width, box->height); + gtk_widget_queue_draw_area (widget, x - 1, y - 1, width - 2, height + 2); tile_group_t group; group.num_tiles = 0; @@ -592,12 +593,12 @@ static gboolean on_button_motion_event (GtkWidget *widget, GdkEventMotion *event box = &game->selection_box; box->visible = 1; - gtk_widget_queue_draw_area (widget, box->x - 1, box->y - 1, box->width + 1, box->height + 2); + gtk_widget_queue_draw_area ( widget, MIN(box->x1, box->x2), MIN(box->y1, box->y2), abs(box->x2 - box->x1), abs(box->y2 - box->y1) ); - box->width = event->x - box->x; - box->height = event->y - box->y; + box->x2 = event->x; + box->x2 = event->y; - gtk_widget_queue_draw_area (widget, box->x - 1, box->y - 1, box->width + 1, box->height + 2); + gtk_widget_queue_draw_area ( widget, MIN(box->x1, box->x2), MIN(box->y1, box->y2), abs(box->x2 - box->x1), abs(box->y2 - box->y1) ); } else { -- 2.43.0