Source refactor. Abstracted common functionalities from 4 onTouches methods in Camera3dTest

This commit is contained in:
Krishna Narasimhan 2015-02-21 11:39:26 +01:00
parent a303142da5
commit 36be1ec24b
1 changed files with 14 additions and 42 deletions

View File

@ -709,11 +709,8 @@ void Camera3DTestDemo::updateCamera(float fDelta)
} }
} }
} }
bool Camera3DTestDemo::isState(unsigned int state,unsigned int bit) const template<typename T>
{ bool Camera3DTestDemo::onTouchesCommon(Touch* touch, Event* event, T touchProperty)
return (state & bit) == bit;
}
bool Camera3DTestDemo::onTouchesZoomOut(Touch* touch, Event* event)
{ {
auto target = static_cast<Label*>(event->getCurrentTarget()); auto target = static_cast<Label*>(event->getCurrentTarget());
@ -723,29 +720,26 @@ bool Camera3DTestDemo::onTouchesZoomOut(Touch* touch, Event* event)
if (rect.containsPoint(locationInNode)) if (rect.containsPoint(locationInNode))
{ {
_bZoomOut = true; touchProperty = true;
return true; return true;
} }
return false; return false;
} }
bool Camera3DTestDemo::isState(unsigned int state,unsigned int bit) const
{
return (state & bit) == bit;
}
bool Camera3DTestDemo::onTouchesZoomOut(Touch* touch, Event* event)
{
return Camera3DTestDemo::onTouchesCommon(touch, event, _bZoomOut);
}
void Camera3DTestDemo::onTouchesZoomOutEnd(Touch* touch, Event* event) void Camera3DTestDemo::onTouchesZoomOutEnd(Touch* touch, Event* event)
{ {
_bZoomOut = false; _bZoomOut = false;
} }
bool Camera3DTestDemo::onTouchesZoomIn(Touch* touch, Event* event) bool Camera3DTestDemo::onTouchesZoomIn(Touch* touch, Event* event)
{ {
auto target = static_cast<Label*>(event->getCurrentTarget()); return Camera3DTestDemo::onTouchesCommon(touch, event, _bZoomIn);
Vec2 locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
if (rect.containsPoint(locationInNode))
{
_bZoomIn = true;
return true;
}
return false;
} }
void Camera3DTestDemo::onTouchesZoomInEnd(Touch* touch, Event* event) void Camera3DTestDemo::onTouchesZoomInEnd(Touch* touch, Event* event)
{ {
@ -753,18 +747,7 @@ void Camera3DTestDemo::onTouchesZoomInEnd(Touch* touch, Event* event)
} }
bool Camera3DTestDemo::onTouchesRotateLeft(Touch* touch, Event* event) bool Camera3DTestDemo::onTouchesRotateLeft(Touch* touch, Event* event)
{ {
auto target = static_cast<Label*>(event->getCurrentTarget()); return Camera3DTestDemo::onTouchesCommon(touch, event, _bRotateLeft);
Vec2 locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
if (rect.containsPoint(locationInNode))
{
_bRotateLeft = true;
return true;
}
return false;
} }
void Camera3DTestDemo::onTouchesRotateLeftEnd(Touch* touch, Event* event) void Camera3DTestDemo::onTouchesRotateLeftEnd(Touch* touch, Event* event)
{ {
@ -772,18 +755,7 @@ void Camera3DTestDemo::onTouchesRotateLeftEnd(Touch* touch, Event* event)
} }
bool Camera3DTestDemo::onTouchesRotateRight(Touch* touch, Event* event) bool Camera3DTestDemo::onTouchesRotateRight(Touch* touch, Event* event)
{ {
auto target = static_cast<Label*>(event->getCurrentTarget()); return Camera3DTestDemo::onTouchesCommon(touch, event, _bRotateRight);
Vec2 locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
if (rect.containsPoint(locationInNode))
{
_bRotateRight = true;
return true;
}
return false;
} }
void Camera3DTestDemo::onTouchesRotateRightEnd(Touch* touch, Event* event) void Camera3DTestDemo::onTouchesRotateRightEnd(Touch* touch, Event* event)
{ {