Skip to content

Commit

Permalink
Merge pull request gameplay3d#792 from kwhatmough/master
Browse files Browse the repository at this point in the history
Return indices (not hashes) for touch events on iOS.
  • Loading branch information
seanpaultaylor committed Jan 24, 2013
2 parents ef248ce + 569ddbb commit 82796bf
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gameplay/src/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Button : public Label
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by the control.
*
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/CheckBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CheckBox : public Button
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by the control.
*
Expand Down
4 changes: 2 additions & 2 deletions gameplay/src/Container.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class Container : public Control
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by a control within this container.
*
Expand Down Expand Up @@ -340,7 +340,7 @@ class Container : public Control
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by scrolling within this container.
*
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ class Control : public Ref, public AnimationTarget, public ScriptTarget
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by this control.
*
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class Game
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @see Touch::TouchEvent
*/
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Joystick : public Control
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by the control.
*
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Layout : public Ref
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @see Touch::TouchEvent
*/
Expand Down
122 changes: 119 additions & 3 deletions gameplay/src/PlatformiOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@
static AppDelegate *__appDelegate = NULL;
static View* __view = NULL;

class TouchPointListElement
{
public:
TouchPointListElement* _next;
TouchPointListElement* _prev;
unsigned int _id; // as assigned from hash
unsigned int _index; // to save time during touchesBegan
int _x;
int _y;

TouchPointListElement()
{
_next = NULL;
_prev = NULL;
_id = 0;
_index = 0;
_x = 0;
_y = 0;
}
};
static TouchPointListElement* __touchPointListHead = NULL;
static TouchPointListElement* __touchPointListTail = NULL;

static double __timeStart;
static double __timeAbsolute;
static bool __vsync = WINDOW_VSYNC;
Expand Down Expand Up @@ -516,7 +539,29 @@ - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
touchID = [touch hash];
}
Platform::touchEventInternal(Touch::TOUCH_PRESS, touchPoint.x * WINDOW_SCALE, touchPoint.y * WINDOW_SCALE, touchID);

// Map hash to index
TouchPointListElement* elem = new TouchPointListElement();
if (__touchPointListTail)
{
// Insert at end of list
__touchPointListTail->_next = elem;
elem->_index = __touchPointListTail->_index + 1;
}
else
{
// Insert into empty list
__touchPointListHead = elem;
elem->_index = 0;
}

elem->_prev = __touchPointListTail;
__touchPointListTail = elem;
elem->_id = touchID;
elem->_x = touchPoint.x * WINDOW_SCALE;
elem->_y = touchPoint.y * WINDOW_SCALE;

Platform::touchEventInternal(Touch::TOUCH_PRESS, elem->_x, elem->_y, elem->_index);
}
}

Expand All @@ -528,7 +573,67 @@ - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
CGPoint touchPoint = [touch locationInView:self];
if(self.multipleTouchEnabled == YES)
touchID = [touch hash];
Platform::touchEventInternal(Touch::TOUCH_RELEASE, touchPoint.x * WINDOW_SCALE, touchPoint.y * WINDOW_SCALE, touchID);

// Map hash to index
TouchPointListElement* elem = NULL;
for (TouchPointListElement* p = __touchPointListHead; p; p = p->_next)
{
if (p->_id == touchID)
{
// Remove from list
elem = p;
p = elem->_next;

if (elem->_prev)
{
elem->_prev->_next = p;
}
else
{
__touchPointListHead = p;
}

if (p)
{
p->_prev = elem->_prev;
}
else
{
__touchPointListTail = elem->_prev;
break;
}
}

if (elem)
{
// Release at the old index and press at the new index
Platform::touchEventInternal(Touch::TOUCH_RELEASE, p->_x, p->_y, p->_index);
p->_index--;
Platform::touchEventInternal(Touch::TOUCH_PRESS, p->_x, p->_y, p->_index);
}
}

if (elem)
{
Platform::touchEventInternal(Touch::TOUCH_RELEASE, touchPoint.x * WINDOW_SCALE, touchPoint.y * WINDOW_SCALE, elem->_index);
delete elem;
}
else
{
// It seems possible to receive an ID not in the list.
// The best we can do is clear the whole list.
TouchPointListElement* p = __touchPointListTail;
while (p)
{
TouchPointListElement* e = p;
p = e->_prev;
// Neglect p->_next since the whole list is being deleted.
Platform::touchEventInternal(Touch::TOUCH_RELEASE, e->_x, e->_y, e->_index);
delete e;
}
__touchPointListTail = NULL;
__touchPointListHead = NULL;
}
}
}

Expand All @@ -546,7 +651,18 @@ - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
CGPoint touchPoint = [touch locationInView:self];
if(self.multipleTouchEnabled == YES)
touchID = [touch hash];
Platform::touchEventInternal(Touch::TOUCH_MOVE, touchPoint.x * WINDOW_SCALE, touchPoint.y * WINDOW_SCALE, touchID);

// Map hash to index
for (TouchPointListElement* p = __touchPointListHead; p; p = p->_next)
{
if (p->_id == touchID)
{
p->_x = touchPoint.x * WINDOW_SCALE;
p->_y = touchPoint.y * WINDOW_SCALE;
Platform::touchEventInternal(Touch::TOUCH_MOVE, p->_x, p->_y, p->_index);
break;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/RadioButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class RadioButton : public Button
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by the control.
*
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/ScriptController.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ class ScriptController
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @see Touch::TouchEvent
*/
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/Slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Slider : public Label
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by the control.
*
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/TextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class TextBox : public Label
* @param evt The touch event that occurred.
* @param x The x position of the touch in pixels. Left edge is zero.
* @param y The y position of the touch in pixels. Top edge is zero.
* @param contactIndex An integer to identify this contact point within the currently active touch set.
* @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
*
* @return Whether the touch event was consumed by the control.
*
Expand Down

0 comments on commit 82796bf

Please sign in to comment.