]> git.cworth.org Git - kub/commitdiff
Allow selection of a tile by including any corner
authorKevin Worth <kworth@kworth-laptop.(none)>
Fri, 12 Jun 2009 13:54:26 +0000 (09:54 -0400)
committerKevin Worth <kworth@kworth-laptop.(none)>
Mon, 15 Jun 2009 18:55:39 +0000 (14:55 -0400)
      A group of tiles can now be selected by overlapping the
      selection_box with any corner of each tile(top-left,
      bottom-right, etc)

      Bug fix: previously, the corners of the selection_box were
      not being updated if the mouse was clicked without being
      dragged. Now, with each click, x2 is set equal to x1, and
      y2 to y1. Then, as before, they are updated as the mouse
      is dragged.

kub.c

diff --git a/kub.c b/kub.c
index f77dfcbd4bdd093b556332e79f616e72c6df41f7..bae99e772f789f28424709c2c93a51b75cb0a937 100644 (file)
--- a/kub.c
+++ b/kub.c
@@ -537,7 +537,9 @@ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event,
        game->click_y = event->y;
        /*...these two lines*/
        game->selection_box.x1 = event->x;
        game->click_y = event->y;
        /*...these two lines*/
        game->selection_box.x1 = event->x;
+       game->selection_box.x2 = event->x;
        game->selection_box.y1 = event->y;
        game->selection_box.y1 = event->y;
+       game->selection_box.y2 = event->y;
     }
     return TRUE;
 }
     }
     return TRUE;
 }
@@ -550,26 +552,38 @@ static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *even
        selection_box_t *box;
        box = &game->selection_box;
 
        selection_box_t *box;
        box = &game->selection_box;
 
-       int x = MIN(box->x1, box->x2);
-       int y = MIN(box->y1, box->y2);
+       int x_min = MIN(box->x1, box->x2);
+       int x_max = MAX(box->x1, box->x2);
+       int y_min = MIN(box->y1, box->y2);
+       int y_max = MAX(box->y1, box->y2);
        int width = abs(box->x2 - box->x1);
        int height = abs(box->y2 - box->y1);
 
        box->visible = 0;       
        int width = abs(box->x2 - box->x1);
        int height = abs(box->y2 - box->y1);
 
        box->visible = 0;       
-       gtk_widget_queue_draw_area (widget, x, y, width, height);
+       gtk_widget_queue_draw_area (widget, x_min, y_min, width, height);
 
        tile_group_t group;
        group.num_tiles = 0;
 
 
        tile_group_t group;
        group.num_tiles = 0;
 
-       int i, tile_x, tile_y;
+       int i, tile_x, tile_y, tile_x2, tile_y2;
        for (i = 0; i < game->deck.num_tiles; i++)
         {
            tile_x = game->deck.tiles[i].x;
            tile_y = game->deck.tiles[i].y;
        for (i = 0; i < game->deck.num_tiles; i++)
         {
            tile_x = game->deck.tiles[i].x;
            tile_y = game->deck.tiles[i].y;
-           if ( (event->x >= tile_x && game->click_x <= tile_x &&
-                 event->y >= tile_y && game->click_y <= tile_y) ||
-                (event->x >= tile_x && game->click_x <= tile_x &&
-                 event->y <= (tile_y + TILE_HEIGHT) && game->click_y >= tile_y) )
+           tile_x2 = tile_x + TILE_WIDTH;
+           tile_y2 = tile_y + TILE_HEIGHT;
+           if (/*If top-left corner*/
+               (tile_x >= x_min && tile_x <= x_max &&
+                tile_y >= y_min && tile_y <= y_max) ||
+               /*or bottom-right corner*/
+               (tile_x2 >= x_min && tile_x2 <= x_max &&
+                tile_y2 >= y_min && tile_y2 <= y_max) ||
+               /*or bottom-left corner*/
+               (tile_x >= x_min && tile_x <= x_max &&
+                tile_y2 >= y_min && tile_y2 <= y_max) ||
+               /*or top-right corner of tile selected*/
+               (tile_x2 >= x_min && tile_x2 <= x_max &&
+                tile_y >= y_min && tile_y <= y_max) )
             {
                group.tiles[group.num_tiles] = game->deck.tiles[i];
                group.num_tiles++;
             {
                group.tiles[group.num_tiles] = game->deck.tiles[i];
                group.num_tiles++;
@@ -580,7 +594,7 @@ static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *even
        for (i = 0; i < group.num_tiles; i++)
            tile_print(group.tiles[i]);
     }
        for (i = 0; i < group.num_tiles; i++)
            tile_print(group.tiles[i]);
     }
-
+    
     game->select_mode = 1;
 
     return TRUE;
     game->select_mode = 1;
 
     return TRUE;