From 936a590e44f49282717fa02b4fd74421997f8ba7 Mon Sep 17 00:00:00 2001 From: Kevin Worth <kworth@kworth-laptop.(none)> Date: Tue, 30 Jun 2009 12:27:21 -0400 Subject: [PATCH] Highlight tile when clicked and/or dragged. New .svg file added(highlighted version of tile) A tile is highlighted when clicked and remains highlighted until another tile or empty space is clicked. --- kub.c | 32 +++++++++++++-- tiles/selectedtile.svg | 89 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 tiles/selectedtile.svg diff --git a/kub.c b/kub.c index bae99e7..a4d5dce 100644 --- a/kub.c +++ b/kub.c @@ -53,6 +53,7 @@ typedef struct tile { int number; int x; int y; + int selected; } tile_t; #define DECK_MAX_TILES 104 @@ -95,6 +96,7 @@ typedef struct game { deck_t deck; selection_box_t selection_box; RsvgHandle *blanktile; + RsvgHandle *selectedtile; int current_tile; int select_mode; @@ -125,6 +127,7 @@ static void tile_init (tile_t *tile, color_t color, int number) tile->number = number; tile->x = 0; tile->y = 0; + tile->selected = 0; } static void tile_set_x_y (tile_t *tile, int x, int y) @@ -157,7 +160,11 @@ static void tile_draw(game_t *game, tile_t *tile, cairo_t *cr, GdkRegion *region cairo_save(cr); cairo_translate(cr, tile->x, tile->y); - rsvg_handle_render_cairo (game->blanktile, cr); + + if (tile->selected) + rsvg_handle_render_cairo (game->selectedtile, cr); + else + rsvg_handle_render_cairo (game->blanktile, cr); if (tile->color == BLACK) cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); @@ -477,6 +484,10 @@ static void game_init(game_t *game) deck_init(&game->deck); deck_shuffle(&game->deck); + game->selectedtile = rsvg_handle_new_from_file ("tiles/selectedtile.svg", &error); + if (error) + FATAL_ERROR (error->message); + game->blanktile = rsvg_handle_new_from_file ("tiles/blanktile.svg", &error); if (error) FATAL_ERROR (error->message); @@ -515,6 +526,7 @@ static gboolean on_key_press_event (GtkWidget *widget, GdkEventKey *event, game_ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, game_t *game) { int i, tile_x, tile_y; + tile_t *curr_tile = &game->deck.tiles[game->current_tile]; for (i = 0; i < game->deck.num_tiles; i++) { @@ -524,13 +536,28 @@ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) ) { game->select_mode = 0; + + curr_tile = &game->deck.tiles[game->current_tile]; + game->deck.tiles[game->current_tile].selected = 0; + gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2); + game->current_tile = i; + curr_tile = &game->deck.tiles[game->current_tile]; + if (!curr_tile->selected) + curr_tile->selected = 1; + else + curr_tile->selected = 0; + gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2); + game->diff_x = event->x - tile_x; game->diff_y = event->y - tile_y; } } if (game->select_mode) { + game->deck.tiles[game->current_tile].selected = 0; + gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2); + game->selection_box.visible = 1; /*These next two lines are likely to be replaced by...*/ game->click_x = event->x; @@ -593,8 +620,7 @@ static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *even printf("is set %d\n", tile_group_is_set(&group) ); for (i = 0; i < group.num_tiles; i++) tile_print(group.tiles[i]); - } - + } game->select_mode = 1; return TRUE; diff --git a/tiles/selectedtile.svg b/tiles/selectedtile.svg new file mode 100644 index 0000000..6b13914 --- /dev/null +++ b/tiles/selectedtile.svg @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="544" + height="852" + id="svg1421" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="selectedtile.svg" + sodipodi:docbase="/home/kworth/kub/tiles" + inkscape:output_extension="org.inkscape.output.svg.inkscape"> + <metadata + id="metadata1438"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs1436"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 426 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="544 : 426 : 1" + inkscape:persp3d-origin="272 : 284 : 1" + id="perspective2447" /> + </defs> + <sodipodi:namedview + inkscape:window-height="687" + inkscape:window-width="649" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + inkscape:zoom="7.3333333" + inkscape:cx="23.314862" + inkscape:cy="829.88877" + inkscape:window-x="13" + inkscape:window-y="51" + inkscape:current-layer="svg1421" + showgrid="false" /> + <rect + id="tile" + style="fill:#ffffe4;fill-opacity:0.75;stroke:#b2964a;stroke-width:1" + width="35" + height="50" + x="0" + y="0" /> + <g + id="sun" + style="fill:#ffffe4;fill-opacity:0.75;stroke:#b2964a;stroke-width:1" + transform="matrix(0.5905,0,0,0.5905,-56.74979,-52.44054)"> +<!-- Triangular rays around the sun --> <path + d="M 139.38034,162.33228 L 132.916,161.60434 L 131.18921,168.5345 L 125.8984,164.2523 L 120.91689,168.73756 L 119.6583,162.38682 L 112.48703,162.86394 L 114.80783,156.12386 L 109.11958,153.15712 L 114.8007,149.75492 L 112.10076,143.3248 L 119.03117,143.60194 L 120.29189,137.12259 L 125.36176,141.10086 L 130.56421,136.91952 L 132.1242,143.32475 L 138.99407,142.79315 L 136.39722,148.95452 L 142.36152,152.49996 L 136.64051,156.25356 L 139.38034,162.33228 z " + id="path1425" /> +<!-- The circle of the sun itself --> <path + transform="matrix(0.98685,-0.161642,0.161642,0.98685,-19.31536,24.84557)" + d="M 133.69581,149.74696 C 133.69843,155.9537 128.66761,160.98664 122.46087,160.98664 C 116.25413,160.98664 111.22331,155.9537 111.22593,149.74696 C 111.22331,143.54022 116.25413,138.50728 122.46087,138.50728 C 128.66761,138.50728 133.69843,143.54022 133.69581,149.74696 z " + id="path1427" /> +<!-- The right eye of the sun --> <path + transform="translate(9.112005,3.852231)" + d="M 121.49343,146.01378 C 121.49343,146.93435 120.8135,147.68061 119.97476,147.68061 C 119.13602,147.68061 118.45609,146.93435 118.45609,146.01378 C 118.45609,145.09321 119.13602,144.34695 119.97476,144.34695 C 120.8135,144.34695 121.49343,145.09321 121.49343,146.01378 z " + id="path1429" /> +<!-- The left eye of the sun --> <path + transform="translate(2.407652,3.667036)" + d="M 121.49343,146.01378 C 121.49343,146.93435 120.8135,147.68061 119.97476,147.68061 C 119.13602,147.68061 118.45609,146.93435 118.45609,146.01378 C 118.45609,145.09321 119.13602,144.34695 119.97476,144.34695 C 120.8135,144.34695 121.49343,145.09321 121.49343,146.01378 z " + id="path1431" /> +<!-- The sun's grumpy mouth --> <path + d="M 119.78955,156.19997 C 119.78296,156.70099 120.16156,156.94238 120.60445,157.38527 C 120.83248,157.61331 121.18299,157.78567 121.41934,157.90384 C 122.00513,158.19674 122.87596,158.05201 123.5677,158.05201 C 124.43595,158.05201 124.64727,157.91967 125.41974,157.53344 C 125.86375,157.31143 126.22871,157.01783 126.67912,156.79262 C 127.13862,156.56287 127.62672,156.57811 128.08667,156.34813 C 128.38261,156.20017 129.25716,156.34443 129.56829,156.42222 C 130.05387,156.54361 130.68093,156.8231 131.124,157.08895 C 131.41598,157.26413 131.6912,157.59827 131.86482,157.82976 C 131.97287,157.97384 132.09156,158.06099 132.16115,158.20017" + id="path1433" /> + </g> + <path + style="fill:#c8ab37;fill-opacity:0.97456515000000021" + d="M 0.55894937,24.986364 L 0.55894937,0.5090908 L 17.46804,0.5090908 L 34.377131,0.5090908 L 34.377131,24.986364 L 34.377131,49.463636 L 17.46804,49.463636 L 0.55894937,49.463636 L 0.55894937,24.986364 z M 17.618561,45.1 C 17.676085,45.1 18.399419,45.652273 19.225971,46.327273 C 20.052524,47.002273 20.779514,47.554546 20.841506,47.554546 C 20.903501,47.554546 21.1872,46.609901 21.471954,45.455336 L 21.989684,43.356129 L 22.490224,43.418609 C 24.474036,43.66625 26.058949,43.808913 26.058949,43.739844 C 26.058949,43.694823 25.690768,42.844267 25.240768,41.849721 C 24.790768,40.855176 24.422586,40.015115 24.422586,39.982919 C 24.422586,39.950726 25.189631,39.425863 26.127131,38.816559 C 27.064631,38.207257 27.831677,37.661413 27.831677,37.603577 C 27.831677,37.545737 27.033949,37.029498 26.058949,36.456376 C 25.083949,35.88325 24.286222,35.378083 24.286222,35.333778 C 24.286222,35.289475 24.632589,34.429889 25.055927,33.42359 C 25.479264,32.41729 25.801423,31.570791 25.771836,31.542479 C 25.742248,31.514167 24.780951,31.563305 23.63562,31.651671 L 21.553203,31.812336 L 21.426476,31.331167 C 21.356779,31.066525 21.135727,30.190341 20.935249,29.384091 C 20.734769,28.577841 20.531769,27.918182 20.484133,27.918182 C 20.436498,27.918182 19.70352,28.475413 18.855295,29.156473 C 18.007071,29.837533 17.240549,30.361656 17.151917,30.321189 C 17.063284,30.280723 16.346449,29.730355 15.558949,29.09815 C 14.671588,28.385777 14.094817,28.007705 14.042151,28.10389 C 13.995414,28.189252 13.822727,28.995455 13.658407,29.895455 C 13.494088,30.795455 13.329141,31.638007 13.29186,31.767794 C 13.229949,31.983328 13.041708,31.996245 11.118786,31.9169 C 9.7762299,31.8615 9.0134949,31.878427 9.0134949,31.963615 C 9.0134949,32.037089 9.3509949,32.888735 9.7634949,33.856165 C 10.175995,34.823595 10.513495,35.679176 10.513495,35.757459 C 10.513495,35.83574 9.7464494,36.358067 8.8089494,36.918182 C 7.8714494,37.478297 7.1044039,37.972233 7.1044039,38.015815 C 7.1044039,38.059397 7.895163,38.505985 8.8616458,39.00823 L 10.618889,39.921403 L 9.918464,41.953507 C 9.5332312,43.071164 9.2487221,44.014404 9.2862221,44.049594 C 9.3237221,44.084786 10.291706,44.050664 11.437299,43.973773 C 12.582888,43.896877 13.549259,43.863037 13.584784,43.898563 C 13.62031,43.93409 13.80628,44.755877 13.998051,45.72476 C 14.189822,46.693646 14.373801,47.567516 14.406895,47.666702 C 14.44462,47.779768 15.035335,47.3347 15.990521,46.47352 C 16.82842,45.718081 17.561039,45.1 17.618561,45.1 z" + id="path2451" /> +</svg> -- 2.45.2