From 36be1ec24b69ef2d98e1de05772236faf543edc0 Mon Sep 17 00:00:00 2001 From: Krishna Narasimhan Date: Sat, 21 Feb 2015 11:39:26 +0100 Subject: [PATCH] Source refactor. Abstracted common functionalities from 4 onTouches methods in Camera3dTest --- .../Classes/Camera3DTest/Camera3DTest.cpp | 56 +++++-------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 0408ea92dd..0374102c83 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -709,11 +709,8 @@ void Camera3DTestDemo::updateCamera(float fDelta) } } } -bool Camera3DTestDemo::isState(unsigned int state,unsigned int bit) const -{ - return (state & bit) == bit; -} -bool Camera3DTestDemo::onTouchesZoomOut(Touch* touch, Event* event) +template +bool Camera3DTestDemo::onTouchesCommon(Touch* touch, Event* event, T touchProperty) { auto target = static_cast(event->getCurrentTarget()); @@ -723,29 +720,26 @@ bool Camera3DTestDemo::onTouchesZoomOut(Touch* touch, Event* event) if (rect.containsPoint(locationInNode)) { - _bZoomOut = true; + touchProperty = true; return true; } 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) { _bZoomOut = false; } bool Camera3DTestDemo::onTouchesZoomIn(Touch* touch, Event* event) { - auto target = static_cast(event->getCurrentTarget()); - - 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; + return Camera3DTestDemo::onTouchesCommon(touch, event, _bZoomIn); } 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) { - auto target = static_cast(event->getCurrentTarget()); - - 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; + return Camera3DTestDemo::onTouchesCommon(touch, event, _bRotateLeft); } 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) { - auto target = static_cast(event->getCurrentTarget()); - - 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; + return Camera3DTestDemo::onTouchesCommon(touch, event, _bRotateRight); } void Camera3DTestDemo::onTouchesRotateRightEnd(Touch* touch, Event* event) {