|
@@ -4,7 +4,6 @@
|
|
|
#include "AbsoluteLayout.h"
|
|
#include "AbsoluteLayout.h"
|
|
|
#include "FlowLayout.h"
|
|
#include "FlowLayout.h"
|
|
|
#include "VerticalLayout.h"
|
|
#include "VerticalLayout.h"
|
|
|
-#include "ScrollLayout.h"
|
|
|
|
|
#include "Label.h"
|
|
#include "Label.h"
|
|
|
#include "Button.h"
|
|
#include "Button.h"
|
|
|
#include "CheckBox.h"
|
|
#include "CheckBox.h"
|
|
@@ -16,7 +15,26 @@
|
|
|
namespace gameplay
|
|
namespace gameplay
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
-Container::Container() : _layout(NULL)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * If the user stops scrolling for this amount of time (in millis) before
|
|
|
|
|
+ * touch/click release, don't apply inertia.
|
|
|
|
|
+ */
|
|
|
|
|
+ static const long STOP_TIME = 100L;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Factor to multiply friction by before applying to velocity.
|
|
|
|
|
+ */
|
|
|
|
|
+ static const float FRICTION_FACTOR = 5.0f;
|
|
|
|
|
+
|
|
|
|
|
+Container::Container()
|
|
|
|
|
+ : _layout(NULL), _scrollBarTopCap(NULL), _scrollBarVertical(NULL), _scrollBarBottomCap(NULL),
|
|
|
|
|
+ _scrollBarLeftCap(NULL), _scrollBarHorizontal(NULL), _scrollBarRightCap(NULL),
|
|
|
|
|
+ _scrollState(SCROLL_NONE), _scrollBarBounds(Rectangle::empty()), _scrollPosition(Vector2::zero()),
|
|
|
|
|
+ _scrolling(false), _firstX(0), _firstY(0),
|
|
|
|
|
+ _lastX(0), _lastY(0),
|
|
|
|
|
+ _startTimeX(0), _startTimeY(0), _lastTime(0),
|
|
|
|
|
+ _velocity(Vector2::zero()), _friction(1.0f),
|
|
|
|
|
+ _goingRight(false), _goingDown(false)
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -49,9 +67,6 @@ Container* Container::create(Layout::Type type)
|
|
|
case Layout::LAYOUT_VERTICAL:
|
|
case Layout::LAYOUT_VERTICAL:
|
|
|
layout = VerticalLayout::create();
|
|
layout = VerticalLayout::create();
|
|
|
break;
|
|
break;
|
|
|
- case Layout::LAYOUT_SCROLL:
|
|
|
|
|
- layout = ScrollLayout::create();
|
|
|
|
|
- break;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Container* container = new Container();
|
|
Container* container = new Container();
|
|
@@ -67,6 +82,7 @@ Container* Container::create(Theme::Style* style, Properties* properties, Theme*
|
|
|
const char* layoutString = properties->getString("layout");
|
|
const char* layoutString = properties->getString("layout");
|
|
|
Container* container = Container::create(getLayoutType(layoutString));
|
|
Container* container = Container::create(getLayoutType(layoutString));
|
|
|
container->initialize(style, properties);
|
|
container->initialize(style, properties);
|
|
|
|
|
+ container->_scrollState = getScrollState(properties->getString("scroll"));
|
|
|
container->addControls(theme, properties);
|
|
container->addControls(theme, properties);
|
|
|
|
|
|
|
|
return container;
|
|
return container;
|
|
@@ -225,6 +241,20 @@ const std::vector<Control*>& Container::getControls() const
|
|
|
return _controls;
|
|
return _controls;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void Container::setScrollState(ScrollState scrollState)
|
|
|
|
|
+{
|
|
|
|
|
+ if (scrollState != _scrollState)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollState = scrollState;
|
|
|
|
|
+ _dirty = true;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Container::ScrollState Container::getScrollState() const
|
|
|
|
|
+{
|
|
|
|
|
+ return _scrollState;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
Animation* Container::getAnimation(const char* id) const
|
|
Animation* Container::getAnimation(const char* id) const
|
|
|
{
|
|
{
|
|
|
std::vector<Control*>::const_iterator itr = _controls.begin();
|
|
std::vector<Control*>::const_iterator itr = _controls.begin();
|
|
@@ -250,13 +280,35 @@ Animation* Container::getAnimation(const char* id) const
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Container::update(const Rectangle& clip, const Vector2& offset)
|
|
|
|
|
|
|
+void Container::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
|
|
|
{
|
|
{
|
|
|
// Update this container's viewport.
|
|
// Update this container's viewport.
|
|
|
- Control::update(clip, offset);
|
|
|
|
|
|
|
+ Control::update(clip, offset, elapsedTime);
|
|
|
|
|
+
|
|
|
|
|
+ // Get scrollbar images and diminish clipping bounds to make room for scrollbars.
|
|
|
|
|
+ if ((_scrollState & SCROLL_HORIZONTAL) == SCROLL_HORIZONTAL)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollBarLeftCap = getImage("scrollBarLeftCap", _state);
|
|
|
|
|
+ _scrollBarHorizontal = getImage("horizontalScrollBar", _state);
|
|
|
|
|
+ _scrollBarRightCap = getImage("scrollBarRightCap", _state);
|
|
|
|
|
+
|
|
|
|
|
+ _viewportClipBounds.height -= _scrollBarHorizontal->getRegion().height;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ((_scrollState & SCROLL_VERTICAL) == SCROLL_VERTICAL)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollBarTopCap = getImage("scrollBarTopCap", _state);
|
|
|
|
|
+ _scrollBarVertical = getImage("verticalScrollBar", _state);
|
|
|
|
|
+ _scrollBarBottomCap = getImage("scrollBarBottomCap", _state);
|
|
|
|
|
+
|
|
|
|
|
+ _viewportClipBounds.width -= _scrollBarVertical->getRegion().width;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
GP_ASSERT(_layout);
|
|
GP_ASSERT(_layout);
|
|
|
- _layout->update(this);
|
|
|
|
|
|
|
+ _layout->update(this, elapsedTime);
|
|
|
|
|
+
|
|
|
|
|
+ if (_scrollState != SCROLL_NONE)
|
|
|
|
|
+ this->updateScroll(this, elapsedTime);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needsClear, float targetHeight)
|
|
void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needsClear, float targetHeight)
|
|
@@ -289,7 +341,80 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- _dirty = false;
|
|
|
|
|
|
|
+ if (_scrollState != SCROLL_NONE)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Draw scroll bars.
|
|
|
|
|
+ Rectangle clipRegion(_viewportClipBounds);
|
|
|
|
|
+
|
|
|
|
|
+ if (_scrollBarBounds.height > 0 && (_scrolling || _velocity.y) && _scrollBarTopCap && _scrollBarVertical && _scrollBarBottomCap)
|
|
|
|
|
+ {
|
|
|
|
|
+ const Rectangle& topRegion = _scrollBarTopCap->getRegion();
|
|
|
|
|
+ const Theme::UVs& topUVs = _scrollBarTopCap->getUVs();
|
|
|
|
|
+ Vector4 topColor = _scrollBarTopCap->getColor();
|
|
|
|
|
+
|
|
|
|
|
+ const Rectangle& verticalRegion = _scrollBarVertical->getRegion();
|
|
|
|
|
+ const Theme::UVs& verticalUVs = _scrollBarVertical->getUVs();
|
|
|
|
|
+ Vector4 verticalColor = _scrollBarVertical->getColor();
|
|
|
|
|
+
|
|
|
|
|
+ const Rectangle& bottomRegion = _scrollBarBottomCap->getRegion();
|
|
|
|
|
+ const Theme::UVs& bottomUVs = _scrollBarBottomCap->getUVs();
|
|
|
|
|
+ Vector4 bottomColor = _scrollBarBottomCap->getColor();
|
|
|
|
|
+
|
|
|
|
|
+ clipRegion.width += verticalRegion.width;
|
|
|
|
|
+
|
|
|
|
|
+ Rectangle bounds(_viewportBounds.x + _viewportBounds.width - verticalRegion.width,
|
|
|
|
|
+ _viewportBounds.y + _scrollBarBounds.y,
|
|
|
|
|
+ topRegion.width, topRegion.height);
|
|
|
|
|
+ spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, topUVs.u1, topUVs.v1, topUVs.u2, topUVs.v2, topColor, clipRegion);
|
|
|
|
|
+
|
|
|
|
|
+ bounds.y += topRegion.height;
|
|
|
|
|
+ bounds.height = _scrollBarBounds.height - topRegion.height - bottomRegion.height;
|
|
|
|
|
+ spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, verticalUVs.u1, verticalUVs.v1, verticalUVs.u2, verticalUVs.v2, verticalColor, clipRegion);
|
|
|
|
|
+
|
|
|
|
|
+ bounds.y += bounds.height;
|
|
|
|
|
+ bounds.height = bottomRegion.height;
|
|
|
|
|
+ spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, bottomUVs.u1, bottomUVs.v1, bottomUVs.u2, bottomUVs.v2, bottomColor, clipRegion);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (_scrollBarBounds.width > 0 && (_scrolling || _velocity.x) && _scrollBarLeftCap && _scrollBarHorizontal && _scrollBarRightCap)
|
|
|
|
|
+ {
|
|
|
|
|
+ const Rectangle& leftRegion = _scrollBarLeftCap->getRegion();
|
|
|
|
|
+ const Theme::UVs& leftUVs = _scrollBarLeftCap->getUVs();
|
|
|
|
|
+ Vector4 leftColor = _scrollBarLeftCap->getColor();
|
|
|
|
|
+
|
|
|
|
|
+ const Rectangle& horizontalRegion = _scrollBarHorizontal->getRegion();
|
|
|
|
|
+ const Theme::UVs& horizontalUVs = _scrollBarHorizontal->getUVs();
|
|
|
|
|
+ Vector4 horizontalColor = _scrollBarHorizontal->getColor();
|
|
|
|
|
+
|
|
|
|
|
+ const Rectangle& rightRegion = _scrollBarRightCap->getRegion();
|
|
|
|
|
+ const Theme::UVs& rightUVs = _scrollBarRightCap->getUVs();
|
|
|
|
|
+ Vector4 rightColor = _scrollBarRightCap->getColor();
|
|
|
|
|
+
|
|
|
|
|
+ clipRegion.height += horizontalRegion.height;
|
|
|
|
|
+
|
|
|
|
|
+ Rectangle bounds(_viewportBounds.x + _scrollBarBounds.x,
|
|
|
|
|
+ _viewportBounds.y + _viewportBounds.height - horizontalRegion.height,
|
|
|
|
|
+ leftRegion.width, leftRegion.height);
|
|
|
|
|
+ spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, leftUVs.u1, leftUVs.v1, leftUVs.u2, leftUVs.v2, leftColor, clipRegion);
|
|
|
|
|
+
|
|
|
|
|
+ bounds.x += leftRegion.width;
|
|
|
|
|
+ bounds.width = _scrollBarBounds.width - leftRegion.width - rightRegion.width;
|
|
|
|
|
+ spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, horizontalUVs.u1, horizontalUVs.v1, horizontalUVs.u2, horizontalUVs.v2, horizontalColor, clipRegion);
|
|
|
|
|
+
|
|
|
|
|
+ bounds.x += bounds.width;
|
|
|
|
|
+ bounds.width = rightRegion.width;
|
|
|
|
|
+ spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, rightUVs.u1, rightUVs.v1, rightUVs.u2, rightUVs.v2, rightColor, clipRegion);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (_velocity.isZero())
|
|
|
|
|
+ {
|
|
|
|
|
+ _dirty = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ _dirty = false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool Container::isDirty()
|
|
bool Container::isDirty()
|
|
@@ -328,9 +453,9 @@ bool Container::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int con
|
|
|
float yPos = border.top + padding.top;
|
|
float yPos = border.top + padding.top;
|
|
|
|
|
|
|
|
Vector2* offset = NULL;
|
|
Vector2* offset = NULL;
|
|
|
- if (_layout->getType() == Layout::LAYOUT_SCROLL)
|
|
|
|
|
|
|
+ if (_scrollState != SCROLL_NONE)
|
|
|
{
|
|
{
|
|
|
- offset = &((ScrollLayout*)_layout)->_scrollPosition;
|
|
|
|
|
|
|
+ offset = &_scrollPosition;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::vector<Control*>::const_iterator it;
|
|
std::vector<Control*>::const_iterator it;
|
|
@@ -382,7 +507,7 @@ bool Container::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int con
|
|
|
if (!eventConsumed)
|
|
if (!eventConsumed)
|
|
|
{
|
|
{
|
|
|
// Pass the event on to the layout.
|
|
// Pass the event on to the layout.
|
|
|
- if (_layout->touchEvent(evt, x - xPos, y - yPos, contactIndex))
|
|
|
|
|
|
|
+ if (touchEventScroll(evt, x - xPos, y - yPos, contactIndex))
|
|
|
{
|
|
{
|
|
|
_dirty = true;
|
|
_dirty = true;
|
|
|
}
|
|
}
|
|
@@ -447,4 +572,221 @@ Layout::Type Container::getLayoutType(const char* layoutString)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void Container::updateScroll(const Container* container, long elapsedTime)
|
|
|
|
|
+{
|
|
|
|
|
+ GP_ASSERT(container);
|
|
|
|
|
+
|
|
|
|
|
+ const Rectangle& containerBounds = container->getBounds();
|
|
|
|
|
+ const Theme::Border& containerBorder = container->getBorder(container->getState());
|
|
|
|
|
+ const Theme::Padding& containerPadding = container->getPadding();
|
|
|
|
|
+
|
|
|
|
|
+ // Calculate total width and height.
|
|
|
|
|
+ float totalWidth = 0;
|
|
|
|
|
+ float totalHeight = 0;
|
|
|
|
|
+ std::vector<Control*> controls = container->getControls();
|
|
|
|
|
+ unsigned int controlsCount = controls.size();
|
|
|
|
|
+ for (unsigned int i = 0; i < controlsCount; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Control* control = controls.at(i);
|
|
|
|
|
+
|
|
|
|
|
+ const Rectangle& bounds = control->getBounds();
|
|
|
|
|
+ const Theme::Margin& margin = control->getMargin();
|
|
|
|
|
+
|
|
|
|
|
+ float newWidth = bounds.x + bounds.width;
|
|
|
|
|
+ if (newWidth > totalWidth)
|
|
|
|
|
+ {
|
|
|
|
|
+ totalWidth = newWidth;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ float newHeight = bounds.y + bounds.height;
|
|
|
|
|
+ if (newHeight > totalHeight)
|
|
|
|
|
+ {
|
|
|
|
|
+ totalHeight = newHeight;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ float vWidth = container->getImageRegion("verticalScrollBar", container->getState()).width;
|
|
|
|
|
+ float hHeight = container->getImageRegion("horizontalScrollBar", container->getState()).height;
|
|
|
|
|
+ float clipWidth = containerBounds.width - containerBorder.left - containerBorder.right - containerPadding.left - containerPadding.right - vWidth;
|
|
|
|
|
+ float clipHeight = containerBounds.height - containerBorder.top - containerBorder.bottom - containerPadding.top - containerPadding.bottom - hHeight;
|
|
|
|
|
+
|
|
|
|
|
+ // Apply and dampen inertia.
|
|
|
|
|
+ if (!_scrolling && !_velocity.isZero())
|
|
|
|
|
+ {
|
|
|
|
|
+ // Calculate the time passed since last update.
|
|
|
|
|
+ float elapsedSecs = (float)elapsedTime * 0.001f;
|
|
|
|
|
+
|
|
|
|
|
+ _scrollPosition.x += _velocity.x * elapsedSecs;
|
|
|
|
|
+ _scrollPosition.y += _velocity.y * elapsedSecs;
|
|
|
|
|
+
|
|
|
|
|
+ float dampening = 1.0f - _friction * FRICTION_FACTOR * elapsedSecs;
|
|
|
|
|
+ _velocity.x *= dampening;
|
|
|
|
|
+ _velocity.y *= dampening;
|
|
|
|
|
+
|
|
|
|
|
+ if (abs(_velocity.x) < 100.0f)
|
|
|
|
|
+ _velocity.x = 0.0f;
|
|
|
|
|
+ if (abs(_velocity.y) < 100.0f)
|
|
|
|
|
+ _velocity.y = 0.0f;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Stop scrolling when the far edge is reached.
|
|
|
|
|
+ if (-_scrollPosition.x > totalWidth - clipWidth)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollPosition.x = -(totalWidth - clipWidth);
|
|
|
|
|
+ _velocity.x = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (-_scrollPosition.y > totalHeight - clipHeight)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollPosition.y = -(totalHeight - clipHeight);
|
|
|
|
|
+ _velocity.y = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (_scrollPosition.x > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollPosition.x = 0;
|
|
|
|
|
+ _velocity.x = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (_scrollPosition.y > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollPosition.y = 0;
|
|
|
|
|
+ _velocity.y = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ float scrollWidth = 0;
|
|
|
|
|
+ if (clipWidth < totalWidth)
|
|
|
|
|
+ scrollWidth = (clipWidth / totalWidth) * clipWidth;
|
|
|
|
|
+
|
|
|
|
|
+ float scrollHeight = 0;
|
|
|
|
|
+ if (clipHeight < totalHeight)
|
|
|
|
|
+ scrollHeight = (clipHeight / totalHeight) * clipHeight;
|
|
|
|
|
+
|
|
|
|
|
+ _scrollBarBounds.set(((-_scrollPosition.x) / totalWidth) * clipWidth,
|
|
|
|
|
+ ((-_scrollPosition.y) / totalHeight) * clipHeight,
|
|
|
|
|
+ scrollWidth, scrollHeight);
|
|
|
|
|
+
|
|
|
|
|
+ // Position controls within scroll area.
|
|
|
|
|
+ for (unsigned int i = 0; i < controlsCount; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Control* control = controls.at(i);
|
|
|
|
|
+ control->update(container->getClip(), _scrollPosition, elapsedTime);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
|
|
|
|
|
+{
|
|
|
|
|
+ switch(evt)
|
|
|
|
|
+ {
|
|
|
|
|
+ case Touch::TOUCH_PRESS:
|
|
|
|
|
+ _lastX = _firstX = x;
|
|
|
|
|
+ _lastY = _firstY = y;
|
|
|
|
|
+ _velocity.set(0, 0);
|
|
|
|
|
+ _scrolling = true;
|
|
|
|
|
+ _startTimeX = _startTimeY = 0;
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case Touch::TOUCH_MOVE:
|
|
|
|
|
+ if (_scrolling)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Calculate the latest movement delta for the next update to use.
|
|
|
|
|
+ int vx = x - _lastX;
|
|
|
|
|
+ int vy = y - _lastY;
|
|
|
|
|
+ _velocity.set(vx, vy);
|
|
|
|
|
+ _scrollPosition.x += vx;
|
|
|
|
|
+ _scrollPosition.y += vy;
|
|
|
|
|
+ _lastX = x;
|
|
|
|
|
+ _lastY = y;
|
|
|
|
|
+
|
|
|
|
|
+ // If the user changes direction, reset the start time and position.
|
|
|
|
|
+ bool goingRight = (vx > 0);
|
|
|
|
|
+ if (goingRight != _goingRight)
|
|
|
|
|
+ {
|
|
|
|
|
+ _firstX = x;
|
|
|
|
|
+ _goingRight = goingRight;
|
|
|
|
|
+ _startTimeX = Game::getAbsoluteTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bool goingDown = (vy > 0);
|
|
|
|
|
+ if (goingDown != _goingDown)
|
|
|
|
|
+ {
|
|
|
|
|
+ _firstY = y;
|
|
|
|
|
+ _goingDown = goingDown;
|
|
|
|
|
+ _startTimeY = Game::getAbsoluteTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!_startTimeX)
|
|
|
|
|
+ _startTimeX = Game::getAbsoluteTime();
|
|
|
|
|
+
|
|
|
|
|
+ if (!_startTimeY)
|
|
|
|
|
+ _startTimeY = Game::getAbsoluteTime();
|
|
|
|
|
+
|
|
|
|
|
+ _lastTime = Game::getAbsoluteTime();
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case Touch::TOUCH_RELEASE:
|
|
|
|
|
+ long timeSinceLastMove = Game::getAbsoluteTime() - _lastTime;
|
|
|
|
|
+ if (timeSinceLastMove > STOP_TIME)
|
|
|
|
|
+ {
|
|
|
|
|
+ _velocity.set(0, 0);
|
|
|
|
|
+ _scrolling = false;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int dx = _lastX - _firstX;
|
|
|
|
|
+ int dy = _lastY - _firstY;
|
|
|
|
|
+
|
|
|
|
|
+ long timeTakenX = Game::getAbsoluteTime() - _startTimeX;
|
|
|
|
|
+ float elapsedSecsX = (float)timeTakenX * 0.001f;
|
|
|
|
|
+ long timeTakenY = Game::getAbsoluteTime() - _startTimeY;
|
|
|
|
|
+ float elapsedSecsY = (float)timeTakenY * 0.001f;
|
|
|
|
|
+
|
|
|
|
|
+ float vx = dx;
|
|
|
|
|
+ float vy = dy;
|
|
|
|
|
+ if (elapsedSecsX > 0)
|
|
|
|
|
+ vx = (float)dx / elapsedSecsX;
|
|
|
|
|
+ if (elapsedSecsY > 0)
|
|
|
|
|
+ vy = (float)dy / elapsedSecsY;
|
|
|
|
|
+
|
|
|
|
|
+ _velocity.set(vx, vy);
|
|
|
|
|
+
|
|
|
|
|
+ _scrolling = false;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Container::ScrollState Container::getScrollState(const char* scrollState)
|
|
|
|
|
+{
|
|
|
|
|
+ if (!scrollState)
|
|
|
|
|
+ return Container::SCROLL_NONE;
|
|
|
|
|
+
|
|
|
|
|
+ if (strcmp(scrollState, "SCROLL_NONE") == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Container::SCROLL_NONE;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (strcmp(scrollState, "SCROLL_HORIZONTAL") == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Container::SCROLL_HORIZONTAL;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (strcmp(scrollState, "SCROLL_VERTICAL") == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Container::SCROLL_VERTICAL;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (strcmp(scrollState, "SCROLL_BOTH") == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return Container::SCROLL_BOTH;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ GP_ERROR("Failed to get corresponding scroll state for unsupported value '%s'.", scrollState);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Container::SCROLL_NONE;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
}
|
|
}
|