mutter/clutter/examples/image-content.c

111 lines
3.5 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <clutter/clutter.h>
static const struct {
ClutterContentGravity gravity;
const char *name;
} gravities[] = {
{ CLUTTER_CONTENT_GRAVITY_TOP_LEFT, "Top Left" },
{ CLUTTER_CONTENT_GRAVITY_TOP, "Top" },
{ CLUTTER_CONTENT_GRAVITY_TOP_RIGHT, "Top Right" },
{ CLUTTER_CONTENT_GRAVITY_LEFT, "Left" },
{ CLUTTER_CONTENT_GRAVITY_CENTER, "Center" },
{ CLUTTER_CONTENT_GRAVITY_RIGHT, "Right" },
{ CLUTTER_CONTENT_GRAVITY_BOTTOM_LEFT, "Bottom Left" },
{ CLUTTER_CONTENT_GRAVITY_BOTTOM, "Bottom" },
{ CLUTTER_CONTENT_GRAVITY_BOTTOM_RIGHT, "Bottom Right" },
{ CLUTTER_CONTENT_GRAVITY_RESIZE_FILL, "Resize Fill" },
{ CLUTTER_CONTENT_GRAVITY_RESIZE_ASPECT, "Resize Aspect" },
};
static int n_gravities = G_N_ELEMENTS (gravities);
static int cur_gravity = 0;
static void
on_tap (ClutterTapAction *action,
ClutterActor *actor,
ClutterText *label)
{
gchar *str;
clutter_actor_save_easing_state (actor);
clutter_actor_set_content_gravity (actor, gravities[cur_gravity].gravity);
clutter_actor_restore_easing_state (actor);
str = g_strconcat ("Content gravity: ", gravities[cur_gravity].name, NULL);
clutter_text_set_text (label, str);
g_free (str);
cur_gravity += 1;
if (cur_gravity >= n_gravities)
cur_gravity = 0;
}
int
main (int argc, char *argv[])
{
ClutterActor *stage, *text;
ClutterContent *image;
ClutterAction *action;
GdkPixbuf *pixbuf;
gchar *str;
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return EXIT_FAILURE;
stage = clutter_stage_new ();
clutter_actor_set_name (stage, "Stage");
clutter_stage_set_title (CLUTTER_STAGE (stage), "Content Box");
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
clutter_actor_set_margin_top (stage, 12);
clutter_actor_set_margin_right (stage, 12);
clutter_actor_set_margin_bottom (stage, 12);
clutter_actor_set_margin_left (stage, 12);
clutter_actor_show (stage);
Fully rework the conformance test suite The current conformance test suite is suboptimal in many ways. All tests are built into the same binary, which makes adding new tests, builting tests, and running groups of tests much more awkward than it needs to be. The first issue, especially, raises the bar of contribution in a significant way, while the other two take their toll on the maintainer. All of these changes were introduced back when we had both Clutter and Cogl tests in tree, and because we were building the test suite for every single change; since then, Cogl moved out of tree with all its tests, and we build the conformance test suite only when running the `check` make target. This admittedly large-ish commit changes the way the conformance test suite works, taking advantage of the changes in the GTest API and test harness. First of all, all tests are now built separately, using their own test suite as defined by each separate file. All tests run under the TAP harness provided by GTest and Automake, to gather a proper report using the Test Anything Protocol without using the `gtester` harness and the `gtester-report` script. We also use the Makefile rules provided by GLib to vastly simplify the build environment for the conformance test suite. On top of the changes for the build and harness, we also provide new API for creating and running test suites for Clutter. The API is public, because the test suite has to use it, but it's minimal and mostly provides convenience wrappers around GTest that make writing test units for Clutter easier. This commit disables all tests in the conformance test suite, as well as moving the data files outside of the tests/data directory; the next few commits will re-establish the conformance test suite separately so we can check that everything works in a reliable way.
2013-12-12 09:36:16 -05:00
pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL);
image = clutter_image_new ();
clutter_image_set_data (CLUTTER_IMAGE (image),
gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_has_alpha (pixbuf)
? COGL_PIXEL_FORMAT_RGBA_8888
: COGL_PIXEL_FORMAT_RGB_888,
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_rowstride (pixbuf),
NULL);
g_object_unref (pixbuf);
clutter_actor_set_content_scaling_filters (stage,
2012-03-16 08:05:11 -04:00
CLUTTER_SCALING_FILTER_TRILINEAR,
CLUTTER_SCALING_FILTER_LINEAR);
clutter_actor_set_content_gravity (stage, gravities[n_gravities - 1].gravity);
clutter_actor_set_content (stage, image);
g_object_unref (image);
str = g_strconcat ("Content gravity: ",
gravities[n_gravities - 1].name,
NULL);
text = clutter_text_new ();
clutter_text_set_text (CLUTTER_TEXT (text), str);
clutter_actor_add_constraint (text, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
clutter_actor_add_child (stage, text);
g_free (str);
action = clutter_tap_action_new ();
g_signal_connect (action, "tap", G_CALLBACK (on_tap), text);
clutter_actor_add_action (stage, action);
clutter_main ();
return EXIT_SUCCESS;
}