2008-11-07 14:32:28 -05:00
|
|
|
#include <gmodule.h>
|
2008-04-25 09:37:36 -04:00
|
|
|
#include <clutter/clutter.h>
|
2008-09-18 06:24:37 -04:00
|
|
|
#include <string.h>
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
#define DOT_SIZE 2
|
|
|
|
#define TEX_SIZE 64
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
typedef struct _CallbackData CallbackData;
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
struct _CallbackData
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2008-09-18 06:24:37 -04:00
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *tex;
|
|
|
|
ClutterActor *box;
|
|
|
|
ClutterMotionEvent event;
|
|
|
|
guint idle_source;
|
2008-04-25 09:37:36 -04:00
|
|
|
};
|
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
static ClutterActor *
|
|
|
|
make_label (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2008-09-18 06:24:37 -04:00
|
|
|
ClutterActor *label;
|
|
|
|
gchar *text;
|
|
|
|
gchar *argv[] = { "ls", "--help", NULL };
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-12-11 08:48:01 -05:00
|
|
|
label = clutter_text_new ();
|
|
|
|
clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 10");
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
if (g_spawn_sync (NULL, argv, NULL,
|
|
|
|
G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_SEARCH_PATH,
|
|
|
|
NULL, NULL, &text, NULL, NULL, NULL))
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2008-12-11 08:48:01 -05:00
|
|
|
clutter_text_set_text (CLUTTER_TEXT (label), text);
|
2008-09-18 06:24:37 -04:00
|
|
|
g_free (text);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
return label;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
static ClutterActor *
|
|
|
|
make_tex (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2008-09-18 06:24:37 -04:00
|
|
|
ClutterActor *tex = clutter_texture_new ();
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
clutter_actor_set_size (tex, TEX_SIZE * 2, TEX_SIZE * 2);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
return tex;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
static ClutterActor *
|
|
|
|
make_box (void)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2008-09-18 06:24:37 -04:00
|
|
|
ClutterActor *box;
|
|
|
|
static const ClutterColor blue = { 0x00, 0x00, 0xff, 0xff };
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
box = clutter_rectangle_new_with_color (&blue);
|
|
|
|
clutter_actor_set_size (box, DOT_SIZE + 2, DOT_SIZE + 2);
|
|
|
|
clutter_actor_hide (box);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
return box;
|
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
static gboolean
|
|
|
|
on_motion_idle (gpointer user_data)
|
|
|
|
{
|
|
|
|
CallbackData *data = (CallbackData *) user_data;
|
|
|
|
guchar *pixels, *p;
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 11:44:47 -04:00
|
|
|
gfloat stage_width, stage_height;
|
2008-09-18 06:24:37 -04:00
|
|
|
gint x, y;
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
data->idle_source = 0;
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
clutter_actor_get_size (data->stage, &stage_width, &stage_height);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 11:44:47 -04:00
|
|
|
x = CLAMP (data->event.x - TEX_SIZE / 2, 0, stage_width - TEX_SIZE);
|
|
|
|
y = CLAMP (data->event.y - TEX_SIZE / 2, 0, stage_height - TEX_SIZE);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 11:44:47 -04:00
|
|
|
clutter_actor_set_position (data->box,
|
|
|
|
x + TEX_SIZE / 2 - 1,
|
2008-09-18 06:24:37 -04:00
|
|
|
y + TEX_SIZE / 2 - 1);
|
|
|
|
clutter_actor_show (data->box);
|
|
|
|
/* Redraw so that the layouting will be done and the box will be
|
|
|
|
drawn in the right position */
|
|
|
|
clutter_redraw (CLUTTER_STAGE (data->stage));
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
pixels = clutter_stage_read_pixels (CLUTTER_STAGE (data->stage),
|
Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.
ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.
So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:
- we have to maintain twice the amount of entry points in ClutterActor
- we still do an integer-to-float implicit conversion
- we introduce a weird impedance between pixels and "pixels with
fractionary bits"
- language bindings will have to choose what to bind, and resort
to manually overriding the API
+ *except* for language bindings based on GObject-Introspection, as
they cannot do manual overrides, thus will replicate the entire
set of entry points
For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:
void clutter_actor_set_x (ClutterActor *self,
gfloat x);
void clutter_actor_get_size (ClutterActor *self,
gfloat *width,
gfloat *height);
gfloat clutter_actor_get_height (ClutterActor *self);
etc.
The issues I have identified are:
- we'll have a two cases of compiler warnings:
- printf() format of the return values from %d to %f
- clutter_actor_get_size() taking floats instead of unsigned ints
- we'll have a problem with varargs when passing an integer instead
of a floating point value, except on 64bit platforms where the
size of a float is the same as the size of an int
To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:
- we remove ambiguity in the API with regard to pixels and units
- we remove entry points we get to maintain for the whole 1.0
version of the API
- we make things simpler to bind for both manual language bindings
and automatic (gobject-introspection based) ones
- we have the simplest API possible while still exposing the
capabilities of the underlying GL implementation
2009-05-06 11:44:47 -04:00
|
|
|
x, y,
|
|
|
|
TEX_SIZE, TEX_SIZE);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
/* Make a red dot in the center */
|
|
|
|
p = pixels + (TEX_SIZE / 2 - DOT_SIZE / 2) * TEX_SIZE * 4
|
|
|
|
+ (TEX_SIZE / 2 - DOT_SIZE / 2) * 4;
|
|
|
|
for (y = 0; y < DOT_SIZE; y++)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2008-09-18 06:24:37 -04:00
|
|
|
for (x = 0; x < DOT_SIZE; x++)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2008-09-18 06:24:37 -04:00
|
|
|
*(p++) = 255;
|
|
|
|
memset (p, 0, 3);
|
|
|
|
p += 3;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
2008-09-18 06:24:37 -04:00
|
|
|
p += TEX_SIZE * 4 - DOT_SIZE * 4;
|
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
/* Set all of the alpa values to full */
|
|
|
|
for (p = pixels + TEX_SIZE * TEX_SIZE * 4; p > pixels; p -= 4)
|
|
|
|
*(p - 1) = 255;
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (data->tex),
|
|
|
|
pixels, TRUE,
|
|
|
|
TEX_SIZE, TEX_SIZE,
|
|
|
|
TEX_SIZE * 4, 4, 0, NULL);
|
|
|
|
g_free (pixels);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
static gboolean
|
|
|
|
on_motion (ClutterActor *stage, ClutterMotionEvent *event, CallbackData *data)
|
|
|
|
{
|
|
|
|
/* Handle the motion event in an idle handler so that multiple
|
|
|
|
events will be combined into one */
|
|
|
|
if (data->idle_source == 0)
|
|
|
|
data->idle_source = clutter_threads_add_idle (on_motion_idle, data);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
data->event = *event;
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_stage_read_pixels_main (int argc, char **argv)
|
2008-09-18 06:24:37 -04:00
|
|
|
{
|
|
|
|
CallbackData data;
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
clutter_init (&argc, &argv);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
data.idle_source = 0;
|
|
|
|
data.stage = clutter_stage_get_default ();
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
data.tex = make_tex ();
|
|
|
|
data.box = make_box ();
|
|
|
|
clutter_actor_set_position (data.tex,
|
|
|
|
clutter_actor_get_width (data.stage)
|
|
|
|
- clutter_actor_get_width (data.tex),
|
|
|
|
clutter_actor_get_height (data.stage)
|
|
|
|
- clutter_actor_get_height (data.tex));
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (data.stage),
|
|
|
|
make_label (), data.tex, data.box, NULL);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
g_signal_connect (data.stage, "motion-event", G_CALLBACK (on_motion), &data);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-09-18 06:24:37 -04:00
|
|
|
clutter_actor_show (data.stage);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|