2
* Copyright (C) 2011 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
19
#include "unity-mt-grab-handle-group.h"
21
unsigned int unity::MT::FADE_MSEC = 0;
24
unity::MT::GrabHandleGroup::show(unsigned int handles)
26
for(const unity::MT::GrabHandle::Ptr & handle : mHandles)
27
if (handles & handle->id ())
30
mState = State::FADE_IN;
34
unity::MT::GrabHandleGroup::hide()
36
for(const unity::MT::GrabHandle::Ptr & handle : mHandles)
39
mState = State::FADE_OUT;
43
unity::MT::GrabHandleGroup::raiseHandle(const std::shared_ptr <const unity::MT::GrabHandle> &h)
45
mOwner->raiseGrabHandle (h);
49
unity::MT::GrabHandleGroup::animate(unsigned int msec)
57
mOpacity += ((float) msec / (float) unity::MT::FADE_MSEC) * std::numeric_limits <unsigned short>::max ();
59
if (mOpacity >= std::numeric_limits <unsigned short>::max ())
61
mOpacity = std::numeric_limits <unsigned short>::max ();
66
mOpacity -= ((float) msec / (float) unity::MT::FADE_MSEC) * std::numeric_limits <unsigned short>::max ();
78
mMoreAnimate = mState != State::NONE;
84
unity::MT::GrabHandleGroup::opacity()
90
unity::MT::GrabHandleGroup::visible()
92
return mOpacity > 0.0f;
96
unity::MT::GrabHandleGroup::needsAnimate()
102
unity::MT::GrabHandleGroup::relayout(const nux::Geometry& rect, bool hard)
104
/* Each grab handle at each vertex, eg:
116
const float pos[9][2] =
118
{0.0f, 0.0f}, {0.5f, 0.0f}, {1.0f, 0.0f},
119
{1.0f, 0.5f}, {1.0f, 1.0f},
120
{0.5f, 1.0f}, {0.0f, 1.0f}, {0.0f, 0.5f},
121
{0.5f, 0.5f} /* middle */
124
for (unsigned int i = 0; i < NUM_HANDLES; i++)
126
unity::MT::GrabHandle::Ptr & handle = mHandles.at(i);
128
handle->reposition (rect.x + rect.width * pos[i][0] -
129
handle->width () / 2,
130
rect.y + rect.height * pos[i][1] -
131
handle->height () / 2,
132
unity::MT::PositionSet | (hard ? unity::MT::PositionLock : 0));
136
unity::MT::GrabHandleGroup::GrabHandleGroup(GrabHandleWindow *owner,
137
std::vector <unity::MT::TextureSize> &textures) :
145
unity::MT::GrabHandleGroup::Ptr
146
unity::MT::GrabHandleGroup::create (GrabHandleWindow *owner,
147
std::vector<unity::MT::TextureSize> &textures)
149
unity::MT::GrabHandleGroup::Ptr p = unity::MT::GrabHandleGroup::Ptr (new unity::MT::GrabHandleGroup (owner, textures));
150
for (unsigned int i = 0; i < NUM_HANDLES; i++)
151
p->mHandles.push_back(unity::MT::GrabHandle::create (textures.at(i).first,
152
textures.at(i).second.width,
153
textures.at(i).second.height,
155
handlesMask.find (i)->second));
159
unity::MT::GrabHandleGroup::~GrabHandleGroup()
161
for (unity::MT::GrabHandle::Ptr & handle : mHandles)
162
handle->damage (nux::Geometry (handle->x (),
169
unity::MT::GrabHandleGroup::requestMovement (int x,
171
unsigned int direction,
174
mOwner->requestMovement (x, y, direction, button);
177
std::vector <unity::MT::TextureLayout>
178
unity::MT::GrabHandleGroup::layout(unsigned int handles)
180
std::vector <unity::MT::TextureLayout> layout;
182
for(const unity::MT::GrabHandle::Ptr & handle : mHandles)
183
if (handle->id () & handles)
184
layout.push_back (handle->layout ());
190
unity::MT::GrabHandleGroup::forEachHandle (const std::function <void (const unity::MT::GrabHandle::Ptr &)> &f)
192
for (unity::MT::GrabHandle::Ptr &h : mHandles)