1 #include <clutter/clutter.h>
2 
3 #include <stdlib.h>
4 #include <string.h>
5 
6 #include "tests/clutter-test-utils.h"
7 
8 #define STAGE_WIDTH  640
9 #define STAGE_HEIGHT 480
10 
11 #define COLS 18
12 #define ROWS 20
13 
14 static void
on_after_paint(ClutterActor * actor,ClutterPaintContext * paint_context,gconstpointer * data)15 on_after_paint (ClutterActor        *actor,
16                 ClutterPaintContext *paint_context,
17                 gconstpointer       *data)
18 {
19   static GTimer *timer = NULL;
20   static int fps = 0;
21 
22   if (!timer)
23     {
24       timer = g_timer_new ();
25       g_timer_start (timer);
26     }
27 
28   if (g_timer_elapsed (timer, NULL) >= 1)
29     {
30       printf ("fps: %d\n", fps);
31       g_timer_start (timer);
32       fps = 0;
33     }
34 
35   ++fps;
36 }
37 
38 static gboolean
queue_redraw(gpointer stage)39 queue_redraw (gpointer stage)
40 {
41   clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
42 
43   return G_SOURCE_CONTINUE;
44 }
45 
46 int
main(int argc,char * argv[])47 main (int argc, char *argv[])
48 {
49   ClutterActor    *stage;
50   ClutterActor    *group;
51 
52   g_setenv ("CLUTTER_VBLANK", "none", FALSE);
53   g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE);
54 
55   clutter_test_init (&argc, &argv);
56 
57   stage = clutter_test_get_stage ();
58   clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
59   clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_Black);
60   clutter_stage_set_title (CLUTTER_STAGE (stage), "Text");
61 
62   group = clutter_actor_new ();
63   clutter_actor_set_size (group, STAGE_WIDTH, STAGE_WIDTH);
64   clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
65 
66   clutter_threads_add_idle (queue_redraw, stage);
67 
68   g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL);
69 
70   {
71     gint row, col;
72 
73     for (row=0; row<ROWS; row++)
74       for (col=0; col<COLS; col++)
75         {
76           ClutterActor *label;
77           gchar font_name[64];
78           gchar text[64];
79           gint  font_size = row+10;
80           gdouble scale = 0.17 + (1.5 * col / COLS);
81 
82           sprintf (font_name, "Sans %ipx", font_size);
83           sprintf (text, "OH");
84 
85           if (row==0)
86             {
87               sprintf (font_name, "Sans 10px");
88               sprintf (text, "%1.2f", scale);
89               font_size = 10;
90               scale = 1.0;
91             }
92           if (col==0)
93             {
94               sprintf (font_name, "Sans 10px");
95               sprintf (text, "%ipx", font_size);
96               if (row == 0)
97                 strcpy (text, "");
98               font_size = 10;
99               scale = 1.0;
100             }
101 
102           label = clutter_text_new_with_text (font_name, text);
103           clutter_text_set_color (CLUTTER_TEXT (label), CLUTTER_COLOR_White);
104           clutter_actor_set_position (label, (1.0*STAGE_WIDTH/COLS)*col,
105                                              (1.0*STAGE_HEIGHT/ROWS)*row);
106           /*clutter_actor_set_clip (label, 0,0, (1.0*STAGE_WIDTH/COLS),
107                                               (1.0*STAGE_HEIGHT/ROWS));*/
108           clutter_actor_set_scale (label, scale, scale);
109           clutter_text_set_line_wrap (CLUTTER_TEXT (label), FALSE);
110           clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
111         }
112   }
113   clutter_actor_show (stage);
114 
115   g_signal_connect (stage, "key-press-event",
116 		    G_CALLBACK (clutter_test_quit), NULL);
117 
118   clutter_test_main ();
119 
120   clutter_actor_destroy (stage);
121 
122   return 0;
123 }
124