| 1 |
#include <stdlib.h> |
| 2 |
#include <gmodule.h> |
| 3 |
#include <clutter/clutter.h> |
| 4 |
|
| 5 |
/* each time the timeline animating the label completes, swap the direction */ |
| 6 |
static void |
| 7 |
timeline_completed (ClutterTimeline *timeline, |
| 8 |
gpointer user_data) |
| 9 |
{ |
| 10 |
clutter_timeline_set_direction (timeline, |
| 11 |
!clutter_timeline_get_direction (timeline)); |
| 12 |
clutter_timeline_start (timeline); |
| 13 |
} |
| 14 |
|
| 15 |
static gboolean |
| 16 |
change_filter (gpointer actor) |
| 17 |
{ |
| 18 |
ClutterTextureQuality old_quality; |
| 19 |
|
| 20 |
old_quality = clutter_texture_get_filter_quality (actor); |
| 21 |
switch (old_quality) |
| 22 |
{ |
| 23 |
case CLUTTER_TEXTURE_QUALITY_LOW: |
| 24 |
clutter_texture_set_filter_quality (actor, |
| 25 |
CLUTTER_TEXTURE_QUALITY_MEDIUM); |
| 26 |
g_print ("Setting texture rendering quality to medium\n"); |
| 27 |
break; |
| 28 |
case CLUTTER_TEXTURE_QUALITY_MEDIUM: |
| 29 |
clutter_texture_set_filter_quality (actor, |
| 30 |
CLUTTER_TEXTURE_QUALITY_HIGH); |
| 31 |
g_print ("Setting texture rendering quality to high\n"); |
| 32 |
break; |
| 33 |
case CLUTTER_TEXTURE_QUALITY_HIGH: |
| 34 |
clutter_texture_set_filter_quality (actor, |
| 35 |
CLUTTER_TEXTURE_QUALITY_LOW); |
| 36 |
g_print ("Setting texture rendering quality to low\n"); |
| 37 |
break; |
| 38 |
} |
| 39 |
return TRUE; |
| 40 |
} |
| 41 |
|
| 42 |
G_MODULE_EXPORT gint |
| 43 |
test_texture_quality_main (int argc, char *argv[]) |
| 44 |
{ |
| 45 |
ClutterTimeline *timeline; |
| 46 |
ClutterAlpha *alpha; |
| 47 |
ClutterBehaviour *depth_behavior; |
| 48 |
ClutterActor *stage; |
| 49 |
ClutterActor *image; |
| 50 |
ClutterColor stage_color = { 0x12, 0x34, 0x56, 0xff }; |
| 51 |
ClutterFog stage_fog = { 10.0, -50.0 }; |
| 52 |
GError *error; |
| 53 |
gchar *file; |
| 54 |
|
| 55 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 56 |
return 1; |
| 57 |
|
| 58 |
stage = clutter_stage_new (); |
| 59 |
clutter_actor_set_background_color (stage, &stage_color); |
| 60 |
clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE); |
| 61 |
clutter_stage_set_fog (CLUTTER_STAGE (stage), &stage_fog); |
| 62 |
g_signal_connect (stage, |
| 63 |
"destroy", G_CALLBACK (clutter_main_quit), |
| 64 |
NULL); |
| 65 |
g_signal_connect (stage, |
| 66 |
"button-press-event", G_CALLBACK (clutter_main_quit), |
| 67 |
NULL); |
| 68 |
|
| 69 |
if (argc < 2) |
| 70 |
g_print ("Hint: the redhand.png isn't a good test image for this test.\n" |
| 71 |
"This test can take any image file as an argument\n"); |
| 72 |
|
| 73 |
file = (argc > 1) |
| 74 |
? g_strdup (argv[1]) |
| 75 |
: g_build_filename (TESTS_DATADIR, "redhand.png", NULL); |
| 76 |
|
| 77 |
error = NULL; |
| 78 |
image = clutter_texture_new_from_file (file, &error); |
| 79 |
if (error) |
| 80 |
g_error ("Unable to load image: %s", error->message); |
| 81 |
|
| 82 |
g_free (file); |
| 83 |
|
| 84 |
/* center the image */ |
| 85 |
clutter_actor_set_position (image, |
| 86 |
(clutter_actor_get_width (stage) - clutter_actor_get_width (image))/2, |
| 87 |
(clutter_actor_get_height (stage) - clutter_actor_get_height (image))/2); |
| 88 |
clutter_container_add (CLUTTER_CONTAINER (stage), image, NULL); |
| 89 |
|
| 90 |
timeline = clutter_timeline_new (5000); |
| 91 |
g_signal_connect (timeline, |
| 92 |
"completed", G_CALLBACK (timeline_completed), |
| 93 |
NULL); |
| 94 |
|
| 95 |
alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR); |
| 96 |
depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400); |
| 97 |
clutter_behaviour_apply (depth_behavior, image); |
| 98 |
|
| 99 |
clutter_actor_show (stage); |
| 100 |
clutter_timeline_start (timeline); |
| 101 |
|
| 102 |
clutter_threads_add_timeout (10000, change_filter, image); |
| 103 |
|
| 104 |
clutter_main (); |
| 105 |
|
| 106 |
g_object_unref (depth_behavior); |
| 107 |
g_object_unref (timeline); |
| 108 |
|
| 109 |
return EXIT_SUCCESS; |
| 110 |
} |
| 111 |
|
| 112 |
G_MODULE_EXPORT const char * |
| 113 |
test_texture_quality_describe (void) |
| 114 |
{ |
| 115 |
return "Change the texture filtering quality."; |
| 116 |
} |