summaryrefslogtreecommitdiff
path: root/src
diff options
authorJason Smith <jason.smith@canonical.com>2010-12-16 02:02:03 -0500
committerJason Smith <jason.smith@canonical.com>2010-12-16 02:02:03 -0500
commita7aa47249d64ccc8280ffc171358808ef5523945 (patch)
tree45d143f67f5ab476976e5fec43b16c00a00a14e3 /src
parent65d9fe8215b5f83d0e17922b30b07c229d6da5ca (diff)
animate drag window back into place on launcher... sexy :)
(bzr r712.1.1)
Diffstat (limited to 'src')
-rw-r--r--src/Launcher.cpp29
-rw-r--r--src/Launcher.h3
-rw-r--r--src/LauncherDragWindow.cpp58
-rw-r--r--src/LauncherDragWindow.h18
4 files changed, 91 insertions, 17 deletions
diff --git a/src/Launcher.cpp b/src/Launcher.cpp
index 4edd815fc..f8531d7ce 100644
--- a/src/Launcher.cpp
+++ b/src/Launcher.cpp
@@ -245,7 +245,6 @@ Launcher::Launcher(nux::BaseWindow *parent, CompScreen *screen, NUX_FILE_LINE_DE
_icon_under_mouse = NULL;
_icon_mouse_down = NULL;
_drag_icon = NULL;
- _drag_icon_under_mouse = NULL;
_icon_image_size = 48;
_icon_glow_size = 62;
_icon_image_size_delta = 6;
@@ -334,6 +333,8 @@ void Launcher::SetMousePosition (int x, int y)
bool Launcher::MouseBeyondDragThreshold ()
{
+ if (_launcher_action_state != ACTION_DRAG_ICON)
+ return false;
return _mouse_position.x > GetGeometry ().width + _icon_size / 2;
}
@@ -703,7 +704,9 @@ void Launcher::FillRenderArg (LauncherIcon *icon,
{
if (MouseBeyondDragThreshold ())
arg.stick_thingy = true;
- arg.skip = true;
+
+ if (_launcher_action_state == ACTION_DRAG_ICON || (_drag_window && _drag_window->Animating ()))
+ arg.skip = true;
size_modifier *= DragThresholdProgress (current);
}
@@ -742,6 +745,9 @@ void Launcher::FillRenderArg (LauncherIcon *icon,
icon->SetCenter (nux::Point3 (roundf (center.x), roundf (center.y), roundf (center.z)));
+ if (icon == _drag_icon && _drag_window && _drag_window->Animating ())
+ _drag_window->SetAnimationTarget ((int) center.x, (int) center.y + _parent->GetGeometry ().y);
+
center.y += (half_size * size_modifier) + spacing; // move to end
}
@@ -1593,6 +1599,14 @@ void Launcher::PositionChildLayout(float offsetX, float offsetY)
{
}
+void Launcher::OnDragWindowAnimCompleted ()
+{
+ if (_drag_window)
+ _drag_window->ShowWindow (false);
+
+ EnsureAnimation ();
+}
+
void Launcher::StartIconDrag (LauncherIcon *icon)
{
if (!icon)
@@ -1618,13 +1632,14 @@ void Launcher::EndIconDrag ()
{
if (_drag_window)
{
- _drag_window->ShowWindow (false);
- _drag_window->UnReference ();
- _drag_window = NULL;
+ _drag_window->SetAnimationTarget ((int) (_drag_icon->GetCenter ().x), (int) (_drag_icon->GetCenter ().y));
+ _drag_window->StartAnimation ();
+ _drag_window->anim_completed.connect (sigc::mem_fun (this, &Launcher::OnDragWindowAnimCompleted));
}
- _drag_icon_under_mouse = NULL;
- _drag_icon = NULL;
+ if (MouseBeyondDragThreshold ())
+ SetTimeStruct (&_drag_threshold_time, &_drag_threshold_time, ANIM_DURATION_SHORT);
+
_render_drag_window = false;
}
diff --git a/src/Launcher.h b/src/Launcher.h
index 1a73969f8..b759683c5 100644
--- a/src/Launcher.h
+++ b/src/Launcher.h
@@ -125,6 +125,7 @@ private:
bool MouseBeyondDragThreshold ();
+ void OnDragWindowAnimCompleted ();
void OnTriggerMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags);
void OnTriggerMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags);
@@ -248,9 +249,7 @@ private:
LauncherIcon* _icon_under_mouse;
LauncherIcon* _icon_mouse_down;
-
LauncherIcon* _drag_icon;
- LauncherIcon* _drag_icon_under_mouse;
int _space_between_icons;
int _icon_size;
diff --git a/src/LauncherDragWindow.cpp b/src/LauncherDragWindow.cpp
index 75935575c..7fe189e63 100644
--- a/src/LauncherDragWindow.cpp
+++ b/src/LauncherDragWindow.cpp
@@ -29,18 +29,72 @@ LauncherDragWindow::LauncherDragWindow (nux::IntrusiveSP<nux::IOpenGLBaseTexture
: nux::BaseWindow ("")
{
_icon = icon;
+ _anim_handle = 0;
SetBaseSize (_icon->GetWidth(), _icon->GetHeight());
}
LauncherDragWindow::~LauncherDragWindow ()
{
+ if (_anim_handle)
+ g_source_remove (_anim_handle);
}
-void LauncherDragWindow::Draw (nux::GraphicsEngine& GfxContext, bool forceDraw)
+bool
+LauncherDragWindow::Animating ()
{
+ return _anim_handle != 0;
}
-void LauncherDragWindow::DrawContent (nux::GraphicsEngine& GfxContext, bool force_draw)
+void
+LauncherDragWindow::SetAnimationTarget (int x, int y)
+{
+ _animation_target = nux::Point2 (x, y);
+}
+
+void
+LauncherDragWindow::StartAnimation ()
+{
+ if (_anim_handle)
+ return;
+
+ _anim_handle = g_timeout_add (15, &LauncherDragWindow::OnAnimationTimeout, this);
+}
+
+gboolean
+LauncherDragWindow::OnAnimationTimeout (gpointer data)
+{
+ LauncherDragWindow *self = (LauncherDragWindow*) data;
+ nux::Geometry geo = self->GetGeometry ();
+
+ int half_size = geo.width / 2;
+
+ int target_x = (int) (self->_animation_target.x) - half_size;
+ int target_y = (int) (self->_animation_target.y) - half_size;
+
+ int x_delta = (int) ((float) (target_x - geo.x) * .3f);
+ if (abs (x_delta) < 5)
+ x_delta = (x_delta >= 0) ? MIN (5, target_x - geo.x) : MAX (-5, target_x - geo.x);
+
+ int y_delta = (int) ((float) (target_y - geo.y) * .3f);
+ if (abs (y_delta) < 5)
+ y_delta = (y_delta >= 0) ? MIN (5, target_y - geo.y) : MAX (-5, target_y - geo.y);
+
+ self->SetBaseXY (geo.x + x_delta, geo.y + y_delta);
+
+ geo = self->GetGeometry ();
+
+ if (geo.x == target_x && geo.y == target_y)
+ {
+ self->anim_completed.emit ();
+ self->_anim_handle = 0;
+ return false;
+ }
+
+ return true;
+}
+
+void
+LauncherDragWindow::DrawContent (nux::GraphicsEngine& GfxContext, bool force_draw)
{
nux::Geometry geo = GetGeometry ();
geo.SetX (0);
diff --git a/src/LauncherDragWindow.h b/src/LauncherDragWindow.h
index e502f0a29..9e4853834 100644
--- a/src/LauncherDragWindow.h
+++ b/src/LauncherDragWindow.h
@@ -33,16 +33,22 @@ public:
~LauncherDragWindow ();
- void Draw (nux::GraphicsEngine& gfxContext,
- bool forceDraw);
-
- void DrawContent (nux::GraphicsEngine& gfxContext,
- bool forceDraw);
+ void DrawContent (nux::GraphicsEngine& gfxContext, bool forceDraw);
+
+ void SetAnimationTarget (int x, int y);
+ void StartAnimation ();
+
+ bool Animating ();
+
+ sigc::signal<void> anim_completed;
private:
- nux::IntrusiveSP<nux::IOpenGLBaseTexture> _icon;
+ static gboolean OnAnimationTimeout (gpointer data);
+ nux::IntrusiveSP<nux::IOpenGLBaseTexture> _icon;
+ nux::Point2 _animation_target;
+ guint32 _anim_handle;
};