[the-board] [ui] Add ability to move multiple things at once
- From: Lucas Rocha <lucasr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [the-board] [ui] Add ability to move multiple things at once
- Date: Fri, 14 Jan 2011 01:36:48 +0000 (UTC)
commit 90f69e467ec1995184b0b264a38d451d0345826c
Author: Lucas Rocha <lucasr gnome org>
Date: Thu Jan 13 21:44:08 2011 +0000
[ui] Add ability to move multiple things at once
src/js/ui/page.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/js/ui/thing.js | 7 ----
2 files changed, 89 insertions(+), 7 deletions(-)
---
diff --git a/src/js/ui/page.js b/src/js/ui/page.js
index de2e9ea..78deadd 100644
--- a/src/js/ui/page.js
+++ b/src/js/ui/page.js
@@ -11,6 +11,9 @@ const Clutter = imports.gi.Clutter;
const Background = imports.ui.background;
const Thing = imports.ui.thing;
+// util imports
+const MathUtil = imports.util.mathUtil;
+
// model imports
const PageModel = imports.model.pageModel;
@@ -273,6 +276,10 @@ Page.prototype = {
thing.connect("drag-begin",
Lang.bind(this, this._onThingDragBegin));
+ thing._Page_dragMotionId =
+ thing.connect("drag-motion",
+ Lang.bind(this, this._onThingDragMotion));
+
thing._Page_dragEndId =
thing.connect("drag-end",
Lang.bind(this, this._onThingDragEnd));
@@ -352,6 +359,26 @@ Page.prototype = {
transition: _ADD_THING_TRANSITION });
},
+ _areaUnion : function(area1, area2) {
+ let union = { x1: 0,
+ y1: 0,
+ x2: 0,
+ y2: 0 };
+
+ if (area1 && area2) {
+ union.x1 = Math.min(area1.x1, area2.x1);
+ union.y1 = Math.min(area1.y1, area2.y1);
+ union.x2 = Math.max(area1.x2, area2.x2);
+ union.y2 = Math.max(area1.y2, area2.y2);
+ } else if (area1) {
+ union = area1;
+ } else if (area2) {
+ union = area2;
+ }
+
+ return union;
+ },
+
_updateSelectedThings : function() {
if (this._selectionBox.visible) {
let x1 = this._selectionBox.x - this._selectionBox.anchorX;
@@ -362,10 +389,23 @@ Page.prototype = {
this._selectedThings = this._getThingsInArea(x1, y1, x2, y2);
} else {
this._selectedThings = [];
+ delete this._dragArea;
}
let updateSelection = function(thing) {
thing.selected = this._selectedThings.indexOf(thing) >= 0;
+
+ if (thing.selected) {
+ let state = thing.onGetState();
+
+ let thingArea = { x1: state.x,
+ y1: state.y,
+ x2: state.x + state.width,
+ y2: state.y + state.height };
+
+ this._dragArea =
+ this._areaUnion(this._dragArea, thingArea);
+ }
};
this._things.forEach(Lang.bind(this, updateSelection));
@@ -376,6 +416,17 @@ Page.prototype = {
this._updateSelectedThings();
},
+ _ensureDragArea : function(draggedThing) {
+ if (!this._dragArea) {
+ let state = draggedThing.onGetState();
+
+ this._dragArea = { x1: state.x,
+ y1: state.y,
+ x2: state.x + state.width,
+ y2: state.y + state.height };
+ }
+ },
+
_onMainBoxClicked : function(o, event) {
if (this._cancelSelectionOnClick) {
this._unselectAllThings();
@@ -444,11 +495,48 @@ Page.prototype = {
_onThingDragBegin : function(thing) {
thing.actor.raise(null);
+ this._ensureDragArea(thing);
+
if (this._activeThing && this._activeThing != thing) {
this.setActiveThing(null);
}
},
+ _onThingDragMotion : function(thing, deltaX, deltaY) {
+ let minDeltaX = -this._dragArea.x1;
+ let maxDeltaX = this._mainBox.allocation.x2 -
+ this._mainBox.allocation.x1 -
+ this._dragArea.x2;
+
+ let minDeltaY = -this._dragArea.y1;
+ let maxDeltaY = this._mainBox.allocation.y2 -
+ this._mainBox.allocation.y1 -
+ this._dragArea.y2;
+
+ deltaX = MathUtil.clamp(deltaX, minDeltaX, maxDeltaX);
+ deltaY = MathUtil.clamp(deltaY, minDeltaY, maxDeltaY);
+
+ this._dragArea.x1 += deltaX;
+ this._dragArea.x2 += deltaX;
+ this._dragArea.y1 += deltaY;
+ this._dragArea.y2 += deltaY;
+
+ let moveThing = function(thingToMove) {
+ let state = thingToMove.onGetState();
+
+ let newX = state.x + deltaX;
+ let newY = state.y + deltaY;
+
+ thingToMove.setPosition(newX, newY);
+ };
+
+ if (!thing.selected) {
+ moveThing(thing);
+ }
+
+ this._selectedThings.forEach(moveThing);
+ },
+
_onThingDragEnd : function(thing) {
if (this._activeThing !== thing) {
thing.actor.lower(this._dimBox);
@@ -526,6 +614,7 @@ Page.prototype = {
thing.disconnect(thing._Page_activateId);
thing.disconnect(thing._Page_deactivateId);
thing.disconnect(thing._Page_dragBeginId);
+ thing.disconnect(thing._Page_dragMotionId);
thing.disconnect(thing._Page_dragEndId);
thing.disconnect(thing._Page_removeId);
thing.disconnect(thing._Page_saveId);
diff --git a/src/js/ui/thing.js b/src/js/ui/thing.js
index 5e3781f..ac81684 100644
--- a/src/js/ui/thing.js
+++ b/src/js/ui/thing.js
@@ -320,13 +320,6 @@ Thing.prototype = {
_onMainBoxDragMotion : function(action, actor, deltaX, deltaY) {
Tb.signal_stop_emission_by_name(action, "drag-motion");
-
- let newX = this._mainBox.x + deltaX;
- let newY = this._mainBox.y + deltaY;
-
- this._updatePosition(newX, newY,
- false /* not from state */);
-
this.emit("drag-motion", deltaX, deltaY);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]