[go: up one dir, main page]

File: test-unproject.c

package info (click to toggle)
clutter 0.8.0-1.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 11,808 kB
  • ctags: 10,141
  • sloc: ansic: 60,915; xml: 27,567; sh: 9,271; makefile: 848
file content (147 lines) | stat: -rw-r--r-- 3,599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <clutter/clutter.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

ClutterActor *label;

#define RECT_L 200
#define RECT_T 150
#define RECT_W 320
#define RECT_H 240

void
on_event (ClutterStage *stage,
	  ClutterEvent *event,
	  gpointer      user_data)
{
  switch (event->type)
    {
    case CLUTTER_BUTTON_PRESS:
      {
	gint x, y;
	ClutterActor * actor;
	ClutterUnit xu2, yu2;

        clutter_event_get_coords (event, &x, &y);

	actor = clutter_stage_get_actor_at_pos (stage, x, y);


	if (clutter_actor_transform_stage_point (actor,
						CLUTTER_UNITS_FROM_DEVICE (x),
						CLUTTER_UNITS_FROM_DEVICE (y),
						&xu2, &yu2))
	  {
	    gchar *txt;

	    if (actor != CLUTTER_ACTOR (stage))
	      txt = g_strdup_printf ("Click on rectangle\n"
				     "Screen coords: [%d, %d]\n"
				     "Local coords : [%d, %d]",
				     x, y,
				     CLUTTER_UNITS_TO_DEVICE (xu2),
				     CLUTTER_UNITS_TO_DEVICE (yu2));
	    else
	      txt = g_strdup_printf ("Click on stage\n"
				     "Screen coords: [%d, %d]\n"
				     "Local coords : [%d, %d]",
				     x, y,
				     CLUTTER_UNITS_TO_DEVICE (xu2),
				     CLUTTER_UNITS_TO_DEVICE (yu2));

	    clutter_label_set_text (CLUTTER_LABEL (label), txt);
	    g_free (txt);
	  }
	else
	  clutter_label_set_text (CLUTTER_LABEL (label),
				  "Unprojection failed.");
      }
      break;

    default:
      break;
    }
}


int
main (int argc, char *argv[])
{
  gchar *txt;
  ClutterActor *rect, *stage, *label0;
  int i, rotate_x = 0, rotate_y = 60, rotate_z = 0;
  ClutterColor stage_clr = { 0x0, 0x0, 0x0, 0xff },
               white     = { 0xff, 0xff, 0xff, 0xff },
               blue      = { 0, 0xff, 0xff, 0xff };

  for (i = 0; i < argc; ++i)
    {
      if (!strncmp (argv[i], "--rotate-x", 10))
	{
	  rotate_x = atoi (argv[i] + 11);
	}
      else if (!strncmp (argv[i], "--rotate-y", 10))
	{
	  rotate_y = atoi (argv[i] + 11);
	}
      else if (!strncmp (argv[i], "--rotate-z", 10))
	{
	  rotate_z = atoi (argv[i] + 11);
	}
      else if (!strncmp (argv[i], "--help", 6))
	{
	  printf ("%s [--rotage-x=degrees] [--rotage-y=degrees] "
		  "[--rotage-z=degrees]\n",
		  argv[0]);

	  exit (0);
	}
    }

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();

  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_clr);
  clutter_actor_set_size (stage, 640, 480);

  rect = clutter_rectangle_new_with_color (&white);
  clutter_actor_set_size (rect, RECT_W, RECT_H);
  clutter_actor_set_position (rect, RECT_L, RECT_T);
  clutter_actor_set_rotation (rect, CLUTTER_X_AXIS, rotate_x, 0, 0, 0);
  clutter_actor_set_rotation (rect, CLUTTER_Y_AXIS, rotate_y, 0, 0, 0);
  clutter_actor_set_rotation (rect, CLUTTER_Z_AXIS, rotate_z, 0, 0, 0);
  clutter_group_add (CLUTTER_GROUP (stage), rect);

  txt = g_strdup_printf ("Rectangle: L %d, R %d, T %d, B %d\n"
			 "Rotation : x %d, y %d, z %d",
			 RECT_L, RECT_L + RECT_W,
			 RECT_T, RECT_T + RECT_H,
			 rotate_x, rotate_y, rotate_z);

  label0 = clutter_label_new_with_text ("Mono 8pt", txt);
  clutter_label_set_color (CLUTTER_LABEL (label0), &white);

  clutter_actor_set_position (label0, 10, 10);
  clutter_group_add (CLUTTER_GROUP (stage), label0);

  g_free (txt);

  label =
    clutter_label_new_with_text ("Mono 8pt", "Click around!");

  clutter_label_set_color (CLUTTER_LABEL (label), &blue);

  clutter_actor_set_position (label, 10, 50);
  clutter_group_add (CLUTTER_GROUP (stage), label);

  clutter_actor_show_all (stage);

  g_signal_connect (stage, "event", G_CALLBACK (on_event), NULL);

  clutter_main();

  return EXIT_SUCCESS;
}