cookbook: Add an empty recipe for shadows under text
authorEmmanuele Bassi <ebassi@linux.intel.com>
Sun, 18 Jul 2010 09:56:35 +0000 (10:56 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Sun, 18 Jul 2010 09:56:35 +0000 (10:56 +0100)
Currently, it's just an example and an image, but it should be easy to
flesh it out properly for the "Text" chapter.

doc/cookbook/Makefile.am
doc/cookbook/clutter-cookbook.xml.in
doc/cookbook/examples/.gitignore
doc/cookbook/examples/Makefile.am
doc/cookbook/examples/text-shadow.c [new file with mode: 0644]
doc/cookbook/images/text-shadow.png [new file with mode: 0644]
doc/cookbook/text.xml [new file with mode: 0644]

index 3752f5d..d13cbf1 100644 (file)
@@ -34,6 +34,7 @@ IMAGE_FILES = \
        images/textures-reflection.png \
        images/actors-opacity.png \
        images/actors-opacity-container-affects-opacity.png \
+       images/text-shadow.png \
        $(NULL)
 VIDEO_FILES = \
        videos/animations-fading-out.ogv \
index fce2d3a..646d942 100644 (file)
@@ -43,6 +43,7 @@
   <xi:include href="events.xml" />
   <xi:include href="textures.xml" />
   <xi:include href="animations.xml" />
+  <xi:include href="text.xml" />
 
   <appendix id="contributing">
     <title>Contributing to this document</title>
index 16cad26..5353a9d 100644 (file)
@@ -4,6 +4,7 @@ NULL =
 
 noinst_PROGRAMS = \
        textures-reflection     \
+       text-shadow             \
        $(NULL)
 
 INCLUDES = \
@@ -26,3 +27,5 @@ AM_CFLAGS = \
 AM_LDFLAGS = $(CLUTTER_LIBS)
 
 textures_reflection_SOURCES    = textures-reflection.c
+
+text_shadow_SOURCES            = text-shadow.c
diff --git a/doc/cookbook/examples/text-shadow.c b/doc/cookbook/examples/text-shadow.c
new file mode 100644 (file)
index 0000000..4afe62c
--- /dev/null
@@ -0,0 +1,59 @@
+#include <stdlib.h>
+#include <cogl/cogl.h>
+#include <cogl-pango.h>
+#include <clutter/clutter.h>
+
+#define SHADOW_X_OFFSET         3
+#define SHADOW_Y_OFFSET         3
+
+static void
+_text_paint_cb (ClutterActor *actor)
+{
+  ClutterText *text = CLUTTER_TEXT (actor);
+
+  ClutterActorBox alloc = { 0, };
+  clutter_actor_get_allocation_box (actor, &alloc);
+
+  PangoLayout *layout;
+  layout = clutter_text_get_layout (text);
+
+  ClutterColor text_color = { 0, };
+  clutter_text_get_color (text, &text_color);
+
+  guint8 real_opacity;
+  real_opacity = clutter_actor_get_paint_opacity (actor)
+               * text_color.alpha
+               / 255;
+
+  CoglColor color;
+  cogl_color_set_from_4ub (&color, 0xcc, 0xcc, 0xcc, real_opacity);
+  cogl_pango_render_layout (layout, SHADOW_X_OFFSET, SHADOW_Y_OFFSET, &color, 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+  clutter_init (&argc, &argv);
+
+  ClutterActor *stage;
+
+  stage = clutter_stage_new ();
+  clutter_stage_set_title (CLUTTER_STAGE (stage), "Text shadow");
+  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
+
+  ClutterActor *text;
+  text = clutter_text_new ();
+  clutter_text_set_text (CLUTTER_TEXT (text), "Hello, World!");
+  clutter_text_set_font_name (CLUTTER_TEXT (text), "Sans 64px");
+  clutter_actor_add_constraint (text, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5));
+  clutter_actor_add_constraint (text, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5));
+  g_signal_connect (text, "paint", G_CALLBACK (_text_paint_cb), NULL);
+
+  clutter_container_add (CLUTTER_CONTAINER (stage), text, NULL);
+
+  clutter_actor_show (stage);
+
+  clutter_main ();
+
+  return EXIT_SUCCESS;
+}
diff --git a/doc/cookbook/images/text-shadow.png b/doc/cookbook/images/text-shadow.png
new file mode 100644 (file)
index 0000000..61824ef
Binary files /dev/null and b/doc/cookbook/images/text-shadow.png differ
diff --git a/doc/cookbook/text.xml b/doc/cookbook/text.xml
new file mode 100644 (file)
index 0000000..6ec3a5c
--- /dev/null
@@ -0,0 +1,40 @@
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<chapter id="text">
+  <title>Text</title>
+
+  <epigraph>
+    <attribution>Antoine de Saint-Exupery</attribution>
+    <para>A rock pile ceases to be a rock pile the moment a single man
+    contemplates it, bearing within him the image of a cathedral.</para>
+  </epigraph>
+
+  <section id="text-introduction">
+    <title>Introduction</title>
+
+  </section>
+
+  <section id="text-shadow">
+    <title>Drawing a shadow under the text</title>
+
+    <section>
+      <title>Problem</title>
+
+      <para>You want to draw a shadow under the text displayed by a
+      ClutterText actor.</para>
+    </section>
+
+    <section>
+      <title>Solution</title>
+
+    </section>
+
+    <section>
+      <title>Discussion</title>
+
+    </section>
+
+  </section>
+
+</chapter>