Commit 25860123 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Move tile rotation in tiles getter.

parent c6426b25
......@@ -395,15 +395,7 @@ draw_tile_cb (OVCCBoard *board,
dest_y;
gint rotation;
pix = tile_get_pixbuf (ovcc_tile_get_id (tile));
rotation = ovcc_tile_get_rotation (tile);
if (rotation > 0) {
GdkPixbuf *new;
new = gdk_pixbuf_rotate_simple (pix, 360 - 90 * rotation);
g_object_unref (pix);
pix = new;
}
pix = tile_get_pixbuf (tile);
ovccgtk_board_board_to_widget_coords (self, pos->x, pos->y, &dest_x, &dest_y);
gdk_draw_pixbuf (window, self->priv->gc, pix, 0, 0, dest_x, dest_y,
TILE_SIZE, TILE_SIZE, GDK_RGB_DITHER_NORMAL, 0, 0);
......
......@@ -198,17 +198,9 @@ update_tile_image (App *app)
tile = ovcc_stack_peek (app->game.stack);
if (tile) {
GdkPixbuf *pix;
gint rotation = ovcc_tile_get_rotation (tile);
GdkPixbuf *pix;
pix = tile_get_pixbuf (ovcc_tile_get_id (tile));
if (rotation > 0) {
GdkPixbuf *new;
new = gdk_pixbuf_rotate_simple (pix, 360 - 90 * rotation);
g_object_unref (pix);
pix = new;
}
pix = tile_get_pixbuf (tile);
gtk_image_set_from_pixbuf (GTK_IMAGE (app->current_tile_image), pix);
g_object_unref (pix);
ovcc_tile_unref (tile);
......
......@@ -145,8 +145,18 @@ load_tile (OVCCTileID id)
}
/**
* tile_get_pixbuf_by_id:
* @id: An #OVCCTileID
*
* Gets a graphical representation of a tile from its ID.
* See tile_get_pixbuf() too.
*
* Returns: The image representing the tile. You should unref the returned
* pixbuf when no longer needed.
*/
GdkPixbuf *
tile_get_pixbuf (OVCCTileID id)
tile_get_pixbuf_by_id (OVCCTileID id)
{
GdkPixbuf *pixbuf;
......@@ -159,8 +169,37 @@ tile_get_pixbuf (OVCCTileID id)
return g_object_ref (pixbuf);
}
/**
* tile_get_pixbuf:
* @tile: An #OVCCTile
*
* Gets a graphical representation of a tile.
* It gets the image, as tile_get_pixbuf_by_id() does, but rotates it if needed
* too.
*
* Returns: The image representing @tile. You should unref the returned pixbuf
* when no longer needed.
*/
GdkPixbuf *
tile_get_pixbuf (OVCCTile *tile)
{
GdkPixbuf *pix;
gint rotation = ovcc_tile_get_rotation (tile);
pix = tile_get_pixbuf_by_id (ovcc_tile_get_id (tile));
if (rotation > 0) {
GdkPixbuf *new;
new = gdk_pixbuf_rotate_simple (pix, 360 - 90 * rotation);
g_object_unref (pix);
pix = new;
}
return pix;
}
gboolean
tile_exists (OVCCTileID id)
{
return tile_get_pixbuf (id) != NULL;
return tile_get_pixbuf_by_id (id) != NULL;
}
......@@ -29,8 +29,9 @@ G_BEGIN_DECLS
#define TILE_SIZE 64
GdkPixbuf *tile_get_pixbuf (OVCCTileID id);
gboolean tile_exists (OVCCTileID id);
GdkPixbuf *tile_get_pixbuf_by_id (OVCCTileID id);
GdkPixbuf *tile_get_pixbuf (OVCCTile *tile);
gboolean tile_exists (OVCCTileID id);
G_END_DECLS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment