Back to index

unity  6.0.0
unity-mt-grab-handle.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
00017  */
00018 
00019 #ifndef _UNITY_MT_GRAB_HANDLE_H
00020 #define _UNITY_MT_GRAB_HANDLE_H
00021 
00022 #include <Nux/Nux.h>
00023 #include <glib.h>
00024 #include <boost/noncopyable.hpp>
00025 #include <boost/shared_ptr.hpp>
00026 #include <boost/enable_shared_from_this.hpp>
00027 #include <boost/weak_ptr.hpp>
00028 
00029 #include "unity-mt-texture.h"
00030 #include "unity-mt-grab-handle-window.h"
00031 
00032 namespace unity
00033 {
00034 namespace MT
00035 {
00036 
00037 static const unsigned int NUM_HANDLES = 9;
00038 
00039 /* Update the server side position */
00040 static const unsigned int PositionLock = (1 << 0);
00041 
00042 /* Update the client side position */
00043 static const unsigned int PositionSet = (1 << 2);
00044 
00045 static const unsigned int TopLeftHandle = (1 << 0);
00046 static const unsigned int TopHandle = (1 << 1);
00047 static const unsigned int TopRightHandle = (1 << 2);
00048 static const unsigned int RightHandle = (1 << 3);
00049 static const unsigned int BottomRightHandle = (1 << 4);
00050 static const unsigned int BottomHandle = (1 << 5);
00051 static const unsigned int BottomLeftHandle = (1 << 6);
00052 static const unsigned int LeftHandle = (1 << 7);
00053 static const unsigned int MiddleHandle = (1 << 8);
00054 
00055 static const std::map <unsigned int, int> maskHandles = {
00056  { TopLeftHandle, 0 },
00057  { TopHandle, 1 },
00058  { TopRightHandle, 2 },
00059  { RightHandle, 3 },
00060  { BottomRightHandle, 4},
00061  { BottomHandle, 5 },
00062  { BottomLeftHandle, 6 },
00063  { LeftHandle, 7 },
00064  { MiddleHandle, 8 }
00065 };
00066 
00067 static const std::map <int, unsigned int> handlesMask = {
00068  { 0, TopLeftHandle },
00069  { 1, TopHandle },
00070  { 2, TopRightHandle },
00071  { 3, RightHandle },
00072  { 4, BottomRightHandle},
00073  { 5, BottomHandle },
00074  { 6, BottomLeftHandle },
00075  { 7, LeftHandle },
00076  { 8, MiddleHandle }
00077 };
00078 
00079 class GrabHandleGroup;
00080 
00081 class GrabHandle :
00082   public boost::enable_shared_from_this <GrabHandle>,
00083   boost::noncopyable
00084 {
00085 public:
00086 
00087   typedef boost::shared_ptr <GrabHandle> Ptr;
00088 
00089   static GrabHandle::Ptr create (Texture::Ptr    texture,
00090                                  unsigned int    width,
00091                                  unsigned int    height,
00092                                  const boost::shared_ptr <GrabHandleGroup> &owner,
00093                                  unsigned int id);
00094   ~GrabHandle();
00095 
00096   bool operator== (const GrabHandle &other) const
00097   {
00098     return mId == other.mId;
00099   }
00100 
00101   bool operator!= (const GrabHandle &other) const
00102   {
00103     return !(*this == other);
00104   }
00105 
00106   void buttonPress (int x,
00107                     int y,
00108                     unsigned int button) const;
00109 
00110   void requestMovement (int x,
00111                         int y,
00112                         unsigned int button) const;
00113 
00114   void reposition(int x,
00115                 int y,
00116                   unsigned int flags);
00117   void reposition(int x, int y, unsigned int flags) const;
00118 
00119   void show();
00120   void hide();
00121   void raise() const;
00122 
00123   TextureLayout layout();
00124 
00125   unsigned int id () const { return mId; }
00126   unsigned int width () const { return mRect.width; }
00127   unsigned int height () const { return mRect.height; }
00128   int          x () const { return mRect.x; }
00129   int          y () const { return mRect.y; }
00130 
00131   void damage (const nux::Geometry &g) const { mImpl->damage (g); }
00132 
00133 public:
00134 
00135   class Impl :
00136     boost::noncopyable
00137   {
00138     public:
00139 
00140       virtual ~Impl () {};
00141 
00142       virtual void show () = 0;
00143       virtual void hide () = 0;
00144 
00145       virtual void buttonPress (int x,
00146                                 int y,
00147                                 unsigned int button) const = 0;
00148 
00149       virtual void lockPosition (int x,
00150                                  int y,
00151                                  unsigned int flags) = 0;
00152 
00153       virtual void damage (const nux::Geometry &g) = 0;
00154   };
00155 
00156   class ImplFactory;
00157 
00158 private:
00159 
00160   GrabHandle(Texture::Ptr    texture,
00161              unsigned int    width,
00162              unsigned int    height,
00163              const boost::shared_ptr <GrabHandleGroup> &owner,
00164              unsigned int id);
00165 
00166   boost::weak_ptr <GrabHandleGroup>      mOwner;
00167   Texture::Ptr                           mTexture;
00168   unsigned int                           mId;
00169   nux::Geometry                          mRect;
00170   Impl                                   *mImpl;
00171 };
00172 };
00173 };
00174 
00175 #endif