diff options
author | Benjamin Otte <otte@redhat.com> | 2011-10-13 13:23:06 -0700 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2011-10-15 00:06:22 -0700 |
commit | 239ca50fa8020d19b338eb72128b34390f335132 (patch) | |
tree | 96ea926560da2165c5eb899eaa529423885d411b | |
parent | d7a24ac78647089d74368b5fe9ede214f32cf8d3 (diff) |
rectangle: Introduce game_rectangle_path()
Just a tiny convenience function to draw rectangles.
-rw-r--r-- | libgame/game-geom-basics.c | 19 | ||||
-rw-r--r-- | libgame/game-geom-basics.h | 3 | ||||
-rw-r--r-- | libgame/game-graphic.c | 4 |
3 files changed, 25 insertions, 1 deletions
diff --git a/libgame/game-geom-basics.c b/libgame/game-geom-basics.c index 6d0e4cb..880084f 100644 --- a/libgame/game-geom-basics.c +++ b/libgame/game-geom-basics.c @@ -150,6 +150,25 @@ game_rectangle_resize (GameRectangle *dest, const GameRectangle *src, dest->y2 = src->y1 + (src->y2 - src->y1) * y; } + +/** + * game_rectangle_path: + * @cr: a cairo context + * @rect: the rectangle + * + * Adds the path of @rect to the given cairo context. This is equivalent to + * calling cairo_rectangle() on @cr with the coordinates of @rect. + **/ +void +game_rectangle_path (cairo_t *cr, const GameRectangle *rect) +{ + g_return_if_fail (cr != NULL); + g_return_if_fail (rect != NULL); + + if (GAME_RECTANGLE_IS_VALID (rect)) + cairo_rectangle (cr, rect->x1, rect->y1, rect->x2 - rect->x1, rect->y2 - rect->y1); +} + /*** COLORS ***/ GAME_STRUCT_AS_TYPE (GameColor, game_color) diff --git a/libgame/game-geom-basics.h b/libgame/game-geom-basics.h index 2325f38..57d8751 100644 --- a/libgame/game-geom-basics.h +++ b/libgame/game-geom-basics.h @@ -93,6 +93,9 @@ void game_rectangle_resize (GameRectangle * dest, double x, double y); +void game_rectangle_path (cairo_t * cr, + const GameRectangle * rect); + /* color stuff */ GType game_color_get_type (void) G_GNUC_CONST; diff --git a/libgame/game-graphic.c b/libgame/game-graphic.c index 7363eae..c73b55b 100644 --- a/libgame/game-graphic.c +++ b/libgame/game-graphic.c @@ -288,8 +288,10 @@ game_graphic_draw_area_no_cache (GameGraphic *graphic, cairo_t *cr, GameGraphicClass *klass; cairo_save (cr); - cairo_rectangle (cr, rect->x1, rect->y1, rect->x2 - rect->x1, rect->y2 - rect->y1); + + game_rectangle_path (cr, &graphic->rect); cairo_clip (cr); + klass = GAME_GRAPHIC_GET_CLASS (graphic); g_return_val_if_fail (klass->draw, FALSE); klass->draw (graphic, cr, rect); |