diff options
13 files changed, 1094 insertions, 605 deletions
diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp new file mode 100644 index 000000000..e50448ec5 --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#include "unity-mt-grab-handle-group.h" + +unsigned int unity::MT::FADE_MSEC = 0; + +void +unity::MT::GrabHandleGroup::show(unsigned int handles) +{ + for(const unity::MT::GrabHandle::Ptr & handle : mHandles) + if (handles & handle->id ()) + handle->show(); + + mState = State::FADE_IN; +} + +void +unity::MT::GrabHandleGroup::hide() +{ + for(const unity::MT::GrabHandle::Ptr & handle : mHandles) + handle->hide(); + + mState = State::FADE_OUT; +} + +void +unity::MT::GrabHandleGroup::raiseHandle(const boost::shared_ptr <const unity::MT::GrabHandle> &h) +{ + mOwner->raiseGrabHandle (h); +} + +bool +unity::MT::GrabHandleGroup::animate(unsigned int msec) +{ + mMoreAnimate = false; + + switch (mState) + { + case State::FADE_IN: + + mOpacity += ((float) msec / (float) unity::MT::FADE_MSEC) * std::numeric_limits <short>::max (); + + if (mOpacity >= std::numeric_limits <short>::max ()) + { + mOpacity = std::numeric_limits <short>::max (); + mState = State::NONE; + } + break; + case State::FADE_OUT: + mOpacity -= ((float) msec / (float) unity::MT::FADE_MSEC) * std::numeric_limits <short>::max (); + + if (mOpacity <= 0) + { + mOpacity = 0; + mState = State::NONE; + } + break; + default: + break; + } + + mMoreAnimate = mState != State::NONE; + + return mMoreAnimate; +} + +int +unity::MT::GrabHandleGroup::opacity() +{ + return mOpacity; +} + +bool +unity::MT::GrabHandleGroup::visible() +{ + return mOpacity > 0.0f; +} + +bool +unity::MT::GrabHandleGroup::needsAnimate() +{ + return mMoreAnimate; +} + +void +unity::MT::GrabHandleGroup::relayout(const nux::Geometry& rect, bool hard) +{ + /* Each grab handle at each vertex, eg: + * + * 1 - topleft + * 2 - top + * 3 - topright + * 4 - right + * 5 - bottom-right + * 6 - bottom + * 7 - bottom-left + * 8 - left + */ + + const float pos[9][2] = + { + {0.0f, 0.0f}, {0.5f, 0.0f}, {1.0f, 0.0f}, + {1.0f, 0.5f}, {1.0f, 1.0f}, + {0.5f, 1.0f}, {0.0f, 1.0f}, {0.0f, 0.5f}, + {0.5f, 0.5f} /* middle */ + }; + + for (unsigned int i = 0; i < NUM_HANDLES; i++) + { + unity::MT::GrabHandle::Ptr & handle = mHandles.at(i); + + handle->reposition (rect.x + rect.width * pos[i][0] - + handle->width () / 2, + rect.y + rect.height * pos[i][1] - + handle->height () / 2, + unity::MT::PositionSet | (hard ? unity::MT::PositionLock : 0)); + } +} + +unity::MT::GrabHandleGroup::GrabHandleGroup(GrabHandleWindow *owner, + std::vector <unity::MT::TextureSize> &textures) : + mState(State::NONE), + mOpacity(0.0f), + mMoreAnimate(false), + mOwner(owner) +{ +} + +unity::MT::GrabHandleGroup::Ptr +unity::MT::GrabHandleGroup::create (GrabHandleWindow *owner, + std::vector<unity::MT::TextureSize> &textures) +{ + unity::MT::GrabHandleGroup::Ptr p = unity::MT::GrabHandleGroup::Ptr (new unity::MT::GrabHandleGroup (owner, textures)); + for (unsigned int i = 0; i < NUM_HANDLES; i++) + p->mHandles.push_back(unity::MT::GrabHandle::create (textures.at(i).first, + textures.at(i).second.width, + textures.at(i).second.height, + p, + handlesMask.find (i)->second)); + return p; +} + +unity::MT::GrabHandleGroup::~GrabHandleGroup() +{ + for (unity::MT::GrabHandle::Ptr & handle : mHandles) + handle->damage (nux::Geometry (handle->x (), + handle->y (), + handle->width (), + handle->height ())); +} + +void +unity::MT::GrabHandleGroup::requestMovement (int x, + int y, + unsigned int direction, + unsigned int button) +{ + mOwner->requestMovement (x, y, direction, button); +} + +std::vector <unity::MT::TextureLayout> +unity::MT::GrabHandleGroup::layout(unsigned int handles) +{ + std::vector <unity::MT::TextureLayout> layout; + + for(const unity::MT::GrabHandle::Ptr & handle : mHandles) + if (handle->id () & handles) + layout.push_back (handle->layout ()); + + return layout; +} + +void +unity::MT::GrabHandleGroup::forEachHandle (const std::function <void (const unity::MT::GrabHandle::Ptr &)> &f) +{ + for (unity::MT::GrabHandle::Ptr &h : mHandles) + f (h); +} diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.h new file mode 100644 index 000000000..73f9a85db --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _UNITY_MT_GRAB_HANDLE_GROUP_H +#define _UNITY_MT_GRAB_HANDLE_GROUP_H + +#include <Nux/Nux.h> +#include <glib.h> +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/weak_ptr.hpp> + +#include "unity-mt-grab-handle.h" +#include "unity-mt-texture.h" +#include "unity-mt-grab-handle-window.h" + +namespace unity +{ +namespace MT +{ +extern unsigned int FADE_MSEC; + +class GrabHandleGroup : + public boost::enable_shared_from_this <GrabHandleGroup>, + boost::noncopyable +{ +public: + + typedef boost::shared_ptr <GrabHandleGroup> Ptr; + + static GrabHandleGroup::Ptr create (GrabHandleWindow *owner, + std::vector<TextureSize> &textures); + ~GrabHandleGroup(); + + void relayout(const nux::Geometry&, bool); + void restack(); + + bool visible(); + bool animate(unsigned int); + bool needsAnimate(); + + int opacity(); + + void hide(); + void show(unsigned int handles = ~0); + void raiseHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &); + + std::vector <TextureLayout> layout(unsigned int handles); + + void forEachHandle (const std::function<void (const unity::MT::GrabHandle::Ptr &)> &); + + void requestMovement (int x, + int y, + unsigned int direction, + unsigned int button); +private: + + GrabHandleGroup(GrabHandleWindow *owner, + std::vector<TextureSize> &textures); + + enum class State + { + FADE_IN = 1, + FADE_OUT, + NONE + }; + + State mState; + int mOpacity; + + bool mMoreAnimate; + std::vector <unity::MT::GrabHandle::Ptr> mHandles; + GrabHandleWindow *mOwner; +}; +}; +}; + +#endif diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp new file mode 100644 index 000000000..4c698d60d --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#include "unity-mt-grab-handle-impl-factory.h" +#include "unity-mt-grab-handle.h" + +unity::MT::GrabHandle::ImplFactory * unity::MT::GrabHandle::ImplFactory::mDefault = NULL; + +unity::MT::GrabHandle::ImplFactory::ImplFactory () +{ +} + +unity::MT::GrabHandle::ImplFactory::~ImplFactory () +{ +} + +unity::MT::GrabHandle::ImplFactory * +unity::MT::GrabHandle::ImplFactory::Default() +{ + return mDefault; +} + +void +unity::MT::GrabHandle::ImplFactory::SetDefault (ImplFactory *factory) +{ + if (mDefault) + { + delete mDefault; + mDefault = NULL; + } + + mDefault = factory; +} diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.h new file mode 100644 index 000000000..d8989e00f --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _UNITY_MT_GRAB_HANDLE_IMPL_FACTORY_H +#define _UNITY_MT_GRAB_HANDLE_IMPL_FACTORY_H + +#include <Nux/Nux.h> +#include <glib.h> +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/weak_ptr.hpp> + +#include "unity-mt-grab-handle.h" + +namespace unity +{ +namespace MT +{ +class GrabHandle::ImplFactory +{ + public: + + virtual ~ImplFactory(); + + static ImplFactory * + Default(); + + static void + SetDefault(ImplFactory *); + + virtual GrabHandle::Impl * create(const GrabHandle::Ptr &h) = 0; + + protected: + + static ImplFactory *mDefault; + + ImplFactory(); +}; +}; +}; + +#endif diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.cpp new file mode 100644 index 000000000..48fb1b589 --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#include "unity-mt-grab-handle-layout.h" +#include "unity-mt-grab-handle.h" + +unsigned int +unity::MT::getLayoutForMask (unsigned int state, + unsigned int actions) +{ + unsigned int allHandles = 0; + for (unsigned int i = 0; i < NUM_HANDLES; i++) + { + allHandles |= (1 << i); + } + + struct _skipInfo + { + /* All must match in order for skipping to apply */ + unsigned int state; /* Match if in state */ + unsigned int notstate; /* Match if not in state */ + unsigned int actions; /* Match if in actions */ + unsigned int notactions; /* Match if not in actions */ + unsigned int allowOnly; + }; + + const unsigned int numSkipInfo = 5; + const struct _skipInfo skip[5] = + { + /* Vertically maximized, don't care + * about left or right handles, or + * the movement handle */ + { + MaximizedVertMask, + MaximizedHorzMask, + 0, ~0, + LeftHandle | RightHandle | MiddleHandle + }, + /* Horizontally maximized, don't care + * about top or bottom handles, or + * the movement handle */ + { + MaximizedHorzMask, + MaximizedVertMask, + 0, ~0, + TopHandle | BottomHandle | MiddleHandle + }, + /* Maximized, don't care about the movement + * handle */ + { + MaximizedVertMask | MaximizedHorzMask, + 0, 0, ~0, + MiddleHandle + }, + /* Immovable, don't show move handle */ + { + 0, + ~0, + ~0, MoveMask, + TopLeftHandle | TopHandle | TopRightHandle | + LeftHandle | RightHandle | + BottomLeftHandle | BottomHandle | BottomRightHandle + }, + /* Not resizable, don't show resize handle */ + { + 0, + ~0, + ~0, ResizeMask, + MiddleHandle + }, + }; + + for (unsigned int j = 0; j < numSkipInfo; j++) + { + const bool exactState = skip[j].state && skip[j].state != static_cast <unsigned int> (~0); + const bool exactActions = skip[j].actions && skip[j].actions != static_cast <unsigned int> (~0); + + bool stateMatch = false; + bool actionMatch = false; + + if (exactState) + stateMatch = (skip[j].state & state) == skip[j].state; + else + stateMatch = skip[j].state & state; + + stateMatch &= !(state & skip[j].notstate); + + if (exactActions) + actionMatch = (skip[j].actions & actions) == skip[j].actions; + else + actionMatch = skip[j].actions & actions; + + actionMatch &= !(actions & skip[j].notactions); + + if (stateMatch || actionMatch) + allHandles &= skip[j].allowOnly; + } + + return allHandles; +} diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.h new file mode 100644 index 000000000..87589a113 --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-layout.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _UNITY_MT_GRAB_HANDLE_LAYOUT_H +#define _UNITY_MT_GRAB_HANDLE_LAYOUT_H + +namespace unity +{ +namespace MT +{ +extern unsigned int MaximizedVertMask; +extern unsigned int MaximizedHorzMask; +extern unsigned int MoveMask; +extern unsigned int ResizeMask; + +unsigned int getLayoutForMask (unsigned int state, + unsigned int actions); +}; +}; + +#endif diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-window.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-window.h new file mode 100644 index 000000000..24e18da85 --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-window.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _UNITY_MT_GRAB_HANDLE_WINDOW_H +#define _UNITY_MT_GRAB_HANDLE_WINDOW_H + +#include <Nux/Nux.h> + +namespace unity +{ +namespace MT +{ + +class GrabHandle; + +class GrabHandleWindow +{ + public: + + virtual ~GrabHandleWindow () {}; + virtual void requestMovement (int x, + int y, + unsigned int direction, + unsigned int button) = 0; + virtual void raiseGrabHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &) = 0; +}; + +}; +}; + +#endif diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp new file mode 100644 index 000000000..b1cb13349 --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#include "unity-mt-grab-handle.h" +#include "unity-mt-grab-handle-group.h" +#include "unity-mt-grab-handle-window.h" +#include "unity-mt-texture.h" +#include "unity-mt-grab-handle-impl-factory.h" + +void +unity::MT::GrabHandle::buttonPress (int x, + int y, + unsigned int button) const +{ + mImpl->buttonPress (x, y, button); +} + +void +unity::MT::GrabHandle::requestMovement (int x, + int y, + unsigned int button) const +{ + unity::MT::GrabHandleGroup::Ptr ghg = mOwner.lock (); + ghg->requestMovement (x, y, (maskHandles.find (mId))->second, button); +} + +void +unity::MT::GrabHandle::show () +{ + mImpl->show (); +} + +void +unity::MT::GrabHandle::hide () +{ + mImpl->hide (); +} + +void +unity::MT::GrabHandle::raise () const +{ + unity::MT::GrabHandleGroup::Ptr ghg = mOwner.lock (); + boost::shared_ptr <const unity::MT::GrabHandle> gh = shared_from_this (); + ghg->raiseHandle (gh); +} + +void +unity::MT::GrabHandle::reposition(int x, + int y, + unsigned int flags) +{ + damage (mRect); + + if (flags & PositionSet) + { + mRect.x = x; + mRect.y = y; + } + + if (flags & PositionLock) + { + mImpl->lockPosition (x, y, flags); + } + + damage (mRect); +} + +void +unity::MT::GrabHandle::reposition(int x, int y, unsigned int flags) const +{ + if (flags & PositionLock) + { + mImpl->lockPosition (x, y, flags); + } +} + +unity::MT::TextureLayout +unity::MT::GrabHandle::layout() +{ + return TextureLayout(mTexture, mRect); +} + +unity::MT::GrabHandle::GrabHandle(Texture::Ptr texture, + unsigned int width, + unsigned int height, + const boost::shared_ptr <GrabHandleGroup> &owner, + unsigned int id) : + mOwner(owner), + mTexture (texture), + mId(id), + mRect (0, 0, width, height), + mImpl (NULL) +{ +} + +unity::MT::GrabHandle::Ptr +unity::MT::GrabHandle::create (Texture::Ptr texture, unsigned int width, unsigned int height, + const boost::shared_ptr <GrabHandleGroup> &owner, + unsigned int id) +{ + unity::MT::GrabHandle::Ptr p (new unity::MT::GrabHandle (texture, width, height, owner, id)); + p->mImpl = unity::MT::GrabHandle::ImplFactory::Default ()->create (p); + + return p; +} + +unity::MT::GrabHandle::~GrabHandle() +{ + delete mImpl; +} diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.h new file mode 100644 index 000000000..d0221393a --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.h @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _UNITY_MT_GRAB_HANDLE_H +#define _UNITY_MT_GRAB_HANDLE_H + +#include <Nux/Nux.h> +#include <glib.h> +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/enable_shared_from_this.hpp> +#include <boost/weak_ptr.hpp> + +#include "unity-mt-texture.h" +#include "unity-mt-grab-handle-window.h" + +namespace unity +{ +namespace MT +{ + +static const unsigned int NUM_HANDLES = 9; + +/* Update the server side position */ +static const unsigned int PositionLock = (1 << 0); + +/* Update the client side position */ +static const unsigned int PositionSet = (1 << 2); + +static const unsigned int TopLeftHandle = (1 << 0); +static const unsigned int TopHandle = (1 << 1); +static const unsigned int TopRightHandle = (1 << 2); +static const unsigned int RightHandle = (1 << 3); +static const unsigned int BottomRightHandle = (1 << 4); +static const unsigned int BottomHandle = (1 << 5); +static const unsigned int BottomLeftHandle = (1 << 6); +static const unsigned int LeftHandle = (1 << 7); +static const unsigned int MiddleHandle = (1 << 8); + +static const std::map <unsigned int, int> maskHandles = { + { TopLeftHandle, 0 }, + { TopHandle, 1 }, + { TopRightHandle, 2 }, + { RightHandle, 3 }, + { BottomRightHandle, 4}, + { BottomHandle, 5 }, + { BottomLeftHandle, 6 }, + { LeftHandle, 7 }, + { MiddleHandle, 8 } +}; + +static const std::map <int, unsigned int> handlesMask = { + { 0, TopLeftHandle }, + { 1, TopHandle }, + { 2, TopRightHandle }, + { 3, RightHandle }, + { 4, BottomRightHandle}, + { 5, BottomHandle }, + { 6, BottomLeftHandle }, + { 7, LeftHandle }, + { 8, MiddleHandle } +}; + +class GrabHandleGroup; + +class GrabHandle : + public boost::enable_shared_from_this <GrabHandle>, + boost::noncopyable +{ +public: + + typedef boost::shared_ptr <GrabHandle> Ptr; + + static GrabHandle::Ptr create (Texture::Ptr texture, + unsigned int width, + unsigned int height, + const boost::shared_ptr <GrabHandleGroup> &owner, + unsigned int id); + ~GrabHandle(); + + bool operator== (const GrabHandle &other) const + { + return mId == other.mId; + } + + bool operator!= (const GrabHandle &other) const + { + return !(*this == other); + } + + void buttonPress (int x, + int y, + unsigned int button) const; + + void requestMovement (int x, + int y, + unsigned int button) const; + + void reposition(int x, + int y, + unsigned int flags); + void reposition(int x, int y, unsigned int flags) const; + + void show(); + void hide(); + void raise() const; + + TextureLayout layout(); + + unsigned int id () const { return mId; } + unsigned int width () const { return mRect.width; } + unsigned int height () const { return mRect.height; } + int x () const { return mRect.x; } + int y () const { return mRect.y; } + + void damage (const nux::Geometry &g) const { mImpl->damage (g); } + +public: + + class Impl : + boost::noncopyable + { + public: + + virtual ~Impl () {}; + + virtual void show () = 0; + virtual void hide () = 0; + + virtual void buttonPress (int x, + int y, + unsigned int button) const = 0; + + virtual void lockPosition (int x, + int y, + unsigned int flags) = 0; + + virtual void damage (const nux::Geometry &g) = 0; + }; + + class ImplFactory; + +private: + + GrabHandle(Texture::Ptr texture, + unsigned int width, + unsigned int height, + const boost::shared_ptr <GrabHandleGroup> &owner, + unsigned int id); + + boost::weak_ptr <GrabHandleGroup> mOwner; + Texture::Ptr mTexture; + unsigned int mId; + nux::Geometry mRect; + Impl *mImpl; +}; +}; +}; + +#endif diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp index baae39d40..39732df66 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.cpp @@ -19,37 +19,43 @@ #include "unity-mt-grab-handles.h" #include <iostream> -#define NUM_HANDLES 9 -#define FADE_MSEC UnityMTGrabHandlesScreen::get (screen)->optionGetFadeDuration () - COMPIZ_PLUGIN_20090315(unitymtgrabhandles, UnityMTGrabHandlesPluginVTable); -unity::MT::GrabHandle::ImplFactory * unity::MT::GrabHandle::ImplFactory::mDefault = NULL; +unsigned int unity::MT::MaximizedHorzMask = CompWindowStateMaximizedHorzMask; +unsigned int unity::MT::MaximizedVertMask = CompWindowStateMaximizedVertMask; +unsigned int unity::MT::MoveMask = CompWindowActionMoveMask; +unsigned int unity::MT::ResizeMask = CompWindowActionResizeMask; -unity::MT::GrabHandle::ImplFactory::ImplFactory () +unity::MT::X11TextureFactory::X11TextureFactory () : + Factory () { } -unity::MT::GrabHandle::ImplFactory::~ImplFactory () +unity::MT::X11TextureFactory::~X11TextureFactory () { } -unity::MT::GrabHandle::ImplFactory * -unity::MT::GrabHandle::ImplFactory::Default() +void +unity::MT::X11TextureFactory::setActiveWrap (const GLTexture::List &t) { - return mDefault; + mWrap = t; } -void -unity::MT::GrabHandle::ImplFactory::SetDefault (ImplFactory *factory) +unity::MT::Texture::Ptr +unity::MT::X11TextureFactory::create () { - if (mDefault) - { - delete mDefault; - mDefault = NULL; - } + return boost::shared_static_cast <unity::MT::Texture> (unity::MT::X11Texture::Ptr (new unity::MT::X11Texture (mWrap))); +} - mDefault = factory; +unity::MT::X11Texture::X11Texture (const GLTexture::List &t) +{ + mTexture = t; +} + +const GLTexture::List & +unity::MT::X11Texture::get () +{ + return mTexture; } unity::MT::X11ImplFactory::X11ImplFactory (Display *dpy) : @@ -158,221 +164,6 @@ unity::MT::X11GrabHandleImpl::buttonPress (int x, } void -unity::MT::GrabHandle::buttonPress (int x, - int y, - unsigned int button) const -{ - mImpl->buttonPress (x, y, button); -} - -void -unity::MT::GrabHandle::requestMovement (int x, - int y, - unsigned int button) const -{ - unity::MT::GrabHandleGroup::Ptr ghg = mOwner.lock (); - ghg->requestMovement (x, y, (maskHandles.find (mId))->second, button); -} - -void -unity::MT::GrabHandle::show () -{ - mImpl->show (); -} - -void -unity::MT::GrabHandle::hide () -{ - mImpl->hide (); -} - -void -unity::MT::GrabHandle::raise () const -{ - unity::MT::GrabHandleGroup::Ptr ghg = mOwner.lock (); - boost::shared_ptr <const unity::MT::GrabHandle> gh = shared_from_this (); - ghg->raiseHandle (gh); -} - -void -unity::MT::GrabHandle::reposition(int x, - int y, - unsigned int flags) -{ - damage (mRect); - - if (flags & PositionSet) - { - mRect.x = x; - mRect.y = y; - } - - if (flags & PositionLock) - { - mImpl->lockPosition (x, y, flags); - } - - damage (mRect); -} - -void -unity::MT::GrabHandle::reposition(int x, int y, unsigned int flags) const -{ - if (flags & PositionLock) - { - mImpl->lockPosition (x, y, flags); - } -} - -unity::MT::TextureLayout -unity::MT::GrabHandle::layout() -{ - return TextureLayout(mTexture, mRect); -} - -unity::MT::GrabHandle::GrabHandle(GLTexture::List *texture, - unsigned int width, - unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, - unsigned int id) : - mOwner(owner), - mTexture (texture), - mId(id), - mRect (0, 0, width, height), - mImpl (NULL) -{ -} - -unity::MT::GrabHandle::Ptr -unity::MT::GrabHandle::create (GLTexture::List *texture, unsigned int width, unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, - unsigned int id) -{ - unity::MT::GrabHandle::Ptr p (new unity::MT::GrabHandle (texture, width, height, owner, id)); - p->mImpl = unity::MT::GrabHandle::ImplFactory::Default ()->create (p); - - return p; -} - -unity::MT::GrabHandle::~GrabHandle() -{ - delete mImpl; -} - -void -unity::MT::GrabHandleGroup::show(unsigned int handles) -{ - for(const unity::MT::GrabHandle::Ptr & handle : mHandles) - if (handles & handle->id ()) - handle->show(); - - mState = State::FADE_IN; -} - -void -unity::MT::GrabHandleGroup::hide() -{ - for(const unity::MT::GrabHandle::Ptr & handle : mHandles) - handle->hide(); - - mState = State::FADE_OUT; -} - -void -unity::MT::GrabHandleGroup::raiseHandle(const boost::shared_ptr <const unity::MT::GrabHandle> &h) -{ - mOwner->raiseGrabHandle (h); -} - -bool -unity::MT::GrabHandleGroup::animate(unsigned int msec) -{ - mMoreAnimate = false; - - switch (mState) - { - case State::FADE_IN: - - mOpacity += ((float) msec / (float) FADE_MSEC) * OPAQUE; - - if (mOpacity >= OPAQUE) - { - mOpacity = OPAQUE; - mState = State::NONE; - } - break; - case State::FADE_OUT: - mOpacity -= ((float) msec / (float) FADE_MSEC) * OPAQUE; - - if (mOpacity <= 0) - { - mOpacity = 0; - mState = State::NONE; - } - break; - default: - break; - } - - mMoreAnimate = mState != State::NONE; - - return mMoreAnimate; -} - -int -unity::MT::GrabHandleGroup::opacity() -{ - return mOpacity; -} - -bool -unity::MT::GrabHandleGroup::visible() -{ - return mOpacity > 0.0f; -} - -bool -unity::MT::GrabHandleGroup::needsAnimate() -{ - return mMoreAnimate; -} - -void -unity::MT::GrabHandleGroup::relayout(const nux::Geometry& rect, bool hard) -{ - /* Each grab handle at each vertex, eg: - * - * 1 - topleft - * 2 - top - * 3 - topright - * 4 - right - * 5 - bottom-right - * 6 - bottom - * 7 - bottom-left - * 8 - left - */ - - const float pos[9][2] = - { - {0.0f, 0.0f}, {0.5f, 0.0f}, {1.0f, 0.0f}, - {1.0f, 0.5f}, {1.0f, 1.0f}, - {0.5f, 1.0f}, {0.0f, 1.0f}, {0.0f, 0.5f}, - {0.5f, 0.5f} /* middle */ - }; - - for (unsigned int i = 0; i < NUM_HANDLES; i++) - { - unity::MT::GrabHandle::Ptr & handle = mHandles.at(i); - CompPoint p(rect.x + rect.width * pos[i][0] - - handle->width () / 2, - rect.y + rect.height * pos[i][1] - - handle->height () / 2); - - handle->reposition (p.x (), p.y (), unity::MT::PositionSet | (hard ? unity::MT::PositionLock : 0)); - } -} - -void UnityMTGrabHandlesWindow::raiseGrabHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &h) { UnityMTGrabHandlesScreen::get (screen)->raiseHandle (h, window->frame ()); @@ -416,161 +207,6 @@ UnityMTGrabHandlesWindow::requestMovement (int x, &event); } -unity::MT::GrabHandleGroup::GrabHandleGroup(GrabHandleWindow *owner, - std::vector <unity::MT::TextureSize> &textures) : - mState(State::NONE), - mOpacity(0.0f), - mMoreAnimate(false), - mOwner(owner) -{ -} - -unity::MT::GrabHandleGroup::Ptr -unity::MT::GrabHandleGroup::create (GrabHandleWindow *owner, - std::vector<unity::MT::TextureSize> &textures) -{ - unity::MT::GrabHandleGroup::Ptr p = unity::MT::GrabHandleGroup::Ptr (new unity::MT::GrabHandleGroup (owner, textures)); - for (unsigned int i = 0; i < NUM_HANDLES; i++) - p->mHandles.push_back(unity::MT::GrabHandle::create (textures.at(i).first, - textures.at(i).second.width, - textures.at(i).second.height, - p, - handlesMask.find (i)->second)); - return p; -} - -unity::MT::GrabHandleGroup::~GrabHandleGroup() -{ - for (unity::MT::GrabHandle::Ptr & handle : mHandles) - handle->damage (nux::Geometry (handle->x (), - handle->y (), - handle->width (), - handle->height ())); -} - -void -unity::MT::GrabHandleGroup::requestMovement (int x, - int y, - unsigned int direction, - unsigned int button) -{ - mOwner->requestMovement (x, y, direction, button); -} - -unsigned int -unity::MT::getLayoutForMask (unsigned int state, - unsigned int actions) -{ - unsigned int allHandles = 0; - for (unsigned int i = 0; i < NUM_HANDLES; i++) - { - allHandles |= (1 << i); - } - - struct _skipInfo - { - /* All must match in order for skipping to apply */ - unsigned int state; /* Match if in state */ - unsigned int notstate; /* Match if not in state */ - unsigned int actions; /* Match if in actions */ - unsigned int notactions; /* Match if not in actions */ - unsigned int allowOnly; - }; - - const unsigned int numSkipInfo = 5; - const struct _skipInfo skip[5] = - { - /* Vertically maximized, don't care - * about left or right handles, or - * the movement handle */ - { - CompWindowStateMaximizedVertMask, - CompWindowStateMaximizedHorzMask, - 0, ~0, - LeftHandle | RightHandle | MiddleHandle - }, - /* Horizontally maximized, don't care - * about top or bottom handles, or - * the movement handle */ - { - CompWindowStateMaximizedHorzMask, - CompWindowStateMaximizedVertMask, - 0, ~0, - TopHandle | BottomHandle | MiddleHandle - }, - /* Maximized, don't care about the movement - * handle */ - { - CompWindowStateMaximizedVertMask | CompWindowStateMaximizedHorzMask, - 0, 0, ~0, - MiddleHandle - }, - /* Immovable, don't show move handle */ - { - 0, - ~0, - ~0, CompWindowActionMoveMask, - TopLeftHandle | TopHandle | TopRightHandle | - LeftHandle | RightHandle | - BottomLeftHandle | BottomHandle | BottomRightHandle - }, - /* Not resizable, don't show resize handle */ - { - 0, - ~0, - ~0, CompWindowActionResizeMask, - MiddleHandle - }, - }; - - for (unsigned int j = 0; j < numSkipInfo; j++) - { - const bool exactState = skip[j].state && skip[j].state != static_cast <unsigned int> (~0); - const bool exactActions = skip[j].actions && skip[j].actions != static_cast <unsigned int> (~0); - - bool stateMatch = false; - bool actionMatch = false; - - if (exactState) - stateMatch = (skip[j].state & state) == skip[j].state; - else - stateMatch = skip[j].state & state; - - stateMatch &= !(state & skip[j].notstate); - - if (exactActions) - actionMatch = (skip[j].actions & actions) == skip[j].actions; - else - actionMatch = skip[j].actions & actions; - - actionMatch &= !(actions & skip[j].notactions); - - if (stateMatch || actionMatch) - allHandles &= skip[j].allowOnly; - } - - return allHandles; -} - -std::vector <unity::MT::TextureLayout> -unity::MT::GrabHandleGroup::layout(unsigned int handles) -{ - std::vector <unity::MT::TextureLayout> layout; - - for(const unity::MT::GrabHandle::Ptr & handle : mHandles) - if (handle->id () & handles) - layout.push_back (handle->layout ()); - - return layout; -} - -void -unity::MT::GrabHandleGroup::forEachHandle (const std::function <void (const unity::MT::GrabHandle::Ptr &)> &f) -{ - for (unity::MT::GrabHandle::Ptr &h : mHandles) - f (h); -} - /* Super speed hack */ static bool sortPointers(void *p1, void *p2) @@ -836,7 +472,7 @@ UnityMTGrabHandlesWindow::glDraw(const GLMatrix& transform, * region */ CompRegion reg = CompRegion(layout.second.x, layout.second.y, layout.second.width, layout.second.height); - for(GLTexture * tex : *layout.first) + for(GLTexture * tex : boost::shared_static_cast <unity::MT::X11Texture> (layout.first)->get ()) { GLTexture::MatrixList matl; GLTexture::Matrix mat = tex->matrix(); @@ -1113,6 +749,16 @@ UnityMTGrabHandlesScreen::hideHandles(CompAction* action, return true; } +void +UnityMTGrabHandlesScreen::optionChanged (CompOption *option, + UnitymtgrabhandlesOptions::Options num) +{ + if (num == UnitymtgrabhandlesOptions::FadeDuration) + { + unity::MT::FADE_MSEC = optionGetFadeDuration (); + } +} + UnityMTGrabHandlesScreen::UnityMTGrabHandlesScreen(CompScreen* s) : PluginClassHandler <UnityMTGrabHandlesScreen, CompScreen> (s), cScreen(CompositeScreen::get(s)), @@ -1125,39 +771,42 @@ UnityMTGrabHandlesScreen::UnityMTGrabHandlesScreen(CompScreen* s) : mMoreAnimate(false) { unity::MT::GrabHandle::ImplFactory::SetDefault (new unity::MT::X11ImplFactory (screen->dpy ())); + unity::MT::Texture::Factory::SetDefault (new unity::MT::X11TextureFactory ()); ScreenInterface::setHandler(s); CompositeScreenInterface::setHandler(cScreen); GLScreenInterface::setHandler(gScreen); - mHandleTextures.resize(NUM_HANDLES); + mHandleTextures.resize(unity::MT::NUM_HANDLES); - for (unsigned int i = 0; i < NUM_HANDLES; i++) + for (unsigned int i = 0; i < unity::MT::NUM_HANDLES; i++) { CompString fname = "handle-"; CompString pname("unitymtgrabhandles"); CompSize size; fname = compPrintf("%s%i.png", fname.c_str(), i); - mHandleTextures.at(i).first = - new GLTexture::List (GLTexture::readImageToTexture(fname, pname, - size)); + GLTexture::List t = GLTexture::readImageToTexture(fname, pname, + size); + (static_cast <unity::MT::X11TextureFactory *> (unity::MT::Texture::Factory::Default ()))->setActiveWrap (t); + + mHandleTextures.at(i).first = unity::MT::Texture::Factory::Default ()->create (); mHandleTextures.at (i).second.width = size.width (); mHandleTextures.at (i).second.height = size.height (); } + unity::MT::FADE_MSEC = optionGetFadeDuration (); + optionSetToggleHandlesKeyInitiate(boost::bind(&UnityMTGrabHandlesScreen::toggleHandles, this, _1, _2, _3)); optionSetShowHandlesKeyInitiate(boost::bind(&UnityMTGrabHandlesScreen::showHandles, this, _1, _2, _3)); optionSetHideHandlesKeyInitiate(boost::bind(&UnityMTGrabHandlesScreen::hideHandles, this, _1, _2, _3)); + optionSetFadeDurationNotify(boost::bind(&UnityMTGrabHandlesScreen::optionChanged, this, _1, _2)); } UnityMTGrabHandlesScreen::~UnityMTGrabHandlesScreen() { mGrabHandles.clear (); - for (auto it : mHandleTextures) - if (it.first) - delete it.first; } UnityMTGrabHandlesWindow::UnityMTGrabHandlesWindow(CompWindow* w) : diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h index ebff8ac57..88b0a906b 100644 --- a/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h +++ b/plugins/unity-mt-grab-handles/src/unity-mt-grab-handles.h @@ -28,14 +28,19 @@ #include <core/atoms.h> +#include "unity-mt-texture.h" +#include "unity-mt-grab-handle.h" +#include "unity-mt-grab-handle-group.h" +#include "unity-mt-grab-handle-window.h" +#include "unity-mt-grab-handle-impl-factory.h" +#include "unity-mt-grab-handle-layout.h" + #include "unitymtgrabhandles_options.h" namespace unity { namespace MT { -typedef std::pair <GLTexture::List*, nux::Geometry> TextureSize; -typedef std::pair <GLTexture::List*, nux::Geometry> TextureLayout; class DummyDamager { @@ -48,160 +53,36 @@ public: } }; -/* Update the server side position */ -static const unsigned int PositionLock = (1 << 0); - -/* Update the client side position */ -static const unsigned int PositionSet = (1 << 2); - -static const unsigned int TopLeftHandle = (1 << 0); -static const unsigned int TopHandle = (1 << 1); -static const unsigned int TopRightHandle = (1 << 2); -static const unsigned int RightHandle = (1 << 3); -static const unsigned int BottomRightHandle = (1 << 4); -static const unsigned int BottomHandle = (1 << 5); -static const unsigned int BottomLeftHandle = (1 << 6); -static const unsigned int LeftHandle = (1 << 7); -static const unsigned int MiddleHandle = (1 << 8); - -static const std::map <unsigned int, int> maskHandles = { - { TopLeftHandle, 0 }, - { TopHandle, 1 }, - { TopRightHandle, 2 }, - { RightHandle, 3 }, - { BottomRightHandle, 4}, - { BottomHandle, 5 }, - { BottomLeftHandle, 6 }, - { LeftHandle, 7 }, - { MiddleHandle, 8 } -}; - -static const std::map <int, unsigned int> handlesMask = { - { 0, TopLeftHandle }, - { 1, TopHandle }, - { 2, TopRightHandle }, - { 3, RightHandle }, - { 4, BottomRightHandle}, - { 5, BottomHandle }, - { 6, BottomLeftHandle }, - { 7, LeftHandle }, - { 8, MiddleHandle } -}; - -unsigned int getLayoutForMask (unsigned int state, - unsigned int actions); - -class GrabHandleGroup; - -class GrabHandle : - public boost::enable_shared_from_this <GrabHandle>, - boost::noncopyable +class X11TextureFactory : + public Texture::Factory { -public: - - typedef boost::shared_ptr <GrabHandle> Ptr; - - static GrabHandle::Ptr create (GLTexture::List *texture, - unsigned int width, - unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, - unsigned int id); - ~GrabHandle(); - - bool operator== (const GrabHandle &other) const - { - return mId == other.mId; - } - - bool operator!= (const GrabHandle &other) const - { - return !(*this == other); - } - - void buttonPress (int x, - int y, - unsigned int button) const; - - void requestMovement (int x, - int y, - unsigned int button) const; - - void reposition(int x, - int y, - unsigned int flags); - void reposition(int x, int y, unsigned int flags) const; - - void show(); - void hide(); - void raise() const; - - TextureLayout layout(); - - unsigned int id () const { return mId; } - unsigned int width () const { return mRect.width; } - unsigned int height () const { return mRect.height; } - int x () const { return mRect.x; } - int y () const { return mRect.y; } - - void damage (const nux::Geometry &g) const { mImpl->damage (g); } - -public: - - class Impl : - boost::noncopyable - { - public: - - virtual ~Impl () {}; - - virtual void show () = 0; - virtual void hide () = 0; - - virtual void buttonPress (int x, - int y, - unsigned int button) const = 0; - - virtual void lockPosition (int x, - int y, - unsigned int flags) = 0; - - virtual void damage (const nux::Geometry &g) = 0; - }; + public: + X11TextureFactory (); + ~X11TextureFactory (); - class ImplFactory - { - public: + void setActiveWrap (const GLTexture::List &); - virtual ~ImplFactory(); + Texture::Ptr create (); - static ImplFactory * - Default(); + private: - static void - SetDefault(ImplFactory *); + GLTexture::List mWrap; +}; - virtual GrabHandle::Impl * create(const GrabHandle::Ptr &h) = 0; +class X11Texture : + public Texture +{ + public: - protected: + typedef boost::shared_ptr <X11Texture> Ptr; - static ImplFactory *mDefault; + X11Texture (const GLTexture::List &t); - ImplFactory(); - }; + const GLTexture::List & get (); -private: + private: - GrabHandle(GLTexture::List *texture, - unsigned int width, - unsigned int height, - const boost::shared_ptr <GrabHandleGroup> &owner, - unsigned int id); - - boost::weak_ptr <GrabHandleGroup> mOwner; - GLTexture::List *mTexture; - unsigned int mId; - nux::Geometry mRect; - Impl *mImpl; + GLTexture::List mTexture; }; class X11ImplFactory : @@ -251,70 +132,6 @@ private: Display *mDpy; }; -class GrabHandleWindow -{ - public: - - virtual ~GrabHandleWindow () {}; - virtual void requestMovement (int x, - int y, - unsigned int direction, - unsigned int button) = 0; - virtual void raiseGrabHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &) = 0; -}; - -class GrabHandleGroup : - public boost::enable_shared_from_this <GrabHandleGroup>, - boost::noncopyable -{ -public: - - typedef boost::shared_ptr <GrabHandleGroup> Ptr; - - static GrabHandleGroup::Ptr create (GrabHandleWindow *owner, - std::vector<TextureSize> &textures); - ~GrabHandleGroup(); - - void relayout(const nux::Geometry&, bool); - void restack(); - - bool visible(); - bool animate(unsigned int); - bool needsAnimate(); - - int opacity(); - - void hide(); - void show(unsigned int handles = ~0); - void raiseHandle (const boost::shared_ptr <const unity::MT::GrabHandle> &); - - std::vector <TextureLayout> layout(unsigned int handles); - - void forEachHandle (const std::function<void (const unity::MT::GrabHandle::Ptr &)> &); - - void requestMovement (int x, - int y, - unsigned int direction, - unsigned int button); -private: - - GrabHandleGroup(GrabHandleWindow *owner, - std::vector<TextureSize> &textures); - - enum class State - { - FADE_IN = 1, - FADE_OUT, - NONE - }; - - State mState; - int mOpacity; - - bool mMoreAnimate; - std::vector <unity::MT::GrabHandle::Ptr> mHandles; - GrabHandleWindow *mOwner; -}; }; }; @@ -349,6 +166,9 @@ public: CompAction::State state, CompOption::Vector& options); + void optionChanged (CompOption *option, + UnitymtgrabhandlesOptions::Options num); + void addHandles(const unity::MT::GrabHandleGroup::Ptr & handles); void removeHandles(const unity::MT::GrabHandleGroup::Ptr & handles); diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp b/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp new file mode 100644 index 000000000..d4435c8de --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-texture.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#include "unity-mt-texture.h" + +unity::MT::Texture::Factory * unity::MT::Texture::Factory::mDefault = NULL; + +unity::MT::Texture::Factory::Factory () +{ +} + +unity::MT::Texture::Factory::~Factory () +{ +} + +void +unity::MT::Texture::Factory::SetDefault (Factory *f) +{ + if (mDefault) + { + delete mDefault; + mDefault = NULL; + } + + mDefault = f; +} + +unity::MT::Texture::Factory * +unity::MT::Texture::Factory::Default () +{ + return mDefault; +} + +unity::MT::Texture::Texture () +{ +} + +unity::MT::Texture::~Texture () +{ +} diff --git a/plugins/unity-mt-grab-handles/src/unity-mt-texture.h b/plugins/unity-mt-grab-handles/src/unity-mt-texture.h new file mode 100644 index 000000000..a72d883ea --- /dev/null +++ b/plugins/unity-mt-grab-handles/src/unity-mt-texture.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _UNITY_MT_GRAB_HANDLES_TEXTURE_H +#define _UNITY_MT_GRAB_HANDLES_TEXTURE_H + +#include <Nux/Nux.h> +#include <boost/noncopyable.hpp> + +namespace unity +{ +namespace MT +{ +class Texture +{ + public: + + typedef boost::shared_ptr <Texture> Ptr; + + virtual ~Texture (); + + class Factory : + boost::noncopyable + { + public: + + virtual ~Factory (); + + virtual unity::MT::Texture::Ptr + create () = 0; + + static void + SetDefault (Factory *); + + static Factory * + Default (); + + protected: + + Factory (); + + private: + + static Factory *mDefault; + }; + + protected: + + Texture (); +}; + + +typedef std::pair <Texture::Ptr, nux::Geometry> TextureSize; +typedef std::pair <Texture::Ptr, nux::Geometry> TextureLayout; + +}; +}; + +#endif |
