2010-05-19 07:27:09 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2011-05-25 10:38:56 -04:00
|
|
|
#define RECT_SIZE 128
|
|
|
|
|
2010-05-19 07:27:09 -04:00
|
|
|
#define H_PADDING 32
|
2010-05-19 13:17:49 -04:00
|
|
|
#define V_PADDING 32
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
NorthWest, North, NorthEast,
|
|
|
|
West, Center, East,
|
|
|
|
SouthWest, South, SouthEast,
|
|
|
|
|
|
|
|
N_RECTS
|
|
|
|
};
|
|
|
|
|
|
|
|
static ClutterActor *rects[N_RECTS] = { NULL, };
|
|
|
|
static const gchar *colors[N_RECTS] = {
|
|
|
|
"#8ae234", "#73d216", "#4e9a06",
|
|
|
|
"#729fcf", "#3465a4", "#204a87",
|
|
|
|
"#ef2929", "#cc0000", "#a40000"
|
|
|
|
};
|
2011-09-02 10:36:40 -04:00
|
|
|
static const gchar *names[N_RECTS] = {
|
|
|
|
"North West", "North", "North East",
|
|
|
|
"West", "Center", "East",
|
|
|
|
"South West", "South", "South East"
|
|
|
|
};
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2011-05-25 10:38:56 -04:00
|
|
|
static const gchar *desaturare_glsl_shader =
|
|
|
|
"uniform sampler2D tex;\n"
|
|
|
|
"uniform float factor;\n"
|
|
|
|
"\n"
|
|
|
|
"vec3 desaturate (const vec3 color, const float desaturation)\n"
|
|
|
|
"{\n"
|
|
|
|
" const vec3 gray_conv = vec3 (0.299, 0.587, 0.114);\n"
|
|
|
|
" vec3 gray = vec3 (dot (gray_conv, color));\n"
|
|
|
|
" return vec3 (mix (color.rgb, gray, desaturation));\n"
|
|
|
|
"}\n"
|
|
|
|
"\n"
|
|
|
|
"void main ()\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n"
|
|
|
|
" color.rgb = desaturate (color.rgb, factor);\n"
|
|
|
|
" cogl_color_out = color;\n"
|
|
|
|
"}\n";
|
|
|
|
|
2010-05-19 07:27:09 -04:00
|
|
|
static gboolean is_expanded = FALSE;
|
|
|
|
|
2019-01-20 03:03:50 -05:00
|
|
|
const char *
|
|
|
|
test_bind_constraint_describe (void);
|
|
|
|
|
|
|
|
int
|
|
|
|
test_bind_constraint_main (int argc, char *argv[]);
|
|
|
|
|
2010-05-19 07:27:09 -04:00
|
|
|
static gboolean
|
|
|
|
on_button_release (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer data G_GNUC_UNUSED)
|
|
|
|
{
|
|
|
|
if (!is_expanded)
|
|
|
|
{
|
2010-05-19 13:17:49 -04:00
|
|
|
gfloat north_offset, south_offset;
|
|
|
|
gfloat west_offset, east_offset;
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
/* expand the 8 rectangles by animating the offset of the
|
|
|
|
* bind constraints
|
|
|
|
*/
|
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
north_offset = (clutter_actor_get_height (rects[Center]) + V_PADDING)
|
|
|
|
* -1.0f;
|
|
|
|
south_offset = (clutter_actor_get_height (rects[Center]) + V_PADDING);
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
west_offset = (clutter_actor_get_width (rects[Center]) + H_PADDING)
|
|
|
|
* -1.0f;
|
|
|
|
east_offset = (clutter_actor_get_width (rects[Center]) + H_PADDING);
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[NorthWest], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 07:27:09 -04:00
|
|
|
"opacity", 255,
|
2010-05-19 13:17:49 -04:00
|
|
|
"@constraints.x-bind.offset", west_offset,
|
|
|
|
"@constraints.y-bind.offset", north_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 07:27:09 -04:00
|
|
|
NULL);
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[North], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 07:27:09 -04:00
|
|
|
"opacity", 255,
|
2010-05-19 13:17:49 -04:00
|
|
|
"@constraints.y-bind.offset", north_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[NorthEast], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 13:17:49 -04:00
|
|
|
"opacity", 255,
|
|
|
|
"@constraints.x-bind.offset", east_offset,
|
|
|
|
"@constraints.y-bind.offset", north_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[West], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 13:17:49 -04:00
|
|
|
"opacity", 255,
|
|
|
|
"@constraints.x-bind.offset", west_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
2011-09-02 10:36:40 -04:00
|
|
|
/* turn on the desaturation effect and set the center
|
|
|
|
* rectangle not reactive
|
|
|
|
*/
|
2010-05-19 13:17:49 -04:00
|
|
|
clutter_actor_animate (rects[Center], CLUTTER_LINEAR, 500,
|
2011-05-25 10:38:56 -04:00
|
|
|
"@effects.desaturate.enabled", TRUE,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", FALSE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[East], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 13:17:49 -04:00
|
|
|
"opacity", 255,
|
|
|
|
"@constraints.x-bind.offset", east_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[SouthWest], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 13:17:49 -04:00
|
|
|
"opacity", 255,
|
|
|
|
"@constraints.x-bind.offset", west_offset,
|
|
|
|
"@constraints.y-bind.offset", south_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[South], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 13:17:49 -04:00
|
|
|
"opacity", 255,
|
|
|
|
"@constraints.y-bind.offset", south_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_animate (rects[SouthEast], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 13:17:49 -04:00
|
|
|
"opacity", 255,
|
|
|
|
"@constraints.x-bind.offset", east_offset,
|
|
|
|
"@constraints.y-bind.offset", south_offset,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 07:27:09 -04:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-19 13:17:49 -04:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
clutter_actor_animate (rects[Center], CLUTTER_LINEAR, 500,
|
2011-05-25 10:38:56 -04:00
|
|
|
"@effects.desaturate.enabled", FALSE,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", TRUE,
|
2010-05-19 09:34:18 -04:00
|
|
|
NULL);
|
2010-05-19 13:17:49 -04:00
|
|
|
|
|
|
|
for (i = NorthWest; i < N_RECTS; i++)
|
|
|
|
{
|
|
|
|
if (i == Center)
|
|
|
|
continue;
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
/* put the 8 rectangles back into their initial state */
|
|
|
|
clutter_actor_animate (rects[i], CLUTTER_EASE_OUT_EXPO, 500,
|
2010-05-19 13:17:49 -04:00
|
|
|
"opacity", 0,
|
|
|
|
"@constraints.x-bind.offset", 0.0f,
|
|
|
|
"@constraints.y-bind.offset", 0.0f,
|
2011-09-02 10:36:40 -04:00
|
|
|
"reactive", FALSE,
|
2010-05-19 13:17:49 -04:00
|
|
|
NULL);
|
|
|
|
}
|
2010-05-19 07:27:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
is_expanded = !is_expanded;
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
g_print ("Selected: [%s]\n", clutter_actor_get_name (actor));
|
|
|
|
|
2010-05-19 07:27:09 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-05-08 05:51:14 -04:00
|
|
|
G_MODULE_EXPORT const char *
|
|
|
|
test_bind_constraint_describe (void)
|
|
|
|
{
|
|
|
|
return "Demonstrate the usage of ClutterBindConstraint";
|
|
|
|
}
|
|
|
|
|
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_bind_constraint_main (int argc, char *argv[])
|
2010-05-19 07:27:09 -04:00
|
|
|
{
|
|
|
|
ClutterActor *stage, *rect;
|
|
|
|
ClutterConstraint *constraint;
|
2011-05-25 10:38:56 -04:00
|
|
|
ClutterEffect *effect;
|
2010-05-19 13:17:49 -04:00
|
|
|
ClutterColor rect_color;
|
|
|
|
gint i;
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2011-02-21 19:19:35 -05:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2010-05-19 07:27:09 -04:00
|
|
|
|
|
|
|
stage = clutter_stage_new ();
|
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Constraints");
|
|
|
|
clutter_actor_set_size (stage, 800, 600);
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
/* main rectangle */
|
2010-05-19 13:17:49 -04:00
|
|
|
clutter_color_from_string (&rect_color, "#3465a4");
|
2012-01-17 11:54:30 -05:00
|
|
|
rect = clutter_actor_new ();
|
2010-05-19 07:27:09 -04:00
|
|
|
g_signal_connect (rect, "button-release-event",
|
|
|
|
G_CALLBACK (on_button_release),
|
|
|
|
NULL);
|
2012-01-17 11:54:30 -05:00
|
|
|
clutter_actor_set_background_color (rect, &rect_color);
|
2011-05-25 10:38:56 -04:00
|
|
|
clutter_actor_set_size (rect, RECT_SIZE, RECT_SIZE);
|
2010-05-19 07:27:09 -04:00
|
|
|
clutter_actor_set_reactive (rect, TRUE);
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_set_name (rect, names[Center]);
|
2012-01-17 11:54:30 -05:00
|
|
|
clutter_actor_add_child (stage, rect);
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
/* align the center rectangle to the center of the stage */
|
2011-10-15 13:35:45 -04:00
|
|
|
constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5);
|
|
|
|
clutter_actor_add_constraint_with_name (rect, "align", constraint);
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2011-05-25 10:38:56 -04:00
|
|
|
/* this is the equivalent of the DesaturateEffect; we cannot animate
|
|
|
|
* the factor because the animation API only understands GObject
|
|
|
|
* properties; so we use the ActorMeta:enabled property to toggle
|
|
|
|
* the shader
|
|
|
|
*/
|
|
|
|
effect = clutter_shader_effect_new (CLUTTER_FRAGMENT_SHADER);
|
|
|
|
clutter_shader_effect_set_shader_source (CLUTTER_SHADER_EFFECT (effect),
|
|
|
|
desaturare_glsl_shader);
|
|
|
|
clutter_shader_effect_set_uniform (CLUTTER_SHADER_EFFECT (effect),
|
|
|
|
"tex", G_TYPE_INT, 1, 0);
|
|
|
|
clutter_shader_effect_set_uniform (CLUTTER_SHADER_EFFECT (effect),
|
2011-09-02 10:36:40 -04:00
|
|
|
"factor", G_TYPE_FLOAT, 1, 0.66);
|
2011-05-25 10:38:56 -04:00
|
|
|
clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE);
|
|
|
|
clutter_actor_add_effect_with_name (rect, "desaturate", effect);
|
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
rects[Center] = rect;
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
/* build the other rectangles, and bind their position and size
|
|
|
|
* to the center rectangle. we are going to animate the offset
|
|
|
|
* of the BindConstraints
|
|
|
|
*/
|
2010-05-19 13:17:49 -04:00
|
|
|
for (i = 0; i < N_RECTS; i++)
|
|
|
|
{
|
|
|
|
if (i == Center)
|
|
|
|
continue;
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
clutter_color_from_string (&rect_color, colors[i]);
|
2012-01-17 11:54:30 -05:00
|
|
|
|
|
|
|
rect = clutter_actor_new ();
|
|
|
|
clutter_actor_set_background_color (rect, &rect_color);
|
2010-05-19 13:17:49 -04:00
|
|
|
clutter_actor_set_opacity (rect, 0);
|
2011-09-02 10:36:40 -04:00
|
|
|
clutter_actor_set_name (rect, names[i]);
|
2012-01-17 11:54:30 -05:00
|
|
|
clutter_actor_add_child (stage, rect);
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_X, 0.0);
|
2010-05-20 06:19:51 -04:00
|
|
|
clutter_actor_add_constraint_with_name (rect, "x-bind", constraint);
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_Y, 0.0);
|
2010-05-20 06:19:51 -04:00
|
|
|
clutter_actor_add_constraint_with_name (rect, "y-bind", constraint);
|
2010-05-19 07:27:09 -04:00
|
|
|
|
2011-01-25 06:10:29 -05:00
|
|
|
constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_SIZE, 0.0);
|
|
|
|
clutter_actor_add_constraint_with_name (rect, "size-bind", constraint);
|
|
|
|
|
2011-09-02 10:36:40 -04:00
|
|
|
g_signal_connect (rect, "button-release-event",
|
|
|
|
G_CALLBACK (on_button_release),
|
|
|
|
NULL);
|
|
|
|
|
2010-05-19 13:17:49 -04:00
|
|
|
rects[i] = rect;
|
|
|
|
}
|
2010-05-19 07:27:09 -04:00
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|