2007-06-13 09:31:56 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-11-07 14:32:28 -05:00
|
|
|
#include <gmodule.h>
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2007-07-26 07:04:04 -04:00
|
|
|
static ClutterActor *main_stage, *rect, *p[5];
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
init_handles ()
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
ClutterVertex v[4];
|
2007-07-02 05:21:58 -04:00
|
|
|
ClutterVertex v1, v2;
|
2007-06-13 09:31:56 -04:00
|
|
|
ClutterColor blue = { 0, 0, 0xff, 0xff };
|
|
|
|
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 13:07:52 -04:00
|
|
|
clutter_actor_get_abs_allocation_vertices (rect, v);
|
2007-06-13 09:31:56 -04:00
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
p[i] = clutter_rectangle_new_with_color (&blue);
|
|
|
|
clutter_actor_set_size (p[i], 5, 5);
|
|
|
|
clutter_actor_set_position (p[i], 0, 0);
|
2007-07-26 07:04:04 -04:00
|
|
|
clutter_group_add (CLUTTER_GROUP (main_stage), p[i]);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2009-01-08 10:45:22 -05:00
|
|
|
clutter_actor_set_positionu (p[i],
|
|
|
|
v[i].x -
|
|
|
|
clutter_actor_get_widthu (p[i])/2,
|
|
|
|
v[i].y -
|
|
|
|
clutter_actor_get_heightu (p[i])/2);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
clutter_actor_raise_top (p[i]);
|
|
|
|
|
|
|
|
clutter_actor_show (p[i]);
|
|
|
|
}
|
|
|
|
|
2009-01-08 10:45:22 -05:00
|
|
|
v1.x = clutter_actor_get_widthu (rect) / 2;
|
|
|
|
v1.y = clutter_actor_get_heightu (rect) / 2;
|
2007-07-02 05:21:58 -04:00
|
|
|
v1.z = 0;
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2007-07-02 05:21:58 -04:00
|
|
|
clutter_actor_apply_transform_to_point (rect, &v1, &v2);
|
2007-06-13 09:31:56 -04:00
|
|
|
p[4] = clutter_rectangle_new_with_color (&blue);
|
|
|
|
clutter_actor_set_size (p[4], 5, 5);
|
|
|
|
clutter_actor_set_position (p[4], 0, 0);
|
2007-07-26 07:04:04 -04:00
|
|
|
clutter_group_add (CLUTTER_GROUP (main_stage), p[4]);
|
2009-01-08 10:45:22 -05:00
|
|
|
clutter_actor_set_positionu (p[4],
|
|
|
|
v2.x -
|
|
|
|
clutter_actor_get_widthu (p[4])/2,
|
|
|
|
v2.y -
|
|
|
|
clutter_actor_get_heightu (p[4])/2);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
clutter_actor_raise_top (p[4]);
|
|
|
|
|
|
|
|
clutter_actor_show (p[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
place_handles ()
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
ClutterVertex v[4];
|
2007-07-02 05:21:58 -04:00
|
|
|
ClutterVertex v1, v2;
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 13:07:52 -04:00
|
|
|
clutter_actor_get_abs_allocation_vertices (rect, v);
|
2007-06-13 09:31:56 -04:00
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
{
|
2009-01-08 10:45:22 -05:00
|
|
|
clutter_actor_set_positionu (p[i],
|
|
|
|
v[i].x -
|
|
|
|
clutter_actor_get_widthu (p[i])/2,
|
|
|
|
v[i].y -
|
|
|
|
clutter_actor_get_heightu (p[i])/2);
|
2007-06-13 09:31:56 -04:00
|
|
|
}
|
|
|
|
|
2009-01-08 10:45:22 -05:00
|
|
|
v1.x = clutter_actor_get_widthu (rect)/2;
|
|
|
|
v1.y = clutter_actor_get_heightu (rect)/2;
|
2007-07-02 05:21:58 -04:00
|
|
|
v1.z = 0;
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2007-07-02 05:21:58 -04:00
|
|
|
clutter_actor_apply_transform_to_point (rect, &v1, &v2);
|
2009-01-08 10:45:22 -05:00
|
|
|
clutter_actor_set_positionu (p[4],
|
|
|
|
v2.x - clutter_actor_get_widthu (p[4])/2,
|
|
|
|
v2.y - clutter_actor_get_heightu (p[4])/2);
|
2007-06-13 09:31:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define M(m,row,col) (m)[col*4+row]
|
|
|
|
|
|
|
|
static gint
|
|
|
|
find_handle_index (ClutterActor * a)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
for (i = 0; i < sizeof(p)/sizeof(p[0]); ++i)
|
|
|
|
if (p[i] == a)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
static gboolean
|
2007-06-13 09:31:56 -04:00
|
|
|
on_event (ClutterStage *stage,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
static ClutterActor * dragging = NULL;
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case CLUTTER_BUTTON_PRESS:
|
|
|
|
{
|
|
|
|
gint x, y;
|
|
|
|
ClutterActor * actor;
|
|
|
|
|
|
|
|
clutter_event_get_coords (event, &x, &y);
|
|
|
|
|
2009-04-24 10:05:02 -04:00
|
|
|
actor = clutter_stage_get_actor_at_pos (stage,
|
|
|
|
CLUTTER_PICK_ALL,
|
|
|
|
x, y);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
if (actor != CLUTTER_ACTOR (stage))
|
|
|
|
{
|
|
|
|
if (actor != rect)
|
|
|
|
dragging = actor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_MOTION:
|
|
|
|
{
|
|
|
|
if (dragging)
|
|
|
|
{
|
|
|
|
gint x, y;
|
|
|
|
gint i;
|
|
|
|
ClutterActorBox box1, box2;
|
2009-01-08 10:45:22 -05:00
|
|
|
ClutterUnit xp, yp;
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
i = find_handle_index (dragging);
|
|
|
|
|
|
|
|
if (i < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
clutter_event_get_coords (event, &x, &y);
|
|
|
|
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 13:07:52 -04:00
|
|
|
clutter_actor_get_allocation_box (dragging, &box1);
|
|
|
|
clutter_actor_get_allocation_box (rect, &box2);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2009-01-08 10:45:22 -05:00
|
|
|
xp = CLUTTER_UNITS_FROM_DEVICE (x - 3) - box1.x1;
|
|
|
|
yp = CLUTTER_UNITS_FROM_DEVICE (y - 3) - box1.y1;
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
if (i == 4)
|
|
|
|
{
|
|
|
|
g_debug ("moving box by %f, %f",
|
2009-01-08 10:45:22 -05:00
|
|
|
CLUTTER_UNITS_TO_FLOAT (xp),
|
|
|
|
CLUTTER_UNITS_TO_FLOAT (yp));
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2009-01-08 10:45:22 -05:00
|
|
|
clutter_actor_move_byu (rect, xp, yp);
|
2007-06-13 09:31:56 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_debug ("adjusting box by %f, %f, handle %d",
|
2009-01-08 10:45:22 -05:00
|
|
|
CLUTTER_UNITS_TO_FLOAT (xp),
|
|
|
|
CLUTTER_UNITS_TO_FLOAT (yp),
|
2007-06-13 09:31:56 -04:00
|
|
|
i);
|
2009-01-08 10:45:22 -05:00
|
|
|
|
2007-06-13 09:31:56 -04:00
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
box2.x1 += xp;
|
|
|
|
box2.y1 += yp;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
box2.x2 += xp;
|
|
|
|
box2.y1 += yp;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
box2.x1 += xp;
|
|
|
|
box2.y2 += yp;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
box2.x2 += xp;
|
|
|
|
box2.y2 += yp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com>
Bug #815 - Split up request, allocation, and paint box
* clutter/clutter-actor.[ch]: Rework the size allocation,
request and paint area. Now ::request_coords() is called
::allocate(), and ::query_coords() has been split into
::get_preferred_width() and ::get_preferred_height(). See
the documentation and the layout test on how to implement
a container and layout manager with the new API. (#915,
based on a patch by Havoc Pennington, Lucas Rocha and Johan
Bilien)
* clutter/clutter-clone-texture.c: Port CloneTexture to
the new size negotiation API; it just means forwarding
the requests to the parent texture.
* clutter/clutter-deprecated.h: Add deprecated and replaced
API.
* clutter/clutter-entry.c: Port Entry to the new size
negotiation API.
* clutter/clutter-group.c: Port Group to the new size
negotiation API; the semantics of the Group actor do not
change.
* clutter/clutter-label.c: Port Label to the new size
negotiation API, and vastly simplify the code.
* clutter/clutter-main.[ch]: Add API for executing a
relayout when needed.
* clutter/clutter-private.h: Add new Stage private API.
* clutter/clutter-rectangle.c: Update the get_abs_opacity()
call to get_paint_opacity().
* clutter/clutter-stage.c:
(clutter_stage_get_preferred_width),
(clutter_stage_get_preferred_height),
(clutter_stage_allocate),
(clutter_stage_class_init): Port Stage to the new size
negotiation API.
* clutter/clutter-texture.c: Port Texture to the new size
negotiation API.
* clutter/clutter-types.h: Add ClutterRequestMode enumeration.
* clutter/x11/clutter-stage-x11.c: Port the X11 stage
implementation to the new size negotiation API.
* tests/Makefile.am: Add the layout manager test case.
* tests/test-opacity.c: Update.
* tests/test-project.c: Update.
* tests/test-layout.c: Test case for a layout manager implemented
using the new size negotiation API; the layout manager handles
both transformed and untransformed children.
2008-06-10 13:07:52 -04:00
|
|
|
/* FIXME this is just plain wrong, to allocate directly
|
|
|
|
* like this
|
|
|
|
*/
|
|
|
|
clutter_actor_allocate (rect, &box2, TRUE);
|
2007-06-13 09:31:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
place_handles ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLUTTER_BUTTON_RELEASE:
|
|
|
|
{
|
|
|
|
dragging = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-09-22 09:33:19 -04:00
|
|
|
|
|
|
|
return FALSE;
|
2007-06-13 09:31:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_project_main (int argc, char *argv[])
|
2007-06-13 09:31:56 -04:00
|
|
|
{
|
2007-07-26 07:04:04 -04:00
|
|
|
ClutterActor *label;
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff },
|
|
|
|
white = { 0xff, 0xff, 0xff, 0xff };
|
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
2007-07-26 07:04:04 -04:00
|
|
|
main_stage = clutter_stage_get_default ();
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2007-07-26 07:04:04 -04:00
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (main_stage), &stage_color);
|
|
|
|
clutter_actor_set_size (main_stage, 640, 480);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
rect = clutter_rectangle_new_with_color (&white);
|
|
|
|
clutter_actor_set_size (rect, 320, 240);
|
|
|
|
clutter_actor_set_position (rect, 180, 120);
|
2007-11-19 06:43:20 -05:00
|
|
|
clutter_actor_set_rotation (rect, CLUTTER_Y_AXIS, 60, 0, 0, 0);
|
2007-07-26 07:04:04 -04:00
|
|
|
clutter_group_add (CLUTTER_GROUP (main_stage), rect);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2008-12-11 08:48:01 -05:00
|
|
|
label = clutter_text_new_with_text ("Mono 8pt", "Drag the blue rectangles");
|
|
|
|
clutter_text_set_color (CLUTTER_TEXT (label), &white);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
clutter_actor_set_position (label, 10, 10);
|
2007-07-26 07:04:04 -04:00
|
|
|
clutter_group_add (CLUTTER_GROUP (main_stage), label);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2007-07-26 07:04:04 -04:00
|
|
|
clutter_actor_show_all (main_stage);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
2007-07-26 07:04:04 -04:00
|
|
|
g_signal_connect (main_stage, "event", G_CALLBACK (on_event), NULL);
|
2007-06-13 09:31:56 -04:00
|
|
|
|
|
|
|
init_handles ();
|
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|