[ease: 1/2] Select actors in the editor and drag them around.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease: 1/2] Select actors in the editor and drag them around.
- Date: Wed, 19 May 2010 01:30:14 +0000 (UTC)
commit 5b62c8b889d666d19f994ba1644f265a6d40c02f
Author: Nate Stedman <natesm gmail com>
Date: Tue May 18 21:21:31 2010 -0400
Select actors in the editor and drag them around.
src/libease/Actor.vala | 21 ++++++++
src/libease/EditorEmbed.vala | 114 +++++++++++++++++++++++++++++++++++++++++-
src/libease/SlideActor.vala | 15 ++++--
3 files changed, 145 insertions(+), 5 deletions(-)
---
diff --git a/src/libease/Actor.vala b/src/libease/Actor.vala
index e4de0ab..a278d65 100644
--- a/src/libease/Actor.vala
+++ b/src/libease/Actor.vala
@@ -35,6 +35,9 @@ namespace Ease
// where this actor is (editor, player, sidebar)
public ActorContext context;
+
+ // if the actor is a slide background
+ public bool is_background;
/**
* Instantiate a new Actor
@@ -49,6 +52,24 @@ namespace Ease
{
element = e;
context = c;
+ is_background = false;
+ }
+
+ /**
+ * Move this Actor and update its { link Element}
+ *
+ * Used in the editor and tied to Clutter MotionEvents.
+ *
+ * @param x_change The amount of X motion.
+ * @param y_change The amount of Y motion.
+ */
+ public void translate(float x_change, float y_change)
+ {
+ x += x_change;
+ y += y_change;
+
+ element.x = x;
+ element.y = y;
}
}
}
diff --git a/src/libease/EditorEmbed.vala b/src/libease/EditorEmbed.vala
index bdcfa74..1a1672f 100644
--- a/src/libease/EditorEmbed.vala
+++ b/src/libease/EditorEmbed.vala
@@ -33,10 +33,22 @@ namespace Ease
{
// overall display
private Clutter.Rectangle view_background;
+
+ // selection rectangle
+ private Clutter.Rectangle selection_rectangle;
// the current slide's actor
private SlideActor slide_actor;
+ // the currently selected Actor
+ private Actor selected;
+
+ // if the selected Actor is being dragged
+ private bool is_dragging;
+ private bool is_drag_ready;
+ private float mouse_x;
+ private float mouse_y;
+
private Document document;
public float zoom;
public bool zoom_fit;
@@ -130,9 +142,40 @@ namespace Ease
if (slide_actor != null)
{
contents.remove_actor(slide_actor);
+ for (unowned List<Clutter.Actor>* itr = slide_actor.contents.get_children();
+ itr != null;
+ itr = itr->next)
+ {
+ ((Actor*)(itr->data))->button_press_event.disconnect(actor_clicked);
+ ((Actor*)(itr->data))->button_release_event.disconnect(actor_released);
+ ((Actor*)(itr->data))->motion_event.disconnect(actor_motion);
+ ((Actor*)(itr->data))->set_reactive(false);
+ }
}
- slide_actor = new SlideActor.from_slide(document, slide, false, ActorContext.Editor);
+ // remove the selection rectangle
+ if (selection_rectangle != null)
+ {
+ contents.remove_actor(selection_rectangle);
+ }
+
+ // create a new SlideActor
+ slide_actor = new SlideActor.from_slide(document,
+ slide,
+ false,
+ ActorContext.Editor);
+
+ // make the elements clickable
+ for (unowned List<Clutter.Actor>* itr = slide_actor.contents.get_children();
+ itr != null;
+ itr = itr->next)
+ {
+
+ ((Actor*)(itr->data))->button_press_event.connect(actor_clicked);
+ ((Actor*)(itr->data))->button_release_event.connect(actor_released);
+ ((Actor*)(itr->data))->motion_event.connect(actor_motion);
+ ((Actor*)(itr->data))->set_reactive(true);
+ }
contents.add_actor(slide_actor);
reposition_group();
@@ -159,5 +202,74 @@ namespace Ease
? height / 2 - h / 2
: 0;
}
+
+ public bool actor_clicked(Clutter.Actor sender, Clutter.Event event)
+ {
+ Actor act = (Actor)sender;
+ stdout.printf("Name: %s\n", act.element.data.get("ease_name"));
+
+ // if the sender is already selected, drag it
+ if (sender == selected)
+ {
+ is_dragging = true;
+ is_drag_ready = false;
+ return true;
+ }
+
+ // remove the selection rectangle
+ if (selection_rectangle != null)
+ {
+ contents.remove_actor(selection_rectangle);
+ }
+
+ selected = (Actor)sender;
+
+ // make a new selection rectangle
+ selection_rectangle = new Clutter.Rectangle();
+ selection_rectangle.border_color = {0, 0, 0, 255};
+ selection_rectangle.color = {0, 0, 0, 0};
+ selection_rectangle.set_border_width(2);
+ selection_rectangle.set_position(selected.x + slide_actor.x,
+ selected.y + slide_actor.y);
+ selection_rectangle.set_size(selected.width, selected.height);
+ contents.add_actor(selection_rectangle);
+
+ return true;
+ }
+
+ public bool actor_released(Clutter.Actor sender, Clutter.Event event)
+ {
+ if (sender == selected && is_dragging)
+ {
+ is_dragging = false;
+ }
+ return true;
+ }
+
+ public bool actor_motion(Clutter.Actor sender, Clutter.Event event)
+ {
+ Actor actor = (Actor)sender;
+
+ if (sender == selected && is_dragging)
+ {
+ if (!is_drag_ready)
+ {
+ is_drag_ready = true;
+ mouse_x = event.motion.x;
+ mouse_y = event.motion.y;
+ return true;
+ }
+ actor.translate(event.motion.x - mouse_x,
+ event.motion.y - mouse_y);
+
+ mouse_x = event.motion.x;
+ mouse_y = event.motion.y;
+
+ selection_rectangle.set_position(selected.x + slide_actor.x,
+ selected.y + slide_actor.y);
+ selection_rectangle.set_size(selected.width, selected.height);
+ }
+ return true;
+ }
}
}
diff --git a/src/libease/SlideActor.vala b/src/libease/SlideActor.vala
index 609a0dd..41ba301 100644
--- a/src/libease/SlideActor.vala
+++ b/src/libease/SlideActor.vala
@@ -37,6 +37,9 @@ namespace Ease
// the group of the slide's contents
public Clutter.Group contents;
+ // the context of the actor (presentation, etc.)
+ public ActorContext context;
+
// timelines
public Clutter.Timeline animation_time { get; set; }
private Clutter.Alpha animation_alpha { get; set; }
@@ -59,9 +62,10 @@ namespace Ease
public const float ZOOM_OUT_SCALE = 0.75f;
public SlideActor.from_slide(Document document, Slide s, bool clip,
- ActorContext context)
+ ActorContext ctx)
{
slide = s;
+ context = ctx;
// clip the actor's bounds
if (clip)
@@ -74,7 +78,8 @@ namespace Ease
{
try
{
- background = new Clutter.Texture.from_file(document.path + slide.background_image);
+ background = new Clutter.Texture.from_file(document.path +
+ slide.background_image);
background.width = document.width;
background.height = document.height;
}
@@ -244,8 +249,10 @@ namespace Ease
new_slide.opacity = 0;
time1 = new Clutter.Timeline(length / 2);
time2 = new Clutter.Timeline(length / 2);
- alpha1 = new Clutter.Alpha.full(time1, Clutter.AnimationMode.EASE_IN_SINE);
- alpha2 = new Clutter.Alpha.full(time2, Clutter.AnimationMode.EASE_OUT_SINE);
+ alpha1 = new Clutter.Alpha.full(time1,
+ Clutter.AnimationMode.EASE_IN_SINE);
+ alpha2 = new Clutter.Alpha.full(time2,
+ Clutter.AnimationMode.EASE_OUT_SINE);
switch (slide.variant)
{
case "Bottom to Top":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]