├── Resources
├── HelloWorld.png
└── Fishfam_base_TH8.jpg
├── proj.android
├── jni
│ ├── Application.mk
│ ├── Android.mk
│ └── hellocpp
│ │ └── main.cpp
├── res
│ ├── drawable-hdpi
│ │ └── icon.png
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ └── values
│ │ └── strings.xml
├── project.properties
├── .classpath
├── ant.properties
├── proguard-project.txt
├── AndroidManifest.xml
├── build_native.sh
├── src
│ └── my
│ │ └── test
│ │ └── smooth
│ │ └── smooth_panning_zoom.java
├── README.md
├── build.xml
├── .project
└── .cproject
├── proj.win32
├── main.h
├── smooth_panning_zoom.vcxproj.user
├── main.cpp
├── smooth_panning_zoom.vcxproj.filters
├── smooth_panning_zoom.sln
└── smooth_panning_zoom.vcxproj
├── .gitignore
├── Classes
├── HelloWorldScene.h
├── AppDelegate.h
├── AppDelegate.cpp
├── HelloWorldScene.cpp
├── PanZoomLayer.h
└── PanZoomLayer.cpp
└── README.md
/Resources/HelloWorld.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dariodepaolis/cocos2d-x-panzoomlayer/HEAD/Resources/HelloWorld.png
--------------------------------------------------------------------------------
/Resources/Fishfam_base_TH8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dariodepaolis/cocos2d-x-panzoomlayer/HEAD/Resources/Fishfam_base_TH8.jpg
--------------------------------------------------------------------------------
/proj.android/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_STL := gnustl_static
2 | APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1
3 |
--------------------------------------------------------------------------------
/proj.android/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dariodepaolis/cocos2d-x-panzoomlayer/HEAD/proj.android/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/proj.android/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dariodepaolis/cocos2d-x-panzoomlayer/HEAD/proj.android/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/proj.android/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dariodepaolis/cocos2d-x-panzoomlayer/HEAD/proj.android/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/proj.android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | smooth_panning_zoom
4 |
5 |
--------------------------------------------------------------------------------
/proj.win32/main.h:
--------------------------------------------------------------------------------
1 | #ifndef __MAIN_H__
2 | #define __MAIN_H__
3 |
4 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
5 |
6 | // Windows Header Files:
7 | #include
8 | #include
9 |
10 | // C RunTime Header Files
11 | #include "CCStdC.h"
12 |
13 | #endif // __MAIN_H__
14 |
--------------------------------------------------------------------------------
/proj.android/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-8
12 |
13 | android.library.reference.1=../../../cocos2dx/platform/android/java
14 |
--------------------------------------------------------------------------------
/proj.android/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 |
6 | # Compiled Dynamic libraries
7 | *.so
8 | *.dylib
9 |
10 | # Compiled Static libraries
11 | *.lai
12 | *.la
13 | *.a
14 |
15 |
16 | *.sdf
17 | *.suo
18 | *.opensdf
19 |
20 | *.class
21 | *.dex
22 | *.ap_
23 | *.cache
24 | *.jar
25 |
26 |
27 | **/proj.win32/Debug.win32/
28 | proj.win32/Debug.win32/
29 |
30 | **/proj.win32/Release.win32/
31 | proj.win32/Release.win32/
32 |
33 |
34 | **/proj.android/assets/
35 | **/proj.android/obj/
36 |
37 |
38 | **/proj.linux/
39 | **/proj.linux/*
--------------------------------------------------------------------------------
/proj.win32/smooth_panning_zoom.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(ProjectDir)..\Resources
5 | WindowsLocalDebugger
6 |
7 |
8 | $(ProjectDir)..\Resources
9 | WindowsLocalDebugger
10 |
11 |
--------------------------------------------------------------------------------
/proj.win32/main.cpp:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 | #include "AppDelegate.h"
3 | #include "CCEGLView.h"
4 |
5 | USING_NS_CC;
6 |
7 | int APIENTRY _tWinMain(HINSTANCE hInstance,
8 | HINSTANCE hPrevInstance,
9 | LPTSTR lpCmdLine,
10 | int nCmdShow)
11 | {
12 | UNREFERENCED_PARAMETER(hPrevInstance);
13 | UNREFERENCED_PARAMETER(lpCmdLine);
14 |
15 | // create the application instance
16 | AppDelegate app;
17 | CCEGLView* eglView = CCEGLView::sharedOpenGLView();
18 | eglView->setViewName("smooth_panning_zoom");
19 | eglView->setFrameSize( 1280, 720 );
20 | return CCApplication::sharedApplication()->run();
21 | }
22 |
--------------------------------------------------------------------------------
/Classes/HelloWorldScene.h:
--------------------------------------------------------------------------------
1 | #ifndef __HELLOWORLD_SCENE_H__
2 | #define __HELLOWORLD_SCENE_H__
3 |
4 | #include "cocos2d.h"
5 |
6 | using namespace cocos2d;
7 |
8 | class HelloWorld : public Layer {
9 | public:
10 | // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
11 | virtual bool init();
12 |
13 | // there's no 'id' in cpp, so we recommend returning the class instance pointer
14 | static Scene* scene();
15 |
16 | // a selector callback
17 | void menuCloseCallback(Ref *pSender);
18 |
19 | // implement the "static node()" method manually
20 | CREATE_FUNC(HelloWorld);
21 | };
22 |
23 | #endif // __HELLOWORLD_SCENE_H__
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | cocos2d-x-panzoomlayer
2 | ======================
3 |
4 | You can use panning and zooming with inheriting this class!
5 |
6 |
7 | *Usage Example:*
8 |
9 | ```
10 | auto map = Sprite::create("map.jpg");
11 | auto mapSize = map->getContentSize();
12 | map->setAnchorPoint(Vec2(0, 0));
13 | map->setPosition(mapSize * -0.5f);
14 | PanZoomLayer *pzLayer = PanZoomLayer::create();
15 | this->addChild(pzLayer);
16 | pzLayer->SetPanBoundsRect(Rect(mapSize.width * -0.5f, mapSize.height * -0.5f, mapSize.width * 1.0f, mapSize.height * 1.0f));
17 | pzLayer->setScale(1.0f);
18 | pzLayer->addChild(map);
19 | ```
20 |
21 | For reference: [Original post on Cocos2Dx Forum](http://www.cocos2d-x.org/forums/6/topics/5430)
22 |
--------------------------------------------------------------------------------
/proj.android/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 |
--------------------------------------------------------------------------------
/proj.android/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/Classes/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #ifndef _APP_DELEGATE_H_
2 | #define _APP_DELEGATE_H_
3 |
4 | #include "cocos2d.h"
5 |
6 | class AppDelegate : private cocos2d::Application {
7 | public:
8 | AppDelegate() {};
9 | virtual ~AppDelegate() {};
10 |
11 | /**
12 | @brief Implement CCDirector and CCScene init code here.
13 | @return true Initialize success, app continue.
14 | @return false Initialize failed, app terminate.
15 | */
16 | virtual bool applicationDidFinishLaunching();
17 |
18 | /**
19 | @brief The function be called when the application enter background
20 | @param the pointer of the application
21 | */
22 | virtual void applicationDidEnterBackground();
23 |
24 | /**
25 | @brief The function be called when the application enter foreground
26 | @param the pointer of the application
27 | */
28 | virtual void applicationWillEnterForeground();
29 | };
30 |
31 | #endif // _APP_DELEGATE_H_
32 |
--------------------------------------------------------------------------------
/proj.android/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | LOCAL_MODULE := cocos2dcpp_shared
6 |
7 | LOCAL_MODULE_FILENAME := libcocos2dcpp
8 |
9 | LOCAL_SRC_FILES := hellocpp/main.cpp \
10 | ../../Classes/AppDelegate.cpp \
11 | ../../Classes/PanZoomLayer.cpp \
12 | ../../Classes/HelloWorldScene.cpp
13 |
14 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
15 |
16 | LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
17 | LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
18 | LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
19 | LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
20 | LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
21 |
22 | include $(BUILD_SHARED_LIBRARY)
23 |
24 | $(call import-module,cocos2dx)
25 | $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
26 | $(call import-module,CocosDenshion/android)
27 | $(call import-module,extensions)
28 | $(call import-module,external/Box2D)
29 | $(call import-module,external/chipmunk)
30 |
--------------------------------------------------------------------------------
/Classes/AppDelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 | #include "HelloWorldScene.h"
3 |
4 | using namespace cocos2d;
5 |
6 | bool AppDelegate::applicationDidFinishLaunching() {
7 | // initialize director
8 | auto director = Director::getInstance();
9 | auto glview = director->getOpenGLView();
10 |
11 | director->setOpenGLView(glview);
12 |
13 | // turn on display FPS
14 | director->setDisplayStats(true);
15 |
16 | // set FPS. the default value is 1.0/60 if you don't call this
17 | director->setAnimationInterval(1.0 / 60);
18 |
19 | // create a scene. it's an autorelease object
20 | auto scene = HelloWorld::scene();
21 |
22 | // run
23 | director->runWithScene(scene);
24 |
25 | return true;
26 | }
27 |
28 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
29 | void AppDelegate::applicationDidEnterBackground() {
30 | Director::getInstance()->stopAnimation();
31 | }
32 |
33 | // this function will be called when the app is active again
34 | void AppDelegate::applicationWillEnterForeground() {
35 | Director::getInstance()->startAnimation();
36 | }
37 |
--------------------------------------------------------------------------------
/proj.android/jni/hellocpp/main.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 | #include "cocos2d.h"
3 | #include "CCEventType.h"
4 | #include "platform/android/jni/JniHelper.h"
5 | #include
6 | #include
7 |
8 | #define LOG_TAG "main"
9 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
10 |
11 | using namespace cocos2d;
12 |
13 | extern "C"
14 | {
15 |
16 | jint JNI_OnLoad(JavaVM *vm, void *reserved)
17 | {
18 | JniHelper::setJavaVM(vm);
19 |
20 | return JNI_VERSION_1_4;
21 | }
22 |
23 | void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
24 | {
25 | if (!CCDirector::sharedDirector()->getOpenGLView())
26 | {
27 | CCEGLView *view = CCEGLView::sharedOpenGLView();
28 | view->setFrameSize(w, h);
29 |
30 | AppDelegate *pAppDelegate = new AppDelegate();
31 | CCApplication::sharedApplication()->run();
32 | }
33 | else
34 | {
35 | ccGLInvalidateStateCache();
36 | CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
37 | ccDrawInit();
38 | CCTextureCache::reloadAllTextures();
39 | CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_COME_TO_FOREGROUND, NULL);
40 | CCDirector::sharedDirector()->setGLDefaultValues();
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/proj.android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
11 |
13 |
14 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Classes/HelloWorldScene.cpp:
--------------------------------------------------------------------------------
1 | #include "HelloWorldScene.h"
2 | #include "PanZoomLayer.h"
3 |
4 | using namespace cocos2d;
5 |
6 | Scene* HelloWorld::scene() {
7 | auto scene = Scene::create();
8 | auto layer = HelloWorld::create();
9 | scene->addChild(layer);
10 | return scene;
11 | }
12 |
13 | bool HelloWorld::init() {
14 | if (!Layer::init()) {
15 | return false;
16 | }
17 |
18 | Size visibleSize = Director::getInstance()->getVisibleSize();
19 |
20 | auto map = Sprite::create("Fishfam_base_TH8.jpg");
21 | auto mapSize = map->getContentSize();
22 | map->setAnchorPoint(Vec2(0, 0));
23 | map->setPosition(mapSize * -0.5f);
24 | PanZoomLayer *pzLayer = PanZoomLayer::create();
25 | this->addChild(pzLayer);
26 | pzLayer->SetPanBoundsRect(Rect(mapSize.width * -0.5f, mapSize.height * -0.5f, mapSize.width * 1.0f, mapSize.height * 1.0f));
27 | pzLayer->setScale(1.0f);
28 | pzLayer->addChild(map);
29 |
30 | return true;
31 | }
32 |
33 |
34 | void HelloWorld::menuCloseCallback(Ref * pSender) {
35 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
36 | MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.", "Alert");
37 | return;
38 | #endif
39 |
40 | Director::getInstance()->end();
41 |
42 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
43 | exit(0);
44 | #endif
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/proj.win32/smooth_panning_zoom.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {84a8ebd7-7cf0-47f6-b75e-d441df67da40}
6 |
7 |
8 | {bb6c862e-70e9-49d9-81b7-3829a6f50471}
9 |
10 |
11 |
12 |
13 | win32
14 |
15 |
16 | Classes
17 |
18 |
19 | Classes
20 |
21 |
22 | Classes
23 |
24 |
25 |
26 |
27 | win32
28 |
29 |
30 | Classes
31 |
32 |
33 | Classes
34 |
35 |
36 | Classes
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Classes/PanZoomLayer.h:
--------------------------------------------------------------------------------
1 | #ifndef __PANZOOMLAYER_H__
2 | #define __PANZOOMLAYER_H__
3 |
4 | #include "cocos2d.h"
5 |
6 | using namespace cocos2d;
7 |
8 | class PanZoomLayer : public LayerColor {
9 |
10 | private:
11 | Vector _touches;
12 | Vec2 _beganTouchPoint;
13 | Vec2 _endedTouchPoint;
14 | Vec2 _deltaSum;
15 | Vec2 _prevDeltaPoint;
16 | double _accelerationFactor;
17 | timeval _timeStamp;
18 | Rect _panBoundsRect;
19 | float _maxScale;
20 | float _minScale;
21 | float _productFactor;
22 | bool _isHolding;
23 |
24 | public:
25 | PanZoomLayer() {};
26 | virtual ~PanZoomLayer() {};
27 |
28 | static PanZoomLayer *create();
29 |
30 | virtual bool init();
31 | virtual void onEnter();
32 | virtual void onExit();
33 |
34 | virtual void update(float dt);
35 |
36 | virtual void onTouchesBegan(const std::vector &touches, Event *event);
37 | virtual void onTouchesMoved(const std::vector &touches, Event *event);
38 | virtual void onTouchesEnded(const std::vector &touches, Event *event);
39 |
40 | virtual void setPosition(Vec2 position);
41 | virtual void setScale(float scale);
42 |
43 | void SetPanBoundsRect(Rect rect);
44 | void SetMaxScale(float maxScale);
45 | float GetMaxScale();
46 | void SetMinScale(float minScale);
47 | float GetMinScale();
48 |
49 | void Holding();
50 | void UnHolding();
51 |
52 | void SetProductFactor(float v);
53 | };
54 |
55 | #endif // __PANZOOMLAYER_H__
56 |
--------------------------------------------------------------------------------
/proj.android/build_native.sh:
--------------------------------------------------------------------------------
1 | APPNAME="smooth_panning_zoom"
2 | NDK_ROOT="C:\work\android-ndk-r8e"
3 |
4 | # options
5 |
6 | buildexternalsfromsource=
7 |
8 | usage(){
9 | cat << EOF
10 | usage: $0 [options]
11 |
12 | Build C/C++ code for $APPNAME using Android NDK
13 |
14 | OPTIONS:
15 | -s Build externals from source
16 | -h this help
17 | EOF
18 | }
19 |
20 | while getopts "sh" OPTION; do
21 | case "$OPTION" in
22 | s)
23 | buildexternalsfromsource=1
24 | ;;
25 | h)
26 | usage
27 | exit 0
28 | ;;
29 | esac
30 | done
31 |
32 | # paths
33 |
34 | if [ -z "${NDK_ROOT+aaa}" ];then
35 | echo "please define NDK_ROOT"
36 | exit 1
37 | fi
38 |
39 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
40 | # ... use paths relative to current directory
41 | COCOS2DX_ROOT="$DIR/../../.."
42 | APP_ROOT="$DIR/.."
43 | APP_ANDROID_ROOT="$DIR"
44 |
45 | echo "NDK_ROOT = $NDK_ROOT"
46 | echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
47 | echo "APP_ROOT = $APP_ROOT"
48 | echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
49 |
50 | # make sure assets is exist
51 | if [ -d "$APP_ANDROID_ROOT"/assets ]; then
52 | rm -rf "$APP_ANDROID_ROOT"/assets
53 | fi
54 |
55 | mkdir "$APP_ANDROID_ROOT"/assets
56 |
57 | # copy resources
58 | for file in "$APP_ROOT"/Resources/*
59 | do
60 | if [ -d "$file" ]; then
61 | cp -rf "$file" "$APP_ANDROID_ROOT"/assets
62 | fi
63 |
64 | if [ -f "$file" ]; then
65 | cp "$file" "$APP_ANDROID_ROOT"/assets
66 | fi
67 | done
68 |
69 | # run ndk-build
70 | if [[ "$buildexternalsfromsource" ]]; then
71 | echo "Building external dependencies from source"
72 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
73 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
74 | else
75 | echo "Using prebuilt externals"
76 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
77 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"
78 | fi
79 |
--------------------------------------------------------------------------------
/proj.android/src/my/test/smooth/smooth_panning_zoom.java:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2010-2011 cocos2d-x.org
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 | package my.test.smooth;
25 |
26 | import org.cocos2dx.lib.Cocos2dxActivity;
27 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
28 |
29 | import android.os.Bundle;
30 |
31 | public class smooth_panning_zoom extends Cocos2dxActivity{
32 |
33 | protected void onCreate(Bundle savedInstanceState){
34 | super.onCreate(savedInstanceState);
35 | }
36 |
37 | public Cocos2dxGLSurfaceView onCreateView() {
38 | Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
39 | // smooth_panning_zoom should create stencil buffer
40 | glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
41 |
42 | return glSurfaceView;
43 | }
44 |
45 | static {
46 | System.loadLibrary("cocos2dcpp");
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/proj.android/README.md:
--------------------------------------------------------------------------------
1 | ## Prerequisites:
2 |
3 | * Android NDK
4 | * Android SDK **OR** Eclipse ADT Bundle
5 | * Android AVD target installed
6 |
7 | ## Building project
8 |
9 | There are two ways of building Android projects.
10 |
11 | 1. Eclipse
12 | 2. Command Line
13 |
14 | ### Import Project in Eclipse
15 |
16 | #### Features:
17 |
18 | 1. Complete workflow from Eclipse, including:
19 | * Build C++.
20 | * Clean C++.
21 | * Build and Run whole project.
22 | * Logcat view.
23 | * Debug Java code.
24 | * Javascript editor.
25 | * Project management.
26 | 2. True C++ editing, including:
27 | * Code completion.
28 | * Jump to definition.
29 | * Refactoring tools etc.
30 | * Quick open C++ files.
31 |
32 |
33 | #### Setup Eclipse Environment (only once)
34 |
35 |
36 | **NOTE:** This step needs to be done only once to setup the Eclipse environment for cocos2d-x projects. Skip this section if you've done this before.
37 |
38 | 1. Download Eclipse ADT bundle from [Google ADT homepage](http://developer.android.com/sdk/index.html)
39 |
40 | **OR**
41 |
42 | Install Eclipse with Java. Add ADT and CDT plugins.
43 |
44 | 2. Only for Windows
45 | 1. Install [Cygwin](http://www.cygwin.com/) with make (select make package from the list during the install).
46 | 2. Add `Cygwin\bin` directory to system PATH variable.
47 | 3. Add this line `none /cygdrive cygdrive binary,noacl,posix=0,user 0 0` to `Cygwin\etc\fstab` file.
48 |
49 | 3. Set up Variables:
50 | 1. Path Variable `COCOS2DX`:
51 | * Eclipse->Preferences->General->Workspace->**Linked Resources**
52 | * Click **New** button to add a Path Variable `COCOS2DX` pointing to the root cocos2d-x directory.
53 | 
54 |
55 | 2. C/C++ Environment Variable `NDK_ROOT`:
56 | * Eclipse->Preferences->C/C++->Build->**Environment**.
57 | * Click **Add** button and add a new variable `NDK_ROOT` pointing to the root NDK directory.
58 | 
59 | * Only for Windows: Add new variables **CYGWIN** with value `nodosfilewarning` and **SHELLOPTS** with value `igncr`
60 |
61 | 4. Import libcocos2dx library project:
62 | 1. File->New->Project->Android Project From Existing Code.
63 | 2. Click **Browse** button and open `cocos2d-x/cocos2dx/platform/android/java` directory.
64 | 3. Click **Finish** to add project.
65 |
66 | #### Adding and running from Eclipse
67 |
68 |  
69 |
70 | 1. File->New->Project->Android Project From Existing Code
71 | 2. **Browse** to your project directory. eg: `cocos2d-x/cocos2dx/samples/Cpp/TestCpp/proj.android/`
72 | 3. Add the project
73 | 4. Click **Run** or **Debug** to compile C++ followed by Java and to run on connected device or emulator.
74 |
75 |
76 | ### Running project from Command Line
77 |
78 | $ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/
79 | $ export NDK_ROOT=/path/to/ndk
80 | $ ./build_native.sh
81 | $ ant debug install
82 |
83 | If the last command results in sdk.dir missing error then do:
84 |
85 | $ android list target
86 | $ android update project -p . -t (id from step 6)
87 | $ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6)
88 |
--------------------------------------------------------------------------------
/proj.android/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
29 |
30 |
31 |
40 |
41 |
42 |
43 |
47 |
48 |
60 |
61 |
62 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/proj.android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | smooth_panning_zoom
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
25 | clean,full,incremental,
26 |
27 |
28 | ?children?
29 | ?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\||
30 |
31 |
32 | ?name?
33 |
34 |
35 |
36 | org.eclipse.cdt.make.core.append_environment
37 | true
38 |
39 |
40 | org.eclipse.cdt.make.core.autoBuildTarget
41 | all
42 |
43 |
44 | org.eclipse.cdt.make.core.buildArguments
45 | ${ProjDirPath}/build_native.sh
46 |
47 |
48 | org.eclipse.cdt.make.core.buildCommand
49 | bash
50 |
51 |
52 | org.eclipse.cdt.make.core.buildLocation
53 | ${ProjDirPath}
54 |
55 |
56 | org.eclipse.cdt.make.core.cleanBuildTarget
57 | clean
58 |
59 |
60 | org.eclipse.cdt.make.core.contents
61 | org.eclipse.cdt.make.core.activeConfigSettings
62 |
63 |
64 | org.eclipse.cdt.make.core.enableAutoBuild
65 | false
66 |
67 |
68 | org.eclipse.cdt.make.core.enableCleanBuild
69 | true
70 |
71 |
72 | org.eclipse.cdt.make.core.enableFullBuild
73 | true
74 |
75 |
76 | org.eclipse.cdt.make.core.fullBuildTarget
77 |
78 |
79 |
80 | org.eclipse.cdt.make.core.stopOnError
81 | true
82 |
83 |
84 | org.eclipse.cdt.make.core.useDefaultBuildCmd
85 | false
86 |
87 |
88 |
89 |
90 | com.android.ide.eclipse.adt.ApkBuilder
91 |
92 |
93 |
94 |
95 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
96 | full,incremental,
97 |
98 |
99 |
100 |
101 |
102 | com.android.ide.eclipse.adt.AndroidNature
103 | org.eclipse.jdt.core.javanature
104 | org.eclipse.cdt.core.cnature
105 | org.eclipse.cdt.core.ccnature
106 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
107 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
108 |
109 |
110 |
111 | Classes
112 | 2
113 | COCOS2DX/projects/smooth_panning_zoom/Classes
114 |
115 |
116 | cocos2dx
117 | 2
118 | COCOS2DX/cocos2dx
119 |
120 |
121 | extensions
122 | 2
123 | COCOS2DX/extensions
124 |
125 |
126 | scripting
127 | 2
128 | COCOS2DX/scripting
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/proj.win32/smooth_panning_zoom.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smooth_panning_zoom", "smooth_panning_zoom.vcxproj", "{76A39BB2-9B84-4C65-98A5-654D86B86F2A}"
5 | ProjectSection(ProjectDependencies) = postProject
6 | {21B2C324-891F-48EA-AD1A-5AE13DE12E28} = {21B2C324-891F-48EA-AD1A-5AE13DE12E28}
7 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
8 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}
9 | {929480E7-23C0-4DF6-8456-096D71547116} = {929480E7-23C0-4DF6-8456-096D71547116}
10 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
11 | EndProjectSection
12 | EndProject
13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\..\..\cocos2dx\proj.win32\cocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
14 | EndProject
15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCocosDenshion", "..\..\..\CocosDenshion\proj.win32\CocosDenshion.vcxproj", "{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}"
16 | ProjectSection(ProjectDependencies) = postProject
17 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
18 | EndProjectSection
19 | EndProject
20 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libExtensions", "..\..\..\extensions\proj.win32\libExtensions.vcxproj", "{21B2C324-891F-48EA-AD1A-5AE13DE12E28}"
21 | ProjectSection(ProjectDependencies) = postProject
22 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
23 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}
24 | {929480E7-23C0-4DF6-8456-096D71547116} = {929480E7-23C0-4DF6-8456-096D71547116}
25 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
26 | EndProjectSection
27 | EndProject
28 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libBox2D", "..\..\..\external\Box2D\proj.win32\Box2D.vcxproj", "{929480E7-23C0-4DF6-8456-096D71547116}"
29 | EndProject
30 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libchipmunk", "..\..\..\external\chipmunk\proj.win32\chipmunk.vcxproj", "{207BC7A9-CCF1-4F2F-A04D-45F72242AE25}"
31 | EndProject
32 | Global
33 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
34 | Debug|Win32 = Debug|Win32
35 | Release|Win32 = Release|Win32
36 | EndGlobalSection
37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
38 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.ActiveCfg = Debug|Win32
39 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.Build.0 = Debug|Win32
40 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.ActiveCfg = Release|Win32
41 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.Build.0 = Release|Win32
42 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.ActiveCfg = Debug|Win32
43 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.Build.0 = Debug|Win32
44 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.ActiveCfg = Release|Win32
45 | {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.Build.0 = Release|Win32
46 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Win32.ActiveCfg = Debug|Win32
47 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Debug|Win32.Build.0 = Debug|Win32
48 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Win32.ActiveCfg = Release|Win32
49 | {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}.Release|Win32.Build.0 = Release|Win32
50 | {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Debug|Win32.ActiveCfg = Debug|Win32
51 | {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Debug|Win32.Build.0 = Debug|Win32
52 | {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Release|Win32.ActiveCfg = Release|Win32
53 | {21B2C324-891F-48EA-AD1A-5AE13DE12E28}.Release|Win32.Build.0 = Release|Win32
54 | {929480E7-23C0-4DF6-8456-096D71547116}.Debug|Win32.ActiveCfg = Debug|Win32
55 | {929480E7-23C0-4DF6-8456-096D71547116}.Debug|Win32.Build.0 = Debug|Win32
56 | {929480E7-23C0-4DF6-8456-096D71547116}.Release|Win32.ActiveCfg = Release|Win32
57 | {929480E7-23C0-4DF6-8456-096D71547116}.Release|Win32.Build.0 = Release|Win32
58 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Win32.ActiveCfg = Debug|Win32
59 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Debug|Win32.Build.0 = Debug|Win32
60 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Win32.ActiveCfg = Release|Win32
61 | {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}.Release|Win32.Build.0 = Release|Win32
62 | EndGlobalSection
63 | GlobalSection(SolutionProperties) = preSolution
64 | HideSolutionNode = FALSE
65 | EndGlobalSection
66 | EndGlobal
67 |
--------------------------------------------------------------------------------
/Classes/PanZoomLayer.cpp:
--------------------------------------------------------------------------------
1 | #include "PanZoomLayer.h"
2 |
3 | PanZoomLayer *PanZoomLayer::create() {
4 | PanZoomLayer *pRet = new PanZoomLayer;
5 | if (pRet && pRet->init()) {
6 | pRet->autorelease();
7 | return pRet;
8 | }
9 | CC_SAFE_DELETE(pRet);
10 | return NULL;
11 | }
12 |
13 | bool PanZoomLayer::init() {
14 | if (!LayerColor::initWithColor(Color4B(255, 0, 0, 0))) return false;
15 |
16 | this->setAnchorPoint(Vec2(0, 0));
17 |
18 | _accelerationFactor = 0.0f;
19 | _productFactor = 55.0f;
20 |
21 | _maxScale = 8.0f;
22 | _minScale = 0.1f;
23 |
24 | _isHolding = false;
25 |
26 | return true;
27 | }
28 |
29 | void PanZoomLayer::onEnter() {
30 | Layer::onEnter();
31 | Director::getInstance()->getScheduler()->scheduleUpdate(this, 0, false);
32 | auto touchListener = EventListenerTouchAllAtOnce::create();
33 | touchListener->onTouchesBegan = CC_CALLBACK_2(PanZoomLayer::onTouchesBegan, this);
34 | touchListener->onTouchesMoved = CC_CALLBACK_2(PanZoomLayer::onTouchesMoved, this);
35 | touchListener->onTouchesEnded = CC_CALLBACK_2(PanZoomLayer::onTouchesEnded, this);
36 | this->_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
37 | }
38 |
39 | void PanZoomLayer::onExit() {
40 | Director::getInstance()->getScheduler()->unscheduleAllForTarget(this);
41 | Layer::onExit();
42 | _touches.clear();
43 | }
44 |
45 | void PanZoomLayer::update(float dt) {
46 | // Skip smoothe panning when dt is high value
47 | if (dt > 1.0f / 55) return;
48 |
49 | LayerColor::update(dt);
50 |
51 | if (_touches.size() == 1) {
52 | _accelerationFactor *= 40 * dt * 0.95f;
53 | }
54 | else if (_touches.size() == 0) {
55 | _accelerationFactor = fabs(_accelerationFactor - 0);
56 | if (_accelerationFactor < FLT_EPSILON) return;
57 | if (_accelerationFactor < 0.004f) {
58 | _accelerationFactor = 0;
59 | }
60 | else {
61 | double d = dt * 60;
62 | if (d > 0.99) d = 0.99;
63 | double i = (0 - _accelerationFactor) * 0.025 * d;
64 |
65 | _accelerationFactor = (_accelerationFactor + i) * d;
66 |
67 | Vec2 adder = _deltaSum;
68 | adder.x *= this->getContentSize().width;
69 | adder.y *= this->getContentSize().height;
70 |
71 | this->setPosition(this->getPosition() + adder * 2.5 * _accelerationFactor);
72 | }
73 | }
74 | }
75 |
76 | void PanZoomLayer::onTouchesBegan(const std::vector &touches, Event *event) {
77 | if (_isHolding) return;
78 |
79 | for (auto &touch: touches) {
80 | _touches.pushBack(touch);
81 | }
82 |
83 | _deltaSum = Vec2(0, 0);
84 | _accelerationFactor = 0;
85 | gettimeofday(&_timeStamp, NULL);
86 | }
87 |
88 | void PanZoomLayer::onTouchesMoved(const std::vector &touches, Event *event) {
89 | if (_isHolding) return;
90 |
91 | if (_touches.size() == 1) {
92 | Touch *touch = (Touch *) _touches.at(0);
93 | Vec2 curTouchPosition = Director::getInstance()->convertToGL(touch->getLocationInView());
94 | Vec2 prevTouchPosition = Director::getInstance()->convertToGL(touch->getPreviousLocationInView());
95 | Vec2 deltaPosition = curTouchPosition - prevTouchPosition;
96 | this->setPosition(this->getPosition() + deltaPosition);
97 |
98 | float prevAngle = CC_RADIANS_TO_DEGREES(_prevDeltaPoint.getAngle());
99 | float angle = CC_RADIANS_TO_DEGREES(deltaPosition.getAngle());
100 | if (fabs(prevAngle - angle) <= 30) {
101 | _deltaSum = Vec2(0, 0);
102 | }
103 |
104 | _prevDeltaPoint = deltaPosition;
105 |
106 | _deltaSum.x = _deltaSum.x + deltaPosition.x / this->getContentSize().width;
107 | _deltaSum.y = _deltaSum.y + deltaPosition.y / this->getContentSize().height;
108 |
109 | _accelerationFactor += _deltaSum.getLength() * 4.0;
110 | }
111 | else if (_touches.size() >= 2) {
112 | // Get the two first touches
113 | Touch *touch1 = (Touch *) _touches.at(0);
114 | Touch *touch2 = (Touch *) _touches.at(1);
115 | log("touch1 %f", touch1->getLocation().x);
116 | log("touch2 %f", touch2->getLocation().x);
117 |
118 | // Get current and previous positions of the touches
119 | Vec2 curPosTouch1 = Director::getInstance()->convertToGL(touch1->getLocationInView());
120 | Vec2 curPosTouch2 = Director::getInstance()->convertToGL(touch2->getLocationInView());
121 | Vec2 prevPosTouch1 = Director::getInstance()->convertToGL(touch1->getPreviousLocationInView());
122 | Vec2 prevPosTouch2 = Director::getInstance()->convertToGL(touch2->getPreviousLocationInView());
123 |
124 | // Calculate current and previous positions of the layer relative the anchor point
125 | Vec2 curPosLayer = curPosTouch1.getMidpoint(curPosTouch2);
126 | Vec2 prevPosLayer = prevPosTouch1.getMidpoint(prevPosTouch2);
127 | log("curPosLayer %f %f", curPosLayer.x, curPosLayer.y);
128 | log("prevPosLayer %f %f", prevPosLayer.x, prevPosLayer.y);
129 |
130 | // Calculate new scale
131 | float prevScale = this->getScale();
132 | float curScale = this->getScale() * curPosTouch1.distance(curPosTouch2) / prevPosTouch1.distance(prevPosTouch2);
133 |
134 | this->setScale(curScale);
135 | log("setScale %f", curScale);
136 |
137 | if (this->getScale() != prevScale) {
138 | Vec2 realCurPosLayer = this->convertToNodeSpaceAR(curPosLayer);
139 | float deltaX = (realCurPosLayer.x) * (this->getScale() - prevScale);
140 | float deltaY = (realCurPosLayer.y) * (this->getScale() - prevScale);
141 |
142 | this->setPosition(Vec2(this->getPosition().x - deltaX, this->getPosition().y - deltaY));
143 | }
144 |
145 | // If current and previous position of the multitouch's center aren't equal -> change position of the layer
146 | if (!prevPosLayer.equals(curPosLayer)) {
147 | this->setPosition(Vec2(this->getPosition().x + curPosLayer.x - prevPosLayer.x,
148 | this->getPosition().y + curPosLayer.y - prevPosLayer.y));
149 | }
150 | }
151 | }
152 |
153 | void PanZoomLayer::onTouchesEnded(const std::vector &touches, Event *event) {
154 | if (_isHolding) return;
155 |
156 | for (auto touch: touches) {
157 | _touches.eraseObject(touch);
158 | }
159 | }
160 |
161 | void PanZoomLayer::setPosition(Vec2 position) {
162 | Node::setPosition(position);
163 |
164 | if (_panBoundsRect.equals(Rect::ZERO) == false) {
165 | Rect boundBox;
166 | boundBox.origin = this->getPosition() / this->getScale();
167 | boundBox.size = this->getContentSize() / this->getScale();
168 | // log("boundBox : origin(%.1f, %.1f), size(%.1f, %.1f)", boundBox.origin.x, boundBox.origin.y, boundBox.size.width, boundBox.size.height);
169 |
170 | // OpenGL coordinate system
171 | float left = boundBox.getMinX();
172 | float right = boundBox.getMaxX();
173 | float top = boundBox.getMaxY();
174 | float bottom = boundBox.getMinY();
175 | // log("left,right(%.1f, %.1f), top,bottom(%.1f, %.1f)", left, right, top, bottom);
176 |
177 | float min_x = _panBoundsRect.getMinX() + boundBox.size.width;
178 | float max_x = _panBoundsRect.getMaxX() + boundBox.size.width;
179 | float min_y = _panBoundsRect.getMinY() + boundBox.size.height;
180 | float max_y = _panBoundsRect.getMaxY() + boundBox.size.height;
181 | // log("min(%.1f, %.1f), max(%.1f, %.1f)", min_x, min_y, max_x, max_y);
182 |
183 | float scale = this->getScale();
184 | float arLeft = min_x * scale;
185 | float arRight = max_x * scale - this->getContentSize().width;
186 | float arTop = max_y * scale - this->getContentSize().height;
187 | float arBottom = min_y * scale;
188 |
189 | if (left < min_x) {
190 | Node::setPosition(arLeft, this->getPosition().y);
191 | }
192 |
193 | if (right > max_x) {
194 | Node::setPosition(arRight, this->getPosition().y);
195 | }
196 |
197 | if (top > max_y) {
198 | Node::setPosition(this->getPosition().x, arTop);
199 | }
200 |
201 | if (bottom < min_y) {
202 | Node::setPosition(this->getPosition().x, arBottom);
203 | }
204 | }
205 | }
206 |
207 | void PanZoomLayer::setScale(float scale) {
208 | LayerColor::setScale(MIN(MAX(scale, _minScale), _maxScale));
209 | this->setPosition(this->getPosition());
210 | }
211 |
212 | void PanZoomLayer::SetPanBoundsRect(Rect rect) {
213 | _panBoundsRect = rect;
214 |
215 | Size visibleSize = Director::getInstance()->getVisibleSize();
216 | float wFactor = _panBoundsRect.size.width / visibleSize.width;
217 | float hFactor = _panBoundsRect.size.height / visibleSize.height;
218 | float minScale;
219 | if (wFactor > hFactor)
220 | minScale = wFactor;
221 | else
222 | minScale = hFactor;
223 | SetMinScale(minScale);
224 | }
225 |
226 | void PanZoomLayer::SetMaxScale(float maxScale) {
227 | _maxScale = maxScale;
228 | }
229 |
230 | float PanZoomLayer::GetMaxScale() {
231 | return _maxScale;
232 | }
233 |
234 | void PanZoomLayer::SetMinScale(float minScale) {
235 | _minScale = minScale;
236 | }
237 |
238 | float PanZoomLayer::GetMinScale() {
239 | return _minScale;
240 | }
241 |
242 | void PanZoomLayer::Holding() {
243 | _isHolding = true;
244 | }
245 |
246 | void PanZoomLayer::UnHolding() {
247 | _isHolding = false;
248 | }
249 |
250 | void PanZoomLayer::SetProductFactor(float v) {
251 | _productFactor = v;
252 | }
253 |
--------------------------------------------------------------------------------
/proj.android/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
33 |
34 |
35 |
45 |
48 |
49 |
50 |
51 |
61 |
64 |
65 |
66 |
67 |
75 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/proj.win32/smooth_panning_zoom.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}
15 | test_win32
16 | Win32Proj
17 |
18 |
19 |
20 | Application
21 | Unicode
22 | true
23 | v100
24 | v110
25 | v110_xp
26 | v120
27 | v120_xp
28 |
29 |
30 | Application
31 | Unicode
32 | v100
33 | v110
34 | v110_xp
35 | v120
36 | v120_xp
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | <_ProjectFileVersion>10.0.40219.1
50 | $(SolutionDir)$(Configuration).win32\
51 | $(Configuration).win32\
52 | true
53 | $(SolutionDir)$(Configuration).win32\
54 | $(Configuration).win32\
55 | false
56 | AllRules.ruleset
57 |
58 |
59 | AllRules.ruleset
60 |
61 |
62 |
63 |
64 | $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath)
65 |
66 |
67 | $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\lib;$(LibraryPath)
68 |
69 |
70 |
71 | Disabled
72 | $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\external;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;..\Classes;..;%(AdditionalIncludeDirectories)
73 | WIN32;_DEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
74 | true
75 | EnableFastChecks
76 | MultiThreadedDebugDLL
77 |
78 |
79 | Level3
80 | EditAndContinue
81 | 4267;4251;4244;%(DisableSpecificWarnings)
82 |
83 |
84 | libExtensions.lib;libcocos2d.lib;libCocosDenshion.lib;opengl32.lib;glew32.lib;libBox2d.lib;libchipmunk.lib;libcurl_imp.lib;pthreadVCE2.lib;websockets.lib;%(AdditionalDependencies)
85 | $(OutDir)$(ProjectName).exe
86 | $(OutDir);%(AdditionalLibraryDirectories)
87 | true
88 | Windows
89 | MachineX86
90 |
91 |
92 |
93 |
94 |
95 |
96 | if not exist "$(OutDir)" mkdir "$(OutDir)"
97 | xcopy /Y /Q "$(ProjectDir)..\..\..\external\libwebsockets\win32\lib\*.*" "$(OutDir)"
98 |
99 |
100 |
101 |
102 | MaxSpeed
103 | true
104 | $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\external;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;..\Classes;..;%(AdditionalIncludeDirectories)
105 | WIN32;NDEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;CC_ENABLE_CHIPMUNK_INTEGRATION=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
106 | MultiThreadedDLL
107 | true
108 |
109 |
110 | Level3
111 | ProgramDatabase
112 | 4267;4251;4244;%(DisableSpecificWarnings)
113 |
114 |
115 | libExtensions.lib;libcocos2d.lib;libCocosDenshion.lib;opengl32.lib;glew32.lib;libBox2d.lib;libchipmunk.lib;libcurl_imp.lib;pthreadVCE2.lib;websockets.lib;%(AdditionalDependencies)
116 | $(OutDir)$(ProjectName).exe
117 | $(OutDir);%(AdditionalLibraryDirectories)
118 | true
119 | Windows
120 | true
121 | true
122 | MachineX86
123 |
124 |
125 |
126 |
127 |
128 |
129 | if not exist "$(OutDir)" mkdir "$(OutDir)"
130 | xcopy /Y /Q "$(ProjectDir)..\..\..\external\libwebsockets\win32\lib\*.*" "$(OutDir)"
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | {98a51ba8-fc3a-415b-ac8f-8c7bd464e93e}
148 | false
149 |
150 |
151 | {f8edd7fa-9a51-4e80-baeb-860825d2eac6}
152 | false
153 |
154 |
155 | {21b2c324-891f-48ea-ad1a-5ae13de12e28}
156 | false
157 |
158 |
159 | {929480e7-23c0-4df6-8456-096d71547116}
160 | false
161 |
162 |
163 | {207bc7a9-ccf1-4f2f-a04d-45f72242ae25}
164 | false
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------