From 8668a019a0bde8a078f999cd5b960a1f63f700ec Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 5 Aug 2010 11:41:25 +0100 Subject: [PATCH] cookbook: Fix the text-shadow recipe Fill out the recipe and add more comments to the example code. --- doc/cookbook/examples/text-shadow.c | 10 ++-- doc/cookbook/text.xml | 71 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/doc/cookbook/examples/text-shadow.c b/doc/cookbook/examples/text-shadow.c index 4afe62c4a..ced68b7b3 100644 --- a/doc/cookbook/examples/text-shadow.c +++ b/doc/cookbook/examples/text-shadow.c @@ -11,22 +11,26 @@ _text_paint_cb (ClutterActor *actor) { ClutterText *text = CLUTTER_TEXT (actor); - ClutterActorBox alloc = { 0, }; - clutter_actor_get_allocation_box (actor, &alloc); - + /* Get the PangoLayout that the Text actor is going to paint */ PangoLayout *layout; layout = clutter_text_get_layout (text); + /* Get the color of the text, to extract the alpha component */ ClutterColor text_color = { 0, }; clutter_text_get_color (text, &text_color); + /* Composite the opacity so that the shadow is correctly blended */ guint8 real_opacity; real_opacity = clutter_actor_get_paint_opacity (actor) * text_color.alpha / 255; + /* Create a #ccc color and premultiply it */ CoglColor color; cogl_color_set_from_4ub (&color, 0xcc, 0xcc, 0xcc, real_opacity); + cogl_color_premultiply (&color); + + /* Finally, render the Text layout at a given offset using the color */ cogl_pango_render_layout (layout, SHADOW_X_OFFSET, SHADOW_Y_OFFSET, &color, 0); } diff --git a/doc/cookbook/text.xml b/doc/cookbook/text.xml index a278bb980..01ba040c1 100644 --- a/doc/cookbook/text.xml +++ b/doc/cookbook/text.xml @@ -29,6 +29,11 @@
Solution + Override the paint signal of + ClutterText and use the CoglPango API to paint the + PangoLayout of the actor with the color of the + shadow at a given offset. + @@ -46,6 +51,72 @@
Discussion + The ClutterText class provides an actor that + transforms the PangoLayout object into an element of + the Clutter scene graph. The underlying layout is painted, though, + through a subset of the Cogl API, called + CoglPango. + + It is possible to paint PangoLayout created by a + ClutterText by invoking + cogl_pango_render_layout(): + + + + + + This function will paint the layout at the given offsets using the + provided color. + + The cogl_pango_render_layout() + function will only work with PangoLayouts created by + Clutter. + + Since the shadow of the text is literally the same text but painted + with a different color and at an offset, we can use the + paint signal of ClutterText to paint + the shadow, and then let ClutterText paint its contents on + top: + + + + + + Note that we are using the PangoLayout of the + ClutterText because the ClutterText actor + always keeps an updated layout internally. It is, however, possible for + any ClutterActor to create a PangoLayout using + clutter_actor_create_pango_layout(), and then paint + that layout using cogl_pango_render_layout() in + their implementation of the paint virtual + function. +