cookbook: Make example code C90 compliant

Modified all cookbook example code to prevent ISO C90 compliance
warnings occurring during compilation.
This commit is contained in:
Elliot Smith 2010-11-12 09:32:04 +00:00
parent 03a713e18e
commit f9d2310b72
16 changed files with 113 additions and 89 deletions

View File

@ -65,16 +65,15 @@ int
main (int argc,
char *argv[])
{
/* seed random number generator */
srand ((unsigned int) time (NULL));
State *state = g_new0 (State, 1);
ClutterActor *red;
ClutterActor *green;
ClutterActor *blue;
State *state = g_new0 (State, 1);
clutter_init (&argc, &argv);
/* seed random number generator */
srand ((unsigned int) time (NULL));
clutter_init (&argc, &argv);
state->animator = clutter_animator_new ();
clutter_animator_set_duration (state->animator, 500);

View File

@ -17,10 +17,12 @@ button_pressed_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
AnimationSpec *animation_spec;
if (clutter_actor_get_animation (actor) != NULL)
return TRUE;
AnimationSpec *animation_spec = (AnimationSpec *) user_data;
animation_spec = (AnimationSpec *) user_data;
clutter_actor_animate (actor, CLUTTER_LINEAR, 500,
animation_spec->axis, animation_spec->target,

View File

@ -115,13 +115,13 @@ int
main (int argc,
char *argv[])
{
/* seed random number generator */
srand ((unsigned int) time (NULL));
Lasso *lasso = g_new0 (Lasso, 1);
ClutterActor *stage;
/* seed random number generator */
srand ((unsigned int) time (NULL));
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();

View File

@ -13,14 +13,15 @@ _scroll_event_cb (ClutterActor *viewport,
gfloat viewport_height = clutter_actor_get_height (viewport);
gfloat scrollable_height = clutter_actor_get_height (scrollable);
gfloat y;
ClutterScrollDirection direction;
/* no need to scroll if the scrollable is shorter than the viewport */
if (scrollable_height < viewport_height)
return TRUE;
gfloat y = clutter_actor_get_y (scrollable);
y = clutter_actor_get_y (scrollable);
ClutterScrollDirection direction;
direction = clutter_event_get_scroll_direction (event);
switch (direction)
@ -63,6 +64,10 @@ _scroll_event_cb (ClutterActor *viewport,
int
main (int argc, char *argv[])
{
ClutterActor *stage;
ClutterActor *viewport;
ClutterActor *texture;
gchar *image_file_path = TESTS_DATA_DIR "/redhand.png";
if (argc > 1)
@ -70,10 +75,6 @@ main (int argc, char *argv[])
image_file_path = argv[1];
}
ClutterActor *stage;
ClutterActor *viewport;
ClutterActor *texture;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();

View File

@ -16,10 +16,10 @@ static void
_convert_clutter_path_node_to_cogl_path (const ClutterPathNode *node,
gpointer data)
{
g_return_if_fail (node != NULL);
ClutterKnot knot;
g_return_if_fail (node != NULL);
switch (node->type)
{
case CLUTTER_PATH_MOVE_TO:

View File

@ -22,8 +22,10 @@ _pointer_motion_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
/* get the coordinates where the pointer crossed into the actor */
gfloat stage_x, stage_y;
gfloat actor_x, actor_y;
/* get the coordinates where the pointer crossed into the actor */
clutter_event_get_coords (event, &stage_x, &stage_y);
/*
@ -31,7 +33,6 @@ _pointer_motion_cb (ClutterActor *actor,
* the actor which emitted the signal, it can be useful to
* transform them to actor-relative coordinates
*/
gfloat actor_x, actor_y;
clutter_actor_transform_stage_point (actor,
stage_x, stage_y,
&actor_x, &actor_y);

View File

@ -9,9 +9,10 @@ _pointer_motion_cb (ClutterActor *actor,
gpointer user_data)
{
gfloat stage_x, stage_y;
gfloat actor_x, actor_y;
clutter_event_get_coords (event, &stage_x, &stage_y);
gfloat actor_x, actor_y;
clutter_actor_transform_stage_point (actor,
stage_x, stage_y,
&actor_x, &actor_y);

View File

@ -11,6 +11,8 @@ main (int argc, char *argv[])
ClutterActor *box;
ClutterActor *rect1, *rect2;
guint align_x, align_y, diff_x, diff_y;
ClutterColor *color;
ClutterActor *rect;
clutter_init (&argc, &argv);
@ -54,11 +56,11 @@ main (int argc, char *argv[])
else if (align_y == 4)
diff_y = 2;
ClutterColor *color = clutter_color_new (255 - diff_x * 50,
color = clutter_color_new (255 - diff_x * 50,
100 + diff_y * 50,
0,
255);
ClutterActor *rect = clutter_rectangle_new_with_color (color);
rect = clutter_rectangle_new_with_color (color);
clutter_actor_set_size (rect, 100, 100);
clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout),
rect,

View File

@ -12,11 +12,6 @@ static const ClutterColor box_color = { 0x33, 0x33, 0x55, 0xff };
int
main (int argc, char *argv[])
{
gchar *filename = TESTS_DATA_DIR "/redhand.png";
if (argc > 1)
filename = argv[1];
ClutterLayoutManager *layout;
ClutterActor *box;
ClutterActor *stage;
@ -25,6 +20,11 @@ main (int argc, char *argv[])
GError *error = NULL;
gfloat width;
gchar *filename = TESTS_DATA_DIR "/redhand.png";
if (argc > 1)
filename = argv[1];
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();

View File

@ -22,6 +22,8 @@ foo_button_clicked_cb (ClutterClickAction *action,
ClutterActor *actor,
gpointer user_data)
{
gfloat z_angle;
/* get the UI definition passed to the handler */
ClutterScript *ui = CLUTTER_SCRIPT (user_data);
@ -36,7 +38,6 @@ foo_button_clicked_cb (ClutterClickAction *action,
return;
/* get the current rotation and increment it */
gfloat z_angle;
z_angle = clutter_actor_get_rotation (rectangle,
CLUTTER_Z_AXIS,
NULL, NULL, NULL);
@ -54,13 +55,16 @@ foo_button_clicked_cb (ClutterClickAction *action,
int
main (int argc, char *argv[])
{
clutter_init (&argc, &argv);
ClutterScript *ui = clutter_script_new ();
ClutterActor *stage;
ClutterScript *ui;
gchar *filename = "script-signals.json";
GError *error = NULL;
clutter_init (&argc, &argv);
ui = clutter_script_new ();
clutter_script_load_from_file (ui, filename, &error);
if (error != NULL)
@ -70,7 +74,6 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
ClutterActor *stage;
clutter_script_get_objects (ui,
"stage", &stage,
NULL);

View File

@ -4,13 +4,16 @@
int
main (int argc, char *argv[])
{
clutter_init (&argc, &argv);
ClutterScript *ui = clutter_script_new ();
ClutterActor *stage;
ClutterScript *ui;
gchar *filename = "script-ui.json";
GError *error = NULL;
clutter_init (&argc, &argv);
ui = clutter_script_new ();
/* load a JSON file into the script */
clutter_script_load_from_file (ui, filename, &error);
@ -22,8 +25,6 @@ main (int argc, char *argv[])
}
/* retrieve objects from the script */
ClutterActor *stage;
clutter_script_get_objects (ui,
"stage", &stage,
NULL);

View File

@ -9,24 +9,24 @@
static void
_text_paint_cb (ClutterActor *actor)
{
PangoLayout *layout;
guint8 real_opacity;
CoglColor color;
ClutterText *text = CLUTTER_TEXT (actor);
ClutterColor text_color = { 0, };
/* Get the PangoLayout that the Text actor is going to paint */
PangoLayout *layout;
layout = clutter_text_get_layout (text);
/* Get the color of the text, to extract the alpha component */
ClutterColor text_color = { 0, };
clutter_text_get_color (text, &text_color);
/* Composite the opacity so that the shadow is correctly blended */
guint8 real_opacity;
real_opacity = clutter_actor_get_paint_opacity (actor)
* text_color.alpha
/ 255;
/* Create a #ccc color and premultiply it */
CoglColor color;
cogl_color_init_from_4ub (&color, 0xcc, 0xcc, 0xcc, real_opacity);
cogl_color_premultiply (&color);
@ -37,15 +37,15 @@ _text_paint_cb (ClutterActor *actor)
int
main (int argc, char *argv[])
{
clutter_init (&argc, &argv);
ClutterActor *stage;
ClutterActor *text;
clutter_init (&argc, &argv);
stage = clutter_stage_new ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "Text shadow");
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
ClutterActor *text;
text = clutter_text_new ();
clutter_text_set_text (CLUTTER_TEXT (text), "Hello, World!");
clutter_text_set_font_name (CLUTTER_TEXT (text), "Sans 64px");

View File

@ -33,7 +33,12 @@ _update_progress_cb (ClutterTimeline *timeline,
guint elapsed_msecs,
ClutterTexture *texture)
{
CoglHandle copy;
gdouble progress;
CoglColor constant;
CoglHandle material = clutter_texture_get_cogl_material (texture);
if (material == COGL_INVALID_HANDLE)
return;
@ -41,15 +46,14 @@ _update_progress_cb (ClutterTimeline *timeline,
* its creation; if you need to modify it later you should use a copy
* instead. Cogl makes copying materials reasonably cheap
*/
CoglHandle copy = cogl_material_copy (material);
copy = cogl_material_copy (material);
gdouble progress = clutter_timeline_get_progress (timeline);
progress = clutter_timeline_get_progress (timeline);
/* Create the constant color to be used when combining the two
* material layers; we use a black color with an alpha component
* depending on the current progress of the timeline
*/
CoglColor constant;
cogl_color_init_from_4ub (&constant, 0x00, 0x00, 0x00, 0xff * progress);
/* This sets the value of the constant color we use when combining
@ -95,6 +99,13 @@ print_usage_and_exit (const char *exec_name,
int
main (int argc, char *argv[])
{
CoglHandle texture_1;
CoglHandle texture_2;
CoglHandle material;
ClutterActor *stage;
ClutterActor *texture;
ClutterTimeline *timeline;
clutter_init_with_args (&argc, &argv,
" - Crossfade", entries,
NULL,
@ -106,13 +117,13 @@ main (int argc, char *argv[])
/* Load the source and target images using Cogl, because we need
* to combine them into the same ClutterTexture.
*/
CoglHandle texture_1 = load_cogl_texture ("source", source);
CoglHandle texture_2 = load_cogl_texture ("target", target);
texture_1 = load_cogl_texture ("source", source);
texture_2 = load_cogl_texture ("target", target);
/* Create a new Cogl material holding the two textures inside two
* separate layers.
*/
CoglHandle material = cogl_material_new ();
material = cogl_material_new ();
cogl_material_set_layer (material, 1, texture_1);
cogl_material_set_layer (material, 0, texture_2);
@ -137,13 +148,13 @@ main (int argc, char *argv[])
* assign the material we created earlier to the Texture for painting
* it
*/
ClutterActor *stage = clutter_stage_get_default ();
stage = clutter_stage_get_default ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "cross-fade");
clutter_actor_set_size (stage, 400, 300);
clutter_actor_show (stage);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
ClutterActor *texture = clutter_texture_new ();
texture = clutter_texture_new ();
clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture);
clutter_texture_set_cogl_material (CLUTTER_TEXTURE (texture), material);
clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5));
@ -151,7 +162,7 @@ main (int argc, char *argv[])
cogl_handle_unref (material);
/* The timeline will drive the cross-fading */
ClutterTimeline *timeline = clutter_timeline_new (duration);
timeline = clutter_timeline_new (duration);
g_signal_connect (timeline, "new-frame", G_CALLBACK (_update_progress_cb), texture);
clutter_timeline_start (timeline);

View File

@ -26,6 +26,11 @@ typedef struct {
static gboolean
load_next_image (State *app)
{
gpointer next;
gchar *image_path;
CoglHandle *cogl_texture;
GError *error = NULL;
/* don't do anything if already animating */
ClutterTimeline *timeline = clutter_state_get_timeline (app->transitions);
@ -38,16 +43,15 @@ load_next_image (State *app)
if (!app->next_image_index)
app->next_image_index = 0;
gpointer next = g_slist_nth_data (app->image_paths, app->next_image_index);
next = g_slist_nth_data (app->image_paths, app->next_image_index);
if (next == NULL)
return FALSE;
gchar *image_path = (gchar *)next;
image_path = (gchar *)next;
g_debug ("Loading %s", image_path);
CoglHandle *cogl_texture;
cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (app->top));
if (cogl_texture != NULL)
@ -60,7 +64,6 @@ load_next_image (State *app)
}
/* load the next image into the top */
GError *error = NULL;
clutter_texture_set_from_file (CLUTTER_TEXTURE (app->top),
image_path,
&error);
@ -95,23 +98,8 @@ _key_pressed_cb (ClutterActor *actor,
int
main (int argc, char *argv[])
{
if (argc < 2)
{
g_print ("Usage: %s <image paths to load>\n", argv[0]);
exit (EXIT_FAILURE);
}
State *app = g_new0 (State, 1);
app->image_paths = NULL;
/*
* NB if your shell globs arguments to this program so argv
* includes non-image files, they will fail to load and throw errors
*/
guint i;
for (i = 1; i < argc; i++)
app->image_paths = g_slist_append (app->image_paths, argv[i]);
GError *error = NULL;
/* UI */
@ -119,6 +107,21 @@ main (int argc, char *argv[])
ClutterLayoutManager *layout;
ClutterActor *box;
if (argc < 2)
{
g_print ("Usage: %s <image paths to load>\n", argv[0]);
exit (EXIT_FAILURE);
}
app->image_paths = NULL;
/*
* NB if your shell globs arguments to this program so argv
* includes non-image files, they will fail to load and throw errors
*/
for (i = 1; i < argc; i++)
app->image_paths = g_slist_append (app->image_paths, argv[i]);
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();

View File

@ -61,6 +61,15 @@ load_image (ClutterTexture *texture,
int
main (int argc, char *argv[])
{
GError *error = NULL;
/* UI */
ClutterActor *stage;
ClutterLayoutManager *layout;
ClutterActor *box;
ClutterActor *top, *bottom;
ClutterState *transitions;
clutter_init_with_args (&argc, &argv,
" - cross-fade", entries,
NULL,
@ -72,15 +81,6 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
GError *error = NULL;
/* UI */
ClutterActor *stage;
ClutterLayoutManager *layout;
ClutterActor *box;
ClutterActor *top, *bottom;
ClutterState *transitions;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();

View File

@ -71,17 +71,18 @@ out:
int
main (int argc, char *argv[])
{
clutter_init (&argc, &argv);
ClutterActor *stage;
ClutterActor *texture;
GError *error = NULL;
ClutterActor *clone;
gfloat y_offset;
clutter_init (&argc, &argv);
stage = clutter_stage_new ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "Reflection");
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
ClutterActor *texture;
GError *error = NULL;
texture = clutter_texture_new ();
clutter_texture_set_from_file (CLUTTER_TEXTURE (texture),
TESTS_DATA_DIR "/redhand.png",
@ -89,8 +90,7 @@ main (int argc, char *argv[])
clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5));
clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.2));
ClutterActor *clone;
gfloat y_offset = clutter_actor_get_height (texture) + V_PADDING;
y_offset = clutter_actor_get_height (texture) + V_PADDING;
clone = clutter_clone_new (texture);
clutter_actor_add_constraint (clone, clutter_bind_constraint_new (texture, CLUTTER_BIND_X, 0.0));