2012-03-09 11:26:34 -05:00
|
|
|
#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
|
2012-10-01 10:15:06 -04:00
|
|
|
on_tap (ClutterTapAction *action,
|
|
|
|
ClutterActor *actor,
|
|
|
|
ClutterText *label)
|
2012-03-09 11:26:34 -05:00
|
|
|
{
|
2012-03-16 11:05:42 -04:00
|
|
|
gchar *str;
|
|
|
|
|
2012-03-29 08:53:40 -04:00
|
|
|
clutter_actor_save_easing_state (actor);
|
2012-03-09 11:26:34 -05:00
|
|
|
clutter_actor_set_content_gravity (actor, gravities[cur_gravity].gravity);
|
2012-03-29 08:53:40 -04:00
|
|
|
clutter_actor_restore_easing_state (actor);
|
2012-03-16 11:05:42 -04:00
|
|
|
|
|
|
|
str = g_strconcat ("Content gravity: ", gravities[cur_gravity].name, NULL);
|
|
|
|
clutter_text_set_text (label, str);
|
|
|
|
g_free (str);
|
2012-03-09 11:26:34 -05:00
|
|
|
|
|
|
|
cur_gravity += 1;
|
|
|
|
|
|
|
|
if (cur_gravity >= n_gravities)
|
|
|
|
cur_gravity = 0;
|
|
|
|
}
|
|
|
|
|
2012-05-01 13:30:10 -04:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2012-03-09 11:26:34 -05:00
|
|
|
{
|
2012-03-09 11:26:44 -05:00
|
|
|
ClutterActor *stage, *box, *text;
|
2012-03-09 11:26:34 -05:00
|
|
|
ClutterContent *image;
|
|
|
|
ClutterAction *action;
|
|
|
|
GdkPixbuf *pixbuf;
|
2012-03-16 11:05:42 -04:00
|
|
|
gchar *str;
|
2012-03-09 11:26:34 -05:00
|
|
|
|
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
stage = clutter_stage_new ();
|
|
|
|
clutter_actor_set_name (stage, "Stage");
|
2012-03-09 11:26:44 -05:00
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Content Box");
|
2012-03-09 11:26:34 -05:00
|
|
|
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
|
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
box = clutter_actor_new ();
|
2012-03-13 13:19:15 -04:00
|
|
|
clutter_actor_set_name (box, "Image");
|
2012-03-09 11:26:34 -05:00
|
|
|
clutter_actor_set_margin_top (box, 12);
|
|
|
|
clutter_actor_set_margin_right (box, 12);
|
|
|
|
clutter_actor_set_margin_bottom (box, 12);
|
|
|
|
clutter_actor_set_margin_left (box, 12);
|
|
|
|
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0));
|
|
|
|
clutter_actor_add_child (stage, box);
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (TESTS_DATADIR G_DIR_SEPARATOR_S "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);
|
|
|
|
|
2012-03-09 11:26:44 -05:00
|
|
|
clutter_actor_set_content_scaling_filters (box,
|
Rename 'bilinear' scaling filter to 'trilinear'
Yes, it's not really the proper GL name for a linear-on-every-axis of a
texture plus linear-between-mipmap-levels minification filter, but it
has three redeeming qualities as a name:
- LINEAR_MIPMAP_LINEAR sucks, as it introduces GL concepts like
mipmaps in the API naming, while we're trying to avoid that;
- people using GL already know what 'trilinear' means in this context
without going all Khronos on their asses;
- we're using 2D textures anyway, so 'linear on two axes and linear
between mipmap levels' can be effectively approximated to
'trilinear'.
I mean, if even the OpenGL official wiki says:
Unfortunately, what most people think of as "trilinear" is not linear
filtering of a 3D texture, but what in OpenGL terms is GL_LINEAR mag
filter and GL_LINEAR_MIPMAP_LINEAR in the min filter in a 2D texture.
That is, it is bilinear filtering of each appropriate mipmap level,
and doing a third linear filter between the adjacent mipmap levels.
Hence the term "trilinear".
-- http://www.opengl.org/wiki/Texture
then the horse has already been flogged to death, and I don't intend to
be accused of necrophilia and sadism by flogging it some more.
Prior art: every single GL tutorial in the history of ever;
CoreAnimation's scaling filter enumerations.
If people want to start using 1D or 3D textures they they are probably
going to be using Cogl API directly, and that has the GL naming scheme
for minification and magnification filters anyway.
2012-03-16 08:05:11 -04:00
|
|
|
CLUTTER_SCALING_FILTER_TRILINEAR,
|
2012-03-09 11:26:44 -05:00
|
|
|
CLUTTER_SCALING_FILTER_LINEAR);
|
|
|
|
clutter_actor_set_content_gravity (box, gravities[n_gravities - 1].gravity);
|
2012-03-09 11:26:34 -05:00
|
|
|
clutter_actor_set_content (box, image);
|
|
|
|
g_object_unref (image);
|
|
|
|
|
2012-03-16 11:05:42 -04:00
|
|
|
str = g_strconcat ("Content gravity: ",
|
|
|
|
gravities[n_gravities - 1].name,
|
|
|
|
NULL);
|
|
|
|
|
2012-03-09 11:26:44 -05:00
|
|
|
text = clutter_text_new ();
|
2012-03-16 11:05:42 -04:00
|
|
|
clutter_text_set_text (CLUTTER_TEXT (text), str);
|
2012-03-09 11:26:44 -05:00
|
|
|
clutter_actor_add_constraint (text, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
|
|
|
|
clutter_actor_add_child (stage, text);
|
|
|
|
|
2012-03-16 11:05:42 -04:00
|
|
|
g_free (str);
|
|
|
|
|
2012-10-01 10:15:06 -04:00
|
|
|
action = clutter_tap_action_new ();
|
|
|
|
g_signal_connect (action, "tap", G_CALLBACK (on_tap), text);
|
2012-03-09 11:26:34 -05:00
|
|
|
clutter_actor_set_reactive (box, TRUE);
|
|
|
|
clutter_actor_add_action (box, action);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|