cairo-texture: Deprecate create()/create_region()

The recommended way of drawing on a ClutterCairoTexture is the ::draw
signal.
This commit is contained in:
Emmanuele Bassi 2011-07-26 12:53:22 +01:00
parent 2f445682b1
commit 278daca61c
6 changed files with 59 additions and 34 deletions

View File

@ -718,6 +718,10 @@ intersect_rectangles (cairo_rectangle_int_t *a,
* to upload the contents of the context when done drawing
*
* Since: 1.0
*
* Deprecated: 1.8: Use the #ClutterCairoTexture::draw signal and
* clutter_cairo_texture_invalidate_rectangle() to obtain a
* clipped Cairo context for 2D drawing.
*/
cairo_t *
clutter_cairo_texture_create_region (ClutterCairoTexture *self,
@ -879,6 +883,10 @@ clutter_cairo_texture_invalidate (ClutterCairoTexture *self)
* to upload the contents of the context when done drawing
*
* Since: 1.0
*
* Deprecated: 1.8: Use the #ClutterCairoTexture::draw signal and
* the clutter_cairo_texture_invalidate() function to obtain a
* Cairo context for 2D drawing.
*/
cairo_t *
clutter_cairo_texture_create (ClutterCairoTexture *self)

View File

@ -115,12 +115,14 @@ GType clutter_cairo_texture_get_type (void) G_GNUC_CONST;
ClutterActor * clutter_cairo_texture_new (guint width,
guint height);
#ifndef CLUTTER_DISABLE_DEPRECATED
cairo_t * clutter_cairo_texture_create_region (ClutterCairoTexture *self,
gint x_offset,
gint y_offset,
gint width,
gint height);
cairo_t * clutter_cairo_texture_create (ClutterCairoTexture *self);
#endif /* CLUTTER_DISABLE_DEPRECATED */
void clutter_cairo_texture_set_surface_size (ClutterCairoTexture *self,
guint width,

View File

@ -1,3 +1,4 @@
#undef CLUTTER_DISABLE_DEPRECATED
#include <clutter/clutter.h>
#include <cogl/cogl.h>

View File

@ -7,15 +7,15 @@ static const ClutterColor bg_color = { 0xcc, 0xcc, 0xcc, 0x99 };
static gboolean is_expanded = FALSE;
static void
update_background (ClutterActor *tex,
const ClutterColor *color,
gfloat width,
gfloat height)
static gboolean
draw_background (ClutterCairoTexture *texture,
cairo_t *cr)
{
cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (tex));
cairo_pattern_t *pat;
gfloat x, y;
guint width, height;
clutter_cairo_texture_get_surface_size (texture, &width, &height);
#define BG_ROUND_RADIUS 12
@ -33,7 +33,7 @@ update_background (ClutterActor *tex,
cairo_close_path (cr);
clutter_cairo_set_source_color (cr, color);
clutter_cairo_set_source_color (cr, &bg_color);
cairo_stroke (cr);
x += 4;
@ -63,9 +63,10 @@ update_background (ClutterActor *tex,
cairo_fill (cr);
cairo_pattern_destroy (pat);
cairo_destroy (cr);
#undef BG_ROUND_RADIUS
return TRUE;
}
static gboolean
@ -147,8 +148,7 @@ on_box_allocation_changed (ClutterActor *box,
clutter_cairo_texture_set_surface_size (CLUTTER_CAIRO_TEXTURE (background),
new_width,
new_height);
update_background (background, &bg_color, new_width, new_height);
clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (background));
}
G_MODULE_EXPORT int
@ -183,6 +183,7 @@ test_bin_layout_main (int argc, char *argv[])
* box's size
*/
rect = clutter_cairo_texture_new (100, 100);
g_signal_connect (rect, "draw", G_CALLBACK (draw_background), NULL);
/* first method: use clutter_box_pack() */
clutter_box_pack (CLUTTER_BOX (box), rect,

View File

@ -2,6 +2,7 @@
* Pretty cairo flower hack.
*/
#undef CLUTTER_DISABLE_DEPRECATED
#include <clutter/clutter.h>
#ifndef _MSC_VER

View File

@ -50,6 +50,9 @@ static ClutterActor *easing_mode_label = NULL;
static ClutterAnimation *last_animation = NULL;
static ClutterColor stage_color = { 0x88, 0x88, 0xdd, 0xff };
static ClutterColor bouncer_color = { 0xee, 0x33, 0, 0xff };
static void
on_animation_completed (ClutterAnimation *animation,
ClutterActor *rectangle)
@ -126,23 +129,19 @@ on_button_press (ClutterActor *actor,
return TRUE;
}
static ClutterActor *
make_bouncer (const ClutterColor *base_color,
gfloat width,
gfloat height)
static gboolean
draw_bouncer (ClutterCairoTexture *texture,
cairo_t *cr)
{
ClutterActor *retval;
cairo_t *cr;
guint width, height;
float radius;
cairo_pattern_t *pattern;
gfloat radius = MAX (width, height);
retval = clutter_cairo_texture_new (width, height);
clutter_cairo_texture_get_surface_size (texture, &width, &height);
cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (retval));
radius = MAX (width, height);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
clutter_cairo_texture_clear (texture);
cairo_arc (cr, radius / 2, radius / 2, radius / 2, 0.0, 2.0 * G_PI);
@ -150,28 +149,41 @@ make_bouncer (const ClutterColor *base_color,
radius, radius, radius);
cairo_pattern_add_color_stop_rgba (pattern,
0,
base_color->red / 255.0,
base_color->green / 255.0,
base_color->blue / 255.0,
base_color->alpha / 255.0);
bouncer_color.red / 255.0,
bouncer_color.green / 255.0,
bouncer_color.blue / 255.0,
bouncer_color.alpha / 255.0);
cairo_pattern_add_color_stop_rgba (pattern,
0.9,
base_color->red / 255.0,
base_color->green / 255.0,
base_color->blue / 255.0,
bouncer_color.red / 255.0,
bouncer_color.green / 255.0,
bouncer_color.blue / 255.0,
0.1);
cairo_set_source (cr, pattern);
cairo_fill_preserve (cr);
cairo_pattern_destroy (pattern);
cairo_destroy (cr);
return TRUE;
}
static ClutterActor *
make_bouncer (gfloat width,
gfloat height)
{
ClutterActor *retval;
retval = clutter_cairo_texture_new (width, height);
g_signal_connect (retval, "draw", G_CALLBACK (draw_bouncer), NULL);
clutter_actor_set_name (retval, "bouncer");
clutter_actor_set_size (retval, width, height);
clutter_actor_set_anchor_point (retval, width / 2, height / 2);
clutter_actor_set_reactive (retval, TRUE);
clutter_cairo_texture_invalidate (CLUTTER_CAIRO_TEXTURE (retval));
return retval;
}
@ -198,8 +210,6 @@ G_MODULE_EXPORT int
test_easing_main (int argc, char *argv[])
{
ClutterActor *stage, *rect, *label;
ClutterColor stage_color = { 0x88, 0x88, 0xdd, 0xff };
ClutterColor rect_color = { 0xee, 0x33, 0, 0xff };
gchar *text;
gfloat stage_width, stage_height;
gfloat label_width, label_height;
@ -212,13 +222,15 @@ test_easing_main (int argc, char *argv[])
&error) != CLUTTER_INIT_SUCCESS)
return 1;
stage = clutter_stage_get_default ();
stage = clutter_stage_new ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "Easing Modes");
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
main_stage = stage;
clutter_actor_get_size (stage, &stage_width, &stage_height);
rect = make_bouncer (&rect_color, 50, 50);
rect = make_bouncer (50, 50);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
clutter_actor_set_position (rect, stage_width / 2, stage_height / 2);