~elementary-os/elementaryos/os-patch-mutter-bionic

« back to all changes in this revision

Viewing changes to clutter/tests/micro-bench/test-text.c

  • Committer: RabbitBot
  • Date: 2018-04-11 14:49:36 UTC
  • Revision ID: rabbitbot@elementary.io-20180411144936-hgymqa9d8d1xfpbh
Initial import, version 3.28.0-2

Show diffs side-by-side

added added

removed removed

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