Convert README to README.rst for Github co-hosting
[sparrow.git] / clutter-app.c
blob0f5747f4c240e4aa4e420f691cead59928f0273f
1 /*
2 * Based on an example from the clutter-gst package:
4 * video-sink.c - A small example around the videotestsrc ! warptv !
5 * ffmpegcolorspace ! cluttersink pipeline.
7 * Copyright (C) 2007,2008 OpenedHand
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include <clutter-gst/clutter-gst.h>
26 #include "app.h"
28 void
29 size_change (ClutterTexture *texture,
30 gfloat width,
31 gfloat height,
32 gpointer user_data)
34 ClutterActor *stage;
35 gfloat new_x, new_y, new_width, new_height;
36 gfloat stage_width, stage_height;
38 stage = clutter_actor_get_stage (CLUTTER_ACTOR (texture));
39 if (stage == NULL)
40 return;
42 clutter_actor_get_size (stage, &stage_width, &stage_height);
44 new_height = (height * stage_width) / width;
45 if (new_height <= stage_height)
47 new_width = stage_width;
49 new_x = 0;
50 new_y = (stage_height - new_height) / 2;
52 else
54 new_width = (width * stage_height) / height;
55 new_height = stage_height;
57 new_x = (stage_width - new_width) / 2;
58 new_y = 0;
61 clutter_actor_set_position (CLUTTER_ACTOR (texture), new_x, new_y);
62 clutter_actor_set_size (CLUTTER_ACTOR (texture), new_width, new_height);
65 void
66 set_initial_size (ClutterTexture *texture)
68 ClutterActor *stage;
69 gfloat new_x, new_y;
70 gfloat stage_width, stage_height;
71 stage = clutter_actor_get_stage (CLUTTER_ACTOR (texture));
72 clutter_actor_get_size (stage, &stage_width, &stage_height);
73 new_x = (stage_width - WIDTH) / 2;
74 new_y = (stage_height - HEIGHT) / 2;
75 clutter_actor_set_position (CLUTTER_ACTOR(texture), new_x, new_y);
76 clutter_actor_set_size (CLUTTER_ACTOR(texture), WIDTH, HEIGHT);
80 int
81 main (int argc, char *argv[])
83 ClutterTimeline *timeline;
84 ClutterActor *stage;
85 ClutterActor *texture;
86 ClutterColor black = {0, 0, 0, 255};
88 clutter_init (&argc, &argv);
89 gst_init (&argc, &argv);
91 stage = clutter_stage_get_default();
92 clutter_stage_set_color(CLUTTER_STAGE(stage), &black);
93 clutter_stage_set_fullscreen(CLUTTER_STAGE(stage), TRUE);
94 clutter_stage_hide_cursor(CLUTTER_STAGE(stage));
96 /* Make a timeline */
97 timeline = clutter_timeline_new (1000);
98 g_object_set(timeline, "loop", TRUE, NULL);
100 /* We need to set certain props on the target texture currently for
101 * efficient/corrent playback onto the texture (which sucks a bit)
103 texture = g_object_new (CLUTTER_TYPE_TEXTURE,
104 "sync-size", FALSE,
105 "disable-slicing", TRUE,
106 NULL);
109 g_signal_connect (CLUTTER_TEXTURE (texture),
110 "size-change",
111 G_CALLBACK (size_change), NULL);
115 GstElement *sink = clutter_gst_video_sink_new(CLUTTER_TEXTURE(texture));
117 GstPipeline *pipeline = make_pipeline(sink);
119 gst_element_set_state (GST_ELEMENT(pipeline), GST_STATE_PLAYING);
121 /* start the timeline */
122 clutter_timeline_start (timeline);
124 clutter_group_add (CLUTTER_GROUP (stage), texture);
125 // clutter_actor_set_opacity (texture, 0x11);
126 clutter_actor_show_all (stage);
128 set_initial_size(CLUTTER_TEXTURE(texture));
129 clutter_main();
131 return 0;