From 1b19fd140ff139b5854a1a62447faf31b175d8f6 Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 10 Sep 2020 13:15:11 +0100 Subject: [PATCH] Updated demos to use DALi clang-format Change-Id: I2be80c43c2f83b2333df48210b53258e4be1acae --- .clang-format | 96 + .../src/main/cpp/dali-demo-native-activity-jni.h | 18 +- build/android/app/src/main/cpp/main.cpp | 79 +- builder/dali-builder.cpp | 120 +- demo/dali-demo.cpp | 8 +- examples-reel/dali-examples-reel.cpp | 10 +- .../alpha-blending-cpu-example.cpp | 95 +- .../animated-gradient-call-active.cpp | 453 +++-- .../animated-gradient-card-active.cpp | 685 ++++---- .../animated-images/animated-images-example.cpp | 245 ++- .../animated-shapes/animated-shapes-example.cpp | 496 +++--- .../animated-vector-images-example.cpp | 200 ++- examples/arc-visual/arc-visual-example.cpp | 294 ++-- examples/benchmark/benchmark.cpp | 471 +++-- examples/bezier-curve/bezier-curve-example.cpp | 538 +++--- examples/blocks/blocks-example.cpp | 467 +++-- examples/bloom-view/bloom-view-example.cpp | 152 +- examples/bubble-effect/bubble-effect-example.cpp | 229 ++- examples/builder/examples.cpp | 294 ++-- examples/buttons/buttons-example.cpp | 476 +++-- .../clipping-draw-order/clipping-draw-order.cpp | 168 +- examples/clipping/clipping-example.cpp | 139 +- examples/clipping/clipping-item-factory.cpp | 35 +- examples/clipping/clipping-item-factory.h | 11 +- .../clipping/item-view-orientation-constraint.h | 44 +- examples/color-visual/color-visual-example.cpp | 91 +- .../compressed-texture-formats-example.cpp | 150 +- examples/contact-cards/clipped-image.cpp | 102 +- examples/contact-cards/clipped-image.h | 9 +- examples/contact-cards/contact-card-layout-info.h | 3 +- examples/contact-cards/contact-card-layouter.cpp | 54 +- examples/contact-cards/contact-card-layouter.h | 20 +- examples/contact-cards/contact-card.cpp | 286 +-- examples/contact-cards/contact-card.h | 38 +- examples/contact-cards/contact-cards-example.cpp | 42 +- examples/contact-cards/contact-data.cpp | 37 +- examples/contact-cards/contact-data.h | 11 +- examples/contact-cards/masked-image.cpp | 16 +- examples/contact-cards/masked-image.h | 9 +- .../cube-transition-effect-example.cpp | 309 ++-- examples/deferred-shading/deferred-shading.cpp | 402 +++-- .../dissolve-effect/dissolve-effect-example.cpp | 342 ++-- examples/drag-and-drop/drag-and-drop-example.cpp | 129 +- examples/effects-view/effects-view-example.cpp | 184 +- examples/flex-container/flex-container-example.cpp | 268 ++- examples/focus-integration/focus-integration.cpp | 172 +- examples/fpp-game/fpp-game-example.cpp | 38 +- examples/fpp-game/fpp-game-tutorial-controller.cpp | 149 +- examples/fpp-game/fpp-game-tutorial-controller.h | 28 +- examples/fpp-game/game-camera.cpp | 183 +- examples/fpp-game/game-camera.h | 19 +- examples/fpp-game/game-container.h | 24 +- examples/fpp-game/game-entity.cpp | 34 +- examples/fpp-game/game-entity.h | 18 +- examples/fpp-game/game-model.cpp | 34 +- examples/fpp-game/game-model.h | 36 +- examples/fpp-game/game-renderer.cpp | 43 +- examples/fpp-game/game-renderer.h | 15 +- examples/fpp-game/game-scene.cpp | 134 +- examples/fpp-game/game-scene.h | 48 +- examples/fpp-game/game-texture.cpp | 44 +- examples/fpp-game/game-texture.h | 22 +- examples/fpp-game/game-utils.cpp | 36 +- examples/fpp-game/game-utils.h | 11 +- examples/fpp-game/third-party/picojson.h | 1836 ++++++++++++-------- examples/frame-callback/frame-callback-example.cpp | 118 +- examples/frame-callback/frame-callback.cpp | 24 +- examples/frame-callback/frame-callback.h | 13 +- .../gaussian-blur-view-example.cpp | 124 +- examples/gestures/gesture-example.cpp | 316 ++-- examples/gradients/gradients-example.cpp | 163 +- examples/hello-world/hello-world-example.cpp | 39 +- .../homescreen-benchmark/homescreen-benchmark.cpp | 416 +++-- examples/image-policies/image-policies-example.cpp | 445 +++-- .../image-scaling-and-filtering-example.cpp | 649 ++++--- examples/image-scaling-irregular-grid/grid-flags.h | 108 +- .../image-scaling-irregular-grid-example.cpp | 417 +++-- .../image-view-alpha-blending-example.cpp | 98 +- .../image-view-pixel-area-example.cpp | 268 ++- examples/image-view-svg/image-view-svg-example.cpp | 208 ++- examples/image-view-url/image-view-url-example.cpp | 137 +- examples/image-view/image-view-example.cpp | 266 ++- examples/item-view/item-view-example.cpp | 701 ++++---- examples/line-mesh/line-mesh-example.cpp | 320 ++-- examples/magnifier/magnifier-example.cpp | 169 +- examples/mesh-morph/mesh-morph-example.cpp | 333 ++-- examples/mesh-visual/mesh-visual-example.cpp | 430 +++-- .../metaball-explosion-example.cpp | 347 ++-- .../metaball-refrac/metaball-refrac-example.cpp | 445 ++--- examples/model3d-view/model3d-view-example.cpp | 164 +- examples/motion-blur/motion-blur-example.cpp | 271 ++- examples/motion-stretch/motion-stretch-example.cpp | 246 ++- .../native-image-source-example.cpp | 292 ++-- examples/page-turn-view/page-turn-view-example.cpp | 186 +- examples/perf-scroll/perf-scroll.cpp | 458 ++--- examples/pivot/pivot-example.cpp | 91 +- examples/point-mesh/point-mesh-example.cpp | 177 +- examples/popup/popup-example.cpp | 674 ++++--- .../pre-render-callback-example.cpp | 179 +- .../primitive-shapes/primitive-shapes-example.cpp | 482 +++-- examples/progress-bar/progress-bar-example.cpp | 218 ++- .../property-notification-example.cpp | 61 +- examples/ray-marching/ray-marching-example.cpp | 145 +- examples/reflection-demo/gltf-scene.cpp | 338 ++-- examples/reflection-demo/gltf-scene.h | 82 +- examples/reflection-demo/pico-json.h | 1032 +++++++---- examples/reflection-demo/reflection-example.cpp | 442 +++-- .../refraction-effect-example.cpp | 399 ++--- .../remote-image-loading-example.cpp | 131 +- .../renderer-stencil/renderer-stencil-example.cpp | 523 +++--- .../renderer-stencil/renderer-stencil-shaders.h | 16 +- .../rendering-basic-light-example.cpp | 329 ++-- examples/rendering-basic-pbr/ktx-loader.cpp | 79 +- examples/rendering-basic-pbr/ktx-loader.h | 7 +- examples/rendering-basic-pbr/model-pbr.cpp | 57 +- examples/rendering-basic-pbr/model-pbr.h | 14 +- examples/rendering-basic-pbr/model-skybox.cpp | 151 +- examples/rendering-basic-pbr/model-skybox.h | 12 +- examples/rendering-basic-pbr/obj-loader.cpp | 370 ++-- examples/rendering-basic-pbr/obj-loader.h | 79 +- .../rendering-basic-pbr-example.cpp | 330 ++-- examples/rendering-cube/rendering-cube.cpp | 190 +- examples/rendering-line/rendering-line.cpp | 78 +- .../rendering-radial-progress/radial-progress.cpp | 165 +- examples/rendering-skybox/look-camera.cpp | 107 +- examples/rendering-skybox/look-camera.h | 15 +- examples/rendering-skybox/rendering-skybox.cpp | 366 ++-- .../rendering-textured-cube.cpp | 189 +- examples/rendering-triangle/rendering-triangle.cpp | 80 +- examples/scroll-view/scroll-view-example.cpp | 498 +++--- .../shadows-and-lights-example.cpp | 365 ++-- .../simple-text-label-example.cpp | 180 +- .../simple-scroll-view-example.cpp | 102 +- examples/simple-text-field/simple-text-field.cpp | 41 +- .../simple-text-label-example.cpp | 40 +- .../simple-text-renderer-example.cpp | 228 ++- .../simple-text-visual-example.cpp | 45 +- .../simple-visuals-control/my-control-impl.cpp | 71 +- examples/simple-visuals-control/my-control-impl.h | 28 +- examples/simple-visuals-control/my-control.cpp | 28 +- examples/simple-visuals-control/my-control.h | 23 +- .../simple-visuals-application.cpp | 69 +- .../simple-visuals-application.h | 20 +- .../simple-visuals-example.cpp | 12 +- .../size-negotiation/size-negotiation-example.cpp | 953 +++++----- examples/sparkle/sparkle-effect-example.cpp | 382 ++-- examples/sparkle/sparkle-effect.h | 447 ++--- examples/styling/image-channel-control-impl.cpp | 168 +- examples/styling/image-channel-control-impl.h | 56 +- examples/styling/image-channel-control.cpp | 40 +- examples/styling/image-channel-control.h | 29 +- examples/styling/style-example.cpp | 15 +- examples/styling/styling-application.cpp | 716 ++++---- examples/styling/styling-application.h | 56 +- .../super-blur-view/super-blur-view-example.cpp | 66 +- examples/text-editor/text-editor-example.cpp | 272 ++- examples/text-field/text-field-example.cpp | 109 +- examples/text-fonts/text-fonts-example.cpp | 186 +- examples/text-label-emojis/emoji-strings.h | 68 +- examples/text-label-emojis/text-label-emojis.cpp | 82 +- .../text-label-multi-language-example.cpp | 72 +- examples/text-label/expanding-buttons-impl.cpp | 84 +- examples/text-label/expanding-buttons-impl.h | 39 +- examples/text-label/expanding-buttons.cpp | 34 +- examples/text-label/expanding-buttons.h | 25 +- examples/text-label/text-label-example.cpp | 574 +++--- .../text-memory-profiling-example.cpp | 270 ++- examples/text-overlap/text-overlap-example.cpp | 140 +- examples/text-overlap/text-overlap-example.h | 41 +- examples/text-scrolling/text-scrolling-example.cpp | 389 ++--- examples/textured-mesh/textured-mesh-example.cpp | 152 +- examples/tilt/tilt-example.cpp | 63 +- examples/tooltip/tooltip-example.cpp | 132 +- examples/transitions/shadow-button-impl.cpp | 304 ++-- examples/transitions/shadow-button-impl.h | 85 +- examples/transitions/shadow-button.cpp | 38 +- examples/transitions/shadow-button.h | 27 +- examples/transitions/transition-application.cpp | 175 +- examples/transitions/transition-application.h | 29 +- examples/transitions/transition-example.cpp | 9 +- examples/video-view/video-view-example.cpp | 300 ++-- .../visual-fitting-mode-example.cpp | 198 +-- examples/visual-transitions/beat-control-impl.cpp | 193 +- examples/visual-transitions/beat-control-impl.h | 68 +- examples/visual-transitions/beat-control.cpp | 30 +- examples/visual-transitions/beat-control.h | 25 +- .../visual-transitions/transition-application.cpp | 280 ++- .../visual-transitions/transition-application.h | 35 +- examples/visual-transitions/transition-example.cpp | 9 +- examples/web-view/web-view-example.cpp | 98 +- shared/dali-demo-strings.h | 398 ++--- shared/dali-table-view.cpp | 710 ++++---- shared/dali-table-view.h | 115 +- shared/execute-process-android.cpp | 14 +- shared/execute-process-unix.cpp | 14 +- shared/execute-process-win.cpp | 32 +- shared/execute-process.h | 7 +- shared/multi-language-strings.h | 325 ++-- shared/utility.h | 51 +- shared/view.h | 135 +- tests-reel/dali-tests-reel.cpp | 10 +- 201 files changed, 19111 insertions(+), 19041 deletions(-) create mode 100644 .clang-format mode change 100755 => 100644 examples/cube-transition-effect/cube-transition-effect-example.cpp mode change 100755 => 100644 examples/deferred-shading/deferred-shading.cpp mode change 100755 => 100644 examples/dissolve-effect/dissolve-effect-example.cpp mode change 100755 => 100644 examples/image-view-svg/image-view-svg-example.cpp mode change 100755 => 100644 examples/item-view/item-view-example.cpp mode change 100755 => 100644 examples/model3d-view/model3d-view-example.cpp mode change 100755 => 100644 examples/motion-blur/motion-blur-example.cpp mode change 100755 => 100644 examples/motion-stretch/motion-stretch-example.cpp mode change 100755 => 100644 examples/primitive-shapes/primitive-shapes-example.cpp mode change 100755 => 100644 examples/reflection-demo/reflection-example.cpp mode change 100755 => 100644 examples/shadows-and-lights/shadows-and-lights-example.cpp mode change 100755 => 100644 examples/sparkle/sparkle-effect-example.cpp mode change 100755 => 100644 examples/styling/styling-application.cpp mode change 100755 => 100644 examples/text-label/text-label-example.cpp mode change 100755 => 100644 examples/text-overlap/text-overlap-example.cpp mode change 100755 => 100644 examples/text-scrolling/text-scrolling-example.cpp mode change 100755 => 100644 examples/video-view/video-view-example.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d314ca1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,96 @@ +--- +Language: Cpp +BasedOnStyle: Google +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: true + AfterUnion: true + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +ConstructorInitializerAllOnOneLineOrOnePerLine: true +AllowAllConstructorInitializersOnNextLine : false +ConstructorInitializerIndentWidth: 0 +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +SpaceBeforeCtorInitializerColon: false +IndentCaseLabels: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '^DALI_ENUM_TO_STRING_TABLE_BEGIN' +MacroBlockEnd: 'DALI_ENUM_TO_STRING_TABLE_END' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: Never +SpaceInEmptyParentheses: false +SpacesInConditionalStatement : false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceAfterTemplateKeyword: false +Standard: Auto +TabWidth: 2 +UseTab: Never +... diff --git a/build/android/app/src/main/cpp/dali-demo-native-activity-jni.h b/build/android/app/src/main/cpp/dali-demo-native-activity-jni.h index 2b2df8d..834f1b6 100644 --- a/build/android/app/src/main/cpp/dali-demo-native-activity-jni.h +++ b/build/android/app/src/main/cpp/dali-demo-native-activity-jni.h @@ -17,8 +17,8 @@ #ifndef ANDROID_DALI_DEMO_NATIVE_ACTIVITY_JNI_H #define ANDROID_DALI_DEMO_NATIVE_ACTIVITY_JNI_H -#include #include +#include class DaliDemoNativeActivity { @@ -46,10 +46,10 @@ public: std::string ToString() { std::string out; - if (string) + if(string) { const char* utf = env->GetStringUTFChars(string, 0); - out = std::string(utf); + out = std::string(utf); env->ReleaseStringUTFChars(string, utf); } return out; @@ -57,7 +57,7 @@ public: ~JString() { - if (string) + if(string) { env->DeleteLocalRef(string); } @@ -87,22 +87,22 @@ public: std::string CallStringMethod(const std::string& name, const std::string& arg) { jmethodID methodID = env->GetMethodID(clazz, name.c_str(), "(Ljava/lang/String;)Ljava/lang/String;"); - JString argument(env, arg); - JString returnValue(env, (jstring)env->CallObjectMethod(activity->clazz, methodID, argument.string)); + JString argument(env, arg); + JString returnValue(env, (jstring)env->CallObjectMethod(activity->clazz, methodID, argument.string)); return returnValue.ToString(); } void CallVoidMethod(const std::string& name, const std::string& arg) { jmethodID methodID = env->GetMethodID(clazz, name.c_str(), "(Ljava/lang/String;)V"); - JString argument(env, arg); + JString argument(env, arg); env->CallVoidMethod(activity->clazz, methodID, argument.string); } private: ANativeActivity* activity; - JNIEnv* env; - jclass clazz; + JNIEnv* env; + jclass clazz; }; std::string GetMetaData(const std::string& key) diff --git a/build/android/app/src/main/cpp/main.cpp b/build/android/app/src/main/cpp/main.cpp index 09fe76a..0ba207a 100644 --- a/build/android/app/src/main/cpp/main.cpp +++ b/build/android/app/src/main/cpp/main.cpp @@ -16,50 +16,49 @@ */ // EXTERNAL INCLUDES -#include #include +#include #include #include #include #include #include -#include #include +#include #include // from android_native_app_glue.c #ifndef NDEBUG -#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "dalidemo", __VA_ARGS__)) +#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "dalidemo", __VA_ARGS__)) #else -#define LOGV(...) ((void)0) +#define LOGV(...) ((void)0) #endif namespace { - -void free_saved_state(struct android_app *android_app) +void free_saved_state(struct android_app* android_app) { LOGV("free_saved_state"); pthread_mutex_lock(&android_app->mutex); - if (android_app->savedState != NULL) + if(android_app->savedState != NULL) { free(android_app->savedState); - android_app->savedState = NULL; + android_app->savedState = NULL; android_app->savedStateSize = 0; } pthread_mutex_unlock(&android_app->mutex); } -void android_app_destroy(struct android_app *android_app) +void android_app_destroy(struct android_app* android_app) { LOGV("android_app_destroy"); free_saved_state(android_app); pthread_mutex_lock(&android_app->mutex); - if (android_app->inputQueue != NULL) + if(android_app->inputQueue != NULL) { AInputQueue_detachLooper(android_app->inputQueue); } @@ -73,20 +72,20 @@ void android_app_destroy(struct android_app *android_app) // Can't touch android_app object after this. } -} +} // namespace void ExtractAsset(struct android_app* state, const std::string& assetPath, const std::string& filePath) { AAsset* asset = AAssetManager_open(state->activity->assetManager, assetPath.c_str(), AASSET_MODE_BUFFER); - if (asset) + if(asset) { size_t length = AAsset_getLength(asset) + 1; char* buffer = new char[length]; - length = AAsset_read(asset, buffer, length); + length = AAsset_read(asset, buffer, length); FILE* file = fopen(filePath.c_str(), "wb"); - if (file) + if(file) { fwrite(buffer, 1, length, file); fclose(file); @@ -100,13 +99,13 @@ void ExtractAsset(struct android_app* state, const std::string& assetPath, const void ExtractAssets(struct android_app* state, const std::string& assetDirPath, const std::string& filesDirPath) { AAssetDir* assetDir = AAssetManager_openDir(state->activity->assetManager, assetDirPath.c_str()); - if (assetDir) + if(assetDir) { - if (mkdir(filesDirPath.c_str(), S_IRWXU) != -1) + if(mkdir(filesDirPath.c_str(), S_IRWXU) != -1) { - const char *filename = NULL; + const char* filename = NULL; std::string assetPath = assetDirPath + "/"; - while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) + while((filename = AAssetDir_getNextFileName(assetDir)) != NULL) { ExtractAsset(state, assetPath + filename, filesDirPath + "/" + filename); } @@ -119,24 +118,24 @@ void ExtractAssets(struct android_app* state, const std::string& assetDirPath, c void ExtractFontConfig(struct android_app* state, std::string assetFontConfig, std::string fontsPath) { AAsset* asset = AAssetManager_open(state->activity->assetManager, assetFontConfig.c_str(), AASSET_MODE_BUFFER); - if (asset) + if(asset) { size_t length = AAsset_getLength(asset) + 1; char* buffer = new char[length]; - length = AAsset_read(asset, buffer, length); + length = AAsset_read(asset, buffer, length); std::string fontConfig = std::string(buffer, length); - int i = fontConfig.find("~"); - if (i != std::string::npos) + int i = fontConfig.find("~"); + if(i != std::string::npos) { std::string filesDir = state->activity->internalDataPath; fontConfig.replace(i, 1, filesDir); } std::string fontsFontConfig = fontsPath; - FILE* file = fopen(fontsFontConfig.c_str(), "wb"); - if (file) + FILE* file = fopen(fontsFontConfig.c_str(), "wb"); + if(file) { fwrite(fontConfig.c_str(), 1, fontConfig.size(), file); fclose(file); @@ -149,7 +148,7 @@ void ExtractFontConfig(struct android_app* state, std::string assetFontConfig, s extern "C" void FcConfigPathInit(const char* path, const char* file); -void android_main( struct android_app* state ) +void android_main(struct android_app* state) { LOGV("android_main() >>"); @@ -161,14 +160,14 @@ void android_main( struct android_app* state ) std::string fontconfigFile = fontconfigPath + "/fonts.conf"; setenv("FONTCONFIG_FILE", fontconfigFile.c_str(), 1); - struct stat st = { 0 }; - FcConfigPathInit( fontconfigPath.c_str(), fontconfigFile.c_str() ); + struct stat st = {0}; + FcConfigPathInit(fontconfigPath.c_str(), fontconfigFile.c_str()); - if (stat(fontconfigPath.c_str(), &st) == -1) + if(stat(fontconfigPath.c_str(), &st) == -1) { mkdir(fontconfigPath.c_str(), S_IRWXU); ExtractFontConfig(state, "fonts/fonts.conf", fontconfigPath + "/fonts.conf"); - ExtractFontConfig(state, "fonts/fonts.dtd", fontconfigPath + "/fonts.dtd" ); + ExtractFontConfig(state, "fonts/fonts.dtd", fontconfigPath + "/fonts.dtd"); ExtractFontConfig(state, "fonts/local.conf", fontconfigPath + "/local.conf"); ExtractAssets(state, "fonts/dejavu", fontconfigPath + "/dejavu"); ExtractAssets(state, "fonts/tizen", fontconfigPath + "/tizen"); @@ -183,34 +182,34 @@ void android_main( struct android_app* state ) DaliDemoNativeActivity nativeActivity(state->activity); - int status = 0; - std::string libpath = "/data/data/com.sec.dalidemo/lib/libdali-demo.so"; + int status = 0; + std::string libpath = "/data/data/com.sec.dalidemo/lib/libdali-demo.so"; std::string callParam = nativeActivity.GetIntentStringExtra("start"); - if (callParam.empty()) + if(callParam.empty()) { callParam = nativeActivity.GetMetaData("start"); } - if (!callParam.empty()) + if(!callParam.empty()) { - libpath = "/data/data/com.sec.dalidemo/lib/lib" + callParam + ".so"; + libpath = "/data/data/com.sec.dalidemo/lib/lib" + callParam + ".so"; } void* handle = dlopen(libpath.c_str(), RTLD_LAZY); - if (!handle) + if(!handle) { std::exit(status); } - dlerror(); /* Clear any existing error */ + dlerror(); /* Clear any existing error */ - int (*main)(int, char**) = (int(*)(int, char**))dlsym(handle, "main"); - if (main) + int (*main)(int, char**) = (int (*)(int, char**))dlsym(handle, "main"); + if(main) { - status = main( 0, nullptr ); + status = main(0, nullptr); } - if (handle) + if(handle) { dlclose(handle); handle = nullptr; diff --git a/builder/dali-builder.cpp b/builder/dali-builder.cpp index f264ced..ba5a101 100644 --- a/builder/dali-builder.cpp +++ b/builder/dali-builder.cpp @@ -26,19 +26,19 @@ // //------------------------------------------------------------------------------ -#include -#include #include #include #include +#include +#include +#include #include #include -#include -#include #include +#include -#include "sys/stat.h" #include +#include "sys/stat.h" #include @@ -49,8 +49,8 @@ using namespace Dali::Toolkit; namespace { - -std::string JSON_BROKEN(" \ +std::string JSON_BROKEN( + " \ { \ 'stage': \ [ \ @@ -64,7 +64,7 @@ std::string JSON_BROKEN(" \ } \ "); -std::string ReplaceQuotes(const std::string &single_quoted) +std::string ReplaceQuotes(const std::string& single_quoted) { std::string s(single_quoted); @@ -74,8 +74,7 @@ std::string ReplaceQuotes(const std::string &single_quoted) return s; } -} // anon namespace - +} // namespace //------------------------------------------------------------------------------ // @@ -87,13 +86,20 @@ class FileWatcher public: FileWatcher(void); ~FileWatcher(void); - explicit FileWatcher(const std::string &fn): mLastTime(0) { SetFilename(fn) ; }; + explicit FileWatcher(const std::string& fn) + : mLastTime(0) + { + SetFilename(fn); + }; - void SetFilename(const std::string &fn); + void SetFilename(const std::string& fn); std::string GetFilename(); - bool FileHasChanged(void); - std::string GetFileContents(void) { return GetFileContents(mstringPath) ; }; + bool FileHasChanged(void); + std::string GetFileContents(void) + { + return GetFileContents(mstringPath); + }; private: // compiler does @@ -103,20 +109,21 @@ private: std::time_t mLastTime; std::string mstringPath; - std::string GetFileContents(const std::string &filename) + std::string GetFileContents(const std::string& filename) { - std::streampos bufferSize = 0; + std::streampos bufferSize = 0; Dali::Vector fileBuffer; - if( !Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) + if(!Dali::FileLoader::ReadFile(filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY)) { return std::string(); } - return std::string( &fileBuffer[0], bufferSize ); + return std::string(&fileBuffer[0], bufferSize); }; }; -FileWatcher::FileWatcher(void) : mLastTime(0) +FileWatcher::FileWatcher(void) +: mLastTime(0) { } @@ -150,7 +157,7 @@ FileWatcher::~FileWatcher() { } -void FileWatcher::SetFilename(const std::string &fn) +void FileWatcher::SetFilename(const std::string& fn) { mstringPath = fn; } @@ -160,7 +167,6 @@ std::string FileWatcher::GetFilename(void) return mstringPath; } - //------------------------------------------------------------------------------ // // @@ -169,21 +175,26 @@ std::string FileWatcher::GetFilename(void) class ExampleApp : public ConnectionTracker { public: - ExampleApp(Application &app) : mApp(app) + ExampleApp(Application& app) + : mApp(app) { app.InitSignal().Connect(this, &ExampleApp::Create); - } - ~ExampleApp() {} + ~ExampleApp() + { + } public: - void SetJSONFilename(std::string const &fn) { fw.SetFilename(fn) ; }; + void SetJSONFilename(std::string const& fn) + { + fw.SetFilename(fn); + }; void Create(Application& app) { - mTimer = Timer::New( 500 ); // ms - mTimer.TickSignal().Connect( this, &ExampleApp::OnTimer); + mTimer = Timer::New(500); // ms + mTimer.TickSignal().Connect(this, &ExampleApp::OnTimer); mTimer.Start(); // Connect to key events in order to exit @@ -192,45 +203,45 @@ public: private: Application& mApp; - Layer mRootLayer; + Layer mRootLayer; FileWatcher fw; - Timer mTimer; + Timer mTimer; void ReloadJsonFile(Builder& builder, Layer& layer) { Window window = mApp.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); builder = Builder::New(); - builder.QuitSignal().Connect( this, &ExampleApp::OnBuilderQuit ); + builder.QuitSignal().Connect(this, &ExampleApp::OnBuilderQuit); Property::Map defaultDirs; - defaultDirs[ TOKEN_STRING(DEMO_IMAGE_DIR) ] = DEMO_IMAGE_DIR; - defaultDirs[ TOKEN_STRING(DEMO_MODEL_DIR) ] = DEMO_MODEL_DIR; - defaultDirs[ TOKEN_STRING(DEMO_SCRIPT_DIR) ] = DEMO_SCRIPT_DIR; + defaultDirs[TOKEN_STRING(DEMO_IMAGE_DIR)] = DEMO_IMAGE_DIR; + defaultDirs[TOKEN_STRING(DEMO_MODEL_DIR)] = DEMO_MODEL_DIR; + defaultDirs[TOKEN_STRING(DEMO_SCRIPT_DIR)] = DEMO_SCRIPT_DIR; - builder.AddConstants( defaultDirs ); + builder.AddConstants(defaultDirs); if(!layer) { layer = Layer::New(); - layer.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - layer.SetProperty( Actor::Property::SIZE, window.GetRootLayer().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) ); + layer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + layer.SetProperty(Actor::Property::SIZE, window.GetRootLayer().GetCurrentProperty(Actor::Property::SIZE)); window.GetRootLayer().Add(layer); // render tasks may have been setup last load so remove them RenderTaskList taskList = window.GetRenderTaskList(); - if( taskList.GetTaskCount() > 1 ) + if(taskList.GetTaskCount() > 1) { typedef std::vector Collection; - typedef Collection::iterator ColIter; - Collection tasks; + typedef Collection::iterator ColIter; + Collection tasks; for(unsigned int i = 1; i < taskList.GetTaskCount(); ++i) { - tasks.push_back( taskList.GetTask(i) ); + tasks.push_back(taskList.GetTask(i)); } for(ColIter iter = tasks.begin(); iter != tasks.end(); ++iter) @@ -239,16 +250,16 @@ private: } RenderTask defaultTask = taskList.GetTask(0); - defaultTask.SetSourceActor( window.GetRootLayer() ); - defaultTask.SetFrameBuffer( FrameBuffer() ); + defaultTask.SetSourceActor(window.GetRootLayer()); + defaultTask.SetFrameBuffer(FrameBuffer()); } } unsigned int numChildren = layer.GetChildCount(); - for(unsigned int i=0; i 1) { diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index a6bee7a..eecd9ad 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,12 @@ #include // INTERNAL INCLUDES -#include "shared/dali-table-view.h" #include "shared/dali-demo-strings.h" +#include "shared/dali-table-view.h" using namespace Dali; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { // Configure gettext for internalization #ifdef INTERNATIONALIZATION_ENABLED @@ -60,7 +60,7 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("animated-gradient-call-active.example", DALI_DEMO_STR_TITLE_CALL_ACTIVE)); demo.AddExample(Example("animated-gradient-card-active.example", DALI_DEMO_STR_TITLE_CARD_ACTIVE)); - demo.SortAlphabetically( true ); + demo.SortAlphabetically(true); // Start the event loop app.MainLoop(); diff --git a/examples-reel/dali-examples-reel.cpp b/examples-reel/dali-examples-reel.cpp index 9b0c043..8284065 100644 --- a/examples-reel/dali-examples-reel.cpp +++ b/examples-reel/dali-examples-reel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,12 @@ #include // INTERNAL INCLUDES -#include "shared/dali-table-view.h" #include "shared/dali-demo-strings.h" +#include "shared/dali-table-view.h" using namespace Dali; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { // Configure gettext for internalization #ifdef INTERNATIONALIZATION_ENABLED @@ -33,7 +33,7 @@ int DALI_EXPORT_API main(int argc, char **argv) setlocale(LC_ALL, DEMO_LANG); #endif - Application app = Application::New( &argc, &argv, DEMO_STYLE_DIR "/examples-theme.json" ); + Application app = Application::New(&argc, &argv, DEMO_STYLE_DIR "/examples-theme.json"); // Create the demo launcher DaliTableView demo(app); @@ -101,7 +101,7 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("transitions.example", DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS)); demo.AddExample(Example("web-view.example", DALI_DEMO_STR_TITLE_WEB_VIEW)); - demo.SortAlphabetically( true ); + demo.SortAlphabetically(true); // Start the event loop app.MainLoop(); diff --git a/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp b/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp index 4080037..5a2573f 100644 --- a/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp +++ b/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp @@ -22,23 +22,23 @@ using namespace Dali; namespace { -const char* const IMAGE_PATH_1 ( DEMO_IMAGE_DIR "people-small-7b.jpg" ); // 100x100 -const char* const IMAGE_PATH_2 ( DEMO_IMAGE_DIR "people-medium-7.jpg" ); -const char* const IMAGE_PATH_3 ( DEMO_IMAGE_DIR "people-medium-7-rgb565.png" ); // is compressed -const char* const IMAGE_PATH_4 ( DEMO_IMAGE_DIR "people-medium-7-masked.png" ); // has alpha channel -const char* const MASK_IMAGE_PATH_1 ( DEMO_IMAGE_DIR "store_mask_profile_n.png" ); // 300x300 -const char* const MASK_IMAGE_PATH_2 ( DEMO_IMAGE_DIR "store_mask_profile_f.png" ); -} +const char* const IMAGE_PATH_1(DEMO_IMAGE_DIR "people-small-7b.jpg"); // 100x100 +const char* const IMAGE_PATH_2(DEMO_IMAGE_DIR "people-medium-7.jpg"); +const char* const IMAGE_PATH_3(DEMO_IMAGE_DIR "people-medium-7-rgb565.png"); // is compressed +const char* const IMAGE_PATH_4(DEMO_IMAGE_DIR "people-medium-7-masked.png"); // has alpha channel +const char* const MASK_IMAGE_PATH_1(DEMO_IMAGE_DIR "store_mask_profile_n.png"); // 300x300 +const char* const MASK_IMAGE_PATH_2(DEMO_IMAGE_DIR "store_mask_profile_f.png"); +} // namespace class ImageViewAlphaBlendApp : public ConnectionTracker { public: - ImageViewAlphaBlendApp( Application& application ) - : mApplication( application ), - mImageCombinationIndex( 0 ) + ImageViewAlphaBlendApp(Application& application) + : mApplication(application), + mImageCombinationIndex(0) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create ); + mApplication.InitSignal().Connect(this, &ImageViewAlphaBlendApp::Create); } ~ImageViewAlphaBlendApp() @@ -48,7 +48,7 @@ public: private: // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // This creates an image view with one of 3 images, and one of 2 masks. // Clicking the screen will cycle through each combination of mask and image. @@ -56,42 +56,42 @@ private: // Get a handle to the window Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); mImageView = Toolkit::ImageView::New(); - mImageView.SetProperty( Actor::Property::SIZE, Vector2(200, 200) ); - mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mImageView.SetProperty(Actor::Property::SIZE, Vector2(200, 200)); + mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); window.Add(mImageView); mImageLabel = Toolkit::TextLabel::New(); - mImageLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mImageLabel.SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::BOTTOM_CENTER ); - mImageLabel.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -50.0f, 0.0f ) ); - mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK ); + mImageLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mImageLabel.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::BOTTOM_CENTER); + mImageLabel.SetProperty(Actor::Property::POSITION, Vector3(0.0f, -50.0f, 0.0f)); + mImageLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK); window.Add(mImageLabel); mMaskLabel = Toolkit::TextLabel::New(); - mMaskLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mMaskLabel.SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::BOTTOM_CENTER ); - mMaskLabel.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); - mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK ); + mMaskLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mMaskLabel.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::BOTTOM_CENTER); + mMaskLabel.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); + mMaskLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK); window.Add(mMaskLabel); LoadImages(); - window.TouchedSignal().Connect( this, &ImageViewAlphaBlendApp::OnTouched ); + window.TouchedSignal().Connect(this, &ImageViewAlphaBlendApp::OnTouched); } - void OnTouched( const TouchEvent& touch ) + void OnTouched(const TouchEvent& touch) { static bool touched = false; - if( touch.GetState( 0 ) == PointState::DOWN ) + if(touch.GetState(0) == PointState::DOWN) { touched = true; } - if( touch.GetState( 0 ) == PointState::UP && touched ) + if(touch.GetState(0) == PointState::UP && touched) { mImageCombinationIndex++; touched = false; @@ -101,48 +101,47 @@ private: void LoadImages() { - const char* images[4] = { IMAGE_PATH_1, IMAGE_PATH_2, IMAGE_PATH_3, IMAGE_PATH_4 }; - const char* masks[2] = { MASK_IMAGE_PATH_1, MASK_IMAGE_PATH_2 }; + const char* images[4] = {IMAGE_PATH_1, IMAGE_PATH_2, IMAGE_PATH_3, IMAGE_PATH_4}; + const char* masks[2] = {MASK_IMAGE_PATH_1, MASK_IMAGE_PATH_2}; - const char* mask = masks[mImageCombinationIndex%2 ]; // Cycle through masks - const char* image = images[(mImageCombinationIndex/2)%4]; // then images + const char* mask = masks[mImageCombinationIndex % 2]; // Cycle through masks + const char* image = images[(mImageCombinationIndex / 2) % 4]; // then images Property::Map map; - map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE ); - map.Add( Toolkit::ImageVisual::Property::URL, image ); - map.Add( Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mask ); + map.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE); + map.Add(Toolkit::ImageVisual::Property::URL, image); + map.Add(Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mask); - if( mImageCombinationIndex%2 == 0 ) + if(mImageCombinationIndex % 2 == 0) { - map.Add( Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, 1.f ); - map.Add( Toolkit::ImageVisual::Property::CROP_TO_MASK, false ); + map.Add(Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, 1.f); + map.Add(Toolkit::ImageVisual::Property::CROP_TO_MASK, false); } else { - map.Add( Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f ); - map.Add( Toolkit::ImageVisual::Property::CROP_TO_MASK, true ); + map.Add(Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, 1.6f); + map.Add(Toolkit::ImageVisual::Property::CROP_TO_MASK, true); } - mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); + mImageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map); - mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(image, '/') ); - mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(mask, '/') ); + mImageLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, strrchr(image, '/')); + mMaskLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, strrchr(mask, '/')); } void OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } } } - private: - Application& mApplication; + Application& mApplication; Toolkit::ImageView mImageView; Toolkit::TextLabel mImageLabel; Toolkit::TextLabel mMaskLabel; @@ -150,10 +149,10 @@ private: int mImageCombinationIndex; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ImageViewAlphaBlendApp test( application ); + Application application = Application::New(&argc, &argv); + ImageViewAlphaBlendApp test(application); application.MainLoop(); return 0; } diff --git a/examples/animated-gradient-call-active/animated-gradient-call-active.cpp b/examples/animated-gradient-call-active/animated-gradient-call-active.cpp index 8b1d8ea..21cdde2 100644 --- a/examples/animated-gradient-call-active/animated-gradient-call-active.cpp +++ b/examples/animated-gradient-call-active/animated-gradient-call-active.cpp @@ -14,12 +14,12 @@ * limitations under the License. * */ -#include #include -#include #include #include +#include #include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -30,72 +30,72 @@ namespace { // The value for scale-change between wearable-mobile // Can be changed on App-Create time -Vector2 WINDOW_SIZE = Vector2( 360.0f, 360.0f ); -Vector2 SCALED_WINDOW_SIZE = Vector2( 1.0f, 1.0f ); -Vector3 SCALED_WINDOW_SIZE_3 = Vector3( 1.0f, 1.0f, 0.0f ); -float SCALED_WIDTH = 1.0f; -float SCALED_HEIGHT = 1.0f; -float FONT_SCALE = 0.25f; +Vector2 WINDOW_SIZE = Vector2(360.0f, 360.0f); +Vector2 SCALED_WINDOW_SIZE = Vector2(1.0f, 1.0f); +Vector3 SCALED_WINDOW_SIZE_3 = Vector3(1.0f, 1.0f, 0.0f); +float SCALED_WIDTH = 1.0f; +float SCALED_HEIGHT = 1.0f; +float FONT_SCALE = 0.25f; // const parameters for animations const float CHANGE_DURATION = 0.2f; // const parameters for icon position and size when resolution is 360x360 -const Vector2 ICON_CALL_SIZE = Vector2( 54.0f, 54.0f ); -const Vector3 ICON_CALL_POSITION = Vector3( 0.0f, 0.0f, 0.0f ); -const Vector2 ICON_DECALL_SIZE = Vector2( 54.0f, 54.0f ); -const Vector3 ICON_DECALL_POSITION = Vector3( 141.0f, 0.0f, 0.0f ); -const Vector2 ICON_BATTERY_SIZE = Vector2( 14.0f, 23.0f ); -const Vector3 ICON_BATTERY_POSITION = Vector3( 0.0f, 25.5f, 0.0f ); -const Vector2 BUTTON_CALL_START_SIZE = Vector2( 54.0f, 54.0f ); -const Vector3 BUTTON_CALL_START_POSITION = Vector3( -141.0f, 0.0f, 0.0f ); - -const Vector2 BUTTON_DECALL_ICON_SIZE = Vector2( 62.0f, 62.0f ); -const Vector3 BUTTON_DECALL_ICON_POSITION = Vector3( 0.0f, 0.0f, 0.0f ); -const Vector2 BUTTON_DECALL_SIZE = Vector2( 360.0f, 82.0f ); -const Vector3 BUTTON_DECALL_CLIP_POSITION = Vector3( 0.0f, 82.0f, 0.0f ); -const Vector3 BUTTON_DECALL_POSITION = Vector3( 0.0f, 0.0f, 0.0f ); +const Vector2 ICON_CALL_SIZE = Vector2(54.0f, 54.0f); +const Vector3 ICON_CALL_POSITION = Vector3(0.0f, 0.0f, 0.0f); +const Vector2 ICON_DECALL_SIZE = Vector2(54.0f, 54.0f); +const Vector3 ICON_DECALL_POSITION = Vector3(141.0f, 0.0f, 0.0f); +const Vector2 ICON_BATTERY_SIZE = Vector2(14.0f, 23.0f); +const Vector3 ICON_BATTERY_POSITION = Vector3(0.0f, 25.5f, 0.0f); +const Vector2 BUTTON_CALL_START_SIZE = Vector2(54.0f, 54.0f); +const Vector3 BUTTON_CALL_START_POSITION = Vector3(-141.0f, 0.0f, 0.0f); + +const Vector2 BUTTON_DECALL_ICON_SIZE = Vector2(62.0f, 62.0f); +const Vector3 BUTTON_DECALL_ICON_POSITION = Vector3(0.0f, 0.0f, 0.0f); +const Vector2 BUTTON_DECALL_SIZE = Vector2(360.0f, 82.0f); +const Vector3 BUTTON_DECALL_CLIP_POSITION = Vector3(0.0f, 82.0f, 0.0f); +const Vector3 BUTTON_DECALL_POSITION = Vector3(0.0f, 0.0f, 0.0f); // icon image name -const char * const ICON_CALL_IMAGE( DEMO_IMAGE_DIR "Call_Accept.png" ); -const char * const ICON_DECALL_IMAGE( DEMO_IMAGE_DIR "Call_Decline.png" ); -const char * const ICON_BATTERY_IMAGE( DEMO_IMAGE_DIR "Call_Battery.png" ); -const char * const BUTTON_DECALL_ICON_IMAGE( DEMO_IMAGE_DIR "Call_Decline_wh.png" ); +const char* const ICON_CALL_IMAGE(DEMO_IMAGE_DIR "Call_Accept.png"); +const char* const ICON_DECALL_IMAGE(DEMO_IMAGE_DIR "Call_Decline.png"); +const char* const ICON_BATTERY_IMAGE(DEMO_IMAGE_DIR "Call_Battery.png"); +const char* const BUTTON_DECALL_ICON_IMAGE(DEMO_IMAGE_DIR "Call_Decline_wh.png"); // const parameters for string position and size and font-size when resolution is 360x360 -const Vector2 LABEL_INCOMING_SIZE = Vector2( 156.0f, 26.0f ); -const Vector3 LABEL_INCOMING_POSITION = Vector3( 0.0f, -47.0f, 0.0f ); -const Vector4 LABEL_INCOMING_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_INCOMING_FONT_SIZE = 21.39f; -const Vector2 LABEL_NAME_SIZE = Vector2( 230.0f, 45.0f ); -const Vector3 LABEL_NAME_POSITION = Vector3( 0.0f, -2.5f, 0.0f ); -const Vector4 LABEL_NAME_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_NAME_FONT_SIZE = 37.71f; -const Vector2 LABEL_NUMBER_SIZE = Vector2( 196.0f, 25.0f ); -const Vector3 LABEL_NUMBER_POSITION = Vector3( 0.0f, 31.0f, 0.0f ); -const Vector4 LABEL_NUMBER_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_NUMBER_FONT_SIZE = 20.55f; -const Vector2 LABEL_DECLINE_SIZE = Vector2( 203.0f, 25.0f ); -const Vector3 LABEL_DECLINE_POSITION = Vector3( 0.0f, -50.5f, 0.0f ); -const Vector4 LABEL_DECLINE_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_DECLINE_FONT_SIZE = 20.55f; -const Vector2 LABEL_TIME_SIZE = Vector2( 91.0f, 26.0f ); -const Vector3 LABEL_TIME_POSITION = Vector3( 0.0f, -47.0f, 0.0f ); -const Vector4 LABEL_TIME_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_TIME_FONT_SIZE = 21.39f; +const Vector2 LABEL_INCOMING_SIZE = Vector2(156.0f, 26.0f); +const Vector3 LABEL_INCOMING_POSITION = Vector3(0.0f, -47.0f, 0.0f); +const Vector4 LABEL_INCOMING_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_INCOMING_FONT_SIZE = 21.39f; +const Vector2 LABEL_NAME_SIZE = Vector2(230.0f, 45.0f); +const Vector3 LABEL_NAME_POSITION = Vector3(0.0f, -2.5f, 0.0f); +const Vector4 LABEL_NAME_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_NAME_FONT_SIZE = 37.71f; +const Vector2 LABEL_NUMBER_SIZE = Vector2(196.0f, 25.0f); +const Vector3 LABEL_NUMBER_POSITION = Vector3(0.0f, 31.0f, 0.0f); +const Vector4 LABEL_NUMBER_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_NUMBER_FONT_SIZE = 20.55f; +const Vector2 LABEL_DECLINE_SIZE = Vector2(203.0f, 25.0f); +const Vector3 LABEL_DECLINE_POSITION = Vector3(0.0f, -50.5f, 0.0f); +const Vector4 LABEL_DECLINE_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_DECLINE_FONT_SIZE = 20.55f; +const Vector2 LABEL_TIME_SIZE = Vector2(91.0f, 26.0f); +const Vector3 LABEL_TIME_POSITION = Vector3(0.0f, -47.0f, 0.0f); +const Vector4 LABEL_TIME_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_TIME_FONT_SIZE = 21.39f; // string string -const char * const LABEL_INCOMING_STR( "Incoming Call" ); -const char * const LABEL_NAME_STR( "Sam Smith" ); -const char * const LABEL_NUMBER_STR( "+1 908-247-1695" ); -const char * const LABEL_DECLINE_STR( "Decline Message" ); -const char * const LABEL_TIME_STR( "1:03" ); +const char* const LABEL_INCOMING_STR("Incoming Call"); +const char* const LABEL_NAME_STR("Sam Smith"); +const char* const LABEL_NUMBER_STR("+1 908-247-1695"); +const char* const LABEL_DECLINE_STR("Decline Message"); +const char* const LABEL_TIME_STR("1:03"); // Set style from json -const char * const BACKGROUND_STYLE_JSON( DEMO_STYLE_DIR "animated-gradient-call-active-style.json" ); -const char * const BACKGROUND_INCOME_STYLE_STR( "IncomeBackground" ); -const char * const BACKGROUND_ACTIVE_STYLE_STR( "ActiveBackground" ); -const char * const DECLINE_BUTTON_STYLE_STR( "DeclineButton" ); +const char* const BACKGROUND_STYLE_JSON(DEMO_STYLE_DIR "animated-gradient-call-active-style.json"); +const char* const BACKGROUND_INCOME_STYLE_STR("IncomeBackground"); +const char* const BACKGROUND_ACTIVE_STYLE_STR("ActiveBackground"); +const char* const DECLINE_BUTTON_STYLE_STR("DeclineButton"); } // unnamed namespace @@ -105,20 +105,20 @@ class CallController : public ConnectionTracker { public: CallController(Application& application) - : mApplication( application ), - mColorStart( 0.0f, 0.0f, 0.0f, 0.0f ), - mColorEnd( 0.0f, 0.0f, 0.0f, 0.0f ), - mColorReduce( 0.0f, 0.0f, 0.0f, 0.0f ), - mButtonColorStart( 0.0f, 0.0f, 0.0f, 0.0f ), - mButtonColorEnd( 0.0f, 0.0f, 0.0f, 0.0f ), - mDuration( 0.0f ), - mBackgroundDurationIncoming( 0.0f ), - mBackgroundDurationActive( 0.0f ), - mButtonDuration( 0.0f ), - mButtonDelay( 0.0f ) + : mApplication(application), + mColorStart(0.0f, 0.0f, 0.0f, 0.0f), + mColorEnd(0.0f, 0.0f, 0.0f, 0.0f), + mColorReduce(0.0f, 0.0f, 0.0f, 0.0f), + mButtonColorStart(0.0f, 0.0f, 0.0f, 0.0f), + mButtonColorEnd(0.0f, 0.0f, 0.0f, 0.0f), + mDuration(0.0f), + mBackgroundDurationIncoming(0.0f), + mBackgroundDurationActive(0.0f), + mButtonDuration(0.0f), + mButtonDelay(0.0f) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &CallController::Create ); + mApplication.InitSignal().Connect(this, &CallController::Create); } ~CallController() @@ -131,28 +131,28 @@ public: { // Get a handle to the main window mWindow = application.GetWindow(); - mWindow.KeyEventSignal().Connect( this, &CallController::OnKeyEvent ); + mWindow.KeyEventSignal().Connect(this, &CallController::OnKeyEvent); // Apply custom style for background and button. - StyleManager::Get().ApplyTheme( BACKGROUND_STYLE_JSON ); + StyleManager::Get().ApplyTheme(BACKGROUND_STYLE_JSON); // Get current device's width and height. const Window::WindowSize windowSize = mWindow.GetSize(); - WINDOW_SIZE = Vector2(windowSize.GetWidth(), windowSize.GetHeight()); - SCALED_WINDOW_SIZE = WINDOW_SIZE / 360.0f; - SCALED_WINDOW_SIZE_3 = Vector3( SCALED_WINDOW_SIZE.x, SCALED_WINDOW_SIZE.y, 0.0f ); - SCALED_WIDTH = SCALED_WINDOW_SIZE.x < SCALED_WINDOW_SIZE.y ? SCALED_WINDOW_SIZE.x : SCALED_WINDOW_SIZE.y; - SCALED_HEIGHT = SCALED_WIDTH; + WINDOW_SIZE = Vector2(windowSize.GetWidth(), windowSize.GetHeight()); + SCALED_WINDOW_SIZE = WINDOW_SIZE / 360.0f; + SCALED_WINDOW_SIZE_3 = Vector3(SCALED_WINDOW_SIZE.x, SCALED_WINDOW_SIZE.y, 0.0f); + SCALED_WIDTH = SCALED_WINDOW_SIZE.x < SCALED_WINDOW_SIZE.y ? SCALED_WINDOW_SIZE.x : SCALED_WINDOW_SIZE.y; + SCALED_HEIGHT = SCALED_WIDTH; // Note that this is heuristic value FONT_SCALE = 0.25f * WINDOW_SIZE.y / WINDOW_SIZE.x; mBackground = Control::New(); - mBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mBackground.SetProperty( Actor::Property::SIZE, WINDOW_SIZE ); + mBackground.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mBackground.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mBackground.SetProperty(Actor::Property::SIZE, WINDOW_SIZE); - mWindow.Add( mBackground ); + mWindow.Add(mBackground); BuildParameter(); SetupActors(); @@ -163,9 +163,9 @@ public: void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -173,7 +173,6 @@ public: } private: - // Setup const parameter values void BuildParameter() { @@ -190,162 +189,162 @@ private: void SetupComingActors() { mButtonIconDecall = ImageView::New(); - mButtonIconDecall.SetImage( ICON_DECALL_IMAGE ); - mButtonIconDecall.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mButtonIconDecall.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mButtonIconDecall.SetProperty( Actor::Property::SIZE, ICON_DECALL_SIZE * SCALED_WIDTH ); - mButtonIconDecall.SetProperty( Actor::Property::POSITION, ICON_DECALL_POSITION * SCALED_WIDTH ); + mButtonIconDecall.SetImage(ICON_DECALL_IMAGE); + mButtonIconDecall.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mButtonIconDecall.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mButtonIconDecall.SetProperty(Actor::Property::SIZE, ICON_DECALL_SIZE * SCALED_WIDTH); + mButtonIconDecall.SetProperty(Actor::Property::POSITION, ICON_DECALL_POSITION * SCALED_WIDTH); mButtonIconBattery = ImageView::New(); - mButtonIconBattery.SetImage( ICON_BATTERY_IMAGE ); - mButtonIconBattery.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mButtonIconBattery.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mButtonIconBattery.SetProperty( Actor::Property::SIZE, ICON_BATTERY_SIZE * SCALED_WIDTH ); - mButtonIconBattery.SetProperty( Actor::Property::POSITION, ICON_BATTERY_POSITION * SCALED_WIDTH ); + mButtonIconBattery.SetImage(ICON_BATTERY_IMAGE); + mButtonIconBattery.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mButtonIconBattery.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mButtonIconBattery.SetProperty(Actor::Property::SIZE, ICON_BATTERY_SIZE * SCALED_WIDTH); + mButtonIconBattery.SetProperty(Actor::Property::POSITION, ICON_BATTERY_POSITION * SCALED_WIDTH); mCallStartButton = PushButton::New(); - mCallStartButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCallStartButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mCallStartButton.SetProperty( Actor::Property::SIZE, BUTTON_CALL_START_SIZE * SCALED_WIDTH ); - mCallStartButton.SetProperty( Actor::Property::POSITION, BUTTON_CALL_START_POSITION * SCALED_WIDTH ); - mCallStartButton.ClickedSignal().Connect( this, &CallController::OnButtonClicked ); - mCallStartButton.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, ICON_CALL_IMAGE ); - mCallStartButton.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, ICON_CALL_IMAGE ); - mCallStartButton.SetProperty( Control::Property::BACKGROUND, ICON_CALL_IMAGE ); - mCallStartButton.SetProperty( Button::Property::LABEL, "" ); - - mWindow.Add( mCallStartButton ); - mWindow.Add( mButtonIconDecall ); - mWindow.Add( mButtonIconBattery ); - - mLabelIncoming = TextLabel::New( LABEL_INCOMING_STR ); - mLabelIncoming.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLabelIncoming.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLabelIncoming.SetProperty( Actor::Property::SIZE, LABEL_INCOMING_SIZE * SCALED_WINDOW_SIZE ); - mLabelIncoming.SetProperty( Actor::Property::POSITION, LABEL_INCOMING_POSITION * SCALED_WINDOW_SIZE_3 ); - mLabelIncoming.SetProperty( Actor::Property::VISIBLE, true ); - mLabelIncoming.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_INCOMING_FONT_COLOR ); - mLabelIncoming.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_INCOMING_FONT_SIZE * FONT_SCALE ); - mLabelIncoming.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabelIncoming.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mLabelName = TextLabel::New( LABEL_NAME_STR ); - mLabelName.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLabelName.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLabelName.SetProperty( Actor::Property::SIZE, LABEL_NAME_SIZE * SCALED_WINDOW_SIZE ); - mLabelName.SetProperty( Actor::Property::POSITION, LABEL_NAME_POSITION * SCALED_WINDOW_SIZE_3 ); - mLabelName.SetProperty( Actor::Property::VISIBLE, true ); - mLabelName.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_NAME_FONT_COLOR ); - mLabelName.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_NAME_FONT_SIZE * FONT_SCALE ); - mLabelName.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabelName.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mLabelNumber = TextLabel::New( LABEL_NUMBER_STR ); - mLabelNumber.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLabelNumber.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLabelNumber.SetProperty( Actor::Property::SIZE, LABEL_NUMBER_SIZE * SCALED_WINDOW_SIZE ); - mLabelNumber.SetProperty( Actor::Property::POSITION, LABEL_NUMBER_POSITION * SCALED_WINDOW_SIZE_3 ); - mLabelNumber.SetProperty( Actor::Property::VISIBLE, true ); - mLabelNumber.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_NUMBER_FONT_COLOR ); - mLabelNumber.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_NUMBER_FONT_SIZE * FONT_SCALE ); - mLabelNumber.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabelNumber.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mLabelDecline = TextLabel::New( LABEL_DECLINE_STR ); - mLabelDecline.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mLabelDecline.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mLabelDecline.SetProperty( Actor::Property::SIZE, LABEL_DECLINE_SIZE * SCALED_WINDOW_SIZE ); - mLabelDecline.SetProperty( Actor::Property::POSITION, LABEL_DECLINE_POSITION * SCALED_WIDTH ); - mLabelDecline.SetProperty( Actor::Property::VISIBLE, true ); - mLabelDecline.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_DECLINE_FONT_COLOR ); - mLabelDecline.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_DECLINE_FONT_SIZE * FONT_SCALE ); - mLabelDecline.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabelDecline.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mWindow.Add( mLabelIncoming ); - mWindow.Add( mLabelName ); - mWindow.Add( mLabelNumber ); - mWindow.Add( mLabelDecline ); + mCallStartButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCallStartButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCallStartButton.SetProperty(Actor::Property::SIZE, BUTTON_CALL_START_SIZE * SCALED_WIDTH); + mCallStartButton.SetProperty(Actor::Property::POSITION, BUTTON_CALL_START_POSITION * SCALED_WIDTH); + mCallStartButton.ClickedSignal().Connect(this, &CallController::OnButtonClicked); + mCallStartButton.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, ICON_CALL_IMAGE); + mCallStartButton.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, ICON_CALL_IMAGE); + mCallStartButton.SetProperty(Control::Property::BACKGROUND, ICON_CALL_IMAGE); + mCallStartButton.SetProperty(Button::Property::LABEL, ""); + + mWindow.Add(mCallStartButton); + mWindow.Add(mButtonIconDecall); + mWindow.Add(mButtonIconBattery); + + mLabelIncoming = TextLabel::New(LABEL_INCOMING_STR); + mLabelIncoming.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLabelIncoming.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLabelIncoming.SetProperty(Actor::Property::SIZE, LABEL_INCOMING_SIZE * SCALED_WINDOW_SIZE); + mLabelIncoming.SetProperty(Actor::Property::POSITION, LABEL_INCOMING_POSITION * SCALED_WINDOW_SIZE_3); + mLabelIncoming.SetProperty(Actor::Property::VISIBLE, true); + mLabelIncoming.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_INCOMING_FONT_COLOR); + mLabelIncoming.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_INCOMING_FONT_SIZE * FONT_SCALE); + mLabelIncoming.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabelIncoming.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mLabelName = TextLabel::New(LABEL_NAME_STR); + mLabelName.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLabelName.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLabelName.SetProperty(Actor::Property::SIZE, LABEL_NAME_SIZE * SCALED_WINDOW_SIZE); + mLabelName.SetProperty(Actor::Property::POSITION, LABEL_NAME_POSITION * SCALED_WINDOW_SIZE_3); + mLabelName.SetProperty(Actor::Property::VISIBLE, true); + mLabelName.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_NAME_FONT_COLOR); + mLabelName.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_NAME_FONT_SIZE * FONT_SCALE); + mLabelName.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabelName.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mLabelNumber = TextLabel::New(LABEL_NUMBER_STR); + mLabelNumber.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLabelNumber.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLabelNumber.SetProperty(Actor::Property::SIZE, LABEL_NUMBER_SIZE * SCALED_WINDOW_SIZE); + mLabelNumber.SetProperty(Actor::Property::POSITION, LABEL_NUMBER_POSITION * SCALED_WINDOW_SIZE_3); + mLabelNumber.SetProperty(Actor::Property::VISIBLE, true); + mLabelNumber.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_NUMBER_FONT_COLOR); + mLabelNumber.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_NUMBER_FONT_SIZE * FONT_SCALE); + mLabelNumber.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabelNumber.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mLabelDecline = TextLabel::New(LABEL_DECLINE_STR); + mLabelDecline.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mLabelDecline.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mLabelDecline.SetProperty(Actor::Property::SIZE, LABEL_DECLINE_SIZE * SCALED_WINDOW_SIZE); + mLabelDecline.SetProperty(Actor::Property::POSITION, LABEL_DECLINE_POSITION * SCALED_WIDTH); + mLabelDecline.SetProperty(Actor::Property::VISIBLE, true); + mLabelDecline.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_DECLINE_FONT_COLOR); + mLabelDecline.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_DECLINE_FONT_SIZE * FONT_SCALE); + mLabelDecline.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabelDecline.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mWindow.Add(mLabelIncoming); + mWindow.Add(mLabelName); + mWindow.Add(mLabelNumber); + mWindow.Add(mLabelDecline); } // Create and Add to window when visible at call active void SetupActiveActors() { mButtonClip = Control::New(); - mButtonClip.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mButtonClip.SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::BOTTOM_CENTER ); - mButtonClip.SetProperty( Actor::Property::SIZE, BUTTON_DECALL_SIZE * SCALED_WIDTH ); - mButtonClip.SetProperty( Actor::Property::POSITION, BUTTON_DECALL_CLIP_POSITION * SCALED_WIDTH ); + mButtonClip.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mButtonClip.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::BOTTOM_CENTER); + mButtonClip.SetProperty(Actor::Property::SIZE, BUTTON_DECALL_SIZE * SCALED_WIDTH); + mButtonClip.SetProperty(Actor::Property::POSITION, BUTTON_DECALL_CLIP_POSITION * SCALED_WIDTH); mButtonIcon = ImageView::New(); - mButtonIcon.SetImage( BUTTON_DECALL_ICON_IMAGE ); - mButtonIcon.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mButtonIcon.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mButtonIcon.SetProperty( Actor::Property::SIZE, BUTTON_DECALL_ICON_SIZE * SCALED_WIDTH ); - mButtonIcon.SetProperty( Actor::Property::POSITION, BUTTON_DECALL_ICON_POSITION * SCALED_WIDTH ); + mButtonIcon.SetImage(BUTTON_DECALL_ICON_IMAGE); + mButtonIcon.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mButtonIcon.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mButtonIcon.SetProperty(Actor::Property::SIZE, BUTTON_DECALL_ICON_SIZE * SCALED_WIDTH); + mButtonIcon.SetProperty(Actor::Property::POSITION, BUTTON_DECALL_ICON_POSITION * SCALED_WIDTH); mCallEndButton = PushButton::New(); - mCallEndButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCallEndButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mCallEndButton.SetProperty( Actor::Property::SIZE, BUTTON_DECALL_SIZE * SCALED_WIDTH ); - mCallEndButton.SetProperty( Actor::Property::POSITION, BUTTON_DECALL_POSITION * SCALED_WIDTH ); - mCallEndButton.ClickedSignal().Connect( this, &CallController::OnButtonClicked ); - mCallEndButton.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, "" ); - mCallEndButton.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, "" ); - mCallEndButton.SetStyleName( DECLINE_BUTTON_STYLE_STR ); - mCallEndButton.SetProperty( Button::Property::LABEL, "" ); - - mButtonClip.Add( mCallEndButton ); - mButtonClip.Add( mButtonIcon ); - - mLabelTime = TextLabel::New( LABEL_TIME_STR ); - mLabelTime.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLabelTime.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLabelTime.SetProperty( Actor::Property::SIZE, LABEL_TIME_SIZE * SCALED_WINDOW_SIZE ); - mLabelTime.SetProperty( Actor::Property::POSITION, LABEL_TIME_POSITION * SCALED_WINDOW_SIZE_3 ); - mLabelTime.SetProperty( Actor::Property::VISIBLE, false ); - mLabelTime.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_TIME_FONT_COLOR ); - mLabelTime.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_TIME_FONT_SIZE * FONT_SCALE ); - mLabelTime.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabelTime.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mWindow.Add( mLabelTime ); + mCallEndButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCallEndButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCallEndButton.SetProperty(Actor::Property::SIZE, BUTTON_DECALL_SIZE * SCALED_WIDTH); + mCallEndButton.SetProperty(Actor::Property::POSITION, BUTTON_DECALL_POSITION * SCALED_WIDTH); + mCallEndButton.ClickedSignal().Connect(this, &CallController::OnButtonClicked); + mCallEndButton.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, ""); + mCallEndButton.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, ""); + mCallEndButton.SetStyleName(DECLINE_BUTTON_STYLE_STR); + mCallEndButton.SetProperty(Button::Property::LABEL, ""); + + mButtonClip.Add(mCallEndButton); + mButtonClip.Add(mButtonIcon); + + mLabelTime = TextLabel::New(LABEL_TIME_STR); + mLabelTime.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLabelTime.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLabelTime.SetProperty(Actor::Property::SIZE, LABEL_TIME_SIZE * SCALED_WINDOW_SIZE); + mLabelTime.SetProperty(Actor::Property::POSITION, LABEL_TIME_POSITION * SCALED_WINDOW_SIZE_3); + mLabelTime.SetProperty(Actor::Property::VISIBLE, false); + mLabelTime.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_TIME_FONT_COLOR); + mLabelTime.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_TIME_FONT_SIZE * FONT_SCALE); + mLabelTime.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabelTime.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mWindow.Add(mLabelTime); } void SetupAnimation() { - mMoveFront = Animation::New( mDuration ); - mMoveBack = Animation::New( mDuration ); - - mMoveFront.AnimateTo( Property( mButtonClip, Actor::Property::POSITION_Y ), 0.0f * SCALED_HEIGHT ); - mMoveBack.AnimateTo( Property( mButtonClip, Actor::Property::POSITION_Y ), BUTTON_DECALL_CLIP_POSITION.y * SCALED_HEIGHT ); - - mMoveFront.AnimateTo( Property( mCallStartButton, Actor::Property::VISIBLE ), false ); - mMoveFront.AnimateTo( Property( mButtonIconDecall, Actor::Property::VISIBLE ), false ); - mMoveBack.AnimateTo( Property( mCallStartButton, Actor::Property::VISIBLE ), true ); - mMoveBack.AnimateTo( Property( mButtonIconDecall, Actor::Property::VISIBLE ), true ); - - mMoveFront.AnimateTo( Property( mLabelIncoming, Actor::Property::VISIBLE ), false ); - mMoveFront.AnimateTo( Property( mLabelNumber, Actor::Property::VISIBLE ), false ); - mMoveFront.AnimateTo( Property( mLabelTime, Actor::Property::VISIBLE ), true ); - mMoveBack.AnimateTo( Property( mLabelIncoming, Actor::Property::VISIBLE ), true ); - mMoveBack.AnimateTo( Property( mLabelNumber, Actor::Property::VISIBLE ), true ); - mMoveBack.AnimateTo( Property( mLabelTime, Actor::Property::VISIBLE ), false ); + mMoveFront = Animation::New(mDuration); + mMoveBack = Animation::New(mDuration); + + mMoveFront.AnimateTo(Property(mButtonClip, Actor::Property::POSITION_Y), 0.0f * SCALED_HEIGHT); + mMoveBack.AnimateTo(Property(mButtonClip, Actor::Property::POSITION_Y), BUTTON_DECALL_CLIP_POSITION.y * SCALED_HEIGHT); + + mMoveFront.AnimateTo(Property(mCallStartButton, Actor::Property::VISIBLE), false); + mMoveFront.AnimateTo(Property(mButtonIconDecall, Actor::Property::VISIBLE), false); + mMoveBack.AnimateTo(Property(mCallStartButton, Actor::Property::VISIBLE), true); + mMoveBack.AnimateTo(Property(mButtonIconDecall, Actor::Property::VISIBLE), true); + + mMoveFront.AnimateTo(Property(mLabelIncoming, Actor::Property::VISIBLE), false); + mMoveFront.AnimateTo(Property(mLabelNumber, Actor::Property::VISIBLE), false); + mMoveFront.AnimateTo(Property(mLabelTime, Actor::Property::VISIBLE), true); + mMoveBack.AnimateTo(Property(mLabelIncoming, Actor::Property::VISIBLE), true); + mMoveBack.AnimateTo(Property(mLabelNumber, Actor::Property::VISIBLE), true); + mMoveBack.AnimateTo(Property(mLabelTime, Actor::Property::VISIBLE), false); } bool OnButtonClicked(Button button) { - if( button == mCallStartButton ) + if(button == mCallStartButton) { - mBackground.SetStyleName( BACKGROUND_ACTIVE_STYLE_STR ); - mWindow.Add( mButtonClip ); + mBackground.SetStyleName(BACKGROUND_ACTIVE_STYLE_STR); + mWindow.Add(mButtonClip); mMoveFront.Play(); } - else if( button == mCallEndButton ) + else if(button == mCallEndButton) { - mBackground.SetStyleName( BACKGROUND_INCOME_STYLE_STR ); - mTempTimer = Timer::New( mDuration * 1000.0f ); - mTempTimer.TickSignal().Connect( this, &CallController::smallTick ); + mBackground.SetStyleName(BACKGROUND_INCOME_STYLE_STR); + mTempTimer = Timer::New(mDuration * 1000.0f); + mTempTimer.TickSignal().Connect(this, &CallController::smallTick); mTempTimer.Start(); mMoveBack.Play(); } @@ -359,30 +358,30 @@ private: void Reset() { - mBackground.SetStyleName( BACKGROUND_INCOME_STYLE_STR ); + mBackground.SetStyleName(BACKGROUND_INCOME_STYLE_STR); } private: - Application& mApplication; - Window mWindow; + Application& mApplication; + Window mWindow; Control mBackground; // Show when call incommint PushButton mCallStartButton; - ImageView mButtonIconDecall; - ImageView mButtonIconBattery; - TextLabel mLabelIncoming; - TextLabel mLabelName; - TextLabel mLabelNumber; - TextLabel mLabelDecline; + ImageView mButtonIconDecall; + ImageView mButtonIconBattery; + TextLabel mLabelIncoming; + TextLabel mLabelName; + TextLabel mLabelNumber; + TextLabel mLabelDecline; // Show when call active PushButton mCallEndButton; - ImageView mButtonIcon; - Control mButtonBackground; - Control mButtonClip; - TextLabel mLabelTime; + ImageView mButtonIcon; + Control mButtonBackground; + Control mButtonClip; + TextLabel mLabelTime; Timer mTempTimer; @@ -403,11 +402,11 @@ private: float mButtonDelay; }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - CallController test( application ); + CallController test(application); application.MainLoop(); return 0; diff --git a/examples/animated-gradient-card-active/animated-gradient-card-active.cpp b/examples/animated-gradient-card-active/animated-gradient-card-active.cpp index a4da888..8e3d06b 100644 --- a/examples/animated-gradient-card-active/animated-gradient-card-active.cpp +++ b/examples/animated-gradient-card-active/animated-gradient-card-active.cpp @@ -14,12 +14,12 @@ * limitations under the License. * */ -#include #include -#include #include #include +#include #include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -30,113 +30,115 @@ namespace { // The value for scale-change between wearable-mobile // Can be changed on App-Create time -Vector2 WINDOW_SIZE = Vector2( 360.0f, 360.0f ); -Vector2 SCALED_WINDOW_SIZE = Vector2( 1.0f, 1.0f ); -Vector3 SCALED_WINDOW_SIZE_3 = Vector3( 1.0f, 1.0f, 0.0f ); -float SCALED_WIDTH = 1.0f; -float SCALED_HEIGHT = 1.0f; -float FONT_SCALE = 0.25f; +Vector2 WINDOW_SIZE = Vector2(360.0f, 360.0f); +Vector2 SCALED_WINDOW_SIZE = Vector2(1.0f, 1.0f); +Vector3 SCALED_WINDOW_SIZE_3 = Vector3(1.0f, 1.0f, 0.0f); +float SCALED_WIDTH = 1.0f; +float SCALED_HEIGHT = 1.0f; +float FONT_SCALE = 0.25f; // const parameters for color and animation -const float CHANGE_DURATION = 0.2f; -const float CARD_MOVE_DURATION = 1.0f; -const float LOADING_ONE_CYCLE_DURATION = 2.0f; -const int LOADING_CYCLE_CNT = 4; -const int LOADING_CYCLE_DT = 10; -const Vector4 DEFAULT_COLOR = Vector4( 0.5f, 0.5f, 0.5f, 1.0f ); - -const float PSEUDO_SCROLL_TIME = 100.0f; +const float CHANGE_DURATION = 0.2f; +const float CARD_MOVE_DURATION = 1.0f; +const float LOADING_ONE_CYCLE_DURATION = 2.0f; +const int LOADING_CYCLE_CNT = 4; +const int LOADING_CYCLE_DT = 10; +const Vector4 DEFAULT_COLOR = Vector4(0.5f, 0.5f, 0.5f, 1.0f); + +const float PSEUDO_SCROLL_TIME = 100.0f; const float PSEUDO_SCROLL_OFFSET = 0.05f; // const static parameters for cards when resolution is 360x360 -const int CARD_NUM = 3; -const Vector2 CARD_SIZE = Vector2( 210.0f, 143.0f ); -const Vector2 CARD_OFFSET = Vector2( 0.0f, 12.5f ); -const Vector2 CARD_DIFF = Vector2( 240.0f, 0.0f ); -const float CARD_BOUNCE_ANIMATION_RATE = 0.3f; +const int CARD_NUM = 3; +const Vector2 CARD_SIZE = Vector2(210.0f, 143.0f); +const Vector2 CARD_OFFSET = Vector2(0.0f, 12.5f); +const Vector2 CARD_DIFF = Vector2(240.0f, 0.0f); +const float CARD_BOUNCE_ANIMATION_RATE = 0.3f; -const Vector2 CARD_SIZE_BIG = Vector2( 292.0f, 199.0f ); -const Vector2 CARD_BIG_OFFSET = Vector2( 0.0f, -5.5f ); -const float CARD_MOVE_DIST = 40.0f; +const Vector2 CARD_SIZE_BIG = Vector2(292.0f, 199.0f); +const Vector2 CARD_BIG_OFFSET = Vector2(0.0f, -5.5f); +const float CARD_MOVE_DIST = 40.0f; // const private parameters for each cards const Vector4 CARD_COLOR_START_LIST[] = -{ - Vector4( 0x24, 0x2C, 0x93, 255.f ) / 255.f, - Vector4( 0x7A, 0x1C, 0x9E, 255.f ) / 255.f, - Vector4( 0xA9, 0x0C, 0x96, 255.f ) / 255.f, + { + Vector4(0x24, 0x2C, 0x93, 255.f) / 255.f, + Vector4(0x7A, 0x1C, 0x9E, 255.f) / 255.f, + Vector4(0xA9, 0x0C, 0x96, 255.f) / 255.f, }; const Vector4 CARD_COLOR_END_LIST[] = -{ - Vector4( 0x04, 0x13, 0x23, 255.f ) / 255.f, - Vector4( 0x28, 0x01, 0x45, 255.f ) / 255.f, - Vector4( 0x37, 0x0A, 0x2E, 255.f ) / 255.f, + { + Vector4(0x04, 0x13, 0x23, 255.f) / 255.f, + Vector4(0x28, 0x01, 0x45, 255.f) / 255.f, + Vector4(0x37, 0x0A, 0x2E, 255.f) / 255.f, }; const Vector4 CARD_COLOR_BACKGROUND_LIST[] = -{ - Vector4( 0x28, 0x2B, 0x6E, 255.f ) / 255.f, - Vector4( 0x4D, 0x15, 0x61, 255.f ) / 255.f, - Vector4( 0x70, 0x21, 0x61, 255.f ) / 255.f, + { + Vector4(0x28, 0x2B, 0x6E, 255.f) / 255.f, + Vector4(0x4D, 0x15, 0x61, 255.f) / 255.f, + Vector4(0x70, 0x21, 0x61, 255.f) / 255.f, }; -const char * const CARD_IMAGE_LIST[] = -{ - ( DEMO_IMAGE_DIR "Card_01.png" ), - ( DEMO_IMAGE_DIR "Card_02.png" ), - ( DEMO_IMAGE_DIR "Card_03.png" ), +const char* const CARD_IMAGE_LIST[] = + { + (DEMO_IMAGE_DIR "Card_01.png"), + (DEMO_IMAGE_DIR "Card_02.png"), + (DEMO_IMAGE_DIR "Card_03.png"), }; // const parameters for add button position and size when resolution is 360x360x -const Vector2 BUTTON_ADD_SIZE = Vector2( 292.0f, 52.0f ); -const Vector3 BUTTON_ADD_POSITION = Vector3( 0.0f, 0.0f, 0.0f ); -const char * const BUTTON_ADD_IMAGE( DEMO_IMAGE_DIR "Card_Add_Button.png" ); +const Vector2 BUTTON_ADD_SIZE = Vector2(292.0f, 52.0f); +const Vector3 BUTTON_ADD_POSITION = Vector3(0.0f, 0.0f, 0.0f); +const char* const BUTTON_ADD_IMAGE(DEMO_IMAGE_DIR "Card_Add_Button.png"); // const parameters for string position and size and font-size when resolution is 360x360 -const Vector2 LABEL_TICKET_SIZE = Vector2( 148.0f, 31.0f ); -const Vector3 LABEL_TICKET_POSITION = Vector3( 0.0f, 72.5f, 0.0f ); -const Vector4 LABEL_TICKET_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_TICKET_FONT_SIZE = 25.0f; -const Vector2 LABEL_HOLD_SIZE = Vector2( 180.0f, 60.0f ); -const Vector3 LABEL_HOLD_POSITION = Vector3( 1.0f, 103.0f, 0.0f ); -const Vector4 LABEL_HOLD_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_HOLD_FONT_SIZE = 25.0f; -const Vector2 LABEL_TERMINAL_SIZE = Vector2( 180.0f, 60.0f ); -const Vector3 LABEL_TERMINAL_POSITION = Vector3( 1.0f, 133.0f, 0.0f ); -const Vector4 LABEL_TERMINAL_FONT_COLOR = Vector4( 0.98f, 0.98f, 0.98f, 1.0f ); -const float LABEL_TERMINAL_FONT_SIZE = 25.0f; +const Vector2 LABEL_TICKET_SIZE = Vector2(148.0f, 31.0f); +const Vector3 LABEL_TICKET_POSITION = Vector3(0.0f, 72.5f, 0.0f); +const Vector4 LABEL_TICKET_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_TICKET_FONT_SIZE = 25.0f; +const Vector2 LABEL_HOLD_SIZE = Vector2(180.0f, 60.0f); +const Vector3 LABEL_HOLD_POSITION = Vector3(1.0f, 103.0f, 0.0f); +const Vector4 LABEL_HOLD_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_HOLD_FONT_SIZE = 25.0f; +const Vector2 LABEL_TERMINAL_SIZE = Vector2(180.0f, 60.0f); +const Vector3 LABEL_TERMINAL_POSITION = Vector3(1.0f, 133.0f, 0.0f); +const Vector4 LABEL_TERMINAL_FONT_COLOR = Vector4(0.98f, 0.98f, 0.98f, 1.0f); +const float LABEL_TERMINAL_FONT_SIZE = 25.0f; // string string -const char * const LABEL_TICKET_STR( "Select Ticket" ); -const char * const LABEL_HOLD_STR( "Hold near" ); -const char * const LABEL_TERMINAL_STR( "terminal" ); +const char* const LABEL_TICKET_STR("Select Ticket"); +const char* const LABEL_HOLD_STR("Hold near"); +const char* const LABEL_TERMINAL_STR("terminal"); class CardManager { public: CardManager() - : mSize( 0.0f, 0.0f ), - mOffset( 0.0f, 0.0f), - mDiff( 0.0f, 0.0f), - mCurIndex( 0 ), - mCurState( 0 ) + : mSize(0.0f, 0.0f), + mOffset(0.0f, 0.0f), + mDiff(0.0f, 0.0f), + mCurIndex(0), + mCurState(0) + { + } + ~CardManager() { } - ~CardManager() {} void Init(Window& window) { - mSize = CARD_SIZE * SCALED_WIDTH; + mSize = CARD_SIZE * SCALED_WIDTH; mOffset = CARD_OFFSET * SCALED_WIDTH; - mDiff = CARD_DIFF * SCALED_WIDTH; + mDiff = CARD_DIFF * SCALED_WIDTH; mCurIndex = 0; mCurState = 0; - for( int k = 0; k < CARD_NUM; k++ ) + for(int k = 0; k < CARD_NUM; k++) { mPosition[k] = mOffset + mDiff * k; - mColorStart[k] = CARD_COLOR_START_LIST[k]; - mColorEnd[k] = CARD_COLOR_END_LIST[k]; + mColorStart[k] = CARD_COLOR_START_LIST[k]; + mColorEnd[k] = CARD_COLOR_END_LIST[k]; mColorBackground[k] = CARD_COLOR_BACKGROUND_LIST[k]; mImageUrl[k] = CARD_IMAGE_LIST[k]; @@ -151,34 +153,34 @@ public: mCard[k].SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); } - mCard[k].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCard[k].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mCard[k].SetProperty( Actor::Property::SIZE, Vector2( mSize.x, mSize.y ) ); - mCard[k].SetProperty( Actor::Property::POSITION, Vector2( mPosition[k].x, mPosition[k].y )); + mCard[k].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCard[k].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCard[k].SetProperty(Actor::Property::SIZE, Vector2(mSize.x, mSize.y)); + mCard[k].SetProperty(Actor::Property::POSITION, Vector2(mPosition[k].x, mPosition[k].y)); - window.Add( mCard[k] ); + window.Add(mCard[k]); } } bool MoveRight(float duration) { - Animation anim = Animation::New( duration ); - for( int k = 0; k < CARD_NUM; k++ ) + Animation anim = Animation::New(duration); + for(int k = 0; k < CARD_NUM; k++) { - if( mCurIndex == 0 ) + if(mCurIndex == 0) { - anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), mDiff.x * CARD_BOUNCE_ANIMATION_RATE, AlphaFunction::BOUNCE ); + anim.AnimateBy(Property(mCard[k], Actor::Property::POSITION_X), mDiff.x * CARD_BOUNCE_ANIMATION_RATE, AlphaFunction::BOUNCE); } else { - anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), mDiff.x, AlphaFunction::EASE_OUT ); + anim.AnimateBy(Property(mCard[k], Actor::Property::POSITION_X), mDiff.x, AlphaFunction::EASE_OUT); } } bool res = false; - if( mCurIndex != 0 ) + if(mCurIndex != 0) { mCurIndex = (mCurIndex - 1) % CARD_NUM; - res = true; + res = true; } anim.Play(); return res; @@ -186,23 +188,23 @@ public: bool MoveLeft(float duration) { - Animation anim = Animation::New( duration ); - for( int k = 0; k < CARD_NUM; k++ ) + Animation anim = Animation::New(duration); + for(int k = 0; k < CARD_NUM; k++) { - if( mCurIndex == CARD_NUM - 1 ) + if(mCurIndex == CARD_NUM - 1) { - anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), -mDiff.x * CARD_BOUNCE_ANIMATION_RATE, AlphaFunction::BOUNCE ); + anim.AnimateBy(Property(mCard[k], Actor::Property::POSITION_X), -mDiff.x * CARD_BOUNCE_ANIMATION_RATE, AlphaFunction::BOUNCE); } else { - anim.AnimateBy( Property( mCard[k], Actor::Property::POSITION_X ), -mDiff.x, AlphaFunction::EASE_OUT ); + anim.AnimateBy(Property(mCard[k], Actor::Property::POSITION_X), -mDiff.x, AlphaFunction::EASE_OUT); } } bool res = false; - if( mCurIndex != CARD_NUM - 1 ) + if(mCurIndex != CARD_NUM - 1) { mCurIndex = (mCurIndex + 1) % CARD_NUM; - res = true; + res = true; } anim.Play(); return res; @@ -210,39 +212,39 @@ public: Vector4 GetColorStart(int index) { - DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM ); + DALI_ASSERT_ALWAYS(index >= 0 && index < CARD_NUM); return mColorStart[index]; } Vector4 GetColorEnd(int index) { - DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM ); + DALI_ASSERT_ALWAYS(index >= 0 && index < CARD_NUM); return mColorEnd[index]; } Vector4 GetColorBackground(int index) { - DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM ); + DALI_ASSERT_ALWAYS(index >= 0 && index < CARD_NUM); return mColorBackground[index]; } - ImageView& operator [](int index) + ImageView& operator[](int index) { - DALI_ASSERT_ALWAYS( index >= 0 && index < CARD_NUM ); + DALI_ASSERT_ALWAYS(index >= 0 && index < CARD_NUM); return mCard[index]; } - ImageView mCard[CARD_NUM]; + ImageView mCard[CARD_NUM]; std::string mImageUrl[CARD_NUM]; - Vector4 mColorStart[CARD_NUM]; - Vector4 mColorEnd[CARD_NUM]; - Vector4 mColorBackground[CARD_NUM]; - Vector2 mPosition[CARD_NUM]; - Vector2 mSize; - Vector2 mOffset; - Vector2 mDiff; - int mCurIndex; - int mCurState; + Vector4 mColorStart[CARD_NUM]; + Vector4 mColorEnd[CARD_NUM]; + Vector4 mColorBackground[CARD_NUM]; + Vector2 mPosition[CARD_NUM]; + Vector2 mSize; + Vector2 mOffset; + Vector2 mDiff; + int mCurIndex; + int mCurState; }; } // unnamed namespace @@ -253,23 +255,23 @@ class CardController : public ConnectionTracker { public: CardController(Application& application) - : mApplication( application ), - mNormalColor( 0.0f, 0.0f, 0.0f, 0.0f ), - mNormalStartColor( 0.0f, 0.0f, 0.0f, 0.0f ), - mNormalEndColor( 0.0f, 0.0f, 0.0f, 0.0f), - mFirstTouchPos( 0.0f, 0.0f ), - mLastTouchPos( 0.0f, 0.0f ), - mCardDuration( 0.0f ), - mDuration( 0.0f ), - mLoadingTime( 0.0f ), - mLoadingCount( 0 ), - mLoadingCountScale( 0 ), - mTickCount( 0 ), - mCancelSignal( false ), - mIsTouchedActor( false ) + : mApplication(application), + mNormalColor(0.0f, 0.0f, 0.0f, 0.0f), + mNormalStartColor(0.0f, 0.0f, 0.0f, 0.0f), + mNormalEndColor(0.0f, 0.0f, 0.0f, 0.0f), + mFirstTouchPos(0.0f, 0.0f), + mLastTouchPos(0.0f, 0.0f), + mCardDuration(0.0f), + mDuration(0.0f), + mLoadingTime(0.0f), + mLoadingCount(0), + mLoadingCountScale(0), + mTickCount(0), + mCancelSignal(false), + mIsTouchedActor(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &CardController::Create ); + mApplication.InitSignal().Connect(this, &CardController::Create); } ~CardController() @@ -282,25 +284,25 @@ public: { // Get a handle to the window mWindow = application.GetWindow(); - mWindow.KeyEventSignal().Connect( this, &CardController::OnKeyEvent ); + mWindow.KeyEventSignal().Connect(this, &CardController::OnKeyEvent); // Get current device's width and height. const Window::WindowSize windowSize = mWindow.GetSize(); - WINDOW_SIZE = Vector2(windowSize.GetWidth(), windowSize.GetHeight() ); - SCALED_WINDOW_SIZE = WINDOW_SIZE / 360.0f; - SCALED_WINDOW_SIZE_3 = Vector3( SCALED_WINDOW_SIZE.x, SCALED_WINDOW_SIZE.y, 0.0f ); - SCALED_WIDTH = SCALED_WINDOW_SIZE.x < SCALED_WINDOW_SIZE.y ? SCALED_WINDOW_SIZE.x : SCALED_WINDOW_SIZE.y; - SCALED_HEIGHT = SCALED_WIDTH; + WINDOW_SIZE = Vector2(windowSize.GetWidth(), windowSize.GetHeight()); + SCALED_WINDOW_SIZE = WINDOW_SIZE / 360.0f; + SCALED_WINDOW_SIZE_3 = Vector3(SCALED_WINDOW_SIZE.x, SCALED_WINDOW_SIZE.y, 0.0f); + SCALED_WIDTH = SCALED_WINDOW_SIZE.x < SCALED_WINDOW_SIZE.y ? SCALED_WINDOW_SIZE.x : SCALED_WINDOW_SIZE.y; + SCALED_HEIGHT = SCALED_WIDTH; // Note that this is heuristic value FONT_SCALE = 0.25f * WINDOW_SIZE.y / WINDOW_SIZE.x; mBackground = Control::New(); - mBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mBackground.SetProperty( Actor::Property::SIZE, WINDOW_SIZE ); + mBackground.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mBackground.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mBackground.SetProperty(Actor::Property::SIZE, WINDOW_SIZE); - mWindow.Add( mBackground ); + mWindow.Add(mBackground); BuildParameter(); InitMap(); @@ -308,32 +310,32 @@ public: SetupActors(); SetupAnimation(); - mWindow.GetRootLayer().TouchedSignal().Connect( this, &CardController::OnTouchLayer ); + mWindow.GetRootLayer().TouchedSignal().Connect(this, &CardController::OnTouchLayer); Reset(); } - bool OnTouchCards(Actor actor, const TouchEvent &data) + bool OnTouchCards(Actor actor, const TouchEvent& data) { - if( data.GetPointCount() > 0 ) + if(data.GetPointCount() > 0) { - if( data.GetState( 0 ) == PointState::DOWN ) + if(data.GetState(0) == PointState::DOWN) { - if( mCards.mCurState == 0 ) + if(mCards.mCurState == 0) { mIsTouchedActor = false; - if( mCards[mCards.mCurIndex] == actor ) + if(mCards[mCards.mCurIndex] == actor) { mIsTouchedActor = true; } mCards.mCurState = 3; - mTempTimer = Timer::New( PSEUDO_SCROLL_TIME ); - mTempTimer.TickSignal().Connect( this, &CardController::OnDetectMotionLayer ); + mTempTimer = Timer::New(PSEUDO_SCROLL_TIME); + mTempTimer.TickSignal().Connect(this, &CardController::OnDetectMotionLayer); mTempTimer.Start(); - mFirstTouchPos = data.GetScreenPosition( 0 ); - mLastTouchPos = mFirstTouchPos; + mFirstTouchPos = data.GetScreenPosition(0); + mLastTouchPos = mFirstTouchPos; } - else if( mCards.mCurState == 1 ) + else if(mCards.mCurState == 1) { mCancelSignal = true; return false; @@ -341,33 +343,33 @@ public: } else { - mLastTouchPos = data.GetScreenPosition( 0 ); + mLastTouchPos = data.GetScreenPosition(0); } } return true; } - bool OnTouchLayer(Actor actor, const TouchEvent &data) + bool OnTouchLayer(Actor actor, const TouchEvent& data) { - if( data.GetPointCount() > 0 ) + if(data.GetPointCount() > 0) { - if( data.GetState( 0 ) == PointState::DOWN ) + if(data.GetState(0) == PointState::DOWN) { - if( mCards.mCurState == 0 ) + if(mCards.mCurState == 0) { - mIsTouchedActor = false; + mIsTouchedActor = false; mCards.mCurState = 3; - mTempTimer = Timer::New( PSEUDO_SCROLL_TIME ); - mTempTimer.TickSignal().Connect( this, &CardController::OnDetectMotionLayer ); + mTempTimer = Timer::New(PSEUDO_SCROLL_TIME); + mTempTimer.TickSignal().Connect(this, &CardController::OnDetectMotionLayer); mTempTimer.Start(); - mFirstTouchPos = data.GetScreenPosition( 0 ); - mLastTouchPos = mFirstTouchPos; + mFirstTouchPos = data.GetScreenPosition(0); + mLastTouchPos = mFirstTouchPos; } } else { - mLastTouchPos = data.GetScreenPosition( 0 ); + mLastTouchPos = data.GetScreenPosition(0); } } return true; @@ -376,37 +378,37 @@ public: // Heuristic Scroll View bool OnDetectMotionLayer() { - if( mCards.mCurState == 3 ) + if(mCards.mCurState == 3) { - Vector2 diff = (mLastTouchPos - mFirstTouchPos); - float offset = PSEUDO_SCROLL_OFFSET; + Vector2 diff = (mLastTouchPos - mFirstTouchPos); + float offset = PSEUDO_SCROLL_OFFSET; const float windowWidth = mWindow.GetSize().GetWidth(); // Scroll to right - if( diff.x > windowWidth * offset ) + if(diff.x > windowWidth * offset) { mCards.mCurState = 2; MoveRight(); - mCardChanger = Timer::New( mCardDuration * 1000.0f ); - mCardChanger.TickSignal().Connect( this, &CardController::OnTickLayer ); + mCardChanger = Timer::New(mCardDuration * 1000.0f); + mCardChanger.TickSignal().Connect(this, &CardController::OnTickLayer); mCardChanger.Start(); } // Scroll to left - else if( diff.x < -windowWidth * offset ) + else if(diff.x < -windowWidth * offset) { mCards.mCurState = 2; MoveLeft(); - mCardChanger = Timer::New( mCardDuration * 1000.0f ); - mCardChanger.TickSignal().Connect( this, &CardController::OnTickLayer ); + mCardChanger = Timer::New(mCardDuration * 1000.0f); + mCardChanger.TickSignal().Connect(this, &CardController::OnTickLayer); mCardChanger.Start(); } // Not a scroll input else { // Run NFC Tag effect if we touch a card - if (mIsTouchedActor) + if(mIsTouchedActor) { mCards.mCurState = 1; - RunAnimation( mCards.mCurIndex ); + RunAnimation(mCards.mCurIndex); } else { @@ -425,9 +427,9 @@ public: void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -435,120 +437,119 @@ public: } private: - // Utility function to make animation parameter map. return Property::Map - Property::Value BuildMap(const Property::Value &start, const Property::Value &target, int dir, float duration, float delay, int repeat, float repeat_delay, int motion, int easing) + Property::Value BuildMap(const Property::Value& start, const Property::Value& target, int dir, float duration, float delay, int repeat, float repeat_delay, int motion, int easing) { Property::Map map; map.Clear(); - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::START, start ); - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target ); - if( dir == 0 ) + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::START, start); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target); + if(dir == 0) { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD); } else { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION, DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD); } - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION, duration ); - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY, delay ); - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT, repeat ); - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY, repeat_delay ); - if( motion == 0 ) + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DURATION, duration); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::DELAY, delay); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT, repeat); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::REPEAT_DELAY, repeat_delay); + if(motion == 0) { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP); } else { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::MOTION_TYPE, DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR); } - if( easing == 0 ) + if(easing == 0) { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::LINEAR ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::LINEAR); } - else if( easing == 1 ) + else if(easing == 1) { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN); } - else if( easing == 2 ) + else if(easing == 2) { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::OUT ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::OUT); } else { - map.Insert( DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN_OUT ); + map.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::EASING_TYPE, DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN_OUT); } - return Property::Value( map ); + return Property::Value(map); } // Setup background visual property during nothing action void InitMapNormal() { mBackgroundNormalMap.Clear(); - mBackgroundNormalMap.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT ); + mBackgroundNormalMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); - mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, -0.5 ) ); - mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.5 ) ); - mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor ); - mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor ); - mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) ); - mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f ); - mBackgroundNormalMap.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, 0.0f ); + mBackgroundNormalMap.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2(-0.5, -0.5)); + mBackgroundNormalMap.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2(0.5, 0.5)); + mBackgroundNormalMap.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor); + mBackgroundNormalMap.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor); + mBackgroundNormalMap.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2(0.0f, 0.0f)); + mBackgroundNormalMap.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f); + mBackgroundNormalMap.Insert(Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, 0.0f); } // Setup background visual property during NFC tagging start void InitMapStart() { mBackgroundMapStart.Clear(); - mBackgroundMapStart.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT ); + mBackgroundMapStart.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); - mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, -0.5 ) ); - mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.5 ) ); - mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor ); - mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor ); - mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) ); - mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f ); - mBackgroundMapStart.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap( 0.0f, 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0 ) ); + mBackgroundMapStart.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2(-0.5, -0.5)); + mBackgroundMapStart.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2(0.5, 0.5)); + mBackgroundMapStart.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor); + mBackgroundMapStart.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor); + mBackgroundMapStart.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2(0.0f, 0.0f)); + mBackgroundMapStart.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f); + mBackgroundMapStart.Insert(Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap(0.0f, 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0)); - mColorAnimationStartStart = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 0, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() ); - mColorAnimationStartEnd = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 0, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() ); + mColorAnimationStartStart = *(BuildMap(mNormalColor, Vector4(0, 0, 0, 0), 0, mDuration, 0.0f, 1, 0.0f, 0, 0).GetMap()); + mColorAnimationStartEnd = *(BuildMap(mNormalColor, Vector4(0, 0, 0, 0), 0, mDuration, 0.0f, 1, 0.0f, 0, 0).GetMap()); } // Setup background visual property during NFC tagging end void InitMapEnd() { mBackgroundMapEnd.Clear(); - mBackgroundMapEnd.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT ); + mBackgroundMapEnd.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); - mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, -0.5 ) ); - mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.5 ) ); - mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor ); - mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor ); - mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) ); - mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f ); - mBackgroundMapEnd.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap( 0.0f, 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0 ) ); + mBackgroundMapEnd.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2(-0.5, -0.5)); + mBackgroundMapEnd.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2(0.5, 0.5)); + mBackgroundMapEnd.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalColor); + mBackgroundMapEnd.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalColor); + mBackgroundMapEnd.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2(0.0f, 0.0f)); + mBackgroundMapEnd.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f); + mBackgroundMapEnd.Insert(Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap(0.0f, 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0)); - mColorAnimationEndStart = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 1, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() ); - mColorAnimationEndEnd = *( BuildMap( mNormalColor, Vector4( 0, 0, 0, 0 ), 1, mDuration, 0.0f, 1, 0.0f, 0, 0 ).GetMap() ); + mColorAnimationEndStart = *(BuildMap(mNormalColor, Vector4(0, 0, 0, 0), 1, mDuration, 0.0f, 1, 0.0f, 0, 0).GetMap()); + mColorAnimationEndEnd = *(BuildMap(mNormalColor, Vector4(0, 0, 0, 0), 1, mDuration, 0.0f, 1, 0.0f, 0, 0).GetMap()); } // Setup background visual property during card change void InitMapMove() { mBackgroundMapMove.Clear(); - mBackgroundMapMove.Insert( Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::SPREAD_TYPE, Toolkit::DevelAnimatedGradientVisual::SpreadType::CLAMP); + mBackgroundMapMove.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::SPREAD_TYPE, Toolkit::DevelAnimatedGradientVisual::SpreadType::CLAMP); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2( -0.5, 0.0 ) ); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2( 0.5, 0.0 ) ); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalStartColor ); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalEndColor ); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2( 0.0f, 0.0f ) ); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f ); - mBackgroundMapMove.Insert( Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap( -1.0f, 1.0f, 0, mCardDuration, 0.0f, 1, 0.0f, 0, 2 ) ); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_POSITION, Vector2(-0.5, 0.0)); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_POSITION, Vector2(0.5, 0.0)); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR, mNormalStartColor); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR, mNormalEndColor); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_CENTER, Vector2(0.0f, 0.0f)); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT, 0.0f); + mBackgroundMapMove.Insert(Toolkit::DevelAnimatedGradientVisual::Property::OFFSET, BuildMap(-1.0f, 1.0f, 0, mCardDuration, 0.0f, 1, 0.0f, 0, 2)); } void InitMap() @@ -562,15 +563,15 @@ private: // Setup const parameter values void BuildParameter() { - mNormalColor = DEFAULT_COLOR; - mCardDuration = CARD_MOVE_DURATION; - mDuration = CHANGE_DURATION; - mLoadingTime = LOADING_ONE_CYCLE_DURATION; - mLoadingCount = LOADING_CYCLE_CNT; + mNormalColor = DEFAULT_COLOR; + mCardDuration = CARD_MOVE_DURATION; + mDuration = CHANGE_DURATION; + mLoadingTime = LOADING_ONE_CYCLE_DURATION; + mLoadingCount = LOADING_CYCLE_CNT; mLoadingCountScale = LOADING_CYCLE_DT; mNormalStartColor = mNormalColor; - mNormalEndColor = mNormalColor; + mNormalEndColor = mNormalColor; } void BuildAnimation() @@ -580,68 +581,68 @@ private: void SetupCards() { - mCards.Init( mWindow ); - for( int k = 0; k < CARD_NUM; k++ ) + mCards.Init(mWindow); + for(int k = 0; k < CARD_NUM; k++) { - mCards[k].TouchedSignal().Connect( this, &CardController::OnTouchCards ); + mCards[k].TouchedSignal().Connect(this, &CardController::OnTouchCards); } - mNormalStartColor = mCards.GetColorBackground( mCards.mCurIndex ); - mNormalEndColor = mCards.GetColorBackground( mCards.mCurIndex ); + mNormalStartColor = mCards.GetColorBackground(mCards.mCurIndex); + mNormalEndColor = mCards.GetColorBackground(mCards.mCurIndex); } // Create and Add to window void SetupActors() { mAddButton = ImageView::New(); - mAddButton.SetImage( BUTTON_ADD_IMAGE ); - mAddButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mAddButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mAddButton.SetProperty( Actor::Property::SIZE, BUTTON_ADD_SIZE * SCALED_WIDTH ); - mAddButton.SetProperty( Actor::Property::POSITION, BUTTON_ADD_POSITION * SCALED_WIDTH ); - - mLabel1 = TextLabel::New( LABEL_TICKET_STR ); - mLabel1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mLabel1.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mLabel1.SetProperty( Actor::Property::SIZE, LABEL_TICKET_SIZE * SCALED_WIDTH ); - mLabel1.SetProperty( Actor::Property::POSITION, LABEL_TICKET_POSITION * SCALED_WIDTH ); - mLabel1.SetProperty( Actor::Property::VISIBLE, true ); - mLabel1.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_TICKET_FONT_COLOR ); - mLabel1.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_TICKET_FONT_SIZE * FONT_SCALE ); - mLabel1.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabel1.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mLabel2 = TextLabel::New( LABEL_HOLD_STR ); - mLabel2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLabel2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLabel2.SetProperty( Actor::Property::SIZE, LABEL_HOLD_SIZE * SCALED_WIDTH ); - mLabel2.SetProperty( Actor::Property::POSITION, LABEL_HOLD_POSITION * SCALED_WIDTH ); - mLabel2.SetProperty( Actor::Property::VISIBLE, false ); - mLabel2.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_HOLD_FONT_COLOR ); - mLabel2.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_HOLD_FONT_SIZE * FONT_SCALE ); - mLabel2.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabel2.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mLabel3 = TextLabel::New( LABEL_TERMINAL_STR ); - mLabel3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLabel3.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLabel3.SetProperty( Actor::Property::SIZE, LABEL_TERMINAL_SIZE * SCALED_WIDTH ); - mLabel3.SetProperty( Actor::Property::POSITION, LABEL_TERMINAL_POSITION * SCALED_WIDTH ); - mLabel3.SetProperty( Actor::Property::VISIBLE, false ); - mLabel3.SetProperty( TextLabel::Property::TEXT_COLOR, LABEL_TERMINAL_FONT_COLOR ); - mLabel3.SetProperty( TextLabel::Property::POINT_SIZE, LABEL_TERMINAL_FONT_SIZE * FONT_SCALE ); - mLabel3.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabel3.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - - mWindow.Add( mAddButton ); - mWindow.Add( mLabel1 ); - mWindow.Add( mLabel2 ); - mWindow.Add( mLabel3 ); + mAddButton.SetImage(BUTTON_ADD_IMAGE); + mAddButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mAddButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mAddButton.SetProperty(Actor::Property::SIZE, BUTTON_ADD_SIZE * SCALED_WIDTH); + mAddButton.SetProperty(Actor::Property::POSITION, BUTTON_ADD_POSITION * SCALED_WIDTH); + + mLabel1 = TextLabel::New(LABEL_TICKET_STR); + mLabel1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mLabel1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mLabel1.SetProperty(Actor::Property::SIZE, LABEL_TICKET_SIZE * SCALED_WIDTH); + mLabel1.SetProperty(Actor::Property::POSITION, LABEL_TICKET_POSITION * SCALED_WIDTH); + mLabel1.SetProperty(Actor::Property::VISIBLE, true); + mLabel1.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_TICKET_FONT_COLOR); + mLabel1.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_TICKET_FONT_SIZE * FONT_SCALE); + mLabel1.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabel1.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mLabel2 = TextLabel::New(LABEL_HOLD_STR); + mLabel2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLabel2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLabel2.SetProperty(Actor::Property::SIZE, LABEL_HOLD_SIZE * SCALED_WIDTH); + mLabel2.SetProperty(Actor::Property::POSITION, LABEL_HOLD_POSITION * SCALED_WIDTH); + mLabel2.SetProperty(Actor::Property::VISIBLE, false); + mLabel2.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_HOLD_FONT_COLOR); + mLabel2.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_HOLD_FONT_SIZE * FONT_SCALE); + mLabel2.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabel2.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mLabel3 = TextLabel::New(LABEL_TERMINAL_STR); + mLabel3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLabel3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLabel3.SetProperty(Actor::Property::SIZE, LABEL_TERMINAL_SIZE * SCALED_WIDTH); + mLabel3.SetProperty(Actor::Property::POSITION, LABEL_TERMINAL_POSITION * SCALED_WIDTH); + mLabel3.SetProperty(Actor::Property::VISIBLE, false); + mLabel3.SetProperty(TextLabel::Property::TEXT_COLOR, LABEL_TERMINAL_FONT_COLOR); + mLabel3.SetProperty(TextLabel::Property::POINT_SIZE, LABEL_TERMINAL_FONT_SIZE * FONT_SCALE); + mLabel3.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabel3.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + mWindow.Add(mAddButton); + mWindow.Add(mLabel1); + mWindow.Add(mLabel2); + mWindow.Add(mLabel3); } void SetupAnimation() { - mMoveFront = Animation::New( mDuration ); - mMoveBack = Animation::New( mDuration ); + mMoveFront = Animation::New(mDuration); + mMoveBack = Animation::New(mDuration); } // Run animations when 'index' card active @@ -649,81 +650,81 @@ private: { //set animated background color here mColorAnimationStartStart[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor; - mColorAnimationStartEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor; - mColorAnimationEndStart[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor; - mColorAnimationEndEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor; + mColorAnimationStartEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor; + mColorAnimationEndStart[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor; + mColorAnimationEndEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::START] = mNormalStartColor; - mColorAnimationStartStart[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorStart( index ); - mColorAnimationStartEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorEnd( index ); - mColorAnimationEndStart[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorStart( index ); - mColorAnimationEndEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorEnd( index ); + mColorAnimationStartStart[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorStart(index); + mColorAnimationStartEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorEnd(index); + mColorAnimationEndStart[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorStart(index); + mColorAnimationEndEnd[DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET] = mCards.GetColorEnd(index); mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mColorAnimationStartStart; - mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mColorAnimationStartEnd; - mBackgroundMapEnd[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mColorAnimationEndStart; - mBackgroundMapEnd[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mColorAnimationEndEnd; + mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mColorAnimationStartEnd; + mBackgroundMapEnd[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mColorAnimationEndStart; + mBackgroundMapEnd[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mColorAnimationEndEnd; - if( index == 1 ) + if(index == 1) { // Rotate background gradient - mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = BuildMap( 0.0f, Math::PI * 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0 ); + mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = BuildMap(0.0f, Math::PI * 2.0f, 0, mLoadingTime, 0.0f, -1, 0.0f, 0, 0); } - else if( index == 2 ) + else if(index == 2) { // Rotate background gradient more slow - mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = BuildMap( 0.0f, Math::PI * 2.0f, 0, mLoadingTime * 2.0, 0.0f, -1, 0.0f, 0, 0 ); + mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = BuildMap(0.0f, Math::PI * 2.0f, 0, mLoadingTime * 2.0, 0.0f, -1, 0.0f, 0, 0); } else { mBackgroundMapStart[Toolkit::DevelAnimatedGradientVisual::Property::ROTATE_AMOUNT] = 0.0f; } - mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapStart ); + mBackground.SetProperty(Control::Property::BACKGROUND, mBackgroundMapStart); - mTickCount = 0; - mBackgroundChanger = Timer::New( mLoadingTime * 1000.0f / mLoadingCountScale ); - mBackgroundChanger.TickSignal().Connect( this, &CardController::OnTickBackground ); + mTickCount = 0; + mBackgroundChanger = Timer::New(mLoadingTime * 1000.0f / mLoadingCountScale); + mBackgroundChanger.TickSignal().Connect(this, &CardController::OnTickBackground); mBackgroundChanger.Start(); - mMoveFront.AnimateTo( Property( mCards[index], Actor::Property::SIZE_WIDTH ), CARD_SIZE_BIG.x * SCALED_WIDTH ); - mMoveFront.AnimateTo( Property( mCards[index], Actor::Property::SIZE_HEIGHT ), CARD_SIZE_BIG.y * SCALED_HEIGHT ); - mMoveFront.AnimateTo( Property( mCards[index], Actor::Property::POSITION_Y ), CARD_BIG_OFFSET.y * SCALED_HEIGHT ); - mMoveBack.AnimateTo( Property( mCards[index], Actor::Property::SIZE_WIDTH ), CARD_SIZE.x * SCALED_WIDTH ); - mMoveBack.AnimateTo( Property( mCards[index], Actor::Property::SIZE_HEIGHT ), CARD_SIZE.y * SCALED_HEIGHT ); - mMoveBack.AnimateTo( Property( mCards[index], Actor::Property::POSITION_Y ), CARD_OFFSET.y * SCALED_HEIGHT ); - for( int i = 0; i < index; i++ ) + mMoveFront.AnimateTo(Property(mCards[index], Actor::Property::SIZE_WIDTH), CARD_SIZE_BIG.x * SCALED_WIDTH); + mMoveFront.AnimateTo(Property(mCards[index], Actor::Property::SIZE_HEIGHT), CARD_SIZE_BIG.y * SCALED_HEIGHT); + mMoveFront.AnimateTo(Property(mCards[index], Actor::Property::POSITION_Y), CARD_BIG_OFFSET.y * SCALED_HEIGHT); + mMoveBack.AnimateTo(Property(mCards[index], Actor::Property::SIZE_WIDTH), CARD_SIZE.x * SCALED_WIDTH); + mMoveBack.AnimateTo(Property(mCards[index], Actor::Property::SIZE_HEIGHT), CARD_SIZE.y * SCALED_HEIGHT); + mMoveBack.AnimateTo(Property(mCards[index], Actor::Property::POSITION_Y), CARD_OFFSET.y * SCALED_HEIGHT); + for(int i = 0; i < index; i++) { - mMoveFront.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), -CARD_MOVE_DIST * SCALED_WIDTH ); - mMoveBack.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), CARD_MOVE_DIST * SCALED_WIDTH ); + mMoveFront.AnimateBy(Property(mCards[i], Actor::Property::POSITION_X), -CARD_MOVE_DIST * SCALED_WIDTH); + mMoveBack.AnimateBy(Property(mCards[i], Actor::Property::POSITION_X), CARD_MOVE_DIST * SCALED_WIDTH); } - for( int i = index + 1; i < CARD_NUM; i++ ) + for(int i = index + 1; i < CARD_NUM; i++) { - mMoveFront.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), CARD_MOVE_DIST * SCALED_WIDTH ); - mMoveBack.AnimateBy( Property( mCards[i], Actor::Property::POSITION_X ), -CARD_MOVE_DIST * SCALED_WIDTH ); + mMoveFront.AnimateBy(Property(mCards[i], Actor::Property::POSITION_X), CARD_MOVE_DIST * SCALED_WIDTH); + mMoveBack.AnimateBy(Property(mCards[i], Actor::Property::POSITION_X), -CARD_MOVE_DIST * SCALED_WIDTH); } - mMoveFront.AnimateTo( Property( mAddButton, Actor::Property::POSITION_Y ), BUTTON_ADD_SIZE.y * SCALED_HEIGHT ); - mMoveBack.AnimateTo( Property( mAddButton, Actor::Property::POSITION_Y ), 0.f * SCALED_HEIGHT ); + mMoveFront.AnimateTo(Property(mAddButton, Actor::Property::POSITION_Y), BUTTON_ADD_SIZE.y * SCALED_HEIGHT); + mMoveBack.AnimateTo(Property(mAddButton, Actor::Property::POSITION_Y), 0.f * SCALED_HEIGHT); - mMoveFront.AnimateTo( Property( mLabel1, Actor::Property::VISIBLE), false ); - mMoveFront.AnimateTo( Property( mLabel2, Actor::Property::VISIBLE), true ); - mMoveFront.AnimateTo( Property( mLabel3, Actor::Property::VISIBLE), true ); - mMoveBack.AnimateTo( Property( mLabel1, Actor::Property::VISIBLE), true ); - mMoveBack.AnimateTo( Property( mLabel2, Actor::Property::VISIBLE), false ); - mMoveBack.AnimateTo( Property( mLabel3, Actor::Property::VISIBLE), false ); + mMoveFront.AnimateTo(Property(mLabel1, Actor::Property::VISIBLE), false); + mMoveFront.AnimateTo(Property(mLabel2, Actor::Property::VISIBLE), true); + mMoveFront.AnimateTo(Property(mLabel3, Actor::Property::VISIBLE), true); + mMoveBack.AnimateTo(Property(mLabel1, Actor::Property::VISIBLE), true); + mMoveBack.AnimateTo(Property(mLabel2, Actor::Property::VISIBLE), false); + mMoveBack.AnimateTo(Property(mLabel3, Actor::Property::VISIBLE), false); mMoveFront.Play(); } bool OnTickBackground() { mTickCount++; - if( mCancelSignal || mTickCount >= mLoadingCount * mLoadingCountScale ) + if(mCancelSignal || mTickCount >= mLoadingCount * mLoadingCountScale) { - if( mCards.mCurState == 1 ) + if(mCards.mCurState == 1) { mCards.mCurState = 2; - mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapEnd ); + mBackground.SetProperty(Control::Property::BACKGROUND, mBackgroundMapEnd); mMoveBack.Play(); - mBackgroundChanger.SetInterval( mDuration * 1000.0f ); + mBackgroundChanger.SetInterval(mDuration * 1000.0f); return true; } else @@ -736,49 +737,49 @@ private: } void MoveRight() { - if( mCards.MoveRight( mCardDuration ) ) + if(mCards.MoveRight(mCardDuration)) { // Set smooth background color change here - mNormalEndColor = mCards.GetColorBackground( mCards.mCurIndex ); + mNormalEndColor = mCards.GetColorBackground(mCards.mCurIndex); mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mNormalEndColor; - mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalStartColor; + mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalStartColor; - (*mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::OFFSET].GetMap())[DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION] = Property::Value( DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD ); + (*mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::OFFSET].GetMap())[DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION] = Property::Value(DevelAnimatedGradientVisual::AnimationParameter::DirectionType::BACKWARD); - mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapMove ); + mBackground.SetProperty(Control::Property::BACKGROUND, mBackgroundMapMove); } } void MoveLeft() { - if( mCards.MoveLeft( mCardDuration ) ) + if(mCards.MoveLeft(mCardDuration)) { //Set smooth background color change here - mNormalEndColor = mCards.GetColorBackground( mCards.mCurIndex ); + mNormalEndColor = mCards.GetColorBackground(mCards.mCurIndex); mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mNormalStartColor; - mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalEndColor; + mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalEndColor; - (*mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::OFFSET].GetMap())[DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION] = Property::Value( DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD ); + (*mBackgroundMapMove[Toolkit::DevelAnimatedGradientVisual::Property::OFFSET].GetMap())[DevelAnimatedGradientVisual::AnimationParameter::Property::DIRECTION] = Property::Value(DevelAnimatedGradientVisual::AnimationParameter::DirectionType::FORWARD); - mBackground.SetProperty( Control::Property::BACKGROUND, mBackgroundMapMove ); + mBackground.SetProperty(Control::Property::BACKGROUND, mBackgroundMapMove); } } void Reset() { mCards.mCurState = 0; - mCancelSignal = false; + mCancelSignal = false; mMoveFront.Clear(); mMoveBack.Clear(); - mNormalStartColor = mNormalEndColor; + mNormalStartColor = mNormalEndColor; mBackgroundNormalMap[Toolkit::DevelAnimatedGradientVisual::Property::START_COLOR] = mNormalStartColor; - mBackgroundNormalMap[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalEndColor; + mBackgroundNormalMap[Toolkit::DevelAnimatedGradientVisual::Property::END_COLOR] = mNormalEndColor; mBackground.SetProperty(Control::Property::BACKGROUND, mBackgroundNormalMap); } private: - Application& mApplication; - Window mWindow; + Application& mApplication; + Window mWindow; CardManager mCards; @@ -818,19 +819,19 @@ private: float mCardDuration; float mDuration; float mLoadingTime; - int mLoadingCount; - int mLoadingCountScale; - int mTickCount; + int mLoadingCount; + int mLoadingCountScale; + int mTickCount; bool mCancelSignal; bool mIsTouchedActor; }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - CardController test( application ); + CardController test(application); application.MainLoop(); diff --git a/examples/animated-images/animated-images-example.cpp b/examples/animated-images/animated-images-example.cpp index 1b96ac1..9db95e4 100644 --- a/examples/animated-images/animated-images-example.cpp +++ b/examples/animated-images/animated-images-example.cpp @@ -25,45 +25,42 @@ using namespace Dali::Toolkit; namespace { -const char * const PLAY_ICON_UNSELECTED( DEMO_IMAGE_DIR "icon-play.png" ); -const char * const PLAY_ICON_SELECTED( DEMO_IMAGE_DIR "icon-play-selected.png" ); +const char* const PLAY_ICON_UNSELECTED(DEMO_IMAGE_DIR "icon-play.png"); +const char* const PLAY_ICON_SELECTED(DEMO_IMAGE_DIR "icon-play-selected.png"); const unsigned int ANIMATED_IMAGE_COUNT = 2; -const char * ANIMATED_IMAGE_URLS[ ANIMATED_IMAGE_COUNT ] = -{ - DEMO_IMAGE_DIR "dog-anim.webp", - DEMO_IMAGE_DIR "dali-logo-anim.gif" -}; +const char* ANIMATED_IMAGE_URLS[ANIMATED_IMAGE_COUNT] = + { + DEMO_IMAGE_DIR "dog-anim.webp", + DEMO_IMAGE_DIR "dali-logo-anim.gif"}; -const char * ANIMATED_ARRAY_URL_FORMATS[ ANIMATED_IMAGE_COUNT ] = -{ - DEMO_IMAGE_DIR "dog-anim-%03d.png", // Images are named dog-anim-001.png, dog-anim-002.png, etc. - DEMO_IMAGE_DIR "dali-logo-anim-%03d.png" // Images are named dali-logo-anim-001.png, dali-logo-anim-002.png, etc. +const char* ANIMATED_ARRAY_URL_FORMATS[ANIMATED_IMAGE_COUNT] = + { + DEMO_IMAGE_DIR "dog-anim-%03d.png", // Images are named dog-anim-001.png, dog-anim-002.png, etc. + DEMO_IMAGE_DIR "dali-logo-anim-%03d.png" // Images are named dali-logo-anim-001.png, dali-logo-anim-002.png, etc. }; -int ANIMATED_ARRAY_NUMBER_OF_FRAMES[ ANIMATED_IMAGE_COUNT ] = -{ - 8, - 15 -}; +int ANIMATED_ARRAY_NUMBER_OF_FRAMES[ANIMATED_IMAGE_COUNT] = + { + 8, + 15}; -const char * ANIMATION_RADIO_BUTTON_NAME( "Animation Image" ); -const char * ARRAY_RADIO_BUTTON_NAME( "Array" ); +const char* ANIMATION_RADIO_BUTTON_NAME("Animation Image"); +const char* ARRAY_RADIO_BUTTON_NAME("Array"); /// Structure to specify the layout information for the animated images views. struct ImageLayoutInfo { Vector3 anchorPoint; Vector3 parentOrigin; - float yPosition; + float yPosition; }; -ImageLayoutInfo IMAGE_LAYOUT_INFO[ ANIMATED_IMAGE_COUNT ] = -{ - { AnchorPoint::BOTTOM_CENTER, ParentOrigin::CENTER, -80.0f }, - { AnchorPoint::TOP_CENTER, ParentOrigin::CENTER, 80.0f } -}; +ImageLayoutInfo IMAGE_LAYOUT_INFO[ANIMATED_IMAGE_COUNT] = + { + {AnchorPoint::BOTTOM_CENTER, ParentOrigin::CENTER, -80.0f}, + {AnchorPoint::TOP_CENTER, ParentOrigin::CENTER, 80.0f}}; } // unnamed namespace @@ -77,40 +74,38 @@ ImageLayoutInfo IMAGE_LAYOUT_INFO[ ANIMATED_IMAGE_COUNT ] = class AnimatedImageController : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application A reference to the Application class */ - AnimatedImageController( Application& application ) - : mApplication( application ), - mImageType( ImageType::ANIMATED_IMAGE ) + AnimatedImageController(Application& application) + : mApplication(application), + mImageType(ImageType::ANIMATED_IMAGE) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &AnimatedImageController::Create ); + mApplication.InitSignal().Connect(this, &AnimatedImageController::Create); } private: - /** * @brief The image types supported by the application. */ enum class ImageType { - ANIMATED_IMAGE, ///< Displays Animated Image Files. - IMAGE_ARRAY ///< Displays an array of URLs that are used as an animated image. + ANIMATED_IMAGE, ///< Displays Animated Image Files. + IMAGE_ARRAY ///< Displays an array of URLs that are used as an animated image. }; /** * @brief Called to initialise the application content. * @param[in] application A reference to the Application class */ - void Create( Application& application ) + void Create(Application& application) { // Set the window background color and connect to the window's key signal to allow Back and Escape to exit. Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); - window.KeyEventSignal().Connect( this, &AnimatedImageController::OnKeyEvent ); + window.SetBackgroundColor(Color::WHITE); + window.KeyEventSignal().Connect(this, &AnimatedImageController::OnKeyEvent); // Create the animated image-views CreateAnimatedImageViews(window); @@ -120,7 +115,7 @@ private: // Create a tap gesture detector to use to pause the animated images mTapDetector = TapGestureDetector::New(); - mTapDetector.DetectedSignal().Connect( this, &AnimatedImageController::OnTap ); + mTapDetector.DetectedSignal().Connect(this, &AnimatedImageController::OnTap); } /** @@ -128,27 +123,27 @@ private: */ void CreateRadioButtonLayout(Window& window) { - mAnimatedImageButton = CreateRadioButton( ANIMATION_RADIO_BUTTON_NAME, true ); - mArrayButton = CreateRadioButton( ARRAY_RADIO_BUTTON_NAME, false ); - - Toolkit::TableView radioButtonLayout = Toolkit::TableView::New( 1, 2 ); - radioButtonLayout.SetProperty( Dali::Actor::Property::NAME, "RadioButtonsLayout" ); - radioButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); - radioButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - radioButtonLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - radioButtonLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - radioButtonLayout.SetFitHeight( 0 ); - radioButtonLayout.AddChild( mAnimatedImageButton, TableView::CellPosition( 0, 0 ) ); - radioButtonLayout.AddChild( mArrayButton, TableView::CellPosition( 0, 1 ) ); - radioButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), - HorizontalAlignment::CENTER, - VerticalAlignment::CENTER ); - radioButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), - HorizontalAlignment::CENTER, - VerticalAlignment::CENTER ); - radioButtonLayout.SetProperty( Actor::Property::POSITION_Y, -10.0f ); - - window.Add( radioButtonLayout ); + mAnimatedImageButton = CreateRadioButton(ANIMATION_RADIO_BUTTON_NAME, true); + mArrayButton = CreateRadioButton(ARRAY_RADIO_BUTTON_NAME, false); + + Toolkit::TableView radioButtonLayout = Toolkit::TableView::New(1, 2); + radioButtonLayout.SetProperty(Dali::Actor::Property::NAME, "RadioButtonsLayout"); + radioButtonLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + radioButtonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + radioButtonLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + radioButtonLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + radioButtonLayout.SetFitHeight(0); + radioButtonLayout.AddChild(mAnimatedImageButton, TableView::CellPosition(0, 0)); + radioButtonLayout.AddChild(mArrayButton, TableView::CellPosition(0, 1)); + radioButtonLayout.SetCellAlignment(TableView::CellPosition(0, 0), + HorizontalAlignment::CENTER, + VerticalAlignment::CENTER); + radioButtonLayout.SetCellAlignment(TableView::CellPosition(0, 1), + HorizontalAlignment::CENTER, + VerticalAlignment::CENTER); + radioButtonLayout.SetProperty(Actor::Property::POSITION_Y, -10.0f); + + window.Add(radioButtonLayout); } /** @@ -157,11 +152,11 @@ private: * @param[in] selected Whether the button is selected * @return The created radio-button */ - RadioButton CreateRadioButton( const char * const name, bool selected ) + RadioButton CreateRadioButton(const char* const name, bool selected) { - RadioButton radioButton = Toolkit::RadioButton::New( name ); - radioButton.SetProperty( Button::Property::SELECTED, selected ); - radioButton.ClickedSignal().Connect( this, &AnimatedImageController::OnRadioButtonClicked ); + RadioButton radioButton = Toolkit::RadioButton::New(name); + radioButton.SetProperty(Button::Property::SELECTED, selected); + radioButton.ClickedSignal().Connect(this, &AnimatedImageController::OnRadioButtonClicked); return radioButton; } @@ -170,10 +165,10 @@ private: */ void CreateAnimatedImageViews(Window window) { - for( unsigned int index = 0; index < ANIMATED_IMAGE_COUNT; ++index ) + for(unsigned int index = 0; index < ANIMATED_IMAGE_COUNT; ++index) { - Control& control = ( index == 0 ) ? mActorDog : mActorLogo; - if( control ) + Control& control = (index == 0) ? mActorDog : mActorLogo; + if(control) { // Remove the previous control from the window, it's resources (and children) will be deleted automatically control.Unparent(); @@ -181,17 +176,17 @@ private: // Create and lay out the image view according to the index control = Toolkit::ImageView::New(); - control.SetProperty( Toolkit::ImageView::Property::IMAGE, SetupViewProperties( mImageType, index ) ); - control.SetProperty( Actor::Property::ANCHOR_POINT, IMAGE_LAYOUT_INFO[ index ].anchorPoint ); - control.SetProperty( Actor::Property::PARENT_ORIGIN, IMAGE_LAYOUT_INFO[ index ].parentOrigin ); - control.SetProperty( Actor::Property::POSITION_Y, IMAGE_LAYOUT_INFO[ index ].yPosition ); + control.SetProperty(Toolkit::ImageView::Property::IMAGE, SetupViewProperties(mImageType, index)); + control.SetProperty(Actor::Property::ANCHOR_POINT, IMAGE_LAYOUT_INFO[index].anchorPoint); + control.SetProperty(Actor::Property::PARENT_ORIGIN, IMAGE_LAYOUT_INFO[index].parentOrigin); + control.SetProperty(Actor::Property::POSITION_Y, IMAGE_LAYOUT_INFO[index].yPosition); - control.SetProperty( Actor::Property::SIZE, Vector2(300, 300) ); + control.SetProperty(Actor::Property::SIZE, Vector2(300, 300)); // We do not want the animated image playing when it's added to the window. - PauseAnimatedImage( control ); + PauseAnimatedImage(control); - window.Add( control ); + window.Add(control); } } @@ -200,16 +195,16 @@ private: * @details Also sets up the control so it can be paused when tapped. * @param[in] control The animated image to play */ - void PlayAnimatedImage( Control& control ) + void PlayAnimatedImage(Control& control) { - DevelControl::DoAction( control, - ImageView::Property::IMAGE, - DevelAnimatedImageVisual::Action::PLAY, - Property::Value() ); + DevelControl::DoAction(control, + ImageView::Property::IMAGE, + DevelAnimatedImageVisual::Action::PLAY, + Property::Value()); - if( mTapDetector ) + if(mTapDetector) { - mTapDetector.Attach( control ); + mTapDetector.Attach(control); } } @@ -219,25 +214,25 @@ private: * the button is tapped. * @param[in] control The animated image to pause */ - void PauseAnimatedImage( Control& control ) + void PauseAnimatedImage(Control& control) { - DevelControl::DoAction( control, - ImageView::Property::IMAGE, - DevelAnimatedImageVisual::Action::PAUSE, - Property::Value() ); + DevelControl::DoAction(control, + ImageView::Property::IMAGE, + DevelAnimatedImageVisual::Action::PAUSE, + Property::Value()); // Create a push button, and add it as child of the control Toolkit::PushButton animateButton = Toolkit::PushButton::New(); - animateButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON_UNSELECTED ); - animateButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED ); - animateButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - animateButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - animateButton.ClickedSignal().Connect( this, &AnimatedImageController::OnPlayButtonClicked ); - control.Add( animateButton ); - - if( mTapDetector ) + animateButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON_UNSELECTED); + animateButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED); + animateButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + animateButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + animateButton.ClickedSignal().Connect(this, &AnimatedImageController::OnPlayButtonClicked); + control.Add(animateButton); + + if(mTapDetector) { - mTapDetector.Detach( control ); + mTapDetector.Detach(control); } } @@ -247,10 +242,10 @@ private: * @param[in] button The button that has been clicked * @return We return true to state that we handled the event */ - bool OnPlayButtonClicked( Toolkit::Button button ) + bool OnPlayButtonClicked(Toolkit::Button button) { - Control control = ( button.GetParent() == mActorDog ) ? mActorDog : mActorLogo; - PlayAnimatedImage( control ); + Control control = (button.GetParent() == mActorDog) ? mActorDog : mActorLogo; + PlayAnimatedImage(control); button.Unparent(); @@ -262,10 +257,10 @@ private: * @details This method is used to pause the tapped animated image view. * @param[in] actor The actor that's tapped */ - void OnTap( Dali::Actor actor, const Dali::TapGesture& /* tap */ ) + void OnTap(Dali::Actor actor, const Dali::TapGesture& /* tap */) { - Control control = ( actor == mActorDog ) ? mActorDog : mActorLogo; - PauseAnimatedImage( control ); + Control control = (actor == mActorDog) ? mActorDog : mActorLogo; + PauseAnimatedImage(control); } /** @@ -275,9 +270,9 @@ private: * @return We return true to state that we handled the event. * */ - bool OnRadioButtonClicked( Toolkit::Button button ) + bool OnRadioButtonClicked(Toolkit::Button button) { - mImageType = ( button == mAnimatedImageButton ) ? ImageType::ANIMATED_IMAGE : ImageType::IMAGE_ARRAY; + mImageType = (button == mAnimatedImageButton) ? ImageType::ANIMATED_IMAGE : ImageType::IMAGE_ARRAY; CreateAnimatedImageViews(mApplication.GetWindow()); return true; @@ -293,7 +288,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -306,12 +301,12 @@ private: * @param[in] index The index * @return The set up property value */ - Property::Value SetupViewProperties( ImageType type, int index ) + Property::Value SetupViewProperties(ImageType type, int index) { Property::Map map; - AddUrl( map, type, index ); - AddCache( map, type, index ); + AddUrl(map, type, index); + AddCache(map, type, index); return Property::Value(map); } @@ -321,27 +316,27 @@ private: * @param[in] type The Image type * @param[in] index The index */ - void AddUrl( Property::Map& map, ImageType type, int index ) + void AddUrl(Property::Map& map, ImageType type, int index) { - if( type == ImageType::ANIMATED_IMAGE ) + if(type == ImageType::ANIMATED_IMAGE) { - map.Add( Toolkit::ImageVisual::Property::URL, Property::Value( ANIMATED_IMAGE_URLS[ index ] ) ); + map.Add(Toolkit::ImageVisual::Property::URL, Property::Value(ANIMATED_IMAGE_URLS[index])); } else { Property::Array frameUrls; - for( int i = 1; i <= ANIMATED_ARRAY_NUMBER_OF_FRAMES[ index ]; ++i ) + for(int i = 1; i <= ANIMATED_ARRAY_NUMBER_OF_FRAMES[index]; ++i) { char* buffer; - int len = asprintf( &buffer, ANIMATED_ARRAY_URL_FORMATS[ index ], i ); - if( len > 0 ) + int len = asprintf(&buffer, ANIMATED_ARRAY_URL_FORMATS[index], i); + if(len > 0) { - std::string frameUrl( buffer ); - free( buffer ); - frameUrls.Add( Property::Value( frameUrl ) ); + std::string frameUrl(buffer); + free(buffer); + frameUrls.Add(Property::Value(frameUrl)); } } - map.Add( Toolkit::ImageVisual::Property::URL, Property::Value( frameUrls ) ); + map.Add(Toolkit::ImageVisual::Property::URL, Property::Value(frameUrls)); } } @@ -351,36 +346,36 @@ private: * @param[in] type The Image type * @param[in] index The index */ - void AddCache( Property::Map& map, ImageType type, int index ) + void AddCache(Property::Map& map, ImageType type, int index) { - if( type == ImageType::IMAGE_ARRAY ) + if(type == ImageType::IMAGE_ARRAY) { map - .Add( Toolkit::ImageVisual::Property::BATCH_SIZE, 4 ) - .Add( Toolkit::ImageVisual::Property::CACHE_SIZE, 10 ) - .Add( Toolkit::ImageVisual::Property::FRAME_DELAY, 150 ); + .Add(Toolkit::ImageVisual::Property::BATCH_SIZE, 4) + .Add(Toolkit::ImageVisual::Property::CACHE_SIZE, 10) + .Add(Toolkit::ImageVisual::Property::FRAME_DELAY, 150); } } private: - Application& mApplication; ///< A reference to the application. + Application& mApplication; ///< A reference to the application. Toolkit::ImageView mActorDog; ///< The current dog image view. Toolkit::ImageView mActorLogo; ///< The current logo image view. - Toolkit::RadioButton mAnimatedImageButton; ///< The Animated Image Radio Button. - Toolkit::RadioButton mArrayButton; ///< The Array Radio Button. + Toolkit::RadioButton mAnimatedImageButton; ///< The Animated Image Radio Button. + Toolkit::RadioButton mArrayButton; ///< The Array Radio Button. TapGestureDetector mTapDetector; ///< The tap detector. ImageType mImageType; ///< The current Image type. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - AnimatedImageController test( application ); + AnimatedImageController test(application); application.MainLoop(); diff --git a/examples/animated-shapes/animated-shapes-example.cpp b/examples/animated-shapes/animated-shapes-example.cpp index b4633cd..04c9bbd 100644 --- a/examples/animated-shapes/animated-shapes-example.cpp +++ b/examples/animated-shapes/animated-shapes-example.cpp @@ -15,8 +15,8 @@ * */ -#include #include +#include #include "shared/view.h" #include @@ -26,9 +26,9 @@ using namespace Dali::Toolkit; namespace { - const char* APPLICATION_TITLE("Animated Shapes"); +// clang-format off const char* VERTEX_SHADER = DALI_COMPOSE_SHADER ( attribute mediump vec3 aCoefficient; @@ -60,21 +60,25 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER gl_FragColor = vec4( uColor.rgb, uColor.a * alpha ); } ); +// clang-format on -Shader CreateShader( unsigned int pointCount ) +Shader CreateShader(unsigned int pointCount) { std::ostringstream vertexShader; - vertexShader << "#define MAX_POINT_COUNT "<< pointCount << "\n"< -#include "shared/view.h" -#include #include #include #include #include #include #include +#include +#include +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; namespace { - -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-gradient.jpg" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "Animated Vector Images" ); +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-gradient.jpg"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("Animated Vector Images"); const char* IMAGE_PATH[] = { - DEMO_IMAGE_DIR "insta_camera.json", - DEMO_IMAGE_DIR "you're_in!.json", - DEMO_IMAGE_DIR "jolly_walker.json" -}; + DEMO_IMAGE_DIR "insta_camera.json", + DEMO_IMAGE_DIR "you're_in!.json", + DEMO_IMAGE_DIR "jolly_walker.json"}; const unsigned int NUMBER_OF_IMAGES = 3; @@ -51,159 +49,156 @@ enum CellPlacement NUMBER_OF_ROWS }; -unsigned int GetControlIndex( Control control ) +unsigned int GetControlIndex(Control control) { - std::string controlName = control.GetProperty< std::string >( Dali::Actor::Property::NAME ); - unsigned int index = 0; + std::string controlName = control.GetProperty(Dali::Actor::Property::NAME); + unsigned int index = 0; - if ( controlName != "") + if(controlName != "") { - index = std::stoul( controlName ); + index = std::stoul(controlName); } return index; } -} // namespace +} // namespace // This example shows the usage of AnimatedVectorImageVisual. // It doesn't work on Ubuntu because the visual uses the external library to render frames. -class AnimatedVectorImageViewController: public ConnectionTracker +class AnimatedVectorImageViewController : public ConnectionTracker { - public: - - AnimatedVectorImageViewController( Application& application ) - : mApplication( application ) +public: + AnimatedVectorImageViewController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &AnimatedVectorImageViewController::Create ); + mApplication.InitSignal().Connect(this, &AnimatedVectorImageViewController::Create); } - void Create( Application& application ) + void Create(Application& application) { // The Init signal is received once (only) during the Application lifetime // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); - + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Create a table view to show a pair of buttons above each image. - mTable = TableView::New( CellPlacement::NUMBER_OF_ROWS, NUMBER_OF_IMAGES ); - mTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Vector3 offset( 0.9f, 0.70f, 0.0f ); - mTable.SetProperty( Actor::Property::SIZE_MODE_FACTOR, offset ); + mTable = TableView::New(CellPlacement::NUMBER_OF_ROWS, NUMBER_OF_IMAGES); + mTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mTable.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + Vector3 offset(0.9f, 0.70f, 0.0f); + mTable.SetProperty(Actor::Property::SIZE_MODE_FACTOR, offset); mTable.SetFitHeight(CellPlacement::TOP_BUTTON); mTable.SetFitHeight(CellPlacement::LOWER_BUTTON); - mContentLayer.Add( mTable ); + mContentLayer.Add(mTable); - for( unsigned int x = 0; x < NUMBER_OF_IMAGES; x++ ) + for(unsigned int x = 0; x < NUMBER_OF_IMAGES; x++) { mPlayButtons[x] = PushButton::New(); - mPlayButtons[x].SetProperty( Button::Property::LABEL, "Play" ); - mPlayButtons[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mPlayButtons[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mPlayButtons[x].ClickedSignal().Connect( this, &AnimatedVectorImageViewController::OnPlayButtonClicked ); - mPlayButtons[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mPlayButtons[x].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + mPlayButtons[x].SetProperty(Button::Property::LABEL, "Play"); + mPlayButtons[x].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mPlayButtons[x].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mPlayButtons[x].ClickedSignal().Connect(this, &AnimatedVectorImageViewController::OnPlayButtonClicked); + mPlayButtons[x].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mPlayButtons[x].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); std::string s = std::to_string(x); - mPlayButtons[x].SetProperty( Dali::Actor::Property::NAME, s ); - mTable.AddChild( mPlayButtons[x], TableView::CellPosition( CellPlacement::TOP_BUTTON, x ) ); + mPlayButtons[x].SetProperty(Dali::Actor::Property::NAME, s); + mTable.AddChild(mPlayButtons[x], TableView::CellPosition(CellPlacement::TOP_BUTTON, x)); mStopButtons[x] = PushButton::New(); - mStopButtons[x].SetProperty( Button::Property::LABEL, "Stop" ); - mStopButtons[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mStopButtons[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mStopButtons[x].ClickedSignal().Connect( this, &AnimatedVectorImageViewController::OnStopButtonClicked ); - mStopButtons[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mStopButtons[x].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mStopButtons[x].SetProperty( Dali::Actor::Property::NAME, s ); - mTable.AddChild( mStopButtons[x], TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) ); - - mImageViews[x] = ImageView::New( ); + mStopButtons[x].SetProperty(Button::Property::LABEL, "Stop"); + mStopButtons[x].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mStopButtons[x].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mStopButtons[x].ClickedSignal().Connect(this, &AnimatedVectorImageViewController::OnStopButtonClicked); + mStopButtons[x].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mStopButtons[x].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mStopButtons[x].SetProperty(Dali::Actor::Property::NAME, s); + mTable.AddChild(mStopButtons[x], TableView::CellPosition(CellPlacement::LOWER_BUTTON, x)); + + mImageViews[x] = ImageView::New(); Property::Map imagePropertyMap; - imagePropertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - imagePropertyMap.Insert( ImageVisual::Property::URL, IMAGE_PATH[ x ] ); - imagePropertyMap.Insert( DevelImageVisual::Property::LOOP_COUNT, 3 ); - mImageViews[x].SetProperty( ImageView::Property::IMAGE, imagePropertyMap ); + imagePropertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); + imagePropertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATH[x]); + imagePropertyMap.Insert(DevelImageVisual::Property::LOOP_COUNT, 3); + mImageViews[x].SetProperty(ImageView::Property::IMAGE, imagePropertyMap); - mImageViews[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mImageViews[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mImageViews[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mImageViews[x].SetProperty( Dali::Actor::Property::NAME, s ); + mImageViews[x].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageViews[x].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mImageViews[x].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mImageViews[x].SetProperty(Dali::Actor::Property::NAME, s); - DevelControl::VisualEventSignal( mImageViews[x] ).Connect( this, &AnimatedVectorImageViewController::OnVisualEvent ); + DevelControl::VisualEventSignal(mImageViews[x]).Connect(this, &AnimatedVectorImageViewController::OnVisualEvent); - mTable.AddChild( mImageViews[x], TableView::CellPosition( CellPlacement::IMAGE, x ) ); + mTable.AddChild(mImageViews[x], TableView::CellPosition(CellPlacement::IMAGE, x)); } application.GetWindow().KeyEventSignal().Connect(this, &AnimatedVectorImageViewController::OnKeyEvent); } private: - - bool OnPlayButtonClicked( Button button ) + bool OnPlayButtonClicked(Button button) { - unsigned int controlIndex = GetControlIndex( button ); + unsigned int controlIndex = GetControlIndex(button); - ImageView imageView = mImageViews[controlIndex]; + ImageView imageView = mImageViews[controlIndex]; - Property::Map map = imageView.GetProperty< Property::Map >( ImageView::Property::IMAGE ); - Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE ); + Property::Map map = imageView.GetProperty(ImageView::Property::IMAGE); + Property::Value* value = map.Find(DevelImageVisual::Property::PLAY_STATE); - if( value ) + if(value) { - if( value->Get< int >() != static_cast< int >( DevelImageVisual::PlayState::PLAYING ) ) + if(value->Get() != static_cast(DevelImageVisual::PlayState::PLAYING)) { - mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Pause" ); + mPlayButtons[controlIndex].SetProperty(Button::Property::LABEL, "Pause"); - DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PLAY, Property::Value() ); + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PLAY, Property::Value()); } else { - mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Play" ); + mPlayButtons[controlIndex].SetProperty(Button::Property::LABEL, "Play"); - DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Value() ); + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Value()); } } return true; } - bool OnStopButtonClicked( Button button ) + bool OnStopButtonClicked(Button button) { - unsigned int controlIndex = GetControlIndex( button ); - ImageView imageView = mImageViews[controlIndex]; - DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::STOP, Property::Value() ); + unsigned int controlIndex = GetControlIndex(button); + ImageView imageView = mImageViews[controlIndex]; + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::STOP, Property::Value()); return true; } - void OnVisualEvent( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId ) + void OnVisualEvent(Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId) { - unsigned int controlIndex = GetControlIndex( control ); + unsigned int controlIndex = GetControlIndex(control); - if( visualIndex == ImageView::Property::IMAGE && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED ) + if(visualIndex == ImageView::Property::IMAGE && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED) { - mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Play" ); + mPlayButtons[controlIndex].SetProperty(Button::Property::LABEL, "Play"); } } /** * Main key event handler */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -211,22 +206,21 @@ private: } private: - Application& mApplication; - - Control mView; ///< The View instance. - ToolBar mToolBar; ///< The View's Toolbar. - Layer mContentLayer; ///< Content layer - TableView mTable; - ImageView mImageViews[ NUMBER_OF_IMAGES ]; - PushButton mPlayButtons[ NUMBER_OF_IMAGES ]; - PushButton mStopButtons[ NUMBER_OF_IMAGES ]; - + Application& mApplication; + + Control mView; ///< The View instance. + ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer + TableView mTable; + ImageView mImageViews[NUMBER_OF_IMAGES]; + PushButton mPlayButtons[NUMBER_OF_IMAGES]; + PushButton mStopButtons[NUMBER_OF_IMAGES]; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - AnimatedVectorImageViewController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + AnimatedVectorImageViewController test(application); application.MainLoop(); return 0; } diff --git a/examples/arc-visual/arc-visual-example.cpp b/examples/arc-visual/arc-visual-example.cpp index 3a1aa95..8ccb78a 100644 --- a/examples/arc-visual/arc-visual-example.cpp +++ b/examples/arc-visual/arc-visual-example.cpp @@ -17,64 +17,52 @@ #include #include -#include -#include +#include #include +#include #include -#include using namespace Dali; using namespace Dali::Toolkit; namespace { - -const float START_ANGLE_INITIAL_VALUE( 0.0f ); -const float START_ANGLE_TARGET_VALUE( 360.0f ); -const float SWEEP_ANGLE_INITIAL_VALUE( 90.0f ); -const float SWEEP_ANGLE_TARGET_VALUE( 360.0f ); -const float ANIMATION_DURATION( 3.0f ); - -const Property::Value BACKGROUND -{ - { Visual::Property::TYPE, DevelVisual::ARC }, - { Visual::Property::MIX_COLOR, Color::RED }, - { DevelArcVisual::Property::START_ANGLE, 0.0f }, - { DevelArcVisual::Property::SWEEP_ANGLE, 90.0f }, - { DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND }, - { DevelArcVisual::Property::THICKNESS, 20.0f } -}; - -const Property::Value TEXT_BACKGROUND -{ - { Visual::Property::TYPE, Visual::COLOR }, - { ColorVisual::Property::MIX_COLOR, Vector4( 0.8f, 0.8f, 0.8f, 1.0f ) }, - { DevelVisual::Property::CORNER_RADIUS, 0.5f }, - { DevelVisual::Property::CORNER_RADIUS_POLICY, Toolkit::Visual::Transform::Policy::RELATIVE } -}; - -const Property::Value TRANSITION_ANIMATOR -{ - { "timePeriod", Property::Map().Add( "duration", ANIMATION_DURATION ) } -}; - -const Property::Value TRANSITION_START_ANGLE -{ - { "target", "background" }, - { "property", "startAngle" }, - { "initialValue", START_ANGLE_INITIAL_VALUE }, - { "targetValue", START_ANGLE_TARGET_VALUE }, - { "animator", TRANSITION_ANIMATOR } -}; - -const Property::Value TRANSITION_SWEEP_ANGLE -{ - { "target", "background" }, - { "property", "sweepAngle" }, - { "initialValue", SWEEP_ANGLE_INITIAL_VALUE }, - { "targetValue", SWEEP_ANGLE_TARGET_VALUE }, - { "animator", TRANSITION_ANIMATOR } -}; +const float START_ANGLE_INITIAL_VALUE(0.0f); +const float START_ANGLE_TARGET_VALUE(360.0f); +const float SWEEP_ANGLE_INITIAL_VALUE(90.0f); +const float SWEEP_ANGLE_TARGET_VALUE(360.0f); +const float ANIMATION_DURATION(3.0f); + +const Property::Value BACKGROUND{ + {Visual::Property::TYPE, DevelVisual::ARC}, + {Visual::Property::MIX_COLOR, Color::RED}, + {DevelArcVisual::Property::START_ANGLE, 0.0f}, + {DevelArcVisual::Property::SWEEP_ANGLE, 90.0f}, + {DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND}, + {DevelArcVisual::Property::THICKNESS, 20.0f}}; + +const Property::Value TEXT_BACKGROUND{ + {Visual::Property::TYPE, Visual::COLOR}, + {ColorVisual::Property::MIX_COLOR, Vector4(0.8f, 0.8f, 0.8f, 1.0f)}, + {DevelVisual::Property::CORNER_RADIUS, 0.5f}, + {DevelVisual::Property::CORNER_RADIUS_POLICY, Toolkit::Visual::Transform::Policy::RELATIVE}}; + +const Property::Value TRANSITION_ANIMATOR{ + {"timePeriod", Property::Map().Add("duration", ANIMATION_DURATION)}}; + +const Property::Value TRANSITION_START_ANGLE{ + {"target", "background"}, + {"property", "startAngle"}, + {"initialValue", START_ANGLE_INITIAL_VALUE}, + {"targetValue", START_ANGLE_TARGET_VALUE}, + {"animator", TRANSITION_ANIMATOR}}; + +const Property::Value TRANSITION_SWEEP_ANGLE{ + {"target", "background"}, + {"property", "sweepAngle"}, + {"initialValue", SWEEP_ANGLE_INITIAL_VALUE}, + {"targetValue", SWEEP_ANGLE_TARGET_VALUE}, + {"animator", TRANSITION_ANIMATOR}}; } // namespace @@ -83,155 +71,151 @@ const Property::Value TRANSITION_SWEEP_ANGLE class ArcVisualExample : public ConnectionTracker { public: - - ArcVisualExample( Application& application ) - : mApplication( application ), - mSelectedPoperty( DevelArcVisual::Property::START_ANGLE ) + ArcVisualExample(Application& application) + : mApplication(application), + mSelectedPoperty(DevelArcVisual::Property::START_ANGLE) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ArcVisualExample::Create ); + mApplication.InitSignal().Connect(this, &ArcVisualExample::Create); } ~ArcVisualExample() = default; private: - // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); mControl = Control::New(); - mControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mControl.SetProperty( Actor::Property::SIZE, Vector2( 300.0f, 300.0f ) ); - mControl.SetProperty( Control::Property::BACKGROUND, BACKGROUND ); - window.Add( mControl ); - - mStartAngleLabel = TextLabel::New( "1" ); - mStartAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mStartAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); - mStartAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( -30.0f, -10.0f ) ); - mStartAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); - mStartAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mStartAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mStartAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); - mStartAngleLabel.TouchedSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); - window.Add( mStartAngleLabel ); - - mSweepAngleLabel = TextLabel::New( "2" ); - mSweepAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mSweepAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mSweepAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, -10.0f ) ); - mSweepAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); - mSweepAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mSweepAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mSweepAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); - mSweepAngleLabel.TouchedSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); - window.Add( mSweepAngleLabel ); - - mThicknessLabel = TextLabel::New( "3" ); - mThicknessLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mThicknessLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); - mThicknessLabel.SetProperty( Actor::Property::POSITION, Vector2( 30.0f, -10.0f ) ); - mThicknessLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); - mThicknessLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mThicknessLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mThicknessLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); - mThicknessLabel.TouchedSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); - window.Add( mThicknessLabel ); - - mPlusTextLabel = TextLabel::New( "+" ); - mPlusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mPlusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mPlusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( 20.0f, 10.0f ) ); - mPlusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); - mPlusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mPlusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mPlusTextLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); - mPlusTextLabel.TouchedSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); - window.Add( mPlusTextLabel ); - - mMinusTextLabel = TextLabel::New( "-" ); - mMinusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mMinusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); - mMinusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( -20.0f, 10.0f ) ); - mMinusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); - mMinusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mMinusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); - mMinusTextLabel.SetProperty( Control::Property::PADDING, Extents( 25.0f, 25.0f, 10.0f, 10.0f ) ); - mMinusTextLabel.TouchedSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); - window.Add( mMinusTextLabel ); + mControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mControl.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f)); + mControl.SetProperty(Control::Property::BACKGROUND, BACKGROUND); + window.Add(mControl); + + mStartAngleLabel = TextLabel::New("1"); + mStartAngleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mStartAngleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mStartAngleLabel.SetProperty(Actor::Property::POSITION, Vector2(-30.0f, -10.0f)); + mStartAngleLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND); + mStartAngleLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mStartAngleLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mStartAngleLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f)); + mStartAngleLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch); + window.Add(mStartAngleLabel); + + mSweepAngleLabel = TextLabel::New("2"); + mSweepAngleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSweepAngleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mSweepAngleLabel.SetProperty(Actor::Property::POSITION, Vector2(0.0f, -10.0f)); + mSweepAngleLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND); + mSweepAngleLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mSweepAngleLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mSweepAngleLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f)); + mSweepAngleLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch); + window.Add(mSweepAngleLabel); + + mThicknessLabel = TextLabel::New("3"); + mThicknessLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mThicknessLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT); + mThicknessLabel.SetProperty(Actor::Property::POSITION, Vector2(30.0f, -10.0f)); + mThicknessLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND); + mThicknessLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mThicknessLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mThicknessLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f)); + mThicknessLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch); + window.Add(mThicknessLabel); + + mPlusTextLabel = TextLabel::New("+"); + mPlusTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mPlusTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mPlusTextLabel.SetProperty(Actor::Property::POSITION, Vector2(20.0f, 10.0f)); + mPlusTextLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND); + mPlusTextLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mPlusTextLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mPlusTextLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f)); + mPlusTextLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch); + window.Add(mPlusTextLabel); + + mMinusTextLabel = TextLabel::New("-"); + mMinusTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mMinusTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + mMinusTextLabel.SetProperty(Actor::Property::POSITION, Vector2(-20.0f, 10.0f)); + mMinusTextLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND); + mMinusTextLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mMinusTextLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + mMinusTextLabel.SetProperty(Control::Property::PADDING, Extents(25.0f, 25.0f, 10.0f, 10.0f)); + mMinusTextLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch); + window.Add(mMinusTextLabel); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &ArcVisualExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &ArcVisualExample::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &ArcVisualExample::OnKeyEvent); } - bool OnButtonTouch( Actor actor, const TouchEvent& touch ) + bool OnButtonTouch(Actor actor, const TouchEvent& touch) { - if( touch.GetState( 0 ) == PointState::UP ) + if(touch.GetState(0) == PointState::UP) { - Control control = Control::DownCast( actor ); - if( control == mStartAngleLabel ) + Control control = Control::DownCast(actor); + if(control == mStartAngleLabel) { mSelectedPoperty = DevelArcVisual::Property::START_ANGLE; } - else if( control == mSweepAngleLabel ) + else if(control == mSweepAngleLabel) { mSelectedPoperty = DevelArcVisual::Property::SWEEP_ANGLE; } - else if( control == mThicknessLabel ) + else if(control == mThicknessLabel) { mSelectedPoperty = DevelArcVisual::Property::THICKNESS; } - else if( control == mPlusTextLabel ) + else if(control == mPlusTextLabel) { - Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); - Property::Value* value = map.Find( mSelectedPoperty ); - if( value ) + Property::Map map = mControl.GetProperty(Control::Property::BACKGROUND); + Property::Value* value = map.Find(mSelectedPoperty); + if(value) { - DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, - Property::Map().Add( mSelectedPoperty, value->Get< float >() + 5.0f ) ); + DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get() + 5.0f)); } } else { - Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); - Property::Value* value = map.Find( mSelectedPoperty ); - if( value ) + Property::Map map = mControl.GetProperty(Control::Property::BACKGROUND); + Property::Value* value = map.Find(mSelectedPoperty); + if(value) { - DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, - Property::Map().Add( mSelectedPoperty, value->Get< float >() - 5.0f ) ); + DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get() - 5.0f)); } } } return true; } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - if( touch.GetState( 0 ) == PointState::UP ) + if(touch.GetState(0) == PointState::UP) { Property::Array array; - array.PushBack( TRANSITION_START_ANGLE ); - array.PushBack( TRANSITION_SWEEP_ANGLE ); + array.PushBack(TRANSITION_START_ANGLE); + array.PushBack(TRANSITION_SWEEP_ANGLE); - TransitionData transitionData = TransitionData::New( array ); - Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mControl ), transitionData ); + TransitionData transitionData = TransitionData::New(array); + Animation animation = DevelControl::CreateTransition(Toolkit::Internal::GetImplementation(mControl), transitionData); animation.Play(); } return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::UP ) + if(event.GetState() == KeyEvent::UP) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -239,20 +223,20 @@ private: } private: - Application& mApplication; - Control mControl; - TextLabel mStartAngleLabel; - TextLabel mSweepAngleLabel; - TextLabel mThicknessLabel; - TextLabel mPlusTextLabel; - TextLabel mMinusTextLabel; + Application& mApplication; + Control mControl; + TextLabel mStartAngleLabel; + TextLabel mSweepAngleLabel; + TextLabel mThicknessLabel; + TextLabel mPlusTextLabel; + TextLabel mMinusTextLabel; Property::Index mSelectedPoperty; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ArcVisualExample test( application ); + Application application = Application::New(&argc, &argv); + ArcVisualExample test(application); application.MainLoop(); return 0; } diff --git a/examples/benchmark/benchmark.cpp b/examples/benchmark/benchmark.cpp index b1d05d5..c437dc2 100644 --- a/examples/benchmark/benchmark.cpp +++ b/examples/benchmark/benchmark.cpp @@ -24,125 +24,124 @@ using namespace Dali; using namespace Dali::Toolkit; - namespace { const char* IMAGE_PATH[] = { - DEMO_IMAGE_DIR "gallery-medium-1.jpg", - DEMO_IMAGE_DIR "gallery-medium-2.jpg", - DEMO_IMAGE_DIR "gallery-medium-3.jpg", - DEMO_IMAGE_DIR "gallery-medium-4.jpg", - DEMO_IMAGE_DIR "gallery-medium-5.jpg", - DEMO_IMAGE_DIR "gallery-medium-6.jpg", - DEMO_IMAGE_DIR "gallery-medium-7.jpg", - DEMO_IMAGE_DIR "gallery-medium-8.jpg", - DEMO_IMAGE_DIR "gallery-medium-9.jpg", - DEMO_IMAGE_DIR "gallery-medium-10.jpg", - DEMO_IMAGE_DIR "gallery-medium-11.jpg", - DEMO_IMAGE_DIR "gallery-medium-12.jpg", - DEMO_IMAGE_DIR "gallery-medium-13.jpg", - DEMO_IMAGE_DIR "gallery-medium-14.jpg", - DEMO_IMAGE_DIR "gallery-medium-15.jpg", - DEMO_IMAGE_DIR "gallery-medium-16.jpg", - DEMO_IMAGE_DIR "gallery-medium-17.jpg", - DEMO_IMAGE_DIR "gallery-medium-18.jpg", - DEMO_IMAGE_DIR "gallery-medium-19.jpg", - DEMO_IMAGE_DIR "gallery-medium-20.jpg", - DEMO_IMAGE_DIR "gallery-medium-21.jpg", - DEMO_IMAGE_DIR "gallery-medium-22.jpg", - DEMO_IMAGE_DIR "gallery-medium-23.jpg", - DEMO_IMAGE_DIR "gallery-medium-24.jpg", - DEMO_IMAGE_DIR "gallery-medium-25.jpg", - DEMO_IMAGE_DIR "gallery-medium-26.jpg", - DEMO_IMAGE_DIR "gallery-medium-27.jpg", - DEMO_IMAGE_DIR "gallery-medium-28.jpg", - DEMO_IMAGE_DIR "gallery-medium-29.jpg", - DEMO_IMAGE_DIR "gallery-medium-30.jpg", - DEMO_IMAGE_DIR "gallery-medium-31.jpg", - DEMO_IMAGE_DIR "gallery-medium-32.jpg", - DEMO_IMAGE_DIR "gallery-medium-33.jpg", - DEMO_IMAGE_DIR "gallery-medium-34.jpg", - DEMO_IMAGE_DIR "gallery-medium-35.jpg", - DEMO_IMAGE_DIR "gallery-medium-36.jpg", - DEMO_IMAGE_DIR "gallery-medium-37.jpg", - DEMO_IMAGE_DIR "gallery-medium-38.jpg", - DEMO_IMAGE_DIR "gallery-medium-39.jpg", - DEMO_IMAGE_DIR "gallery-medium-40.jpg", - DEMO_IMAGE_DIR "gallery-medium-41.jpg", - DEMO_IMAGE_DIR "gallery-medium-42.jpg", - DEMO_IMAGE_DIR "gallery-medium-43.jpg", - DEMO_IMAGE_DIR "gallery-medium-44.jpg", - DEMO_IMAGE_DIR "gallery-medium-45.jpg", - DEMO_IMAGE_DIR "gallery-medium-46.jpg", - DEMO_IMAGE_DIR "gallery-medium-47.jpg", - DEMO_IMAGE_DIR "gallery-medium-48.jpg", - DEMO_IMAGE_DIR "gallery-medium-49.jpg", - DEMO_IMAGE_DIR "gallery-medium-50.jpg", - DEMO_IMAGE_DIR "gallery-medium-51.jpg", - DEMO_IMAGE_DIR "gallery-medium-52.jpg", - DEMO_IMAGE_DIR "gallery-medium-53.jpg", + DEMO_IMAGE_DIR "gallery-medium-1.jpg", + DEMO_IMAGE_DIR "gallery-medium-2.jpg", + DEMO_IMAGE_DIR "gallery-medium-3.jpg", + DEMO_IMAGE_DIR "gallery-medium-4.jpg", + DEMO_IMAGE_DIR "gallery-medium-5.jpg", + DEMO_IMAGE_DIR "gallery-medium-6.jpg", + DEMO_IMAGE_DIR "gallery-medium-7.jpg", + DEMO_IMAGE_DIR "gallery-medium-8.jpg", + DEMO_IMAGE_DIR "gallery-medium-9.jpg", + DEMO_IMAGE_DIR "gallery-medium-10.jpg", + DEMO_IMAGE_DIR "gallery-medium-11.jpg", + DEMO_IMAGE_DIR "gallery-medium-12.jpg", + DEMO_IMAGE_DIR "gallery-medium-13.jpg", + DEMO_IMAGE_DIR "gallery-medium-14.jpg", + DEMO_IMAGE_DIR "gallery-medium-15.jpg", + DEMO_IMAGE_DIR "gallery-medium-16.jpg", + DEMO_IMAGE_DIR "gallery-medium-17.jpg", + DEMO_IMAGE_DIR "gallery-medium-18.jpg", + DEMO_IMAGE_DIR "gallery-medium-19.jpg", + DEMO_IMAGE_DIR "gallery-medium-20.jpg", + DEMO_IMAGE_DIR "gallery-medium-21.jpg", + DEMO_IMAGE_DIR "gallery-medium-22.jpg", + DEMO_IMAGE_DIR "gallery-medium-23.jpg", + DEMO_IMAGE_DIR "gallery-medium-24.jpg", + DEMO_IMAGE_DIR "gallery-medium-25.jpg", + DEMO_IMAGE_DIR "gallery-medium-26.jpg", + DEMO_IMAGE_DIR "gallery-medium-27.jpg", + DEMO_IMAGE_DIR "gallery-medium-28.jpg", + DEMO_IMAGE_DIR "gallery-medium-29.jpg", + DEMO_IMAGE_DIR "gallery-medium-30.jpg", + DEMO_IMAGE_DIR "gallery-medium-31.jpg", + DEMO_IMAGE_DIR "gallery-medium-32.jpg", + DEMO_IMAGE_DIR "gallery-medium-33.jpg", + DEMO_IMAGE_DIR "gallery-medium-34.jpg", + DEMO_IMAGE_DIR "gallery-medium-35.jpg", + DEMO_IMAGE_DIR "gallery-medium-36.jpg", + DEMO_IMAGE_DIR "gallery-medium-37.jpg", + DEMO_IMAGE_DIR "gallery-medium-38.jpg", + DEMO_IMAGE_DIR "gallery-medium-39.jpg", + DEMO_IMAGE_DIR "gallery-medium-40.jpg", + DEMO_IMAGE_DIR "gallery-medium-41.jpg", + DEMO_IMAGE_DIR "gallery-medium-42.jpg", + DEMO_IMAGE_DIR "gallery-medium-43.jpg", + DEMO_IMAGE_DIR "gallery-medium-44.jpg", + DEMO_IMAGE_DIR "gallery-medium-45.jpg", + DEMO_IMAGE_DIR "gallery-medium-46.jpg", + DEMO_IMAGE_DIR "gallery-medium-47.jpg", + DEMO_IMAGE_DIR "gallery-medium-48.jpg", + DEMO_IMAGE_DIR "gallery-medium-49.jpg", + DEMO_IMAGE_DIR "gallery-medium-50.jpg", + DEMO_IMAGE_DIR "gallery-medium-51.jpg", + DEMO_IMAGE_DIR "gallery-medium-52.jpg", + DEMO_IMAGE_DIR "gallery-medium-53.jpg", }; const char* NINEPATCH_IMAGE_PATH[] = { - DEMO_IMAGE_DIR "selection-popup-bg.1.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.2.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.3.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.4.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.5.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.6.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.7.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.8.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.9.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.10.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.11.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.12.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.13.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.14.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.15.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.16.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.17.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.18.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.19.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.20.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.21.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.22.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.23.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.24.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.25.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.26.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.27.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.28.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.29.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.30.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.31.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.32.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.33.9.png", - DEMO_IMAGE_DIR "button-disabled.9.png", - DEMO_IMAGE_DIR "button-down.9.png", - DEMO_IMAGE_DIR "button-down-disabled.9.png", - DEMO_IMAGE_DIR "button-up-1.9.png", - DEMO_IMAGE_DIR "button-up-2.9.png", - DEMO_IMAGE_DIR "button-up-3.9.png", - DEMO_IMAGE_DIR "button-up-4.9.png", - DEMO_IMAGE_DIR "button-up-5.9.png", - DEMO_IMAGE_DIR "button-up-6.9.png", - DEMO_IMAGE_DIR "button-up-7.9.png", - DEMO_IMAGE_DIR "button-up-8.9.png", - DEMO_IMAGE_DIR "button-up-9.9.png", - DEMO_IMAGE_DIR "button-up-10.9.png", - DEMO_IMAGE_DIR "button-up-11.9.png", - DEMO_IMAGE_DIR "button-up-12.9.png", - DEMO_IMAGE_DIR "button-up-13.9.png", - DEMO_IMAGE_DIR "button-up-14.9.png", - DEMO_IMAGE_DIR "button-up-15.9.png", - DEMO_IMAGE_DIR "button-up-16.9.png", - DEMO_IMAGE_DIR "button-up-17.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.1.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.2.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.3.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.4.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.5.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.6.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.7.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.8.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.9.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.10.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.11.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.12.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.13.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.14.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.15.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.16.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.17.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.18.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.19.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.20.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.21.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.22.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.23.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.24.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.25.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.26.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.27.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.28.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.29.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.30.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.31.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.32.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.33.9.png", + DEMO_IMAGE_DIR "button-disabled.9.png", + DEMO_IMAGE_DIR "button-down.9.png", + DEMO_IMAGE_DIR "button-down-disabled.9.png", + DEMO_IMAGE_DIR "button-up-1.9.png", + DEMO_IMAGE_DIR "button-up-2.9.png", + DEMO_IMAGE_DIR "button-up-3.9.png", + DEMO_IMAGE_DIR "button-up-4.9.png", + DEMO_IMAGE_DIR "button-up-5.9.png", + DEMO_IMAGE_DIR "button-up-6.9.png", + DEMO_IMAGE_DIR "button-up-7.9.png", + DEMO_IMAGE_DIR "button-up-8.9.png", + DEMO_IMAGE_DIR "button-up-9.9.png", + DEMO_IMAGE_DIR "button-up-10.9.png", + DEMO_IMAGE_DIR "button-up-11.9.png", + DEMO_IMAGE_DIR "button-up-12.9.png", + DEMO_IMAGE_DIR "button-up-13.9.png", + DEMO_IMAGE_DIR "button-up-14.9.png", + DEMO_IMAGE_DIR "button-up-15.9.png", + DEMO_IMAGE_DIR "button-up-16.9.png", + DEMO_IMAGE_DIR "button-up-17.9.png", }; -const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); +const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); const unsigned int NUM_NINEPATCH_IMAGES = sizeof(NINEPATCH_IMAGE_PATH) / sizeof(char*); -const float ANIMATION_TIME ( 5.0f ); // animation length in seconds +const float ANIMATION_TIME(5.0f); // animation length in seconds struct VertexWithTexture { @@ -150,6 +149,7 @@ struct VertexWithTexture Vector2 texCoord; }; +// clang-format off const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n attribute mediump vec2 aTexCoord;\n @@ -174,26 +174,27 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n }\n ); +// clang-format on -bool gUseMesh(false); -bool gNinePatch(false); +bool gUseMesh(false); +bool gNinePatch(false); unsigned int gRowsPerPage(25); -unsigned int gColumnsPerPage( 25 ); +unsigned int gColumnsPerPage(25); unsigned int gPageCount(13); -Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) +Renderer CreateRenderer(unsigned int index, Geometry geometry, Shader shader) { - Renderer renderer = Renderer::New( geometry, shader ); - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; - Texture texture = DemoHelper::LoadTexture( imagePath ); - TextureSet textureSet = TextureSet::New(); - textureSet.SetTexture( 0u, texture ); - renderer.SetTextures( textureSet ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); + Renderer renderer = Renderer::New(geometry, shader); + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; + Texture texture = DemoHelper::LoadTexture(imagePath); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture(0u, texture); + renderer.SetTextures(textureSet); + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF); return renderer; } -} +} // namespace // Test application to compare performance between using a mesh and ImageView // By default, the application consist of 10 pages of 25x25 Image views, this can be modified using the following command line arguments: // -r NumberOfRows (Modifies the number of rows per page) @@ -206,38 +207,37 @@ Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) class Benchmark : public ConnectionTracker { public: - - Benchmark( Application& application ) - : mApplication( application ), - mRowsPerPage( gRowsPerPage ), - mColumnsPerPage( gColumnsPerPage ), - mPageCount( gPageCount ) + Benchmark(Application& application) + : mApplication(application), + mRowsPerPage(gRowsPerPage), + mColumnsPerPage(gColumnsPerPage), + mPageCount(gPageCount) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &Benchmark::Create ); + mApplication.InitSignal().Connect(this, &Benchmark::Create); } ~Benchmark() = default; // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); Vector2 windowSize = window.GetSize(); - window.GetRootLayer().SetProperty( Layer::Property::DEPTH_TEST, false ); + window.GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, false); - mSize = Vector3( windowSize.x / mColumnsPerPage, windowSize.y / mRowsPerPage, 0.0f ); + mSize = Vector3(windowSize.x / mColumnsPerPage, windowSize.y / mRowsPerPage, 0.0f); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &Benchmark::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &Benchmark::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &Benchmark::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &Benchmark::OnKeyEvent); - if( gUseMesh ) + if(gUseMesh) { CreateMeshActors(); } @@ -249,29 +249,29 @@ public: ShowAnimation(); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); return true; } - const char* ImagePath( int i ) + const char* ImagePath(int i) { return !gNinePatch ? IMAGE_PATH[i % NUM_IMAGES] : NINEPATCH_IMAGE_PATH[i % NUM_NINEPATCH_IMAGES]; } void CreateImageViews() { - Window window = mApplication.GetWindow(); - unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount); + Window window = mApplication.GetWindow(); + unsigned int actorCount(mRowsPerPage * mColumnsPerPage * mPageCount); mImageView.resize(actorCount); - for( size_t i(0); i renderers( numImages ); - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); - Geometry geometry = DemoHelper::CreateTexturedQuad(); - for( unsigned int i(0); i renderers(numImages); + Shader shader = Shader::New(VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE); + Geometry geometry = DemoHelper::CreateTexturedQuad(); + for(unsigned int i(0); i < numImages; ++i) { - renderers[i] = CreateRenderer( i, geometry, shader ); + renderers[i] = CreateRenderer(i, geometry, shader); } //Create the actors - Window window = mApplication.GetWindow(); - unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount); + Window window = mApplication.GetWindow(); + unsigned int actorCount(mRowsPerPage * mColumnsPerPage * mPageCount); mActor.resize(actorCount); - for( size_t i(0); i( mRowsPerPage ) * mColumnsPerPage ) ) + if(count < (static_cast(mRowsPerPage) * mColumnsPerPage)) { duration = durationPerActor; - delay = delayBetweenActors * count; + delay = delayBetweenActors * count; } - if( gUseMesh ) + if(gUseMesh) { - mActor[count].SetProperty( Actor::Property::POSITION, initialPosition ); - mActor[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) ); - mActor[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian(0.0f),Vector3::XAXIS) ); - mShow.AnimateTo( Property( mActor[count], Actor::Property::POSITION), Vector3(xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); - mShow.AnimateTo( Property( mActor[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); + mActor[count].SetProperty(Actor::Property::POSITION, initialPosition); + mActor[count].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); + mActor[count].SetProperty(Actor::Property::ORIENTATION, Quaternion(Radian(0.0f), Vector3::XAXIS)); + mShow.AnimateTo(Property(mActor[count], Actor::Property::POSITION), Vector3(xpos + mSize.x * 0.5f, ypos + mSize.y * 0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); + mShow.AnimateTo(Property(mActor[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); } else { - mImageView[count].SetProperty( Actor::Property::POSITION, initialPosition ); - mImageView[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) ); - mImageView[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian(0.0f),Vector3::XAXIS) ); - mShow.AnimateTo( Property( mImageView[count], Actor::Property::POSITION), Vector3(xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); - mShow.AnimateTo( Property( mImageView[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); + mImageView[count].SetProperty(Actor::Property::POSITION, initialPosition); + mImageView[count].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); + mImageView[count].SetProperty(Actor::Property::ORIENTATION, Quaternion(Radian(0.0f), Vector3::XAXIS)); + mShow.AnimateTo(Property(mImageView[count], Actor::Property::POSITION), Vector3(xpos + mSize.x * 0.5f, ypos + mSize.y * 0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); + mShow.AnimateTo(Property(mImageView[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); } ++count; } } mShow.Play(); - mShow.FinishedSignal().Connect( this, &Benchmark::OnAnimationEnd ); + mShow.FinishedSignal().Connect(this, &Benchmark::OnAnimationEnd); } void ScrollAnimation() { - Window window = mApplication.GetWindow(); - Vector3 windowSize( window.GetSize() ); + Window window = mApplication.GetWindow(); + Vector3 windowSize(window.GetSize()); mScroll = Animation::New(10.0f); - size_t actorCount( static_cast< size_t >( mRowsPerPage ) * mColumnsPerPage * mPageCount ); - for( size_t i(0); i(mRowsPerPage) * mColumnsPerPage * mPageCount); + for(size_t i(0); i < actorCount; ++i) { - if( gUseMesh ) + if(gUseMesh) { - mScroll.AnimateBy( Property( mActor[i], Actor::Property::POSITION), Vector3(-4.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(0.0f,3.0f)); - mScroll.AnimateBy( Property( mActor[i], Actor::Property::POSITION), Vector3(-4.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(3.0f,3.0f)); - mScroll.AnimateBy( Property( mActor[i], Actor::Property::POSITION), Vector3(-4.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(6.0f,2.0f)); - mScroll.AnimateBy( Property( mActor[i], Actor::Property::POSITION), Vector3( 12.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(8.0f,2.0f)); + mScroll.AnimateBy(Property(mActor[i], Actor::Property::POSITION), Vector3(-4.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(0.0f, 3.0f)); + mScroll.AnimateBy(Property(mActor[i], Actor::Property::POSITION), Vector3(-4.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(3.0f, 3.0f)); + mScroll.AnimateBy(Property(mActor[i], Actor::Property::POSITION), Vector3(-4.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(6.0f, 2.0f)); + mScroll.AnimateBy(Property(mActor[i], Actor::Property::POSITION), Vector3(12.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(8.0f, 2.0f)); } else { - mScroll.AnimateBy( Property( mImageView[i], Actor::Property::POSITION), Vector3(-4.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(0.0f,3.0f)); - mScroll.AnimateBy( Property( mImageView[i], Actor::Property::POSITION), Vector3(-4.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(3.0f,3.0f)); - mScroll.AnimateBy( Property( mImageView[i], Actor::Property::POSITION), Vector3(-4.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(6.0f,2.0f)); - mScroll.AnimateBy( Property( mImageView[i], Actor::Property::POSITION), Vector3( 12.0f*windowSize.x,0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(8.0f,2.0f)); + mScroll.AnimateBy(Property(mImageView[i], Actor::Property::POSITION), Vector3(-4.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(0.0f, 3.0f)); + mScroll.AnimateBy(Property(mImageView[i], Actor::Property::POSITION), Vector3(-4.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(3.0f, 3.0f)); + mScroll.AnimateBy(Property(mImageView[i], Actor::Property::POSITION), Vector3(-4.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(6.0f, 2.0f)); + mScroll.AnimateBy(Property(mImageView[i], Actor::Property::POSITION), Vector3(12.0f * windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_OUT, TimePeriod(8.0f, 2.0f)); } } mScroll.Play(); - mScroll.FinishedSignal().Connect( this, &Benchmark::OnAnimationEnd ); + mScroll.FinishedSignal().Connect(this, &Benchmark::OnAnimationEnd); } void HideAnimation() { - size_t count(0); - unsigned int actorsPerPage( mRowsPerPage*mColumnsPerPage ); + size_t count(0); + unsigned int actorsPerPage(mRowsPerPage * mColumnsPerPage); mHide = Animation::New(0.0f); unsigned int totalColumns = mColumnsPerPage * mPageCount; - float finalZ = mApplication.GetWindow().GetRenderTaskList().GetTask(0).GetCameraActor().GetCurrentProperty< Vector3 >( Actor::Property::WORLD_POSITION ).z; - float totalDuration( 5.0f); - float durationPerActor( 0.5f ); - float delayBetweenActors = ( totalDuration - durationPerActor) / (mRowsPerPage*mColumnsPerPage); - for( size_t i(0); i(Actor::Property::WORLD_POSITION).z; + float totalDuration(5.0f); + float durationPerActor(0.5f); + float delayBetweenActors = (totalDuration - durationPerActor) / (mRowsPerPage * mColumnsPerPage); + for(size_t i(0); i < mRowsPerPage; ++i) { - for( size_t j(0);j mActor; - std::vector mImageView; + std::vector mActor; + std::vector mImageView; - Vector3 mSize; - unsigned int mRowsPerPage; - unsigned int mColumnsPerPage; - unsigned int mPageCount; + Vector3 mSize; + unsigned int mRowsPerPage; + unsigned int mColumnsPerPage; + unsigned int mPageCount; - Animation mShow; - Animation mScroll; - Animation mHide; + Animation mShow; + Animation mScroll; + Animation mHide; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - for( int i(1) ; i < argc; ++i ) + for(int i(1); i < argc; ++i) { - std::string arg( argv[i] ); - if( arg.compare("--use-mesh") == 0) + std::string arg(argv[i]); + if(arg.compare("--use-mesh") == 0) { gUseMesh = true; } - else if( arg.compare("--nine-patch" ) == 0) + else if(arg.compare("--nine-patch") == 0) { gNinePatch = true; } - else if( arg.compare(0, 2, "-r" ) == 0) + else if(arg.compare(0, 2, "-r") == 0) { - gRowsPerPage = atoi( arg.substr( 2, arg.size()).c_str()); + gRowsPerPage = atoi(arg.substr(2, arg.size()).c_str()); } - else if( arg.compare(0, 2, "-c" ) == 0) + else if(arg.compare(0, 2, "-c") == 0) { - gColumnsPerPage = atoi( arg.substr( 2, arg.size()).c_str()); + gColumnsPerPage = atoi(arg.substr(2, arg.size()).c_str()); } - else if( arg.compare(0, 2, "-p" ) == 0) + else if(arg.compare(0, 2, "-p") == 0) { - gPageCount = atoi( arg.substr( 2, arg.size()).c_str()); + gPageCount = atoi(arg.substr(2, arg.size()).c_str()); } } - Benchmark test( application ); + Benchmark test(application); application.MainLoop(); return 0; diff --git a/examples/bezier-curve/bezier-curve-example.cpp b/examples/bezier-curve/bezier-curve-example.cpp index 07eb159..b8765c3 100644 --- a/examples/bezier-curve/bezier-curve-example.cpp +++ b/examples/bezier-curve/bezier-curve-example.cpp @@ -15,9 +15,9 @@ * */ -#include #include #include +#include #include "shared/view.h" #include @@ -28,21 +28,21 @@ using namespace std; namespace { - -const Vector4 GRID_BACKGROUND_COLOR(0.85f, 0.85f, 0.85f, 1.0f); -const Vector4 CONTROL_POINT1_COLOR(Color::MAGENTA); -const Vector4 CONTROL_POINT2_COLOR(0.0, 0.9, 0.9, 1.0); -const Vector3 CONTROL_POINT1_ORIGIN(-100, 200, 0); -const Vector3 CONTROL_POINT2_ORIGIN( 100, -200, 0); -const char* const CIRCLE1_IMAGE( DEMO_IMAGE_DIR "circle1.png" ); -const char* const CIRCLE2_IMAGE( DEMO_IMAGE_DIR "circle2.png" ); -const char* const ANIMATION_BACKGROUND( DEMO_IMAGE_DIR "slider-skin.9.png" ); -const char* APPLICATION_TITLE("Bezier curve animation"); -const float ANIM_LEFT_FACTOR(0.2f); -const float ANIM_RIGHT_FACTOR(0.8f); -const int AXIS_LABEL_POINT_SIZE(7); -const float AXIS_LINE_SIZE(1.0f); - +const Vector4 GRID_BACKGROUND_COLOR(0.85f, 0.85f, 0.85f, 1.0f); +const Vector4 CONTROL_POINT1_COLOR(Color::MAGENTA); +const Vector4 CONTROL_POINT2_COLOR(0.0, 0.9, 0.9, 1.0); +const Vector3 CONTROL_POINT1_ORIGIN(-100, 200, 0); +const Vector3 CONTROL_POINT2_ORIGIN(100, -200, 0); +const char* const CIRCLE1_IMAGE(DEMO_IMAGE_DIR "circle1.png"); +const char* const CIRCLE2_IMAGE(DEMO_IMAGE_DIR "circle2.png"); +const char* const ANIMATION_BACKGROUND(DEMO_IMAGE_DIR "slider-skin.9.png"); +const char* APPLICATION_TITLE("Bezier curve animation"); +const float ANIM_LEFT_FACTOR(0.2f); +const float ANIM_RIGHT_FACTOR(0.8f); +const int AXIS_LABEL_POINT_SIZE(7); +const float AXIS_LINE_SIZE(1.0f); + +// clang-format off const char* CURVE_VERTEX_SHADER = DALI_COMPOSE_SHADER ( attribute mediump vec2 aPosition; @@ -62,27 +62,30 @@ const char* CURVE_FRAGMENT_SHADER = DALI_COMPOSE_SHADER gl_FragColor = vec4(0.0,0.0,0.0,1.0); } ); - +// clang-format on inline float Clamp(float v, float min, float max) { - if(vmax) return max; + if(v < min) return min; + if(v > max) return max; return v; } struct HandlePositionConstraint { - HandlePositionConstraint( float minRelX, float maxRelX, float minRelY, float maxRelY ) - : minRelX(minRelX), maxRelX(maxRelX), minRelY(minRelY), maxRelY(maxRelY) + HandlePositionConstraint(float minRelX, float maxRelX, float minRelY, float maxRelY) + : minRelX(minRelX), + maxRelX(maxRelX), + minRelY(minRelY), + maxRelY(maxRelY) { } - void operator()( Vector3& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs) { - Vector3 size( inputs[0]->GetVector3() ); - current.x = Clamp(current.x, minRelX*size.x, maxRelX*size.x ); - current.y = Clamp(current.y, minRelY*size.y, maxRelY*size.y ); + Vector3 size(inputs[0]->GetVector3()); + current.x = Clamp(current.x, minRelX * size.x, maxRelX * size.x); + current.y = Clamp(current.y, minRelY * size.y, maxRelY * size.y); } float minRelX; @@ -91,24 +94,21 @@ struct HandlePositionConstraint float maxRelY; }; -void AnimatingPositionConstraint( Vector3& current, const PropertyInputContainer& inputs ) +void AnimatingPositionConstraint(Vector3& current, const PropertyInputContainer& inputs) { - float positionFactor( inputs[0]->GetFloat() ); // -1 - 2 - Vector3 size( inputs[1]->GetVector3() ); + float positionFactor(inputs[0]->GetFloat()); // -1 - 2 + Vector3 size(inputs[1]->GetVector3()); - current.x = size.x * (positionFactor-0.5f); // size * (-1.5 - 1.5) + current.x = size.x * (positionFactor - 0.5f); // size * (-1.5 - 1.5) } } //unnamed namespace - - class BezierCurveExample : public ConnectionTracker { public: - - BezierCurveExample( Application& application ) - : mApplication( application ), + BezierCurveExample(Application& application) + : mApplication(application), mControlPoint1(), mControlPoint2(), mControlLine1(), @@ -130,15 +130,15 @@ public: mLastControlPointPosition1(), mLastControlPointPosition2(), mPositionFactorIndex(), - mDuration( 2.0f ), - mControlPoint1Id( 0.0f ), - mControlPoint2Id( 0.0f ), - mControlPointScale( 0.5f ), - mControlPointZoomScale( mControlPointScale * 2.0 ), - mGoingRight( true ) + mDuration(2.0f), + mControlPoint1Id(0.0f), + mControlPoint2Id(0.0f), + mControlPointScale(0.5f), + mControlPointZoomScale(mControlPointScale * 2.0), + mGoingRight(true) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &BezierCurveExample::Create ); + mApplication.InitSignal().Connect(this, &BezierCurveExample::Create); } ~BezierCurveExample() @@ -147,125 +147,123 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { Window window = mApplication.GetWindow(); - window.KeyEventSignal().Connect( this, &BezierCurveExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &BezierCurveExample::OnKeyEvent); CreateBackground(window); - mControlPointScale = 0.5f; + mControlPointScale = 0.5f; mControlPointZoomScale = mControlPointScale * 2.0f; mContentLayer = Layer::New(); - mContentLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mContentLayer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); mContentLayer.TouchedSignal().Connect(this, &BezierCurveExample::OnTouchLayer); - mContentLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - window.Add( mContentLayer ); + mContentLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + window.Add(mContentLayer); // 6 rows: title, grid, coords, play, anim1, anim2 TableView contentLayout = TableView::New(5, 1); - contentLayout.SetProperty( Dali::Actor::Property::NAME,"contentLayout"); - contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - contentLayout.SetCellPadding( Size( 30, 30 ) ); - contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_CENTER); - contentLayout.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); - mContentLayer.Add( contentLayout ); + contentLayout.SetProperty(Dali::Actor::Property::NAME, "contentLayout"); + contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + contentLayout.SetCellPadding(Size(30, 30)); + contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mContentLayer.Add(contentLayout); // Create a TextLabel for the application title. - Toolkit::TextLabel label = Toolkit::TextLabel::New( APPLICATION_TITLE ); - label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK ); - contentLayout.Add( label ); + Toolkit::TextLabel label = Toolkit::TextLabel::New(APPLICATION_TITLE); + label.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + label.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLACK); + contentLayout.Add(label); contentLayout.SetFitHeight(0); mGrid = Control::New(); - mGrid.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); - mGrid.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); + mGrid.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH); + mGrid.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); - mGrid.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mGrid.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + mGrid.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mGrid.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); mGrid.SetBackgroundColor(GRID_BACKGROUND_COLOR); - contentLayout.Add( mGrid ); - contentLayout.SetCellAlignment(1, HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + contentLayout.Add(mGrid); + contentLayout.SetCellAlignment(1, HorizontalAlignment::CENTER, VerticalAlignment::CENTER); CreateCubic(mGrid); - CreateControlPoints( mGrid ); // Control points constrained to double height of grid - CreateAxisLabels( mGrid ); + CreateControlPoints(mGrid); // Control points constrained to double height of grid + CreateAxisLabels(mGrid); mCoefficientLabel = TextLabel::New(); - mCoefficientLabel.SetProperty( TextLabel::Property::ENABLE_MARKUP, true ); - mCoefficientLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mCoefficientLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mCoefficientLabel.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - - contentLayout.Add( mCoefficientLabel ); - SetLabel( Vector2(0,0), Vector2(1,1)); - contentLayout.SetCellAlignment(2, HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + mCoefficientLabel.SetProperty(TextLabel::Property::ENABLE_MARKUP, true); + mCoefficientLabel.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mCoefficientLabel.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mCoefficientLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + + contentLayout.Add(mCoefficientLabel); + SetLabel(Vector2(0, 0), Vector2(1, 1)); + contentLayout.SetCellAlignment(2, HorizontalAlignment::CENTER, VerticalAlignment::CENTER); contentLayout.SetFitHeight(2); // Setup Play button and 2 icons to show off current anim and linear anim PushButton play = PushButton::New(); - play.SetProperty( Dali::Actor::Property::NAME,"Play"); - play.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - play.SetProperty( Button::Property::LABEL, "Play"); - play.ClickedSignal().Connect( this, &BezierCurveExample::OnPlayClicked ); + play.SetProperty(Dali::Actor::Property::NAME, "Play"); + play.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + play.SetProperty(Button::Property::LABEL, "Play"); + play.ClickedSignal().Connect(this, &BezierCurveExample::OnPlayClicked); - contentLayout.Add( play ); - contentLayout.SetCellAlignment(3, HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + contentLayout.Add(play); + contentLayout.SetCellAlignment(3, HorizontalAlignment::CENTER, VerticalAlignment::CENTER); contentLayout.SetFitHeight(3); auto animContainer = Control::New(); - animContainer.SetProperty( Dali::Actor::Property::NAME,"AnimationContainer"); - animContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - animContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + animContainer.SetProperty(Dali::Actor::Property::NAME, "AnimationContainer"); + animContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + animContainer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); auto animRail = Control::New(); - animRail.SetProperty( Control::Property::BACKGROUND, Property::Map() - .Add( Visual::Property::TYPE, Visual::IMAGE ) - .Add( ImageVisual::Property::URL, ANIMATION_BACKGROUND ) ); - animRail.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - animRail.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.666f, 0.2f, 1.0f ) ); - animRail.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - animContainer.Add( animRail ); + animRail.SetProperty(Control::Property::BACKGROUND, Property::Map().Add(Visual::Property::TYPE, Visual::IMAGE).Add(ImageVisual::Property::URL, ANIMATION_BACKGROUND)); + animRail.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + animRail.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.666f, 0.2f, 1.0f)); + animRail.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + animContainer.Add(animRail); - contentLayout.Add( animContainer ); - contentLayout.SetFixedHeight(4, 150 ); + contentLayout.Add(animContainer); + contentLayout.SetFixedHeight(4, 150); - mAnimIcon1 = ImageView::New( CIRCLE1_IMAGE ); - mAnimIcon1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mAnimIcon1.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mAnimIcon1 = ImageView::New(CIRCLE1_IMAGE); + mAnimIcon1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mAnimIcon1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); // Would like some means of setting and animating position as a percentage of // parent size without using constraints, but this will have to suffice for the moment. - mPositionFactorIndex = mAnimIcon1.RegisterProperty( "positionFactor", ANIM_LEFT_FACTOR); // range: 0-1 (+/- 1) - Constraint constraint = Constraint::New( mAnimIcon1, Actor::Property::POSITION, AnimatingPositionConstraint ); - constraint.AddSource( Source( mAnimIcon1, mPositionFactorIndex ) ); - constraint.AddSource( Source( animContainer, Actor::Property::SIZE ) ); + mPositionFactorIndex = mAnimIcon1.RegisterProperty("positionFactor", ANIM_LEFT_FACTOR); // range: 0-1 (+/- 1) + Constraint constraint = Constraint::New(mAnimIcon1, Actor::Property::POSITION, AnimatingPositionConstraint); + constraint.AddSource(Source(mAnimIcon1, mPositionFactorIndex)); + constraint.AddSource(Source(animContainer, Actor::Property::SIZE)); constraint.Apply(); - animContainer.Add( mAnimIcon1 ); + animContainer.Add(mAnimIcon1); // First UpdateCurve needs to run after size negotiation and after images have loaded - mGrid.OnRelayoutSignal().Connect( this, &BezierCurveExample::InitialUpdateCurve ); + mGrid.OnRelayoutSignal().Connect(this, &BezierCurveExample::InitialUpdateCurve); - auto controlPoint1 = Control::DownCast( mControlPoint1 ); - if( controlPoint1 ) + auto controlPoint1 = Control::DownCast(mControlPoint1); + if(controlPoint1) { - controlPoint1.ResourceReadySignal().Connect( this, &BezierCurveExample::ControlPointReady ); + controlPoint1.ResourceReadySignal().Connect(this, &BezierCurveExample::ControlPointReady); } - auto controlPoint2 = Control::DownCast( mControlPoint2 ); - if( controlPoint2 ) + auto controlPoint2 = Control::DownCast(mControlPoint2); + if(controlPoint2) { - controlPoint2.ResourceReadySignal().Connect( this, &BezierCurveExample::ControlPointReady ); + controlPoint2.ResourceReadySignal().Connect(this, &BezierCurveExample::ControlPointReady); } } - void ControlPointReady( Control control ) + void ControlPointReady(Control control) { UpdateCurve(); } @@ -275,138 +273,138 @@ public: UpdateCurve(); } - void CreateBackground( Window window ) + void CreateBackground(Window window) { Toolkit::Control background = Dali::Toolkit::Control::New(); - background.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - background.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - background.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); + background.SetProperty(Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + background.SetProperty(Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + background.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); Property::Map map; - map.Insert( Visual::Property::TYPE, Visual::COLOR ); - map.Insert( ColorVisual::Property::MIX_COLOR, Vector4( 253/255.0f, 245/255.0f, 230/255.0f, 1.0f ) ); - background.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map ); - window.Add( background ); + map.Insert(Visual::Property::TYPE, Visual::COLOR); + map.Insert(ColorVisual::Property::MIX_COLOR, Vector4(253 / 255.0f, 245 / 255.0f, 230 / 255.0f, 1.0f)); + background.SetProperty(Dali::Toolkit::Control::Property::BACKGROUND, map); + window.Add(background); } void CreateCubic(Actor parent) { // Create a mesh to draw the cubic as a single line mCurve = Actor::New(); - mCurve.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mCurve.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mCurve.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mCurve.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - Shader shader = Shader::New( CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER ); + Shader shader = Shader::New(CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER); Property::Map curveVertexFormat; curveVertexFormat["aPosition"] = Property::VECTOR2; - mCurveVertices = VertexBuffer::New( curveVertexFormat ); - Vector2 vertexData[2] = { Vector2(-0.5f, 0.5f), Vector2( 0.5f, -0.5f ) }; - mCurveVertices.SetData( vertexData, 2 ); + mCurveVertices = VertexBuffer::New(curveVertexFormat); + Vector2 vertexData[2] = {Vector2(-0.5f, 0.5f), Vector2(0.5f, -0.5f)}; + mCurveVertices.SetData(vertexData, 2); Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( mCurveVertices ); - geometry.SetType( Geometry::LINE_STRIP ); + geometry.AddVertexBuffer(mCurveVertices); + geometry.SetType(Geometry::LINE_STRIP); - Renderer renderer = Renderer::New( geometry, shader ); - mCurve.AddRenderer( renderer ); + Renderer renderer = Renderer::New(geometry, shader); + mCurve.AddRenderer(renderer); parent.Add(mCurve); } - Actor CreateControlPoint( Actor parent, const char* url, Vector3 position) + Actor CreateControlPoint(Actor parent, const char* url, Vector3 position) { - Actor actor = ImageView::New( url ); - actor.SetProperty( Actor::Property::SCALE, mControlPointScale); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + Actor actor = ImageView::New(url); + actor.SetProperty(Actor::Property::SCALE, mControlPointScale); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); // Curve and line drawing works off current value (i.e. last update frame's value). Need to animate to ensure // initial position is baked to both frames before initially drawing the curve. - auto positionAnimation = Animation::New( 0.01f ); - positionAnimation.AnimateTo( Property( actor, Actor::Property::POSITION ), position, AlphaFunction::EASE_IN_OUT ); + auto positionAnimation = Animation::New(0.01f); + positionAnimation.AnimateTo(Property(actor, Actor::Property::POSITION), position, AlphaFunction::EASE_IN_OUT); positionAnimation.Play(); - positionAnimation.FinishedSignal().Connect( this, &BezierCurveExample::OnAnimationFinished ); + positionAnimation.FinishedSignal().Connect(this, &BezierCurveExample::OnAnimationFinished); // Set up constraints for drag/drop - Constraint constraint = Constraint::New( actor, Actor::Property::POSITION, HandlePositionConstraint( -0.5, 0.5, -1, 1)); - constraint.AddSource( Source( parent, Actor::Property::SIZE ) ); + Constraint constraint = Constraint::New(actor, Actor::Property::POSITION, HandlePositionConstraint(-0.5, 0.5, -1, 1)); + constraint.AddSource(Source(parent, Actor::Property::SIZE)); constraint.Apply(); actor.TouchedSignal().Connect(this, &BezierCurveExample::OnTouchControlPoint); return actor; } - Actor CreateControlLine( VertexBuffer vertexBuffer ) + Actor CreateControlLine(VertexBuffer vertexBuffer) { Actor line = Actor::New(); - line.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - line.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + line.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + line.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - Shader shader = Shader::New( CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER ); + Shader shader = Shader::New(CURVE_VERTEX_SHADER, CURVE_FRAGMENT_SHADER); Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::LINE_STRIP ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::LINE_STRIP); - Renderer renderer = Renderer::New( geometry, shader ); - line.AddRenderer( renderer ); + Renderer renderer = Renderer::New(geometry, shader); + line.AddRenderer(renderer); return line; } - void CreateControlPoints( Actor parent ) + void CreateControlPoints(Actor parent) { - mControlPoint1 = CreateControlPoint( parent, - CIRCLE1_IMAGE, - CONTROL_POINT1_ORIGIN ); - mControlPoint1Id = mControlPoint1.GetProperty< int >( Actor::Property::ID ); + mControlPoint1 = CreateControlPoint(parent, + CIRCLE1_IMAGE, + CONTROL_POINT1_ORIGIN); + mControlPoint1Id = mControlPoint1.GetProperty(Actor::Property::ID); - mControlPoint2 = CreateControlPoint( parent, - CIRCLE2_IMAGE, - CONTROL_POINT2_ORIGIN ); - mControlPoint2Id = mControlPoint2.GetProperty< int >( Actor::Property::ID ); + mControlPoint2 = CreateControlPoint(parent, + CIRCLE2_IMAGE, + CONTROL_POINT2_ORIGIN); + mControlPoint2Id = mControlPoint2.GetProperty(Actor::Property::ID); Property::Map lineVertexFormat; lineVertexFormat["aPosition"] = Property::VECTOR2; - mLine1Vertices = VertexBuffer::New( lineVertexFormat ); - mLine2Vertices = VertexBuffer::New( lineVertexFormat ); + mLine1Vertices = VertexBuffer::New(lineVertexFormat); + mLine2Vertices = VertexBuffer::New(lineVertexFormat); - mControlLine1 = CreateControlLine( mLine1Vertices ); - mControlLine2 = CreateControlLine( mLine2Vertices ); + mControlLine1 = CreateControlLine(mLine1Vertices); + mControlLine2 = CreateControlLine(mLine2Vertices); - parent.Add( mControlLine1 ); - parent.Add( mControlLine2 ); - parent.Add( mControlPoint1 ); - parent.Add( mControlPoint2 ); + parent.Add(mControlLine1); + parent.Add(mControlLine2); + parent.Add(mControlPoint1); + parent.Add(mControlPoint2); } - void CreateAxisLabels( Actor parent ) + void CreateAxisLabels(Actor parent) { - TextLabel progressionLabel = TextLabel::New( "Progression" ); - progressionLabel.SetProperty( TextLabel::Property::POINT_SIZE, AXIS_LABEL_POINT_SIZE ); - progressionLabel.SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian( Degree(-90.0f) ), Vector3::ZAXIS ) ); - progressionLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); - progressionLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); - CreateLine( progressionLabel, ParentOrigin::BOTTOM_LEFT ); - - TextLabel timeLabel = TextLabel::New( "Time" ); - timeLabel.SetProperty( TextLabel::Property::POINT_SIZE, AXIS_LABEL_POINT_SIZE ); - timeLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - timeLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); - CreateLine( timeLabel, ParentOrigin::TOP_LEFT ); - - parent.Add( progressionLabel ); - parent.Add( timeLabel ); + TextLabel progressionLabel = TextLabel::New("Progression"); + progressionLabel.SetProperty(TextLabel::Property::POINT_SIZE, AXIS_LABEL_POINT_SIZE); + progressionLabel.SetProperty(Actor::Property::ORIENTATION, Quaternion(Radian(Degree(-90.0f)), Vector3::ZAXIS)); + progressionLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT); + progressionLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + CreateLine(progressionLabel, ParentOrigin::BOTTOM_LEFT); + + TextLabel timeLabel = TextLabel::New("Time"); + timeLabel.SetProperty(TextLabel::Property::POINT_SIZE, AXIS_LABEL_POINT_SIZE); + timeLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + timeLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + CreateLine(timeLabel, ParentOrigin::TOP_LEFT); + + parent.Add(progressionLabel); + parent.Add(timeLabel); } - void CreateLine( Actor parent, const Vector3& parentOrigin ) + void CreateLine(Actor parent, const Vector3& parentOrigin) { Control control = Control::New(); - control.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - control.SetProperty( Actor::Property::PARENT_ORIGIN, parentOrigin ); - control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - control.SetProperty( Actor::Property::SIZE_HEIGHT, AXIS_LINE_SIZE ); - control.SetBackgroundColor( Color::BLACK ); - parent.Add( control ); + control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + control.SetProperty(Actor::Property::PARENT_ORIGIN, parentOrigin); + control.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + control.SetProperty(Actor::Property::SIZE_HEIGHT, AXIS_LINE_SIZE); + control.SetBackgroundColor(Color::BLACK); + parent.Add(control); } - void SetLabel( Vector2 pos1, Vector2 pos2 ) + void SetLabel(Vector2 pos1, Vector2 pos2) { std::ostringstream oss; oss.setf(std::ios::fixed, std::ios::floatfield); @@ -415,22 +413,22 @@ public: oss << "" << pos2.x << ", " << pos2.y << ""; oss << " )"; - mCoefficientLabel.SetProperty( TextLabel::Property::TEXT, oss.str() ); + mCoefficientLabel.SetProperty(TextLabel::Property::TEXT, oss.str()); } - Vector2 AlignToGrid( Vector3 actorPos, Vector3 gridSize ) + Vector2 AlignToGrid(Vector3 actorPos, Vector3 gridSize) { actorPos /= gridSize; // => -0.5 - 0.5 - actorPos.x = Clamp( actorPos.x, -0.5f, 0.5f ); - return Vector2( actorPos.x + 0.5f, 0.5f - actorPos.y ); + actorPos.x = Clamp(actorPos.x, -0.5f, 0.5f); + return Vector2(actorPos.x + 0.5f, 0.5f - actorPos.y); } void GetControlPoints(Vector2& pt1, Vector2& pt2) { - Vector3 gridSize = mGrid.GetProperty( Actor::Property::SIZE ); // Get target value + Vector3 gridSize = mGrid.GetProperty(Actor::Property::SIZE); // Get target value - pt1 = AlignToGrid( mControlPoint1.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), gridSize ); - pt2 = AlignToGrid( mControlPoint2.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), gridSize ); + pt1 = AlignToGrid(mControlPoint1.GetCurrentProperty(Actor::Property::POSITION), gridSize); + pt2 = AlignToGrid(mControlPoint2.GetCurrentProperty(Actor::Property::POSITION), gridSize); } /** @@ -438,93 +436,93 @@ public: * @param[out] point The point in the grid in the range -0.5 -> 0.5 in x and y, with y up. * @param[out] position The actor position, floored to the nearest pixel */ - void GetPoint( Actor actor, Vector2& point, Vector2& position) + void GetPoint(Actor actor, Vector2& point, Vector2& position) { - auto gridSize = mGrid.GetProperty( Actor::Property::SIZE ); // Get target value - auto currentPosition = actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); // Get constrained current value + auto gridSize = mGrid.GetProperty(Actor::Property::SIZE); // Get target value + auto currentPosition = actor.GetCurrentProperty(Actor::Property::POSITION); // Get constrained current value - position = Vector2( floor( currentPosition.x ), floor( currentPosition.y ) ); + position = Vector2(floor(currentPosition.x), floor(currentPosition.y)); - point.x = Clamp( position.x / gridSize.x, -0.5f, 0.5f ) + 0.5f; + point.x = Clamp(position.x / gridSize.x, -0.5f, 0.5f) + 0.5f; point.y = 0.5f - position.y / gridSize.y; } void UpdateCurve() { - Vector2 point1, point2; - Vector2 position1, position2; + Vector2 point1, point2; + Vector2 position1, position2; const int NUMBER_OF_SEGMENTS(40); - GetPoint( mControlPoint1, point1, position1 ); - GetPoint( mControlPoint2, point2, position2 ); + GetPoint(mControlPoint1, point1, position1); + GetPoint(mControlPoint2, point2, position2); - if( position1 != mLastControlPointPosition1 || - position2 != mLastControlPointPosition2 ) + if(position1 != mLastControlPointPosition1 || + position2 != mLastControlPointPosition2) { mLastControlPointPosition1 = position1; mLastControlPointPosition2 = position2; - SetLabel( point1, point2 ); + SetLabel(point1, point2); Path path = Path::New(); path.AddPoint(Vector3::ZERO); path.AddPoint(Vector3(1.0f, 1.0f, 1.0f)); - path.AddControlPoint( Vector3( point1.x, point1.y, 0 ) ); - path.AddControlPoint( Vector3( point2.x, point2.y, 0 ) ); + path.AddControlPoint(Vector3(point1.x, point1.y, 0)); + path.AddControlPoint(Vector3(point2.x, point2.y, 0)); Dali::Vector verts; - verts.Resize(2*(NUMBER_OF_SEGMENTS+1)); // 1 more point than segment - for( int i=0; i<=NUMBER_OF_SEGMENTS; ++i) + verts.Resize(2 * (NUMBER_OF_SEGMENTS + 1)); // 1 more point than segment + for(int i = 0; i <= NUMBER_OF_SEGMENTS; ++i) { Vector3 position, tangent; - path.Sample( i/float(NUMBER_OF_SEGMENTS), position, tangent ); - verts[i*2] = position.x-0.5; - verts[i*2+1] = 0.5-position.y; + path.Sample(i / float(NUMBER_OF_SEGMENTS), position, tangent); + verts[i * 2] = position.x - 0.5; + verts[i * 2 + 1] = 0.5 - position.y; } - mCurveVertices.SetData(&verts[0], NUMBER_OF_SEGMENTS+1); + mCurveVertices.SetData(&verts[0], NUMBER_OF_SEGMENTS + 1); - Vector4 line1( -0.5f, 0.5f, point1.x-0.5f, 0.5f-point1.y ); - mLine1Vertices.SetData( line1.AsFloat(), 2 ); + Vector4 line1(-0.5f, 0.5f, point1.x - 0.5f, 0.5f - point1.y); + mLine1Vertices.SetData(line1.AsFloat(), 2); - Vector4 line2( 0.5f, -0.5f, point2.x-0.5f, 0.5f-point2.y ); - mLine2Vertices.SetData( line2.AsFloat(), 2 ); + Vector4 line2(0.5f, -0.5f, point2.x - 0.5f, 0.5f - point2.y); + mLine2Vertices.SetData(line2.AsFloat(), 2); } } - bool OnTouchControlPoint( Actor controlPoint, const TouchEvent& event ) + bool OnTouchControlPoint(Actor controlPoint, const TouchEvent& event) { - if( event.GetPointCount() > 0 ) + if(event.GetPointCount() > 0) { - if( event.GetState( 0 ) == PointState::DOWN ) + if(event.GetState(0) == PointState::DOWN) { - Vector2 screenPoint = event.GetScreenPosition( 0 ); - mRelativeDragPoint = screenPoint; - mRelativeDragPoint -= Vector2(controlPoint.GetCurrentProperty< Vector3 >( Actor::Property::POSITION )); - mDragActor = controlPoint; + Vector2 screenPoint = event.GetScreenPosition(0); + mRelativeDragPoint = screenPoint; + mRelativeDragPoint -= Vector2(controlPoint.GetCurrentProperty(Actor::Property::POSITION)); + mDragActor = controlPoint; mDragAnimation = Animation::New(0.25f); - mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3( mControlPointZoomScale, mControlPointZoomScale, 1.0f), AlphaFunction::EASE_OUT); + mDragAnimation.AnimateTo(Property(mDragActor, Actor::Property::SCALE), Vector3(mControlPointZoomScale, mControlPointZoomScale, 1.0f), AlphaFunction::EASE_OUT); mDragAnimation.Play(); } } return false; // Don't mark this as consumed - let the layer get the touch } - bool OnTouchLayer( Actor actor, const TouchEvent& event ) + bool OnTouchLayer(Actor actor, const TouchEvent& event) { - if( event.GetPointCount() > 0 ) + if(event.GetPointCount() > 0) { - if( mDragActor ) + if(mDragActor) { - Vector3 position( event.GetScreenPosition( 0 ) ); + Vector3 position(event.GetScreenPosition(0)); - mDragActor.SetProperty( Actor::Property::POSITION, position - Vector3( mRelativeDragPoint ) ); + mDragActor.SetProperty(Actor::Property::POSITION, position - Vector3(mRelativeDragPoint)); - if( event.GetState( 0 ) == PointState::UP ) // Stop dragging + if(event.GetState(0) == PointState::UP) // Stop dragging { mDragAnimation = Animation::New(0.25f); - mDragAnimation.AnimateTo( Property( mDragActor, Actor::Property::SCALE ), Vector3( mControlPointScale, mControlPointScale, 1.0f), AlphaFunction::EASE_IN); - mDragAnimation.FinishedSignal().Connect( this, &BezierCurveExample::OnAnimationFinished ); + mDragAnimation.AnimateTo(Property(mDragActor, Actor::Property::SCALE), Vector3(mControlPointScale, mControlPointScale, 1.0f), AlphaFunction::EASE_IN); + mDragAnimation.FinishedSignal().Connect(this, &BezierCurveExample::OnAnimationFinished); mDragAnimation.Play(); mDragActor.Reset(); } @@ -534,25 +532,25 @@ public: return false; } - void OnAnimationFinished( Animation& animation ) + void OnAnimationFinished(Animation& animation) { UpdateCurve(); } - bool OnPlayClicked( Button button ) + bool OnPlayClicked(Button button) { - if( ! mBezierAnimation ) + if(!mBezierAnimation) { - mBezierAnimation = Animation::New( mDuration ); + mBezierAnimation = Animation::New(mDuration); } mBezierAnimation.Stop(); mBezierAnimation.Clear(); float positionFactor = ANIM_LEFT_FACTOR; - if( mGoingRight ) + if(mGoingRight) { positionFactor = ANIM_RIGHT_FACTOR; - mGoingRight = false; + mGoingRight = false; } else { @@ -562,7 +560,7 @@ public: Vector2 pt1, pt2; GetControlPoints(pt1, pt2); - mBezierAnimation.AnimateTo( Property(mAnimIcon1, mPositionFactorIndex), positionFactor, AlphaFunction( pt1, pt2 ) ); + mBezierAnimation.AnimateTo(Property(mAnimIcon1, mPositionFactorIndex), positionFactor, AlphaFunction(pt1, pt2)); mBezierAnimation.Play(); return true; } @@ -572,50 +570,48 @@ public: */ void OnKeyEvent(const KeyEvent& event) { - - if( event.GetState() == KeyEvent::DOWN && (IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK )) ) + if(event.GetState() == KeyEvent::DOWN && (IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))) { mApplication.Quit(); } } private: - Application& mApplication; - Actor mControlPoint1; - Actor mControlPoint2; - Actor mControlLine1; - Actor mControlLine2; - ImageView mAnimIcon1; - ImageView mAnimIcon2; - Actor mDragActor; - Actor mCurve; - TextLabel mCoefficientLabel; - Layer mContentLayer; - Control mGrid; - Timer mTimer; - Animation mDragAnimation; - Animation mBezierAnimation; - VertexBuffer mCurveVertices; - VertexBuffer mLine1Vertices; - VertexBuffer mLine2Vertices; - Vector2 mRelativeDragPoint; - Vector2 mLastControlPointPosition1; - Vector2 mLastControlPointPosition2; + Application& mApplication; + Actor mControlPoint1; + Actor mControlPoint2; + Actor mControlLine1; + Actor mControlLine2; + ImageView mAnimIcon1; + ImageView mAnimIcon2; + Actor mDragActor; + Actor mCurve; + TextLabel mCoefficientLabel; + Layer mContentLayer; + Control mGrid; + Timer mTimer; + Animation mDragAnimation; + Animation mBezierAnimation; + VertexBuffer mCurveVertices; + VertexBuffer mLine1Vertices; + VertexBuffer mLine2Vertices; + Vector2 mRelativeDragPoint; + Vector2 mLastControlPointPosition1; + Vector2 mLastControlPointPosition2; Property::Index mPositionFactorIndex; - float mDuration; - unsigned int mControlPoint1Id; - unsigned int mControlPoint2Id; - float mControlPointScale; - float mControlPointZoomScale; - bool mGoingRight; + float mDuration; + unsigned int mControlPoint1Id; + unsigned int mControlPoint2Id; + float mControlPointScale; + float mControlPointZoomScale; + bool mGoingRight; }; - -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - BezierCurveExample test( application ); + BezierCurveExample test(application); application.MainLoop(); return 0; } diff --git a/examples/blocks/blocks-example.cpp b/examples/blocks/blocks-example.cpp index 9018283..fcdc2c0 100644 --- a/examples/blocks/blocks-example.cpp +++ b/examples/blocks/blocks-example.cpp @@ -15,15 +15,15 @@ * */ -#include +#include #include -#include #include -#include +#include +#include -#include #include #include +#include #include "shared/view.h" using namespace Dali; @@ -32,44 +32,44 @@ using namespace DemoHelper; namespace { -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-blocks.jpg" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "DALi Blocks" ); -const char* BALL_IMAGE = DEMO_IMAGE_DIR "blocks-ball.png"; -const char* PADDLE_IMAGE = DEMO_IMAGE_DIR "blocks-paddle.png"; +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-blocks.jpg"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("DALi Blocks"); +const char* BALL_IMAGE = DEMO_IMAGE_DIR "blocks-ball.png"; +const char* PADDLE_IMAGE = DEMO_IMAGE_DIR "blocks-paddle.png"; const char* PADDLE_HANDLE_IMAGE = DEMO_IMAGE_DIR "blocks-paddle-handle.png"; -const char* BRICK_IMAGE_PATH[] = { DEMO_IMAGE_DIR "blocks-brick-1.png", - DEMO_IMAGE_DIR "blocks-brick-2.png", - DEMO_IMAGE_DIR "blocks-brick-3.png", - DEMO_IMAGE_DIR "blocks-brick-4.png" }; +const char* BRICK_IMAGE_PATH[] = {DEMO_IMAGE_DIR "blocks-brick-1.png", + DEMO_IMAGE_DIR "blocks-brick-2.png", + DEMO_IMAGE_DIR "blocks-brick-3.png", + DEMO_IMAGE_DIR "blocks-brick-4.png"}; -const int TOTAL_BRICKS(4); ///< Total bricks in game. +const int TOTAL_BRICKS(4); ///< Total bricks in game. const Vector3 ICON_SIZE(100.0f, 100.0f, 0.0f); -const float SCREEN_MARGIN = 10.0f; ///< Margin indentation around screen -const Vector3 MENU_BUTTON_SIZE = Vector3(0.15f, 0.05f, 1.0f); ///< Standard Menu Buttons. +const float SCREEN_MARGIN = 10.0f; ///< Margin indentation around screen +const Vector3 MENU_BUTTON_SIZE = Vector3(0.15f, 0.05f, 1.0f); ///< Standard Menu Buttons. -const float MAX_ANIMATION_DURATION = 60.0f; ///< 60 seconds animations. Long enough for ball to hit an obstacle. -const float BALL_VELOCITY = 300.0f; ///< Ball velocity in pixels/second. -const float MAX_VELOCITY = 500.0f; ///< Max. velocity in pixels/second. -const Vector3 PADDLE_COLLISION_MARGIN(0.0f, 0.0f, 0.0f); ///< Collision margin for ball-paddle detection. -const Vector3 BRICK_COLLISION_MARGIN(0.0f, 0.0f, 0.0f); ///< Collision margin for ball-brick detection. -const Vector3 INITIAL_BALL_DIRECTION(1.0f, 1.0f, 0.0f); ///< Initial ball direction. +const float MAX_ANIMATION_DURATION = 60.0f; ///< 60 seconds animations. Long enough for ball to hit an obstacle. +const float BALL_VELOCITY = 300.0f; ///< Ball velocity in pixels/second. +const float MAX_VELOCITY = 500.0f; ///< Max. velocity in pixels/second. +const Vector3 PADDLE_COLLISION_MARGIN(0.0f, 0.0f, 0.0f); ///< Collision margin for ball-paddle detection. +const Vector3 BRICK_COLLISION_MARGIN(0.0f, 0.0f, 0.0f); ///< Collision margin for ball-brick detection. +const Vector3 INITIAL_BALL_DIRECTION(1.0f, 1.0f, 0.0f); ///< Initial ball direction. -const std::string WOBBLE_PROPERTY_NAME("wobbleProperty"); ///< Wobble property name. -const std::string COLLISION_PROPERTY_NAME("collisionProperty"); ///< Collision property name. +const std::string WOBBLE_PROPERTY_NAME("wobbleProperty"); ///< Wobble property name. +const std::string COLLISION_PROPERTY_NAME("collisionProperty"); ///< Collision property name. -const Vector2 BRICK_SIZE(0.1f, 0.05f ); ///< Brick size relative to width of window. -const Vector2 BALL_SIZE( 0.05f, 0.05f ); ///< Ball size relative to width of window. -const Vector2 PADDLE_SIZE( 0.2f, 0.05f ); ///< Paddle size relative to width of window. -const Vector2 PADDLE_HANDLE_SIZE( 0.3f, 0.3f ); ///< Paddle handle size relative to width of window. -const Vector2 BALL_START_POSITION(0.5f, 0.8f); ///< Ball start position relative to window size. -const Vector2 PADDLE_START_POSITION(0.5f, 0.9f); ///< Paddler start position relative to window size. -const Vector2 PADDLE_HIT_MARGIN( 0.1, 0.15f ); ///< Extra hit Area for Paddle when touching. +const Vector2 BRICK_SIZE(0.1f, 0.05f); ///< Brick size relative to width of window. +const Vector2 BALL_SIZE(0.05f, 0.05f); ///< Ball size relative to width of window. +const Vector2 PADDLE_SIZE(0.2f, 0.05f); ///< Paddle size relative to width of window. +const Vector2 PADDLE_HANDLE_SIZE(0.3f, 0.3f); ///< Paddle handle size relative to width of window. +const Vector2 BALL_START_POSITION(0.5f, 0.8f); ///< Ball start position relative to window size. +const Vector2 PADDLE_START_POSITION(0.5f, 0.9f); ///< Paddler start position relative to window size. +const Vector2 PADDLE_HIT_MARGIN(0.1, 0.15f); ///< Extra hit Area for Paddle when touching. -const int TOTAL_LIVES(3); ///< Total lives in game before it's game over! -const int TOTAL_LEVELS(3); ///< 3 Levels total, then repeats. +const int TOTAL_LIVES(3); ///< Total lives in game before it's game over! +const int TOTAL_LEVELS(3); ///< 3 Levels total, then repeats. // constraints //////////////////////////////////////////////////////////////// @@ -89,7 +89,7 @@ struct CollisionCircleRectangleConstraint * @param[in] adjustSize (optional) Adjusts the rectangular size of detection */ CollisionCircleRectangleConstraint(Vector3 adjustPosition = Vector3::ZERO, - Vector3 adjustSize = Vector3::ZERO) + Vector3 adjustSize = Vector3::ZERO) : mAdjustPosition(adjustPosition), mAdjustSize(adjustSize) { @@ -107,24 +107,24 @@ struct CollisionCircleRectangleConstraint * Actor B's Size property. * @return The collision vector is returned. */ - void operator()( Vector3& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs) { - const Vector3& a = inputs[0]->GetVector3(); - const Vector3 b = inputs[1]->GetVector3() + mAdjustPosition; - const Vector3& sizeA = inputs[2]->GetVector3(); - const Vector3& sizeB = inputs[3]->GetVector3(); - const Vector3 sizeA2 = sizeA * 0.5f; // circle radius - const Vector3 sizeB2 = (sizeB + mAdjustSize) * 0.5f; // rectangle half rectangle. + const Vector3& a = inputs[0]->GetVector3(); + const Vector3 b = inputs[1]->GetVector3() + mAdjustPosition; + const Vector3& sizeA = inputs[2]->GetVector3(); + const Vector3& sizeB = inputs[3]->GetVector3(); + const Vector3 sizeA2 = sizeA * 0.5f; // circle radius + const Vector3 sizeB2 = (sizeB + mAdjustSize) * 0.5f; // rectangle half rectangle. // get collision relative to a (rectangle). Vector3 delta = a - b; // reduce rectangle to 0. - if (delta.x > sizeB2.x) + if(delta.x > sizeB2.x) { delta.x -= sizeB2.x; } - else if (delta.x < -sizeB2.x) + else if(delta.x < -sizeB2.x) { delta.x += sizeB2.x; } @@ -133,11 +133,11 @@ struct CollisionCircleRectangleConstraint delta.x = 0; } - if (delta.y > sizeB2.y) + if(delta.y > sizeB2.y) { delta.y -= sizeB2.y; } - else if (delta.y < -sizeB2.y) + else if(delta.y < -sizeB2.y) { delta.y += sizeB2.y; } @@ -158,8 +158,8 @@ struct CollisionCircleRectangleConstraint } } - const Vector3 mAdjustPosition; ///< Position Adjustment value - const Vector3 mAdjustSize; ///< Size Adjustment value + const Vector3 mAdjustPosition; ///< Position Adjustment value + const Vector3 mAdjustSize; ///< Size Adjustment value }; /** @@ -177,10 +177,9 @@ struct WobbleConstraint * * @param[in] deviation The max. deviation of wobble effect in degrees. */ - WobbleConstraint( Degree deviation ) - : mDeviation( deviation ) + WobbleConstraint(Degree deviation) + : mDeviation(deviation) { - } /** @@ -188,16 +187,16 @@ struct WobbleConstraint * @param[in] inputs Contains the wobble property (value from 0.0f to 1.0f) * @return The rotation (quaternion) is generated. */ - void operator()( Quaternion& current, const PropertyInputContainer& inputs ) + void operator()(Quaternion& current, const PropertyInputContainer& inputs) { const float& wobble = inputs[0]->GetFloat(); - float f = sinf(wobble * 10.0f) * (1.0f-wobble); + float f = sinf(wobble * 10.0f) * (1.0f - wobble); current = Quaternion(mDeviation * f, Vector3::ZAXIS); } - Radian mDeviation; ///< Deviation factor in radians. + Radian mDeviation; ///< Deviation factor in radians. }; } // unnamed namespace @@ -208,13 +207,12 @@ struct WobbleConstraint class ExampleController : public ConnectionTracker { public: - /** * Constructor * @param application Application class, stored as reference */ - ExampleController( Application& application ) - : mApplication( application ), + ExampleController(Application& application) + : mApplication(application), mView(), mContentLayer(), mBall(), @@ -226,7 +224,7 @@ public: mPaddleHandle(), mPaddleHitMargin(), mWobbleAnimation(), - mWobbleProperty( Property::INVALID_INDEX ), + mWobbleProperty(Property::INVALID_INDEX), mLevelContainer(), mBrickImageMap(), mDragAnimation(), @@ -234,9 +232,9 @@ public: mRelativeDragPoint(), mDestroyAnimationMap(), mPaddleFullSize(), - mLevel( 0 ), - mLives( TOTAL_LIVES ), - mBrickCount( 0 ) + mLevel(0), + mLives(TOTAL_LIVES), + mBrickCount(0) { // Connect to the Application's Init and orientation changed signal @@ -254,63 +252,62 @@ public: // Creates a default view with a default tool bar. // The view is added to the window. Toolkit::ToolBar toolBar; - mContentLayer = DemoHelper::CreateView( application, - mView, - toolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContentLayer = DemoHelper::CreateView(application, + mView, + toolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Add an extra space on the right to center the title text. - toolBar.AddControl( Actor::New(), DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT ); + toolBar.AddControl(Actor::New(), DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT); // Create the content layer, which is where game actors appear. AddContentLayer(); } private: - /** * Adds a new layer to the window, containing game actors. */ void AddContentLayer() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); const Vector3 windowSize(window.GetSize()); // Ball setup - mBallStartPosition = windowSize * Vector3( BALL_START_POSITION ); - mBall = CreateImage(BALL_IMAGE); - mBall.SetProperty( Actor::Property::POSITION, mBallStartPosition ); - mBall.SetProperty( Actor::Property::SIZE, BALL_SIZE * windowSize.width ); + mBallStartPosition = windowSize * Vector3(BALL_START_POSITION); + mBall = CreateImage(BALL_IMAGE); + mBall.SetProperty(Actor::Property::POSITION, mBallStartPosition); + mBall.SetProperty(Actor::Property::SIZE, BALL_SIZE * windowSize.width); mContentLayer.Add(mBall); mBallVelocity = Vector3::ZERO; // Paddle setup mPaddleHitMargin = Vector2(windowSize) * PADDLE_HIT_MARGIN; - mPaddle = Actor::New(); - mPaddleHandle = CreateImage(PADDLE_HANDLE_IMAGE); - mPaddleImage = CreateImage(PADDLE_IMAGE); - mPaddle.Add( mPaddleHandle ); - mPaddle.Add( mPaddleImage ); - mPaddleHandle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mPaddleHandle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mPaddleHandle.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, windowSize.width * 0.0125f )); - mPaddleImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mPaddleImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mPaddle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mPaddle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mPaddle = Actor::New(); + mPaddleHandle = CreateImage(PADDLE_HANDLE_IMAGE); + mPaddleImage = CreateImage(PADDLE_IMAGE); + mPaddle.Add(mPaddleHandle); + mPaddle.Add(mPaddleImage); + mPaddleHandle.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mPaddleHandle.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mPaddleHandle.SetProperty(Actor::Property::POSITION, Vector2(0.0f, windowSize.width * 0.0125f)); + mPaddleImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mPaddleImage.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mPaddle.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mPaddle.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); mPaddleFullSize = PADDLE_SIZE * windowSize.width; - mPaddle.SetProperty( Actor::Property::SIZE, mPaddleFullSize + mPaddleHitMargin ); - mPaddleHandle.SetProperty( Actor::Property::SIZE, PADDLE_HANDLE_SIZE * windowSize.width ); - mPaddleImage.SetProperty( Actor::Property::SIZE, mPaddleFullSize ); + mPaddle.SetProperty(Actor::Property::SIZE, mPaddleFullSize + mPaddleHitMargin); + mPaddleHandle.SetProperty(Actor::Property::SIZE, PADDLE_HANDLE_SIZE * windowSize.width); + mPaddleImage.SetProperty(Actor::Property::SIZE, mPaddleFullSize); - mWobbleProperty = mPaddle.RegisterProperty(WOBBLE_PROPERTY_NAME, 0.0f); - Constraint wobbleConstraint = Constraint::New( mPaddle, Actor::Property::ORIENTATION, WobbleConstraint(Degree( 10.0f ))); - wobbleConstraint.AddSource( LocalSource(mWobbleProperty) ); + mWobbleProperty = mPaddle.RegisterProperty(WOBBLE_PROPERTY_NAME, 0.0f); + Constraint wobbleConstraint = Constraint::New(mPaddle, Actor::Property::ORIENTATION, WobbleConstraint(Degree(10.0f))); + wobbleConstraint.AddSource(LocalSource(mWobbleProperty)); wobbleConstraint.Apply(); - mPaddle.SetProperty( Actor::Property::POSITION, windowSize * Vector3( PADDLE_START_POSITION ) ); + mPaddle.SetProperty(Actor::Property::POSITION, windowSize * Vector3(PADDLE_START_POSITION)); mContentLayer.Add(mPaddle); mPaddle.TouchedSignal().Connect(this, &ExampleController::OnTouchPaddle); mContentLayer.TouchedSignal().Connect(this, &ExampleController::OnTouchLayer); @@ -318,31 +315,31 @@ private: const float margin(BALL_SIZE.width * windowSize.width * 0.5f); // Set up notifications for ball's collisions against walls. - PropertyNotification leftNotification = mBall.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(margin) ); - leftNotification.NotifySignal().Connect( this, &ExampleController::OnHitLeftWall ); + PropertyNotification leftNotification = mBall.AddPropertyNotification(Actor::Property::POSITION_X, LessThanCondition(margin)); + leftNotification.NotifySignal().Connect(this, &ExampleController::OnHitLeftWall); - PropertyNotification rightNotification = mBall.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(windowSize.width - margin) ); - rightNotification.NotifySignal().Connect( this, &ExampleController::OnHitRightWall ); + PropertyNotification rightNotification = mBall.AddPropertyNotification(Actor::Property::POSITION_X, GreaterThanCondition(windowSize.width - margin)); + rightNotification.NotifySignal().Connect(this, &ExampleController::OnHitRightWall); - PropertyNotification topNotification = mBall.AddPropertyNotification( Actor::Property::POSITION_Y, LessThanCondition(margin) ); - topNotification.NotifySignal().Connect( this, &ExampleController::OnHitTopWall ); + PropertyNotification topNotification = mBall.AddPropertyNotification(Actor::Property::POSITION_Y, LessThanCondition(margin)); + topNotification.NotifySignal().Connect(this, &ExampleController::OnHitTopWall); - PropertyNotification bottomNotification = mBall.AddPropertyNotification( Actor::Property::POSITION_Y, GreaterThanCondition(windowSize.height + margin) ); - bottomNotification.NotifySignal().Connect( this, &ExampleController::OnHitBottomWall ); + PropertyNotification bottomNotification = mBall.AddPropertyNotification(Actor::Property::POSITION_Y, GreaterThanCondition(windowSize.height + margin)); + bottomNotification.NotifySignal().Connect(this, &ExampleController::OnHitBottomWall); // Set up notification for ball colliding against paddle. Actor delegate = Actor::New(); window.Add(delegate); - Property::Index property = delegate.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO); - Constraint constraint = Constraint::New( delegate, property, CollisionCircleRectangleConstraint( -Vector3(0.0f, mPaddleHitMargin.height * 0.575f, 0.0f),-Vector3(mPaddleHitMargin) ) ); - constraint.AddSource( Source(mBall, Actor::Property::POSITION) ); - constraint.AddSource( Source(mPaddle, Actor::Property::POSITION) ); - constraint.AddSource( Source(mBall, Actor::Property::SIZE) ); - constraint.AddSource( Source(mPaddle, Actor::Property::SIZE) ); + Property::Index property = delegate.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO); + Constraint constraint = Constraint::New(delegate, property, CollisionCircleRectangleConstraint(-Vector3(0.0f, mPaddleHitMargin.height * 0.575f, 0.0f), -Vector3(mPaddleHitMargin))); + constraint.AddSource(Source(mBall, Actor::Property::POSITION)); + constraint.AddSource(Source(mPaddle, Actor::Property::POSITION)); + constraint.AddSource(Source(mBall, Actor::Property::SIZE)); + constraint.AddSource(Source(mPaddle, Actor::Property::SIZE)); constraint.Apply(); - PropertyNotification paddleNotification = delegate.AddPropertyNotification( property, GreaterThanCondition(0.0f) ); - paddleNotification.NotifySignal().Connect( this, &ExampleController::OnHitPaddle ); + PropertyNotification paddleNotification = delegate.AddPropertyNotification(property, GreaterThanCondition(0.0f)); + paddleNotification.NotifySignal().Connect(this, &ExampleController::OnHitPaddle); RestartGame(); } @@ -355,10 +352,10 @@ private: { mLives = TOTAL_LIVES; mLevel = 0; - mBall.SetProperty( Actor::Property::POSITION, mBallStartPosition ); + mBall.SetProperty(Actor::Property::POSITION, mBallStartPosition); mBallVelocity = Vector3::ZERO; - mPaddle.SetProperty( Actor::Property::SIZE, mPaddleFullSize + mPaddleHitMargin ); - mPaddleImage.SetProperty( Actor::Property::SIZE, mPaddleFullSize ); + mPaddle.SetProperty(Actor::Property::SIZE, mPaddleFullSize + mPaddleHitMargin); + mPaddleImage.SetProperty(Actor::Property::SIZE, mPaddleFullSize); LoadLevel(mLevel); } @@ -373,30 +370,30 @@ private: { if(mLevelContainer && mLevelContainer.GetParent() == mContentLayer) { - mContentLayer.Remove( mLevelContainer ); + mContentLayer.Remove(mLevelContainer); } mLevelContainer = Actor::New(); - mLevelContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLevelContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLevelContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mLevelContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLevelContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLevelContainer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - mContentLayer.Add( mLevelContainer ); + mContentLayer.Add(mLevelContainer); mBrickCount = 0; - if( mBrickImageMap.Empty() ) + if(mBrickImageMap.Empty()) { - Vector2 windowSize(mApplication.GetWindow().GetSize()); + Vector2 windowSize(mApplication.GetWindow().GetSize()); const Vector2 brickSize(BRICK_SIZE * Vector2(windowSize.x, windowSize.x)); - mBrickImageMap["desiredWidth"] = static_cast( brickSize.width ); - mBrickImageMap["desiredHeight"] = static_cast( brickSize.height ); - mBrickImageMap["fittingMode"] = "SCALE_TO_FILL"; - mBrickImageMap["samplingMode"] = "BOX_THEN_LINEAR"; + mBrickImageMap["desiredWidth"] = static_cast(brickSize.width); + mBrickImageMap["desiredHeight"] = static_cast(brickSize.height); + mBrickImageMap["fittingMode"] = "SCALE_TO_FILL"; + mBrickImageMap["samplingMode"] = "BOX_THEN_LINEAR"; } - switch(level%TOTAL_LEVELS) + switch(level % TOTAL_LEVELS) { case 0: { @@ -425,19 +422,19 @@ private: */ void GenerateLevel0() { - Vector2 windowSize(mApplication.GetWindow().GetSize()); + Vector2 windowSize(mApplication.GetWindow().GetSize()); const Vector2 brickSize(BRICK_SIZE * windowSize.width); - const int columns = (0.85f * windowSize.width) / brickSize.width; // 85 percent of the width of the screen covered with bricks. - const int rows = (0.3f * windowSize.height) / brickSize.height; // 30 percent of the height of the screen covered with bricks. - const Vector2 offset( (windowSize.x - (columns * brickSize.width)) * 0.5f, - windowSize.y * 0.125f ); + const int columns = (0.85f * windowSize.width) / brickSize.width; // 85 percent of the width of the screen covered with bricks. + const int rows = (0.3f * windowSize.height) / brickSize.height; // 30 percent of the height of the screen covered with bricks. + const Vector2 offset((windowSize.x - (columns * brickSize.width)) * 0.5f, + windowSize.y * 0.125f); for(int j = 0; j < rows; j++) { for(int i = 0; i < columns; i++) { - Actor brick = CreateBrick(Vector2(i * brickSize.width + offset.x, j * brickSize.height + offset.y) + (brickSize * 0.5f), j % TOTAL_BRICKS ); + Actor brick = CreateBrick(Vector2(i * brickSize.width + offset.x, j * brickSize.height + offset.y) + (brickSize * 0.5f), j % TOTAL_BRICKS); mLevelContainer.Add(brick); mBrickCount++; } @@ -449,23 +446,23 @@ private: */ void GenerateLevel1() { - Vector2 windowSize(mApplication.GetWindow().GetSize()); + Vector2 windowSize(mApplication.GetWindow().GetSize()); const Vector2 brickSize(BRICK_SIZE * windowSize.width); - const int columns = (0.85f * windowSize.width) / brickSize.width; // 85 percent of the width of the screen covered with bricks. - const int rows = (0.3f * windowSize.height) / brickSize.height; // 30 percent of the height of the screen covered with bricks. - const Vector2 offset( (windowSize.x - (columns * brickSize.width)) * 0.5f, - windowSize.y * 0.125f ); + const int columns = (0.85f * windowSize.width) / brickSize.width; // 85 percent of the width of the screen covered with bricks. + const int rows = (0.3f * windowSize.height) / brickSize.height; // 30 percent of the height of the screen covered with bricks. + const Vector2 offset((windowSize.x - (columns * brickSize.width)) * 0.5f, + windowSize.y * 0.125f); for(int j = 0; j < rows; j++) { for(int i = 0; i < columns; i++) { - int i2 = columns - i - 1; - int j2 = rows - j - 1; - int brickIndex = std::min( std::min(i, j), std::min(i2, j2) ) % TOTAL_BRICKS; + int i2 = columns - i - 1; + int j2 = rows - j - 1; + int brickIndex = std::min(std::min(i, j), std::min(i2, j2)) % TOTAL_BRICKS; - Actor brick = CreateBrick(Vector2(i * brickSize.width + offset.x, j * brickSize.height + offset.y) + (brickSize * 0.5f), brickIndex ); + Actor brick = CreateBrick(Vector2(i * brickSize.width + offset.x, j * brickSize.height + offset.y) + (brickSize * 0.5f), brickIndex); mLevelContainer.Add(brick); mBrickCount++; @@ -478,52 +475,52 @@ private: */ void GenerateLevel2() { - Vector2 windowSize(mApplication.GetWindow().GetSize()); + Vector2 windowSize(mApplication.GetWindow().GetSize()); const Vector2 brickSize(BRICK_SIZE * windowSize.width); - const int columns = (0.85f * windowSize.width) / brickSize.width; // 85 percent of the width of the screen covered with bricks. - const int rows = (0.3f * windowSize.height) / brickSize.height; // 30 percent of the height of the screen covered with bricks. - const Vector2 offset( (windowSize.x - (columns * brickSize.width)) * 0.5f, - windowSize.y * 0.125f ); + const int columns = (0.85f * windowSize.width) / brickSize.width; // 85 percent of the width of the screen covered with bricks. + const int rows = (0.3f * windowSize.height) / brickSize.height; // 30 percent of the height of the screen covered with bricks. + const Vector2 offset((windowSize.x - (columns * brickSize.width)) * 0.5f, + windowSize.y * 0.125f); // lays down bricks in a spiral formation starting at i,j = (0,0) top left corner // travelling right di,dj = (1,0) initially - int i = 0; - int j = 0; + int i = 0; + int j = 0; int di = 1; int dj = 0; // contracting boundaries - int left = 0; - int right = columns - 1; - int top = 2; + int left = 0; + int right = columns - 1; + int top = 2; int bottom = rows - 1; // length of current line. we stop laying down bricks when the length is 1 brick or less. int length = 0; while(true) { - Actor brick = CreateBrick(Vector2(i * brickSize.width + offset.x, j * brickSize.height + offset.y) + (brickSize * 0.5f), 0 ); + Actor brick = CreateBrick(Vector2(i * brickSize.width + offset.x, j * brickSize.height + offset.y) + (brickSize * 0.5f), 0); mLevelContainer.Add(brick); - i+=di; - j+=dj; + i += di; + j += dj; bool turn(false); - if((i==right) && (di==1)) + if((i == right) && (di == 1)) { right -= 2; turn = true; } - if((j==bottom) && (dj==1)) + if((j == bottom) && (dj == 1)) { bottom -= 2; turn = true; } - if((i==left) && (di==-1)) + if((i == left) && (di == -1)) { left += 2; turn = true; } - if((j==top) && (dj==-1)) + if((j == top) && (dj == -1)) { top += 2; turn = true; @@ -533,7 +530,7 @@ private: // turn 90 degrees clockwise. std::swap(di, dj); di = -di; - if (length<=1) + if(length <= 1) { break; } @@ -544,35 +541,34 @@ private: } } - /** * Creates a brick at a specified position on the window * @param[in] position the position for the brick * @param[in] type the type of brick * @return The Brick Actor is returned. */ - Actor CreateBrick( const Vector2& position, int type ) + Actor CreateBrick(const Vector2& position, int type) { mBrickImageMap["url"] = BRICK_IMAGE_PATH[type]; - ImageView brick = ImageView::New(); - brick.SetProperty( ImageView::Property::IMAGE, mBrickImageMap ); - brick.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - brick.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - brick.SetProperty( Actor::Property::POSITION, position ); + ImageView brick = ImageView::New(); + brick.SetProperty(ImageView::Property::IMAGE, mBrickImageMap); + brick.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + brick.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + brick.SetProperty(Actor::Property::POSITION, position); // Add a constraint on the brick between it and the ball generating a collision-property - Property::Index property = brick.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO); - Constraint constraint = Constraint::New( brick, property, CollisionCircleRectangleConstraint(BRICK_COLLISION_MARGIN) ); - constraint.AddSource( Source(mBall, Actor::Property::POSITION) ); - constraint.AddSource( Source(brick, Actor::Property::POSITION) ); - constraint.AddSource( Source(mBall, Actor::Property::SIZE) ); - constraint.AddSource( Source(brick, Actor::Property::SIZE) ); + Property::Index property = brick.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO); + Constraint constraint = Constraint::New(brick, property, CollisionCircleRectangleConstraint(BRICK_COLLISION_MARGIN)); + constraint.AddSource(Source(mBall, Actor::Property::POSITION)); + constraint.AddSource(Source(brick, Actor::Property::POSITION)); + constraint.AddSource(Source(mBall, Actor::Property::SIZE)); + constraint.AddSource(Source(brick, Actor::Property::SIZE)); constraint.Apply(); // Now add a notification on this collision-property - PropertyNotification brickNotification = brick.AddPropertyNotification( property, GreaterThanCondition(0.0f) ); - brickNotification.NotifySignal().Connect( this, &ExampleController::OnHitBrick ); + PropertyNotification brickNotification = brick.AddPropertyNotification(property, GreaterThanCondition(0.0f)); + brickNotification.NotifySignal().Connect(this, &ExampleController::OnHitBrick); return brick; } @@ -590,8 +586,8 @@ private: propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL); ImageView actor = ImageView::New(); actor.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); - actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); return actor; } @@ -606,7 +602,7 @@ private: } mBallAnimation = Animation::New(MAX_ANIMATION_DURATION); - mBallAnimation.AnimateBy( Property( mBall, Actor::Property::POSITION ), mBallVelocity * MAX_ANIMATION_DURATION); + mBallAnimation.AnimateBy(Property(mBall, Actor::Property::POSITION), mBallVelocity * MAX_ANIMATION_DURATION); mBallAnimation.Play(); } @@ -617,19 +613,19 @@ private: */ bool OnTouchPaddle(Actor actor, const TouchEvent& event) { - if(event.GetPointCount()>0) + if(event.GetPointCount() > 0) { - if( event.GetState( 0 ) == PointState::DOWN ) // Commence dragging + if(event.GetState(0) == PointState::DOWN) // Commence dragging { // Get point where user touched paddle (relative to paddle's center) - Vector2 screenPoint = event.GetScreenPosition( 0 ); - mRelativeDragPoint = screenPoint; - mRelativeDragPoint -= actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); + Vector2 screenPoint = event.GetScreenPosition(0); + mRelativeDragPoint = screenPoint; + mRelativeDragPoint -= actor.GetCurrentProperty(Actor::Property::POSITION); - mDragActor = actor; + mDragActor = actor; mDragAnimation = Animation::New(0.25f); - mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.1f, 1.1f, 1.0f), AlphaFunction::EASE_OUT); - mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::EASE_OUT); + mDragAnimation.AnimateTo(Property(mDragActor, Actor::Property::SCALE), Vector3(1.1f, 1.1f, 1.0f), AlphaFunction::EASE_OUT); + mDragAnimation.AnimateTo(Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::EASE_OUT); mDragAnimation.Play(); } } @@ -643,18 +639,18 @@ private: */ bool OnTouchLayer(Actor actor, const TouchEvent& event) { - if(event.GetPointCount()>0) + if(event.GetPointCount() > 0) { if(mDragActor) { - Vector3 position( event.GetScreenPosition( 0 ) ); - mPaddle.SetProperty( Actor::Property::POSITION, position - mRelativeDragPoint ); + Vector3 position(event.GetScreenPosition(0)); + mPaddle.SetProperty(Actor::Property::POSITION, position - mRelativeDragPoint); - if( event.GetState( 0 ) == PointState::UP ) // Stop dragging + if(event.GetState(0) == PointState::UP) // Stop dragging { mDragAnimation = Animation::New(0.25f); - mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.0f, 1.0f, 1.0f), AlphaFunction::EASE_IN); - mDragAnimation.AnimateTo( Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f), AlphaFunction::EASE_OUT); + mDragAnimation.AnimateTo(Property(mDragActor, Actor::Property::SCALE), Vector3(1.0f, 1.0f, 1.0f), AlphaFunction::EASE_IN); + mDragAnimation.AnimateTo(Property(mPaddleHandle, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f), AlphaFunction::EASE_OUT); mDragAnimation.Play(); mDragActor.Reset(); } @@ -704,17 +700,17 @@ private: mBallAnimation.Clear(); } - if(mLives>0) + if(mLives > 0) { mLives--; const float f(static_cast(mLives) / TOTAL_LIVES); mBallVelocity = Vector3::ZERO; Animation shrink = Animation::New(0.5f); - shrink.AnimateTo( Property(mPaddle, Actor::Property::SIZE_WIDTH), mPaddleFullSize.x * f + mPaddleHitMargin.x); - shrink.AnimateTo( Property(mPaddleImage, Actor::Property::SIZE_WIDTH), mPaddleFullSize.x * f ); + shrink.AnimateTo(Property(mPaddle, Actor::Property::SIZE_WIDTH), mPaddleFullSize.x * f + mPaddleHitMargin.x); + shrink.AnimateTo(Property(mPaddleImage, Actor::Property::SIZE_WIDTH), mPaddleFullSize.x * f); - shrink.FinishedSignal().Connect( this, &ExampleController::OnPaddleShrunk ); + shrink.FinishedSignal().Connect(this, &ExampleController::OnPaddleShrunk); shrink.Play(); } } @@ -723,13 +719,13 @@ private: * Paddle Shrink Animation complete. * @param[in] source The animation responsible for shrinking the paddle. */ - void OnPaddleShrunk( Animation &source ) + void OnPaddleShrunk(Animation& source) { // Reposition Ball in start position, and make ball appear. - mBall.SetProperty( Actor::Property::POSITION, mBallStartPosition ); - mBall.SetProperty( Actor::Property::COLOR, Vector4(1.0f, 1.0f, 1.0f, 0.1f) ); + mBall.SetProperty(Actor::Property::POSITION, mBallStartPosition); + mBall.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 1.0f, 1.0f, 0.1f)); Animation appear = Animation::New(0.5f); - appear.AnimateTo( Property(mBall, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f) ); + appear.AnimateTo(Property(mBall, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 1.0f)); appear.Play(); if(!mLives) @@ -744,9 +740,9 @@ private: */ void OnHitPaddle(PropertyNotification& source) { - Actor delegate = Actor::DownCast(source.GetTarget()); - Vector3 collisionVector = delegate.GetCurrentProperty< Vector3 >( source.GetTargetProperty() ); - Vector3 ballRelativePosition(mBall.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) - mPaddle.GetCurrentProperty< Vector3 >( Actor::Property::POSITION )); + Actor delegate = Actor::DownCast(source.GetTarget()); + Vector3 collisionVector = delegate.GetCurrentProperty(source.GetTargetProperty()); + Vector3 ballRelativePosition(mBall.GetCurrentProperty(Actor::Property::POSITION) - mPaddle.GetCurrentProperty(Actor::Property::POSITION)); ballRelativePosition.Normalize(); collisionVector.x += ballRelativePosition.x * 0.5f; @@ -760,15 +756,15 @@ private: const float normalVelocity = fabsf(mBallVelocity.Dot(collisionVector)); mBallVelocity += collisionVector * normalVelocity * 2.0f; const float currentSpeed = mBallVelocity.Length(); - const float limitedSpeed = std::min( currentSpeed, MAX_VELOCITY ); - mBallVelocity = mBallVelocity * limitedSpeed / currentSpeed; + const float limitedSpeed = std::min(currentSpeed, MAX_VELOCITY); + mBallVelocity = mBallVelocity * limitedSpeed / currentSpeed; } ContinueAnimation(); // wobble paddle mWobbleAnimation = Animation::New(0.5f); - mWobbleAnimation.AnimateTo( Property( mPaddle, mWobbleProperty ), 1.0f ); + mWobbleAnimation.AnimateTo(Property(mPaddle, mWobbleProperty), 1.0f); mWobbleAnimation.Play(); mPaddle.SetProperty(mWobbleProperty, 0.0f); } @@ -779,14 +775,14 @@ private: */ void OnHitBrick(PropertyNotification& source) { - Actor brick = Actor::DownCast(source.GetTarget()); - Vector3 collisionVector = brick.GetCurrentProperty< Vector3 >( source.GetTargetProperty() ); + Actor brick = Actor::DownCast(source.GetTarget()); + Vector3 collisionVector = brick.GetCurrentProperty(source.GetTargetProperty()); const float normalVelocity = fabsf(mBallVelocity.Dot(collisionVector)); mBallVelocity += collisionVector * normalVelocity * 2.0f; const float currentSpeed = mBallVelocity.Length(); - const float limitedSpeed = std::min( currentSpeed, MAX_VELOCITY ); - mBallVelocity = mBallVelocity * limitedSpeed / currentSpeed; + const float limitedSpeed = std::min(currentSpeed, MAX_VELOCITY); + mBallVelocity = mBallVelocity * limitedSpeed / currentSpeed; ContinueAnimation(); @@ -796,9 +792,9 @@ private: // fade brick (destroy) Animation destroyAnimation = Animation::New(0.5f); - destroyAnimation.AnimateTo( Property( brick, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN ); + destroyAnimation.AnimateTo(Property(brick, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN); destroyAnimation.Play(); - destroyAnimation.FinishedSignal().Connect( this, &ExampleController::OnBrickDestroyed ); + destroyAnimation.FinishedSignal().Connect(this, &ExampleController::OnBrickDestroyed); mDestroyAnimationMap[destroyAnimation] = brick; } @@ -806,7 +802,7 @@ private: * Brick Destruction Animation complete. * @param[in] source The animation responsible for destroying the brick */ - void OnBrickDestroyed( Animation& source ) + void OnBrickDestroyed(Animation& source) { // Remove brick from window, it's constraint and property notification should also remove themselves. Actor brick = mDestroyAnimationMap[source]; @@ -828,7 +824,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -836,38 +832,37 @@ private: } private: - - Application& mApplication; ///< Application instance - Toolkit::Control mView; ///< The View instance. - Layer mContentLayer; ///< The content layer (contains game actors) - ImageView mBall; ///< The Moving ball image. - Vector3 mBallStartPosition; ///< Ball Start position - Vector3 mBallVelocity; ///< Ball's current direction. - Animation mBallAnimation; ///< Ball's animation - Actor mPaddle; ///< The paddle including hit area. - ImageView mPaddleImage; ///< The paddle's image. - ImageView mPaddleHandle; ///< The paddle's handle (where the user touches) - Vector2 mPaddleHitMargin; ///< The paddle hit margin. - Animation mWobbleAnimation; ///< Paddle's animation when hit (wobbles) - Property::Index mWobbleProperty; ///< The wobble property (generated from animation) - Actor mLevelContainer; ///< The level container (contains bricks) - Property::Map mBrickImageMap; ///< The property map used to load the brick + Application& mApplication; ///< Application instance + Toolkit::Control mView; ///< The View instance. + Layer mContentLayer; ///< The content layer (contains game actors) + ImageView mBall; ///< The Moving ball image. + Vector3 mBallStartPosition; ///< Ball Start position + Vector3 mBallVelocity; ///< Ball's current direction. + Animation mBallAnimation; ///< Ball's animation + Actor mPaddle; ///< The paddle including hit area. + ImageView mPaddleImage; ///< The paddle's image. + ImageView mPaddleHandle; ///< The paddle's handle (where the user touches) + Vector2 mPaddleHitMargin; ///< The paddle hit margin. + Animation mWobbleAnimation; ///< Paddle's animation when hit (wobbles) + Property::Index mWobbleProperty; ///< The wobble property (generated from animation) + Actor mLevelContainer; ///< The level container (contains bricks) + Property::Map mBrickImageMap; ///< The property map used to load the brick // actor - dragging functionality - Animation mDragAnimation; ///< Animation for dragging. (grows - affects ACTOR::SCALE) - Actor mDragActor; ///< The actor which is being dragged (if any) - Vector3 mRelativeDragPoint; ///< The point the user touched, relative to the actor. - std::map mDestroyAnimationMap; ///< Keep track of which actors are to be destroyed. - Vector2 mPaddleFullSize; ///< Initial 100% size of the paddle. - int mLevel; ///< Current level - int mLives; ///< Total lives. - int mBrickCount; ///< Total bricks on screen. + Animation mDragAnimation; ///< Animation for dragging. (grows - affects ACTOR::SCALE) + Actor mDragActor; ///< The actor which is being dragged (if any) + Vector3 mRelativeDragPoint; ///< The point the user touched, relative to the actor. + std::map mDestroyAnimationMap; ///< Keep track of which actors are to be destroyed. + Vector2 mPaddleFullSize; ///< Initial 100% size of the paddle. + int mLevel; ///< Current level + int mLives; ///< Total lives. + int mBrickCount; ///< Total bricks on screen. }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ExampleController test(app); app.MainLoop(); return 0; diff --git a/examples/bloom-view/bloom-view-example.cpp b/examples/bloom-view/bloom-view-example.cpp index 870c62c..61d5851 100644 --- a/examples/bloom-view/bloom-view-example.cpp +++ b/examples/bloom-view/bloom-view-example.cpp @@ -15,38 +15,37 @@ * */ -#include #include #include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { +const char* BACKGROUND_IMAGE_PATH(DEMO_IMAGE_DIR "desktop_background_1440x2560.png"); +const char* UI_DIFFUSE_IMAGE(DEMO_IMAGE_DIR "UI-Leather-DIFF.png"); -const char* BACKGROUND_IMAGE_PATH( DEMO_IMAGE_DIR "desktop_background_1440x2560.png" ); -const char* UI_DIFFUSE_IMAGE( DEMO_IMAGE_DIR "UI-Leather-DIFF.png" ); - -const Rect UI_PIXEL_AREA( 0, 0, 720, 1280 ); +const Rect UI_PIXEL_AREA(0, 0, 720, 1280); -const Rect PANEL1_PIXEL_AREA( 0, 0, 720, 39 ); -const Rect PANEL2_PIXEL_AREA( 0, 39, 720, 100 ); +const Rect PANEL1_PIXEL_AREA(0, 0, 720, 39); +const Rect PANEL2_PIXEL_AREA(0, 39, 720, 100); const unsigned int NUM_MOVEMENT_ANIMATIONS = 2; // for animating bloom intensity on tap gesture const float PULSE_BLOOM_INCREASE_ANIM_TIME = 1.175; const float PULSE_BLOOM_DECREASE_ANIM_TIME = 2.4; -const float PULSE_BLOOM_TOTAL_ANIM_TIME = PULSE_BLOOM_INCREASE_ANIM_TIME + PULSE_BLOOM_DECREASE_ANIM_TIME; -const float PULSE_BLOOM_INTENSITY_DEFAULT = 1.0f; +const float PULSE_BLOOM_TOTAL_ANIM_TIME = PULSE_BLOOM_INCREASE_ANIM_TIME + PULSE_BLOOM_DECREASE_ANIM_TIME; +const float PULSE_BLOOM_INTENSITY_DEFAULT = 1.0f; const float PULSE_BLOOM_INTENSITY_INCREASE = 3.0f; // These values depend on the button background image const Vector4 BUTTON_IMAGE_BORDER(16.0f, 16.0f, 16.0f, 20.0f); -const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons -const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); +const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons +const Vector3 BUTTON_SIZE_CONSTRAINT(0.24f, 0.09f, 1.0f); } // namespace @@ -56,12 +55,11 @@ const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); class BloomExample : public ConnectionTracker { public: - - BloomExample( Application &application ) + BloomExample(Application& application) : mApplication(application), mCurrentAnimation(0) { - application.InitSignal().Connect( this, &BloomExample::Create ); + application.InitSignal().Connect(this, &BloomExample::Create); } ~BloomExample() @@ -69,70 +67,69 @@ public: } public: - - void Create( Application& application ) + void Create(Application& application) { - Window window = application.GetWindow(); + Window window = application.GetWindow(); Vector2 windowSize = window.GetSize(); - Vector2 viewSize( windowSize ); + Vector2 viewSize(windowSize); mRootActor = Actor::New(); - mRootActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mRootActor.SetProperty( Actor::Property::SIZE, windowSize ); - window.Add( mRootActor ); + mRootActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mRootActor.SetProperty(Actor::Property::SIZE, windowSize); + window.Add(mRootActor); // Create the object that will perform the blooming work mBloomView = Dali::Toolkit::BloomView::New(); - mBloomView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mBloomView.SetProperty( Actor::Property::SIZE, viewSize ); - mRootActor.Add( mBloomView ); + mBloomView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mBloomView.SetProperty(Actor::Property::SIZE, viewSize); + mRootActor.Add(mBloomView); mBloomView.Activate(); Layer backgroundLayer = Layer::New(); - backgroundLayer.SetProperty( Actor::Property::SIZE, viewSize ); - backgroundLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mBloomView.Add( backgroundLayer ); + backgroundLayer.SetProperty(Actor::Property::SIZE, viewSize); + backgroundLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mBloomView.Add(backgroundLayer); // Create the background image - ImageView backgroundImage = ImageView::New( BACKGROUND_IMAGE_PATH ); - backgroundImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - backgroundImage.SetProperty( Actor::Property::SIZE, viewSize ); - backgroundLayer.Add( backgroundImage ); + ImageView backgroundImage = ImageView::New(BACKGROUND_IMAGE_PATH); + backgroundImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + backgroundImage.SetProperty(Actor::Property::SIZE, viewSize); + backgroundLayer.Add(backgroundImage); Layer foregroundLayer = Layer::New(); - foregroundLayer.SetProperty( Actor::Property::SIZE, viewSize ); - foregroundLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mBloomView.Add( foregroundLayer ); + foregroundLayer.SetProperty(Actor::Property::SIZE, viewSize); + foregroundLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mBloomView.Add(foregroundLayer); // Create visible actors mObjectRootActor = Actor::New(); - mObjectRootActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mObjectRootActor.SetProperty( Actor::Property::SIZE, viewSize ); - foregroundLayer.Add( mObjectRootActor ); + mObjectRootActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mObjectRootActor.SetProperty(Actor::Property::SIZE, viewSize); + foregroundLayer.Add(mObjectRootActor); - ImageView imageView = ImageView::New( UI_DIFFUSE_IMAGE ); - imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView.SetProperty( Actor::Property::SIZE, viewSize ); - mObjectRootActor.Add( imageView ); + ImageView imageView = ImageView::New(UI_DIFFUSE_IMAGE); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView.SetProperty(Actor::Property::SIZE, viewSize); + mObjectRootActor.Add(imageView); - imageView = ImageView::New( UI_DIFFUSE_IMAGE ); - imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView.SetProperty( Actor::Property::SIZE, windowSize * 0.5f ); - imageView.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 100.0f ) ); - mObjectRootActor.Add( imageView ); + imageView = ImageView::New(UI_DIFFUSE_IMAGE); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView.SetProperty(Actor::Property::SIZE, windowSize * 0.5f); + imageView.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 100.0f)); + mObjectRootActor.Add(imageView); AnimateBloomView(); PulseBloomIntensity(); // Respond to key events - window.KeyEventSignal().Connect( this, &BloomExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &BloomExample::OnKeyEvent); } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -159,41 +156,40 @@ public: } // ROTATE - mRotationAnimation = Animation::New( 5.0f ); - mRotationAnimation.AnimateBy( Property( mObjectRootActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); - mRotationAnimation.SetEndAction( Animation::DISCARD ); - mRotationAnimation.SetLooping( true ); + mRotationAnimation = Animation::New(5.0f); + mRotationAnimation.AnimateBy(Property(mObjectRootActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::YAXIS), AlphaFunction::EASE_IN_OUT); + mRotationAnimation.SetEndAction(Animation::DISCARD); + mRotationAnimation.SetLooping(true); mRotationAnimation.Play(); // TRANSLATE - mTranslationAnimation = Animation::New( 7.5f ); - mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::Property::POSITION), Vector3(100.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.5f) ); - mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::Property::POSITION), Vector3(300.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.5f, 2.5f) ); - mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::Property::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(5.0f, 2.5f) ); - mTranslationAnimation.SetEndAction( Animation::DISCARD ); - mTranslationAnimation.SetLooping( true ); + mTranslationAnimation = Animation::New(7.5f); + mTranslationAnimation.AnimateBy(Property(mObjectRootActor, Actor::Property::POSITION), Vector3(100.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.5f)); + mTranslationAnimation.AnimateBy(Property(mObjectRootActor, Actor::Property::POSITION), Vector3(300.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.5f, 2.5f)); + mTranslationAnimation.AnimateBy(Property(mObjectRootActor, Actor::Property::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(5.0f, 2.5f)); + mTranslationAnimation.SetEndAction(Animation::DISCARD); + mTranslationAnimation.SetLooping(true); //mTranslationAnimation.Play(); // BLUR - mBlurAnimation = Animation::New( 4.0f ); - mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunction::LINEAR, TimePeriod(0.0f, 0.5f) ); - mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunction::LINEAR, TimePeriod(2.0f, 0.5f) ); - mBlurAnimation.SetEndAction( Animation::DISCARD ); - mBlurAnimation.SetLooping( true ); + mBlurAnimation = Animation::New(4.0f); + mBlurAnimation.AnimateTo(Property(mBloomView, mBloomView.GetBlurStrengthPropertyIndex()), 0.0f, AlphaFunction::LINEAR, TimePeriod(0.0f, 0.5f)); + mBlurAnimation.AnimateTo(Property(mBloomView, mBloomView.GetBlurStrengthPropertyIndex()), 1.0f, AlphaFunction::LINEAR, TimePeriod(2.0f, 0.5f)); + mBlurAnimation.SetEndAction(Animation::DISCARD); + mBlurAnimation.SetLooping(true); mBlurAnimation.Play(); } void PulseBloomIntensity() { - mPulseBloomIntensityAnim = Animation::New( 2.5f ); - mPulseBloomIntensityAnim.AnimateTo( Property(mBloomView, mBloomView.GetBloomIntensityPropertyIndex()), 3.0f, AlphaFunction::BOUNCE, TimePeriod(2.5f) ); - mPulseBloomIntensityAnim.SetEndAction( Animation::DISCARD ); - mPulseBloomIntensityAnim.SetLooping( true ); + mPulseBloomIntensityAnim = Animation::New(2.5f); + mPulseBloomIntensityAnim.AnimateTo(Property(mBloomView, mBloomView.GetBloomIntensityPropertyIndex()), 3.0f, AlphaFunction::BOUNCE, TimePeriod(2.5f)); + mPulseBloomIntensityAnim.SetEndAction(Animation::DISCARD); + mPulseBloomIntensityAnim.SetLooping(true); mPulseBloomIntensityAnim.Play(); } private: - Application& mApplication; Actor mRootActor; @@ -201,20 +197,20 @@ private: Actor mObjectRootActor; unsigned int mCurrentAnimation; - Animation mRotationAnimation; - Animation mResizeAnimation; - Animation mTranslationAnimation; - Animation mBlurAnimation; - Animation mPulseBloomIntensityAnim; + Animation mRotationAnimation; + Animation mResizeAnimation; + Animation mTranslationAnimation; + Animation mBlurAnimation; + Animation mPulseBloomIntensityAnim; BloomView mBloomView; }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - BloomExample theApp( application ); + BloomExample theApp(application); application.MainLoop(); return 0; diff --git a/examples/bubble-effect/bubble-effect-example.cpp b/examples/bubble-effect/bubble-effect-example.cpp index a668384..d4a922b 100644 --- a/examples/bubble-effect/bubble-effect-example.cpp +++ b/examples/bubble-effect/bubble-effect-example.cpp @@ -15,52 +15,51 @@ * */ -#include #include #include -#include "shared/view.h" +#include #include "shared/utility.h" +#include "shared/view.h" using namespace Dali; namespace { -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const APPLICATION_TITLE( "Bubble Effect" ); -const char * const CHANGE_BACKGROUND_ICON( DEMO_IMAGE_DIR "icon-change.png" ); -const char * const CHANGE_BACKGROUND_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char * const CHANGE_BUBBLE_SHAPE_ICON( DEMO_IMAGE_DIR "icon-replace.png" ); -const char * const CHANGE_BUBBLE_SHAPE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" ); - -const char* BACKGROUND_IMAGES[]= -{ - DEMO_IMAGE_DIR "background-1.jpg", - DEMO_IMAGE_DIR "background-2.jpg", - DEMO_IMAGE_DIR "background-3.jpg", - DEMO_IMAGE_DIR "background-4.jpg", - DEMO_IMAGE_DIR "background-5.jpg", +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const APPLICATION_TITLE("Bubble Effect"); +const char* const CHANGE_BACKGROUND_ICON(DEMO_IMAGE_DIR "icon-change.png"); +const char* const CHANGE_BACKGROUND_ICON_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* const CHANGE_BUBBLE_SHAPE_ICON(DEMO_IMAGE_DIR "icon-replace.png"); +const char* const CHANGE_BUBBLE_SHAPE_ICON_SELECTED(DEMO_IMAGE_DIR "icon-replace-selected.png"); + +const char* BACKGROUND_IMAGES[] = + { + DEMO_IMAGE_DIR "background-1.jpg", + DEMO_IMAGE_DIR "background-2.jpg", + DEMO_IMAGE_DIR "background-3.jpg", + DEMO_IMAGE_DIR "background-4.jpg", + DEMO_IMAGE_DIR "background-5.jpg", }; -const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) ); +const unsigned int NUM_BACKGROUND_IMAGES(sizeof(BACKGROUND_IMAGES) / sizeof(BACKGROUND_IMAGES[0])); const char* BUBBLE_SHAPE_IMAGES[] = -{ - DEMO_IMAGE_DIR "bubble-ball.png", - DEMO_IMAGE_DIR "icon-effect-cross.png", - DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png", - DEMO_IMAGE_DIR "icon-replace.png" -}; -const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / sizeof( BUBBLE_SHAPE_IMAGES[0] ) ); + { + DEMO_IMAGE_DIR "bubble-ball.png", + DEMO_IMAGE_DIR "icon-effect-cross.png", + DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png", + DEMO_IMAGE_DIR "icon-replace.png"}; +const unsigned int NUM_BUBBLE_SHAPE_IMAGES(sizeof(BUBBLE_SHAPE_IMAGES) / sizeof(BUBBLE_SHAPE_IMAGES[0])); -const Vector2 DEFAULT_BUBBLE_SIZE( 10.f, 30.f ); -const unsigned int DEFAULT_NUMBER_OF_BUBBLES( 1000 ); +const Vector2 DEFAULT_BUBBLE_SIZE(10.f, 30.f); +const unsigned int DEFAULT_NUMBER_OF_BUBBLES(1000); -}// end LOCAL_STUFF +} // namespace // This example shows the usage of BubbleEmitter which displays lots of moving bubbles on the window. class BubbleEffectExample : public ConnectionTracker { public: - BubbleEffectExample(Application &app) + BubbleEffectExample(Application& app) : mApp(app), mBackground(), mBubbleEmitter(), @@ -68,15 +67,15 @@ public: mChangeBackgroundButton(), mChangeBubbleShapeButton(), mTimerForBubbleEmission(), - mHSVDelta( Vector3( 0.f, 0.f, 0.5f ) ), + mHSVDelta(Vector3(0.f, 0.f, 0.5f)), mCurrentTouchPosition(), mEmitPosition(), - mAnimateComponentCount( 0 ), - mNonMovementCount( 0 ), - mTimerInterval( 16 ), - mCurrentBackgroundImageId( 0 ), - mCurrentBubbleShapeImageId( 0 ), - mNeedNewAnimation( true ) + mAnimateComponentCount(0), + mNonMovementCount(0), + mTimerInterval(16), + mCurrentBackgroundImageId(0), + mCurrentBubbleShapeImageId(0), + mNeedNewAnimation(true) { // Connect to the Application's Init signal app.InitSignal().Connect(this, &BubbleEffectExample::Create); @@ -87,11 +86,10 @@ public: } private: - // The Init signal is received once (only) during the Application lifetime void Create(Application& app) { - Window window = app.GetWindow(); + Window window = app.GetWindow(); Vector2 windowSize = window.GetSize(); window.KeyEventSignal().Connect(this, &BubbleEffectExample::OnKeyEvent); @@ -99,78 +97,77 @@ private: // Creates a default view with a default tool bar. // The view is added to the window. Toolkit::ToolBar toolBar; - Layer content = DemoHelper::CreateView( app, - mBackground, - toolBar, - "", - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + Layer content = DemoHelper::CreateView(app, + mBackground, + toolBar, + "", + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Add a button to change background. (right of toolbar) mChangeBackgroundButton = Toolkit::PushButton::New(); - mChangeBackgroundButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON ); - mChangeBackgroundButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON_SELECTED ); - mChangeBackgroundButton.ClickedSignal().Connect( this, &BubbleEffectExample::OnChangeIconClicked ); - toolBar.AddControl( mChangeBackgroundButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_RIGHT, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mChangeBackgroundButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON); + mChangeBackgroundButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON_SELECTED); + mChangeBackgroundButton.ClickedSignal().Connect(this, &BubbleEffectExample::OnChangeIconClicked); + toolBar.AddControl(mChangeBackgroundButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_RIGHT, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Add a button to change bubble shape. ( left of bar ) mChangeBubbleShapeButton = Toolkit::PushButton::New(); - mChangeBubbleShapeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BUBBLE_SHAPE_ICON ); - mChangeBubbleShapeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BUBBLE_SHAPE_ICON_SELECTED ); - mChangeBubbleShapeButton.ClickedSignal().Connect( this, &BubbleEffectExample::OnChangeIconClicked ); - toolBar.AddControl( mChangeBubbleShapeButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_LEFT, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mChangeBubbleShapeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BUBBLE_SHAPE_ICON); + mChangeBubbleShapeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BUBBLE_SHAPE_ICON_SELECTED); + mChangeBubbleShapeButton.ClickedSignal().Connect(this, &BubbleEffectExample::OnChangeIconClicked); + toolBar.AddControl(mChangeBubbleShapeButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_LEFT, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create and initialize the BubbleEmitter object - mBubbleEmitter = Toolkit::BubbleEmitter::New( windowSize, - DemoHelper::LoadTexture( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ), - DEFAULT_NUMBER_OF_BUBBLES, - DEFAULT_BUBBLE_SIZE); + mBubbleEmitter = Toolkit::BubbleEmitter::New(windowSize, + DemoHelper::LoadTexture(BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId]), + DEFAULT_NUMBER_OF_BUBBLES, + DEFAULT_BUBBLE_SIZE); - mBubbleEmitter.SetBackground( DemoHelper::LoadWindowFillingTexture( window.GetSize(), BACKGROUND_IMAGES[mCurrentBackgroundImageId] ), mHSVDelta ); + mBubbleEmitter.SetBackground(DemoHelper::LoadWindowFillingTexture(window.GetSize(), BACKGROUND_IMAGES[mCurrentBackgroundImageId]), mHSVDelta); // Get the root actor of all bubbles, and add it to window. Actor bubbleRoot = mBubbleEmitter.GetRootActor(); - bubbleRoot.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - bubbleRoot.SetProperty( Actor::Property::POSITION_Z, 0.1f); // Make sure the bubbles displayed on top og the background. - content.Add( bubbleRoot ); + bubbleRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + bubbleRoot.SetProperty(Actor::Property::POSITION_Z, 0.1f); // Make sure the bubbles displayed on top og the background. + content.Add(bubbleRoot); // Set the application background - mBackground.SetProperty( Toolkit::Control::Property::BACKGROUND, BACKGROUND_IMAGES[ mCurrentBackgroundImageId ] ); + mBackground.SetProperty(Toolkit::Control::Property::BACKGROUND, BACKGROUND_IMAGES[mCurrentBackgroundImageId]); // Set up the timer to emit bubble regularly when the finger is touched down but not moved - mTimerForBubbleEmission = Timer::New( mTimerInterval ); + mTimerForBubbleEmission = Timer::New(mTimerInterval); mTimerForBubbleEmission.TickSignal().Connect(this, &BubbleEffectExample::OnTimerTick); // Connect the callback to the touch signal on the background - mBackground.TouchedSignal().Connect( this, &BubbleEffectExample::OnTouch ); + mBackground.TouchedSignal().Connect(this, &BubbleEffectExample::OnTouch); } - -/*********** + /*********** * Emit bubbles *****************/ // Set up the animation of emitting bubbles, to be efficient, every animation controls multiple emission ( 4 here ) - void SetUpAnimation( Vector2 emitPosition, Vector2 direction ) + void SetUpAnimation(Vector2 emitPosition, Vector2 direction) { - if( mNeedNewAnimation ) + if(mNeedNewAnimation) { - float duration = Random::Range(1.f, 1.5f); - mEmitAnimation = Animation::New( duration ); - mNeedNewAnimation = false; + float duration = Random::Range(1.f, 1.5f); + mEmitAnimation = Animation::New(duration); + mNeedNewAnimation = false; mAnimateComponentCount = 0; } - mBubbleEmitter.EmitBubble( mEmitAnimation, emitPosition, direction + Vector2(0.f, 30.f) /* upwards */, Vector2(300, 600) ); + mBubbleEmitter.EmitBubble(mEmitAnimation, emitPosition, direction + Vector2(0.f, 30.f) /* upwards */, Vector2(300, 600)); mAnimateComponentCount++; - if( mAnimateComponentCount % 4 ==0 ) + if(mAnimateComponentCount % 4 == 0) { mEmitAnimation.Play(); mNeedNewAnimation = true; @@ -188,14 +185,14 @@ private: { for(int i = 0; i < 4; i++) // emit 4 bubbles every timer tick { - SetUpAnimation( mCurrentTouchPosition+Vector2(rand()%5, rand()%5), Vector2(rand()%60-30, rand()%100-50) ); + SetUpAnimation(mCurrentTouchPosition + Vector2(rand() % 5, rand() % 5), Vector2(rand() % 60 - 30, rand() % 100 - 50)); } } } else { mNonMovementCount = 0; - mEmitPosition = mCurrentTouchPosition; + mEmitPosition = mCurrentTouchPosition; } return true; @@ -204,11 +201,11 @@ private: // Callback function of the touch signal on the background bool OnTouch(Dali::Actor actor, const Dali::TouchEvent& event) { - switch( event.GetState( 0 ) ) + switch(event.GetState(0)) { case PointState::DOWN: { - mCurrentTouchPosition = mEmitPosition = event.GetScreenPosition( 0 ); + mCurrentTouchPosition = mEmitPosition = event.GetScreenPosition(0); mTimerForBubbleEmission.Start(); mNonMovementCount = 0; @@ -216,13 +213,13 @@ private: } case PointState::MOTION: { - Vector2 displacement = event.GetScreenPosition( 0 ) - mCurrentTouchPosition; - mCurrentTouchPosition = event.GetScreenPosition( 0 ); + Vector2 displacement = event.GetScreenPosition(0) - mCurrentTouchPosition; + mCurrentTouchPosition = event.GetScreenPosition(0); //emit multiple bubbles along the moving direction when the finger moves quickly float step = std::min(5.f, displacement.Length()); - for( float i=0.25f; i #include #include -#include #include -#include +#include #include +#include +#include -#include -#include -#include -#include -#include #include #include +#include #include +#include +#include +#include +#include -#include "sys/stat.h" -#include #include +#include +#include "sys/stat.h" -#include #include +#include #include "shared/view.h" #define TOKEN_STRING(x) #x @@ -52,15 +52,15 @@ using namespace Dali::Toolkit; namespace { - -const char* BACKGROUND_IMAGE( "" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); +const char* BACKGROUND_IMAGE(""); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* EDIT_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* EDIT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); std::string USER_DIRECTORY; -std::string JSON_BROKEN(" \ +std::string JSON_BROKEN( + " \ { \ 'stage': \ [ \ @@ -74,7 +74,7 @@ std::string JSON_BROKEN(" \ } \ "); -std::string ReplaceQuotes(const std::string &single_quoted) +std::string ReplaceQuotes(const std::string& single_quoted) { std::string s(single_quoted); @@ -84,32 +84,32 @@ std::string ReplaceQuotes(const std::string &single_quoted) return s; } -std::string GetFileContents(const std::string &fn) +std::string GetFileContents(const std::string& fn) { - std::streampos bufferSize = 0; + std::streampos bufferSize = 0; Dali::Vector fileBuffer; - if( !Dali::FileLoader::ReadFile( fn, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) ) + if(!Dali::FileLoader::ReadFile(fn, bufferSize, fileBuffer, FileLoader::FileType::BINARY)) { return std::string(); } - return std::string( &fileBuffer[0], bufferSize ); + return std::string(&fileBuffer[0], bufferSize); }; typedef std::vector FileList; void DirectoryFileList(const std::string& directory, FileList& files) { - DIR *d; - struct dirent *dir; + DIR* d; + struct dirent* dir; d = opendir(directory.c_str()); - if (d) + if(d) { - while ((dir = readdir(d)) != NULL) + while((dir = readdir(d)) != NULL) { - if (dir->d_type == DT_REG) + if(dir->d_type == DT_REG) { - files.push_back( directory + std::string(dir->d_name) ); + files.push_back(directory + std::string(dir->d_name)); } } @@ -119,7 +119,7 @@ void DirectoryFileList(const std::string& directory, FileList& files) void DirectoryFilesByType(const std::string& dir, const std::string& fileType /* ie "json" */, FileList& files) { - typedef FileList Collection; + typedef FileList Collection; typedef FileList::iterator Iter; Collection allFiles; @@ -127,25 +127,25 @@ void DirectoryFilesByType(const std::string& dir, const std::string& fileType /* for(Iter iter = allFiles.begin(); iter != allFiles.end(); ++iter) { - size_t pos = (*iter).rfind( '.' ); - if( pos != std::string::npos ) + size_t pos = (*iter).rfind('.'); + if(pos != std::string::npos) { - if( (*iter).substr( pos+1 ) == fileType ) + if((*iter).substr(pos + 1) == fileType) { - files.push_back( (*iter) ); + files.push_back((*iter)); } } } } -const std::string ShortName( const std::string& name ) +const std::string ShortName(const std::string& name) { - size_t pos = name.rfind( '/' ); + size_t pos = name.rfind('/'); - if( pos != std::string::npos ) + if(pos != std::string::npos) { pos++; - return name.substr( pos ); + return name.substr(pos); } else { @@ -163,13 +163,19 @@ class FileWatcher public: FileWatcher(void); ~FileWatcher(void); - explicit FileWatcher(const std::string &fn) { SetFilename(fn) ; }; + explicit FileWatcher(const std::string& fn) + { + SetFilename(fn); + }; - void SetFilename(const std::string &fn); + void SetFilename(const std::string& fn); std::string GetFilename() const; - bool FileHasChanged(void); - std::string GetFileContents(void) const { return ::GetFileContents(mstringPath) ; }; + bool FileHasChanged(void); + std::string GetFileContents(void) const + { + return ::GetFileContents(mstringPath); + }; private: // compiler does @@ -178,10 +184,10 @@ private: std::time_t mLastTime; std::string mstringPath; - }; -FileWatcher::FileWatcher(void) : mLastTime(0) +FileWatcher::FileWatcher(void) +: mLastTime(0) { } @@ -214,7 +220,7 @@ FileWatcher::~FileWatcher() { } -void FileWatcher::SetFilename(const std::string &fn) +void FileWatcher::SetFilename(const std::string& fn) { mstringPath = fn; FileHasChanged(); // update last time @@ -225,9 +231,7 @@ std::string FileWatcher::GetFilename(void) const return mstringPath; } - -} // anon namespace - +} // namespace //------------------------------------------------------------------------------ // @@ -237,28 +241,30 @@ std::string FileWatcher::GetFilename(void) const class ExampleApp : public ConnectionTracker, public Toolkit::ItemFactory { public: - ExampleApp(Application &app) : mApp(app) + ExampleApp(Application& app) + : mApp(app) { app.InitSignal().Connect(this, &ExampleApp::Create); } - ~ExampleApp() {} + ~ExampleApp() + { + } public: - void SetTitle(const std::string& title) { if(!mTitleActor) { - mTitleActor = DemoHelper::CreateToolBarLabel( "" ); + mTitleActor = DemoHelper::CreateToolBarLabel(""); // Add title to the tool bar. - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER ); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER); } - mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, title); } - bool OnBackButtonPressed( Toolkit::Button button ) + bool OnBackButtonPressed(Toolkit::Button button) { OnQuitOrBack(); return true; @@ -269,32 +275,32 @@ public: Window window = mApp.GetWindow(); mTapDetector = TapGestureDetector::New(); - mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap ); + mTapDetector.DetectedSignal().Connect(this, &ExampleApp::OnTap); mFiles.clear(); mItemView = ItemView::New(*this); - mItemView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mItemView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST ); + mItemView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mItemView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLayout = DefaultItemLayout::New(DefaultItemLayout::LIST); - mLayout->SetItemSize( Vector3( window.GetSize().GetWidth(), 50, 1 ) ); + mLayout->SetItemSize(Vector3(window.GetSize().GetWidth(), 50, 1)); - mItemView.AddLayout( *mLayout ); + mItemView.AddLayout(*mLayout); - mItemView.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true ); + mItemView.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); mFiles.clear(); FileList files; - if( USER_DIRECTORY.size() ) + if(USER_DIRECTORY.size()) { - DirectoryFilesByType( USER_DIRECTORY, "json", files ); + DirectoryFilesByType(USER_DIRECTORY, "json", files); } else { - DirectoryFilesByType( DEMO_SCRIPT_DIR, "json", files ); + DirectoryFilesByType(DEMO_SCRIPT_DIR, "json", files); } std::sort(files.begin(), files.end()); @@ -304,29 +310,29 @@ public: { JsonParser parser = JsonParser::New(); - std::string data( GetFileContents( *iter ) ); + std::string data(GetFileContents(*iter)); - parser.Parse( data ); + parser.Parse(data); - if( parser.ParseError() ) + if(parser.ParseError()) { std::cout << "Parser Error:" << *iter << std::endl; std::cout << parser.GetErrorLineNumber() << "(" << parser.GetErrorColumn() << "):" << parser.GetErrorDescription() << std::endl; exit(1); } - if( parser.GetRoot() ) + if(parser.GetRoot()) { - if( const TreeNode* node = parser.GetRoot()->Find("stage") ) + if(const TreeNode* node = parser.GetRoot()->Find("stage")) { // only those with a stage section - if( node->Size() ) + if(node->Size()) { - mFiles.push_back( *iter ); + mFiles.push_back(*iter); - mItemView.InsertItem( Item(itemId, - MenuItem( ShortName( *iter ) ) ), - 0.5f ); + mItemView.InsertItem(Item(itemId, + MenuItem(ShortName(*iter))), + 0.5f); itemId++; } @@ -344,34 +350,33 @@ public: // Activate the layout Vector3 size(window.GetSize()); - mItemView.ActivateLayout(0, size, 0.0f/*immediate*/); + mItemView.ActivateLayout(0, size, 0.0f /*immediate*/); } - - void OnTap( Actor actor, const TapGesture& tap ) + void OnTap(Actor actor, const TapGesture& tap) { - ItemId id = mItemView.GetItemId( actor ); + ItemId id = mItemView.GetItemId(actor); - LoadFromFileList( id ); + LoadFromFileList(id); } Actor MenuItem(const std::string& text) { - TextLabel label = TextLabel::New( ShortName( text ) ); - label.SetStyleName( "BuilderLabel" ); - label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + TextLabel label = TextLabel::New(ShortName(text)); + label.SetStyleName("BuilderLabel"); + label.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); // Hook up tap detector - mTapDetector.Attach( label ); + mTapDetector.Attach(label); return label; } bool OnTimer() { - if( mFileWatcher.FileHasChanged() ) + if(mFileWatcher.FileHasChanged()) { - LoadFromFile( mFileWatcher.GetFilename() ); + LoadFromFile(mFileWatcher.GetFilename()); } return true; @@ -382,26 +387,26 @@ public: Window window = mApp.GetWindow(); builder = Builder::New(); - builder.QuitSignal().Connect( this, &ExampleApp::OnQuitOrBack ); + builder.QuitSignal().Connect(this, &ExampleApp::OnQuitOrBack); Property::Map defaultDirs; - defaultDirs[ TOKEN_STRING(DEMO_IMAGE_DIR) ] = DEMO_IMAGE_DIR; - defaultDirs[ TOKEN_STRING(DEMO_MODEL_DIR) ] = DEMO_MODEL_DIR; - defaultDirs[ TOKEN_STRING(DEMO_SCRIPT_DIR) ] = DEMO_SCRIPT_DIR; + defaultDirs[TOKEN_STRING(DEMO_IMAGE_DIR)] = DEMO_IMAGE_DIR; + defaultDirs[TOKEN_STRING(DEMO_MODEL_DIR)] = DEMO_MODEL_DIR; + defaultDirs[TOKEN_STRING(DEMO_SCRIPT_DIR)] = DEMO_SCRIPT_DIR; - builder.AddConstants( defaultDirs ); + builder.AddConstants(defaultDirs); // render tasks may have been setup last load so remove them RenderTaskList taskList = window.GetRenderTaskList(); - if( taskList.GetTaskCount() > 1 ) + if(taskList.GetTaskCount() > 1) { typedef std::vector Collection; - typedef Collection::iterator ColIter; - Collection tasks; + typedef Collection::iterator ColIter; + Collection tasks; for(unsigned int i = 1; i < taskList.GetTaskCount(); ++i) { - tasks.push_back( taskList.GetTask(i) ); + tasks.push_back(taskList.GetTask(i)); } for(ColIter iter = tasks.begin(); iter != tasks.end(); ++iter) @@ -410,15 +415,15 @@ public: } RenderTask defaultTask = taskList.GetTask(0); - defaultTask.SetSourceActor( window.GetRootLayer() ); - defaultTask.SetFrameBuffer( FrameBuffer() ); + defaultTask.SetSourceActor(window.GetRootLayer()); + defaultTask.SetFrameBuffer(FrameBuffer()); } unsigned int numChildren = layer.GetChildCount(); - for(unsigned int i=0; i( Actor::Property::SIZE ); + mBuilderLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mBuilderLayer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + Dali::Vector3 size = mApp.GetWindow().GetRootLayer().GetCurrentProperty(Actor::Property::SIZE); size.y -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight; - mBuilderLayer.SetProperty( Actor::Property::SIZE, size ); + mBuilderLayer.SetProperty(Actor::Property::SIZE, size); - mNavigationView.Push( mBuilderLayer ); + mNavigationView.Push(mBuilderLayer); } void Create(Application& app) @@ -465,12 +469,12 @@ public: window.KeyEventSignal().Connect(this, &ExampleApp::OnKeyEvent); - Layer contents = DemoHelper::CreateView( app, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); + Layer contents = DemoHelper::CreateView(app, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); SetTitle("Select Example"); @@ -478,40 +482,34 @@ public: // Create an edit mode button. (left of toolbar) Toolkit::PushButton backButton = Toolkit::PushButton::New(); - backButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE ); - backButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED ); - backButton.ClickedSignal().Connect( this, &ExampleApp::OnBackButtonPressed); - backButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( backButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + backButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE); + backButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED); + backButton.ClickedSignal().Connect(this, &ExampleApp::OnBackButtonPressed); + backButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(backButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); mNavigationView = Toolkit::NavigationView::New(); - mNavigationView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mNavigationView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mNavigationView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mNavigationView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); - window.Add( mNavigationView ); + window.Add(mNavigationView); // Set up the background gradient. Property::Array stopOffsets; - stopOffsets.PushBack( 0.0f ); - stopOffsets.PushBack( 1.0f ); + stopOffsets.PushBack(0.0f); + stopOffsets.PushBack(1.0f); Property::Array stopColors; - stopColors.PushBack( Color::WHITE ); - stopColors.PushBack( Vector4( 0.45f, 0.70f, 0.80f, 1.0f ) ); // Medium bright, pastel blue + stopColors.PushBack(Color::WHITE); + stopColors.PushBack(Vector4(0.45f, 0.70f, 0.80f, 1.0f)); // Medium bright, pastel blue const float percentageWindowHeight = window.GetSize().GetHeight() * 0.6f; - mNavigationView.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map() - .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::GRADIENT ) - .Add( Toolkit::GradientVisual::Property::STOP_OFFSET, stopOffsets ) - .Add( Toolkit::GradientVisual::Property::STOP_COLOR, stopColors ) - .Add( Toolkit::GradientVisual::Property::START_POSITION, Vector2( 0.0f, -percentageWindowHeight ) ) - .Add( Toolkit::GradientVisual::Property::END_POSITION, Vector2( 0.0f, percentageWindowHeight ) ) - .Add( Toolkit::GradientVisual::Property::UNITS, Toolkit::GradientVisual::Units::USER_SPACE ) ); + mNavigationView.SetProperty(Toolkit::Control::Property::BACKGROUND, Dali::Property::Map().Add(Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::GRADIENT).Add(Toolkit::GradientVisual::Property::STOP_OFFSET, stopOffsets).Add(Toolkit::GradientVisual::Property::STOP_COLOR, stopColors).Add(Toolkit::GradientVisual::Property::START_POSITION, Vector2(0.0f, -percentageWindowHeight)).Add(Toolkit::GradientVisual::Property::END_POSITION, Vector2(0.0f, percentageWindowHeight)).Add(Toolkit::GradientVisual::Property::UNITS, Toolkit::GradientVisual::Units::USER_SPACE)); SetUpItemView(); - mNavigationView.Push( mItemView ); + mNavigationView.Push(mItemView); - mTimer = Timer::New( 500 ); // ms - mTimer.TickSignal().Connect( this, &ExampleApp::OnTimer); + mTimer = Timer::New(500); // ms + mTimer.TickSignal().Connect(this, &ExampleApp::OnTimer); mTimer.Start(); } // Create(app) @@ -523,8 +521,8 @@ public: virtual Actor NewItem(unsigned int itemId) { - DALI_ASSERT_DEBUG( itemId < mFiles.size() ); - return MenuItem( ShortName( mFiles[itemId] ) ); + DALI_ASSERT_DEBUG(itemId < mFiles.size()); + return MenuItem(ShortName(mFiles[itemId])); } /** @@ -534,7 +532,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { OnQuitOrBack(); } @@ -546,7 +544,7 @@ public: */ void OnQuitOrBack() { - if ( mItemView.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) + if(mItemView.GetProperty(Actor::Property::CONNECTED_TO_SCENE)) { mApp.Quit(); } @@ -559,14 +557,14 @@ public: private: Application& mApp; - ItemLayoutPtr mLayout; - ItemView mItemView; + ItemLayoutPtr mLayout; + ItemView mItemView; Toolkit::NavigationView mNavigationView; Toolkit::Control mView; Toolkit::ToolBar mToolBar; - TextLabel mTitleActor; + TextLabel mTitleActor; Layer mBuilderLayer; @@ -578,7 +576,7 @@ private: FileList mFiles; FileWatcher mFileWatcher; - Timer mTimer; + Timer mTimer; }; //------------------------------------------------------------------------------ @@ -586,7 +584,7 @@ private: // // //------------------------------------------------------------------------------ -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { if(argc > 2) { diff --git a/examples/buttons/buttons-example.cpp b/examples/buttons/buttons-example.cpp index 79649b5..502902f 100644 --- a/examples/buttons/buttons-example.cpp +++ b/examples/buttons/buttons-example.cpp @@ -15,10 +15,10 @@ * */ -#include "shared/view.h" -#include #include #include +#include +#include "shared/view.h" using namespace Dali; @@ -26,12 +26,10 @@ using namespace Dali; // "DP" stands for Device independent Pixels #define DP(x) x - namespace { - const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg"; -const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; +const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; const char* const TOOLBAR_TITLE = "Buttons"; @@ -46,22 +44,22 @@ const char* const BIG_IMAGE_3 = DEMO_IMAGE_DIR "gallery-large-13.jpg"; const char* const ENABLED_IMAGE = DEMO_IMAGE_DIR "item-select-check.png"; -const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); +const Vector4 BACKGROUND_COLOUR(1.0f, 1.0f, 1.0f, 0.15f); // Layout sizes -const int RADIO_LABEL_THUMBNAIL_SIZE = 60; +const int RADIO_LABEL_THUMBNAIL_SIZE = 60; const int RADIO_LABEL_THUMBNAIL_SIZE_SMALL = 40; -const int RADIO_IMAGE_SPACING = 8; -const int BUTTON_HEIGHT = 48; +const int RADIO_IMAGE_SPACING = 8; +const int BUTTON_HEIGHT = 48; -const int MARGIN_SIZE = 10; -const int TOP_MARGIN = 85; +const int MARGIN_SIZE = 10; +const int TOP_MARGIN = 85; const int GROUP2_HEIGHT = 238; const int GROUP1_HEIGHT = 120; const int GROUP3_HEIGHT = 190; const int GROUP4_HEIGHT = BUTTON_HEIGHT + MARGIN_SIZE * 2; -} // namespace +} // namespace /** This example shows how to create and use different buttons. * @@ -71,15 +69,14 @@ const int GROUP4_HEIGHT = BUTTON_HEIGHT + MARGIN_SIZE * 2; * Selecting one of these will enable/disable the image loading push button * 4. A group of check boxes */ -class ButtonsController: public ConnectionTracker +class ButtonsController : public ConnectionTracker { - public: - - ButtonsController( Application& application ) - : mApplication( application ) +public: + ButtonsController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ButtonsController::Create ); + mApplication.InitSignal().Connect(this, &ButtonsController::Create); } ~ButtonsController() @@ -87,7 +84,7 @@ class ButtonsController: public ConnectionTracker // Nothing to do here } - void Create( Application& application ) + void Create(Application& application) { // The Init signal is received once (only) during the Application lifetime @@ -96,272 +93,272 @@ class ButtonsController: public ConnectionTracker // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - TOOLBAR_TITLE ); - - Toolkit::TableView contentTable = Toolkit::TableView::New( 4, 1 ); - contentTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - contentTable.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - contentTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - contentTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - contentTable.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5f ) ); - - for( unsigned int i = 0; i < contentTable.GetRows(); ++i ) + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + TOOLBAR_TITLE); + + Toolkit::TableView contentTable = Toolkit::TableView::New(4, 1); + contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + contentTable.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + contentTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + contentTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + contentTable.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5f)); + + for(unsigned int i = 0; i < contentTable.GetRows(); ++i) { - contentTable.SetFitHeight( i ); + contentTable.SetFitHeight(i); } - contentTable.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, TOP_MARGIN )); + contentTable.SetProperty(Actor::Property::POSITION, Vector2(0.0f, TOP_MARGIN)); - mContentLayer.Add( contentTable ); + mContentLayer.Add(contentTable); // Image selector radio group - Toolkit::TableView radioGroup2Background = Toolkit::TableView::New( 2, 2 ); - radioGroup2Background.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - radioGroup2Background.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - radioGroup2Background.SetBackgroundColor( BACKGROUND_COLOUR ); - radioGroup2Background.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); - radioGroup2Background.SetFitHeight( 0 ); - radioGroup2Background.SetFitHeight( 1 ); - radioGroup2Background.SetFitWidth( 0 ); - - contentTable.Add( radioGroup2Background ); - - Toolkit::TableView radioButtonsGroup2 = Toolkit::TableView::New( 3, 1 ); - radioButtonsGroup2.SetCellPadding( Size( 0.0f, MARGIN_SIZE * 0.5f ) ); - radioButtonsGroup2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - for( unsigned int i = 0; i < radioButtonsGroup2.GetRows(); ++i ) + Toolkit::TableView radioGroup2Background = Toolkit::TableView::New(2, 2); + radioGroup2Background.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + radioGroup2Background.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + radioGroup2Background.SetBackgroundColor(BACKGROUND_COLOUR); + radioGroup2Background.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); + radioGroup2Background.SetFitHeight(0); + radioGroup2Background.SetFitHeight(1); + radioGroup2Background.SetFitWidth(0); + + contentTable.Add(radioGroup2Background); + + Toolkit::TableView radioButtonsGroup2 = Toolkit::TableView::New(3, 1); + radioButtonsGroup2.SetCellPadding(Size(0.0f, MARGIN_SIZE * 0.5f)); + radioButtonsGroup2.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + for(unsigned int i = 0; i < radioButtonsGroup2.GetRows(); ++i) { - radioButtonsGroup2.SetFitHeight( i ); + radioButtonsGroup2.SetFitHeight(i); } - radioButtonsGroup2.SetFitWidth( 0 ); + radioButtonsGroup2.SetFitWidth(0); - radioGroup2Background.AddChild( radioButtonsGroup2, Toolkit::TableView::CellPosition( 0, 0 ) ); + radioGroup2Background.AddChild(radioButtonsGroup2, Toolkit::TableView::CellPosition(0, 0)); // TableView to lay out 3x Radio buttons on the left, and 3x Image thumbnails on the right. - Toolkit::TableView imageSelectTableView = Toolkit::TableView::New( 3, 2 ); - imageSelectTableView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - imageSelectTableView.SetFitHeight( 0 ); - imageSelectTableView.SetFitHeight( 1 ); - imageSelectTableView.SetFitHeight( 2 ); - imageSelectTableView.SetFitWidth( 0 ); - imageSelectTableView.SetFitWidth( 1 ); - imageSelectTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + Toolkit::TableView imageSelectTableView = Toolkit::TableView::New(3, 2); + imageSelectTableView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + imageSelectTableView.SetFitHeight(0); + imageSelectTableView.SetFitHeight(1); + imageSelectTableView.SetFitHeight(2); + imageSelectTableView.SetFitWidth(0); + imageSelectTableView.SetFitWidth(1); + imageSelectTableView.SetCellPadding(Vector2(6.0f, 0.0f)); - radioButtonsGroup2.Add( imageSelectTableView ); + radioButtonsGroup2.Add(imageSelectTableView); int radioY = 0; // Radio 1 { - Toolkit::ImageView image = Toolkit::ImageView::New( SMALL_IMAGE_1 ); - image.SetProperty( Actor::Property::SIZE, Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); + Toolkit::ImageView image = Toolkit::ImageView::New(SMALL_IMAGE_1); + image.SetProperty(Actor::Property::SIZE, Vector2(DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE))); - mRadioButtonImage1 = Dali::Toolkit::RadioButton::New( "1" ); - mRadioButtonImage1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mRadioButtonImage1.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mRadioButtonImage1.SetProperty( Actor::Property::POSITION, Vector2( 0, DP(radioY) )); - mRadioButtonImage1.SetProperty( Toolkit::Button::Property::SELECTED, true ); + mRadioButtonImage1 = Dali::Toolkit::RadioButton::New("1"); + mRadioButtonImage1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mRadioButtonImage1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mRadioButtonImage1.SetProperty(Actor::Property::POSITION, Vector2(0, DP(radioY))); + mRadioButtonImage1.SetProperty(Toolkit::Button::Property::SELECTED, true); - imageSelectTableView.AddChild( mRadioButtonImage1, Toolkit::TableView::CellPosition( 0, 0 ) ); - imageSelectTableView.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) ); + imageSelectTableView.AddChild(mRadioButtonImage1, Toolkit::TableView::CellPosition(0, 0)); + imageSelectTableView.AddChild(image, Toolkit::TableView::CellPosition(0, 1)); } // Radio 2 { radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING; - Toolkit::ImageView image = Toolkit::ImageView::New( SMALL_IMAGE_2 ); - image.SetProperty( Actor::Property::SIZE, Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); + Toolkit::ImageView image = Toolkit::ImageView::New(SMALL_IMAGE_2); + image.SetProperty(Actor::Property::SIZE, Vector2(DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE))); - mRadioButtonImage2 = Dali::Toolkit::RadioButton::New( "2" ); - mRadioButtonImage2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mRadioButtonImage2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mRadioButtonImage2.SetProperty( Actor::Property::POSITION, Vector2( 0, DP(radioY) )); + mRadioButtonImage2 = Dali::Toolkit::RadioButton::New("2"); + mRadioButtonImage2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mRadioButtonImage2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mRadioButtonImage2.SetProperty(Actor::Property::POSITION, Vector2(0, DP(radioY))); - imageSelectTableView.AddChild( mRadioButtonImage2, Toolkit::TableView::CellPosition( 1, 0 ) ); - imageSelectTableView.AddChild( image, Toolkit::TableView::CellPosition( 1, 1 ) ); + imageSelectTableView.AddChild(mRadioButtonImage2, Toolkit::TableView::CellPosition(1, 0)); + imageSelectTableView.AddChild(image, Toolkit::TableView::CellPosition(1, 1)); } // Radio 3 { radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING; - Toolkit::ImageView image = Toolkit::ImageView::New( SMALL_IMAGE_3 ); - image.SetProperty( Actor::Property::SIZE, Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); + Toolkit::ImageView image = Toolkit::ImageView::New(SMALL_IMAGE_3); + image.SetProperty(Actor::Property::SIZE, Vector2(DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE))); - mRadioButtonImage3 = Dali::Toolkit::RadioButton::New( "3" ); - mRadioButtonImage3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mRadioButtonImage3.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mRadioButtonImage3.SetProperty( Actor::Property::POSITION, Vector2( 0, DP(radioY) )); + mRadioButtonImage3 = Dali::Toolkit::RadioButton::New("3"); + mRadioButtonImage3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mRadioButtonImage3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mRadioButtonImage3.SetProperty(Actor::Property::POSITION, Vector2(0, DP(radioY))); - imageSelectTableView.AddChild( mRadioButtonImage3, Toolkit::TableView::CellPosition( 2, 0 ) ); - imageSelectTableView.AddChild( image, Toolkit::TableView::CellPosition( 2, 1 ) ); + imageSelectTableView.AddChild(mRadioButtonImage3, Toolkit::TableView::CellPosition(2, 0)); + imageSelectTableView.AddChild(image, Toolkit::TableView::CellPosition(2, 1)); } // Create select button mUpdateButton = Toolkit::PushButton::New(); - mUpdateButton.SetProperty( Toolkit::Button::Property::LABEL, "Select" ); - mUpdateButton.SetProperty( Dali::Actor::Property::NAME, "selectButton" ); - mUpdateButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mUpdateButton.SetProperty(Toolkit::Button::Property::LABEL, "Select"); + mUpdateButton.SetProperty(Dali::Actor::Property::NAME, "selectButton"); + mUpdateButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); - mUpdateButton.ClickedSignal().Connect( this, &ButtonsController::OnButtonClicked ); + mUpdateButton.ClickedSignal().Connect(this, &ButtonsController::OnButtonClicked); - radioGroup2Background.AddChild( mUpdateButton, Toolkit::TableView::CellPosition( 1, 0 ) ); + radioGroup2Background.AddChild(mUpdateButton, Toolkit::TableView::CellPosition(1, 0)); // ImageView to display selected image - mImage = Toolkit::ImageView::New( BIG_IMAGE_1 ); - mImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mImage.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - radioGroup2Background.AddChild( mImage, Toolkit::TableView::CellPosition( 0, 1, 2, 1 ) ); + mImage = Toolkit::ImageView::New(BIG_IMAGE_1); + mImage.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mImage.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + radioGroup2Background.AddChild(mImage, Toolkit::TableView::CellPosition(0, 1, 2, 1)); // The enable/disable radio group - Toolkit::TableView radioGroup1Background = Toolkit::TableView::New( 1, 1 ); - radioGroup1Background.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - radioGroup1Background.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - radioGroup1Background.SetBackgroundColor( BACKGROUND_COLOUR ); - radioGroup1Background.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); - radioGroup1Background.SetFitHeight( 0 ); + Toolkit::TableView radioGroup1Background = Toolkit::TableView::New(1, 1); + radioGroup1Background.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + radioGroup1Background.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + radioGroup1Background.SetBackgroundColor(BACKGROUND_COLOUR); + radioGroup1Background.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); + radioGroup1Background.SetFitHeight(0); - contentTable.Add( radioGroup1Background ); + contentTable.Add(radioGroup1Background); // Radio group - Toolkit::TableView radioButtonsGroup1 = Toolkit::TableView::New( 2, 1 ); - radioButtonsGroup1.SetCellPadding( Size( 0.0f, MARGIN_SIZE * 0.5f ) ); - radioButtonsGroup1.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - for( unsigned int i = 0; i < radioButtonsGroup1.GetRows(); ++i ) + Toolkit::TableView radioButtonsGroup1 = Toolkit::TableView::New(2, 1); + radioButtonsGroup1.SetCellPadding(Size(0.0f, MARGIN_SIZE * 0.5f)); + radioButtonsGroup1.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + for(unsigned int i = 0; i < radioButtonsGroup1.GetRows(); ++i) { - radioButtonsGroup1.SetFitHeight( i ); + radioButtonsGroup1.SetFitHeight(i); } - radioButtonsGroup1.SetFitWidth( 0 ); + radioButtonsGroup1.SetFitWidth(0); - radioGroup1Background.Add( radioButtonsGroup1 ); + radioGroup1Background.Add(radioButtonsGroup1); // TableView to lay out 2x Radio buttons on the left, and 1x Tick image on the right. - Toolkit::TableView tableView = Toolkit::TableView::New( 2, 2 ); - tableView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - tableView.SetFitHeight( 0 ); - tableView.SetFitHeight( 1 ); - tableView.SetFitWidth( 0 ); - tableView.SetFitWidth( 1 ); + Toolkit::TableView tableView = Toolkit::TableView::New(2, 2); + tableView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + tableView.SetFitHeight(0); + tableView.SetFitHeight(1); + tableView.SetFitWidth(0); + tableView.SetFitWidth(1); - Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( "Select enabled" ); - textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); - textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); - textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel textLabel = Toolkit::TextLabel::New("Select enabled"); + textLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH); + textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); + textLabel.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - Toolkit::ImageView image = Toolkit::ImageView::New( ENABLED_IMAGE ); - image.SetProperty( Actor::Property::SIZE, Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); - image.SetProperty( Actor::Property::PADDING, Padding( DP(20.0f), 0.0f, 0.0f, 0.0f ) ); - tableView.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) ); + Toolkit::ImageView image = Toolkit::ImageView::New(ENABLED_IMAGE); + image.SetProperty(Actor::Property::SIZE, Vector2(DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE))); + image.SetProperty(Actor::Property::PADDING, Padding(DP(20.0f), 0.0f, 0.0f, 0.0f)); + tableView.AddChild(image, Toolkit::TableView::CellPosition(0, 1)); - radioButtonsGroup1.Add( tableView ); + radioButtonsGroup1.Add(tableView); // First radio button { - Toolkit::RadioButton radioButton = Dali::Toolkit::RadioButton::New( "Select enabled" ); - radioButton.SetProperty( Dali::Actor::Property::NAME, "radioSelectEnable" ); - radioButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - radioButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - radioButton.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 )); - radioButton.SetProperty( Toolkit::Button::Property::SELECTED, true ); + Toolkit::RadioButton radioButton = Dali::Toolkit::RadioButton::New("Select enabled"); + radioButton.SetProperty(Dali::Actor::Property::NAME, "radioSelectEnable"); + radioButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + radioButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + radioButton.SetProperty(Actor::Property::POSITION, Vector2(0, 0)); + radioButton.SetProperty(Toolkit::Button::Property::SELECTED, true); - radioButton.StateChangedSignal().Connect( this, &ButtonsController::EnableSelectButton ); + radioButton.StateChangedSignal().Connect(this, &ButtonsController::EnableSelectButton); - tableView.AddChild( radioButton, Toolkit::TableView::CellPosition( 0, 0 ) ); + tableView.AddChild(radioButton, Toolkit::TableView::CellPosition(0, 0)); } // Second radio button { - Toolkit::RadioButton radioButton = Dali::Toolkit::RadioButton::New( "Select disabled" ); - radioButton.SetProperty( Dali::Actor::Property::NAME, "radioSelectDisable" ); - radioButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - radioButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - radioButton.SetProperty( Actor::Property::POSITION, Vector2( 0, DP(50) )); + Toolkit::RadioButton radioButton = Dali::Toolkit::RadioButton::New("Select disabled"); + radioButton.SetProperty(Dali::Actor::Property::NAME, "radioSelectDisable"); + radioButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + radioButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + radioButton.SetProperty(Actor::Property::POSITION, Vector2(0, DP(50))); - radioButton.StateChangedSignal().Connect( this, &ButtonsController::EnableSelectButton ); + radioButton.StateChangedSignal().Connect(this, &ButtonsController::EnableSelectButton); - tableView.AddChild( radioButton, Toolkit::TableView::CellPosition( 1, 0 ) ); + tableView.AddChild(radioButton, Toolkit::TableView::CellPosition(1, 0)); } // CheckBoxes - Toolkit::TableView checkBoxBackground = Toolkit::TableView::New( 3, 1 ); - checkBoxBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - checkBoxBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - checkBoxBackground.SetBackgroundColor( BACKGROUND_COLOUR ); - checkBoxBackground.SetCellPadding( Size( MARGIN_SIZE / 2.0f, MARGIN_SIZE / 2.0f ) ); + Toolkit::TableView checkBoxBackground = Toolkit::TableView::New(3, 1); + checkBoxBackground.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + checkBoxBackground.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + checkBoxBackground.SetBackgroundColor(BACKGROUND_COLOUR); + checkBoxBackground.SetCellPadding(Size(MARGIN_SIZE / 2.0f, MARGIN_SIZE / 2.0f)); - for( unsigned int i = 0; i < checkBoxBackground.GetRows(); ++i ) + for(unsigned int i = 0; i < checkBoxBackground.GetRows(); ++i) { - checkBoxBackground.SetFitHeight( i ); + checkBoxBackground.SetFitHeight(i); } - contentTable.Add( checkBoxBackground ); + contentTable.Add(checkBoxBackground); { mCheckboxButton1 = Toolkit::CheckBoxButton::New(); - mCheckboxButton1.SetProperty( Dali::Actor::Property::NAME, "checkbox1" ); - mCheckboxButton1.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox1 is unselected" ); - mCheckboxButton1.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesSelected ); - mCheckboxButton1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mCheckboxButton1.SetProperty(Dali::Actor::Property::NAME, "checkbox1"); + mCheckboxButton1.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox1 is unselected"); + mCheckboxButton1.StateChangedSignal().Connect(this, &ButtonsController::OnCheckBoxesSelected); + mCheckboxButton1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); - checkBoxBackground.Add( mCheckboxButton1 ); + checkBoxBackground.Add(mCheckboxButton1); } { mCheckboxButton2 = Toolkit::CheckBoxButton::New(); - mCheckboxButton2.SetProperty( Dali::Actor::Property::NAME, "checkbox2" ); - mCheckboxButton2.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox2 is selected" ); - mCheckboxButton2.SetProperty( Toolkit::Button::Property::SELECTED, true ); - mCheckboxButton2.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesSelected ); - mCheckboxButton2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mCheckboxButton2.SetProperty(Dali::Actor::Property::NAME, "checkbox2"); + mCheckboxButton2.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox2 is selected"); + mCheckboxButton2.SetProperty(Toolkit::Button::Property::SELECTED, true); + mCheckboxButton2.StateChangedSignal().Connect(this, &ButtonsController::OnCheckBoxesSelected); + mCheckboxButton2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); - checkBoxBackground.Add( mCheckboxButton2 ); + checkBoxBackground.Add(mCheckboxButton2); } { mCheckboxButton3 = Toolkit::CheckBoxButton::New(); - mCheckboxButton3.SetProperty( Dali::Actor::Property::NAME, "checkbox3" ); - mCheckboxButton3.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox3 is unselected" ); - mCheckboxButton3.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesSelected ); - mCheckboxButton3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mCheckboxButton3.SetProperty(Dali::Actor::Property::NAME, "checkbox3"); + mCheckboxButton3.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox3 is unselected"); + mCheckboxButton3.StateChangedSignal().Connect(this, &ButtonsController::OnCheckBoxesSelected); + mCheckboxButton3.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); - checkBoxBackground.Add( mCheckboxButton3 ); + checkBoxBackground.Add(mCheckboxButton3); } // Create togglabe button - Toolkit::TableView toggleBackground = Toolkit::TableView::New( 3, 1 ); - toggleBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - toggleBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - toggleBackground.SetBackgroundColor( BACKGROUND_COLOUR ); - toggleBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); + Toolkit::TableView toggleBackground = Toolkit::TableView::New(3, 1); + toggleBackground.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + toggleBackground.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + toggleBackground.SetBackgroundColor(BACKGROUND_COLOUR); + toggleBackground.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); - for( unsigned int i = 0; i < toggleBackground.GetRows(); ++i ) + for(unsigned int i = 0; i < toggleBackground.GetRows(); ++i) { - toggleBackground.SetFitHeight( i ); + toggleBackground.SetFitHeight(i); } - contentTable.Add( toggleBackground ); + contentTable.Add(toggleBackground); mToggleButton = Toolkit::PushButton::New(); - mToggleButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true ); - mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Unselected" ); - mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mToggleButton.StateChangedSignal().Connect( this, &ButtonsController::OnButtonSelected ); + mToggleButton.SetProperty(Toolkit::Button::Property::TOGGLABLE, true); + mToggleButton.SetProperty(Toolkit::Button::Property::LABEL, "Unselected"); + mToggleButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mToggleButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mToggleButton.StateChangedSignal().Connect(this, &ButtonsController::OnButtonSelected); - toggleBackground.Add( mToggleButton ); + toggleBackground.Add(mToggleButton); } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { // Exit application when click back or escape. mApplication.Quit(); @@ -369,60 +366,60 @@ class ButtonsController: public ConnectionTracker } } - bool OnButtonSelected( Toolkit::Button button ) + bool OnButtonSelected(Toolkit::Button button) { - Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( button ); - if( pushButton ) + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast(button); + if(pushButton) { - bool isSelected = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get(); - if( isSelected ) + bool isSelected = button.GetProperty(Toolkit::Button::Property::SELECTED).Get(); + if(isSelected) { - pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Selected" ); + pushButton.SetProperty(Toolkit::Button::Property::LABEL, "Selected"); } else { - pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Unselected" ); + pushButton.SetProperty(Toolkit::Button::Property::LABEL, "Unselected"); } } return true; } - bool EnableSelectButton( Toolkit::Button button ) + bool EnableSelectButton(Toolkit::Button button) { - bool isSelected = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get(); - if( !isSelected ) + bool isSelected = button.GetProperty(Toolkit::Button::Property::SELECTED).Get(); + if(!isSelected) { return true; } - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "radioSelectEnable" ) + if(button.GetProperty(Dali::Actor::Property::NAME) == "radioSelectEnable") { - mUpdateButton.SetProperty( Toolkit::Button::Property::DISABLED, false ); + mUpdateButton.SetProperty(Toolkit::Button::Property::DISABLED, false); - mRadioButtonImage1.SetProperty( Toolkit::Button::Property::DISABLED, false ); - mRadioButtonImage2.SetProperty( Toolkit::Button::Property::DISABLED, false ); - mRadioButtonImage3.SetProperty( Toolkit::Button::Property::DISABLED, false ); + mRadioButtonImage1.SetProperty(Toolkit::Button::Property::DISABLED, false); + mRadioButtonImage2.SetProperty(Toolkit::Button::Property::DISABLED, false); + mRadioButtonImage3.SetProperty(Toolkit::Button::Property::DISABLED, false); - mCheckboxButton1.SetProperty( Toolkit::Button::Property::DISABLED, false ); - mCheckboxButton2.SetProperty( Toolkit::Button::Property::DISABLED, false ); - mCheckboxButton3.SetProperty( Toolkit::Button::Property::DISABLED, false ); + mCheckboxButton1.SetProperty(Toolkit::Button::Property::DISABLED, false); + mCheckboxButton2.SetProperty(Toolkit::Button::Property::DISABLED, false); + mCheckboxButton3.SetProperty(Toolkit::Button::Property::DISABLED, false); - mToggleButton.SetProperty( Toolkit::Button::Property::DISABLED, false ); + mToggleButton.SetProperty(Toolkit::Button::Property::DISABLED, false); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "radioSelectDisable" ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == "radioSelectDisable") { - mUpdateButton.SetProperty( Toolkit::Button::Property::DISABLED, true ); + mUpdateButton.SetProperty(Toolkit::Button::Property::DISABLED, true); - mRadioButtonImage1.SetProperty( Toolkit::Button::Property::DISABLED, true ); - mRadioButtonImage2.SetProperty( Toolkit::Button::Property::DISABLED, true ); - mRadioButtonImage3.SetProperty( Toolkit::Button::Property::DISABLED, true ); + mRadioButtonImage1.SetProperty(Toolkit::Button::Property::DISABLED, true); + mRadioButtonImage2.SetProperty(Toolkit::Button::Property::DISABLED, true); + mRadioButtonImage3.SetProperty(Toolkit::Button::Property::DISABLED, true); - mCheckboxButton1.SetProperty( Toolkit::Button::Property::DISABLED, true ); - mCheckboxButton2.SetProperty( Toolkit::Button::Property::DISABLED, true ); - mCheckboxButton3.SetProperty( Toolkit::Button::Property::DISABLED, true ); + mCheckboxButton1.SetProperty(Toolkit::Button::Property::DISABLED, true); + mCheckboxButton2.SetProperty(Toolkit::Button::Property::DISABLED, true); + mCheckboxButton3.SetProperty(Toolkit::Button::Property::DISABLED, true); - mToggleButton.SetProperty( Toolkit::Button::Property::DISABLED, true ); + mToggleButton.SetProperty(Toolkit::Button::Property::DISABLED, true); } return true; @@ -430,57 +427,57 @@ class ButtonsController: public ConnectionTracker bool OnButtonClicked(Toolkit::Button button) { - if( mRadioButtonImage1.GetProperty( Toolkit::Button::Property::SELECTED ).Get() ) + if(mRadioButtonImage1.GetProperty(Toolkit::Button::Property::SELECTED).Get()) { - mImage.SetImage( BIG_IMAGE_1 ); + mImage.SetImage(BIG_IMAGE_1); } - else if( mRadioButtonImage2.GetProperty( Toolkit::Button::Property::SELECTED ).Get() ) + else if(mRadioButtonImage2.GetProperty(Toolkit::Button::Property::SELECTED).Get()) { - mImage.SetImage( BIG_IMAGE_2 ); + mImage.SetImage(BIG_IMAGE_2); } - else if( mRadioButtonImage3.GetProperty( Toolkit::Button::Property::SELECTED ).Get() ) + else if(mRadioButtonImage3.GetProperty(Toolkit::Button::Property::SELECTED).Get()) { - mImage.SetImage( BIG_IMAGE_3 ); + mImage.SetImage(BIG_IMAGE_3); } return true; } - bool OnCheckBoxesSelected( Toolkit::Button button ) + bool OnCheckBoxesSelected(Toolkit::Button button) { - bool isSelected = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get(); - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "checkbox1" ) + bool isSelected = button.GetProperty(Toolkit::Button::Property::SELECTED).Get(); + if(button.GetProperty(Dali::Actor::Property::NAME) == "checkbox1") { - if( isSelected ) + if(isSelected) { - button.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox1 is selected"); + button.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox1 is selected"); } else { - button.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox1 is unselected"); + button.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox1 is unselected"); } } - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "checkbox2" ) + if(button.GetProperty(Dali::Actor::Property::NAME) == "checkbox2") { - if( isSelected ) + if(isSelected) { - button.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox2 is selected"); + button.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox2 is selected"); } else { - button.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox2 is unselected"); + button.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox2 is unselected"); } } - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "checkbox3" ) + if(button.GetProperty(Dali::Actor::Property::NAME) == "checkbox3") { - if( isSelected ) + if(isSelected) { - button.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox3 is selected"); + button.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox3 is selected"); } else { - button.SetProperty( Toolkit::Button::Property::LABEL, "CheckBox3 is unselected"); + button.SetProperty(Toolkit::Button::Property::LABEL, "CheckBox3 is unselected"); } } @@ -488,11 +485,10 @@ class ButtonsController: public ConnectionTracker } private: - - Application& mApplication; - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - Layer mContentLayer; ///< Content layer + Application& mApplication; + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer Toolkit::RadioButton mRadioButtonImage1; Toolkit::RadioButton mRadioButtonImage2; @@ -505,15 +501,15 @@ private: Toolkit::CheckBoxButton mCheckboxButton2; Toolkit::CheckBoxButton mCheckboxButton3; - Animation mAnimation; + Animation mAnimation; Toolkit::ImageView mImage; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - ButtonsController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + ButtonsController test(application); application.MainLoop(); return 0; } diff --git a/examples/clipping-draw-order/clipping-draw-order.cpp b/examples/clipping-draw-order/clipping-draw-order.cpp index 0653f2a..4f3a9c4 100644 --- a/examples/clipping-draw-order/clipping-draw-order.cpp +++ b/examples/clipping-draw-order/clipping-draw-order.cpp @@ -22,23 +22,21 @@ using namespace Dali; using namespace Dali::Toolkit; const char* images[] = { - DEMO_IMAGE_DIR "gallery-small-1.jpg", - DEMO_IMAGE_DIR "gallery-small-2.jpg", - DEMO_IMAGE_DIR "gallery-small-3.jpg", - DEMO_IMAGE_DIR "gallery-small-4.jpg", - DEMO_IMAGE_DIR "gallery-small-5.jpg" -}; + DEMO_IMAGE_DIR "gallery-small-1.jpg", + DEMO_IMAGE_DIR "gallery-small-2.jpg", + DEMO_IMAGE_DIR "gallery-small-3.jpg", + DEMO_IMAGE_DIR "gallery-small-4.jpg", + DEMO_IMAGE_DIR "gallery-small-5.jpg"}; // This verification example confirms drawing order is the same, with or without clipping enabled. class ClippingDrawOrderVerification : public ConnectionTracker { public: - - ClippingDrawOrderVerification( Application& application ) - : mApplication( application ) + ClippingDrawOrderVerification(Application& application) + : mApplication(application) { // Connect to the Application's Init signal. - mApplication.InitSignal().Connect( this, &ClippingDrawOrderVerification::Create ); + mApplication.InitSignal().Connect(this, &ClippingDrawOrderVerification::Create); } ~ClippingDrawOrderVerification() @@ -47,29 +45,29 @@ public: } // The Init signal is received once (only) during the Application lifetime. - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Connect to the window's key signal to allow Back and Escape to exit. - window.KeyEventSignal().Connect( this, &ClippingDrawOrderVerification::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &ClippingDrawOrderVerification::OnKeyEvent); // Create the title label. - TextLabel title = TextLabel::New( "Clipping draw order verification" ); - title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - title.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - title.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - title.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + TextLabel title = TextLabel::New("Clipping draw order verification"); + title.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + title.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + title.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + title.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); // Create the description label. - TextLabel description = TextLabel::New( "The bottom tree should have the same draw order as the top tree.\nThey should look identical except \"C\" is clipped on the bottom tree." ); - description.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - description.SetProperty( TextLabel::Property::MULTI_LINE, true ); - description.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - description.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 1.0f, 0.5f ) ); - window.Add( description ); + TextLabel description = TextLabel::New("The bottom tree should have the same draw order as the top tree.\nThey should look identical except \"C\" is clipped on the bottom tree."); + description.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + description.SetProperty(TextLabel::Property::MULTI_LINE, true); + description.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + description.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 1.0f, 0.5f)); + window.Add(description); /* * Create a 4-row TableView. @@ -89,28 +87,28 @@ public: * | Explanation | * +---------------+ */ - TableView view = TableView::New( 4, 1 ); - view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - view.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + TableView view = TableView::New(4, 1); + view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + view.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - view.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - view.SetCellAlignment( Toolkit::TableView::CellPosition( 1, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - view.SetCellAlignment( Toolkit::TableView::CellPosition( 2, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - view.SetCellAlignment( Toolkit::TableView::CellPosition( 3, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + view.SetCellAlignment(Toolkit::TableView::CellPosition(0, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + view.SetCellAlignment(Toolkit::TableView::CellPosition(1, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + view.SetCellAlignment(Toolkit::TableView::CellPosition(2, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + view.SetCellAlignment(Toolkit::TableView::CellPosition(3, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); - view.SetCellPadding( Vector2( 14.0f, 7.0f ) ); + view.SetCellPadding(Vector2(14.0f, 7.0f)); - view.SetRelativeWidth( 0u, 1.0f ); + view.SetRelativeWidth(0u, 1.0f); - view.SetFitHeight( 0u ); - view.SetRelativeHeight( 1u, 0.5f ); - view.SetRelativeHeight( 2u, 0.5f ); - view.SetFitHeight( 3u ); + view.SetFitHeight(0u); + view.SetRelativeHeight(1u, 0.5f); + view.SetRelativeHeight(2u, 0.5f); + view.SetFitHeight(3u); // Add the title and description to the TableView. - view.AddChild( title, TableView::CellPosition( 0u, 0u ) ); - view.AddChild( description, TableView::CellPosition( 3u, 0u ) ); + view.AddChild(title, TableView::CellPosition(0u, 0u)); + view.AddChild(description, TableView::CellPosition(3u, 0u)); /* For each of the 2 tree views, we create a small tree of actors as follows: @@ -125,83 +123,83 @@ public: The correct draw order is "ABCDE" (the same as if clipping was not enabled). */ const float treeYStart = 0.12f; - const float depthGap = 0.35f; + const float depthGap = 0.35f; - for( int tree = 0; tree < 2; ++tree ) + for(int tree = 0; tree < 2; ++tree) { Control container = Control::New(); - container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - container.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Vector4 backgroundColor = tree == 0 ? Vector4( 0.77f, 1.0f, 0.77f, 1.0f ) : Vector4( 0.8f, 0.8f, 1.0f, 1.0f ); - container.SetProperty( Control::Property::BACKGROUND, backgroundColor ); + container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + container.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + container.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + Vector4 backgroundColor = tree == 0 ? Vector4(0.77f, 1.0f, 0.77f, 1.0f) : Vector4(0.8f, 0.8f, 1.0f, 1.0f); + container.SetProperty(Control::Property::BACKGROUND, backgroundColor); ImageView image[5]; // Loop for each of the 5 images & labels. - for( int i = 0; i < 5; ++i ) + for(int i = 0; i < 5; ++i) { std::stringstream labelStream; - labelStream << static_cast( static_cast( i ) + 'A' ); - TextLabel textLabel = TextLabel::New( labelStream.str() ); - textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); + labelStream << static_cast(static_cast(i) + 'A'); + TextLabel textLabel = TextLabel::New(labelStream.str()); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); - image[i] = ImageView::New( images[i] ); - image[i].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); + image[i] = ImageView::New(images[i]); + image[i].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); // Calculate the relative positioning for the images and labels. - float depth = static_cast( i == 0 ? 0 : ( ( i - 1 ) % 2 ) + 1 ); + float depth = static_cast(i == 0 ? 0 : ((i - 1) % 2) + 1); - if( i == 0 ) + if(i == 0) { - image[i].SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, treeYStart, 0.5f ) ); - textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 1.0f, 0.05f * depth, 0.5f ) ); + image[i].SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, treeYStart, 0.5f)); + textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(1.0f, 0.05f * depth, 0.5f)); } else { float b = i > 2 ? 1.0f : -1.0f; - image[i].SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f + ( 0.2f * b ), depthGap, 0.5f ) ); - textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.98f + 0.215f * b + ( 0.04f * b * depth ), treeYStart + 0.02f + ( 0.16f * depth ), 0.5f ) ); + image[i].SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f + (0.2f * b), depthGap, 0.5f)); + textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.98f + 0.215f * b + (0.04f * b * depth), treeYStart + 0.02f + (0.16f * depth), 0.5f)); } - container.Add( textLabel ); + container.Add(textLabel); } // Create the title label. - std::string treeText = tree == 0 ? "Without Clipping" : "With Clipping"; - TextLabel treeLabel = TextLabel::New( treeText ); - treeLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - treeLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM" ); - treeLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - treeLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - container.Add( treeLabel ); + std::string treeText = tree == 0 ? "Without Clipping" : "With Clipping"; + TextLabel treeLabel = TextLabel::New(treeText); + treeLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + treeLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM"); + treeLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + treeLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + container.Add(treeLabel); // Enable clipping for the 2nd tree. - if( tree == 1 ) + if(tree == 1) { - image[1].SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + image[1].SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN); } // Build the tree structure. - container.Add( image[0] ); + container.Add(image[0]); - image[0].Add( image[1] ); - image[1].Add( image[2] ); + image[0].Add(image[1]); + image[1].Add(image[2]); - image[0].Add( image[3] ); - image[3].Add( image[4] ); + image[0].Add(image[3]); + image[3].Add(image[4]); // Add the finished tree to the TableView. - view.AddChild( container, TableView::CellPosition( 1u + tree, 0u ) ); + view.AddChild(container, TableView::CellPosition(1u + tree, 0u)); } // Add the finished TableView to the window. - window.Add( view ); + window.Add(view); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &ClippingDrawOrderVerification::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &ClippingDrawOrderVerification::OnTouch); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // Quit the application. mApplication.Quit(); @@ -214,11 +212,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -226,13 +224,13 @@ public: } private: - Application& mApplication; + Application& mApplication; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ClippingDrawOrderVerification verification( application ); + Application application = Application::New(&argc, &argv); + ClippingDrawOrderVerification verification(application); application.MainLoop(); return 0; } diff --git a/examples/clipping/clipping-example.cpp b/examples/clipping/clipping-example.cpp index 7157db9..917d5a3 100644 --- a/examples/clipping/clipping-example.cpp +++ b/examples/clipping/clipping-example.cpp @@ -16,8 +16,8 @@ */ // EXTERNAL INCLUDES -#include #include +#include #include // INTERNAL INCLUDES @@ -29,16 +29,16 @@ using namespace Dali::Toolkit; namespace { -const char * const APPLICATION_TITLE( "Clipping Controls" ); -const Vector3 APPLICATION_TITLE_PARENT_ORIGIN( 0.5f, 0.03f, 0.5f ); // Set the parent origin to a small percentage below the top (so the demo will scale for different resolutions). +const char* const APPLICATION_TITLE("Clipping Controls"); +const Vector3 APPLICATION_TITLE_PARENT_ORIGIN(0.5f, 0.03f, 0.5f); // Set the parent origin to a small percentage below the top (so the demo will scale for different resolutions). -const Vector3 ITEM_VIEW_LAYOUT_SIZE_SCALE( 0.75f, 0.5f, 0.75f ); -const float ITEM_VIEW_BORDER_SIZE = 2.0f; -const float ITEM_VIEW_MAXIMUM_ROTATION_IN_DEGREES = 20.0f; -const float ITEM_VIEW_LAYOUT_POSITION_CHANGE_MULTIPLIER = 3.0f; -const float ITEM_VIEW_ROTATION_ANIMATION_TIME = 0.2f; +const Vector3 ITEM_VIEW_LAYOUT_SIZE_SCALE(0.75f, 0.5f, 0.75f); +const float ITEM_VIEW_BORDER_SIZE = 2.0f; +const float ITEM_VIEW_MAXIMUM_ROTATION_IN_DEGREES = 20.0f; +const float ITEM_VIEW_LAYOUT_POSITION_CHANGE_MULTIPLIER = 3.0f; +const float ITEM_VIEW_ROTATION_ANIMATION_TIME = 0.2f; -const char * const BUTTON_LABEL( "Toggle Clipping Mode" ); +const char* const BUTTON_LABEL("Toggle Clipping Mode"); } // unnamed namespace /** @@ -54,90 +54,85 @@ const char * const BUTTON_LABEL( "Toggle Clipping Mode" ); class ClippingExample : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application A reference to the Application class. */ - ClippingExample( Application& application ) - : mApplication( application ) + ClippingExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ClippingExample::Create ); + mApplication.InitSignal().Connect(this, &ClippingExample::Create); } private: - /** * @brief Called to initialise the application content. * @param[in] application A reference to the Application class. */ - void Create( Application& application ) + void Create(Application& application) { // Connect to the window's key signal to allow Back and Escape to exit. Window window = application.GetWindow(); - window.KeyEventSignal().Connect( this, &ClippingExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &ClippingExample::OnKeyEvent); // Create a TextLabel for the application title. - Toolkit::TextLabel label = Toolkit::TextLabel::New( APPLICATION_TITLE ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - label.SetProperty( Actor::Property::PARENT_ORIGIN, APPLICATION_TITLE_PARENT_ORIGIN ); - label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - window.Add( label ); + Toolkit::TextLabel label = Toolkit::TextLabel::New(APPLICATION_TITLE); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + label.SetProperty(Actor::Property::PARENT_ORIGIN, APPLICATION_TITLE_PARENT_ORIGIN); + label.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + label.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + window.Add(label); // Create an item-view which clips its children. - mItemView = ItemView::New( mClippingItemFactory ); - mItemView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mItemView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mItemView.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); // Enable clipping. No need to create any renderers. - window.Add( mItemView ); + mItemView = ItemView::New(mClippingItemFactory); + mItemView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mItemView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mItemView.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN); // Enable clipping. No need to create any renderers. + window.Add(mItemView); // Create a Spiral Layout and add it to the Item View. - mItemView.AddLayout( * DefaultItemLayout::New( DefaultItemLayout::SPIRAL ) ); - window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); // The item-view spiral layout requires Layer 3D behaviour. + mItemView.AddLayout(*DefaultItemLayout::New(DefaultItemLayout::SPIRAL)); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); // The item-view spiral layout requires Layer 3D behaviour. // Calculate the size we would like our item-view layout to be, and then activate the layout. const Vector2 windowSize = window.GetSize(); - const Vector3 itemViewLayoutSize( ITEM_VIEW_LAYOUT_SIZE_SCALE.x * windowSize.x, ITEM_VIEW_LAYOUT_SIZE_SCALE.y * windowSize.y, ITEM_VIEW_LAYOUT_SIZE_SCALE.z * windowSize.x ); - mItemView.ActivateLayout( 0, itemViewLayoutSize, 0.0f ); + const Vector3 itemViewLayoutSize(ITEM_VIEW_LAYOUT_SIZE_SCALE.x * windowSize.x, ITEM_VIEW_LAYOUT_SIZE_SCALE.y * windowSize.y, ITEM_VIEW_LAYOUT_SIZE_SCALE.z * windowSize.x); + mItemView.ActivateLayout(0, itemViewLayoutSize, 0.0f); // Connect to the scroll started and completed signals to apply orientation constraints & animations. - mItemView.ScrollStartedSignal().Connect( this, &ClippingExample::ScrollStarted ); - mItemView.ScrollCompletedSignal().Connect( this, &ClippingExample::ScrollCompleted ); + mItemView.ScrollStartedSignal().Connect(this, &ClippingExample::ScrollStarted); + mItemView.ScrollCompletedSignal().Connect(this, &ClippingExample::ScrollCompleted); // Create a constraint for the item-view which we apply when we start scrolling and remove when we stop. - mItemViewOrientationConstraint = Constraint::New< Quaternion >( mItemView, Actor::Property::ORIENTATION, ItemViewOrientationConstraint( ITEM_VIEW_MAXIMUM_ROTATION_IN_DEGREES, ITEM_VIEW_LAYOUT_POSITION_CHANGE_MULTIPLIER ) ); - mItemViewOrientationConstraint.AddSource( LocalSource( ItemView::Property::LAYOUT_POSITION ) ); + mItemViewOrientationConstraint = Constraint::New(mItemView, Actor::Property::ORIENTATION, ItemViewOrientationConstraint(ITEM_VIEW_MAXIMUM_ROTATION_IN_DEGREES, ITEM_VIEW_LAYOUT_POSITION_CHANGE_MULTIPLIER)); + mItemViewOrientationConstraint.AddSource(LocalSource(ItemView::Property::LAYOUT_POSITION)); // Create a border around item-view (as item-view is clipping its children, we should NOT add this as a child of item-view). Control border = Control::New(); - border.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - border.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - border.SetProperty( Control::Property::BACKGROUND, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::BORDER ) - .Add( BorderVisual::Property::COLOR, Color::WHITE ) - .Add( BorderVisual::Property::SIZE, 2.0f ) - .Add( BorderVisual::Property::ANTI_ALIASING, true ) ); - border.SetProperty( Actor::Property::SIZE, Vector3( itemViewLayoutSize.x + ITEM_VIEW_BORDER_SIZE * 2.0f, itemViewLayoutSize.y + ITEM_VIEW_BORDER_SIZE * 2.0f, itemViewLayoutSize.z + ITEM_VIEW_BORDER_SIZE * 2.0f ) ); - window.Add( border ); + border.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + border.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + border.SetProperty(Control::Property::BACKGROUND, + Property::Map().Add(Toolkit::Visual::Property::TYPE, Visual::BORDER).Add(BorderVisual::Property::COLOR, Color::WHITE).Add(BorderVisual::Property::SIZE, 2.0f).Add(BorderVisual::Property::ANTI_ALIASING, true)); + border.SetProperty(Actor::Property::SIZE, Vector3(itemViewLayoutSize.x + ITEM_VIEW_BORDER_SIZE * 2.0f, itemViewLayoutSize.y + ITEM_VIEW_BORDER_SIZE * 2.0f, itemViewLayoutSize.z + ITEM_VIEW_BORDER_SIZE * 2.0f)); + window.Add(border); // Constrain the border's orientation to the orientation of item-view. - Constraint constraint = Constraint::New< Quaternion >( border, Actor::Property::ORIENTATION, EqualToConstraint() ); - constraint.AddSource( Source( mItemView, Actor::Property::ORIENTATION ) ); + Constraint constraint = Constraint::New(border, Actor::Property::ORIENTATION, EqualToConstraint()); + constraint.AddSource(Source(mItemView, Actor::Property::ORIENTATION)); constraint.Apply(); // Create a button to toggle the clipping mode PushButton button = Toolkit::PushButton::New(); - button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - button.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D ); - button.SetProperty( Button::Property::LABEL, BUTTON_LABEL ); - button.ClickedSignal().Connect( this, &ClippingExample::OnButtonClicked ); - window.Add( button ); + button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + button.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + button.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + button.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + button.SetProperty(Button::Property::LABEL, BUTTON_LABEL); + button.ClickedSignal().Connect(this, &ClippingExample::OnButtonClicked); + window.Add(button); } /** @@ -145,7 +140,7 @@ private: * * Here we want to apply the item-view constraint. */ - void ScrollStarted( const Vector2& /* currentScrollPosition */ ) + void ScrollStarted(const Vector2& /* currentScrollPosition */) { mItemViewOrientationConstraint.Apply(); } @@ -155,10 +150,10 @@ private: * * Here we remove the item-view orientation constraint and perform an animation to return the item-view back to base-rotation. */ - void ScrollCompleted( const Vector2& /* currentScrollPosition */ ) + void ScrollCompleted(const Vector2& /* currentScrollPosition */) { - Animation animation = Animation::New( ITEM_VIEW_ROTATION_ANIMATION_TIME ); - animation.AnimateTo( Property( mItemView, Actor::Property::ORIENTATION ), Quaternion( Degree( 0.0f ), Vector3::XAXIS ), AlphaFunction::EASE_IN_SINE ); + Animation animation = Animation::New(ITEM_VIEW_ROTATION_ANIMATION_TIME); + animation.AnimateTo(Property(mItemView, Actor::Property::ORIENTATION), Quaternion(Degree(0.0f), Vector3::XAXIS), AlphaFunction::EASE_IN_SINE); animation.Play(); mItemViewOrientationConstraint.Remove(); @@ -170,11 +165,11 @@ private: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -187,27 +182,27 @@ private: * Will use this to toggle between the clipping modes. * @param[in] button The button that has been clicked. */ - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { - if( mItemView ) + if(mItemView) { - ClippingMode::Type currentMode = static_cast< ClippingMode::Type >( mItemView.GetProperty( Actor::Property::CLIPPING_MODE ).Get< int >() ); - mItemView.SetProperty( Actor::Property::CLIPPING_MODE, ( currentMode == ClippingMode::CLIP_CHILDREN ) ? ClippingMode::DISABLED : ClippingMode::CLIP_CHILDREN ); + ClippingMode::Type currentMode = static_cast(mItemView.GetProperty(Actor::Property::CLIPPING_MODE).Get()); + mItemView.SetProperty(Actor::Property::CLIPPING_MODE, (currentMode == ClippingMode::CLIP_CHILDREN) ? ClippingMode::DISABLED : ClippingMode::CLIP_CHILDREN); } return true; } // Data - Application& mApplication; ///< Reference to the application class. - ItemView mItemView; ///< The item view which whose children we would like to clip. - ClippingItemFactory mClippingItemFactory; ///< The ItemFactory used to create our items. - Constraint mItemViewOrientationConstraint; ///< The constraint used to control the orientation of item-view. + Application& mApplication; ///< Reference to the application class. + ItemView mItemView; ///< The item view which whose children we would like to clip. + ClippingItemFactory mClippingItemFactory; ///< The ItemFactory used to create our items. + Constraint mItemViewOrientationConstraint; ///< The constraint used to control the orientation of item-view. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ClippingExample test(app); app.MainLoop(); return 0; diff --git a/examples/clipping/clipping-item-factory.cpp b/examples/clipping/clipping-item-factory.cpp index a30afa1..e229731 100644 --- a/examples/clipping/clipping-item-factory.cpp +++ b/examples/clipping/clipping-item-factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,19 @@ #include "clipping-item-factory.h" // EXTERNAL INCLUDES -#include +#include #include #include -#include #include -#include +#include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { -const char * IMAGE_PATHS[] = { +const char* IMAGE_PATHS[] = { DEMO_IMAGE_DIR "gallery-medium-1.jpg", DEMO_IMAGE_DIR "gallery-medium-2.jpg", DEMO_IMAGE_DIR "gallery-medium-3.jpg", @@ -86,7 +86,7 @@ const char * IMAGE_PATHS[] = { DEMO_IMAGE_DIR "gallery-medium-52.jpg", DEMO_IMAGE_DIR "gallery-medium-53.jpg", }; -const unsigned int NUM_IMAGES = sizeof( IMAGE_PATHS ) / sizeof( char * ); +const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*); const unsigned int NUM_IMAGES_MULTIPLIER = 10; const float ITEM_BORDER_SIZE = 2.0f; @@ -101,28 +101,25 @@ unsigned int ClippingItemFactory::GetNumberOfItems() return NUM_IMAGES * NUM_IMAGES_MULTIPLIER; } -Actor ClippingItemFactory::NewItem( unsigned int itemId ) +Actor ClippingItemFactory::NewItem(unsigned int itemId) { // Create an image view for this item Property::Map propertyMap; - propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); - propertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATHS[ itemId % NUM_IMAGES ] ); + propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATHS[itemId % NUM_IMAGES]); propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL); ImageView actor = ImageView::New(); actor.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); // Add a border image child actor ImageView borderActor = ImageView::New(); - borderActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - borderActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); - borderActor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) ); - borderActor.SetProperty( Actor::Property::COLOR_MODE, USE_PARENT_COLOR ); - borderActor.SetProperty( ImageView::Property::IMAGE, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::BORDER ) - .Add( BorderVisual::Property::COLOR, Color::WHITE ) - .Add( BorderVisual::Property::SIZE, ITEM_BORDER_SIZE ) - .Add( BorderVisual::Property::ANTI_ALIASING, true ) ); + borderActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + borderActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + borderActor.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS); + borderActor.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f)); + borderActor.SetProperty(Actor::Property::COLOR_MODE, USE_PARENT_COLOR); + borderActor.SetProperty(ImageView::Property::IMAGE, + Property::Map().Add(Toolkit::Visual::Property::TYPE, Visual::BORDER).Add(BorderVisual::Property::COLOR, Color::WHITE).Add(BorderVisual::Property::SIZE, ITEM_BORDER_SIZE).Add(BorderVisual::Property::ANTI_ALIASING, true)); actor.Add(borderActor); return actor; diff --git a/examples/clipping/clipping-item-factory.h b/examples/clipping/clipping-item-factory.h index 344afea..a84b49d 100644 --- a/examples/clipping/clipping-item-factory.h +++ b/examples/clipping/clipping-item-factory.h @@ -2,7 +2,7 @@ #define CLIPPING_ITEM_FACTORY_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,14 +26,12 @@ class ClippingItemFactory : public Dali::Toolkit::ItemFactory { public: - /** * @brief Constructor */ ClippingItemFactory(); private: // From ItemFactory - /** * Query the number of items available from the factory. * The maximum available item has an ID of GetNumberOfItems() - 1. @@ -45,12 +43,11 @@ private: // From ItemFactory * @param itemId * @return the created actor. */ - virtual Dali::Actor NewItem( unsigned int itemId ); + virtual Dali::Actor NewItem(unsigned int itemId); private: - - ClippingItemFactory( const ClippingItemFactory& ); ///< Undefined - ClippingItemFactory& operator=( const ClippingItemFactory& ); ///< Undefined + ClippingItemFactory(const ClippingItemFactory&); ///< Undefined + ClippingItemFactory& operator=(const ClippingItemFactory&); ///< Undefined }; #endif // CLIPPING_ITEM_FACTORY_H diff --git a/examples/clipping/item-view-orientation-constraint.h b/examples/clipping/item-view-orientation-constraint.h index 0ff4bf9..337fe28 100644 --- a/examples/clipping/item-view-orientation-constraint.h +++ b/examples/clipping/item-view-orientation-constraint.h @@ -2,7 +2,7 @@ #define ITEM_VIEW_ORIENTATION_CONSTRAINT_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,19 +32,18 @@ class ItemViewOrientationConstraint { public: - /** * @brief Constructor. * @param[in] maximumRotationInDegrees The maximum rotation (in degrees) that we should rotate the item-view by. * @param[in] layoutPositionChangeMultiplier This value is used to multiply the change in layout position * (in order to exaggerate the amount moved so it's more visible). */ - ItemViewOrientationConstraint( float maximumRotationInDegrees, float layoutPositionChangeMultiplier ) - : mMaximumRotationInDegrees( maximumRotationInDegrees ), - mLayoutPositionChangeMultiplier( layoutPositionChangeMultiplier ), - mStartingLayoutPosition( 0.0f ), - mStartingAngle( 0.0f ), - mFirstCall( true ) + ItemViewOrientationConstraint(float maximumRotationInDegrees, float layoutPositionChangeMultiplier) + : mMaximumRotationInDegrees(maximumRotationInDegrees), + mLayoutPositionChangeMultiplier(layoutPositionChangeMultiplier), + mStartingLayoutPosition(0.0f), + mStartingAngle(0.0f), + mFirstCall(true) { } @@ -58,22 +57,22 @@ public: * @param[in] inputs The constraint inputs: * [0] ItemView::Property::LAYOUT_POSITION, float */ - void operator()( Dali::Quaternion& rotation, const Dali::PropertyInputContainer& inputs ) + void operator()(Dali::Quaternion& rotation, const Dali::PropertyInputContainer& inputs) { - const float& layoutPosition = inputs[ 0 ]->GetFloat(); + const float& layoutPosition = inputs[0]->GetFloat(); // Store values for base reference when called the first call. - if( mFirstCall ) + if(mFirstCall) { mStartingLayoutPosition = layoutPosition; Dali::Vector3 axis; - Dali::Radian angleInRadians; - rotation.ToAxisAngle( axis, angleInRadians ); - Dali::Degree angleInDegrees( angleInRadians ); // Convert to Degrees + Dali::Radian angleInRadians; + rotation.ToAxisAngle(axis, angleInRadians); + Dali::Degree angleInDegrees(angleInRadians); // Convert to Degrees mStartingAngle = angleInDegrees.degree; - if( axis.x < 0.0f ) // We only rotate round the X-Axis. So if the X-Axis is negative, then the angle is also a negative angle. + if(axis.x < 0.0f) // We only rotate round the X-Axis. So if the X-Axis is negative, then the angle is also a negative angle. { mStartingAngle = -mStartingAngle; } @@ -84,19 +83,18 @@ public: { // All subsequent calls should tilt the orientation of the item-view around the X-Axis depending on how much our position has changed in the layout. - Dali::Degree angle( mStartingAngle + mLayoutPositionChangeMultiplier * ( mStartingLayoutPosition - layoutPosition ) ); - Dali::ClampInPlace( angle.degree, -mMaximumRotationInDegrees, mMaximumRotationInDegrees ); // Ensure the angle does not exceed maximum specified (in both directions). - rotation = Dali::Quaternion( angle, Dali::Vector3::XAXIS ); + Dali::Degree angle(mStartingAngle + mLayoutPositionChangeMultiplier * (mStartingLayoutPosition - layoutPosition)); + Dali::ClampInPlace(angle.degree, -mMaximumRotationInDegrees, mMaximumRotationInDegrees); // Ensure the angle does not exceed maximum specified (in both directions). + rotation = Dali::Quaternion(angle, Dali::Vector3::XAXIS); } } private: - - const float mMaximumRotationInDegrees; ///< The maximum allowable rotation of the item-view. + const float mMaximumRotationInDegrees; ///< The maximum allowable rotation of the item-view. const float mLayoutPositionChangeMultiplier; ///< This value is used to multiply the change in layout position. - float mStartingLayoutPosition; ///< The starting layout position. - float mStartingAngle; ///< The starting angle (in degrees) of the item-view. - bool mFirstCall; ///< A boolean to state whether this is the first time the operator() is called. Allows us to set the starting values. + float mStartingLayoutPosition; ///< The starting layout position. + float mStartingAngle; ///< The starting angle (in degrees) of the item-view. + bool mFirstCall; ///< A boolean to state whether this is the first time the operator() is called. Allows us to set the starting values. }; #endif // ITEM_VIEW_ORIENTATION_CONSTRAINT_H diff --git a/examples/color-visual/color-visual-example.cpp b/examples/color-visual/color-visual-example.cpp index 809fdae..a7d7104 100644 --- a/examples/color-visual/color-visual-example.cpp +++ b/examples/color-visual/color-visual-example.cpp @@ -17,32 +17,26 @@ #include #include -#include -#include #include +#include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { +const char* IMAGE_FILE(DEMO_IMAGE_DIR "gallery-medium-1.jpg"); -const char* IMAGE_FILE( DEMO_IMAGE_DIR "gallery-medium-1.jpg" ); +const float BLUR_RADIUS_VALUE(10.0f); +const float NO_BLUR_VALUE(0.0f); +const float ANIMATION_DURATION(2.0f); -const float BLUR_RADIUS_VALUE( 10.0f ); -const float NO_BLUR_VALUE( 0.0f ); -const float ANIMATION_DURATION( 2.0f ); - -const Property::Value SHADOW -{ - { Visual::Property::TYPE, Visual::COLOR }, - { Visual::Property::MIX_COLOR, Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) }, - { Visual::Property::TRANSFORM, Property::Map{ { Visual::Transform::Property::OFFSET, Vector2( 0.05f, 0.05f ) }, - { Visual::Transform::Property::SIZE, Vector2( 1.05f, 1.05f ) }, - { Visual::Transform::Property::ORIGIN, Align::CENTER }, - { Visual::Transform::Property::ANCHOR_POINT, Align::CENTER } } }, - { DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_VALUE } -}; +const Property::Value SHADOW{ + {Visual::Property::TYPE, Visual::COLOR}, + {Visual::Property::MIX_COLOR, Vector4(0.0f, 0.0f, 0.0f, 0.5f)}, + {Visual::Property::TRANSFORM, Property::Map{{Visual::Transform::Property::OFFSET, Vector2(0.05f, 0.05f)}, {Visual::Transform::Property::SIZE, Vector2(1.05f, 1.05f)}, {Visual::Transform::Property::ORIGIN, Align::CENTER}, {Visual::Transform::Property::ANCHOR_POINT, Align::CENTER}}}, + {DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_VALUE}}; } // namespace @@ -51,13 +45,12 @@ const Property::Value SHADOW class ColorVisualExample : public ConnectionTracker { public: - - ColorVisualExample( Application& application ) - : mApplication( application ), - mShadowVisible( true ) + ColorVisualExample(Application& application) + : mApplication(application), + mShadowVisible(true) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ColorVisualExample::Create ); + mApplication.InitSignal().Connect(this, &ColorVisualExample::Create); } ~ColorVisualExample() @@ -66,60 +59,56 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); - mImageView = ImageView::New( IMAGE_FILE ); - mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mImageView.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) ); - mImageView.SetProperty( DevelControl::Property::SHADOW, SHADOW ); + mImageView = ImageView::New(IMAGE_FILE); + mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageView.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f)); + mImageView.SetProperty(DevelControl::Property::SHADOW, SHADOW); - window.Add( mImageView ); + window.Add(mImageView); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &ColorVisualExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &ColorVisualExample::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &ColorVisualExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &ColorVisualExample::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - if( touch.GetState( 0 ) == PointState::UP ) + if(touch.GetState(0) == PointState::UP) { float initialValue, targetValue; - if( !mShadowVisible ) + if(!mShadowVisible) { initialValue = NO_BLUR_VALUE; - targetValue = BLUR_RADIUS_VALUE; + targetValue = BLUR_RADIUS_VALUE; } else { initialValue = BLUR_RADIUS_VALUE; - targetValue = NO_BLUR_VALUE; + targetValue = NO_BLUR_VALUE; } mShadowVisible = !mShadowVisible; - TransitionData transitionData = TransitionData::New( Property::Map().Add( "target", "shadow" ) - .Add( "property", "blurRadius" ) - .Add( "initialValue", initialValue ) - .Add( "targetValue", targetValue ) - .Add( "animator", Property::Map().Add( "duration", ANIMATION_DURATION ) ) ); - Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mImageView ), transitionData ); + TransitionData transitionData = TransitionData::New(Property::Map().Add("target", "shadow").Add("property", "blurRadius").Add("initialValue", initialValue).Add("targetValue", targetValue).Add("animator", Property::Map().Add("duration", ANIMATION_DURATION))); + Animation animation = DevelControl::CreateTransition(Toolkit::Internal::GetImplementation(mImageView), transitionData); animation.Play(); } return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -127,15 +116,15 @@ public: } private: - Application& mApplication; - ImageView mImageView; - bool mShadowVisible; + Application& mApplication; + ImageView mImageView; + bool mShadowVisible; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ColorVisualExample test( application ); + Application application = Application::New(&argc, &argv); + ColorVisualExample test(application); application.MainLoop(); return 0; } diff --git a/examples/compressed-texture-formats/compressed-texture-formats-example.cpp b/examples/compressed-texture-formats/compressed-texture-formats-example.cpp index cf081f5..1749a63 100644 --- a/examples/compressed-texture-formats/compressed-texture-formats-example.cpp +++ b/examples/compressed-texture-formats/compressed-texture-formats-example.cpp @@ -16,9 +16,9 @@ */ // EXTERNAL INCLUDES -#include #include #include +#include // INTERNAL INCLUDES #include "shared/utility.h" @@ -28,12 +28,11 @@ using Dali::Toolkit::TextLabel; namespace { - -const char* IMAGE_FILENAME_ETC = DEMO_IMAGE_DIR "tx-etc1.ktx"; -const char* IMAGE_FILENAME_ASTC_LINEAR = DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx"; +const char* IMAGE_FILENAME_ETC = DEMO_IMAGE_DIR "tx-etc1.ktx"; +const char* IMAGE_FILENAME_ASTC_LINEAR = DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx"; const char* IMAGE_FILENAME_ASTC_LINEAR_NATIVE = DEMO_IMAGE_DIR "tx-astc-4x4-linear-native.astc"; - +// clang-format off static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n attribute mediump vec2 aTexCoord;\n @@ -58,6 +57,7 @@ static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n }\n ); +// clang-format on /** * @brief Create a renderer to render an image and adds it to an actor @@ -66,23 +66,23 @@ static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( * @param[in[ geometry The geometry to use * @param[in] shader The shader to use */ -void AddImage( const char*imagePath, Actor& actor, Geometry& geometry, Shader& shader ) +void AddImage(const char* imagePath, Actor& actor, Geometry& geometry, Shader& shader) { //Load the texture - Texture texture = DemoHelper::LoadTexture( imagePath ); + Texture texture = DemoHelper::LoadTexture(imagePath); TextureSet textureSet = TextureSet::New(); - textureSet.SetTexture( 0u, texture ); + textureSet.SetTexture(0u, texture); //Create the renderer - Renderer renderer = Renderer::New( geometry, shader ); - renderer.SetTextures( textureSet ); + Renderer renderer = Renderer::New(geometry, shader); + renderer.SetTextures(textureSet); //Set actor size and add the renderer - actor.SetProperty( Actor::Property::SIZE, Vector2( texture.GetWidth(), texture.GetHeight() ) ); - actor.AddRenderer( renderer ); + actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight())); + actor.AddRenderer(renderer); } -} +} // namespace /** * @brief This example shows 3 images, each of a different compressed texture type. * If built and run on a OpenGL ES 3.1 compatable target, then all 3 images will display. @@ -91,12 +91,11 @@ void AddImage( const char*imagePath, Actor& actor, Geometry& geometry, Shader& s class CompressedTextureFormatsController : public ConnectionTracker { public: - - CompressedTextureFormatsController( Application& application ) - : mApplication( application ) + CompressedTextureFormatsController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &CompressedTextureFormatsController::Create ); + mApplication.InitSignal().Connect(this, &CompressedTextureFormatsController::Create); } ~CompressedTextureFormatsController() @@ -105,83 +104,82 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Setup a TableView to hold a grid of images and labels. - Toolkit::TableView table = Toolkit::TableView::New( 3u, 2u ); - table.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - table.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.SetRelativeWidth( 0u, 0.5f ); - table.SetRelativeWidth( 1u, 0.5f ); - table.SetRelativeHeight( 0u, 1.0f / 3.0f ); - table.SetRelativeHeight( 1u, 1.0f / 3.0f ); - table.SetRelativeHeight( 2u, 1.0f / 3.0f ); - + Toolkit::TableView table = Toolkit::TableView::New(3u, 2u); + table.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + table.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.SetRelativeWidth(0u, 0.5f); + table.SetRelativeWidth(1u, 0.5f); + table.SetRelativeHeight(0u, 1.0f / 3.0f); + table.SetRelativeHeight(1u, 1.0f / 3.0f); + table.SetRelativeHeight(2u, 1.0f / 3.0f); // Add text labels. - TextLabel textLabel = TextLabel::New( "ETC1 (KTX):" ); - textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - table.AddChild( textLabel, Toolkit::TableView::CellPosition( 0u, 0u ) ); - table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); - - textLabel = TextLabel::New( "ASTC (KTX) 4x4 linear:" ); - textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - table.AddChild( textLabel, Toolkit::TableView::CellPosition( 1u, 0u ) ); - table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); - - textLabel = TextLabel::New( "ASTC (Native) 4x4 linear:" ); - textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - table.AddChild( textLabel, Toolkit::TableView::CellPosition( 2u, 0u ) ); - table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); + TextLabel textLabel = TextLabel::New("ETC1 (KTX):"); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + textLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + table.AddChild(textLabel, Toolkit::TableView::CellPosition(0u, 0u)); + table.SetCellAlignment(Toolkit::TableView::CellPosition(0u, 0u), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); + + textLabel = TextLabel::New("ASTC (KTX) 4x4 linear:"); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + textLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + table.AddChild(textLabel, Toolkit::TableView::CellPosition(1u, 0u)); + table.SetCellAlignment(Toolkit::TableView::CellPosition(1u, 0u), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); + + textLabel = TextLabel::New("ASTC (Native) 4x4 linear:"); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + textLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + table.AddChild(textLabel, Toolkit::TableView::CellPosition(2u, 0u)); + table.SetCellAlignment(Toolkit::TableView::CellPosition(2u, 0u), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); //Create the geometry and the shader renderers will use Geometry geometry = DemoHelper::CreateTexturedQuad(); - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); + Shader shader = Shader::New(VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE); // Add images. Actor actor = Actor::New(); - actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - AddImage( IMAGE_FILENAME_ETC, actor, geometry, shader ); - table.AddChild( actor, Toolkit::TableView::CellPosition( 0u, 1u ) ); - table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + AddImage(IMAGE_FILENAME_ETC, actor, geometry, shader); + table.AddChild(actor, Toolkit::TableView::CellPosition(0u, 1u)); + table.SetCellAlignment(Toolkit::TableView::CellPosition(0u, 1u), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); actor = Actor::New(); - actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - AddImage( IMAGE_FILENAME_ASTC_LINEAR, actor, geometry, shader ); - table.AddChild( actor, Toolkit::TableView::CellPosition( 1u, 1u ) ); - table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + AddImage(IMAGE_FILENAME_ASTC_LINEAR, actor, geometry, shader); + table.AddChild(actor, Toolkit::TableView::CellPosition(1u, 1u)); + table.SetCellAlignment(Toolkit::TableView::CellPosition(1u, 1u), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); actor = Actor::New(); - actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - AddImage( IMAGE_FILENAME_ASTC_LINEAR_NATIVE, actor, geometry, shader ); - table.AddChild( actor, Toolkit::TableView::CellPosition( 2u, 1u ) ); - table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + AddImage(IMAGE_FILENAME_ASTC_LINEAR_NATIVE, actor, geometry, shader); + table.AddChild(actor, Toolkit::TableView::CellPosition(2u, 1u)); + table.SetCellAlignment(Toolkit::TableView::CellPosition(2u, 1u), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); - window.Add( table ); + window.Add(table); // Respond to touch and key signals - window.GetRootLayer().TouchedSignal().Connect( this, &CompressedTextureFormatsController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &CompressedTextureFormatsController::OnTouch); window.KeyEventSignal().Connect(this, &CompressedTextureFormatsController::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -192,7 +190,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -200,13 +198,13 @@ public: } private: - Application& mApplication; + Application& mApplication; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - CompressedTextureFormatsController test( application ); + Application application = Application::New(&argc, &argv); + CompressedTextureFormatsController test(application); application.MainLoop(); return 0; } diff --git a/examples/contact-cards/clipped-image.cpp b/examples/contact-cards/clipped-image.cpp index fad71e0..0de8617 100644 --- a/examples/contact-cards/clipped-image.cpp +++ b/examples/contact-cards/clipped-image.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,14 +23,12 @@ namespace ClippedImage { - using namespace Dali; using namespace Dali::Toolkit; namespace { - -const char * const DELTA_PROPERTY_NAME( "uDelta" ); ///< Name of uniform used to mix the Circle and Quad geometries. +const char* const DELTA_PROPERTY_NAME("uDelta"); ///< Name of uniform used to mix the Circle and Quad geometries. /** * @brief This vertex-shader mixes in the quad and circle geometry depending on the value of uDelta. @@ -38,6 +36,7 @@ const char * const DELTA_PROPERTY_NAME( "uDelta" ); ///< Name of uniform used to * uDelta is used to mix in the Circle and the Quad positions. * If uDelta is 0.0f, then the circle position is adopted and if it is 1.0f, then the quad position is adopted. */ +// clang-format off const char * VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPositionCircle;\n attribute mediump vec2 aPositionQuad;\n @@ -62,6 +61,7 @@ const char * FRAGMENT_SHADER = DALI_COMPOSE_SHADER( gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n ); +// clang-format on /** * @brief Creates the shader required for the clipped image @@ -75,9 +75,9 @@ Shader& CreateShader() // be managed by the application writer. static Shader shader; - if( !shader ) + if(!shader) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + shader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); } return shader; @@ -95,7 +95,7 @@ Geometry& CreateGeometry() // be managed by the application writer. static Geometry geometry; - if ( !geometry ) + if(!geometry) { const int vertexCount = 34; // Needs to be 4n plus 2 where n is a positive integer above 4 @@ -103,87 +103,87 @@ Geometry& CreateGeometry() // Radius is bound to actor's dimensions so this should not be increased. // If a bigger circle is required then the actor size should be increased. - const float radius = 0.5f; + const float radius = 0.5f; const Vector2 center = Vector2::ZERO; // Create a buffer for vertex data Vector2 circleBuffer[vertexCount]; - int idx = 0; + int idx = 0; // Center vertex for triangle fan - circleBuffer[ idx++ ] = center; + circleBuffer[idx++] = center; // Outer vertices of the circle const int outerVertexCount = vertexCount - 1; - for ( int i = 0; i < outerVertexCount; ++i ) + for(int i = 0; i < outerVertexCount; ++i) { - const float percent = ( i / static_cast< float >( outerVertexCount - 1 ) ); - const float rad = percent * 2.0f * Math::PI; + const float percent = (i / static_cast(outerVertexCount - 1)); + const float rad = percent * 2.0f * Math::PI; // Vertex position Vector2 outer; - outer.x = center.x + radius * cos( rad ); - outer.y = center.y + radius * sin( rad ); + outer.x = center.x + radius * cos(rad); + outer.y = center.y + radius * sin(rad); - circleBuffer[ idx++ ] = outer; + circleBuffer[idx++] = outer; } Property::Map circleVertexFormat; circleVertexFormat["aPositionCircle"] = Property::VECTOR2; - VertexBuffer circleVertices = VertexBuffer::New( circleVertexFormat ); - circleVertices.SetData( circleBuffer, vertexCount ); + VertexBuffer circleVertices = VertexBuffer::New(circleVertexFormat); + circleVertices.SetData(circleBuffer, vertexCount); // Create the Quad Geometry Vector2 quadBuffer[vertexCount]; - idx = 0; - quadBuffer[ idx++ ] = center; + idx = 0; + quadBuffer[idx++] = center; - const size_t vertsPerSide = ( vertexCount - 2 ) / 4; - Vector2 outer( 0.5f, 0.0f ); - quadBuffer[ idx++ ] = outer; - float incrementPerBuffer = 1.0f / static_cast< float >( vertsPerSide ); + const size_t vertsPerSide = (vertexCount - 2) / 4; + Vector2 outer(0.5f, 0.0f); + quadBuffer[idx++] = outer; + float incrementPerBuffer = 1.0f / static_cast(vertsPerSide); - for( size_t i = 0; i < vertsPerSide && outer.y < 0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.y < 0.5f; ++i) { outer.y += incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.x > -0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.x > -0.5f; ++i) { outer.x -= incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.y > -0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.y > -0.5f; ++i) { outer.y -= incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.x < 0.5f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.x < 0.5f; ++i) { outer.x += incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } - for( size_t i = 0; i < vertsPerSide && outer.y < 0.0f; ++i ) + for(size_t i = 0; i < vertsPerSide && outer.y < 0.0f; ++i) { outer.y += incrementPerBuffer; - quadBuffer[ idx++ ] = outer; + quadBuffer[idx++] = outer; } Property::Map vertexFormat; vertexFormat["aPositionQuad"] = Property::VECTOR2; - VertexBuffer quadVertices2 = VertexBuffer::New( vertexFormat ); - quadVertices2.SetData( quadBuffer, vertexCount ); + VertexBuffer quadVertices2 = VertexBuffer::New(vertexFormat); + quadVertices2.SetData(quadBuffer, vertexCount); // Create the geometry object itself geometry = Geometry::New(); - geometry.AddVertexBuffer( circleVertices ); - geometry.AddVertexBuffer( quadVertices2 ); - geometry.SetType( Geometry::TRIANGLE_FAN ); + geometry.AddVertexBuffer(circleVertices); + geometry.AddVertexBuffer(quadVertices2); + geometry.SetType(Geometry::TRIANGLE_FAN); } return geometry; @@ -192,28 +192,28 @@ Geometry& CreateGeometry() } // unnamed namespace const float CIRCLE_GEOMETRY = 0.0f; -const float QUAD_GEOMETRY = 1.0f; +const float QUAD_GEOMETRY = 1.0f; -Dali::Toolkit::Control Create( const std::string& imagePath, Property::Index& propertyIndex ) +Dali::Toolkit::Control Create(const std::string& imagePath, Property::Index& propertyIndex) { // Create a control which whose geometry will be morphed between a circle and a quad Control clippedImage = Control::New(); - clippedImage.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + clippedImage.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN); // Create the required renderer and add to the clipped image control - Renderer renderer = Renderer::New( CreateGeometry(), CreateShader() ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - clippedImage.AddRenderer( renderer ); + Renderer renderer = Renderer::New(CreateGeometry(), CreateShader()); + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + clippedImage.AddRenderer(renderer); // Register the property on the clipped image control which will allow animations between a circle and a quad - propertyIndex = clippedImage.RegisterProperty( DELTA_PROPERTY_NAME, 0.0f ); + propertyIndex = clippedImage.RegisterProperty(DELTA_PROPERTY_NAME, 0.0f); // Add the actual image to the control - Control image = ImageView::New( imagePath ); - image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - image.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - image.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - clippedImage.Add( image ); + Control image = ImageView::New(imagePath); + image.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + image.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + image.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + clippedImage.Add(image); return clippedImage; } diff --git a/examples/contact-cards/clipped-image.h b/examples/contact-cards/clipped-image.h index edfd86a..504c6c4 100644 --- a/examples/contact-cards/clipped-image.h +++ b/examples/contact-cards/clipped-image.h @@ -2,7 +2,7 @@ #define CLIPPED_IMAGE_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ */ // EXTERNAL INCLUDES -#include #include +#include /** * @brief This namespace provides a helper function to create a control that clips an image either as a quad or a circle. @@ -29,9 +29,8 @@ */ namespace ClippedImage { - extern const float CIRCLE_GEOMETRY; ///< Setting or animating the returned propertyIndex in Create() to this value will provide a circle geometry on the image @see Create -extern const float QUAD_GEOMETRY; ///< Setting or animating the returned propertyIndex in Create() to this value will provide a quad geometry on the image @see Create +extern const float QUAD_GEOMETRY; ///< Setting or animating the returned propertyIndex in Create() to this value will provide a quad geometry on the image @see Create /** * @brief Creates a clipping image whose geometry (i.e. clip area) can be morphed between a circle and a quad by animating the propertyIndex out parameter. @@ -43,7 +42,7 @@ extern const float QUAD_GEOMETRY; ///< Setting or animating the returned propert * @param[out] propertyIndex Gets set with the property index which the caller can animate using the CIRCLE_GEOMETRY & QUAD_GEOMETRY values. * @return The image-mesh control */ -Dali::Toolkit::Control Create( const std::string& imagePath, Dali::Property::Index& propertyIndex ); +Dali::Toolkit::Control Create(const std::string& imagePath, Dali::Property::Index& propertyIndex); } // namespace ClippedImage diff --git a/examples/contact-cards/contact-card-layout-info.h b/examples/contact-cards/contact-card-layout-info.h index 68e3f20..d871e86 100644 --- a/examples/contact-cards/contact-card-layout-info.h +++ b/examples/contact-cards/contact-card-layout-info.h @@ -2,7 +2,7 @@ #define CONTACT_CARD_LAYOUT_INFO_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,4 +51,3 @@ struct ContactCardLayoutInfo }; #endif // CONTACT_CARD_LAYOUT_INFO_H - diff --git a/examples/contact-cards/contact-card-layouter.cpp b/examples/contact-cards/contact-card-layouter.cpp index e5ab2c9..d4eef9a 100644 --- a/examples/contact-cards/contact-card-layouter.cpp +++ b/examples/contact-cards/contact-card-layouter.cpp @@ -27,16 +27,16 @@ namespace { const float DEFAULT_PADDING = 25.0f; -const float MINIMUM_ITEMS_PER_ROW_OR_COLUMN( 3.0f ); +const float MINIMUM_ITEMS_PER_ROW_OR_COLUMN(3.0f); -const float HEADER_HEIGHT_TO_UNFOLDED_SIZE_RATIO( 0.1f ); -const Vector2 HEADER_FOLDED_POSITION_AS_RATIO_OF_SIZE( -0.05f, -1.5f ); -const Vector2 HEADER_UNFOLDED_POSITION( Vector2::ZERO ); +const float HEADER_HEIGHT_TO_UNFOLDED_SIZE_RATIO(0.1f); +const Vector2 HEADER_FOLDED_POSITION_AS_RATIO_OF_SIZE(-0.05f, -1.5f); +const Vector2 HEADER_UNFOLDED_POSITION(Vector2::ZERO); -const float IMAGE_SIZE_AS_RATIO_TO_FOLDED_SIZE( 0.5f ); -const Vector2 IMAGE_FOLDED_POSITION_AS_RATIO_OF_SIZE( 0.5f, 0.25f ); +const float IMAGE_SIZE_AS_RATIO_TO_FOLDED_SIZE(0.5f); +const Vector2 IMAGE_FOLDED_POSITION_AS_RATIO_OF_SIZE(0.5f, 0.25f); -const float FOLDED_TEXT_POSITION_AS_RATIO_OF_IMAGE_SIZE( 1.01f ); +const float FOLDED_TEXT_POSITION_AS_RATIO_OF_IMAGE_SIZE(1.01f); } // unnamed namespace ContactCardLayouter::ContactCardLayouter() @@ -44,8 +44,8 @@ ContactCardLayouter::ContactCardLayouter() mContactCards(), mLastPosition(), mPositionIncrementer(), - mItemsPerRow( 0 ), - mInitialized( false ) + mItemsPerRow(0), + mInitialized(false) { } @@ -54,40 +54,40 @@ ContactCardLayouter::~ContactCardLayouter() // Nothing to do as ContactCardContainer uses intrusive pointers so they will be automatically deleted } -void ContactCardLayouter::AddContact( Dali::Window window, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath ) +void ContactCardLayouter::AddContact(Dali::Window window, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath) { - if( ! mInitialized ) + if(!mInitialized) { // Set up the common layouting info shared between all contact cards when first called - mContactCardLayoutInfo.unfoldedPosition = mContactCardLayoutInfo.padding = Vector2( DEFAULT_PADDING, DEFAULT_PADDING ); - mContactCardLayoutInfo.unfoldedSize = Vector2( window.GetSize() ) - mContactCardLayoutInfo.padding * ( MINIMUM_ITEMS_PER_ROW_OR_COLUMN - 1.0f ); + mContactCardLayoutInfo.unfoldedPosition = mContactCardLayoutInfo.padding = Vector2(DEFAULT_PADDING, DEFAULT_PADDING); + mContactCardLayoutInfo.unfoldedSize = Vector2(window.GetSize()) - mContactCardLayoutInfo.padding * (MINIMUM_ITEMS_PER_ROW_OR_COLUMN - 1.0f); // Calculate the size of the folded card (use the minimum of width/height as size) - mContactCardLayoutInfo.foldedSize = ( mContactCardLayoutInfo.unfoldedSize - ( mContactCardLayoutInfo.padding * ( MINIMUM_ITEMS_PER_ROW_OR_COLUMN - 1.0f ) ) ) / MINIMUM_ITEMS_PER_ROW_OR_COLUMN; - mContactCardLayoutInfo.foldedSize.width = mContactCardLayoutInfo.foldedSize.height = std::min( mContactCardLayoutInfo.foldedSize.width, mContactCardLayoutInfo.foldedSize.height ); + mContactCardLayoutInfo.foldedSize = (mContactCardLayoutInfo.unfoldedSize - (mContactCardLayoutInfo.padding * (MINIMUM_ITEMS_PER_ROW_OR_COLUMN - 1.0f))) / MINIMUM_ITEMS_PER_ROW_OR_COLUMN; + mContactCardLayoutInfo.foldedSize.width = mContactCardLayoutInfo.foldedSize.height = std::min(mContactCardLayoutInfo.foldedSize.width, mContactCardLayoutInfo.foldedSize.height); // Set the size and positions of the header - mContactCardLayoutInfo.headerSize.width = mContactCardLayoutInfo.unfoldedSize.width; - mContactCardLayoutInfo.headerSize.height = mContactCardLayoutInfo.unfoldedSize.height * HEADER_HEIGHT_TO_UNFOLDED_SIZE_RATIO; - mContactCardLayoutInfo.headerFoldedPosition = mContactCardLayoutInfo.headerSize * HEADER_FOLDED_POSITION_AS_RATIO_OF_SIZE; + mContactCardLayoutInfo.headerSize.width = mContactCardLayoutInfo.unfoldedSize.width; + mContactCardLayoutInfo.headerSize.height = mContactCardLayoutInfo.unfoldedSize.height * HEADER_HEIGHT_TO_UNFOLDED_SIZE_RATIO; + mContactCardLayoutInfo.headerFoldedPosition = mContactCardLayoutInfo.headerSize * HEADER_FOLDED_POSITION_AS_RATIO_OF_SIZE; mContactCardLayoutInfo.headerUnfoldedPosition = HEADER_UNFOLDED_POSITION; // Set the image size and positions - mContactCardLayoutInfo.imageSize = mContactCardLayoutInfo.foldedSize * IMAGE_SIZE_AS_RATIO_TO_FOLDED_SIZE; - mContactCardLayoutInfo.imageFoldedPosition = mContactCardLayoutInfo.imageSize * IMAGE_FOLDED_POSITION_AS_RATIO_OF_SIZE; + mContactCardLayoutInfo.imageSize = mContactCardLayoutInfo.foldedSize * IMAGE_SIZE_AS_RATIO_TO_FOLDED_SIZE; + mContactCardLayoutInfo.imageFoldedPosition = mContactCardLayoutInfo.imageSize * IMAGE_FOLDED_POSITION_AS_RATIO_OF_SIZE; mContactCardLayoutInfo.imageUnfoldedPosition.x = mContactCardLayoutInfo.padding.width; mContactCardLayoutInfo.imageUnfoldedPosition.y = mContactCardLayoutInfo.headerSize.height + mContactCardLayoutInfo.padding.height; // Set the positions of the contact name - mContactCardLayoutInfo.textFoldedPosition.x = 0.0f; - mContactCardLayoutInfo.textFoldedPosition.y = mContactCardLayoutInfo.imageFoldedPosition.x + mContactCardLayoutInfo.imageSize.height * FOLDED_TEXT_POSITION_AS_RATIO_OF_IMAGE_SIZE; + mContactCardLayoutInfo.textFoldedPosition.x = 0.0f; + mContactCardLayoutInfo.textFoldedPosition.y = mContactCardLayoutInfo.imageFoldedPosition.x + mContactCardLayoutInfo.imageSize.height * FOLDED_TEXT_POSITION_AS_RATIO_OF_IMAGE_SIZE; mContactCardLayoutInfo.textUnfoldedPosition.x = mContactCardLayoutInfo.padding.width; mContactCardLayoutInfo.textUnfoldedPosition.y = mContactCardLayoutInfo.imageUnfoldedPosition.y + mContactCardLayoutInfo.imageSize.height + mContactCardLayoutInfo.padding.height; // Figure out the positions of the contact cards - mItemsPerRow = ( mContactCardLayoutInfo.unfoldedSize.width + mContactCardLayoutInfo.padding.width ) / ( mContactCardLayoutInfo.foldedSize.width + mContactCardLayoutInfo.padding.width ); - mLastPosition = mContactCardLayoutInfo.unfoldedPosition; + mItemsPerRow = (mContactCardLayoutInfo.unfoldedSize.width + mContactCardLayoutInfo.padding.width) / (mContactCardLayoutInfo.foldedSize.width + mContactCardLayoutInfo.padding.width); + mLastPosition = mContactCardLayoutInfo.unfoldedPosition; mPositionIncrementer.x = mContactCardLayoutInfo.foldedSize.width + mContactCardLayoutInfo.padding.width; mPositionIncrementer.y = mContactCardLayoutInfo.foldedSize.height + mContactCardLayoutInfo.padding.height; @@ -95,16 +95,16 @@ void ContactCardLayouter::AddContact( Dali::Window window, const std::string& co } // Create a new contact card and add to our container - mContactCards.push_back( new ContactCard( window, mContactCardLayoutInfo, contactName, contactAddress, imagePath, NextCardPosition() ) ); + mContactCards.push_back(new ContactCard(window, mContactCardLayoutInfo, contactName, contactAddress, imagePath, NextCardPosition())); } const Vector2& ContactCardLayouter::NextCardPosition() { size_t currentNumOfCards = mContactCards.size(); - if( currentNumOfCards ) + if(currentNumOfCards) { - if( currentNumOfCards % mItemsPerRow ) + if(currentNumOfCards % mItemsPerRow) { mLastPosition.x += mPositionIncrementer.x; } diff --git a/examples/contact-cards/contact-card-layouter.h b/examples/contact-cards/contact-card-layouter.h index 06a8512..d7e10c3 100644 --- a/examples/contact-cards/contact-card-layouter.h +++ b/examples/contact-cards/contact-card-layouter.h @@ -19,11 +19,11 @@ */ // EXTERNAL INCLUDES -#include -#include #include #include #include +#include +#include // INTERNAL INCLUDES #include "contact-card-layout-info.h" @@ -41,7 +41,6 @@ class ContactCard; class ContactCardLayouter { public: - /** * @brief Constructor. */ @@ -59,10 +58,9 @@ public: * @param[in] contactAddress The address of the contact to display. * @param[in] imagePath The path to the image to display. */ - void AddContact( Dali::Window window, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath ); + void AddContact(Dali::Window window, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath); private: - /** * @brief Calculates the next position of the contact card that's about to be added to our container. * @return A reference to the next position. @@ -71,17 +69,15 @@ private: ContactCardLayoutInfo mContactCardLayoutInfo; ///< The common layouting information used by all contact cards. Set up when AddContact is first called. - typedef Dali::IntrusivePtr< ContactCard > ContactCardPtr; ///< Better than raw pointers as these are ref counted and the memory is released when the count reduces to 0. - typedef std::vector< ContactCardPtr > ContactCardContainer; - ContactCardContainer mContactCards; ///< Contains all the contact cards. + typedef Dali::IntrusivePtr ContactCardPtr; ///< Better than raw pointers as these are ref counted and the memory is released when the count reduces to 0. + typedef std::vector ContactCardContainer; + ContactCardContainer mContactCards; ///< Contains all the contact cards. - Dali::Vector2 mLastPosition; ///< The last position a contact card was added. + Dali::Vector2 mLastPosition; ///< The last position a contact card was added. Dali::Vector2 mPositionIncrementer; ///< Calculated once when AddContact is first called. - size_t mItemsPerRow; ///< Calculated once when AddContact is first called and stores the number of items we have in a row. + size_t mItemsPerRow; ///< Calculated once when AddContact is first called and stores the number of items we have in a row. bool mInitialized; ///< Whether initialization has taken place or not. }; - - #endif // CONTACT_CARD_LAYOUTER_H diff --git a/examples/contact-cards/contact-card.cpp b/examples/contact-cards/contact-card.cpp index 4959d80..2a8d6ce 100644 --- a/examples/contact-cards/contact-card.cpp +++ b/examples/contact-cards/contact-card.cpp @@ -19,13 +19,13 @@ #include "contact-card.h" // EXTERNAL INCLUDES -#include #include #include +#include // INTERNAL INCLUDES -#include "contact-card-layout-info.h" #include "clipped-image.h" +#include "contact-card-layout-info.h" #include "masked-image.h" using namespace Dali; @@ -47,14 +47,14 @@ namespace * o---------------o | | | | | Fade out other cards Animation ( 0ms To 160ms) * o---------------------------------------o Mesh Morph Animation ( 0ms To 400ms) */ -const TimePeriod TIME_PERIOD_UNFOLD_X( 0.0f, 0.36f ); ///< Start at 0ms, duration 360ms -const TimePeriod TIME_PERIOD_UNFOLD_Y( 0.04f, 0.36f ); ///< Start at 40ms, duration 360ms -const TimePeriod TIME_PERIOD_UNFOLD_WIDTH( 0.0f, 0.36f ); ///< Start at 0ms, duration 360ms -const TimePeriod TIME_PERIOD_UNFOLD_HEIGHT( 0.04f, 0.36f ); ///< Start at 40ms, duration 360ms -const TimePeriod TIME_PERIOD_UNFOLD_NAME_OPACITY( 0.0f, 0.08f ); ///< Start at 0ms, duration 80ms -const TimePeriod TIME_PERIOD_UNFOLD_DETAIL_OPACITY( 0.08f, 0.08f ); ///< Start at 80ms, duration 80ms -const TimePeriod TIME_PERIOD_UNFOLD_SIBLING_OPACITY( 0.0f, 0.08f ); ///< Start at 0ms, duration 80ms -const TimePeriod TIME_PERIOD_UNFOLD_MESH_MORPH( 0.0f, 0.4f ); ///< Start at 0ms, duration 400ms +const TimePeriod TIME_PERIOD_UNFOLD_X(0.0f, 0.36f); ///< Start at 0ms, duration 360ms +const TimePeriod TIME_PERIOD_UNFOLD_Y(0.04f, 0.36f); ///< Start at 40ms, duration 360ms +const TimePeriod TIME_PERIOD_UNFOLD_WIDTH(0.0f, 0.36f); ///< Start at 0ms, duration 360ms +const TimePeriod TIME_PERIOD_UNFOLD_HEIGHT(0.04f, 0.36f); ///< Start at 40ms, duration 360ms +const TimePeriod TIME_PERIOD_UNFOLD_NAME_OPACITY(0.0f, 0.08f); ///< Start at 0ms, duration 80ms +const TimePeriod TIME_PERIOD_UNFOLD_DETAIL_OPACITY(0.08f, 0.08f); ///< Start at 80ms, duration 80ms +const TimePeriod TIME_PERIOD_UNFOLD_SIBLING_OPACITY(0.0f, 0.08f); ///< Start at 0ms, duration 80ms +const TimePeriod TIME_PERIOD_UNFOLD_MESH_MORPH(0.0f, 0.4f); ///< Start at 0ms, duration 400ms /* * The constants below are used to create the following Fold Animation: @@ -70,29 +70,29 @@ const TimePeriod TIME_PERIOD_UNFOLD_MESH_MORPH( 0.0f, 0.4f ); ///< Start at 0ms, * | | | | | | | o-------o Fade in other cards animation (320ms To 400ms) * o---------------------------------------o Morph Animation ( 0ms To 400ms) */ -const TimePeriod TIME_PERIOD_FOLD_X( 0.064f, 0.336f ); ///< Start at 64ms, duration 336ms -const TimePeriod TIME_PERIOD_FOLD_Y( 0.0f, 0.336f ); ///< Start at 0ms, duration 336ms -const TimePeriod TIME_PERIOD_FOLD_WIDTH( 0.064f, 0.336f ); ///< Start at 64ms, duration 336ms -const TimePeriod TIME_PERIOD_FOLD_HEIGHT( 0.0f, 0.336f ); ///< Start at 0ms, duration 336ms -const TimePeriod TIME_PERIOD_FOLD_NAME_OPACITY( 0.08f, 0.08f ); ///< Start at 80ms, duration 80ms -const TimePeriod TIME_PERIOD_FOLD_DETAIL_OPACITY( 0.0f, 0.08f ); ///< Start at 0ms, duration 80ms -const TimePeriod TIME_PERIOD_FOLD_SIBLING_OPACITY( 0.32f, 0.08f ); ///< Start at 320ms, duration 80ms -const TimePeriod TIME_PERIOD_FOLD_MESH_MORPH( 0.0f, 0.4f ); ///< Start at 0ms, duration 400ms +const TimePeriod TIME_PERIOD_FOLD_X(0.064f, 0.336f); ///< Start at 64ms, duration 336ms +const TimePeriod TIME_PERIOD_FOLD_Y(0.0f, 0.336f); ///< Start at 0ms, duration 336ms +const TimePeriod TIME_PERIOD_FOLD_WIDTH(0.064f, 0.336f); ///< Start at 64ms, duration 336ms +const TimePeriod TIME_PERIOD_FOLD_HEIGHT(0.0f, 0.336f); ///< Start at 0ms, duration 336ms +const TimePeriod TIME_PERIOD_FOLD_NAME_OPACITY(0.08f, 0.08f); ///< Start at 80ms, duration 80ms +const TimePeriod TIME_PERIOD_FOLD_DETAIL_OPACITY(0.0f, 0.08f); ///< Start at 0ms, duration 80ms +const TimePeriod TIME_PERIOD_FOLD_SIBLING_OPACITY(0.32f, 0.08f); ///< Start at 320ms, duration 80ms +const TimePeriod TIME_PERIOD_FOLD_MESH_MORPH(0.0f, 0.4f); ///< Start at 0ms, duration 400ms -AlphaFunction ALPHA_FUNCTION_UNFOLD( AlphaFunction::DEFAULT ); ///< Alpha function used for the Unfold Animation -AlphaFunction ALPHA_FUNCTION_FOLD( AlphaFunction::EASE_IN_OUT ); ///< Alpha function used for the Fold Animation +AlphaFunction ALPHA_FUNCTION_UNFOLD(AlphaFunction::DEFAULT); ///< Alpha function used for the Unfold Animation +AlphaFunction ALPHA_FUNCTION_FOLD(AlphaFunction::EASE_IN_OUT); ///< Alpha function used for the Fold Animation -const Vector4 HEADER_COLOR( 231.0f/255.0f, 231.0f/255.0f, 231.0f/255.0f, 1.0f ); ///< The color of the header +const Vector4 HEADER_COLOR(231.0f / 255.0f, 231.0f / 255.0f, 231.0f / 255.0f, 1.0f); ///< The color of the header } // unnamed namespace ContactCard::ContactCard( - Dali::Window window, - const ContactCardLayoutInfo& contactCardLayoutInfo, - const std::string& contactName, - const std::string& contactAddress, - const std::string& imagePath, - const Vector2& position ) + Dali::Window window, + const ContactCardLayoutInfo& contactCardLayoutInfo, + const std::string& contactName, + const std::string& contactAddress, + const std::string& imagePath, + const Vector2& position) : mTapDetector(), mContactCard(), mHeader(), @@ -101,93 +101,93 @@ ContactCard::ContactCard( mNameText(), mDetailText(), mAnimation(), - mSlotDelegate( this ), - mContactCardLayoutInfo( contactCardLayoutInfo ), - foldedPosition( position ), - mClippedImagePropertyIndex( Property::INVALID_INDEX ), - mFolded( true ) + mSlotDelegate(this), + mContactCardLayoutInfo(contactCardLayoutInfo), + foldedPosition(position), + mClippedImagePropertyIndex(Property::INVALID_INDEX), + mFolded(true) { // Connect to the window's key signal to allow Back and Escape to fold a contact card if it is unfolded - window.KeyEventSignal().Connect( mSlotDelegate, &ContactCard::OnKeyEvent ); + window.KeyEventSignal().Connect(mSlotDelegate, &ContactCard::OnKeyEvent); // Create a control which will be used for the background and to clip the contents mContactCard = Control::New(); - mContactCard.SetProperty( Control::Property::BACKGROUND, - Property::Map{ { Toolkit::Visual::Property::TYPE, Visual::COLOR }, - { ColorVisual::Property::MIX_COLOR, Color::WHITE } } ); - mContactCard.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); - mContactCard.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mContactCard.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mContactCard.SetProperty( Actor::Property::POSITION, Vector2( foldedPosition.x, foldedPosition.y )); - mContactCard.SetProperty( Actor::Property::SIZE, mContactCardLayoutInfo.foldedSize ); - window.Add( mContactCard ); + mContactCard.SetProperty(Control::Property::BACKGROUND, + Property::Map{{Toolkit::Visual::Property::TYPE, Visual::COLOR}, + {ColorVisual::Property::MIX_COLOR, Color::WHITE}}); + mContactCard.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN); + mContactCard.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mContactCard.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mContactCard.SetProperty(Actor::Property::POSITION, Vector2(foldedPosition.x, foldedPosition.y)); + mContactCard.SetProperty(Actor::Property::SIZE, mContactCardLayoutInfo.foldedSize); + window.Add(mContactCard); // Create the header which will be shown only when the contact is unfolded mHeader = Control::New(); - mHeader.SetProperty( Actor::Property::SIZE, mContactCardLayoutInfo.headerSize ); - mHeader.SetProperty( Control::Property::BACKGROUND, - Property::Map{ { Toolkit::Visual::Property::TYPE, Visual::COLOR }, - { ColorVisual::Property::MIX_COLOR, HEADER_COLOR } } ); - mHeader.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mHeader.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mHeader.SetProperty( Actor::Property::POSITION, Vector2( mContactCardLayoutInfo.headerFoldedPosition.x, mContactCardLayoutInfo.headerFoldedPosition.y )); + mHeader.SetProperty(Actor::Property::SIZE, mContactCardLayoutInfo.headerSize); + mHeader.SetProperty(Control::Property::BACKGROUND, + Property::Map{{Toolkit::Visual::Property::TYPE, Visual::COLOR}, + {ColorVisual::Property::MIX_COLOR, HEADER_COLOR}}); + mHeader.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mHeader.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mHeader.SetProperty(Actor::Property::POSITION, Vector2(mContactCardLayoutInfo.headerFoldedPosition.x, mContactCardLayoutInfo.headerFoldedPosition.y)); // Create a clipped image (whose clipping can be animated) - mClippedImage = ClippedImage::Create( imagePath, mClippedImagePropertyIndex ); - mClippedImage.SetProperty( Actor::Property::SIZE, mContactCardLayoutInfo.imageSize ); - mClippedImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mClippedImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mClippedImage.SetProperty( Actor::Property::POSITION, Vector2( mContactCardLayoutInfo.imageFoldedPosition.x, mContactCardLayoutInfo.imageFoldedPosition.y )); - mClippedImage.SetProperty( Actor::Property::VISIBLE, false ); // Hide image as we only want to display it if we are animating or unfolded - mContactCard.Add( mClippedImage ); + mClippedImage = ClippedImage::Create(imagePath, mClippedImagePropertyIndex); + mClippedImage.SetProperty(Actor::Property::SIZE, mContactCardLayoutInfo.imageSize); + mClippedImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mClippedImage.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mClippedImage.SetProperty(Actor::Property::POSITION, Vector2(mContactCardLayoutInfo.imageFoldedPosition.x, mContactCardLayoutInfo.imageFoldedPosition.y)); + mClippedImage.SetProperty(Actor::Property::VISIBLE, false); // Hide image as we only want to display it if we are animating or unfolded + mContactCard.Add(mClippedImage); // Create an image with a mask which is to be used when the contact is folded - mMaskedImage = MaskedImage::Create( imagePath ); - mMaskedImage.SetProperty( Actor::Property::SIZE, mContactCardLayoutInfo.imageSize ); - mMaskedImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mMaskedImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mMaskedImage.SetProperty( Actor::Property::POSITION, Vector2( mContactCardLayoutInfo.imageFoldedPosition.x, mContactCardLayoutInfo.imageFoldedPosition.y )); - mContactCard.Add( mMaskedImage ); + mMaskedImage = MaskedImage::Create(imagePath); + mMaskedImage.SetProperty(Actor::Property::SIZE, mContactCardLayoutInfo.imageSize); + mMaskedImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mMaskedImage.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mMaskedImage.SetProperty(Actor::Property::POSITION, Vector2(mContactCardLayoutInfo.imageFoldedPosition.x, mContactCardLayoutInfo.imageFoldedPosition.y)); + mContactCard.Add(mMaskedImage); // Add the text label for just the name - mNameText = TextLabel::New( contactName ); - mNameText.SetStyleName( "ContactNameTextLabel" ); - mNameText.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mNameText.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mNameText.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mNameText.SetProperty( Actor::Property::POSITION, Vector2( mContactCardLayoutInfo.textFoldedPosition.x, mContactCardLayoutInfo.textFoldedPosition.y )); - mContactCard.Add( mNameText ); + mNameText = TextLabel::New(contactName); + mNameText.SetStyleName("ContactNameTextLabel"); + mNameText.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mNameText.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mNameText.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mNameText.SetProperty(Actor::Property::POSITION, Vector2(mContactCardLayoutInfo.textFoldedPosition.x, mContactCardLayoutInfo.textFoldedPosition.y)); + mContactCard.Add(mNameText); // Create the detail text-label - std::string detailString( contactName ); + std::string detailString(contactName); detailString += "\n\n"; detailString += contactAddress; - mDetailText = TextLabel::New( detailString ); - mDetailText.SetStyleName( "ContactDetailTextLabel" ); - mDetailText.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mDetailText.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mDetailText.SetProperty( Actor::Property::POSITION, Vector2( mContactCardLayoutInfo.textFoldedPosition.x, mContactCardLayoutInfo.textFoldedPosition.y )); - mDetailText.SetProperty( Actor::Property::SIZE, Vector2( mContactCardLayoutInfo.unfoldedSize.width - mContactCardLayoutInfo.textFoldedPosition.x * 2.0f, 0.0f ) ); - mDetailText.SetProperty( Actor::Property::OPACITY, 0.0f ); + mDetailText = TextLabel::New(detailString); + mDetailText.SetStyleName("ContactDetailTextLabel"); + mDetailText.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mDetailText.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mDetailText.SetProperty(Actor::Property::POSITION, Vector2(mContactCardLayoutInfo.textFoldedPosition.x, mContactCardLayoutInfo.textFoldedPosition.y)); + mDetailText.SetProperty(Actor::Property::SIZE, Vector2(mContactCardLayoutInfo.unfoldedSize.width - mContactCardLayoutInfo.textFoldedPosition.x * 2.0f, 0.0f)); + mDetailText.SetProperty(Actor::Property::OPACITY, 0.0f); // Attach tap detection to the overall clip control mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach( mContactCard ); - mTapDetector.DetectedSignal().Connect( mSlotDelegate, &ContactCard::OnTap ); + mTapDetector.Attach(mContactCard); + mTapDetector.DetectedSignal().Connect(mSlotDelegate, &ContactCard::OnTap); } ContactCard::~ContactCard() { - if( mContactCard ) + if(mContactCard) { mContactCard.Unparent(); } } -void ContactCard::OnTap( Actor actor, const TapGesture& /* gesture */ ) +void ContactCard::OnTap(Actor actor, const TapGesture& /* gesture */) { - if( actor == mContactCard ) + if(actor == mContactCard) { Animate(); } @@ -197,124 +197,124 @@ void ContactCard::Animate() { KeyInputFocusManager keyInputFocusManager = KeyInputFocusManager::Get(); - mAnimation = Animation::New( 0.0f ); // Overall duration is unimportant as superseded by TimePeriods set later + mAnimation = Animation::New(0.0f); // Overall duration is unimportant as superseded by TimePeriods set later - if( mFolded ) + if(mFolded) { // Set key-input-focus to our contact-card so that we can fold the contact-card if we receive a Back or Esc key - keyInputFocusManager.SetFocus( mContactCard ); + keyInputFocusManager.SetFocus(mContactCard); - mContactCard.Add( mHeader ); - mContactCard.Add( mDetailText ); + mContactCard.Add(mHeader); + mContactCard.Add(mDetailText); // Show clipped-image to animate geometry and hide the masked-image - mClippedImage.SetProperty( Actor::Property::VISIBLE, true ); - mMaskedImage.SetProperty( Actor::Property::VISIBLE, false ); + mClippedImage.SetProperty(Actor::Property::VISIBLE, true); + mMaskedImage.SetProperty(Actor::Property::VISIBLE, false); // Animate the size of the control (and clipping area) - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_X ), mContactCardLayoutInfo.unfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X ); - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.unfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y ); - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_WIDTH ), mContactCardLayoutInfo.unfoldedSize.width, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_WIDTH ); - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_HEIGHT ), mContactCardLayoutInfo.unfoldedSize.height, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_HEIGHT ); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::POSITION_X), mContactCardLayoutInfo.unfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::POSITION_Y), mContactCardLayoutInfo.unfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::SIZE_WIDTH), mContactCardLayoutInfo.unfoldedSize.width, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_WIDTH); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::SIZE_HEIGHT), mContactCardLayoutInfo.unfoldedSize.height, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_HEIGHT); // Animate the header area into position - mAnimation.AnimateTo( Property( mHeader, Actor::Property::POSITION_X ), mContactCardLayoutInfo.headerUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X ); - mAnimation.AnimateTo( Property( mHeader, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.headerUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y ); + mAnimation.AnimateTo(Property(mHeader, Actor::Property::POSITION_X), mContactCardLayoutInfo.headerUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X); + mAnimation.AnimateTo(Property(mHeader, Actor::Property::POSITION_Y), mContactCardLayoutInfo.headerUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y); // Animate the clipped image into the unfolded position and into a quad - mAnimation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_X ), mContactCardLayoutInfo.imageUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X ); - mAnimation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.imageUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y ); - mAnimation.AnimateTo( Property( mClippedImage, mClippedImagePropertyIndex ), ClippedImage::QUAD_GEOMETRY, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_MESH_MORPH ); + mAnimation.AnimateTo(Property(mClippedImage, Actor::Property::POSITION_X), mContactCardLayoutInfo.imageUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X); + mAnimation.AnimateTo(Property(mClippedImage, Actor::Property::POSITION_Y), mContactCardLayoutInfo.imageUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y); + mAnimation.AnimateTo(Property(mClippedImage, mClippedImagePropertyIndex), ClippedImage::QUAD_GEOMETRY, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_MESH_MORPH); // Fade out the opacity of the name, and animate into the unfolded position - mAnimation.AnimateTo( Property( mNameText, Actor::Property::COLOR_ALPHA ), 0.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_NAME_OPACITY ); - mAnimation.AnimateTo( Property( mNameText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X ); - mAnimation.AnimateTo( Property( mNameText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y ); + mAnimation.AnimateTo(Property(mNameText, Actor::Property::COLOR_ALPHA), 0.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_NAME_OPACITY); + mAnimation.AnimateTo(Property(mNameText, Actor::Property::POSITION_X), mContactCardLayoutInfo.textUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X); + mAnimation.AnimateTo(Property(mNameText, Actor::Property::POSITION_Y), mContactCardLayoutInfo.textUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y); // Fade in the opacity of the detail, and animate into the unfolded position - mAnimation.AnimateTo( Property( mDetailText, Actor::Property::COLOR_ALPHA ), 1.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_DETAIL_OPACITY ); - mAnimation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X ); - mAnimation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y ); + mAnimation.AnimateTo(Property(mDetailText, Actor::Property::COLOR_ALPHA), 1.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_DETAIL_OPACITY); + mAnimation.AnimateTo(Property(mDetailText, Actor::Property::POSITION_X), mContactCardLayoutInfo.textUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X); + mAnimation.AnimateTo(Property(mDetailText, Actor::Property::POSITION_Y), mContactCardLayoutInfo.textUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y); // Fade out all the siblings Actor parent = mContactCard.GetParent(); - for( size_t i = 0; i < parent.GetChildCount(); ++i ) + for(size_t i = 0; i < parent.GetChildCount(); ++i) { - Actor sibling = parent.GetChildAt( i ); - if( sibling != mContactCard ) + Actor sibling = parent.GetChildAt(i); + if(sibling != mContactCard) { - mAnimation.AnimateTo( Property( sibling, Actor::Property::COLOR_ALPHA ), 0.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_SIBLING_OPACITY ); - sibling.SetProperty( Actor::Property::SENSITIVE, false ); + mAnimation.AnimateTo(Property(sibling, Actor::Property::COLOR_ALPHA), 0.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_SIBLING_OPACITY); + sibling.SetProperty(Actor::Property::SENSITIVE, false); } } - mAnimation.FinishedSignal().Connect( mSlotDelegate, &ContactCard::OnAnimationFinished ); + mAnimation.FinishedSignal().Connect(mSlotDelegate, &ContactCard::OnAnimationFinished); mAnimation.Play(); } else { // Remove key-input-focus from our contact-card when we are folded - keyInputFocusManager.RemoveFocus( mContactCard ); + keyInputFocusManager.RemoveFocus(mContactCard); - mContactCard.Add( mNameText ); + mContactCard.Add(mNameText); // Animate the size of the control (and clipping area) - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_X ), foldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X ); - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_Y ), foldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y ); - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_WIDTH ), mContactCardLayoutInfo.foldedSize.width, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_WIDTH ); - mAnimation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_HEIGHT ), mContactCardLayoutInfo.foldedSize.height, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_HEIGHT ); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::POSITION_X), foldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::POSITION_Y), foldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::SIZE_WIDTH), mContactCardLayoutInfo.foldedSize.width, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_WIDTH); + mAnimation.AnimateTo(Property(mContactCard, Actor::Property::SIZE_HEIGHT), mContactCardLayoutInfo.foldedSize.height, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_HEIGHT); // Animate the header area out of position - mAnimation.AnimateTo( Property( mHeader, Actor::Property::POSITION_X ), mContactCardLayoutInfo.headerFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X ); - mAnimation.AnimateTo( Property( mHeader, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.headerFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y ); + mAnimation.AnimateTo(Property(mHeader, Actor::Property::POSITION_X), mContactCardLayoutInfo.headerFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X); + mAnimation.AnimateTo(Property(mHeader, Actor::Property::POSITION_Y), mContactCardLayoutInfo.headerFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y); // Animate the clipped image into the folded position and into a circle - mAnimation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_X ), mContactCardLayoutInfo.imageFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X ); - mAnimation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.imageFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y ); - mAnimation.AnimateTo( Property( mClippedImage, mClippedImagePropertyIndex ), ClippedImage::CIRCLE_GEOMETRY, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_MESH_MORPH ); + mAnimation.AnimateTo(Property(mClippedImage, Actor::Property::POSITION_X), mContactCardLayoutInfo.imageFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X); + mAnimation.AnimateTo(Property(mClippedImage, Actor::Property::POSITION_Y), mContactCardLayoutInfo.imageFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y); + mAnimation.AnimateTo(Property(mClippedImage, mClippedImagePropertyIndex), ClippedImage::CIRCLE_GEOMETRY, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_MESH_MORPH); // Fade in the opacity of the name, and animate into the folded position - mAnimation.AnimateTo( Property( mNameText, Actor::Property::COLOR_ALPHA ), 1.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_NAME_OPACITY ); - mAnimation.AnimateTo( Property( mNameText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X ); - mAnimation.AnimateTo( Property( mNameText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y ); + mAnimation.AnimateTo(Property(mNameText, Actor::Property::COLOR_ALPHA), 1.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_NAME_OPACITY); + mAnimation.AnimateTo(Property(mNameText, Actor::Property::POSITION_X), mContactCardLayoutInfo.textFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X); + mAnimation.AnimateTo(Property(mNameText, Actor::Property::POSITION_Y), mContactCardLayoutInfo.textFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y); // Fade out the opacity of the detail, and animate into the folded position - mAnimation.AnimateTo( Property( mDetailText, Actor::Property::COLOR_ALPHA ), 0.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_DETAIL_OPACITY ); - mAnimation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X ); - mAnimation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y ); + mAnimation.AnimateTo(Property(mDetailText, Actor::Property::COLOR_ALPHA), 0.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_DETAIL_OPACITY); + mAnimation.AnimateTo(Property(mDetailText, Actor::Property::POSITION_X), mContactCardLayoutInfo.textFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X); + mAnimation.AnimateTo(Property(mDetailText, Actor::Property::POSITION_Y), mContactCardLayoutInfo.textFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y); // Slowly fade in all the siblings Actor parent = mContactCard.GetParent(); - for( size_t i = 0; i < parent.GetChildCount(); ++i ) + for(size_t i = 0; i < parent.GetChildCount(); ++i) { - Actor sibling = parent.GetChildAt( i ); - if( sibling != mContactCard ) + Actor sibling = parent.GetChildAt(i); + if(sibling != mContactCard) { - mAnimation.AnimateTo( Property( sibling, Actor::Property::COLOR_ALPHA ), 1.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_SIBLING_OPACITY ); - sibling.SetProperty( Actor::Property::SENSITIVE, true ); + mAnimation.AnimateTo(Property(sibling, Actor::Property::COLOR_ALPHA), 1.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_SIBLING_OPACITY); + sibling.SetProperty(Actor::Property::SENSITIVE, true); } } - mAnimation.FinishedSignal().Connect( mSlotDelegate, &ContactCard::OnAnimationFinished ); + mAnimation.FinishedSignal().Connect(mSlotDelegate, &ContactCard::OnAnimationFinished); mAnimation.Play(); } mFolded = !mFolded; } -void ContactCard::OnAnimationFinished( Animation& animation ) +void ContactCard::OnAnimationFinished(Animation& animation) { // Ensure the finishing animation is the latest as we do not want to change state if a previous animation has finished - if( mAnimation == animation ) + if(mAnimation == animation) { - if( mFolded ) + if(mFolded) { mHeader.Unparent(); mDetailText.Unparent(); // Hide the clipped-image as we have finished animating the geometry and show the masked-image again - mClippedImage.SetProperty( Actor::Property::VISIBLE, false ); - mMaskedImage.SetProperty( Actor::Property::VISIBLE, true ); + mClippedImage.SetProperty(Actor::Property::VISIBLE, false); + mMaskedImage.SetProperty(Actor::Property::VISIBLE, true); } else { @@ -324,15 +324,15 @@ void ContactCard::OnAnimationFinished( Animation& animation ) } } -void ContactCard::OnKeyEvent( const KeyEvent& event ) +void ContactCard::OnKeyEvent(const KeyEvent& event) { - if( ( ! mFolded ) && // If we're folded then there's no need to do any more checking - ( event.GetState() == KeyEvent::DOWN ) ) + if((!mFolded) && // If we're folded then there's no need to do any more checking + (event.GetState() == KeyEvent::DOWN)) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { KeyInputFocusManager keyInputFocusManager = KeyInputFocusManager::Get(); - if( keyInputFocusManager.GetCurrentFocusControl() == mContactCard ) + if(keyInputFocusManager.GetCurrentFocusControl() == mContactCard) { // Our contact-card is set to receive focus and we're unfolded so animate back to the folded state Animate(); diff --git a/examples/contact-cards/contact-card.h b/examples/contact-cards/contact-card.h index 21a981f..d171952 100644 --- a/examples/contact-cards/contact-card.h +++ b/examples/contact-cards/contact-card.h @@ -19,13 +19,13 @@ */ // EXTERNAL INCLUDES -#include +#include #include #include #include #include #include -#include +#include struct ContactCardLayoutInfo; @@ -44,7 +44,6 @@ struct ContactCardLayoutInfo; class ContactCard : public Dali::RefObject { public: - /** * @brief Constructor. * @@ -57,10 +56,9 @@ public: * @param[in] imagePath The path to the image to display. * @param[in] position The unique folded position of this particular contact-card. */ - ContactCard( Dali::Window window, const ContactCardLayoutInfo& contactCardLayoutInfo, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath, const Dali::Vector2& position ); + ContactCard(Dali::Window window, const ContactCardLayoutInfo& contactCardLayoutInfo, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath, const Dali::Vector2& position); private: - /** * @brief Private Destructor. Will only be deleted when ref-count goes to 0. * @@ -73,7 +71,7 @@ private: * @param[in] actor The tapped actor. * @param[in] gesture The tap gesture. */ - void OnTap( Dali::Actor actor, const Dali::TapGesture& gesture ); + void OnTap(Dali::Actor actor, const Dali::TapGesture& gesture); /** * @brief Animates the fold/unfold animation as required. @@ -84,7 +82,7 @@ private: * @brief Called when the animation finishes. * @param[in] animation The animation which has just finished. */ - void OnAnimationFinished( Dali::Animation& animation ); + void OnAnimationFinished(Dali::Animation& animation); /** * @brief Called when any key event is received @@ -92,24 +90,24 @@ private: * Will use this to fold a contact card if it is unfolded. * @param[in] event The key event information */ - void OnKeyEvent( const Dali::KeyEvent& event ); + void OnKeyEvent(const Dali::KeyEvent& event); - Dali::TapGestureDetector mTapDetector; ///< Used for tap detection. - Dali::Toolkit::Control mContactCard; ///< Used for the background and to clip the contents. - Dali::Toolkit::Control mHeader; ///< Header shown when unfolded. - Dali::Toolkit::Control mClippedImage; ///< The image representing the contact (whose clipping can be animated). - Dali::Toolkit::Control mMaskedImage; ///< The image with a mask (better quality around the edges than the clipped image when folded). - Dali::Toolkit::Control mNameText; ///< The text shown when folded. - Dali::Toolkit::Control mDetailText; ///< The text shown when unfolded. + Dali::TapGestureDetector mTapDetector; ///< Used for tap detection. + Dali::Toolkit::Control mContactCard; ///< Used for the background and to clip the contents. + Dali::Toolkit::Control mHeader; ///< Header shown when unfolded. + Dali::Toolkit::Control mClippedImage; ///< The image representing the contact (whose clipping can be animated). + Dali::Toolkit::Control mMaskedImage; ///< The image with a mask (better quality around the edges than the clipped image when folded). + Dali::Toolkit::Control mNameText; ///< The text shown when folded. + Dali::Toolkit::Control mDetailText; ///< The text shown when unfolded. Dali::Animation mAnimation; ///< The fold/unfold animation. - Dali::SlotDelegate< ContactCard > mSlotDelegate; ///< Used to automatically disconnect our member functions from signals that this class connects to upon destruction. Can be used instead of inheriting from ConnectionTracker. + Dali::SlotDelegate mSlotDelegate; ///< Used to automatically disconnect our member functions from signals that this class connects to upon destruction. Can be used instead of inheriting from ConnectionTracker. - const ContactCardLayoutInfo& mContactCardLayoutInfo; ///< Reference to the common data used by all contact cards. - const Dali::Vector2 foldedPosition; ///< The unique position of this card when it is folded. - Dali::Property::Index mClippedImagePropertyIndex; ///< Index used to animate the clipping of mClippedImage. - bool mFolded; ///< Whether the contact card is folded or not. + const ContactCardLayoutInfo& mContactCardLayoutInfo; ///< Reference to the common data used by all contact cards. + const Dali::Vector2 foldedPosition; ///< The unique position of this card when it is folded. + Dali::Property::Index mClippedImagePropertyIndex; ///< Index used to animate the clipping of mClippedImage. + bool mFolded; ///< Whether the contact card is folded or not. }; #endif // CONTACT_CARD_H diff --git a/examples/contact-cards/contact-cards-example.cpp b/examples/contact-cards/contact-cards-example.cpp index 343edbe..e856900 100644 --- a/examples/contact-cards/contact-cards-example.cpp +++ b/examples/contact-cards/contact-cards-example.cpp @@ -16,11 +16,11 @@ */ // EXTERNAL INCLUDES -#include +#include #include #include #include -#include +#include // INTERNAL INCLUDES #include "contact-card-layouter.h" @@ -31,8 +31,8 @@ using namespace Dali::Toolkit; namespace { -const Vector4 WINDOW_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the window -const char * const THEME_PATH( DEMO_STYLE_DIR "contact-cards-example-theme.json" ); ///< The theme used for this example +const Vector4 WINDOW_COLOR(211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f); ///< The color of the window +const char* const THEME_PATH(DEMO_STYLE_DIR "contact-cards-example-theme.json"); ///< The theme used for this example } // unnamed namespace /** @@ -58,35 +58,33 @@ const char * const THEME_PATH( DEMO_STYLE_DIR "contact-cards-example-theme.json" class ContactCardController : public ConnectionTracker // Inherit from ConnectionTracker so that our signals can be automatically disconnected upon our destruction. { public: - /** * @brief Constructor. * @param[in] application A reference to the Application class. */ - ContactCardController( Application& application ) - : mApplication( application ) + ContactCardController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ContactCardController::Create ); + mApplication.InitSignal().Connect(this, &ContactCardController::Create); } private: - /** * @brief Called to initialise the application content * @param[in] application A reference to the Application class. */ - void Create( Application& application ) + void Create(Application& application) { // Set the window background color and connect to the window's key signal to allow Back and Escape to exit. Window window = application.GetWindow(); - window.SetBackgroundColor( WINDOW_COLOR ); - window.KeyEventSignal().Connect( this, &ContactCardController::OnKeyEvent ); + window.SetBackgroundColor(WINDOW_COLOR); + window.KeyEventSignal().Connect(this, &ContactCardController::OnKeyEvent); // Add all the contacts to the layouter - for( size_t i = 0; i < ContactData::TABLE_SIZE; ++i ) + for(size_t i = 0; i < ContactData::TABLE_SIZE; ++i) { - mContactCardLayouter.AddContact( window, ContactData::TABLE[ i ].name, ContactData::TABLE[ i ].address, ContactData::TABLE[ i ].imagePath ); + mContactCardLayouter.AddContact(window, ContactData::TABLE[i].name, ContactData::TABLE[i].address, ContactData::TABLE[i].imagePath); } } @@ -96,14 +94,14 @@ private: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { KeyInputFocusManager keyInputFocusManager = KeyInputFocusManager::Get(); - if( ! keyInputFocusManager.GetCurrentFocusControl() ) // Don't quit if a control has focus + if(!keyInputFocusManager.GetCurrentFocusControl()) // Don't quit if a control has focus { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -111,14 +109,14 @@ private: } } - Application& mApplication; ///< Reference to the application class. + Application& mApplication; ///< Reference to the application class. ContactCardLayouter mContactCardLayouter; ///< The contact card layouter. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, THEME_PATH ); - ContactCardController contactCardController( application ); + Application application = Application::New(&argc, &argv, THEME_PATH); + ContactCardController contactCardController(application); application.MainLoop(); return 0; } diff --git a/examples/contact-cards/contact-data.cpp b/examples/contact-cards/contact-data.cpp index 5ff3163..269f903 100644 --- a/examples/contact-cards/contact-data.cpp +++ b/examples/contact-cards/contact-data.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,25 +20,24 @@ namespace ContactData { - const Item TABLE[] = -{ - { "Shelia Ramos", "19 Wormley Ct\nWinters Way\nWaltham Abbey\nEN9 3HW", DEMO_IMAGE_DIR "gallery-small-19.jpg" }, - { "Walter Jensen", "32 Upper Fant Rd\nMaidstone\nME16 8DN", DEMO_IMAGE_DIR "gallery-small-2.jpg" }, - { "Randal Parks", "8 Rymill St\nLondon\nE16 2JF", DEMO_IMAGE_DIR "gallery-small-3.jpg" }, - { "Tasha Cooper", "2 Kyles View\nColintraive\nPA22 3AS", DEMO_IMAGE_DIR "gallery-small-4.jpg" }, - { "Domingo Lynch", "Red Lion Farm\nWatlington\nOX49 5LG", DEMO_IMAGE_DIR "gallery-small-5.jpg" }, - { "Dan Haynes", "239 Whitefield Dr\nLiverpool\nL32 0RD", DEMO_IMAGE_DIR "gallery-small-6.jpg" }, - { "Leslie Wong", "1 Tullyvar Rd\nAughnacloy\nBT69 6BQ", DEMO_IMAGE_DIR "gallery-small-7.jpg" }, - { "Mable Hodges", "5 Mortimer Rd\nGrazeley\nReading\nRG7 1LA", DEMO_IMAGE_DIR "gallery-small-8.jpg" }, - { "Kristi Riley", "10 Jura Dr\nOld Kilpatrick\nGlasgow\nG60 5EH", DEMO_IMAGE_DIR "gallery-small-17.jpg" }, - { "Terry Clark", "142 Raeberry St\nGlasgow\nG20 6EA", DEMO_IMAGE_DIR "gallery-small-18.jpg" }, - { "Horace Bailey", "11 Assembly St\nNormanton\nWF6 2DB", DEMO_IMAGE_DIR "gallery-small-11.jpg" }, - { "Suzanne Delgado", "6 Grange Rd\nDownpatrick\nBT30 7DB", DEMO_IMAGE_DIR "gallery-small-12.jpg" }, - { "Jamie Bennett", "117 Potter St\nNorthwood\nHA6 1QF", DEMO_IMAGE_DIR "gallery-small-13.jpg" }, - { "Emmett Yates", "18 Renfrew Way\nBletchley\nMilton Keynes\nMK3 7NY", DEMO_IMAGE_DIR "gallery-small-14.jpg" }, - { "Glen Vaughn", "5 Hasman Terrace\nCove Bay\nAberdeen\nAB12 3GD", DEMO_IMAGE_DIR "gallery-small-15.jpg" }, + { + {"Shelia Ramos", "19 Wormley Ct\nWinters Way\nWaltham Abbey\nEN9 3HW", DEMO_IMAGE_DIR "gallery-small-19.jpg"}, + {"Walter Jensen", "32 Upper Fant Rd\nMaidstone\nME16 8DN", DEMO_IMAGE_DIR "gallery-small-2.jpg"}, + {"Randal Parks", "8 Rymill St\nLondon\nE16 2JF", DEMO_IMAGE_DIR "gallery-small-3.jpg"}, + {"Tasha Cooper", "2 Kyles View\nColintraive\nPA22 3AS", DEMO_IMAGE_DIR "gallery-small-4.jpg"}, + {"Domingo Lynch", "Red Lion Farm\nWatlington\nOX49 5LG", DEMO_IMAGE_DIR "gallery-small-5.jpg"}, + {"Dan Haynes", "239 Whitefield Dr\nLiverpool\nL32 0RD", DEMO_IMAGE_DIR "gallery-small-6.jpg"}, + {"Leslie Wong", "1 Tullyvar Rd\nAughnacloy\nBT69 6BQ", DEMO_IMAGE_DIR "gallery-small-7.jpg"}, + {"Mable Hodges", "5 Mortimer Rd\nGrazeley\nReading\nRG7 1LA", DEMO_IMAGE_DIR "gallery-small-8.jpg"}, + {"Kristi Riley", "10 Jura Dr\nOld Kilpatrick\nGlasgow\nG60 5EH", DEMO_IMAGE_DIR "gallery-small-17.jpg"}, + {"Terry Clark", "142 Raeberry St\nGlasgow\nG20 6EA", DEMO_IMAGE_DIR "gallery-small-18.jpg"}, + {"Horace Bailey", "11 Assembly St\nNormanton\nWF6 2DB", DEMO_IMAGE_DIR "gallery-small-11.jpg"}, + {"Suzanne Delgado", "6 Grange Rd\nDownpatrick\nBT30 7DB", DEMO_IMAGE_DIR "gallery-small-12.jpg"}, + {"Jamie Bennett", "117 Potter St\nNorthwood\nHA6 1QF", DEMO_IMAGE_DIR "gallery-small-13.jpg"}, + {"Emmett Yates", "18 Renfrew Way\nBletchley\nMilton Keynes\nMK3 7NY", DEMO_IMAGE_DIR "gallery-small-14.jpg"}, + {"Glen Vaughn", "5 Hasman Terrace\nCove Bay\nAberdeen\nAB12 3GD", DEMO_IMAGE_DIR "gallery-small-15.jpg"}, }; -const size_t TABLE_SIZE = sizeof( TABLE ) / sizeof( TABLE[ 0 ] ); +const size_t TABLE_SIZE = sizeof(TABLE) / sizeof(TABLE[0]); } // namespace ContactData diff --git a/examples/contact-cards/contact-data.h b/examples/contact-cards/contact-data.h index 0036774..f9cfa7f 100644 --- a/examples/contact-cards/contact-data.h +++ b/examples/contact-cards/contact-data.h @@ -2,7 +2,7 @@ #define CONTACT_DATA_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,18 +23,17 @@ namespace ContactData { - /** * @brief The information for an individual contact. */ struct Item { - const char * const name; ///< The name of the contact. - const char * const address; ///< The address of the contact. - const char * const imagePath; ///< The path to the image that represents the contact. + const char* const name; ///< The name of the contact. + const char* const address; ///< The address of the contact. + const char* const imagePath; ///< The path to the image that represents the contact. }; -extern const Item TABLE[]; ///< The table that has the information for all the contacts. +extern const Item TABLE[]; ///< The table that has the information for all the contacts. extern const size_t TABLE_SIZE; ///< The size of TABLE. Can use this to iterate through TABLE. } // namespace ContactData diff --git a/examples/contact-cards/masked-image.cpp b/examples/contact-cards/masked-image.cpp index ede6e75..2279b8a 100644 --- a/examples/contact-cards/masked-image.cpp +++ b/examples/contact-cards/masked-image.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,25 +23,23 @@ namespace MaskedImage { - using namespace Dali; using namespace Dali::Toolkit; namespace { -const char* const IMAGE_MASK ( DEMO_IMAGE_DIR "contact-cards-mask.png" ); +const char* const IMAGE_MASK(DEMO_IMAGE_DIR "contact-cards-mask.png"); } // unnamed namespace -Dali::Toolkit::Control Create( const std::string& imagePath ) +Dali::Toolkit::Control Create(const std::string& imagePath) { Control maskedImage = ImageView::New(); maskedImage.SetProperty( Toolkit::ImageView::Property::IMAGE, - Property::Map{ { Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE }, - { ImageVisual::Property::URL, imagePath }, - { ImageVisual::Property::ALPHA_MASK_URL, IMAGE_MASK } } - ); + Property::Map{{Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE}, + {ImageVisual::Property::URL, imagePath}, + {ImageVisual::Property::ALPHA_MASK_URL, IMAGE_MASK}}); return maskedImage; } -} // namespace ClippedImage +} // namespace MaskedImage diff --git a/examples/contact-cards/masked-image.h b/examples/contact-cards/masked-image.h index 9fefc84..91df593 100644 --- a/examples/contact-cards/masked-image.h +++ b/examples/contact-cards/masked-image.h @@ -2,7 +2,7 @@ #define MASKED_IMAGE_H /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ */ // EXTERNAL INCLUDES -#include #include +#include /** * @brief This namespace provides a helper function which creates an ImageView with a mask that matches the Circle geometry provided by ClippedImage. @@ -30,15 +30,14 @@ */ namespace MaskedImage { - /** * @brief Creates an image with a circular mask. * * @param[in] imagePath The path to the image to show. * @return The ImageView with a mask control. */ -Dali::Toolkit::Control Create( const std::string& imagePath ); +Dali::Toolkit::Control Create(const std::string& imagePath); -} // namespace ClippedImage +} // namespace MaskedImage #endif // MASKED_IMAGE_H diff --git a/examples/cube-transition-effect/cube-transition-effect-example.cpp b/examples/cube-transition-effect/cube-transition-effect-example.cpp old mode 100755 new mode 100644 index 59a8e0f..7759267 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@ -19,17 +19,16 @@ #include // INTERNAL INCLUDES -#include "shared/view.h" #include "shared/utility.h" +#include "shared/view.h" -#include #include #include -#include #include +#include #include #include - +#include using namespace Dali; @@ -38,47 +37,46 @@ using Dali::Toolkit::TextLabel; // LOCAL STUFF namespace { - -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const APPLICATION_TITLE_WAVE( "Cube Transition: Wave" ); -const char * const APPLICATION_TITLE_CROSS( "Cube Transition: Cross" ); -const char * const APPLICATION_TITLE_FOLD( "Cube Transition: Fold" ); -const char * const EFFECT_WAVE_IMAGE( DEMO_IMAGE_DIR "icon-effect-wave.png" ); -const char * const EFFECT_WAVE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-wave-selected.png" ); -const char * const EFFECT_CROSS_IMAGE( DEMO_IMAGE_DIR "icon-effect-cross.png" ); -const char * const EFFECT_CROSS_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-cross-selected.png" ); -const char * const EFFECT_FOLD_IMAGE( DEMO_IMAGE_DIR "icon-effect-fold.png" ); -const char * const EFFECT_FOLD_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-fold-selected.png" ); -const char * const SLIDE_SHOW_START_ICON( DEMO_IMAGE_DIR "icon-play.png" ); -const char * const SLIDE_SHOW_START_ICON_SELECTED( DEMO_IMAGE_DIR "icon-play-selected.png" ); -const char * const SLIDE_SHOW_STOP_ICON( DEMO_IMAGE_DIR "icon-stop.png" ); -const char * const SLIDE_SHOW_STOP_ICON_SELECTED( DEMO_IMAGE_DIR "icon-stop-selected.png" ); +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const APPLICATION_TITLE_WAVE("Cube Transition: Wave"); +const char* const APPLICATION_TITLE_CROSS("Cube Transition: Cross"); +const char* const APPLICATION_TITLE_FOLD("Cube Transition: Fold"); +const char* const EFFECT_WAVE_IMAGE(DEMO_IMAGE_DIR "icon-effect-wave.png"); +const char* const EFFECT_WAVE_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-effect-wave-selected.png"); +const char* const EFFECT_CROSS_IMAGE(DEMO_IMAGE_DIR "icon-effect-cross.png"); +const char* const EFFECT_CROSS_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-effect-cross-selected.png"); +const char* const EFFECT_FOLD_IMAGE(DEMO_IMAGE_DIR "icon-effect-fold.png"); +const char* const EFFECT_FOLD_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-effect-fold-selected.png"); +const char* const SLIDE_SHOW_START_ICON(DEMO_IMAGE_DIR "icon-play.png"); +const char* const SLIDE_SHOW_START_ICON_SELECTED(DEMO_IMAGE_DIR "icon-play-selected.png"); +const char* const SLIDE_SHOW_STOP_ICON(DEMO_IMAGE_DIR "icon-stop.png"); +const char* const SLIDE_SHOW_STOP_ICON_SELECTED(DEMO_IMAGE_DIR "icon-stop-selected.png"); const char* IMAGES[] = -{ - DEMO_IMAGE_DIR "gallery-large-1.jpg", - DEMO_IMAGE_DIR "gallery-large-2.jpg", - DEMO_IMAGE_DIR "gallery-large-3.jpg", - DEMO_IMAGE_DIR "gallery-large-4.jpg", - DEMO_IMAGE_DIR "gallery-large-5.jpg", - DEMO_IMAGE_DIR "gallery-large-6.jpg", - DEMO_IMAGE_DIR "gallery-large-7.jpg", - DEMO_IMAGE_DIR "gallery-large-8.jpg", - DEMO_IMAGE_DIR "gallery-large-9.jpg", - DEMO_IMAGE_DIR "gallery-large-10.jpg", - DEMO_IMAGE_DIR "gallery-large-11.jpg", - DEMO_IMAGE_DIR "gallery-large-12.jpg", - DEMO_IMAGE_DIR "gallery-large-13.jpg", - DEMO_IMAGE_DIR "gallery-large-14.jpg", - DEMO_IMAGE_DIR "gallery-large-15.jpg", - DEMO_IMAGE_DIR "gallery-large-16.jpg", - DEMO_IMAGE_DIR "gallery-large-17.jpg", - DEMO_IMAGE_DIR "gallery-large-18.jpg", - DEMO_IMAGE_DIR "gallery-large-19.jpg", - DEMO_IMAGE_DIR "gallery-large-20.jpg", - DEMO_IMAGE_DIR "gallery-large-21.jpg", + { + DEMO_IMAGE_DIR "gallery-large-1.jpg", + DEMO_IMAGE_DIR "gallery-large-2.jpg", + DEMO_IMAGE_DIR "gallery-large-3.jpg", + DEMO_IMAGE_DIR "gallery-large-4.jpg", + DEMO_IMAGE_DIR "gallery-large-5.jpg", + DEMO_IMAGE_DIR "gallery-large-6.jpg", + DEMO_IMAGE_DIR "gallery-large-7.jpg", + DEMO_IMAGE_DIR "gallery-large-8.jpg", + DEMO_IMAGE_DIR "gallery-large-9.jpg", + DEMO_IMAGE_DIR "gallery-large-10.jpg", + DEMO_IMAGE_DIR "gallery-large-11.jpg", + DEMO_IMAGE_DIR "gallery-large-12.jpg", + DEMO_IMAGE_DIR "gallery-large-13.jpg", + DEMO_IMAGE_DIR "gallery-large-14.jpg", + DEMO_IMAGE_DIR "gallery-large-15.jpg", + DEMO_IMAGE_DIR "gallery-large-16.jpg", + DEMO_IMAGE_DIR "gallery-large-17.jpg", + DEMO_IMAGE_DIR "gallery-large-18.jpg", + DEMO_IMAGE_DIR "gallery-large-19.jpg", + DEMO_IMAGE_DIR "gallery-large-20.jpg", + DEMO_IMAGE_DIR "gallery-large-21.jpg", }; -const int NUM_IMAGES( sizeof(IMAGES) / sizeof(IMAGES[0]) ); +const int NUM_IMAGES(sizeof(IMAGES) / sizeof(IMAGES[0])); // the number of cubes: NUM_COLUMNS*NUM_ROWS // better choose the numbers that can divide viewAreaSize.x @@ -105,27 +103,25 @@ const int VIEWINGTIME = 2000; // 2 seconds class CubeTransitionApp : public ConnectionTracker { public: - /** * Constructor * @param application class, stored as reference */ - CubeTransitionApp( Application& application ); + CubeTransitionApp(Application& application); ~CubeTransitionApp(); private: - /** * This method gets called once the main loop of application is up and running */ - void OnInit( Application& application ); + void OnInit(Application& application); /** * PanGesture callback. This method gets called when the pan gesture is detected. * @param[in] actor The actor receiving the pan gesture. * @param[in] gesture The detected pan gesture. */ - void OnPanGesture( Actor actor, const PanGesture& gesture ); + void OnPanGesture(Actor actor, const PanGesture& gesture); /** * Load the next image and start the transition; */ @@ -139,19 +135,19 @@ private: * Change the effect when the effect button is clicked * @param[in] button The handle of the clicked button */ - bool OnEffectButtonClicked( Toolkit::Button button ); + bool OnEffectButtonClicked(Toolkit::Button button); /** * Callback function of slideshow button * Start or stop the automatical image display when the slideshow button is clicked * @param[in] button The handle of the clicked button */ - bool OnSildeshowButtonClicked( Toolkit::Button button ); + bool OnSildeshowButtonClicked(Toolkit::Button button); /** * Callback function of cube transition completed signal * @param[in] effect The cube effect used for the transition * @param[in] texture The target Texture of the completed transition */ - void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture image ); + void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture image); /** * Callback function of timer tick * The timer is used to count the image display duration in slideshow, @@ -163,44 +159,44 @@ private: * @param[in] filepath Path to the image file * @return New texture object */ - Texture LoadWindowFillingTexture( const char* filepath ); + Texture LoadWindowFillingTexture(const char* filepath); private: - Application& mApplication; - Toolkit::Control mView; - Toolkit::ToolBar mToolBar; - Layer mContent; - Toolkit::TextLabel mTitle; + Application& mApplication; + Toolkit::Control mView; + Toolkit::ToolBar mToolBar; + Layer mContent; + Toolkit::TextLabel mTitle; - Vector2 mViewSize; + Vector2 mViewSize; - Texture mCurrentTexture; - Texture mNextTexture; - unsigned int mIndex; - bool mIsImageLoading; + Texture mCurrentTexture; + Texture mNextTexture; + unsigned int mIndex; + bool mIsImageLoading; - PanGestureDetector mPanGestureDetector; + PanGestureDetector mPanGestureDetector; - Toolkit::CubeTransitionEffect mCubeWaveEffect; - Toolkit::CubeTransitionEffect mCubeCrossEffect; - Toolkit::CubeTransitionEffect mCubeFoldEffect; - Toolkit::CubeTransitionEffect mCurrentEffect; + Toolkit::CubeTransitionEffect mCubeWaveEffect; + Toolkit::CubeTransitionEffect mCubeCrossEffect; + Toolkit::CubeTransitionEffect mCubeFoldEffect; + Toolkit::CubeTransitionEffect mCurrentEffect; - bool mSlideshow; - Timer mViewTimer; - Toolkit::PushButton mSlideshowButton; + bool mSlideshow; + Timer mViewTimer; + Toolkit::PushButton mSlideshowButton; - Vector2 mPanPosition; - Vector2 mPanDisplacement; + Vector2 mPanPosition; + Vector2 mPanDisplacement; }; -CubeTransitionApp::CubeTransitionApp( Application& application ) -: mApplication( application ), - mIndex( 0 ), - mIsImageLoading( false ), - mSlideshow( false ) +CubeTransitionApp::CubeTransitionApp(Application& application) +: mApplication(application), + mIndex(0), + mIsImageLoading(false), + mSlideshow(false) { - mApplication.InitSignal().Connect( this, &CubeTransitionApp::OnInit ); + mApplication.InitSignal().Connect(this, &CubeTransitionApp::OnInit); } CubeTransitionApp::~CubeTransitionApp() @@ -208,107 +204,104 @@ CubeTransitionApp::~CubeTransitionApp() //Nothing to do } -void CubeTransitionApp::OnInit( Application& application ) +void CubeTransitionApp::OnInit(Application& application) { application.GetWindow().KeyEventSignal().Connect(this, &CubeTransitionApp::OnKeyEvent); // Creates a default view with a default tool bar, the view is added to the window. - mContent = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" ); - mContent.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); - + mContent = DemoHelper::CreateView(application, mView, mToolBar, "", TOOLBAR_IMAGE, ""); + mContent.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); // Add an effect changing toggle button Toolkit::ToggleButton effectChangeToggleButton = Toolkit::ToggleButton::ToggleButton::New(); - effectChangeToggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS, - Property::Array{ EFFECT_WAVE_IMAGE, - EFFECT_CROSS_IMAGE, - EFFECT_FOLD_IMAGE } - ); + effectChangeToggleButton.SetProperty(Toolkit::ToggleButton::Property::STATE_VISUALS, + Property::Array{EFFECT_WAVE_IMAGE, + EFFECT_CROSS_IMAGE, + EFFECT_FOLD_IMAGE}); - effectChangeToggleButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked ); - mToolBar.AddControl( effectChangeToggleButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + effectChangeToggleButton.ClickedSignal().Connect(this, &CubeTransitionApp::OnEffectButtonClicked); + mToolBar.AddControl(effectChangeToggleButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Add title to the tool bar. - mTitle = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE ); - mToolBar.AddControl( mTitle, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER ); + mTitle = DemoHelper::CreateToolBarLabel(APPLICATION_TITLE_WAVE); + mToolBar.AddControl(mTitle, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER); //Add an slideshow icon on the right of the title mSlideshowButton = Toolkit::PushButton::New(); - mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON ); - mSlideshowButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON_SELECTED ); - mSlideshowButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnSildeshowButtonClicked ); - mToolBar.AddControl( mSlideshowButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING ); + mSlideshowButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON); + mSlideshowButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON_SELECTED); + mSlideshowButton.ClickedSignal().Connect(this, &CubeTransitionApp::OnSildeshowButtonClicked); + mToolBar.AddControl(mSlideshowButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING); // Set size to window size to avoid seeing a black border on transition mViewSize = application.GetWindow().GetSize(); // show the first image - mCurrentTexture = LoadWindowFillingTexture( IMAGES[mIndex] ); + mCurrentTexture = LoadWindowFillingTexture(IMAGES[mIndex]); //use small cubes - mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE ); - mCubeWaveEffect.SetTransitionDuration( ANIMATION_DURATION_WAVE ); - mCubeWaveEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_WAVE ); + mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New(NUM_ROWS_WAVE, NUM_COLUMNS_WAVE); + mCubeWaveEffect.SetTransitionDuration(ANIMATION_DURATION_WAVE); + mCubeWaveEffect.SetCubeDisplacement(CUBE_DISPLACEMENT_WAVE); mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); - mCubeWaveEffect.SetProperty( Actor::Property::SIZE, mViewSize ); - mCubeWaveEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCubeWaveEffect.SetCurrentTexture( mCurrentTexture ); + mCubeWaveEffect.SetProperty(Actor::Property::SIZE, mViewSize); + mCubeWaveEffect.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCubeWaveEffect.SetCurrentTexture(mCurrentTexture); // use big cubes - mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS ); - mCubeCrossEffect.SetTransitionDuration( ANIMATION_DURATION_CROSS ); - mCubeCrossEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_CROSS ); + mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS); + mCubeCrossEffect.SetTransitionDuration(ANIMATION_DURATION_CROSS); + mCubeCrossEffect.SetCubeDisplacement(CUBE_DISPLACEMENT_CROSS); mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); - mCubeCrossEffect.SetProperty( Actor::Property::SIZE, mViewSize ); - mCubeCrossEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCubeCrossEffect.SetCurrentTexture( mCurrentTexture ); + mCubeCrossEffect.SetProperty(Actor::Property::SIZE, mViewSize); + mCubeCrossEffect.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCubeCrossEffect.SetCurrentTexture(mCurrentTexture); - mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New( NUM_ROWS_FOLD, NUM_COLUMNS_FOLD ); - mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD ); + mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New(NUM_ROWS_FOLD, NUM_COLUMNS_FOLD); + mCubeFoldEffect.SetTransitionDuration(ANIMATION_DURATION_FOLD); mCubeFoldEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); - mCubeFoldEffect.SetProperty( Actor::Property::SIZE, mViewSize ); - mCubeFoldEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCubeFoldEffect.SetCurrentTexture( mCurrentTexture ); - - mViewTimer = Timer::New( VIEWINGTIME ); - mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick ); + mCubeFoldEffect.SetProperty(Actor::Property::SIZE, mViewSize); + mCubeFoldEffect.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCubeFoldEffect.SetCurrentTexture(mCurrentTexture); + mViewTimer = Timer::New(VIEWINGTIME); + mViewTimer.TickSignal().Connect(this, &CubeTransitionApp::OnTimerTick); mCurrentEffect = mCubeWaveEffect; - mContent.Add( mCurrentEffect ); + mContent.Add(mCurrentEffect); // use pan gesture to detect the cursor or finger movement mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.DetectedSignal().Connect( this, &CubeTransitionApp::OnPanGesture ); - mPanGestureDetector.Attach( mContent ); + mPanGestureDetector.DetectedSignal().Connect(this, &CubeTransitionApp::OnPanGesture); + mPanGestureDetector.Attach(mContent); } // signal handler, called when the pan gesture is detected -void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) +void CubeTransitionApp::OnPanGesture(Actor actor, const PanGesture& gesture) { // does not response when the transition has not finished - if( mIsImageLoading || mCubeWaveEffect.IsTransitioning() || mCubeCrossEffect.IsTransitioning() || mCubeFoldEffect.IsTransitioning() || mSlideshow ) + if(mIsImageLoading || mCubeWaveEffect.IsTransitioning() || mCubeCrossEffect.IsTransitioning() || mCubeFoldEffect.IsTransitioning() || mSlideshow) { return; } - if( gesture.GetState() == GestureState::CONTINUING ) + if(gesture.GetState() == GestureState::CONTINUING) { const Vector2& displacement = gesture.GetDisplacement(); - if( displacement.x < 0) + if(displacement.x < 0) { - mIndex = (mIndex + 1)%NUM_IMAGES; + mIndex = (mIndex + 1) % NUM_IMAGES; } else { - mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; + mIndex = (mIndex + NUM_IMAGES - 1) % NUM_IMAGES; } - mPanPosition = gesture.GetPosition(); + mPanPosition = gesture.GetPosition(); mPanDisplacement = displacement; GoToNextImage(); } @@ -316,64 +309,64 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) void CubeTransitionApp::GoToNextImage() { - mNextTexture = LoadWindowFillingTexture( IMAGES[ mIndex ] ); - mCurrentEffect.SetTargetTexture( mNextTexture ); + mNextTexture = LoadWindowFillingTexture(IMAGES[mIndex]); + mCurrentEffect.SetTargetTexture(mNextTexture); mIsImageLoading = false; - mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement ); + mCurrentEffect.StartTransition(mPanPosition, mPanDisplacement); mCurrentTexture = mNextTexture; } -bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) +bool CubeTransitionApp::OnEffectButtonClicked(Toolkit::Button button) { - mContent.Remove( mCurrentEffect ); + mContent.Remove(mCurrentEffect); if(mCurrentEffect == mCubeWaveEffect) { mCurrentEffect = mCubeCrossEffect; - mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) ); + mTitle.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS)); } else if(mCurrentEffect == mCubeCrossEffect) { mCurrentEffect = mCubeFoldEffect; - mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) ); + mTitle.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD)); } else { mCurrentEffect = mCubeWaveEffect; - mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) ); + mTitle.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE)); } - mContent.Add( mCurrentEffect ); + mContent.Add(mCurrentEffect); // Set the current image to cube transition effect // only need to set at beginning or change from another effect - mCurrentEffect.SetCurrentTexture( mCurrentTexture ); + mCurrentEffect.SetCurrentTexture(mCurrentTexture); return true; } -bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) +bool CubeTransitionApp::OnSildeshowButtonClicked(Toolkit::Button button) { mSlideshow = !mSlideshow; - if( mSlideshow ) + if(mSlideshow) { - mPanGestureDetector.Detach( mContent ); - mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON ); - mSlideshowButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON_SELECTED ); - mPanPosition = Vector2( mViewSize.width, mViewSize.height*0.5f ); - mPanDisplacement = Vector2( -10.f, 0.f ); + mPanGestureDetector.Detach(mContent); + mSlideshowButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON); + mSlideshowButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON_SELECTED); + mPanPosition = Vector2(mViewSize.width, mViewSize.height * 0.5f); + mPanDisplacement = Vector2(-10.f, 0.f); mViewTimer.Start(); } else { - mPanGestureDetector.Attach( mContent ); - mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON ); - mSlideshowButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON_SELECTED ); + mPanGestureDetector.Attach(mContent); + mSlideshowButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON); + mSlideshowButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON_SELECTED); mViewTimer.Stop(); } return true; } -void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture texture ) +void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture texture) { - if( mSlideshow ) + if(mSlideshow) { mViewTimer.Start(); } @@ -383,7 +376,7 @@ bool CubeTransitionApp::OnTimerTick() { if(mSlideshow) { - mIndex = (mIndex + 1)%NUM_IMAGES; + mIndex = (mIndex + 1) % NUM_IMAGES; GoToNextImage(); } @@ -391,14 +384,14 @@ bool CubeTransitionApp::OnTimerTick() return false; } -Texture CubeTransitionApp::LoadWindowFillingTexture( const char* filepath ) +Texture CubeTransitionApp::LoadWindowFillingTexture(const char* filepath) { - ImageDimensions dimensions( mApplication.GetWindow().GetSize() ); - Devel::PixelBuffer pixelBuffer = LoadImageFromFile( filepath, dimensions, FittingMode::SCALE_TO_FILL ); - PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); + ImageDimensions dimensions(mApplication.GetWindow().GetSize()); + Devel::PixelBuffer pixelBuffer = LoadImageFromFile(filepath, dimensions, FittingMode::SCALE_TO_FILL); + PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); - Texture texture = Texture::New( TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight() ); - texture.Upload( pixelData ); + Texture texture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight()); + texture.Upload(pixelData); return texture; } @@ -406,17 +399,17 @@ void CubeTransitionApp::OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } } } -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - CubeTransitionApp test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + CubeTransitionApp test(application); application.MainLoop(); return 0; diff --git a/examples/deferred-shading/deferred-shading.cpp b/examples/deferred-shading/deferred-shading.cpp old mode 100755 new mode 100644 index 4221187..83bb611 --- a/examples/deferred-shading/deferred-shading.cpp +++ b/examples/deferred-shading/deferred-shading.cpp @@ -14,12 +14,12 @@ * limitations under the License. * */ +#include +#include +#include #include "dali/dali.h" #include "dali/public-api/actors/actor.h" #include "dali/public-api/rendering/renderer.h" -#include -#include -#include using namespace Dali; @@ -40,6 +40,8 @@ namespace #define DEFINE(x) "#define " DALI_COMPOSE_SHADER(x) DALI_COMPOSE_SHADER(\n) +// clang-format off + //============================================================================= // PRE-PASS //============================================================================= @@ -209,19 +211,21 @@ void main() oColor = vec4(finalColor, 1.f); }); +// clang-format on //============================================================================= // PRNG for floats. struct FloatRand { - std::random_device mDevice; - std::mt19937 mMersenneTwister; + std::random_device mDevice; + std::mt19937 mMersenneTwister; std::uniform_real_distribution mDistribution; FloatRand() : mMersenneTwister(mDevice()), mDistribution(0., 1.) - {} + { + } float operator()() { @@ -239,7 +243,7 @@ float FastFloor(float x) Vector3 FromHueSaturationLightness(Vector3 hsl) { Vector3 rgb; - if (hsl.y * hsl.y > 0.f) + if(hsl.y * hsl.y > 0.f) { if(hsl.x >= 360.f) { @@ -247,50 +251,50 @@ Vector3 FromHueSaturationLightness(Vector3 hsl) } hsl.x /= 60.f; - int i = FastFloor(hsl.x); + int i = FastFloor(hsl.x); float ff = hsl.x - i; - float p = hsl.z * (1.0 - hsl.y); - float q = hsl.z * (1.0 - (hsl.y * ff)); - float t = hsl.z * (1.0 - (hsl.y * (1.f - ff))); + float p = hsl.z * (1.0 - hsl.y); + float q = hsl.z * (1.0 - (hsl.y * ff)); + float t = hsl.z * (1.0 - (hsl.y * (1.f - ff))); - switch (i) + switch(i) { - case 0: - rgb.r = hsl.z; - rgb.g = t; - rgb.b = p; - break; - - case 1: - rgb.r = q; - rgb.g = hsl.z; - rgb.b = p; - break; - - case 2: - rgb.r = p; - rgb.g = hsl.z; - rgb.b = t; - break; - - case 3: - rgb.r = p; - rgb.g = q; - rgb.b = hsl.z; - break; - - case 4: - rgb.r = t; - rgb.g = p; - rgb.b = hsl.z; - break; - - case 5: - default: - rgb.r = hsl.z; - rgb.g = p; - rgb.b = q; - break; + case 0: + rgb.r = hsl.z; + rgb.g = t; + rgb.b = p; + break; + + case 1: + rgb.r = q; + rgb.g = hsl.z; + rgb.b = p; + break; + + case 2: + rgb.r = p; + rgb.g = hsl.z; + rgb.b = t; + break; + + case 3: + rgb.r = p; + rgb.g = q; + rgb.b = hsl.z; + break; + + case 4: + rgb.r = t; + rgb.g = p; + rgb.b = hsl.z; + break; + + case 5: + default: + rgb.r = hsl.z; + rgb.g = p; + rgb.b = q; + break; } } else @@ -312,26 +316,26 @@ Geometry CreateTexturedQuadGeometry(bool flipV) }; Vertex vertexData[] = { - { Vector3(-.5f, .5f, .0f), Vector2(.0f, 1.0f) }, - { Vector3(.5f, .5f, .0f), Vector2(1.0f, 1.0f) }, - { Vector3(-.5f, -.5f, .0f), Vector2(.0f, .0f) }, - { Vector3(.5f, -.5f, .0f), Vector2(1.0f, .0f) }, + {Vector3(-.5f, .5f, .0f), Vector2(.0f, 1.0f)}, + {Vector3(.5f, .5f, .0f), Vector2(1.0f, 1.0f)}, + {Vector3(-.5f, -.5f, .0f), Vector2(.0f, .0f)}, + {Vector3(.5f, -.5f, .0f), Vector2(1.0f, .0f)}, }; - if (flipV) + if(flipV) { std::swap(vertexData[0].aTexCoord, vertexData[2].aTexCoord); std::swap(vertexData[1].aTexCoord, vertexData[3].aTexCoord); } - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR3 ) - .Add( "aTexCoord", Property::VECTOR2 ) ); - vertexBuffer.SetData( vertexData, std::extent::value ); + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3) + .Add("aTexCoord", Property::VECTOR2)); + vertexBuffer.SetData(vertexData, std::extent::value); Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLE_STRIP ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLE_STRIP); return geometry; } @@ -339,12 +343,12 @@ Geometry CreateTexturedQuadGeometry(bool flipV) Geometry CreateOctahedron(bool invertNormals) { Vector3 positions[] = { - Vector3{ -1.f, 0.f, 0.f }, - Vector3{ 1.f, 0.f, 0.f }, - Vector3{ 0.f, -1.f, 0.f }, - Vector3{ 0.f, 1.f, 0.f }, - Vector3{ 0.f, 0.f, -1.f }, - Vector3{ 0.f, 0.f, 1.f }, + Vector3{-1.f, 0.f, 0.f}, + Vector3{1.f, 0.f, 0.f}, + Vector3{0.f, -1.f, 0.f}, + Vector3{0.f, 1.f, 0.f}, + Vector3{0.f, 0.f, -1.f}, + Vector3{0.f, 0.f, 1.f}, }; struct Vertex @@ -353,72 +357,71 @@ Geometry CreateOctahedron(bool invertNormals) Vector3 normal; }; Vertex vertexData[] = { - { positions[0] }, - { positions[3] }, - { positions[5] }, + {positions[0]}, + {positions[3]}, + {positions[5]}, - { positions[5] }, - { positions[3] }, - { positions[1] }, + {positions[5]}, + {positions[3]}, + {positions[1]}, - { positions[1] }, - { positions[3] }, - { positions[4] }, + {positions[1]}, + {positions[3]}, + {positions[4]}, - { positions[4] }, - { positions[3] }, - { positions[0] }, + {positions[4]}, + {positions[3]}, + {positions[0]}, - { positions[0] }, - { positions[5] }, - { positions[2] }, + {positions[0]}, + {positions[5]}, + {positions[2]}, - { positions[5] }, - { positions[1] }, - { positions[2] }, + {positions[5]}, + {positions[1]}, + {positions[2]}, - { positions[1] }, - { positions[4] }, - { positions[2] }, + {positions[1]}, + {positions[4]}, + {positions[2]}, - { positions[4] }, - { positions[0] }, - { positions[2] }, + {positions[4]}, + {positions[0]}, + {positions[2]}, }; // Calculate normals - for (uint32_t i = 0; i < std::extent::value / 3; ++i) + for(uint32_t i = 0; i < std::extent::value / 3; ++i) { uint32_t idx = i * 3; - Vector3 normal = (vertexData[idx + 2].position - vertexData[idx].position). - Cross(vertexData[idx + 1].position - vertexData[idx].position); + Vector3 normal = (vertexData[idx + 2].position - vertexData[idx].position).Cross(vertexData[idx + 1].position - vertexData[idx].position); normal.Normalize(); normal *= invertNormals * 2.f - 1.f; vertexData[idx++].normal = normal; vertexData[idx++].normal = normal; - vertexData[idx].normal = normal; + vertexData[idx].normal = normal; } // Configure property buffers and create geometry. VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() - .Add("aPosition", Property::VECTOR3) - .Add("aNormal", Property::VECTOR3)); + .Add("aPosition", Property::VECTOR3) + .Add("aNormal", Property::VECTOR3)); vertexBuffer.SetData(vertexData, std::extent::value); Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLES ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLES); return geometry; } //============================================================================= enum RendererOptions { - OPTION_NONE = 0x0, - OPTION_BLEND = 0x01, - OPTION_DEPTH_TEST = 0x02, + OPTION_NONE = 0x0, + OPTION_BLEND = 0x01, + OPTION_DEPTH_TEST = 0x02, OPTION_DEPTH_WRITE = 0x04 }; @@ -426,14 +429,14 @@ Renderer CreateRenderer(TextureSet textures, Geometry geometry, Shader shader, u { Renderer renderer = Renderer::New(geometry, shader); renderer.SetProperty(Renderer::Property::BLEND_MODE, - (options & OPTION_BLEND) ? BlendMode::ON : BlendMode::OFF); + (options & OPTION_BLEND) ? BlendMode::ON : BlendMode::OFF); renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, - (options & OPTION_DEPTH_TEST) ? DepthTestMode::ON : DepthTestMode::OFF); + (options & OPTION_DEPTH_TEST) ? DepthTestMode::ON : DepthTestMode::OFF); renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, - (options & OPTION_DEPTH_WRITE) ? DepthWriteMode::ON : DepthWriteMode::OFF); + (options & OPTION_DEPTH_WRITE) ? DepthWriteMode::ON : DepthWriteMode::OFF); renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); - if (!textures) + if(!textures) { textures = TextureSet::New(); } @@ -445,8 +448,8 @@ Renderer CreateRenderer(TextureSet textures, Geometry geometry, Shader shader, u //============================================================================= void CenterActor(Actor actor) { - actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); } //============================================================================= @@ -455,14 +458,14 @@ void RegisterDepthProperties(float depth, float near, Handle& h) h.RegisterProperty("uDepth_InvDepth_Near", Vector3(depth, 1.f / depth, near)); } -} +} // namespace //============================================================================= /// Create a String whose size can be evaluated at compile time struct ConstantString { - const char * const string; - const uint16_t size; + const char* const string; + const uint16_t size; template constexpr ConstantString(const char (&input)[inputSize]) @@ -475,7 +478,7 @@ struct ConstantString constexpr ConstantString POSITION_STRING("position"); constexpr ConstantString RADIUS_STRING("radius"); constexpr ConstantString COLOR_STRING("color"); -constexpr uint16_t LIGHT_SOURCE_BUFFER_SIZE(128u); +constexpr uint16_t LIGHT_SOURCE_BUFFER_SIZE(128u); //============================================================================= class DeferredShadingExample : public ConnectionTracker @@ -485,7 +488,7 @@ public: { enum { - NONE = 0x0, + NONE = 0x0, SHOW_LIGHTS = 0x1, }; }; @@ -494,32 +497,32 @@ public: : mApp(app), mOptions(options) { - app.InitSignal().Connect( this, &DeferredShadingExample::Create ); - app.TerminateSignal().Connect( this, &DeferredShadingExample::Destroy ); + app.InitSignal().Connect(this, &DeferredShadingExample::Create); + app.TerminateSignal().Connect(this, &DeferredShadingExample::Destroy); } private: void Create(Application& app) { // Grab window, configure layer - Window window = app.GetWindow(); - auto rootLayer = window.GetRootLayer(); - rootLayer.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); + Window window = app.GetWindow(); + auto rootLayer = window.GetRootLayer(); + rootLayer.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); Vector2 windowSize = window.GetSize(); float unit = windowSize.y / 24.f; // Get camera - we'll be re-using the same old camera in the two passes. - RenderTaskList tasks = window.GetRenderTaskList(); - CameraActor camera = tasks.GetTask(0).GetCameraActor(); + RenderTaskList tasks = window.GetRenderTaskList(); + CameraActor camera = tasks.GetTask(0).GetCameraActor(); auto zCameraPos = camera.GetProperty(Actor::Property::POSITION_Z).Get(); camera.SetFarClippingPlane(zCameraPos + windowSize.y * .5f); camera.SetNearClippingPlane(zCameraPos - windowSize.y * .5f); const float zNear = camera.GetNearClippingPlane(); - const float zFar = camera.GetFarClippingPlane(); + const float zFar = camera.GetFarClippingPlane(); const float depth = zFar - zNear; // Create root of scene that shall be rendered off-screen. @@ -539,69 +542,62 @@ private: Geometry mesh = CreateOctahedron(false); // Create main actors - Shader preShader = Shader::New(PREPASS_VSH, PREPASS_FSH); + Shader preShader = Shader::New(PREPASS_VSH, PREPASS_FSH); TextureSet noTexturesThanks = TextureSet::New(); - Renderer meshRenderer = CreateRenderer(noTexturesThanks, mesh, preShader, - OPTION_DEPTH_TEST | OPTION_DEPTH_WRITE); + Renderer meshRenderer = CreateRenderer(noTexturesThanks, mesh, preShader, OPTION_DEPTH_TEST | OPTION_DEPTH_WRITE); meshRenderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); RegisterDepthProperties(depth, zNear, meshRenderer); float c = 1.f; - for (auto v: { - Vector3{ -c, -c, -c }, - Vector3{ c, -c, -c }, - Vector3{ -c, c, -c }, - Vector3{ c, c, -c }, - Vector3{ -c, -c, c }, - Vector3{ c, -c, c }, - Vector3{ -c, c, c }, - Vector3{ c, c, c }, - - Vector3{ 0.f, -c, -c }, - Vector3{ 0.f, c, -c }, - Vector3{ 0.f, -c, c }, - Vector3{ 0.f, c, c }, - - Vector3{ -c, 0.f, -c }, - Vector3{ c, 0.f, -c }, - Vector3{ -c, 0.f, c }, - Vector3{ c, 0.f, c }, - - Vector3{ -c, -c, 0.f }, - Vector3{ c, -c, 0.f }, - Vector3{ -c, c, 0.f }, - Vector3{ c, c, 0.f }, - }) + for(auto v : { + Vector3{-c, -c, -c}, + Vector3{c, -c, -c}, + Vector3{-c, c, -c}, + Vector3{c, c, -c}, + Vector3{-c, -c, c}, + Vector3{c, -c, c}, + Vector3{-c, c, c}, + Vector3{c, c, c}, + + Vector3{0.f, -c, -c}, + Vector3{0.f, c, -c}, + Vector3{0.f, -c, c}, + Vector3{0.f, c, c}, + + Vector3{-c, 0.f, -c}, + Vector3{c, 0.f, -c}, + Vector3{-c, 0.f, c}, + Vector3{c, 0.f, c}, + + Vector3{-c, -c, 0.f}, + Vector3{c, -c, 0.f}, + Vector3{-c, c, 0.f}, + Vector3{c, c, 0.f}, + }) { Actor a = Actor::New(); CenterActor(a); - Vector3 position{ v * unit * 5.f }; - a.SetProperty( Actor::Property::POSITION, position ); + Vector3 position{v * unit * 5.f}; + a.SetProperty(Actor::Property::POSITION, position); - float scale = (c + ((v.x + v.y + v.z) + c * 3.f) * .5f) / (c * 4.f); - Vector3 size{ Vector3::ONE * scale * unit * 2.f }; - a.SetProperty( Actor::Property::SIZE, size); + float scale = (c + ((v.x + v.y + v.z) + c * 3.f) * .5f) / (c * 4.f); + Vector3 size{Vector3::ONE * scale * unit * 2.f}; + a.SetProperty(Actor::Property::SIZE, size); - a.SetProperty( Actor::Property::COLOR,Color::WHITE * .25f + - (Color::RED * (v.x + c) / (c * 2.f) + - Color::GREEN * (v.y + c) / (c * 2.f) + - Color::BLUE * (v.z + c) / (c * 2.f)) * .015625f); + a.SetProperty(Actor::Property::COLOR, Color::WHITE * .25f + (Color::RED * (v.x + c) / (c * 2.f) + Color::GREEN * (v.y + c) / (c * 2.f) + Color::BLUE * (v.z + c) / (c * 2.f)) * .015625f); a.AddRenderer(meshRenderer); axis.Add(a); } // Create off-screen textures, fbo and render task. - uint32_t width = static_cast(windowSize.x); + uint32_t width = static_cast(windowSize.x); uint32_t height = static_cast(windowSize.y); - Texture rttNormal = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGB888, - width, height); - Texture rttPosition = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, - width, height); - Texture rttColor = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGB888, - width, height); - FrameBuffer fbo = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH); + Texture rttNormal = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGB888, width, height); + Texture rttPosition = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, width, height); + Texture rttColor = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGB888, width, height); + FrameBuffer fbo = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH); fbo.AttachColorTexture(rttNormal); fbo.AttachColorTexture(rttPosition); fbo.AttachColorTexture(rttColor); @@ -622,7 +618,7 @@ private: // Create final image for deferred shading auto finalImage = Actor::New(); CenterActor(finalImage); - finalImage.SetProperty( Actor::Property::SIZE, windowSize); + finalImage.SetProperty(Actor::Property::SIZE, windowSize); TextureSet finalImageTextures = TextureSet::New(); finalImageTextures.SetTexture(0, rttNormal); @@ -635,17 +631,16 @@ private: finalImageTextures.SetSampler(1, sampler); finalImageTextures.SetSampler(2, sampler); - Shader shdMain = Shader::New(MAINPASS_VSH, MAINPASS_FSH); - Geometry finalImageGeom = CreateTexturedQuadGeometry(true); + Shader shdMain = Shader::New(MAINPASS_VSH, MAINPASS_FSH); + Geometry finalImageGeom = CreateTexturedQuadGeometry(true); Renderer finalImageRenderer = CreateRenderer(finalImageTextures, finalImageGeom, shdMain); RegisterDepthProperties(depth, zNear, finalImageRenderer); - auto propInvProjection = finalImageRenderer.RegisterProperty("uInvProjection", Matrix::IDENTITY); - Constraint cnstrInvProjection = Constraint::New(finalImageRenderer, propInvProjection, - [zCameraPos, zNear, depth](Matrix& output, const PropertyInputContainer& input) { - output = input[0]->GetMatrix(); - DALI_ASSERT_ALWAYS(output.Invert() && "Failed to invert projection matrix."); - }); + auto propInvProjection = finalImageRenderer.RegisterProperty("uInvProjection", Matrix::IDENTITY); + Constraint cnstrInvProjection = Constraint::New(finalImageRenderer, propInvProjection, [zCameraPos, zNear, depth](Matrix& output, const PropertyInputContainer& input) { + output = input[0]->GetMatrix(); + DALI_ASSERT_ALWAYS(output.Invert() && "Failed to invert projection matrix."); + }); cnstrInvProjection.AddSource(Source(camera, CameraActor::Property::PROJECTION_MATRIX)); cnstrInvProjection.AddSource(Source(camera, CameraActor::Property::VIEW_MATRIX)); cnstrInvProjection.Apply(); @@ -662,29 +657,28 @@ private: // Create Lights const bool showLights = mOptions & Options::SHOW_LIGHTS; - Renderer lightRenderer; - if (showLights) + Renderer lightRenderer; + if(showLights) { Geometry lightMesh = CreateOctahedron(true); - lightRenderer = CreateRenderer(noTexturesThanks, lightMesh, preShader, - OPTION_DEPTH_TEST | OPTION_DEPTH_WRITE); + lightRenderer = CreateRenderer(noTexturesThanks, lightMesh, preShader, OPTION_DEPTH_TEST | OPTION_DEPTH_WRITE); lightRenderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT); } - Vector3 lightPos{ unit * 12.f, 0.f, 0.f }; - float theta = M_PI * 2.f / MAX_LIGHTS; - float cosTheta = std::cos(theta); - float sinTheta = std::sin(theta); - for (int i = 0; i < MAX_LIGHTS; ++i) + Vector3 lightPos{unit * 12.f, 0.f, 0.f}; + float theta = M_PI * 2.f / MAX_LIGHTS; + float cosTheta = std::cos(theta); + float sinTheta = std::sin(theta); + for(int i = 0; i < MAX_LIGHTS; ++i) { Vector3 color = FromHueSaturationLightness(Vector3((360.f * i) / MAX_LIGHTS, .5f, 1.f)); Actor light = CreateLight(lightPos * (1 + (i % 8)) / 8.f, unit * 16.f, color, camera, finalImageRenderer); - float z = (((i & 1) << 1) - 1) * unit * 8.f; + float z = (((i & 1) << 1) - 1) * unit * 8.f; lightPos = Vector3(cosTheta * lightPos.x - sinTheta * lightPos.y, sinTheta * lightPos.x + cosTheta * lightPos.y, z); - if (showLights) + if(showLights) { light.SetProperty(Actor::Property::SIZE, Vector3::ONE * unit / 8.f); light.AddRenderer(lightRenderer); @@ -723,11 +717,11 @@ private: light.SetProperty(Actor::Property::COLOR, Color::WHITE); light.SetProperty(Actor::Property::POSITION, position); - auto iPropRadius = light.RegisterProperty("radius", radius); + auto iPropRadius = light.RegisterProperty("radius", radius); auto iPropLightColor = light.RegisterProperty("lightcolor", color); // Create light source uniforms on lighting shader. - char buffer[LIGHT_SOURCE_BUFFER_SIZE]; + char buffer[LIGHT_SOURCE_BUFFER_SIZE]; char* writep = buffer + snprintf(buffer, LIGHT_SOURCE_BUFFER_SIZE, "uLights[%d].", mNumLights); ++mNumLights; @@ -742,25 +736,22 @@ private: // Constrain the light position, radius and color to lighting shader uniforms. // Convert light position to view space; - Constraint cLightPos = Constraint::New(renderer, oPropLightPos, [](Vector3& output, const PropertyInputContainer& input) - { + Constraint cLightPos = Constraint::New(renderer, oPropLightPos, [](Vector3& output, const PropertyInputContainer& input) { Vector4 worldPos(input[0]->GetVector3()); worldPos.w = 1.f; worldPos = input[1]->GetMatrix() * worldPos; - output = Vector3(worldPos); + output = Vector3(worldPos); }); cLightPos.AddSource(Source(light, Actor::Property::WORLD_POSITION)); cLightPos.AddSource(Source(camera, CameraActor::Property::VIEW_MATRIX)); cLightPos.Apply(); - Constraint cLightRadius = Constraint::New(renderer, oPropLightRadius, - EqualToConstraint()); + Constraint cLightRadius = Constraint::New(renderer, oPropLightRadius, EqualToConstraint()); cLightRadius.AddSource(Source(light, iPropRadius)); cLightRadius.Apply(); - Constraint cLightColor = Constraint::New(renderer, oPropLightColor, - EqualToConstraint()); + Constraint cLightColor = Constraint::New(renderer, oPropLightColor, EqualToConstraint()); cLightColor.AddSource(Source(light, iPropLightColor)); cLightColor.Apply(); @@ -769,10 +760,10 @@ private: void OnPan(Actor, PanGesture const& gesture) { - Quaternion q = mAxis.GetProperty(Actor::Property::ORIENTATION).Get(); + Quaternion q = mAxis.GetProperty(Actor::Property::ORIENTATION).Get(); const Vector2& displacement = gesture.GetScreenDisplacement(); - Quaternion qx(Radian(Degree(displacement.y) * -.5f), Vector3::XAXIS); - Quaternion qy(Radian(Degree(displacement.x) * .5f), Vector3::YAXIS); + Quaternion qx(Radian(Degree(displacement.y) * -.5f), Vector3::XAXIS); + Quaternion qy(Radian(Degree(displacement.x) * .5f), Vector3::YAXIS); mAxis.SetProperty(Actor::Property::ORIENTATION, qy * qx * q); } @@ -780,7 +771,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApp.Quit(); } @@ -788,32 +779,29 @@ private: } Application& mApp; - uint32_t mOptions; + uint32_t mOptions; Actor mSceneRoot; Actor mAxis; RenderTask mSceneRender; - Actor mFinalImage; + Actor mFinalImage; int mNumLights = 0; PanGestureDetector mPanDetector; }; - int main(int argc, char** argv) { - const bool showLights = [](int argc, char** argv) - { + const bool showLights = [](int argc, char** argv) { auto endArgs = argv + argc; - return std::find_if(argv, endArgs, [](const char* arg) - { - return strcmp(arg, "--show-lights") == 0; - }) != endArgs; + return std::find_if(argv, endArgs, [](const char* arg) { + return strcmp(arg, "--show-lights") == 0; + }) != endArgs; }(argc, argv); - Application app = Application::New(&argc, &argv); + Application app = Application::New(&argc, &argv); DeferredShadingExample example(app, (showLights ? DeferredShadingExample::Options::SHOW_LIGHTS : 0)); app.MainLoop(); return 0; diff --git a/examples/dissolve-effect/dissolve-effect-example.cpp b/examples/dissolve-effect/dissolve-effect-example.cpp old mode 100755 new mode 100644 index 6e7aaec..bcc7e57 --- a/examples/dissolve-effect/dissolve-effect-example.cpp +++ b/examples/dissolve-effect/dissolve-effect-example.cpp @@ -21,10 +21,10 @@ // INTERNAL INCLUDES #include "shared/view.h" -#include -#include #include #include +#include +#include using namespace Dali; @@ -33,45 +33,44 @@ using Dali::Toolkit::TextLabel; // LOCAL STUFF namespace { - -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const APPLICATION_TITLE_HIGHP( "Dissolve Effect(highp)" ); -const char * const APPLICATION_TITLE_MEDIUMP( "Dissolve Effect(mediump)" ); -const char * const EFFECT_HIGHP_IMAGE( DEMO_IMAGE_DIR "icon-highp.png" ); -const char * const EFFECT_HIGHP_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-highp-selected.png" ); -const char * const EFFECT_MEDIUMP_IMAGE( DEMO_IMAGE_DIR "icon-mediump.png" ); -const char * const EFFECT_MEDIUMP_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-mediump-selected.png" ); -const char * const PLAY_ICON( DEMO_IMAGE_DIR "icon-play.png" ); -const char * const PLAY_ICON_SELECTED( DEMO_IMAGE_DIR "icon-play-selected.png" ); -const char * const STOP_ICON( DEMO_IMAGE_DIR "icon-stop.png" ); -const char * const STOP_ICON_SELECTED( DEMO_IMAGE_DIR "icon-stop-selected.png" ); +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const APPLICATION_TITLE_HIGHP("Dissolve Effect(highp)"); +const char* const APPLICATION_TITLE_MEDIUMP("Dissolve Effect(mediump)"); +const char* const EFFECT_HIGHP_IMAGE(DEMO_IMAGE_DIR "icon-highp.png"); +const char* const EFFECT_HIGHP_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-highp-selected.png"); +const char* const EFFECT_MEDIUMP_IMAGE(DEMO_IMAGE_DIR "icon-mediump.png"); +const char* const EFFECT_MEDIUMP_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-mediump-selected.png"); +const char* const PLAY_ICON(DEMO_IMAGE_DIR "icon-play.png"); +const char* const PLAY_ICON_SELECTED(DEMO_IMAGE_DIR "icon-play-selected.png"); +const char* const STOP_ICON(DEMO_IMAGE_DIR "icon-stop.png"); +const char* const STOP_ICON_SELECTED(DEMO_IMAGE_DIR "icon-stop-selected.png"); const char* IMAGES[] = -{ - DEMO_IMAGE_DIR "gallery-large-1.jpg", - DEMO_IMAGE_DIR "gallery-large-2.jpg", - DEMO_IMAGE_DIR "gallery-large-3.jpg", - DEMO_IMAGE_DIR "gallery-large-4.jpg", - DEMO_IMAGE_DIR "gallery-large-5.jpg", - DEMO_IMAGE_DIR "gallery-large-6.jpg", - DEMO_IMAGE_DIR "gallery-large-7.jpg", - DEMO_IMAGE_DIR "gallery-large-8.jpg", - DEMO_IMAGE_DIR "gallery-large-9.jpg", - DEMO_IMAGE_DIR "gallery-large-10.jpg", - DEMO_IMAGE_DIR "gallery-large-11.jpg", - DEMO_IMAGE_DIR "gallery-large-12.jpg", - DEMO_IMAGE_DIR "gallery-large-13.jpg", - DEMO_IMAGE_DIR "gallery-large-14.jpg", - DEMO_IMAGE_DIR "gallery-large-15.jpg", - DEMO_IMAGE_DIR "gallery-large-16.jpg", - DEMO_IMAGE_DIR "gallery-large-17.jpg", - DEMO_IMAGE_DIR "gallery-large-18.jpg", - DEMO_IMAGE_DIR "gallery-large-19.jpg", - DEMO_IMAGE_DIR "gallery-large-20.jpg", - DEMO_IMAGE_DIR "gallery-large-21.jpg", + { + DEMO_IMAGE_DIR "gallery-large-1.jpg", + DEMO_IMAGE_DIR "gallery-large-2.jpg", + DEMO_IMAGE_DIR "gallery-large-3.jpg", + DEMO_IMAGE_DIR "gallery-large-4.jpg", + DEMO_IMAGE_DIR "gallery-large-5.jpg", + DEMO_IMAGE_DIR "gallery-large-6.jpg", + DEMO_IMAGE_DIR "gallery-large-7.jpg", + DEMO_IMAGE_DIR "gallery-large-8.jpg", + DEMO_IMAGE_DIR "gallery-large-9.jpg", + DEMO_IMAGE_DIR "gallery-large-10.jpg", + DEMO_IMAGE_DIR "gallery-large-11.jpg", + DEMO_IMAGE_DIR "gallery-large-12.jpg", + DEMO_IMAGE_DIR "gallery-large-13.jpg", + DEMO_IMAGE_DIR "gallery-large-14.jpg", + DEMO_IMAGE_DIR "gallery-large-15.jpg", + DEMO_IMAGE_DIR "gallery-large-16.jpg", + DEMO_IMAGE_DIR "gallery-large-17.jpg", + DEMO_IMAGE_DIR "gallery-large-18.jpg", + DEMO_IMAGE_DIR "gallery-large-19.jpg", + DEMO_IMAGE_DIR "gallery-large-20.jpg", + DEMO_IMAGE_DIR "gallery-large-21.jpg", }; -const int NUM_IMAGES( sizeof(IMAGES) / sizeof(IMAGES[0]) ); +const int NUM_IMAGES(sizeof(IMAGES) / sizeof(IMAGES[0])); // The duration of the current image staying on screen when slideshow is on const int VIEWINGTIME = 2000; // 2 seconds @@ -87,18 +86,18 @@ const float INITIAL_DEPTH = 10.0f; * load time to cover the entire window with pixels with no borders, * and filter mode BOX_THEN_LINEAR to sample the image with maximum quality. */ -Toolkit::ImageView CreateWindowFillingImageView( const Vector2& windowSize, const char * const imagePath ) +Toolkit::ImageView CreateWindowFillingImageView(const Vector2& windowSize, const char* const imagePath) { Toolkit::ImageView imageView = Toolkit::ImageView::New(); - Property::Map map; - map[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE; - map[Toolkit::ImageVisual::Property::URL] = imagePath; - map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = windowSize.x; - map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = windowSize.y; - map[Toolkit::ImageVisual::Property::FITTING_MODE] = FittingMode::SCALE_TO_FILL; - map[Toolkit::ImageVisual::Property::SAMPLING_MODE] = SamplingMode::BOX_THEN_LINEAR; + Property::Map map; + map[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE; + map[Toolkit::ImageVisual::Property::URL] = imagePath; + map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = windowSize.x; + map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = windowSize.y; + map[Toolkit::ImageVisual::Property::FITTING_MODE] = FittingMode::SCALE_TO_FILL; + map[Toolkit::ImageVisual::Property::SAMPLING_MODE] = SamplingMode::BOX_THEN_LINEAR; map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = true; - imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); + imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map); return imageView; } @@ -108,27 +107,25 @@ Toolkit::ImageView CreateWindowFillingImageView( const Vector2& windowSize, cons class DissolveEffectApp : public ConnectionTracker { public: - /** * Constructor * @param application class, stored as reference */ - DissolveEffectApp( Application& application ); + DissolveEffectApp(Application& application); ~DissolveEffectApp(); private: - /** * This method gets called once the main loop of application is up and running */ - void OnInit( Application& application ); + void OnInit(Application& application); /** * PanGesture callback. This method gets called when the pan gesture is detected. * @param[in] actor The actor receiving the pan gesture. * @param[in] gesture The detected pan gesture. */ - void OnPanGesture( Actor actor, const PanGesture& gesture ); + void OnPanGesture(Actor actor, const PanGesture& gesture); /** * Set up the animations for transition @@ -141,13 +138,13 @@ private: * Change the precision of the effect shader when the effect button is clicked * @param[in] button The handle of the clicked button */ - bool OnEffectButtonClicked( Toolkit::Button button ); + bool OnEffectButtonClicked(Toolkit::Button button); /** * Callback function of slideshow button * Start or stop the automatical image display when the slideshow button is clicked * @param[in] button The handle of the clicked button */ - bool OnSildeshowButtonClicked( Toolkit::Button button ); + bool OnSildeshowButtonClicked(Toolkit::Button button); /** * Callback function of cube transition completed signal * @param[in] effect The cube effect used for the transition @@ -166,45 +163,45 @@ private: void OnKeyEvent(const KeyEvent& event); private: - Application& mApplication; - Toolkit::Control mView; - Toolkit::ToolBar mToolBar; - Layer mContent; - Toolkit::TextLabel mTitleActor; - Actor mParent; + Application& mApplication; + Toolkit::Control mView; + Toolkit::ToolBar mToolBar; + Layer mContent; + Toolkit::TextLabel mTitleActor; + Actor mParent; - Toolkit::ImageView mCurrentImage; - Toolkit::ImageView mNextImage; - unsigned int mIndex; + Toolkit::ImageView mCurrentImage; + Toolkit::ImageView mNextImage; + unsigned int mIndex; - Property::Map mDissolveEffect; - Property::Map mEmptyEffect; + Property::Map mDissolveEffect; + Property::Map mEmptyEffect; - bool mUseHighPrecision; - Animation mAnimation; + bool mUseHighPrecision; + Animation mAnimation; - PanGestureDetector mPanGestureDetector; - bool mIsTransiting; + PanGestureDetector mPanGestureDetector; + bool mIsTransiting; - bool mSlideshow; - Timer mViewTimer; - bool mTimerReady; - unsigned int mCentralLineIndex; + bool mSlideshow; + Timer mViewTimer; + bool mTimerReady; + unsigned int mCentralLineIndex; - Toolkit::PushButton mPlayStopButton; - Toolkit::PushButton mEffectChangeButton; + Toolkit::PushButton mPlayStopButton; + Toolkit::PushButton mEffectChangeButton; }; -DissolveEffectApp::DissolveEffectApp( Application& application ) -: mApplication( application ), - mIndex( 0 ), +DissolveEffectApp::DissolveEffectApp(Application& application) +: mApplication(application), + mIndex(0), mUseHighPrecision(true), - mIsTransiting( false ), - mSlideshow( false ), - mTimerReady( false ), - mCentralLineIndex( 0 ) + mIsTransiting(false), + mSlideshow(false), + mTimerReady(false), + mCentralLineIndex(0) { - mApplication.InitSignal().Connect( this, &DissolveEffectApp::OnInit ); + mApplication.InitSignal().Connect(this, &DissolveEffectApp::OnInit); } DissolveEffectApp::~DissolveEffectApp() @@ -212,90 +209,90 @@ DissolveEffectApp::~DissolveEffectApp() //Nothing to do } -void DissolveEffectApp::OnInit( Application& application ) +void DissolveEffectApp::OnInit(Application& application) { - auto window = application.GetWindow(); + auto window = application.GetWindow(); Vector2 windowSize = window.GetSize(); window.KeyEventSignal().Connect(this, &DissolveEffectApp::OnKeyEvent); // Creates a default view with a default tool bar, the view is added to the window. - mContent = DemoHelper::CreateView( application, mView,mToolBar, "", TOOLBAR_IMAGE, "" ); + mContent = DemoHelper::CreateView(application, mView, mToolBar, "", TOOLBAR_IMAGE, ""); // Add an effect-changing button on the right of the tool bar. mEffectChangeButton = Toolkit::PushButton::New(); - mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE ); - mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE_SELECTED ); - mEffectChangeButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnEffectButtonClicked ); - mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mEffectChangeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE); + mEffectChangeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE_SELECTED); + mEffectChangeButton.ClickedSignal().Connect(this, &DissolveEffectApp::OnEffectButtonClicked); + mToolBar.AddControl(mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Add title to the tool bar. - mTitleActor = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_HIGHP ); - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER ); + mTitleActor = DemoHelper::CreateToolBarLabel(APPLICATION_TITLE_HIGHP); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER); // Add an slide-show button on the right of the title mPlayStopButton = Toolkit::PushButton::New(); - mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON ); - mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED ); - mPlayStopButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnSildeshowButtonClicked ); - mToolBar.AddControl( mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING ); + mPlayStopButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON); + mPlayStopButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED); + mPlayStopButton.ClickedSignal().Connect(this, &DissolveEffectApp::OnSildeshowButtonClicked); + mToolBar.AddControl(mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING); // use pan gesture to detect the cursor or finger movement mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture ); + mPanGestureDetector.DetectedSignal().Connect(this, &DissolveEffectApp::OnPanGesture); - mViewTimer = Timer::New( VIEWINGTIME ); - mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick ); + mViewTimer = Timer::New(VIEWINGTIME); + mViewTimer.TickSignal().Connect(this, &DissolveEffectApp::OnTimerTick); mTimerReady = true; // Set size to window size to avoid seeing a black border on transition mParent = Actor::New(); - mParent.SetProperty( Actor::Property::SIZE, windowSize ); - mParent.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mContent.Add( mParent ); + mParent.SetProperty(Actor::Property::SIZE, windowSize); + mParent.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mContent.Add(mParent); // show the first image - mCurrentImage = CreateWindowFillingImageView( windowSize, IMAGES[mIndex] ); - mCurrentImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mCurrentImage.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - mParent.Add( mCurrentImage ); + mCurrentImage = CreateWindowFillingImageView(windowSize, IMAGES[mIndex]); + mCurrentImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCurrentImage.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mCurrentImage.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + mParent.Add(mCurrentImage); - mPanGestureDetector.Attach( mCurrentImage ); + mPanGestureDetector.Attach(mCurrentImage); - mDissolveEffect = Dali::Toolkit::CreateDissolveEffect( mUseHighPrecision ); + mDissolveEffect = Dali::Toolkit::CreateDissolveEffect(mUseHighPrecision); Property::Map emptyShaderMap; - mEmptyEffect.Insert( "shader", emptyShaderMap ); + mEmptyEffect.Insert("shader", emptyShaderMap); } // signal handler, called when the pan gesture is detected -void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture ) +void DissolveEffectApp::OnPanGesture(Actor actor, const PanGesture& gesture) { // does not response when the animation has not finished - if( mIsTransiting || mSlideshow ) + if(mIsTransiting || mSlideshow) { return; } - if( gesture.GetState() == GestureState::CONTINUING ) + if(gesture.GetState() == GestureState::CONTINUING) { const Vector2& displacement = gesture.GetDisplacement(); - if( displacement.x < 0) + if(displacement.x < 0) { - mIndex = (mIndex + 1)%NUM_IMAGES; + mIndex = (mIndex + 1) % NUM_IMAGES; } else { - mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; + mIndex = (mIndex + NUM_IMAGES - 1) % NUM_IMAGES; } - mNextImage = CreateWindowFillingImageView( mApplication.GetWindow().GetSize(), IMAGES[ mIndex ] ); - mNextImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mNextImage.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - mNextImage.SetProperty( Actor::Property::POSITION_Z, INITIAL_DEPTH); - mParent.Add( mNextImage ); - Vector2 size = Vector2( mCurrentImage.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) ); - StartTransition( gesture.GetPosition() / size, displacement * Vector2(1.0, size.x/size.y)); + mNextImage = CreateWindowFillingImageView(mApplication.GetWindow().GetSize(), IMAGES[mIndex]); + mNextImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mNextImage.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mNextImage.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + mNextImage.SetProperty(Actor::Property::POSITION_Z, INITIAL_DEPTH); + mParent.Add(mNextImage); + Vector2 size = Vector2(mCurrentImage.GetCurrentProperty(Actor::Property::SIZE)); + StartTransition(gesture.GetPosition() / size, displacement * Vector2(1.0, size.x / size.y)); } } @@ -303,25 +300,25 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement) { mAnimation = Animation::New(TRANSITION_DURATION); - Dali::Toolkit::DissolveEffectSetCentralLine( mCurrentImage, position, displacement, 0.0f ); - mCurrentImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mDissolveEffect ); - mAnimation.AnimateTo( Property( mCurrentImage, "uPercentage" ), 1.0f, AlphaFunction::LINEAR ); + Dali::Toolkit::DissolveEffectSetCentralLine(mCurrentImage, position, displacement, 0.0f); + mCurrentImage.SetProperty(Toolkit::ImageView::Property::IMAGE, mDissolveEffect); + mAnimation.AnimateTo(Property(mCurrentImage, "uPercentage"), 1.0f, AlphaFunction::LINEAR); - mNextImage.SetProperty( Actor::Property::OPACITY,0.0f); - mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR ); + mNextImage.SetProperty(Actor::Property::OPACITY, 0.0f); + mAnimation.AnimateTo(Property(mNextImage, Actor::Property::COLOR_ALPHA), 1.0f, AlphaFunction::LINEAR); if(mUseHighPrecision) { - Dali::Toolkit::DissolveEffectSetCentralLine( mNextImage, position, displacement, 1.0f ); - mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mDissolveEffect ); - mAnimation.AnimateTo( Property( mNextImage, "uPercentage" ), 0.0f, AlphaFunction::LINEAR ); + Dali::Toolkit::DissolveEffectSetCentralLine(mNextImage, position, displacement, 1.0f); + mNextImage.SetProperty(Toolkit::ImageView::Property::IMAGE, mDissolveEffect); + mAnimation.AnimateTo(Property(mNextImage, "uPercentage"), 0.0f, AlphaFunction::LINEAR); } else { - mAnimation.AnimateTo( Property( mNextImage, Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR ); + mAnimation.AnimateTo(Property(mNextImage, Actor::Property::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunction::LINEAR); } - mAnimation.FinishedSignal().Connect( this, &DissolveEffectApp::OnTransitionCompleted ); + mAnimation.FinishedSignal().Connect(this, &DissolveEffectApp::OnTransitionCompleted); mAnimation.Play(); mIsTransiting = true; } @@ -330,67 +327,67 @@ void DissolveEffectApp::OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } } } -bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button ) +bool DissolveEffectApp::OnEffectButtonClicked(Toolkit::Button button) { mUseHighPrecision = !mUseHighPrecision; - mDissolveEffect = Dali::Toolkit::CreateDissolveEffect(mUseHighPrecision); + mDissolveEffect = Dali::Toolkit::CreateDissolveEffect(mUseHighPrecision); if(mUseHighPrecision) { - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP) ); - mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE ); - mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE_SELECTED ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP)); + mEffectChangeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE); + mEffectChangeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE_SELECTED); } else { - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_MEDIUMP) ); - mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_MEDIUMP_IMAGE ); - mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_MEDIUMP_IMAGE_SELECTED ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_MEDIUMP)); + mEffectChangeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_MEDIUMP_IMAGE); + mEffectChangeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_MEDIUMP_IMAGE_SELECTED); } return true; } -bool DissolveEffectApp::OnSildeshowButtonClicked( Toolkit::Button button ) +bool DissolveEffectApp::OnSildeshowButtonClicked(Toolkit::Button button) { mSlideshow = !mSlideshow; - if( mSlideshow ) + if(mSlideshow) { - mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, STOP_ICON ); - mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STOP_ICON_SELECTED ); - mPanGestureDetector.Detach( mParent ); + mPlayStopButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, STOP_ICON); + mPlayStopButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STOP_ICON_SELECTED); + mPanGestureDetector.Detach(mParent); mViewTimer.Start(); mTimerReady = false; } else { - mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON ); - mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED ); + mPlayStopButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON); + mPlayStopButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED); mTimerReady = true; - mPanGestureDetector.Attach( mParent ); + mPanGestureDetector.Attach(mParent); } return true; } -void DissolveEffectApp::OnTransitionCompleted( Animation& source ) +void DissolveEffectApp::OnTransitionCompleted(Animation& source) { if(mUseHighPrecision) { - mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mEmptyEffect ); + mNextImage.SetProperty(Toolkit::ImageView::Property::IMAGE, mEmptyEffect); } - mParent.Remove( mCurrentImage ); - mPanGestureDetector.Detach( mCurrentImage ); + mParent.Remove(mCurrentImage); + mPanGestureDetector.Detach(mCurrentImage); mCurrentImage = mNextImage; - mPanGestureDetector.Attach( mCurrentImage ); + mPanGestureDetector.Attach(mCurrentImage); mIsTransiting = false; - if( mSlideshow) + if(mSlideshow) { mViewTimer.Start(); mTimerReady = false; @@ -402,46 +399,45 @@ bool DissolveEffectApp::OnTimerTick() mTimerReady = true; if(mSlideshow) { - mIndex = (mIndex + 1)%NUM_IMAGES; - mNextImage = CreateWindowFillingImageView( mApplication.GetWindow().GetSize(), IMAGES[ mIndex ] ); - mNextImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mNextImage.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - mNextImage.SetProperty( Actor::Property::POSITION_Z, INITIAL_DEPTH); - mParent.Add( mNextImage ); - switch( mCentralLineIndex%4 ) + mIndex = (mIndex + 1) % NUM_IMAGES; + mNextImage = CreateWindowFillingImageView(mApplication.GetWindow().GetSize(), IMAGES[mIndex]); + mNextImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mNextImage.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mNextImage.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + mNextImage.SetProperty(Actor::Property::POSITION_Z, INITIAL_DEPTH); + mParent.Add(mNextImage); + switch(mCentralLineIndex % 4) { case 0: { - StartTransition(Vector2(1.0f,0.5f), Vector2(-1.0f, 0.0f)); + StartTransition(Vector2(1.0f, 0.5f), Vector2(-1.0f, 0.0f)); break; } case 1: { - StartTransition(Vector2(0.5f,0.0f), Vector2(0.0f, 1.0f)); + StartTransition(Vector2(0.5f, 0.0f), Vector2(0.0f, 1.0f)); break; } case 2: { - StartTransition(Vector2(0.0f,0.5f), Vector2(1.0f, 0.0f)); + StartTransition(Vector2(0.0f, 0.5f), Vector2(1.0f, 0.0f)); break; } default: { - StartTransition(Vector2(0.5f,1.0f), Vector2(0.0f, -1.0f)); + StartTransition(Vector2(0.5f, 1.0f), Vector2(0.0f, -1.0f)); break; } - } mCentralLineIndex++; } - return false; //return false to stop the timer + return false; //return false to stop the timer } -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - DissolveEffectApp test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + DissolveEffectApp test(application); application.MainLoop(); return 0; diff --git a/examples/drag-and-drop/drag-and-drop-example.cpp b/examples/drag-and-drop/drag-and-drop-example.cpp index b9e7f08..85e2d0b 100644 --- a/examples/drag-and-drop/drag-and-drop-example.cpp +++ b/examples/drag-and-drop/drag-and-drop-example.cpp @@ -16,9 +16,9 @@ */ #include -#include -#include #include +#include +#include using namespace Dali; using Dali::Toolkit::TextLabel; @@ -27,42 +27,40 @@ using namespace Dali::Toolkit; namespace { Vector4 TEXT_LABEL_COLOR[] = -{ - Color::MAGENTA, - Color::YELLOW, - Color::CYAN, - Color::BLUE, - Color::MAGENTA, - Color::YELLOW, - Color::CYAN, - Color::BLUE -}; - -const float TEXT_LABEL_POSITION_X = 100.0f; -const float TEXT_LABEL_POSITION_START_Y = 50.0f; -const float TEXT_LABEL_WIDTH = 250.0f; -const float TEXT_LABEL_HEIGHT = 70.0f; -const unsigned int TEXT_LABEL_NUM = sizeof(TEXT_LABEL_COLOR) / sizeof(TEXT_LABEL_COLOR[0]); + { + Color::MAGENTA, + Color::YELLOW, + Color::CYAN, + Color::BLUE, + Color::MAGENTA, + Color::YELLOW, + Color::CYAN, + Color::BLUE}; + +const float TEXT_LABEL_POSITION_X = 100.0f; +const float TEXT_LABEL_POSITION_START_Y = 50.0f; +const float TEXT_LABEL_WIDTH = 250.0f; +const float TEXT_LABEL_HEIGHT = 70.0f; +const unsigned int TEXT_LABEL_NUM = sizeof(TEXT_LABEL_COLOR) / sizeof(TEXT_LABEL_COLOR[0]); const float DROP_ANIMATION_DURATION_S = 0.5f; #if defined(DEBUG_ENABLED) - Debug::Filter* gDragAndDropFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_DRAG_AND_DROP_EXAMPLE"); +Debug::Filter* gDragAndDropFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_DRAG_AND_DROP_EXAMPLE"); #endif -} +} // namespace //This example shows how to use drag and drop function by several simple TextActors class DragAndDropExample : public ConnectionTracker { public: - - DragAndDropExample( Application& application ) - : mApplication( application ), + DragAndDropExample(Application& application) + : mApplication(application), mDragIndex(-1), mDragRealIndex(-1) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &DragAndDropExample::Create ); + mApplication.InitSignal().Connect(this, &DragAndDropExample::Create); } ~DragAndDropExample() @@ -71,40 +69,40 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { auto window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); mDragAndDropDetector = Dali::Toolkit::DragAndDropDetector::New(); // Respond to key events - window.KeyEventSignal().Connect( this, &DragAndDropExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &DragAndDropExample::OnKeyEvent); TextLabel hintText = TextLabel::New("please drag one textlabel, move and drop on other textlabel"); - hintText.SetProperty( Actor::Property::POSITION, Vector2(0.0f, 700.0f)); - hintText.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - hintText.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + hintText.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 700.0f)); + hintText.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + hintText.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); hintText.SetProperty(TextLabel::Property::MULTI_LINE, true); window.Add(hintText); - for(unsigned int i = 0 ; i < TEXT_LABEL_NUM; i++) + for(unsigned int i = 0; i < TEXT_LABEL_NUM; i++) { std::string str = "textlabel "; - mTextLabel[i] = TextLabel::New(str + std::to_string(i)); - mTextLabel[i].SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mTextLabel[i].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); - mTextLabel[i].SetProperty( Dali::Actor::Property::NAME,"textlabel " + std::to_string(i)); - mTextLabel[i].SetProperty( Actor::Property::LEAVE_REQUIRED,true); + mTextLabel[i] = TextLabel::New(str + std::to_string(i)); + mTextLabel[i].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mTextLabel[i].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mTextLabel[i].SetProperty(Dali::Actor::Property::NAME, "textlabel " + std::to_string(i)); + mTextLabel[i].SetProperty(Actor::Property::LEAVE_REQUIRED, true); mTextLabel[i].SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); mTextLabel[i].SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); mTextLabel[i].SetBackgroundColor(TEXT_LABEL_COLOR[i]); - mTextLabel[i].SetProperty( Actor::Property::SIZE, Vector2(TEXT_LABEL_WIDTH, TEXT_LABEL_HEIGHT) ); - mTextLabel[i].SetProperty( Actor::Property::POSITION, Vector2(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * i)); + mTextLabel[i].SetProperty(Actor::Property::SIZE, Vector2(TEXT_LABEL_WIDTH, TEXT_LABEL_HEIGHT)); + mTextLabel[i].SetProperty(Actor::Property::POSITION, Vector2(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * i)); mDragAndDropDetector.Attach(mTextLabel[i]); - mRect[i] = Rect(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * i, TEXT_LABEL_WIDTH, TEXT_LABEL_HEIGHT); + mRect[i] = Rect(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * i, TEXT_LABEL_WIDTH, TEXT_LABEL_HEIGHT); mOrder[i] = i; window.Add(mTextLabel[i]); @@ -118,11 +116,11 @@ public: mDragAndDropDetector.EndedSignal().Connect(this, &DragAndDropExample::OnEnd); } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -132,11 +130,11 @@ public: void OnStart(Control control, Dali::Toolkit::DragAndDropDetector detector) { DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---OnStart---\n"); - DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str()); + DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty(Dali::Actor::Property::NAME).c_str()); - control.SetProperty( Actor::Property::OPACITY,0.1f); - Vector2 screenPos = detector.GetCurrentScreenPosition(); - control.ScreenToLocal(mDragLocalPos.x, mDragLocalPos.y,screenPos.x, screenPos.y ); + control.SetProperty(Actor::Property::OPACITY, 0.1f); + Vector2 screenPos = detector.GetCurrentScreenPosition(); + control.ScreenToLocal(mDragLocalPos.x, mDragLocalPos.y, screenPos.x, screenPos.y); Rect targetRect(screenPos.x, screenPos.y, 0.0f, 0.0f); for(unsigned int i = 0; i < TEXT_LABEL_NUM; i++) @@ -153,30 +151,30 @@ public: void OnEnter(Control control, Dali::Toolkit::DragAndDropDetector detector) { DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---OnEnter---\n"); - DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str()); + DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty(Dali::Actor::Property::NAME).c_str()); } void OnExit(Control control, Dali::Toolkit::DragAndDropDetector detector) { DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---OnExit---\n"); - DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str()); + DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty(Dali::Actor::Property::NAME).c_str()); } void OnMoved(Control control, Dali::Toolkit::DragAndDropDetector detector) { DALI_LOG_INFO(gDragAndDropFilter, Debug::Verbose, "---OnMoved---\n"); - DALI_LOG_INFO(gDragAndDropFilter, Debug::Verbose, "---control name is %s---\n", control.GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str()); + DALI_LOG_INFO(gDragAndDropFilter, Debug::Verbose, "---control name is %s---\n", control.GetProperty(Dali::Actor::Property::NAME).c_str()); DALI_LOG_INFO(gDragAndDropFilter, Debug::Verbose, "---coordinate is (%f, %f)---\n", detector.GetCurrentScreenPosition().x, detector.GetCurrentScreenPosition().y); } void OnDropped(Control control, Dali::Toolkit::DragAndDropDetector detector) { DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---OnDropped---\n"); - DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str()); + DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty(Dali::Actor::Property::NAME).c_str()); - Vector2 screenPos = detector.GetCurrentScreenPosition(); + Vector2 screenPos = detector.GetCurrentScreenPosition(); Rect targetRect(screenPos.x, screenPos.y, 0.0f, 0.0f); - int droppedIndex = -1; + int droppedIndex = -1; for(unsigned int i = 0; i < TEXT_LABEL_NUM; i++) { if(mRect[i].Contains(targetRect)) @@ -192,14 +190,15 @@ public: for(int i = mDragIndex + 1; i <= droppedIndex; i++) { mAnimation.AnimateTo(Property(mTextLabel[mOrder[i]], Actor::Property::POSITION), - Vector3(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * (i - 1), 0.0f), AlphaFunction::EASE_OUT); + Vector3(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * (i - 1), 0.0f), + AlphaFunction::EASE_OUT); mAnimation.Play(); } int tmpId = mOrder[mDragIndex]; for(int i = mDragIndex; i < droppedIndex; i++) { - mOrder[i] = mOrder[i+1]; + mOrder[i] = mOrder[i + 1]; } mOrder[droppedIndex] = tmpId; @@ -209,14 +208,15 @@ public: for(int i = mDragIndex - 1; i >= droppedIndex; i--) { mAnimation.AnimateTo(Property(mTextLabel[mOrder[i]], Actor::Property::POSITION), - Vector3(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * (i + 1), 0.0f), AlphaFunction::EASE_OUT); + Vector3(TEXT_LABEL_POSITION_X, TEXT_LABEL_POSITION_START_Y + TEXT_LABEL_HEIGHT * (i + 1), 0.0f), + AlphaFunction::EASE_OUT); mAnimation.Play(); } int tmpId = mOrder[mDragIndex]; for(int i = mDragIndex; i > droppedIndex; i--) { - mOrder[i] = mOrder[i-1]; + mOrder[i] = mOrder[i - 1]; } mOrder[droppedIndex] = tmpId; @@ -242,7 +242,7 @@ public: void DropAnimationFinished(Animation& animation) { - for(unsigned int i = 0 ; i < TEXT_LABEL_NUM; i++) + for(unsigned int i = 0; i < TEXT_LABEL_NUM; i++) { mDragAndDropDetector.Attach(mTextLabel[i]); } @@ -251,16 +251,16 @@ public: void OnEnd(Control control, Dali::Toolkit::DragAndDropDetector detector) { DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---OnEnd---\n"); - DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str()); + DALI_LOG_INFO(gDragAndDropFilter, Debug::General, "---control name is %s---\n", control.GetProperty(Dali::Actor::Property::NAME).c_str()); - control.SetProperty( Actor::Property::OPACITY,1.0f); + control.SetProperty(Actor::Property::OPACITY, 1.0f); } private: - Application& mApplication; + Application& mApplication; Dali::Toolkit::DragAndDropDetector mDragAndDropDetector; - TextLabel mTextLabel[TEXT_LABEL_NUM]; + TextLabel mTextLabel[TEXT_LABEL_NUM]; Rect mRect[TEXT_LABEL_NUM]; int mOrder[TEXT_LABEL_NUM]; @@ -268,13 +268,12 @@ private: int mDragRealIndex; Vector2 mDragLocalPos; - }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - DragAndDropExample test( application ); + Application application = Application::New(&argc, &argv); + DragAndDropExample test(application); application.MainLoop(); return 0; } diff --git a/examples/effects-view/effects-view-example.cpp b/examples/effects-view/effects-view-example.cpp index c446cfb..b041a26 100644 --- a/examples/effects-view/effects-view-example.cpp +++ b/examples/effects-view/effects-view-example.cpp @@ -20,9 +20,9 @@ // INTERNAL INCLUDES #include "shared/view.h" -#include #include #include +#include #include using namespace Dali; @@ -30,11 +30,11 @@ using namespace Dali::Toolkit; namespace { -const char* const TITLE( "EffectsView: effect size = " ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* VIEW_SWAP_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* VIEW_SWAP_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char* TEST_IMAGE( DEMO_IMAGE_DIR "Kid1.svg" ); +const char* const TITLE("EffectsView: effect size = "); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* VIEW_SWAP_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* VIEW_SWAP_SELECTED_IMAGE(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* TEST_IMAGE(DEMO_IMAGE_DIR "Kid1.svg"); } // namespace // This example illustrates the capabilities of the EffectsView container @@ -42,22 +42,20 @@ const char* TEST_IMAGE( DEMO_IMAGE_DIR "Kid1.svg" ); class EffectsViewApp : public ConnectionTracker { public: - /** * Constructor */ - EffectsViewApp( Application& application ); + EffectsViewApp(Application& application); /** * Destructor */ ~EffectsViewApp(); private: - /** * Initialisation. This method gets called once the main loop of application is up and running */ - void OnAppInitialize( Application& application ); + void OnAppInitialize(Application& application); /** * Create a effect view of drop shadow @@ -66,13 +64,13 @@ private: * @param[in] viewSize Size of the effect view * @param[in] effectSize The effect size used in image filters. */ - EffectsView CreateEffectsView( EffectsView::EffectType type, const Vector2& viewSize, int effectSize ); + EffectsView CreateEffectsView(EffectsView::EffectType type, const Vector2& viewSize, int effectSize); /** * Animate the effect offset and color properties. * @param[in] effectsView The view whose properties to be animated. */ - void AnimateEffectProperties( EffectsView& effectsView ); + void AnimateEffectProperties(EffectsView& effectsView); /** * Set title onto the toolbar @@ -84,7 +82,7 @@ private: * Callback function to change the effect size. * @param[in] button The button which triggered the callback. */ - bool ChangeEffectSize( Button button ); + bool ChangeEffectSize(Button button); /** * Main key event handler @@ -92,23 +90,23 @@ private: void OnKeyEvent(const KeyEvent& event); private: - Application& mApplication; - Layer mContents; - Toolkit::Control mView; - Toolkit::ToolBar mToolBar; - EffectsView mDropShadowView; - EffectsView mEmbossView; - Toolkit::TextLabel mTitleActor; ///< The title on the toolbar - Vector2 mWindowSize; - int mEffectSize; + Application& mApplication; + Layer mContents; + Toolkit::Control mView; + Toolkit::ToolBar mToolBar; + EffectsView mDropShadowView; + EffectsView mEmbossView; + Toolkit::TextLabel mTitleActor; ///< The title on the toolbar + Vector2 mWindowSize; + int mEffectSize; }; -EffectsViewApp::EffectsViewApp( Application& application ) -: mApplication( application ), - mEffectSize( 2 ) +EffectsViewApp::EffectsViewApp(Application& application) +: mApplication(application), + mEffectSize(2) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &EffectsViewApp::OnAppInitialize ); + mApplication.InitSignal().Connect(this, &EffectsViewApp::OnAppInitialize); } EffectsViewApp::~EffectsViewApp() @@ -116,127 +114,125 @@ EffectsViewApp::~EffectsViewApp() // Nothing to do here; } -void EffectsViewApp::OnAppInitialize( Application& application ) +void EffectsViewApp::OnAppInitialize(Application& application) { // The Init signal is received once (only) during the Application lifetime auto window = application.GetWindow(); window.KeyEventSignal().Connect(this, &EffectsViewApp::OnKeyEvent); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); mWindowSize = window.GetSize(); // Creates a default view with a default tool bar. // The view is added to the window. - mContents = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" ); + mContents = DemoHelper::CreateView(application, mView, mToolBar, "", TOOLBAR_IMAGE, ""); // Creates view change button. Toolkit::PushButton viewButton = Toolkit::PushButton::New(); - viewButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, VIEW_SWAP_IMAGE ); - viewButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, VIEW_SWAP_SELECTED_IMAGE ); + viewButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, VIEW_SWAP_IMAGE); + viewButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, VIEW_SWAP_SELECTED_IMAGE); // Connects the view change button clicked signal to the OnView method. - viewButton.ClickedSignal().Connect( this, &EffectsViewApp::ChangeEffectSize ); - mToolBar.AddControl( viewButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); - - Vector2 effectsViewSize( mWindowSize.width, mWindowSize.height * 0.25f ); - mDropShadowView = CreateEffectsView( EffectsView::DROP_SHADOW, effectsViewSize, mEffectSize ); - mDropShadowView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mDropShadowView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mDropShadowView.SetProperty( Actor::Property::POSITION_Z, -mWindowSize.height * 0.1f ); - mContents.Add( mDropShadowView ); - - mEmbossView = CreateEffectsView( EffectsView::EMBOSS, effectsViewSize, mEffectSize ); - mEmbossView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mEmbossView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mEmbossView.SetProperty( Actor::Property::POSITION_Z, mWindowSize.height * 0.1f ); - mContents.Add( mEmbossView ); - - SetTitle( mEffectSize ); + viewButton.ClickedSignal().Connect(this, &EffectsViewApp::ChangeEffectSize); + mToolBar.AddControl(viewButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); + + Vector2 effectsViewSize(mWindowSize.width, mWindowSize.height * 0.25f); + mDropShadowView = CreateEffectsView(EffectsView::DROP_SHADOW, effectsViewSize, mEffectSize); + mDropShadowView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mDropShadowView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mDropShadowView.SetProperty(Actor::Property::POSITION_Z, -mWindowSize.height * 0.1f); + mContents.Add(mDropShadowView); + + mEmbossView = CreateEffectsView(EffectsView::EMBOSS, effectsViewSize, mEffectSize); + mEmbossView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mEmbossView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mEmbossView.SetProperty(Actor::Property::POSITION_Z, mWindowSize.height * 0.1f); + mContents.Add(mEmbossView); + + SetTitle(mEffectSize); } - -EffectsView EffectsViewApp::CreateEffectsView( EffectsView::EffectType type, const Vector2& viewSize, int effectSize ) +EffectsView EffectsViewApp::CreateEffectsView(EffectsView::EffectType type, const Vector2& viewSize, int effectSize) { Toolkit::EffectsView effectsView = Toolkit::EffectsView::New(type); // set control size - effectsView.SetProperty( Actor::Property::SIZE, Vector2( viewSize.width, viewSize.height ) ); + effectsView.SetProperty(Actor::Property::SIZE, Vector2(viewSize.width, viewSize.height)); // set effect size property - effectsView.SetProperty( EffectsView::Property::EFFECT_SIZE, effectSize ); + effectsView.SetProperty(EffectsView::Property::EFFECT_SIZE, effectSize); // Create some content // text - std::string text = ( type == EffectsView::DROP_SHADOW) ? "Drop Shadow" : "Emboss"; - TextLabel textActor( TextLabel::New( text ) ); - textActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT ); - textActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); - textActor.SetProperty( Actor::Property::SIZE, viewSize ); - textActor.SetProperty( Actor::Property::POSITION, Vector2( viewSize.width*0.4f, viewSize.height*0.3f )); - textActor.SetProperty( TextLabel::Property::POINT_SIZE, 14.f ); - effectsView.Add( textActor ); + std::string text = (type == EffectsView::DROP_SHADOW) ? "Drop Shadow" : "Emboss"; + TextLabel textActor(TextLabel::New(text)); + textActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT); + textActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); + textActor.SetProperty(Actor::Property::SIZE, viewSize); + textActor.SetProperty(Actor::Property::POSITION, Vector2(viewSize.width * 0.4f, viewSize.height * 0.3f)); + textActor.SetProperty(TextLabel::Property::POINT_SIZE, 14.f); + effectsView.Add(textActor); // image - ImageView icon = ImageView::New( TEST_IMAGE ); - icon.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT ); - icon.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); - icon.SetProperty( Actor::Property::POSITION_X, viewSize.width*0.1f ); - icon.SetProperty( Actor::Property::SIZE, Vector2( viewSize.height*0.8f, viewSize.height*0.8f ) ); - effectsView.Add( icon ); + ImageView icon = ImageView::New(TEST_IMAGE); + icon.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT); + icon.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); + icon.SetProperty(Actor::Property::POSITION_X, viewSize.width * 0.1f); + icon.SetProperty(Actor::Property::SIZE, Vector2(viewSize.height * 0.8f, viewSize.height * 0.8f)); + effectsView.Add(icon); - AnimateEffectProperties( effectsView ); + AnimateEffectProperties(effectsView); return effectsView; } -void EffectsViewApp::AnimateEffectProperties( EffectsView& effectsView ) +void EffectsViewApp::AnimateEffectProperties(EffectsView& effectsView) { - const float animationTime( 5.0f ); - Animation animation( Animation::New(animationTime) ); + const float animationTime(5.0f); + Animation animation(Animation::New(animationTime)); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3( 2.f,-2.f, 0.0f), TimePeriod(animationTime * 0.0f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3(-2.f,-2.f, 0.0f), TimePeriod(animationTime * 0.2f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3(-2.f, 2.f, 0.0f), TimePeriod(animationTime * 0.4f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3( 4.f, 4.f, 0.0f), TimePeriod(animationTime * 0.6f, animationTime * 0.2f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_OFFSET ), Vector3::ZERO, TimePeriod(animationTime * 0.8f, animationTime * 0.2f) ); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(2.f, -2.f, 0.0f), TimePeriod(animationTime * 0.0f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(-2.f, -2.f, 0.0f), TimePeriod(animationTime * 0.2f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(-2.f, 2.f, 0.0f), TimePeriod(animationTime * 0.4f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3(4.f, 4.f, 0.0f), TimePeriod(animationTime * 0.6f, animationTime * 0.2f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_OFFSET), Vector3::ZERO, TimePeriod(animationTime * 0.8f, animationTime * 0.2f)); - effectsView.SetProperty( EffectsView::Property::EFFECT_COLOR, Color::BLACK ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_COLOR ), Color::BLUE, TimePeriod(animationTime * 0.0f, animationTime * 0.33f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_COLOR ), Color::RED, TimePeriod(animationTime * 0.33f, animationTime * 0.33f) ); - animation.AnimateTo( Property( effectsView, EffectsView::Property::EFFECT_COLOR ), Color::BLACK, TimePeriod(animationTime * 0.66f, animationTime * 0.34f)); + effectsView.SetProperty(EffectsView::Property::EFFECT_COLOR, Color::BLACK); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_COLOR), Color::BLUE, TimePeriod(animationTime * 0.0f, animationTime * 0.33f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_COLOR), Color::RED, TimePeriod(animationTime * 0.33f, animationTime * 0.33f)); + animation.AnimateTo(Property(effectsView, EffectsView::Property::EFFECT_COLOR), Color::BLACK, TimePeriod(animationTime * 0.66f, animationTime * 0.34f)); - animation.SetLooping( true ); + animation.SetLooping(true); animation.Play(); } void EffectsViewApp::SetTitle(int effectSize) { std::ostringstream title; - title< #include "shared/view.h" -#include #include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { - const int NUM_FLEX_ITEMS = 8; -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-default.png" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-default.png"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); -const DemoHelper::ViewStyle VIEW_STYLE( 0.08f, 0.45f, 80.f, 4.f ); +const DemoHelper::ViewStyle VIEW_STYLE(0.08f, 0.45f, 80.f, 4.f); const std::string FLEX_DIRECTION[] = { - "column", - "columnReverse", - "row", - "rowReverse" -}; + "column", + "columnReverse", + "row", + "rowReverse"}; const unsigned int NUM_FLEX_DIRECTION = sizeof(FLEX_DIRECTION) / sizeof(std::string); const std::string FLEX_WRAP[] = { - "noWrap", - "Wrap" -}; + "noWrap", + "Wrap"}; const unsigned int NUM_FLEX_WRAP = sizeof(FLEX_WRAP) / sizeof(std::string); const std::string CONTENT_DIRECTION[] = { - "inherit", - "LTR", - "RTL" -}; + "inherit", + "LTR", + "RTL"}; const unsigned int NUM_CONTENT_DIRECTION = sizeof(CONTENT_DIRECTION) / sizeof(std::string); const std::string JUSTIFY_CONTENT[] = { - "flexStart", - "center", - "flexEnd", - "spaceBetween", - "spaceAround" -}; + "flexStart", + "center", + "flexEnd", + "spaceBetween", + "spaceAround"}; const unsigned int NUM_JUSTIFY_CONTENT = sizeof(JUSTIFY_CONTENT) / sizeof(std::string); const std::string ALIGN_ITEMS[] = { - "flexStart", - "center", - "flexEnd", - "stretch" -}; + "flexStart", + "center", + "flexEnd", + "stretch"}; const unsigned int NUM_ALIGN_ITEMS = sizeof(ALIGN_ITEMS) / sizeof(std::string); const std::string ALIGN_CONTENT[] = { - "flexStart", - "center", - "flexEnd", - "stretch" -}; + "flexStart", + "center", + "flexEnd", + "stretch"}; const unsigned int NUM_ALIGN_CONTENT = sizeof(ALIGN_CONTENT) / sizeof(std::string); @@ -96,19 +89,18 @@ const unsigned int NUM_ALIGN_CONTENT = sizeof(ALIGN_CONTENT) / sizeof(std::strin class FlexContainerExample : public ConnectionTracker { public: - /** * Constructor * @param application class, stored as reference */ - FlexContainerExample( Application& application ) - : mApplication( application ), - mCurrentFlexDirection( FlexContainer::ROW ), - mCurrentFlexWrap( FlexContainer::WRAP ), - mCurrentContentDirection( FlexContainer::INHERIT), - mCurrentJustifyContent( FlexContainer::JUSTIFY_FLEX_START ), - mCurrentAlignItems( FlexContainer::ALIGN_FLEX_START ), - mCurrentAlignContent( FlexContainer::ALIGN_FLEX_START ) + FlexContainerExample(Application& application) + : mApplication(application), + mCurrentFlexDirection(FlexContainer::ROW), + mCurrentFlexWrap(FlexContainer::WRAP), + mCurrentContentDirection(FlexContainer::INHERIT), + mCurrentJustifyContent(FlexContainer::JUSTIFY_FLEX_START), + mCurrentAlignItems(FlexContainer::ALIGN_FLEX_START), + mCurrentAlignContent(FlexContainer::ALIGN_FLEX_START) { // Connect to the Application's Init signal mApplication.InitSignal().Connect(this, &FlexContainerExample::OnInit); @@ -121,189 +113,188 @@ public: { auto window = app.GetWindow(); window.KeyEventSignal().Connect(this, &FlexContainerExample::OnKeyEvent); - window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR,Layer::LAYER_3D ); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); Vector2 windowSize = window.GetSize(); // Creates a default view with a default tool bar. // The view is added to the window. - Layer contents = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); + Layer contents = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); // Create a flex direction toggle button. (left of toolbar) mFlexDirectionButton = Toolkit::PushButton::New(); - mFlexDirectionButton.SetProperty( Dali::Actor::Property::NAME,"mFlexDirectionButton"); - mFlexDirectionButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-change.png" ); - mFlexDirectionButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-change-selected.png" ); - mFlexDirectionButton.ClickedSignal().Connect( this, &FlexContainerExample::OnFlexDirectionButtonClicked); - mFlexDirectionButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( mFlexDirectionButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mFlexDirectionButton.SetProperty(Dali::Actor::Property::NAME, "mFlexDirectionButton"); + mFlexDirectionButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-change.png"); + mFlexDirectionButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-change-selected.png"); + mFlexDirectionButton.ClickedSignal().Connect(this, &FlexContainerExample::OnFlexDirectionButtonClicked); + mFlexDirectionButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mFlexDirectionButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a flex wrap toggle button. (left of toolbar) mFlexWrapButton = Toolkit::PushButton::New(); - mFlexWrapButton.SetProperty( Dali::Actor::Property::NAME,"mFlexWrapButton"); - mFlexWrapButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-edit.png" ); - mFlexWrapButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-edit-selected.png" ); - mFlexWrapButton.ClickedSignal().Connect( this, &FlexContainerExample::OnFlexWrapButtonClicked); - mFlexWrapButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( mFlexWrapButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mFlexWrapButton.SetProperty(Dali::Actor::Property::NAME, "mFlexWrapButton"); + mFlexWrapButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-edit.png"); + mFlexWrapButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-edit-selected.png"); + mFlexWrapButton.ClickedSignal().Connect(this, &FlexContainerExample::OnFlexWrapButtonClicked); + mFlexWrapButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mFlexWrapButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a content direction toggle button. (left of toolbar) mContentDirectionButton = Toolkit::PushButton::New(); - mContentDirectionButton.SetProperty( Dali::Actor::Property::NAME,"mContentDirectionButton"); - mContentDirectionButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-replace.png" ); - mContentDirectionButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-replace-selected.png" ); - mContentDirectionButton.ClickedSignal().Connect( this, &FlexContainerExample::OnContentDirectionButtonClicked); - mContentDirectionButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( mContentDirectionButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mContentDirectionButton.SetProperty(Dali::Actor::Property::NAME, "mContentDirectionButton"); + mContentDirectionButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-replace.png"); + mContentDirectionButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-replace-selected.png"); + mContentDirectionButton.ClickedSignal().Connect(this, &FlexContainerExample::OnContentDirectionButtonClicked); + mContentDirectionButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mContentDirectionButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a justify content toggle button. (right of toolbar) mJustifyContentButton = Toolkit::PushButton::New(); - mJustifyContentButton.SetProperty( Dali::Actor::Property::NAME,"mJustifyContentButton"); - mJustifyContentButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-reset.png" ); - mJustifyContentButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-reset-selected.png" ); - mJustifyContentButton.ClickedSignal().Connect( this, &FlexContainerExample::OnJustifyContentButtonClicked); - mJustifyContentButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( mJustifyContentButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mJustifyContentButton.SetProperty(Dali::Actor::Property::NAME, "mJustifyContentButton"); + mJustifyContentButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-reset.png"); + mJustifyContentButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-reset-selected.png"); + mJustifyContentButton.ClickedSignal().Connect(this, &FlexContainerExample::OnJustifyContentButtonClicked); + mJustifyContentButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mJustifyContentButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a align items toggle button. (right of toolbar) mAlignItemsButton = Toolkit::PushButton::New(); - mAlignItemsButton.SetProperty( Dali::Actor::Property::NAME,"mAlignItemsButton"); - mAlignItemsButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-highp.png" ); - mAlignItemsButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-highp-selected.png" ); - mAlignItemsButton.ClickedSignal().Connect( this, &FlexContainerExample::OnAlignItemsButtonClicked); - mAlignItemsButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( mAlignItemsButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mAlignItemsButton.SetProperty(Dali::Actor::Property::NAME, "mAlignItemsButton"); + mAlignItemsButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-highp.png"); + mAlignItemsButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-highp-selected.png"); + mAlignItemsButton.ClickedSignal().Connect(this, &FlexContainerExample::OnAlignItemsButtonClicked); + mAlignItemsButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mAlignItemsButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a align content toggle button. (right of toolbar) mAlignContentButton = Toolkit::PushButton::New(); - mAlignContentButton.SetProperty( Dali::Actor::Property::NAME,"mAlignContentButton"); - mAlignContentButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-effect-cross.png" ); - mAlignContentButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-effect-cross-selected.png" ); - mAlignContentButton.ClickedSignal().Connect( this, &FlexContainerExample::OnAlignContentButtonClicked); - mAlignContentButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( mAlignContentButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mAlignContentButton.SetProperty(Dali::Actor::Property::NAME, "mAlignContentButton"); + mAlignContentButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-effect-cross.png"); + mAlignContentButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEMO_IMAGE_DIR "icon-effect-cross-selected.png"); + mAlignContentButton.ClickedSignal().Connect(this, &FlexContainerExample::OnAlignContentButtonClicked); + mAlignContentButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mAlignContentButton, VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create the base flex container mFlexContainer = FlexContainer::New(); - mFlexContainer.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mFlexContainer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); - mFlexContainer.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width, windowSize.height - VIEW_STYLE.mToolBarHeight ) ); - mFlexContainer.SetProperty( Actor::Property::POSITION_Y, VIEW_STYLE.mToolBarHeight); + mFlexContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mFlexContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mFlexContainer.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width, windowSize.height - VIEW_STYLE.mToolBarHeight)); + mFlexContainer.SetProperty(Actor::Property::POSITION_Y, VIEW_STYLE.mToolBarHeight); mFlexContainer.SetProperty(FlexContainer::Property::FLEX_DIRECTION, FlexContainer::COLUMN); // column as main axis contents.Add(mFlexContainer); // Add a text label to the container for showing the recently updated flexbox property value - mFlexPropertyLabel = TextLabel::New( FLEX_DIRECTION[mCurrentFlexDirection] ); + mFlexPropertyLabel = TextLabel::New(FLEX_DIRECTION[mCurrentFlexDirection]); mFlexPropertyLabel.SetProperty(FlexContainer::ChildProperty::FLEX_MARGIN, Vector4(10.0f, 10.0f, 10.0f, 10.0f)); mFlexPropertyLabel.SetProperty(FlexContainer::ChildProperty::FLEX, 0.05f); // 5 pecent of the container size in the main axis mFlexPropertyLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); mFlexPropertyLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - mFlexContainer.Add( mFlexPropertyLabel ); + mFlexContainer.Add(mFlexPropertyLabel); // Create the flex container for the flex items and add it to the base flex container mFlexItemContainer = FlexContainer::New(); - mFlexItemContainer.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mFlexItemContainer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); - mFlexItemContainer.SetBackgroundColor( Color::YELLOW ); + mFlexItemContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mFlexItemContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mFlexItemContainer.SetBackgroundColor(Color::YELLOW); mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_DIRECTION, mCurrentFlexDirection); mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_WRAP, mCurrentFlexWrap); mFlexItemContainer.SetProperty(FlexContainer::ChildProperty::FLEX, 0.95f); // 95 pecent of the container size in the main axis mFlexContainer.Add(mFlexItemContainer); // Create flex items and add them to the container - for (int i = 0; i < NUM_FLEX_ITEMS; i++) + for(int i = 0; i < NUM_FLEX_ITEMS; i++) { PushButton flexItem = PushButton::New(); - flexItem.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - flexItem.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + flexItem.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + flexItem.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); // Set different background colour to help to identify different items flexItem.SetBackgroundColor(Vector4(static_cast(i) / NUM_FLEX_ITEMS, static_cast(NUM_FLEX_ITEMS - i) / NUM_FLEX_ITEMS, 1.0f, 1.0f)); - flexItem.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, "" ); - flexItem.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, "" ); + flexItem.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ""); + flexItem.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ""); // Add a label to the button so that we can identify each item more easily std::ostringstream index; index << i + 1; - flexItem.SetProperty( Toolkit::Button::Property::LABEL, index.str() ); - flexItem.SetProperty( Dali::Actor::Property::NAME,"FlexItem " + index.str()); + flexItem.SetProperty(Toolkit::Button::Property::LABEL, index.str()); + flexItem.SetProperty(Dali::Actor::Property::NAME, "FlexItem " + index.str()); // Set a fixed size to the items so that we can wrap the line and test these // flex properties that only work when there are multiple lines in the layout flexItem.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); // Make sure there are still extra space in the line after wrapping - flexItem.SetProperty( Actor::Property::SIZE, Vector2(windowSize.width / NUM_FLEX_ITEMS * 1.25f, (windowSize.height - VIEW_STYLE.mToolBarHeight) * 0.95f / NUM_FLEX_ITEMS * 1.25f) ); + flexItem.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width / NUM_FLEX_ITEMS * 1.25f, (windowSize.height - VIEW_STYLE.mToolBarHeight) * 0.95f / NUM_FLEX_ITEMS * 1.25f)); - mFlexItemContainer.Add( flexItem ); + mFlexItemContainer.Add(flexItem); } // Update the title - SetTitle( "Flex direction", FLEX_DIRECTION[mCurrentFlexDirection] ); + SetTitle("Flex direction", FLEX_DIRECTION[mCurrentFlexDirection]); } - bool OnFlexDirectionButtonClicked( Toolkit::Button button ) + bool OnFlexDirectionButtonClicked(Toolkit::Button button) { - mCurrentFlexDirection = static_cast( ( mCurrentFlexDirection + 1 ) % NUM_FLEX_DIRECTION ); + mCurrentFlexDirection = static_cast((mCurrentFlexDirection + 1) % NUM_FLEX_DIRECTION); mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_DIRECTION, mCurrentFlexDirection); - SetTitle( "Flex direction", FLEX_DIRECTION[mCurrentFlexDirection] ); + SetTitle("Flex direction", FLEX_DIRECTION[mCurrentFlexDirection]); return true; } - bool OnFlexWrapButtonClicked( Toolkit::Button button ) + bool OnFlexWrapButtonClicked(Toolkit::Button button) { - mCurrentFlexWrap = static_cast( ( mCurrentFlexWrap + 1 ) % NUM_FLEX_WRAP ); + mCurrentFlexWrap = static_cast((mCurrentFlexWrap + 1) % NUM_FLEX_WRAP); mFlexItemContainer.SetProperty(FlexContainer::Property::FLEX_WRAP, mCurrentFlexWrap); - SetTitle( "Flex wrap", FLEX_WRAP[mCurrentFlexWrap] ); + SetTitle("Flex wrap", FLEX_WRAP[mCurrentFlexWrap]); return true; } - bool OnContentDirectionButtonClicked( Toolkit::Button button ) + bool OnContentDirectionButtonClicked(Toolkit::Button button) { - mCurrentContentDirection = static_cast( ( mCurrentContentDirection + 1 ) % NUM_CONTENT_DIRECTION ); + mCurrentContentDirection = static_cast((mCurrentContentDirection + 1) % NUM_CONTENT_DIRECTION); mFlexItemContainer.SetProperty(FlexContainer::Property::CONTENT_DIRECTION, mCurrentContentDirection); - SetTitle( "Content direction", CONTENT_DIRECTION[mCurrentContentDirection] ); + SetTitle("Content direction", CONTENT_DIRECTION[mCurrentContentDirection]); return true; } - bool OnJustifyContentButtonClicked( Toolkit::Button button ) + bool OnJustifyContentButtonClicked(Toolkit::Button button) { - mCurrentJustifyContent = static_cast( ( mCurrentJustifyContent + 1 ) % NUM_JUSTIFY_CONTENT ); + mCurrentJustifyContent = static_cast((mCurrentJustifyContent + 1) % NUM_JUSTIFY_CONTENT); mFlexItemContainer.SetProperty(FlexContainer::Property::JUSTIFY_CONTENT, mCurrentJustifyContent); - SetTitle( "Justify content", JUSTIFY_CONTENT[mCurrentJustifyContent] ); + SetTitle("Justify content", JUSTIFY_CONTENT[mCurrentJustifyContent]); return true; } - bool OnAlignItemsButtonClicked( Toolkit::Button button ) + bool OnAlignItemsButtonClicked(Toolkit::Button button) { - mCurrentAlignItems = static_cast( ( mCurrentAlignItems + 1 ) % ( NUM_ALIGN_ITEMS + 1 ) ); + mCurrentAlignItems = static_cast((mCurrentAlignItems + 1) % (NUM_ALIGN_ITEMS + 1)); mCurrentAlignItems = mCurrentAlignItems < FlexContainer::ALIGN_FLEX_START ? FlexContainer::ALIGN_FLEX_START : mCurrentAlignItems; // skip auto as it is invalid for alignItems property - mFlexItemContainer.SetProperty(FlexContainer::Property::ALIGN_ITEMS, mCurrentAlignItems ); - SetTitle( "Align Items", ALIGN_ITEMS[mCurrentAlignItems - 1] ); + mFlexItemContainer.SetProperty(FlexContainer::Property::ALIGN_ITEMS, mCurrentAlignItems); + SetTitle("Align Items", ALIGN_ITEMS[mCurrentAlignItems - 1]); return true; } - bool OnAlignContentButtonClicked( Toolkit::Button button ) + bool OnAlignContentButtonClicked(Toolkit::Button button) { - mCurrentAlignContent = static_cast( ( mCurrentAlignContent + 1 ) % (NUM_ALIGN_CONTENT + 1 ) ); + mCurrentAlignContent = static_cast((mCurrentAlignContent + 1) % (NUM_ALIGN_CONTENT + 1)); mCurrentAlignContent = mCurrentAlignContent < FlexContainer::ALIGN_FLEX_START ? FlexContainer::ALIGN_FLEX_START : mCurrentAlignContent; // skip auto as it is invalid for alignContent property mFlexItemContainer.SetProperty(FlexContainer::Property::ALIGN_CONTENT, mCurrentAlignContent); - SetTitle( "Align content", ALIGN_CONTENT[mCurrentAlignContent - 1] ); + SetTitle("Align content", ALIGN_CONTENT[mCurrentAlignContent - 1]); return true; } private: - /** * Sets/Updates the title of the View and the value of the recently updated * flexbox property. @@ -315,14 +306,14 @@ private: { if(!mTitleActor) { - mTitleActor = DemoHelper::CreateToolBarLabel( "" ); + mTitleActor = DemoHelper::CreateToolBarLabel(""); // Add title to the tool bar. - mToolBar.AddControl( mTitleActor, VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER ); + mToolBar.AddControl(mTitleActor, VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER); } // Update the title and property value - mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); - mFlexPropertyLabel.SetProperty( TextLabel::Property::TEXT, propertyValue ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, title); + mFlexPropertyLabel.SetProperty(TextLabel::Property::TEXT, propertyValue); } /** @@ -332,7 +323,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -340,23 +331,22 @@ private: } private: - Application& mApplication; Toolkit::Control mView; Toolkit::ToolBar mToolBar; - TextLabel mTitleActor; ///< The Toolbar's Title. + TextLabel mTitleActor; ///< The Toolbar's Title. FlexContainer mFlexContainer; FlexContainer mFlexItemContainer; - TextLabel mFlexPropertyLabel; + TextLabel mFlexPropertyLabel; - FlexContainer::FlexDirection mCurrentFlexDirection; - FlexContainer::WrapType mCurrentFlexWrap; + FlexContainer::FlexDirection mCurrentFlexDirection; + FlexContainer::WrapType mCurrentFlexWrap; FlexContainer::ContentDirection mCurrentContentDirection; - FlexContainer::Justification mCurrentJustifyContent; - FlexContainer::Alignment mCurrentAlignItems; - FlexContainer::Alignment mCurrentAlignContent; + FlexContainer::Justification mCurrentJustifyContent; + FlexContainer::Alignment mCurrentAlignItems; + FlexContainer::Alignment mCurrentAlignContent; Toolkit::PushButton mFlexDirectionButton; Toolkit::PushButton mFlexWrapButton; @@ -366,9 +356,9 @@ private: Toolkit::PushButton mAlignContentButton; }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); FlexContainerExample test(app); app.MainLoop(); return 0; diff --git a/examples/focus-integration/focus-integration.cpp b/examples/focus-integration/focus-integration.cpp index 6f9dad5..5c471cb 100644 --- a/examples/focus-integration/focus-integration.cpp +++ b/examples/focus-integration/focus-integration.cpp @@ -15,161 +15,158 @@ * */ -#include "shared/view.h" #include #include +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; namespace { - const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg"; -const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; -const char* const TOOLBAR_TITLE = "Focus Integration"; -const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); +const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; +const char* const TOOLBAR_TITLE = "Focus Integration"; +const Vector4 BACKGROUND_COLOUR(1.0f, 1.0f, 1.0f, 0.15f); // Layout sizes -const int MARGIN_SIZE = 10; -const int TOP_MARGIN = 85; -const std::string ITEMNAME[] = { "TextLabel", "TextField", "TextEditor", "PushButton", "RadioButton", "CheckBoxButton" }; +const int MARGIN_SIZE = 10; +const int TOP_MARGIN = 85; +const std::string ITEMNAME[] = {"TextLabel", "TextField", "TextEditor", "PushButton", "RadioButton", "CheckBoxButton"}; -} // namespace +} // namespace /** * @brief Shows how integrated DALi Focus works. */ -class FocusIntegrationExample: public ConnectionTracker +class FocusIntegrationExample : public ConnectionTracker { public: - - FocusIntegrationExample( Application& application ) - : mApplication( application ) + FocusIntegrationExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &FocusIntegrationExample::Create ); + mApplication.InitSignal().Connect(this, &FocusIntegrationExample::Create); } - void Create( Application& application ) + void Create(Application& application) { - mWindow = application.GetWindow(); + mWindow = application.GetWindow(); Vector2 windowSize = mWindow.GetSize(); - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - TOOLBAR_TITLE ); + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + TOOLBAR_TITLE); TableView contentTable = TableView::New(2, 1); contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); contentTable.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); - contentTable.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); - contentTable.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); + contentTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + contentTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); contentTable.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5f)); - contentTable.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true); + contentTable.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); - for( unsigned int i = 0; i < contentTable.GetRows(); ++i ) + for(unsigned int i = 0; i < contentTable.GetRows(); ++i) { - contentTable.SetFitHeight( i ); + contentTable.SetFitHeight(i); } - contentTable.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, TOP_MARGIN )); - mContentLayer.Add( contentTable ); + contentTable.SetProperty(Actor::Property::POSITION, Vector2(0.0f, TOP_MARGIN)); + mContentLayer.Add(contentTable); // Create label to display which control's KeyEvent callback is called mEventLabel = TextLabel::New("Controls don't get KeyEvent yet"); - mEventLabel.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width, windowSize.height*0.1f ) ); + mEventLabel.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width, windowSize.height * 0.1f)); mEventLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); - mEventLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mEventLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mEventLabel.SetBackgroundColor( Color::WHITE ); - contentTable.Add( mEventLabel ); + mEventLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mEventLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mEventLabel.SetBackgroundColor(Color::WHITE); + contentTable.Add(mEventLabel); - mContainer = TableView::New( 4, 3 ); - mContainer.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width, windowSize.height*0.4f ) ); + mContainer = TableView::New(4, 3); + mContainer.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width, windowSize.height * 0.4f)); mContainer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); - mContainer.SetBackgroundColor( BACKGROUND_COLOUR ); - mContainer.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); - mContainer.SetRelativeHeight( 0, 0.2f); - mContainer.SetRelativeHeight( 1, 0.3f); - mContainer.SetRelativeHeight( 2, 0.2f); - mContainer.SetRelativeHeight( 3, 0.3f); - mContainer.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true); - contentTable.Add( mContainer ); + mContainer.SetBackgroundColor(BACKGROUND_COLOUR); + mContainer.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); + mContainer.SetRelativeHeight(0, 0.2f); + mContainer.SetRelativeHeight(1, 0.3f); + mContainer.SetRelativeHeight(2, 0.2f); + mContainer.SetRelativeHeight(3, 0.3f); + mContainer.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + contentTable.Add(mContainer); // Make name label for each controls for(int i = 0; i < 6; i++) { - TextLabel itemLabel = TextLabel::New( ITEMNAME[i] ); - itemLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - itemLabel.SetBackgroundColor( BACKGROUND_COLOUR ); - itemLabel.SetProperty( TextLabel::Property::POINT_SIZE, 14.0f ); - itemLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - itemLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mContainer.AddChild( itemLabel, TableView::CellPosition( (i/3)*2, i%3 ) ); + TextLabel itemLabel = TextLabel::New(ITEMNAME[i]); + itemLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + itemLabel.SetBackgroundColor(BACKGROUND_COLOUR); + itemLabel.SetProperty(TextLabel::Property::POINT_SIZE, 14.0f); + itemLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + itemLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mContainer.AddChild(itemLabel, TableView::CellPosition((i / 3) * 2, i % 3)); } TextLabel textLabel = TextLabel::New("TextLabel"); - mContainer.AddChild( textLabel, TableView::CellPosition( 1, 0 ) ); + mContainer.AddChild(textLabel, TableView::CellPosition(1, 0)); TextField textField = TextField::New(); - textField.SetBackgroundColor( Color::WHITE ); - textField.SetProperty( TextField::Property::TEXT, "Text" ); - mContainer.AddChild( textField, TableView::CellPosition( 1, 1 ) ); + textField.SetBackgroundColor(Color::WHITE); + textField.SetProperty(TextField::Property::TEXT, "Text"); + mContainer.AddChild(textField, TableView::CellPosition(1, 1)); TextEditor textEditor = TextEditor::New(); - textEditor.SetBackgroundColor( Color::WHITE ); - textEditor.SetProperty( TextEditor::Property::TEXT, "Text\nText" ); - mContainer.AddChild( textEditor, TableView::CellPosition( 1, 2 ) ); + textEditor.SetBackgroundColor(Color::WHITE); + textEditor.SetProperty(TextEditor::Property::TEXT, "Text\nText"); + mContainer.AddChild(textEditor, TableView::CellPosition(1, 2)); PushButton pushButton = PushButton::New(); - mContainer.AddChild( pushButton, TableView::CellPosition( 3, 0 ) ); + mContainer.AddChild(pushButton, TableView::CellPosition(3, 0)); RadioButton radioButton = RadioButton::New(); - mContainer.AddChild( radioButton, TableView::CellPosition( 3, 1 ) ); + mContainer.AddChild(radioButton, TableView::CellPosition(3, 1)); CheckBoxButton checkBoxButton = CheckBoxButton::New(); - mContainer.AddChild( checkBoxButton, TableView::CellPosition( 3, 2 ) ); + mContainer.AddChild(checkBoxButton, TableView::CellPosition(3, 2)); // Set name and keyboard focusable for each controls - for(int i = 0; i<6; i++) + for(int i = 0; i < 6; i++) { - Control control = Control::DownCast( mContainer.GetChildAt( TableView::CellPosition( (i/3)*2+1, i%3 ) ) ); - control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true); - control.SetProperty( Dali::Actor::Property::NAME,ITEMNAME[i]); - control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - control.KeyEventSignal().Connect( this, &FocusIntegrationExample::OnControlKeyEvent ); + Control control = Control::DownCast(mContainer.GetChildAt(TableView::CellPosition((i / 3) * 2 + 1, i % 3))); + control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + control.SetProperty(Dali::Actor::Property::NAME, ITEMNAME[i]); + control.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + control.KeyEventSignal().Connect(this, &FocusIntegrationExample::OnControlKeyEvent); } - KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &FocusIntegrationExample::OnPreFocusChange ); + KeyboardFocusManager::Get().PreFocusChangeSignal().Connect(this, &FocusIntegrationExample::OnPreFocusChange); // Respond to key events - mWindow.KeyEventSignal().Connect( this, &FocusIntegrationExample::OnKeyEvent ); + mWindow.KeyEventSignal().Connect(this, &FocusIntegrationExample::OnKeyEvent); } // Callback for KeyboardFocusManager - Actor OnPreFocusChange( Actor current, Actor next, Control::KeyboardFocus::Direction direction ) + Actor OnPreFocusChange(Actor current, Actor next, Control::KeyboardFocus::Direction direction) { - if( !current && !next ) + if(!current && !next) { - next = mContainer.GetChildAt( TableView::CellPosition( 1, 0 ) ); + next = mContainer.GetChildAt(TableView::CellPosition(1, 0)); } return next; } // Callback for each controls. // Display current control name. - bool OnControlKeyEvent( Control control, const KeyEvent& event ) + bool OnControlKeyEvent(Control control, const KeyEvent& event) { - std::string controlName = control.GetProperty< std::string >( Dali::Actor::Property::NAME ); - mEventLabel.SetProperty( TextLabel::Property::TEXT, controlName+"'s KeyEvent works\n" ); + std::string controlName = control.GetProperty(Dali::Actor::Property::NAME); + mEventLabel.SetProperty(TextLabel::Property::TEXT, controlName + "'s KeyEvent works\n"); return false; } private: - /** * Main key event handler */ @@ -177,7 +174,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -185,22 +182,21 @@ private: } private: - - Application& mApplication; - Window mWindow; - TableView mContainer; - TextLabel mEventLabel; - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - Layer mContentLayer; ///< Content layer. + Application& mApplication; + Window mWindow; + TableView mContainer; + TextLabel mEventLabel; + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer. }; // -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - FocusIntegrationExample test( application ); + FocusIntegrationExample test(application); application.MainLoop(); diff --git a/examples/fpp-game/fpp-game-example.cpp b/examples/fpp-game/fpp-game-example.cpp index 989a3fa..4918032 100644 --- a/examples/fpp-game/fpp-game-example.cpp +++ b/examples/fpp-game/fpp-game-example.cpp @@ -15,10 +15,10 @@ * */ -#include "game-renderer.h" #include "game-model.h" -#include "game-texture.h" +#include "game-renderer.h" #include "game-scene.h" +#include "game-texture.h" #include "fpp-game-tutorial-controller.h" @@ -28,11 +28,9 @@ using namespace Dali; namespace { - const char* SCENE_URL = -{ - DEMO_GAME_DIR "/scene.json" -}; + { + DEMO_GAME_DIR "/scene.json"}; } /* This example creates 3D environment with first person camera control @@ -78,12 +76,11 @@ const char* SCENE_URL = class GameController : public ConnectionTracker { public: - - GameController( Application& application ) - : mApplication( application ) + GameController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &GameController::Create ); + mApplication.InitSignal().Connect(this, &GameController::Create); } ~GameController() @@ -91,24 +88,24 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window mWindow = application.GetWindow(); - mWindow.SetBackgroundColor( Color::BLACK ); + mWindow.SetBackgroundColor(Color::BLACK); // Use 3D layer - mWindow.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); + mWindow.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); // Load game scene - mScene.Load( mWindow, SCENE_URL ); + mScene.Load(mWindow, SCENE_URL); // Display tutorial - mTutorialController.DisplayTutorial( mWindow ); + mTutorialController.DisplayTutorial(mWindow); // Connect OnKeyEvent signal - mWindow.KeyEventSignal().Connect( this, &GameController::OnKeyEvent ); + mWindow.KeyEventSignal().Connect(this, &GameController::OnKeyEvent); } // Handle a quit key event @@ -116,7 +113,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -124,17 +121,16 @@ public: } private: - Application& mApplication; GameScene mScene; Window mWindow; FppGameTutorialController mTutorialController; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - GameController test( application ); + Application application = Application::New(&argc, &argv); + GameController test(application); application.MainLoop(); return 0; } diff --git a/examples/fpp-game/fpp-game-tutorial-controller.cpp b/examples/fpp-game/fpp-game-tutorial-controller.cpp index 28ae003..10572b6 100644 --- a/examples/fpp-game/fpp-game-tutorial-controller.cpp +++ b/examples/fpp-game/fpp-game-tutorial-controller.cpp @@ -17,76 +17,74 @@ #include "fpp-game-tutorial-controller.h" -#include -#include +#include +#include #include +#include +#include #include #include -#include -#include using namespace Dali; using namespace Dali::Toolkit; FppGameTutorialController::FppGameTutorialController() -: mLeftTutorialComplete( false ), - mRightTutorialComplete( false ) +: mLeftTutorialComplete(false), + mRightTutorialComplete(false) { - } FppGameTutorialController::~FppGameTutorialController() { - } -void FppGameTutorialController::OnTouch( const TouchEvent& touchEvent ) +void FppGameTutorialController::OnTouch(const TouchEvent& touchEvent) { - Vector2 size( mWindow.GetSize() ); + Vector2 size(mWindow.GetSize()); - bool isLandscape( size.x > size.y ); + bool isLandscape(size.x > size.y); - if( !isLandscape ) + if(!isLandscape) { - std::swap( size.x, size.y ); + std::swap(size.x, size.y); } - Vector2 sizeHalf( size * 0.5f ); + Vector2 sizeHalf(size * 0.5f); - for( size_t i = 0; i < touchEvent.GetPointCount(); ++i ) + for(size_t i = 0; i < touchEvent.GetPointCount(); ++i) { - Vector2 pos = touchEvent.GetScreenPosition( i ); - if( !isLandscape ) + Vector2 pos = touchEvent.GetScreenPosition(i); + if(!isLandscape) { - std::swap( pos.x, pos.y ); + std::swap(pos.x, pos.y); } // left label touched - if( touchEvent.GetState( i ) == PointState::STARTED ) + if(touchEvent.GetState(i) == PointState::STARTED) { - if( pos.x < sizeHalf.x && !mLeftTutorialComplete ) + if(pos.x < sizeHalf.x && !mLeftTutorialComplete) { mLeftTutorialComplete = true; - Animation animation = Animation::New( 1.0f ); - animation.AnimateTo( Property( mLeftLabel, Actor::Property::COLOR_ALPHA ), 0.0f ); + Animation animation = Animation::New(1.0f); + animation.AnimateTo(Property(mLeftLabel, Actor::Property::COLOR_ALPHA), 0.0f); // connect complete signal - if( mRightTutorialComplete ) + if(mRightTutorialComplete) { - animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialComplete ); + animation.FinishedSignal().Connect(this, &FppGameTutorialController::OnTutorialComplete); } animation.Play(); } // right label touched - else if( !mRightTutorialComplete ) + else if(!mRightTutorialComplete) { mRightTutorialComplete = true; - Animation animation = Animation::New( 1.0f ); - animation.AnimateTo( Property( mRightLabel, Actor::Property::COLOR_ALPHA ), 0.0f ); + Animation animation = Animation::New(1.0f); + animation.AnimateTo(Property(mRightLabel, Actor::Property::COLOR_ALPHA), 0.0f); // connect complete signal - if( mLeftTutorialComplete ) + if(mLeftTutorialComplete) { - animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialComplete ); + animation.FinishedSignal().Connect(this, &FppGameTutorialController::OnTutorialComplete); } animation.Play(); } @@ -94,85 +92,82 @@ void FppGameTutorialController::OnTouch( const TouchEvent& touchEvent ) } } -void FppGameTutorialController::DisplayTutorial( Dali::Window window ) +void FppGameTutorialController::DisplayTutorial(Dali::Window window) { mWindow = window; - Vector2 windowSize( mWindow.GetSize() ); - bool isLandscape( windowSize.x > windowSize.y ); - if( !isLandscape ) + Vector2 windowSize(mWindow.GetSize()); + bool isLandscape(windowSize.x > windowSize.y); + if(!isLandscape) { - std::swap( windowSize.x, windowSize.y ); + std::swap(windowSize.x, windowSize.y); } mUiRoot = Actor::New(); - mWindow.Add( mUiRoot ); + mWindow.Add(mUiRoot); // left tutorial text label mLeftLabel = Toolkit::TextLabel::New("Touch here to walk"); - mLeftLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLeftLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLeftLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mLeftLabel.SetProperty( Actor::Property::SIZE, Vector3( windowSize.x*0.5, windowSize.y, 1.0f ) ); - mLeftLabel.SetProperty( Toolkit::Control::Property::BACKGROUND, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR ) - .Add( ColorVisual::Property::MIX_COLOR, Vector4( 0.0, 0.0, 0.7, 0.2 ) ) ); - mLeftLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White. - mLeftLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mLeftLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + mLeftLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLeftLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLeftLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mLeftLabel.SetProperty(Actor::Property::SIZE, Vector3(windowSize.x * 0.5, windowSize.y, 1.0f)); + mLeftLabel.SetProperty(Toolkit::Control::Property::BACKGROUND, + Property::Map().Add(Toolkit::Visual::Property::TYPE, Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Vector4(0.0, 0.0, 0.7, 0.2))); + mLeftLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Vector4(1.0f, 1.0f, 1.0f, 1.0f)); // White. + mLeftLabel.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mLeftLabel.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); // right tutorial text label mRightLabel = Toolkit::TextLabel::New("Touch here to look around"); - mRightLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mRightLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mRightLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mRightLabel.SetProperty( Actor::Property::SIZE, Vector3( windowSize.x*0.5, windowSize.y, 1.0f ) ); - mRightLabel.SetProperty( Toolkit::Control::Property::BACKGROUND, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR ) - .Add( ColorVisual::Property::MIX_COLOR, Vector4( 0.5, 0.0, 0.0, 0.2 ) ) ); - mRightLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White. - mRightLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mRightLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + mRightLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mRightLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mRightLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mRightLabel.SetProperty(Actor::Property::SIZE, Vector3(windowSize.x * 0.5, windowSize.y, 1.0f)); + mRightLabel.SetProperty(Toolkit::Control::Property::BACKGROUND, + Property::Map().Add(Toolkit::Visual::Property::TYPE, Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Vector4(0.5, 0.0, 0.0, 0.2))); + mRightLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Vector4(1.0f, 1.0f, 1.0f, 1.0f)); // White. + mRightLabel.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mRightLabel.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); // create camera dedicated to be used with UI controls CameraActor uiCamera = CameraActor::New(); - mTutorialRenderTask = mWindow.GetRenderTaskList().CreateTask(); - mTutorialRenderTask.SetCameraActor( uiCamera ); - mTutorialRenderTask.SetClearEnabled( false ); - mTutorialRenderTask.SetSourceActor( mUiRoot ); - mTutorialRenderTask.SetExclusive( true ); + mTutorialRenderTask = mWindow.GetRenderTaskList().CreateTask(); + mTutorialRenderTask.SetCameraActor(uiCamera); + mTutorialRenderTask.SetClearEnabled(false); + mTutorialRenderTask.SetSourceActor(mUiRoot); + mTutorialRenderTask.SetExclusive(true); - if( !isLandscape ) + if(!isLandscape) { - uiCamera.RotateBy( Degree(90.0f), Vector3( 0.0f, 0.0f, 1.0f )); + uiCamera.RotateBy(Degree(90.0f), Vector3(0.0f, 0.0f, 1.0f)); } - mLeftLabel.SetProperty( Actor::Property::POSITION, Vector3( -windowSize.x*0.25f, 0.0, 0.0 ) ); - mRightLabel.SetProperty( Actor::Property::POSITION, Vector3( windowSize.x*0.25f, 0.0, 0.0 ) ); + mLeftLabel.SetProperty(Actor::Property::POSITION, Vector3(-windowSize.x * 0.25f, 0.0, 0.0)); + mRightLabel.SetProperty(Actor::Property::POSITION, Vector3(windowSize.x * 0.25f, 0.0, 0.0)); - mUiRoot.Add( mLeftLabel ); - mUiRoot.Add( mRightLabel ); - mWindow.Add( uiCamera ); + mUiRoot.Add(mLeftLabel); + mUiRoot.Add(mRightLabel); + mWindow.Add(uiCamera); - Animation animation = Animation::New( 1.0f ); - animation.AnimateTo( Property( mLeftLabel, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_OUT ); - animation.AnimateTo( Property( mRightLabel, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_OUT ); + Animation animation = Animation::New(1.0f); + animation.AnimateTo(Property(mLeftLabel, Actor::Property::COLOR_ALPHA), 1.0f, AlphaFunction::EASE_OUT); + animation.AnimateTo(Property(mRightLabel, Actor::Property::COLOR_ALPHA), 1.0f, AlphaFunction::EASE_OUT); - animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialAnimationFinished ); + animation.FinishedSignal().Connect(this, &FppGameTutorialController::OnTutorialAnimationFinished); animation.Play(); } -void FppGameTutorialController::OnTutorialAnimationFinished( Animation& animation ) +void FppGameTutorialController::OnTutorialAnimationFinished(Animation& animation) { // touch signal will wait for a single touch on each side of screen - mWindow.TouchedSignal().Connect( this, &FppGameTutorialController::OnTouch ); + mWindow.TouchedSignal().Connect(this, &FppGameTutorialController::OnTouch); } -void FppGameTutorialController::OnTutorialComplete( Animation& animation ) +void FppGameTutorialController::OnTutorialComplete(Animation& animation) { - mWindow.Remove( mUiRoot ); + mWindow.Remove(mUiRoot); mUiRoot.Reset(); - mWindow.GetRenderTaskList().RemoveTask( mTutorialRenderTask ); + mWindow.GetRenderTaskList().RemoveTask(mTutorialRenderTask); } - diff --git a/examples/fpp-game/fpp-game-tutorial-controller.h b/examples/fpp-game/fpp-game-tutorial-controller.h index cc09dae..dd594e6 100644 --- a/examples/fpp-game/fpp-game-tutorial-controller.h +++ b/examples/fpp-game/fpp-game-tutorial-controller.h @@ -18,16 +18,15 @@ * */ +#include #include +#include #include #include -#include -#include class FppGameTutorialController : public Dali::ConnectionTracker { public: - /** * Creates new instance of FppGameTutorialController */ @@ -42,35 +41,34 @@ public: * Displays UI with tutorial * @param[in] window The window to display the tutorial on */ - void DisplayTutorial( Dali::Window window ); + void DisplayTutorial(Dali::Window window); /** * Handles tutorial touch input * @param[in] touchEvent Incoming touch event in the UI space */ - void OnTouch( const Dali::TouchEvent& touchEvent ); + void OnTouch(const Dali::TouchEvent& touchEvent); /** * Handles tutorial animation finished signal * @param[in] animation Animation object */ - void OnTutorialAnimationFinished( Dali::Animation& animation ); + void OnTutorialAnimationFinished(Dali::Animation& animation); /** * Handles tutorial completion window * @param animation Animation object */ - void OnTutorialComplete( Dali::Animation& animation ); + void OnTutorialComplete(Dali::Animation& animation); private: - - Dali::RenderTask mTutorialRenderTask; /// RenderTask associated with rendering tutorial - Dali::Actor mUiRoot; /// The parent actor for tutorial UI - Dali::Toolkit::TextLabel mLeftLabel; /// Text label displaying left message - Dali::Toolkit::TextLabel mRightLabel; /// Text label displaying right message - bool mLeftTutorialComplete; /// Flag indicating the walk (left) tutorial action has been performed - bool mRightTutorialComplete; /// Flag indicating the look (right) tutorial action has been performed - Dali::Window mWindow; + Dali::RenderTask mTutorialRenderTask; /// RenderTask associated with rendering tutorial + Dali::Actor mUiRoot; /// The parent actor for tutorial UI + Dali::Toolkit::TextLabel mLeftLabel; /// Text label displaying left message + Dali::Toolkit::TextLabel mRightLabel; /// Text label displaying right message + bool mLeftTutorialComplete; /// Flag indicating the walk (left) tutorial action has been performed + bool mRightTutorialComplete; /// Flag indicating the look (right) tutorial action has been performed + Dali::Window mWindow; }; #endif // FPPGAMETUTORIAL_H diff --git a/examples/fpp-game/game-camera.cpp b/examples/fpp-game/game-camera.cpp index 0b7255b..ce05083 100644 --- a/examples/fpp-game/game-camera.cpp +++ b/examples/fpp-game/game-camera.cpp @@ -17,9 +17,9 @@ #include "game-camera.h" +#include #include #include -#include using namespace Dali; @@ -27,55 +27,55 @@ namespace { // Input sensitivity, the larger value, the more sensitive input // Default value has been chosen empirically -const float CAMERA_SENSITIVITY ( 90.0f ); +const float CAMERA_SENSITIVITY(90.0f); // Vertical angle limit of the camera -const float CAMERA_VERTICAL_LIMIT ( 80.0f ); +const float CAMERA_VERTICAL_LIMIT(80.0f); // Position where camera is instantiated by default -const Vector3 CAMERA_DEFAULT_POSITION ( 1.0f, -1.5f, -3.0f ); +const Vector3 CAMERA_DEFAULT_POSITION(1.0f, -1.5f, -3.0f); // Field-of-View in degrees -const float CAMERA_DEFAULT_FOV ( 60.0f ); +const float CAMERA_DEFAULT_FOV(60.0f); // Near plane -const float CAMERA_DEFAULT_NEAR ( 0.1f ); +const float CAMERA_DEFAULT_NEAR(0.1f); // Far plane -const float CAMERA_DEFAULT_FAR ( 100.0f ); +const float CAMERA_DEFAULT_FAR(100.0f); // Default forward vector -const Vector3 CAMERA_FORWARD ( 0.0f, 0.0f, 1.0f ); +const Vector3 CAMERA_FORWARD(0.0f, 0.0f, 1.0f); // Default up vector -const Vector3 CAMERA_UP ( Vector3::YAXIS ); -} +const Vector3 CAMERA_UP(Vector3::YAXIS); +} // namespace GameCamera::GameCamera() -: mFovY( CAMERA_DEFAULT_FOV ), - mNear( CAMERA_DEFAULT_NEAR ), - mFar( CAMERA_DEFAULT_FAR ), - mWalkingTouchId( -1 ), - mLookingTouchId( -1 ), - mPortraitMode( false ) +: mFovY(CAMERA_DEFAULT_FOV), + mNear(CAMERA_DEFAULT_NEAR), + mFar(CAMERA_DEFAULT_FAR), + mWalkingTouchId(-1), + mLookingTouchId(-1), + mPortraitMode(false) { } GameCamera::~GameCamera() { mTimer.Stop(); - mCameraActor.Remove( mInterceptorActor ); + mCameraActor.Remove(mInterceptorActor); } -void GameCamera::Initialise( CameraActor defaultCamera, float fovY, float near, float far, const Vector2& sceneSize ) +void GameCamera::Initialise(CameraActor defaultCamera, float fovY, float near, float far, const Vector2& sceneSize) { mCameraActor = defaultCamera; mFovY = fovY; mNear = near; - mFar = far; + mFar = far; - mSceneSize = sceneSize; + mSceneSize = sceneSize; mPortraitMode = mSceneSize.x < mSceneSize.y ? true : false; // Initialise default camera @@ -85,8 +85,8 @@ void GameCamera::Initialise( CameraActor defaultCamera, float fovY, float near, CreateInterceptorActor(); // Start timer - mTimer = Timer::New( 16 ); - mTimer.TickSignal().Connect( this, &GameCamera::OnTick ); + mTimer = Timer::New(16); + mTimer.TickSignal().Connect(this, &GameCamera::OnTick); mTimer.Start(); } @@ -94,52 +94,52 @@ bool GameCamera::OnTick() { // --------------------------------------------------------------------- // update rotation - Vector2 tmp( mScreenLookDelta ); + Vector2 tmp(mScreenLookDelta); mScreenLookDelta = Vector2::ZERO; - if( mPortraitMode ) + if(mPortraitMode) { - float yaw = ( (tmp.y / mSceneSize.y ) * CAMERA_SENSITIVITY ); - float pitch = ( (tmp.x / mSceneSize.x ) * CAMERA_SENSITIVITY ); + float yaw = ((tmp.y / mSceneSize.y) * CAMERA_SENSITIVITY); + float pitch = ((tmp.x / mSceneSize.x) * CAMERA_SENSITIVITY); mCameraYawPitch.y -= yaw; mCameraYawPitch.x -= pitch; - if( abs( mCameraYawPitch.y ) > CAMERA_VERTICAL_LIMIT ) + if(abs(mCameraYawPitch.y) > CAMERA_VERTICAL_LIMIT) { - mCameraYawPitch.y = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.y < 0) ? -1.0f : 1.0f ); + mCameraYawPitch.y = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.y < 0) ? -1.0f : 1.0f); } } else { - float yaw = ( (tmp.y / mSceneSize.x ) * CAMERA_SENSITIVITY ); - float pitch = ( (tmp.x / mSceneSize.y ) * CAMERA_SENSITIVITY ); + float yaw = ((tmp.y / mSceneSize.x) * CAMERA_SENSITIVITY); + float pitch = ((tmp.x / mSceneSize.y) * CAMERA_SENSITIVITY); mCameraYawPitch.x -= yaw; mCameraYawPitch.y -= pitch; - if( abs( mCameraYawPitch.x ) > CAMERA_VERTICAL_LIMIT ) + if(abs(mCameraYawPitch.x) > CAMERA_VERTICAL_LIMIT) { - mCameraYawPitch.x = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.x < 0) ? -1.0f : 1.0f ); + mCameraYawPitch.x = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.x < 0) ? -1.0f : 1.0f); } } Quaternion rotation; - Quaternion rotX( Degree( mCameraYawPitch.x), Vector3( 1.0f, 0.0f, 0.0f ) ); - Quaternion rotY( Degree( mCameraYawPitch.y), Vector3( 0.0f, 1.0f, 0.0f ) ); - if (mPortraitMode ) + Quaternion rotX(Degree(mCameraYawPitch.x), Vector3(1.0f, 0.0f, 0.0f)); + Quaternion rotY(Degree(mCameraYawPitch.y), Vector3(0.0f, 1.0f, 0.0f)); + if(mPortraitMode) { - Quaternion rotZ( Degree( mPortraitMode ? 90.0 : 0.0f), Vector3( 0.0f, 0.0f, 1.0f ) ); - rotation = ( rotZ * rotX * rotY ); + Quaternion rotZ(Degree(mPortraitMode ? 90.0 : 0.0f), Vector3(0.0f, 0.0f, 1.0f)); + rotation = (rotZ * rotX * rotY); } else { - rotation = ( rotY * rotX ); + rotation = (rotY * rotX); } - mCameraActor.SetProperty( Actor::Property::ORIENTATION, rotation ); + mCameraActor.SetProperty(Actor::Property::ORIENTATION, rotation); // --------------------------------------------------------------------- // update position - Vector3 position( mCameraPosition ); + Vector3 position(mCameraPosition); // Rotate CAMERA_FORWARD vector - Vector3 forwardVector = rotation.Rotate( CAMERA_FORWARD ); + Vector3 forwardVector = rotation.Rotate(CAMERA_FORWARD); // Cancel vertical movement forwardVector.y = 0.0f; @@ -148,15 +148,15 @@ bool GameCamera::OnTick() forwardVector.Normalize(); // compute sideways vector - Vector3 sidewaysVector = forwardVector.Cross( CAMERA_UP ); + Vector3 sidewaysVector = forwardVector.Cross(CAMERA_UP); sidewaysVector.Normalize(); - const float forwardSpeed( mScreenWalkDelta.y / mSceneSize.y ); - const float sidewaysSpeed( mScreenWalkDelta.x / mSceneSize.x ); + const float forwardSpeed(mScreenWalkDelta.y / mSceneSize.y); + const float sidewaysSpeed(mScreenWalkDelta.x / mSceneSize.x); // Adjust walking speed - if ( mPortraitMode ) + if(mPortraitMode) { position += forwardVector * (forwardSpeed * 0.5f); } @@ -167,7 +167,7 @@ bool GameCamera::OnTick() position += sidewaysVector * (sidewaysSpeed * 0.5f); - mCameraActor.SetProperty( Actor::Property::POSITION, position ); + mCameraActor.SetProperty(Actor::Property::POSITION, position); mCameraPosition = position; @@ -176,15 +176,15 @@ bool GameCamera::OnTick() void GameCamera::InitialiseDefaultCamera() { - mCameraActor.SetProperty( Dali::Actor::Property::NAME, "GameCamera" ); - mCameraActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mCameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCameraActor.SetFieldOfView( Radian( Degree( mFovY ) ) ); + mCameraActor.SetProperty(Dali::Actor::Property::NAME, "GameCamera"); + mCameraActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCameraActor.SetFieldOfView(Radian(Degree(mFovY))); // should be read from file - mCameraActor.SetNearClippingPlane( mNear ); - mCameraActor.SetFarClippingPlane( mFar ); - mCameraActor.SetProperty( Actor::Property::POSITION, CAMERA_DEFAULT_POSITION ); + mCameraActor.SetNearClippingPlane(mNear); + mCameraActor.SetFarClippingPlane(mFar); + mCameraActor.SetProperty(Actor::Property::POSITION, CAMERA_DEFAULT_POSITION); // Camera position is shadowed in order to avoid using.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) mCameraPosition = CAMERA_DEFAULT_POSITION; @@ -193,89 +193,88 @@ void GameCamera::InitialiseDefaultCamera() void GameCamera::CreateInterceptorActor() { mInterceptorActor = Actor::New(); - mInterceptorActor.SetProperty( Dali::Actor::Property::NAME, "GameInputInterceptor" ); - mInterceptorActor.SetProperty( Actor::Property::SIZE, Vector3( mSceneSize.x, mSceneSize.y, 1 ) ); - mInterceptorActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0, 0.0, 1.0 ) ); - mInterceptorActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mInterceptorActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCameraActor.Add( mInterceptorActor ); + mInterceptorActor.SetProperty(Dali::Actor::Property::NAME, "GameInputInterceptor"); + mInterceptorActor.SetProperty(Actor::Property::SIZE, Vector3(mSceneSize.x, mSceneSize.y, 1)); + mInterceptorActor.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 1.0)); + mInterceptorActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mInterceptorActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCameraActor.Add(mInterceptorActor); // Connect TouchedSignal to interceptor actor - mInterceptorActor.TouchedSignal().Connect( this, &GameCamera::OnTouch ); + mInterceptorActor.TouchedSignal().Connect(this, &GameCamera::OnTouch); } -bool GameCamera::OnTouch( Actor actor, const TouchEvent& touch ) +bool GameCamera::OnTouch(Actor actor, const TouchEvent& touch) { - for( int i = 0; i < (int)touch.GetPointCount() && i < 3; ++i ) + for(int i = 0; i < (int)touch.GetPointCount() && i < 3; ++i) { - int id = touch.GetDeviceId( i ); - Vector2 tmp( touch.GetScreenPosition( i ) ); + int id = touch.GetDeviceId(i); + Vector2 tmp(touch.GetScreenPosition(i)); Vector2 position; - float halfWindowSize; - if( mPortraitMode ) + float halfWindowSize; + if(mPortraitMode) { - position.x = tmp.y; - position.y = tmp.x; + position.x = tmp.y; + position.y = tmp.x; halfWindowSize = mSceneSize.y / 2; } else { - position.x = tmp.x; - position.y = tmp.y; + position.x = tmp.x; + position.y = tmp.y; halfWindowSize = mSceneSize.x / 2; } // touch started - if( touch.GetState( i ) == PointState::STARTED ) + if(touch.GetState(i) == PointState::STARTED) { // start looking - if( position.x > halfWindowSize && mLookingTouchId < 0 ) + if(position.x > halfWindowSize && mLookingTouchId < 0) { - mLookingTouchId = id; + mLookingTouchId = id; mOldTouchLookPosition = position; } // start walking - else if( position.x < halfWindowSize && mWalkingTouchId < 0 ) + else if(position.x < halfWindowSize && mWalkingTouchId < 0) { - mWalkingTouchId = id; + mWalkingTouchId = id; mOldTouchWalkPosition = position; - mScreenWalkDelta = Vector2::ZERO; + mScreenWalkDelta = Vector2::ZERO; } } - else if( touch.GetState( i ) == PointState::FINISHED || - touch.GetState( i ) == PointState::LEAVE || - touch.GetState( i ) == PointState::INTERRUPTED - ) + else if(touch.GetState(i) == PointState::FINISHED || + touch.GetState(i) == PointState::LEAVE || + touch.GetState(i) == PointState::INTERRUPTED) { // terminate look - if( mLookingTouchId == id ) + if(mLookingTouchId == id) { - mScreenLookDelta = Vector2::ZERO; + mScreenLookDelta = Vector2::ZERO; mOldTouchLookPosition = Vector2::ZERO; - mLookingTouchId = -1; + mLookingTouchId = -1; } // terminate walking - else if( mWalkingTouchId == id ) + else if(mWalkingTouchId == id) { - mScreenWalkDelta = Vector2::ZERO; + mScreenWalkDelta = Vector2::ZERO; mOldTouchWalkPosition = Vector2::ZERO; - mWalkingTouchId = -1; + mWalkingTouchId = -1; } } else // on motion { // update looking - if( mLookingTouchId == id ) + if(mLookingTouchId == id) { - mScreenLookDelta.x += ( position.x - mOldTouchLookPosition.x ); - mScreenLookDelta.y += ( position.y - mOldTouchLookPosition.y ); + mScreenLookDelta.x += (position.x - mOldTouchLookPosition.x); + mScreenLookDelta.y += (position.y - mOldTouchLookPosition.y); mOldTouchLookPosition = position; } // update walking - else if ( mWalkingTouchId == id ) + else if(mWalkingTouchId == id) { - mScreenWalkDelta.x += ( position.x - mOldTouchWalkPosition.x ); - mScreenWalkDelta.y += ( position.y - mOldTouchWalkPosition.y ); + mScreenWalkDelta.x += (position.x - mOldTouchWalkPosition.x); + mScreenWalkDelta.y += (position.y - mOldTouchWalkPosition.y); mOldTouchWalkPosition = position; } } diff --git a/examples/fpp-game/game-camera.h b/examples/fpp-game/game-camera.h index 879af85..fd908a3 100644 --- a/examples/fpp-game/game-camera.h +++ b/examples/fpp-game/game-camera.h @@ -41,7 +41,6 @@ class GameCamera : public Dali::ConnectionTracker { public: - /** * Creates an instance of GameCamera */ @@ -60,10 +59,9 @@ public: * @param[in] far Far Plane * @param[in] sceneSize The size of the scene this is looking at */ - void Initialise( Dali::CameraActor defaultCamera, float fov, float near, float far, const Dali::Vector2& sceneSize ); + void Initialise(Dali::CameraActor defaultCamera, float fov, float near, float far, const Dali::Vector2& sceneSize); private: - /** * Sets up a perspective camera using Dali default camera */ @@ -81,7 +79,7 @@ private: * @param[in] actor Actor receiving signal * @param[in] touch Touch data */ - bool OnTouch( Dali::Actor actor, const Dali::TouchEvent& touch ); + bool OnTouch(Dali::Actor actor, const Dali::TouchEvent& touch); /** * Handles camera tick() update @@ -90,14 +88,13 @@ private: bool OnTick(); private: - - Dali::CameraActor mCameraActor; /// Camera actor - Dali::Actor mInterceptorActor; /// Actor intercepting user input + Dali::CameraActor mCameraActor; /// Camera actor + Dali::Actor mInterceptorActor; /// Actor intercepting user input Dali::Timer mTimer; /// Per-frame timer - Dali::Vector2 mScreenLookDelta; /// Look delta vector in screen space - Dali::Vector2 mScreenWalkDelta; /// Walk delta vector in screen space + Dali::Vector2 mScreenLookDelta; /// Look delta vector in screen space + Dali::Vector2 mScreenWalkDelta; /// Walk delta vector in screen space Dali::Vector2 mOldTouchLookPosition; /// Previous look vector in screen space Dali::Vector2 mOldTouchWalkPosition; /// Previuus walk vector in screen space @@ -105,13 +102,13 @@ private: float mFovY; /// Camera field-of-view float mNear; /// Near plane - float mFar; /// Far plane + float mFar; /// Far plane int mWalkingTouchId; /// Touch device id bound to the walking action int mLookingTouchId; /// Touch device id bound to the looking action Dali::Vector3 mCameraPosition; /// Current camera position ( shadowing the actor position ) - Dali::Vector2 mSceneSize; /// The size of the scene we are looking at + Dali::Vector2 mSceneSize; /// The size of the scene we are looking at bool mPortraitMode; /// flag if window is in portrait mode ( physically window width < height ) }; diff --git a/examples/fpp-game/game-container.h b/examples/fpp-game/game-container.h index d7cc40b..cdc99ee 100644 --- a/examples/fpp-game/game-container.h +++ b/examples/fpp-game/game-container.h @@ -2,7 +2,7 @@ #define GAME_CONTAINER_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ #include - /** * GameContainer is a vector which owns heap-allocated objects. * Unlike vector this will call delete on the stored pointers during destruction. @@ -34,12 +33,12 @@ * * @endcode */ -template< class T > class GameContainer : public Dali::Vector< T > +template +class GameContainer : public Dali::Vector { public: - - typedef typename Dali::Vector< T >::Iterator Iterator; - typedef typename Dali::Vector< T >::ConstIterator ConstIterator; + typedef typename Dali::Vector::Iterator Iterator; + typedef typename Dali::Vector::ConstIterator ConstIterator; /** * Create a owner container. @@ -62,21 +61,20 @@ public: */ void Clear() { - ConstIterator end = Dali::Vector< T >::End(); - for( Iterator iter = Dali::Vector< T >::Begin(); iter != end; ++iter ) + ConstIterator end = Dali::Vector::End(); + for(Iterator iter = Dali::Vector::Begin(); iter != end; ++iter) { - delete (*iter); + delete(*iter); } - Dali::Vector< T >::Clear(); + Dali::Vector::Clear(); } private: - // Undefined copy constructor. - GameContainer( const GameContainer& ); + GameContainer(const GameContainer&); // Undefined assignment operator. - GameContainer& operator=( const GameContainer& ); + GameContainer& operator=(const GameContainer&); }; #endif // GAMECACHE_H diff --git a/examples/fpp-game/game-entity.cpp b/examples/fpp-game/game-entity.cpp index 7a03759..f5986f6 100644 --- a/examples/fpp-game/game-entity.cpp +++ b/examples/fpp-game/game-entity.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ #include "game-entity.h" #include "game-renderer.h" -GameEntity::GameEntity( const char* name ) +GameEntity::GameEntity(const char* name) { mActor = Dali::Actor::New(); - mActor.SetProperty( Dali::Actor::Property::NAME, name ); + mActor.SetProperty(Dali::Actor::Property::NAME, name); } GameEntity::~GameEntity() @@ -30,18 +30,18 @@ GameEntity::~GameEntity() void GameEntity::UpdateRenderer() { - if( mActor.GetRendererCount() ) + if(mActor.GetRendererCount()) { - Dali::Renderer currentRenderer = mActor.GetRendererAt( 0 ); - if( currentRenderer == mGameRenderer.GetRenderer() ) + Dali::Renderer currentRenderer = mActor.GetRendererAt(0); + if(currentRenderer == mGameRenderer.GetRenderer()) { return; } - mActor.RemoveRenderer( currentRenderer ); + mActor.RemoveRenderer(currentRenderer); } - if( mGameRenderer.GetRenderer() ) + if(mGameRenderer.GetRenderer()) { - mActor.AddRenderer( mGameRenderer.GetRenderer() ); + mActor.AddRenderer(mGameRenderer.GetRenderer()); } } @@ -55,22 +55,22 @@ Dali::Actor& GameEntity::GetActor() return mActor; } -void GameEntity::SetLocation( const Dali::Vector3& loc ) +void GameEntity::SetLocation(const Dali::Vector3& loc) { - mActor.SetProperty( Dali::Actor::Property::POSITION, loc ); + mActor.SetProperty(Dali::Actor::Property::POSITION, loc); } -void GameEntity::SetRotation( const Dali::Quaternion& rot ) +void GameEntity::SetRotation(const Dali::Quaternion& rot) { - mActor.SetProperty( Dali::Actor::Property::ORIENTATION, rot ); + mActor.SetProperty(Dali::Actor::Property::ORIENTATION, rot); } -void GameEntity::SetScale( const Dali::Vector3& scale ) +void GameEntity::SetScale(const Dali::Vector3& scale) { - mActor.SetProperty( Dali::Actor::Property::SCALE, scale ); + mActor.SetProperty(Dali::Actor::Property::SCALE, scale); } -void GameEntity::SetSize( const Dali::Vector3& size ) +void GameEntity::SetSize(const Dali::Vector3& size) { - mActor.SetProperty( Dali::Actor::Property::SIZE, size ); + mActor.SetProperty(Dali::Actor::Property::SIZE, size); } diff --git a/examples/fpp-game/game-entity.h b/examples/fpp-game/game-entity.h index 3601bdf..b81bb6b 100644 --- a/examples/fpp-game/game-entity.h +++ b/examples/fpp-game/game-entity.h @@ -2,7 +2,7 @@ #define GAME_ENTITY_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,12 +31,11 @@ class GameEntity { public: - /** * Creates an instance of GameEntity with given name * @param[in] name Name of created entity */ - GameEntity( const char* name ); + GameEntity(const char* name); /** * Destroys an instance of GameEntity @@ -58,25 +57,25 @@ public: * Sets location of entity * @param[in] location Local position of entity */ - void SetLocation( const Dali::Vector3& location ); + void SetLocation(const Dali::Vector3& location); /** * Sets rotation of entity * @param[in] rotation Local rotation of entity */ - void SetRotation( const Dali::Quaternion& rotation ); + void SetRotation(const Dali::Quaternion& rotation); /** * Sets scale of entity * @param[in] scale Local scale of entity */ - void SetScale( const Dali::Vector3& scale ); + void SetScale(const Dali::Vector3& scale); /** * Sets size of entity * @param[in] size Bounding box of entity */ - void SetSize( const Dali::Vector3& size ); + void SetSize(const Dali::Vector3& size); /** * Updates Dali::Renderer in case if anything changed ( geometry, texture, etc. ) @@ -84,9 +83,8 @@ public: void UpdateRenderer(); private: - - Dali::Actor mActor; - GameRenderer mGameRenderer; + Dali::Actor mActor; + GameRenderer mGameRenderer; }; #endif diff --git a/examples/fpp-game/game-model.cpp b/examples/fpp-game/game-model.cpp index 24bfb1c..95fee2d 100644 --- a/examples/fpp-game/game-model.cpp +++ b/examples/fpp-game/game-model.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,41 +23,37 @@ using namespace GameUtils; namespace { // 'MODV' tag stored in the big-endian (network) order -const uint32_t MODV_TAG( 0x4D4F4456 ); -} +const uint32_t MODV_TAG(0x4D4F4456); +} // namespace -GameModel::GameModel( const char *filename ) - : mUniqueId( false ), - mIsReady( false ) +GameModel::GameModel(const char* filename) +: mUniqueId(false), + mIsReady(false) { ByteArray bytes; - if( !LoadFile( filename, bytes ) ) + if(!LoadFile(filename, bytes)) { return; } - mHeader = *(reinterpret_cast( bytes.data() )); + mHeader = *(reinterpret_cast(bytes.data())); // expect big-endian - if( MODV_TAG != mHeader.tag ) + if(MODV_TAG != mHeader.tag) { // jump to little-endian variant - mHeader = *(reinterpret_cast( bytes.data() + bytes.size()/2 )); + mHeader = *(reinterpret_cast(bytes.data() + bytes.size() / 2)); } - mVertexBuffer = Dali::VertexBuffer::New( Dali::Property::Map(). - Add( "aPosition", Dali::Property::VECTOR3 ). - Add( "aNormal", Dali::Property::VECTOR3 ). - Add( "aTexCoord", Dali::Property::VECTOR2 ) - ); + mVertexBuffer = Dali::VertexBuffer::New(Dali::Property::Map().Add("aPosition", Dali::Property::VECTOR3).Add("aNormal", Dali::Property::VECTOR3).Add("aTexCoord", Dali::Property::VECTOR2)); - mVertexBuffer.SetData( bytes.data() + mHeader.dataBeginOffset, mHeader.vertexBufferSize/mHeader.vertexStride ); + mVertexBuffer.SetData(bytes.data() + mHeader.dataBeginOffset, mHeader.vertexBufferSize / mHeader.vertexStride); mGeometry = Dali::Geometry::New(); - mGeometry.AddVertexBuffer( mVertexBuffer ); - mGeometry.SetType( Dali::Geometry::TRIANGLES ); + mGeometry.AddVertexBuffer(mVertexBuffer); + mGeometry.SetType(Dali::Geometry::TRIANGLES); - mUniqueId = HashString( filename ); + mUniqueId = HashString(filename); mIsReady = true; } diff --git a/examples/fpp-game/game-model.h b/examples/fpp-game/game-model.h index af72750..a73e6e2 100644 --- a/examples/fpp-game/game-model.h +++ b/examples/fpp-game/game-model.h @@ -2,7 +2,7 @@ #define GAME_MODEL_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,16 +29,16 @@ */ struct ModelHeader { - uint32_t tag; /// 'MODV' tag - uint32_t version; /// File version - uint32_t vertexBufferSize; /// total size of the vertex buffer to allocate - uint32_t attributeCount; /// number of stored attributes - uint32_t attributeFormat[16]; /// format encoded as ((type << 16)|(count)); 'type' represents primitive type, 'count' represents number of components ( 1-4 ) - uint32_t attributeOffset[16]; /// attribute offsets - uint32_t attributeSize[16]; /// attribute size in bytes - uint32_t vertexStride; /// vertex stride - uint32_t reserved; /// reserved, may point at additional structure - uint32_t dataBeginOffset; /// start of actual vertex data + uint32_t tag; /// 'MODV' tag + uint32_t version; /// File version + uint32_t vertexBufferSize; /// total size of the vertex buffer to allocate + uint32_t attributeCount; /// number of stored attributes + uint32_t attributeFormat[16]; /// format encoded as ((type << 16)|(count)); 'type' represents primitive type, 'count' represents number of components ( 1-4 ) + uint32_t attributeOffset[16]; /// attribute offsets + uint32_t attributeSize[16]; /// attribute size in bytes + uint32_t vertexStride; /// vertex stride + uint32_t reserved; /// reserved, may point at additional structure + uint32_t dataBeginOffset; /// start of actual vertex data }; /** @@ -52,12 +52,11 @@ struct ModelHeader class GameModel { public: - /** * Creates an instance of GameModel and loads the '.mod' file * @param[in] filename Name of file to load */ - GameModel( const char* filename ); + GameModel(const char* filename); /** * Destroys an instance of GameModel @@ -83,14 +82,13 @@ public: uint32_t GetUniqueId(); private: + Dali::Geometry mGeometry; + Dali::VertexBuffer mVertexBuffer; - Dali::Geometry mGeometry; - Dali::VertexBuffer mVertexBuffer; - - ModelHeader mHeader; + ModelHeader mHeader; - uint32_t mUniqueId; - bool mIsReady; + uint32_t mUniqueId; + bool mIsReady; }; #endif diff --git a/examples/fpp-game/game-renderer.cpp b/examples/fpp-game/game-renderer.cpp index b578539..7e54d01 100644 --- a/examples/fpp-game/game-renderer.cpp +++ b/examples/fpp-game/game-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,15 @@ * */ +#include "game-renderer.h" #include "game-model.h" #include "game-texture.h" -#include "game-renderer.h" #include namespace { +// clang-format off const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute highp vec3 aPosition;\n @@ -46,12 +47,13 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(1.2, 1.2, 1.2, 1.0);\n }\n ); +// clang-format on -} +} // namespace GameRenderer::GameRenderer() - : mModel( NULL ), - mTexture( NULL ) +: mModel(NULL), + mTexture(NULL) { } @@ -59,13 +61,13 @@ GameRenderer::~GameRenderer() { } -void GameRenderer::SetModel( GameModel* model ) +void GameRenderer::SetModel(GameModel* model) { mModel = model; Setup(); } -void GameRenderer::SetMainTexture( GameTexture* texture ) +void GameRenderer::SetMainTexture(GameTexture* texture) { mTexture = texture; Setup(); @@ -73,32 +75,32 @@ void GameRenderer::SetMainTexture( GameTexture* texture ) void GameRenderer::Setup() { - if( !mRenderer && mModel ) + if(!mRenderer && mModel) { - Dali::Shader shader = Dali::Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); - mRenderer = Dali::Renderer::New( mModel->GetGeometry(), shader ); - mRenderer.SetProperty( Dali::Renderer::Property::DEPTH_WRITE_MODE, Dali::DepthWriteMode::ON ); - mRenderer.SetProperty( Dali::Renderer::Property::DEPTH_FUNCTION, Dali::DepthFunction::LESS_EQUAL ); - mRenderer.SetProperty( Dali::Renderer::Property::DEPTH_TEST_MODE, Dali::DepthTestMode::ON ); + Dali::Shader shader = Dali::Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); + mRenderer = Dali::Renderer::New(mModel->GetGeometry(), shader); + mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_WRITE_MODE, Dali::DepthWriteMode::ON); + mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_FUNCTION, Dali::DepthFunction::LESS_EQUAL); + mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_TEST_MODE, Dali::DepthTestMode::ON); } Dali::TextureSet textureSet; - Dali::Geometry geometry; + Dali::Geometry geometry; - if( mModel ) + if(mModel) { geometry = mModel->GetGeometry(); } - if( mTexture && mTexture->GetTextureSet() ) + if(mTexture && mTexture->GetTextureSet()) { textureSet = mTexture->GetTextureSet(); } - if( textureSet && geometry ) + if(textureSet && geometry) { - mRenderer.SetGeometry( geometry ); - mRenderer.SetTextures( textureSet ); + mRenderer.SetGeometry(geometry); + mRenderer.SetTextures(textureSet); } } @@ -106,6 +108,3 @@ Dali::Renderer& GameRenderer::GetRenderer() { return mRenderer; } - - - diff --git a/examples/fpp-game/game-renderer.h b/examples/fpp-game/game-renderer.h index de1222b..926b25d 100644 --- a/examples/fpp-game/game-renderer.h +++ b/examples/fpp-game/game-renderer.h @@ -2,7 +2,7 @@ #define GAME_RENDERER_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,6 @@ class GameTexture; class GameRenderer { public: - /** * Creates an instance of the GameRenderer */ @@ -47,14 +46,14 @@ public: * Resets the Dali::Renderer or creates new one on first time setup * @param[in] model Pointer to the GameModel object */ - void SetModel( GameModel* model ); + void SetModel(GameModel* model); /** * Sets main texture on the renderer * Resets the Dali::Renderer or creates new one on first time setup * @param[in] texture Pointer to the GameTexture object */ - void SetMainTexture( GameTexture* texture ); + void SetMainTexture(GameTexture* texture); /** * Retrieves DALi renderer object @@ -62,17 +61,15 @@ public: Dali::Renderer& GetRenderer(); private: - /** * Initialises rendering data */ void Setup(); private: - - Dali::Renderer mRenderer; - GameModel* mModel; - GameTexture* mTexture; + Dali::Renderer mRenderer; + GameModel* mModel; + GameTexture* mTexture; }; #endif diff --git a/examples/fpp-game/game-scene.cpp b/examples/fpp-game/game-scene.cpp index 1c322ee..538943d 100644 --- a/examples/fpp-game/game-scene.cpp +++ b/examples/fpp-game/game-scene.cpp @@ -15,15 +15,15 @@ * */ -#include #include +#include -#include "game-scene.h" -#include "game-model.h" -#include "game-texture.h" +#include "game-camera.h" #include "game-entity.h" +#include "game-model.h" #include "game-renderer.h" -#include "game-camera.h" +#include "game-scene.h" +#include "game-texture.h" #include "third-party/picojson.h" @@ -44,131 +44,127 @@ GameScene::~GameScene() { } -bool GameScene::Load(Window window, const char *filename) +bool GameScene::Load(Window window, const char* filename) { ByteArray bytes; - if( !LoadFile( filename, bytes ) ) + if(!LoadFile(filename, bytes)) { return false; } // add EOL - bytes.push_back( '\0'); + bytes.push_back('\0'); picojson::value root; - picojson::parse( root, bytes.data() ); + picojson::parse(root, bytes.data()); - bool failed( false ); + bool failed(false); - if( root.is() ) + if(root.is()) { object rootObject = root.get(); - for( object::iterator it = rootObject.begin(); it != rootObject.end(); ++it ) + for(object::iterator it = rootObject.begin(); it != rootObject.end(); ++it) { - std::string entityName( (*it).first ); + std::string entityName((*it).first); - GameEntity* entity = new GameEntity( entityName.c_str() ); - mEntities.PushBack( entity ); + GameEntity* entity = new GameEntity(entityName.c_str()); + mEntities.PushBack(entity); - value& val( (*it).second ); - value& vLocation = val.get( "location" ); - value& vRotation = val.get( "rotation" ); - value& vScale = val.get( "scale" ); - value& vSize = val.get( "size" ); - value& vModel = val.get( "model" ); - value& vTexture = val.get( "texture" ); + value& val((*it).second); + value& vLocation = val.get("location"); + value& vRotation = val.get("rotation"); + value& vScale = val.get("scale"); + value& vSize = val.get("size"); + value& vModel = val.get("model"); + value& vTexture = val.get("texture"); - if( !vLocation.is() ) + if(!vLocation.is()) { array& location = vLocation.get(); - entity->SetLocation( Vector3( - location.at(0).get(), - location.at(1).get(), - location.at(2).get() - )); + entity->SetLocation(Vector3( + location.at(0).get(), + location.at(1).get(), + location.at(2).get())); } - if( !vRotation.is() ) + if(!vRotation.is()) { array& rotation = vRotation.get(); - entity->SetRotation( Quaternion( Vector4( - -rotation.at(0).get(), - rotation.at(1).get(), - -rotation.at(2).get(), - rotation.at(3).get() - )) ); + entity->SetRotation(Quaternion(Vector4( + -rotation.at(0).get(), + rotation.at(1).get(), + -rotation.at(2).get(), + rotation.at(3).get()))); } - if( !vScale.is() ) + if(!vScale.is()) { array& scale = vScale.get(); - entity->SetScale( Vector3( - scale.at(0).get(), - scale.at(1).get(), - scale.at(2).get() - )); + entity->SetScale(Vector3( + scale.at(0).get(), + scale.at(1).get(), + scale.at(2).get())); } - if( !vSize.is() ) + if(!vSize.is()) { array& size = vSize.get(); - entity->SetSize( Vector3( - size.at(0).get(), - size.at(1).get(), - size.at(2).get() - )); + entity->SetSize(Vector3( + size.at(0).get(), + size.at(1).get(), + size.at(2).get())); } - GameModel* model( NULL ); - GameTexture* texture( NULL ); + GameModel* model(NULL); + GameTexture* texture(NULL); - if( !vModel.is() ) + if(!vModel.is()) { std::string& strModel = vModel.get(); - model = GetResource( strModel.c_str(), mModelCache ); + model = GetResource(strModel.c_str(), mModelCache); } - if( !vTexture.is() ) + if(!vTexture.is()) { std::string& strTexture = vTexture.get(); - texture = GetResource( strTexture.c_str(), mTextureCache ); + texture = GetResource(strTexture.c_str(), mTextureCache); } - if( !model || !texture ) + if(!model || !texture) { failed = true; break; } - entity->GetGameRenderer().SetModel( model ); - entity->GetGameRenderer().SetMainTexture( texture ); + entity->GetGameRenderer().SetModel(model); + entity->GetGameRenderer().SetMainTexture(texture); } } - if( failed ) + if(failed) { return false; } // add all to the window mRootActor = Actor::New(); - mRootActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mRootActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - window.GetRootLayer().Add( mRootActor ); - mRootActor.SetProperty( Actor::Property::SCALE, Vector3( -1.0, 1.0, 1.0 ) ); - mRootActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0, 0.0, 0.0 ) ); - mRootActor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( 90 ), Vector3( 1.0, 0.0, 0.0 ) ) ); - for( size_t i = 0; i < mEntities.Size(); ++i ) + mRootActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mRootActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + window.GetRootLayer().Add(mRootActor); + mRootActor.SetProperty(Actor::Property::SCALE, Vector3(-1.0, 1.0, 1.0)); + mRootActor.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 0.0)); + mRootActor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Degree(90), Vector3(1.0, 0.0, 0.0))); + for(size_t i = 0; i < mEntities.Size(); ++i) { - Actor actor( mEntities[i]->GetActor() ); - actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mRootActor.Add( actor ); + Actor actor(mEntities[i]->GetActor()); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mRootActor.Add(actor); mEntities[i]->UpdateRenderer(); } // update camera - mCamera.Initialise( window.GetRenderTaskList().GetTask(0).GetCameraActor(), 60.0f, 0.1f, 100.0f, window.GetSize() ); + mCamera.Initialise(window.GetRenderTaskList().GetTask(0).GetCameraActor(), 60.0f, 0.1f, 100.0f, window.GetSize()); return true; } diff --git a/examples/fpp-game/game-scene.h b/examples/fpp-game/game-scene.h index a726c2f..87264d7 100644 --- a/examples/fpp-game/game-scene.h +++ b/examples/fpp-game/game-scene.h @@ -18,13 +18,13 @@ * */ -#include -#include #include +#include +#include +#include "game-camera.h" #include "game-container.h" #include "game-utils.h" -#include "game-camera.h" #include #include @@ -37,14 +37,13 @@ class GameModel; /** * Container based types owning heap allocated data of specifed types */ -typedef GameContainer< GameEntity* > EntityArray; -typedef GameContainer< GameTexture* > TextureArray; -typedef GameContainer< GameModel* > ModelArray; +typedef GameContainer EntityArray; +typedef GameContainer TextureArray; +typedef GameContainer ModelArray; class GameScene { public: - /** * Creates an instance of the GameScene */ @@ -62,7 +61,7 @@ public: * @param[in] filename Path to the scene file * @return true if suceess */ - bool Load( Dali::Window window, const char* filename ); + bool Load(Dali::Window window, const char* filename); /** * Loads resource ( model or texture ) or gets if from cache if already loaded @@ -70,8 +69,8 @@ public: * @param[in] cache Reference to the cache array to be used * @return Pointer to the resource or NULL otherwise */ - template - T* GetResource( const char* filename, GameContainer& cache ); + template + T* GetResource(const char* filename, GameContainer& cache); /** * Returns scene root actor @@ -80,46 +79,43 @@ public: Dali::Actor& GetRootActor(); private: - - EntityArray mEntities; - GameCamera mCamera; + EntityArray mEntities; + GameCamera mCamera; // internal scene cache - ModelArray mModelCache; - TextureArray mTextureCache; + ModelArray mModelCache; + TextureArray mTextureCache; - Dali::Actor mRootActor; + Dali::Actor mRootActor; }; - template -T* GameScene::GetResource( const char* filename, GameContainer& cache ) +T* GameScene::GetResource(const char* filename, GameContainer& cache) { - std::string path( DEMO_GAME_DIR ); + std::string path(DEMO_GAME_DIR); path += "/"; path += filename; - uint32_t hash( GameUtils::HashString( path.c_str() ) ); + uint32_t hash(GameUtils::HashString(path.c_str())); - for( typename GameContainer::Iterator iter = cache.Begin(); iter != cache.End(); ++iter ) + for(typename GameContainer::Iterator iter = cache.Begin(); iter != cache.End(); ++iter) { - if( (*iter)->GetUniqueId() == hash ) + if((*iter)->GetUniqueId() == hash) { return (*iter); } } // load resource - T* resource = new T( path.c_str() ); - if( !resource->IsReady() ) + T* resource = new T(path.c_str()); + if(!resource->IsReady()) { return NULL; } - cache.PushBack( resource ); + cache.PushBack(resource); return resource; } - #endif diff --git a/examples/fpp-game/game-texture.cpp b/examples/fpp-game/game-texture.cpp index 630c28f..d60c5d2 100644 --- a/examples/fpp-game/game-texture.cpp +++ b/examples/fpp-game/game-texture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ #include GameTexture::GameTexture() -: mUniqueId( 0 ), - mIsReady( false ) +: mUniqueId(0), + mIsReady(false) { } @@ -32,40 +32,40 @@ GameTexture::~GameTexture() { } -GameTexture::GameTexture( const char* filename ) -: mUniqueId( 0 ), - mIsReady( false ) +GameTexture::GameTexture(const char* filename) +: mUniqueId(0), + mIsReady(false) { - Load( filename ); + Load(filename); } -bool GameTexture::Load( const char* filename ) +bool GameTexture::Load(const char* filename) { - Dali::PixelData pixelData = Dali::Toolkit::SyncImageLoader::Load( filename ); + Dali::PixelData pixelData = Dali::Toolkit::SyncImageLoader::Load(filename); - if( !pixelData ) + if(!pixelData) { return false; } - Dali::Texture texture = Dali::Texture::New( Dali::TextureType::TEXTURE_2D, - pixelData.GetPixelFormat(), - pixelData.GetWidth(), - pixelData.GetHeight() ); - texture.Upload( pixelData ); + Dali::Texture texture = Dali::Texture::New(Dali::TextureType::TEXTURE_2D, + pixelData.GetPixelFormat(), + pixelData.GetWidth(), + pixelData.GetHeight()); + texture.Upload(pixelData); texture.GenerateMipmaps(); Dali::TextureSet textureSet = Dali::TextureSet::New(); - textureSet.SetTexture( 0, texture ); + textureSet.SetTexture(0, texture); Dali::Sampler sampler = Dali::Sampler::New(); - sampler.SetWrapMode( Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT ); - sampler.SetFilterMode( Dali::FilterMode::LINEAR_MIPMAP_LINEAR, Dali::FilterMode::LINEAR ); - textureSet.SetSampler( 0, sampler ); + sampler.SetWrapMode(Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT); + sampler.SetFilterMode(Dali::FilterMode::LINEAR_MIPMAP_LINEAR, Dali::FilterMode::LINEAR); + textureSet.SetSampler(0, sampler); - mTexture = texture; - mSampler = sampler; + mTexture = texture; + mSampler = sampler; mTextureSet = textureSet; - mUniqueId = GameUtils::HashString( filename ); + mUniqueId = GameUtils::HashString(filename); mIsReady = true; diff --git a/examples/fpp-game/game-texture.h b/examples/fpp-game/game-texture.h index 78de926..65a9487 100644 --- a/examples/fpp-game/game-texture.h +++ b/examples/fpp-game/game-texture.h @@ -2,7 +2,7 @@ #define GAME_TEXTURE_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +18,15 @@ * */ -#include -#include #include +#include +#include #include class GameTexture { public: - /** * Creates an instance of the GameTexture */ @@ -36,7 +35,7 @@ public: /** * Creates an instance of the GameTexture with given filename */ - GameTexture( const char* filename ); + GameTexture(const char* filename); /** * Destroys an instance of the GameTexture @@ -47,7 +46,7 @@ public: * @brief Loads texture from file * @return Returns true if success */ - bool Load( const char* filename ); + bool Load(const char* filename); /** * Checks status of texture, returns false if failed to load @@ -68,14 +67,13 @@ public: uint32_t GetUniqueId(); private: + Dali::Texture mTexture; + Dali::Sampler mSampler; + Dali::TextureSet mTextureSet; - Dali::Texture mTexture; - Dali::Sampler mSampler; - Dali::TextureSet mTextureSet; - - uint32_t mUniqueId; + uint32_t mUniqueId; - bool mIsReady; + bool mIsReady; }; #endif diff --git a/examples/fpp-game/game-utils.cpp b/examples/fpp-game/game-utils.cpp index 1f3f502..9011a26 100644 --- a/examples/fpp-game/game-utils.cpp +++ b/examples/fpp-game/game-utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,48 +15,48 @@ * */ +#include +#include #include #include -#include -#include #include "game-utils.h" namespace GameUtils { -bool LoadFile( const char* filename, ByteArray& bytes ) +bool LoadFile(const char* filename, ByteArray& bytes) { - Dali::FileStream fileStream( filename, Dali::FileStream::READ | Dali::FileStream::BINARY ); - FILE* fin = fileStream.GetFile(); + Dali::FileStream fileStream(filename, Dali::FileStream::READ | Dali::FileStream::BINARY); + FILE* fin = fileStream.GetFile(); - if( fin ) + if(fin) { - if( fseek( fin, 0, SEEK_END ) ) + if(fseek(fin, 0, SEEK_END)) { return false; } - bytes.resize( ftell( fin ) ); - std::fill( bytes.begin(), bytes.end(), 0 ); - if( fseek( fin, 0, SEEK_SET ) ) + bytes.resize(ftell(fin)); + std::fill(bytes.begin(), bytes.end(), 0); + if(fseek(fin, 0, SEEK_SET)) { return false; } - size_t result = fread( bytes.data(), 1, bytes.size(), fin ); - return ( result != 0 ); + size_t result = fread(bytes.data(), 1, bytes.size(), fin); + return (result != 0); } return false; } -size_t HashString( const char* str ) +size_t HashString(const char* str) { size_t hash = 5381; - int c; - while( ( c = *str++ ) ) + int c; + while((c = *str++)) { - hash = ((hash << 5) + hash) + c; + hash = ((hash << 5) + hash) + c; } return hash; } -} +} // namespace GameUtils diff --git a/examples/fpp-game/game-utils.h b/examples/fpp-game/game-utils.h index 6d70ff1..e5a0548 100644 --- a/examples/fpp-game/game-utils.h +++ b/examples/fpp-game/game-utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ #ifndef GAME_UTILS_H #define GAME_UTILS_H -#include #include #include +#include namespace GameUtils { @@ -29,14 +29,13 @@ typedef std::vector ByteArray; /** * Loads file from the storage and returns byte array */ -bool LoadFile( const char* filename, ByteArray& out ); +bool LoadFile(const char* filename, ByteArray& out); /** * Computes hash value from string using djb2 algorithm * @return hash value */ -size_t HashString( const char* str ); -} +size_t HashString(const char* str); +} // namespace GameUtils #endif - diff --git a/examples/fpp-game/third-party/picojson.h b/examples/fpp-game/third-party/picojson.h index c0081e7..a7b6ccb 100644 --- a/examples/fpp-game/third-party/picojson.h +++ b/examples/fpp-game/third-party/picojson.h @@ -29,349 +29,431 @@ #define picojson_h #include +#include #include #include #include -#include #include #include #include #include #include #include -#include #include +#include // for isnan/isinf -#if __cplusplus>=201103L -# include +#if __cplusplus >= 201103L +#include +#else +extern "C" +{ +#ifdef _MSC_VER +#include +#elif defined(__INTEL_COMPILER) +#include #else -extern "C" { -# ifdef _MSC_VER -# include -# elif defined(__INTEL_COMPILER) -# include -# else -# include -# endif +#include +#endif } #endif #ifndef PICOJSON_USE_RVALUE_REFERENCE -# if (defined(__cpp_rvalue_references) && __cpp_rvalue_references >= 200610) || (defined(_MSC_VER) && _MSC_VER >= 1600) -# define PICOJSON_USE_RVALUE_REFERENCE 1 -# else -# define PICOJSON_USE_RVALUE_REFERENCE 0 -# endif -#endif//PICOJSON_USE_RVALUE_REFERENCE - +#if(defined(__cpp_rvalue_references) && __cpp_rvalue_references >= 200610) || (defined(_MSC_VER) && _MSC_VER >= 1600) +#define PICOJSON_USE_RVALUE_REFERENCE 1 +#else +#define PICOJSON_USE_RVALUE_REFERENCE 0 +#endif +#endif //PICOJSON_USE_RVALUE_REFERENCE // experimental support for int64_t (see README.mkdn for detail) #ifdef PICOJSON_USE_INT64 -# define __STDC_FORMAT_MACROS -# include -# include +#define __STDC_FORMAT_MACROS +#include +#include #endif // to disable the use of localeconv(3), set PICOJSON_USE_LOCALE to 0 #ifndef PICOJSON_USE_LOCALE -# define PICOJSON_USE_LOCALE 1 +#define PICOJSON_USE_LOCALE 1 #endif #if PICOJSON_USE_LOCALE -extern "C" { -# include +extern "C" +{ +#include } #endif #ifndef PICOJSON_ASSERT -# define PICOJSON_ASSERT(e) do { if (! (e)) throw std::runtime_error(#e); } while (0) +#define PICOJSON_ASSERT(e) \ + do \ + { \ + if(!(e)) throw std::runtime_error(#e); \ + } while(0) #endif #ifdef _MSC_VER - #define SNPRINTF _snprintf_s - #pragma warning(push) - #pragma warning(disable : 4244) // conversion from int to char - #pragma warning(disable : 4127) // conditional expression is constant - #pragma warning(disable : 4702) // unreachable code +#define SNPRINTF _snprintf_s +#pragma warning(push) +#pragma warning(disable : 4244) // conversion from int to char +#pragma warning(disable : 4127) // conditional expression is constant +#pragma warning(disable : 4702) // unreachable code #else - #define SNPRINTF snprintf +#define SNPRINTF snprintf #endif -namespace picojson { - - enum { - null_type, - boolean_type, - number_type, - string_type, - array_type, - object_type +namespace picojson +{ +enum +{ + null_type, + boolean_type, + number_type, + string_type, + array_type, + object_type #ifdef PICOJSON_USE_INT64 - , int64_type + , + int64_type #endif - }; +}; - enum { - INDENT_WIDTH = 2 - }; +enum +{ + INDENT_WIDTH = 2 +}; - struct null {}; +struct null +{ +}; - class value { - public: - typedef std::vector array; - typedef std::map object; - union _storage { - bool boolean_; - double number_; +class value +{ +public: + typedef std::vector array; + typedef std::map object; + union _storage + { + bool boolean_; + double number_; #ifdef PICOJSON_USE_INT64 - int64_t int64_; + int64_t int64_; #endif - std::string* string_; - array* array_; - object* object_; - }; - protected: - int type_; - _storage u_; - public: - value(); - value(int type, bool); - explicit value(bool b); + std::string* string_; + array* array_; + object* object_; + }; + +protected: + int type_; + _storage u_; + +public: + value(); + value(int type, bool); + explicit value(bool b); #ifdef PICOJSON_USE_INT64 - explicit value(int64_t i); + explicit value(int64_t i); #endif - explicit value(double n); - explicit value(const std::string& s); - explicit value(const array& a); - explicit value(const object& o); - explicit value(const char* s); - value(const char* s, size_t len); - ~value(); - value(const value& x); - value& operator=(const value& x); + explicit value(double n); + explicit value(const std::string& s); + explicit value(const array& a); + explicit value(const object& o); + explicit value(const char* s); + value(const char* s, size_t len); + ~value(); + value(const value& x); + value& operator=(const value& x); #if PICOJSON_USE_RVALUE_REFERENCE - value(value&& x)throw(); - value& operator=(value&& x)throw(); + value(value&& x) throw(); + value& operator=(value&& x) throw(); #endif - void swap(value& x)throw(); - template bool is() const; - template const T& get() const; - template T& get(); - template void set(const T &); + void swap(value& x) throw(); + template + bool is() const; + template + const T& get() const; + template + T& get(); + template + void set(const T&); #if PICOJSON_USE_RVALUE_REFERENCE - template void set(T &&); + template + void set(T&&); #endif - bool evaluate_as_boolean() const; - const value& get(size_t idx) const; - const value& get(const std::string& key) const; - value& get(size_t idx); - value& get(const std::string& key); - - bool contains(size_t idx) const; - bool contains(const std::string& key) const; - std::string to_str() const; - template void serialize(Iter os, bool prettify = false) const; - std::string serialize(bool prettify = false) const; - private: - template value(const T*); // intentionally defined to block implicit conversion of pointer to bool - template static void _indent(Iter os, int indent); - template void _serialize(Iter os, int indent) const; - std::string _serialize(int indent) const; - void clear(); - }; - - typedef value::array array; - typedef value::object object; - - inline value::value() : type_(null_type) {} + bool evaluate_as_boolean() const; + const value& get(size_t idx) const; + const value& get(const std::string& key) const; + value& get(size_t idx); + value& get(const std::string& key); + + bool contains(size_t idx) const; + bool contains(const std::string& key) const; + std::string to_str() const; + template + void serialize(Iter os, bool prettify = false) const; + std::string serialize(bool prettify = false) const; + +private: + template + value(const T*); // intentionally defined to block implicit conversion of pointer to bool + template + static void _indent(Iter os, int indent); + template + void _serialize(Iter os, int indent) const; + std::string _serialize(int indent) const; + void clear(); +}; + +typedef value::array array; +typedef value::object object; + +inline value::value() +: type_(null_type) +{ +} - inline value::value(int type, bool) : type_(type) { - switch (type) { -#define INIT(p, v) case p##type: u_.p = v; break - INIT(boolean_, false); - INIT(number_, 0.0); +inline value::value(int type, bool) +: type_(type) +{ + switch(type) + { +#define INIT(p, v) \ + case p##type: \ + u_.p = v; \ + break + INIT(boolean_, false); + INIT(number_, 0.0); #ifdef PICOJSON_USE_INT64 - INIT(int64_, 0); + INIT(int64_, 0); #endif - INIT(string_, new std::string()); - INIT(array_, new array()); - INIT(object_, new object()); + INIT(string_, new std::string()); + INIT(array_, new array()); + INIT(object_, new object()); #undef INIT - default: break; - } + default: + break; } +} - inline value::value(bool b) : type_(boolean_type) { - u_.boolean_ = b; - } +inline value::value(bool b) +: type_(boolean_type) +{ + u_.boolean_ = b; +} #ifdef PICOJSON_USE_INT64 - inline value::value(int64_t i) : type_(int64_type) { - u_.int64_ = i; - } +inline value::value(int64_t i) +: type_(int64_type) +{ + u_.int64_ = i; +} #endif - inline value::value(double n) : type_(number_type) { - if ( +inline value::value(double n) +: type_(number_type) +{ + if( #ifdef _MSC_VER - ! _finite(n) -#elif __cplusplus>=201103L || !(defined(isnan) && defined(isinf)) - std::isnan(n) || std::isinf(n) + !_finite(n) +#elif __cplusplus >= 201103L || !(defined(isnan) && defined(isinf)) + std::isnan(n) || std::isinf(n) #else - isnan(n) || isinf(n) + isnan(n) || isinf(n) #endif - ) { - throw std::overflow_error(""); - } - u_.number_ = n; + ) + { + throw std::overflow_error(""); } + u_.number_ = n; +} - inline value::value(const std::string& s) : type_(string_type) { - u_.string_ = new std::string(s); - } +inline value::value(const std::string& s) +: type_(string_type) +{ + u_.string_ = new std::string(s); +} - inline value::value(const array& a) : type_(array_type) { - u_.array_ = new array(a); - } +inline value::value(const array& a) +: type_(array_type) +{ + u_.array_ = new array(a); +} - inline value::value(const object& o) : type_(object_type) { - u_.object_ = new object(o); - } +inline value::value(const object& o) +: type_(object_type) +{ + u_.object_ = new object(o); +} - inline value::value(const char* s) : type_(string_type) { - u_.string_ = new std::string(s); - } +inline value::value(const char* s) +: type_(string_type) +{ + u_.string_ = new std::string(s); +} - inline value::value(const char* s, size_t len) : type_(string_type) { - u_.string_ = new std::string(s, len); - } +inline value::value(const char* s, size_t len) +: type_(string_type) +{ + u_.string_ = new std::string(s, len); +} - inline void value::clear() { - switch (type_) { -#define DEINIT(p) case p##type: delete u_.p; break - DEINIT(string_); - DEINIT(array_); - DEINIT(object_); +inline void value::clear() +{ + switch(type_) + { +#define DEINIT(p) \ + case p##type: \ + delete u_.p; \ + break + DEINIT(string_); + DEINIT(array_); + DEINIT(object_); #undef DEINIT - default: break; - } + default: + break; } +} - inline value::~value() { - clear(); - } +inline value::~value() +{ + clear(); +} - inline value::value(const value& x) : type_(x.type_) { - switch (type_) { -#define INIT(p, v) case p##type: u_.p = v; break - INIT(string_, new std::string(*x.u_.string_)); - INIT(array_, new array(*x.u_.array_)); - INIT(object_, new object(*x.u_.object_)); +inline value::value(const value& x) +: type_(x.type_) +{ + switch(type_) + { +#define INIT(p, v) \ + case p##type: \ + u_.p = v; \ + break + INIT(string_, new std::string(*x.u_.string_)); + INIT(array_, new array(*x.u_.array_)); + INIT(object_, new object(*x.u_.object_)); #undef INIT default: u_ = x.u_; break; - } } +} - inline value& value::operator=(const value& x) { - if (this != &x) { - value t(x); - swap(t); - } - return *this; +inline value& value::operator=(const value& x) +{ + if(this != &x) + { + value t(x); + swap(t); } + return *this; +} #if PICOJSON_USE_RVALUE_REFERENCE - inline value::value(value&& x)throw() : type_(null_type) { - swap(x); - } - inline value& value::operator=(value&& x)throw() { - swap(x); - return *this; - } +inline value::value(value&& x) throw() +: type_(null_type) +{ + swap(x); +} +inline value& value::operator=(value&& x) throw() +{ + swap(x); + return *this; +} #endif - inline void value::swap(value& x)throw() { - std::swap(type_, x.type_); - std::swap(u_, x.u_); - } +inline void value::swap(value& x) throw() +{ + std::swap(type_, x.type_); + std::swap(u_, x.u_); +} -#define IS(ctype, jtype) \ - template <> inline bool value::is() const { \ - return type_ == jtype##_type; \ +#define IS(ctype, jtype) \ + template<> \ + inline bool value::is() const \ + { \ + return type_ == jtype##_type; \ } - IS(null, null) - IS(bool, boolean) +IS(null, null) +IS(bool, boolean) #ifdef PICOJSON_USE_INT64 - IS(int64_t, int64) +IS(int64_t, int64) #endif - IS(std::string, string) - IS(array, array) - IS(object, object) +IS(std::string, string) +IS(array, array) +IS(object, object) #undef IS - template <> inline bool value::is() const { - return type_ == number_type +template<> +inline bool value::is() const +{ + return type_ == number_type #ifdef PICOJSON_USE_INT64 - || type_ == int64_type + || type_ == int64_type #endif - ; - } - -#define GET(ctype, var) \ - template <> inline const ctype& value::get() const { \ - PICOJSON_ASSERT("type mismatch! call is() before get()" \ - && is()); \ - return var; \ - } \ - template <> inline ctype& value::get() { \ - PICOJSON_ASSERT("type mismatch! call is() before get()" \ - && is()); \ - return var; \ - } - GET(bool, u_.boolean_) - GET(std::string, *u_.string_) - GET(array, *u_.array_) - GET(object, *u_.object_) + ; +} + +#define GET(ctype, var) \ + template<> \ + inline const ctype& value::get() const \ + { \ + PICOJSON_ASSERT("type mismatch! call is() before get()" && is()); \ + return var; \ + } \ + template<> \ + inline ctype& value::get() \ + { \ + PICOJSON_ASSERT("type mismatch! call is() before get()" && is()); \ + return var; \ + } +GET(bool, u_.boolean_) +GET(std::string, *u_.string_) +GET(array, *u_.array_) +GET(object, *u_.object_) #ifdef PICOJSON_USE_INT64 - GET(double, (type_ == int64_type && (const_cast(this)->type_ = number_type, const_cast(this)->u_.number_ = u_.int64_), u_.number_)) - GET(int64_t, u_.int64_) +GET(double, (type_ == int64_type && (const_cast(this)->type_ = number_type, const_cast(this)->u_.number_ = u_.int64_), u_.number_)) +GET(int64_t, u_.int64_) #else - GET(double, u_.number_) +GET(double, u_.number_) #endif #undef GET -#define SET(ctype, jtype, setter) \ - template <> inline void value::set(const ctype &_val) { \ - clear(); \ - type_ = jtype##_type; \ - setter \ - } - SET(bool, boolean, u_.boolean_ = _val;) - SET(std::string, string, u_.string_ = new std::string(_val);) - SET(array, array, u_.array_ = new array(_val);) - SET(object, object, u_.object_ = new object(_val);) - SET(double, number, u_.number_ = _val;) +#define SET(ctype, jtype, setter) \ + template<> \ + inline void value::set(const ctype& _val) \ + { \ + clear(); \ + type_ = jtype##_type; \ + setter \ + } +SET(bool, boolean, u_.boolean_ = _val;) +SET(std::string, string, u_.string_ = new std::string(_val);) +SET(array, array, u_.array_ = new array(_val);) +SET(object, object, u_.object_ = new object(_val);) +SET(double, number, u_.number_ = _val;) #ifdef PICOJSON_USE_INT64 - SET(int64_t, int64, u_.int64_ = _val;) +SET(int64_t, int64, u_.int64_ = _val;) #endif #undef SET #if PICOJSON_USE_RVALUE_REFERENCE -#define MOVESET(ctype, jtype, setter) \ - template <> inline void value::set(ctype &&_val) { \ - clear(); \ - type_ = jtype##_type; \ - setter \ - } - MOVESET(std::string, string, u_.string_ = new std::string(std::move(_val));) - MOVESET(array, array, u_.array_ = new array(std::move(_val));) - MOVESET(object, object, u_.object_ = new object(std::move(_val));) +#define MOVESET(ctype, jtype, setter) \ + template<> \ + inline void value::set(ctype && _val) \ + { \ + clear(); \ + type_ = jtype##_type; \ + setter \ + } +MOVESET(std::string, string, u_.string_ = new std::string(std::move(_val));) +MOVESET(array, array, u_.array_ = new array(std::move(_val));) +MOVESET(object, object, u_.object_ = new object(std::move(_val));) #undef MOVESET #endif - inline bool value::evaluate_as_boolean() const { - switch (type_) { +inline bool value::evaluate_as_boolean() const +{ + switch(type_) + { case null_type: return false; case boolean_type: @@ -383,70 +465,85 @@ namespace picojson { return u_.int64_ != 0; #endif case string_type: - return ! u_.string_->empty(); + return !u_.string_->empty(); default: return true; - } } +} - inline const value& value::get(size_t idx) const { - static value s_null; - PICOJSON_ASSERT(is()); - return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; - } +inline const value& value::get(size_t idx) const +{ + static value s_null; + PICOJSON_ASSERT(is()); + return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; +} - inline value& value::get(size_t idx) { - static value s_null; - PICOJSON_ASSERT(is()); - return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; - } +inline value& value::get(size_t idx) +{ + static value s_null; + PICOJSON_ASSERT(is()); + return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; +} - inline const value& value::get(const std::string& key) const { - static value s_null; - PICOJSON_ASSERT(is()); - object::const_iterator i = u_.object_->find(key); - return i != u_.object_->end() ? i->second : s_null; - } +inline const value& value::get(const std::string& key) const +{ + static value s_null; + PICOJSON_ASSERT(is()); + object::const_iterator i = u_.object_->find(key); + return i != u_.object_->end() ? i->second : s_null; +} - inline value& value::get(const std::string& key) { - static value s_null; - PICOJSON_ASSERT(is()); - object::iterator i = u_.object_->find(key); - return i != u_.object_->end() ? i->second : s_null; - } +inline value& value::get(const std::string& key) +{ + static value s_null; + PICOJSON_ASSERT(is()); + object::iterator i = u_.object_->find(key); + return i != u_.object_->end() ? i->second : s_null; +} - inline bool value::contains(size_t idx) const { - PICOJSON_ASSERT(is()); - return idx < u_.array_->size(); - } +inline bool value::contains(size_t idx) const +{ + PICOJSON_ASSERT(is()); + return idx < u_.array_->size(); +} - inline bool value::contains(const std::string& key) const { - PICOJSON_ASSERT(is()); - object::const_iterator i = u_.object_->find(key); - return i != u_.object_->end(); - } +inline bool value::contains(const std::string& key) const +{ + PICOJSON_ASSERT(is()); + object::const_iterator i = u_.object_->find(key); + return i != u_.object_->end(); +} - inline std::string value::to_str() const { - switch (type_) { - case null_type: return "null"; - case boolean_type: return u_.boolean_ ? "true" : "false"; +inline std::string value::to_str() const +{ + switch(type_) + { + case null_type: + return "null"; + case boolean_type: + return u_.boolean_ ? "true" : "false"; #ifdef PICOJSON_USE_INT64 - case int64_type: { + case int64_type: + { char buf[sizeof("-9223372036854775808")]; SNPRINTF(buf, sizeof(buf), "%" PRId64, u_.int64_); return buf; } #endif - case number_type: { - char buf[256]; + case number_type: + { + char buf[256]; double tmp; SNPRINTF(buf, sizeof(buf), fabs(u_.number_) < (1ULL << 53) && modf(u_.number_, &tmp) == 0 ? "%.f" : "%.17g", u_.number_); #if PICOJSON_USE_LOCALE - char *decimal_point = localeconv()->decimal_point; - if (strcmp(decimal_point, ".") != 0) { + char* decimal_point = localeconv()->decimal_point; + if(strcmp(decimal_point, ".") != 0) + { size_t decimal_point_len = strlen(decimal_point); - for (char *p = buf; *p != '\0'; ++p) { - if (strncmp(p, decimal_point, decimal_point_len) == 0) { + for(char* p = buf; *p != '\0'; ++p) + { + if(strncmp(p, decimal_point, decimal_point_len) == 0) + { return std::string(buf, p) + "." + (p + decimal_point_len); } } @@ -454,125 +551,166 @@ namespace picojson { #endif return buf; } - case string_type: return *u_.string_; - case array_type: return "array"; - case object_type: return "object"; - default: PICOJSON_ASSERT(0); + case string_type: + return *u_.string_; + case array_type: + return "array"; + case object_type: + return "object"; + default: + PICOJSON_ASSERT(0); #ifdef _MSC_VER __assume(0); #endif - } - return std::string(); - } - - template void copy(const std::string& s, Iter oi) { - std::copy(s.begin(), s.end(), oi); - } - - template - struct serialize_str_char { - Iter oi; - void operator()(char c) { - switch (c) { -#define MAP(val, sym) case val: copy(sym, oi); break - MAP('"', "\\\""); - MAP('\\', "\\\\"); - MAP('/', "\\/"); - MAP('\b', "\\b"); - MAP('\f', "\\f"); - MAP('\n', "\\n"); - MAP('\r', "\\r"); - MAP('\t', "\\t"); + } + return std::string(); +} + +template +void copy(const std::string& s, Iter oi) +{ + std::copy(s.begin(), s.end(), oi); +} + +template +struct serialize_str_char +{ + Iter oi; + void operator()(char c) + { + switch(c) + { +#define MAP(val, sym) \ + case val: \ + copy(sym, oi); \ + break + MAP('"', "\\\""); + MAP('\\', "\\\\"); + MAP('/', "\\/"); + MAP('\b', "\\b"); + MAP('\f', "\\f"); + MAP('\n', "\\n"); + MAP('\r', "\\r"); + MAP('\t', "\\t"); #undef MAP default: - if (static_cast(c) < 0x20 || c == 0x7f) { - char buf[7]; - SNPRINTF(buf, sizeof(buf), "\\u%04x", c & 0xff); - copy(buf, buf + 6, oi); - } else { - *oi++ = c; - } - break; - } + if(static_cast(c) < 0x20 || c == 0x7f) + { + char buf[7]; + SNPRINTF(buf, sizeof(buf), "\\u%04x", c & 0xff); + copy(buf, buf + 6, oi); + } + else + { + *oi++ = c; + } + break; } - }; - - template void serialize_str(const std::string& s, Iter oi) { - *oi++ = '"'; - serialize_str_char process_char = { oi }; - std::for_each(s.begin(), s.end(), process_char); - *oi++ = '"'; } +}; - template void value::serialize(Iter oi, bool prettify) const { - return _serialize(oi, prettify ? 0 : -1); - } +template +void serialize_str(const std::string& s, Iter oi) +{ + *oi++ = '"'; + serialize_str_char process_char = {oi}; + std::for_each(s.begin(), s.end(), process_char); + *oi++ = '"'; +} - inline std::string value::serialize(bool prettify) const { - return _serialize(prettify ? 0 : -1); - } +template +void value::serialize(Iter oi, bool prettify) const +{ + return _serialize(oi, prettify ? 0 : -1); +} - template void value::_indent(Iter oi, int indent) { - *oi++ = '\n'; - for (int i = 0; i < indent * INDENT_WIDTH; ++i) { - *oi++ = ' '; - } +inline std::string value::serialize(bool prettify) const +{ + return _serialize(prettify ? 0 : -1); +} + +template +void value::_indent(Iter oi, int indent) +{ + *oi++ = '\n'; + for(int i = 0; i < indent * INDENT_WIDTH; ++i) + { + *oi++ = ' '; } +} - template void value::_serialize(Iter oi, int indent) const { - switch (type_) { +template +void value::_serialize(Iter oi, int indent) const +{ + switch(type_) + { case string_type: serialize_str(*u_.string_, oi); break; - case array_type: { + case array_type: + { *oi++ = '['; - if (indent != -1) { + if(indent != -1) + { ++indent; } - for (array::const_iterator i = u_.array_->begin(); - i != u_.array_->end(); - ++i) { - if (i != u_.array_->begin()) { - *oi++ = ','; - } - if (indent != -1) { + for(array::const_iterator i = u_.array_->begin(); + i != u_.array_->end(); + ++i) + { + if(i != u_.array_->begin()) + { + *oi++ = ','; + } + if(indent != -1) + { _indent(oi, indent); } - i->_serialize(oi, indent); + i->_serialize(oi, indent); } - if (indent != -1) { + if(indent != -1) + { --indent; - if (! u_.array_->empty()) { + if(!u_.array_->empty()) + { _indent(oi, indent); } } *oi++ = ']'; break; } - case object_type: { + case object_type: + { *oi++ = '{'; - if (indent != -1) { + if(indent != -1) + { ++indent; } - for (object::const_iterator i = u_.object_->begin(); - i != u_.object_->end(); - ++i) { - if (i != u_.object_->begin()) { - *oi++ = ','; - } - if (indent != -1) { + for(object::const_iterator i = u_.object_->begin(); + i != u_.object_->end(); + ++i) + { + if(i != u_.object_->begin()) + { + *oi++ = ','; + } + if(indent != -1) + { _indent(oi, indent); } - serialize_str(i->first, oi); - *oi++ = ':'; - if (indent != -1) { + serialize_str(i->first, oi); + *oi++ = ':'; + if(indent != -1) + { *oi++ = ' '; } i->second._serialize(oi, indent); } - if (indent != -1) { + if(indent != -1) + { --indent; - if (! u_.object_->empty()) { + if(!u_.object_->empty()) + { _indent(oi, indent); } } @@ -582,253 +720,350 @@ namespace picojson { default: copy(to_str(), oi); break; - } - if (indent == 0) { - *oi++ = '\n'; - } } - - inline std::string value::_serialize(int indent) const { - std::string s; - _serialize(std::back_inserter(s), indent); - return s; + if(indent == 0) + { + *oi++ = '\n'; } +} - template class input { - protected: - Iter cur_, end_; - bool consumed_; - int line_; - public: - input(const Iter& first, const Iter& last) : cur_(first), end_(last), consumed_(false), line_(1) {} - int getc() { - if (consumed_) { - if (*cur_ == '\n') { - ++line_; - } - ++cur_; - } - if (cur_ == end_) { - consumed_ = false; - return -1; +inline std::string value::_serialize(int indent) const +{ + std::string s; + _serialize(std::back_inserter(s), indent); + return s; +} + +template +class input +{ +protected: + Iter cur_, end_; + bool consumed_; + int line_; + +public: + input(const Iter& first, const Iter& last) + : cur_(first), + end_(last), + consumed_(false), + line_(1) + { + } + int getc() + { + if(consumed_) + { + if(*cur_ == '\n') + { + ++line_; } - consumed_ = true; - return *cur_ & 0xff; + ++cur_; } - void ungetc() { + if(cur_ == end_) + { consumed_ = false; + return -1; } - Iter cur() const { - if (consumed_) { - input *self = const_cast*>(this); - self->consumed_ = false; - ++self->cur_; - } - return cur_; - } - int line() const { return line_; } - void skip_ws() { - while (1) { - int ch = getc(); - if (! (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) { - ungetc(); - break; - } - } + consumed_ = true; + return *cur_ & 0xff; + } + void ungetc() + { + consumed_ = false; + } + Iter cur() const + { + if(consumed_) + { + input* self = const_cast*>(this); + self->consumed_ = false; + ++self->cur_; } - bool expect(int expect) { - skip_ws(); - if (getc() != expect) { - ungetc(); - return false; + return cur_; + } + int line() const + { + return line_; + } + void skip_ws() + { + while(1) + { + int ch = getc(); + if(!(ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) + { + ungetc(); + break; } - return true; } - bool match(const std::string& pattern) { - for (std::string::const_iterator pi(pattern.begin()); - pi != pattern.end(); - ++pi) { - if (getc() != *pi) { - ungetc(); - return false; - } - } - return true; + } + bool expect(int expect) + { + skip_ws(); + if(getc() != expect) + { + ungetc(); + return false; } - }; - - template inline int _parse_quadhex(input &in) { - int uni_ch = 0, hex; - for (int i = 0; i < 4; i++) { - if ((hex = in.getc()) == -1) { - return -1; - } - if ('0' <= hex && hex <= '9') { - hex -= '0'; - } else if ('A' <= hex && hex <= 'F') { - hex -= 'A' - 0xa; - } else if ('a' <= hex && hex <= 'f') { - hex -= 'a' - 0xa; - } else { - in.ungetc(); - return -1; + return true; + } + bool match(const std::string& pattern) + { + for(std::string::const_iterator pi(pattern.begin()); + pi != pattern.end(); + ++pi) + { + if(getc() != *pi) + { + ungetc(); + return false; } - uni_ch = uni_ch * 16 + hex; } - return uni_ch; + return true; } +}; - template inline bool _parse_codepoint(String& out, input& in) { - int uni_ch; - if ((uni_ch = _parse_quadhex(in)) == -1) { - return false; +template +inline int _parse_quadhex(input& in) +{ + int uni_ch = 0, hex; + for(int i = 0; i < 4; i++) + { + if((hex = in.getc()) == -1) + { + return -1; } - if (0xd800 <= uni_ch && uni_ch <= 0xdfff) { - if (0xdc00 <= uni_ch) { - // a second 16-bit of a surrogate pair appeared - return false; - } - // first 16-bit of surrogate pair, get the next one - if (in.getc() != '\\' || in.getc() != 'u') { - in.ungetc(); - return false; - } - int second = _parse_quadhex(in); - if (! (0xdc00 <= second && second <= 0xdfff)) { - return false; - } - uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff); - uni_ch += 0x10000; + if('0' <= hex && hex <= '9') + { + hex -= '0'; } - if (uni_ch < 0x80) { - out.push_back(uni_ch); - } else { - if (uni_ch < 0x800) { - out.push_back(0xc0 | (uni_ch >> 6)); - } else { - if (uni_ch < 0x10000) { - out.push_back(0xe0 | (uni_ch >> 12)); - } else { - out.push_back(0xf0 | (uni_ch >> 18)); - out.push_back(0x80 | ((uni_ch >> 12) & 0x3f)); - } - out.push_back(0x80 | ((uni_ch >> 6) & 0x3f)); - } - out.push_back(0x80 | (uni_ch & 0x3f)); + else if('A' <= hex && hex <= 'F') + { + hex -= 'A' - 0xa; } - return true; + else if('a' <= hex && hex <= 'f') + { + hex -= 'a' - 0xa; + } + else + { + in.ungetc(); + return -1; + } + uni_ch = uni_ch * 16 + hex; } + return uni_ch; +} - template inline bool _parse_string(String& out, input& in) { - while (1) { - int ch = in.getc(); - if (ch < ' ') { - in.ungetc(); - return false; - } else if (ch == '"') { - return true; - } else if (ch == '\\') { - if ((ch = in.getc()) == -1) { - return false; - } - switch (ch) { -#define MAP(sym, val) case sym: out.push_back(val); break - MAP('"', '\"'); - MAP('\\', '\\'); - MAP('/', '/'); - MAP('b', '\b'); - MAP('f', '\f'); - MAP('n', '\n'); - MAP('r', '\r'); - MAP('t', '\t'); -#undef MAP - case 'u': - if (! _parse_codepoint(out, in)) { - return false; - } - break; - default: - return false; - } - } else { - out.push_back(ch); - } - } +template +inline bool _parse_codepoint(String& out, input& in) +{ + int uni_ch; + if((uni_ch = _parse_quadhex(in)) == -1) + { return false; } - - template inline bool _parse_array(Context& ctx, input& in) { - if (! ctx.parse_array_start()) { + if(0xd800 <= uni_ch && uni_ch <= 0xdfff) + { + if(0xdc00 <= uni_ch) + { + // a second 16-bit of a surrogate pair appeared return false; } - size_t idx = 0; - if (in.expect(']')) { - return ctx.parse_array_stop(idx); + // first 16-bit of surrogate pair, get the next one + if(in.getc() != '\\' || in.getc() != 'u') + { + in.ungetc(); + return false; } - do { - if (! ctx.parse_array_item(in, idx)) { - return false; + int second = _parse_quadhex(in); + if(!(0xdc00 <= second && second <= 0xdfff)) + { + return false; + } + uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff); + uni_ch += 0x10000; + } + if(uni_ch < 0x80) + { + out.push_back(uni_ch); + } + else + { + if(uni_ch < 0x800) + { + out.push_back(0xc0 | (uni_ch >> 6)); + } + else + { + if(uni_ch < 0x10000) + { + out.push_back(0xe0 | (uni_ch >> 12)); } - idx++; - } while (in.expect(',')); - return in.expect(']') && ctx.parse_array_stop(idx); + else + { + out.push_back(0xf0 | (uni_ch >> 18)); + out.push_back(0x80 | ((uni_ch >> 12) & 0x3f)); + } + out.push_back(0x80 | ((uni_ch >> 6) & 0x3f)); + } + out.push_back(0x80 | (uni_ch & 0x3f)); } + return true; +} - template inline bool _parse_object(Context& ctx, input& in) { - if (! ctx.parse_object_start()) { +template +inline bool _parse_string(String& out, input& in) +{ + while(1) + { + int ch = in.getc(); + if(ch < ' ') + { + in.ungetc(); return false; } - if (in.expect('}')) { + else if(ch == '"') + { return true; } - do { - std::string key; - if (! in.expect('"') - || ! _parse_string(key, in) - || ! in.expect(':')) { - return false; + else if(ch == '\\') + { + if((ch = in.getc()) == -1) + { + return false; } - if (! ctx.parse_object_item(in, key)) { - return false; + switch(ch) + { +#define MAP(sym, val) \ + case sym: \ + out.push_back(val); \ + break + MAP('"', '\"'); + MAP('\\', '\\'); + MAP('/', '/'); + MAP('b', '\b'); + MAP('f', '\f'); + MAP('n', '\n'); + MAP('r', '\r'); + MAP('t', '\t'); +#undef MAP + case 'u': + if(!_parse_codepoint(out, in)) + { + return false; + } + break; + default: + return false; } - } while (in.expect(',')); - return in.expect('}'); + } + else + { + out.push_back(ch); + } } + return false; +} - template inline std::string _parse_number(input& in) { - std::string num_str; - while (1) { - int ch = in.getc(); - if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' - || ch == 'e' || ch == 'E') { - num_str.push_back(ch); - } else if (ch == '.') { +template +inline bool _parse_array(Context& ctx, input& in) +{ + if(!ctx.parse_array_start()) + { + return false; + } + size_t idx = 0; + if(in.expect(']')) + { + return ctx.parse_array_stop(idx); + } + do + { + if(!ctx.parse_array_item(in, idx)) + { + return false; + } + idx++; + } while(in.expect(',')); + return in.expect(']') && ctx.parse_array_stop(idx); +} + +template +inline bool _parse_object(Context& ctx, input& in) +{ + if(!ctx.parse_object_start()) + { + return false; + } + if(in.expect('}')) + { + return true; + } + do + { + std::string key; + if(!in.expect('"') || !_parse_string(key, in) || !in.expect(':')) + { + return false; + } + if(!ctx.parse_object_item(in, key)) + { + return false; + } + } while(in.expect(',')); + return in.expect('}'); +} + +template +inline std::string _parse_number(input& in) +{ + std::string num_str; + while(1) + { + int ch = in.getc(); + if(('0' <= ch && ch <= '9') || ch == '+' || ch == '-' || ch == 'e' || ch == 'E') + { + num_str.push_back(ch); + } + else if(ch == '.') + { #if PICOJSON_USE_LOCALE - num_str += localeconv()->decimal_point; + num_str += localeconv()->decimal_point; #else - num_str.push_back('.'); + num_str.push_back('.'); #endif - } else { - in.ungetc(); - break; - } } - return num_str; + else + { + in.ungetc(); + break; + } } + return num_str; +} - template inline bool _parse(Context& ctx, input& in) { - in.skip_ws(); - int ch = in.getc(); - switch (ch) { -#define IS(ch, text, op) case ch: \ - if (in.match(text) && op) { \ - return true; \ - } else { \ - return false; \ - } - IS('n', "ull", ctx.set_null()); - IS('f', "alse", ctx.set_bool(false)); - IS('t', "rue", ctx.set_bool(true)); +template +inline bool _parse(Context& ctx, input& in) +{ + in.skip_ws(); + int ch = in.getc(); + switch(ch) + { +#define IS(ch, text, op) \ + case ch: \ + if(in.match(text) && op) \ + { \ + return true; \ + } \ + else \ + { \ + return false; \ + } + IS('n', "ull", ctx.set_null()); + IS('f', "alse", ctx.set_bool(false)); + IS('t', "rue", ctx.set_bool(true)); #undef IS case '"': return ctx.parse_string(in); @@ -837,237 +1072,346 @@ namespace picojson { case '{': return _parse_object(ctx, in); default: - if (('0' <= ch && ch <= '9') || ch == '-') { + if(('0' <= ch && ch <= '9') || ch == '-') + { double f; - char *endp; - in.ungetc(); + char* endp; + in.ungetc(); std::string num_str = _parse_number(in); - if (num_str.empty()) { + if(num_str.empty()) + { return false; } #ifdef PICOJSON_USE_INT64 { - errno = 0; + errno = 0; intmax_t ival = strtoimax(num_str.c_str(), &endp, 10); - if (errno == 0 - && std::numeric_limits::min() <= ival - && ival <= std::numeric_limits::max() - && endp == num_str.c_str() + num_str.size()) { + if(errno == 0 && std::numeric_limits::min() <= ival && ival <= std::numeric_limits::max() && endp == num_str.c_str() + num_str.size()) + { ctx.set_int64(ival); return true; } } #endif f = strtod(num_str.c_str(), &endp); - if (endp == num_str.c_str() + num_str.size()) { + if(endp == num_str.c_str() + num_str.size()) + { ctx.set_number(f); return true; } return false; } break; - } - in.ungetc(); - return false; } + in.ungetc(); + return false; +} - class deny_parse_context { - public: - bool set_null() { return false; } - bool set_bool(bool) { return false; } +class deny_parse_context +{ +public: + bool set_null() + { + return false; + } + bool set_bool(bool) + { + return false; + } #ifdef PICOJSON_USE_INT64 - bool set_int64(int64_t) { return false; } + bool set_int64(int64_t) + { + return false; + } #endif - bool set_number(double) { return false; } - template bool parse_string(input&) { return false; } - bool parse_array_start() { return false; } - template bool parse_array_item(input&, size_t) { - return false; - } - bool parse_array_stop(size_t) { return false; } - bool parse_object_start() { return false; } - template bool parse_object_item(input&, const std::string&) { - return false; - } - }; + bool set_number(double) + { + return false; + } + template + bool parse_string(input&) + { + return false; + } + bool parse_array_start() + { + return false; + } + template + bool parse_array_item(input&, size_t) + { + return false; + } + bool parse_array_stop(size_t) + { + return false; + } + bool parse_object_start() + { + return false; + } + template + bool parse_object_item(input&, const std::string&) + { + return false; + } +}; - class default_parse_context { - protected: - value* out_; - public: - default_parse_context(value* out) : out_(out) {} - bool set_null() { - *out_ = value(); - return true; - } - bool set_bool(bool b) { - *out_ = value(b); - return true; - } +class default_parse_context +{ +protected: + value* out_; + +public: + default_parse_context(value* out) + : out_(out) + { + } + bool set_null() + { + *out_ = value(); + return true; + } + bool set_bool(bool b) + { + *out_ = value(b); + return true; + } #ifdef PICOJSON_USE_INT64 - bool set_int64(int64_t i) { - *out_ = value(i); - return true; - } + bool set_int64(int64_t i) + { + *out_ = value(i); + return true; + } #endif - bool set_number(double f) { - *out_ = value(f); - return true; - } - template bool parse_string(input& in) { - *out_ = value(string_type, false); - return _parse_string(out_->get(), in); - } - bool parse_array_start() { - *out_ = value(array_type, false); - return true; - } - template bool parse_array_item(input& in, size_t) { - array& a = out_->get(); - a.push_back(value()); - default_parse_context ctx(&a.back()); - return _parse(ctx, in); - } - bool parse_array_stop(size_t) { return true; } - bool parse_object_start() { - *out_ = value(object_type, false); - return true; - } - template bool parse_object_item(input& in, const std::string& key) { - object& o = out_->get(); - default_parse_context ctx(&o[key]); - return _parse(ctx, in); + bool set_number(double f) + { + *out_ = value(f); + return true; + } + template + bool parse_string(input& in) + { + *out_ = value(string_type, false); + return _parse_string(out_->get(), in); + } + bool parse_array_start() + { + *out_ = value(array_type, false); + return true; + } + template + bool parse_array_item(input& in, size_t) + { + array& a = out_->get(); + a.push_back(value()); + default_parse_context ctx(&a.back()); + return _parse(ctx, in); + } + bool parse_array_stop(size_t) + { + return true; + } + bool parse_object_start() + { + *out_ = value(object_type, false); + return true; + } + template + bool parse_object_item(input& in, const std::string& key) + { + object& o = out_->get(); + default_parse_context ctx(&o[key]); + return _parse(ctx, in); + } + +private: + default_parse_context(const default_parse_context&); + default_parse_context& operator=(const default_parse_context&); +}; + +class null_parse_context +{ +public: + struct dummy_str + { + void push_back(int) + { } - private: - default_parse_context(const default_parse_context&); - default_parse_context& operator=(const default_parse_context&); }; - class null_parse_context { - public: - struct dummy_str { - void push_back(int) {} - }; - public: - null_parse_context() {} - bool set_null() { return true; } - bool set_bool(bool) { return true; } +public: + null_parse_context() + { + } + bool set_null() + { + return true; + } + bool set_bool(bool) + { + return true; + } #ifdef PICOJSON_USE_INT64 - bool set_int64(int64_t) { return true; } + bool set_int64(int64_t) + { + return true; + } #endif - bool set_number(double) { return true; } - template bool parse_string(input& in) { - dummy_str s; - return _parse_string(s, in); - } - bool parse_array_start() { return true; } - template bool parse_array_item(input& in, size_t) { - return _parse(*this, in); - } - bool parse_array_stop(size_t) { return true; } - bool parse_object_start() { return true; } - template bool parse_object_item(input& in, const std::string&) { - return _parse(*this, in); - } - private: - null_parse_context(const null_parse_context&); - null_parse_context& operator=(const null_parse_context&); - }; + bool set_number(double) + { + return true; + } + template + bool parse_string(input& in) + { + dummy_str s; + return _parse_string(s, in); + } + bool parse_array_start() + { + return true; + } + template + bool parse_array_item(input& in, size_t) + { + return _parse(*this, in); + } + bool parse_array_stop(size_t) + { + return true; + } + bool parse_object_start() + { + return true; + } + template + bool parse_object_item(input& in, const std::string&) + { + return _parse(*this, in); + } + +private: + null_parse_context(const null_parse_context&); + null_parse_context& operator=(const null_parse_context&); +}; + +// obsolete, use the version below +template +inline std::string parse(value& out, Iter& pos, const Iter& last) +{ + std::string err; + pos = parse(out, pos, last, &err); + return err; +} - // obsolete, use the version below - template inline std::string parse(value& out, Iter& pos, const Iter& last) { - std::string err; - pos = parse(out, pos, last, &err); - return err; - } - - template inline Iter _parse(Context& ctx, const Iter& first, const Iter& last, std::string* err) { - input in(first, last); - if (! _parse(ctx, in) && err != NULL) { - char buf[64]; - SNPRINTF(buf, sizeof(buf), "syntax error at line %d near: ", in.line()); - *err = buf; - while (1) { - int ch = in.getc(); - if (ch == -1 || ch == '\n') { - break; - } else if (ch >= ' ') { - err->push_back(ch); - } +template +inline Iter _parse(Context& ctx, const Iter& first, const Iter& last, std::string* err) +{ + input in(first, last); + if(!_parse(ctx, in) && err != NULL) + { + char buf[64]; + SNPRINTF(buf, sizeof(buf), "syntax error at line %d near: ", in.line()); + *err = buf; + while(1) + { + int ch = in.getc(); + if(ch == -1 || ch == '\n') + { + break; + } + else if(ch >= ' ') + { + err->push_back(ch); } } - return in.cur(); } + return in.cur(); +} - template inline Iter parse(value& out, const Iter& first, const Iter& last, std::string* err) { - default_parse_context ctx(&out); - return _parse(ctx, first, last, err); - } +template +inline Iter parse(value& out, const Iter& first, const Iter& last, std::string* err) +{ + default_parse_context ctx(&out); + return _parse(ctx, first, last, err); +} - inline std::string parse(value& out, const std::string& s) { - std::string err; - parse(out, s.begin(), s.end(), &err); - return err; - } +inline std::string parse(value& out, const std::string& s) +{ + std::string err; + parse(out, s.begin(), s.end(), &err); + return err; +} - inline std::string parse(value& out, std::istream& is) { - std::string err; - parse(out, std::istreambuf_iterator(is.rdbuf()), - std::istreambuf_iterator(), &err); - return err; - } +inline std::string parse(value& out, std::istream& is) +{ + std::string err; + parse(out, std::istreambuf_iterator(is.rdbuf()), std::istreambuf_iterator(), &err); + return err; +} - template struct last_error_t { - static std::string s; - }; - template std::string last_error_t::s; +template +struct last_error_t +{ + static std::string s; +}; +template +std::string last_error_t::s; - inline void set_last_error(const std::string& s) { - last_error_t::s = s; - } +inline void set_last_error(const std::string& s) +{ + last_error_t::s = s; +} - inline const std::string& get_last_error() { - return last_error_t::s; - } +inline const std::string& get_last_error() +{ + return last_error_t::s; +} - inline bool operator==(const value& x, const value& y) { - if (x.is()) - return y.is(); -#define PICOJSON_CMP(type) \ - if (x.is()) \ - return y.is() && x.get() == y.get() - PICOJSON_CMP(bool); - PICOJSON_CMP(double); - PICOJSON_CMP(std::string); - PICOJSON_CMP(array); - PICOJSON_CMP(object); +inline bool operator==(const value& x, const value& y) +{ + if(x.is()) + return y.is(); +#define PICOJSON_CMP(type) \ + if(x.is()) \ + return y.is() && x.get() == y.get() + PICOJSON_CMP(bool); + PICOJSON_CMP(double); + PICOJSON_CMP(std::string); + PICOJSON_CMP(array); + PICOJSON_CMP(object); #undef PICOJSON_CMP - PICOJSON_ASSERT(0); + PICOJSON_ASSERT(0); #ifdef _MSC_VER - __assume(0); + __assume(0); #endif - return false; - } + return false; +} - inline bool operator!=(const value& x, const value& y) { - return ! (x == y); - } +inline bool operator!=(const value& x, const value& y) +{ + return !(x == y); } +} // namespace picojson #if !PICOJSON_USE_RVALUE_REFERENCE -namespace std { - template<> inline void swap(picojson::value& x, picojson::value& y) - { - x.swap(y); - } +namespace std +{ +template<> +inline void swap(picojson::value& x, picojson::value& y) +{ + x.swap(y); } +} // namespace std #endif inline std::istream& operator>>(std::istream& is, picojson::value& x) { picojson::set_last_error(std::string()); std::string err = picojson::parse(x, is); - if (! err.empty()) { + if(!err.empty()) + { picojson::set_last_error(err); is.setstate(std::ios::failbit); } @@ -1080,7 +1424,7 @@ inline std::ostream& operator<<(std::ostream& os, const picojson::value& x) return os; } #ifdef _MSC_VER - #pragma warning(pop) +#pragma warning(pop) #endif #endif diff --git a/examples/frame-callback/frame-callback-example.cpp b/examples/frame-callback/frame-callback-example.cpp index 6ec5cab..fa045fb 100644 --- a/examples/frame-callback/frame-callback-example.cpp +++ b/examples/frame-callback/frame-callback-example.cpp @@ -27,15 +27,15 @@ using namespace Dali::Toolkit; namespace { -const char * IMAGE_NAME = DEMO_IMAGE_DIR "application-icon-1.png"; +const char* IMAGE_NAME = DEMO_IMAGE_DIR "application-icon-1.png"; -const char * TEXT_ENABLED( "FrameCallback: ON" ); -const char * TEXT_DISABLED( "FrameCallback: OFF" ); -Vector4 TEXT_COLOR_ENABLED( Color::BLACK ); -Vector4 TEXT_COLOR_DISABLED( Color::RED ); +const char* TEXT_ENABLED("FrameCallback: ON"); +const char* TEXT_DISABLED("FrameCallback: OFF"); +Vector4 TEXT_COLOR_ENABLED(Color::BLACK); +Vector4 TEXT_COLOR_DISABLED(Color::RED); -float ANIMATION_TIME( 4.0f ); -float ANIMATION_PROGRESS_MULTIPLIER( 0.02f ); +float ANIMATION_TIME(4.0f); +float ANIMATION_PROGRESS_MULTIPLIER(0.02f); } // unnamed namespace /** @@ -48,24 +48,22 @@ float ANIMATION_PROGRESS_MULTIPLIER( 0.02f ); class FrameCallbackController : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application The application. */ - FrameCallbackController( Application& application ) - : mApplication( application ), + FrameCallbackController(Application& application) + : mApplication(application), mFrameCallback(), mTextLabel(), mTapDetector(), - mFrameCallbackEnabled( false ) + mFrameCallbackEnabled(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &FrameCallbackController::Create ); + mApplication.InitSignal().Connect(this, &FrameCallbackController::Create); } private: - /** * @brief Creates the scene. * @@ -74,63 +72,63 @@ private: * Set the FrameCallbackInterface on the window. * Tapping on the window enables/disables the FrameCallback. */ - void Create( Application& application ) + void Create(Application& application) { // Set the window background color and connect to the window's key signal to allow Back and Escape to exit. Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); - window.KeyEventSignal().Connect( this, &FrameCallbackController::OnKeyEvent ); + window.SetBackgroundColor(Color::WHITE); + window.KeyEventSignal().Connect(this, &FrameCallbackController::OnKeyEvent); // Notify mFrameCallback about the window width. // Can call methods in mFrameCallback directly as we have not set it on the window yet. Vector2 windowSize = window.GetSize(); - mFrameCallback.SetWindowWidth( windowSize.width ); + mFrameCallback.SetWindowWidth(windowSize.width); // Detect taps on the root layer. mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach( window.GetRootLayer() ); - mTapDetector.DetectedSignal().Connect( this, &FrameCallbackController::OnTap ); + mTapDetector.Attach(window.GetRootLayer()); + mTapDetector.DetectedSignal().Connect(this, &FrameCallbackController::OnTap); // Create some key-frames to be used by all animations. KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add( 0.0f, 0.0f ); - keyFrames.Add( 0.25f, windowSize.width * 0.5f ); - keyFrames.Add( 0.75f, -windowSize.width * 0.5f ); - keyFrames.Add( 1.0f, 0.0f ); + keyFrames.Add(0.0f, 0.0f); + keyFrames.Add(0.25f, windowSize.width * 0.5f); + keyFrames.Add(0.75f, -windowSize.width * 0.5f); + keyFrames.Add(1.0f, 0.0f); float yPos = 0.0f; - for( int i = 0; yPos < windowSize.height; ++i ) + for(int i = 0; yPos < windowSize.height; ++i) { - ImageView imageView = ImageView::New( IMAGE_NAME ); - imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - imageView.SetProperty( Actor::Property::POSITION_Y, yPos ); + ImageView imageView = ImageView::New(IMAGE_NAME); + imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + imageView.SetProperty(Actor::Property::POSITION_Y, yPos); yPos += imageView.GetNaturalSize().height; // Add the ID of the created ImageView to mFrameCallback. // Again, can call methods in mFrameCallback directly as we have not set it on the window yet. - mFrameCallback.AddId( imageView.GetProperty< int >( Actor::Property::ID ) ); + mFrameCallback.AddId(imageView.GetProperty(Actor::Property::ID)); - window.Add( imageView ); + window.Add(imageView); // Create an animation and set the progress so that each image starts at a different point. - Animation animation = Animation::New( ANIMATION_TIME ); - animation.SetLooping( true ); - animation.AnimateBetween( Property( imageView, Actor::Property::POSITION_X ), keyFrames ); - animation.SetCurrentProgress( std::min( 1.0f, ANIMATION_PROGRESS_MULTIPLIER * i ) ); + Animation animation = Animation::New(ANIMATION_TIME); + animation.SetLooping(true); + animation.AnimateBetween(Property(imageView, Actor::Property::POSITION_X), keyFrames); + animation.SetCurrentProgress(std::min(1.0f, ANIMATION_PROGRESS_MULTIPLIER * i)); animation.Play(); } // Create a text-label to display whether the FrameCallback is enabled/disabled. - mTextLabel = TextLabel::New( TEXT_ENABLED ); - mTextLabel.SetProperty( TextLabel::Property::TEXT_COLOR, TEXT_COLOR_ENABLED ); - mTextLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - window.Add( mTextLabel ); + mTextLabel = TextLabel::New(TEXT_ENABLED); + mTextLabel.SetProperty(TextLabel::Property::TEXT_COLOR, TEXT_COLOR_ENABLED); + mTextLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + window.Add(mTextLabel); // Set the FrameCallbackInterface on the root layer. - DevelStage::AddFrameCallback( Stage::GetCurrent(), mFrameCallback, window.GetRootLayer() ); + DevelStage::AddFrameCallback(Stage::GetCurrent(), mFrameCallback, window.GetRootLayer()); mFrameCallbackEnabled = true; } @@ -139,19 +137,19 @@ private: * * Toggle enabling/disabling of the FrameCallbackInterface */ - void OnTap( Actor actor, const TapGesture& /* tap */ ) + void OnTap(Actor actor, const TapGesture& /* tap */) { - if( mFrameCallbackEnabled ) + if(mFrameCallbackEnabled) { - DevelStage::RemoveFrameCallback( Stage::GetCurrent(), mFrameCallback ); - mTextLabel.SetProperty( TextLabel::Property::TEXT, TEXT_DISABLED ); - mTextLabel.SetProperty( TextLabel::Property::TEXT_COLOR, TEXT_COLOR_DISABLED ); + DevelStage::RemoveFrameCallback(Stage::GetCurrent(), mFrameCallback); + mTextLabel.SetProperty(TextLabel::Property::TEXT, TEXT_DISABLED); + mTextLabel.SetProperty(TextLabel::Property::TEXT_COLOR, TEXT_COLOR_DISABLED); } else { - DevelStage::AddFrameCallback( Stage::GetCurrent(), mFrameCallback, actor ); - mTextLabel.SetProperty( TextLabel::Property::TEXT, TEXT_ENABLED ); - mTextLabel.SetProperty( TextLabel::Property::TEXT_COLOR, TEXT_COLOR_ENABLED ); + DevelStage::AddFrameCallback(Stage::GetCurrent(), mFrameCallback, actor); + mTextLabel.SetProperty(TextLabel::Property::TEXT, TEXT_ENABLED); + mTextLabel.SetProperty(TextLabel::Property::TEXT_COLOR, TEXT_COLOR_ENABLED); } mFrameCallbackEnabled = !mFrameCallbackEnabled; @@ -163,11 +161,11 @@ private: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -175,17 +173,17 @@ private: } private: - Application& mApplication; ///< A reference to the application instance. - FrameCallback mFrameCallback; ///< An instance of our implementation of the FrameCallbackInterface. - TextLabel mTextLabel; ///< Text label which shows whether the frame-callback is enabled/disabled. - TapGestureDetector mTapDetector; ///< Tap detector to enable/disable the FrameCallbackInterface. - bool mFrameCallbackEnabled; ///< Stores whether the FrameCallbackInterface is enabled/disabled. + Application& mApplication; ///< A reference to the application instance. + FrameCallback mFrameCallback; ///< An instance of our implementation of the FrameCallbackInterface. + TextLabel mTextLabel; ///< Text label which shows whether the frame-callback is enabled/disabled. + TapGestureDetector mTapDetector; ///< Tap detector to enable/disable the FrameCallbackInterface. + bool mFrameCallbackEnabled; ///< Stores whether the FrameCallbackInterface is enabled/disabled. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - FrameCallbackController controller( application ); + Application application = Application::New(&argc, &argv); + FrameCallbackController controller(application); application.MainLoop(); return 0; } diff --git a/examples/frame-callback/frame-callback.cpp b/examples/frame-callback/frame-callback.cpp index f2c6a30..88c66f6 100644 --- a/examples/frame-callback/frame-callback.cpp +++ b/examples/frame-callback/frame-callback.cpp @@ -23,47 +23,47 @@ using namespace std; FrameCallback::FrameCallback() : mActorIdContainer(), - windowHalfWidth( 0.0f ) + windowHalfWidth(0.0f) { } -void FrameCallback::SetWindowWidth( float windowWidth ) +void FrameCallback::SetWindowWidth(float windowWidth) { windowHalfWidth = windowWidth * 0.5f; } -void FrameCallback::AddId( uint32_t id ) +void FrameCallback::AddId(uint32_t id) { - mActorIdContainer.PushBack( id ); + mActorIdContainer.PushBack(id); } -void FrameCallback::Update( Dali::UpdateProxy& updateProxy, float /* elapsedSeconds */ ) +void FrameCallback::Update(Dali::UpdateProxy& updateProxy, float /* elapsedSeconds */) { // Go through Actor ID container and check if we've hit the sides. - for( auto&& i : mActorIdContainer ) + for(auto&& i : mActorIdContainer) { Vector3 position; Vector3 size; - if( updateProxy.GetPositionAndSize( i, position, size ) ) // Retrieve the position and size using the Actor ID. + if(updateProxy.GetPositionAndSize(i, position, size)) // Retrieve the position and size using the Actor ID. { float halfWidthPoint = windowHalfWidth - size.width * 0.5f; - float xTranslation = abs( position.x ); - if( xTranslation > halfWidthPoint ) + float xTranslation = abs(position.x); + if(xTranslation > halfWidthPoint) { // Actor has hit the edge, adjust the size accordingly. float adjustment = xTranslation - halfWidthPoint; size.width += adjustment * SIZE_MULTIPLIER; size.height += adjustment * SIZE_MULTIPLIER; - updateProxy.SetSize( i, size ); // Set the size using the UpdateProxy. + updateProxy.SetSize(i, size); // Set the size using the UpdateProxy. } // Retrieve the actor's position and set make it more transparent the closer it is to the middle. Vector4 color; - if( updateProxy.GetColor( i, color ) ) + if(updateProxy.GetColor(i, color)) { color.a = xTranslation / halfWidthPoint; - updateProxy.SetColor( i, color ); + updateProxy.SetColor(i, color); } } } diff --git a/examples/frame-callback/frame-callback.h b/examples/frame-callback/frame-callback.h index d4f49db..e41db59 100644 --- a/examples/frame-callback/frame-callback.h +++ b/examples/frame-callback/frame-callback.h @@ -32,7 +32,6 @@ class FrameCallback : public Dali::FrameCallbackInterface { public: - /** * @brief Constructor. */ @@ -42,27 +41,25 @@ public: * @brief Sets the window width. * @param[in] windowWidth The window width. */ - void SetWindowWidth( float windowWidth ); + void SetWindowWidth(float windowWidth); /** * @brief The actor with the specified ID will be changed when Update() is called. * @param[in] id Actor ID of actor which should be changed by the FrameCallback. */ - void AddId( uint32_t id ); + void AddId(uint32_t id); private: - /** * @brief Called when every frame is updated. * @param[in] updateProxy Used to set the world-matrix and sizes. * @param[in] elapsedSeconds Time elapsed time since the last frame (in seconds) */ - virtual void Update( Dali::UpdateProxy& updateProxy, float elapsedSeconds ); + virtual void Update(Dali::UpdateProxy& updateProxy, float elapsedSeconds); private: - - Dali::Vector< uint32_t > mActorIdContainer; ///< Container of Actor IDs. - float windowHalfWidth; ///< Half the width of the window. Center is 0,0 in the world matrix. + Dali::Vector mActorIdContainer; ///< Container of Actor IDs. + float windowHalfWidth; ///< Half the width of the window. Center is 0,0 in the world matrix. constexpr static float SIZE_MULTIPLIER = 2.0f; ///< Multiplier for the size to set as the actors hit the edge. }; diff --git a/examples/gaussian-blur-view/gaussian-blur-view-example.cpp b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp index 00aeb51..e9ff1cc 100644 --- a/examples/gaussian-blur-view/gaussian-blur-view-example.cpp +++ b/examples/gaussian-blur-view/gaussian-blur-view-example.cpp @@ -21,16 +21,15 @@ #include using namespace Dali; -using Dali::Toolkit::TextLabel; using Dali::Toolkit::GaussianBlurView; +using Dali::Toolkit::TextLabel; namespace { +const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "lake_front.jpg"); +const float BACKGROUND_IMAGE_WIDTH = 2048.0f; -const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" ); -const float BACKGROUND_IMAGE_WIDTH = 2048.0f; - -} +} // namespace /** * This example shows a scrolling background image which can be blurred (on/off) by tapping the screen @@ -38,102 +37,100 @@ const float BACKGROUND_IMAGE_WIDTH = 2048.0f; class GaussianBlurViewExample : public ConnectionTracker { public: - - GaussianBlurViewExample( Application& application ) - : mApplication( application ), - mExcessWidth( 0.0f ), - mStrength( 1.0f ), - mActivate( false ) + GaussianBlurViewExample(Application& application) + : mApplication(application), + mExcessWidth(0.0f), + mStrength(1.0f), + mActivate(false) { - mApplication.InitSignal().Connect( this, &GaussianBlurViewExample::Create ); + mApplication.InitSignal().Connect(this, &GaussianBlurViewExample::Create); } ~GaussianBlurViewExample() = default; private: - - void Create( Application& application ) + void Create(Application& application) { - auto window = application.GetWindow(); + auto window = application.GetWindow(); Vector2 windowSize = window.GetSize(); window.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent); - mImageView = Toolkit::ImageView::New( BACKGROUND_IMAGE ); - mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mImageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mImageView = Toolkit::ImageView::New(BACKGROUND_IMAGE); + mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - float excessWidth = std::max( 0.0f, (BACKGROUND_IMAGE_WIDTH - windowSize.width) * 0.5f ); + float excessWidth = std::max(0.0f, (BACKGROUND_IMAGE_WIDTH - windowSize.width) * 0.5f); - if( excessWidth > 0.0f ) + if(excessWidth > 0.0f) { // Move background image to show GaussianBlurView activity float pixelsPerSecond = 10.0f; - float duration = excessWidth / pixelsPerSecond; - float qDuration = duration * 0.25f; + float duration = excessWidth / pixelsPerSecond; + float qDuration = duration * 0.25f; - mAnimation = Animation::New( duration ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), excessWidth, TimePeriod(0.0f , qDuration) ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(qDuration , qDuration) ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), -excessWidth, TimePeriod(2.0f*qDuration, qDuration) ); - mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(3.0f*qDuration, qDuration) ); + mAnimation = Animation::New(duration); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), excessWidth, TimePeriod(0.0f, qDuration)); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(qDuration, qDuration)); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), -excessWidth, TimePeriod(2.0f * qDuration, qDuration)); + mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(3.0f * qDuration, qDuration)); - mAnimation.SetLooping( true ); + mAnimation.SetLooping(true); mAnimation.Play(); } Layer onTop = Layer::New(); - onTop.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - onTop.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - onTop.SetProperty( Actor::Property::SIZE, windowSize ); - window.Add( onTop ); + onTop.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + onTop.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + onTop.SetProperty(Actor::Property::SIZE, windowSize); + window.Add(onTop); onTop.RaiseToTop(); - mOnLabel = TextLabel::New( "Blur ON" ); - mOnLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mOnLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::GREEN ); - mOnLabel.SetProperty( Actor::Property::VISIBLE, false ); - onTop.Add( mOnLabel ); + mOnLabel = TextLabel::New("Blur ON"); + mOnLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mOnLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::GREEN); + mOnLabel.SetProperty(Actor::Property::VISIBLE, false); + onTop.Add(mOnLabel); - mOffLabel = TextLabel::New( "Blur OFF" ); - mOffLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mOffLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mOffLabel.SetProperty( Actor::Property::VISIBLE, true ); - onTop.Add( mOffLabel ); + mOffLabel = TextLabel::New("Blur OFF"); + mOffLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mOffLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + mOffLabel.SetProperty(Actor::Property::VISIBLE, true); + onTop.Add(mOffLabel); - mGaussianBlurView = GaussianBlurView::New( 30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false ); - mGaussianBlurView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mGaussianBlurView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mGaussianBlurView.SetProperty( Actor::Property::SIZE, windowSize ); - window.Add( mGaussianBlurView ); + mGaussianBlurView = GaussianBlurView::New(30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false); + mGaussianBlurView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mGaussianBlurView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mGaussianBlurView.SetProperty(Actor::Property::SIZE, windowSize); + window.Add(mGaussianBlurView); - mGaussianBlurView.Add( mImageView ); - mGaussianBlurView.SetProperty( mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength ); + mGaussianBlurView.Add(mImageView); + mGaussianBlurView.SetProperty(mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength); - window.GetRootLayer().TouchedSignal().Connect( this, &GaussianBlurViewExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &GaussianBlurViewExample::OnTouch); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - const PointState::Type state = touch.GetState( 0 ); + const PointState::Type state = touch.GetState(0); - if( PointState::DOWN == state ) + if(PointState::DOWN == state) { - if( !mActivate ) + if(!mActivate) { mActivate = true; mGaussianBlurView.Activate(); - mOnLabel.SetProperty( Actor::Property::VISIBLE, true ); - mOffLabel.SetProperty( Actor::Property::VISIBLE, false ); + mOnLabel.SetProperty(Actor::Property::VISIBLE, true); + mOffLabel.SetProperty(Actor::Property::VISIBLE, false); } else { mActivate = false; mGaussianBlurView.Deactivate(); - mOnLabel.SetProperty( Actor::Property::VISIBLE, false ); - mOffLabel.SetProperty( Actor::Property::VISIBLE, true ); + mOnLabel.SetProperty(Actor::Property::VISIBLE, false); + mOffLabel.SetProperty(Actor::Property::VISIBLE, true); } } @@ -144,7 +141,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -152,8 +149,7 @@ private: } private: - - Application& mApplication; + Application& mApplication; Toolkit::ImageView mImageView; @@ -170,11 +166,11 @@ private: bool mActivate; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - GaussianBlurViewExample test( application ); + GaussianBlurViewExample test(application); application.MainLoop(); diff --git a/examples/gestures/gesture-example.cpp b/examples/gestures/gesture-example.cpp index d04c63e..129a1b7 100644 --- a/examples/gestures/gesture-example.cpp +++ b/examples/gestures/gesture-example.cpp @@ -25,47 +25,41 @@ using namespace std; namespace { -const Property::Value BACKGROUND -{ - { Toolkit::Visual::Property::TYPE, Visual::GRADIENT }, - { GradientVisual::Property::STOP_COLOR, Property::Array{ Vector4( 167.0f, 207.0f, 223.0f, 255.0f ) / 255.0f, - Vector4( 0.0f, 64.0f, 137.0f, 255.0f ) / 255.0f } }, - { GradientVisual::Property::START_POSITION, Vector2( 0.0f, -0.5f ) }, - { GradientVisual::Property::END_POSITION, Vector2( 0.0f, 0.5f ) } -}; - -const Property::Value CONTROL_BACKGROUND -{ - { Toolkit::Visual::Property::TYPE, Visual::GRADIENT }, - { GradientVisual::Property::STOP_COLOR, Property::Array{ Vector4( 234.0f, 185.0f, 45.0f, 255.0f ) / 255.0f, - Vector4( 199.0f, 152.0f, 16.0f, 255.0f ) / 255.0f } }, - { GradientVisual::Property::CENTER, Vector2::ZERO }, - { GradientVisual::Property::RADIUS, 0.5f } -}; - -const float HELP_ANIMATION_DURATION( 25.0f ); -const float HELP_ANIMATION_SEGMENT_TIME( 5.0f ); -const float HELP_ANIMATION_TRANSITION_DURATION( 0.75f ); -const Vector2 HELP_TEXT_POSITION_MULTIPLIER( 0.25f, 0.13f ); - -const float SHAKY_ANIMATION_DURATION( 0.1f ); -const float SHAKY_ANIMATION_SEGMENT_TIME( 0.05f ); -const float SHAKY_ANIMATION_ANGLE( 1.0f ); - -const float TOUCH_MODE_ANIMATION_DURATION( 0.1f ); -const Vector4 TOUCH_MODE_COLOR( 1.0f, 0.7f, 0.7f, 1.0f ); - -const float PAN_MODE_CHANGE_ANIMATION_DURATION( 0.25f ); -const Vector3 PAN_MODE_START_ANIMATION_SCALE( 1.2f, 1.2f, 1.0f ); -const Vector3 PAN_MODE_END_ANIMATION_SCALE( 0.8f, 0.8f, 1.0f ); - -const float TAP_ANIMATION_DURATION( 0.5f ); -const Vector4 TAP_ANIMATION_COLOR( 0.8f, 0.5, 0.2f, 0.6f ); - -const Vector3 MINIMUM_SCALE( Vector3::ONE ); -const Vector3 MAXIMUM_SCALE( Vector3::ONE * 2.0f ); -const float SCALE_BACK_ANIMATION_DURATION( 0.25f ); -const float ROTATE_BACK_ANIMATION_DURATION( 0.25f ); +const Property::Value BACKGROUND{ + {Toolkit::Visual::Property::TYPE, Visual::GRADIENT}, + {GradientVisual::Property::STOP_COLOR, Property::Array{Vector4(167.0f, 207.0f, 223.0f, 255.0f) / 255.0f, Vector4(0.0f, 64.0f, 137.0f, 255.0f) / 255.0f}}, + {GradientVisual::Property::START_POSITION, Vector2(0.0f, -0.5f)}, + {GradientVisual::Property::END_POSITION, Vector2(0.0f, 0.5f)}}; + +const Property::Value CONTROL_BACKGROUND{ + {Toolkit::Visual::Property::TYPE, Visual::GRADIENT}, + {GradientVisual::Property::STOP_COLOR, Property::Array{Vector4(234.0f, 185.0f, 45.0f, 255.0f) / 255.0f, Vector4(199.0f, 152.0f, 16.0f, 255.0f) / 255.0f}}, + {GradientVisual::Property::CENTER, Vector2::ZERO}, + {GradientVisual::Property::RADIUS, 0.5f}}; + +const float HELP_ANIMATION_DURATION(25.0f); +const float HELP_ANIMATION_SEGMENT_TIME(5.0f); +const float HELP_ANIMATION_TRANSITION_DURATION(0.75f); +const Vector2 HELP_TEXT_POSITION_MULTIPLIER(0.25f, 0.13f); + +const float SHAKY_ANIMATION_DURATION(0.1f); +const float SHAKY_ANIMATION_SEGMENT_TIME(0.05f); +const float SHAKY_ANIMATION_ANGLE(1.0f); + +const float TOUCH_MODE_ANIMATION_DURATION(0.1f); +const Vector4 TOUCH_MODE_COLOR(1.0f, 0.7f, 0.7f, 1.0f); + +const float PAN_MODE_CHANGE_ANIMATION_DURATION(0.25f); +const Vector3 PAN_MODE_START_ANIMATION_SCALE(1.2f, 1.2f, 1.0f); +const Vector3 PAN_MODE_END_ANIMATION_SCALE(0.8f, 0.8f, 1.0f); + +const float TAP_ANIMATION_DURATION(0.5f); +const Vector4 TAP_ANIMATION_COLOR(0.8f, 0.5, 0.2f, 0.6f); + +const Vector3 MINIMUM_SCALE(Vector3::ONE); +const Vector3 MAXIMUM_SCALE(Vector3::ONE * 2.0f); +const float SCALE_BACK_ANIMATION_DURATION(0.25f); +const float ROTATE_BACK_ANIMATION_DURATION(0.25f); /** * @brief Shows the given string between the given start and end times. @@ -78,28 +72,28 @@ const float ROTATE_BACK_ANIMATION_DURATION( 0.25f ); * @param[in] startTime When to start the animators * @param[in] endTime When to end the animators */ -void AddHelpInfo( const std::string&& string, const Vector2& windowSize, Actor parent, Animation animation, float startTime, float endTime ) +void AddHelpInfo(const std::string&& string, const Vector2& windowSize, Actor parent, Animation animation, float startTime, float endTime) { - Actor text = TextLabel::New( std::move( string ) ); - Vector3 position( windowSize * HELP_TEXT_POSITION_MULTIPLIER ); + Actor text = TextLabel::New(std::move(string)); + Vector3 position(windowSize * HELP_TEXT_POSITION_MULTIPLIER); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - text.SetProperty( Actor::Property::POSITION, position ); - text.SetProperty( Actor::Property::OPACITY, 0.0f ); - text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, Text::HorizontalAlignment::CENTER ); - text.SetProperty( TextLabel::Property::MULTI_LINE, true ); - parent.Add( text ); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + text.SetProperty(Actor::Property::POSITION, position); + text.SetProperty(Actor::Property::OPACITY, 0.0f); + text.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Text::HorizontalAlignment::CENTER); + text.SetProperty(TextLabel::Property::MULTI_LINE, true); + parent.Add(text); // Animate IN - TimePeriod timePeriod( startTime, HELP_ANIMATION_TRANSITION_DURATION ); - animation.AnimateTo( Property( text, Actor::Property::COLOR_ALPHA ), 1.0f, timePeriod ); - animation.AnimateBy( Property( text, Actor::Property::POSITION_X ), -position.x, timePeriod ); + TimePeriod timePeriod(startTime, HELP_ANIMATION_TRANSITION_DURATION); + animation.AnimateTo(Property(text, Actor::Property::COLOR_ALPHA), 1.0f, timePeriod); + animation.AnimateBy(Property(text, Actor::Property::POSITION_X), -position.x, timePeriod); // Animate OUT timePeriod.delaySeconds = endTime; - animation.AnimateTo( Property( text, Actor::Property::COLOR_ALPHA ), 0.0f, timePeriod ); - animation.AnimateBy( Property( text, Actor::Property::POSITION_X ), -position.x, timePeriod ); + animation.AnimateTo(Property(text, Actor::Property::COLOR_ALPHA), 0.0f, timePeriod); + animation.AnimateBy(Property(text, Actor::Property::POSITION_X), -position.x, timePeriod); } } // unnamed namespace @@ -116,99 +110,97 @@ void AddHelpInfo( const std::string&& string, const Vector2& windowSize, Actor p class GestureExample : public ConnectionTracker { public: - /** * @brief Constructor. * * @param[in] application Reference to the application */ - GestureExample( Application &application ) - : mApplication( application ) + GestureExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - application.InitSignal().Connect( this, &GestureExample::Create ); + application.InitSignal().Connect(this, &GestureExample::Create); } private: - /** * @brief Creates the scene as described in this class' description. * * @param[in] application Reference to the application class */ - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window & connect to the key event signal - auto window = application.GetWindow(); + auto window = application.GetWindow(); Vector2 windowSize = window.GetSize(); window.KeyEventSignal().Connect(this, &GestureExample::OnKeyEvent); // Create a background with a linear gradient which matches parent size & is placed in the center. Actor background = Control::New(); - background.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - background.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - background.SetProperty( Control::Property::BACKGROUND, BACKGROUND ); - window.Add( background ); + background.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + background.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + background.SetProperty(Control::Property::BACKGROUND, BACKGROUND); + window.Add(background); // Create a control with a circular gradient that we'll use for the gestures and be a quarter of the size of the window. Actor touchControl = Control::New(); - touchControl.SetProperty( Actor::Property::SIZE, windowSize * 0.25f ); - touchControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - touchControl.SetProperty( Control::Property::BACKGROUND, CONTROL_BACKGROUND ); - background.Add( touchControl ); + touchControl.SetProperty(Actor::Property::SIZE, windowSize * 0.25f); + touchControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + touchControl.SetProperty(Control::Property::BACKGROUND, CONTROL_BACKGROUND); + background.Add(touchControl); // Connect to the touch signal - touchControl.TouchedSignal().Connect( this, &GestureExample::OnTouch ); - touchControl.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); + touchControl.TouchedSignal().Connect(this, &GestureExample::OnTouch); + touchControl.SetProperty(Actor::Property::LEAVE_REQUIRED, true); // Create a long press gesture detector, attach the actor & connect mLongPressDetector = LongPressGestureDetector::New(); - mLongPressDetector.Attach( touchControl ); - mLongPressDetector.DetectedSignal().Connect( this, &GestureExample::OnLongPress ); + mLongPressDetector.Attach(touchControl); + mLongPressDetector.DetectedSignal().Connect(this, &GestureExample::OnLongPress); // Create a pan gesture detector & connect, don't attach the actor as we'll attach it when we detect a long-press mPanDetector = PanGestureDetector::New(); - mPanDetector.DetectedSignal().Connect( this, &GestureExample::OnPan ); + mPanDetector.DetectedSignal().Connect(this, &GestureExample::OnPan); // Create a tap gesture detector, attach the actor & connect mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach( touchControl ); - mTapDetector.DetectedSignal().Connect( this, &GestureExample::OnTap ); + mTapDetector.Attach(touchControl); + mTapDetector.DetectedSignal().Connect(this, &GestureExample::OnTap); // Create a pinch gesture detector, attach the actor & connect mPinchDetector = PinchGestureDetector::New(); - mPinchDetector.Attach( touchControl ); - mPinchDetector.DetectedSignal().Connect( this, &GestureExample::OnPinch ); + mPinchDetector.Attach(touchControl); + mPinchDetector.DetectedSignal().Connect(this, &GestureExample::OnPinch); // Create a rotation gesture detector, attach the actor & connect mRotationDetector = RotationGestureDetector::New(); - mRotationDetector.Attach( touchControl ); - mRotationDetector.DetectedSignal().Connect( this, &GestureExample::OnRotation ); + mRotationDetector.Attach(touchControl); + mRotationDetector.DetectedSignal().Connect(this, &GestureExample::OnRotation); // Create an animation which shakes the actor when in Pan mode - mShakeAnimation = Animation::New( SHAKY_ANIMATION_DURATION ); - mShakeAnimation.AnimateBy( Property( touchControl, Actor::Property::ORIENTATION ), - Quaternion( Degree( SHAKY_ANIMATION_ANGLE ), Vector3::ZAXIS ), - AlphaFunction::BOUNCE, - TimePeriod( 0.0f, SHAKY_ANIMATION_SEGMENT_TIME ) ); - mShakeAnimation.AnimateBy( Property( touchControl, Actor::Property::ORIENTATION ), - Quaternion( Degree( -SHAKY_ANIMATION_ANGLE ), Vector3::ZAXIS ), - AlphaFunction::BOUNCE, - TimePeriod( SHAKY_ANIMATION_SEGMENT_TIME, SHAKY_ANIMATION_SEGMENT_TIME ) ); + mShakeAnimation = Animation::New(SHAKY_ANIMATION_DURATION); + mShakeAnimation.AnimateBy(Property(touchControl, Actor::Property::ORIENTATION), + Quaternion(Degree(SHAKY_ANIMATION_ANGLE), Vector3::ZAXIS), + AlphaFunction::BOUNCE, + TimePeriod(0.0f, SHAKY_ANIMATION_SEGMENT_TIME)); + mShakeAnimation.AnimateBy(Property(touchControl, Actor::Property::ORIENTATION), + Quaternion(Degree(-SHAKY_ANIMATION_ANGLE), Vector3::ZAXIS), + AlphaFunction::BOUNCE, + TimePeriod(SHAKY_ANIMATION_SEGMENT_TIME, SHAKY_ANIMATION_SEGMENT_TIME)); // Animate help information // Here we just animate some text on the screen to show tips on how to use this example // The help animation loops - Animation helpAnimation = Animation::New( HELP_ANIMATION_DURATION ); + Animation helpAnimation = Animation::New(HELP_ANIMATION_DURATION); - float startTime( 0.0f ); - float endTime( startTime + HELP_ANIMATION_SEGMENT_TIME ); + float startTime(0.0f); + float endTime(startTime + HELP_ANIMATION_SEGMENT_TIME); - AddHelpInfo( "Tap image for animation", windowSize, background, helpAnimation, startTime, endTime ); - AddHelpInfo( "Press & Hold image to drag", windowSize, background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); - AddHelpInfo( "Pinch image to resize", windowSize, background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); - AddHelpInfo( "Move fingers in a circular motion on image to rotate", windowSize, background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME ); - helpAnimation.SetLooping( true ); + AddHelpInfo("Tap image for animation", windowSize, background, helpAnimation, startTime, endTime); + AddHelpInfo("Press & Hold image to drag", windowSize, background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME); + AddHelpInfo("Pinch image to resize", windowSize, background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME); + AddHelpInfo("Move fingers in a circular motion on image to rotate", windowSize, background, helpAnimation, startTime += HELP_ANIMATION_SEGMENT_TIME, endTime += HELP_ANIMATION_SEGMENT_TIME); + helpAnimation.SetLooping(true); helpAnimation.Play(); } @@ -218,16 +210,16 @@ private: * @param[in] actor The touched actor * @param[in] touch The touch event */ - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - switch( touch.GetState( 0 ) ) + switch(touch.GetState(0)) { case PointState::DOWN: { // When we get a touch point, change the color of the actor. - Animation anim = Animation::New( TOUCH_MODE_ANIMATION_DURATION ); - anim.AnimateTo( Property( actor, Actor::Property::COLOR ), TOUCH_MODE_COLOR ); + Animation anim = Animation::New(TOUCH_MODE_ANIMATION_DURATION); + anim.AnimateTo(Property(actor, Actor::Property::COLOR), TOUCH_MODE_COLOR); anim.Play(); break; } @@ -236,16 +228,16 @@ private: case PointState::UP: case PointState::INTERRUPTED: { - if( ! mPanStarted ) + if(!mPanStarted) { // If we're not panning, change the color back to normal. - Animation anim = Animation::New( TOUCH_MODE_ANIMATION_DURATION ); - anim.AnimateTo( Property( actor, Actor::Property::COLOR ), Vector4::ONE ); + Animation anim = Animation::New(TOUCH_MODE_ANIMATION_DURATION); + anim.AnimateTo(Property(actor, Actor::Property::COLOR), Vector4::ONE); anim.Play(); // Stop the shake animation from looping. - mShakeAnimation.SetLooping( false ); + mShakeAnimation.SetLooping(false); } break; } @@ -264,20 +256,20 @@ private: * @param[in] actor The actor that's been long-pressed * @param[in] longPress The long-press gesture information */ - void OnLongPress( Actor actor, const LongPressGesture& longPress ) + void OnLongPress(Actor actor, const LongPressGesture& longPress) { - if( longPress.GetState() == GestureState::STARTED ) + if(longPress.GetState() == GestureState::STARTED) { // When we first receive a long press, attach the actor to the pan detector. - mPanDetector.Attach( actor ); + mPanDetector.Attach(actor); // Do a small animation to indicate to the user that we are in pan mode. - Animation anim = Animation::New( PAN_MODE_CHANGE_ANIMATION_DURATION ); - anim.AnimateTo( Property( actor, Actor::Property::SCALE ), actor.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ) * PAN_MODE_START_ANIMATION_SCALE, AlphaFunction::BOUNCE ); + Animation anim = Animation::New(PAN_MODE_CHANGE_ANIMATION_DURATION); + anim.AnimateTo(Property(actor, Actor::Property::SCALE), actor.GetCurrentProperty(Actor::Property::SCALE) * PAN_MODE_START_ANIMATION_SCALE, AlphaFunction::BOUNCE); anim.Play(); // Start the shake animation so the user knows when they are in pan mode. - mShakeAnimation.SetLooping( true ); + mShakeAnimation.SetLooping(true); mShakeAnimation.Play(); } } @@ -288,22 +280,22 @@ private: * @param[in] actor The actor that's been panned * @param[in] pan The pan gesture information */ - void OnPan( Actor actor, const PanGesture& pan ) + void OnPan(Actor actor, const PanGesture& pan) { // Just move the actor by the displacement. // As the displacement is in local actor coords, we will have to multiply the displacement by the // actor's scale so that it moves the correct amount in the parent's coordinate system. - Vector3 scaledDisplacement( pan.GetDisplacement() ); - scaledDisplacement *= actor.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ); + Vector3 scaledDisplacement(pan.GetDisplacement()); + scaledDisplacement *= actor.GetCurrentProperty(Actor::Property::SCALE); Vector3 currentPosition; - actor.GetProperty( Actor::Property::POSITION ).Get( currentPosition ); + actor.GetProperty(Actor::Property::POSITION).Get(currentPosition); Vector3 newPosition = currentPosition + scaledDisplacement; - actor.SetProperty( Actor::Property::POSITION, newPosition ); + actor.SetProperty(Actor::Property::POSITION, newPosition); - switch( pan.GetState() ) + switch(pan.GetState()) { case GestureState::STARTED: { @@ -316,23 +308,23 @@ private: { // If we cancel or finish the pan, do an animation to indicate this and stop the shake animation. - Animation anim = Animation::New( PAN_MODE_CHANGE_ANIMATION_DURATION ); - anim.AnimateTo( Property( actor, Actor::Property::COLOR ), Vector4::ONE ); - anim.AnimateTo( Property( actor, Actor::Property::SCALE ), actor.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ) * PAN_MODE_END_ANIMATION_SCALE, AlphaFunction::BOUNCE ); + Animation anim = Animation::New(PAN_MODE_CHANGE_ANIMATION_DURATION); + anim.AnimateTo(Property(actor, Actor::Property::COLOR), Vector4::ONE); + anim.AnimateTo(Property(actor, Actor::Property::SCALE), actor.GetCurrentProperty(Actor::Property::SCALE) * PAN_MODE_END_ANIMATION_SCALE, AlphaFunction::BOUNCE); // Move actor back to center if we're out of bounds Vector2 halfWindowSize = Vector2(mApplication.GetWindow().GetSize()) * 0.5f; - if( ( abs( newPosition.x ) > halfWindowSize.width ) || - ( abs( newPosition.y ) > halfWindowSize.height ) ) + if((abs(newPosition.x) > halfWindowSize.width) || + (abs(newPosition.y) > halfWindowSize.height)) { - anim.AnimateTo( Property( actor, Actor::Property::POSITION ), Vector3::ZERO, AlphaFunction::EASE_IN ); + anim.AnimateTo(Property(actor, Actor::Property::POSITION), Vector3::ZERO, AlphaFunction::EASE_IN); } anim.Play(); // Set end of pan configuration and disconnect the actor from the pan detector - mShakeAnimation.SetLooping( false ); + mShakeAnimation.SetLooping(false); mPanStarted = false; - mPanDetector.Detach( actor ); + mPanDetector.Detach(actor); break; } @@ -349,15 +341,15 @@ private: * @param[in] actor The actor that's been tapped * @param[in] tap The tap gesture information */ - void OnTap( Actor actor, const TapGesture& tap ) + void OnTap(Actor actor, const TapGesture& tap) { // Do a short animation to show a tap has happened. - Animation anim = Animation::New( TAP_ANIMATION_DURATION ); - anim.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( ANGLE_360, Vector3::ZAXIS ) ); - anim.AnimateTo( Property( actor, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::LINEAR ); - anim.AnimateTo( Property( actor, Actor::Property::COLOR ), TAP_ANIMATION_COLOR, AlphaFunction::BOUNCE ); - anim.AnimateTo( Property( actor, Actor::Property::POSITION ), Vector3::ZERO, AlphaFunction::EASE_OUT_SQUARE ); + Animation anim = Animation::New(TAP_ANIMATION_DURATION); + anim.AnimateBy(Property(actor, Actor::Property::ORIENTATION), Quaternion(ANGLE_360, Vector3::ZAXIS)); + anim.AnimateTo(Property(actor, Actor::Property::SCALE), Vector3::ONE, AlphaFunction::LINEAR); + anim.AnimateTo(Property(actor, Actor::Property::COLOR), TAP_ANIMATION_COLOR, AlphaFunction::BOUNCE); + anim.AnimateTo(Property(actor, Actor::Property::POSITION), Vector3::ZERO, AlphaFunction::EASE_OUT_SQUARE); anim.Play(); } @@ -367,35 +359,35 @@ private: * @param[in] actor The actor that's been pinched * @param[in] pinch The pinch gesture information */ - void OnPinch( Actor actor, const PinchGesture& pinch ) + void OnPinch(Actor actor, const PinchGesture& pinch) { - switch( pinch.GetState() ) + switch(pinch.GetState()) { case GestureState::STARTED: { // Starting scale is required so that we know what to multiply the pinch.scale by. - mStartingScale = actor.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ); + mStartingScale = actor.GetCurrentProperty(Actor::Property::SCALE); break; } case GestureState::FINISHED: case GestureState::CANCELLED: { - Vector3 scale( actor.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ) ); + Vector3 scale(actor.GetCurrentProperty(Actor::Property::SCALE)); // Ensure the actor sizes itself to be within the limits defined. - if ( scale.x < MINIMUM_SCALE.x ) + if(scale.x < MINIMUM_SCALE.x) { scale = MINIMUM_SCALE; } - else if ( scale.x > MAXIMUM_SCALE.x ) + else if(scale.x > MAXIMUM_SCALE.x) { scale = MAXIMUM_SCALE; } // Do an animation to come back to go back to the limits. - Animation anim = Animation::New( SCALE_BACK_ANIMATION_DURATION ); - anim.AnimateTo( Property( actor, Actor::Property::SCALE ), scale, AlphaFunction::LINEAR ); + Animation anim = Animation::New(SCALE_BACK_ANIMATION_DURATION); + anim.AnimateTo(Property(actor, Actor::Property::SCALE), scale, AlphaFunction::LINEAR); anim.Play(); break; } @@ -406,7 +398,7 @@ private: } } - actor.SetProperty( Actor::Property::SCALE, mStartingScale * pinch.GetScale() ); + actor.SetProperty(Actor::Property::SCALE, mStartingScale * pinch.GetScale()); } /** @@ -415,14 +407,14 @@ private: * @param[in] actor The actor that's been pinched * @param[in] rotation The rotation gesture information */ - void OnRotation( Actor actor, const RotationGesture& rotation ) + void OnRotation(Actor actor, const RotationGesture& rotation) { - switch( rotation.GetState() ) + switch(rotation.GetState()) { case GestureState::STARTED: { // Starting orientation is required so that we know what to multiply the rotation.rotation by. - mStartingOrientation = actor.GetCurrentProperty< Quaternion >( Actor::Property::ORIENTATION ); + mStartingOrientation = actor.GetCurrentProperty(Actor::Property::ORIENTATION); break; } @@ -430,8 +422,8 @@ private: case GestureState::CANCELLED: { // Do an animation to come back to go back to the original orientation. - Animation anim = Animation::New( ROTATE_BACK_ANIMATION_DURATION ); - anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion::IDENTITY, AlphaFunction::LINEAR ); + Animation anim = Animation::New(ROTATE_BACK_ANIMATION_DURATION); + anim.AnimateTo(Property(actor, Actor::Property::ORIENTATION), Quaternion::IDENTITY, AlphaFunction::LINEAR); anim.Play(); break; } @@ -442,7 +434,7 @@ private: } } - actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( mStartingOrientation * Quaternion( rotation.GetRotation(), Vector3::ZAXIS ) ) ); + actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(mStartingOrientation * Quaternion(rotation.GetRotation(), Vector3::ZAXIS))); } /** @@ -451,11 +443,11 @@ private: * Will use this to quit the application if Back or the Escape key is received. * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -463,24 +455,24 @@ private: } private: - Application& mApplication; + Application& mApplication; - PanGestureDetector mPanDetector; + PanGestureDetector mPanDetector; LongPressGestureDetector mLongPressDetector; - TapGestureDetector mTapDetector; - PinchGestureDetector mPinchDetector; - RotationGestureDetector mRotationDetector; + TapGestureDetector mTapDetector; + PinchGestureDetector mPinchDetector; + RotationGestureDetector mRotationDetector; - Vector3 mStartingScale; ///< Set to the scale of the control when pinch starts. + Vector3 mStartingScale; ///< Set to the scale of the control when pinch starts. Quaternion mStartingOrientation; ///< Set to the orientation of the control when the rotation starts. - Animation mShakeAnimation; ///< "Shake" animation to show when we are in panning mode. - bool mPanStarted = false; ///< Set to true to state that panning has started. + Animation mShakeAnimation; ///< "Shake" animation to show when we are in panning mode. + bool mPanStarted = false; ///< Set to true to state that panning has started. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - GestureExample controller( application ); + Application application = Application::New(&argc, &argv); + GestureExample controller(application); application.MainLoop(); return 0; } diff --git a/examples/gradients/gradients-example.cpp b/examples/gradients/gradients-example.cpp index 518e093..85eba7c 100644 --- a/examples/gradients/gradients-example.cpp +++ b/examples/gradients/gradients-example.cpp @@ -24,31 +24,30 @@ using namespace Dali::Toolkit; namespace { -const char * const APPLICATION_TITLE( "Color Gradients" ); +const char* const APPLICATION_TITLE("Color Gradients"); -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const CHANGE_ICON( DEMO_IMAGE_DIR "icon-change.png" ); -const char * const CHANGE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char * const ROUNDED_CORNER_ICON( DEMO_IMAGE_DIR "icon-replace.png" ); -const char * const ROUNDED_CORNER_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" ); +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const CHANGE_ICON(DEMO_IMAGE_DIR "icon-change.png"); +const char* const CHANGE_ICON_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* const ROUNDED_CORNER_ICON(DEMO_IMAGE_DIR "icon-replace.png"); +const char* const ROUNDED_CORNER_ICON_SELECTED(DEMO_IMAGE_DIR "icon-replace-selected.png"); -const float CORNER_RADIUS_VALUE( 20.0f ); +const float CORNER_RADIUS_VALUE(20.0f); -} +} // namespace // This example shows how to render color gradients // class GradientController : public ConnectionTracker { public: - - GradientController( Application& application ) - : mApplication( application ), - mIndex( 0 ), - mRoundedCorner( false ) + GradientController(Application& application) + : mApplication(application), + mIndex(0), + mRoundedCorner(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &GradientController::Create ); + mApplication.InitSignal().Connect(this, &GradientController::Create); } ~GradientController() @@ -57,7 +56,7 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window auto window = application.GetWindow(); @@ -66,74 +65,74 @@ public: // Creates a default view with a default tool bar. // The view is added to the window. Toolkit::ToolBar toolBar; - Layer content = DemoHelper::CreateView( application, - mView, - toolBar, - "", - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + Layer content = DemoHelper::CreateView(application, + mView, + toolBar, + "", + TOOLBAR_IMAGE, + APPLICATION_TITLE); PushButton changeButton = Toolkit::PushButton::New(); - changeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_ICON ); - changeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_ICON_SELECTED ); - changeButton.ClickedSignal().Connect( this, &GradientController::OnChangeIconClicked ); - toolBar.AddControl( changeButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_RIGHT, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + changeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_ICON); + changeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_ICON_SELECTED); + changeButton.ClickedSignal().Connect(this, &GradientController::OnChangeIconClicked); + toolBar.AddControl(changeButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_RIGHT, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); PushButton roundedCornerButton = Toolkit::PushButton::New(); - roundedCornerButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ROUNDED_CORNER_ICON ); - roundedCornerButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ROUNDED_CORNER_ICON_SELECTED ); - roundedCornerButton.ClickedSignal().Connect( this, &GradientController::OnRoundedCornerClicked ); - toolBar.AddControl( roundedCornerButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_CENTER, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + roundedCornerButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ROUNDED_CORNER_ICON); + roundedCornerButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ROUNDED_CORNER_ICON_SELECTED); + roundedCornerButton.ClickedSignal().Connect(this, &GradientController::OnRoundedCornerClicked); + toolBar.AddControl(roundedCornerButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_CENTER, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); mGradientControl = Control::New(); - mGradientControl.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mGradientControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mGradientControl.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Vector3 offset( 0.9f, 0.7f, 0.0f ); - mGradientControl.SetProperty( Actor::Property::SIZE_MODE_FACTOR, offset ); - content.Add( mGradientControl ); + mGradientControl.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mGradientControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mGradientControl.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + Vector3 offset(0.9f, 0.7f, 0.0f); + mGradientControl.SetProperty(Actor::Property::SIZE_MODE_FACTOR, offset); + content.Add(mGradientControl); -// ---- Gradient for background + // ---- Gradient for background - mGradientMap.Insert( Toolkit::Visual::Property::TYPE, Visual::GRADIENT ); + mGradientMap.Insert(Toolkit::Visual::Property::TYPE, Visual::GRADIENT); Property::Array stopOffsets; - stopOffsets.PushBack( 0.0f ); - stopOffsets.PushBack( 0.3f ); - stopOffsets.PushBack( 0.6f ); - stopOffsets.PushBack( 0.8f ); - stopOffsets.PushBack( 1.0f ); - mGradientMap.Insert( GradientVisual::Property::STOP_OFFSET, stopOffsets ); + stopOffsets.PushBack(0.0f); + stopOffsets.PushBack(0.3f); + stopOffsets.PushBack(0.6f); + stopOffsets.PushBack(0.8f); + stopOffsets.PushBack(1.0f); + mGradientMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets); Property::Array stopColors; - stopColors.PushBack( Vector4( 129.f, 198.f, 193.f, 255.f )/255.f ); - stopColors.PushBack( Vector4( 196.f, 198.f, 71.f, 122.f )/255.f ); - stopColors.PushBack( Vector4( 214.f, 37.f, 139.f, 191.f )/255.f ); - stopColors.PushBack( Vector4( 129.f, 198.f, 193.f, 150.f )/255.f ); - stopColors.PushBack( Color::YELLOW ); - mGradientMap.Insert( GradientVisual::Property::STOP_COLOR, stopColors ); + stopColors.PushBack(Vector4(129.f, 198.f, 193.f, 255.f) / 255.f); + stopColors.PushBack(Vector4(196.f, 198.f, 71.f, 122.f) / 255.f); + stopColors.PushBack(Vector4(214.f, 37.f, 139.f, 191.f) / 255.f); + stopColors.PushBack(Vector4(129.f, 198.f, 193.f, 150.f) / 255.f); + stopColors.PushBack(Color::YELLOW); + mGradientMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors); - mGradientMap.Insert( DevelVisual::Property::CORNER_RADIUS, mRoundedCorner ? CORNER_RADIUS_VALUE : 0.0f ); + mGradientMap.Insert(DevelVisual::Property::CORNER_RADIUS, mRoundedCorner ? CORNER_RADIUS_VALUE : 0.0f); UpdateGradientMap(); } - bool OnChangeIconClicked( Toolkit::Button button ) + bool OnChangeIconClicked(Toolkit::Button button) { mIndex++; UpdateGradientMap(); return true; } - bool OnRoundedCornerClicked( Toolkit::Button button ) + bool OnRoundedCornerClicked(Toolkit::Button button) { - mRoundedCorner = !mRoundedCorner; + mRoundedCorner = !mRoundedCorner; mGradientMap[DevelVisual::Property::CORNER_RADIUS] = mRoundedCorner ? CORNER_RADIUS_VALUE : 0.0f; UpdateGradientMap(); @@ -145,47 +144,47 @@ public: { Property::Map gradientMap; - switch( mIndex%4 ) + switch(mIndex % 4) { case 0: // linear gradient with units as objectBoundingBox { - gradientMap.Insert( GradientVisual::Property::START_POSITION, Vector2( 0.5f, 0.5f ) ); - gradientMap.Insert( GradientVisual::Property::END_POSITION, Vector2( -0.5f, -0.5f ) ); + gradientMap.Insert(GradientVisual::Property::START_POSITION, Vector2(0.5f, 0.5f)); + gradientMap.Insert(GradientVisual::Property::END_POSITION, Vector2(-0.5f, -0.5f)); break; } case 1: // linear gradient with units as userSpaceOnUse { - Vector2 halfWindowSize = Vector2(mApplication.GetWindow().GetSize())*0.5f; - gradientMap.Insert( GradientVisual::Property::START_POSITION, halfWindowSize ); - gradientMap.Insert( GradientVisual::Property::END_POSITION, -halfWindowSize ); - gradientMap.Insert( GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE ); + Vector2 halfWindowSize = Vector2(mApplication.GetWindow().GetSize()) * 0.5f; + gradientMap.Insert(GradientVisual::Property::START_POSITION, halfWindowSize); + gradientMap.Insert(GradientVisual::Property::END_POSITION, -halfWindowSize); + gradientMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE); break; } case 2: // radial gradient with units as objectBoundingBox { - gradientMap.Insert( GradientVisual::Property::CENTER, Vector2( 0.5f, 0.5f ) ); - gradientMap.Insert( GradientVisual::Property::RADIUS, 1.414f ); + gradientMap.Insert(GradientVisual::Property::CENTER, Vector2(0.5f, 0.5f)); + gradientMap.Insert(GradientVisual::Property::RADIUS, 1.414f); break; } default: // radial gradient with units as userSpaceOnUse { Vector2 windowSize = mApplication.GetWindow().GetSize(); - gradientMap.Insert( GradientVisual::Property::CENTER, windowSize * 0.5f ); - gradientMap.Insert( GradientVisual::Property::RADIUS, windowSize.Length()); - gradientMap.Insert( GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE ); + gradientMap.Insert(GradientVisual::Property::CENTER, windowSize * 0.5f); + gradientMap.Insert(GradientVisual::Property::RADIUS, windowSize.Length()); + gradientMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE); break; } } - gradientMap.Merge( mGradientMap ); - mGradientControl.SetProperty( Control::Property::BACKGROUND, gradientMap ); + gradientMap.Merge(mGradientMap); + mGradientControl.SetProperty(Control::Property::BACKGROUND, gradientMap); } void OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -193,19 +192,19 @@ public: } private: - Application& mApplication; + Application& mApplication; Property::Map mGradientMap; - Control mView; - Control mGradientControl; - unsigned mIndex; - bool mRoundedCorner; + Control mView; + Control mGradientControl; + unsigned mIndex; + bool mRoundedCorner; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - GradientController test( application ); + Application application = Application::New(&argc, &argv); + GradientController test(application); application.MainLoop(); return 0; } diff --git a/examples/hello-world/hello-world-example.cpp b/examples/hello-world/hello-world-example.cpp index 1f3599a..0d14414 100644 --- a/examples/hello-world/hello-world-example.cpp +++ b/examples/hello-world/hello-world-example.cpp @@ -25,47 +25,46 @@ using Dali::Toolkit::TextLabel; class HelloWorldController : public ConnectionTracker { public: - - HelloWorldController( Application& application ) - : mApplication( application ) + HelloWorldController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &HelloWorldController::Create ); + mApplication.InitSignal().Connect(this, &HelloWorldController::Create); } ~HelloWorldController() = default; // Nothing to do in destructor // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); - TextLabel textLabel = TextLabel::New( "Hello World" ); - textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - textLabel.SetProperty( Dali::Actor::Property::NAME, "helloWorldLabel" ); - window.Add( textLabel ); + TextLabel textLabel = TextLabel::New("Hello World"); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + textLabel.SetProperty(Dali::Actor::Property::NAME, "helloWorldLabel"); + window.Add(textLabel); // Respond to a touch anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &HelloWorldController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &HelloWorldController::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &HelloWorldController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &HelloWorldController::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -73,13 +72,13 @@ public: } private: - Application& mApplication; + Application& mApplication; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - HelloWorldController test( application ); + Application application = Application::New(&argc, &argv); + HelloWorldController test(application); application.MainLoop(); return 0; } diff --git a/examples/homescreen-benchmark/homescreen-benchmark.cpp b/examples/homescreen-benchmark/homescreen-benchmark.cpp index f710406..bd5b161 100644 --- a/examples/homescreen-benchmark/homescreen-benchmark.cpp +++ b/examples/homescreen-benchmark/homescreen-benchmark.cpp @@ -18,8 +18,8 @@ // EXTERNAL INCLUDES #include #include -#include #include +#include #include #include @@ -35,68 +35,49 @@ enum IconType CHECKBOX }; -const char* IMAGE_PATH_PREFIX ( DEMO_IMAGE_DIR "application-icon-" ); -const char* IMAGE_PATH_POSTFIX ( ".png" ); -const int TOTAL_ICON_DEFINITIONS ( 147 ); +const char* IMAGE_PATH_PREFIX(DEMO_IMAGE_DIR "application-icon-"); +const char* IMAGE_PATH_POSTFIX(".png"); +const int TOTAL_ICON_DEFINITIONS(147); -const char* BACKGROUND_IMAGE ( DEMO_IMAGE_DIR "background-3.jpg" ); -const float PAGE_SCALE_FACTOR_X ( 0.95f ); -const float PAGE_SCALE_FACTOR_Y ( 0.95f ); -const float PAGE_DURATION_SCALE_FACTOR ( 10.0f ); ///< Time-scale factor, larger = animation is slower +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-3.jpg"); +const float PAGE_SCALE_FACTOR_X(0.95f); +const float PAGE_SCALE_FACTOR_Y(0.95f); +const float PAGE_DURATION_SCALE_FACTOR(10.0f); ///< Time-scale factor, larger = animation is slower -const float DEFAULT_OPT_ROW_COUNT ( 5 ); -const float DEFAULT_OPT_COL_COUNT ( 4 ); -const float DEFAULT_OPT_PAGE_COUNT ( 10 ); -const bool DEFAULT_OPT_USE_TABLEVIEW ( true ); -const bool DEFAULT_OPT_ICON_LABELS ( true ); -const IconType DEFAULT_OPT_ICON_TYPE ( IMAGEVIEW ); -const bool DEFAULT_OPT_USE_TEXT_LABEL ( false ); +const float DEFAULT_OPT_ROW_COUNT(5); +const float DEFAULT_OPT_COL_COUNT(4); +const float DEFAULT_OPT_PAGE_COUNT(10); +const bool DEFAULT_OPT_USE_TABLEVIEW(true); +const bool DEFAULT_OPT_ICON_LABELS(true); +const IconType DEFAULT_OPT_ICON_TYPE(IMAGEVIEW); +const bool DEFAULT_OPT_USE_TEXT_LABEL(false); // The image/label area tries to make sure the positioning will be relative to previous sibling -const float IMAGE_AREA ( 0.60f ); -const float LABEL_AREA ( 0.50f ); - - +const float IMAGE_AREA(0.60f); +const float LABEL_AREA(0.50f); /** * Random words used as unique application names. * The number matches the value of TOTAL_ICON_DEFINITIONS. */ const char* DEMO_APPS_NAMES[] = -{ - "Achdyer", "Aughm", "Cerl", "Daril", "Emgha", "Ghatan", "Issum", "Lertan", "Mosorrad", - "Achtortor", "Aughtheryer", "Certin", "Darpban", "Emiton", "Gibanis", "Itenthbel", "Liadem", "Mosraye", - "Ackirlor", "Awitad", "Checerper", "Dasrad", "Emworeng", "Hatdyn", "K'ackves", "Liathar", "Mosth", - "Ackptin", "Banengon", "Chegit", "Deeqskel", "Endnys", "Heesban", "Kagdra", "Liephden", "Neabar", - "Aighte", "Banhinat", "Cheirat", "Delurnther", "Enessray", "Hesub", "Kalbankim", "Likellor", "Neerdem", - "Akala", "Belrisash", "Che'rak", "Denalda", "Engyer", "Hinkelenth", "Kal'enda", "Loightmos", "Nichqua", - "Alealdny", "Bilorm", "Cheves", "Derynkel", "En'rady", "Hirryer", "Kimest", "Loromum", "Nudraough", - "Angash", "Bleustcer", "Chiperath", "Deurnos", "Enthount", "Ideinta", "Kimundeng", "Lorr", "Nuyim", - "Anglor", "Bliagelor", "Chralerack", "Doyaryke", "Enundem", "Im'eld", "Koachlor", "Lortas", "Nycha", - "Anveraugh", "Blorynton", "Chram", "Draithon", "Essina", "Ina'ir", "Kuren", "Lyerr", "Nyia", - "Ardangas", "Booten", "Clyimen", "Drantess", "Faughald", "Ing'moro", "Kygver", "Maustbur", "Nyjac", - "Ardug", "Bripolqua", "Coqueang", "Druardny", "Fiummos", "Ingormess", "Kyning", "Menvor", "Nystondar", - "Ardworu", "Bryray", "Craennther", "Dynsaytor", "Garash", "Ingshy", "Laiyach", "Meusten", "Okine", - "Ascerald", "Burust", "Cykage", "Dytinris", "Garight", "Issath", "Lasuzu", "Mirodskel", "Oldit", - "Ash'ach", "Cataikel", "Dalek", "Eeni", "Garrynath", "Issendris", "Lekew", "Morhatrod", "Om'mose", - "Athiund", "Cerilwar", "Darhkel", "Elmryn", "Ghalora", "Issey", "Lerengom", "Moserbel", "Onye", - "Ososrak", "Pecertin", "Perrd" -}; + { + "Achdyer", "Aughm", "Cerl", "Daril", "Emgha", "Ghatan", "Issum", "Lertan", "Mosorrad", "Achtortor", "Aughtheryer", "Certin", "Darpban", "Emiton", "Gibanis", "Itenthbel", "Liadem", "Mosraye", "Ackirlor", "Awitad", "Checerper", "Dasrad", "Emworeng", "Hatdyn", "K'ackves", "Liathar", "Mosth", "Ackptin", "Banengon", "Chegit", "Deeqskel", "Endnys", "Heesban", "Kagdra", "Liephden", "Neabar", "Aighte", "Banhinat", "Cheirat", "Delurnther", "Enessray", "Hesub", "Kalbankim", "Likellor", "Neerdem", "Akala", "Belrisash", "Che'rak", "Denalda", "Engyer", "Hinkelenth", "Kal'enda", "Loightmos", "Nichqua", "Alealdny", "Bilorm", "Cheves", "Derynkel", "En'rady", "Hirryer", "Kimest", "Loromum", "Nudraough", "Angash", "Bleustcer", "Chiperath", "Deurnos", "Enthount", "Ideinta", "Kimundeng", "Lorr", "Nuyim", "Anglor", "Bliagelor", "Chralerack", "Doyaryke", "Enundem", "Im'eld", "Koachlor", "Lortas", "Nycha", "Anveraugh", "Blorynton", "Chram", "Draithon", "Essina", "Ina'ir", "Kuren", "Lyerr", "Nyia", "Ardangas", "Booten", "Clyimen", "Drantess", "Faughald", "Ing'moro", "Kygver", "Maustbur", "Nyjac", "Ardug", "Bripolqua", "Coqueang", "Druardny", "Fiummos", "Ingormess", "Kyning", "Menvor", "Nystondar", "Ardworu", "Bryray", "Craennther", "Dynsaytor", "Garash", "Ingshy", "Laiyach", "Meusten", "Okine", "Ascerald", "Burust", "Cykage", "Dytinris", "Garight", "Issath", "Lasuzu", "Mirodskel", "Oldit", "Ash'ach", "Cataikel", "Dalek", "Eeni", "Garrynath", "Issendris", "Lekew", "Morhatrod", "Om'mose", "Athiund", "Cerilwar", "Darhkel", "Elmryn", "Ghalora", "Issey", "Lerengom", "Moserbel", "Onye", "Ososrak", "Pecertin", "Perrd"}; // This code comes from command-line-options.cpp. the reason it's here is to // keep consistent the extra-help formatting when '--help' used. -void PrintHelp( const char * const opt, const char * const optDescription) +void PrintHelp(const char* const opt, const char* const optDescription) { const std::ios_base::fmtflags flags = std::cout.flags(); std::cout << std::left << " -"; - std::cout.width( 18 ); + std::cout.width(18); std::cout << opt; std::cout << optDescription; std::cout << std::endl; - std::cout.flags( flags ); + std::cout.flags(flags); } -} +} // namespace /** * @brief This example is a benchmark that mimics the paged applications list of the homescreen application. @@ -104,38 +85,37 @@ void PrintHelp( const char * const opt, const char * const optDescription) class HomescreenBenchmark : public ConnectionTracker { public: - // Config structure passed to the constructor. It makes easier to increase number // of setup parameters if needed. struct Config { - Config() : - mRows( DEFAULT_OPT_ROW_COUNT ), - mCols( DEFAULT_OPT_COL_COUNT ), - mPageCount( DEFAULT_OPT_PAGE_COUNT ), - mTableViewEnabled( DEFAULT_OPT_USE_TABLEVIEW ), - mIconLabelsEnabled( DEFAULT_OPT_ICON_LABELS ), - mIconType( DEFAULT_OPT_ICON_TYPE ), - mUseTextLabel( DEFAULT_OPT_USE_TEXT_LABEL ) + Config() + : mRows(DEFAULT_OPT_ROW_COUNT), + mCols(DEFAULT_OPT_COL_COUNT), + mPageCount(DEFAULT_OPT_PAGE_COUNT), + mTableViewEnabled(DEFAULT_OPT_USE_TABLEVIEW), + mIconLabelsEnabled(DEFAULT_OPT_ICON_LABELS), + mIconType(DEFAULT_OPT_ICON_TYPE), + mUseTextLabel(DEFAULT_OPT_USE_TEXT_LABEL) { } - int mRows; - int mCols; - int mPageCount; - bool mTableViewEnabled; - bool mIconLabelsEnabled; + int mRows; + int mCols; + int mPageCount; + bool mTableViewEnabled; + bool mIconLabelsEnabled; IconType mIconType; - bool mUseTextLabel; + bool mUseTextLabel; }; // animation script data struct ScriptData { - ScriptData( int pages, float duration, bool flick ) - : mPages( pages ), - mDuration( duration ), - mFlick( flick ) + ScriptData(int pages, float duration, bool flick) + : mPages(pages), + mDuration(duration), + mFlick(flick) { } @@ -144,14 +124,14 @@ public: bool mFlick; ///< Use flick or 'one-by-one' scroll }; - HomescreenBenchmark( Application& application, const Config& config ) - : mApplication( application ), - mConfig( config ), - mScriptFrame( 0 ), - mCurrentPage( 0 ) + HomescreenBenchmark(Application& application, const Config& config) + : mApplication(application), + mConfig(config), + mScriptFrame(0), + mCurrentPage(0) { // Connect to the Application's Init signal. - mApplication.InitSignal().Connect( this, &HomescreenBenchmark::Create ); + mApplication.InitSignal().Connect(this, &HomescreenBenchmark::Create); } ~HomescreenBenchmark() @@ -159,7 +139,7 @@ public: } // The Init signal is received once (only) during the Application lifetime. - void Create( Application& application ) + void Create(Application& application) { // Create benchmark script CreateScript(); @@ -168,29 +148,29 @@ public: Window window = application.GetWindow(); mScrollParent = Actor::New(); - mScrollParent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mScrollParent.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mScrollParent.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mScrollParent.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mScrollParent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mScrollParent.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); // create background - Toolkit::ImageView background = Toolkit::ImageView::New( BACKGROUND_IMAGE ); - window.Add( background ); - background.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - background.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - background.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + Toolkit::ImageView background = Toolkit::ImageView::New(BACKGROUND_IMAGE); + window.Add(background); + background.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + background.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + background.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); PopulatePages(); - window.Add( mScrollParent ); + window.Add(mScrollParent); // Respond to a click anywhere on the window. - window.GetRootLayer().TouchedSignal().Connect( this, &HomescreenBenchmark::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &HomescreenBenchmark::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &HomescreenBenchmark::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &HomescreenBenchmark::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // Quit the application. mApplication.Quit(); @@ -202,148 +182,143 @@ public: // Create root page actor. Toolkit::Control pageActor; - if( mConfig.mTableViewEnabled ) + if(mConfig.mTableViewEnabled) { - pageActor = Toolkit::TableView::New( mConfig.mRows, mConfig.mCols ); + pageActor = Toolkit::TableView::New(mConfig.mRows, mConfig.mCols); } else { pageActor = Toolkit::Control::New(); } - pageActor.SetBackgroundColor( Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) ); - pageActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - pageActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - pageActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - pageActor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( PAGE_SCALE_FACTOR_X, PAGE_SCALE_FACTOR_Y, 1.0f ) ); + pageActor.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f)); + pageActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + pageActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + pageActor.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + pageActor.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(PAGE_SCALE_FACTOR_X, PAGE_SCALE_FACTOR_Y, 1.0f)); return pageActor; } - Toolkit::ImageView CreateImageView( const unsigned int currentIconIndex ) + Toolkit::ImageView CreateImageView(const unsigned int currentIconIndex) { // Create empty image to avoid early renderer creation Toolkit::ImageView imageView = Toolkit::ImageView::New(); // Auto-generate the Icons image URL. - Property::Map map; + Property::Map map; std::stringstream imagePath; imagePath << IMAGE_PATH_PREFIX << currentIconIndex << IMAGE_PATH_POSTFIX; - map[ Dali::Toolkit::ImageVisual::Property::URL ] = imagePath.str(); + map[Dali::Toolkit::ImageVisual::Property::URL] = imagePath.str(); - imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); - imageView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - imageView.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( IMAGE_AREA, IMAGE_AREA, 1.0f ) ); + imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map); + imageView.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + imageView.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(IMAGE_AREA, IMAGE_AREA, 1.0f)); return imageView; } - Toolkit::Button CreateButton( const unsigned int currentIconIndex ) + Toolkit::Button CreateButton(const unsigned int currentIconIndex) { Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::New(); - button.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - button.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - button.SetProperty( Toolkit::Button::Property::SELECTED, ( currentIconIndex % 2 == 0 ) ); // Select half the button + button.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + button.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + button.SetProperty(Toolkit::Button::Property::SELECTED, (currentIconIndex % 2 == 0)); // Select half the button return button; } - void AddIconsToPage( Actor page, bool useTextLabel ) + void AddIconsToPage(Actor page, bool useTextLabel) { Window window = mApplication.GetWindow(); - Size windowSize( window.GetSize() ); + Size windowSize(window.GetSize()); const float scaledHeight = windowSize.y * PAGE_SCALE_FACTOR_Y; - const float scaledWidth = windowSize.x * PAGE_SCALE_FACTOR_X; - const float PADDING = windowSize.y / 64.0f; - const float ROW_HEIGHT = ( scaledHeight - (PADDING*2.0f) ) / static_cast( mConfig.mRows ); - const float COL_WIDTH = ( scaledWidth - (PADDING*2.0f) ) / static_cast( mConfig.mCols ); + const float scaledWidth = windowSize.x * PAGE_SCALE_FACTOR_X; + const float PADDING = windowSize.y / 64.0f; + const float ROW_HEIGHT = (scaledHeight - (PADDING * 2.0f)) / static_cast(mConfig.mRows); + const float COL_WIDTH = (scaledWidth - (PADDING * 2.0f)) / static_cast(mConfig.mCols); Vector2 dpi = window.GetDpi(); static int currentIconIndex = 0; - for( int y = 0; y < mConfig.mRows; ++y ) + for(int y = 0; y < mConfig.mRows; ++y) { - for( int x = 0; x < mConfig.mCols; ++x ) + for(int x = 0; x < mConfig.mCols; ++x) { // Create parent icon view Toolkit::Control iconView = Toolkit::Control::New(); - iconView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - iconView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + iconView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + iconView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); - if( !mConfig.mTableViewEnabled ) + if(!mConfig.mTableViewEnabled) { float rowX = x * COL_WIDTH + PADDING; float rowY = y * ROW_HEIGHT + PADDING; - iconView.SetProperty( Actor::Property::SIZE, Vector3( COL_WIDTH, ROW_HEIGHT, 1.0f ) ); - iconView.SetProperty( Actor::Property::POSITION, Vector3( rowX, rowY, 0.0f ) ); + iconView.SetProperty(Actor::Property::SIZE, Vector3(COL_WIDTH, ROW_HEIGHT, 1.0f)); + iconView.SetProperty(Actor::Property::POSITION, Vector3(rowX, rowY, 0.0f)); } else { - iconView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - iconView.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); + iconView.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + iconView.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); } Actor icon; - switch( mConfig.mIconType ) + switch(mConfig.mIconType) { case CHECKBOX: { - icon = CreateButton( currentIconIndex ); + icon = CreateButton(currentIconIndex); break; } case IMAGEVIEW: { - icon = CreateImageView( currentIconIndex ); + icon = CreateImageView(currentIconIndex); break; } } - if( mConfig.mIconLabelsEnabled ) + if(mConfig.mIconLabelsEnabled) { // create label - if( useTextLabel ) + if(useTextLabel) { - Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( DEMO_APPS_NAMES[currentIconIndex] ); - textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - textLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White. - textLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, ( ( static_cast( ROW_HEIGHT * LABEL_AREA ) * 72.0f ) / dpi.y ) * 0.25f ); - textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "TOP" ); - icon.Add( textLabel ); + Toolkit::TextLabel textLabel = Toolkit::TextLabel::New(DEMO_APPS_NAMES[currentIconIndex]); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + textLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + textLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + textLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Vector4(1.0f, 1.0f, 1.0f, 1.0f)); // White. + textLabel.SetProperty(Toolkit::TextLabel::Property::POINT_SIZE, ((static_cast(ROW_HEIGHT * LABEL_AREA) * 72.0f) / dpi.y) * 0.25f); + textLabel.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + textLabel.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "TOP"); + icon.Add(textLabel); } else { Property::Map map; - map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ). - Add( Toolkit::TextVisual::Property::TEXT, DEMO_APPS_NAMES[currentIconIndex] ). - Add( Toolkit::TextVisual::Property::TEXT_COLOR, Color::WHITE ). - Add( Toolkit::TextVisual::Property::POINT_SIZE, ( ( static_cast( ROW_HEIGHT * LABEL_AREA ) * 72.0f ) / dpi.y ) * 0.25f ). - Add( Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "CENTER" ). - Add( Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "TOP" ); + map.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::TEXT, DEMO_APPS_NAMES[currentIconIndex]).Add(Toolkit::TextVisual::Property::TEXT_COLOR, Color::WHITE).Add(Toolkit::TextVisual::Property::POINT_SIZE, ((static_cast(ROW_HEIGHT * LABEL_AREA) * 72.0f) / dpi.y) * 0.25f).Add(Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "CENTER").Add(Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "TOP"); Toolkit::Control control = Toolkit::Control::New(); - control.SetProperty( Toolkit::Control::Property::BACKGROUND, map ); - control.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - control.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - icon.Add( control ); + control.SetProperty(Toolkit::Control::Property::BACKGROUND, map); + control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + icon.Add(control); } } - iconView.Add( icon ); - page.Add( iconView ); + iconView.Add(icon); + page.Add(iconView); // We only have images and names for a certain number of icons. // Wrap around if we have used them all. - if( ++currentIconIndex == TOTAL_ICON_DEFINITIONS ) + if(++currentIconIndex == TOTAL_ICON_DEFINITIONS) { currentIconIndex = 0; } @@ -354,46 +329,46 @@ public: void CreateScript() { const int lastPage = mConfig.mPageCount - 1; - const int halfA = lastPage / 2; - const int halfB = lastPage / 2 + lastPage % 2; - mScriptFrameData.push_back( ScriptData( lastPage, 1.5f, true ) ); - mScriptFrameData.push_back( ScriptData( -lastPage, 1.5f, true ) ); - mScriptFrameData.push_back( ScriptData( halfA, 1.0f, true ) ); - mScriptFrameData.push_back( ScriptData( halfB, 1.0f, true ) ); - mScriptFrameData.push_back( ScriptData( -lastPage, 0.5f, false ) ); - mScriptFrameData.push_back( ScriptData( halfA, 0.5f, false ) ); - mScriptFrameData.push_back( ScriptData( halfB, 1.0f, true ) ); - mScriptFrameData.push_back( ScriptData( -halfA, 1.0f, true ) ); - mScriptFrameData.push_back( ScriptData( 1, 0.1f, true ) ); - mScriptFrameData.push_back( ScriptData( -1, 0.1f, true ) ); - mScriptFrameData.push_back( ScriptData( 1, 0.1f, true ) ); - mScriptFrameData.push_back( ScriptData( -1, 0.1f, true ) ); - mScriptFrameData.push_back( ScriptData( 1, 0.1f, true ) ); - mScriptFrameData.push_back( ScriptData( -1, 0.1f, true ) ); - mScriptFrameData.push_back( ScriptData( halfA, 1.0f, true ) ); + const int halfA = lastPage / 2; + const int halfB = lastPage / 2 + lastPage % 2; + mScriptFrameData.push_back(ScriptData(lastPage, 1.5f, true)); + mScriptFrameData.push_back(ScriptData(-lastPage, 1.5f, true)); + mScriptFrameData.push_back(ScriptData(halfA, 1.0f, true)); + mScriptFrameData.push_back(ScriptData(halfB, 1.0f, true)); + mScriptFrameData.push_back(ScriptData(-lastPage, 0.5f, false)); + mScriptFrameData.push_back(ScriptData(halfA, 0.5f, false)); + mScriptFrameData.push_back(ScriptData(halfB, 1.0f, true)); + mScriptFrameData.push_back(ScriptData(-halfA, 1.0f, true)); + mScriptFrameData.push_back(ScriptData(1, 0.1f, true)); + mScriptFrameData.push_back(ScriptData(-1, 0.1f, true)); + mScriptFrameData.push_back(ScriptData(1, 0.1f, true)); + mScriptFrameData.push_back(ScriptData(-1, 0.1f, true)); + mScriptFrameData.push_back(ScriptData(1, 0.1f, true)); + mScriptFrameData.push_back(ScriptData(-1, 0.1f, true)); + mScriptFrameData.push_back(ScriptData(halfA, 1.0f, true)); } void PopulatePages() { - Vector3 windowSize( mApplication.GetWindow().GetSize() ); + Vector3 windowSize(mApplication.GetWindow().GetSize()); - for( int i = 0; i < mConfig.mPageCount; ++i ) + for(int i = 0; i < mConfig.mPageCount; ++i) { // Create page. Actor page = AddPage(); // Populate icons. - AddIconsToPage( page, mConfig.mUseTextLabel ); + AddIconsToPage(page, mConfig.mUseTextLabel); // Move page 'a little bit up'. - page.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - page.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - page.SetProperty( Actor::Property::POSITION, Vector3( windowSize.x * i, 0.0f, 0.0f ) ); - mScrollParent.Add( page ); + page.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + page.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + page.SetProperty(Actor::Property::POSITION, Vector3(windowSize.x * i, 0.0f, 0.0f)); + mScrollParent.Add(page); } - mScrollParent.SetProperty( Actor::Property::OPACITY, 1.0f ); - mScrollParent.SetProperty( Actor::Property::SCALE, Vector3::ONE ); + mScrollParent.SetProperty(Actor::Property::OPACITY, 1.0f); + mScrollParent.SetProperty(Actor::Property::SCALE, Vector3::ONE); // Fade in. ShowAnimation(); @@ -401,41 +376,41 @@ public: void ShowAnimation() { - mShowAnimation = Animation::New( 1.0f ); - mShowAnimation.AnimateTo( Property( mScrollParent, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN_OUT ); - mShowAnimation.AnimateTo( Property( mScrollParent, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT ); - mShowAnimation.FinishedSignal().Connect( this, &HomescreenBenchmark::OnAnimationEnd ); + mShowAnimation = Animation::New(1.0f); + mShowAnimation.AnimateTo(Property(mScrollParent, Actor::Property::COLOR_ALPHA), 1.0f, AlphaFunction::EASE_IN_OUT); + mShowAnimation.AnimateTo(Property(mScrollParent, Actor::Property::SCALE), Vector3::ONE, AlphaFunction::EASE_IN_OUT); + mShowAnimation.FinishedSignal().Connect(this, &HomescreenBenchmark::OnAnimationEnd); mShowAnimation.Play(); } void ScrollPages(int pages, float duration, bool flick) { duration *= PAGE_DURATION_SCALE_FACTOR; - Vector3 windowSize( mApplication.GetWindow().GetSize() ); - mScrollAnimation = Animation::New( duration ); - if( flick ) + Vector3 windowSize(mApplication.GetWindow().GetSize()); + mScrollAnimation = Animation::New(duration); + if(flick) { - mScrollAnimation.AnimateBy( Property( mScrollParent, Actor::Property::POSITION ), Vector3( -windowSize.x * pages, 0.0f, 0.0f ), AlphaFunction::EASE_IN_OUT ); + mScrollAnimation.AnimateBy(Property(mScrollParent, Actor::Property::POSITION), Vector3(-windowSize.x * pages, 0.0f, 0.0f), AlphaFunction::EASE_IN_OUT); } else { - int totalPages = abs( pages ); - for( int i = 0; i < totalPages; ++i ) + int totalPages = abs(pages); + for(int i = 0; i < totalPages; ++i) { - mScrollAnimation.AnimateBy( Property( mScrollParent, Actor::Property::POSITION ), Vector3( pages < 0 ? windowSize.x : -windowSize.x, 0.0f, 0.0f ), AlphaFunction::EASE_IN_OUT, TimePeriod( duration * i, duration ) ); + mScrollAnimation.AnimateBy(Property(mScrollParent, Actor::Property::POSITION), Vector3(pages < 0 ? windowSize.x : -windowSize.x, 0.0f, 0.0f), AlphaFunction::EASE_IN_OUT, TimePeriod(duration * i, duration)); } } - mScrollAnimation.FinishedSignal().Connect( this, &HomescreenBenchmark::OnAnimationEnd ); + mScrollAnimation.FinishedSignal().Connect(this, &HomescreenBenchmark::OnAnimationEnd); mScrollAnimation.Play(); mCurrentPage += pages; } - void OnAnimationEnd( Animation& source ) + void OnAnimationEnd(Animation& source) { - if( mScriptFrame < mScriptFrameData.size() ) + if(mScriptFrame < mScriptFrameData.size()) { ScriptData& frame = mScriptFrameData[mScriptFrame]; - ScrollPages( frame.mPages, frame.mDuration, frame.mFlick ); + ScrollPages(frame.mPages, frame.mDuration, frame.mFlick); ++mScriptFrame; } else @@ -444,11 +419,11 @@ public: } } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -456,73 +431,72 @@ public: } private: - - Application& mApplication; - Actor mScrollParent; - Animation mShowAnimation; - Animation mScrollAnimation; - Config mConfig; - std::vector mScriptFrameData; - size_t mScriptFrame; - int mCurrentPage; + Application& mApplication; + Actor mScrollParent; + Animation mShowAnimation; + Animation mScrollAnimation; + Config mConfig; + std::vector mScriptFrameData; + size_t mScriptFrame; + int mCurrentPage; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { // Default settings. HomescreenBenchmark::Config config; bool printHelpAndExit = false; - for( int i = 1 ; i < argc; ++i ) + for(int i = 1; i < argc; ++i) { - std::string arg( argv[i] ); - if( arg.compare( 0, 2, "-r" ) == 0 ) + std::string arg(argv[i]); + if(arg.compare(0, 2, "-r") == 0) { - config.mRows = atoi( arg.substr( 2 ).c_str() ); + config.mRows = atoi(arg.substr(2).c_str()); } - else if( arg.compare( 0, 2, "-c" ) == 0 ) + else if(arg.compare(0, 2, "-c") == 0) { - config.mCols = atoi( arg.substr( 2 ).c_str() ); + config.mCols = atoi(arg.substr(2).c_str()); } - else if( arg.compare( 0, 2, "-p" ) == 0 ) + else if(arg.compare(0, 2, "-p") == 0) { - config.mPageCount = atoi( arg.substr( 2 ).c_str() ); + config.mPageCount = atoi(arg.substr(2).c_str()); } - else if( arg.compare( "--disable-tableview" ) == 0 ) + else if(arg.compare("--disable-tableview") == 0) { config.mTableViewEnabled = false; } - else if( arg.compare( "--disable-icon-labels" ) == 0 ) + else if(arg.compare("--disable-icon-labels") == 0) { config.mIconLabelsEnabled = false; } - else if( arg.compare( "--use-checkbox" ) == 0 ) + else if(arg.compare("--use-checkbox") == 0) { config.mIconType = CHECKBOX; } - else if( arg.compare("--use-text-label" ) == 0) + else if(arg.compare("--use-text-label") == 0) { config.mUseTextLabel = true; } - else if( arg.compare( "--help" ) == 0 ) + else if(arg.compare("--help") == 0) { printHelpAndExit = true; } } - Application application = Application::New( &argc, &argv ); - HomescreenBenchmark test( application, config ); + Application application = Application::New(&argc, &argv); + HomescreenBenchmark test(application, config); - if( printHelpAndExit ) + if(printHelpAndExit) { - PrintHelp( "c", " Number of columns" ); - PrintHelp( "r", " Number of rows" ); - PrintHelp( "p", " Number of pages ( must be greater than 1 )" ); - PrintHelp( "-disable-tableview", " Disables the use of TableView for layouting" ); - PrintHelp( "-disable-icon-labels", " Disables labels for each icon" ); - PrintHelp( "-use-checkbox", " Uses checkboxes for icons" ); - PrintHelp( "-use-text-label", " Uses TextLabel instead of a TextVisual" ); + PrintHelp("c", " Number of columns"); + PrintHelp("r", " Number of rows"); + PrintHelp("p", " Number of pages ( must be greater than 1 )"); + PrintHelp("-disable-tableview", " Disables the use of TableView for layouting"); + PrintHelp("-disable-icon-labels", " Disables labels for each icon"); + PrintHelp("-use-checkbox", " Uses checkboxes for icons"); + PrintHelp("-use-text-label", " Uses TextLabel instead of a TextVisual"); return 0; } diff --git a/examples/image-policies/image-policies-example.cpp b/examples/image-policies/image-policies-example.cpp index 3014b3d..e78f934 100644 --- a/examples/image-policies/image-policies-example.cpp +++ b/examples/image-policies/image-policies-example.cpp @@ -15,33 +15,32 @@ * */ -#include -#include "shared/view.h" -#include #include #include -#include -#include #include +#include #include +#include +#include +#include "shared/view.h" using namespace Dali; using namespace Toolkit; namespace { -const char* NEXT_BUTTON_IMAGE( DEMO_IMAGE_DIR "DarkStyleGreenArrowButton.png" ); -const char* NEXT_BUTTON_PRESSED_IMAGE( DEMO_IMAGE_DIR "DarkStyleGreyArrowButton.png" ); -const char* NEXT_BUTTON_DISABLED_IMAGE( DEMO_IMAGE_DIR "DarkStyleDisabledArrowButton.png" ); -const char* OK_IMAGE_IMAGE( DEMO_IMAGE_DIR "FontStyleButton_OK_02.png" ); -const char* LOADING_IMAGE( DEMO_IMAGE_DIR "animatedLoading.gif" ); +const char* NEXT_BUTTON_IMAGE(DEMO_IMAGE_DIR "DarkStyleGreenArrowButton.png"); +const char* NEXT_BUTTON_PRESSED_IMAGE(DEMO_IMAGE_DIR "DarkStyleGreyArrowButton.png"); +const char* NEXT_BUTTON_DISABLED_IMAGE(DEMO_IMAGE_DIR "DarkStyleDisabledArrowButton.png"); +const char* OK_IMAGE_IMAGE(DEMO_IMAGE_DIR "FontStyleButton_OK_02.png"); +const char* LOADING_IMAGE(DEMO_IMAGE_DIR "animatedLoading.gif"); const char* IMAGE_PATH[] = { - DEMO_IMAGE_DIR "gallery-small-23.jpg", - DEMO_IMAGE_DIR "woodEffect.jpg", - DEMO_IMAGE_DIR "heartsframe.9.png", - DEMO_IMAGE_DIR "keyboard-Landscape.jpg", - DEMO_IMAGE_DIR "keyboard-LandscapeCopy.jpg", + DEMO_IMAGE_DIR "gallery-small-23.jpg", + DEMO_IMAGE_DIR "woodEffect.jpg", + DEMO_IMAGE_DIR "heartsframe.9.png", + DEMO_IMAGE_DIR "keyboard-Landscape.jpg", + DEMO_IMAGE_DIR "keyboard-LandscapeCopy.jpg", }; /** @@ -58,7 +57,7 @@ enum TableRowPlacement NUMBER_OF_ROWS }; -} // namespace +} // namespace /** * Examples showing the various polices of ImageVisual in use. @@ -66,19 +65,18 @@ enum TableRowPlacement * Large images are used to cause loading time to be long enough to show differences. * If hardware causes loading time improve then remote images or larger images may be required in future. */ -class ImagePolicies: public ConnectionTracker +class ImagePolicies : public ConnectionTracker { - public: - +public: /** * Constructor */ - ImagePolicies( Application& application ) - : mApplication( application ), - mExampleIndex( 0 ) + ImagePolicies(Application& application) + : mApplication(application), + mExampleIndex(0) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImagePolicies::Create ); + mApplication.InitSignal().Connect(this, &ImagePolicies::Create); } /** @@ -86,9 +84,9 @@ class ImagePolicies: public ConnectionTracker * This function allows the control (Image view in this case) to attached to the Image loading signal * and re-enable the button after Image has loaded. */ - void ResourceReadySignal( Control control ) + void ResourceReadySignal(Control control) { - mNextButton.SetProperty( Button::Property::DISABLED, false ); + mNextButton.SetProperty(Button::Property::DISABLED, false); } /** @@ -100,29 +98,28 @@ class ImagePolicies: public ConnectionTracker * param[in] imageFilenameId Which image to load, referring to the array of filenames for this example. * return An ImageView with the required set up */ - ImageView CreateImageView( bool correctionEnabled, ImageVisual::LoadPolicy::Type loadPolicy, ImageVisual::ReleasePolicy::Type releasePolicy, bool synchronousLoading, unsigned int imageFilenameId ) + ImageView CreateImageView(bool correctionEnabled, ImageVisual::LoadPolicy::Type loadPolicy, ImageVisual::ReleasePolicy::Type releasePolicy, bool synchronousLoading, unsigned int imageFilenameId) { - ImageView imageView = ImageView::New( ); + ImageView imageView = ImageView::New(); Property::Map imagePropertyMap; - imagePropertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - imagePropertyMap.Insert( ImageVisual::Property::URL, IMAGE_PATH[imageFilenameId ] ); - imagePropertyMap.Insert( ImageVisual::Property::ORIENTATION_CORRECTION, correctionEnabled ); - imagePropertyMap.Insert( ImageVisual::Property::LOAD_POLICY, loadPolicy ); - imagePropertyMap.Insert( ImageVisual::Property::RELEASE_POLICY, releasePolicy ); - if( synchronousLoading ) + imagePropertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); + imagePropertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATH[imageFilenameId]); + imagePropertyMap.Insert(ImageVisual::Property::ORIENTATION_CORRECTION, correctionEnabled); + imagePropertyMap.Insert(ImageVisual::Property::LOAD_POLICY, loadPolicy); + imagePropertyMap.Insert(ImageVisual::Property::RELEASE_POLICY, releasePolicy); + if(synchronousLoading) { - imagePropertyMap.Insert( DevelImageVisual::Property::SYNCHRONOUS_LOADING, true ); + imagePropertyMap.Insert(DevelImageVisual::Property::SYNCHRONOUS_LOADING, true); } - imageView.SetProperty(ImageView::Property::IMAGE , imagePropertyMap ); + imageView.SetProperty(ImageView::Property::IMAGE, imagePropertyMap); - imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - imageView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + imageView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); return imageView; } - /** * To prevent the next button being pressed before an Image has loaded the Button can br disabled. * This function will disable the next button. @@ -131,7 +128,7 @@ class ImagePolicies: public ConnectionTracker void DisableButtonWhilstLoading() { - mNextButton.SetProperty( Button::Property::DISABLED, true ); + mNextButton.SetProperty(Button::Property::DISABLED, true); } /** @@ -139,15 +136,14 @@ class ImagePolicies: public ConnectionTracker */ void OrientationCorrectionExampleNoCorrection() { - - mTitle.SetProperty( Toolkit::TextLabel::Property::TEXT, "Orientation Correction" ); - mInstructions.SetProperty( TextLabel::Property::TEXT, "Orientation Correction not applied"); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, "Orientation Correction"); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Orientation Correction not applied"); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); DisableButtonWhilstLoading(); - ImageView imageView01 = CreateImageView( false, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + ImageView imageView01 = CreateImageView(false, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); - mTable.AddChild( imageView01, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTable.AddChild(imageView01, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); } /** @@ -155,12 +151,12 @@ class ImagePolicies: public ConnectionTracker */ void OrientationCorrectionExampleWithCorrection() { - mInstructions.SetProperty( TextLabel::Property::TEXT, "Orientation Correction applied based on Exif data, now shown in landscape"); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Orientation Correction applied based on Exif data, now shown in landscape"); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); DisableButtonWhilstLoading(); - ImageView imageView01 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); - mTable.AddChild( imageView01, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + ImageView imageView01 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); + mTable.AddChild(imageView01, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); } /** @@ -169,27 +165,27 @@ class ImagePolicies: public ConnectionTracker */ void LoadPolicyImmediateExampleInstructions() { - mTitle.SetProperty( Toolkit::TextLabel::Property::TEXT, "Immediate Loading Policy"); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); - mInstructions.SetProperty( TextLabel::Property::TEXT, "Loading Image before staging, press next to see it in right column"); - TableView dualImageViewTable = TableView::New( 1, 2 ); - dualImageViewTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - dualImageViewTable.SetProperty( Dali::Actor::Property::NAME,"dualTable"); - dualImageViewTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - dualImageViewTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - dualImageViewTable.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + mTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, "Immediate Loading Policy"); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Loading Image before staging, press next to see it in right column"); + TableView dualImageViewTable = TableView::New(1, 2); + dualImageViewTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + dualImageViewTable.SetProperty(Dali::Actor::Property::NAME, "dualTable"); + dualImageViewTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + dualImageViewTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + dualImageViewTable.SetCellPadding(Vector2(6.0f, 0.0f)); TextLabel attached = TextLabel::New("ATTACHED loaded image \nWill appear here"); - attached.SetProperty( TextLabel::Property::MULTI_LINE, true ); + attached.SetProperty(TextLabel::Property::MULTI_LINE, true); TextLabel immediate = TextLabel::New("IMMEDIATE loaded image \nWill appear here"); - immediate.SetProperty( TextLabel::Property::MULTI_LINE, true ); + immediate.SetProperty(TextLabel::Property::MULTI_LINE, true); - dualImageViewTable.AddChild( attached, TableView::CellPosition( 0, 0 ) ); - dualImageViewTable.AddChild( immediate, TableView::CellPosition( 0, 1 ) ); - mTable.AddChild( dualImageViewTable, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + dualImageViewTable.AddChild(attached, TableView::CellPosition(0, 0)); + dualImageViewTable.AddChild(immediate, TableView::CellPosition(0, 1)); + mTable.AddChild(dualImageViewTable, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); DisableButtonWhilstLoading(); - mPersistantImageView = CreateImageView( true, ImageVisual::LoadPolicy::IMMEDIATE, ImageVisual::ReleasePolicy::DESTROYED, false, 4 ); - mPersistantImageView.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + mPersistantImageView = CreateImageView(true, ImageVisual::LoadPolicy::IMMEDIATE, ImageVisual::ReleasePolicy::DESTROYED, false, 4); + mPersistantImageView.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); } /** @@ -197,29 +193,29 @@ class ImagePolicies: public ConnectionTracker */ void LoadPolicyImmediateExample() { - mInstructions.SetProperty( TextLabel::Property::TEXT, "Immediate loading policy on only second column hence image load was almost instant."); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Immediate loading policy on only second column hence image load was almost instant."); DisableButtonWhilstLoading(); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); - TableView dualImageViewTable = TableView::New( 2, 2 ); - dualImageViewTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - dualImageViewTable.SetProperty( Dali::Actor::Property::NAME,"dualTable"); - dualImageViewTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - dualImageViewTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - dualImageViewTable.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + TableView dualImageViewTable = TableView::New(2, 2); + dualImageViewTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + dualImageViewTable.SetProperty(Dali::Actor::Property::NAME, "dualTable"); + dualImageViewTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + dualImageViewTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + dualImageViewTable.SetCellPadding(Vector2(6.0f, 0.0f)); - TextLabel attached = TextLabel::New("ATTACHED"); + TextLabel attached = TextLabel::New("ATTACHED"); TextLabel immediate = TextLabel::New("IMMEDIATE"); - dualImageViewTable.AddChild( attached, TableView::CellPosition( 1, 0 ) ); - dualImageViewTable.AddChild( immediate, TableView::CellPosition( 1, 1 ) ); - dualImageViewTable.SetFitHeight( 1 ); + dualImageViewTable.AddChild(attached, TableView::CellPosition(1, 0)); + dualImageViewTable.AddChild(immediate, TableView::CellPosition(1, 1)); + dualImageViewTable.SetFitHeight(1); - mTable.AddChild( dualImageViewTable, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTable.AddChild(dualImageViewTable, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); - ImageView imageView02 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView02.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); - dualImageViewTable.AddChild( imageView02, TableView::CellPosition( 0, 0 ) ); - dualImageViewTable.AddChild( mPersistantImageView, TableView::CellPosition( 0, 1 ) ); + ImageView imageView02 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView02.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); + dualImageViewTable.AddChild(imageView02, TableView::CellPosition(0, 0)); + dualImageViewTable.AddChild(mPersistantImageView, TableView::CellPosition(0, 1)); } /** @@ -227,23 +223,23 @@ class ImagePolicies: public ConnectionTracker */ void LoadPolicyDestroyedExample() { - mTitle.SetProperty( Toolkit::TextLabel::Property::TEXT, "Release Policy DESTROYED"); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, "Release Policy DESTROYED"); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); mPersistantImageView.Reset(); - mInstructions.SetProperty( TextLabel::Property::TEXT, "ReleasePolicy::DESTROYED shown in first column, press next to destroy it."); + mInstructions.SetProperty(TextLabel::Property::TEXT, "ReleasePolicy::DESTROYED shown in first column, press next to destroy it."); DisableButtonWhilstLoading(); - TableView dualImageViewTable = TableView::New( 1, 2 ); - dualImageViewTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - dualImageViewTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - dualImageViewTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - dualImageViewTable.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + TableView dualImageViewTable = TableView::New(1, 2); + dualImageViewTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + dualImageViewTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + dualImageViewTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + dualImageViewTable.SetCellPadding(Vector2(6.0f, 0.0f)); - mTable.AddChild( dualImageViewTable, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTable.AddChild(dualImageViewTable, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); - ImageView imageView01 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + ImageView imageView01 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); - dualImageViewTable.AddChild( imageView01, TableView::CellPosition( 0, 0 ) ); + dualImageViewTable.AddChild(imageView01, TableView::CellPosition(0, 0)); } /** @@ -252,21 +248,21 @@ class ImagePolicies: public ConnectionTracker */ void LoadPolicyDestroyedExample02() { - mInstructions.SetProperty( TextLabel::Property::TEXT, "Destroyed first image and reloaded in second column (loading took some time)"); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Destroyed first image and reloaded in second column (loading took some time)"); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); DisableButtonWhilstLoading(); - TableView dualImageViewTable = TableView::New( 1, 2 ); - dualImageViewTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - dualImageViewTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - dualImageViewTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - dualImageViewTable.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + TableView dualImageViewTable = TableView::New(1, 2); + dualImageViewTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + dualImageViewTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + dualImageViewTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + dualImageViewTable.SetCellPadding(Vector2(6.0f, 0.0f)); - mTable.AddChild( dualImageViewTable, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTable.AddChild(dualImageViewTable, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); - ImageView imageView01 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + ImageView imageView01 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); - dualImageViewTable.AddChild( imageView01, TableView::CellPosition( 0, 1 ) ); + dualImageViewTable.AddChild(imageView01, TableView::CellPosition(0, 1)); } /** @@ -274,22 +270,22 @@ class ImagePolicies: public ConnectionTracker */ void ReleasePolicyDestroyedExample03() { - mTitle.SetProperty( Toolkit::TextLabel::Property::TEXT, "Detaching with DESTROYED Policy"); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); - mInstructions.SetProperty( TextLabel::Property::TEXT, "Image with ReleasePolicy::DESTROYED shown in first column, Image will be detached, reusing it will be fast"); + mTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, "Detaching with DESTROYED Policy"); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Image with ReleasePolicy::DESTROYED shown in first column, Image will be detached, reusing it will be fast"); DisableButtonWhilstLoading(); - TableView dualImageViewTable = TableView::New( 1, 2 ); - dualImageViewTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - dualImageViewTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - dualImageViewTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - dualImageViewTable.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + TableView dualImageViewTable = TableView::New(1, 2); + dualImageViewTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + dualImageViewTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + dualImageViewTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + dualImageViewTable.SetCellPadding(Vector2(6.0f, 0.0f)); - mTable.AddChild( dualImageViewTable, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTable.AddChild(dualImageViewTable, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); - ImageView imageView01 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + ImageView imageView01 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); - dualImageViewTable.AddChild( imageView01, TableView::CellPosition( 0, 0 ) ); + dualImageViewTable.AddChild(imageView01, TableView::CellPosition(0, 0)); } /** @@ -297,16 +293,16 @@ class ImagePolicies: public ConnectionTracker */ void ReleasePolicyDestroyedExample04() { - mInstructions.SetProperty( TextLabel::Property::TEXT, "Detached first image and reloaded in second column, loading should have seemed instant"); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Detached first image and reloaded in second column, loading should have seemed instant"); DisableButtonWhilstLoading(); - TableView dualImageViewTable = TableView::DownCast( mTable.GetChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ) ); - ImageView imageViewDetached = ImageView::DownCast( dualImageViewTable.GetChildAt( TableView::CellPosition( 0, 0 ) ) ); - dualImageViewTable.RemoveChildAt( TableView::CellPosition( 0, 0 ) ); + TableView dualImageViewTable = TableView::DownCast(mTable.GetChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0))); + ImageView imageViewDetached = ImageView::DownCast(dualImageViewTable.GetChildAt(TableView::CellPosition(0, 0))); + dualImageViewTable.RemoveChildAt(TableView::CellPosition(0, 0)); - ImageView imageView01 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + ImageView imageView01 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); - dualImageViewTable.AddChild( imageView01, TableView::CellPosition( 0, 1 ) ); + dualImageViewTable.AddChild(imageView01, TableView::CellPosition(0, 1)); } /** @@ -314,22 +310,22 @@ class ImagePolicies: public ConnectionTracker */ void ReleasePolicyDestroyedExample05() { - mTitle.SetProperty( Toolkit::TextLabel::Property::TEXT, "Detaching with DETACHED Policy"); - mTable.RemoveChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); - mInstructions.SetProperty( TextLabel::Property::TEXT, "Image with ReleasePolicy::DETACHED shown in first column, will be detached and reloaded"); + mTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, "Detaching with DETACHED Policy"); + mTable.RemoveChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0)); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Image with ReleasePolicy::DETACHED shown in first column, will be detached and reloaded"); DisableButtonWhilstLoading(); - TableView dualImageViewTable = TableView::New( 1, 2 ); - dualImageViewTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - dualImageViewTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - dualImageViewTable.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - dualImageViewTable.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + TableView dualImageViewTable = TableView::New(1, 2); + dualImageViewTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + dualImageViewTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + dualImageViewTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + dualImageViewTable.SetCellPadding(Vector2(6.0f, 0.0f)); - mTable.AddChild( dualImageViewTable, TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ); + mTable.AddChild(dualImageViewTable, TableView::CellPosition(TableRowPlacement::IMAGE, 0)); - ImageView imageView01 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DETACHED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + ImageView imageView01 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DETACHED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); - dualImageViewTable.AddChild( imageView01, TableView::CellPosition( 0, 0 ) ); + dualImageViewTable.AddChild(imageView01, TableView::CellPosition(0, 0)); } /** @@ -338,90 +334,90 @@ class ImagePolicies: public ConnectionTracker */ void ReleasePolicyDestroyedExample06() { - mInstructions.SetProperty( TextLabel::Property::TEXT, "Detached first image and reloaded in second column, loading took some time"); + mInstructions.SetProperty(TextLabel::Property::TEXT, "Detached first image and reloaded in second column, loading took some time"); DisableButtonWhilstLoading(); - TableView dualImageViewTable = TableView::DownCast( mTable.GetChildAt( TableView::CellPosition( TableRowPlacement::IMAGE, 0 ) ) ); - ImageView imageViewDetached = ImageView::DownCast( dualImageViewTable.GetChildAt( TableView::CellPosition( 0, 0 ) ) ); - dualImageViewTable.RemoveChildAt( TableView::CellPosition( 0, 0 ) ); + TableView dualImageViewTable = TableView::DownCast(mTable.GetChildAt(TableView::CellPosition(TableRowPlacement::IMAGE, 0))); + ImageView imageViewDetached = ImageView::DownCast(dualImageViewTable.GetChildAt(TableView::CellPosition(0, 0))); + dualImageViewTable.RemoveChildAt(TableView::CellPosition(0, 0)); - ImageView imageView01 = CreateImageView( true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3 ); - imageView01.ResourceReadySignal().Connect( this, &ImagePolicies::ResourceReadySignal ); + ImageView imageView01 = CreateImageView(true, ImageVisual::LoadPolicy::ATTACHED, ImageVisual::ReleasePolicy::DESTROYED, false, 3); + imageView01.ResourceReadySignal().Connect(this, &ImagePolicies::ResourceReadySignal); - dualImageViewTable.AddChild( imageView01, TableView::CellPosition( 0, 1 ) ); + dualImageViewTable.AddChild(imageView01, TableView::CellPosition(0, 1)); } /** * Created a gradient property map that will produce a Gradient Visual * param[out] gradientMap the output property map */ - void CreateGradient( Property::Map& gradientMap ) + void CreateGradient(Property::Map& gradientMap) { - gradientMap.Insert( Toolkit::Visual::Property::TYPE, Visual::GRADIENT ); + gradientMap.Insert(Toolkit::Visual::Property::TYPE, Visual::GRADIENT); Property::Array stopOffsets; - stopOffsets.PushBack( 0.0f ); - stopOffsets.PushBack( 0.6f ); - stopOffsets.PushBack( 1.0f ); - gradientMap.Insert( GradientVisual::Property::STOP_OFFSET, stopOffsets ); + stopOffsets.PushBack(0.0f); + stopOffsets.PushBack(0.6f); + stopOffsets.PushBack(1.0f); + gradientMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets); Property::Array stopColors; - stopColors.PushBack( Vector4( 54.f, 140.f, 207.f, 223.f )/255.f ); - stopColors.PushBack( Vector4( 54.f, 170.f, 207.f, 123.f )/255.f ); - stopColors.PushBack( Vector4( 54.f, 189.f, 207.f, 123.f )/255.f ); - gradientMap.Insert( GradientVisual::Property::STOP_COLOR, stopColors ); + stopColors.PushBack(Vector4(54.f, 140.f, 207.f, 223.f) / 255.f); + stopColors.PushBack(Vector4(54.f, 170.f, 207.f, 123.f) / 255.f); + stopColors.PushBack(Vector4(54.f, 189.f, 207.f, 123.f) / 255.f); + gradientMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors); - gradientMap.Insert( GradientVisual::Property::START_POSITION, Vector2( 0.5f, 0.5f ) ); - gradientMap.Insert( GradientVisual::Property::END_POSITION, Vector2( -0.5f, -0.5f ) ); + gradientMap.Insert(GradientVisual::Property::START_POSITION, Vector2(0.5f, 0.5f)); + gradientMap.Insert(GradientVisual::Property::END_POSITION, Vector2(-0.5f, -0.5f)); } /** * Start of this example, called once when the application is initiated */ - void Create( Application& application ) + void Create(Application& application) { Property::Map gradientBackground; - CreateGradient( gradientBackground ); + CreateGradient(gradientBackground); // Get a handle to the window Window window = application.GetWindow(); // Create default View. Toolkit::Control view = Toolkit::Control::New(); - view.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - view.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); - view.SetProperty( Toolkit::Control::Property::BACKGROUND , gradientBackground ); - window.Add( view ); + view.SetProperty(Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + view.SetProperty(Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + view.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); + view.SetProperty(Toolkit::Control::Property::BACKGROUND, gradientBackground); + window.Add(view); // Create a table view to show a pair of buttons above each image. - mTable = TableView::New( TableRowPlacement::NUMBER_OF_ROWS, 1 ); - mTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Vector3 offset( 0.9f, 0.90f, 0.0f ); - mTable.SetProperty( Actor::Property::SIZE_MODE_FACTOR, offset ); - mTable.SetFitHeight( TableRowPlacement::NEXT_BUTTON ); - mTable.SetFitHeight( TableRowPlacement::LOADING_STATUS ); - view.Add( mTable ); + mTable = TableView::New(TableRowPlacement::NUMBER_OF_ROWS, 1); + mTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mTable.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + Vector3 offset(0.9f, 0.90f, 0.0f); + mTable.SetProperty(Actor::Property::SIZE_MODE_FACTOR, offset); + mTable.SetFitHeight(TableRowPlacement::NEXT_BUTTON); + mTable.SetFitHeight(TableRowPlacement::LOADING_STATUS); + view.Add(mTable); // Create Next button mNextButton = PushButton::New(); Property::Map imagePropertyMap; - imagePropertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - imagePropertyMap.Insert( ImageVisual::Property::URL, NEXT_BUTTON_IMAGE ); - mNextButton.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, imagePropertyMap ); + imagePropertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); + imagePropertyMap.Insert(ImageVisual::Property::URL, NEXT_BUTTON_IMAGE); + mNextButton.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, imagePropertyMap); imagePropertyMap.Clear(); - imagePropertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE ); - imagePropertyMap.Insert( ImageVisual::Property::URL, NEXT_BUTTON_PRESSED_IMAGE ); - mNextButton.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, imagePropertyMap ); - mNextButton.SetProperty( Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, LOADING_IMAGE ); - mNextButton.SetProperty( Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, NEXT_BUTTON_DISABLED_IMAGE ); - mNextButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mNextButton.SetProperty( Actor::Property::POSITION_Y, -50.0f ); - mNextButton.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) ); - mNextButton.ClickedSignal().Connect( this, &ImagePolicies::ChangeImageClicked ); - mTable.AddChild( mNextButton, TableView::CellPosition( TableRowPlacement::NEXT_BUTTON, 0 ) ); - mTable.SetCellPadding( Vector2( 2.0f, 2.0f ) ); + imagePropertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE); + imagePropertyMap.Insert(ImageVisual::Property::URL, NEXT_BUTTON_PRESSED_IMAGE); + mNextButton.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, imagePropertyMap); + mNextButton.SetProperty(Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, LOADING_IMAGE); + mNextButton.SetProperty(Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, NEXT_BUTTON_DISABLED_IMAGE); + mNextButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mNextButton.SetProperty(Actor::Property::POSITION_Y, -50.0f); + mNextButton.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + mNextButton.ClickedSignal().Connect(this, &ImagePolicies::ChangeImageClicked); + mTable.AddChild(mNextButton, TableView::CellPosition(TableRowPlacement::NEXT_BUTTON, 0)); + mTable.SetCellPadding(Vector2(2.0f, 2.0f)); window.KeyEventSignal().Connect(this, &ImagePolicies::OnKeyEvent); @@ -431,84 +427,83 @@ class ImagePolicies: public ConnectionTracker outlineMap["width"] = 1.0f; // Create Title Label - mTitle = TextLabel::New("Image Polices"); - mTitle.SetProperty( TextLabel::Property::TEXT_COLOR, Color::CYAN ); - mTable.AddChild( mTitle, TableView::CellPosition( TableRowPlacement::TITLE, 0 ) ); - mTable.SetFitHeight( TableRowPlacement::TITLE ); + mTitle = TextLabel::New("Image Polices"); + mTitle.SetProperty(TextLabel::Property::TEXT_COLOR, Color::CYAN); + mTable.AddChild(mTitle, TableView::CellPosition(TableRowPlacement::TITLE, 0)); + mTable.SetFitHeight(TableRowPlacement::TITLE); // Create Instructions label mInstructions = TextLabel::New("This is an explaination of each example"); - mInstructions.SetProperty( TextLabel::Property::MULTI_LINE, true ); - mInstructions.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mInstructions.SetProperty( TextLabel::Property::OUTLINE, outlineMap ); - mInstructions.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mTable.AddChild( mInstructions, TableView::CellPosition( TableRowPlacement::INSTRUCTIONS, 0 ) ); - float value = mInstructions.GetProperty( TextLabel::Property::PIXEL_SIZE ); - mTable.SetFixedHeight( TableRowPlacement::INSTRUCTIONS, value * 5 ); // Space allocated for example instructions - - ChangeImageClicked( mNextButton ); // Start examples ( 0 ) + mInstructions.SetProperty(TextLabel::Property::MULTI_LINE, true); + mInstructions.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + mInstructions.SetProperty(TextLabel::Property::OUTLINE, outlineMap); + mInstructions.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mTable.AddChild(mInstructions, TableView::CellPosition(TableRowPlacement::INSTRUCTIONS, 0)); + float value = mInstructions.GetProperty(TextLabel::Property::PIXEL_SIZE); + mTable.SetFixedHeight(TableRowPlacement::INSTRUCTIONS, value * 5); // Space allocated for example instructions + + ChangeImageClicked(mNextButton); // Start examples ( 0 ) } private: - /** * Callback to the button clicked signal and starts the next example. */ - bool ChangeImageClicked( Button button ) + bool ChangeImageClicked(Button button) { - switch ( mExampleIndex++ ) + switch(mExampleIndex++) { - case 0 : + case 0: { OrientationCorrectionExampleNoCorrection(); break; } - case 1 : + case 1: { OrientationCorrectionExampleWithCorrection(); break; } - case 2 : + case 2: { LoadPolicyImmediateExampleInstructions(); break; } - case 3 : + case 3: { LoadPolicyImmediateExample(); break; } - case 4 : + case 4: { LoadPolicyDestroyedExample(); break; } - case 5 : + case 5: { LoadPolicyDestroyedExample02(); break; } - case 6 : + case 6: { ReleasePolicyDestroyedExample03(); break; } - case 7 : + case 7: { ReleasePolicyDestroyedExample04(); break; } - case 8 : + case 8: { ReleasePolicyDestroyedExample05(); break; } - case 9 : + case 9: { ReleasePolicyDestroyedExample06(); // Change Next button to complete button ( will quit app once pressed ) - button.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, OK_IMAGE_IMAGE ); - button.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, OK_IMAGE_IMAGE ); + button.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, OK_IMAGE_IMAGE); + button.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, OK_IMAGE_IMAGE); break; } default: @@ -527,7 +522,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -537,19 +532,19 @@ private: private: Application& mApplication; - TableView mTable; - TextLabel mInstructions; - TextLabel mTitle; - PushButton mNextButton; - ImageView mPersistantImageView; + TableView mTable; + TextLabel mInstructions; + TextLabel mTitle; + PushButton mNextButton; + ImageView mPersistantImageView; unsigned int mExampleIndex; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - ImagePolicies test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + ImagePolicies test(application); application.MainLoop(); return 0; } diff --git a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp index e79ff90..076f925 100644 --- a/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp +++ b/examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp @@ -15,76 +15,74 @@ * */ -#include -#include #include #include #include -#include "shared/view.h" +#include +#include #include +#include "shared/view.h" using namespace Dali; using Toolkit::TextLabel; namespace { +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-gradient.jpg"); +const Vector4 BACKGROUND_COLOUR(1.0f, 1.0f, 1.0f, 0.15f); -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-gradient.jpg" ); -const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); - -const char* BORDER_IMAGE( DEMO_IMAGE_DIR "border-4px.9.png" ); -const int BORDER_WIDTH = ( 11.0f + 4.0f ); // Shadow size = 11, border size = 4. -const char* RESIZE_HANDLE_IMAGE( DEMO_IMAGE_DIR "resize-handle.png" ); +const char* BORDER_IMAGE(DEMO_IMAGE_DIR "border-4px.9.png"); +const int BORDER_WIDTH = (11.0f + 4.0f); // Shadow size = 11, border size = 4. +const char* RESIZE_HANDLE_IMAGE(DEMO_IMAGE_DIR "resize-handle.png"); const int MARGIN_SIZE = 10; -const char* const NEXT_BUTTON_ID = "NEXT_BUTTON"; +const char* const NEXT_BUTTON_ID = "NEXT_BUTTON"; const char* const PREVIOUS_BUTTON_ID = "PREVIOUS_BUTTON"; -const char * const DALI_ICON_PLAY = DEMO_IMAGE_DIR "icon-play.png"; +const char* const DALI_ICON_PLAY = DEMO_IMAGE_DIR "icon-play.png"; -const char* const FITTING_BUTTON_ID = "FITTING_BUTTON"; -const char* const SAMPLING_BUTTON_ID = "SAMPLING_BUTTON"; -const char* const FITTING_BUTTON_TEXT = "Fitting"; +const char* const FITTING_BUTTON_ID = "FITTING_BUTTON"; +const char* const SAMPLING_BUTTON_ID = "SAMPLING_BUTTON"; +const char* const FITTING_BUTTON_TEXT = "Fitting"; const char* const SAMPLING_BUTTON_TEXT = "Sampling"; const char* const STYLE_LABEL_TEXT = "ImageScalingGroupLabel"; const char* const STYLE_BUTTON_TEXT = "ImageScalingButton"; const char* IMAGE_PATHS[] = -{ - // Variety of sizes, shapes and formats: - DEMO_IMAGE_DIR "dali-logo.png", - DEMO_IMAGE_DIR "layer1.png", - DEMO_IMAGE_DIR "layer2.png", - DEMO_IMAGE_DIR "animation-list.png", - DEMO_IMAGE_DIR "music-libray-main-screen.png", - DEMO_IMAGE_DIR "music-libray-record-cover.png", - DEMO_IMAGE_DIR "contacts-background.png", - DEMO_IMAGE_DIR "portrait_screen_primitive_shapes.gif", - DEMO_IMAGE_DIR "landscape_screen_primitive_shapes.gif", - DEMO_IMAGE_DIR "square_primitive_shapes.bmp", - DEMO_IMAGE_DIR "gallery-large-14.jpg", - DEMO_IMAGE_DIR "book-landscape-cover.jpg", - DEMO_IMAGE_DIR "book-portrait-p1.jpg", - DEMO_IMAGE_DIR "book-landscape-cover-back.jpg", - - // Worst case for aliasing in downscaling, 2k x 2k 1 bit per pixel dithered - // black and white image: - DEMO_IMAGE_DIR "gallery-large-14.wbmp", - - DEMO_IMAGE_DIR "background-1.jpg", - DEMO_IMAGE_DIR "background-blocks.jpg", - DEMO_IMAGE_DIR "background-magnifier.jpg", - DEMO_IMAGE_DIR "gallery-large-14.jpg", - NULL -}; + { + // Variety of sizes, shapes and formats: + DEMO_IMAGE_DIR "dali-logo.png", + DEMO_IMAGE_DIR "layer1.png", + DEMO_IMAGE_DIR "layer2.png", + DEMO_IMAGE_DIR "animation-list.png", + DEMO_IMAGE_DIR "music-libray-main-screen.png", + DEMO_IMAGE_DIR "music-libray-record-cover.png", + DEMO_IMAGE_DIR "contacts-background.png", + DEMO_IMAGE_DIR "portrait_screen_primitive_shapes.gif", + DEMO_IMAGE_DIR "landscape_screen_primitive_shapes.gif", + DEMO_IMAGE_DIR "square_primitive_shapes.bmp", + DEMO_IMAGE_DIR "gallery-large-14.jpg", + DEMO_IMAGE_DIR "book-landscape-cover.jpg", + DEMO_IMAGE_DIR "book-portrait-p1.jpg", + DEMO_IMAGE_DIR "book-landscape-cover-back.jpg", + + // Worst case for aliasing in downscaling, 2k x 2k 1 bit per pixel dithered + // black and white image: + DEMO_IMAGE_DIR "gallery-large-14.wbmp", + + DEMO_IMAGE_DIR "background-1.jpg", + DEMO_IMAGE_DIR "background-blocks.jpg", + DEMO_IMAGE_DIR "background-magnifier.jpg", + DEMO_IMAGE_DIR "gallery-large-14.jpg", + NULL}; const int NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u; /** Cycle the scaling mode options. */ -FittingMode::Type NextScalingMode( FittingMode::Type oldMode ) +FittingMode::Type NextScalingMode(FittingMode::Type oldMode) { FittingMode::Type newMode = FittingMode::SHRINK_TO_FIT; - switch ( oldMode ) + switch(oldMode) { case FittingMode::SHRINK_TO_FIT: newMode = FittingMode::SCALE_TO_FILL; @@ -103,11 +101,11 @@ FittingMode::Type NextScalingMode( FittingMode::Type oldMode ) } /** Cycle through filter mode options. */ -SamplingMode::Type NextFilterMode( SamplingMode::Type oldMode ) +SamplingMode::Type NextFilterMode(SamplingMode::Type oldMode) { SamplingMode::Type newMode = SamplingMode::BOX; - switch ( oldMode ) + switch(oldMode) { case SamplingMode::BOX: newMode = SamplingMode::NEAREST; @@ -134,36 +132,35 @@ SamplingMode::Type NextFilterMode( SamplingMode::Type oldMode ) return newMode; } -const char* StringFromScalingMode( FittingMode::Type scalingMode ) +const char* StringFromScalingMode(FittingMode::Type scalingMode) { return scalingMode == FittingMode::SCALE_TO_FILL ? "SCALE_TO_FILL" : scalingMode == FittingMode::SHRINK_TO_FIT ? "SHRINK_TO_FIT" : scalingMode == FittingMode::FIT_WIDTH ? "FIT_WIDTH" : scalingMode == FittingMode::FIT_HEIGHT ? "FIT_HEIGHT" : "UnknownScalingMode"; } -const char* StringFromFilterMode( SamplingMode::Type filterMode ) +const char* StringFromFilterMode(SamplingMode::Type filterMode) { return filterMode == SamplingMode::BOX ? "BOX" : filterMode == SamplingMode::BOX_THEN_NEAREST ? "BOX_THEN_NEAREST" : filterMode == SamplingMode::BOX_THEN_LINEAR ? "BOX_THEN_LINEAR" : filterMode == SamplingMode::NEAREST ? "NEAREST" : filterMode == SamplingMode::LINEAR ? "LINEAR" : filterMode == SamplingMode::NO_FILTER ? "NO_FILTER" : filterMode == SamplingMode::DONT_CARE ? "DONT_CARE" : "UnknownFilterMode"; } -} +} // namespace // This example shows the load-time image scaling and filtering features. // class ImageScalingAndFilteringController : public ConnectionTracker { public: - - ImageScalingAndFilteringController( Application& application ) - : mApplication( application ), - mLastPinchScale( 1.0f ), - mImageWindowScale( 0.5f, 0.5f ), - mCurrentPath( 0 ), - mFittingMode( FittingMode::FIT_WIDTH ), - mSamplingMode( SamplingMode::BOX_THEN_LINEAR), - mImageLoading( false ), - mQueuedImageLoad( false ) + ImageScalingAndFilteringController(Application& application) + : mApplication(application), + mLastPinchScale(1.0f), + mImageWindowScale(0.5f, 0.5f), + mCurrentPath(0), + mFittingMode(FittingMode::FIT_WIDTH), + mSamplingMode(SamplingMode::BOX_THEN_LINEAR), + mImageLoading(false), + mQueuedImageLoad(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageScalingAndFilteringController::Create ); + mApplication.InitSignal().Connect(this, &ImageScalingAndFilteringController::Create); } ~ImageScalingAndFilteringController() @@ -172,71 +169,71 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window - Window window = application.GetWindow(); + Window window = application.GetWindow(); Vector2 windowSize = window.GetSize(); // Background image: Dali::Property::Map backgroundImage; - backgroundImage.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE ); - backgroundImage.Insert( Toolkit::ImageVisual::Property::URL, BACKGROUND_IMAGE ); - backgroundImage.Insert( Toolkit::ImageVisual::Property::DESIRED_WIDTH, windowSize.width ); - backgroundImage.Insert( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, windowSize.height ); - backgroundImage.Insert( Toolkit::ImageVisual::Property::FITTING_MODE, FittingMode::SCALE_TO_FILL ); - backgroundImage.Insert( Toolkit::ImageVisual::Property::SAMPLING_MODE, SamplingMode::BOX_THEN_NEAREST ); + backgroundImage.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); + backgroundImage.Insert(Toolkit::ImageVisual::Property::URL, BACKGROUND_IMAGE); + backgroundImage.Insert(Toolkit::ImageVisual::Property::DESIRED_WIDTH, windowSize.width); + backgroundImage.Insert(Toolkit::ImageVisual::Property::DESIRED_HEIGHT, windowSize.height); + backgroundImage.Insert(Toolkit::ImageVisual::Property::FITTING_MODE, FittingMode::SCALE_TO_FILL); + backgroundImage.Insert(Toolkit::ImageVisual::Property::SAMPLING_MODE, SamplingMode::BOX_THEN_NEAREST); Toolkit::ImageView background = Toolkit::ImageView::New(); - background.SetProperty( Toolkit::ImageView::Property::IMAGE, backgroundImage ); - background.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - background.SetProperty( Actor::Property::SIZE, windowSize ); - window.Add( background ); + background.SetProperty(Toolkit::ImageView::Property::IMAGE, backgroundImage); + background.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + background.SetProperty(Actor::Property::SIZE, windowSize); + window.Add(background); - mDesiredBox = Toolkit::ImageView::New( BORDER_IMAGE ); - background.Add( mDesiredBox ); + mDesiredBox = Toolkit::ImageView::New(BORDER_IMAGE); + background.Add(mDesiredBox); - mDesiredBox.SetProperty( Actor::Property::SIZE, windowSize * mImageWindowScale ); - mDesiredBox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mDesiredBox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mDesiredBox.SetProperty(Actor::Property::SIZE, windowSize * mImageWindowScale); + mDesiredBox.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mDesiredBox.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); // Initialize the actor - mImageView = Toolkit::ImageView::New( IMAGE_PATHS[ 0 ] ); + mImageView = Toolkit::ImageView::New(IMAGE_PATHS[0]); // Reposition the actor - mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mImageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); // Display the actor on the window - mDesiredBox.Add( mImageView ); + mDesiredBox.Add(mImageView); - mImageView.SetProperty( Actor::Property::SIZE, windowSize * mImageWindowScale ); + mImageView.SetProperty(Actor::Property::SIZE, windowSize * mImageWindowScale); // Setup the pinch detector for scaling the desired image load dimensions: mPinchDetector = PinchGestureDetector::New(); - mPinchDetector.Attach( mImageView ); - mPinchDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPinch ); + mPinchDetector.Attach(mImageView); + mPinchDetector.DetectedSignal().Connect(this, &ImageScalingAndFilteringController::OnPinch); - mGrabCorner = Toolkit::ImageView::New( RESIZE_HANDLE_IMAGE ); - mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mGrabCorner.SetProperty( Dali::Actor::Property::NAME, "GrabCorner" ); - mGrabCorner.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); - mGrabCorner.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); - mGrabCorner.SetProperty( Actor::Property::POSITION, Vector2( -BORDER_WIDTH, -BORDER_WIDTH )); - mGrabCorner.SetProperty( Actor::Property::OPACITY, 0.6f ); + mGrabCorner = Toolkit::ImageView::New(RESIZE_HANDLE_IMAGE); + mGrabCorner.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mGrabCorner.SetProperty(Dali::Actor::Property::NAME, "GrabCorner"); + mGrabCorner.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mGrabCorner.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mGrabCorner.SetProperty(Actor::Property::POSITION, Vector2(-BORDER_WIDTH, -BORDER_WIDTH)); + mGrabCorner.SetProperty(Actor::Property::OPACITY, 0.6f); Layer grabCornerLayer = Layer::New(); - grabCornerLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); - grabCornerLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); - grabCornerLayer.Add( mGrabCorner ); - mDesiredBox.Add( grabCornerLayer ); + grabCornerLayer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + grabCornerLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + grabCornerLayer.Add(mGrabCorner); + mDesiredBox.Add(grabCornerLayer); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( mGrabCorner ); - mPanGestureDetector.DetectedSignal().Connect( this, &ImageScalingAndFilteringController::OnPan ); + mPanGestureDetector.Attach(mGrabCorner); + mPanGestureDetector.DetectedSignal().Connect(this, &ImageScalingAndFilteringController::OnPan); // Tie-in input event handlers: - window.KeyEventSignal().Connect( this, &ImageScalingAndFilteringController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &ImageScalingAndFilteringController::OnKeyEvent); CreateControls(); @@ -248,238 +245,238 @@ public: */ void CreateControls() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); Dali::Layer controlsLayer = Dali::Layer::New(); - controlsLayer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - controlsLayer.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 1.0f, 1.0f, 1.0f ) ); - controlsLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); - controlsLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); - window.Add( controlsLayer ); + controlsLayer.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + controlsLayer.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(1.0f, 1.0f, 1.0f)); + controlsLayer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + controlsLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + window.Add(controlsLayer); // Back and next image buttons in corners of window: - unsigned int playWidth = std::min( windowSize.x * (1 / 5.0f), 58.0f ); - Toolkit::ImageView imagePrevious = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); + unsigned int playWidth = std::min(windowSize.x * (1 / 5.0f), 58.0f); + Toolkit::ImageView imagePrevious = Toolkit::ImageView::New(DALI_ICON_PLAY, ImageDimensions(playWidth, playWidth)); // Last image button: - imagePrevious.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - imagePrevious.RotateBy( Radian(3.14159265358979323846f), Vector3( 0, 1.0f, 0 ) ); - imagePrevious.SetProperty( Actor::Property::POSITION_Y, playWidth * 0.5f ); - imagePrevious.SetProperty( Actor::Property::POSITION_X, playWidth + playWidth * 0.5f ); - imagePrevious.SetProperty( Actor::Property::OPACITY, 0.6f ); - controlsLayer.Add( imagePrevious ); - imagePrevious.SetProperty( Dali::Actor::Property::NAME, PREVIOUS_BUTTON_ID ); - imagePrevious.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + imagePrevious.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + imagePrevious.RotateBy(Radian(3.14159265358979323846f), Vector3(0, 1.0f, 0)); + imagePrevious.SetProperty(Actor::Property::POSITION_Y, playWidth * 0.5f); + imagePrevious.SetProperty(Actor::Property::POSITION_X, playWidth + playWidth * 0.5f); + imagePrevious.SetProperty(Actor::Property::OPACITY, 0.6f); + controlsLayer.Add(imagePrevious); + imagePrevious.SetProperty(Dali::Actor::Property::NAME, PREVIOUS_BUTTON_ID); + imagePrevious.TouchedSignal().Connect(this, &ImageScalingAndFilteringController::OnControlTouched); // Next image button: - Toolkit::ImageView imageNext = Toolkit::ImageView::New( DALI_ICON_PLAY, ImageDimensions( playWidth, playWidth ) ); - imageNext.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); - imageNext.SetProperty( Actor::Property::POSITION_Y, playWidth * 0.5f ); - imageNext.SetProperty( Actor::Property::POSITION_X, windowSize.x - playWidth * 0.5f ); - imageNext.SetProperty( Actor::Property::OPACITY, 0.6f ); - controlsLayer.Add( imageNext ); - imageNext.SetProperty( Dali::Actor::Property::NAME, NEXT_BUTTON_ID ); - imageNext.TouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnControlTouched ); + Toolkit::ImageView imageNext = Toolkit::ImageView::New(DALI_ICON_PLAY, ImageDimensions(playWidth, playWidth)); + imageNext.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + imageNext.SetProperty(Actor::Property::POSITION_Y, playWidth * 0.5f); + imageNext.SetProperty(Actor::Property::POSITION_X, windowSize.x - playWidth * 0.5f); + imageNext.SetProperty(Actor::Property::OPACITY, 0.6f); + controlsLayer.Add(imageNext); + imageNext.SetProperty(Dali::Actor::Property::NAME, NEXT_BUTTON_ID); + imageNext.TouchedSignal().Connect(this, &ImageScalingAndFilteringController::OnControlTouched); // Buttons to popup selectors for fitting and sampling modes: // Wrapper table to hold two buttons side by side: - Toolkit::TableView modesGroupBackground = Toolkit::TableView::New( 1, 2 ); - modesGroupBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - modesGroupBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - modesGroupBackground.SetBackgroundColor( BACKGROUND_COLOUR ); - modesGroupBackground.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE ) ); - modesGroupBackground.SetFitHeight( 0 ); + Toolkit::TableView modesGroupBackground = Toolkit::TableView::New(1, 2); + modesGroupBackground.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + modesGroupBackground.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + modesGroupBackground.SetBackgroundColor(BACKGROUND_COLOUR); + modesGroupBackground.SetCellPadding(Size(MARGIN_SIZE * 0.5f, MARGIN_SIZE)); + modesGroupBackground.SetFitHeight(0); - modesGroupBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); - modesGroupBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); - modesGroupBackground.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f )); + modesGroupBackground.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT); + modesGroupBackground.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + modesGroupBackground.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f)); - controlsLayer.Add( modesGroupBackground ); + controlsLayer.Add(modesGroupBackground); { // Vertical table to hold label and button: - Toolkit::TableView fittingModeGroup = Toolkit::TableView::New( 2, 1 ); - fittingModeGroup.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - fittingModeGroup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - fittingModeGroup.SetBackgroundColor( BACKGROUND_COLOUR ); - fittingModeGroup.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f ) ); - fittingModeGroup.SetFitHeight( 0 ); - fittingModeGroup.SetFitHeight( 1 ); - - TextLabel label = TextLabel::New( "Image fitting mode:" ); - label.SetStyleName( STYLE_LABEL_TEXT ); - fittingModeGroup.Add( label ); - - Toolkit::PushButton button = CreateButton( FITTING_BUTTON_ID, StringFromScalingMode( mFittingMode ) ); - fittingModeGroup.Add( button ); + Toolkit::TableView fittingModeGroup = Toolkit::TableView::New(2, 1); + fittingModeGroup.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + fittingModeGroup.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + fittingModeGroup.SetBackgroundColor(BACKGROUND_COLOUR); + fittingModeGroup.SetCellPadding(Size(MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f)); + fittingModeGroup.SetFitHeight(0); + fittingModeGroup.SetFitHeight(1); + + TextLabel label = TextLabel::New("Image fitting mode:"); + label.SetStyleName(STYLE_LABEL_TEXT); + fittingModeGroup.Add(label); + + Toolkit::PushButton button = CreateButton(FITTING_BUTTON_ID, StringFromScalingMode(mFittingMode)); + fittingModeGroup.Add(button); mFittingModeButton = button; - modesGroupBackground.Add( fittingModeGroup ); + modesGroupBackground.Add(fittingModeGroup); } { // Vertical table to hold label and button: - Toolkit::TableView samplingModeGroup = Toolkit::TableView::New( 2, 1 ); - samplingModeGroup.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - samplingModeGroup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - samplingModeGroup.SetBackgroundColor( BACKGROUND_COLOUR ); - samplingModeGroup.SetCellPadding( Size( MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f ) ); - samplingModeGroup.SetFitHeight( 0 ); - samplingModeGroup.SetFitHeight( 1 ); - - TextLabel label = TextLabel::New( "Image sampling mode:" ); - label.SetStyleName( STYLE_LABEL_TEXT ); - samplingModeGroup.Add( label ); - - Toolkit::PushButton button = CreateButton( SAMPLING_BUTTON_ID, StringFromFilterMode( mSamplingMode ) ); - samplingModeGroup.Add( button ); + Toolkit::TableView samplingModeGroup = Toolkit::TableView::New(2, 1); + samplingModeGroup.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + samplingModeGroup.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + samplingModeGroup.SetBackgroundColor(BACKGROUND_COLOUR); + samplingModeGroup.SetCellPadding(Size(MARGIN_SIZE * 0.5f, MARGIN_SIZE * 0.5f)); + samplingModeGroup.SetFitHeight(0); + samplingModeGroup.SetFitHeight(1); + + TextLabel label = TextLabel::New("Image sampling mode:"); + label.SetStyleName(STYLE_LABEL_TEXT); + samplingModeGroup.Add(label); + + Toolkit::PushButton button = CreateButton(SAMPLING_BUTTON_ID, StringFromFilterMode(mSamplingMode)); + samplingModeGroup.Add(button); mSamplingModeButton = button; - modesGroupBackground.Add( samplingModeGroup ); + modesGroupBackground.Add(samplingModeGroup); } } - Toolkit::PushButton CreateButton( const char * id, const char * label ) + Toolkit::PushButton CreateButton(const char* id, const char* label) { Toolkit::PushButton button = Toolkit::PushButton::New(); - button.SetStyleName( STYLE_BUTTON_TEXT ); - button.SetProperty( Dali::Actor::Property::NAME, id ); - button.SetProperty( Toolkit::Button::Property::LABEL, label ); - button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked ); + button.SetStyleName(STYLE_BUTTON_TEXT); + button.SetProperty(Dali::Actor::Property::NAME, id); + button.SetProperty(Toolkit::Button::Property::LABEL, label); + button.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + button.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + button.ClickedSignal().Connect(this, &ImageScalingAndFilteringController::OnButtonClicked); return button; } Toolkit::Popup CreatePopup() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); const float POPUP_WIDTH_DP = window.GetSize().GetWidth() * 0.75f; Toolkit::Popup popup = Toolkit::Popup::New(); - popup.SetProperty( Dali::Actor::Property::NAME, "POPUP" ); - popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - popup.SetProperty( Actor::Property::SIZE, Vector2( POPUP_WIDTH_DP, 0.0f ) ); + popup.SetProperty(Dali::Actor::Property::NAME, "POPUP"); + popup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + popup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + popup.SetProperty(Actor::Property::SIZE, Vector2(POPUP_WIDTH_DP, 0.0f)); - popup.OutsideTouchedSignal().Connect( this, &ImageScalingAndFilteringController::OnPopupOutsideTouched ); + popup.OutsideTouchedSignal().Connect(this, &ImageScalingAndFilteringController::OnPopupOutsideTouched); return popup; } - Toolkit::PushButton CreatePopupButton( Actor parent, const char* id ) + Toolkit::PushButton CreatePopupButton(Actor parent, const char* id) { Toolkit::PushButton button = Toolkit::PushButton::New(); - button.SetProperty( Dali::Actor::Property::NAME, id ); - button.SetProperty( Toolkit::Button::Property::LABEL, id ); + button.SetProperty(Dali::Actor::Property::NAME, id); + button.SetProperty(Toolkit::Button::Property::LABEL, id); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); - button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + button.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + button.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); - button.ClickedSignal().Connect( this, &ImageScalingAndFilteringController::OnButtonClicked ); + button.ClickedSignal().Connect(this, &ImageScalingAndFilteringController::OnButtonClicked); - parent.Add( button ); + parent.Add(button); return button; } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == FITTING_BUTTON_ID ) + if(button.GetProperty(Dali::Actor::Property::NAME) == FITTING_BUTTON_ID) { mPopup = CreatePopup(); // Four-row table to hold buttons: - Toolkit::TableView fittingModes = Toolkit::TableView::New( 4, 1 ); - fittingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - fittingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - fittingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) ); - fittingModes.SetFitHeight( 0 ); - fittingModes.SetFitHeight( 1 ); - fittingModes.SetFitHeight( 2 ); - fittingModes.SetFitHeight( 3 ); - - CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::SCALE_TO_FILL ) ); - CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::SHRINK_TO_FIT ) ); - CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_WIDTH ) ); - CreatePopupButton( fittingModes, StringFromScalingMode( FittingMode::FIT_HEIGHT ) ); - - mPopup.SetContent( fittingModes ); - mApplication.GetWindow().Add( mPopup ); - mPopup.SetDisplayState( Toolkit::Popup::SHOWN ); + Toolkit::TableView fittingModes = Toolkit::TableView::New(4, 1); + fittingModes.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + fittingModes.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + fittingModes.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5)); + fittingModes.SetFitHeight(0); + fittingModes.SetFitHeight(1); + fittingModes.SetFitHeight(2); + fittingModes.SetFitHeight(3); + + CreatePopupButton(fittingModes, StringFromScalingMode(FittingMode::SCALE_TO_FILL)); + CreatePopupButton(fittingModes, StringFromScalingMode(FittingMode::SHRINK_TO_FIT)); + CreatePopupButton(fittingModes, StringFromScalingMode(FittingMode::FIT_WIDTH)); + CreatePopupButton(fittingModes, StringFromScalingMode(FittingMode::FIT_HEIGHT)); + + mPopup.SetContent(fittingModes); + mApplication.GetWindow().Add(mPopup); + mPopup.SetDisplayState(Toolkit::Popup::SHOWN); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == SAMPLING_BUTTON_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == SAMPLING_BUTTON_ID) { mPopup = CreatePopup(); // Table to hold buttons for each sampling mode: - Toolkit::TableView samplingModes = Toolkit::TableView::New( 6, 1 ); - samplingModes.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - samplingModes.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - samplingModes.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE * 0.5 ) ); - samplingModes.SetFitHeight( 0 ); - samplingModes.SetFitHeight( 1 ); - samplingModes.SetFitHeight( 2 ); - samplingModes.SetFitHeight( 3 ); - samplingModes.SetFitHeight( 4 ); - samplingModes.SetFitHeight( 5 ); - - CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::NEAREST ) ); - CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::LINEAR ) ); - CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX ) ); - CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX_THEN_NEAREST ) ); - CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::BOX_THEN_LINEAR ) ); - CreatePopupButton( samplingModes, StringFromFilterMode( SamplingMode::NO_FILTER ) ); - - mPopup.SetContent( samplingModes ); - mApplication.GetWindow().Add( mPopup ); - mPopup.SetDisplayState( Toolkit::Popup::SHOWN ); + Toolkit::TableView samplingModes = Toolkit::TableView::New(6, 1); + samplingModes.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + samplingModes.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + samplingModes.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5)); + samplingModes.SetFitHeight(0); + samplingModes.SetFitHeight(1); + samplingModes.SetFitHeight(2); + samplingModes.SetFitHeight(3); + samplingModes.SetFitHeight(4); + samplingModes.SetFitHeight(5); + + CreatePopupButton(samplingModes, StringFromFilterMode(SamplingMode::NEAREST)); + CreatePopupButton(samplingModes, StringFromFilterMode(SamplingMode::LINEAR)); + CreatePopupButton(samplingModes, StringFromFilterMode(SamplingMode::BOX)); + CreatePopupButton(samplingModes, StringFromFilterMode(SamplingMode::BOX_THEN_NEAREST)); + CreatePopupButton(samplingModes, StringFromFilterMode(SamplingMode::BOX_THEN_LINEAR)); + CreatePopupButton(samplingModes, StringFromFilterMode(SamplingMode::NO_FILTER)); + + mPopup.SetContent(samplingModes); + mApplication.GetWindow().Add(mPopup); + mPopup.SetDisplayState(Toolkit::Popup::SHOWN); } - else if( CheckFittingModeButton( button, FittingMode::SCALE_TO_FILL) || - CheckFittingModeButton( button, FittingMode::SHRINK_TO_FIT) || - CheckFittingModeButton( button, FittingMode::FIT_WIDTH) || - CheckFittingModeButton( button, FittingMode::FIT_HEIGHT) ) + else if(CheckFittingModeButton(button, FittingMode::SCALE_TO_FILL) || + CheckFittingModeButton(button, FittingMode::SHRINK_TO_FIT) || + CheckFittingModeButton(button, FittingMode::FIT_WIDTH) || + CheckFittingModeButton(button, FittingMode::FIT_HEIGHT)) { } - else if( CheckSamplingModeButton( button, SamplingMode::NEAREST ) || - CheckSamplingModeButton( button, SamplingMode::LINEAR ) || - CheckSamplingModeButton( button, SamplingMode::BOX ) || - CheckSamplingModeButton( button, SamplingMode::LINEAR ) || - CheckSamplingModeButton( button, SamplingMode::BOX_THEN_NEAREST ) || - CheckSamplingModeButton( button, SamplingMode::BOX_THEN_LINEAR ) || - CheckSamplingModeButton( button, SamplingMode::NO_FILTER ) ) + else if(CheckSamplingModeButton(button, SamplingMode::NEAREST) || + CheckSamplingModeButton(button, SamplingMode::LINEAR) || + CheckSamplingModeButton(button, SamplingMode::BOX) || + CheckSamplingModeButton(button, SamplingMode::LINEAR) || + CheckSamplingModeButton(button, SamplingMode::BOX_THEN_NEAREST) || + CheckSamplingModeButton(button, SamplingMode::BOX_THEN_LINEAR) || + CheckSamplingModeButton(button, SamplingMode::NO_FILTER)) { } return true; } - bool CheckFittingModeButton( Actor &button, FittingMode::Type mode ) + bool CheckFittingModeButton(Actor& button, FittingMode::Type mode) { - const char * const modeName = StringFromScalingMode( mode ); - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == modeName ) + const char* const modeName = StringFromScalingMode(mode); + if(button.GetProperty(Dali::Actor::Property::NAME) == modeName) { mFittingMode = mode; - mFittingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName ); + mFittingModeButton.SetProperty(Toolkit::Button::Property::LABEL, modeName); ResizeImage(); - mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); + mPopup.SetDisplayState(Toolkit::Popup::HIDDEN); mPopup.Reset(); return true; } return false; } - bool CheckSamplingModeButton( Actor &button, SamplingMode::Type mode ) + bool CheckSamplingModeButton(Actor& button, SamplingMode::Type mode) { - const char * const modeName = StringFromFilterMode( mode ); - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == modeName ) + const char* const modeName = StringFromFilterMode(mode); + if(button.GetProperty(Dali::Actor::Property::NAME) == modeName) { mSamplingMode = mode; - mSamplingModeButton.SetProperty( Toolkit::Button::Property::LABEL, modeName ); + mSamplingModeButton.SetProperty(Toolkit::Button::Property::LABEL, modeName); ResizeImage(); - mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); + mPopup.SetDisplayState(Toolkit::Popup::HIDDEN); mPopup.Reset(); return true; } @@ -488,29 +485,29 @@ public: void OnPopupOutsideTouched() { - if( mPopup ) + if(mPopup) { - mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); + mPopup.SetDisplayState(Toolkit::Popup::HIDDEN); mPopup.Reset(); } } - bool OnControlTouched( Actor actor, const TouchEvent& event ) + bool OnControlTouched(Actor actor, const TouchEvent& event) { if(event.GetPointCount() > 0) { - switch( event.GetState( 0 ) ) + switch(event.GetState(0)) { case PointState::UP: { - const std::string & name = actor.GetProperty< std::string >( Dali::Actor::Property::NAME ); - if( name == NEXT_BUTTON_ID ) + const std::string& name = actor.GetProperty(Dali::Actor::Property::NAME); + if(name == NEXT_BUTTON_ID) { mCurrentPath = mCurrentPath + 1; - mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0; + mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0; ResizeImage(); } - else if( name == PREVIOUS_BUTTON_ID ) + else if(name == PREVIOUS_BUTTON_ID) { mCurrentPath = mCurrentPath - 1; mCurrentPath = mCurrentPath >= 0 ? mCurrentPath : NUM_IMAGE_PATHS - 1; @@ -528,53 +525,53 @@ public: return false; } - void OnPinch( Actor actor, const PinchGesture& pinch ) + void OnPinch(Actor actor, const PinchGesture& pinch) { - if( pinch.GetState() == GestureState::STARTED ) + if(pinch.GetState() == GestureState::STARTED) { mLastPinchScale = pinch.GetScale(); } const float scale = pinch.GetScale(); - if( ! Equals( scale, mLastPinchScale ) ) + if(!Equals(scale, mLastPinchScale)) { - if ( scale < mLastPinchScale ) + if(scale < mLastPinchScale) { - mImageWindowScale.x = std::max( 0.05f, mImageWindowScale.x * 0.9f ); - mImageWindowScale.y = std::max( 0.05f, mImageWindowScale.y * 0.9f ); + mImageWindowScale.x = std::max(0.05f, mImageWindowScale.x * 0.9f); + mImageWindowScale.y = std::max(0.05f, mImageWindowScale.y * 0.9f); } else { - mImageWindowScale.x = std::max( 0.05f, std::min( 1.0f, mImageWindowScale.x * 1.1f ) ); - mImageWindowScale.y = std::max( 0.05f, std::min( 1.0f, mImageWindowScale.y * 1.1f ) ); + mImageWindowScale.x = std::max(0.05f, std::min(1.0f, mImageWindowScale.x * 1.1f)); + mImageWindowScale.y = std::max(0.05f, std::min(1.0f, mImageWindowScale.y * 1.1f)); } ResizeImage(); } mLastPinchScale = scale; } - void OnPan( Actor actor, const PanGesture& gesture ) + void OnPan(Actor actor, const PanGesture& gesture) { - Window window = mApplication.GetWindow(); - Vector2 windowSize = window.GetSize(); + Window window = mApplication.GetWindow(); + Vector2 windowSize = window.GetSize(); const Vector2& displacement = gesture.GetDisplacement(); // 1.0f and 0.75f are the maximum size caps of the resized image, as a factor of window-size. - mImageWindowScale.x = std::max( 0.05f, std::min( 0.95f, mImageWindowScale.x + ( displacement.x * 2.0f / windowSize.width ) ) ); - mImageWindowScale.y = std::max( 0.05f, std::min( 0.70f, mImageWindowScale.y + ( displacement.y * 2.0f / windowSize.height ) ) ); + mImageWindowScale.x = std::max(0.05f, std::min(0.95f, mImageWindowScale.x + (displacement.x * 2.0f / windowSize.width))); + mImageWindowScale.y = std::max(0.05f, std::min(0.70f, mImageWindowScale.y + (displacement.y * 2.0f / windowSize.height))); ResizeImage(); } void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { - if( mPopup && mPopup.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ) + if(mPopup && mPopup.GetCurrentProperty(Actor::Property::VISIBLE)) { - mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); + mPopup.SetDisplayState(Toolkit::Popup::HIDDEN); mPopup.Reset(); } else @@ -582,53 +579,53 @@ public: mApplication.Quit(); } } - else if ( event.GetKeyName() == "Right" ) + else if(event.GetKeyName() == "Right") { - mImageWindowScale.x = std::max( 0.05f, std::min( 1.0f, mImageWindowScale.x * 1.1f ) ); + mImageWindowScale.x = std::max(0.05f, std::min(1.0f, mImageWindowScale.x * 1.1f)); } - else if ( event.GetKeyName() == "Left" ) + else if(event.GetKeyName() == "Left") { - mImageWindowScale.x = std::max( 0.05f, mImageWindowScale.x * 0.9f ); + mImageWindowScale.x = std::max(0.05f, mImageWindowScale.x * 0.9f); } - else if ( event.GetKeyName() == "Up" ) + else if(event.GetKeyName() == "Up") { - mImageWindowScale.y = std::max( 0.05f, std::min( 1.0f, mImageWindowScale.y * 1.1f ) ); + mImageWindowScale.y = std::max(0.05f, std::min(1.0f, mImageWindowScale.y * 1.1f)); } - else if ( event.GetKeyName() == "Down" ) + else if(event.GetKeyName() == "Down") { - mImageWindowScale.y = std::max( 0.05f, mImageWindowScale.y * 0.9f ); + mImageWindowScale.y = std::max(0.05f, mImageWindowScale.y * 0.9f); } - else if ( event.GetKeyName() == "o" ) + else if(event.GetKeyName() == "o") { - mImageWindowScale.x = std::max( 0.05f, mImageWindowScale.x * 0.9f ); - mImageWindowScale.y = std::max( 0.05f, mImageWindowScale.y * 0.9f ); + mImageWindowScale.x = std::max(0.05f, mImageWindowScale.x * 0.9f); + mImageWindowScale.y = std::max(0.05f, mImageWindowScale.y * 0.9f); } - else if ( event.GetKeyName() == "p" ) + else if(event.GetKeyName() == "p") { - mImageWindowScale.x = std::max( 0.05f, std::min( 1.0f, mImageWindowScale.x * 1.1f ) ); - mImageWindowScale.y = std::max( 0.05f, std::min( 1.0f, mImageWindowScale.y * 1.1f ) ); + mImageWindowScale.x = std::max(0.05f, std::min(1.0f, mImageWindowScale.x * 1.1f)); + mImageWindowScale.y = std::max(0.05f, std::min(1.0f, mImageWindowScale.y * 1.1f)); } - else if ( event.GetKeyName() == "n" ) + else if(event.GetKeyName() == "n") { mCurrentPath = mCurrentPath + 1; - mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0; + mCurrentPath = mCurrentPath < NUM_IMAGE_PATHS ? mCurrentPath : 0; } - else if ( event.GetKeyName() == "b" ) + else if(event.GetKeyName() == "b") { mCurrentPath = mCurrentPath - 1; mCurrentPath = mCurrentPath >= 0 ? mCurrentPath : NUM_IMAGE_PATHS - 1; } // Cycle filter and scaling modes: - else if ( event.GetKeyName() == "f" ) + else if(event.GetKeyName() == "f") { - mSamplingMode = NextFilterMode( mSamplingMode ); - mSamplingModeButton.SetProperty( Toolkit::Button::Property::LABEL, StringFromFilterMode( mSamplingMode ) ); + mSamplingMode = NextFilterMode(mSamplingMode); + mSamplingModeButton.SetProperty(Toolkit::Button::Property::LABEL, StringFromFilterMode(mSamplingMode)); } // Cycle filter and scaling modes: - else if ( event.GetKeyName() == "s" ) + else if(event.GetKeyName() == "s") { - mFittingMode = NextScalingMode( mFittingMode ); - mFittingModeButton.SetProperty( Toolkit::Button::Property::LABEL, StringFromScalingMode( mFittingMode ) ); + mFittingMode = NextScalingMode(mFittingMode); + mFittingModeButton.SetProperty(Toolkit::Button::Property::LABEL, StringFromScalingMode(mFittingMode)); } else { @@ -640,65 +637,61 @@ public: } private: - void LoadImage() { mImageLoading = true; - const char * const path = IMAGE_PATHS[ mCurrentPath ]; - Window window = mApplication.GetWindow(); - Size imageSize = Vector2(window.GetSize()) * mImageWindowScale; - mImageView.SetProperty( Actor::Property::SIZE, imageSize ); + const char* const path = IMAGE_PATHS[mCurrentPath]; + Window window = mApplication.GetWindow(); + Size imageSize = Vector2(window.GetSize()) * mImageWindowScale; + mImageView.SetProperty(Actor::Property::SIZE, imageSize); Property::Map map; - map[Toolkit::ImageVisual::Property::URL] = path; - map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = imageSize.x; + map[Toolkit::ImageVisual::Property::URL] = path; + map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = imageSize.x; map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = imageSize.y; - map[Toolkit::ImageVisual::Property::FITTING_MODE] = mFittingMode; - map[Toolkit::ImageVisual::Property::SAMPLING_MODE] = mSamplingMode; - - mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); + map[Toolkit::ImageVisual::Property::FITTING_MODE] = mFittingMode; + map[Toolkit::ImageVisual::Property::SAMPLING_MODE] = mSamplingMode; + mImageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map); } void ResizeImage() { - - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - Size imageSize = windowSize * mImageWindowScale; + Size imageSize = windowSize * mImageWindowScale; LoadImage(); // Border size needs to be modified to take into account the width of the frame. - Vector2 borderScale( ( imageSize + Vector2( BORDER_WIDTH * 2.0f, BORDER_WIDTH * 2.0f ) ) / windowSize ); - mDesiredBox.SetProperty( Actor::Property::SIZE, windowSize * borderScale ); + Vector2 borderScale((imageSize + Vector2(BORDER_WIDTH * 2.0f, BORDER_WIDTH * 2.0f)) / windowSize); + mDesiredBox.SetProperty(Actor::Property::SIZE, windowSize * borderScale); } private: - Application& mApplication; - Toolkit::ImageView mDesiredBox; //< Background rectangle to show requested image size. - Toolkit::PushButton mFittingModeButton; - Toolkit::PushButton mSamplingModeButton; - Toolkit::Popup mPopup; + Application& mApplication; + Toolkit::ImageView mDesiredBox; //< Background rectangle to show requested image size. + Toolkit::PushButton mFittingModeButton; + Toolkit::PushButton mSamplingModeButton; + Toolkit::Popup mPopup; PinchGestureDetector mPinchDetector; - float mLastPinchScale; - Toolkit::ImageView mGrabCorner; - PanGestureDetector mPanGestureDetector; - Toolkit::ImageView mImageView; - Vector2 mImageWindowScale; - int mCurrentPath; - FittingMode::Type mFittingMode; - SamplingMode::Type mSamplingMode; - bool mImageLoading; - bool mQueuedImageLoad; - + float mLastPinchScale; + Toolkit::ImageView mGrabCorner; + PanGestureDetector mPanGestureDetector; + Toolkit::ImageView mImageView; + Vector2 mImageWindowScale; + int mCurrentPath; + FittingMode::Type mFittingMode; + SamplingMode::Type mSamplingMode; + bool mImageLoading; + bool mQueuedImageLoad; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - ImageScalingAndFilteringController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + ImageScalingAndFilteringController test(application); application.MainLoop(); return 0; } diff --git a/examples/image-scaling-irregular-grid/grid-flags.h b/examples/image-scaling-irregular-grid/grid-flags.h index 1c151cc..f339792 100644 --- a/examples/image-scaling-irregular-grid/grid-flags.h +++ b/examples/image-scaling-irregular-grid/grid-flags.h @@ -16,9 +16,9 @@ * limitations under the License. * */ +#include #include #include -#include /** Controls the output of application logging. */ //#define DEBUG_PRINT_GRID_DIAGNOSTICS @@ -36,23 +36,27 @@ public: /** * Create grid of specified dimensions. */ - GridFlags( unsigned width, unsigned height ) : mCells( width * height ), mWidth( width ), mHeight( height ), mHighestUsedRow( 0 ) + GridFlags(unsigned width, unsigned height) + : mCells(width * height), + mWidth(width), + mHeight(height), + mHighestUsedRow(0) { #ifdef DEBUG_PRINT_GRID_DIAGNOSTICS - fprintf(stderr, "Grid created with dimensions: (%u, %u).\n", mWidth, mHeight ); + fprintf(stderr, "Grid created with dimensions: (%u, %u).\n", mWidth, mHeight); #endif } - void Set( const unsigned x, const unsigned y ) + void Set(const unsigned x, const unsigned y) { - const unsigned index = CellIndex( x, y ); + const unsigned index = CellIndex(x, y); mCells[index] += 1u; ///< += To allow a debug check of the number of times a cell is set. - mHighestUsedRow = std::max( mHighestUsedRow, y ); + mHighestUsedRow = std::max(mHighestUsedRow, y); } - bool Get( unsigned x, unsigned y ) const + bool Get(unsigned x, unsigned y) const { - return mCells[ CellIndex( x, y ) ] != 0; + return mCells[CellIndex(x, y)] != 0; } unsigned GetHighestUsedRow() const @@ -70,47 +74,47 @@ public: * or the largest area rectangular region no greater than the requested * region in x or y. Undefined if false is returned. */ - bool AllocateRegion( const Vector2& region, unsigned& outCellX, unsigned& outCellY, Vector2& outRegion ) + bool AllocateRegion(const Vector2& region, unsigned& outCellX, unsigned& outCellY, Vector2& outRegion) { - const unsigned regionWidth = (region.x + 0.5f); + const unsigned regionWidth = (region.x + 0.5f); const unsigned regionHeight = (region.y + 0.5f); #ifdef DEBUG_PRINT_GRID_DIAGNOSTICS - fprintf( stderr, "Allocation requested for region (%u, %u). Result: ", regionWidth, regionHeight ); + fprintf(stderr, "Allocation requested for region (%u, %u). Result: ", regionWidth, regionHeight); #endif - unsigned bestRegionWidth = 0; + unsigned bestRegionWidth = 0; unsigned bestRegionHeight = 0; - unsigned bestCellX = 0; - unsigned bestCellY = 0; + unsigned bestCellX = 0; + unsigned bestCellY = 0; // Look for a non-set cell: - for( unsigned y = 0; y < mHeight; ++y ) + for(unsigned y = 0; y < mHeight; ++y) { - for( unsigned x = 0; x < mWidth; ++x ) + for(unsigned x = 0; x < mWidth; ++x) { - if ( !Get( x, y) ) + if(!Get(x, y)) { // Look for clear grid cells under the desired region: - const unsigned clampedRegionHeight = std::min( regionHeight, mHeight - y); - const unsigned clampedRegionWidth = std::min( regionWidth, mWidth - x); - const unsigned regionLimitY = y + clampedRegionHeight; - const unsigned regionLimitX = x + clampedRegionWidth; + const unsigned clampedRegionHeight = std::min(regionHeight, mHeight - y); + const unsigned clampedRegionWidth = std::min(regionWidth, mWidth - x); + const unsigned regionLimitY = y + clampedRegionHeight; + const unsigned regionLimitX = x + clampedRegionWidth; - for( unsigned regionY = y; regionY < regionLimitY; ++regionY ) + for(unsigned regionY = y; regionY < regionLimitY; ++regionY) { - for( unsigned regionX = x; regionX < regionLimitX; ++regionX ) + for(unsigned regionX = x; regionX < regionLimitX; ++regionX) { - if( Get( regionX, regionY ) ) + if(Get(regionX, regionY)) { // The region of clear cells is not big enough but remember it // anyway in case there is no region that fits: - const unsigned clearRegionWidth = regionX - x; + const unsigned clearRegionWidth = regionX - x; const unsigned clearRegionHeight = (regionY + 1) - y; - if( clearRegionWidth * clearRegionHeight > bestRegionWidth * bestRegionHeight ) + if(clearRegionWidth * clearRegionHeight > bestRegionWidth * bestRegionHeight) { - bestCellX = x; - bestCellY = y; - bestRegionWidth = clearRegionWidth; + bestCellX = x; + bestCellY = y; + bestRegionWidth = clearRegionWidth; bestRegionHeight = clearRegionHeight; } goto whole_region_not_found; @@ -119,21 +123,21 @@ public: } // Every cell in the region is clear so check if it is the best one yet: - if( clampedRegionWidth * clampedRegionHeight > bestRegionWidth * bestRegionHeight ) + if(clampedRegionWidth * clampedRegionHeight > bestRegionWidth * bestRegionHeight) { - bestCellX = x; - bestCellY = y; - bestRegionWidth = clampedRegionWidth; + bestCellX = x; + bestCellY = y; + bestRegionWidth = clampedRegionWidth; bestRegionHeight = clampedRegionHeight; } // If a big-enough region was found, end the search early and greedily allocate it: - if( clampedRegionHeight == regionHeight && clampedRegionWidth == regionWidth ) + if(clampedRegionHeight == regionHeight && clampedRegionWidth == regionWidth) { x = mWidth; y = mHeight; } -whole_region_not_found: + whole_region_not_found: continue; } } @@ -141,31 +145,31 @@ whole_region_not_found: // Allocate and return the best cell region found: - if( bestRegionWidth == 0 || bestRegionHeight == 0 ) + if(bestRegionWidth == 0 || bestRegionHeight == 0) { #ifdef DEBUG_PRINT_GRID_DIAGNOSTICS - fputs( "false.\n", stderr ); + fputs("false.\n", stderr); #endif return false; } // Allocate the found region: #ifdef DEBUG_PRINT_GRID_DIAGNOSTICS - fprintf( stderr, " - bestCellX = %u, bestCellY = %u, bestRegionWidth = %u, bestRegionHeight = %u - ", bestCellX, bestCellY, bestRegionWidth, bestRegionHeight ); + fprintf(stderr, " - bestCellX = %u, bestCellY = %u, bestRegionWidth = %u, bestRegionHeight = %u - ", bestCellX, bestCellY, bestRegionWidth, bestRegionHeight); #endif - for( unsigned y = bestCellY; y < bestCellY + bestRegionHeight; ++y ) + for(unsigned y = bestCellY; y < bestCellY + bestRegionHeight; ++y) { - for( unsigned x = bestCellX; x < bestCellX + bestRegionWidth; ++x ) + for(unsigned x = bestCellX; x < bestCellX + bestRegionWidth; ++x) { - Set( x, y ); + Set(x, y); } } - outCellX = bestCellX; - outCellY = bestCellY; - outRegion = Vector2( bestRegionWidth, bestRegionHeight ); + outCellX = bestCellX; + outCellY = bestCellY; + outRegion = Vector2(bestRegionWidth, bestRegionHeight); #ifdef DEBUG_PRINT_GRID_DIAGNOSTICS - fputs( "true.\n", stderr ); + fputs("true.\n", stderr); #endif return true; } @@ -173,9 +177,9 @@ whole_region_not_found: /** @return True if every cell was set one or zero times, else false. */ bool DebugCheckGridValid() { - for( unsigned cell = 0; cell < mWidth * mHeight; ++cell ) + for(unsigned cell = 0; cell < mWidth * mHeight; ++cell) { - if( mCells[cell] > 1 ) + if(mCells[cell] > 1) { return false; } @@ -184,17 +188,17 @@ whole_region_not_found: } private: - unsigned CellIndex( unsigned x, unsigned y ) const + unsigned CellIndex(unsigned x, unsigned y) const { const unsigned offset = mWidth * y + x; - assert( offset < mCells.size() && "Out of range access to grid." ); + assert(offset < mCells.size() && "Out of range access to grid."); return offset; } std::vector mCells; - const unsigned mWidth; - const unsigned mHeight; - unsigned mHighestUsedRow; + const unsigned mWidth; + const unsigned mHeight; + unsigned mHighestUsedRow; }; } // namespace Demo diff --git a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp index cb41669..0e5c538 100644 --- a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp +++ b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp @@ -42,14 +42,14 @@ */ // EXTERNAL INCLUDES -#include -#include #include -#include #include #include -#include // std::default_random_engine -#include // std::chrono::system_clock +#include +#include // std::chrono::system_clock +#include +#include +#include // std::default_random_engine // INTERNAL INCLUDES #include "grid-flags.h" @@ -61,15 +61,14 @@ using namespace Dali::Demo; namespace { - /** Controls the output of application logging. */ //#define DEBUG_PRINT_DIAGNOSTICS; -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-gradient.jpg" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "Image Scaling Modes" ); -const char* TOGGLE_SCALING_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* TOGGLE_SCALING_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-gradient.jpg"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("Image Scaling Modes"); +const char* TOGGLE_SCALING_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* TOGGLE_SCALING_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); /** The width of the grid in whole grid cells. */ const unsigned GRID_WIDTH = 9; @@ -89,18 +88,18 @@ const float SPIN_DURATION = 1.0f; /** The target image sizes in grid cells. */ const Vector2 IMAGE_SIZES[] = { - Vector2( 1, 1 ), - Vector2( 2, 1 ), - Vector2( 3, 1 ), - Vector2( 1, 2 ), - Vector2( 1, 3 ), - Vector2( 2, 3 ), - Vector2( 3, 2 ), - // Large, tall configuration: - Vector2( GRID_WIDTH / 2, GRID_WIDTH + GRID_WIDTH / 2 ), - // Large, square-ish images to show shrink-to-fit well with wide and tall images: - Vector2( GRID_WIDTH / 2, GRID_WIDTH / 2.0f * CELL_ASPECT_RATIO + 0.5f ), - Vector2( GRID_WIDTH - 2, (GRID_WIDTH - 2) * CELL_ASPECT_RATIO + 0.5f ), + Vector2(1, 1), + Vector2(2, 1), + Vector2(3, 1), + Vector2(1, 2), + Vector2(1, 3), + Vector2(2, 3), + Vector2(3, 2), + // Large, tall configuration: + Vector2(GRID_WIDTH / 2, GRID_WIDTH + GRID_WIDTH / 2), + // Large, square-ish images to show shrink-to-fit well with wide and tall images: + Vector2(GRID_WIDTH / 2, GRID_WIDTH / 2.0f * CELL_ASPECT_RATIO + 0.5f), + Vector2(GRID_WIDTH - 2, (GRID_WIDTH - 2) * CELL_ASPECT_RATIO + 0.5f), }; const unsigned NUM_IMAGE_SIZES = sizeof(IMAGE_SIZES) / sizeof(IMAGE_SIZES[0]); @@ -166,12 +165,10 @@ const char* IMAGE_PATHS[] = { DEMO_IMAGE_DIR "book-portrait-cover.jpg", DEMO_IMAGE_DIR "book-portrait-p1.jpg", DEMO_IMAGE_DIR "book-portrait-p2.jpg", - NULL -}; -const unsigned NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u; + NULL}; +const unsigned NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u; const unsigned int INITIAL_IMAGES_TO_LOAD = 10; - /** * Creates an ImageView * @@ -180,30 +177,29 @@ const unsigned int INITIAL_IMAGES_TO_LOAD = 10; * @param[in] height The height of the image in pixels. * @param[in] fittingMode The mode to use when scaling the image to fit the desired dimensions. */ -ImageView CreateImageView(const std::string& filename, int width, int height, Dali::FittingMode::Type fittingMode ) +ImageView CreateImageView(const std::string& filename, int width, int height, Dali::FittingMode::Type fittingMode) { - ImageView imageView = ImageView::New(); Property::Map map; - map[Toolkit::ImageVisual::Property::URL] = filename; - map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = width; + map[Toolkit::ImageVisual::Property::URL] = filename; + map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = width; map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = height; - map[Toolkit::ImageVisual::Property::FITTING_MODE] = fittingMode; - imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map ); + map[Toolkit::ImageVisual::Property::FITTING_MODE] = fittingMode; + imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, map); - imageView.SetProperty( Dali::Actor::Property::NAME, filename ); - imageView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - imageView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + imageView.SetProperty(Dali::Actor::Property::NAME, filename); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); return imageView; } /** Cycle the scaling mode options. */ -Dali::FittingMode::Type NextMode( const Dali::FittingMode::Type oldMode ) +Dali::FittingMode::Type NextMode(const Dali::FittingMode::Type oldMode) { Dali::FittingMode::Type newMode = FittingMode::SHRINK_TO_FIT; - switch ( oldMode ) + switch(oldMode) { case FittingMode::SHRINK_TO_FIT: newMode = FittingMode::SCALE_TO_FILL; @@ -226,12 +222,13 @@ Dali::FittingMode::Type NextMode( const Dali::FittingMode::Type oldMode ) * */ struct ImageConfiguration { - ImageConfiguration( const char * const path, const Vector2 dimensions ) : - path( path ), - dimensions( dimensions ) - {} - const char * path; - Vector2 dimensions; + ImageConfiguration(const char* const path, const Vector2 dimensions) + : path(path), + dimensions(dimensions) + { + } + const char* path; + Vector2 dimensions; }; /** @@ -239,20 +236,21 @@ struct ImageConfiguration */ struct PositionedImage { - PositionedImage(ImageConfiguration& configuration, unsigned cellX, unsigned cellY, Vector2 imageGridDims) : - configuration( configuration ), - cellX( cellX ), - cellY( cellY ), - imageGridDims( imageGridDims ) - {} + PositionedImage(ImageConfiguration& configuration, unsigned cellX, unsigned cellY, Vector2 imageGridDims) + : configuration(configuration), + cellX(cellX), + cellY(cellY), + imageGridDims(imageGridDims) + { + } ImageConfiguration configuration; - unsigned cellX; - unsigned cellY; - Vector2 imageGridDims; + unsigned cellX; + unsigned cellY; + Vector2 imageGridDims; }; -} +} // namespace /** * @brief The main class of the demo. @@ -260,16 +258,15 @@ struct PositionedImage class ImageScalingIrregularGridController : public ConnectionTracker { public: - - ImageScalingIrregularGridController( Application& application ) - : mApplication( application ), - mScrolling( false ), - mImagesLoaded( 0 ) + ImageScalingIrregularGridController(Application& application) + : mApplication(application), + mScrolling(false), + mImagesLoaded(0) { std::cout << "ImageScalingIrregularGridController::ImageScalingIrregularGridController" << std::endl; // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageScalingIrregularGridController::Create ); + mApplication.InitSignal().Connect(this, &ImageScalingIrregularGridController::Create); } ~ImageScalingIrregularGridController() @@ -280,22 +277,21 @@ public: /** * Called everytime an ImageView has loaded it's image */ - void ResourceReadySignal( Toolkit::Control control ) + void ResourceReadySignal(Toolkit::Control control) { mImagesLoaded++; // To allow fast startup, we only place a small number of ImageViews on window first - if ( mImagesLoaded == INITIAL_IMAGES_TO_LOAD ) + if(mImagesLoaded == INITIAL_IMAGES_TO_LOAD) { // Adding the ImageViews to the window will trigger loading of the Images - mGridActor.Add( mOffWindowImageViews ); + mGridActor.Add(mOffWindowImageViews); } } - /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { std::cout << "ImageScalingIrregularGridController::Create" << std::endl; @@ -306,94 +302,94 @@ public: window.KeyEventSignal().Connect(this, &ImageScalingIrregularGridController::OnKeyEvent); // Create a default view with a default tool bar: - mContentLayer = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); + mContentLayer = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); // Create an image scaling toggle button. (right of toolbar) Toolkit::PushButton toggleScalingButton = Toolkit::PushButton::New(); - toggleScalingButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE ); - toggleScalingButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE_SELECTED ); - toggleScalingButton.ClickedSignal().Connect( this, &ImageScalingIrregularGridController::OnToggleScalingTouched ); - mToolBar.AddControl( toggleScalingButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + toggleScalingButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE); + toggleScalingButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TOGGLE_SCALING_IMAGE_SELECTED); + toggleScalingButton.ClickedSignal().Connect(this, &ImageScalingIrregularGridController::OnToggleScalingTouched); + mToolBar.AddControl(toggleScalingButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); - SetTitle( APPLICATION_TITLE ); + SetTitle(APPLICATION_TITLE); mOffWindowImageViews = Actor::New(); - mOffWindowImageViews.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mOffWindowImageViews.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mOffWindowImageViews.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mOffWindowImageViews.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mOffWindowImageViews.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mOffWindowImageViews.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); // Build the main content of the widow: - PopulateContentLayer( DEFAULT_SCALING_MODE ); + PopulateContentLayer(DEFAULT_SCALING_MODE); } /** * Build the main part of the application's view. */ - void PopulateContentLayer( const Dali::FittingMode::Type fittingMode ) + void PopulateContentLayer(const Dali::FittingMode::Type fittingMode) { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); float fieldHeight; - Actor imageField = BuildImageField( windowSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, fittingMode, fieldHeight ); + Actor imageField = BuildImageField(windowSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, fittingMode, fieldHeight); mScrollView = ScrollView::New(); - mScrollView.ScrollStartedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollStarted ); - mScrollView.ScrollCompletedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollCompleted ); + mScrollView.ScrollStartedSignal().Connect(this, &ImageScalingIrregularGridController::OnScrollStarted); + mScrollView.ScrollCompletedSignal().Connect(this, &ImageScalingIrregularGridController::OnScrollCompleted); - mScrollView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - mScrollView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mScrollView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mScrollView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - mScrollView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mScrollView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - mScrollView.SetAxisAutoLock( true ); - mScrollView.SetAxisAutoLockGradient( 1.0f ); + mScrollView.SetAxisAutoLock(true); + mScrollView.SetAxisAutoLockGradient(1.0f); // Restrict scrolling to mostly vertical only, but with some horizontal wiggle-room: - RulerPtr rulerX = new FixedRuler( windowSize.width ); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler. - rulerX->SetDomain( RulerDomain( windowSize.width * -0.125f, windowSize.width * 1.125f ) ); //< Scroll slightly left/right of image field. - mScrollView.SetRulerX ( rulerX ); + RulerPtr rulerX = new FixedRuler(windowSize.width); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler. + rulerX->SetDomain(RulerDomain(windowSize.width * -0.125f, windowSize.width * 1.125f)); //< Scroll slightly left/right of image field. + mScrollView.SetRulerX(rulerX); RulerPtr rulerY = new DefaultRuler(); //< Snap in multiples of a screen / window height - rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + windowSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + windowSize.height * 0.5f + GRID_CELL_PADDING ) ); - mScrollView.SetRulerY ( rulerY ); + rulerY->SetDomain(RulerDomain(-fieldHeight * 0.5f + windowSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + windowSize.height * 0.5f + GRID_CELL_PADDING)); + mScrollView.SetRulerY(rulerY); - mContentLayer.Add( mScrollView ); - mScrollView.Add( imageField ); + mContentLayer.Add(mScrollView); + mScrollView.Add(imageField); mGridActor = imageField; // Create the scroll bar mScrollBarVertical = ScrollBar::New(Toolkit::ScrollBar::VERTICAL); - mScrollBarVertical.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_RIGHT); - mScrollBarVertical.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_RIGHT); + mScrollBarVertical.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + mScrollBarVertical.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT); mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH); mScrollView.Add(mScrollBarVertical); mScrollBarHorizontal = ScrollBar::New(Toolkit::ScrollBar::HORIZONTAL); - mScrollBarHorizontal.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_LEFT); - mScrollBarHorizontal.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); + mScrollBarHorizontal.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + mScrollBarHorizontal.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); mScrollBarHorizontal.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH); - mScrollBarHorizontal.SetProperty( Actor::Property::ORIENTATION, Quaternion( Quaternion( Radian( 1.5f * Math::PI ), Vector3::ZAXIS) ) ); + mScrollBarHorizontal.SetProperty(Actor::Property::ORIENTATION, Quaternion(Quaternion(Radian(1.5f * Math::PI), Vector3::ZAXIS))); mScrollView.Add(mScrollBarHorizontal); - mScrollView.OnRelayoutSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollViewRelayout ); + mScrollView.OnRelayoutSignal().Connect(this, &ImageScalingIrregularGridController::OnScrollViewRelayout); // Scroll to top of grid so first images loaded are on-screen: - mScrollView.ScrollTo( Vector2( 0, -1000000 ) ); + mScrollView.ScrollTo(Vector2(0, -1000000)); } void OnScrollViewRelayout(Actor actor) { // Make the height of the horizontal scroll bar to be the same as the width of scroll view. - mScrollBarHorizontal.SetProperty( Actor::Property::SIZE, Vector2(0.0f, mScrollView.GetRelayoutSize( Dimension::WIDTH) )); + mScrollBarHorizontal.SetProperty(Actor::Property::SIZE, Vector2(0.0f, mScrollView.GetRelayoutSize(Dimension::WIDTH))); } /** @@ -401,133 +397,133 @@ public: * through square, to very tall. The images are direct children of the Dali::Actor * returned. **/ - Actor BuildImageField( const float fieldWidth, - const unsigned gridWidth, - const unsigned maxGridHeight, - Dali::FittingMode::Type fittingMode, - float & outFieldHeight ) + Actor BuildImageField(const float fieldWidth, + const unsigned gridWidth, + const unsigned maxGridHeight, + Dali::FittingMode::Type fittingMode, + float& outFieldHeight) { // Generate the list of image configurations to be fitted into the field: std::vector configurations; - configurations.reserve( NUM_IMAGE_PATHS * NUM_IMAGE_SIZES ); - for( unsigned imageIndex = 0; imageIndex < NUM_IMAGE_PATHS; ++imageIndex ) + configurations.reserve(NUM_IMAGE_PATHS * NUM_IMAGE_SIZES); + for(unsigned imageIndex = 0; imageIndex < NUM_IMAGE_PATHS; ++imageIndex) { - for( unsigned dimensionsIndex = 0; dimensionsIndex < NUM_IMAGE_SIZES; ++ dimensionsIndex ) + for(unsigned dimensionsIndex = 0; dimensionsIndex < NUM_IMAGE_SIZES; ++dimensionsIndex) { - configurations.push_back( ImageConfiguration( IMAGE_PATHS[imageIndex], IMAGE_SIZES[dimensionsIndex] ) ); + configurations.push_back(ImageConfiguration(IMAGE_PATHS[imageIndex], IMAGE_SIZES[dimensionsIndex])); } } // Stir-up the list to get some nice irregularity in the generated field: unsigned int seed = std::chrono::system_clock::now().time_since_epoch().count(); - std::shuffle( configurations.begin(), configurations.end(), std::default_random_engine(seed) ); + std::shuffle(configurations.begin(), configurations.end(), std::default_random_engine(seed)); seed = std::chrono::system_clock::now().time_since_epoch().count(); - std::shuffle( configurations.begin(), configurations.end(), std::default_random_engine(seed) ); + std::shuffle(configurations.begin(), configurations.end(), std::default_random_engine(seed)); // Place the images in the grid: std::vector::iterator config, end; - GridFlags grid( gridWidth, maxGridHeight ); - std::vector placedImages; + GridFlags grid(gridWidth, maxGridHeight); + std::vector placedImages; - for( config = configurations.begin(), end = configurations.end(); config != end; ++config ) + for(config = configurations.begin(), end = configurations.end(); config != end; ++config) { unsigned cellX, cellY; - Vector2 imageGridDims; + Vector2 imageGridDims; // Allocate a region of the grid for the image: - bool allocated = grid.AllocateRegion( config->dimensions, cellX, cellY, imageGridDims ); - if( !allocated ) + bool allocated = grid.AllocateRegion(config->dimensions, cellX, cellY, imageGridDims); + if(!allocated) { #ifdef DEBUG_PRINT_DIAGNOSTICS - fprintf( stderr, "Failed to allocate image in grid with dims (%f, %f) and path: %s.\n", config->dimensions.x, config->dimensions.y, config->path ); + fprintf(stderr, "Failed to allocate image in grid with dims (%f, %f) and path: %s.\n", config->dimensions.x, config->dimensions.y, config->path); #endif continue; } - placedImages.push_back( PositionedImage( *config, cellX, cellY, imageGridDims ) ); + placedImages.push_back(PositionedImage(*config, cellX, cellY, imageGridDims)); } - DALI_ASSERT_DEBUG( grid.DebugCheckGridValid() && "Cells were set more than once, indicating erroneous overlap in placing images on the grid." ); + DALI_ASSERT_DEBUG(grid.DebugCheckGridValid() && "Cells were set more than once, indicating erroneous overlap in placing images on the grid."); const unsigned actualGridHeight = grid.GetHighestUsedRow() + 1; // Take the images images in the grid and turn their logical locations into // coordinates in a frame defined by a parent actor: Actor gridActor = Actor::New(); - gridActor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - gridActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - gridActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + gridActor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + gridActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + gridActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); // Work out the constants of the grid and cell dimensions and positions: - const float cellWidth = fieldWidth / gridWidth; - const float cellHeight = cellWidth / CELL_ASPECT_RATIO; - const Vector2 cellSize = Vector2( cellWidth, cellHeight ); - outFieldHeight = actualGridHeight * cellHeight; - const Vector2 gridOrigin = Vector2( -fieldWidth * 0.5f, -outFieldHeight * 0.5 ); + const float cellWidth = fieldWidth / gridWidth; + const float cellHeight = cellWidth / CELL_ASPECT_RATIO; + const Vector2 cellSize = Vector2(cellWidth, cellHeight); + outFieldHeight = actualGridHeight * cellHeight; + const Vector2 gridOrigin = Vector2(-fieldWidth * 0.5f, -outFieldHeight * 0.5); - unsigned int count = 0; + unsigned int count = 0; // Build the image actors in their right locations in their parent's frame: - for( std::vector::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i, ++count ) + for(std::vector::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i, ++count) { - const PositionedImage& imageSource = *i; - const Vector2 imageSize = imageSource.imageGridDims * cellSize - Vector2( GRID_CELL_PADDING * 2, GRID_CELL_PADDING * 2 ); - const Vector2 imageRegionCorner = gridOrigin + cellSize * Vector2( imageSource.cellX, imageSource.cellY ); - const Vector2 imagePosition = imageRegionCorner + Vector2( GRID_CELL_PADDING , GRID_CELL_PADDING ) + imageSize * 0.5f; - - ImageView image = CreateImageView( imageSource.configuration.path, imageSize.x, imageSize.y, fittingMode ); - image.SetProperty( Actor::Property::POSITION, Vector3( imagePosition.x, imagePosition.y, 0 ) ); - image.SetProperty( Actor::Property::SIZE, imageSize ); - image.TouchedSignal().Connect( this, &ImageScalingIrregularGridController::OnTouchImage ); - image.ResourceReadySignal().Connect( this, &ImageScalingIrregularGridController::ResourceReadySignal ); - mFittingModes[image.GetProperty< int >( Actor::Property::ID )] = fittingMode; - mResourceUrls[image.GetProperty< int >( Actor::Property::ID )] = imageSource.configuration.path; - mSizes[image.GetProperty< int >( Actor::Property::ID )] = imageSize; - if ( count < INITIAL_IMAGES_TO_LOAD ) + const PositionedImage& imageSource = *i; + const Vector2 imageSize = imageSource.imageGridDims * cellSize - Vector2(GRID_CELL_PADDING * 2, GRID_CELL_PADDING * 2); + const Vector2 imageRegionCorner = gridOrigin + cellSize * Vector2(imageSource.cellX, imageSource.cellY); + const Vector2 imagePosition = imageRegionCorner + Vector2(GRID_CELL_PADDING, GRID_CELL_PADDING) + imageSize * 0.5f; + + ImageView image = CreateImageView(imageSource.configuration.path, imageSize.x, imageSize.y, fittingMode); + image.SetProperty(Actor::Property::POSITION, Vector3(imagePosition.x, imagePosition.y, 0)); + image.SetProperty(Actor::Property::SIZE, imageSize); + image.TouchedSignal().Connect(this, &ImageScalingIrregularGridController::OnTouchImage); + image.ResourceReadySignal().Connect(this, &ImageScalingIrregularGridController::ResourceReadySignal); + mFittingModes[image.GetProperty(Actor::Property::ID)] = fittingMode; + mResourceUrls[image.GetProperty(Actor::Property::ID)] = imageSource.configuration.path; + mSizes[image.GetProperty(Actor::Property::ID)] = imageSize; + if(count < INITIAL_IMAGES_TO_LOAD) { - gridActor.Add( image ); + gridActor.Add(image); } else { // Store the ImageView in an offwindow actor until the inital batch of ImageViews have finished loading their images // Required - mOffWindowImageViews.Add( image ); + mOffWindowImageViews.Add(image); } } return gridActor; } - /** + /** * Upon Touching an image (Release), change its scaling mode and make it spin, provided we're not scrolling. * @param[in] actor The actor touched * @param[in] event The Touch information. */ - bool OnTouchImage( Actor actor, const TouchEvent& event ) + bool OnTouchImage(Actor actor, const TouchEvent& event) { - if( ( event.GetPointCount() > 0 ) && ( !mScrolling ) ) + if((event.GetPointCount() > 0) && (!mScrolling)) { - if( event.GetState( 0 ) == PointState::UP ) + if(event.GetState(0) == PointState::UP) { // Spin the image a few times: Animation animation = Animation::New(SPIN_DURATION); - animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f * SPIN_DURATION) ), Vector3::XAXIS ), AlphaFunction::EASE_OUT ); + animation.AnimateBy(Property(actor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f * SPIN_DURATION)), Vector3::XAXIS), AlphaFunction::EASE_OUT); animation.Play(); // Change the scaling mode: - const unsigned id = actor.GetProperty< int >( Actor::Property::ID ); - Dali::FittingMode::Type newMode = NextMode( mFittingModes[id] ); - const Vector2 imageSize = mSizes[actor.GetProperty< int >( Actor::Property::ID )]; + const unsigned id = actor.GetProperty(Actor::Property::ID); + Dali::FittingMode::Type newMode = NextMode(mFittingModes[id]); + const Vector2 imageSize = mSizes[actor.GetProperty(Actor::Property::ID)]; - ImageView imageView = ImageView::DownCast( actor ); - if( imageView) + ImageView imageView = ImageView::DownCast(actor); + if(imageView) { Property::Map map; - map[Visual::Property::TYPE] = Visual::IMAGE; - map[ImageVisual::Property::URL] = mResourceUrls[id]; - map[ImageVisual::Property::DESIRED_WIDTH] = imageSize.width + 0.5f; - map[ImageVisual::Property::DESIRED_HEIGHT] = imageSize.height + 0.5f; - map[ImageVisual::Property::FITTING_MODE] = newMode; - imageView.SetProperty( ImageView::Property::IMAGE, map ); + map[Visual::Property::TYPE] = Visual::IMAGE; + map[ImageVisual::Property::URL] = mResourceUrls[id]; + map[ImageVisual::Property::DESIRED_WIDTH] = imageSize.width + 0.5f; + map[ImageVisual::Property::DESIRED_HEIGHT] = imageSize.height + 0.5f; + map[ImageVisual::Property::FITTING_MODE] = newMode; + imageView.SetProperty(ImageView::Property::IMAGE, map); } mFittingModes[id] = newMode; @@ -536,55 +532,52 @@ public: return false; } - /** + /** * Main key event handler. * Quit on escape key. */ void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) - || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } } } - /** + /** * Signal handler, called when the 'Scaling' button has been touched. * * @param[in] button The button that was pressed. */ - bool OnToggleScalingTouched( Button button ) + bool OnToggleScalingTouched(Button button) { const unsigned numChildren = mGridActor.GetChildCount(); - for( unsigned i = 0; i < numChildren; ++i ) + for(unsigned i = 0; i < numChildren; ++i) { - ImageView gridImageView = ImageView::DownCast( mGridActor.GetChildAt( i ) ); - if( gridImageView ) + ImageView gridImageView = ImageView::DownCast(mGridActor.GetChildAt(i)); + if(gridImageView) { // Cycle the scaling mode options: - unsigned int id = gridImageView.GetProperty< int >( Actor::Property::ID ); + unsigned int id = gridImageView.GetProperty(Actor::Property::ID); - const Vector2 imageSize = mSizes[ id ]; - Dali::FittingMode::Type newMode = NextMode( mFittingModes[ id ] ); + const Vector2 imageSize = mSizes[id]; + Dali::FittingMode::Type newMode = NextMode(mFittingModes[id]); Property::Map map; - map[Visual::Property::TYPE] = Visual::IMAGE; - map[ImageVisual::Property::URL] = mResourceUrls[id]; - map[ImageVisual::Property::DESIRED_WIDTH] = imageSize.width; - map[ImageVisual::Property::DESIRED_HEIGHT] = imageSize.height; - map[ImageVisual::Property::FITTING_MODE] = newMode; - gridImageView.SetProperty( ImageView::Property::IMAGE, map ); - + map[Visual::Property::TYPE] = Visual::IMAGE; + map[ImageVisual::Property::URL] = mResourceUrls[id]; + map[ImageVisual::Property::DESIRED_WIDTH] = imageSize.width; + map[ImageVisual::Property::DESIRED_HEIGHT] = imageSize.height; + map[ImageVisual::Property::FITTING_MODE] = newMode; + gridImageView.SetProperty(ImageView::Property::IMAGE, map); + mFittingModes[id] = newMode; - mFittingModes[ id ] = newMode; - - SetTitle( std::string( newMode == FittingMode::SHRINK_TO_FIT ? "SHRINK_TO_FIT" : newMode == FittingMode::SCALE_TO_FILL ? "SCALE_TO_FILL" : newMode == FittingMode::FIT_WIDTH ? "FIT_WIDTH" : "FIT_HEIGHT" ) ); + SetTitle(std::string(newMode == FittingMode::SHRINK_TO_FIT ? "SHRINK_TO_FIT" : newMode == FittingMode::SCALE_TO_FILL ? "SCALE_TO_FILL" : newMode == FittingMode::FIT_WIDTH ? "FIT_WIDTH" : "FIT_HEIGHT")); } } return true; @@ -598,12 +591,12 @@ public: { if(!mTitleActor) { - mTitleActor = DemoHelper::CreateToolBarLabel( "" ); + mTitleActor = DemoHelper::CreateToolBarLabel(""); // Add title to the tool bar. - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER ); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER); } - mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, title); } /** @@ -611,7 +604,7 @@ public: * note this state (mScrolling = true) * @param[in] position Current Scroll Position */ - void OnScrollStarted( const Vector2& position ) + void OnScrollStarted(const Vector2& position) { mScrolling = true; } @@ -621,34 +614,34 @@ public: * note this state (mScrolling = false). * @param[in] position Current Scroll Position */ - void OnScrollCompleted( const Vector2& position ) + void OnScrollCompleted(const Vector2& position) { mScrolling = false; } private: - Application& mApplication; - - Layer mContentLayer; ///< The content layer (contains non gui chrome actors) - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - TextLabel mTitleActor; ///< The Toolbar's Title. - Actor mGridActor; ///< The container for the grid of images - Actor mOffWindowImageViews; ///< ImageViews held off window until the inital batch have loaded their images - ScrollView mScrollView; ///< ScrollView UI Component - ScrollBar mScrollBarVertical; - ScrollBar mScrollBarHorizontal; - bool mScrolling; ///< ScrollView scrolling state (true = scrolling, false = stationary) + Application& mApplication; + + Layer mContentLayer; ///< The content layer (contains non gui chrome actors) + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + TextLabel mTitleActor; ///< The Toolbar's Title. + Actor mGridActor; ///< The container for the grid of images + Actor mOffWindowImageViews; ///< ImageViews held off window until the inital batch have loaded their images + ScrollView mScrollView; ///< ScrollView UI Component + ScrollBar mScrollBarVertical; + ScrollBar mScrollBarHorizontal; + bool mScrolling; ///< ScrollView scrolling state (true = scrolling, false = stationary) std::map mFittingModes; ///< Stores the current scaling mode of each image, keyed by image actor id. - std::map mResourceUrls; ///< Stores the url of each image, keyed by image actor id. - std::map mSizes; ///< Stores the current size of each image, keyed by image actor id. - unsigned int mImagesLoaded; ///< How many images have been loaded + std::map mResourceUrls; ///< Stores the url of each image, keyed by image actor id. + std::map mSizes; ///< Stores the current size of each image, keyed by image actor id. + unsigned int mImagesLoaded; ///< How many images have been loaded }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - ImageScalingIrregularGridController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + ImageScalingIrregularGridController test(application); application.MainLoop(); return 0; } diff --git a/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp b/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp index e1c6a9e..ef05f6f 100644 --- a/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp +++ b/examples/image-view-alpha-blending/image-view-alpha-blending-example.cpp @@ -23,18 +23,18 @@ using namespace Dali; namespace { -const char* const IMAGE_PATH ( DEMO_IMAGE_DIR "gallery-large-20.jpg" ); +const char* const IMAGE_PATH(DEMO_IMAGE_DIR "gallery-large-20.jpg"); } class ImageViewAlphaBlendApp : public ConnectionTracker { public: - ImageViewAlphaBlendApp( Application& application ) - : mApplication( application ), + ImageViewAlphaBlendApp(Application& application) + : mApplication(application), mIndex(0u) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create ); + mApplication.InitSignal().Connect(this, &ImageViewAlphaBlendApp::Create); } ~ImageViewAlphaBlendApp() @@ -44,45 +44,45 @@ public: private: // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent); - auto green0 = Vector4( 0.f, 1.f, 0.f, 0.25f ); - auto green1 = Vector4( 0.f, 0.25f, 0.f, 0.25f ); - auto redGreen0 = CreateTexture( Color::RED, green0 ); - auto redGreen1 = CreateTexture( Color::RED, green1 ); + auto green0 = Vector4(0.f, 1.f, 0.f, 0.25f); + auto green1 = Vector4(0.f, 0.25f, 0.f, 0.25f); + auto redGreen0 = CreateTexture(Color::RED, green0); + auto redGreen1 = CreateTexture(Color::RED, green1); float imageSize = 512.f; - Toolkit::ImageView imageView0 = CreateImageView( IMAGE_PATH ); - imageView0.SetProperty( Actor::Property::SIZE, Vector2(imageSize, imageSize) ); - imageView0.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView0.SetProperty( Actor::Property::POSITION_Y, -imageSize*0.5f ); + Toolkit::ImageView imageView0 = CreateImageView(IMAGE_PATH); + imageView0.SetProperty(Actor::Property::SIZE, Vector2(imageSize, imageSize)); + imageView0.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView0.SetProperty(Actor::Property::POSITION_Y, -imageSize * 0.5f); window.Add(imageView0); - Toolkit::ImageView imageView1 = CreateImageView( redGreen0 ); - imageView1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView1.SetProperty( Actor::Property::SIZE, Vector2(imageSize, imageSize) ); + Toolkit::ImageView imageView1 = CreateImageView(redGreen0); + imageView1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView1.SetProperty(Actor::Property::SIZE, Vector2(imageSize, imageSize)); imageView0.Add(imageView1); - Toolkit::ImageView imageView2 = CreateImageView( IMAGE_PATH ); - imageView2.SetProperty( Actor::Property::SIZE, Vector2(imageSize, imageSize) ); - imageView2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView2.SetProperty( Actor::Property::POSITION_Y, imageSize*0.5f ); + Toolkit::ImageView imageView2 = CreateImageView(IMAGE_PATH); + imageView2.SetProperty(Actor::Property::SIZE, Vector2(imageSize, imageSize)); + imageView2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView2.SetProperty(Actor::Property::POSITION_Y, imageSize * 0.5f); window.Add(imageView2); - Toolkit::ImageView imageView3 = CreateImageView( redGreen1); - imageView3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageView3.SetProperty( Actor::Property::SIZE, Vector2(imageSize, imageSize) ); + Toolkit::ImageView imageView3 = CreateImageView(redGreen1); + imageView3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageView3.SetProperty(Actor::Property::SIZE, Vector2(imageSize, imageSize)); imageView2.Add(imageView3); - imageView2.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true ); - imageView3.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true ); + imageView2.SetProperty(Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true); + imageView3.SetProperty(Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true); - Animation animation = Animation::New( 10.f ); - animation.AnimateTo(Property(imageView0, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 2.f, 8.f )); - animation.AnimateTo(Property(imageView2, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 2.f, 8.f )); - animation.SetLooping( true ); + Animation animation = Animation::New(10.f); + animation.AnimateTo(Property(imageView0, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.f, 8.f)); + animation.AnimateTo(Property(imageView2, Actor::Property::COLOR), Vector4(1.0f, 1.0f, 1.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.f, 8.f)); + animation.SetLooping(true); animation.Play(); } @@ -90,30 +90,30 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } } } - std::string CreateTexture( const Vector4& color1, const Vector4& color2 ) + std::string CreateTexture(const Vector4& color1, const Vector4& color2) { - const auto width = 2u; - const auto height = 1u; - auto size = width * height * 4; - auto pixelBuffer = new unsigned char[size]; - pixelBuffer[0] = 0xFF * color1.x; - pixelBuffer[1] = 0xFF * color1.y; - pixelBuffer[2] = 0xFF * color1.z; - pixelBuffer[3] = 0xFF * color1.w; - pixelBuffer[4] = 0xFF * color2.x; - pixelBuffer[5] = 0xFF * color2.y; - pixelBuffer[6] = 0xFF * color2.z; - pixelBuffer[7] = 0xFF * color2.w; + const auto width = 2u; + const auto height = 1u; + auto size = width * height * 4; + auto pixelBuffer = new unsigned char[size]; + pixelBuffer[0] = 0xFF * color1.x; + pixelBuffer[1] = 0xFF * color1.y; + pixelBuffer[2] = 0xFF * color1.z; + pixelBuffer[3] = 0xFF * color1.w; + pixelBuffer[4] = 0xFF * color2.x; + pixelBuffer[5] = 0xFF * color2.y; + pixelBuffer[6] = 0xFF * color2.z; + pixelBuffer[7] = 0xFF * color2.w; auto pixelData = PixelData::New(pixelBuffer, size, width, height, Pixel::RGBA8888, PixelData::ReleaseFunction::DELETE_ARRAY); - auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ); + auto texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height); texture.Upload(pixelData); return Toolkit::TextureManager::AddTexture(texture); @@ -128,20 +128,20 @@ private: propertyMap.Insert(Toolkit::ImageVisual::Property::URL, std::forward(filename)); propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); propertyMap.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL); - imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap ); + imageView.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); return imageView; } private: - Application& mApplication; + Application& mApplication; unsigned int mIndex; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ImageViewAlphaBlendApp test( application ); + Application application = Application::New(&argc, &argv); + ImageViewAlphaBlendApp test(application); application.MainLoop(); return 0; } diff --git a/examples/image-view-pixel-area/image-view-pixel-area-example.cpp b/examples/image-view-pixel-area/image-view-pixel-area-example.cpp index d7e3323..66f53a2 100644 --- a/examples/image-view-pixel-area/image-view-pixel-area-example.cpp +++ b/examples/image-view-pixel-area/image-view-pixel-area-example.cpp @@ -23,26 +23,26 @@ using namespace Dali; namespace { -const char* BIG_TEST_IMAGE( DEMO_IMAGE_DIR "book-landscape-cover.jpg" ); -const char* SMALL_TEST_IMAGE( DEMO_IMAGE_DIR "gallery-large-1.jpg" ); +const char* BIG_TEST_IMAGE(DEMO_IMAGE_DIR "book-landscape-cover.jpg"); +const char* SMALL_TEST_IMAGE(DEMO_IMAGE_DIR "gallery-large-1.jpg"); -const char * const APPLICATION_TITLE( "Pixel Area & Wrap Mode" ); -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const BUTTON_ICON( DEMO_IMAGE_DIR "icon-change.png" ); -const char * const BUTTON_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); +const char* const APPLICATION_TITLE("Pixel Area & Wrap Mode"); +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const BUTTON_ICON(DEMO_IMAGE_DIR "icon-change.png"); +const char* const BUTTON_ICON_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); -const Vector4 ORIGINAL_PIXEL_AREA( -0.5f, -0.5f, 2.f, 2.f ); -} +const Vector4 ORIGINAL_PIXEL_AREA(-0.5f, -0.5f, 2.f, 2.f); +} // namespace class ImageViewPixelAreaApp : public ConnectionTracker { public: - ImageViewPixelAreaApp( Application& application ) - : mApplication( application ), + ImageViewPixelAreaApp(Application& application) + : mApplication(application), mIndex(0u) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageViewPixelAreaApp::Create ); + mApplication.InitSignal().Connect(this, &ImageViewPixelAreaApp::Create); } ~ImageViewPixelAreaApp() @@ -52,7 +52,7 @@ public: private: // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); @@ -61,161 +61,159 @@ private: Toolkit::ToolBar toolBar; Toolkit::Control background; // Creates a default view with a default tool bar. - mContent = DemoHelper::CreateView( application, - background, - toolBar, - "", - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContent = DemoHelper::CreateView(application, + background, + toolBar, + "", + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Add a button to switch the scene. (right of toolbar) Toolkit::PushButton switchButton = Toolkit::PushButton::New(); - switchButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_ICON ); - switchButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_ICON_SELECTED ); - switchButton.ClickedSignal().Connect( this, &ImageViewPixelAreaApp::OnButtonClicked ); - toolBar.AddControl( switchButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_RIGHT, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); - + switchButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_ICON); + switchButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_ICON_SELECTED); + switchButton.ClickedSignal().Connect(this, &ImageViewPixelAreaApp::OnButtonClicked); + toolBar.AddControl(switchButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_RIGHT, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // for testing image WITH automatic atlasing - visualPropertyMap[0][ Toolkit::ImageVisual::Property::URL ] = SMALL_TEST_IMAGE; - visualPropertyMap[0][ Toolkit::ImageVisual::Property::DESIRED_WIDTH ] = 500; - visualPropertyMap[0][ Toolkit::ImageVisual::Property::DESIRED_HEIGHT ] = 500; - visualPropertyMap[0][ Toolkit::ImageVisual::Property::WRAP_MODE_U ] = WrapMode::CLAMP_TO_EDGE; - visualPropertyMap[0][ Toolkit::ImageVisual::Property::WRAP_MODE_V ] = WrapMode::MIRRORED_REPEAT; - visualPropertyMap[0][ Toolkit::ImageVisual::Property::PIXEL_AREA ] = ORIGINAL_PIXEL_AREA; + visualPropertyMap[0][Toolkit::ImageVisual::Property::URL] = SMALL_TEST_IMAGE; + visualPropertyMap[0][Toolkit::ImageVisual::Property::DESIRED_WIDTH] = 500; + visualPropertyMap[0][Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = 500; + visualPropertyMap[0][Toolkit::ImageVisual::Property::WRAP_MODE_U] = WrapMode::CLAMP_TO_EDGE; + visualPropertyMap[0][Toolkit::ImageVisual::Property::WRAP_MODE_V] = WrapMode::MIRRORED_REPEAT; + visualPropertyMap[0][Toolkit::ImageVisual::Property::PIXEL_AREA] = ORIGINAL_PIXEL_AREA; // for testing image WITHOUT automatic atlasing - visualPropertyMap[1][ Toolkit::ImageVisual::Property::URL ] = BIG_TEST_IMAGE; - visualPropertyMap[1][ Toolkit::ImageVisual::Property::DESIRED_WIDTH ] = 640; - visualPropertyMap[1][ Toolkit::ImageVisual::Property::DESIRED_HEIGHT ] = 720; - visualPropertyMap[1][ Toolkit::ImageVisual::Property::WRAP_MODE_U ] = WrapMode::MIRRORED_REPEAT; - visualPropertyMap[1][ Toolkit::ImageVisual::Property::WRAP_MODE_V ] = WrapMode::REPEAT; - visualPropertyMap[1][ Toolkit::ImageVisual::Property::PIXEL_AREA ] = ORIGINAL_PIXEL_AREA; + visualPropertyMap[1][Toolkit::ImageVisual::Property::URL] = BIG_TEST_IMAGE; + visualPropertyMap[1][Toolkit::ImageVisual::Property::DESIRED_WIDTH] = 640; + visualPropertyMap[1][Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = 720; + visualPropertyMap[1][Toolkit::ImageVisual::Property::WRAP_MODE_U] = WrapMode::MIRRORED_REPEAT; + visualPropertyMap[1][Toolkit::ImageVisual::Property::WRAP_MODE_V] = WrapMode::REPEAT; + visualPropertyMap[1][Toolkit::ImageVisual::Property::PIXEL_AREA] = ORIGINAL_PIXEL_AREA; - CreateScene( visualPropertyMap[0] ); + CreateScene(visualPropertyMap[0]); mWrapLabel = Toolkit::TextLabel::New(" Automatic atlasing\n WrapMode: CLAMP_TO_EDGE, MIRRORED_REPEAT"); - mWrapLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mWrapLabel.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_CENTER ); - mWrapLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mWrapLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mContent.Add( mWrapLabel ); - - mPixelAreaLabel = Toolkit::TextLabel::New( " Use ImageVisual::Property::PIXEL_AREA\n " ); - mPixelAreaLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mPixelAreaLabel.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_CENTER ); - mPixelAreaLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mWrapLabel.Add( mPixelAreaLabel ); + mWrapLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mWrapLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mWrapLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mWrapLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + mWrapLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + mContent.Add(mWrapLabel); + + mPixelAreaLabel = Toolkit::TextLabel::New(" Use ImageVisual::Property::PIXEL_AREA\n "); + mPixelAreaLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mPixelAreaLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mPixelAreaLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mPixelAreaLabel.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + mPixelAreaLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + mWrapLabel.Add(mPixelAreaLabel); } - void CreateScene( const Property::Value& propertyMap ) + void CreateScene(const Property::Value& propertyMap) { - for( int i=0; i<3;i++ ) - for( int j=0; j<3; j++ ) + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) { mImageView[i][j] = Toolkit::ImageView::New(); - mImageView[i][j].SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap ); - mImageView[i][j].SetProperty( Actor::Property::POSITION, Vector2( 50.f*(i-1), 50.f*(j-1) )); + mImageView[i][j].SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); + mImageView[i][j].SetProperty(Actor::Property::POSITION, Vector2(50.f * (i - 1), 50.f * (j - 1))); } - mImageView[1][1].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mImageView[1][1].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER ); - mImageView[1][1].SetProperty( Actor::Property::SCALE, 1.f/3.f ); - mContent.Add( mImageView[1][1] ); - - mImageView[0][0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mImageView[0][0].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT ); - mImageView[0][0].SetProperty( Actor::Property::POSITION, Vector2( -50.f, -50.f )); - mImageView[1][1].Add( mImageView[0][0] ); + mImageView[1][1].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageView[1][1].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mImageView[1][1].SetProperty(Actor::Property::SCALE, 1.f / 3.f); + mContent.Add(mImageView[1][1]); - mImageView[1][0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mImageView[1][0].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_CENTER ); - mImageView[1][1].Add( mImageView[1][0] ); + mImageView[0][0].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mImageView[0][0].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mImageView[0][0].SetProperty(Actor::Property::POSITION, Vector2(-50.f, -50.f)); + mImageView[1][1].Add(mImageView[0][0]); - mImageView[2][0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - mImageView[2][0].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_LEFT ); - mImageView[1][1].Add( mImageView[2][0] ); + mImageView[1][0].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mImageView[1][0].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mImageView[1][1].Add(mImageView[1][0]); - mImageView[0][1].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT ); - mImageView[0][1].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_RIGHT ); - mImageView[1][1].Add( mImageView[0][1] ); + mImageView[2][0].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + mImageView[2][0].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT); + mImageView[1][1].Add(mImageView[2][0]); - mImageView[2][1].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT ); - mImageView[2][1].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_LEFT ); - mImageView[1][1].Add( mImageView[2][1] ); + mImageView[0][1].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT); + mImageView[0][1].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_RIGHT); + mImageView[1][1].Add(mImageView[0][1]); - mImageView[0][2].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); - mImageView[0][2].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_RIGHT ); - mImageView[1][1].Add( mImageView[0][2] ); + mImageView[2][1].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT); + mImageView[2][1].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); + mImageView[1][1].Add(mImageView[2][1]); - mImageView[1][2].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mImageView[1][2].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER ); - mImageView[1][1].Add( mImageView[1][2] ); + mImageView[0][2].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + mImageView[0][2].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + mImageView[1][1].Add(mImageView[0][2]); - mImageView[2][2].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); - mImageView[2][2].SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT ); - mImageView[1][1].Add( mImageView[2][2] ); + mImageView[1][2].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mImageView[1][2].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mImageView[1][1].Add(mImageView[1][2]); + mImageView[2][2].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mImageView[2][2].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mImageView[1][1].Add(mImageView[2][2]); } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) + { + if(mAnimation) { - if( mAnimation ) - { - mAnimation.Stop(); - mAnimation.Clear(); - } + mAnimation.Stop(); + mAnimation.Clear(); + } - mIndex = ( mIndex+1 ) % 4; - if( mIndex%2 == 0 ) + mIndex = (mIndex + 1) % 4; + if(mIndex % 2 == 0) + { + // switch to the other image + // set the pixel area to image visual, the pixel area property is registered on the renderer + mContent.Remove(mImageView[1][1]); + CreateScene(visualPropertyMap[mIndex / 2]); + if(mIndex == 0) { - // switch to the other image - // set the pixel area to image visual, the pixel area property is registered on the renderer - mContent.Remove( mImageView[1][1] ); - CreateScene( visualPropertyMap[mIndex/2] ); - if( mIndex == 0 ) - { - mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT," Automatic atlasing\n WrapMode: CLAMP_TO_EDGE, MIRRORED_REPEAT"); - } - else - { - mWrapLabel.SetProperty( Toolkit::TextLabel::Property::TEXT," No atlasing\n WrapMode: MIRRORED_REPEAT, REPEAT"); - } - mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, " Use ImageVisual::Property::PIXEL_AREA\n " ); + mWrapLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, " Automatic atlasing\n WrapMode: CLAMP_TO_EDGE, MIRRORED_REPEAT"); } else { - // animate the pixel area property on image view, - // the animatable pixel area property is registered on the actor, which overwrites the property on the renderer - mAnimation = Animation::New( 10.f ); - float relativeSubSize = 0.33; - for( int i=0; i<3;i++ ) - for( int j=0; j<3; j++ ) - { - mImageView[i][j].SetProperty( Toolkit::ImageView::Property::PIXEL_AREA, ORIGINAL_PIXEL_AREA ); - mAnimation.AnimateTo( Property(mImageView[i][j], Toolkit::ImageView::Property::PIXEL_AREA), - Vector4( relativeSubSize*i, relativeSubSize*j, relativeSubSize, relativeSubSize ), - AlphaFunction::BOUNCE ); - } - mAnimation.SetLooping( true ); - mAnimation.Play(); - - mPixelAreaLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, " Animate ImageView::Property::PIXEL_AREA \n (Overwrite the ImageVisual property) " ); + mWrapLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, " No atlasing\n WrapMode: MIRRORED_REPEAT, REPEAT"); } - return true; + mPixelAreaLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, " Use ImageVisual::Property::PIXEL_AREA\n "); } + else + { + // animate the pixel area property on image view, + // the animatable pixel area property is registered on the actor, which overwrites the property on the renderer + mAnimation = Animation::New(10.f); + float relativeSubSize = 0.33; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + { + mImageView[i][j].SetProperty(Toolkit::ImageView::Property::PIXEL_AREA, ORIGINAL_PIXEL_AREA); + mAnimation.AnimateTo(Property(mImageView[i][j], Toolkit::ImageView::Property::PIXEL_AREA), + Vector4(relativeSubSize * i, relativeSubSize * j, relativeSubSize, relativeSubSize), + AlphaFunction::BOUNCE); + } + mAnimation.SetLooping(true); + mAnimation.Play(); + + mPixelAreaLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, " Animate ImageView::Property::PIXEL_AREA \n (Overwrite the ImageVisual property) "); + } + return true; + } void OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -223,20 +221,20 @@ private: } private: - Application& mApplication; - Layer mContent; + Application& mApplication; + Layer mContent; Toolkit::ImageView mImageView[3][3]; - Property::Map visualPropertyMap[2]; + Property::Map visualPropertyMap[2]; Toolkit::TextLabel mWrapLabel; Toolkit::TextLabel mPixelAreaLabel; - Animation mAnimation; - unsigned int mIndex; + Animation mAnimation; + unsigned int mIndex; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ImageViewPixelAreaApp test( application ); + Application application = Application::New(&argc, &argv); + ImageViewPixelAreaApp test(application); application.MainLoop(); return 0; } diff --git a/examples/image-view-svg/image-view-svg-example.cpp b/examples/image-view-svg/image-view-svg-example.cpp old mode 100755 new mode 100644 index fa3f1cb..d40156e --- a/examples/image-view-svg/image-view-svg-example.cpp +++ b/examples/image-view-svg/image-view-svg-example.cpp @@ -27,7 +27,7 @@ const float MIN_SCALE = 0.6f; const float MAX_SCALE = 6.f; const char* SVG_IMAGES[] = -{ + { DEMO_IMAGE_DIR "Camera.svg", DEMO_IMAGE_DIR "Contacts.svg", DEMO_IMAGE_DIR "Mail.svg", @@ -35,9 +35,8 @@ const char* SVG_IMAGES[] = DEMO_IMAGE_DIR "Phone.svg", DEMO_IMAGE_DIR "Settings.svg", DEMO_IMAGE_DIR "World.svg", - DEMO_IMAGE_DIR "Kid1.svg" -}; -const unsigned int NUM_SVG_IMAGES( sizeof( SVG_IMAGES ) / sizeof( SVG_IMAGES[0] ) ); + DEMO_IMAGE_DIR "Kid1.svg"}; +const unsigned int NUM_SVG_IMAGES(sizeof(SVG_IMAGES) / sizeof(SVG_IMAGES[0])); const unsigned int NUM_IMAGES_DISPLAYED = 4u; } // unnamed namespace @@ -46,14 +45,13 @@ const unsigned int NUM_IMAGES_DISPLAYED = 4u; class ImageSvgController : public ConnectionTracker { public: - - ImageSvgController( Application& application ) - : mApplication( application ), - mScale( 1.f ), - mIndex( 0 ) + ImageSvgController(Application& application) + : mApplication(application), + mScale(1.f), + mIndex(0) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageSvgController::Create ); + mApplication.InitSignal().Connect(this, &ImageSvgController::Create); } ~ImageSvgController() @@ -61,64 +59,64 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); Vector2 windowSize = window.GetSize(); - mActorSize = windowSize/2.f; + mActorSize = windowSize / 2.f; window.KeyEventSignal().Connect(this, &ImageSvgController::OnKeyEvent); // Background, for receiving gestures mWindowBackground = Actor::New(); - mWindowBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mWindowBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mWindowBackground.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x, windowSize.y ) ); + mWindowBackground.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mWindowBackground.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mWindowBackground.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x, windowSize.y)); window.Add(mWindowBackground); // Push button, for changing the image set for displaying Toolkit::PushButton changeButton = Toolkit::PushButton::New(); - changeButton.SetProperty( Toolkit::Button::Property::LABEL, "Next" ); - changeButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); - changeButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - window.Add( changeButton ); - changeButton.ClickedSignal().Connect( this, &ImageSvgController::OnChangeButtonClicked ); + changeButton.SetProperty(Toolkit::Button::Property::LABEL, "Next"); + changeButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + changeButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + window.Add(changeButton); + changeButton.ClickedSignal().Connect(this, &ImageSvgController::OnChangeButtonClicked); // Push button, for resetting the actor size and position Toolkit::PushButton resetButton = Toolkit::PushButton::New(); - resetButton.SetProperty( Toolkit::Button::Property::LABEL, "Reset" ); - resetButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - resetButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - window.Add( resetButton ); - resetButton.ClickedSignal().Connect( this, &ImageSvgController::OnResetButtonClicked ); + resetButton.SetProperty(Toolkit::Button::Property::LABEL, "Reset"); + resetButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + resetButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + window.Add(resetButton); + resetButton.ClickedSignal().Connect(this, &ImageSvgController::OnResetButtonClicked); // Create and put imageViews to window - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) { - mSvgActor[i] = Toolkit::ImageView::New(SVG_IMAGES[mIndex+i]); - mSvgActor[i].SetProperty( Actor::Property::SIZE, mActorSize ); - mSvgActor[i].TranslateBy( Vector3( 0.0, windowSize.height * 0.05, 0.0f ) ); - window.Add( mSvgActor[i] ); + mSvgActor[i] = Toolkit::ImageView::New(SVG_IMAGES[mIndex + i]); + mSvgActor[i].SetProperty(Actor::Property::SIZE, mActorSize); + mSvgActor[i].TranslateBy(Vector3(0.0, windowSize.height * 0.05, 0.0f)); + window.Add(mSvgActor[i]); } - mSvgActor[0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mSvgActor[0].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); - mSvgActor[1].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mSvgActor[1].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); - mSvgActor[2].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mSvgActor[2].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); - mSvgActor[3].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mSvgActor[3].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mSvgActor[0].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSvgActor[0].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mSvgActor[1].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSvgActor[1].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT); + mSvgActor[2].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSvgActor[2].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + mSvgActor[3].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSvgActor[3].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); // Connect pan gesture for moving the actors mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.DetectedSignal().Connect( this, &ImageSvgController::OnPanGesture ); - mPanGestureDetector.Attach( mWindowBackground ); + mPanGestureDetector.DetectedSignal().Connect(this, &ImageSvgController::OnPanGesture); + mPanGestureDetector.Attach(mWindowBackground); // Connect pinch gesture for resizing the actors mPinchGestureDetector = PinchGestureDetector::New(); - mPinchGestureDetector.Attach( mWindowBackground); + mPinchGestureDetector.Attach(mWindowBackground); mPinchGestureDetector.DetectedSignal().Connect(this, &ImageSvgController::OnPinch); changeButton.RaiseToTop(); @@ -126,24 +124,24 @@ public: } // Callback of push button, for changing image set - bool OnChangeButtonClicked( Toolkit::Button button ) + bool OnChangeButtonClicked(Toolkit::Button button) { - mIndex = ( mIndex + NUM_IMAGES_DISPLAYED ) % NUM_SVG_IMAGES; - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) + mIndex = (mIndex + NUM_IMAGES_DISPLAYED) % NUM_SVG_IMAGES; + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) { - mSvgActor[i].SetImage(SVG_IMAGES[mIndex+i]); + mSvgActor[i].SetImage(SVG_IMAGES[mIndex + i]); } return true; } // Callback of push button, for resetting image size and position - bool OnResetButtonClicked( Toolkit::Button button ) + bool OnResetButtonClicked(Toolkit::Button button) { - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED ; i++ ) + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) { - mSvgActor[i].SetProperty( Actor::Property::SIZE, mActorSize); - mSvgActor[i].SetProperty( Actor::Property::POSITION, Vector3::ZERO ); + mSvgActor[i].SetProperty(Actor::Property::SIZE, mActorSize); + mSvgActor[i].SetProperty(Actor::Property::POSITION, Vector3::ZERO); mScale = 1.f; } @@ -151,11 +149,11 @@ public: } // Callback of pan gesture, for moving the actors - void OnPanGesture( Actor actor, const PanGesture& gesture ) + void OnPanGesture(Actor actor, const PanGesture& gesture) { - if( gesture.GetState() == GestureState::CONTINUING ) + if(gesture.GetState() == GestureState::CONTINUING) { - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) { mSvgActor[i].TranslateBy(Vector3(gesture.GetDisplacement())); } @@ -165,19 +163,19 @@ public: // Callback of pinch gesture, for resizing the actors void OnPinch(Actor actor, const PinchGesture& gesture) { - switch( gesture.GetState() ) + switch(gesture.GetState()) { - // Only scale the image when we start or continue pinching + // Only scale the image when we start or continue pinching case GestureState::STARTED: case GestureState::CONTINUING: { - float scale = std::max( gesture.GetScale(), MIN_SCALE / mScale ); - scale = std::min( MAX_SCALE / mScale, scale ); + float scale = std::max(gesture.GetScale(), MIN_SCALE / mScale); + scale = std::min(MAX_SCALE / mScale, scale); - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) { - mSvgActor[i].SetProperty( Actor::Property::SCALE, scale ); + mSvgActor[i].SetProperty(Actor::Property::SCALE, scale); } break; } @@ -189,10 +187,10 @@ public: mScale = mScale * gesture.GetScale(); mScale = mScale > MAX_SCALE ? MAX_SCALE : mScale; mScale = mScale < MIN_SCALE ? MIN_SCALE : mScale; - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) { - mSvgActor[i].SetProperty( Actor::Property::SIZE, mActorSize * mScale ); - mSvgActor[i].SetProperty( Actor::Property::SCALE, 1.0f ); + mSvgActor[i].SetProperty(Actor::Property::SIZE, mActorSize * mScale); + mSvgActor[i].SetProperty(Actor::Property::SCALE, 1.0f); } break; } @@ -207,42 +205,42 @@ public: /** * Main key event handler */ - void OnKeyEvent(const KeyEvent& event) - { - if(event.GetState() == KeyEvent::DOWN) - { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) - { - mApplication.Quit(); - } - else - { - const char* keyName = event.GetKeyName().c_str(); - if( strcmp(keyName, "Left") == 0 ) - { - if( mScale > MIN_SCALE ) - { - mScale /= 1.1f; - } - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) - { - mSvgActor[i].SetProperty( Actor::Property::SIZE, mActorSize * mScale ); - } - } - else if( strcmp(keyName, "Right") == 0 ) - { - if( mScale < MAX_SCALE ) - { - mScale *= 1.1f; - } - for( unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++ ) - { - mSvgActor[i].SetProperty( Actor::Property::SIZE, mActorSize * mScale ); - } - } - } - } - } + void OnKeyEvent(const KeyEvent& event) + { + if(event.GetState() == KeyEvent::DOWN) + { + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) + { + mApplication.Quit(); + } + else + { + const char* keyName = event.GetKeyName().c_str(); + if(strcmp(keyName, "Left") == 0) + { + if(mScale > MIN_SCALE) + { + mScale /= 1.1f; + } + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) + { + mSvgActor[i].SetProperty(Actor::Property::SIZE, mActorSize * mScale); + } + } + else if(strcmp(keyName, "Right") == 0) + { + if(mScale < MAX_SCALE) + { + mScale *= 1.1f; + } + for(unsigned int i = 0; i < NUM_IMAGES_DISPLAYED; i++) + { + mSvgActor[i].SetProperty(Actor::Property::SIZE, mActorSize * mScale); + } + } + } + } + } private: Application& mApplication; @@ -250,16 +248,16 @@ private: PanGestureDetector mPanGestureDetector; PinchGestureDetector mPinchGestureDetector; - Toolkit::ImageView mSvgActor[4]; - Vector2 mActorSize; - float mScale; - unsigned int mIndex; + Toolkit::ImageView mSvgActor[4]; + Vector2 mActorSize; + float mScale; + unsigned int mIndex; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ImageSvgController test( application ); + Application application = Application::New(&argc, &argv); + ImageSvgController test(application); application.MainLoop(); return 0; } diff --git a/examples/image-view-url/image-view-url-example.cpp b/examples/image-view-url/image-view-url-example.cpp index 9048d95..9036e38 100644 --- a/examples/image-view-url/image-view-url-example.cpp +++ b/examples/image-view-url/image-view-url-example.cpp @@ -24,52 +24,51 @@ using namespace Dali; namespace { -const char* BIG_TEST_IMAGE( DEMO_IMAGE_DIR "book-landscape-cover.jpg" ); +const char* BIG_TEST_IMAGE(DEMO_IMAGE_DIR "book-landscape-cover.jpg"); -const char * const APPLICATION_TITLE( "Image View URL" ); -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const BUTTON_ICON( DEMO_IMAGE_DIR "icon-change.png" ); -const char * const BUTTON_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); +const char* const APPLICATION_TITLE("Image View URL"); +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const BUTTON_ICON(DEMO_IMAGE_DIR "icon-change.png"); +const char* const BUTTON_ICON_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); const char* FILTER_FRAGMENT_SOURCE = -{ - "precision highp float;\n" - "varying mediump vec2 vTexCoord;\n" - "uniform sampler2D sTexture;\n" - "uniform mediump float uDelta;\n" - "void main()\n" - "{\n" - " vec4 color = vec4(0.0);\n" - " vec2 texCoord = vTexCoord * 2. - 1.;\n" - " mat2 rotation = mat2(cos(uDelta), -sin(uDelta), sin(uDelta), cos(uDelta));" - " texCoord = (rotation * texCoord) * .5 + .5;\n" - " color += texture2D( sTexture, texCoord );\n" - " gl_FragColor = color;\n" - "}\n" -}; + { + "precision highp float;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform sampler2D sTexture;\n" + "uniform mediump float uDelta;\n" + "void main()\n" + "{\n" + " vec4 color = vec4(0.0);\n" + " vec2 texCoord = vTexCoord * 2. - 1.;\n" + " mat2 rotation = mat2(cos(uDelta), -sin(uDelta), sin(uDelta), cos(uDelta));" + " texCoord = (rotation * texCoord) * .5 + .5;\n" + " color += texture2D( sTexture, texCoord );\n" + " gl_FragColor = color;\n" + "}\n"}; const char* DELTA_UNIFORM_NAME = "uDelta"; const Vector2 TARGET_SIZE(800.f, 800.f); -} +} // namespace class ImageViewUrlApp : public ConnectionTracker { public: - ImageViewUrlApp( Application& application, std::string url ) - : mApplication( application ), - mUrl( url ), - mDeltaPropertyIndex( Property::INVALID_INDEX ) + ImageViewUrlApp(Application& application, std::string url) + : mApplication(application), + mUrl(url), + mDeltaPropertyIndex(Property::INVALID_INDEX) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageViewUrlApp::Create ); + mApplication.InitSignal().Connect(this, &ImageViewUrlApp::Create); } ~ImageViewUrlApp() = default; private: // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); @@ -78,47 +77,47 @@ private: Toolkit::ToolBar toolBar; Toolkit::Control background; // Creates a default view with a default tool bar. - mContent = DemoHelper::CreateView( application, - background, - toolBar, - "", - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContent = DemoHelper::CreateView(application, + background, + toolBar, + "", + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Add a button to switch the scene. (right of toolbar) Toolkit::PushButton switchButton = Toolkit::PushButton::New(); - switchButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_ICON ); - switchButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_ICON_SELECTED ); - switchButton.ClickedSignal().Connect( this, &ImageViewUrlApp::OnButtonClicked ); - toolBar.AddControl( switchButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_RIGHT, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + switchButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_ICON); + switchButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_ICON_SELECTED); + switchButton.ClickedSignal().Connect(this, &ImageViewUrlApp::OnButtonClicked); + toolBar.AddControl(switchButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_RIGHT, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); std::string url = mUrl; - if( url.empty() ) + if(url.empty()) { url = BIG_TEST_IMAGE; } - CreateRenderTask( url ); - CreateScene( ); + CreateRenderTask(url); + CreateScene(); } - void CreateRenderTask( const std::string& url ) + void CreateRenderTask(const std::string& url) { auto rootActor = mApplication.GetWindow().GetRootLayer(); auto cameraActor = CameraActor::New(TARGET_SIZE); - cameraActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + cameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); cameraActor.SetInvertYAxis(true); rootActor.Add(cameraActor); { // create actor to render input with applied shader - mActorForInput = Toolkit::ImageView::New( url ); - mActorForInput.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mActorForInput.SetProperty( Actor::Property::SIZE, TARGET_SIZE); + mActorForInput = Toolkit::ImageView::New(url); + mActorForInput.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActorForInput.SetProperty(Actor::Property::SIZE, TARGET_SIZE); Property::Map customShader; customShader[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = FILTER_FRAGMENT_SOURCE; Property::Map visualMap; @@ -137,15 +136,15 @@ private: renderTask.SetSourceActor(mActorForInput); renderTask.SetExclusive(true); renderTask.SetInputEnabled(false); - renderTask.SetClearColor(Vector4(1.,0.,0.,1.)); + renderTask.SetClearColor(Vector4(1., 0., 0., 1.)); renderTask.SetClearEnabled(true); renderTask.SetCameraActor(cameraActor); - mOutputTexture = Texture::New(TextureType::TEXTURE_2D, + mOutputTexture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, unsigned(TARGET_SIZE.width), unsigned(TARGET_SIZE.height)); - auto framebuffer = FrameBuffer::New(TARGET_SIZE.width, TARGET_SIZE.height, FrameBuffer::Attachment::NONE ); + auto framebuffer = FrameBuffer::New(TARGET_SIZE.width, TARGET_SIZE.height, FrameBuffer::Attachment::NONE); framebuffer.AttachColorTexture(mOutputTexture); renderTask.SetFrameBuffer(framebuffer); @@ -154,20 +153,20 @@ private: // animate the shader uniform mAnimation = Animation::New(10.f); - mActorForInput.SetProperty( mDeltaPropertyIndex, 0.f ); - mAnimation.AnimateTo( Property( mActorForInput, mDeltaPropertyIndex ), Math::PI * 2.f ); + mActorForInput.SetProperty(mDeltaPropertyIndex, 0.f); + mAnimation.AnimateTo(Property(mActorForInput, mDeltaPropertyIndex), Math::PI * 2.f); mAnimation.SetLooping(true); mAnimation.Play(); } } - void CreateScene( ) + void CreateScene() { - auto url = Dali::Toolkit::TextureManager::AddTexture(mOutputTexture); + auto url = Dali::Toolkit::TextureManager::AddTexture(mOutputTexture); mImageView = Toolkit::ImageView::New(url); - mImageView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mImageView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); mContent.Add(mImageView); } @@ -188,7 +187,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -196,27 +195,27 @@ private: } private: - Application& mApplication; - std::string mUrl; - Layer mContent; + Application& mApplication; + std::string mUrl; + Layer mContent; Toolkit::ImageView mImageView; - Animation mAnimation; - Actor mActorForInput; - Property::Index mDeltaPropertyIndex; - Texture mOutputTexture; + Animation mAnimation; + Actor mActorForInput; + Property::Index mDeltaPropertyIndex; + Texture mOutputTexture; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); std::string url; - if( argc > 1 ) + if(argc > 1) { url = argv[1]; } - ImageViewUrlApp test( application, url ); + ImageViewUrlApp test(application, url); application.MainLoop(); return 0; } diff --git a/examples/image-view/image-view-example.cpp b/examples/image-view/image-view-example.cpp index 2e19d64..f6c74b8 100644 --- a/examples/image-view/image-view-example.cpp +++ b/examples/image-view/image-view-example.cpp @@ -15,78 +15,74 @@ * */ -#include -#include "shared/view.h" -#include #include #include -#include #include +#include #include +#include +#include +#include "shared/view.h" using namespace Dali; namespace { - -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-gradient.jpg" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "Image view" ); +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-gradient.jpg"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("Image view"); const char* IMAGE_PATH[] = { - DEMO_IMAGE_DIR "gallery-small-23.jpg", - DEMO_IMAGE_DIR "woodEffect.jpg", - DEMO_IMAGE_DIR "wood.png", // 32bits image - DEMO_IMAGE_DIR "heartsframe.9.png", - DEMO_IMAGE_DIR "World.svg" -}; + DEMO_IMAGE_DIR "gallery-small-23.jpg", + DEMO_IMAGE_DIR "woodEffect.jpg", + DEMO_IMAGE_DIR "wood.png", // 32bits image + DEMO_IMAGE_DIR "heartsframe.9.png", + DEMO_IMAGE_DIR "World.svg"}; const unsigned int NUMBER_OF_IMAGES = 3; enum CellPlacement { - TOP_BUTTON, - MID_BUTTON, - LOWER_BUTTON, - IMAGE, - NUMBER_OF_ROWS + TOP_BUTTON, + MID_BUTTON, + LOWER_BUTTON, + IMAGE, + NUMBER_OF_ROWS }; - -unsigned int GetButtonIndex( Toolkit::Button button ) +unsigned int GetButtonIndex(Toolkit::Button button) { - std::string buttonName = button.GetProperty< std::string >( Dali::Actor::Property::NAME ); - unsigned int index = 0; + std::string buttonName = button.GetProperty(Dali::Actor::Property::NAME); + unsigned int index = 0; - if ( buttonName != "") + if(buttonName != "") { - index = std::stoul( buttonName ); + index = std::stoul(buttonName); } return index; } - const unsigned int NUMBER_OF_RESOURCES = sizeof(IMAGE_PATH) / sizeof(char*); -std::string EXAMPLE_INSTRUCTIONS = "Instructions: Change button cycles through different image visuals, " - "on/off takes the ImageView and it's current visual on or off window."; +std::string EXAMPLE_INSTRUCTIONS = + "Instructions: Change button cycles through different image visuals, " + "on/off takes the ImageView and it's current visual on or off window."; -const float CORNER_RADIUS_VALUE( 20.0f ); +const float CORNER_RADIUS_VALUE(20.0f); -} // namespace +} // namespace -class ImageViewController: public ConnectionTracker +class ImageViewController : public ConnectionTracker { - public: - - ImageViewController( Application& application ) - : mApplication( application ), - mCurrentPositionToggle( 0, 0 ), - mCurrentPositionImage( 0, 0 ) +public: + ImageViewController(Application& application) + : mApplication(application), + mCurrentPositionToggle(0, 0), + mCurrentPositionImage(0, 0) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ImageViewController::Create ); + mApplication.InitSignal().Connect(this, &ImageViewController::Create); } ~ImageViewController() @@ -94,88 +90,86 @@ class ImageViewController: public ConnectionTracker // Nothing to do here } - void Create( Application& application ) + void Create(Application& application) { // The Init signal is received once (only) during the Application lifetime // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); - + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Create a table view to show a pair of buttons above each image. - mTable = Toolkit::TableView::New( CellPlacement::NUMBER_OF_ROWS, NUMBER_OF_IMAGES ); - mTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Vector3 offset( 0.9f, 0.70f, 0.0f ); - mTable.SetProperty( Actor::Property::SIZE_MODE_FACTOR, offset ); + mTable = Toolkit::TableView::New(CellPlacement::NUMBER_OF_ROWS, NUMBER_OF_IMAGES); + mTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mTable.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + Vector3 offset(0.9f, 0.70f, 0.0f); + mTable.SetProperty(Actor::Property::SIZE_MODE_FACTOR, offset); mTable.SetFitHeight(CellPlacement::TOP_BUTTON); mTable.SetFitHeight(CellPlacement::MID_BUTTON); mTable.SetFitHeight(CellPlacement::LOWER_BUTTON); - mContentLayer.Add( mTable ); - - Toolkit::TextLabel instructions = Toolkit::TextLabel::New( EXAMPLE_INSTRUCTIONS ); - instructions.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - instructions.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_CENTER); - instructions.SetProperty( Actor::Property::POSITION_Y, -50.0f); - instructions.SetProperty( Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL, true ); - instructions.SetProperty( Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 10 ); + mContentLayer.Add(mTable); + + Toolkit::TextLabel instructions = Toolkit::TextLabel::New(EXAMPLE_INSTRUCTIONS); + instructions.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + instructions.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + instructions.SetProperty(Actor::Property::POSITION_Y, -50.0f); + instructions.SetProperty(Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL, true); + instructions.SetProperty(Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 10); mContentLayer.Add(instructions); - for( unsigned int x = 0; x < NUMBER_OF_IMAGES; x++ ) + for(unsigned int x = 0; x < NUMBER_OF_IMAGES; x++) { Toolkit::PushButton button = Toolkit::PushButton::New(); - button.SetProperty( Toolkit::Button::Property::LABEL, "on/off" ); - button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - button.ClickedSignal().Connect( this, &ImageViewController::ToggleImageOnWindow ); - button.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + button.SetProperty(Toolkit::Button::Property::LABEL, "on/off"); + button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + button.ClickedSignal().Connect(this, &ImageViewController::ToggleImageOnWindow); + button.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + button.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); std::string s = std::to_string(x); - button.SetProperty( Dali::Actor::Property::NAME, s ); - mTable.AddChild( button, Toolkit::TableView::CellPosition( CellPlacement::TOP_BUTTON, x ) ); + button.SetProperty(Dali::Actor::Property::NAME, s); + mTable.AddChild(button, Toolkit::TableView::CellPosition(CellPlacement::TOP_BUTTON, x)); Toolkit::PushButton button2 = Toolkit::PushButton::New(); - button2.SetProperty( Toolkit::Button::Property::LABEL, "Change" ); - button2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - button2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - button2.ClickedSignal().Connect( this, &ImageViewController::ChangeImageClicked ); - button2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - button2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - button2.SetProperty( Dali::Actor::Property::NAME, s ); - mTable.AddChild( button2, Toolkit::TableView::CellPosition( CellPlacement::MID_BUTTON, x ) ); + button2.SetProperty(Toolkit::Button::Property::LABEL, "Change"); + button2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + button2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + button2.ClickedSignal().Connect(this, &ImageViewController::ChangeImageClicked); + button2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + button2.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + button2.SetProperty(Dali::Actor::Property::NAME, s); + mTable.AddChild(button2, Toolkit::TableView::CellPosition(CellPlacement::MID_BUTTON, x)); Toolkit::PushButton button3 = Toolkit::PushButton::New(); - button3.SetProperty( Toolkit::Button::Property::LABEL, "Round" ); - button3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - button3.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - button3.ClickedSignal().Connect( this, &ImageViewController::RoundedCornerClicked ); - button3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - button3.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - button3.SetProperty( Dali::Actor::Property::NAME, s ); - mTable.AddChild( button3, Toolkit::TableView::CellPosition( CellPlacement::LOWER_BUTTON, x ) ); - - mImageViews[x] = Toolkit::ImageView::New( ); + button3.SetProperty(Toolkit::Button::Property::LABEL, "Round"); + button3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + button3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + button3.ClickedSignal().Connect(this, &ImageViewController::RoundedCornerClicked); + button3.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + button3.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + button3.SetProperty(Dali::Actor::Property::NAME, s); + mTable.AddChild(button3, Toolkit::TableView::CellPosition(CellPlacement::LOWER_BUTTON, x)); + + mImageViews[x] = Toolkit::ImageView::New(); Property::Map imagePropertyMap; - imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE ); - imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ 0 ] ); - mImageViews[x].SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap ); - + imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); + imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, IMAGE_PATH[0]); + mImageViews[x].SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap); - mImageViews[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mImageViews[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mImageViews[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mTable.AddChild( mImageViews[x], Toolkit::TableView::CellPosition( CellPlacement::IMAGE, x ) ); + mImageViews[x].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImageViews[x].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mImageViews[x].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mTable.AddChild(mImageViews[x], Toolkit::TableView::CellPosition(CellPlacement::IMAGE, x)); // Set changeable counter and toggle for each ImageView - mImageViewImageIndexStatus[x] = 0; - mImageViewToggleStatus[x] = true; + mImageViewImageIndexStatus[x] = 0; + mImageViewToggleStatus[x] = true; mImageViewRoundedCornerStatus[x] = false; } @@ -183,45 +177,44 @@ class ImageViewController: public ConnectionTracker } private: - - void ImmediateLoadImage( const char* urlToLoad ) + void ImmediateLoadImage(const char* urlToLoad) { Property::Map imagePropertyMap; - imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE ); - imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, urlToLoad ); - Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( imagePropertyMap ); + imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); + imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, urlToLoad); + Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(imagePropertyMap); visual.Reset(); } - bool ToggleImageOnWindow( Toolkit::Button button ) + bool ToggleImageOnWindow(Toolkit::Button button) { - unsigned int buttonIndex = GetButtonIndex( button ); + unsigned int buttonIndex = GetButtonIndex(button); - Toolkit::ImageView imageView = mImageViews[ buttonIndex ]; + Toolkit::ImageView imageView = mImageViews[buttonIndex]; - if( mImageViewToggleStatus[ buttonIndex ] ) + if(mImageViewToggleStatus[buttonIndex]) { imageView.Unparent(); } else { - mTable.AddChild( imageView, Toolkit::TableView::CellPosition( CellPlacement::IMAGE, GetButtonIndex( button ) ) ); + mTable.AddChild(imageView, Toolkit::TableView::CellPosition(CellPlacement::IMAGE, GetButtonIndex(button))); } - mImageViewToggleStatus[ buttonIndex ] = !mImageViewToggleStatus[ buttonIndex ]; + mImageViewToggleStatus[buttonIndex] = !mImageViewToggleStatus[buttonIndex]; return true; } - bool ChangeImageClicked( Toolkit::Button button ) + bool ChangeImageClicked(Toolkit::Button button) { - unsigned int buttonIndex = GetButtonIndex( button ); + unsigned int buttonIndex = GetButtonIndex(button); - if( mImageViews[buttonIndex].GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) + if(mImageViews[buttonIndex].GetProperty(Actor::Property::CONNECTED_TO_SCENE)) { ++mImageViewImageIndexStatus[buttonIndex]; - if( mImageViewImageIndexStatus[buttonIndex] == NUMBER_OF_RESOURCES ) + if(mImageViewImageIndexStatus[buttonIndex] == NUMBER_OF_RESOURCES) { mImageViewImageIndexStatus[buttonIndex] = 0; } @@ -230,27 +223,27 @@ private: mImageViewRoundedCornerStatus[buttonIndex] = false; Property::Map imagePropertyMap; - imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE ); - imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] ); - mImageViews[buttonIndex].SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap ); + imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); + imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, IMAGE_PATH[mImageViewImageIndexStatus[buttonIndex]]); + mImageViews[buttonIndex].SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap); } return true; } - bool RoundedCornerClicked( Toolkit::Button button ) + bool RoundedCornerClicked(Toolkit::Button button) { - unsigned int buttonIndex = GetButtonIndex( button ); + unsigned int buttonIndex = GetButtonIndex(button); - if( mImageViews[buttonIndex].GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) + if(mImageViews[buttonIndex].GetProperty(Actor::Property::CONNECTED_TO_SCENE)) { - mImageViewRoundedCornerStatus[ buttonIndex ] = !mImageViewRoundedCornerStatus[ buttonIndex ]; + mImageViewRoundedCornerStatus[buttonIndex] = !mImageViewRoundedCornerStatus[buttonIndex]; Property::Map imagePropertyMap; - imagePropertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE ); - imagePropertyMap.Insert( Toolkit::ImageVisual::Property::URL, IMAGE_PATH[ mImageViewImageIndexStatus[buttonIndex] ] ); - imagePropertyMap.Insert( Toolkit::DevelVisual::Property::CORNER_RADIUS, mImageViewRoundedCornerStatus[buttonIndex] ? CORNER_RADIUS_VALUE : 0.0f ); + imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); + imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, IMAGE_PATH[mImageViewImageIndexStatus[buttonIndex]]); + imagePropertyMap.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImageViewRoundedCornerStatus[buttonIndex] ? CORNER_RADIUS_VALUE : 0.0f); - mImageViews[buttonIndex].SetProperty( Toolkit::ImageView::Property::IMAGE, imagePropertyMap ); + mImageViews[buttonIndex].SetProperty(Toolkit::ImageView::Property::IMAGE, imagePropertyMap); } return true; } @@ -262,7 +255,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -270,26 +263,25 @@ private: } private: - Application& mApplication; + Application& mApplication; - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - Layer mContentLayer; ///< Content layer - Toolkit::TableView mTable; - Toolkit::ImageView mImageViews[ NUMBER_OF_IMAGES ]; - bool mImageViewToggleStatus[ NUMBER_OF_IMAGES ]; - bool mImageViewRoundedCornerStatus[ NUMBER_OF_IMAGES ]; - unsigned int mImageViewImageIndexStatus[ NUMBER_OF_IMAGES ]; + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer + Toolkit::TableView mTable; + Toolkit::ImageView mImageViews[NUMBER_OF_IMAGES]; + bool mImageViewToggleStatus[NUMBER_OF_IMAGES]; + bool mImageViewRoundedCornerStatus[NUMBER_OF_IMAGES]; + unsigned int mImageViewImageIndexStatus[NUMBER_OF_IMAGES]; Toolkit::TableView::CellPosition mCurrentPositionToggle; Toolkit::TableView::CellPosition mCurrentPositionImage; - }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - ImageViewController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + ImageViewController test(application); application.MainLoop(); return 0; } diff --git a/examples/item-view/item-view-example.cpp b/examples/item-view/item-view-example.cpp old mode 100755 new mode 100644 index addbfe5..95378a7 --- a/examples/item-view/item-view-example.cpp +++ b/examples/item-view/item-view-example.cpp @@ -18,16 +18,15 @@ #include #include "shared/view.h" -#include #include #include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { - enum AllImagesLayouts { SPIRAL_LAYOUT, @@ -38,81 +37,81 @@ enum AllImagesLayouts }; const char* IMAGE_PATHS[] = { - DEMO_IMAGE_DIR "gallery-medium-1.jpg", - DEMO_IMAGE_DIR "gallery-medium-2.jpg", - DEMO_IMAGE_DIR "gallery-medium-3.jpg", - DEMO_IMAGE_DIR "gallery-medium-4.jpg", - DEMO_IMAGE_DIR "gallery-medium-5.jpg", - DEMO_IMAGE_DIR "gallery-medium-6.jpg", - DEMO_IMAGE_DIR "gallery-medium-7.jpg", - DEMO_IMAGE_DIR "gallery-medium-8.jpg", - DEMO_IMAGE_DIR "gallery-medium-9.jpg", - DEMO_IMAGE_DIR "gallery-medium-10.jpg", - DEMO_IMAGE_DIR "gallery-medium-11.jpg", - DEMO_IMAGE_DIR "gallery-medium-12.jpg", - DEMO_IMAGE_DIR "gallery-medium-13.jpg", - DEMO_IMAGE_DIR "gallery-medium-14.jpg", - DEMO_IMAGE_DIR "gallery-medium-15.jpg", - DEMO_IMAGE_DIR "gallery-medium-16.jpg", - DEMO_IMAGE_DIR "gallery-medium-17.jpg", - DEMO_IMAGE_DIR "gallery-medium-18.jpg", - DEMO_IMAGE_DIR "gallery-medium-19.jpg", - DEMO_IMAGE_DIR "gallery-medium-20.jpg", - DEMO_IMAGE_DIR "gallery-medium-21.jpg", - DEMO_IMAGE_DIR "gallery-medium-22.jpg", - DEMO_IMAGE_DIR "gallery-medium-23.jpg", - DEMO_IMAGE_DIR "gallery-medium-24.jpg", - DEMO_IMAGE_DIR "gallery-medium-25.jpg", - DEMO_IMAGE_DIR "gallery-medium-26.jpg", - DEMO_IMAGE_DIR "gallery-medium-27.jpg", - DEMO_IMAGE_DIR "gallery-medium-28.jpg", - DEMO_IMAGE_DIR "gallery-medium-29.jpg", - DEMO_IMAGE_DIR "gallery-medium-30.jpg", - DEMO_IMAGE_DIR "gallery-medium-31.jpg", - DEMO_IMAGE_DIR "gallery-medium-32.jpg", - DEMO_IMAGE_DIR "gallery-medium-33.jpg", - DEMO_IMAGE_DIR "gallery-medium-34.jpg", - DEMO_IMAGE_DIR "gallery-medium-35.jpg", - DEMO_IMAGE_DIR "gallery-medium-36.jpg", - DEMO_IMAGE_DIR "gallery-medium-37.jpg", - DEMO_IMAGE_DIR "gallery-medium-38.jpg", - DEMO_IMAGE_DIR "gallery-medium-39.jpg", - DEMO_IMAGE_DIR "gallery-medium-40.jpg", - DEMO_IMAGE_DIR "gallery-medium-41.jpg", - DEMO_IMAGE_DIR "gallery-medium-42.jpg", - DEMO_IMAGE_DIR "gallery-medium-43.jpg", - DEMO_IMAGE_DIR "gallery-medium-44.jpg", - DEMO_IMAGE_DIR "gallery-medium-45.jpg", - DEMO_IMAGE_DIR "gallery-medium-46.jpg", - DEMO_IMAGE_DIR "gallery-medium-47.jpg", - DEMO_IMAGE_DIR "gallery-medium-48.jpg", - DEMO_IMAGE_DIR "gallery-medium-49.jpg", - DEMO_IMAGE_DIR "gallery-medium-50.jpg", - DEMO_IMAGE_DIR "gallery-medium-51.jpg", - DEMO_IMAGE_DIR "gallery-medium-52.jpg", - DEMO_IMAGE_DIR "gallery-medium-53.jpg", + DEMO_IMAGE_DIR "gallery-medium-1.jpg", + DEMO_IMAGE_DIR "gallery-medium-2.jpg", + DEMO_IMAGE_DIR "gallery-medium-3.jpg", + DEMO_IMAGE_DIR "gallery-medium-4.jpg", + DEMO_IMAGE_DIR "gallery-medium-5.jpg", + DEMO_IMAGE_DIR "gallery-medium-6.jpg", + DEMO_IMAGE_DIR "gallery-medium-7.jpg", + DEMO_IMAGE_DIR "gallery-medium-8.jpg", + DEMO_IMAGE_DIR "gallery-medium-9.jpg", + DEMO_IMAGE_DIR "gallery-medium-10.jpg", + DEMO_IMAGE_DIR "gallery-medium-11.jpg", + DEMO_IMAGE_DIR "gallery-medium-12.jpg", + DEMO_IMAGE_DIR "gallery-medium-13.jpg", + DEMO_IMAGE_DIR "gallery-medium-14.jpg", + DEMO_IMAGE_DIR "gallery-medium-15.jpg", + DEMO_IMAGE_DIR "gallery-medium-16.jpg", + DEMO_IMAGE_DIR "gallery-medium-17.jpg", + DEMO_IMAGE_DIR "gallery-medium-18.jpg", + DEMO_IMAGE_DIR "gallery-medium-19.jpg", + DEMO_IMAGE_DIR "gallery-medium-20.jpg", + DEMO_IMAGE_DIR "gallery-medium-21.jpg", + DEMO_IMAGE_DIR "gallery-medium-22.jpg", + DEMO_IMAGE_DIR "gallery-medium-23.jpg", + DEMO_IMAGE_DIR "gallery-medium-24.jpg", + DEMO_IMAGE_DIR "gallery-medium-25.jpg", + DEMO_IMAGE_DIR "gallery-medium-26.jpg", + DEMO_IMAGE_DIR "gallery-medium-27.jpg", + DEMO_IMAGE_DIR "gallery-medium-28.jpg", + DEMO_IMAGE_DIR "gallery-medium-29.jpg", + DEMO_IMAGE_DIR "gallery-medium-30.jpg", + DEMO_IMAGE_DIR "gallery-medium-31.jpg", + DEMO_IMAGE_DIR "gallery-medium-32.jpg", + DEMO_IMAGE_DIR "gallery-medium-33.jpg", + DEMO_IMAGE_DIR "gallery-medium-34.jpg", + DEMO_IMAGE_DIR "gallery-medium-35.jpg", + DEMO_IMAGE_DIR "gallery-medium-36.jpg", + DEMO_IMAGE_DIR "gallery-medium-37.jpg", + DEMO_IMAGE_DIR "gallery-medium-38.jpg", + DEMO_IMAGE_DIR "gallery-medium-39.jpg", + DEMO_IMAGE_DIR "gallery-medium-40.jpg", + DEMO_IMAGE_DIR "gallery-medium-41.jpg", + DEMO_IMAGE_DIR "gallery-medium-42.jpg", + DEMO_IMAGE_DIR "gallery-medium-43.jpg", + DEMO_IMAGE_DIR "gallery-medium-44.jpg", + DEMO_IMAGE_DIR "gallery-medium-45.jpg", + DEMO_IMAGE_DIR "gallery-medium-46.jpg", + DEMO_IMAGE_DIR "gallery-medium-47.jpg", + DEMO_IMAGE_DIR "gallery-medium-48.jpg", + DEMO_IMAGE_DIR "gallery-medium-49.jpg", + DEMO_IMAGE_DIR "gallery-medium-50.jpg", + DEMO_IMAGE_DIR "gallery-medium-51.jpg", + DEMO_IMAGE_DIR "gallery-medium-52.jpg", + DEMO_IMAGE_DIR "gallery-medium-53.jpg", }; const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*); -const char* BACKGROUND_IMAGE( "" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-edit.png" ); -const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-edit-selected.png" ); -const char* SPIRAL_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png" ); -const char* SPIRAL_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-spiral-selected.png" ); -const char* GRID_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-grid.png" ); -const char* GRID_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png" ); -const char* DEPTH_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-depth.png" ); -const char* DEPTH_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-depth-selected.png" ); -const char* DELETE_IMAGE( DEMO_IMAGE_DIR "icon-delete.png" ); -const char* DELETE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-delete-selected.png" ); -const char* REPLACE_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" ); -const char* REPLACE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" ); -const char* INSERT_IMAGE( DEMO_IMAGE_DIR "icon-insert.png" ); -const char* INSERT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-insert-selected.png" ); -const char* SELECTED_IMAGE( DEMO_IMAGE_DIR "item-select-check.png" ); -const char* APPLICATION_TITLE( "ItemView" ); +const char* BACKGROUND_IMAGE(""); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* EDIT_IMAGE(DEMO_IMAGE_DIR "icon-edit.png"); +const char* EDIT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-edit-selected.png"); +const char* SPIRAL_LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png"); +const char* SPIRAL_LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-item-view-layout-spiral-selected.png"); +const char* GRID_LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-item-view-layout-grid.png"); +const char* GRID_LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png"); +const char* DEPTH_LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-item-view-layout-depth.png"); +const char* DEPTH_LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-item-view-layout-depth-selected.png"); +const char* DELETE_IMAGE(DEMO_IMAGE_DIR "icon-delete.png"); +const char* DELETE_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-delete-selected.png"); +const char* REPLACE_IMAGE(DEMO_IMAGE_DIR "icon-replace.png"); +const char* REPLACE_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-replace-selected.png"); +const char* INSERT_IMAGE(DEMO_IMAGE_DIR "icon-insert.png"); +const char* INSERT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-insert-selected.png"); +const char* SELECTED_IMAGE(DEMO_IMAGE_DIR "item-select-check.png"); +const char* APPLICATION_TITLE("ItemView"); const char* SPIRAL_LABEL("Spiral"); const char* GRID_LABEL("Grid"); @@ -120,33 +119,33 @@ const char* DEPTH_LABEL("Depth"); const float ITEM_BORDER_SIZE = 2.0f; -const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f; +const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f; const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f; -const float DEPTH_LAYOUT_COLUMNS = 3.0f; +const float DEPTH_LAYOUT_COLUMNS = 3.0f; const float MIN_SWIPE_DISTANCE = 15.0f; -const float MIN_SWIPE_SPEED = 5.0f; +const float MIN_SWIPE_SPEED = 5.0f; const float SELECTION_BORDER_WIDTH = 3.0f; -const float BUTTON_BORDER = -10.0f; +const float BUTTON_BORDER = -10.0f; const float MENU_OPTION_HEIGHT(140.0f); const float LABEL_TEXT_SIZE_Y = 20.0f; -const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f ); +const Vector3 INITIAL_OFFSCREEN_POSITION(1000.0f, 0, -1000.0f); const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.f; -static Vector3 DepthLayoutItemSizeFunctionPortrait( float layoutWidth ) +static Vector3 DepthLayoutItemSizeFunctionPortrait(float layoutWidth) { - float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT; + float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT; // 1x1 aspect ratio return Vector3(width, width, width); } -static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth ) +static Vector3 DepthLayoutItemSizeFunctionLandscape(float layoutWidth) { - float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE; + float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE; // 1x1 aspect ratio return Vector3(width, width, width); @@ -163,7 +162,6 @@ static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth ) class ItemViewExample : public ConnectionTracker, public ItemFactory { public: - enum Mode { MODE_NORMAL, @@ -180,12 +178,12 @@ public: * Constructor * @param application class, stored as reference */ - ItemViewExample( Application& application ) - : mApplication( application ), - mMode( MODE_NORMAL ), - mOrientation( 0 ), - mCurrentLayout( SPIRAL_LAYOUT ), - mDurationSeconds( 0.25f ) + ItemViewExample(Application& application) + : mApplication(application), + mMode(MODE_NORMAL), + mOrientation(0), + mCurrentLayout(SPIRAL_LAYOUT), + mDurationSeconds(0.25f) { // Connect to the Application's Init signal mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit); @@ -198,94 +196,94 @@ public: { Window window = app.GetWindow(); window.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent); - window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); Vector2 windowSize = window.GetSize(); // Creates a default view with a default tool bar. // The view is added to the window. - Layer contents = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); + Layer contents = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); // Create an edit mode button. (left of toolbar) Toolkit::PushButton editButton = Toolkit::PushButton::New(); - editButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE ); - editButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED ); - editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked); - editButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + editButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE); + editButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED); + editButton.ClickedSignal().Connect(this, &ItemViewExample::OnModeButtonClicked); + editButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a layout toggle button. (right of toolbar) mLayoutButton = Toolkit::PushButton::New(); - mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE ); - mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED ); - mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked); - mLayoutButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED); + mLayoutButton.ClickedSignal().Connect(this, &ItemViewExample::OnLayoutButtonClicked); + mLayoutButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a delete button (bottom right of screen) mDeleteButton = Toolkit::PushButton::New(); - mDeleteButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT); - mDeleteButton.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT); - mDeleteButton.SetProperty( Actor::Property::POSITION, Vector2( BUTTON_BORDER, BUTTON_BORDER )); - mDeleteButton.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D ); - mDeleteButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DELETE_IMAGE ); - mDeleteButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DELETE_IMAGE_SELECTED ); - mDeleteButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE ); - mDeleteButton.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width * 0.15f, windowSize.width * 0.15f ) ); - mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked); - mDeleteButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mDeleteButton.SetProperty( Actor::Property::VISIBLE, false ); - window.Add( mDeleteButton ); + mDeleteButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mDeleteButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mDeleteButton.SetProperty(Actor::Property::POSITION, Vector2(BUTTON_BORDER, BUTTON_BORDER)); + mDeleteButton.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + mDeleteButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DELETE_IMAGE); + mDeleteButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DELETE_IMAGE_SELECTED); + mDeleteButton.SetProperty(Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE); + mDeleteButton.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width * 0.15f, windowSize.width * 0.15f)); + mDeleteButton.ClickedSignal().Connect(this, &ItemViewExample::OnDeleteButtonClicked); + mDeleteButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mDeleteButton.SetProperty(Actor::Property::VISIBLE, false); + window.Add(mDeleteButton); // Create an insert button (bottom right of screen) mInsertButton = Toolkit::PushButton::New(); - mInsertButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT); - mInsertButton.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT); - mInsertButton.SetProperty( Actor::Property::POSITION, Vector2( BUTTON_BORDER, BUTTON_BORDER )); - mInsertButton.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D ); - mInsertButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, INSERT_IMAGE ); - mInsertButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, INSERT_IMAGE_SELECTED ); - mInsertButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE ); - mInsertButton.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width * 0.15f, windowSize.width * 0.15f ) ); - mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked); - mInsertButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mInsertButton.SetProperty( Actor::Property::VISIBLE, false ); - window.Add( mInsertButton ); + mInsertButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mInsertButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mInsertButton.SetProperty(Actor::Property::POSITION, Vector2(BUTTON_BORDER, BUTTON_BORDER)); + mInsertButton.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + mInsertButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, INSERT_IMAGE); + mInsertButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, INSERT_IMAGE_SELECTED); + mInsertButton.SetProperty(Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE); + mInsertButton.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width * 0.15f, windowSize.width * 0.15f)); + mInsertButton.ClickedSignal().Connect(this, &ItemViewExample::OnInsertButtonClicked); + mInsertButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mInsertButton.SetProperty(Actor::Property::VISIBLE, false); + window.Add(mInsertButton); // Create an replace button (bottom right of screen) mReplaceButton = Toolkit::PushButton::New(); - mReplaceButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT); - mReplaceButton.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT); - mReplaceButton.SetProperty( Actor::Property::POSITION, Vector2( BUTTON_BORDER, BUTTON_BORDER )); - mReplaceButton.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D ); - mReplaceButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE ); - mReplaceButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE_SELECTED ); - mReplaceButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE ); - mReplaceButton.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width * 0.15f, windowSize.width * 0.15f ) ); - mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked); - mReplaceButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mReplaceButton.SetProperty( Actor::Property::VISIBLE, false ); - window.Add( mReplaceButton ); + mReplaceButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mReplaceButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + mReplaceButton.SetProperty(Actor::Property::POSITION, Vector2(BUTTON_BORDER, BUTTON_BORDER)); + mReplaceButton.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + mReplaceButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE); + mReplaceButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE_SELECTED); + mReplaceButton.SetProperty(Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE); + mReplaceButton.SetProperty(Actor::Property::SIZE, Vector2(windowSize.width * 0.15f, windowSize.width * 0.15f)); + mReplaceButton.ClickedSignal().Connect(this, &ItemViewExample::OnReplaceButtonClicked); + mReplaceButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mReplaceButton.SetProperty(Actor::Property::VISIBLE, false); + window.Add(mReplaceButton); // Create the item view actor mItemView = ItemView::New(*this); - mItemView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mItemView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + mItemView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mItemView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); // Display item view on the window - window.Add( mItemView ); - window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); + window.Add(mItemView); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); // Create the layouts - mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL ); - mDepthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH ); - mGridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID ); + mSpiralLayout = DefaultItemLayout::New(DefaultItemLayout::SPIRAL); + mDepthLayout = DefaultItemLayout::New(DefaultItemLayout::DEPTH); + mGridLayout = DefaultItemLayout::New(DefaultItemLayout::GRID); // Add the layouts to item view mItemView.AddLayout(*mSpiralLayout); @@ -296,22 +294,22 @@ public: mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED); // Activate the spiral layout - SetLayout( mCurrentLayout ); - mItemView.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true ); - KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange ); + SetLayout(mCurrentLayout); + mItemView.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + KeyboardFocusManager::Get().PreFocusChangeSignal().Connect(this, &ItemViewExample::OnKeyboardPreFocusChange); // Set the title and icon to the current layout SetLayoutTitle(); SetLayoutImage(); mLongPressDetector = LongPressGestureDetector::New(); - mLongPressDetector.Attach( mItemView ); - mLongPressDetector.DetectedSignal().Connect( this, &ItemViewExample::OnLongPress ); + mLongPressDetector.Attach(mItemView); + mLongPressDetector.DetectedSignal().Connect(this, &ItemViewExample::OnLongPress); } - Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocus::Direction direction ) + Actor OnKeyboardPreFocusChange(Actor current, Actor proposed, Control::KeyboardFocus::Direction direction) { - if ( !current && !proposed ) + if(!current && !proposed) { return mItemView; } @@ -324,38 +322,38 @@ public: */ void ChangeLayout() { - Animation animation = Animation::New( mDurationSeconds ); - animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished ); - animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f ); + Animation animation = Animation::New(mDurationSeconds); + animation.FinishedSignal().Connect(this, &ItemViewExample::AnimationFinished); + animation.AnimateTo(Property(mItemView, Actor::Property::COLOR_ALPHA), 0.0f); animation.Play(); } - void AnimationFinished( Animation& ) + void AnimationFinished(Animation&) { - SetLayout( mCurrentLayout ); + SetLayout(mCurrentLayout); - Animation animation = Animation::New( mDurationSeconds ); - animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f ); + Animation animation = Animation::New(mDurationSeconds); + animation.AnimateTo(Property(mItemView, Actor::Property::COLOR_ALPHA), 1.0f); animation.Play(); } /** * Switch to a different item view layout */ - void SetLayout( int layoutId ) + void SetLayout(int layoutId) { Window window = mApplication.GetWindow(); - switch( mCurrentLayout ) + switch(mCurrentLayout) { case SPIRAL_LAYOUT: case DEPTH_LAYOUT: { - window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); break; } case GRID_LAYOUT: { - window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_UI ); + window.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI); break; } } @@ -370,11 +368,11 @@ public: // Set up the depth layout according to the new orientation if(Toolkit::IsVertical(mDepthLayout->GetOrientation())) { - mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( windowSize.width ) ); + mDepthLayout->SetItemSize(DepthLayoutItemSizeFunctionPortrait(windowSize.width)); } else { - mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( windowSize.height ) ); + mDepthLayout->SetItemSize(DepthLayoutItemSizeFunctionLandscape(windowSize.height)); } } @@ -382,10 +380,10 @@ public: mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT); // Activate the layout - mItemView.ActivateLayout( layoutId, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f ); + mItemView.ActivateLayout(layoutId, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f); } - bool OnLayoutButtonClicked( Toolkit::Button button ) + bool OnLayoutButtonClicked(Toolkit::Button button) { // Switch to the next layout mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount(); @@ -398,7 +396,7 @@ public: return true; } - bool OnModeButtonClicked( Toolkit::Button button ) + bool OnModeButtonClicked(Toolkit::Button button) { SwitchToNextMode(); @@ -407,7 +405,7 @@ public: void SwitchToNextMode() { - switch( mMode ) + switch(mMode) { case MODE_REMOVE: { @@ -473,12 +471,12 @@ public: mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { mTapDetector.Attach(mItemView.GetChildAt(i)); } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::RemoveOnTap); } void ExitRemoveMode() @@ -486,87 +484,87 @@ public: mTapDetector.Reset(); } - void RemoveOnTap( Actor actor, const TapGesture& tap ) + void RemoveOnTap(Actor actor, const TapGesture& tap) { - mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f ); + mItemView.RemoveItem(mItemView.GetItemId(actor), 0.5f); } void EnterRemoveManyMode() { SetTitle("Edit: Remove Many"); - mDeleteButton.SetProperty( Actor::Property::VISIBLE, true ); + mDeleteButton.SetProperty(Actor::Property::VISIBLE, true); mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - mTapDetector.Attach( child ); - box.SetProperty( Actor::Property::VISIBLE, true ); + mTapDetector.Attach(child); + box.SetProperty(Actor::Property::VISIBLE, true); } } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::SelectOnTap); } void ExitRemoveManyMode() { - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - box.SetProperty( Actor::Property::VISIBLE, false ); + box.SetProperty(Actor::Property::VISIBLE, false); - Actor tick = box.FindChildByName( "Tick" ); - if( tick ) + Actor tick = box.FindChildByName("Tick"); + if(tick) { - tick.SetProperty( Actor::Property::VISIBLE, false ); + tick.SetProperty(Actor::Property::VISIBLE, false); } } } mTapDetector.Reset(); - mDeleteButton.SetProperty( Actor::Property::VISIBLE, false ); + mDeleteButton.SetProperty(Actor::Property::VISIBLE, false); } - void SelectOnTap( Actor actor, const TapGesture& tap ) + void SelectOnTap(Actor actor, const TapGesture& tap) { - Actor tick = actor.FindChildByName( "Tick" ); - if( tick ) + Actor tick = actor.FindChildByName("Tick"); + if(tick) { - tick.SetProperty( Actor::Property::VISIBLE, !tick.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ); + tick.SetProperty(Actor::Property::VISIBLE, !tick.GetCurrentProperty(Actor::Property::VISIBLE)); } } - void OnLongPress( Actor actor, const LongPressGesture& gesture ) + void OnLongPress(Actor actor, const LongPressGesture& gesture) { - switch( gesture.GetState() ) + switch(gesture.GetState()) { case GestureState::STARTED: { const Size& size = mApplication.GetWindow().GetSize(); - ItemRange range( 0u, 0u ); - mItemView.GetItemsRange( range ); + ItemRange range(0u, 0u); + mItemView.GetItemsRange(range); - const unsigned int item = ( gesture.GetScreenPoint().y < 0.5f * size.height ) ? range.begin : range.end; - mItemView.ScrollToItem( item, SCROLL_TO_ITEM_ANIMATION_TIME ); + const unsigned int item = (gesture.GetScreenPoint().y < 0.5f * size.height) ? range.begin : range.end; + mItemView.ScrollToItem(item, SCROLL_TO_ITEM_ANIMATION_TIME); break; } case GestureState::FINISHED: { Property::Map attributes; - mItemView.DoAction( "stopScrolling", attributes ); + mItemView.DoAction("stopScrolling", attributes); break; } default: @@ -576,24 +574,24 @@ public: } } - bool OnDeleteButtonClicked( Toolkit::Button button ) + bool OnDeleteButtonClicked(Toolkit::Button button) { ItemIdContainer removeList; - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor tick = child.FindChildByName( "Tick" ); + Actor child = mItemView.GetChildAt(i); + Actor tick = child.FindChildByName("Tick"); - if( tick && tick.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ) + if(tick && tick.GetCurrentProperty(Actor::Property::VISIBLE)) { - removeList.push_back( mItemView.GetItemId(child) ); + removeList.push_back(mItemView.GetItemId(child)); } } - if( ! removeList.empty() ) + if(!removeList.empty()) { - mItemView.RemoveItems( removeList, 0.5f ); + mItemView.RemoveItems(removeList, 0.5f); } return true; @@ -605,12 +603,12 @@ public: mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - mTapDetector.Attach( mItemView.GetChildAt(i) ); + mTapDetector.Attach(mItemView.GetChildAt(i)); } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::InsertOnTap); } void ExitInsertMode() @@ -618,80 +616,80 @@ public: mTapDetector.Reset(); } - void InsertOnTap( Actor actor, const TapGesture& tap ) + void InsertOnTap(Actor actor, const TapGesture& tap) { - ItemId id = mItemView.GetItemId( actor ); + ItemId id = mItemView.GetItemId(actor); - Actor newActor = NewItem( rand() ); + Actor newActor = NewItem(rand()); - mItemView.InsertItem( Item(id,newActor), 0.5f ); + mItemView.InsertItem(Item(id, newActor), 0.5f); } void EnterInsertManyMode() { SetTitle("Edit: Insert Many"); - mInsertButton.SetProperty( Actor::Property::VISIBLE, true ); + mInsertButton.SetProperty(Actor::Property::VISIBLE, true); mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - mTapDetector.Attach( child ); - box.SetProperty( Actor::Property::VISIBLE, true ); + mTapDetector.Attach(child); + box.SetProperty(Actor::Property::VISIBLE, true); } } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::SelectOnTap); } void ExitInsertManyMode() { - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - box.SetProperty( Actor::Property::VISIBLE, false ); + box.SetProperty(Actor::Property::VISIBLE, false); - Actor tick = box.FindChildByName( "Tick" ); - if( tick ) + Actor tick = box.FindChildByName("Tick"); + if(tick) { - tick.SetProperty( Actor::Property::VISIBLE, false ); + tick.SetProperty(Actor::Property::VISIBLE, false); } } } mTapDetector.Reset(); - mInsertButton.SetProperty( Actor::Property::VISIBLE, false ); + mInsertButton.SetProperty(Actor::Property::VISIBLE, false); } - bool OnInsertButtonClicked( Toolkit::Button button ) + bool OnInsertButtonClicked(Toolkit::Button button) { ItemContainer insertList; - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor tick = child.FindChildByName( "Tick" ); + Actor child = mItemView.GetChildAt(i); + Actor tick = child.FindChildByName("Tick"); - if( tick && tick.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ) + if(tick && tick.GetCurrentProperty(Actor::Property::VISIBLE)) { - insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) ); + insertList.push_back(Item(mItemView.GetItemId(child), NewItem(rand()))); } } - if( ! insertList.empty() ) + if(!insertList.empty()) { - mItemView.InsertItems( insertList, 0.5f ); + mItemView.InsertItems(insertList, 0.5f); } return true; @@ -703,17 +701,17 @@ public: mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { mTapDetector.Attach(mItemView.GetChildAt(i)); } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::ReplaceOnTap); } - void ReplaceOnTap( Actor actor, const TapGesture& tap ) + void ReplaceOnTap(Actor actor, const TapGesture& tap) { - mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f ); + mItemView.ReplaceItem(Item(mItemView.GetItemId(actor), NewItem(rand())), 0.5f); } void ExitReplaceMode() @@ -725,67 +723,67 @@ public: { SetTitle("Edit: Replace Many"); - mReplaceButton.SetProperty( Actor::Property::VISIBLE, true ); + mReplaceButton.SetProperty(Actor::Property::VISIBLE, true); mTapDetector = TapGestureDetector::New(); - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - mTapDetector.Attach( child ); - box.SetProperty( Actor::Property::VISIBLE, true ); + mTapDetector.Attach(child); + box.SetProperty(Actor::Property::VISIBLE, true); } } - mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap ); + mTapDetector.DetectedSignal().Connect(this, &ItemViewExample::SelectOnTap); } void ExitReplaceManyMode() { - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor box = child.FindChildByName( "CheckBox" ); + Actor child = mItemView.GetChildAt(i); + Actor box = child.FindChildByName("CheckBox"); - if( box ) + if(box) { - box.SetProperty( Actor::Property::VISIBLE, false ); + box.SetProperty(Actor::Property::VISIBLE, false); - Actor tick = box.FindChildByName( "Tick" ); - if( tick ) + Actor tick = box.FindChildByName("Tick"); + if(tick) { - tick.SetProperty( Actor::Property::VISIBLE, false ); + tick.SetProperty(Actor::Property::VISIBLE, false); } } } mTapDetector.Reset(); - mReplaceButton.SetProperty( Actor::Property::VISIBLE, false ); + mReplaceButton.SetProperty(Actor::Property::VISIBLE, false); } - bool OnReplaceButtonClicked( Toolkit::Button button ) + bool OnReplaceButtonClicked(Toolkit::Button button) { ItemContainer replaceList; - for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + for(unsigned int i = 0u; i < mItemView.GetChildCount(); ++i) { - Actor child = mItemView.GetChildAt( i ); - Actor tick = child.FindChildByName( "Tick" ); + Actor child = mItemView.GetChildAt(i); + Actor tick = child.FindChildByName("Tick"); - if( tick && tick.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ) + if(tick && tick.GetCurrentProperty(Actor::Property::VISIBLE)) { - replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) ); + replaceList.push_back(Item(mItemView.GetItemId(child), NewItem(rand()))); } } - if( ! replaceList.empty() ) + if(!replaceList.empty()) { - mItemView.ReplaceItems( replaceList, 0.5f ); + mItemView.ReplaceItems(replaceList, 0.5f); } return true; @@ -793,22 +791,22 @@ public: void SetLayoutTitle() { - if( MODE_NORMAL == mMode ) + if(MODE_NORMAL == mMode) { std::stringstream ss(APPLICATION_TITLE); switch(mCurrentLayout) { - case SPIRAL_LAYOUT: - ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL; - break; - case GRID_LAYOUT: - ss << APPLICATION_TITLE << ": " << GRID_LABEL; - break; - case DEPTH_LAYOUT: - ss << APPLICATION_TITLE << ": " << DEPTH_LABEL; - break; - default: - break; + case SPIRAL_LAYOUT: + ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL; + break; + case GRID_LAYOUT: + ss << APPLICATION_TITLE << ": " << GRID_LABEL; + break; + case DEPTH_LAYOUT: + ss << APPLICATION_TITLE << ": " << DEPTH_LABEL; + break; + default: + break; } SetTitle(ss.str()); } @@ -816,28 +814,28 @@ public: void SetLayoutImage() { - if( mLayoutButton ) + if(mLayoutButton) { - switch( mCurrentLayout ) + switch(mCurrentLayout) { case SPIRAL_LAYOUT: { - mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE ); - mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED); break; } case GRID_LAYOUT: { - mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE ); - mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE_SELECTED ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE_SELECTED); break; } case DEPTH_LAYOUT: { - mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE ); - mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE_SELECTED ); + mLayoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE); + mLayoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE_SELECTED); break; } @@ -848,7 +846,6 @@ public: } public: // From ItemFactory - /** * Query the number of items available from the factory. * The maximum available item has an ID of GetNumberOfItems() - 1. @@ -867,81 +864,80 @@ public: // From ItemFactory { // Create an image view for this item Property::Map propertyMap; - propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); - propertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATHS[ itemId % NUM_IMAGES ] ); + propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + propertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATHS[itemId % NUM_IMAGES]); propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL); ImageView actor = ImageView::New(); - actor.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap ); - actor.SetProperty( Actor::Property::POSITION_Z, 0.0f ); - actor.SetProperty( Actor::Property::POSITION, INITIAL_OFFSCREEN_POSITION ); + actor.SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); + actor.SetProperty(Actor::Property::POSITION_Z, 0.0f); + actor.SetProperty(Actor::Property::POSITION, INITIAL_OFFSCREEN_POSITION); // Add a border image child actor ImageView borderActor = ImageView::New(); - borderActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - borderActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); - borderActor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) ); - borderActor.SetProperty( Actor::Property::COLOR_MODE, USE_PARENT_COLOR ); + borderActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + borderActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + borderActor.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS); + borderActor.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f)); + borderActor.SetProperty(Actor::Property::COLOR_MODE, USE_PARENT_COLOR); Property::Map borderProperty; - borderProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER ); - borderProperty.Insert( BorderVisual::Property::COLOR, Color::WHITE ); - borderProperty.Insert( BorderVisual::Property::SIZE, ITEM_BORDER_SIZE ); - borderProperty.Insert( BorderVisual::Property::ANTI_ALIASING, true ); - borderActor.SetProperty( ImageView::Property::IMAGE, borderProperty ); + borderProperty.Insert(Toolkit::Visual::Property::TYPE, Visual::BORDER); + borderProperty.Insert(BorderVisual::Property::COLOR, Color::WHITE); + borderProperty.Insert(BorderVisual::Property::SIZE, ITEM_BORDER_SIZE); + borderProperty.Insert(BorderVisual::Property::ANTI_ALIASING, true); + borderActor.SetProperty(ImageView::Property::IMAGE, borderProperty); actor.Add(borderActor); - actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true ); + actor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); Vector3 spiralItemSize; Vector2 windowSize = mApplication.GetWindow().GetSize(); - static_cast(*mSpiralLayout).GetItemSize( 0u, Vector3( windowSize ), spiralItemSize ); + static_cast(*mSpiralLayout).GetItemSize(0u, Vector3(windowSize), spiralItemSize); // Add a checkbox child actor; invisible until edit-mode is enabled ImageView checkbox = ImageView::New(); - checkbox.SetProperty( Dali::Actor::Property::NAME, "CheckBox" ); - checkbox.SetProperty( Actor::Property::COLOR_MODE, USE_PARENT_COLOR ); - checkbox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - checkbox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); - checkbox.SetProperty( Actor::Property::SIZE, Vector2( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ) ); - checkbox.SetProperty( Actor::Property::POSITION, Vector2( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH )); - checkbox.SetProperty( Actor::Property::POSITION_Z, 0.1f ); + checkbox.SetProperty(Dali::Actor::Property::NAME, "CheckBox"); + checkbox.SetProperty(Actor::Property::COLOR_MODE, USE_PARENT_COLOR); + checkbox.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + checkbox.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + checkbox.SetProperty(Actor::Property::SIZE, Vector2(spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f)); + checkbox.SetProperty(Actor::Property::POSITION, Vector2(-SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH)); + checkbox.SetProperty(Actor::Property::POSITION_Z, 0.1f); Property::Map solidColorProperty; - solidColorProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::COLOR ); - solidColorProperty.Insert( ColorVisual::Property::MIX_COLOR, Vector4(0.f, 0.f, 0.f, 0.6f) ); - checkbox.SetProperty( ImageView::Property::IMAGE, solidColorProperty ); + solidColorProperty.Insert(Toolkit::Visual::Property::TYPE, Visual::COLOR); + solidColorProperty.Insert(ColorVisual::Property::MIX_COLOR, Vector4(0.f, 0.f, 0.f, 0.6f)); + checkbox.SetProperty(ImageView::Property::IMAGE, solidColorProperty); - if( MODE_REMOVE_MANY != mMode && - MODE_INSERT_MANY != mMode && - MODE_REPLACE_MANY != mMode ) + if(MODE_REMOVE_MANY != mMode && + MODE_INSERT_MANY != mMode && + MODE_REPLACE_MANY != mMode) { - checkbox.SetProperty( Actor::Property::VISIBLE, false ); + checkbox.SetProperty(Actor::Property::VISIBLE, false); } - borderActor.Add( checkbox ); - - ImageView tick = ImageView::New( SELECTED_IMAGE ); - tick.SetProperty( Dali::Actor::Property::NAME, "Tick" ); - tick.SetProperty( Actor::Property::COLOR_MODE, USE_PARENT_COLOR ); - tick.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - tick.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); - tick.SetProperty( Actor::Property::SIZE, Vector2( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ) ); - tick.SetProperty( Actor::Property::POSITION_Z, 0.2f ); - tick.SetProperty( Actor::Property::VISIBLE, false ); - checkbox.Add( tick ); + borderActor.Add(checkbox); + + ImageView tick = ImageView::New(SELECTED_IMAGE); + tick.SetProperty(Dali::Actor::Property::NAME, "Tick"); + tick.SetProperty(Actor::Property::COLOR_MODE, USE_PARENT_COLOR); + tick.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + tick.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + tick.SetProperty(Actor::Property::SIZE, Vector2(spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f)); + tick.SetProperty(Actor::Property::POSITION_Z, 0.2f); + tick.SetProperty(Actor::Property::VISIBLE, false); + checkbox.Add(tick); // Connect new items for various editing modes - if( mTapDetector ) + if(mTapDetector) { - mTapDetector.Attach( actor ); + mTapDetector.Attach(actor); } return actor; } private: - /** * Sets/Updates the title of the View * @param[in] title The new title for the view. @@ -950,12 +946,12 @@ private: { if(!mTitleActor) { - mTitleActor = DemoHelper::CreateToolBarLabel( "" ); + mTitleActor = DemoHelper::CreateToolBarLabel(""); // Add title to the tool bar. - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER ); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER); } - mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, title); } /** @@ -965,7 +961,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -973,25 +969,24 @@ private: } private: - Application& mApplication; - Mode mMode; + Mode mMode; Toolkit::Control mView; - unsigned int mOrientation; + unsigned int mOrientation; Toolkit::ToolBar mToolBar; - TextLabel mTitleActor; ///< The Toolbar's Title. + TextLabel mTitleActor; ///< The Toolbar's Title. - ItemView mItemView; + ItemView mItemView; unsigned int mCurrentLayout; - float mDurationSeconds; + float mDurationSeconds; ItemLayoutPtr mSpiralLayout; ItemLayoutPtr mDepthLayout; ItemLayoutPtr mGridLayout; - TapGestureDetector mTapDetector; + TapGestureDetector mTapDetector; Toolkit::PushButton mLayoutButton; Toolkit::PushButton mDeleteButton; Toolkit::PushButton mInsertButton; @@ -1000,9 +995,9 @@ private: LongPressGestureDetector mLongPressDetector; }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ItemViewExample test(app); app.MainLoop(); return 0; diff --git a/examples/line-mesh/line-mesh-example.cpp b/examples/line-mesh/line-mesh-example.cpp index 3d1d2db..3ef3d51 100644 --- a/examples/line-mesh/line-mesh-example.cpp +++ b/examples/line-mesh/line-mesh-example.cpp @@ -16,9 +16,9 @@ */ // EXTERNAL INCLUDES -#include #include #include +#include // INTERNAL INCLUDES #include "shared/view.h" @@ -29,47 +29,42 @@ using namespace Dali; namespace { - -#define MAKE_SHADER(A)#A +#define MAKE_SHADER(A) #A const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aPosition1; -attribute mediump vec2 aPosition2; -attribute lowp vec3 aColor; -uniform mediump mat4 uMvpMatrix; -uniform mediump vec3 uSize; -uniform mediump float uMorphAmount; - -varying lowp vec3 vColor; - -void main() -{ - mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); - mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); - vColor = aColor; - vertexPosition.xyz *= uSize; - vertexPosition = uMvpMatrix * vertexPosition; - gl_Position = vertexPosition; -} -); + attribute mediump vec2 aPosition1; + attribute mediump vec2 aPosition2; + attribute lowp vec3 aColor; + uniform mediump mat4 uMvpMatrix; + uniform mediump vec3 uSize; + uniform mediump float uMorphAmount; + + varying lowp vec3 vColor; + + void main() { + mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); + mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); + vColor = aColor; + vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + gl_Position = vertexPosition; + }); const char* FRAGMENT_SHADER = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform sampler2D sTexture; + uniform lowp vec4 uColor; + uniform sampler2D sTexture; -varying lowp vec3 vColor; + varying lowp vec3 vColor; -void main() -{ - gl_FragColor = uColor * vec4( vColor, 1.0 ); -} -); + void main() { + gl_FragColor = uColor * vec4(vColor, 1.0); + }); -const unsigned short INDEX_LINES[] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 }; -const unsigned short INDEX_LOOP[] = { 0, 1, 2, 3, 4 }; -const unsigned short INDEX_STRIP[] = { 0, 1, 2, 3, 4, 0 }; -const unsigned short* INDICES[3] = { &INDEX_LINES[0], &INDEX_LOOP[0], &INDEX_STRIP[0] }; -const unsigned int INDICES_SIZE[3] = { sizeof(INDEX_LINES)/sizeof(INDEX_LINES[0]), sizeof(INDEX_LOOP)/sizeof(INDEX_LOOP[0]), sizeof(INDEX_STRIP)/sizeof(INDEX_STRIP[0])}; +const unsigned short INDEX_LINES[] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 0}; +const unsigned short INDEX_LOOP[] = {0, 1, 2, 3, 4}; +const unsigned short INDEX_STRIP[] = {0, 1, 2, 3, 4, 0}; +const unsigned short* INDICES[3] = {&INDEX_LINES[0], &INDEX_LOOP[0], &INDEX_STRIP[0]}; +const unsigned int INDICES_SIZE[3] = {sizeof(INDEX_LINES) / sizeof(INDEX_LINES[0]), sizeof(INDEX_LOOP) / sizeof(INDEX_LOOP[0]), sizeof(INDEX_STRIP) / sizeof(INDEX_STRIP[0])}; Geometry CreateGeometry() { @@ -84,26 +79,25 @@ Geometry CreateGeometry() // Create new geometry object Vertex pentagonVertexData[5] = { - { Vector2( 0.0f, 1.00f), Vector2( 0.0f, -1.00f), Vector3( 1.0f, 1.0f, 1.0f ) }, // 0 - { Vector2( -0.95f, 0.31f), Vector2( 0.59f, 0.81f), Vector3( 1.0f, 0.0f, 0.0f ) }, // 1 - { Vector2( -0.59f, -0.81f), Vector2( -0.95f, -0.31f), Vector3( 0.0f, 1.0f, 0.0f ) }, // 2 - { Vector2( 0.59f, -0.81f), Vector2( 0.95f, -0.31f), Vector3( 0.0f, 0.0f, 1.0f ) }, // 3 - { Vector2( 0.95f, 0.31f), Vector2( -0.59f, 0.81f), Vector3( 1.0f, 1.0f, 0.0f ) }, // 4 + {Vector2(0.0f, 1.00f), Vector2(0.0f, -1.00f), Vector3(1.0f, 1.0f, 1.0f)}, // 0 + {Vector2(-0.95f, 0.31f), Vector2(0.59f, 0.81f), Vector3(1.0f, 0.0f, 0.0f)}, // 1 + {Vector2(-0.59f, -0.81f), Vector2(-0.95f, -0.31f), Vector3(0.0f, 1.0f, 0.0f)}, // 2 + {Vector2(0.59f, -0.81f), Vector2(0.95f, -0.31f), Vector3(0.0f, 0.0f, 1.0f)}, // 3 + {Vector2(0.95f, 0.31f), Vector2(-0.59f, 0.81f), Vector3(1.0f, 1.0f, 0.0f)}, // 4 }; Property::Map pentagonVertexFormat; pentagonVertexFormat["aPosition1"] = Property::VECTOR2; pentagonVertexFormat["aPosition2"] = Property::VECTOR2; - pentagonVertexFormat["aColor"] = Property::VECTOR3; - VertexBuffer pentagonVertices = VertexBuffer::New( pentagonVertexFormat ); + pentagonVertexFormat["aColor"] = Property::VECTOR3; + VertexBuffer pentagonVertices = VertexBuffer::New(pentagonVertexFormat); pentagonVertices.SetData(pentagonVertexData, 5); - // Create the geometry object Geometry pentagonGeometry = Geometry::New(); - pentagonGeometry.AddVertexBuffer( pentagonVertices ); - pentagonGeometry.SetIndexBuffer( INDICES[0], INDICES_SIZE[0] ); - pentagonGeometry.SetType( Geometry::LINES ); + pentagonGeometry.AddVertexBuffer(pentagonVertices); + pentagonGeometry.SetIndexBuffer(INDICES[0], INDICES_SIZE[0]); + pentagonGeometry.SetType(Geometry::LINES); return pentagonGeometry; } @@ -114,13 +108,12 @@ Geometry CreateGeometry() class ExampleController : public ConnectionTracker { public: - /** * The example controller constructor. * @param[in] application The application instance */ - ExampleController( Application& application ) - : mApplication( application ), + ExampleController(Application& application) + : mApplication(application), mWindowSize(), mShader(), mGeometry(), @@ -130,12 +123,12 @@ public: mMinusButton(), mPlusButton(), mIndicesCountLabel(), - mPrimitiveType( Geometry::LINES ), - mCurrentIndexCount( 0 ), - mMaxIndexCount( 0 ) + mPrimitiveType(Geometry::LINES), + mCurrentIndexCount(0), + mMaxIndexCount(0) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ExampleController::Create ); + mApplication.InitSignal().Connect(this, &ExampleController::Create); } /** @@ -150,14 +143,14 @@ public: * Invoked upon creation of application * @param[in] application The application instance */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); // initial settings - mPrimitiveType = Geometry::LINES; + mPrimitiveType = Geometry::LINES; mCurrentIndexCount = 10; - mMaxIndexCount = 10; + mMaxIndexCount = 10; CreateRadioButtons(); @@ -178,38 +171,38 @@ public: Window window = mApplication.GetWindow(); // destroy mesh actor and its resources if already exists - if( mMeshActor ) + if(mMeshActor) { - window.Remove( mMeshActor ); + window.Remove(mMeshActor); mMeshActor.Reset(); } - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); mGeometry = CreateGeometry(); - mRenderer = Renderer::New( mGeometry, mShader ); + mRenderer = Renderer::New(mGeometry, mShader); - mRenderer.SetIndexRange( 0, 10 ); // lines + mRenderer.SetIndexRange(0, 10); // lines mPrimitiveType = Geometry::LINES; mMeshActor = Actor::New(); - mMeshActor.AddRenderer( mRenderer ); - mMeshActor.SetProperty( Actor::Property::SIZE, Vector2(200, 200) ); - mMeshActor.SetProperty( DevelActor::Property::UPDATE_SIZE_HINT, Vector2(400, 400) ); + mMeshActor.AddRenderer(mRenderer); + mMeshActor.SetProperty(Actor::Property::SIZE, Vector2(200, 200)); + mMeshActor.SetProperty(DevelActor::Property::UPDATE_SIZE_HINT, Vector2(400, 400)); - Property::Index morphAmountIndex = mMeshActor.RegisterProperty( "uMorphAmount", 0.0f ); + Property::Index morphAmountIndex = mMeshActor.RegisterProperty("uMorphAmount", 0.0f); - mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, 0 ); + mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 0); - mMeshActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mMeshActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - window.Add( mMeshActor ); + mMeshActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mMeshActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + window.Add(mMeshActor); - Animation animation = Animation::New(5); + Animation animation = Animation::New(5); KeyFrames keyFrames = KeyFrames::New(); keyFrames.Add(0.0f, 0.0f); keyFrames.Add(1.0f, 1.0f); - animation.AnimateBetween( Property( mMeshActor, morphAmountIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); + animation.AnimateBetween(Property(mMeshActor, morphAmountIndex), keyFrames, AlphaFunction(AlphaFunction::SIN)); animation.SetLooping(true); animation.Play(); } @@ -221,77 +214,75 @@ public: { Window window = mApplication.GetWindow(); - Toolkit::TableView modeSelectTableView = Toolkit::TableView::New( 4, 1 ); - modeSelectTableView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - modeSelectTableView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - modeSelectTableView.SetFitHeight( 0 ); - modeSelectTableView.SetFitHeight( 1 ); - modeSelectTableView.SetFitHeight( 2 ); - modeSelectTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) ); - modeSelectTableView.SetProperty( Actor::Property::SCALE, Vector3( 0.8f, 0.8f, 0.8f )); + Toolkit::TableView modeSelectTableView = Toolkit::TableView::New(4, 1); + modeSelectTableView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + modeSelectTableView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + modeSelectTableView.SetFitHeight(0); + modeSelectTableView.SetFitHeight(1); + modeSelectTableView.SetFitHeight(2); + modeSelectTableView.SetCellPadding(Vector2(6.0f, 0.0f)); + modeSelectTableView.SetProperty(Actor::Property::SCALE, Vector3(0.8f, 0.8f, 0.8f)); const char* labels[] = - { - "LINES", - "LINE_LOOP", - "LINE_STRIP" - }; + { + "LINES", + "LINE_LOOP", + "LINE_STRIP"}; - for( int i = 0; i < 3; ++i ) + for(int i = 0; i < 3; ++i) { Dali::Toolkit::RadioButton radio = Dali::Toolkit::RadioButton::New(); - radio.SetProperty( Toolkit::Button::Property::LABEL, - Property::Map() - .Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) - .Add( Toolkit::TextVisual::Property::TEXT, labels[i] ) - .Add( Toolkit::TextVisual::Property::TEXT_COLOR, Vector4( 0.8f, 0.8f, 0.8f, 1.0f ) ) - ); - - radio.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - radio.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - radio.SetProperty( Toolkit::Button::Property::SELECTED, i == 0 ); - radio.PressedSignal().Connect( this, &ExampleController::OnButtonPressed ); + radio.SetProperty(Toolkit::Button::Property::LABEL, + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT) + .Add(Toolkit::TextVisual::Property::TEXT, labels[i]) + .Add(Toolkit::TextVisual::Property::TEXT_COLOR, Vector4(0.8f, 0.8f, 0.8f, 1.0f))); + + radio.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + radio.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + radio.SetProperty(Toolkit::Button::Property::SELECTED, i == 0); + radio.PressedSignal().Connect(this, &ExampleController::OnButtonPressed); mButtons[i] = radio; - modeSelectTableView.AddChild( radio, Toolkit::TableView::CellPosition( i, 0 ) ); + modeSelectTableView.AddChild(radio, Toolkit::TableView::CellPosition(i, 0)); } - Toolkit::TableView elementCountTableView = Toolkit::TableView::New( 1, 3 ); - elementCountTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) ); - elementCountTableView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); - elementCountTableView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); - elementCountTableView.SetFitHeight( 0 ); - elementCountTableView.SetFitWidth( 0 ); - elementCountTableView.SetFitWidth( 1 ); - elementCountTableView.SetFitWidth( 2 ); + Toolkit::TableView elementCountTableView = Toolkit::TableView::New(1, 3); + elementCountTableView.SetCellPadding(Vector2(6.0f, 0.0f)); + elementCountTableView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + elementCountTableView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT); + elementCountTableView.SetFitHeight(0); + elementCountTableView.SetFitWidth(0); + elementCountTableView.SetFitWidth(1); + elementCountTableView.SetFitWidth(2); mMinusButton = Toolkit::PushButton::New(); - mMinusButton.SetProperty( Toolkit::Button::Property::LABEL, "<<" ); - mMinusButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mMinusButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); + mMinusButton.SetProperty(Toolkit::Button::Property::LABEL, "<<"); + mMinusButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mMinusButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); Toolkit::PushButton mPlusButton = Toolkit::PushButton::New(); - mPlusButton.SetProperty( Toolkit::Button::Property::LABEL, ">>" ); - mPlusButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mPlusButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_RIGHT ); + mPlusButton.SetProperty(Toolkit::Button::Property::LABEL, ">>"); + mPlusButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mPlusButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_RIGHT); - mMinusButton.ClickedSignal().Connect( this, &ExampleController::OnButtonClicked ); - mPlusButton.ClickedSignal().Connect( this, &ExampleController::OnButtonClicked ); + mMinusButton.ClickedSignal().Connect(this, &ExampleController::OnButtonClicked); + mPlusButton.ClickedSignal().Connect(this, &ExampleController::OnButtonClicked); mIndicesCountLabel = Toolkit::TextLabel::New(); - mIndicesCountLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mIndicesCountLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mIndicesCountLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mIndicesCountLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); std::stringstream str; str << mCurrentIndexCount; - mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, str.str() ); - mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0, 1.0, 1.0, 1.0 ) ); - mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM"); - mIndicesCountLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); - mIndicesCountLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + mIndicesCountLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, str.str()); + mIndicesCountLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Vector4(1.0, 1.0, 1.0, 1.0)); + mIndicesCountLabel.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM"); + mIndicesCountLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH); + mIndicesCountLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); - elementCountTableView.AddChild( mMinusButton, Toolkit::TableView::CellPosition( 0, 0 ) ); - elementCountTableView.AddChild( mIndicesCountLabel, Toolkit::TableView::CellPosition( 0, 1 ) ); - elementCountTableView.AddChild( mPlusButton, Toolkit::TableView::CellPosition( 0, 2 ) ); + elementCountTableView.AddChild(mMinusButton, Toolkit::TableView::CellPosition(0, 0)); + elementCountTableView.AddChild(mIndicesCountLabel, Toolkit::TableView::CellPosition(0, 1)); + elementCountTableView.AddChild(mPlusButton, Toolkit::TableView::CellPosition(0, 2)); window.Add(modeSelectTableView); window.Add(elementCountTableView); @@ -301,7 +292,7 @@ public: * Invoked whenever the quit button is clicked * @param[in] button the quit button */ - bool OnQuitButtonClicked( Toolkit::Button button ) + bool OnQuitButtonClicked(Toolkit::Button button) { // quit the application mApplication.Quit(); @@ -312,89 +303,88 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } } } - bool OnButtonPressed( Toolkit::Button button ) + bool OnButtonPressed(Toolkit::Button button) { int indicesArray; - if( button == mButtons[0] ) + if(button == mButtons[0]) { mCurrentIndexCount = 10; - mMaxIndexCount = 10; - mPrimitiveType = Geometry::LINES; - indicesArray = 0; + mMaxIndexCount = 10; + mPrimitiveType = Geometry::LINES; + indicesArray = 0; } - else if( button == mButtons[1] ) + else if(button == mButtons[1]) { mCurrentIndexCount = 5; - mMaxIndexCount = 5; - mPrimitiveType = Geometry::LINE_LOOP; - indicesArray = 1; + mMaxIndexCount = 5; + mPrimitiveType = Geometry::LINE_LOOP; + indicesArray = 1; } else { mCurrentIndexCount = 6; - mMaxIndexCount = 6; - mPrimitiveType = Geometry::LINE_STRIP; - indicesArray = 2; + mMaxIndexCount = 6; + mPrimitiveType = Geometry::LINE_STRIP; + indicesArray = 2; } std::stringstream str; str << mCurrentIndexCount; - mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, str.str() ); - mGeometry.SetType( mPrimitiveType ); - mGeometry.SetIndexBuffer( INDICES[ indicesArray ], INDICES_SIZE[ indicesArray ] ); - mRenderer.SetIndexRange( 0, mCurrentIndexCount ); + mIndicesCountLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, str.str()); + mGeometry.SetType(mPrimitiveType); + mGeometry.SetIndexBuffer(INDICES[indicesArray], INDICES_SIZE[indicesArray]); + mRenderer.SetIndexRange(0, mCurrentIndexCount); return true; } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { - if( button == mMinusButton ) + if(button == mMinusButton) { - if (--mCurrentIndexCount < 2 ) + if(--mCurrentIndexCount < 2) mCurrentIndexCount = 2; } else { - if (++mCurrentIndexCount > mMaxIndexCount ) + if(++mCurrentIndexCount > mMaxIndexCount) mCurrentIndexCount = mMaxIndexCount; } std::stringstream str; str << mCurrentIndexCount; - mIndicesCountLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, str.str() ); - mRenderer.SetIndexRange( 0, mCurrentIndexCount ); + mIndicesCountLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, str.str()); + mRenderer.SetIndexRange(0, mCurrentIndexCount); return true; } private: - - Application& mApplication; ///< Application instance - Vector3 mWindowSize; ///< The size of the window - - Shader mShader; - Geometry mGeometry; - Renderer mRenderer; - Actor mMeshActor; - Toolkit::RadioButton mButtons[3]; - Toolkit::PushButton mMinusButton; - Toolkit::PushButton mPlusButton; - Toolkit::TextLabel mIndicesCountLabel; - Geometry::Type mPrimitiveType; - int mCurrentIndexCount; - int mMaxIndexCount; + Application& mApplication; ///< Application instance + Vector3 mWindowSize; ///< The size of the window + + Shader mShader; + Geometry mGeometry; + Renderer mRenderer; + Actor mMeshActor; + Toolkit::RadioButton mButtons[3]; + Toolkit::PushButton mMinusButton; + Toolkit::PushButton mPlusButton; + Toolkit::TextLabel mIndicesCountLabel; + Geometry::Type mPrimitiveType; + int mCurrentIndexCount; + int mMaxIndexCount; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ExampleController test( application ); + Application application = Application::New(&argc, &argv); + ExampleController test(application); application.MainLoop(); return 0; } diff --git a/examples/magnifier/magnifier-example.cpp b/examples/magnifier/magnifier-example.cpp index eadf675..7802769 100644 --- a/examples/magnifier/magnifier-example.cpp +++ b/examples/magnifier/magnifier-example.cpp @@ -26,16 +26,16 @@ using namespace Dali; namespace { -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-magnifier.jpg" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "Magnifier Example" ); -const Vector3 MAGNIFIER_SIZE(0.25f, 0.25f, 0.0f); ///< Magnifier sides should be 25% of the width of the window -const float ANIMATION_DURATION(60.0f); ///< Run animation for a minute before repeating. -const float MAGNIFIER_DISPLAY_DURATION(0.125f); ///< Duration in seconds for show/hide manual magnifier animation +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-magnifier.jpg"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("Magnifier Example"); +const Vector3 MAGNIFIER_SIZE(0.25f, 0.25f, 0.0f); ///< Magnifier sides should be 25% of the width of the window +const float ANIMATION_DURATION(60.0f); ///< Run animation for a minute before repeating. +const float MAGNIFIER_DISPLAY_DURATION(0.125f); ///< Duration in seconds for show/hide manual magnifier animation -const float MAGNIFICATION_FACTOR(2.0f); ///< Amount to magnify by. -const float MAGNIFIER_INDENT(10.0f); ///< Indentation around edge of window to define where magnifiers may move. -const float FINGER_RADIUS_INCHES(0.25f); ///< Average finger radius in inches from the center of index finger to edge. +const float MAGNIFICATION_FACTOR(2.0f); ///< Amount to magnify by. +const float MAGNIFIER_INDENT(10.0f); ///< Indentation around edge of window to define where magnifiers may move. +const float FINGER_RADIUS_INCHES(0.25f); ///< Average finger radius in inches from the center of index finger to edge. /** * MagnifierPathConstraint @@ -51,26 +51,26 @@ struct MagnifierPathConstraint * within window bounds. */ MagnifierPathConstraint(const Vector3& windowSize, - Vector3 offset = Vector3::ZERO) + Vector3 offset = Vector3::ZERO) : mWindowSize(windowSize), mOffset(offset) { } - void operator()( Vector3& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs) { - float time = inputs[1]->GetFloat(); + float time = inputs[1]->GetFloat(); const Vector3& size = inputs[0]->GetVector3(); current = mOffset; - Vector3 range( mWindowSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f ); + Vector3 range(mWindowSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f); current.x += 0.5f * sinf(time * 0.471f) * range.width; current.y += 0.5f * sinf(time * 0.8739f) * range.height; } - Vector3 mWindowSize; ///< Keep track of the window size for determining path within window bounds - Vector3 mOffset; ///< Amount to offset magnifier path + Vector3 mWindowSize; ///< Keep track of the window size for determining path within window bounds + Vector3 mOffset; ///< Amount to offset magnifier path }; /** @@ -99,11 +99,11 @@ struct ConfinementConstraint { } - void operator()( Vector3& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs) { - const Vector3& size = inputs[0]->GetVector3(); - const Vector3 origin = inputs[1]->GetVector3(); - const Vector3& anchor = inputs[2]->GetVector3(); + const Vector3& size = inputs[0]->GetVector3(); + const Vector3 origin = inputs[1]->GetVector3(); + const Vector3& anchor = inputs[2]->GetVector3(); const Vector3& referenceSize = inputs[3]->GetVector3(); Vector3 offset(mOffsetOrigin * referenceSize); @@ -150,34 +150,33 @@ struct ConfinementConstraint current.y -= std::max(corner.y, 0.0f); } - Vector3 mOffsetOrigin; ///< Manual Parent Offset Origin. - Vector3 mMinIndent; ///< Top-Left Margin - Vector3 mMaxIndent; ///< Bottom-Right Margin. - bool mFlipHorizontal; ///< Whether to flip actor's position if exceeds horizontal screen bounds - bool mFlipVertical; ///< Whether to flip actor's position if exceeds vertical screen bounds + Vector3 mOffsetOrigin; ///< Manual Parent Offset Origin. + Vector3 mMinIndent; ///< Top-Left Margin + Vector3 mMaxIndent; ///< Bottom-Right Margin. + bool mFlipHorizontal; ///< Whether to flip actor's position if exceeds horizontal screen bounds + bool mFlipVertical; ///< Whether to flip actor's position if exceeds vertical screen bounds }; -} +} // namespace // This example shows how to use the Magnifier component. // class ExampleController : public ConnectionTracker { public: - /** * The example controller constructor. * @param[in] application The application instance */ - ExampleController( Application& application ) - : mApplication( application ), + ExampleController(Application& application) + : mApplication(application), mView(), mAnimationTime(0.0f), - mAnimationTimeProperty( Property::INVALID_INDEX ), + mAnimationTimeProperty(Property::INVALID_INDEX), mMagnifierShown(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ExampleController::Create ); + mApplication.InitSignal().Connect(this, &ExampleController::Create); } /** @@ -192,7 +191,7 @@ public: * Invoked upon creation of application * @param[in] application The application instance */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); @@ -203,59 +202,59 @@ public: // Creates a default view with a default tool bar. // The view is added to the window. Toolkit::ToolBar toolBar; - mContent = DemoHelper::CreateView( application, - mView, - toolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContent = DemoHelper::CreateView(application, + mView, + toolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + APPLICATION_TITLE); - mContent.SetProperty( Actor::Property::LEAVE_REQUIRED,true); - mContent.TouchedSignal().Connect( this, &ExampleController::OnTouched ); + mContent.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mContent.TouchedSignal().Connect(this, &ExampleController::OnTouched); // Create magnifier (controlled by human touch) Layer overlay = Layer::New(); - overlay.SetProperty( Actor::Property::SENSITIVE,false); - overlay.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - overlay.SetProperty( Actor::Property::SIZE, mWindowSize); + overlay.SetProperty(Actor::Property::SENSITIVE, false); + overlay.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + overlay.SetProperty(Actor::Property::SIZE, mWindowSize); window.Add(overlay); mMagnifier = Toolkit::Magnifier::New(); - mMagnifier.SetSourceActor( mView ); - mMagnifier.SetProperty( Actor::Property::SIZE, MAGNIFIER_SIZE * mWindowSize.width ); // Size of magnifier is in relation to window width - mMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR ); - mMagnifier.SetProperty( Actor::Property::SCALE,Vector3::ZERO); - overlay.Add( mMagnifier ); + mMagnifier.SetSourceActor(mView); + mMagnifier.SetProperty(Actor::Property::SIZE, MAGNIFIER_SIZE * mWindowSize.width); // Size of magnifier is in relation to window width + mMagnifier.SetProperty(Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR); + mMagnifier.SetProperty(Actor::Property::SCALE, Vector3::ZERO); + overlay.Add(mMagnifier); // Apply constraint to animate the position of the magnifier. - Constraint constraint = Constraint::New( mMagnifier, Actor::Property::POSITION, ConfinementConstraint(Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT) ); - constraint.AddSource( LocalSource(Actor::Property::SIZE) ); - constraint.AddSource( LocalSource(Actor::Property::PARENT_ORIGIN) ); - constraint.AddSource( LocalSource(Actor::Property::ANCHOR_POINT) ); - constraint.AddSource( ParentSource(Actor::Property::SIZE) ); + Constraint constraint = Constraint::New(mMagnifier, Actor::Property::POSITION, ConfinementConstraint(Vector3(0.5f, 0.5f, 0.0f), Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT)); + constraint.AddSource(LocalSource(Actor::Property::SIZE)); + constraint.AddSource(LocalSource(Actor::Property::PARENT_ORIGIN)); + constraint.AddSource(LocalSource(Actor::Property::ANCHOR_POINT)); + constraint.AddSource(ParentSource(Actor::Property::SIZE)); constraint.SetRemoveAction(Constraint::DISCARD); constraint.Apply(); // Create bouncing magnifier automatically bounces around screen. mBouncingMagnifier = Toolkit::Magnifier::New(); - mBouncingMagnifier.SetSourceActor( mView ); - mBouncingMagnifier.SetProperty( Actor::Property::SIZE, MAGNIFIER_SIZE * mWindowSize.width ); // Size of magnifier is in relation to window width - mBouncingMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR ); - overlay.Add( mBouncingMagnifier ); + mBouncingMagnifier.SetSourceActor(mView); + mBouncingMagnifier.SetProperty(Actor::Property::SIZE, MAGNIFIER_SIZE * mWindowSize.width); // Size of magnifier is in relation to window width + mBouncingMagnifier.SetProperty(Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR); + overlay.Add(mBouncingMagnifier); - mAnimationTimeProperty = mBouncingMagnifier.RegisterProperty("animationTime", 0.0f); + mAnimationTimeProperty = mBouncingMagnifier.RegisterProperty("animationTime", 0.0f); ContinueAnimation(); // Apply constraint to animate the position of the magnifier. - constraint = Constraint::New( mBouncingMagnifier, Actor::Property::POSITION, MagnifierPathConstraint(mWindowSize, mWindowSize * 0.5f) ); - constraint.AddSource( LocalSource(Actor::Property::SIZE) ); - constraint.AddSource( LocalSource(mAnimationTimeProperty) ); + constraint = Constraint::New(mBouncingMagnifier, Actor::Property::POSITION, MagnifierPathConstraint(mWindowSize, mWindowSize * 0.5f)); + constraint.AddSource(LocalSource(Actor::Property::SIZE)); + constraint.AddSource(LocalSource(mAnimationTimeProperty)); constraint.Apply(); // Apply constraint to animate the source of the magnifier. - constraint = Constraint::New( mBouncingMagnifier, Toolkit::Magnifier::Property::SOURCE_POSITION, MagnifierPathConstraint(mWindowSize) ); - constraint.AddSource( LocalSource(Actor::Property::SIZE) ); - constraint.AddSource( LocalSource(mAnimationTimeProperty) ); + constraint = Constraint::New(mBouncingMagnifier, Toolkit::Magnifier::Property::SOURCE_POSITION, MagnifierPathConstraint(mWindowSize)); + constraint.AddSource(LocalSource(Actor::Property::SIZE)); + constraint.AddSource(LocalSource(mAnimationTimeProperty)); constraint.Apply(); } @@ -263,7 +262,7 @@ public: * Invoked whenever the animation finishes (every 60 seconds) * @param[in] animation The animation */ - void OnAnimationFinished( Animation& animation ) + void OnAnimationFinished(Animation& animation) { animation.FinishedSignal().Disconnect(this, &ExampleController::OnAnimationFinished); animation.Clear(); @@ -277,7 +276,7 @@ public: { Animation animation = Animation::New(ANIMATION_DURATION); mAnimationTime += ANIMATION_DURATION; - animation.AnimateTo( Property(mBouncingMagnifier, mAnimationTimeProperty), mAnimationTime ); + animation.AnimateTo(Property(mBouncingMagnifier, mAnimationTimeProperty), mAnimationTime); animation.Play(); animation.FinishedSignal().Connect(this, &ExampleController::OnAnimationFinished); } @@ -286,7 +285,7 @@ public: * Invoked whenever the quit button is clicked * @param[in] button the quit button */ - bool OnQuitButtonClicked( Toolkit::Button button ) + bool OnQuitButtonClicked(Toolkit::Button button) { // quit the application mApplication.Quit(); @@ -298,11 +297,11 @@ public: * @param[in] actor The actor that received the touch * @param[in] event The touch-event information */ - bool OnTouched( Actor actor, const TouchEvent& event ) + bool OnTouched(Actor actor, const TouchEvent& event) { if(event.GetPointCount() > 0) { - switch( event.GetState( 0 ) ) + switch(event.GetState(0)) { case PointState::DOWN: case PointState::MOTION: @@ -323,7 +322,7 @@ public: } } // end switch - Vector3 touchPoint( event.GetScreenPosition( 0 ) ); + Vector3 touchPoint(event.GetScreenPosition(0)); SetMagnifierPosition(touchPoint - mWindowSize * 0.5f); } @@ -365,20 +364,20 @@ public: */ void SetMagnifierPosition(const Vector3 position) { - mMagnifier.SetProperty( Toolkit::Magnifier::Property::SOURCE_POSITION, position ); + mMagnifier.SetProperty(Toolkit::Magnifier::Property::SOURCE_POSITION, position); // position magnifier glass such that bottom edge is touching/near top of finger. Vector3 glassPosition(position); glassPosition.y -= mWindowSize.width * MAGNIFIER_SIZE.height * 0.5f + mApplication.GetWindow().GetDpi().GetHeight() * FINGER_RADIUS_INCHES; - mMagnifier.SetProperty( Actor::Property::POSITION, glassPosition ); + mMagnifier.SetProperty(Actor::Property::POSITION, glassPosition); } void OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -386,23 +385,21 @@ public: } private: - - Application& mApplication; ///< Application instance - Toolkit::Control mView; ///< The view - Layer mContent; ///< The content layer - Toolkit::Magnifier mMagnifier; ///< The manually controlled magnifier - Toolkit::Magnifier mBouncingMagnifier; ///< The animating magnifier (swirly animation) - Vector3 mWindowSize; ///< The size of the window - float mAnimationTime; ///< Keep track of start animation time. - Property::Index mAnimationTimeProperty; ///< Animation time property (responsible for swirly animation) - bool mMagnifierShown; ///< Flag indicating whether the magnifier is being shown or not. - + Application& mApplication; ///< Application instance + Toolkit::Control mView; ///< The view + Layer mContent; ///< The content layer + Toolkit::Magnifier mMagnifier; ///< The manually controlled magnifier + Toolkit::Magnifier mBouncingMagnifier; ///< The animating magnifier (swirly animation) + Vector3 mWindowSize; ///< The size of the window + float mAnimationTime; ///< Keep track of start animation time. + Property::Index mAnimationTimeProperty; ///< Animation time property (responsible for swirly animation) + bool mMagnifierShown; ///< Flag indicating whether the magnifier is being shown or not. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - ExampleController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + ExampleController test(application); application.MainLoop(); return 0; } diff --git a/examples/mesh-morph/mesh-morph-example.cpp b/examples/mesh-morph/mesh-morph-example.cpp index 3a50a0f..aa9d57d 100644 --- a/examples/mesh-morph/mesh-morph-example.cpp +++ b/examples/mesh-morph/mesh-morph-example.cpp @@ -16,8 +16,8 @@ */ // EXTERNAL INCLUDES -#include #include +#include // INTERNAL INCLUDES #include "shared/view.h" @@ -26,225 +26,226 @@ using namespace Dali; namespace { - -#define MAKE_SHADER(A)#A +#define MAKE_SHADER(A) #A const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aInitPos; -attribute mediump vec2 aFinalPos; -attribute mediump vec3 aColor; -uniform mediump mat4 uMvpMatrix; -uniform mediump vec3 uSize; -uniform mediump float uDelta; -uniform lowp vec4 uColor; -varying lowp vec4 vColor; - -void main() -{ - mediump vec4 vertexPosition = vec4(mix(aInitPos, aFinalPos, uDelta), 0.0, 1.0); - vertexPosition.xyz *= uSize; - vertexPosition = uMvpMatrix * vertexPosition; - gl_Position = vertexPosition; - vColor = vec4(aColor, 0.) * uColor; -} -); + attribute mediump vec2 aInitPos; + attribute mediump vec2 aFinalPos; + attribute mediump vec3 aColor; + uniform mediump mat4 uMvpMatrix; + uniform mediump vec3 uSize; + uniform mediump float uDelta; + uniform lowp vec4 uColor; + varying lowp vec4 vColor; + + void main() { + mediump vec4 vertexPosition = vec4(mix(aInitPos, aFinalPos, uDelta), 0.0, 1.0); + vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + gl_Position = vertexPosition; + vColor = vec4(aColor, 0.) * uColor; + }); const char* FRAGMENT_SHADER = MAKE_SHADER( -varying lowp vec4 vColor; + varying lowp vec4 vColor; -void main() -{ - gl_FragColor = vColor; -} -); + void main() { + gl_FragColor = vColor; + }); Geometry CreateGeometry() { // Create vertices - struct VertexPosition { Vector2 position; }; - struct VertexColor { Vector3 color; }; + struct VertexPosition + { + Vector2 position; + }; + struct VertexColor + { + Vector3 color; + }; VertexPosition quad[] = { // yellow - { Vector2(-.5, -.5) }, - { Vector2( .0, .0) }, - { Vector2(-.5, .5) }, + {Vector2(-.5, -.5)}, + {Vector2(.0, .0)}, + {Vector2(-.5, .5)}, // green - { Vector2(-.5, -.5) }, - { Vector2( .5, -.5) }, - { Vector2( .0, .0) }, + {Vector2(-.5, -.5)}, + {Vector2(.5, -.5)}, + {Vector2(.0, .0)}, // blue - { Vector2(.5, -.5) }, - { Vector2(.5, .0) }, - { Vector2(.25, -.25) }, + {Vector2(.5, -.5)}, + {Vector2(.5, .0)}, + {Vector2(.25, -.25)}, // red - { Vector2(.25, -.25) }, - { Vector2(.5, .0) }, - { Vector2(.25, .25) }, - { Vector2(.25, .25) }, - { Vector2(.0, .0) }, - { Vector2(.25, -.25) }, + {Vector2(.25, -.25)}, + {Vector2(.5, .0)}, + {Vector2(.25, .25)}, + {Vector2(.25, .25)}, + {Vector2(.0, .0)}, + {Vector2(.25, -.25)}, // cyan - { Vector2( .0, .0) }, - { Vector2( .25, .25) }, - { Vector2(-.25, .25) }, + {Vector2(.0, .0)}, + {Vector2(.25, .25)}, + {Vector2(-.25, .25)}, // magenta - { Vector2(-.25, .25) }, - { Vector2( .25, .25) }, - { Vector2( .0, .5) }, - { Vector2( .0, .5) }, - { Vector2(-.5, .5) }, - { Vector2(-.25, .25) }, + {Vector2(-.25, .25)}, + {Vector2(.25, .25)}, + {Vector2(.0, .5)}, + {Vector2(.0, .5)}, + {Vector2(-.5, .5)}, + {Vector2(-.25, .25)}, // orange - { Vector2( .5, .0) }, - { Vector2( .5, .5) }, - { Vector2( .0, .5) }, + {Vector2(.5, .0)}, + {Vector2(.5, .5)}, + {Vector2(.0, .5)}, }; float bigSide = 0.707106781; - float side = bigSide * .5f; - // float smallSide = side * .5f; - - Vector2 pA = Vector2( side, .25 ); - Vector2 pB = pA + Vector2( 0., bigSide ); - Vector2 pC = pB + Vector2( -bigSide, 0. ); - Vector2 pD = pA + Vector2(-.5, -.5 ); - Vector2 pE = pD + Vector2( .0, 1. ); - Vector2 pF = pD + Vector2(-side, side ); - Vector2 pF2 = pD + Vector2( 0., bigSide ); - Vector2 pG = pD + Vector2(-.25, .25 ); - Vector2 pH = pD + Vector2( -.5, .0 ); - Vector2 pI = pD + Vector2(-.25, -.25 ); - Vector2 pJ = pD + Vector2( 0., -.5); - Vector2 pK = pD + Vector2(-.5, -.5); - Vector2 pL = pB + Vector2(0, -side); - Vector2 pM = pL + Vector2(side, -side); - Vector2 pN = pB + Vector2(side, -side); + float side = bigSide * .5f; + // float smallSide = side * .5f; + + Vector2 pA = Vector2(side, .25); + Vector2 pB = pA + Vector2(0., bigSide); + Vector2 pC = pB + Vector2(-bigSide, 0.); + Vector2 pD = pA + Vector2(-.5, -.5); + Vector2 pE = pD + Vector2(.0, 1.); + Vector2 pF = pD + Vector2(-side, side); + Vector2 pF2 = pD + Vector2(0., bigSide); + Vector2 pG = pD + Vector2(-.25, .25); + Vector2 pH = pD + Vector2(-.5, .0); + Vector2 pI = pD + Vector2(-.25, -.25); + Vector2 pJ = pD + Vector2(0., -.5); + Vector2 pK = pD + Vector2(-.5, -.5); + Vector2 pL = pB + Vector2(0, -side); + Vector2 pM = pL + Vector2(side, -side); + Vector2 pN = pB + Vector2(side, -side); VertexPosition cat[] = { // yellow - { pA }, - { pB }, - { pC }, + {pA}, + {pB}, + {pC}, // green - { pD }, - { pA }, - { pE }, + {pD}, + {pA}, + {pE}, // blue - { pJ }, - { pD }, - { pI }, + {pJ}, + {pD}, + {pI}, // red - { pI }, - { pD }, - { pG }, - { pG }, - { pH }, - { pI }, + {pI}, + {pD}, + {pG}, + {pG}, + {pH}, + {pI}, // cyan - { pI }, - { pH }, - { pK }, + {pI}, + {pH}, + {pK}, // magenta - { pL }, - { pM }, - { pN }, - { pN }, - { pB }, - { pL }, + {pL}, + {pM}, + {pN}, + {pN}, + {pB}, + {pL}, // orange - { pD }, - { pF2 }, - { pF }, + {pD}, + {pF2}, + {pF}, }; VertexColor colors[] = { // yellow - { Vector3( 1., 1., 0. ) }, - { Vector3( 1., 1., 0. ) }, - { Vector3( 1., 1., 0. ) }, + {Vector3(1., 1., 0.)}, + {Vector3(1., 1., 0.)}, + {Vector3(1., 1., 0.)}, // green - { Vector3( 0., 1., 0. ) }, - { Vector3( 0., 1., 0. ) }, - { Vector3( 0., 1., 0. ) }, + {Vector3(0., 1., 0.)}, + {Vector3(0., 1., 0.)}, + {Vector3(0., 1., 0.)}, // blue - { Vector3( 0., 0., 1. ) }, - { Vector3( 0., 0., 1. ) }, - { Vector3( 0., 0., 1. ) }, + {Vector3(0., 0., 1.)}, + {Vector3(0., 0., 1.)}, + {Vector3(0., 0., 1.)}, // red - { Vector3( 1., 0., 0. ) }, - { Vector3( 1., 0., 0. ) }, - { Vector3( 1., 0., 0. ) }, - { Vector3( 1., 0., 0. ) }, - { Vector3( 1., 0., 0. ) }, - { Vector3( 1., 0., 0. ) }, + {Vector3(1., 0., 0.)}, + {Vector3(1., 0., 0.)}, + {Vector3(1., 0., 0.)}, + {Vector3(1., 0., 0.)}, + {Vector3(1., 0., 0.)}, + {Vector3(1., 0., 0.)}, // cyan - { Vector3( 0., 1., 1. ) }, - { Vector3( 0., 1., 1. ) }, - { Vector3( 0., 1., 1. ) }, + {Vector3(0., 1., 1.)}, + {Vector3(0., 1., 1.)}, + {Vector3(0., 1., 1.)}, // magenta - { Vector3( 1., 0., 1. ) }, - { Vector3( 1., 0., 1. ) }, - { Vector3( 1., 0., 1. ) }, - { Vector3( 1., 0., 1. ) }, - { Vector3( 1., 0., 1. ) }, - { Vector3( 1., 0., 1. ) }, + {Vector3(1., 0., 1.)}, + {Vector3(1., 0., 1.)}, + {Vector3(1., 0., 1.)}, + {Vector3(1., 0., 1.)}, + {Vector3(1., 0., 1.)}, + {Vector3(1., 0., 1.)}, // orange - { Vector3( 1., 0.5, 0. ) }, - { Vector3( 1., 0.5, 0. ) }, - { Vector3( 1., 0.5, 0. ) }, + {Vector3(1., 0.5, 0.)}, + {Vector3(1., 0.5, 0.)}, + {Vector3(1., 0.5, 0.)}, }; - unsigned int numberOfVertices = sizeof(quad)/sizeof(VertexPosition); + unsigned int numberOfVertices = sizeof(quad) / sizeof(VertexPosition); Property::Map initialPositionVertexFormat; initialPositionVertexFormat["aInitPos"] = Property::VECTOR2; - VertexBuffer initialPositionVertices = VertexBuffer::New( initialPositionVertexFormat ); - initialPositionVertices.SetData( quad, numberOfVertices ); + VertexBuffer initialPositionVertices = VertexBuffer::New(initialPositionVertexFormat); + initialPositionVertices.SetData(quad, numberOfVertices); Property::Map finalPositionVertexFormat; finalPositionVertexFormat["aFinalPos"] = Property::VECTOR2; - VertexBuffer finalPositionVertices = VertexBuffer::New( finalPositionVertexFormat ); - finalPositionVertices.SetData( cat, numberOfVertices ); + VertexBuffer finalPositionVertices = VertexBuffer::New(finalPositionVertexFormat); + finalPositionVertices.SetData(cat, numberOfVertices); Property::Map colorVertexFormat; colorVertexFormat["aColor"] = Property::VECTOR3; - VertexBuffer colorVertices = VertexBuffer::New( colorVertexFormat ); - colorVertices.SetData( colors, numberOfVertices ); + VertexBuffer colorVertices = VertexBuffer::New(colorVertexFormat); + colorVertices.SetData(colors, numberOfVertices); // Create the geometry object Geometry texturedQuadGeometry = Geometry::New(); - texturedQuadGeometry.AddVertexBuffer( initialPositionVertices ); - texturedQuadGeometry.AddVertexBuffer( finalPositionVertices ); - texturedQuadGeometry.AddVertexBuffer( colorVertices ); + texturedQuadGeometry.AddVertexBuffer(initialPositionVertices); + texturedQuadGeometry.AddVertexBuffer(finalPositionVertices); + texturedQuadGeometry.AddVertexBuffer(colorVertices); return texturedQuadGeometry; } -inline float StationarySin( float progress ) ///< Single revolution +inline float StationarySin(float progress) ///< Single revolution { float val = cosf(progress * 2.0f * Math::PI) + .5f; - val = val > 1.f ? 1.f : val; - val = val < 0.f ? 0.f : val; + val = val > 1.f ? 1.f : val; + val = val < 0.f ? 0.f : val; return val; } @@ -255,16 +256,15 @@ inline float StationarySin( float progress ) ///< Single revolution class ExampleController : public ConnectionTracker { public: - /** * The example controller constructor. * @param[in] application The application instance */ - ExampleController( Application& application ) - : mApplication( application ) + ExampleController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ExampleController::Create ); + mApplication.InitSignal().Connect(this, &ExampleController::Create); } /** @@ -279,7 +279,7 @@ public: * Invoked upon creation of application * @param[in] application The application instance */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); @@ -288,26 +288,26 @@ public: // The Init signal is received once (only) during the Application lifetime - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); mGeometry = CreateGeometry(); - mRenderer = Renderer::New( mGeometry, mShader ); + mRenderer = Renderer::New(mGeometry, mShader); mMeshActor = Actor::New(); - mMeshActor.AddRenderer( mRenderer ); - mMeshActor.SetProperty( Actor::Property::SIZE, Vector2(400, 400) ); - mMeshActor.SetProperty( DevelActor::Property::UPDATE_SIZE_HINT, Vector2(480, 700) ); + mMeshActor.AddRenderer(mRenderer); + mMeshActor.SetProperty(Actor::Property::SIZE, Vector2(400, 400)); + mMeshActor.SetProperty(DevelActor::Property::UPDATE_SIZE_HINT, Vector2(480, 700)); - Property::Index morphDeltaIndex = mMeshActor.RegisterProperty( "uDelta", 0.f ); + Property::Index morphDeltaIndex = mMeshActor.RegisterProperty("uDelta", 0.f); - mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, 0 ); + mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 0); - mMeshActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mMeshActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - window.Add( mMeshActor ); + mMeshActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mMeshActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + window.Add(mMeshActor); - Animation animation = Animation::New(10); - animation.AnimateTo( Property( mMeshActor, morphDeltaIndex ), 1.f, StationarySin ); - animation.SetLooping( true ); + Animation animation = Animation::New(10); + animation.AnimateTo(Property(mMeshActor, morphDeltaIndex), 1.f, StationarySin); + animation.SetLooping(true); animation.Play(); window.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f)); @@ -317,7 +317,7 @@ public: * Invoked whenever the quit button is clicked * @param[in] button the quit button */ - bool OnQuitButtonClicked( Toolkit::Button button ) + bool OnQuitButtonClicked(Toolkit::Button button) { // quit the application mApplication.Quit(); @@ -328,7 +328,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -336,9 +336,8 @@ public: } private: - - Application& mApplication; ///< Application instance - Vector3 mWindowSize; ///< The size of the window + Application& mApplication; ///< Application instance + Vector3 mWindowSize; ///< The size of the window Shader mShader; Geometry mGeometry; @@ -347,10 +346,10 @@ private: Timer mMorphTimer; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ExampleController test( application ); + Application application = Application::New(&argc, &argv); + ExampleController test(application); application.MainLoop(); return 0; } diff --git a/examples/mesh-visual/mesh-visual-example.cpp b/examples/mesh-visual/mesh-visual-example.cpp index affde27..68e3ddf 100644 --- a/examples/mesh-visual/mesh-visual-example.cpp +++ b/examples/mesh-visual/mesh-visual-example.cpp @@ -8,81 +8,77 @@ namespace // Keeps information about each model for access. struct Model { - Control control; // Control housing the mesh visual of the model. - Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation. + Control control; // Control housing the mesh visual of the model. + Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation. Animation rotationAnimation; // Automatically rotates when left alone. }; // Files for meshes -const char * const MODEL_FILE_TABLE[] = -{ +const char* const MODEL_FILE_TABLE[] = + { DEMO_MODEL_DIR "Dino.obj", DEMO_MODEL_DIR "ToyRobot-Metal.obj", - DEMO_MODEL_DIR "Toyrobot-Plastic.obj" -}; + DEMO_MODEL_DIR "Toyrobot-Plastic.obj"}; -const char * const MATERIAL_FILE_TABLE[] = -{ +const char* const MATERIAL_FILE_TABLE[] = + { DEMO_MODEL_DIR "Dino.mtl", DEMO_MODEL_DIR "ToyRobot-Metal.mtl", - DEMO_MODEL_DIR "Toyrobot-Plastic.mtl" -}; + DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"}; -const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" ); +const char* const TEXTURES_PATH(DEMO_IMAGE_DIR ""); // Possible shading modes. MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] = -{ - MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING, - MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING, - MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING -}; + { + MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING, + MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING, + MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING}; // Button labels. -const char * const PAUSE = " || "; -const char * const PLAY = " > "; -const char * const FIXED = "FIXED"; -const char * const MANUAL = "MANUAL"; -const char * const FRONT = "FRONT"; -const char * const BACK = "BACK"; +const char* const PAUSE = " || "; +const char* const PLAY = " > "; +const char* const FIXED = "FIXED"; +const char* const MANUAL = "MANUAL"; +const char* const FRONT = "FRONT"; +const char* const BACK = "BACK"; // Image urls for the light. -const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png"; -const char * const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png"; +const char* const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png"; +const char* const LIGHT_URL_BACK = DEMO_IMAGE_DIR "light-icon-back.png"; const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f; const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f; -const float MODEL_SCALE = 0.75f; -const float LIGHT_SCALE = 0.15f; -const float BUTTONS_OFFSET_BOTTOM = 0.08f; -const float BUTTONS_OFFSET_SIDE = 0.2f; -const int NUM_MESHES = 2; +const float MODEL_SCALE = 0.75f; +const float LIGHT_SCALE = 0.15f; +const float BUTTONS_OFFSET_BOTTOM = 0.08f; +const float BUTTONS_OFFSET_SIDE = 0.2f; +const int NUM_MESHES = 2; // Used to identify actors. const int MODEL_TAG = 0; const int LIGHT_TAG = 1; const int LAYER_TAG = 2; -const Vector4 WINDOW_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the window +const Vector4 WINDOW_COLOR(211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f); ///< The color of the window } // unnamed namespace class MeshVisualController : public ConnectionTracker { public: - - MeshVisualController( Application& application ) - : mApplication( application ), //Store handle to the application. - mModelIndex( 1 ), //Start with metal robot. - mShadingModeIndex( 0 ), //Start with texture and detailed specular lighting. - mTag( -1 ), //Non-valid default, which will get set to a correct value when used. - mSelectedModelIndex( -1 ), //Non-valid default, which will get set to a correct value when used. - mPaused( false ), //Animations play by default. - mLightFixed( true ), //The light is fixed by default. - mLightFront( true ) //The light is in front by default. + MeshVisualController(Application& application) + : mApplication(application), //Store handle to the application. + mModelIndex(1), //Start with metal robot. + mShadingModeIndex(0), //Start with texture and detailed specular lighting. + mTag(-1), //Non-valid default, which will get set to a correct value when used. + mSelectedModelIndex(-1), //Non-valid default, which will get set to a correct value when used. + mPaused(false), //Animations play by default. + mLightFixed(true), //The light is fixed by default. + mLightFront(true) //The light is in front by default. { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &MeshVisualController::Create ); + mApplication.InitSignal().Connect(this, &MeshVisualController::Create); } ~MeshVisualController() @@ -90,78 +86,78 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( WINDOW_COLOR ); + window.SetBackgroundColor(WINDOW_COLOR); //Set up root layer to receive touch gestures. Layer rootLayer = window.GetRootLayer(); - rootLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor. - rootLayer.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); + rootLayer.RegisterProperty("Tag", LAYER_TAG); //Used to differentiate between different kinds of actor. + rootLayer.TouchedSignal().Connect(this, &MeshVisualController::OnTouch); //Place models on the scene. - SetupModels( rootLayer ); + SetupModels(rootLayer); //Place buttons on the scene. - SetupButtons( rootLayer ); + SetupButtons(rootLayer); //Add a light to the scene. - SetupLight( rootLayer ); + SetupLight(rootLayer); //Allow for exiting of the application via key presses. - window.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &MeshVisualController::OnKeyEvent); } //Loads and adds the models to the scene, inside containers for hit detection. - void SetupModels( Layer layer ) + void SetupModels(Layer layer) { //Add containers to house each renderer-holding-actor. - for( int i = 0; i < NUM_MESHES; i++ ) + for(int i = 0; i < NUM_MESHES; i++) { mContainers[i] = Actor::New(); - mContainers[i].SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mContainers[i].RegisterProperty( "Tag", MODEL_TAG ); //Used to differentiate between different kinds of actor. - mContainers[i].RegisterProperty( "Model", Property::Value( i ) ); //Used to index into the model. - mContainers[i].TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); - layer.Add( mContainers[i] ); + mContainers[i].SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mContainers[i].RegisterProperty("Tag", MODEL_TAG); //Used to differentiate between different kinds of actor. + mContainers[i].RegisterProperty("Model", Property::Value(i)); //Used to index into the model. + mContainers[i].TouchedSignal().Connect(this, &MeshVisualController::OnTouch); + layer.Add(mContainers[i]); } //Position each container individually on screen //Main, central model - mContainers[0].SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( MODEL_SCALE, MODEL_SCALE, 0.0f ) ); - mContainers[0].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mContainers[0].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mContainers[0].SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(MODEL_SCALE, MODEL_SCALE, 0.0f)); + mContainers[0].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mContainers[0].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); //Top left model - mContainers[1].SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( MODEL_SCALE / 3.0f, MODEL_SCALE / 3.0f, 0.0f ) ); - mContainers[1].SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.05, 0.03, 0.5 ) ); //Offset from top left - mContainers[1].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mContainers[1].SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(MODEL_SCALE / 3.0f, MODEL_SCALE / 3.0f, 0.0f)); + mContainers[1].SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.05, 0.03, 0.5)); //Offset from top left + mContainers[1].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); //Set up models - for( int i = 0; i < NUM_MESHES; i++ ) + for(int i = 0; i < NUM_MESHES; i++) { //Create control to display model Control control = Control::New(); - control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - control.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - control.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mContainers[i].Add( control ); + control.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mContainers[i].Add(control); //Make model spin to demonstrate 3D - Animation rotationAnimation = Animation::New( 15.0f ); - float spin = i % 2 == 0 ? 1.0f : -1.0f; //Make actors spin in different directions to better show independence. - rotationAnimation.AnimateBy( Property( control, Actor::Property::ORIENTATION ), - Quaternion( Degree( 0.0f ), Degree( spin * 360.0f ), Degree( 0.0f ) ) ); - rotationAnimation.SetLooping( true ); + Animation rotationAnimation = Animation::New(15.0f); + float spin = i % 2 == 0 ? 1.0f : -1.0f; //Make actors spin in different directions to better show independence. + rotationAnimation.AnimateBy(Property(control, Actor::Property::ORIENTATION), + Quaternion(Degree(0.0f), Degree(spin * 360.0f), Degree(0.0f))); + rotationAnimation.SetLooping(true); rotationAnimation.Play(); //Store model information in corresponding structs. - mModels[i].control = control; - mModels[i].rotation.x = 0.0f; - mModels[i].rotation.y = 0.0f; + mModels[i].control = control; + mModels[i].rotation.x = 0.0f; + mModels[i].rotation.y = 0.0f; mModels[i].rotationAnimation = rotationAnimation; } @@ -170,126 +166,126 @@ public: } //Place the various buttons on the bottom of the screen, with title labels where necessary. - void SetupButtons( Layer layer ) + void SetupButtons(Layer layer) { //Actor for positioning model and shading mode buttons. Actor positionActorModel = Actor::New(); - positionActorModel.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); - positionActorModel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - layer.Add( positionActorModel ); + positionActorModel.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5)); + positionActorModel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + layer.Add(positionActorModel); //Create button for model changing. PushButton modelButton = Toolkit::PushButton::New(); - modelButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked ); - modelButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - modelButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - modelButton.SetProperty( Toolkit::Button::Property::LABEL, "Model" ); - positionActorModel.Add( modelButton ); + modelButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + modelButton.ClickedSignal().Connect(this, &MeshVisualController::OnChangeModelClicked); + modelButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + modelButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + modelButton.SetProperty(Toolkit::Button::Property::LABEL, "Model"); + positionActorModel.Add(modelButton); //Create button for shading mode changing. PushButton shadingModeButton = Toolkit::PushButton::New(); - shadingModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked ); - shadingModeButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - shadingModeButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - shadingModeButton.SetProperty( Toolkit::Button::Property::LABEL, "Shading Mode" ); - positionActorModel.Add( shadingModeButton ); + shadingModeButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + shadingModeButton.ClickedSignal().Connect(this, &MeshVisualController::OnChangeShadingModeClicked); + shadingModeButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + shadingModeButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + shadingModeButton.SetProperty(Toolkit::Button::Property::LABEL, "Shading Mode"); + positionActorModel.Add(shadingModeButton); //Text label title for changing model or shading mode. - TextLabel changeTitleLabel = TextLabel::New( "Change" ); - changeTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - changeTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); - changeTitleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - changeTitleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - modelButton.Add( changeTitleLabel ); + TextLabel changeTitleLabel = TextLabel::New("Change"); + changeTitleLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + changeTitleLabel.SetProperty(TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}"); + changeTitleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + changeTitleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + modelButton.Add(changeTitleLabel); //Create button for pausing animations. PushButton pauseButton = Toolkit::PushButton::New(); - pauseButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked ); - pauseButton.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); - pauseButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - pauseButton.SetProperty( Toolkit::Button::Property::LABEL, PAUSE ); - layer.Add( pauseButton ); + pauseButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + pauseButton.ClickedSignal().Connect(this, &MeshVisualController::OnPauseClicked); + pauseButton.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5)); + pauseButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + pauseButton.SetProperty(Toolkit::Button::Property::LABEL, PAUSE); + layer.Add(pauseButton); //Actor for positioning light position buttons. Actor positionActorLight = Actor::New(); - positionActorLight.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 1.0 - BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) ); - positionActorLight.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - layer.Add( positionActorLight ); + positionActorLight.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(1.0 - BUTTONS_OFFSET_SIDE, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5)); + positionActorLight.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + layer.Add(positionActorLight); //Create button for switching between manual and fixed light position. PushButton lightModeButton = Toolkit::PushButton::New(); - lightModeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked ); - lightModeButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - lightModeButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - lightModeButton.SetProperty( Toolkit::Button::Property::LABEL, FIXED ); - positionActorLight.Add( lightModeButton ); + lightModeButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + lightModeButton.ClickedSignal().Connect(this, &MeshVisualController::OnChangeLightModeClicked); + lightModeButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + lightModeButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + lightModeButton.SetProperty(Toolkit::Button::Property::LABEL, FIXED); + positionActorLight.Add(lightModeButton); //Create button for switching between front and back light position. PushButton lightSideButton = Toolkit::PushButton::New(); - lightSideButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked ); - lightSideButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - lightSideButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - lightSideButton.SetProperty( Toolkit::Button::Property::LABEL, FRONT ); - positionActorLight.Add( lightSideButton ); + lightSideButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + lightSideButton.ClickedSignal().Connect(this, &MeshVisualController::OnChangeLightSideClicked); + lightSideButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + lightSideButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + lightSideButton.SetProperty(Toolkit::Button::Property::LABEL, FRONT); + positionActorLight.Add(lightSideButton); //Text label title for light position mode. - TextLabel lightTitleLabel = TextLabel::New( "Light Position" ); - lightTitleLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - lightTitleLabel.SetProperty( TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}" ); - lightTitleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - lightTitleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - lightModeButton.Add( lightTitleLabel ); + TextLabel lightTitleLabel = TextLabel::New("Light Position"); + lightTitleLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + lightTitleLabel.SetProperty(TextLabel::Property::UNDERLINE, "{\"thickness\":\"2.0\"}"); + lightTitleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + lightTitleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + lightModeButton.Add(lightTitleLabel); } //Add a point light source the the scene, on a layer above the first. - void SetupLight( Layer baseLayer ) + void SetupLight(Layer baseLayer) { //Create control to act as light source of scene. mLightSource = Control::New(); - mLightSource.RegisterProperty( "Tag", LIGHT_TAG ); + mLightSource.RegisterProperty("Tag", LIGHT_TAG); //Set size of control based on screen dimensions. - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - if( windowSize.width < windowSize.height ) + if(windowSize.width < windowSize.height) { //Scale to width. - mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); - mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - mLightSource.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( LIGHT_SCALE, 0.0f, 0.0f ) ); + mLightSource.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH); + mLightSource.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + mLightSource.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(LIGHT_SCALE, 0.0f, 0.0f)); } else { //Scale to height. - mLightSource.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); - mLightSource.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH ); - mLightSource.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.0f, LIGHT_SCALE, 0.0f ) ); + mLightSource.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT); + mLightSource.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH); + mLightSource.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.0f, LIGHT_SCALE, 0.0f)); } //Set position relative to top left, as the light source property is also relative to the top left. - mLightSource.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mLightSource.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLightSource.SetProperty( Actor::Property::POSITION, Vector2( windowSize.width * 0.85f, windowSize.height * 0.125 )); + mLightSource.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mLightSource.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLightSource.SetProperty(Actor::Property::POSITION, Vector2(windowSize.width * 0.85f, windowSize.height * 0.125)); //Supply an image to represent the light. SetLightImage(); //Connect to touch signal for dragging. - mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch ); + mLightSource.TouchedSignal().Connect(this, &MeshVisualController::OnTouch); //Place the light source on a layer above the base, so that it is rendered above everything else. Layer upperLayer = Layer::New(); - upperLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - upperLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - upperLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + upperLayer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + upperLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + upperLayer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - baseLayer.Add( upperLayer ); - upperLayer.Add( mLightSource ); + baseLayer.Add(upperLayer); + upperLayer.Add(mLightSource); //Decide which light to use to begin with. SetLightMode(); @@ -300,7 +296,7 @@ public: { std::string imageUrl; - if( mLightFront ) + if(mLightFront) { imageUrl = LIGHT_URL_FRONT; } @@ -310,9 +306,9 @@ public: } Property::Map lightMap; - lightMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE ); - lightMap.Insert( ImageVisual::Property::URL, imageUrl ); - mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) ); + lightMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE); + lightMap.Insert(ImageVisual::Property::URL, imageUrl); + mLightSource.SetProperty(Control::Property::BACKGROUND, Property::Value(lightMap)); } //Updates the displayed models to account for parameter changes. @@ -320,26 +316,25 @@ public: { //Create mesh property map Property::Map map; - map.Insert( Toolkit::Visual::Property::TYPE, Visual::MESH ); - map.Insert( Visual::Property::TRANSFORM, - Property::Map().Add( Visual::Transform::Property::ORIGIN, Align::CENTER ) - .Add( Visual::Transform::Property::ANCHOR_POINT, Align::CENTER ) ); - map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex] ); - map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex] ); - map.Insert( MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH ); - map.Insert( MeshVisual::Property::SHADING_MODE, SHADING_MODE_TABLE[mShadingModeIndex] ); + map.Insert(Toolkit::Visual::Property::TYPE, Visual::MESH); + map.Insert(Visual::Property::TRANSFORM, + Property::Map().Add(Visual::Transform::Property::ORIGIN, Align::CENTER).Add(Visual::Transform::Property::ANCHOR_POINT, Align::CENTER)); + map.Insert(MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex]); + map.Insert(MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex]); + map.Insert(MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH); + map.Insert(MeshVisual::Property::SHADING_MODE, SHADING_MODE_TABLE[mShadingModeIndex]); //Set the two controls to use the mesh - for( int i = 0; i < NUM_MESHES; i++ ) + for(int i = 0; i < NUM_MESHES; i++) { - mModels[i].control.SetProperty( Control::Property::BACKGROUND, Property::Value( map ) ); + mModels[i].control.SetProperty(Control::Property::BACKGROUND, Property::Value(map)); } } //Set the mode used to light the models. void SetLightMode() { - if( mLightFixed ) + if(mLightFixed) { UseFixedLight(); } @@ -353,19 +348,18 @@ public: void UseFixedLight() { //Hide draggable source - mLightSource.SetProperty( Actor::Property::VISIBLE, false ); + mLightSource.SetProperty(Actor::Property::VISIBLE, false); //Use window dimensions to place light at center, offset in z axis. - Window window = mApplication.GetWindow(); - float width = window.GetSize().GetWidth(); - float height = window.GetSize().GetHeight(); - Vector3 lightPosition = Vector3( width / 2.0f, height / 2.0f, - ( mLightFront ? 1 : -1 ) * std::max( width, height ) * 5.0f ); + Window window = mApplication.GetWindow(); + float width = window.GetSize().GetWidth(); + float height = window.GetSize().GetHeight(); + Vector3 lightPosition = Vector3(width / 2.0f, height / 2.0f, (mLightFront ? 1 : -1) * std::max(width, height) * 5.0f); //Set global light position - for( int i = 0; i < NUM_MESHES; ++i ) + for(int i = 0; i < NUM_MESHES; ++i) { - mModels[i].control.RegisterProperty( "lightPosition", lightPosition, Property::ANIMATABLE ); + mModels[i].control.RegisterProperty("lightPosition", lightPosition, Property::ANIMATABLE); } } @@ -373,7 +367,7 @@ public: void UseManualLight() { //Show draggable source - mLightSource.SetProperty( Actor::Property::VISIBLE, true ); + mLightSource.SetProperty(Actor::Property::VISIBLE, true); //Update to switch light position of models to that of the source. UpdateLight(); @@ -383,37 +377,36 @@ public: void UpdateLight() { //Set light position to the x and y of the light control, offset into/out of the screen. - Vector3 controlPosition = mLightSource.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ); - Vector3 lightPosition = Vector3( controlPosition.x, controlPosition.y, - ( mLightFront ? 1 : -1 ) * mApplication.GetWindow().GetSize().GetWidth() / 2.0f ); + Vector3 controlPosition = mLightSource.GetCurrentProperty(Actor::Property::POSITION); + Vector3 lightPosition = Vector3(controlPosition.x, controlPosition.y, (mLightFront ? 1 : -1) * mApplication.GetWindow().GetSize().GetWidth() / 2.0f); - for( int i = 0; i < NUM_MESHES; ++i ) + for(int i = 0; i < NUM_MESHES; ++i) { - mModels[i].control.RegisterProperty( "lightPosition", lightPosition, Property::ANIMATABLE ); + mModels[i].control.RegisterProperty("lightPosition", lightPosition, Property::ANIMATABLE); } } //If the light source is touched, move it by dragging it. //If a model is touched, rotate it by panning around. - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - switch( touch.GetState( 0 ) ) + switch(touch.GetState(0)) { case PointState::DOWN: { //Determine what was touched. - actor.GetProperty( actor.GetPropertyIndex( "Tag" ) ).Get( mTag ); + actor.GetProperty(actor.GetPropertyIndex("Tag")).Get(mTag); - if( mTag == MODEL_TAG ) + if(mTag == MODEL_TAG) { //Find out which model has been selected - actor.GetProperty( actor.GetPropertyIndex( "Model" ) ).Get( mSelectedModelIndex ); + actor.GetProperty(actor.GetPropertyIndex("Model")).Get(mSelectedModelIndex); //Pause current animation, as the touch gesture will be used to manually rotate the model mModels[mSelectedModelIndex].rotationAnimation.Pause(); //Store start points. - mPanStart = touch.GetScreenPosition( 0 ); + mPanStart = touch.GetScreenPosition(0); mRotationStart = mModels[mSelectedModelIndex].rotation; } @@ -422,26 +415,26 @@ public: case PointState::MOTION: { //Switch on the kind of actor we're interacting with. - switch( mTag ) + switch(mTag) { case MODEL_TAG: //Rotate model { //Calculate displacement and corresponding rotation. - Vector2 displacement = touch.GetScreenPosition( 0 ) - mPanStart; - mModels[mSelectedModelIndex].rotation = Vector2( mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR, // Y displacement rotates around X axis - mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR ); // X displacement rotates around Y axis - Quaternion rotation = Quaternion( Radian( mModels[mSelectedModelIndex].rotation.x ), Vector3::XAXIS) * - Quaternion( Radian( mModels[mSelectedModelIndex].rotation.y ), Vector3::YAXIS); + Vector2 displacement = touch.GetScreenPosition(0) - mPanStart; + mModels[mSelectedModelIndex].rotation = Vector2(mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR, // Y displacement rotates around X axis + mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR); // X displacement rotates around Y axis + Quaternion rotation = Quaternion(Radian(mModels[mSelectedModelIndex].rotation.x), Vector3::XAXIS) * + Quaternion(Radian(mModels[mSelectedModelIndex].rotation.y), Vector3::YAXIS); //Apply rotation. - mModels[mSelectedModelIndex].control.SetProperty( Actor::Property::ORIENTATION, rotation ); + mModels[mSelectedModelIndex].control.SetProperty(Actor::Property::ORIENTATION, rotation); break; } case LIGHT_TAG: //Drag light { //Set light source to new position and update the models accordingly. - mLightSource.SetProperty( Actor::Property::POSITION, Vector3( touch.GetScreenPosition( 0 ) ) ); + mLightSource.SetProperty(Actor::Property::POSITION, Vector3(touch.GetScreenPosition(0))); UpdateLight(); break; @@ -453,10 +446,10 @@ public: case PointState::INTERRUPTED: //Same as finished. case PointState::FINISHED: { - if( mTag == MODEL_TAG ) + if(mTag == MODEL_TAG) { //Return to automatic animation - if( !mPaused ) + if(!mPaused) { mModels[mSelectedModelIndex].rotationAnimation.Play(); } @@ -475,7 +468,7 @@ public: } //Cycle through the list of models. - bool OnChangeModelClicked( Toolkit::Button button ) + bool OnChangeModelClicked(Toolkit::Button button) { ++mModelIndex %= 3; @@ -485,7 +478,7 @@ public: } //Cycle through the list of shading modes. - bool OnChangeShadingModeClicked( Toolkit::Button button ) + bool OnChangeShadingModeClicked(Toolkit::Button button) { ++mShadingModeIndex %= 3; @@ -496,48 +489,47 @@ public: //Pause all animations, and keep them paused even after user panning. //This button is a toggle, so pressing again will start the animations again. - bool OnPauseClicked( Toolkit::Button button ) + bool OnPauseClicked(Toolkit::Button button) { //Toggle pause state. mPaused = !mPaused; //If we wish to pause animations, do so and keep them paused. - if( mPaused ) + if(mPaused) { - for( int i = 0; i < NUM_MESHES ; ++i ) + for(int i = 0; i < NUM_MESHES; ++i) { mModels[i].rotationAnimation.Pause(); } - button.SetProperty( Toolkit::Button::Property::LABEL, PLAY ); + button.SetProperty(Toolkit::Button::Property::LABEL, PLAY); } else //Unpause all animations again. { - for( int i = 0; i < NUM_MESHES ; ++i ) + for(int i = 0; i < NUM_MESHES; ++i) { mModels[i].rotationAnimation.Play(); } - button.SetProperty( Toolkit::Button::Property::LABEL, PAUSE ); + button.SetProperty(Toolkit::Button::Property::LABEL, PAUSE); } return true; } - //Switch between a fixed light source above/behind the screen, and a light source the user can drag around. - bool OnChangeLightModeClicked( Toolkit::Button button ) + bool OnChangeLightModeClicked(Toolkit::Button button) { //Toggle state. mLightFixed = !mLightFixed; - if( mLightFixed ) + if(mLightFixed) { - button.SetProperty( Toolkit::Button::Property::LABEL, FIXED ); + button.SetProperty(Toolkit::Button::Property::LABEL, FIXED); } else { - button.SetProperty( Toolkit::Button::Property::LABEL, MANUAL ); + button.SetProperty(Toolkit::Button::Property::LABEL, MANUAL); } SetLightMode(); @@ -546,18 +538,18 @@ public: } //Switch between the light being in front of and behind the models. - bool OnChangeLightSideClicked( Toolkit::Button button ) + bool OnChangeLightSideClicked(Toolkit::Button button) { //Toggle state. mLightFront = !mLightFront; - if( mLightFront ) + if(mLightFront) { - button.SetProperty( Toolkit::Button::Property::LABEL, FRONT ); + button.SetProperty(Toolkit::Button::Property::LABEL, FRONT); } else { - button.SetProperty( Toolkit::Button::Property::LABEL, BACK ); + button.SetProperty(Toolkit::Button::Property::LABEL, BACK); } //Change light image. @@ -570,11 +562,11 @@ public: } //If escape or the back button is pressed, quit the application (and return to the launcher) - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -582,7 +574,7 @@ public: } private: - Application& mApplication; + Application& mApplication; //The models displayed on screen, including information about rotation. Model mModels[NUM_MESHES]; @@ -595,19 +587,19 @@ private: Vector2 mPanStart; Vector2 mRotationStart; - int mModelIndex; //Index of model to load. - int mShadingModeIndex; //Index of shading mode to use. - int mTag; //Identifies what kind of actor has been selected in OnTouch. - int mSelectedModelIndex; //Index of model selected on screen. - bool mPaused; //If true, all animations are paused and should stay so. - bool mLightFixed; //If false, the light is in manual. - bool mLightFront; //Bool for light being in front or behind the models. + int mModelIndex; //Index of model to load. + int mShadingModeIndex; //Index of shading mode to use. + int mTag; //Identifies what kind of actor has been selected in OnTouch. + int mSelectedModelIndex; //Index of model selected on screen. + bool mPaused; //If true, all animations are paused and should stay so. + bool mLightFixed; //If false, the light is in manual. + bool mLightFront; //Bool for light being in front or behind the models. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - MeshVisualController test( application ); + Application application = Application::New(&argc, &argv); + MeshVisualController test(application); application.MainLoop(); return 0; } diff --git a/examples/metaball-explosion/metaball-explosion-example.cpp b/examples/metaball-explosion/metaball-explosion-example.cpp index 92209c3..0c65e00 100644 --- a/examples/metaball-explosion/metaball-explosion-example.cpp +++ b/examples/metaball-explosion/metaball-explosion-example.cpp @@ -16,15 +16,15 @@ */ // EXTERNAL INCLUDES +#include // uint32_t, uint16_t etc #include #include -#include // uint32_t, uint16_t etc +#include +#include #include -#include #include -#include -#include +#include // INTERNAL INCLUDES #include "shared/utility.h" // DemoHelper::LoadTexture @@ -34,7 +34,7 @@ using namespace Dali; namespace // unnamed namespace for constants { // background image -const char * const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-2.jpg" ); +const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-2.jpg"); // number of metaballs constexpr uint32_t METABALL_NUMBER = 6; @@ -42,6 +42,7 @@ constexpr uint32_t METABALL_NUMBER = 6; /** * Vertex shader code for metaball */ +// clang-format off const char* const METABALL_VERTEX_SHADER = DALI_COMPOSE_SHADER ( attribute mediump vec2 aPosition;\n attribute mediump vec2 aTexture;\n @@ -157,16 +158,17 @@ const char* const REFRACTION_FRAG_SHADER = DALI_COMPOSE_SHADER ( gl_FragColor.a = 1.0; }\n ); +// clang-format on /** * Metadata for each ball */ struct MetaballInfo { - Actor actor; - Vector2 position; - float radius; - float initRadius; + Actor actor; + Vector2 position; + float radius; + float initRadius; //new shader stuff Property::Index positionIndex; @@ -183,12 +185,11 @@ struct MetaballInfo class MetaballExplosionController : public ConnectionTracker { public: - /** * Constructor * @param application */ - MetaballExplosionController( Application& application ); + MetaballExplosionController(Application& application); /** * Destructor @@ -198,13 +199,13 @@ public: /** * Creates the metaballs and initializes the scene */ - void Create( Application& app ); + void Create(Application& app); /** * Touch event handler to center metaballs at touch position * and start explosion animation on release */ - bool OnTouch( Actor actor, const TouchEvent& touch ); + bool OnTouch(Actor actor, const TouchEvent& touch); /** * Key event handler to quit application on escape or back key @@ -212,35 +213,34 @@ public: void OnKeyEvent(const KeyEvent& event); private: // Data + Application& mApplication; + Vector2 mScreenSize; - Application& mApplication; - Vector2 mScreenSize; + Texture mBackgroundTexture; + FrameBuffer mMetaballFBO; - Texture mBackgroundTexture; - FrameBuffer mMetaballFBO; + Actor mMetaballRoot; + MetaballInfo mMetaballs[METABALL_NUMBER]; - Actor mMetaballRoot; - MetaballInfo mMetaballs[METABALL_NUMBER]; - - Property::Index mPositionIndex; - Actor mCompositionActor; + Property::Index mPositionIndex; + Actor mCompositionActor; //Motion - Vector2 mCurrentTouchPosition; - Vector2 mMetaballPosVariation; - Vector2 mMetaballPosVariationFrom; - Vector2 mMetaballPosVariationTo; - Vector2 mMetaballCenter; + Vector2 mCurrentTouchPosition; + Vector2 mMetaballPosVariation; + Vector2 mMetaballPosVariationFrom; + Vector2 mMetaballPosVariationTo; + Vector2 mMetaballCenter; //Animations - Animation mPositionVarAnimation[METABALL_NUMBER]; + Animation mPositionVarAnimation[METABALL_NUMBER]; - uint32_t mDispersion; - Animation mDispersionAnimation[METABALL_NUMBER]; + uint32_t mDispersion; + Animation mDispersionAnimation[METABALL_NUMBER]; - Timer mTimerDispersion; + Timer mTimerDispersion; - float mTimeMultiplier; + float mTimeMultiplier; // Private helper functions @@ -248,7 +248,7 @@ private: // Data * Create a mesh data with the geometry for the metaball rendering * @param aspectMappedTexture whether texture coords should be mapped based on aspect ratio */ - Geometry CreateGeometry( bool aspectMappedTexture = true ); + Geometry CreateGeometry(bool aspectMappedTexture = true); /** * Create a actors and renderers for the metaballs @@ -273,22 +273,22 @@ private: // Data /** * Function to reset metaball state */ - void ResetMetaballs( bool resetAnims ); + void ResetMetaballs(bool resetAnims); /** * Function to create disperse each of the ball that compose the metaball when exploding */ - void DisperseBallAnimation( uint32_t ball ); + void DisperseBallAnimation(uint32_t ball); /** * Function to make metaballs come back to reset position */ - void LaunchResetMetaballPosition( Animation& source ); + void LaunchResetMetaballPosition(Animation& source); /** * Function to set things at the end of the animation */ - void EndDisperseAnimation( Animation& source ); + void EndDisperseAnimation(Animation& source); /** * Function to init dispersion of the metaballs one by one using a timer @@ -299,15 +299,15 @@ private: // Data /** * Function to set the actual position of the metaballs when the user clicks the screen */ - void SetPositionToMetaballs( const Vector2& metaballCenter ); + void SetPositionToMetaballs(const Vector2& metaballCenter); }; /** * Implementation */ -MetaballExplosionController::MetaballExplosionController( Application& application ) -: mApplication( application ), +MetaballExplosionController::MetaballExplosionController(Application& application) +: mApplication(application), mScreenSize(), mBackgroundTexture(), mMetaballFBO(), @@ -321,13 +321,13 @@ MetaballExplosionController::MetaballExplosionController( Application& applicati mMetaballPosVariationTo(), mMetaballCenter(), mPositionVarAnimation(), - mDispersion( 0 ), + mDispersion(0), mDispersionAnimation(), mTimerDispersion(), - mTimeMultiplier( 1.0f ) + mTimeMultiplier(1.0f) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &MetaballExplosionController::Create ); + mApplication.InitSignal().Connect(this, &MetaballExplosionController::Create); } MetaballExplosionController::~MetaballExplosionController() @@ -335,11 +335,11 @@ MetaballExplosionController::~MetaballExplosionController() // Nothing to do here; } -void MetaballExplosionController::Create( Application& app ) +void MetaballExplosionController::Create(Application& app) { Window window = app.GetWindow(); - window.KeyEventSignal().Connect( this, &MetaballExplosionController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &MetaballExplosionController::OnKeyEvent); mScreenSize = window.GetSize(); @@ -348,9 +348,9 @@ void MetaballExplosionController::Create( Application& app ) window.SetBackgroundColor(Color::BLACK); // Load background texture - mBackgroundTexture = DemoHelper::LoadTexture( BACKGROUND_IMAGE ); + mBackgroundTexture = DemoHelper::LoadTexture(BACKGROUND_IMAGE); - srand( static_cast( time(0) ) ); + srand(static_cast(time(0))); //Create internal data CreateMetaballActors(); @@ -359,15 +359,15 @@ void MetaballExplosionController::Create( Application& app ) CreateAnimations(); - mDispersion = 0; - mTimerDispersion = Timer::New( 150 ); - mTimerDispersion.TickSignal().Connect( this, &MetaballExplosionController::OnTimerDispersionTick ); + mDispersion = 0; + mTimerDispersion = Timer::New(150); + mTimerDispersion.TickSignal().Connect(this, &MetaballExplosionController::OnTimerDispersionTick); // Connect the callback to the touch signal on the mesh actor - window.GetRootLayer().TouchedSignal().Connect( this, &MetaballExplosionController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &MetaballExplosionController::OnTouch); } -Geometry MetaballExplosionController::CreateGeometry( bool aspectMappedTexture ) +Geometry MetaballExplosionController::CreateGeometry(bool aspectMappedTexture) { const float aspect = mScreenSize.y / mScreenSize.x; @@ -375,49 +375,53 @@ Geometry MetaballExplosionController::CreateGeometry( bool aspectMappedTexture ) const float xsize = mScreenSize.x * 0.5; // Create the meshdata for the metaballs - struct VertexPosition { Vector2 position; }; - struct VertexTexture { Vector2 texture; }; - - VertexPosition vertices[] = + struct VertexPosition { - { Vector2( -xsize, -xsize * aspect ) }, - { Vector2( xsize, -xsize * aspect ) }, - { Vector2( -xsize, xsize * aspect ) }, - { Vector2( xsize, xsize * aspect ) } + Vector2 position; }; - - const float textureAspect = (aspectMappedTexture) ? aspect : 1.0f; - VertexTexture textures[] = + struct VertexTexture { - { Vector2( 0.0f, 0.0f ) }, - { Vector2( 1.0f, 0.0f ) }, - { Vector2( 0.0f, 1.0f * textureAspect ) }, - { Vector2( 1.0f, 1.0f * textureAspect ) } + Vector2 texture; }; - uint32_t numberOfVertices = sizeof(vertices)/sizeof(VertexPosition); + VertexPosition vertices[] = + { + {Vector2(-xsize, -xsize * aspect)}, + {Vector2(xsize, -xsize * aspect)}, + {Vector2(-xsize, xsize * aspect)}, + {Vector2(xsize, xsize * aspect)}}; + + const float textureAspect = (aspectMappedTexture) ? aspect : 1.0f; + VertexTexture textures[] = + { + {Vector2(0.0f, 0.0f)}, + {Vector2(1.0f, 0.0f)}, + {Vector2(0.0f, 1.0f * textureAspect)}, + {Vector2(1.0f, 1.0f * textureAspect)}}; + + uint32_t numberOfVertices = sizeof(vertices) / sizeof(VertexPosition); // Vertices Property::Map positionVertexFormat; positionVertexFormat["aPosition"] = Property::VECTOR2; - VertexBuffer positionVertices = VertexBuffer::New( positionVertexFormat ); - positionVertices.SetData( vertices, numberOfVertices ); + VertexBuffer positionVertices = VertexBuffer::New(positionVertexFormat); + positionVertices.SetData(vertices, numberOfVertices); // Textures Property::Map textureVertexFormat; textureVertexFormat["aTexture"] = Property::VECTOR2; - VertexBuffer textureVertices = VertexBuffer::New( textureVertexFormat ); - textureVertices.SetData( textures, numberOfVertices ); + VertexBuffer textureVertices = VertexBuffer::New(textureVertexFormat); + textureVertices.SetData(textures, numberOfVertices); // Indices - const uint16_t indices[] = { 0, 3, 1, 0, 2, 3 }; + const uint16_t indices[] = {0, 3, 1, 0, 2, 3}; // Create the geometry object Geometry texturedQuadGeometry = Geometry::New(); - texturedQuadGeometry.AddVertexBuffer( positionVertices ); - texturedQuadGeometry.AddVertexBuffer( textureVertices ); + texturedQuadGeometry.AddVertexBuffer(positionVertices); + texturedQuadGeometry.AddVertexBuffer(textureVertices); - texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) ); + texturedQuadGeometry.SetIndexBuffer(&indices[0], sizeof(indices) / sizeof(indices[0])); return texturedQuadGeometry; } @@ -425,46 +429,45 @@ Geometry MetaballExplosionController::CreateGeometry( bool aspectMappedTexture ) void MetaballExplosionController::CreateMetaballActors() { // Create the shader for the metaballs, tell DALi that shader modifies geometry so we dont need to set a meaningless size - Shader shader = Shader::New( METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER, Shader::Hint::MODIFIES_GEOMETRY ); + Shader shader = Shader::New(METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER, Shader::Hint::MODIFIES_GEOMETRY); Geometry metaballGeom = CreateGeometry(); // Reuse same renderer for each actor - Renderer renderer = Renderer::New( metaballGeom, shader ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE ); + Renderer renderer = Renderer::New(metaballGeom, shader); + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE); //Initialization of each of the metaballs - for( uint32_t i = 0; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mMetaballs[i].position = Vector2(0.0f, 0.0f); - mMetaballs[i].radius = mMetaballs[i].initRadius = Random::Range(0.05f,0.07f); + mMetaballs[i].radius = mMetaballs[i].initRadius = Random::Range(0.05f, 0.07f); - mMetaballs[i].actor = Actor::New( ); - mMetaballs[i].actor.SetProperty( Dali::Actor::Property::NAME, "Metaball" ); - mMetaballs[i].actor.SetProperty( Actor::Property::SCALE, 1.0f ); - mMetaballs[i].actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mMetaballs[i].actor.AddRenderer( renderer ); + mMetaballs[i].actor = Actor::New(); + mMetaballs[i].actor.SetProperty(Dali::Actor::Property::NAME, "Metaball"); + mMetaballs[i].actor.SetProperty(Actor::Property::SCALE, 1.0f); + mMetaballs[i].actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mMetaballs[i].actor.AddRenderer(renderer); - mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty( "uPositionMetaball", mMetaballs[i].position ); + mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty("uPositionMetaball", mMetaballs[i].position); - mMetaballs[i].positionVarIndex = mMetaballs[i].actor.RegisterProperty( "uPositionVar", Vector2(0.f,0.f) ); + mMetaballs[i].positionVarIndex = mMetaballs[i].actor.RegisterProperty("uPositionVar", Vector2(0.f, 0.f)); - mMetaballs[i].actor.RegisterProperty( "uGravityVector", Vector2(Random::Range(-0.2,0.2),Random::Range(-0.2,0.2)) ); - mMetaballs[i].actor.RegisterProperty( "uRadius", mMetaballs[i].radius ); - mMetaballs[i].actor.RegisterProperty( "uRadiusVar", 0.f ); + mMetaballs[i].actor.RegisterProperty("uGravityVector", Vector2(Random::Range(-0.2, 0.2), Random::Range(-0.2, 0.2))); + mMetaballs[i].actor.RegisterProperty("uRadius", mMetaballs[i].radius); + mMetaballs[i].actor.RegisterProperty("uRadiusVar", 0.f); } // Root creation mMetaballRoot = Actor::New(); - mMetaballRoot.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - for( uint32_t i = 0; i < METABALL_NUMBER; i++ ) + mMetaballRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { - mMetaballRoot.Add( mMetaballs[i].actor ); + mMetaballRoot.Add(mMetaballs[i].actor); } - } void MetaballExplosionController::CreateMetaballImage() @@ -472,183 +475,183 @@ void MetaballExplosionController::CreateMetaballImage() // Create an FBO and a render task to create to render the metaballs with a fragment shader Window window = mApplication.GetWindow(); - mMetaballFBO = FrameBuffer::New( mScreenSize.x, mScreenSize.y ); + mMetaballFBO = FrameBuffer::New(mScreenSize.x, mScreenSize.y); window.Add(mMetaballRoot); // Create the render task used to render the metaballs RenderTaskList taskList = window.GetRenderTaskList(); - RenderTask task = taskList.CreateTask(); - task.SetRefreshRate( RenderTask::REFRESH_ALWAYS ); - task.SetSourceActor( mMetaballRoot ); - task.SetExclusive( true ); - task.SetClearColor( Color::BLACK ); - task.SetClearEnabled( true ); - task.SetFrameBuffer( mMetaballFBO ); + RenderTask task = taskList.CreateTask(); + task.SetRefreshRate(RenderTask::REFRESH_ALWAYS); + task.SetSourceActor(mMetaballRoot); + task.SetExclusive(true); + task.SetClearColor(Color::BLACK); + task.SetClearEnabled(true); + task.SetFrameBuffer(mMetaballFBO); } void MetaballExplosionController::CreateComposition() { //Create new shader - Shader shader = Shader::New( METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER ); + Shader shader = Shader::New(METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER); // Create new texture set auto textureSet = TextureSet::New(); - textureSet.SetTexture( 0u, mBackgroundTexture ); - textureSet.SetTexture( 1u, mMetaballFBO.GetColorTexture() ); + textureSet.SetTexture(0u, mBackgroundTexture); + textureSet.SetTexture(1u, mMetaballFBO.GetColorTexture()); // Create geometry - Geometry metaballGeom = CreateGeometry( false ); + Geometry metaballGeom = CreateGeometry(false); - Renderer mRenderer = Renderer::New( metaballGeom, shader ); - mRenderer.SetTextures( textureSet ); + Renderer mRenderer = Renderer::New(metaballGeom, shader); + mRenderer.SetTextures(textureSet); // Create actor - mCompositionActor = Actor::New( ); - mCompositionActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mCompositionActor.SetProperty( Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); - mCompositionActor.SetProperty( Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y) ); - mCompositionActor.AddRenderer( mRenderer ); + mCompositionActor = Actor::New(); + mCompositionActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCompositionActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); + mCompositionActor.SetProperty(Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y)); + mCompositionActor.AddRenderer(mRenderer); - Vector2 metaballCenter(0.0,0); + Vector2 metaballCenter(0.0, 0); metaballCenter.x = metaballCenter.x * 0.5; metaballCenter.y = metaballCenter.y * 0.5; - mPositionIndex = mCompositionActor.RegisterProperty( "uPositionMetaball", metaballCenter ); + mPositionIndex = mCompositionActor.RegisterProperty("uPositionMetaball", metaballCenter); - SetPositionToMetaballs( metaballCenter ); + SetPositionToMetaballs(metaballCenter); - mCompositionActor.SetProperty( Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y) ); + mCompositionActor.SetProperty(Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y)); Window window = mApplication.GetWindow(); - window.Add( mCompositionActor ); + window.Add(mCompositionActor); } void MetaballExplosionController::CreateAnimations() { Vector2 direction; - for( uint32_t i = 0; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { KeyFrames keySinCosVariation = KeyFrames::New(); - Vector2 sinCosVariation( 0,0 ); + Vector2 sinCosVariation(0, 0); - direction.x = Random::Range( -100.f,100.f ); - direction.y = Random::Range( -100.f,100.f ); + direction.x = Random::Range(-100.f, 100.f); + direction.y = Random::Range(-100.f, 100.f); direction.Normalize(); direction *= 0.1f; - for( uint32_t j = 0; j < 360; j++ ) + for(uint32_t j = 0; j < 360; j++) { - sinCosVariation.x = sinf( j * Math::PI/180.f ) * direction.x; - sinCosVariation.y = cosf( j * Math::PI/180.f ) * direction.y; - float key = j/360.f; - keySinCosVariation.Add( key, sinCosVariation ); + sinCosVariation.x = sinf(j * Math::PI / 180.f) * direction.x; + sinCosVariation.y = cosf(j * Math::PI / 180.f) * direction.y; + float key = j / 360.f; + keySinCosVariation.Add(key, sinCosVariation); } - mPositionVarAnimation[i] = Animation::New( 3.f ); - mPositionVarAnimation[i].AnimateBetween( Property( mMetaballs[i].actor, mMetaballs[i].positionVarIndex ), keySinCosVariation ); - mPositionVarAnimation[i].SetLooping( true ); + mPositionVarAnimation[i] = Animation::New(3.f); + mPositionVarAnimation[i].AnimateBetween(Property(mMetaballs[i].actor, mMetaballs[i].positionVarIndex), keySinCosVariation); + mPositionVarAnimation[i].SetLooping(true); mPositionVarAnimation[i].Play(); } } -void MetaballExplosionController::ResetMetaballs( bool resetAnims ) +void MetaballExplosionController::ResetMetaballs(bool resetAnims) { - for( uint32_t i = 0; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { - if( mDispersionAnimation[i] ) + if(mDispersionAnimation[i]) { mDispersionAnimation[i].Clear(); } - mMetaballs[i].position = Vector2( 0.0f, 0.0f ); - mMetaballs[i].actor.SetProperty( mMetaballs[i].positionIndex, mMetaballs[i].position ); + mMetaballs[i].position = Vector2(0.0f, 0.0f); + mMetaballs[i].actor.SetProperty(mMetaballs[i].positionIndex, mMetaballs[i].position); } mTimerDispersion.Stop(); mDispersion = 0; - mCompositionActor.SetProperty( mPositionIndex, Vector2(0,0) ); + mCompositionActor.SetProperty(mPositionIndex, Vector2(0, 0)); } -void MetaballExplosionController::DisperseBallAnimation( uint32_t ball ) +void MetaballExplosionController::DisperseBallAnimation(uint32_t ball) { Vector2 position; - position.x = Random::Range(-1.5f,1.5f); - position.y = Random::Range(-1.5f,1.5f); + position.x = Random::Range(-1.5f, 1.5f); + position.y = Random::Range(-1.5f, 1.5f); mDispersionAnimation[ball] = Animation::New(2.0f * mTimeMultiplier); - mDispersionAnimation[ball].AnimateTo( Property(mMetaballs[ball].actor, mMetaballs[ball].positionIndex), position); + mDispersionAnimation[ball].AnimateTo(Property(mMetaballs[ball].actor, mMetaballs[ball].positionIndex), position); mDispersionAnimation[ball].Play(); - if( ball == METABALL_NUMBER - 1 ) + if(ball == METABALL_NUMBER - 1) { - mDispersionAnimation[ball].FinishedSignal().Connect( this, &MetaballExplosionController::LaunchResetMetaballPosition ); + mDispersionAnimation[ball].FinishedSignal().Connect(this, &MetaballExplosionController::LaunchResetMetaballPosition); } } -void MetaballExplosionController::LaunchResetMetaballPosition( Animation& source ) +void MetaballExplosionController::LaunchResetMetaballPosition(Animation& source) { - for( uint32_t i = 0; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { - mDispersionAnimation[i] = Animation::New( 1.5f + i * 0.25f * mTimeMultiplier ); - mDispersionAnimation[i].AnimateTo(Property( mMetaballs[i].actor, mMetaballs[i].positionIndex), Vector2(0,0) ); + mDispersionAnimation[i] = Animation::New(1.5f + i * 0.25f * mTimeMultiplier); + mDispersionAnimation[i].AnimateTo(Property(mMetaballs[i].actor, mMetaballs[i].positionIndex), Vector2(0, 0)); mDispersionAnimation[i].Play(); - if( i == METABALL_NUMBER - 1 ) + if(i == METABALL_NUMBER - 1) { - mDispersionAnimation[i].FinishedSignal().Connect( this, &MetaballExplosionController::EndDisperseAnimation ); + mDispersionAnimation[i].FinishedSignal().Connect(this, &MetaballExplosionController::EndDisperseAnimation); } } } -void MetaballExplosionController::EndDisperseAnimation( Animation& source ) +void MetaballExplosionController::EndDisperseAnimation(Animation& source) { - mCompositionActor.SetProperty( mPositionIndex, Vector2(0,0) ); + mCompositionActor.SetProperty(mPositionIndex, Vector2(0, 0)); } bool MetaballExplosionController::OnTimerDispersionTick() { - if( mDispersion < METABALL_NUMBER ) + if(mDispersion < METABALL_NUMBER) { - DisperseBallAnimation( mDispersion ); + DisperseBallAnimation(mDispersion); mDispersion++; } return true; } -void MetaballExplosionController::SetPositionToMetaballs( const Vector2& metaballCenter ) +void MetaballExplosionController::SetPositionToMetaballs(const Vector2& metaballCenter) { //We set the position for the metaballs based on click position - for( uint32_t i = 0; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mMetaballs[i].position = metaballCenter; - mMetaballs[i].actor.SetProperty( mMetaballs[i].positionIndex, mMetaballs[i].position ); + mMetaballs[i].actor.SetProperty(mMetaballs[i].positionIndex, mMetaballs[i].position); } - mCompositionActor.SetProperty( mPositionIndex, metaballCenter ); + mCompositionActor.SetProperty(mPositionIndex, metaballCenter); } -bool MetaballExplosionController::OnTouch( Actor actor, const TouchEvent& touch ) +bool MetaballExplosionController::OnTouch(Actor actor, const TouchEvent& touch) { float aspectR = mScreenSize.y / mScreenSize.x; - switch( touch.GetState( 0 ) ) + switch(touch.GetState(0)) { case PointState::DOWN: { ResetMetaballs(true); - const Vector2 screen = touch.GetScreenPosition( 0 ); - Vector2 metaballCenter = Vector2( (screen.x / mScreenSize.x) - 0.5f, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5f ) * 2.0f; + const Vector2 screen = touch.GetScreenPosition(0); + Vector2 metaballCenter = Vector2((screen.x / mScreenSize.x) - 0.5f, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5f) * 2.0f; SetPositionToMetaballs(metaballCenter); break; } case PointState::MOTION: { - const Vector2 screen = touch.GetScreenPosition( 0 ); - Vector2 metaballCenter = Vector2( (screen.x / mScreenSize.x) - 0.5f, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5f ) * 2.0f; + const Vector2 screen = touch.GetScreenPosition(0); + Vector2 metaballCenter = Vector2((screen.x / mScreenSize.x) - 0.5f, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5f) * 2.0f; SetPositionToMetaballs(metaballCenter); break; } @@ -661,7 +664,7 @@ bool MetaballExplosionController::OnTouch( Actor actor, const TouchEvent& touch } default: break; - } + } return true; } @@ -669,7 +672,7 @@ void MetaballExplosionController::OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -679,11 +682,11 @@ void MetaballExplosionController::OnKeyEvent(const KeyEvent& event) /** * Main entry point */ -int32_t DALI_EXPORT_API main( int argc, char **argv ) +int32_t DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - MetaballExplosionController test( application ); + MetaballExplosionController test(application); application.MainLoop(); diff --git a/examples/metaball-refrac/metaball-refrac-example.cpp b/examples/metaball-refrac/metaball-refrac-example.cpp index 021a2ac..1d1c046 100644 --- a/examples/metaball-refrac/metaball-refrac-example.cpp +++ b/examples/metaball-refrac/metaball-refrac-example.cpp @@ -16,14 +16,14 @@ */ // EXTERNAL INCLUDES +#include // uint32_t, uint16_t etc #include #include -#include // uint32_t, uint16_t etc +#include #include -#include #include -#include +#include // INTERNAL INCLUDES #include "shared/utility.h" // DemoHelper::LoadTexture @@ -32,13 +32,15 @@ using namespace Dali; namespace // unnamed namespace for constants { -const char * const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-2.jpg" ); -const float GRAVITY_X(0); -const float GRAVITY_Y(-0.09); +const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-2.jpg"); +const float GRAVITY_X(0); +const float GRAVITY_Y(-0.09); // number of metaballs constexpr uint32_t METABALL_NUMBER = 6; +// clang-format off + /** * Vertex shader for metaballs */ @@ -146,6 +148,7 @@ const char* const FRAG_SHADER = DALI_COMPOSE_SHADER ( gl_FragColor = texture2D(sTexture, vTexCoord);\n }\n ); +// clang-format on /** * Metadata for each ball @@ -176,12 +179,11 @@ struct MetaballInfo class MetaballRefracController : public ConnectionTracker { public: - /** * Constructor * @param application */ - MetaballRefracController( Application& application ); + MetaballRefracController(Application& application); /** * Destructor @@ -191,54 +193,53 @@ public: /** * Creates the metaballs and initializes the scene */ - void Create( Application& app ); + void Create(Application& app); /** * Touch handler, start the grow animation and creates additional metaballs */ - bool OnTouch( Actor actor, const TouchEvent& touch ); + bool OnTouch(Actor actor, const TouchEvent& touch); /** * Key event callback to quit the application on escape or back key */ - void OnKeyEvent( const KeyEvent& event ); + void OnKeyEvent(const KeyEvent& event); private: // Data + Application& mApplication; + Vector2 mScreenSize; - Application& mApplication; - Vector2 mScreenSize; - - Texture mBackgroundTexture; - FrameBuffer mMetaballFBO; + Texture mBackgroundTexture; + FrameBuffer mMetaballFBO; - Actor mMetaballRoot; - MetaballInfo mMetaballs[METABALL_NUMBER]; + Actor mMetaballRoot; + MetaballInfo mMetaballs[METABALL_NUMBER]; - Actor mCompositionActor; + Actor mCompositionActor; //Motion - Vector2 mCurrentTouchPosition; - Vector2 mMetaballPosVariation; - Vector2 mMetaballPosVariationFrom; - Vector2 mMetaballPosVariationTo; - Vector2 mMetaballCenter; + Vector2 mCurrentTouchPosition; + Vector2 mMetaballPosVariation; + Vector2 mMetaballPosVariationFrom; + Vector2 mMetaballPosVariationTo; + Vector2 mMetaballCenter; - Vector2 mGravity; - Vector2 mGravityVar; + Vector2 mGravity; + Vector2 mGravityVar; - Renderer mRendererRefraction; - TextureSet mTextureSetRefraction; - Shader mShaderRefraction; - TextureSet mTextureSetNormal; - Shader mShaderNormal; + Renderer mRendererRefraction; + TextureSet mTextureSetRefraction; + Shader mShaderRefraction; + TextureSet mTextureSetNormal; + Shader mShaderNormal; // Animations - Animation mGravityAnimation[METABALL_NUMBER]; - Animation mRadiusDecAnimation[METABALL_NUMBER]; - Animation mRadiusIncFastAnimation[METABALL_NUMBER]; - Animation mRadiusIncSlowAnimation[METABALL_NUMBER]; - Animation mRadiusVarAnimation[METABALL_NUMBER]; - Animation mPositionVarAnimation[METABALL_NUMBER]; + Animation mGravityAnimation[METABALL_NUMBER]; + Animation mRadiusDecAnimation[METABALL_NUMBER]; + Animation mRadiusIncFastAnimation[METABALL_NUMBER]; + Animation mRadiusIncSlowAnimation[METABALL_NUMBER]; + Animation mRadiusVarAnimation[METABALL_NUMBER]; + Animation mPositionVarAnimation[METABALL_NUMBER]; // Private Helper functions @@ -246,7 +247,7 @@ private: // Data * Create a mesh data with the geometry for the metaball rendering * @param aspectMappedTexture whether texture coords should be mapped based on aspect ratio */ - Geometry CreateGeometry( bool aspectMappedTexture = true ); + Geometry CreateGeometry(bool aspectMappedTexture = true); /** * Create a actor for the metaballs @@ -271,12 +272,12 @@ private: // Data /** * Function to launch the grow slow radius for the metaballs, and also the small variations for metaball[2] and [3] */ - void LaunchRadiusIncSlowAnimations( Animation& source ); + void LaunchRadiusIncSlowAnimations(Animation& source); /** * Function to launch the animation to get the metaball[1] back to the center */ - void LaunchGetBackToPositionAnimation( Animation& source ); + void LaunchGetBackToPositionAnimation(Animation& source); /** * Function to stop all animations related to the click of the user in the screen @@ -296,19 +297,18 @@ private: // Data /** * Function to set the actual position of the metaballs when the user clicks the screen */ - void SetPositionToMetaballs( const Vector2& metaballCenter ); - + void SetPositionToMetaballs(const Vector2& metaballCenter); }; /** * Implementation */ -MetaballRefracController::MetaballRefracController( Application& application ) - : mApplication( application ) +MetaballRefracController::MetaballRefracController(Application& application) +: mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &MetaballRefracController::Create ); + mApplication.InitSignal().Connect(this, &MetaballRefracController::Create); } MetaballRefracController::~MetaballRefracController() @@ -316,21 +316,21 @@ MetaballRefracController::~MetaballRefracController() // Nothing to do here; } -void MetaballRefracController::Create( Application& app ) +void MetaballRefracController::Create(Application& app) { Window window = app.GetWindow(); - window.KeyEventSignal().Connect( this, &MetaballRefracController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &MetaballRefracController::OnKeyEvent); mScreenSize = window.GetSize(); window.SetBackgroundColor(Color::BLACK); // Load background texture - mBackgroundTexture = DemoHelper::LoadTexture( BACKGROUND_IMAGE ); + mBackgroundTexture = DemoHelper::LoadTexture(BACKGROUND_IMAGE); - mGravity = Vector2(GRAVITY_X,GRAVITY_Y); - mGravityVar = Vector2(0,0); + mGravity = Vector2(GRAVITY_X, GRAVITY_Y); + mGravityVar = Vector2(0, 0); CreateMetaballActors(); CreateMetaballImage(); @@ -338,10 +338,10 @@ void MetaballRefracController::Create( Application& app ) CreateAnimations(); // Connect the callback to the touch signal on the mesh actor - window.GetRootLayer().TouchedSignal().Connect( this, &MetaballRefracController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &MetaballRefracController::OnTouch); } -Geometry MetaballRefracController::CreateGeometry( bool aspectMappedTexture ) +Geometry MetaballRefracController::CreateGeometry(bool aspectMappedTexture) { const float aspect = mScreenSize.y / mScreenSize.x; @@ -349,49 +349,53 @@ Geometry MetaballRefracController::CreateGeometry( bool aspectMappedTexture ) const float xsize = mScreenSize.x * 0.5; // Create the meshdata for the metaballs - struct VertexPosition { Vector2 position; }; - struct VertexTexture { Vector2 texture; }; - - VertexPosition vertices[] = + struct VertexPosition { - { Vector2( -xsize, -xsize * aspect ) }, - { Vector2( xsize, -xsize * aspect ) }, - { Vector2( -xsize, xsize * aspect ) }, - { Vector2( xsize, xsize * aspect ) } + Vector2 position; }; - - const float textureAspect = (aspectMappedTexture) ? aspect : 1.0f; - VertexTexture textures[] = + struct VertexTexture { - { Vector2( 0.0f, 0.0f ) }, - { Vector2( 1.0f, 0.0f ) }, - { Vector2( 0.0f, 1.0f * textureAspect ) }, - { Vector2( 1.0f, 1.0f * textureAspect ) } + Vector2 texture; }; - uint32_t numberOfVertices = sizeof(vertices)/sizeof(VertexPosition); + VertexPosition vertices[] = + { + {Vector2(-xsize, -xsize * aspect)}, + {Vector2(xsize, -xsize * aspect)}, + {Vector2(-xsize, xsize * aspect)}, + {Vector2(xsize, xsize * aspect)}}; + + const float textureAspect = (aspectMappedTexture) ? aspect : 1.0f; + VertexTexture textures[] = + { + {Vector2(0.0f, 0.0f)}, + {Vector2(1.0f, 0.0f)}, + {Vector2(0.0f, 1.0f * textureAspect)}, + {Vector2(1.0f, 1.0f * textureAspect)}}; + + uint32_t numberOfVertices = sizeof(vertices) / sizeof(VertexPosition); // Vertices Property::Map positionVertexFormat; positionVertexFormat["aPosition"] = Property::VECTOR2; - VertexBuffer positionVertices = VertexBuffer::New( positionVertexFormat ); - positionVertices.SetData( vertices, numberOfVertices ); + VertexBuffer positionVertices = VertexBuffer::New(positionVertexFormat); + positionVertices.SetData(vertices, numberOfVertices); // Textures Property::Map textureVertexFormat; textureVertexFormat["aTexture"] = Property::VECTOR2; - VertexBuffer textureVertices = VertexBuffer::New( textureVertexFormat ); - textureVertices.SetData( textures, numberOfVertices ); + VertexBuffer textureVertices = VertexBuffer::New(textureVertexFormat); + textureVertices.SetData(textures, numberOfVertices); // Indices - const uint16_t indices[] = { 0, 3, 1, 0, 2, 3 }; + const uint16_t indices[] = {0, 3, 1, 0, 2, 3}; // Create the geometry object Geometry texturedQuadGeometry = Geometry::New(); - texturedQuadGeometry.AddVertexBuffer( positionVertices ); - texturedQuadGeometry.AddVertexBuffer( textureVertices ); + texturedQuadGeometry.AddVertexBuffer(positionVertices); + texturedQuadGeometry.AddVertexBuffer(textureVertices); - texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) ); + texturedQuadGeometry.SetIndexBuffer(&indices[0], sizeof(indices) / sizeof(indices[0])); return texturedQuadGeometry; } @@ -401,14 +405,14 @@ void MetaballRefracController::CreateMetaballActors() const float aspect = mScreenSize.y / mScreenSize.x; // Create the renderer for the metaballs - Shader shader = Shader::New( METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER, Shader::Hint::MODIFIES_GEOMETRY ); + Shader shader = Shader::New(METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER, Shader::Hint::MODIFIES_GEOMETRY); Geometry metaballGeometry = CreateGeometry(); - Renderer renderer = Renderer::New( metaballGeometry, shader ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE ); + Renderer renderer = Renderer::New(metaballGeometry, shader); + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE); // Each metaball has a different radius mMetaballs[0].radius = mMetaballs[0].initRadius = 0.0145f; @@ -417,32 +421,31 @@ void MetaballRefracController::CreateMetaballActors() mMetaballs[3].radius = mMetaballs[3].initRadius = 0.0135f; // Initialization of each of the metaballs - for( uint32_t i = 0 ; i < METABALL_NUMBER ; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mMetaballs[i].position = Vector2(0.0f, 0.0f); mMetaballs[i].actor = Actor::New(); - mMetaballs[i].actor.SetProperty( Dali::Actor::Property::NAME, "Metaball" ); - mMetaballs[i].actor.SetProperty( Actor::Property::SCALE, 1.0f ); - mMetaballs[i].actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - - - mMetaballs[i].actor.AddRenderer( renderer ); - - mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty( "uPositionMetaball", mMetaballs[i].position ); - mMetaballs[i].positionVarIndex = mMetaballs[i].actor.RegisterProperty( "uPositionVar", Vector2(0.f,0.f) ); - mMetaballs[i].gravityIndex = mMetaballs[i].actor.RegisterProperty( "uGravityVector", Vector2(0.f,0.f) ); - mMetaballs[i].radiusIndex = mMetaballs[i].actor.RegisterProperty( "uRadius", mMetaballs[i].radius ); - mMetaballs[i].radiusVarIndex = mMetaballs[i].actor.RegisterProperty( "uRadiusVar", 0.f ); - mMetaballs[i].aspectIndex = mMetaballs[i].actor.RegisterProperty( "uAspect", aspect ); + mMetaballs[i].actor.SetProperty(Dali::Actor::Property::NAME, "Metaball"); + mMetaballs[i].actor.SetProperty(Actor::Property::SCALE, 1.0f); + mMetaballs[i].actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + + mMetaballs[i].actor.AddRenderer(renderer); + + mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty("uPositionMetaball", mMetaballs[i].position); + mMetaballs[i].positionVarIndex = mMetaballs[i].actor.RegisterProperty("uPositionVar", Vector2(0.f, 0.f)); + mMetaballs[i].gravityIndex = mMetaballs[i].actor.RegisterProperty("uGravityVector", Vector2(0.f, 0.f)); + mMetaballs[i].radiusIndex = mMetaballs[i].actor.RegisterProperty("uRadius", mMetaballs[i].radius); + mMetaballs[i].radiusVarIndex = mMetaballs[i].actor.RegisterProperty("uRadiusVar", 0.f); + mMetaballs[i].aspectIndex = mMetaballs[i].actor.RegisterProperty("uAspect", aspect); } //Root creation mMetaballRoot = Actor::New(); - mMetaballRoot.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - for( uint32_t i = 0 ; i < METABALL_NUMBER ; i++ ) + mMetaballRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { - mMetaballRoot.Add( mMetaballs[i].actor ); + mMetaballRoot.Add(mMetaballs[i].actor); } } @@ -450,174 +453,174 @@ void MetaballRefracController::CreateMetaballImage() { // Create an FBO and a render task to create to render the metaballs with a fragment shader Window window = mApplication.GetWindow(); - mMetaballFBO = FrameBuffer::New( mScreenSize.x, mScreenSize.y ); + mMetaballFBO = FrameBuffer::New(mScreenSize.x, mScreenSize.y); window.Add(mMetaballRoot); //Creation of the render task used to render the metaballs RenderTaskList taskList = window.GetRenderTaskList(); - RenderTask task = taskList.CreateTask(); - task.SetRefreshRate( RenderTask::REFRESH_ALWAYS ); - task.SetSourceActor( mMetaballRoot ); - task.SetExclusive( true ); - task.SetClearColor( Color::BLACK ); - task.SetClearEnabled( true ); - task.SetFrameBuffer( mMetaballFBO ); + RenderTask task = taskList.CreateTask(); + task.SetRefreshRate(RenderTask::REFRESH_ALWAYS); + task.SetSourceActor(mMetaballRoot); + task.SetExclusive(true); + task.SetClearColor(Color::BLACK); + task.SetClearEnabled(true); + task.SetFrameBuffer(mMetaballFBO); } void MetaballRefracController::CreateComposition() { // Create Refraction shader and renderer - mShaderRefraction = Shader::New( METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER ); + mShaderRefraction = Shader::New(METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER); // Create new texture set mTextureSetRefraction = TextureSet::New(); - mTextureSetRefraction.SetTexture( 0u, mBackgroundTexture ); - mTextureSetRefraction.SetTexture( 1u, mMetaballFBO.GetColorTexture() ); + mTextureSetRefraction.SetTexture(0u, mBackgroundTexture); + mTextureSetRefraction.SetTexture(1u, mMetaballFBO.GetColorTexture()); // Create normal shader - mShaderNormal = Shader::New( METABALL_VERTEX_SHADER, FRAG_SHADER ); + mShaderNormal = Shader::New(METABALL_VERTEX_SHADER, FRAG_SHADER); // Create new texture set mTextureSetNormal = TextureSet::New(); - mTextureSetNormal.SetTexture( 0u, mBackgroundTexture ); + mTextureSetNormal.SetTexture(0u, mBackgroundTexture); // Create actor - mCompositionActor = Actor::New( ); - mCompositionActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mCompositionActor.SetProperty( Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); - mCompositionActor.SetProperty( Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y) ); + mCompositionActor = Actor::New(); + mCompositionActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCompositionActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); + mCompositionActor.SetProperty(Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y)); // Create geometry - Geometry metaballGeometry = CreateGeometry( false ); - mRendererRefraction = Renderer::New( metaballGeometry, mShaderNormal ); - mRendererRefraction.SetTextures( mTextureSetNormal ); - mCompositionActor.AddRenderer( mRendererRefraction ); + Geometry metaballGeometry = CreateGeometry(false); + mRendererRefraction = Renderer::New(metaballGeometry, mShaderNormal); + mRendererRefraction.SetTextures(mTextureSetNormal); + mCompositionActor.AddRenderer(mRendererRefraction); Window window = mApplication.GetWindow(); - window.Add( mCompositionActor ); + window.Add(mCompositionActor); } void MetaballRefracController::CreateAnimations() { uint32_t i = 0; - float key; + float key; - mPositionVarAnimation[1] = Animation::New( 2.f ); - mPositionVarAnimation[1].SetLooping( false ); + mPositionVarAnimation[1] = Animation::New(2.f); + mPositionVarAnimation[1].SetLooping(false); mPositionVarAnimation[1].Pause(); - mPositionVarAnimation[1].FinishedSignal().Connect( this, &MetaballRefracController::LaunchGetBackToPositionAnimation ); + mPositionVarAnimation[1].FinishedSignal().Connect(this, &MetaballRefracController::LaunchGetBackToPositionAnimation); KeyFrames keySinCosVariation = KeyFrames::New(); - Vector2 sinCosVariation(0,0); - for( i = 0 ; i < 360; i++ ) + Vector2 sinCosVariation(0, 0); + for(i = 0; i < 360; i++) { - sinCosVariation.x = 0.05f * ( -sinf(i * Math::PI_OVER_180) + cosf(i * Math::PI_OVER_180) ); - sinCosVariation.y = 0.05f * ( sinf(i * Math::PI_OVER_180) - cosf(i * Math::PI_OVER_180) ); - key = i/360.f; + sinCosVariation.x = 0.05f * (-sinf(i * Math::PI_OVER_180) + cosf(i * Math::PI_OVER_180)); + sinCosVariation.y = 0.05f * (sinf(i * Math::PI_OVER_180) - cosf(i * Math::PI_OVER_180)); + key = i / 360.f; keySinCosVariation.Add(key, sinCosVariation); } mPositionVarAnimation[2] = Animation::New(6.f); - mPositionVarAnimation[2].AnimateBetween(Property( mMetaballs[2].actor, mMetaballs[2].positionVarIndex ), keySinCosVariation); - mPositionVarAnimation[2].SetLooping( true ); + mPositionVarAnimation[2].AnimateBetween(Property(mMetaballs[2].actor, mMetaballs[2].positionVarIndex), keySinCosVariation); + mPositionVarAnimation[2].SetLooping(true); mPositionVarAnimation[2].Pause(); KeyFrames keyCosSinVariation = KeyFrames::New(); - Vector2 cosSinVariation(0,0); - for( i = 0 ; i < 360; i++ ) + Vector2 cosSinVariation(0, 0); + for(i = 0; i < 360; i++) { - cosSinVariation.x = 0.05f * ( -sinf(i * Math::PI_OVER_180) - cosf(i * Math::PI_OVER_180) ); - cosSinVariation.y = 0.05f * ( sinf(i * Math::PI_OVER_180) + cosf(i * Math::PI_OVER_180) ); - key = i/360.f; + cosSinVariation.x = 0.05f * (-sinf(i * Math::PI_OVER_180) - cosf(i * Math::PI_OVER_180)); + cosSinVariation.y = 0.05f * (sinf(i * Math::PI_OVER_180) + cosf(i * Math::PI_OVER_180)); + key = i / 360.f; keyCosSinVariation.Add(key, cosSinVariation); } mPositionVarAnimation[3] = Animation::New(6.f); - mPositionVarAnimation[3].AnimateBetween(Property( mMetaballs[3].actor, mMetaballs[3].positionVarIndex ), keyCosSinVariation); - mPositionVarAnimation[3].SetLooping( true ); + mPositionVarAnimation[3].AnimateBetween(Property(mMetaballs[3].actor, mMetaballs[3].positionVarIndex), keyCosSinVariation); + mPositionVarAnimation[3].SetLooping(true); mPositionVarAnimation[3].Pause(); //Animations for gravity - for( i = 0 ; i < METABALL_NUMBER; i++ ) + for(i = 0; i < METABALL_NUMBER; i++) { - mGravityAnimation[i] = Animation::New( 25.f ); - mGravityAnimation[i].AnimateBy( Property( mMetaballs[i].actor, mMetaballs[i].gravityIndex ), mGravity * 25.f * 3.f ); - mGravityAnimation[i].SetLooping( false ); + mGravityAnimation[i] = Animation::New(25.f); + mGravityAnimation[i].AnimateBy(Property(mMetaballs[i].actor, mMetaballs[i].gravityIndex), mGravity * 25.f * 3.f); + mGravityAnimation[i].SetLooping(false); mGravityAnimation[i].Pause(); } //Animation to decrease size of metaballs when there is no click - for( i = 0 ; i < METABALL_NUMBER; i++ ) + for(i = 0; i < METABALL_NUMBER; i++) { - mRadiusDecAnimation[i] = Animation::New( 25.f ); - mRadiusDecAnimation[i].AnimateBy( Property( mMetaballs[i].actor, mMetaballs[i].radiusIndex ), -0.004f * 25.f * 3.f ); - mRadiusDecAnimation[i].SetLooping( false ); + mRadiusDecAnimation[i] = Animation::New(25.f); + mRadiusDecAnimation[i].AnimateBy(Property(mMetaballs[i].actor, mMetaballs[i].radiusIndex), -0.004f * 25.f * 3.f); + mRadiusDecAnimation[i].SetLooping(false); mRadiusDecAnimation[i].Pause(); } // Animation to grow the size of the metaballs the first second of the click - for( i = 0 ; i < METABALL_NUMBER; i++ ) + for(i = 0; i < METABALL_NUMBER; i++) { - mRadiusIncFastAnimation[i] = Animation::New( 0.3f ); - mRadiusIncFastAnimation[i].AnimateBy( Property( mMetaballs[i].actor, mMetaballs[i].radiusIndex ), 0.06f ); - mRadiusIncFastAnimation[i].SetLooping( false ); + mRadiusIncFastAnimation[i] = Animation::New(0.3f); + mRadiusIncFastAnimation[i].AnimateBy(Property(mMetaballs[i].actor, mMetaballs[i].radiusIndex), 0.06f); + mRadiusIncFastAnimation[i].SetLooping(false); mRadiusIncFastAnimation[i].Pause(); } - mRadiusIncFastAnimation[0].FinishedSignal().Connect( this, &MetaballRefracController::LaunchRadiusIncSlowAnimations ); + mRadiusIncFastAnimation[0].FinishedSignal().Connect(this, &MetaballRefracController::LaunchRadiusIncSlowAnimations); // Animation to grow the size of the metaballs afterwards - for( i = 0 ; i < METABALL_NUMBER; i++ ) + for(i = 0; i < METABALL_NUMBER; i++) { - mRadiusIncSlowAnimation[i] = Animation::New( 20.f ); - mRadiusIncSlowAnimation[i].AnimateBy( Property( mMetaballs[i].actor, mMetaballs[i].radiusIndex ), 0.04f ); - mRadiusIncSlowAnimation[i].SetLooping( false ); + mRadiusIncSlowAnimation[i] = Animation::New(20.f); + mRadiusIncSlowAnimation[i].AnimateBy(Property(mMetaballs[i].actor, mMetaballs[i].radiusIndex), 0.04f); + mRadiusIncSlowAnimation[i].SetLooping(false); mRadiusIncSlowAnimation[i].Pause(); } // Keyframes of a sin function KeyFrames keySin = KeyFrames::New(); - float val; - for( i = 0 ; i < 360; i++ ) + float val; + for(i = 0; i < 360; i++) { - val = 0.01f * sin(i * Math::PI/180.f); - key = i/360.f; + val = 0.01f * sin(i * Math::PI / 180.f); + key = i / 360.f; keySin.Add(key, val); } //Animation to change the size of the metaball - mRadiusVarAnimation[2] = Animation::New( 8.f ); - mRadiusVarAnimation[2].AnimateBetween( Property( mMetaballs[2].actor, mMetaballs[2].radiusVarIndex ), keySin ); - mRadiusVarAnimation[2].SetLooping( true ); + mRadiusVarAnimation[2] = Animation::New(8.f); + mRadiusVarAnimation[2].AnimateBetween(Property(mMetaballs[2].actor, mMetaballs[2].radiusVarIndex), keySin); + mRadiusVarAnimation[2].SetLooping(true); // Keyframes of a cos function KeyFrames keyCos = KeyFrames::New(); - for( i = 0 ; i < 360; i++ ) + for(i = 0; i < 360; i++) { - val = 0.01f * cos(i * Math::PI/180.f); - key = i/360.f; + val = 0.01f * cos(i * Math::PI / 180.f); + key = i / 360.f; keyCos.Add(key, val); } //Animation to change the size of the metaball - mRadiusVarAnimation[3] = Animation::New( 8.f ); - mRadiusVarAnimation[3].AnimateBetween( Property( mMetaballs[3].actor, mMetaballs[3].radiusVarIndex ), keyCos ); - mRadiusVarAnimation[3].SetLooping( true ); + mRadiusVarAnimation[3] = Animation::New(8.f); + mRadiusVarAnimation[3].AnimateBetween(Property(mMetaballs[3].actor, mMetaballs[3].radiusVarIndex), keyCos); + mRadiusVarAnimation[3].SetLooping(true); } -void MetaballRefracController::LaunchGetBackToPositionAnimation( Animation& source ) +void MetaballRefracController::LaunchGetBackToPositionAnimation(Animation& source) { - mMetaballPosVariationTo = Vector2(0,0); + mMetaballPosVariationTo = Vector2(0, 0); - mPositionVarAnimation[1] = Animation::New( 1.f ); - mPositionVarAnimation[1].SetLooping( false ); - mPositionVarAnimation[1].AnimateTo(Property( mMetaballs[1].actor, mMetaballs[1].positionVarIndex ), Vector2(0,0) ); + mPositionVarAnimation[1] = Animation::New(1.f); + mPositionVarAnimation[1].SetLooping(false); + mPositionVarAnimation[1].AnimateTo(Property(mMetaballs[1].actor, mMetaballs[1].positionVarIndex), Vector2(0, 0)); mPositionVarAnimation[1].Play(); } -void MetaballRefracController::LaunchRadiusIncSlowAnimations( Animation& source ) +void MetaballRefracController::LaunchRadiusIncSlowAnimations(Animation& source) { - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mRadiusIncSlowAnimation[i].Play(); } @@ -627,7 +630,7 @@ void MetaballRefracController::LaunchRadiusIncSlowAnimations( Animation& source void MetaballRefracController::StopClickAnimations() { - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mRadiusIncSlowAnimation[i].Stop(); mRadiusIncFastAnimation[i].Stop(); @@ -639,16 +642,16 @@ void MetaballRefracController::StopClickAnimations() void MetaballRefracController::StopAfterClickAnimations() { - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mGravityAnimation[i].Stop(); mRadiusDecAnimation[i].Stop(); mMetaballs[i].radius = mMetaballs[i].initRadius; - mMetaballs[i].actor.SetProperty( mMetaballs[i].gravityIndex, Vector2(0,0) ); - mMetaballs[i].actor.SetProperty( mMetaballs[i].radiusIndex, mMetaballs[i].radius ); - mMetaballs[i].actor.SetProperty( mMetaballs[i].radiusVarIndex, 0.f ); + mMetaballs[i].actor.SetProperty(mMetaballs[i].gravityIndex, Vector2(0, 0)); + mMetaballs[i].actor.SetProperty(mMetaballs[i].radiusIndex, mMetaballs[i].radius); + mMetaballs[i].actor.SetProperty(mMetaballs[i].radiusVarIndex, 0.f); } mRadiusVarAnimation[2].Stop(); mRadiusVarAnimation[3].Stop(); @@ -656,39 +659,39 @@ void MetaballRefracController::StopAfterClickAnimations() void MetaballRefracController::ResetMetaballsState() { - mRendererRefraction.SetTextures( mTextureSetNormal ); - mRendererRefraction.SetShader( mShaderNormal ); + mRendererRefraction.SetTextures(mTextureSetNormal); + mRendererRefraction.SetShader(mShaderNormal); - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mMetaballs[i].radius = mMetaballs[i].initRadius; } - mMetaballPosVariationTo = Vector2(0,0); - mMetaballPosVariationFrom = Vector2(0,0); - mMetaballPosVariation = Vector2(0,0); - mGravityVar = Vector2(0,0); + mMetaballPosVariationTo = Vector2(0, 0); + mMetaballPosVariationFrom = Vector2(0, 0); + mMetaballPosVariation = Vector2(0, 0); + mGravityVar = Vector2(0, 0); } -void MetaballRefracController::SetPositionToMetaballs( const Vector2& metaballCenter ) +void MetaballRefracController::SetPositionToMetaballs(const Vector2& metaballCenter) { //We set the position for the metaballs based on click position - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mMetaballs[i].position = metaballCenter; - mMetaballs[i].actor.SetProperty( mMetaballs[i].positionIndex, mMetaballs[i].position ); + mMetaballs[i].actor.SetProperty(mMetaballs[i].positionIndex, mMetaballs[i].position); } } -bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch ) +bool MetaballRefracController::OnTouch(Actor actor, const TouchEvent& touch) { const float aspect = mScreenSize.y / mScreenSize.x; - switch( touch.GetState( 0 ) ) + switch(touch.GetState(0)) { case PointState::DOWN: { StopAfterClickAnimations(); - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mRadiusIncFastAnimation[i].Play(); } @@ -696,39 +699,41 @@ bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch ) mRadiusVarAnimation[3].Play(); //We draw with the refraction-composition shader - mRendererRefraction.SetTextures( mTextureSetRefraction ); - mRendererRefraction.SetShader( mShaderRefraction ); - mCurrentTouchPosition = touch.GetScreenPosition( 0 ); + mRendererRefraction.SetTextures(mTextureSetRefraction); + mRendererRefraction.SetShader(mShaderRefraction); + mCurrentTouchPosition = touch.GetScreenPosition(0); //we use the click position for the metaballs - Vector2 metaballCenter = Vector2( (mCurrentTouchPosition.x / mScreenSize.x) - 0.5f, - (aspect * (mScreenSize.y - mCurrentTouchPosition.y) / mScreenSize.y) - 0.5f ) * 2.0f; + Vector2 metaballCenter = Vector2((mCurrentTouchPosition.x / mScreenSize.x) - 0.5f, + (aspect * (mScreenSize.y - mCurrentTouchPosition.y) / mScreenSize.y) - 0.5f) * + 2.0f; SetPositionToMetaballs(metaballCenter); break; } case PointState::MOTION: { - Vector2 screen = touch.GetScreenPosition( 0 ); - Vector2 displacement = screen - mCurrentTouchPosition; + Vector2 screen = touch.GetScreenPosition(0); + Vector2 displacement = screen - mCurrentTouchPosition; mCurrentTouchPosition = screen; - mMetaballPosVariationTo.x += ( displacement.x / mScreenSize.x ) * 2.2f; - mMetaballPosVariationTo.y += (-displacement.y / mScreenSize.y ) * 2.2f; + mMetaballPosVariationTo.x += (displacement.x / mScreenSize.x) * 2.2f; + mMetaballPosVariationTo.y += (-displacement.y / mScreenSize.y) * 2.2f; - if (mPositionVarAnimation[1]) + if(mPositionVarAnimation[1]) { - mPositionVarAnimation[1].FinishedSignal().Disconnect( this, &MetaballRefracController::LaunchGetBackToPositionAnimation ); + mPositionVarAnimation[1].FinishedSignal().Disconnect(this, &MetaballRefracController::LaunchGetBackToPositionAnimation); mPositionVarAnimation[1].Stop(); } - mPositionVarAnimation[1] = Animation::New( 1.f ); - mPositionVarAnimation[1].SetLooping( false ); - mPositionVarAnimation[1].AnimateTo(Property( mMetaballs[1].actor, mMetaballs[1].positionVarIndex ), mMetaballPosVariationTo ); - mPositionVarAnimation[1].FinishedSignal().Connect( this, &MetaballRefracController::LaunchGetBackToPositionAnimation ); + mPositionVarAnimation[1] = Animation::New(1.f); + mPositionVarAnimation[1].SetLooping(false); + mPositionVarAnimation[1].AnimateTo(Property(mMetaballs[1].actor, mMetaballs[1].positionVarIndex), mMetaballPosVariationTo); + mPositionVarAnimation[1].FinishedSignal().Connect(this, &MetaballRefracController::LaunchGetBackToPositionAnimation); mPositionVarAnimation[1].Play(); //we use the click position for the metaballs - Vector2 metaballCenter = Vector2( (screen.x / mScreenSize.x) - 0.5f, - (aspect * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5f) * 2.0f; + Vector2 metaballCenter = Vector2((screen.x / mScreenSize.x) - 0.5f, + (aspect * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5f) * + 2.0f; SetPositionToMetaballs(metaballCenter); break; } @@ -740,12 +745,12 @@ bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch ) StopClickAnimations(); //Launch out of screen animations - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mGravityAnimation[i].Play(); } - for( uint32_t i = 0 ; i < METABALL_NUMBER; i++ ) + for(uint32_t i = 0; i < METABALL_NUMBER; i++) { mRadiusDecAnimation[i].Play(); } @@ -753,15 +758,15 @@ bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch ) } default: break; - } + } return true; } void MetaballRefracController::OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -771,11 +776,11 @@ void MetaballRefracController::OnKeyEvent(const KeyEvent& event) /** * Main entry point */ -int32_t DALI_EXPORT_API main( int argc, char **argv ) +int32_t DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - MetaballRefracController test( application ); + MetaballRefracController test(application); application.MainLoop(); return 0; diff --git a/examples/model3d-view/model3d-view-example.cpp b/examples/model3d-view/model3d-view-example.cpp old mode 100755 new mode 100644 index 2b1c08a..d8d0316 --- a/examples/model3d-view/model3d-view-example.cpp +++ b/examples/model3d-view/model3d-view-example.cpp @@ -24,23 +24,21 @@ namespace { const int MODEL_NUMBER(3); -const char * const MODEL_FILE[] = { - DEMO_MODEL_DIR "Dino.obj", - DEMO_MODEL_DIR "ToyRobot-Metal.obj", - DEMO_MODEL_DIR "Toyrobot-Plastic.obj" -}; +const char* const MODEL_FILE[] = { + DEMO_MODEL_DIR "Dino.obj", + DEMO_MODEL_DIR "ToyRobot-Metal.obj", + DEMO_MODEL_DIR "Toyrobot-Plastic.obj"}; -const char * const MATERIAL_FILE[] = { - DEMO_MODEL_DIR "Dino.mtl", - DEMO_MODEL_DIR "ToyRobot-Metal.mtl", - DEMO_MODEL_DIR "Toyrobot-Plastic.mtl" -}; +const char* const MATERIAL_FILE[] = { + DEMO_MODEL_DIR "Dino.mtl", + DEMO_MODEL_DIR "ToyRobot-Metal.mtl", + DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"}; -const char * const IMAGE_PATH( DEMO_IMAGE_DIR "" ); +const char* const IMAGE_PATH(DEMO_IMAGE_DIR ""); -const char * BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-1.jpg"); +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-1.jpg"); -} +} // namespace /* * This example shows how to create and display a model3d-view control. @@ -55,21 +53,20 @@ const char * BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-1.jpg"); class Model3dViewController : public ConnectionTracker { public: - - Model3dViewController( Application& application ) - : mApplication( application ), - mModelCounter( 0 ), + Model3dViewController(Application& application) + : mApplication(application), + mModelCounter(0), mModel3dView(), mButtonLayer(), mTapDetector(), - mIlluminationShader( Model3dView::DIFFUSE ), + mIlluminationShader(Model3dView::DIFFUSE), mRotationAnimation(), mLightAnimation(), - mPlaying( false ), - mScaled( false ) + mPlaying(false), + mScaled(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &Model3dViewController::Create ); + mApplication.InitSignal().Connect(this, &Model3dViewController::Create); } ~Model3dViewController() @@ -78,116 +75,116 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window - Window window = application.GetWindow(); + Window window = application.GetWindow(); Vector2 screenSize = window.GetSize(); //Add background - Toolkit::ImageView backView = Toolkit::ImageView::New( BACKGROUND_IMAGE ); - backView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - backView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - window.Add( backView ); + Toolkit::ImageView backView = Toolkit::ImageView::New(BACKGROUND_IMAGE); + backView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + backView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + window.Add(backView); mModelCounter = 0; - mModel3dView = Model3dView::New( MODEL_FILE[0], MATERIAL_FILE[0], IMAGE_PATH ); - mModel3dView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mModel3dView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mModel3dView.SetProperty( Dali::Actor::Property::NAME, "model3dViewControl" ); + mModel3dView = Model3dView::New(MODEL_FILE[0], MATERIAL_FILE[0], IMAGE_PATH); + mModel3dView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mModel3dView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mModel3dView.SetProperty(Dali::Actor::Property::NAME, "model3dViewControl"); mModel3dView.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); - mModel3dView.SetProperty( Actor::Property::SIZE, screenSize); + mModel3dView.SetProperty(Actor::Property::SIZE, screenSize); - mModel3dView.SetProperty(Model3dView::Property::LIGHT_POSITION, Vector3(5,10.,0)); + mModel3dView.SetProperty(Model3dView::Property::LIGHT_POSITION, Vector3(5, 10., 0)); - backView.Add( mModel3dView ); + backView.Add(mModel3dView); mIlluminationShader = Model3dView::IlluminationType(mModel3dView.GetProperty(Model3dView::Property::ILLUMINATION_TYPE)); mButtonLayer = Layer::New(); - mButtonLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mButtonLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mButtonLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mButtonLayer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mButtonLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mButtonLayer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); window.Add(mButtonLayer); // Create button for model changing Toolkit::PushButton editButton = Toolkit::PushButton::New(); - editButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - editButton.ClickedSignal().Connect( this, &Model3dViewController::OnChangeModelClicked); - editButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - editButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - editButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Model" ); - mButtonLayer.Add( editButton ); + editButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + editButton.ClickedSignal().Connect(this, &Model3dViewController::OnChangeModelClicked); + editButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + editButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + editButton.SetProperty(Toolkit::Button::Property::LABEL, "Change Model"); + mButtonLayer.Add(editButton); // Create button for shader changing editButton = Toolkit::PushButton::New(); - editButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - editButton.ClickedSignal().Connect( this, &Model3dViewController::OnChangeLightingClicked); - editButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - editButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); - editButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Shader" ); - mButtonLayer.Add( editButton ); + editButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + editButton.ClickedSignal().Connect(this, &Model3dViewController::OnChangeLightingClicked); + editButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + editButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT); + editButton.SetProperty(Toolkit::Button::Property::LABEL, "Change Shader"); + mButtonLayer.Add(editButton); // Create button for pause/resume animation editButton = Toolkit::PushButton::New(); - editButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - editButton.ClickedSignal().Connect( this, &Model3dViewController::OnPauseAnimationsClicked); - editButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - editButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - editButton.SetProperty( Toolkit::Button::Property::LABEL, "Pause Animations" ); - mButtonLayer.Add( editButton ); + editButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + editButton.ClickedSignal().Connect(this, &Model3dViewController::OnPauseAnimationsClicked); + editButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + editButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + editButton.SetProperty(Toolkit::Button::Property::LABEL, "Pause Animations"); + mButtonLayer.Add(editButton); //Create animations mLightAnimation = Animation::New(6.f); - mLightAnimation.AnimateTo(Property(mModel3dView, Model3dView::Property::LIGHT_POSITION), Vector3(-5,10.0,0), TimePeriod( 0.0f, 3.0f )); - mLightAnimation.AnimateTo(Property(mModel3dView, Model3dView::Property::LIGHT_POSITION), Vector3(5,10.0,0), TimePeriod( 3.0f, 3.0f )); + mLightAnimation.AnimateTo(Property(mModel3dView, Model3dView::Property::LIGHT_POSITION), Vector3(-5, 10.0, 0), TimePeriod(0.0f, 3.0f)); + mLightAnimation.AnimateTo(Property(mModel3dView, Model3dView::Property::LIGHT_POSITION), Vector3(5, 10.0, 0), TimePeriod(3.0f, 3.0f)); mLightAnimation.SetLooping(true); mLightAnimation.Play(); mRotationAnimation = Animation::New(15.f); - mRotationAnimation.AnimateBy(Property(mModel3dView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f)) ); + mRotationAnimation.AnimateBy(Property(mModel3dView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f))); mRotationAnimation.SetLooping(true); mRotationAnimation.Play(); mPlaying = true; - mScaled = false; + mScaled = false; // Respond to a click anywhere on the window window.KeyEventSignal().Connect(this, &Model3dViewController::OnKeyEvent); //Create a tap gesture detector for zoom - mTapDetector = TapGestureDetector::New( 2 ); + mTapDetector = TapGestureDetector::New(2); mTapDetector.DetectedSignal().Connect(this, &Model3dViewController::OnTap); - mTapDetector.Attach( backView ); + mTapDetector.Attach(backView); } /** * Main Tap event handler */ - void OnTap( Actor actor, const TapGesture& tap ) + void OnTap(Actor actor, const TapGesture& tap) { - if (mScaled) + if(mScaled) { - mModel3dView.SetProperty( Actor::Property::SCALE, 1.0f ); - mModel3dView.SetProperty( Actor::Property::POSITION, Vector3( 0, 0, 0 ) ); + mModel3dView.SetProperty(Actor::Property::SCALE, 1.0f); + mModel3dView.SetProperty(Actor::Property::POSITION, Vector3(0, 0, 0)); mScaled = false; } else { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 screenSize = window.GetSize(); const Vector2& screenPoint = tap.GetScreenPoint(); - Vector2 position; + Vector2 position; position.x = screenPoint.x - screenSize.x * 0.5; position.y = screenPoint.y - screenSize.y * 0.5; float size = 2.5; - mModel3dView.SetProperty( Actor::Property::SCALE, size ); - mModel3dView.SetProperty( Actor::Property::POSITION, Vector3( -position.x * size, -position.y * size, 0 ) ); + mModel3dView.SetProperty(Actor::Property::SCALE, size); + mModel3dView.SetProperty(Actor::Property::POSITION, Vector3(-position.x * size, -position.y * size, 0)); mScaled = true; } } @@ -208,21 +205,21 @@ public: */ bool OnChangeLightingClicked(Toolkit::Button button) { - if( mIlluminationShader == Model3dView::DIFFUSE_WITH_NORMAL_MAP ) + if(mIlluminationShader == Model3dView::DIFFUSE_WITH_NORMAL_MAP) { mModel3dView.SetProperty(Model3dView::Property::ILLUMINATION_TYPE, Model3dView::DIFFUSE_WITH_TEXTURE); mIlluminationShader = Model3dView::IlluminationType(mModel3dView.GetProperty(Model3dView::Property::ILLUMINATION_TYPE)); } - else if( mIlluminationShader == Model3dView::DIFFUSE_WITH_TEXTURE ) + else if(mIlluminationShader == Model3dView::DIFFUSE_WITH_TEXTURE) { mModel3dView.SetProperty(Model3dView::Property::ILLUMINATION_TYPE, Model3dView::DIFFUSE); mIlluminationShader = Model3dView::IlluminationType(mModel3dView.GetProperty(Model3dView::Property::ILLUMINATION_TYPE)); - } - else if( mIlluminationShader == Model3dView::DIFFUSE ) + } + else if(mIlluminationShader == Model3dView::DIFFUSE) { mModel3dView.SetProperty(Model3dView::Property::ILLUMINATION_TYPE, Model3dView::DIFFUSE_WITH_NORMAL_MAP); mIlluminationShader = Model3dView::IlluminationType(mModel3dView.GetProperty(Model3dView::Property::ILLUMINATION_TYPE)); - } + } return true; } @@ -232,7 +229,7 @@ public: */ void PauseAnimations() { - if( mPlaying ) + if(mPlaying) { mRotationAnimation.Pause(); mLightAnimation.Pause(); @@ -265,7 +262,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -276,29 +273,28 @@ public: } } - private: - Application& mApplication; + Application& mApplication; - int mModelCounter; + int mModelCounter; Model3dView mModel3dView; - Layer mButtonLayer; + Layer mButtonLayer; TapGestureDetector mTapDetector; Model3dView::IlluminationType mIlluminationShader; Animation mRotationAnimation; Animation mLightAnimation; - bool mPlaying; + bool mPlaying; bool mScaled; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - Model3dViewController test( application ); + Application application = Application::New(&argc, &argv); + Model3dViewController test(application); application.MainLoop(); return 0; } diff --git a/examples/motion-blur/motion-blur-example.cpp b/examples/motion-blur/motion-blur-example.cpp old mode 100755 new mode 100644 index 5f82eba..174d390 --- a/examples/motion-blur/motion-blur-example.cpp +++ b/examples/motion-blur/motion-blur-example.cpp @@ -15,38 +15,35 @@ * */ -#include #include +#include -#include "shared/view.h" -#include -#include #include #include +#include +#include +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; - - namespace // unnamed namespace { - //////////////////////////////////////////////////// // // Demo setup parameters // -const float MOTION_BLUR_ACTOR_WIDTH = 256; // actor size on screen -const float MOTION_BLUR_ACTOR_HEIGHT = 256; // "" -const unsigned int MOTION_BLUR_NUM_SAMPLES = 8; +const float MOTION_BLUR_ACTOR_WIDTH = 256; // actor size on screen +const float MOTION_BLUR_ACTOR_HEIGHT = 256; // "" +const unsigned int MOTION_BLUR_NUM_SAMPLES = 8; -const int MOTION_BLUR_NUM_ACTOR_IMAGES = 5; -const char* MOTION_BLUR_ACTOR_IMAGE1( DEMO_IMAGE_DIR "image-with-border-1.jpg" ); -const char* MOTION_BLUR_ACTOR_IMAGE2( DEMO_IMAGE_DIR "image-with-border-2.jpg" ); -const char* MOTION_BLUR_ACTOR_IMAGE3( DEMO_IMAGE_DIR "image-with-border-3.jpg" ); -const char* MOTION_BLUR_ACTOR_IMAGE4( DEMO_IMAGE_DIR "image-with-border-4.jpg" ); -const char* MOTION_BLUR_ACTOR_IMAGE5( DEMO_IMAGE_DIR "image-with-border-1.jpg" ); +const int MOTION_BLUR_NUM_ACTOR_IMAGES = 5; +const char* MOTION_BLUR_ACTOR_IMAGE1(DEMO_IMAGE_DIR "image-with-border-1.jpg"); +const char* MOTION_BLUR_ACTOR_IMAGE2(DEMO_IMAGE_DIR "image-with-border-2.jpg"); +const char* MOTION_BLUR_ACTOR_IMAGE3(DEMO_IMAGE_DIR "image-with-border-3.jpg"); +const char* MOTION_BLUR_ACTOR_IMAGE4(DEMO_IMAGE_DIR "image-with-border-4.jpg"); +const char* MOTION_BLUR_ACTOR_IMAGE5(DEMO_IMAGE_DIR "image-with-border-1.jpg"); const char* MOTION_BLUR_ACTOR_IMAGES[] = { MOTION_BLUR_ACTOR_IMAGE1, @@ -56,31 +53,30 @@ const char* MOTION_BLUR_ACTOR_IMAGES[] = { MOTION_BLUR_ACTOR_IMAGE5, }; -const int NUM_ACTOR_ANIMATIONS = 4; +const int NUM_ACTOR_ANIMATIONS = 4; const int NUM_CAMERA_ANIMATIONS = 2; - const char* BACKGROUND_IMAGE_PATH = DEMO_IMAGE_DIR "background-default.png"; -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char* APPLICATION_TITLE( "Motion Blur" ); -const char* EFFECTS_OFF_ICON( DEMO_IMAGE_DIR "icon-effects-off.png" ); -const char* EFFECTS_OFF_ICON_SELECTED( DEMO_IMAGE_DIR "icon-effects-off-selected.png" ); -const char* EFFECTS_ON_ICON( DEMO_IMAGE_DIR "icon-effects-on.png" ); -const char* EFFECTS_ON_ICON_SELECTED( DEMO_IMAGE_DIR "icon-effects-on-selected.png" ); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* APPLICATION_TITLE("Motion Blur"); +const char* EFFECTS_OFF_ICON(DEMO_IMAGE_DIR "icon-effects-off.png"); +const char* EFFECTS_OFF_ICON_SELECTED(DEMO_IMAGE_DIR "icon-effects-off-selected.png"); +const char* EFFECTS_ON_ICON(DEMO_IMAGE_DIR "icon-effects-on.png"); +const char* EFFECTS_ON_ICON_SELECTED(DEMO_IMAGE_DIR "icon-effects-on-selected.png"); -const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons +const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons -const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); -const Vector3 BUTTON_TITLE_LABEL_TAP_HERE_SIZE_CONSTRAINT( 0.55f, 0.06f, 1.0f ); -const Vector3 BUTTON_TITLE_LABEL_INSTRUCTIONS_POPUP_SIZE_CONSTRAINT( 1.0f, 1.0f, 1.0f ); +const Vector3 BUTTON_SIZE_CONSTRAINT(0.24f, 0.09f, 1.0f); +const Vector3 BUTTON_TITLE_LABEL_TAP_HERE_SIZE_CONSTRAINT(0.55f, 0.06f, 1.0f); +const Vector3 BUTTON_TITLE_LABEL_INSTRUCTIONS_POPUP_SIZE_CONSTRAINT(1.0f, 1.0f, 1.0f); // move this button down a bit so it is visible on target and not covered up by toolbar const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f; -const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. +const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. /** * @brief Set an image to image view, scaled-down to no more than the dimensions passed in. @@ -88,38 +84,36 @@ const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to * Uses SHRINK_TO_FIT which ensures the resulting image is * smaller than or equal to the specified dimensions while preserving its original aspect ratio. */ -void SetImageFittedInBox( ImageView& imageView, Property::Map& shaderEffect, const char * const imagePath, int maxWidth, int maxHeight ) +void SetImageFittedInBox(ImageView& imageView, Property::Map& shaderEffect, const char* const imagePath, int maxWidth, int maxHeight) { Property::Map map; - map[Visual::Property::TYPE] = Visual::IMAGE; + map[Visual::Property::TYPE] = Visual::IMAGE; map[ImageVisual::Property::URL] = imagePath; // Load the image nicely scaled-down to fit within the specified max width and height: - map[ImageVisual::Property::DESIRED_WIDTH] = maxWidth; + map[ImageVisual::Property::DESIRED_WIDTH] = maxWidth; map[ImageVisual::Property::DESIRED_HEIGHT] = maxHeight; - map[ImageVisual::Property::FITTING_MODE] = FittingMode::SHRINK_TO_FIT; - map[ImageVisual::Property::SAMPLING_MODE] = SamplingMode::BOX_THEN_LINEAR; - map.Merge( shaderEffect ); + map[ImageVisual::Property::FITTING_MODE] = FittingMode::SHRINK_TO_FIT; + map[ImageVisual::Property::SAMPLING_MODE] = SamplingMode::BOX_THEN_LINEAR; + map.Merge(shaderEffect); - imageView.SetProperty( ImageView::Property::IMAGE, map ); + imageView.SetProperty(ImageView::Property::IMAGE, map); } } // unnamed namespace - // class MotionBlurExampleApp : public ConnectionTracker { public: - /** * DeviceOrientation describes the four different * orientations the device can be in based on accelerometer reports. */ enum DeviceOrientation { - PORTRAIT = 0, - LANDSCAPE = 90, - PORTRAIT_INVERSE = 180, + PORTRAIT = 0, + LANDSCAPE = 90, + PORTRAIT_INVERSE = 180, LANDSCAPE_INVERSE = 270 }; @@ -127,12 +121,12 @@ public: * Constructor * @param application class, stored as reference */ - MotionBlurExampleApp(Application &app) + MotionBlurExampleApp(Application& app) : mApplication(app), mActorEffectsEnabled(false), mCurrentActorAnimation(0), mCurrentImage(0), - mOrientation( PORTRAIT ) + mOrientation(PORTRAIT) { // Connect to the Application's Init signal app.InitSignal().Connect(this, &MotionBlurExampleApp::OnInit); @@ -153,51 +147,50 @@ public: window.KeyEventSignal().Connect(this, &MotionBlurExampleApp::OnKeyEvent); - // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - BACKGROUND_IMAGE_PATH, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContentLayer = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE_PATH, + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Ensure the content layer is a square so the touch area works in all orientations Vector2 windowSize = window.GetSize(); - float size = std::max( windowSize.width, windowSize.height ); - mContentLayer.SetProperty( Actor::Property::SIZE, Vector2( size, size ) ); + float size = std::max(windowSize.width, windowSize.height); + mContentLayer.SetProperty(Actor::Property::SIZE, Vector2(size, size)); //Add an effects icon on the right of the title mActorEffectsButton = Toolkit::PushButton::New(); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON ); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED ); - mActorEffectsButton.ClickedSignal().Connect( this, &MotionBlurExampleApp::OnEffectButtonClicked ); - mToolBar.AddControl( mActorEffectsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING ); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED); + mActorEffectsButton.ClickedSignal().Connect(this, &MotionBlurExampleApp::OnEffectButtonClicked); + mToolBar.AddControl(mActorEffectsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING); // Creates a mode button. // Create a effect toggle button. (right of toolbar) Toolkit::PushButton layoutButton = Toolkit::PushButton::New(); - layoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE ); - layoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE_SELECTED ); - layoutButton.ClickedSignal().Connect( this, &MotionBlurExampleApp::OnLayoutButtonClicked); - layoutButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( layoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + layoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE); + layoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE_SELECTED); + layoutButton.ClickedSignal().Connect(this, &MotionBlurExampleApp::OnLayoutButtonClicked); + layoutButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(layoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Input mTapGestureDetector = TapGestureDetector::New(); - mTapGestureDetector.Attach( mContentLayer ); - mTapGestureDetector.DetectedSignal().Connect( this, &MotionBlurExampleApp::OnTap ); + mTapGestureDetector.Attach(mContentLayer); + mTapGestureDetector.DetectedSignal().Connect(this, &MotionBlurExampleApp::OnTap); Dali::Window winHandle = app.GetWindow(); - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT ); - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE ); - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); - winHandle.ResizeSignal().Connect( this, &MotionBlurExampleApp::OnWindowResized ); + winHandle.AddAvailableOrientation(Dali::Window::PORTRAIT); + winHandle.AddAvailableOrientation(Dali::Window::LANDSCAPE); + winHandle.AddAvailableOrientation(Dali::Window::PORTRAIT_INVERSE); + winHandle.AddAvailableOrientation(Dali::Window::LANDSCAPE_INVERSE); + winHandle.ResizeSignal().Connect(this, &MotionBlurExampleApp::OnWindowResized); // set initial orientation - Rotate( PORTRAIT ); + Rotate(PORTRAIT); /////////////////////////////////////////////////////// // @@ -205,25 +198,24 @@ public: // // Scale down actor to fit on very low resolution screens with space to interact: - mMotionBlurActorSize = Size( std::min( windowSize.x * 0.3f, MOTION_BLUR_ACTOR_WIDTH ), std::min( windowSize.y * 0.3f, MOTION_BLUR_ACTOR_HEIGHT ) ); - mMotionBlurActorUpdateSize = Size( std::max( mMotionBlurActorSize.x, mMotionBlurActorSize.y ), std::max( mMotionBlurActorSize.x, mMotionBlurActorSize.y ) ); - mMotionBlurActorSize = Size( std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ), std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ) ); + mMotionBlurActorSize = Size(std::min(windowSize.x * 0.3f, MOTION_BLUR_ACTOR_WIDTH), std::min(windowSize.y * 0.3f, MOTION_BLUR_ACTOR_HEIGHT)); + mMotionBlurActorUpdateSize = Size(std::max(mMotionBlurActorSize.x, mMotionBlurActorSize.y), std::max(mMotionBlurActorSize.x, mMotionBlurActorSize.y)); + mMotionBlurActorSize = Size(std::min(mMotionBlurActorSize.x, mMotionBlurActorSize.y), std::min(mMotionBlurActorSize.x, mMotionBlurActorSize.y)); - mMotionBlurEffect = CreateMotionBlurEffect(); + mMotionBlurEffect = CreateMotionBlurEffect(); mMotionBlurImageView = ImageView::New(); - SetImageFittedInBox( mMotionBlurImageView, mMotionBlurEffect, MOTION_BLUR_ACTOR_IMAGE1, mMotionBlurActorSize.x, mMotionBlurActorSize.y ); - mMotionBlurImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mMotionBlurImageView.SetProperty( Actor::Property::SIZE, mMotionBlurActorUpdateSize ); - mMotionBlurImageView.SetProperty( DevelActor::Property::UPDATE_SIZE_HINT, mMotionBlurActorUpdateSize ); + SetImageFittedInBox(mMotionBlurImageView, mMotionBlurEffect, MOTION_BLUR_ACTOR_IMAGE1, mMotionBlurActorSize.x, mMotionBlurActorSize.y); + mMotionBlurImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mMotionBlurImageView.SetProperty(Actor::Property::SIZE, mMotionBlurActorUpdateSize); + mMotionBlurImageView.SetProperty(DevelActor::Property::UPDATE_SIZE_HINT, mMotionBlurActorUpdateSize); - mContentLayer.Add( mMotionBlurImageView ); + mContentLayer.Add(mMotionBlurImageView); // Create shader used for doing motion blur mMotionBlurEffect = CreateMotionBlurEffect(); // set actor shader to the blur one - Toolkit::SetMotionBlurProperties( mMotionBlurImageView, MOTION_BLUR_NUM_SAMPLES ); - + Toolkit::SetMotionBlurProperties(mMotionBlurImageView, MOTION_BLUR_NUM_SAMPLES); } ////////////////////////////////////////////////////////////// @@ -232,42 +224,41 @@ public: // // - void OnWindowResized( Window window, Window::WindowSize size ) + void OnWindowResized(Window window, Window::WindowSize size) { - Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT ); + Rotate(size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT); } - void Rotate( DeviceOrientation orientation ) + void Rotate(DeviceOrientation orientation) { // Resize the root actor const Vector2 targetSize = mApplication.GetWindow().GetSize(); - if( mOrientation != orientation ) + if(mOrientation != orientation) { mOrientation = orientation; // check if actor is on window - if( mView.GetParent() ) + if(mView.GetParent()) { // has parent so we expect it to be on window, start animation - mRotateAnimation = Animation::New( ORIENTATION_DURATION ); - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_WIDTH ), targetSize.width ); - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_HEIGHT ), targetSize.height ); + mRotateAnimation = Animation::New(ORIENTATION_DURATION); + mRotateAnimation.AnimateTo(Property(mView, Actor::Property::SIZE_WIDTH), targetSize.width); + mRotateAnimation.AnimateTo(Property(mView, Actor::Property::SIZE_HEIGHT), targetSize.height); mRotateAnimation.Play(); } else { - mView.SetProperty( Actor::Property::SIZE, targetSize ); + mView.SetProperty(Actor::Property::SIZE, targetSize); } } else { // for first time just set size - mView.SetProperty( Actor::Property::SIZE, targetSize ); + mView.SetProperty(Actor::Property::SIZE, targetSize); } } - ////////////////////////////////////////////////////////////// // // Actor Animation @@ -275,10 +266,10 @@ public: // // move to point on screen that was tapped - void OnTap( Actor actor, const TapGesture& tapGesture ) + void OnTap(Actor actor, const TapGesture& tapGesture) { Vector3 destPos; - float originOffsetX, originOffsetY; + float originOffsetX, originOffsetY; // rotate offset (from top left origin to centre) into actor space Vector2 windowSize = mApplication.GetWindow().GetSize(); @@ -286,20 +277,19 @@ public: // get dest point in local actor space const Vector2& localPoint = tapGesture.GetLocalPoint(); - destPos.x = localPoint.x - originOffsetX; - destPos.y = localPoint.y - originOffsetY; - destPos.z = 0.0f; + destPos.x = localPoint.x - originOffsetX; + destPos.y = localPoint.y - originOffsetY; + destPos.z = 0.0f; - float animDuration = 0.5f; - mActorTapMovementAnimation = Animation::New( animDuration ); - if ( mMotionBlurImageView ) + float animDuration = 0.5f; + mActorTapMovementAnimation = Animation::New(animDuration); + if(mMotionBlurImageView) { - mActorTapMovementAnimation.AnimateTo( Property(mMotionBlurImageView, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration) ); + mActorTapMovementAnimation.AnimateTo(Property(mMotionBlurImageView, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration)); } - mActorTapMovementAnimation.SetEndAction( Animation::BAKE ); + mActorTapMovementAnimation.SetEndAction(Animation::BAKE); mActorTapMovementAnimation.Play(); - // perform some spinning etc if(mActorEffectsEnabled) { @@ -309,9 +299,9 @@ public: case 0: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionBlurImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::YAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -320,9 +310,9 @@ public: case 1: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionBlurImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::ZAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -331,10 +321,10 @@ public: case 2: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionBlurImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::YAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.AnimateBy(Property(mMotionBlurImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::ZAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -343,9 +333,9 @@ public: case 3: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionBlurImageView, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod( 0.0f, 1.0f ) ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionBlurImageView, Actor::Property::SCALE), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod(0.0f, 1.0f)); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -367,14 +357,14 @@ public: if(!mActorEffectsEnabled) { mActorEffectsEnabled = true; - mActorEffectsButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON ); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON_SELECTED ); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON_SELECTED); } else { mActorEffectsEnabled = false; - mActorEffectsButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON ); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED ); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED); } } @@ -384,13 +374,13 @@ public: // // - bool OnLayoutButtonClicked( Toolkit::Button button ) + bool OnLayoutButtonClicked(Toolkit::Button button) { ChangeImage(); return true; } - bool OnEffectButtonClicked( Toolkit::Button button ) + bool OnEffectButtonClicked(Toolkit::Button button) { ToggleActorEffects(); return true; @@ -403,7 +393,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -416,7 +406,6 @@ public: // // - void ChangeImage() { mCurrentImage++; @@ -424,46 +413,44 @@ public: { mCurrentImage = 0; } - SetImageFittedInBox( mMotionBlurImageView, mMotionBlurEffect, MOTION_BLUR_ACTOR_IMAGES[mCurrentImage], mMotionBlurActorSize.x, mMotionBlurActorSize.y ); - + SetImageFittedInBox(mMotionBlurImageView, mMotionBlurEffect, MOTION_BLUR_ACTOR_IMAGES[mCurrentImage], mMotionBlurActorSize.x, mMotionBlurActorSize.y); } - private: - Application& mApplication; ///< Application instance - Toolkit::Control mView; - Toolkit::ToolBar mToolBar; + Application& mApplication; ///< Application instance + Toolkit::Control mView; + Toolkit::ToolBar mToolBar; - Layer mContentLayer; ///< Content layer (contains actor for this blur demo) + Layer mContentLayer; ///< Content layer (contains actor for this blur demo) - PushButton mActorEffectsButton; ///< The actor effects toggling Button. + PushButton mActorEffectsButton; ///< The actor effects toggling Button. // Motion blur Property::Map mMotionBlurEffect; - ImageView mMotionBlurImageView; - Size mMotionBlurActorSize; - Size mMotionBlurActorUpdateSize; + ImageView mMotionBlurImageView; + Size mMotionBlurActorSize; + Size mMotionBlurActorUpdateSize; // animate actor to position where user taps screen Animation mActorTapMovementAnimation; // show different animations to demonstrate blur effect working on an object only movement basis - bool mActorEffectsEnabled; + bool mActorEffectsEnabled; Animation mActorAnimation; - int mCurrentActorAnimation; + int mCurrentActorAnimation; // offer a selection of images that user can cycle between int mCurrentImage; TapGestureDetector mTapGestureDetector; - DeviceOrientation mOrientation; ///< Current Device orientation - Animation mRotateAnimation; ///< Animation for rotating between landscape and portrait. + DeviceOrientation mOrientation; ///< Current Device orientation + Animation mRotateAnimation; ///< Animation for rotating between landscape and portrait. }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); MotionBlurExampleApp test(app); app.MainLoop(); return 0; diff --git a/examples/motion-stretch/motion-stretch-example.cpp b/examples/motion-stretch/motion-stretch-example.cpp old mode 100755 new mode 100644 index 8167dfc..7b815fa --- a/examples/motion-stretch/motion-stretch-example.cpp +++ b/examples/motion-stretch/motion-stretch-example.cpp @@ -15,37 +15,34 @@ * */ -#include #include +#include -#include "shared/view.h" -#include -#include #include #include +#include +#include +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; - - namespace // unnamed namespace { - //////////////////////////////////////////////////// // // Demo setup parameters // -const float MOTION_STRETCH_ACTOR_WIDTH = 256; // actor size on screen -const float MOTION_STRETCH_ACTOR_HEIGHT = 256; // "" +const float MOTION_STRETCH_ACTOR_WIDTH = 256; // actor size on screen +const float MOTION_STRETCH_ACTOR_HEIGHT = 256; // "" -const int MOTION_STRETCH_NUM_ACTOR_IMAGES = 5; -const char* MOTION_STRETCH_ACTOR_IMAGE1( DEMO_IMAGE_DIR "image-with-border-1.jpg" ); -const char* MOTION_STRETCH_ACTOR_IMAGE2( DEMO_IMAGE_DIR "image-with-border-2.jpg" ); -const char* MOTION_STRETCH_ACTOR_IMAGE3( DEMO_IMAGE_DIR "image-with-border-3.jpg" ); -const char* MOTION_STRETCH_ACTOR_IMAGE4( DEMO_IMAGE_DIR "image-with-border-4.jpg" ); -const char* MOTION_STRETCH_ACTOR_IMAGE5( DEMO_IMAGE_DIR "image-with-border-5.jpg" ); +const int MOTION_STRETCH_NUM_ACTOR_IMAGES = 5; +const char* MOTION_STRETCH_ACTOR_IMAGE1(DEMO_IMAGE_DIR "image-with-border-1.jpg"); +const char* MOTION_STRETCH_ACTOR_IMAGE2(DEMO_IMAGE_DIR "image-with-border-2.jpg"); +const char* MOTION_STRETCH_ACTOR_IMAGE3(DEMO_IMAGE_DIR "image-with-border-3.jpg"); +const char* MOTION_STRETCH_ACTOR_IMAGE4(DEMO_IMAGE_DIR "image-with-border-4.jpg"); +const char* MOTION_STRETCH_ACTOR_IMAGE5(DEMO_IMAGE_DIR "image-with-border-5.jpg"); const char* MOTION_STRETCH_ACTOR_IMAGES[] = { MOTION_STRETCH_ACTOR_IMAGE1, @@ -55,51 +52,46 @@ const char* MOTION_STRETCH_ACTOR_IMAGES[] = { MOTION_STRETCH_ACTOR_IMAGE5, }; -const int NUM_ACTOR_ANIMATIONS = 4; +const int NUM_ACTOR_ANIMATIONS = 4; const int NUM_CAMERA_ANIMATIONS = 2; - const char* BACKGROUND_IMAGE_PATH = DEMO_IMAGE_DIR "background-default.png"; -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char* APPLICATION_TITLE( "Motion Stretch" ); -const char* EFFECTS_OFF_ICON( DEMO_IMAGE_DIR "icon-effects-off.png" ); -const char* EFFECTS_OFF_ICON_SELECTED( DEMO_IMAGE_DIR "icon-effects-off-selected.png" ); -const char* EFFECTS_ON_ICON( DEMO_IMAGE_DIR "icon-effects-on.png" ); -const char* EFFECTS_ON_ICON_SELECTED( DEMO_IMAGE_DIR "icon-effects-on-selected.png" ); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* LAYOUT_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* LAYOUT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* APPLICATION_TITLE("Motion Stretch"); +const char* EFFECTS_OFF_ICON(DEMO_IMAGE_DIR "icon-effects-off.png"); +const char* EFFECTS_OFF_ICON_SELECTED(DEMO_IMAGE_DIR "icon-effects-off-selected.png"); +const char* EFFECTS_ON_ICON(DEMO_IMAGE_DIR "icon-effects-on.png"); +const char* EFFECTS_ON_ICON_SELECTED(DEMO_IMAGE_DIR "icon-effects-on-selected.png"); // These values depend on the button background image -const Vector4 BUTTON_IMAGE_BORDER( Vector4::ONE * 3.0f ); +const Vector4 BUTTON_IMAGE_BORDER(Vector4::ONE * 3.0f); -const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons +const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons -const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f ); +const Vector3 BUTTON_SIZE_CONSTRAINT(0.24f, 0.09f, 1.0f); // move this button down a bit so it is visible on target and not covered up by toolbar const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f; -const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. +const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. } // unnamed namespace - - - // class MotionStretchExampleApp : public ConnectionTracker { public: - /** * DeviceOrientation describes the four different * orientations the device can be in based on accelerometer reports. */ enum DeviceOrientation { - PORTRAIT = 0, - LANDSCAPE = 90, - PORTRAIT_INVERSE = 180, + PORTRAIT = 0, + LANDSCAPE = 90, + PORTRAIT_INVERSE = 180, LANDSCAPE_INVERSE = 270 }; @@ -107,12 +99,12 @@ public: * Constructor * @param application class, stored as reference */ - MotionStretchExampleApp(Application &app) + MotionStretchExampleApp(Application& app) : mApplication(app), mActorEffectsEnabled(false), mCurrentActorAnimation(0), mCurrentImage(0), - mOrientation( PORTRAIT ) + mOrientation(PORTRAIT) { // Connect to the Application's Init signal app.InitSignal().Connect(this, &MotionStretchExampleApp::OnInit); @@ -135,68 +127,68 @@ public: // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - BACKGROUND_IMAGE_PATH, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContentLayer = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE_PATH, + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Ensure the content layer is a square so the touch area works in all orientations Vector2 windowSize = window.GetSize(); - float size = std::max( windowSize.width, windowSize.height ); - mContentLayer.SetProperty( Actor::Property::SIZE, Vector2( size, size ) ); + float size = std::max(windowSize.width, windowSize.height); + mContentLayer.SetProperty(Actor::Property::SIZE, Vector2(size, size)); //Add an slideshow icon on the right of the title mActorEffectsButton = Toolkit::PushButton::New(); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON ); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED ); - mActorEffectsButton.ClickedSignal().Connect( this, &MotionStretchExampleApp::OnEffectButtonClicked ); - mToolBar.AddControl( mActorEffectsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING ); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED); + mActorEffectsButton.ClickedSignal().Connect(this, &MotionStretchExampleApp::OnEffectButtonClicked); + mToolBar.AddControl(mActorEffectsButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING); // Creates a mode button. // Create a effect toggle button. (right of toolbar) Toolkit::PushButton layoutButton = Toolkit::PushButton::New(); - layoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE ); - layoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE_SELECTED ); - layoutButton.ClickedSignal().Connect( this, &MotionStretchExampleApp::OnLayoutButtonClicked); - layoutButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( layoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + layoutButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE); + layoutButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, LAYOUT_IMAGE_SELECTED); + layoutButton.ClickedSignal().Connect(this, &MotionStretchExampleApp::OnLayoutButtonClicked); + layoutButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(layoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Input mTapGestureDetector = TapGestureDetector::New(); - mTapGestureDetector.Attach( mContentLayer ); - mTapGestureDetector.DetectedSignal().Connect( this, &MotionStretchExampleApp::OnTap ); + mTapGestureDetector.Attach(mContentLayer); + mTapGestureDetector.DetectedSignal().Connect(this, &MotionStretchExampleApp::OnTap); // set initial orientation Dali::Window winHandle = app.GetWindow(); - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT ); - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE ); - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); - winHandle.ResizeSignal().Connect( this, &MotionStretchExampleApp::OnWindowResized ); + winHandle.AddAvailableOrientation(Dali::Window::PORTRAIT); + winHandle.AddAvailableOrientation(Dali::Window::LANDSCAPE); + winHandle.AddAvailableOrientation(Dali::Window::PORTRAIT_INVERSE); + winHandle.AddAvailableOrientation(Dali::Window::LANDSCAPE_INVERSE); + winHandle.ResizeSignal().Connect(this, &MotionStretchExampleApp::OnWindowResized); // set initial orientation - Rotate( PORTRAIT ); + Rotate(PORTRAIT); /////////////////////////////////////////////////////// // // Motion stretched actor // - mMotionStretchEffect = Toolkit::CreateMotionStretchEffect(); + mMotionStretchEffect = Toolkit::CreateMotionStretchEffect(); mMotionStretchEffect["url"] = MOTION_STRETCH_ACTOR_IMAGE1; - mMotionStretchImageView = ImageView::New(); - mMotionStretchImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mMotionStretchEffect ); - mMotionStretchImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mMotionStretchImageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mMotionStretchImageView.SetProperty( Actor::Property::SIZE, Vector2( MOTION_STRETCH_ACTOR_WIDTH, MOTION_STRETCH_ACTOR_HEIGHT ) ); + mMotionStretchImageView = ImageView::New(); + mMotionStretchImageView.SetProperty(Toolkit::ImageView::Property::IMAGE, mMotionStretchEffect); + mMotionStretchImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mMotionStretchImageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mMotionStretchImageView.SetProperty(Actor::Property::SIZE, Vector2(MOTION_STRETCH_ACTOR_WIDTH, MOTION_STRETCH_ACTOR_HEIGHT)); // Add stretch padding - mMotionStretchImageView.SetProperty( DevelActor::Property::UPDATE_SIZE_HINT, Vector2( MOTION_STRETCH_ACTOR_WIDTH+32, MOTION_STRETCH_ACTOR_HEIGHT+32 ) ); + mMotionStretchImageView.SetProperty(DevelActor::Property::UPDATE_SIZE_HINT, Vector2(MOTION_STRETCH_ACTOR_WIDTH + 32, MOTION_STRETCH_ACTOR_HEIGHT + 32)); - mContentLayer.Add( mMotionStretchImageView ); + mContentLayer.Add(mMotionStretchImageView); // Create shader used for doing motion stretch - Toolkit::SetMotionStretchProperties( mMotionStretchImageView ); + Toolkit::SetMotionStretchProperties(mMotionStretchImageView); } ////////////////////////////////////////////////////////////// @@ -205,38 +197,38 @@ public: // // - void OnWindowResized( Window window, Window::WindowSize size ) + void OnWindowResized(Window window, Window::WindowSize size) { - Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT ); + Rotate(size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT); } - void Rotate( DeviceOrientation orientation ) + void Rotate(DeviceOrientation orientation) { // Resize the root actor const Vector2 targetSize = mApplication.GetWindow().GetSize(); - if( mOrientation != orientation ) + if(mOrientation != orientation) { mOrientation = orientation; // check if actor is on window - if( mView.GetParent() ) + if(mView.GetParent()) { // has parent so we expect it to be on window, start animation - mRotateAnimation = Animation::New( ORIENTATION_DURATION ); - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_WIDTH ), targetSize.width ); - mRotateAnimation.AnimateTo( Property( mView, Actor::Property::SIZE_HEIGHT ), targetSize.height ); + mRotateAnimation = Animation::New(ORIENTATION_DURATION); + mRotateAnimation.AnimateTo(Property(mView, Actor::Property::SIZE_WIDTH), targetSize.width); + mRotateAnimation.AnimateTo(Property(mView, Actor::Property::SIZE_HEIGHT), targetSize.height); mRotateAnimation.Play(); } else { - mView.SetProperty( Actor::Property::SIZE, targetSize ); + mView.SetProperty(Actor::Property::SIZE, targetSize); } } else { // for first time just set size - mView.SetProperty( Actor::Property::SIZE, targetSize ); + mView.SetProperty(Actor::Property::SIZE, targetSize); } } @@ -247,10 +239,10 @@ public: // // move to point on screen that was tapped - void OnTap( Actor actor, const TapGesture& tapGesture ) + void OnTap(Actor actor, const TapGesture& tapGesture) { Vector3 destPos; - float originOffsetX, originOffsetY; + float originOffsetX, originOffsetY; // rotate offset (from top left origin to centre) into actor space Vector2 windowSize = mApplication.GetWindow().GetSize(); @@ -258,20 +250,19 @@ public: // get dest point in local actor space const Vector2& localPoint = tapGesture.GetLocalPoint(); - destPos.x = localPoint.x - originOffsetX; - destPos.y = localPoint.y - originOffsetY; - destPos.z = 0.0f; + destPos.x = localPoint.x - originOffsetX; + destPos.y = localPoint.y - originOffsetY; + destPos.z = 0.0f; - float animDuration = 0.5f; - mActorTapMovementAnimation = Animation::New( animDuration ); - if ( mMotionStretchImageView ) + float animDuration = 0.5f; + mActorTapMovementAnimation = Animation::New(animDuration); + if(mMotionStretchImageView) { - mActorTapMovementAnimation.AnimateTo( Property(mMotionStretchImageView, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration) ); + mActorTapMovementAnimation.AnimateTo(Property(mMotionStretchImageView, Actor::Property::POSITION), destPos, AlphaFunction::EASE_IN_OUT_SINE, TimePeriod(animDuration)); } - mActorTapMovementAnimation.SetEndAction( Animation::BAKE ); + mActorTapMovementAnimation.SetEndAction(Animation::BAKE); mActorTapMovementAnimation.Play(); - // perform some spinning etc if(mActorEffectsEnabled) { @@ -281,9 +272,9 @@ public: case 0: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionStretchImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::YAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -292,9 +283,9 @@ public: case 1: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionStretchImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::ZAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -303,10 +294,10 @@ public: case 2: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.AnimateBy( Property( mMotionStretchImageView, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f) ), Vector3::ZAXIS ), AlphaFunction::EASE_IN_OUT ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionStretchImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::YAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.AnimateBy(Property(mMotionStretchImageView, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::ZAXIS), AlphaFunction::EASE_IN_OUT); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -315,9 +306,9 @@ public: case 3: { float animDuration = 1.0f; - mActorAnimation = Animation::New(animDuration); - mActorAnimation.AnimateBy( Property( mMotionStretchImageView, Actor::Property::SCALE ), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod( 0.0f, 1.0f ) ); - mActorAnimation.SetEndAction( Animation::BAKE ); + mActorAnimation = Animation::New(animDuration); + mActorAnimation.AnimateBy(Property(mMotionStretchImageView, Actor::Property::SCALE), Vector3(2.0f, 2.0f, 2.0f), AlphaFunction::BOUNCE, TimePeriod(0.0f, 1.0f)); + mActorAnimation.SetEndAction(Animation::BAKE); mActorAnimation.Play(); } break; @@ -339,14 +330,14 @@ public: if(!mActorEffectsEnabled) { mActorEffectsEnabled = true; - mActorEffectsButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON ); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON_SELECTED ); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_ON_ICON_SELECTED); } else { mActorEffectsEnabled = false; - mActorEffectsButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON ); - mActorEffectsButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED ); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON); + mActorEffectsButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECTS_OFF_ICON_SELECTED); } } @@ -356,13 +347,13 @@ public: // // - bool OnLayoutButtonClicked( Toolkit::Button button ) + bool OnLayoutButtonClicked(Toolkit::Button button) { ChangeImage(); return true; } - bool OnEffectButtonClicked( Toolkit::Button button ) + bool OnEffectButtonClicked(Toolkit::Button button) { ToggleActorEffects(); return true; @@ -375,7 +366,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -388,7 +379,6 @@ public: // // - void ChangeImage() { mCurrentImage++; @@ -398,43 +388,41 @@ public: } mMotionStretchEffect["url"] = MOTION_STRETCH_ACTOR_IMAGES[mCurrentImage]; - mMotionStretchImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, mMotionStretchEffect ); + mMotionStretchImageView.SetProperty(Toolkit::ImageView::Property::IMAGE, mMotionStretchEffect); } - private: - Application& mApplication; ///< Application instance - Toolkit::Control mView; - Toolkit::ToolBar mToolBar; - Layer mContentLayer; ///< Content layer (contains actor for this stretch demo) + Application& mApplication; ///< Application instance + Toolkit::Control mView; + Toolkit::ToolBar mToolBar; + Layer mContentLayer; ///< Content layer (contains actor for this stretch demo) - PushButton mActorEffectsButton; ///< The actor effects toggling Button. + PushButton mActorEffectsButton; ///< The actor effects toggling Button. // Motion stretch Property::Map mMotionStretchEffect; - ImageView mMotionStretchImageView; + ImageView mMotionStretchImageView; // animate actor to position where user taps screen Animation mActorTapMovementAnimation; // show different animations to demonstrate stretch effect working on an object only movement basis - bool mActorEffectsEnabled; + bool mActorEffectsEnabled; Animation mActorAnimation; - int mCurrentActorAnimation; + int mCurrentActorAnimation; // offer a selection of images that user can cycle between int mCurrentImage; TapGestureDetector mTapGestureDetector; - DeviceOrientation mOrientation; ///< Current Device orientation - Animation mRotateAnimation; ///< Animation for rotating between landscape and portrait. - + DeviceOrientation mOrientation; ///< Current Device orientation + Animation mRotateAnimation; ///< Animation for rotating between landscape and portrait. }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); MotionStretchExampleApp test(app); app.MainLoop(); return 0; diff --git a/examples/native-image-source/native-image-source-example.cpp b/examples/native-image-source/native-image-source-example.cpp index 073a223..4183352 100644 --- a/examples/native-image-source/native-image-source-example.cpp +++ b/examples/native-image-source/native-image-source-example.cpp @@ -16,8 +16,8 @@ */ // EXTERNAL INCLUDES -#include #include +#include #include // INTERNAL INCLUDES @@ -28,11 +28,10 @@ using namespace Toolkit; namespace { - const float BUTTON_HEIGHT = 100.0f; const float BUTTON_COUNT = 5.0f; -const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg"; +const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg"; const std::string CAPTURE_FILENAME = "/tmp/native-image-capture.png"; /** @@ -40,10 +39,11 @@ const std::string CAPTURE_FILENAME = "/tmp/native-image-capture.png"; * @param[in] nativeImage The native image * @return A shader to render the native image */ -Shader CreateShader( NativeImageInterface& nativeImage ) +Shader CreateShader(NativeImageInterface& nativeImage) { static const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D"; + // clang-format off static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n attribute mediump vec2 aTexCoord;\n @@ -68,13 +68,13 @@ Shader CreateShader( NativeImageInterface& nativeImage ) gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n }\n ); - + // clang-format on std::string fragmentShader; //Get custom fragment shader prefix const char* fragmentPrefix = nativeImage.GetCustomFragmentPrefix(); - if( fragmentPrefix ) + if(fragmentPrefix) { fragmentShader = fragmentPrefix; fragmentShader += FRAGMENT_SHADER_TEXTURE; @@ -86,28 +86,27 @@ Shader CreateShader( NativeImageInterface& nativeImage ) //Get custom sampler type name const char* customSamplerTypename = nativeImage.GetCustomSamplerTypename(); - if( customSamplerTypename ) + if(customSamplerTypename) { - fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen(DEFAULT_SAMPLER_TYPENAME), customSamplerTypename ); + fragmentShader.replace(fragmentShader.find(DEFAULT_SAMPLER_TYPENAME), strlen(DEFAULT_SAMPLER_TYPENAME), customSamplerTypename); } - return Shader::New( VERTEX_SHADER_TEXTURE, fragmentShader ); + return Shader::New(VERTEX_SHADER_TEXTURE, fragmentShader); } -} +} // namespace // This example shows how to create and use a NativeImageSource as the target of the render task. // class NativeImageSourceController : public ConnectionTracker { public: - - NativeImageSourceController( Application& application ) - : mApplication( application ), - mRefreshAlways( true ) + NativeImageSourceController(Application& application) + : mApplication(application), + mRefreshAlways(true) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &NativeImageSourceController::Create ); + mApplication.InitSignal().Connect(this, &NativeImageSourceController::Create); } ~NativeImageSourceController() @@ -116,11 +115,11 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); window.KeyEventSignal().Connect(this, &NativeImageSourceController::OnKeyEvent); @@ -131,183 +130,183 @@ public: void CreateButtonArea() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); mButtonArea = Layer::New(); - mButtonArea.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x, BUTTON_HEIGHT ) ); - mButtonArea.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mButtonArea.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - window.Add( mButtonArea ); + mButtonArea.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x, BUTTON_HEIGHT)); + mButtonArea.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mButtonArea.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + window.Add(mButtonArea); mButtonShow = PushButton::New(); - mButtonShow.SetProperty( Button::Property::TOGGLABLE, true ); - mButtonShow.SetProperty( Toolkit::Button::Property::LABEL, "SHOW" ); - mButtonShow.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mButtonShow.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mButtonShow.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT ) ); - mButtonShow.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); - mButtonArea.Add( mButtonShow ); + mButtonShow.SetProperty(Button::Property::TOGGLABLE, true); + mButtonShow.SetProperty(Toolkit::Button::Property::LABEL, "SHOW"); + mButtonShow.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mButtonShow.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mButtonShow.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT)); + mButtonShow.ClickedSignal().Connect(this, &NativeImageSourceController::OnButtonSelected); + mButtonArea.Add(mButtonShow); mButtonRefreshAlways = PushButton::New(); - mButtonRefreshAlways.SetProperty( Button::Property::TOGGLABLE, true ); - mButtonRefreshAlways.SetProperty( Toolkit::Button::Property::LABEL, "ALWAYS" ); - mButtonRefreshAlways.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mButtonRefreshAlways.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mButtonRefreshAlways.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT ) ); - mButtonRefreshAlways.SetProperty( Actor::Property::POSITION, Vector2( (windowSize.x / BUTTON_COUNT)*1.0f, 0.0f )); - mButtonRefreshAlways.StateChangedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); - mButtonArea.Add( mButtonRefreshAlways ); + mButtonRefreshAlways.SetProperty(Button::Property::TOGGLABLE, true); + mButtonRefreshAlways.SetProperty(Toolkit::Button::Property::LABEL, "ALWAYS"); + mButtonRefreshAlways.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mButtonRefreshAlways.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mButtonRefreshAlways.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT)); + mButtonRefreshAlways.SetProperty(Actor::Property::POSITION, Vector2((windowSize.x / BUTTON_COUNT) * 1.0f, 0.0f)); + mButtonRefreshAlways.StateChangedSignal().Connect(this, &NativeImageSourceController::OnButtonSelected); + mButtonArea.Add(mButtonRefreshAlways); mButtonRefreshOnce = PushButton::New(); - mButtonRefreshOnce.SetProperty( Toolkit::Button::Property::LABEL, "ONCE" ); - mButtonRefreshOnce.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mButtonRefreshOnce.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mButtonRefreshOnce.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT ) ); - mButtonRefreshOnce.SetProperty( Actor::Property::POSITION, Vector2( (windowSize.x / BUTTON_COUNT)*2.0f, 0.0f )); - mButtonRefreshOnce.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); - mButtonArea.Add( mButtonRefreshOnce ); + mButtonRefreshOnce.SetProperty(Toolkit::Button::Property::LABEL, "ONCE"); + mButtonRefreshOnce.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mButtonRefreshOnce.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mButtonRefreshOnce.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT)); + mButtonRefreshOnce.SetProperty(Actor::Property::POSITION, Vector2((windowSize.x / BUTTON_COUNT) * 2.0f, 0.0f)); + mButtonRefreshOnce.ClickedSignal().Connect(this, &NativeImageSourceController::OnButtonSelected); + mButtonArea.Add(mButtonRefreshOnce); mButtonCapture = PushButton::New(); - mButtonCapture.SetProperty( Toolkit::Button::Property::LABEL, "CAPTURE" ); - mButtonCapture.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mButtonCapture.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mButtonCapture.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT ) ); - mButtonCapture.SetProperty( Actor::Property::POSITION, Vector2( (windowSize.x / BUTTON_COUNT)*3.0f, 0.0f )); - mButtonCapture.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); - mButtonArea.Add( mButtonCapture ); + mButtonCapture.SetProperty(Toolkit::Button::Property::LABEL, "CAPTURE"); + mButtonCapture.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mButtonCapture.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mButtonCapture.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT)); + mButtonCapture.SetProperty(Actor::Property::POSITION, Vector2((windowSize.x / BUTTON_COUNT) * 3.0f, 0.0f)); + mButtonCapture.ClickedSignal().Connect(this, &NativeImageSourceController::OnButtonSelected); + mButtonArea.Add(mButtonCapture); mButtonReset = PushButton::New(); - mButtonReset.SetProperty( Toolkit::Button::Property::LABEL, "RESET" ); - mButtonReset.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mButtonReset.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mButtonReset.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT ) ); - mButtonReset.SetProperty( Actor::Property::POSITION, Vector2( (windowSize.x / BUTTON_COUNT)*4.0f, 0.0f )); - mButtonReset.ClickedSignal().Connect( this, &NativeImageSourceController::OnButtonSelected ); - mButtonArea.Add( mButtonReset ); + mButtonReset.SetProperty(Toolkit::Button::Property::LABEL, "RESET"); + mButtonReset.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mButtonReset.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mButtonReset.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x / BUTTON_COUNT, BUTTON_HEIGHT)); + mButtonReset.SetProperty(Actor::Property::POSITION, Vector2((windowSize.x / BUTTON_COUNT) * 4.0f, 0.0f)); + mButtonReset.ClickedSignal().Connect(this, &NativeImageSourceController::OnButtonSelected); + mButtonArea.Add(mButtonReset); } void CreateContentAreas() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - float contentHeight( (windowSize.y - BUTTON_HEIGHT)/2.0f ); + float contentHeight((windowSize.y - BUTTON_HEIGHT) / 2.0f); mTopContentArea = Actor::New(); - mTopContentArea.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x, contentHeight ) ); - mTopContentArea.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mTopContentArea.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mTopContentArea.SetProperty( Actor::Property::POSITION_Y, BUTTON_HEIGHT ); - window.Add( mTopContentArea ); + mTopContentArea.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x, contentHeight)); + mTopContentArea.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mTopContentArea.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mTopContentArea.SetProperty(Actor::Property::POSITION_Y, BUTTON_HEIGHT); + window.Add(mTopContentArea); mBottomContentArea = Actor::New(); - mBottomContentArea.SetProperty( Actor::Property::SIZE, Vector2( windowSize.x, contentHeight ) ); - mBottomContentArea.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mBottomContentArea.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - window.Add( mBottomContentArea ); + mBottomContentArea.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x, contentHeight)); + mBottomContentArea.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mBottomContentArea.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + window.Add(mBottomContentArea); mSourceActor = ImageView::New(JPG_FILENAME); - mSourceActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - mSourceActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mTopContentArea.Add( mSourceActor ); + mSourceActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSourceActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTopContentArea.Add(mSourceActor); Animation animation = Animation::New(2.f); - Degree relativeRotationDegrees(90.0f); - Radian relativeRotationRadians(relativeRotationDegrees); - animation.AnimateTo( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(0.f, 0.5f)); - animation.AnimateBy( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(0.5f, 0.5f)); - animation.AnimateBy( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(1.f, 0.5f)); - animation.AnimateBy( Property( mSourceActor, Actor::Property::ORIENTATION ), Quaternion( relativeRotationRadians, Vector3::ZAXIS ), AlphaFunction::LINEAR, TimePeriod(1.5f, 0.5f)); + Degree relativeRotationDegrees(90.0f); + Radian relativeRotationRadians(relativeRotationDegrees); + animation.AnimateTo(Property(mSourceActor, Actor::Property::ORIENTATION), Quaternion(relativeRotationRadians, Vector3::ZAXIS), AlphaFunction::LINEAR, TimePeriod(0.f, 0.5f)); + animation.AnimateBy(Property(mSourceActor, Actor::Property::ORIENTATION), Quaternion(relativeRotationRadians, Vector3::ZAXIS), AlphaFunction::LINEAR, TimePeriod(0.5f, 0.5f)); + animation.AnimateBy(Property(mSourceActor, Actor::Property::ORIENTATION), Quaternion(relativeRotationRadians, Vector3::ZAXIS), AlphaFunction::LINEAR, TimePeriod(1.f, 0.5f)); + animation.AnimateBy(Property(mSourceActor, Actor::Property::ORIENTATION), Quaternion(relativeRotationRadians, Vector3::ZAXIS), AlphaFunction::LINEAR, TimePeriod(1.5f, 0.5f)); animation.SetLooping(true); animation.Play(); - TextLabel textLabel1 = TextLabel::New( "Image" ); - textLabel1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - textLabel1.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mTopContentArea.Add( textLabel1 ); + TextLabel textLabel1 = TextLabel::New("Image"); + textLabel1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + textLabel1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mTopContentArea.Add(textLabel1); // Wait until button press before creating mOffscreenRenderTask - TextLabel textLabel2 = TextLabel::New( "Native Image" ); - textLabel2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - textLabel2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mBottomContentArea.Add( textLabel2 ); + TextLabel textLabel2 = TextLabel::New("Native Image"); + textLabel2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + textLabel2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mBottomContentArea.Add(textLabel2); } void SetupNativeImage() { - if( ! mOffscreenRenderTask ) + if(!mOffscreenRenderTask) { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - float contentHeight( (windowSize.y - BUTTON_HEIGHT)/2.0f ); - Vector2 imageSize( windowSize.x, contentHeight ); + float contentHeight((windowSize.y - BUTTON_HEIGHT) / 2.0f); + Vector2 imageSize(windowSize.x, contentHeight); - mNativeImageSourcePtr = NativeImageSource::New( imageSize.width, imageSize.height, NativeImageSource::COLOR_DEPTH_DEFAULT ); - mNativeTexture = Texture::New( *mNativeImageSourcePtr ); + mNativeImageSourcePtr = NativeImageSource::New(imageSize.width, imageSize.height, NativeImageSource::COLOR_DEPTH_DEFAULT); + mNativeTexture = Texture::New(*mNativeImageSourcePtr); - mFrameBuffer = FrameBuffer::New( mNativeTexture.GetWidth(), mNativeTexture.GetHeight(), FrameBuffer::Attachment::NONE ); - mFrameBuffer.AttachColorTexture( mNativeTexture ); + mFrameBuffer = FrameBuffer::New(mNativeTexture.GetWidth(), mNativeTexture.GetHeight(), FrameBuffer::Attachment::NONE); + mFrameBuffer.AttachColorTexture(mNativeTexture); - mCameraActor = CameraActor::New( imageSize ); - mCameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER ); - mTopContentArea.Add( mCameraActor ); + mCameraActor = CameraActor::New(imageSize); + mCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER); + mTopContentArea.Add(mCameraActor); RenderTaskList taskList = window.GetRenderTaskList(); - mOffscreenRenderTask = taskList.CreateTask(); - mOffscreenRenderTask.SetSourceActor( mSourceActor ); - mOffscreenRenderTask.SetClearColor( Color::WHITE ); - mOffscreenRenderTask.SetClearEnabled( true ); - mOffscreenRenderTask.SetCameraActor( mCameraActor ); - mOffscreenRenderTask.GetCameraActor().SetInvertYAxis( true ); - mOffscreenRenderTask.SetFrameBuffer( mFrameBuffer ); + mOffscreenRenderTask = taskList.CreateTask(); + mOffscreenRenderTask.SetSourceActor(mSourceActor); + mOffscreenRenderTask.SetClearColor(Color::WHITE); + mOffscreenRenderTask.SetClearEnabled(true); + mOffscreenRenderTask.SetCameraActor(mCameraActor); + mOffscreenRenderTask.GetCameraActor().SetInvertYAxis(true); + mOffscreenRenderTask.SetFrameBuffer(mFrameBuffer); } - if( mRefreshAlways ) + if(mRefreshAlways) { - mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ALWAYS ); + mOffscreenRenderTask.SetRefreshRate(RenderTask::REFRESH_ALWAYS); } else { - mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ONCE ); + mOffscreenRenderTask.SetRefreshRate(RenderTask::REFRESH_ONCE); } } - void SetupDisplayActor( bool show ) + void SetupDisplayActor(bool show) { - if( show ) + if(show) { - if( ! mDisplayActor ) + if(!mDisplayActor) { // Make sure we have something to display SetupNativeImage(); mDisplayActor = Actor::New(); - mDisplayActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mDisplayActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mDisplayActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mDisplayActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); Geometry geometry = DemoHelper::CreateTexturedQuad(); - Shader shader = CreateShader( *mNativeImageSourcePtr ); + Shader shader = CreateShader(*mNativeImageSourcePtr); - Renderer renderer = Renderer::New( geometry, shader ); + Renderer renderer = Renderer::New(geometry, shader); TextureSet textureSet = TextureSet::New(); - textureSet.SetTexture( 0u, mNativeTexture ); - renderer.SetTextures( textureSet ); + textureSet.SetTexture(0u, mNativeTexture); + renderer.SetTextures(textureSet); - mDisplayActor.AddRenderer( renderer ); - mDisplayActor.SetProperty( Actor::Property::SIZE, Vector2( mNativeTexture.GetWidth(), mNativeTexture.GetHeight() ) ); + mDisplayActor.AddRenderer(renderer); + mDisplayActor.SetProperty(Actor::Property::SIZE, Vector2(mNativeTexture.GetWidth(), mNativeTexture.GetHeight())); - mBottomContentArea.Add( mDisplayActor ); + mBottomContentArea.Add(mDisplayActor); } } else { - UnparentAndReset( mDisplayActor ); + UnparentAndReset(mDisplayActor); } } @@ -316,23 +315,23 @@ public: mRefreshAlways = false; SetupNativeImage(); - mOffscreenRenderTask.FinishedSignal().Connect( this, &NativeImageSourceController::DoCapture ); + mOffscreenRenderTask.FinishedSignal().Connect(this, &NativeImageSourceController::DoCapture); } void DoCapture(RenderTask& task) { - task.FinishedSignal().Disconnect( this, &NativeImageSourceController::DoCapture ); + task.FinishedSignal().Disconnect(this, &NativeImageSourceController::DoCapture); - mNativeImageSourcePtr->EncodeToFile( CAPTURE_FILENAME ); + mNativeImageSourcePtr->EncodeToFile(CAPTURE_FILENAME); } void Reset() { - SetupDisplayActor( false ); + SetupDisplayActor(false); - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); RenderTaskList taskList = window.GetRenderTaskList(); - taskList.RemoveTask( mOffscreenRenderTask ); + taskList.RemoveTask(mOffscreenRenderTask); mOffscreenRenderTask.Reset(); mCameraActor.Reset(); @@ -341,40 +340,40 @@ public: mNativeImageSourcePtr.Reset(); } - bool OnButtonSelected( Toolkit::Button button ) + bool OnButtonSelected(Toolkit::Button button) { - Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( button ); + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast(button); - if( pushButton == mButtonShow ) + if(pushButton == mButtonShow) { - bool isSelected = mButtonShow.GetProperty( Toolkit::Button::Property::SELECTED ).Get(); + bool isSelected = mButtonShow.GetProperty(Toolkit::Button::Property::SELECTED).Get(); - SetupDisplayActor( isSelected ); + SetupDisplayActor(isSelected); } - else if( pushButton == mButtonRefreshAlways ) + else if(pushButton == mButtonRefreshAlways) { - bool isSelected = mButtonRefreshAlways.GetProperty( Toolkit::Button::Property::SELECTED ).Get(); + bool isSelected = mButtonRefreshAlways.GetProperty(Toolkit::Button::Property::SELECTED).Get(); mRefreshAlways = isSelected; SetupNativeImage(); } - else if( pushButton == mButtonRefreshOnce ) + else if(pushButton == mButtonRefreshOnce) { - bool isSelected = mButtonRefreshAlways.GetProperty( Toolkit::Button::Property::SELECTED ).Get(); + bool isSelected = mButtonRefreshAlways.GetProperty(Toolkit::Button::Property::SELECTED).Get(); - if( isSelected ) + if(isSelected) { - mButtonRefreshAlways.SetProperty( Button::Property::SELECTED, false ); + mButtonRefreshAlways.SetProperty(Button::Property::SELECTED, false); } mRefreshAlways = false; SetupNativeImage(); } - else if( pushButton == mButtonCapture ) + else if(pushButton == mButtonCapture) { Capture(); } - else if( pushButton == mButtonReset ) + else if(pushButton == mButtonReset) { Reset(); } @@ -386,7 +385,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -394,8 +393,7 @@ public: } private: - - Application& mApplication; + Application& mApplication; Layer mButtonArea; Actor mTopContentArea; @@ -413,7 +411,7 @@ private: Texture mNativeTexture; FrameBuffer mFrameBuffer; - RenderTask mOffscreenRenderTask; + RenderTask mOffscreenRenderTask; CameraActor mCameraActor; Actor mDisplayActor; @@ -421,10 +419,10 @@ private: bool mRefreshAlways; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - NativeImageSourceController test( application ); + Application application = Application::New(&argc, &argv); + NativeImageSourceController test(application); application.MainLoop(); return 0; } diff --git a/examples/page-turn-view/page-turn-view-example.cpp b/examples/page-turn-view/page-turn-view-example.cpp index 9e3a238..dc3315a 100644 --- a/examples/page-turn-view/page-turn-view-example.cpp +++ b/examples/page-turn-view/page-turn-view-example.cpp @@ -15,48 +15,45 @@ * */ -#include #include #include #include #include #include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { - -const char* BOOK_COVER_PORTRAIT = ( DEMO_IMAGE_DIR "book-portrait-cover.jpg" ); -const char* BOOK_COVER_LANDSCAPE = ( DEMO_IMAGE_DIR "book-landscape-cover.jpg" ); -const char* BOOK_COVER_BACK_LANDSCAPE = ( DEMO_IMAGE_DIR "book-landscape-cover-back.jpg" ); +const char* BOOK_COVER_PORTRAIT = (DEMO_IMAGE_DIR "book-portrait-cover.jpg"); +const char* BOOK_COVER_LANDSCAPE = (DEMO_IMAGE_DIR "book-landscape-cover.jpg"); +const char* BOOK_COVER_BACK_LANDSCAPE = (DEMO_IMAGE_DIR "book-landscape-cover-back.jpg"); const char* PAGE_IMAGES_PORTRAIT[] = -{ - DEMO_IMAGE_DIR "book-portrait-p1.jpg", - DEMO_IMAGE_DIR "book-portrait-p2.jpg", - DEMO_IMAGE_DIR "book-portrait-p3.jpg", - DEMO_IMAGE_DIR "book-portrait-p4.jpg", - DEMO_IMAGE_DIR "book-portrait-p5.jpg", - DEMO_IMAGE_DIR "book-portrait-p6.jpg", - DEMO_IMAGE_DIR "book-portrait-p7.jpg", - DEMO_IMAGE_DIR "book-portrait-p8.jpg" -}; -const unsigned int NUMBER_OF_PORTRAIT_IMAGE( sizeof(PAGE_IMAGES_PORTRAIT) / sizeof(PAGE_IMAGES_PORTRAIT[0]) ); + { + DEMO_IMAGE_DIR "book-portrait-p1.jpg", + DEMO_IMAGE_DIR "book-portrait-p2.jpg", + DEMO_IMAGE_DIR "book-portrait-p3.jpg", + DEMO_IMAGE_DIR "book-portrait-p4.jpg", + DEMO_IMAGE_DIR "book-portrait-p5.jpg", + DEMO_IMAGE_DIR "book-portrait-p6.jpg", + DEMO_IMAGE_DIR "book-portrait-p7.jpg", + DEMO_IMAGE_DIR "book-portrait-p8.jpg"}; +const unsigned int NUMBER_OF_PORTRAIT_IMAGE(sizeof(PAGE_IMAGES_PORTRAIT) / sizeof(PAGE_IMAGES_PORTRAIT[0])); const char* PAGE_IMAGES_LANDSCAPE[] = -{ - DEMO_IMAGE_DIR "book-landscape-p1.jpg", - DEMO_IMAGE_DIR "book-landscape-p2.jpg", - DEMO_IMAGE_DIR "book-landscape-p3.jpg", - DEMO_IMAGE_DIR "book-landscape-p4.jpg", - DEMO_IMAGE_DIR "book-landscape-p5.jpg", - DEMO_IMAGE_DIR "book-landscape-p6.jpg", - DEMO_IMAGE_DIR "book-landscape-p7.jpg", - DEMO_IMAGE_DIR "book-landscape-p8.jpg" -}; -const unsigned int NUMBER_OF_LANDSCAPE_IMAGE( sizeof(PAGE_IMAGES_LANDSCAPE) / sizeof(PAGE_IMAGES_LANDSCAPE[0]) ); + { + DEMO_IMAGE_DIR "book-landscape-p1.jpg", + DEMO_IMAGE_DIR "book-landscape-p2.jpg", + DEMO_IMAGE_DIR "book-landscape-p3.jpg", + DEMO_IMAGE_DIR "book-landscape-p4.jpg", + DEMO_IMAGE_DIR "book-landscape-p5.jpg", + DEMO_IMAGE_DIR "book-landscape-p6.jpg", + DEMO_IMAGE_DIR "book-landscape-p7.jpg", + DEMO_IMAGE_DIR "book-landscape-p8.jpg"}; +const unsigned int NUMBER_OF_LANDSCAPE_IMAGE(sizeof(PAGE_IMAGES_LANDSCAPE) / sizeof(PAGE_IMAGES_LANDSCAPE[0])); enum DemoOrientation { @@ -65,7 +62,7 @@ enum DemoOrientation UNKNOWN }; -} +} // namespace class PortraitPageFactory : public PageFactory { @@ -75,7 +72,7 @@ class PortraitPageFactory : public PageFactory */ virtual unsigned int GetNumberOfPages() { - return 5*NUMBER_OF_PORTRAIT_IMAGE + 1; + return 5 * NUMBER_OF_PORTRAIT_IMAGE + 1; } /** @@ -83,24 +80,24 @@ class PortraitPageFactory : public PageFactory * @param[in] pageId The ID of the page to create. * @return The texture. */ - virtual Texture NewPage( unsigned int pageId ) + virtual Texture NewPage(unsigned int pageId) { Texture texture; PixelData pixels; - if( pageId == 0 ) + if(pageId == 0) { - pixels = SyncImageLoader::Load( BOOK_COVER_PORTRAIT ); + pixels = SyncImageLoader::Load(BOOK_COVER_PORTRAIT); } else { - pixels = SyncImageLoader::Load( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] ); + pixels = SyncImageLoader::Load(PAGE_IMAGES_PORTRAIT[(pageId - 1) % NUMBER_OF_PORTRAIT_IMAGE]); } - if( pixels ) + if(pixels) { - texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() ); - texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() ); + texture = Texture::New(TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight()); + texture.Upload(pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight()); } return texture; @@ -115,7 +112,7 @@ class LandscapePageFactory : public PageFactory */ virtual unsigned int GetNumberOfPages() { - return 5*NUMBER_OF_LANDSCAPE_IMAGE / 2 + 1; + return 5 * NUMBER_OF_LANDSCAPE_IMAGE / 2 + 1; } /** @@ -123,30 +120,30 @@ class LandscapePageFactory : public PageFactory * @param[in] pageId The ID of the page to create. * @return The texture. */ - virtual Texture NewPage( unsigned int pageId ) + virtual Texture NewPage(unsigned int pageId) { Texture texture; PixelData pixelsFront; PixelData pixelsBack; - if( pageId == 0 ) + if(pageId == 0) { - pixelsFront = SyncImageLoader::Load( BOOK_COVER_LANDSCAPE ); - pixelsBack = SyncImageLoader::Load( BOOK_COVER_BACK_LANDSCAPE ); + pixelsFront = SyncImageLoader::Load(BOOK_COVER_LANDSCAPE); + pixelsBack = SyncImageLoader::Load(BOOK_COVER_BACK_LANDSCAPE); } else { - unsigned int imageId = (pageId-1)*2; - pixelsFront = SyncImageLoader::Load( PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ] ); - pixelsBack = SyncImageLoader::Load( PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] ); + unsigned int imageId = (pageId - 1) * 2; + pixelsFront = SyncImageLoader::Load(PAGE_IMAGES_LANDSCAPE[imageId % NUMBER_OF_LANDSCAPE_IMAGE]); + pixelsBack = SyncImageLoader::Load(PAGE_IMAGES_LANDSCAPE[(imageId + 1) % NUMBER_OF_LANDSCAPE_IMAGE]); } - if( pixelsFront && pixelsBack ) + if(pixelsFront && pixelsBack) { - texture = Texture::New( TextureType::TEXTURE_2D, pixelsFront.GetPixelFormat(), pixelsFront.GetWidth()*2, pixelsFront.GetHeight() ); - texture.Upload( pixelsFront, 0, 0, 0, 0, pixelsFront.GetWidth(), pixelsFront.GetHeight() ); - texture.Upload( pixelsBack, 0, 0, pixelsFront.GetWidth(), 0, pixelsBack.GetWidth(), pixelsBack.GetHeight() ); + texture = Texture::New(TextureType::TEXTURE_2D, pixelsFront.GetPixelFormat(), pixelsFront.GetWidth() * 2, pixelsFront.GetHeight()); + texture.Upload(pixelsFront, 0, 0, 0, 0, pixelsFront.GetWidth(), pixelsFront.GetHeight()); + texture.Upload(pixelsBack, 0, 0, pixelsFront.GetWidth(), 0, pixelsBack.GetWidth(), pixelsBack.GetHeight()); } return texture; @@ -159,39 +156,35 @@ class LandscapePageFactory : public PageFactory class PageTurnExample : public ConnectionTracker { public: - - PageTurnExample( Application &app ); + PageTurnExample(Application& app); ~PageTurnExample(); - void OnInit( Application& app ); + void OnInit(Application& app); private: + void OnWindowResized(Window window, Window::WindowSize size); - - void OnWindowResized( Window window, Window::WindowSize size ); - - void Rotate( DemoOrientation orientation ); + void Rotate(DemoOrientation orientation); void OnKeyEvent(const KeyEvent& event); private: + Application& mApplication; - Application& mApplication; - - PageTurnView mPageTurnPortraitView; - PageTurnView mPageTurnLandscapeView; - PortraitPageFactory mPortraitPageFactory; - LandscapePageFactory mLandscapePageFactory; + PageTurnView mPageTurnPortraitView; + PageTurnView mPageTurnLandscapeView; + PortraitPageFactory mPortraitPageFactory; + LandscapePageFactory mLandscapePageFactory; - DemoOrientation mOrientation; + DemoOrientation mOrientation; }; -PageTurnExample::PageTurnExample( Application &app ) -: mApplication( app ), - mOrientation( UNKNOWN ) +PageTurnExample::PageTurnExample(Application& app) +: mApplication(app), + mOrientation(UNKNOWN) { - app.InitSignal().Connect( this, &PageTurnExample::OnInit ); + app.InitSignal().Connect(this, &PageTurnExample::OnInit); } PageTurnExample::~PageTurnExample() @@ -201,63 +194,63 @@ PageTurnExample::~PageTurnExample() /** * The Init signal is received once (only) during the Application lifetime */ -void PageTurnExample::OnInit( Application& app ) +void PageTurnExample::OnInit(Application& app) { Window window = app.GetWindow(); window.KeyEventSignal().Connect(this, &PageTurnExample::OnKeyEvent); - window.AddAvailableOrientation( Window::PORTRAIT ); - window.AddAvailableOrientation( Window::LANDSCAPE ); - window.AddAvailableOrientation( Window::PORTRAIT_INVERSE ); - window.AddAvailableOrientation( Window::LANDSCAPE_INVERSE ); - window.ResizeSignal().Connect( this, &PageTurnExample::OnWindowResized ); + window.AddAvailableOrientation(Window::PORTRAIT); + window.AddAvailableOrientation(Window::LANDSCAPE); + window.AddAvailableOrientation(Window::PORTRAIT_INVERSE); + window.AddAvailableOrientation(Window::LANDSCAPE_INVERSE); + window.ResizeSignal().Connect(this, &PageTurnExample::OnWindowResized); Window::WindowSize size = window.GetSize(); - Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT ); + Rotate(size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT); } -void PageTurnExample::OnWindowResized( Window window, Window::WindowSize size ) +void PageTurnExample::OnWindowResized(Window window, Window::WindowSize size) { - Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT ); + Rotate(size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT); } -void PageTurnExample::Rotate( DemoOrientation orientation ) +void PageTurnExample::Rotate(DemoOrientation orientation) { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - if( mOrientation != orientation ) + if(mOrientation != orientation) { mOrientation = orientation; - if( PORTRAIT == orientation ) + if(PORTRAIT == orientation) { - if( !mPageTurnPortraitView ) + if(!mPageTurnPortraitView) { - mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, windowSize ); - mPageTurnPortraitView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mPageTurnPortraitView = PageTurnPortraitView::New(mPortraitPageFactory, windowSize); + mPageTurnPortraitView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); } - if( mPageTurnLandscapeView ) + if(mPageTurnLandscapeView) { - window.Remove( mPageTurnLandscapeView ); + window.Remove(mPageTurnLandscapeView); } - window.Add( mPageTurnPortraitView ); + window.Add(mPageTurnPortraitView); } - else if( LANDSCAPE == orientation ) + else if(LANDSCAPE == orientation) { - if( !mPageTurnLandscapeView ) + if(!mPageTurnLandscapeView) { - mPageTurnLandscapeView = PageTurnLandscapeView::New( mLandscapePageFactory, Vector2(windowSize.x*0.5f, windowSize.y) ); - mPageTurnLandscapeView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mPageTurnLandscapeView = PageTurnLandscapeView::New(mLandscapePageFactory, Vector2(windowSize.x * 0.5f, windowSize.y)); + mPageTurnLandscapeView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); } - if( mPageTurnPortraitView ) + if(mPageTurnPortraitView) { - window.Remove( mPageTurnPortraitView ); + window.Remove(mPageTurnPortraitView); } - window.Add( mPageTurnLandscapeView ); + window.Add(mPageTurnLandscapeView); } } } @@ -269,7 +262,7 @@ void PageTurnExample::OnKeyEvent(const KeyEvent& event) { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -277,13 +270,12 @@ void PageTurnExample::OnKeyEvent(const KeyEvent& event) } // Entry point for applications -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv); - PageTurnExample test ( app ); + Application app = Application::New(&argc, &argv); + PageTurnExample test(app); app.MainLoop(); return 0; } - diff --git a/examples/perf-scroll/perf-scroll.cpp b/examples/perf-scroll/perf-scroll.cpp index ea9b633..798194a 100644 --- a/examples/perf-scroll/perf-scroll.cpp +++ b/examples/perf-scroll/perf-scroll.cpp @@ -22,125 +22,124 @@ using namespace Dali; using namespace Dali::Toolkit; - namespace { const char* IMAGE_PATH[] = { - DEMO_IMAGE_DIR "gallery-medium-1.jpg", - DEMO_IMAGE_DIR "gallery-medium-2.jpg", - DEMO_IMAGE_DIR "gallery-medium-3.jpg", - DEMO_IMAGE_DIR "gallery-medium-4.jpg", - DEMO_IMAGE_DIR "gallery-medium-5.jpg", - DEMO_IMAGE_DIR "gallery-medium-6.jpg", - DEMO_IMAGE_DIR "gallery-medium-7.jpg", - DEMO_IMAGE_DIR "gallery-medium-8.jpg", - DEMO_IMAGE_DIR "gallery-medium-9.jpg", - DEMO_IMAGE_DIR "gallery-medium-10.jpg", - DEMO_IMAGE_DIR "gallery-medium-11.jpg", - DEMO_IMAGE_DIR "gallery-medium-12.jpg", - DEMO_IMAGE_DIR "gallery-medium-13.jpg", - DEMO_IMAGE_DIR "gallery-medium-14.jpg", - DEMO_IMAGE_DIR "gallery-medium-15.jpg", - DEMO_IMAGE_DIR "gallery-medium-16.jpg", - DEMO_IMAGE_DIR "gallery-medium-17.jpg", - DEMO_IMAGE_DIR "gallery-medium-18.jpg", - DEMO_IMAGE_DIR "gallery-medium-19.jpg", - DEMO_IMAGE_DIR "gallery-medium-20.jpg", - DEMO_IMAGE_DIR "gallery-medium-21.jpg", - DEMO_IMAGE_DIR "gallery-medium-22.jpg", - DEMO_IMAGE_DIR "gallery-medium-23.jpg", - DEMO_IMAGE_DIR "gallery-medium-24.jpg", - DEMO_IMAGE_DIR "gallery-medium-25.jpg", - DEMO_IMAGE_DIR "gallery-medium-26.jpg", - DEMO_IMAGE_DIR "gallery-medium-27.jpg", - DEMO_IMAGE_DIR "gallery-medium-28.jpg", - DEMO_IMAGE_DIR "gallery-medium-29.jpg", - DEMO_IMAGE_DIR "gallery-medium-30.jpg", - DEMO_IMAGE_DIR "gallery-medium-31.jpg", - DEMO_IMAGE_DIR "gallery-medium-32.jpg", - DEMO_IMAGE_DIR "gallery-medium-33.jpg", - DEMO_IMAGE_DIR "gallery-medium-34.jpg", - DEMO_IMAGE_DIR "gallery-medium-35.jpg", - DEMO_IMAGE_DIR "gallery-medium-36.jpg", - DEMO_IMAGE_DIR "gallery-medium-37.jpg", - DEMO_IMAGE_DIR "gallery-medium-38.jpg", - DEMO_IMAGE_DIR "gallery-medium-39.jpg", - DEMO_IMAGE_DIR "gallery-medium-40.jpg", - DEMO_IMAGE_DIR "gallery-medium-41.jpg", - DEMO_IMAGE_DIR "gallery-medium-42.jpg", - DEMO_IMAGE_DIR "gallery-medium-43.jpg", - DEMO_IMAGE_DIR "gallery-medium-44.jpg", - DEMO_IMAGE_DIR "gallery-medium-45.jpg", - DEMO_IMAGE_DIR "gallery-medium-46.jpg", - DEMO_IMAGE_DIR "gallery-medium-47.jpg", - DEMO_IMAGE_DIR "gallery-medium-48.jpg", - DEMO_IMAGE_DIR "gallery-medium-49.jpg", - DEMO_IMAGE_DIR "gallery-medium-50.jpg", - DEMO_IMAGE_DIR "gallery-medium-51.jpg", - DEMO_IMAGE_DIR "gallery-medium-52.jpg", - DEMO_IMAGE_DIR "gallery-medium-53.jpg", + DEMO_IMAGE_DIR "gallery-medium-1.jpg", + DEMO_IMAGE_DIR "gallery-medium-2.jpg", + DEMO_IMAGE_DIR "gallery-medium-3.jpg", + DEMO_IMAGE_DIR "gallery-medium-4.jpg", + DEMO_IMAGE_DIR "gallery-medium-5.jpg", + DEMO_IMAGE_DIR "gallery-medium-6.jpg", + DEMO_IMAGE_DIR "gallery-medium-7.jpg", + DEMO_IMAGE_DIR "gallery-medium-8.jpg", + DEMO_IMAGE_DIR "gallery-medium-9.jpg", + DEMO_IMAGE_DIR "gallery-medium-10.jpg", + DEMO_IMAGE_DIR "gallery-medium-11.jpg", + DEMO_IMAGE_DIR "gallery-medium-12.jpg", + DEMO_IMAGE_DIR "gallery-medium-13.jpg", + DEMO_IMAGE_DIR "gallery-medium-14.jpg", + DEMO_IMAGE_DIR "gallery-medium-15.jpg", + DEMO_IMAGE_DIR "gallery-medium-16.jpg", + DEMO_IMAGE_DIR "gallery-medium-17.jpg", + DEMO_IMAGE_DIR "gallery-medium-18.jpg", + DEMO_IMAGE_DIR "gallery-medium-19.jpg", + DEMO_IMAGE_DIR "gallery-medium-20.jpg", + DEMO_IMAGE_DIR "gallery-medium-21.jpg", + DEMO_IMAGE_DIR "gallery-medium-22.jpg", + DEMO_IMAGE_DIR "gallery-medium-23.jpg", + DEMO_IMAGE_DIR "gallery-medium-24.jpg", + DEMO_IMAGE_DIR "gallery-medium-25.jpg", + DEMO_IMAGE_DIR "gallery-medium-26.jpg", + DEMO_IMAGE_DIR "gallery-medium-27.jpg", + DEMO_IMAGE_DIR "gallery-medium-28.jpg", + DEMO_IMAGE_DIR "gallery-medium-29.jpg", + DEMO_IMAGE_DIR "gallery-medium-30.jpg", + DEMO_IMAGE_DIR "gallery-medium-31.jpg", + DEMO_IMAGE_DIR "gallery-medium-32.jpg", + DEMO_IMAGE_DIR "gallery-medium-33.jpg", + DEMO_IMAGE_DIR "gallery-medium-34.jpg", + DEMO_IMAGE_DIR "gallery-medium-35.jpg", + DEMO_IMAGE_DIR "gallery-medium-36.jpg", + DEMO_IMAGE_DIR "gallery-medium-37.jpg", + DEMO_IMAGE_DIR "gallery-medium-38.jpg", + DEMO_IMAGE_DIR "gallery-medium-39.jpg", + DEMO_IMAGE_DIR "gallery-medium-40.jpg", + DEMO_IMAGE_DIR "gallery-medium-41.jpg", + DEMO_IMAGE_DIR "gallery-medium-42.jpg", + DEMO_IMAGE_DIR "gallery-medium-43.jpg", + DEMO_IMAGE_DIR "gallery-medium-44.jpg", + DEMO_IMAGE_DIR "gallery-medium-45.jpg", + DEMO_IMAGE_DIR "gallery-medium-46.jpg", + DEMO_IMAGE_DIR "gallery-medium-47.jpg", + DEMO_IMAGE_DIR "gallery-medium-48.jpg", + DEMO_IMAGE_DIR "gallery-medium-49.jpg", + DEMO_IMAGE_DIR "gallery-medium-50.jpg", + DEMO_IMAGE_DIR "gallery-medium-51.jpg", + DEMO_IMAGE_DIR "gallery-medium-52.jpg", + DEMO_IMAGE_DIR "gallery-medium-53.jpg", }; const char* NINEPATCH_IMAGE_PATH[] = { - DEMO_IMAGE_DIR "selection-popup-bg.1.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.2.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.3.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.4.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.5.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.6.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.7.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.8.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.9.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.10.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.11.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.12.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.13.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.14.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.15.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.16.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.17.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.18.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.19.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.20.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.21.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.22.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.23.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.24.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.25.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.26.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.27.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.28.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.29.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.30.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.31.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.32.9.png", - DEMO_IMAGE_DIR "selection-popup-bg.33.9.png", - DEMO_IMAGE_DIR "button-disabled.9.png", - DEMO_IMAGE_DIR "button-down.9.png", - DEMO_IMAGE_DIR "button-down-disabled.9.png", - DEMO_IMAGE_DIR "button-up-1.9.png", - DEMO_IMAGE_DIR "button-up-2.9.png", - DEMO_IMAGE_DIR "button-up-3.9.png", - DEMO_IMAGE_DIR "button-up-4.9.png", - DEMO_IMAGE_DIR "button-up-5.9.png", - DEMO_IMAGE_DIR "button-up-6.9.png", - DEMO_IMAGE_DIR "button-up-7.9.png", - DEMO_IMAGE_DIR "button-up-8.9.png", - DEMO_IMAGE_DIR "button-up-9.9.png", - DEMO_IMAGE_DIR "button-up-10.9.png", - DEMO_IMAGE_DIR "button-up-11.9.png", - DEMO_IMAGE_DIR "button-up-12.9.png", - DEMO_IMAGE_DIR "button-up-13.9.png", - DEMO_IMAGE_DIR "button-up-14.9.png", - DEMO_IMAGE_DIR "button-up-15.9.png", - DEMO_IMAGE_DIR "button-up-16.9.png", - DEMO_IMAGE_DIR "button-up-17.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.1.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.2.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.3.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.4.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.5.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.6.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.7.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.8.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.9.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.10.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.11.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.12.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.13.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.14.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.15.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.16.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.17.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.18.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.19.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.20.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.21.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.22.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.23.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.24.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.25.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.26.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.27.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.28.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.29.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.30.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.31.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.32.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.33.9.png", + DEMO_IMAGE_DIR "button-disabled.9.png", + DEMO_IMAGE_DIR "button-down.9.png", + DEMO_IMAGE_DIR "button-down-disabled.9.png", + DEMO_IMAGE_DIR "button-up-1.9.png", + DEMO_IMAGE_DIR "button-up-2.9.png", + DEMO_IMAGE_DIR "button-up-3.9.png", + DEMO_IMAGE_DIR "button-up-4.9.png", + DEMO_IMAGE_DIR "button-up-5.9.png", + DEMO_IMAGE_DIR "button-up-6.9.png", + DEMO_IMAGE_DIR "button-up-7.9.png", + DEMO_IMAGE_DIR "button-up-8.9.png", + DEMO_IMAGE_DIR "button-up-9.9.png", + DEMO_IMAGE_DIR "button-up-10.9.png", + DEMO_IMAGE_DIR "button-up-11.9.png", + DEMO_IMAGE_DIR "button-up-12.9.png", + DEMO_IMAGE_DIR "button-up-13.9.png", + DEMO_IMAGE_DIR "button-up-14.9.png", + DEMO_IMAGE_DIR "button-up-15.9.png", + DEMO_IMAGE_DIR "button-up-16.9.png", + DEMO_IMAGE_DIR "button-up-17.9.png", }; -const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); +const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); const unsigned int NUM_NINEPATCH_IMAGES = sizeof(NINEPATCH_IMAGE_PATH) / sizeof(char*); -const float ANIMATION_TIME ( 5.0f ); // animation length in seconds +const float ANIMATION_TIME(5.0f); // animation length in seconds struct VertexWithTexture { @@ -148,6 +147,8 @@ struct VertexWithTexture Vector2 texCoord; }; +// clang-format off + const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n attribute mediump vec2 aTexCoord;\n @@ -173,27 +174,28 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( }\n ); -bool gUseMesh(false); -bool gNinePatch(false); +// clang-format on + +bool gUseMesh(false); +bool gNinePatch(false); unsigned int gRowsPerPage(15); unsigned int gColumnsPerPage(15); unsigned int gPageCount(10); -float gDuration(10.0f); +float gDuration(10.0f); -Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) +Renderer CreateRenderer(unsigned int index, Geometry geometry, Shader shader) { - Renderer renderer = Renderer::New( geometry, shader ); - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; - Texture texture = DemoHelper::LoadTexture( imagePath ); - TextureSet textureSet = TextureSet::New(); - textureSet.SetTexture( 0u, texture ); - renderer.SetTextures( textureSet ); - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); + Renderer renderer = Renderer::New(geometry, shader); + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; + Texture texture = DemoHelper::LoadTexture(imagePath); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture(0u, texture); + renderer.SetTextures(textureSet); + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF); return renderer; } - -} +} // namespace // Test application to compare performance between ImageActor and ImageView // By default, the application consist of 10 pages of 25x25 ImageActors, this can be modified using the following command line arguments: // -t duration (sec ) @@ -204,15 +206,14 @@ Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) class PerfScroll : public ConnectionTracker { public: - - PerfScroll( Application& application ) - : mApplication( application ), - mRowsPerPage( gRowsPerPage ), - mColumnsPerPage( gColumnsPerPage ), - mPageCount( gPageCount ) + PerfScroll(Application& application) + : mApplication(application), + mRowsPerPage(gRowsPerPage), + mColumnsPerPage(gColumnsPerPage), + mPageCount(gPageCount) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &PerfScroll::Create ); + mApplication.InitSignal().Connect(this, &PerfScroll::Create); } ~PerfScroll() @@ -221,28 +222,28 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); Vector2 windowSize = window.GetSize(); - window.GetRootLayer().SetProperty( Layer::Property::DEPTH_TEST, false ); + window.GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, false); - mSize = Vector3( windowSize.x / mColumnsPerPage, windowSize.y / mRowsPerPage, 0.0f ); + mSize = Vector3(windowSize.x / mColumnsPerPage, windowSize.y / mRowsPerPage, 0.0f); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &PerfScroll::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &PerfScroll::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &PerfScroll::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &PerfScroll::OnKeyEvent); mParent = Actor::New(); - mParent.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mParent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); window.Add(mParent); - if( gUseMesh ) + if(gUseMesh) { CreateMeshActors(); } @@ -254,25 +255,25 @@ public: ShowAnimation(); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); return true; } - const char* ImagePath( int i ) + const char* ImagePath(int i) { return !gNinePatch ? IMAGE_PATH[i % NUM_IMAGES] : NINEPATCH_IMAGE_PATH[i % NUM_NINEPATCH_IMAGES]; } void CreateImageViews() { - Window window = mApplication.GetWindow(); - unsigned int actorCount( mRowsPerPage*mColumnsPerPage * mPageCount ); - mImageView.resize( actorCount ); + Window window = mApplication.GetWindow(); + unsigned int actorCount(mRowsPerPage * mColumnsPerPage * mPageCount); + mImageView.resize(actorCount); - for( size_t i(0); i renderers( numImages ); - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); - Geometry geometry = DemoHelper::CreateTexturedQuad(); - for( unsigned int i(0); i renderers(numImages); + Shader shader = Shader::New(VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE); + Geometry geometry = DemoHelper::CreateTexturedQuad(); + for(unsigned int i(0); i < numImages; ++i) { - renderers[i] = CreateRenderer( i, geometry, shader ); + renderers[i] = CreateRenderer(i, geometry, shader); } //Create the actors - Window window = mApplication.GetWindow(); - unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount); + Window window = mApplication.GetWindow(); + unsigned int actorCount(mRowsPerPage * mColumnsPerPage * mPageCount); mActor.resize(actorCount); - for( size_t i(0); i( mRowsPerPage ) * mColumnsPerPage ) ) + if(count < (static_cast(mRowsPerPage) * mColumnsPerPage)) { duration = durationPerActor; - delay = delayBetweenActors * count; + delay = delayBetweenActors * count; } - if( gUseMesh ) + if(gUseMesh) { - mActor[count].SetProperty( Actor::Property::POSITION, initialPosition ); - mActor[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) ); - mActor[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Quaternion( Radian( 0.0f ), Vector3::XAXIS ) ) ); - mShow.AnimateTo( Property( mActor[count], Actor::Property::POSITION ), Vector3( xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) ); - mShow.AnimateTo( Property( mActor[count], Actor::Property::SIZE ), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) ); + mActor[count].SetProperty(Actor::Property::POSITION, initialPosition); + mActor[count].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); + mActor[count].SetProperty(Actor::Property::ORIENTATION, Quaternion(Quaternion(Radian(0.0f), Vector3::XAXIS))); + mShow.AnimateTo(Property(mActor[count], Actor::Property::POSITION), Vector3(xpos + mSize.x * 0.5f, ypos + mSize.y * 0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); + mShow.AnimateTo(Property(mActor[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); } else { - mImageView[count].SetProperty( Actor::Property::POSITION, initialPosition ); - mImageView[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) ); - mImageView[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Quaternion( Radian(0.0f), Vector3::XAXIS ) ) ); - mShow.AnimateTo( Property( mImageView[count], Actor::Property::POSITION ), Vector3( xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f ), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) ); - mShow.AnimateTo( Property( mImageView[count], Actor::Property::SIZE ), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) ); + mImageView[count].SetProperty(Actor::Property::POSITION, initialPosition); + mImageView[count].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); + mImageView[count].SetProperty(Actor::Property::ORIENTATION, Quaternion(Quaternion(Radian(0.0f), Vector3::XAXIS))); + mShow.AnimateTo(Property(mImageView[count], Actor::Property::POSITION), Vector3(xpos + mSize.x * 0.5f, ypos + mSize.y * 0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); + mShow.AnimateTo(Property(mImageView[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); } ++count; } } mShow.Play(); - mShow.FinishedSignal().Connect( this, &PerfScroll::OnAnimationEnd ); + mShow.FinishedSignal().Connect(this, &PerfScroll::OnAnimationEnd); } void ScrollAnimation() { - Window window = mApplication.GetWindow(); - Vector3 windowSize( window.GetSize() ); + Window window = mApplication.GetWindow(); + Vector3 windowSize(window.GetSize()); - mScroll = Animation::New( gDuration ); + mScroll = Animation::New(gDuration); - mScroll.AnimateBy( Property( mParent, Actor::Property::POSITION ), Vector3( -(gPageCount-1.)*windowSize.x,0.0f, 0.0f) ); + mScroll.AnimateBy(Property(mParent, Actor::Property::POSITION), Vector3(-(gPageCount - 1.) * windowSize.x, 0.0f, 0.0f)); mScroll.Play(); - mScroll.FinishedSignal().Connect( this, &PerfScroll::OnAnimationEnd ); + mScroll.FinishedSignal().Connect(this, &PerfScroll::OnAnimationEnd); } void HideAnimation() { - size_t count(0); - unsigned int actorsPerPage( mRowsPerPage*mColumnsPerPage ); - mHide = Animation::New( 0.0f ); + size_t count(0); + unsigned int actorsPerPage(mRowsPerPage * mColumnsPerPage); + mHide = Animation::New(0.0f); unsigned int totalColumns = mColumnsPerPage * mPageCount; - float totalDuration( 0.0f ); - float durationPerActor( 0.0f ); - float delayBetweenActors = ( totalDuration - durationPerActor ) / ( mRowsPerPage * mColumnsPerPage ); - for( size_t i(0); i mActor; - std::vector mImageView; - Actor mParent; + std::vector mActor; + std::vector mImageView; + Actor mParent; - Vector3 mSize; - unsigned int mRowsPerPage; - unsigned int mColumnsPerPage; - unsigned int mPageCount; + Vector3 mSize; + unsigned int mRowsPerPage; + unsigned int mColumnsPerPage; + unsigned int mPageCount; - Animation mShow; - Animation mScroll; - Animation mHide; + Animation mShow; + Animation mScroll; + Animation mHide; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - for( int i(1) ; i < argc; ++i ) + for(int i(1); i < argc; ++i) { - std::string arg( argv[i] ); - if( arg.compare("--use-mesh") == 0) + std::string arg(argv[i]); + if(arg.compare("--use-mesh") == 0) { gUseMesh = true; } - else if( arg.compare("--nine-patch" ) == 0) + else if(arg.compare("--nine-patch") == 0) { gNinePatch = true; } - else if( arg.compare(0, 2, "-t" ) == 0) + else if(arg.compare(0, 2, "-t") == 0) { - gDuration = atof( arg.substr( 2, arg.size()).c_str()); + gDuration = atof(arg.substr(2, arg.size()).c_str()); } } - PerfScroll test( application ); + PerfScroll test(application); application.MainLoop(); return 0; diff --git a/examples/pivot/pivot-example.cpp b/examples/pivot/pivot-example.cpp index 5cf21e7..826b4e4 100644 --- a/examples/pivot/pivot-example.cpp +++ b/examples/pivot/pivot-example.cpp @@ -26,17 +26,17 @@ using namespace Dali::Toolkit; namespace { -const int TABLE_VIEW_ROWS = 5; -const int TABLE_VIEW_COLUMNS = 3; -const Vector3 TABLE_VIEW_SIZE_MODE_FACTOR( 0.6f, 0.6f, 1.0f ); +const int TABLE_VIEW_ROWS = 5; +const int TABLE_VIEW_COLUMNS = 3; +const Vector3 TABLE_VIEW_SIZE_MODE_FACTOR(0.6f, 0.6f, 1.0f); -const Quaternion ANIMATION_ROTATION( Degree( 360.0f), Vector3::ZAXIS ); -const AlphaFunction::BuiltinFunction ROTATION_ANIMATION_ALPHA_FUNCTION( AlphaFunction::EASE_IN_OUT ); -const TimePeriod ROTATION_ANIMATION_TIME_PERIOD( 0.0f, 0.5f ); +const Quaternion ANIMATION_ROTATION(Degree(360.0f), Vector3::ZAXIS); +const AlphaFunction::BuiltinFunction ROTATION_ANIMATION_ALPHA_FUNCTION(AlphaFunction::EASE_IN_OUT); +const TimePeriod ROTATION_ANIMATION_TIME_PERIOD(0.0f, 0.5f); -const Vector3 ANIMATION_SCALE( 2.0f, 2.0f, 1.0f ); -const AlphaFunction::BuiltinFunction SCALE_ANIMATION_ALPHA_FUNCTION( AlphaFunction::SIN ); -const TimePeriod SCALE_ANIMATION_TIME_PERIOD( 0.15f, 0.85f ); +const Vector3 ANIMATION_SCALE(2.0f, 2.0f, 1.0f); +const AlphaFunction::BuiltinFunction SCALE_ANIMATION_ALPHA_FUNCTION(AlphaFunction::SIN); +const TimePeriod SCALE_ANIMATION_TIME_PERIOD(0.15f, 0.85f); } // unnamed namespace /** @@ -47,64 +47,62 @@ const TimePeriod SCALE_ANIMATION_TIME_PERIOD( 0.15f, 0.85f ); class PivotController : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application Reference to the application instance. */ - PivotController( Application& application ) - : mApplication( application ) + PivotController(Application& application) + : mApplication(application) { - mApplication.InitSignal().Connect( this, &PivotController::Create ); + mApplication.InitSignal().Connect(this, &PivotController::Create); } private: - /** * @brief The Init signal is received once (only) during the Application lifetime. */ - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); - window.KeyEventSignal().Connect( this, &PivotController::OnKeyEvent ); + window.SetBackgroundColor(Color::WHITE); + window.KeyEventSignal().Connect(this, &PivotController::OnKeyEvent); // Create a table view. - TableView tableView = TableView::New( TABLE_VIEW_ROWS, TABLE_VIEW_COLUMNS ); - tableView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - tableView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - tableView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - tableView.SetProperty( Actor::Property::SIZE_MODE_FACTOR, TABLE_VIEW_SIZE_MODE_FACTOR ); - window.Add( tableView ); + TableView tableView = TableView::New(TABLE_VIEW_ROWS, TABLE_VIEW_COLUMNS); + tableView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + tableView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + tableView.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + tableView.SetProperty(Actor::Property::SIZE_MODE_FACTOR, TABLE_VIEW_SIZE_MODE_FACTOR); + window.Add(tableView); // Create a tap detector - we are going to rotate an actor round our anchor-point (pivot) when one of our controls is tapped. mTapDetector = TapGestureDetector::New(); - mTapDetector.DetectedSignal().Connect( this, &PivotController::OnTap ); + mTapDetector.DetectedSignal().Connect(this, &PivotController::OnTap); - Vector3 anchorPoint( AnchorPoint::CENTER ); // This will be changed depending on the row and column. + Vector3 anchorPoint(AnchorPoint::CENTER); // This will be changed depending on the row and column. // Add controls to the table-view - each control will have a random color. - for( int row = 0; row < TABLE_VIEW_ROWS; ++row ) + for(int row = 0; row < TABLE_VIEW_ROWS; ++row) { - anchorPoint.y = ( row % TABLE_VIEW_ROWS ) * ( 1.0f / ( TABLE_VIEW_ROWS - 1 ) ); // Calculate this row's y anchor-point. + anchorPoint.y = (row % TABLE_VIEW_ROWS) * (1.0f / (TABLE_VIEW_ROWS - 1)); // Calculate this row's y anchor-point. - for( int column = 0; column < TABLE_VIEW_COLUMNS; ++column ) + for(int column = 0; column < TABLE_VIEW_COLUMNS; ++column) { - anchorPoint.x = ( column % TABLE_VIEW_COLUMNS ) * ( 1.0f / ( TABLE_VIEW_COLUMNS - 1 ) ); // Calculate this column's x anchor-point. + anchorPoint.x = (column % TABLE_VIEW_COLUMNS) * (1.0f / (TABLE_VIEW_COLUMNS - 1)); // Calculate this column's x anchor-point. // Create a control with a randomly chosen background color. Control control = Control::New(); - control.SetBackgroundColor( Vector4( Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), 1.0f ) ); - control.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - control.SetProperty( Actor::Property::POSITION_USES_ANCHOR_POINT, false ); // Ensures the position always uses top-left for its calculations. - control.SetProperty( Actor::Property::ANCHOR_POINT, anchorPoint ); // This anchor-point is used for the rotation and the scale. + control.SetBackgroundColor(Vector4(Random::Range(0.0f, 1.0f), Random::Range(0.0f, 1.0f), Random::Range(0.0f, 1.0f), 1.0f)); + control.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + control.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false); // Ensures the position always uses top-left for its calculations. + control.SetProperty(Actor::Property::ANCHOR_POINT, anchorPoint); // This anchor-point is used for the rotation and the scale. // Add to the table-view - tableView.AddChild( control, TableView::CellPosition( row, column ) ); + tableView.AddChild(control, TableView::CellPosition(row, column)); // Attach each control to the tap-detector so we can start the animation around our anchor point. - mTapDetector.Attach( control ); + mTapDetector.Attach(control); } } } @@ -114,15 +112,15 @@ private: * * Here we will start an animation around our pivot. */ - void OnTap( Actor actor, const TapGesture& /* tap */ ) + void OnTap(Actor actor, const TapGesture& /* tap */) { // Raise the actor to the top. actor.RaiseToTop(); // Create the animation to rotate and scale our actor. - Animation animation = Animation::New( 1.0f ); - animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), ANIMATION_ROTATION, ROTATION_ANIMATION_ALPHA_FUNCTION, ROTATION_ANIMATION_TIME_PERIOD ); - animation.AnimateTo( Property( actor, Actor::Property::SCALE ), ANIMATION_SCALE, SCALE_ANIMATION_ALPHA_FUNCTION, SCALE_ANIMATION_TIME_PERIOD ); + Animation animation = Animation::New(1.0f); + animation.AnimateBy(Property(actor, Actor::Property::ORIENTATION), ANIMATION_ROTATION, ROTATION_ANIMATION_ALPHA_FUNCTION, ROTATION_ANIMATION_TIME_PERIOD); + animation.AnimateTo(Property(actor, Actor::Property::SCALE), ANIMATION_SCALE, SCALE_ANIMATION_ALPHA_FUNCTION, SCALE_ANIMATION_TIME_PERIOD); // Play the animation. animation.Play(); @@ -134,11 +132,11 @@ private: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -146,15 +144,14 @@ private: } private: - - Application& mApplication; ///< Reference to the Application instance. + Application& mApplication; ///< Reference to the Application instance. TapGestureDetector mTapDetector; ///< Used for animating the tapped control. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - PivotController test( application ); + Application application = Application::New(&argc, &argv); + PivotController test(application); application.MainLoop(); return 0; } diff --git a/examples/point-mesh/point-mesh-example.cpp b/examples/point-mesh/point-mesh-example.cpp index 38b4028..37fb023 100644 --- a/examples/point-mesh/point-mesh-example.cpp +++ b/examples/point-mesh/point-mesh-example.cpp @@ -19,92 +19,91 @@ #include // INTERNAL INCLUDES -#include "shared/view.h" #include "shared/utility.h" +#include "shared/view.h" using namespace Dali; namespace { -const char* MATERIAL_SAMPLE( DEMO_IMAGE_DIR "gallery-small-48.jpg" ); -const char* MATERIAL_SAMPLE2( DEMO_IMAGE_DIR "gallery-medium-19.jpg" ); +const char* MATERIAL_SAMPLE(DEMO_IMAGE_DIR "gallery-small-48.jpg"); +const char* MATERIAL_SAMPLE2(DEMO_IMAGE_DIR "gallery-medium-19.jpg"); -#define MAKE_SHADER(A)#A +#define MAKE_SHADER(A) #A const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aPosition; -attribute highp float aHue; -varying mediump vec2 vTexCoord; -uniform mediump mat4 uMvpMatrix; -uniform mediump vec3 uSize; -uniform mediump float uPointSize; -uniform lowp vec4 uFadeColor; -varying mediump vec3 vVertexColor; -varying mediump float vHue; - -vec3 hsv2rgb(vec3 c) -{ - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); -} + attribute mediump vec2 aPosition; + attribute highp float aHue; + varying mediump vec2 vTexCoord; + uniform mediump mat4 uMvpMatrix; + uniform mediump vec3 uSize; + uniform mediump float uPointSize; + uniform lowp vec4 uFadeColor; + varying mediump vec3 vVertexColor; + varying mediump float vHue; + + vec3 hsv2rgb(vec3 c) { + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); + } -void main() -{ - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); - vertexPosition.xyz *= (uSize-uPointSize); - vertexPosition = uMvpMatrix * vertexPosition; - vVertexColor = hsv2rgb( vec3( aHue, 0.7, 1.0 ) ); - vHue = aHue; - gl_PointSize = uPointSize; - gl_Position = vertexPosition; -} -); + void main() { + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); + vertexPosition.xyz *= (uSize - uPointSize); + vertexPosition = uMvpMatrix * vertexPosition; + vVertexColor = hsv2rgb(vec3(aHue, 0.7, 1.0)); + vHue = aHue; + gl_PointSize = uPointSize; + gl_Position = vertexPosition; + }); const char* FRAGMENT_SHADER = MAKE_SHADER( -varying mediump vec3 vVertexColor; -varying mediump float vHue; -uniform lowp vec4 uColor; -uniform sampler2D sTexture1; -uniform sampler2D sTexture2; -uniform lowp vec4 uFadeColor; - -void main() -{ - mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord); - mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord); - gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1*vHue) + (texCol2*(1.0-vHue))); -} -); + varying mediump vec3 vVertexColor; + varying mediump float vHue; + uniform lowp vec4 uColor; + uniform sampler2D sTexture1; + uniform sampler2D sTexture2; + uniform lowp vec4 uFadeColor; + + void main() { + mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord); + mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord); + gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1 * vHue) + (texCol2 * (1.0 - vHue))); + }); Geometry CreateGeometry() { // Create vertices - struct Vertex { Vector2 position; float hue; }; + struct Vertex + { + Vector2 position; + float hue; + }; const unsigned int numSides = 20; - Vertex polyhedraVertexData[numSides]; - float angle=0; - float sectorAngle = 2.0f * Math::PI / (float) numSides; + Vertex polyhedraVertexData[numSides]; + float angle = 0; + float sectorAngle = 2.0f * Math::PI / (float)numSides; - for(unsigned int i=0; i #include #include #include +#include +#include "shared/view.h" using namespace Dali; @@ -33,76 +33,72 @@ struct ButtonItem namespace { - const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg"; -const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; +const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; const char* const TOOLBAR_TITLE = "Popup"; const char* CONTEXT_DISABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-carousel.png"; -const char* CONTEXT_ENABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-spiral.png"; -const char* ANIMATION_FADE_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-off.png"; -const char* ANIMATION_ZOOM_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-on.png"; - -const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE"; -const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1"; -const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2"; -const char* const POPUP_BUTTON_TOAST_ID = "POPUP_BUTTON_TOAST"; -const char* const POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_BUTTONS"; -const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT"; -const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE"; -const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT"; +const char* CONTEXT_ENABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-spiral.png"; +const char* ANIMATION_FADE_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-off.png"; +const char* ANIMATION_ZOOM_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-on.png"; + +const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE"; +const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1"; +const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2"; +const char* const POPUP_BUTTON_TOAST_ID = "POPUP_BUTTON_TOAST"; +const char* const POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_BUTTONS"; +const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT"; +const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE"; +const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT"; const char* const POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS"; -const char* const POPUP_BUTTON_FIXED_SIZE_ID = "POPUP_BUTTON_FIXED_SIZE_ID"; -const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX"; -const char* const POPUP_BUTTON_CUSTOM_STYLE = "POPUP_BUTTON_CUSTOM_STYLE"; +const char* const POPUP_BUTTON_FIXED_SIZE_ID = "POPUP_BUTTON_FIXED_SIZE_ID"; +const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX"; +const char* const POPUP_BUTTON_CUSTOM_STYLE = "POPUP_BUTTON_CUSTOM_STYLE"; // Names to give Popup PushButton controls. -const char* const POPUP_CONTROL_OK_NAME = "controlOk"; +const char* const POPUP_CONTROL_OK_NAME = "controlOk"; const char* const POPUP_CONTROL_CANCEL_NAME = "controlCancel"; const char* const CONTENT_TEXT = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; -const char* const IMAGE1 = DEMO_IMAGE_DIR "gallery-medium-5.jpg"; -const char* const IMAGE2 = DEMO_IMAGE_DIR "background-magnifier.jpg"; +const char* const IMAGE1 = DEMO_IMAGE_DIR "gallery-medium-5.jpg"; +const char* const IMAGE2 = DEMO_IMAGE_DIR "background-magnifier.jpg"; // Control area image. -const char* DEFAULT_CONTROL_AREA_IMAGE_PATH = DEMO_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup. +const char* DEFAULT_CONTROL_AREA_IMAGE_PATH = DEMO_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup. const ButtonItem POPUP_BUTTON_ITEMS[] = { - { POPUP_BUTTON_COMPLEX_ID, "Complex" }, - { POPUP_BUTTON_TOAST_ID, "Toast Popup" }, - { POPUP_BUTTON_TITLE_ID, "Title" }, - { POPUP_BUTTON_BUTTONS_1_ID, "1 Button" }, - { POPUP_BUTTON_BUTTONS_2_ID, "2 Buttons" }, - { POPUP_BUTTON_FIXED_SIZE_ID, "Fixed Size" }, - { POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID, "Title + Content + Buttons" }, - { POPUP_BUTTON_CONTENT_TEXT_ID, "Content Text" }, - { POPUP_BUTTON_CONTENT_IMAGE_ID, "Content Image" }, - { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID, "Title + Content" }, - { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" }, - { POPUP_BUTTON_CUSTOM_STYLE, "Custom Styled Popup" } -}; - -const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] ); - -const char * const CUSTOM_POPUP_STYLE_NAME = "CustomPopupStyle"; ///< Custom popup style name -} // anonymous namespace - + {POPUP_BUTTON_COMPLEX_ID, "Complex"}, + {POPUP_BUTTON_TOAST_ID, "Toast Popup"}, + {POPUP_BUTTON_TITLE_ID, "Title"}, + {POPUP_BUTTON_BUTTONS_1_ID, "1 Button"}, + {POPUP_BUTTON_BUTTONS_2_ID, "2 Buttons"}, + {POPUP_BUTTON_FIXED_SIZE_ID, "Fixed Size"}, + {POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID, "Title + Content + Buttons"}, + {POPUP_BUTTON_CONTENT_TEXT_ID, "Content Text"}, + {POPUP_BUTTON_CONTENT_IMAGE_ID, "Content Image"}, + {POPUP_BUTTON_TITLE_CONTENT_TEXT_ID, "Title + Content"}, + {POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons"}, + {POPUP_BUTTON_CUSTOM_STYLE, "Custom Styled Popup"}}; + +const int POPUP_BUTTON_ITEMS_COUNT = sizeof(POPUP_BUTTON_ITEMS) / sizeof(POPUP_BUTTON_ITEMS[0]); + +const char* const CUSTOM_POPUP_STYLE_NAME = "CustomPopupStyle"; ///< Custom popup style name +} // anonymous namespace /** * This example shows the usage of the Popup class. */ -class PopupExample: public ConnectionTracker, public Toolkit::ItemFactory +class PopupExample : public ConnectionTracker, public Toolkit::ItemFactory { public: - - PopupExample( Application& application ) - : mApplication( application ), - mContextual( false ), - mAnimationFade( true ) + PopupExample(Application& application) + : mApplication(application), + mContextual(false), + mAnimationFade(true) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &PopupExample::Create ); + mApplication.InitSignal().Connect(this, &PopupExample::Create); } ~PopupExample() @@ -110,75 +106,75 @@ public: // Nothing to do here } - void Create( Application& application ) + void Create(Application& application) { // The Init signal is received once (only) during the Application lifetime Window window = application.GetWindow(); // Respond to key events if not handled - window.KeyEventSignal().Connect( this, &PopupExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &PopupExample::OnKeyEvent); // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - std::string("") ); + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + std::string("")); - mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" ); - mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE ); + mTitleActor = DemoHelper::CreateToolBarLabel("CUSTOM_TOOLBAR_TITLE"); + mTitleActor.SetProperty(Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE); // Add title to the tool bar. - const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding ); - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER, Toolkit::Alignment::Padding( padding, padding, padding, padding ) ); + const float padding(DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER, Toolkit::Alignment::Padding(padding, padding, padding, padding)); // Create animation button. mAnimationButton = Toolkit::PushButton::New(); - mAnimationButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ANIMATION_FADE_ICON_IMAGE ); - mAnimationButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ANIMATION_ZOOM_ICON_IMAGE ); - mAnimationButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true ); - mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked ); - mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mAnimationButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ANIMATION_FADE_ICON_IMAGE); + mAnimationButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ANIMATION_ZOOM_ICON_IMAGE); + mAnimationButton.SetProperty(Toolkit::Button::Property::TOGGLABLE, true); + mAnimationButton.ClickedSignal().Connect(this, &PopupExample::OnAnimationClicked); + mToolBar.AddControl(mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create context button. mContextButton = Toolkit::PushButton::New(); - mContextButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CONTEXT_DISABLED_ICON_IMAGE ); - mContextButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CONTEXT_ENABLED_ICON_IMAGE ); - mContextButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true ); - mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked ); - mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mContextButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CONTEXT_DISABLED_ICON_IMAGE); + mContextButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CONTEXT_ENABLED_ICON_IMAGE); + mContextButton.SetProperty(Toolkit::Button::Property::TOGGLABLE, true); + mContextButton.ClickedSignal().Connect(this, &PopupExample::OnContextClicked); + mToolBar.AddControl(mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Add title to the tool bar. - mItemView = Toolkit::ItemView::New( *this ); - mItemView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mItemView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mItemView = Toolkit::ItemView::New(*this); + mItemView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mItemView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mItemView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); // Use a grid layout for tests - Vector2 windowSize = window.GetSize(); - Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST ); - Vector3 itemSize; - gridLayout->GetItemSize( 0, Vector3( windowSize ), itemSize ); + Vector2 windowSize = window.GetSize(); + Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New(Toolkit::DefaultItemLayout::LIST); + Vector3 itemSize; + gridLayout->GetItemSize(0, Vector3(windowSize), itemSize); itemSize.height = windowSize.y / 10; - gridLayout->SetItemSize( itemSize ); - mItemView.AddLayout( *gridLayout ); + gridLayout->SetItemSize(itemSize); + mItemView.AddLayout(*gridLayout); - mItemView.ActivateLayout( 0, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f ); + mItemView.ActivateLayout(0, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f); - mContentLayer.Add( mItemView ); + mContentLayer.Add(mItemView); } - bool OnContextClicked( Toolkit::Button button ) + bool OnContextClicked(Toolkit::Button button) { - mContextual = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get(); + mContextual = button.GetProperty(Toolkit::Button::Property::SELECTED).Get(); return true; } - bool OnAnimationClicked( Toolkit::Button button ) + bool OnAnimationClicked(Toolkit::Button button) { - mAnimationFade = ! ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get() ); + mAnimationFade = !(button.GetProperty(Toolkit::Button::Property::SELECTED).Get()); return true; } @@ -193,38 +189,38 @@ public: * same visual appearance. * @param[in] popup The popup whose policies should be modified. */ - void SetupContextualResizePolicy( Toolkit::Popup& popup ) + void SetupContextualResizePolicy(Toolkit::Popup& popup) { Vector2 windowSize = mApplication.GetWindow().GetSize(); // Some defaults when creating a new fixed size. // This is NOT a Vector2 so we can modify each dimension in a for-loop. - float newSize[ Dimension::DIMENSION_COUNT ] = { windowSize.x * 0.75f, windowSize.y * 0.75f }; - bool modifySize = false; + float newSize[Dimension::DIMENSION_COUNT] = {windowSize.x * 0.75f, windowSize.y * 0.75f}; + bool modifySize = false; // Loop through each of two dimensions to process them. - for( unsigned int dimension = 0; dimension < 2; ++dimension ) + for(unsigned int dimension = 0; dimension < 2; ++dimension) { - float windowDimensionSize, sizeModeFactor; + float windowDimensionSize, sizeModeFactor; Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT; // Setup information related to the current dimension we are processing. - if( policyDimension == Dimension::WIDTH ) + if(policyDimension == Dimension::WIDTH) { windowDimensionSize = windowSize.x; - sizeModeFactor = popup.GetProperty< Vector3 >( Actor::Property::SIZE_MODE_FACTOR ).x; + sizeModeFactor = popup.GetProperty(Actor::Property::SIZE_MODE_FACTOR).x; } else { windowDimensionSize = windowSize.y; - sizeModeFactor = popup.GetProperty< Vector3 >( Actor::Property::SIZE_MODE_FACTOR ).y; + sizeModeFactor = popup.GetProperty(Actor::Property::SIZE_MODE_FACTOR).y; } - bool modifyPolicy = false; - ResizePolicy::Type policy = popup.GetResizePolicy( policyDimension ); - ResizePolicy::Type newPolicy( policy ); + bool modifyPolicy = false; + ResizePolicy::Type policy = popup.GetResizePolicy(policyDimension); + ResizePolicy::Type newPolicy(policy); // Switch on each policy type to determine the new behaviour. - switch( policy ) + switch(policy) { case ResizePolicy::FIXED: case ResizePolicy::USE_ASSIGNED_SIZE: @@ -238,91 +234,91 @@ public: { // Set size to 0 so the policy determines size. // If a non-zero size is set, policy is converted to fixed. - newSize[ dimension ] = 0.0f; - modifySize = true; + newSize[dimension] = 0.0f; + modifySize = true; break; } // The following cases emulate the three size-mode related resize policies. case ResizePolicy::FILL_TO_PARENT: { - newPolicy = ResizePolicy::FIXED; - newSize[ dimension ] = windowDimensionSize; - modifyPolicy = true; + newPolicy = ResizePolicy::FIXED; + newSize[dimension] = windowDimensionSize; + modifyPolicy = true; break; } case ResizePolicy::SIZE_RELATIVE_TO_PARENT: { - newPolicy = ResizePolicy::FIXED; - newSize[ dimension ] = windowDimensionSize * sizeModeFactor; - modifyPolicy = true; + newPolicy = ResizePolicy::FIXED; + newSize[dimension] = windowDimensionSize * sizeModeFactor; + modifyPolicy = true; break; } case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT: { - newPolicy = ResizePolicy::FIXED; - newSize[ dimension ] = windowDimensionSize + sizeModeFactor; - modifyPolicy = true; + newPolicy = ResizePolicy::FIXED; + newSize[dimension] = windowDimensionSize + sizeModeFactor; + modifyPolicy = true; break; } } - if( modifyPolicy ) + if(modifyPolicy) { // Set the new policy for this dimension, if it has been modified. - popup.SetResizePolicy( newPolicy, policyDimension ); + popup.SetResizePolicy(newPolicy, policyDimension); modifySize = true; } } - if( modifySize ) + if(modifySize) { // The size is set once at the end. - popup.SetProperty( Actor::Property::SIZE, Vector2( newSize[ 0 ], newSize[ 1 ] ) ); + popup.SetProperty(Actor::Property::SIZE, Vector2(newSize[0], newSize[1])); } } - void SetupPopup( Toolkit::Popup popup, Actor parent ) + void SetupPopup(Toolkit::Popup popup, Actor parent) { - if( mAnimationFade ) + if(mAnimationFade) { - popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "FADE" ); + popup.SetProperty(Toolkit::Popup::Property::ANIMATION_MODE, "FADE"); } else { - popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM" ); + popup.SetProperty(Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM"); } - if( mContextual ) + if(mContextual) { - popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW" ); + popup.SetProperty(Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW"); // Modify the preset demo resize policies (and size) to contextual ones. - SetupContextualResizePolicy( popup ); + SetupContextualResizePolicy(popup); - parent.Add( popup ); + parent.Add(popup); } else { - mApplication.GetWindow().Add( popup ); + mApplication.GetWindow().Add(popup); } - mPopup.SetDisplayState( Toolkit::Popup::SHOWN ); + mPopup.SetDisplayState(Toolkit::Popup::SHOWN); } void HidePopup() { - if( mPopup ) + if(mPopup) { - mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); + mPopup.SetDisplayState(Toolkit::Popup::HIDDEN); } } void PopupHidden() { - if( mPopup ) + if(mPopup) { mPopup.Unparent(); mPopup.Reset(); @@ -331,90 +327,90 @@ public: Toolkit::Popup CreatePopup() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); const float POPUP_WIDTH_DP = window.GetSize().GetWidth() * 0.75f; Toolkit::Popup popup = Toolkit::Popup::New(); - popup.SetProperty( Dali::Actor::Property::NAME, "popup" ); - popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - popup.SetProperty( Actor::Property::SIZE, Vector2( POPUP_WIDTH_DP, 0.0f ) ); - popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false ); + popup.SetProperty(Dali::Actor::Property::NAME, "popup"); + popup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + popup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + popup.SetProperty(Actor::Property::SIZE, Vector2(POPUP_WIDTH_DP, 0.0f)); + popup.SetProperty(Toolkit::Popup::Property::TAIL_VISIBILITY, false); - popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup ); - popup.HiddenSignal().Connect( this, &PopupExample::PopupHidden ); + popup.OutsideTouchedSignal().Connect(this, &PopupExample::HidePopup); + popup.HiddenSignal().Connect(this, &PopupExample::PopupHidden); return popup; } - Toolkit::Popup CreateConfirmationPopup( int numberOfButtons ) + Toolkit::Popup CreateConfirmationPopup(int numberOfButtons) { Toolkit::Popup confirmationPopup = Toolkit::Popup::New(); - confirmationPopup.SetProperty( Dali::Actor::Property::NAME, "MAIN-POPUP-SELF" ); + confirmationPopup.SetProperty(Dali::Actor::Property::NAME, "MAIN-POPUP-SELF"); - if( numberOfButtons > 0 ) + if(numberOfButtons > 0) { // Start with a control area image. - Toolkit::ImageView footer = Toolkit::ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH ); - footer.SetProperty( Dali::Actor::Property::NAME, "controlAreaImage" ); + Toolkit::ImageView footer = Toolkit::ImageView::New(DEFAULT_CONTROL_AREA_IMAGE_PATH); + footer.SetProperty(Dali::Actor::Property::NAME, "controlAreaImage"); // Set up the container's layout. - footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT ); - footer.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 130.0f ) ); - footer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - footer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + footer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + footer.SetResizePolicy(ResizePolicy::FIXED, Dimension::HEIGHT); + footer.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 130.0f)); + footer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + footer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); Actor okButton = CreateOKButton(); - okButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - okButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - okButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); - okButton.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( -20.0f, -20.0f, 0.0 ) ); + okButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + okButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + okButton.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS); + okButton.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(-20.0f, -20.0f, 0.0)); - if( numberOfButtons > 1 ) + if(numberOfButtons > 1) { - Toolkit::TableView controlLayout = Toolkit::TableView::New( 1, 2 ); - controlLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - controlLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - controlLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Toolkit::TableView controlLayout = Toolkit::TableView::New(1, 2); + controlLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + controlLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + controlLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); Actor cancelButton = CreateCancelButton(); - cancelButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - cancelButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); - cancelButton.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( -20.0f, -20.0f, 0.0 ) ); + cancelButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + cancelButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + cancelButton.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS); + cancelButton.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(-20.0f, -20.0f, 0.0)); - controlLayout.SetCellPadding( Size( 10.0f, 10.0f ) ); + controlLayout.SetCellPadding(Size(10.0f, 10.0f)); - controlLayout.SetRelativeWidth( 0, 0.5f ); - controlLayout.SetRelativeWidth( 1, 0.5f ); + controlLayout.SetRelativeWidth(0, 0.5f); + controlLayout.SetRelativeWidth(1, 0.5f); - controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - controlLayout.AddChild( okButton, Toolkit::TableView::CellPosition( 0, 0 ) ); - controlLayout.AddChild( cancelButton, Toolkit::TableView::CellPosition( 0, 1 ) ); + controlLayout.SetCellAlignment(Toolkit::TableView::CellPosition(0, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + controlLayout.SetCellAlignment(Toolkit::TableView::CellPosition(0, 1), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + controlLayout.AddChild(okButton, Toolkit::TableView::CellPosition(0, 0)); + controlLayout.AddChild(cancelButton, Toolkit::TableView::CellPosition(0, 1)); - footer.Add( controlLayout ); + footer.Add(controlLayout); } else { - footer.Add( okButton ); + footer.Add(okButton); } - confirmationPopup.SetFooter( footer ); + confirmationPopup.SetFooter(footer); } - confirmationPopup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup ); + confirmationPopup.OutsideTouchedSignal().Connect(this, &PopupExample::HidePopup); return confirmationPopup; } - Actor CreateTitle( std::string title ) + Actor CreateTitle(std::string title) { - Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title ); - titleActor.SetProperty( Dali::Actor::Property::NAME, "titleActor" ); - titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel titleActor = Toolkit::TextLabel::New(title); + titleActor.SetProperty(Dali::Actor::Property::NAME, "titleActor"); + titleActor.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + titleActor.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + titleActor.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); return titleActor; } @@ -422,10 +418,10 @@ public: Toolkit::PushButton CreateOKButton() { Toolkit::PushButton okayButton = Toolkit::PushButton::New(); - okayButton.SetProperty( Dali::Actor::Property::NAME, POPUP_CONTROL_OK_NAME ); - okayButton.SetProperty( Toolkit::Button::Property::LABEL, "OK!" ); + okayButton.SetProperty(Dali::Actor::Property::NAME, POPUP_CONTROL_OK_NAME); + okayButton.SetProperty(Toolkit::Button::Property::LABEL, "OK!"); - okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked ); + okayButton.ClickedSignal().Connect(this, &PopupExample::OnPopupButtonClicked); return okayButton; } @@ -433,247 +429,247 @@ public: Toolkit::PushButton CreateCancelButton() { Toolkit::PushButton cancelButton = Toolkit::PushButton::New(); - cancelButton.SetProperty( Dali::Actor::Property::NAME, POPUP_CONTROL_CANCEL_NAME ); - cancelButton.SetProperty( Toolkit::Button::Property::LABEL, "Cancel" ); + cancelButton.SetProperty(Dali::Actor::Property::NAME, POPUP_CONTROL_CANCEL_NAME); + cancelButton.SetProperty(Toolkit::Button::Property::LABEL, "Cancel"); - cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked ); + cancelButton.ClickedSignal().Connect(this, &PopupExample::OnPopupButtonClicked); return cancelButton; } - bool OnPopupButtonClicked( Toolkit::Button button ) + bool OnPopupButtonClicked(Toolkit::Button button) { // Handle Popup pushbuttons being clicked. HidePopup(); return true; } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { // Handle menu items that create popups. - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_ID ) + if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_TITLE_ID) { mPopup = CreatePopup(); - mPopup.SetTitle( CreateTitle( "Popup!" ) ); + mPopup.SetTitle(CreateTitle("Popup!")); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_BUTTONS_1_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_BUTTONS_1_ID) { - mPopup = CreateConfirmationPopup( 1 ); - mPopup.SetTitle( CreateTitle( "Title" ) ); + mPopup = CreateConfirmationPopup(1); + mPopup.SetTitle(CreateTitle("Title")); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_BUTTONS_2_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_BUTTONS_2_ID) { - mPopup = CreateConfirmationPopup( 2 ); - mPopup.SetTitle( CreateTitle( "Title" ) ); + mPopup = CreateConfirmationPopup(2); + mPopup.SetTitle(CreateTitle("Title")); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TOAST_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_TOAST_ID) { // Create a toast popup via the type registry (as it is a named-type). - TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" ); - if( typeInfo ) + TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo("PopupToast"); + if(typeInfo) { BaseHandle baseHandle = typeInfo.CreateInstance(); - if( baseHandle ) + if(baseHandle) { - mPopup = Toolkit::Popup::DownCast( baseHandle ); - mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) ); + mPopup = Toolkit::Popup::DownCast(baseHandle); + mPopup.SetTitle(CreateTitle("This is a Toast Popup.\nIt will auto-hide itself")); - mApplication.GetWindow().Add( mPopup ); - mPopup.SetDisplayState( Toolkit::Popup::SHOWN ); + mApplication.GetWindow().Add(mPopup); + mPopup.SetDisplayState(Toolkit::Popup::SHOWN); } } } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID) { - mPopup = CreateConfirmationPopup( 2 ); - mPopup.SetTitle( CreateTitle( "Erase image" ) ); - - Toolkit::TextLabel text = Toolkit::TextLabel::New( "This will erase the image permanently. Are you sure?" ); - text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - text.SetProperty( TextLabel::Property::MULTI_LINE, true ); - text.SetProperty( Actor::Property::PADDING, Padding( 10.0f, 10.0f, 20.0f, 0.0f ) ); - mPopup.SetContent( text ); - - SetupPopup( mPopup, button ); + mPopup = CreateConfirmationPopup(2); + mPopup.SetTitle(CreateTitle("Erase image")); + + Toolkit::TextLabel text = Toolkit::TextLabel::New("This will erase the image permanently. Are you sure?"); + text.SetProperty(Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + text.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + text.SetProperty(TextLabel::Property::MULTI_LINE, true); + text.SetProperty(Actor::Property::PADDING, Padding(10.0f, 10.0f, 20.0f, 0.0f)); + mPopup.SetContent(text); + + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_TEXT_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_CONTENT_TEXT_ID) { mPopup = CreatePopup(); - TextLabel text = TextLabel::New( CONTENT_TEXT ); - text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( TextLabel::Property::MULTI_LINE, true ); - text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - text.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) ); + TextLabel text = TextLabel::New(CONTENT_TEXT); + text.SetProperty(Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(TextLabel::Property::MULTI_LINE, true); + text.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + text.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + text.SetProperty(Actor::Property::PADDING, Padding(20.0f, 20.0f, 20.0f, 20.0f)); - mPopup.Add( text ); + mPopup.Add(text); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_CONTENT_IMAGE_ID) { - mPopup = CreatePopup(); - Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE2 ); - image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - image.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) ); + mPopup = CreatePopup(); + Toolkit::ImageView image = Toolkit::ImageView::New(IMAGE2); + image.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + image.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + image.SetProperty(Actor::Property::PADDING, Padding(20.0f, 20.0f, 20.0f, 20.0f)); - mPopup.Add( image ); + mPopup.Add(image); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID) { mPopup = CreatePopup(); - mPopup.SetTitle( CreateTitle( "Popup!" ) ); + mPopup.SetTitle(CreateTitle("Popup!")); - Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT ); - text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( TextLabel::Property::MULTI_LINE, true ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - text.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) ); + Toolkit::TextLabel text = Toolkit::TextLabel::New(CONTENT_TEXT); + text.SetProperty(Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(TextLabel::Property::MULTI_LINE, true); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + text.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + text.SetProperty(Actor::Property::PADDING, Padding(20.0f, 20.0f, 20.0f, 20.0f)); - mPopup.Add( text ); + mPopup.Add(text); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_FIXED_SIZE_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_FIXED_SIZE_ID) { mPopup = CreatePopup(); - mPopup.SetTitle( CreateTitle( "Popup!" ) ); + mPopup.SetTitle(CreateTitle("Popup!")); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed size popup" ); - text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( TextLabel::Property::MULTI_LINE, true ); - text.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 20.0f ) ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fixed size popup"); + text.SetProperty(Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(TextLabel::Property::MULTI_LINE, true); + text.SetProperty(Actor::Property::PADDING, Padding(20.0f, 20.0f, 20.0f, 20.0f)); - mPopup.Add( text ); + mPopup.Add(text); // Fix the popup's size. - mPopup.SetProperty( Actor::Property::SIZE, Vector2( 240.0f, 400.0f ) ); - mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + mPopup.SetProperty(Actor::Property::SIZE, Vector2(240.0f, 400.0f)); + mPopup.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID) { - mPopup = CreateConfirmationPopup( 2 ); - mPopup.SetTitle( CreateTitle( "Popup!" ) ); + mPopup = CreateConfirmationPopup(2); + mPopup.SetTitle(CreateTitle("Popup!")); - Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT ); - text.SetProperty( Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - text.SetProperty( TextLabel::Property::MULTI_LINE, true ); - text.SetProperty( Actor::Property::PADDING, Padding( 10.0f, 10.0f, 20.0f, 0.0f ) ); + Toolkit::TextLabel text = Toolkit::TextLabel::New(CONTENT_TEXT); + text.SetProperty(Dali::Actor::Property::NAME, "POPUP_CONTENT_TEXT"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + text.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + text.SetProperty(TextLabel::Property::MULTI_LINE, true); + text.SetProperty(Actor::Property::PADDING, Padding(10.0f, 10.0f, 20.0f, 0.0f)); - mPopup.Add( text ); + mPopup.Add(text); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_COMPLEX_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_COMPLEX_ID) { - mPopup = CreateConfirmationPopup( 2 ); - mPopup.SetTitle( CreateTitle( "Warning" ) ); + mPopup = CreateConfirmationPopup(2); + mPopup.SetTitle(CreateTitle("Warning")); // Content - Toolkit::TableView content = Toolkit::TableView::New( 2, 2 ); - content.SetProperty( Dali::Actor::Property::NAME, "COMPLEX_TABLEVIEW" ); - content.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - content.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - content.SetFitHeight( 0 ); - content.SetFitHeight( 1 ); - content.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 20.0f, 20.0f, 0.0f ) ); + Toolkit::TableView content = Toolkit::TableView::New(2, 2); + content.SetProperty(Dali::Actor::Property::NAME, "COMPLEX_TABLEVIEW"); + content.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + content.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + content.SetFitHeight(0); + content.SetFitHeight(1); + content.SetProperty(Actor::Property::PADDING, Padding(20.0f, 20.0f, 20.0f, 0.0f)); // Text { - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Do you really want to quit?"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + text.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); - content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) ); + content.AddChild(text, Toolkit::TableView::CellPosition(0, 0)); } // Image { - Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE1 ); - image.SetProperty( Dali::Actor::Property::NAME, "COMPLEX_IMAGE" ); - image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - image.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 0.0f, 0.0f, 0.0f ) ); - content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) ); + Toolkit::ImageView image = Toolkit::ImageView::New(IMAGE1); + image.SetProperty(Dali::Actor::Property::NAME, "COMPLEX_IMAGE"); + image.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + image.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + image.SetProperty(Actor::Property::PADDING, Padding(20.0f, 0.0f, 0.0f, 0.0f)); + content.AddChild(image, Toolkit::TableView::CellPosition(0, 1)); } // Text 2 { - Toolkit::TableView root = Toolkit::TableView::New( 1, 2 ); - root.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - root.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - root.SetFitHeight( 0 ); - root.SetFitWidth( 0 ); - root.SetProperty( Actor::Property::PADDING, Padding( 0.0f, 0.0f, 0.0f, 20.0f ) ); + Toolkit::TableView root = Toolkit::TableView::New(1, 2); + root.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + root.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + root.SetFitHeight(0); + root.SetFitWidth(0); + root.SetProperty(Actor::Property::PADDING, Padding(0.0f, 0.0f, 0.0f, 20.0f)); Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New(); - checkBox.SetProperty( Actor::Property::SIZE, Vector2( 48, 48 ) ); - root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) ); + checkBox.SetProperty(Actor::Property::SIZE, Vector2(48, 48)); + root.AddChild(checkBox, Toolkit::TableView::CellPosition(0, 0)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Don't show again"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); Actor textActor = text; - textActor.SetProperty( Actor::Property::PADDING, Padding( 20.0f, 0.0f, 0.0f, 10.0f ) ); + textActor.SetProperty(Actor::Property::PADDING, Padding(20.0f, 0.0f, 0.0f, 10.0f)); - root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) ); + root.AddChild(text, Toolkit::TableView::CellPosition(0, 1)); - content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) ); + content.AddChild(root, Toolkit::TableView::CellPosition(1, 0)); } - mPopup.SetContent( content ); + mPopup.SetContent(content); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CUSTOM_STYLE ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_CUSTOM_STYLE) { - mPopup = CreateConfirmationPopup( 2 ); + mPopup = CreateConfirmationPopup(2); - Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Styled Popup" ); - titleActor.SetProperty( Dali::Actor::Property::NAME, "titleActor" ); - titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::RED ); - titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mPopup.SetTitle( titleActor ); + Toolkit::TextLabel titleActor = Toolkit::TextLabel::New("Styled Popup"); + titleActor.SetProperty(Dali::Actor::Property::NAME, "titleActor"); + titleActor.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::RED); + titleActor.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + titleActor.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mPopup.SetTitle(titleActor); - SetupPopup( mPopup, button ); + SetupPopup(mPopup, button); - mPopup.SetStyleName( CUSTOM_POPUP_STYLE_NAME ); + mPopup.SetStyleName(CUSTOM_POPUP_STYLE_NAME); } return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { // Exit application when click back or escape. mApplication.Quit(); @@ -682,7 +678,6 @@ public: } public: // From ItemFactory - /** * @brief Return the number of items to display in the item view * @@ -702,40 +697,37 @@ public: // From ItemFactory virtual Actor NewItem(unsigned int itemId) { Toolkit::PushButton popupButton = Toolkit::PushButton::New(); - popupButton.SetProperty( Dali::Actor::Property::NAME, POPUP_BUTTON_ITEMS[ itemId ].name ); - popupButton.SetProperty( Toolkit::Button::Property::LABEL, POPUP_BUTTON_ITEMS[ itemId ].text ); - popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + popupButton.SetProperty(Dali::Actor::Property::NAME, POPUP_BUTTON_ITEMS[itemId].name); + popupButton.SetProperty(Toolkit::Button::Property::LABEL, POPUP_BUTTON_ITEMS[itemId].text); + popupButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); - popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked ); + popupButton.ClickedSignal().Connect(this, &PopupExample::OnButtonClicked); return popupButton; } private: - - Application& mApplication; - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - Toolkit::PushButton mContextButton; ///< For toggling contextual mode. - Toolkit::PushButton mAnimationButton; ///< For toggling the fade animation. - Layer mContentLayer; ///< Content layer - - Toolkit::TextLabel mTitleActor; ///< Title text + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Toolkit::PushButton mContextButton; ///< For toggling contextual mode. + Toolkit::PushButton mAnimationButton; ///< For toggling the fade animation. + Layer mContentLayer; ///< Content layer - bool mContextual; ///< True if currently using the contextual popup mode. - bool mAnimationFade; ///< True if currently using the fade animation. + Toolkit::TextLabel mTitleActor; ///< Title text - Toolkit::Popup mPopup; ///< The current example popup. + bool mContextual; ///< True if currently using the contextual popup mode. + bool mAnimationFade; ///< True if currently using the fade animation. - Toolkit::ItemView mItemView; ///< ItemView to hold test images + Toolkit::Popup mPopup; ///< The current example popup. + Toolkit::ItemView mItemView; ///< ItemView to hold test images }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - PopupExample test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + PopupExample test(application); application.MainLoop(); return 0; } diff --git a/examples/pre-render-callback/pre-render-callback-example.cpp b/examples/pre-render-callback/pre-render-callback-example.cpp index 57b3bdb..3f236ae 100644 --- a/examples/pre-render-callback/pre-render-callback-example.cpp +++ b/examples/pre-render-callback/pre-render-callback-example.cpp @@ -15,40 +15,39 @@ */ #include -#include -#include #include +#include +#include using namespace Dali::Toolkit; namespace Dali { -const char* SCENE_IMAGE_1( DEMO_IMAGE_DIR "gallery-small-10.jpg"); -const char* SCENE_IMAGE_2( DEMO_IMAGE_DIR "gallery-small-42.jpg"); -const char* SCENE_IMAGE_3( DEMO_IMAGE_DIR "gallery-small-48.jpg"); +const char* SCENE_IMAGE_1(DEMO_IMAGE_DIR "gallery-small-10.jpg"); +const char* SCENE_IMAGE_2(DEMO_IMAGE_DIR "gallery-small-42.jpg"); +const char* SCENE_IMAGE_3(DEMO_IMAGE_DIR "gallery-small-48.jpg"); const char* ROTATE_TEXT("-\\|/"); const float TEXT_HEIGHT = 40.0f; -void AddText( Control textContainer, std::string text, unsigned int yIndex ) +void AddText(Control textContainer, std::string text, unsigned int yIndex) { auto label = TextLabel::New(text); - label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - label.SetProperty( Actor::Property::SIZE, Vector2( 300,TEXT_HEIGHT ) ); - label.SetProperty( Actor::Property::POSITION_Y, yIndex*TEXT_HEIGHT ); - textContainer.Add( label ); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + label.SetProperty(Actor::Property::SIZE, Vector2(300, TEXT_HEIGHT)); + label.SetProperty(Actor::Property::POSITION_Y, yIndex * TEXT_HEIGHT); + textContainer.Add(label); } class PreRenderCallbackController : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application The application. */ - PreRenderCallbackController ( Application& application ) - : mApplication( application ), + PreRenderCallbackController(Application& application) + : mApplication(application), mWindow(), mTapDetector(), mKeepPreRender(false), @@ -57,14 +56,14 @@ public: mImageActor1(), mImageActor2(), mImageActor3(), - mAngle1Index( Property::INVALID_INDEX ), - mAngle3Index( Property::INVALID_INDEX ), + mAngle1Index(Property::INVALID_INDEX), + mAngle3Index(Property::INVALID_INDEX), mSceneActor(), mSceneAnimation(), mSpinner() { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &PreRenderCallbackController::Create ); + mApplication.InitSignal().Connect(this, &PreRenderCallbackController::Create); } private: @@ -75,10 +74,10 @@ private: { } - void operator()( Quaternion& current, const PropertyInputContainer& inputs ) + void operator()(Quaternion& current, const PropertyInputContainer& inputs) { - Radian angle( inputs[0]->GetFloat() ); - current = Quaternion( angle * mSign, Vector3::YAXIS ); + Radian angle(inputs[0]->GetFloat()); + current = Quaternion(angle * mSign, Vector3::YAXIS); } float mSign; @@ -87,96 +86,95 @@ private: /** * @brief Creates the scene. */ - void Create( Application& application ) + void Create(Application& application) { mWindow = application.GetWindow(); - mWindow.SetBackgroundColor( Color::WHITE ); - mWindow.KeyEventSignal().Connect( this, &PreRenderCallbackController::OnKeyEvent ); + mWindow.SetBackgroundColor(Color::WHITE); + mWindow.KeyEventSignal().Connect(this, &PreRenderCallbackController::OnKeyEvent); // Detect taps on the root layer. mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach( mWindow.GetRootLayer() ); - mTapDetector.DetectedSignal().Connect( this, &PreRenderCallbackController::OnTap ); + mTapDetector.Attach(mWindow.GetRootLayer()); + mTapDetector.DetectedSignal().Connect(this, &PreRenderCallbackController::OnTap); CreateAnimatingScene(); auto textContainer = Control::New(); - textContainer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); - AddText(textContainer, "Click to add callback", 1 ); - AddText(textContainer, "Press 1 to add callback", 2 ); - AddText(textContainer, "Press 2 to clear callback", 3 ); - AddText(textContainer, "Press 3 to toggle keep alive", 4 ); - + textContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + AddText(textContainer, "Click to add callback", 1); + AddText(textContainer, "Press 1 to add callback", 2); + AddText(textContainer, "Press 2 to clear callback", 3); + AddText(textContainer, "Press 3 to toggle keep alive", 4); mSpinner = TextLabel::New(""); - mSpinner.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mSpinner.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mSpinner.SetProperty( Actor::Property::SIZE, Vector2(100,100) ); + mSpinner.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mSpinner.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mSpinner.SetProperty(Actor::Property::SIZE, Vector2(100, 100)); mWindow.Add(mSpinner); mWindow.Add(textContainer); - DevelApplication::AddIdleWithReturnValue( application, MakeCallback( this, &PreRenderCallbackController::OnIdle ) ); + DevelApplication::AddIdleWithReturnValue(application, MakeCallback(this, &PreRenderCallbackController::OnIdle)); } void CreateAnimatingScene() { mSceneActor = Layer::New(); - mSceneActor.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); - mSceneActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mSceneActor.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); + mSceneActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); // Create and add images to the scene actor: - mImageActor1 = ImageView::New( SCENE_IMAGE_1 ); - mImageActor2 = ImageView::New( SCENE_IMAGE_2 ); - mImageActor3 = ImageView::New( SCENE_IMAGE_3 ); + mImageActor1 = ImageView::New(SCENE_IMAGE_1); + mImageActor2 = ImageView::New(SCENE_IMAGE_2); + mImageActor3 = ImageView::New(SCENE_IMAGE_3); - mImageActor1.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mImageActor2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mImageActor3.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mImageActor1.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mImageActor2.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mImageActor3.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); - mImageActor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mImageActor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - mImageActor1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER_LEFT); - mImageActor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_RIGHT); + mImageActor1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT); + mImageActor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_RIGHT); - mImageActor3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER_RIGHT); - mImageActor3.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_LEFT); + mImageActor3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT); + mImageActor3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); mSceneActor.Add(mImageActor2); mImageActor2.Add(mImageActor1); mImageActor2.Add(mImageActor3); - Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value( Dali::ANGLE_30 ) ); - Source angleSrc( mImageActor2, angleIndex ); + Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value(Dali::ANGLE_30)); + Source angleSrc(mImageActor2, angleIndex); - Constraint constraint = Constraint::New( mImageActor1, Actor::Property::ORIENTATION, RotationConstraint(-1.0f) ); - constraint.AddSource( angleSrc ); + Constraint constraint = Constraint::New(mImageActor1, Actor::Property::ORIENTATION, RotationConstraint(-1.0f)); + constraint.AddSource(angleSrc); constraint.Apply(); - constraint = Constraint::New( mImageActor3, Actor::Property::ORIENTATION, RotationConstraint(+1.0f) ); - constraint.AddSource( angleSrc ); + constraint = Constraint::New(mImageActor3, Actor::Property::ORIENTATION, RotationConstraint(+1.0f)); + constraint.AddSource(angleSrc); constraint.Apply(); mSceneAnimation = Animation::New(2.5f); // Want to animate angle from 30 => -30 and back again smoothly. - mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-Dali::ANGLE_30), AlphaFunction::SIN ); + mSceneAnimation.AnimateTo(Property(mImageActor2, angleIndex), Property::Value(-Dali::ANGLE_30), AlphaFunction::SIN); mSceneAnimation.SetLooping(true); mSceneAnimation.Play(); - mSceneActor.SetProperty( Actor::Property::SIZE, Vector2(250.0f, 250.0f) ); - mSceneActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 130.0f ) ); - Quaternion p( Degree( -6.0f ), Vector3::XAXIS ); - Quaternion q( Degree( 20.0f ), Vector3::YAXIS ); - mSceneActor.SetProperty( Actor::Property::ORIENTATION, p * q ); + mSceneActor.SetProperty(Actor::Property::SIZE, Vector2(250.0f, 250.0f)); + mSceneActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 130.0f)); + Quaternion p(Degree(-6.0f), Vector3::XAXIS); + Quaternion q(Degree(20.0f), Vector3::YAXIS); + mSceneActor.SetProperty(Actor::Property::ORIENTATION, p * q); - mWindow.Add( mSceneActor ); + mWindow.Add(mSceneActor); } - void OnTap( Actor /* actor */, const TapGesture& /* tap */ ) + void OnTap(Actor /* actor */, const TapGesture& /* tap */) { - Adaptor::Get().SetPreRenderCallback( MakeCallback( this, &PreRenderCallbackController::OnPreRender ) ); + Adaptor::Get().SetPreRenderCallback(MakeCallback(this, &PreRenderCallbackController::OnPreRender)); } /** @@ -185,23 +183,23 @@ private: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } - else if( event.GetKeyName().compare("1") == 0) + else if(event.GetKeyName().compare("1") == 0) { - Adaptor::Get().SetPreRenderCallback( MakeCallback( this, &PreRenderCallbackController::OnPreRender ) ); + Adaptor::Get().SetPreRenderCallback(MakeCallback(this, &PreRenderCallbackController::OnPreRender)); } - else if( event.GetKeyName().compare("2") == 0) + else if(event.GetKeyName().compare("2") == 0) { - Adaptor::Get().SetPreRenderCallback( NULL ); + Adaptor::Get().SetPreRenderCallback(NULL); } - else if( event.GetKeyName().compare("3") == 0) + else if(event.GetKeyName().compare("3") == 0) { mKeepPreRender = !mKeepPreRender; } @@ -220,40 +218,39 @@ private: { // Called from Event thread on main loop int rotation = mRotateTextCharacter; - if( rotation != mLastRTC ) + if(rotation != mLastRTC) { mLastRTC = rotation; - mSpinner.SetProperty(TextLabel::Property::TEXT, std::string(1, ROTATE_TEXT[rotation%4])); + mSpinner.SetProperty(TextLabel::Property::TEXT, std::string(1, ROTATE_TEXT[rotation % 4])); } return true; } - private: - Application& mApplication; - Window mWindow; - TapGestureDetector mTapDetector; ///< Tap detector to enable the PreRenderCallback - bool mKeepPreRender; - int mRotateTextCharacter; - int mLastRTC; + Application& mApplication; + Window mWindow; + TapGestureDetector mTapDetector; ///< Tap detector to enable the PreRenderCallback + bool mKeepPreRender; + int mRotateTextCharacter; + int mLastRTC; // Scene objects: - ImageView mImageActor1; - ImageView mImageActor2; - ImageView mImageActor3; - Property::Index mAngle1Index; - Property::Index mAngle3Index; - Layer mSceneActor; - Animation mSceneAnimation; - TextLabel mSpinner; + ImageView mImageActor1; + ImageView mImageActor2; + ImageView mImageActor3; + Property::Index mAngle1Index; + Property::Index mAngle3Index; + Layer mSceneActor; + Animation mSceneAnimation; + TextLabel mSpinner; }; } // namespace Dali -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Dali::Application application = Dali::Application::New( &argc, &argv ); - Dali::PreRenderCallbackController controller( application ); + Dali::Application application = Dali::Application::New(&argc, &argv); + Dali::PreRenderCallbackController controller(application); application.MainLoop(); return 0; } diff --git a/examples/primitive-shapes/primitive-shapes-example.cpp b/examples/primitive-shapes/primitive-shapes-example.cpp old mode 100755 new mode 100644 index 466abd8..9120faf --- a/examples/primitive-shapes/primitive-shapes-example.cpp +++ b/examples/primitive-shapes/primitive-shapes-example.cpp @@ -23,8 +23,8 @@ using namespace Dali::Toolkit; namespace { - //Button image urls - const char* BUTTON_IMAGE_URL[] = +//Button image urls +const char* BUTTON_IMAGE_URL[] = { DEMO_IMAGE_DIR "sphere-button.png", DEMO_IMAGE_DIR "cone-button.png", @@ -32,48 +32,46 @@ namespace DEMO_IMAGE_DIR "cylinder-button.png", DEMO_IMAGE_DIR "cube-button.png", DEMO_IMAGE_DIR "bevelled-cube-button.png", - DEMO_IMAGE_DIR "octahedron-button.png" - }; - - //Prefix of all shape titles. - const std::string SHAPE_TITLE_PREFIX = "Current Shape: "; - - //Shape property defaults - const int DEFAULT_SLICES = 32; - const int DEFAULT_STACKS = 32; - const float DEFAULT_SCALE_HEIGHT = 16.0f; - const float DEFAULT_SCALE_BOTTOM_RADIUS = 8.0f; - const float DEFAULT_SCALE_TOP_RADIUS = 4.0f; - const float DEFAULT_SCALE_RADIUS = 8.0f; - const float DEFAULT_BEVEL_PERCENTAGE = 0.3f; - const float DEFAULT_BEVEL_SMOOTHNESS = 0.0f; - - //Shape property limits - const int SLICES_LOWER_BOUND = 3; - const int SLICES_UPPER_BOUND = 16; - const int STACKS_LOWER_BOUND = 2; - const int STACKS_UPPER_BOUND = 16; - - //Used to the control rate of rotation when panning an object. - const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f; - const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f; - - const int NUM_MODELS = 7; //Total number of possible base shapes. - const int MAX_PROPERTIES = 3; //Maximum number of properties a shape may require. (For displaying sliders.) + DEMO_IMAGE_DIR "octahedron-button.png"}; + +//Prefix of all shape titles. +const std::string SHAPE_TITLE_PREFIX = "Current Shape: "; + +//Shape property defaults +const int DEFAULT_SLICES = 32; +const int DEFAULT_STACKS = 32; +const float DEFAULT_SCALE_HEIGHT = 16.0f; +const float DEFAULT_SCALE_BOTTOM_RADIUS = 8.0f; +const float DEFAULT_SCALE_TOP_RADIUS = 4.0f; +const float DEFAULT_SCALE_RADIUS = 8.0f; +const float DEFAULT_BEVEL_PERCENTAGE = 0.3f; +const float DEFAULT_BEVEL_SMOOTHNESS = 0.0f; + +//Shape property limits +const int SLICES_LOWER_BOUND = 3; +const int SLICES_UPPER_BOUND = 16; +const int STACKS_LOWER_BOUND = 2; +const int STACKS_UPPER_BOUND = 16; + +//Used to the control rate of rotation when panning an object. +const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f; +const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f; + +const int NUM_MODELS = 7; //Total number of possible base shapes. +const int MAX_PROPERTIES = 3; //Maximum number of properties a shape may require. (For displaying sliders.) } //End namespace class PrimitiveShapesController : public ConnectionTracker { public: - - PrimitiveShapesController( Application& application ) - : mApplication( application ), - mColor( Vector4( 0.3f, 0.7f, 1.0f, 1.0f ) ), - mRotation( Vector2::ZERO ) + PrimitiveShapesController(Application& application) + : mApplication(application), + mColor(Vector4(0.3f, 0.7f, 1.0f, 1.0f)), + mRotation(Vector2::ZERO) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &PrimitiveShapesController::Create ); + mApplication.InitSignal().Connect(this, &PrimitiveShapesController::Create); } ~PrimitiveShapesController() @@ -81,32 +79,32 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); //Set up layer to place UI on. Layer layer = Layer::New(); - layer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - layer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - layer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - layer.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_UI ); //We use a 2D layer as this is closer to UI work than full 3D scene creation. - layer.SetProperty( Layer::Property::DEPTH_TEST, true ); //Enable depth testing, as otherwise the 2D layer would not do so. - window.Add( layer ); + layer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + layer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + layer.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI); //We use a 2D layer as this is closer to UI work than full 3D scene creation. + layer.SetProperty(Layer::Property::DEPTH_TEST, true); //Enable depth testing, as otherwise the 2D layer would not do so. + window.Add(layer); //Set up model selection buttons. - SetupButtons( layer ); + SetupButtons(layer); //Set up model parameter sliders. - SetupSliders( layer ); + SetupSliders(layer); //Set up 3D model. - SetupModel( layer ); + SetupModel(layer); //Allow for exiting of the application via key presses. - window.KeyEventSignal().Connect( this, &PrimitiveShapesController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &PrimitiveShapesController::OnKeyEvent); } //Place buttons on the top of the screen, which allow for selection of the shape to be displayed. @@ -143,52 +141,52 @@ public: // | | // +--------------------------------+ // - void SetupButtons( Layer layer ) + void SetupButtons(Layer layer) { float containerPadding = 10.0f; - float elementPadding = 5.0f; + float elementPadding = 5.0f; //Used to layout the title and the buttons below it. Control topAlignment = Control::New(); - topAlignment.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - topAlignment.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - topAlignment.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - topAlignment.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); - layer.Add( topAlignment ); + topAlignment.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + topAlignment.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + topAlignment.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + topAlignment.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + layer.Add(topAlignment); //Add a title to indicate the currently selected shape. - mShapeTitle = TextLabel::New( "DEFAULT" ); - mShapeTitle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mShapeTitle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mShapeTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mShapeTitle.SetProperty( Actor::Property::PADDING, Padding( elementPadding, elementPadding, elementPadding, elementPadding ) ); - topAlignment.Add( mShapeTitle ); + mShapeTitle = TextLabel::New("DEFAULT"); + mShapeTitle.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mShapeTitle.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mShapeTitle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mShapeTitle.SetProperty(Actor::Property::PADDING, Padding(elementPadding, elementPadding, elementPadding, elementPadding)); + topAlignment.Add(mShapeTitle); //Create a variable-length container that can wrap buttons around as more are added. FlexContainer buttonContainer = FlexContainer::New(); - buttonContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - buttonContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - buttonContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - buttonContainer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT ); - buttonContainer.SetProperty( Actor::Property::PADDING, Padding( containerPadding, containerPadding, containerPadding, containerPadding ) ); - buttonContainer.SetProperty( FlexContainer::Property::FLEX_DIRECTION, FlexContainer::ROW ); - buttonContainer.SetProperty( FlexContainer::Property::FLEX_WRAP, FlexContainer::WRAP ); - topAlignment.Add( buttonContainer ); + buttonContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + buttonContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + buttonContainer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + buttonContainer.SetResizePolicy(ResizePolicy::FIXED, Dimension::HEIGHT); + buttonContainer.SetProperty(Actor::Property::PADDING, Padding(containerPadding, containerPadding, containerPadding, containerPadding)); + buttonContainer.SetProperty(FlexContainer::Property::FLEX_DIRECTION, FlexContainer::ROW); + buttonContainer.SetProperty(FlexContainer::Property::FLEX_WRAP, FlexContainer::WRAP); + topAlignment.Add(buttonContainer); //Create buttons and place them in the container. - for( int modelNumber = 0; modelNumber < NUM_MODELS; modelNumber++ ) + for(int modelNumber = 0; modelNumber < NUM_MODELS; modelNumber++) { PushButton button = Toolkit::PushButton::New(); - button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - button.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - button.SetProperty( Actor::Property::PADDING, Padding( elementPadding, elementPadding, elementPadding, elementPadding ) ); - button.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] ); - button.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber] ); - button.RegisterProperty( "modelNumber", Property::Value( modelNumber ) ); - button.ClickedSignal().Connect( this, &PrimitiveShapesController::OnChangeShapeClicked ); - - buttonContainer.Add( button ); + button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + button.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + button.SetProperty(Actor::Property::PADDING, Padding(elementPadding, elementPadding, elementPadding, elementPadding)); + button.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber]); + button.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, BUTTON_IMAGE_URL[modelNumber]); + button.RegisterProperty("modelNumber", Property::Value(modelNumber)); + button.ClickedSignal().Connect(this, &PrimitiveShapesController::OnChangeShapeClicked); + + buttonContainer.Add(button); } } @@ -226,45 +224,45 @@ public: // | | | // v +--------------------------------+ // - void SetupSliders( Layer layer ) + void SetupSliders(Layer layer) { //Create table to hold sliders and their corresponding labels. - mSliderTable = Toolkit::TableView::New( MAX_PROPERTIES, 2 ); - mSliderTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mSliderTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mSliderTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mSliderTable.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height. - mSliderTable.SetFitWidth( 0 ); //Label column should fit to natural size of label. - mSliderTable.SetRelativeWidth( 1, 1.0f ); //Slider column should fill remaining space. - mSliderTable.SetCellPadding( Vector2( 10.0f, 0.0f ) ); //Leave a gap between the slider and its label. - layer.Add( mSliderTable ); + mSliderTable = Toolkit::TableView::New(MAX_PROPERTIES, 2); + mSliderTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mSliderTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mSliderTable.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mSliderTable.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.9, 0.3, 0.0)); //90% of width, 30% of height. + mSliderTable.SetFitWidth(0); //Label column should fit to natural size of label. + mSliderTable.SetRelativeWidth(1, 1.0f); //Slider column should fill remaining space. + mSliderTable.SetCellPadding(Vector2(10.0f, 0.0f)); //Leave a gap between the slider and its label. + layer.Add(mSliderTable); //Set up sliders, and place labels next to them. - for( int i = 0; i < MAX_PROPERTIES; i++ ) + for(int i = 0; i < MAX_PROPERTIES; i++) { //Create slider Slider slider = Slider::New(); - slider.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - slider.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - slider.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - slider.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - slider.ValueChangedSignal().Connect( this, &PrimitiveShapesController::OnSliderValueChanged ); - mSliders.push_back( slider ); + slider.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + slider.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + slider.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + slider.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + slider.ValueChangedSignal().Connect(this, &PrimitiveShapesController::OnSliderValueChanged); + mSliders.push_back(slider); //Setup slider cell properties - mSliderTable.AddChild( slider, TableView::CellPosition( i, 1 ) ); - mSliderTable.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + mSliderTable.AddChild(slider, TableView::CellPosition(i, 1)); + mSliderTable.SetCellAlignment(TableView::CellPosition(i, 1), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); //Create slider label TextLabel sliderLabel = TextLabel::New(); - sliderLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - sliderLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mSliderLabels.push_back( sliderLabel ); + sliderLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + sliderLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + sliderLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mSliderLabels.push_back(sliderLabel); //Setup slider-label cell properties - mSliderTable.AddChild( sliderLabel, TableView::CellPosition( i, 0 ) ); - mSliderTable.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); + mSliderTable.AddChild(sliderLabel, TableView::CellPosition(i, 0)); + mSliderTable.SetCellAlignment(TableView::CellPosition(i, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); } } @@ -301,58 +299,57 @@ public: // | | // +--------------------------------+ // - void SetupModel( Layer layer ) + void SetupModel(Layer layer) { //Create a container to house the visual-holding actor, to provide a constant hitbox. Actor container = Actor::New(); - container.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - container.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.9, 0.3, 0.0 ) ); //90% of width, 30% of height. - container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - layer.Add( container ); + container.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + container.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.9, 0.3, 0.0)); //90% of width, 30% of height. + container.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + layer.Add(container); //Create control to display the 3D primitive. mModel = Control::New(); - mModel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mModel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - mModel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - container.Add( mModel ); + mModel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mModel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mModel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + container.Add(mModel); //Load default shape. LoadCube(); //Make model spin to demonstrate 3D. mRotationAnimation = Animation::New(15.0f); - mRotationAnimation.AnimateBy( Property( mModel, Actor::Property::ORIENTATION ), - Quaternion( Degree( 0.0f ), Degree( 360.0f ), Degree( 0.0f ) ) ); + mRotationAnimation.AnimateBy(Property(mModel, Actor::Property::ORIENTATION), + Quaternion(Degree(0.0f), Degree(360.0f), Degree(0.0f))); mRotationAnimation.SetLooping(true); mRotationAnimation.Play(); //Attach gesture detector to pan models when rotated. mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( container ); - mPanGestureDetector.DetectedSignal().Connect( this, &PrimitiveShapesController::OnPan ); + mPanGestureDetector.Attach(container); + mPanGestureDetector.DetectedSignal().Connect(this, &PrimitiveShapesController::OnPan); } //Clears all sliders and resets the primitive visual property map. void InitialiseSlidersAndModel() { //Sliders - for( unsigned i = 0; i < mSliders.size(); i++ ) + for(unsigned i = 0; i < mSliders.size(); i++) { - mSliders.at( i ).SetProperty( Slider::Property::MARKS, Property::Value( 0 ) ); //Remove marks - mSliders.at( i ).SetProperty( Actor::Property::VISIBLE, false ); - mSliderLabels.at( i ).SetProperty( TextLabel::Property::TEXT, Property::Value( "Default" ) ); - mSliderLabels.at( i ).SetProperty( Actor::Property::VISIBLE, false ); + mSliders.at(i).SetProperty(Slider::Property::MARKS, Property::Value(0)); //Remove marks + mSliders.at(i).SetProperty(Actor::Property::VISIBLE, false); + mSliderLabels.at(i).SetProperty(TextLabel::Property::TEXT, Property::Value("Default")); + mSliderLabels.at(i).SetProperty(Actor::Property::VISIBLE, false); } //Visual map for model mVisualMap.Clear(); - mVisualMap[ Toolkit::Visual::Property::TYPE ] = Visual::PRIMITIVE; - mVisualMap[ PrimitiveVisual::Property::MIX_COLOR ] = mColor; - mVisualMap[ Visual::Property::TRANSFORM ] = - Property::Map().Add( Visual::Transform::Property::ORIGIN, Align::CENTER ) - .Add( Visual::Transform::Property::ANCHOR_POINT, Align::CENTER ); + mVisualMap[Toolkit::Visual::Property::TYPE] = Visual::PRIMITIVE; + mVisualMap[PrimitiveVisual::Property::MIX_COLOR] = mColor; + mVisualMap[Visual::Property::TRANSFORM] = + Property::Map().Add(Visual::Transform::Property::ORIGIN, Align::CENTER).Add(Visual::Transform::Property::ANCHOR_POINT, Align::CENTER); } //Sets the 3D model to a sphere and modifies the sliders appropriately. @@ -361,24 +358,24 @@ public: InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::SPHERE; - mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES; - mVisualMap[ PrimitiveVisual::Property::STACKS ] = DEFAULT_STACKS; + mVisualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::SPHERE; + mVisualMap[PrimitiveVisual::Property::SLICES] = DEFAULT_SLICES; + mVisualMap[PrimitiveVisual::Property::STACKS] = DEFAULT_STACKS; //Set up sliders. - SetupSlider( 0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" ); - SetupMarks( 0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND ); - mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) ); + SetupSlider(0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices"); + SetupMarks(0, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND); + mSliders.at(0).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(0)); - SetupSlider( 1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::STACKS, "stacks" ); - SetupMarks( 1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND ); - mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) ); + SetupSlider(1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::STACKS, "stacks"); + SetupMarks(1, STACKS_LOWER_BOUND, STACKS_UPPER_BOUND); + mSliders.at(1).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(0)); //Set model in control. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Sphere" ); + mShapeTitle.SetProperty(TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Sphere"); } //Sets the 3D model to a cone and modifies the sliders appropriately. @@ -387,27 +384,27 @@ public: InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CONE; - mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT; - mVisualMap[ PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS ] = DEFAULT_SCALE_BOTTOM_RADIUS; - mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES; + mVisualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::CONE; + mVisualMap[PrimitiveVisual::Property::SCALE_HEIGHT] = DEFAULT_SCALE_HEIGHT; + mVisualMap[PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS] = DEFAULT_SCALE_BOTTOM_RADIUS; + mVisualMap[PrimitiveVisual::Property::SLICES] = DEFAULT_SLICES; //Set up sliders. - SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" ); - mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) ); + SetupSlider(0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight"); + mSliders.at(0).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(1)); - SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" ); - mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) ); + SetupSlider(1, 1.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius"); + mSliders.at(1).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(1)); - SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" ); - SetupMarks( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND ); - mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) ); + SetupSlider(2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices"); + SetupMarks(2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND); + mSliders.at(2).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(0)); //Set model in control. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cone" ); + mShapeTitle.SetProperty(TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cone"); } //Sets the 3D model to a conical frustum and modifies the sliders appropriately. @@ -416,27 +413,27 @@ public: InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CONICAL_FRUSTUM; - mVisualMap[ PrimitiveVisual::Property::SCALE_TOP_RADIUS ] = DEFAULT_SCALE_TOP_RADIUS; - mVisualMap[ PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS ] = DEFAULT_SCALE_BOTTOM_RADIUS; - mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT; - mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES; + mVisualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::CONICAL_FRUSTUM; + mVisualMap[PrimitiveVisual::Property::SCALE_TOP_RADIUS] = DEFAULT_SCALE_TOP_RADIUS; + mVisualMap[PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS] = DEFAULT_SCALE_BOTTOM_RADIUS; + mVisualMap[PrimitiveVisual::Property::SCALE_HEIGHT] = DEFAULT_SCALE_HEIGHT; + mVisualMap[PrimitiveVisual::Property::SLICES] = DEFAULT_SLICES; //Set up used sliders. - SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" ); - mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) ); + SetupSlider(0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight"); + mSliders.at(0).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(1)); - SetupSlider( 1, 0.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius" ); - mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) ); + SetupSlider(1, 0.0f, 32.0f, DEFAULT_SCALE_BOTTOM_RADIUS, PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, "scaleBottomRadius"); + mSliders.at(1).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(1)); - SetupSlider( 2, 0.0f, 32.0f, DEFAULT_SCALE_TOP_RADIUS, PrimitiveVisual::Property::SCALE_TOP_RADIUS, "scaleTopRadius" ); - mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) ); + SetupSlider(2, 0.0f, 32.0f, DEFAULT_SCALE_TOP_RADIUS, PrimitiveVisual::Property::SCALE_TOP_RADIUS, "scaleTopRadius"); + mSliders.at(2).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(1)); //Set model in control. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Conical Frustum" ); + mShapeTitle.SetProperty(TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Conical Frustum"); } //Sets the 3D model to a cylinder and modifies the sliders appropriately. @@ -445,27 +442,27 @@ public: InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CYLINDER; - mVisualMap[ PrimitiveVisual::Property::SCALE_HEIGHT ] = DEFAULT_SCALE_HEIGHT; - mVisualMap[ PrimitiveVisual::Property::SCALE_RADIUS ] = DEFAULT_SCALE_RADIUS; - mVisualMap[ PrimitiveVisual::Property::SLICES ] = DEFAULT_SLICES; + mVisualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::CYLINDER; + mVisualMap[PrimitiveVisual::Property::SCALE_HEIGHT] = DEFAULT_SCALE_HEIGHT; + mVisualMap[PrimitiveVisual::Property::SCALE_RADIUS] = DEFAULT_SCALE_RADIUS; + mVisualMap[PrimitiveVisual::Property::SLICES] = DEFAULT_SLICES; //Set up used sliders. - SetupSlider( 0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight" ); - mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) ); + SetupSlider(0, 1.0f, 32.0f, DEFAULT_SCALE_HEIGHT, PrimitiveVisual::Property::SCALE_HEIGHT, "scaleHeight"); + mSliders.at(0).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(1)); - SetupSlider( 1, 1.0f, 32.0f, DEFAULT_SCALE_RADIUS, PrimitiveVisual::Property::SCALE_RADIUS, "scaleRadius" ); - mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 1 ) ); + SetupSlider(1, 1.0f, 32.0f, DEFAULT_SCALE_RADIUS, PrimitiveVisual::Property::SCALE_RADIUS, "scaleRadius"); + mSliders.at(1).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(1)); - SetupSlider( 2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices" ); - SetupMarks( 2 , SLICES_LOWER_BOUND, SLICES_UPPER_BOUND ); - mSliders.at( 2 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 0 ) ); + SetupSlider(2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND, DEFAULT_STACKS, PrimitiveVisual::Property::SLICES, "slices"); + SetupMarks(2, SLICES_LOWER_BOUND, SLICES_UPPER_BOUND); + mSliders.at(2).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(0)); //Set model in control. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cylinder" ); + mShapeTitle.SetProperty(TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cylinder"); } //Sets the 3D model to a cube and modifies the sliders appropriately. @@ -474,13 +471,13 @@ public: InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::CUBE; + mVisualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::CUBE; //Set model in control. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cube" ); + mShapeTitle.SetProperty(TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Cube"); } //Sets the 3D model to a bevelled cube and modifies the sliders appropriately. @@ -489,22 +486,22 @@ public: InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::BEVELLED_CUBE; - mVisualMap[ PrimitiveVisual::Property::BEVEL_PERCENTAGE ] = DEFAULT_BEVEL_PERCENTAGE; - mVisualMap[ PrimitiveVisual::Property::BEVEL_SMOOTHNESS ] = DEFAULT_BEVEL_SMOOTHNESS; + mVisualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::BEVELLED_CUBE; + mVisualMap[PrimitiveVisual::Property::BEVEL_PERCENTAGE] = DEFAULT_BEVEL_PERCENTAGE; + mVisualMap[PrimitiveVisual::Property::BEVEL_SMOOTHNESS] = DEFAULT_BEVEL_SMOOTHNESS; //Set up used sliders. - SetupSlider( 0, 0.0f, 1.0f, DEFAULT_BEVEL_PERCENTAGE, PrimitiveVisual::Property::BEVEL_PERCENTAGE, "bevelPercentage" ); - mSliders.at( 0 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 2 ) ); + SetupSlider(0, 0.0f, 1.0f, DEFAULT_BEVEL_PERCENTAGE, PrimitiveVisual::Property::BEVEL_PERCENTAGE, "bevelPercentage"); + mSliders.at(0).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(2)); - SetupSlider( 1, 0.0f, 1.0f, DEFAULT_BEVEL_SMOOTHNESS, PrimitiveVisual::Property::BEVEL_SMOOTHNESS, "bevelSmoothness" ); - mSliders.at( 1 ).SetProperty( Slider::Property::VALUE_PRECISION, Property::Value( 2 ) ); + SetupSlider(1, 0.0f, 1.0f, DEFAULT_BEVEL_SMOOTHNESS, PrimitiveVisual::Property::BEVEL_SMOOTHNESS, "bevelSmoothness"); + mSliders.at(1).SetProperty(Slider::Property::VALUE_PRECISION, Property::Value(2)); //Set model in control. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Bevelled Cube" ); + mShapeTitle.SetProperty(TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Bevelled Cube"); } //Sets the 3D model to an octahedron and modifies the sliders appropriately. @@ -513,66 +510,65 @@ public: InitialiseSlidersAndModel(); //Set up specific visual properties. - mVisualMap[ PrimitiveVisual::Property::SHAPE ] = PrimitiveVisual::Shape::OCTAHEDRON; + mVisualMap[PrimitiveVisual::Property::SHAPE] = PrimitiveVisual::Shape::OCTAHEDRON; //Set model in control. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); //Update title. - mShapeTitle.SetProperty( TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Octahedron" ); + mShapeTitle.SetProperty(TextLabel::Property::TEXT, SHAPE_TITLE_PREFIX + "Octahedron"); } //Sets up the slider at the given index for the supplied property, and labels it appropriately. // visualProperty is the property that will be set by this slider. - void SetupSlider( int sliderIndex, float lowerBound, float upperBound, float startPoint, - Property::Index visualProperty, std::string visualPropertyLabel ) + void SetupSlider(int sliderIndex, float lowerBound, float upperBound, float startPoint, Property::Index visualProperty, std::string visualPropertyLabel) { //Set up the slider itself. - mSliders.at( sliderIndex ).RegisterProperty( "visualProperty", Property::Value( visualProperty ), Property::READ_WRITE ); - mSliders.at( sliderIndex ).SetProperty( Slider::Property::LOWER_BOUND, Property::Value( lowerBound ) ); - mSliders.at( sliderIndex ).SetProperty( Slider::Property::UPPER_BOUND, Property::Value( upperBound ) ); - mSliders.at( sliderIndex ).SetProperty( Slider::Property::VALUE, Property::Value( startPoint ) ); - mSliders.at( sliderIndex ).SetProperty( Actor::Property::VISIBLE, true ); + mSliders.at(sliderIndex).RegisterProperty("visualProperty", Property::Value(visualProperty), Property::READ_WRITE); + mSliders.at(sliderIndex).SetProperty(Slider::Property::LOWER_BOUND, Property::Value(lowerBound)); + mSliders.at(sliderIndex).SetProperty(Slider::Property::UPPER_BOUND, Property::Value(upperBound)); + mSliders.at(sliderIndex).SetProperty(Slider::Property::VALUE, Property::Value(startPoint)); + mSliders.at(sliderIndex).SetProperty(Actor::Property::VISIBLE, true); //Label the slider with the property. //We reset the TextLabel to force a relayout of the table. - mSliderTable.RemoveChildAt( TableView::CellPosition(sliderIndex, 0) ); + mSliderTable.RemoveChildAt(TableView::CellPosition(sliderIndex, 0)); - TextLabel sliderLabel = TextLabel::New( visualPropertyLabel ); - sliderLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - sliderLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - sliderLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + TextLabel sliderLabel = TextLabel::New(visualPropertyLabel); + sliderLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + sliderLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + sliderLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); - mSliderTable.AddChild( sliderLabel, TableView::CellPosition( sliderIndex, 0 ) ); - mSliderTable.SetCellAlignment( TableView::CellPosition( sliderIndex, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); + mSliderTable.AddChild(sliderLabel, TableView::CellPosition(sliderIndex, 0)); + mSliderTable.SetCellAlignment(TableView::CellPosition(sliderIndex, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); - mSliderLabels.at( sliderIndex ).SetProperty( Actor::Property::VISIBLE, true ); - mSliderLabels.at( sliderIndex) = sliderLabel; + mSliderLabels.at(sliderIndex).SetProperty(Actor::Property::VISIBLE, true); + mSliderLabels.at(sliderIndex) = sliderLabel; } //Setup snapping to integer values between the two given values. - void SetupMarks( int sliderIndex, int lower, int upper ) + void SetupMarks(int sliderIndex, int lower, int upper) { Property::Array marks; - for( int mark = lower; mark <= upper; mark++ ) + for(int mark = lower; mark <= upper; mark++) { - marks.PushBack( Property::Value( mark ) ); + marks.PushBack(Property::Value(mark)); } - mSliders.at( sliderIndex ).SetProperty( Slider::Property::MARKS, Property::Value( marks ) ); - mSliders.at( sliderIndex ).SetProperty( Slider::Property::SNAP_TO_MARKS, Property::Value( true ) ); + mSliders.at(sliderIndex).SetProperty(Slider::Property::MARKS, Property::Value(marks)); + mSliders.at(sliderIndex).SetProperty(Slider::Property::SNAP_TO_MARKS, Property::Value(true)); } //When a shape button is tapped, switch to the corresponding shape. - bool OnChangeShapeClicked( Button button ) + bool OnChangeShapeClicked(Button button) { //Get the model number from the button. int modelNumber; - button.GetProperty( button.GetPropertyIndex( "modelNumber" ) ).Get( modelNumber ); + button.GetProperty(button.GetPropertyIndex("modelNumber")).Get(modelNumber); //Switch to the shape that corresponds to the model number. - switch( modelNumber ) + switch(modelNumber) { case 0: { @@ -615,23 +611,23 @@ public: } //When the slider is adjusted, change the corresponding shape property accordingly. - bool OnSliderValueChanged( Slider slider, float value ) + bool OnSliderValueChanged(Slider slider, float value) { //Update property map to reflect the change to the specific visual property. int visualProperty; - slider.GetProperty( slider.GetPropertyIndex( "visualProperty" ) ).Get( visualProperty ); - mVisualMap[ visualProperty ] = value; + slider.GetProperty(slider.GetPropertyIndex("visualProperty")).Get(visualProperty); + mVisualMap[visualProperty] = value; //Reload the model to display the change. - mModel.SetProperty( Control::Property::BACKGROUND, Property::Value( mVisualMap ) ); + mModel.SetProperty(Control::Property::BACKGROUND, Property::Value(mVisualMap)); return true; } //Panning around the shape rotates it. - void OnPan( Actor actor, const PanGesture& gesture ) + void OnPan(Actor actor, const PanGesture& gesture) { - switch( gesture.GetState() ) + switch(gesture.GetState()) { case GestureState::STARTED: { @@ -646,10 +642,10 @@ public: const Vector2& displacement = gesture.GetDisplacement(); mRotation.x -= displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis mRotation.y += displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis - Quaternion rotation = Quaternion( Radian( mRotation.x ), Vector3::XAXIS) * - Quaternion( Radian( mRotation.y ), Vector3::YAXIS); + Quaternion rotation = Quaternion(Radian(mRotation.x), Vector3::XAXIS) * + Quaternion(Radian(mRotation.y), Vector3::YAXIS); - mModel.SetProperty( Actor::Property::ORIENTATION, rotation ); + mModel.SetProperty(Actor::Property::ORIENTATION, rotation); break; } @@ -675,11 +671,11 @@ public: } //If escape or the back button is pressed, quit the application (and return to the launcher) - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -689,25 +685,25 @@ public: private: Application& mApplication; - std::vector mSliders; ///< Holds the sliders on screen that each shape accesses. - std::vector mSliderLabels; ///< Holds the labels to each slider. - TableView mSliderTable; ///< A table to layout the sliders next to their labels. + std::vector mSliders; ///< Holds the sliders on screen that each shape accesses. + std::vector mSliderLabels; ///< Holds the labels to each slider. + TableView mSliderTable; ///< A table to layout the sliders next to their labels. - Property::Map mVisualMap; ///< Property map to create a primitive visual. - Control mModel; ///< Control to house the primitive visual. - TextLabel mShapeTitle; ///< Indicates what the currently selected shape is. + Property::Map mVisualMap; ///< Property map to create a primitive visual. + Control mModel; ///< Control to house the primitive visual. + TextLabel mShapeTitle; ///< Indicates what the currently selected shape is. - PanGestureDetector mPanGestureDetector; ///< Detects pan gestures for rotation of the model. - Animation mRotationAnimation; ///< Automatically rotates the model, unless it is being panned. + PanGestureDetector mPanGestureDetector; ///< Detects pan gestures for rotation of the model. + Animation mRotationAnimation; ///< Automatically rotates the model, unless it is being panned. - Vector4 mColor; ///< Color to set all shapes. - Vector2 mRotation; ///< Keeps track of model rotation. + Vector4 mColor; ///< Color to set all shapes. + Vector2 mRotation; ///< Keeps track of model rotation. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - PrimitiveShapesController test( application ); + Application application = Application::New(&argc, &argv); + PrimitiveShapesController test(application); application.MainLoop(); return 0; } diff --git a/examples/progress-bar/progress-bar-example.cpp b/examples/progress-bar/progress-bar-example.cpp index 30864e5..e45478a 100644 --- a/examples/progress-bar/progress-bar-example.cpp +++ b/examples/progress-bar/progress-bar-example.cpp @@ -15,10 +15,10 @@ * */ -#include "shared/view.h" #include #include #include +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; @@ -26,145 +26,143 @@ using Dali::Toolkit::ProgressBar; namespace { -const char * const THEME_PATH( DEMO_STYLE_DIR "progress-bar-example-theme.json" ); ///< The theme used for this example +const char* const THEME_PATH(DEMO_STYLE_DIR "progress-bar-example-theme.json"); ///< The theme used for this example const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg"; -const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; -const char* const TOOLBAR_TITLE = "Progress Bar"; +const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; +const char* const TOOLBAR_TITLE = "Progress Bar"; -const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); +const Vector4 BACKGROUND_COLOUR(1.0f, 1.0f, 1.0f, 0.15f); // Layout sizes -const int MARGIN_SIZE = 10; -const int TOP_MARGIN = 85; +const int MARGIN_SIZE = 10; +const int TOP_MARGIN = 85; const int CIRCULAR_PROGRESS_BAR_SIZE = 64; -const unsigned int TIMER_TIMEOUT_TIME = 50; -const float PROGRESS_INCREMENT_VALUE = 0.01f; +const unsigned int TIMER_TIMEOUT_TIME = 50; +const float PROGRESS_INCREMENT_VALUE = 0.01f; -} // namespace +} // namespace /** * @brief Shows how to create a default progress bar and custom styled progress bars. */ -class ProgressBarExample: public ConnectionTracker +class ProgressBarExample : public ConnectionTracker { public: - - ProgressBarExample( Application& application ) - : mApplication( application ) + ProgressBarExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mProgressValue = 0.0f; + mProgressValue = 0.0f; mSecondaryProgressValue = 0.1f; - isDefaultTheme = true; - mApplication.InitSignal().Connect( this, &ProgressBarExample::Create ); + isDefaultTheme = true; + mApplication.InitSignal().Connect(this, &ProgressBarExample::Create); } private: - - void Create( Application& application ) + void Create(Application& application) { // The Init signal is received once (only) during the Application lifetime // Respond to key events - application.GetWindow().KeyEventSignal().Connect( this, &ProgressBarExample::OnKeyEvent ); + application.GetWindow().KeyEventSignal().Connect(this, &ProgressBarExample::OnKeyEvent); // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - TOOLBAR_TITLE ); + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + TOOLBAR_TITLE); mProgressBarDefault = ProgressBar::New(); - mProgressBarDefault.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_CENTER); - mProgressBarDefault.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); + mProgressBarDefault.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mProgressBarDefault.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); mProgressBarDefault.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); mProgressBarDefault.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); - mProgressBarDefault.ValueChangedSignal().Connect( this, &ProgressBarExample::OnValueChanged ); + mProgressBarDefault.ValueChangedSignal().Connect(this, &ProgressBarExample::OnValueChanged); // Creates a progress bar in circular style - mProgressBarCircular = DevelProgressBar::New( DevelProgressBar::Style::CIRCULAR ); - mProgressBarCircular.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mProgressBarCircular.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mProgressBarCircular.SetProperty( Actor::Property::SIZE, Vector2( CIRCULAR_PROGRESS_BAR_SIZE, CIRCULAR_PROGRESS_BAR_SIZE ) ); + mProgressBarCircular = DevelProgressBar::New(DevelProgressBar::Style::CIRCULAR); + mProgressBarCircular.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mProgressBarCircular.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mProgressBarCircular.SetProperty(Actor::Property::SIZE, Vector2(CIRCULAR_PROGRESS_BAR_SIZE, CIRCULAR_PROGRESS_BAR_SIZE)); Toolkit::TableView contentTable = Toolkit::TableView::New(2, 1); contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); contentTable.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); - contentTable.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); - contentTable.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); + contentTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + contentTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); contentTable.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5f)); - for( unsigned int i = 0; i < contentTable.GetRows(); ++i ) + for(unsigned int i = 0; i < contentTable.GetRows(); ++i) { - contentTable.SetFitHeight( i ); + contentTable.SetFitHeight(i); } - contentTable.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, TOP_MARGIN )); - mContentLayer.Add( contentTable ); + contentTable.SetProperty(Actor::Property::POSITION, Vector2(0.0f, TOP_MARGIN)); + mContentLayer.Add(contentTable); // Image selector for progress bar - Toolkit::TableView progressBackground = Toolkit::TableView::New( 2, 1 ); - progressBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - progressBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - progressBackground.SetBackgroundColor( BACKGROUND_COLOUR ); - progressBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); - progressBackground.SetRelativeWidth( 0, 1.0f ); - - for( unsigned int i = 0; i < progressBackground.GetRows(); ++i ) + Toolkit::TableView progressBackground = Toolkit::TableView::New(2, 1); + progressBackground.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + progressBackground.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + progressBackground.SetBackgroundColor(BACKGROUND_COLOUR); + progressBackground.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); + progressBackground.SetRelativeWidth(0, 1.0f); + + for(unsigned int i = 0; i < progressBackground.GetRows(); ++i) { - progressBackground.SetFitHeight( i ); + progressBackground.SetFitHeight(i); } - contentTable.Add( progressBackground ); - progressBackground.Add( mProgressBarDefault ); - progressBackground.Add( mProgressBarCircular ); + contentTable.Add(progressBackground); + progressBackground.Add(mProgressBarDefault); + progressBackground.Add(mProgressBarCircular); // Create buttons - Toolkit::TableView buttonBackground = Toolkit::TableView::New( 3, 1 ); - buttonBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - buttonBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - buttonBackground.SetBackgroundColor( BACKGROUND_COLOUR ); - buttonBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); + Toolkit::TableView buttonBackground = Toolkit::TableView::New(3, 1); + buttonBackground.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + buttonBackground.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + buttonBackground.SetBackgroundColor(BACKGROUND_COLOUR); + buttonBackground.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); - for( unsigned int i = 0; i < buttonBackground.GetRows(); ++i ) + for(unsigned int i = 0; i < buttonBackground.GetRows(); ++i) { - buttonBackground.SetFitHeight( i ); + buttonBackground.SetFitHeight(i); } - contentTable.Add( buttonBackground ); + contentTable.Add(buttonBackground); mResetProgressButton = Toolkit::PushButton::New(); - mResetProgressButton.SetProperty( Toolkit::Button::Property::LABEL, "Reset" ); - mResetProgressButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mResetProgressButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mResetProgressButton.ClickedSignal().Connect( this, &ProgressBarExample::OnResetProgressButtonSelected ); + mResetProgressButton.SetProperty(Toolkit::Button::Property::LABEL, "Reset"); + mResetProgressButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mResetProgressButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mResetProgressButton.ClickedSignal().Connect(this, &ProgressBarExample::OnResetProgressButtonSelected); - buttonBackground.Add( mResetProgressButton ); + buttonBackground.Add(mResetProgressButton); mSetIndeterminateButton = Toolkit::PushButton::New(); - mSetIndeterminateButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Indeterminate" ); - mSetIndeterminateButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mSetIndeterminateButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mSetIndeterminateButton.ClickedSignal().Connect( this, &ProgressBarExample::OnSetIndeterminateButtonSelected ); + mSetIndeterminateButton.SetProperty(Toolkit::Button::Property::LABEL, "Toggle Indeterminate"); + mSetIndeterminateButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mSetIndeterminateButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mSetIndeterminateButton.ClickedSignal().Connect(this, &ProgressBarExample::OnSetIndeterminateButtonSelected); - buttonBackground.Add( mSetIndeterminateButton ); + buttonBackground.Add(mSetIndeterminateButton); mChangeThemeButton = Toolkit::PushButton::New(); - mChangeThemeButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Theme" ); - mChangeThemeButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mChangeThemeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mChangeThemeButton.ClickedSignal().Connect( this, &ProgressBarExample::OnChangeThemeButtonSelected ); + mChangeThemeButton.SetProperty(Toolkit::Button::Property::LABEL, "Change Theme"); + mChangeThemeButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mChangeThemeButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mChangeThemeButton.ClickedSignal().Connect(this, &ProgressBarExample::OnChangeThemeButtonSelected); - buttonBackground.Add( mChangeThemeButton ); + buttonBackground.Add(mChangeThemeButton); // Create a timer to update the progress of all progress bars - mTimer = Timer::New( TIMER_TIMEOUT_TIME ); - mTimer.TickSignal().Connect( this, &ProgressBarExample::OnTimerTick ); + mTimer = Timer::New(TIMER_TIMEOUT_TIME); + mTimer.TickSignal().Connect(this, &ProgressBarExample::OnTimerTick); mTimer.Start(); } @@ -174,55 +172,55 @@ private: mSecondaryProgressValue = mProgressValue + 0.1f; mProgressBarDefault.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue); mProgressBarDefault.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, mSecondaryProgressValue); - mProgressBarCircular.SetProperty( ProgressBar::Property::PROGRESS_VALUE, mProgressValue ); - mProgressBarCircular.SetProperty( ProgressBar::Property::SECONDARY_PROGRESS_VALUE, mSecondaryProgressValue ); + mProgressBarCircular.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue); + mProgressBarCircular.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, mSecondaryProgressValue); - return ( mProgressValue < 1.0f ); // Only call again if progress has NOT got to the end + return (mProgressValue < 1.0f); // Only call again if progress has NOT got to the end } - bool OnResetProgressButtonSelected( Toolkit::Button button ) + bool OnResetProgressButtonSelected(Toolkit::Button button) { - mProgressValue = 0.0f; + mProgressValue = 0.0f; mSecondaryProgressValue = 0.1f; mProgressBarDefault.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f); mProgressBarDefault.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, 0.1f); - mProgressBarCircular.SetProperty( ProgressBar::Property::PROGRESS_VALUE, 0.0f ); - mProgressBarCircular.SetProperty( ProgressBar::Property::SECONDARY_PROGRESS_VALUE, 0.1f ); + mProgressBarCircular.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f); + mProgressBarCircular.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, 0.1f); mTimer.Start(); return true; } - void OnValueChanged( ProgressBar progressBar, float value, float secondaryValue ) + void OnValueChanged(ProgressBar progressBar, float value, float secondaryValue) { std::stringstream newLabel; - newLabel.precision( 2 ); - newLabel << std::fixed << "current : " << value << " / loaded : " << secondaryValue; + newLabel.precision(2); + newLabel << std::fixed << "current : " << value << " / loaded : " << secondaryValue; - mProgressBarDefault.SetProperty(ProgressBar::Property::LABEL_VISUAL, newLabel.str() ); + mProgressBarDefault.SetProperty(ProgressBar::Property::LABEL_VISUAL, newLabel.str()); } - bool OnSetIndeterminateButtonSelected( Toolkit::Button button ) + bool OnSetIndeterminateButtonSelected(Toolkit::Button button) { - if( mProgressBarDefault.GetProperty(ProgressBar::Property::INDETERMINATE)) + if(mProgressBarDefault.GetProperty(ProgressBar::Property::INDETERMINATE)) { mProgressBarDefault.SetProperty(ProgressBar::Property::INDETERMINATE, false); - mProgressBarCircular.SetProperty( ProgressBar::Property::INDETERMINATE, false ); + mProgressBarCircular.SetProperty(ProgressBar::Property::INDETERMINATE, false); } else { mProgressBarDefault.SetProperty(ProgressBar::Property::INDETERMINATE, true); - mProgressBarCircular.SetProperty( ProgressBar::Property::INDETERMINATE, true ); + mProgressBarCircular.SetProperty(ProgressBar::Property::INDETERMINATE, true); } return true; } - bool OnChangeThemeButtonSelected( Toolkit::Button button ) + bool OnChangeThemeButtonSelected(Toolkit::Button button) { StyleManager styleManager = StyleManager::Get(); - if( isDefaultTheme ) + if(isDefaultTheme) { - styleManager.ApplyTheme( THEME_PATH ); + styleManager.ApplyTheme(THEME_PATH); isDefaultTheme = false; } else @@ -232,11 +230,11 @@ private: } return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { // Exit application when click back or escape. mApplication.Quit(); @@ -246,25 +244,25 @@ private: // Data - Application& mApplication; - Timer mTimer; - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - Layer mContentLayer; ///< Content layer. - ProgressBar mProgressBarDefault; - ProgressBar mProgressBarCircular; + Application& mApplication; + Timer mTimer; + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer. + ProgressBar mProgressBarDefault; + ProgressBar mProgressBarCircular; Toolkit::PushButton mResetProgressButton; Toolkit::PushButton mSetIndeterminateButton; Toolkit::PushButton mChangeThemeButton; - float mProgressValue; - float mSecondaryProgressValue; - bool isDefaultTheme; + float mProgressValue; + float mSecondaryProgressValue; + bool isDefaultTheme; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ProgressBarExample test( application ); + Application application = Application::New(&argc, &argv); + ProgressBarExample test(application); application.MainLoop(); return 0; } diff --git a/examples/property-notification/property-notification-example.cpp b/examples/property-notification/property-notification-example.cpp index 2bb9c7a..6185b69 100644 --- a/examples/property-notification/property-notification-example.cpp +++ b/examples/property-notification/property-notification-example.cpp @@ -15,16 +15,16 @@ * */ -#include #include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { -const float COLOR_ANIMATION_DURATION( 5.0f ); -const float OPACITY_ANIMATION_DURATION( 1.0f ); +const float COLOR_ANIMATION_DURATION(5.0f); +const float OPACITY_ANIMATION_DURATION(1.0f); } // unnamed namespace /** @@ -38,46 +38,45 @@ const float OPACITY_ANIMATION_DURATION( 1.0f ); class PropertyNotificationController : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application A reference to the Application class. */ - PropertyNotificationController( Application& application ) - : mApplication( application ) + PropertyNotificationController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &PropertyNotificationController::Create ); + mApplication.InitSignal().Connect(this, &PropertyNotificationController::Create); } /** * @brief Called to initialise the application content * @param[in] application A reference to the Application class. */ - void Create( Application& application ) + void Create(Application& application) { // Set the window background color and connect to the window's key signal to allow Back and Escape to exit. Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); - window.KeyEventSignal().Connect( this, &PropertyNotificationController::OnKeyEvent ); + window.SetBackgroundColor(Color::WHITE); + window.KeyEventSignal().Connect(this, &PropertyNotificationController::OnKeyEvent); // Create a text label and set the text color to black - mTextLabel = TextLabel::New( "Black to Red Animation\nNew opacity animation at 50% Red" ); - mTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mTextLabel.SetProperty( TextLabel::Property::MULTI_LINE, true ); - mTextLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mTextLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); - window.Add( mTextLabel ); + mTextLabel = TextLabel::New("Black to Red Animation\nNew opacity animation at 50% Red"); + mTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mTextLabel.SetProperty(TextLabel::Property::MULTI_LINE, true); + mTextLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mTextLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLACK); + window.Add(mTextLabel); // Create an animation and animate the text color to red - Animation animation = Animation::New( COLOR_ANIMATION_DURATION ); - animation.AnimateTo( Property( mTextLabel, TextLabel::Property::TEXT_COLOR ), Color::RED ); + Animation animation = Animation::New(COLOR_ANIMATION_DURATION); + animation.AnimateTo(Property(mTextLabel, TextLabel::Property::TEXT_COLOR), Color::RED); animation.Play(); // Set up a property notification so we are notified when the red component of the text-color reaches 50% - PropertyNotification notification = mTextLabel.AddPropertyNotification( TextLabel::Property::TEXT_COLOR_RED, GreaterThanCondition( 0.5f ) ); - notification.NotifySignal().Connect( this, &PropertyNotificationController::RedComponentNotification ); + PropertyNotification notification = mTextLabel.AddPropertyNotification(TextLabel::Property::TEXT_COLOR_RED, GreaterThanCondition(0.5f)); + notification.NotifySignal().Connect(this, &PropertyNotificationController::RedComponentNotification); } /** @@ -86,11 +85,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -103,22 +102,22 @@ public: * In our case, it's when the red component is greater than 50%. * Will use this notification to animate the opacity of the text-label to transparent. */ - void RedComponentNotification( PropertyNotification& /* source */ ) + void RedComponentNotification(PropertyNotification& /* source */) { - Animation animation = Animation::New( OPACITY_ANIMATION_DURATION ); - animation.AnimateTo( Property( mTextLabel, Actor::Property::OPACITY ), 0.0f ); + Animation animation = Animation::New(OPACITY_ANIMATION_DURATION); + animation.AnimateTo(Property(mTextLabel, Actor::Property::OPACITY), 0.0f); animation.Play(); } private: Application& mApplication; - TextLabel mTextLabel; + TextLabel mTextLabel; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - PropertyNotificationController test( application ); + Application application = Application::New(&argc, &argv); + PropertyNotificationController test(application); application.MainLoop(); return 0; } diff --git a/examples/ray-marching/ray-marching-example.cpp b/examples/ray-marching/ray-marching-example.cpp index 39caa42..ed481e6 100644 --- a/examples/ray-marching/ray-marching-example.cpp +++ b/examples/ray-marching/ray-marching-example.cpp @@ -17,20 +17,20 @@ #include #include -#include "shared/view.h" -#include "shared/utility.h" -#include -#include #include +#include +#include +#include "shared/utility.h" +#include "shared/view.h" using namespace Dali; -using Dali::Toolkit::TextLabel; using Dali::Toolkit::Control; +using Dali::Toolkit::TextLabel; using Dali::Toolkit::ToolBar; -const char* BACKGROUND_IMAGE( "" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "Ray Marching" ); +const char* BACKGROUND_IMAGE(""); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("Ray Marching"); const char* SHADER_NAME("raymarch_sphere_shaded"); /** @@ -39,31 +39,31 @@ const char* SHADER_NAME("raymarch_sphere_shaded"); * @param output * @return */ -bool LoadShaderCode( const char* path, const char* filename, std::vector& output ) +bool LoadShaderCode(const char* path, const char* filename, std::vector& output) { - std::string fullpath( path ); + std::string fullpath(path); fullpath += filename; - Dali::FileStream fileStream( fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY ); - FILE* file = fileStream.GetFile(); - if( !file ) + Dali::FileStream fileStream(fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY); + FILE* file = fileStream.GetFile(); + if(!file) { return false; } bool retValue = false; - if( !fseek( file, 0, SEEK_END ) ) + if(!fseek(file, 0, SEEK_END)) { - long int size = ftell( file ); + long int size = ftell(file); - if( ( size != -1L ) && - ( ! fseek( file, 0, SEEK_SET ) ) ) + if((size != -1L) && + (!fseek(file, 0, SEEK_SET))) { - output.resize( size + 1 ); - std::fill( output.begin(), output.end(), 0 ); - ssize_t result = fread( output.data(), size, 1, file ); + output.resize(size + 1); + std::fill(output.begin(), output.end(), 0); + ssize_t result = fread(output.data(), size, 1, file); - retValue = ( result >= 0 ); + retValue = (result >= 0); } } @@ -75,19 +75,19 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& * @param shaderName * @return */ -Shader LoadShaders( const std::string& shaderName ) +Shader LoadShaders(const std::string& shaderName) { std::vector bufV, bufF; - std::string shaderVSH( shaderName ); - std::string shaderFSH( shaderName ); + std::string shaderVSH(shaderName); + std::string shaderFSH(shaderName); shaderVSH += ".vsh"; shaderFSH += ".fsh"; Shader shader; - if( LoadShaderCode( DEMO_SHADER_DIR, shaderVSH.c_str(), bufV ) && - LoadShaderCode( DEMO_SHADER_DIR, shaderFSH.c_str(), bufF ) ) + if(LoadShaderCode(DEMO_SHADER_DIR, shaderVSH.c_str(), bufV) && + LoadShaderCode(DEMO_SHADER_DIR, shaderFSH.c_str(), bufF)) { - shader = Shader::New( bufV.data(), bufF.data() ); + shader = Shader::New(bufV.data(), bufF.data()); } return shader; } @@ -97,12 +97,11 @@ Shader LoadShaders( const std::string& shaderName ) class RayMarchingExample : public ConnectionTracker { public: - - RayMarchingExample( Application& application ) - : mApplication( application ) + RayMarchingExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &RayMarchingExample::Create ); + mApplication.InitSignal().Connect(this, &RayMarchingExample::Create); } ~RayMarchingExample() @@ -111,33 +110,32 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.GetRootLayer().TouchedSignal().Connect( this, &RayMarchingExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &RayMarchingExample::OnTouch); window.KeyEventSignal().Connect(this, &RayMarchingExample::OnKeyEvent); - window.SetBackgroundColor( Color::YELLOW ); + window.SetBackgroundColor(Color::YELLOW); // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Add an extra space on the right to center the title text. - mToolBar.AddControl( Actor::New(), DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT ); + mToolBar.AddControl(Actor::New(), DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT); AddContentLayer(); - } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -151,7 +149,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -164,38 +162,37 @@ public: Renderer CreateQuadRenderer() { // Create shader & geometry needed by Renderer - Shader shader = LoadShaders( SHADER_NAME ); + Shader shader = LoadShaders(SHADER_NAME); Property::Map vertexFormat; vertexFormat["aPosition"] = Property::VECTOR2; - VertexBuffer vertexBuffer = VertexBuffer::New( vertexFormat ); + VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat); - const float P( 0.5f ); + const float P(0.5f); const Vector2 vertices[] = { - Vector2( -P, -P ), - Vector2( +P, -P ), - Vector2( -P, +P ), - Vector2( +P, +P ) - }; + Vector2(-P, -P), + Vector2(+P, -P), + Vector2(-P, +P), + Vector2(+P, +P)}; - vertexBuffer.SetData( vertices, 4 ); + vertexBuffer.SetData(vertices, 4); // Instantiate quad geometry Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLE_STRIP ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLE_STRIP); // Create renderer - Renderer renderer = Renderer::New( geometry, shader ); + Renderer renderer = Renderer::New(geometry, shader); - renderer.RegisterProperty("uRadius", 0.0f ); - renderer.RegisterProperty("uAdjuster", -4.0f ); + renderer.RegisterProperty("uRadius", 0.0f); + renderer.RegisterProperty("uAdjuster", -4.0f); // Animate the sphere radius uniform and a generic uAdjust uniform currently used to move the light around Animation animation = Animation::New(8.0f); - animation.AnimateTo( Property(renderer,"uRadius"), 1.2f, AlphaFunction::BOUNCE); - animation.AnimateTo( Property(renderer,"uAdjuster"), 4.0f, AlphaFunction::BOUNCE); - animation.SetLooping( true ); + animation.AnimateTo(Property(renderer, "uRadius"), 1.2f, AlphaFunction::BOUNCE); + animation.AnimateTo(Property(renderer, "uAdjuster"), 4.0f, AlphaFunction::BOUNCE); + animation.SetLooping(true); animation.Play(); return renderer; @@ -205,30 +202,30 @@ public: { Window window = mApplication.GetWindow(); - //Create all the renderers + //Create all the renderers Renderer renderer = CreateQuadRenderer(); Actor actor = Actor::New(); - actor.AddRenderer( renderer ); + actor.AddRenderer(renderer); - actor.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - actor.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + actor.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); - mContentLayer.Add( actor ); + mContentLayer.Add(actor); } private: - Application& mApplication; - Control mView; - Layer mContentLayer; - ToolBar mToolBar; + Application& mApplication; + Control mView; + Layer mContentLayer; + ToolBar mToolBar; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - RayMarchingExample test( application ); + Application application = Application::New(&argc, &argv); + RayMarchingExample test(application); application.MainLoop(); return 0; } diff --git a/examples/reflection-demo/gltf-scene.cpp b/examples/reflection-demo/gltf-scene.cpp index 46e39cf..924ead9 100644 --- a/examples/reflection-demo/gltf-scene.cpp +++ b/examples/reflection-demo/gltf-scene.cpp @@ -26,26 +26,22 @@ namespace const std::vector GLTF_STR_ATTRIBUTE_TYPE = { "POSITION", "NORMAL", - "TEXCOORD_0" -}; + "TEXCOORD_0"}; const std::vector> GLTF_STR_COMPONENT_TYPE = { - std::make_pair( "VEC2", 2 ), - std::make_pair( "VEC3", 3 ), - std::make_pair( "VEC4", 4 ), - std::make_pair( "SCALAR", 1 ) -}; + std::make_pair("VEC2", 2), + std::make_pair("VEC3", 3), + std::make_pair("VEC4", 4), + std::make_pair("SCALAR", 1)}; -glTFAttributeType glTFAttributeTypeStrToEnum( const std::string& name ) +glTFAttributeType glTFAttributeTypeStrToEnum(const std::string& name) { - int index = -1; - auto iter = std::find_if( GLTF_STR_ATTRIBUTE_TYPE.begin(), GLTF_STR_ATTRIBUTE_TYPE.end(), - [name, &index]( const std::string& val ) - { + int index = -1; + auto iter = std::find_if(GLTF_STR_ATTRIBUTE_TYPE.begin(), GLTF_STR_ATTRIBUTE_TYPE.end(), [name, &index](const std::string& val) { index++; return val == name; }); - if( iter == GLTF_STR_ATTRIBUTE_TYPE.end() ) + if(iter == GLTF_STR_ATTRIBUTE_TYPE.end()) { return glTFAttributeType::UNDEFINED; } @@ -53,14 +49,12 @@ glTFAttributeType glTFAttributeTypeStrToEnum( const std::string& name ) return static_cast(index); } -uint32_t glTFComponentTypeStrToNum( const std::string& name ) +uint32_t glTFComponentTypeStrToNum(const std::string& name) { - auto iter = std::find_if( GLTF_STR_COMPONENT_TYPE.begin(), GLTF_STR_COMPONENT_TYPE.end(), - [name]( const std::pair& val ) - { - return val.first == name; - }); - if( iter == GLTF_STR_COMPONENT_TYPE.end() ) + auto iter = std::find_if(GLTF_STR_COMPONENT_TYPE.begin(), GLTF_STR_COMPONENT_TYPE.end(), [name](const std::pair& val) { + return val.first == name; + }); + if(iter == GLTF_STR_COMPONENT_TYPE.end()) { return 0; } @@ -92,10 +86,9 @@ struct JsonResult }; template -JsonResult JsonFindValue( const picojson::object& object, const std::string& name ) +JsonResult JsonFindValue(const picojson::object& object, const std::string& name) { - auto iter = find_if(object.begin(), object.end(), [name](decltype(*object.begin())& item) - { + auto iter = find_if(object.begin(), object.end(), [name](decltype(*object.begin())& item) { return item.first == name; }); @@ -107,11 +100,10 @@ JsonResult JsonFindValue( const picojson::object& object, const return {true, iter->second}; }; - template -JsonResult JsonGetValue( const picojson::value& val, const std::string& name, const Converted& onFail ) +JsonResult JsonGetValue(const picojson::value& val, const std::string& name, const Converted& onFail) { - if( val.contains(name) ) + if(val.contains(name)) { return {true, static_cast(val.get(name).get())}; } @@ -119,9 +111,9 @@ JsonResult JsonGetValue( const picojson::value& val, const std::strin } template -bool JsonGetValueOut( const picojson::value& val, const std::string& name, Converted& writeOut ) +bool JsonGetValueOut(const picojson::value& val, const std::string& name, Converted& writeOut) { - if( val.contains(name) ) + if(val.contains(name)) { writeOut = static_cast(val.get(name).get()); return true; @@ -129,27 +121,26 @@ bool JsonGetValueOut( const picojson::value& val, const std::string& name, Conve return false; } - /** * Safe json value accessor */ template -JsonResult> JsonGetArray( const picojson::value& val, const std::string& name, std::vector valueOnFail = {} ) +JsonResult> JsonGetArray(const picojson::value& val, const std::string& name, std::vector valueOnFail = {}) { - if(val.contains(name) ) + if(val.contains(name)) { - const auto& array = val.get(name).get(); + const auto& array = val.get(name).get(); std::vector result{}; - for( const auto& item : array ) + for(const auto& item : array) { - result.emplace_back( static_cast(item.get()) ); + result.emplace_back(static_cast(item.get())); } return {true, result}; } return {false, valueOnFail}; } -} +} // namespace glTF::glTF(const std::string& filename) { @@ -157,17 +148,17 @@ glTF::glTF(const std::string& filename) ParseJSON(); } -void glTF::LoadFromFile( const std::string& filename ) +void glTF::LoadFromFile(const std::string& filename) { - std::string jsonFile( filename ); + std::string jsonFile(filename); jsonFile += ".gltf"; - std::string binFile( filename ); + std::string binFile(filename); binFile += ".bin"; // load binary GLTF_LOG("LoadFromFile: %s", binFile.c_str()); - mBuffer = LoadFile(binFile); + mBuffer = LoadFile(binFile); jsonBuffer = LoadFile(jsonFile); // Log errors @@ -177,7 +168,7 @@ void glTF::LoadFromFile( const std::string& filename ) } else { - GLTF_LOG( "GLTF[BIN]: %s loaded, size = %d", binFile.c_str(), int(mBuffer.size())); + GLTF_LOG("GLTF[BIN]: %s loaded, size = %d", binFile.c_str(), int(mBuffer.size())); } if(jsonBuffer.empty()) { @@ -185,7 +176,7 @@ void glTF::LoadFromFile( const std::string& filename ) } else { - GLTF_LOG( "GLTF: %s loaded, size = %d", binFile.c_str(), int(jsonBuffer.size())); + GLTF_LOG("GLTF: %s loaded, size = %d", binFile.c_str(), int(jsonBuffer.size())); } // Abort if errors @@ -198,18 +189,18 @@ void glTF::LoadFromFile( const std::string& filename ) auto err = picojson::parse(jsonNode, std::string(reinterpret_cast(jsonBuffer.data()))); if(!err.empty()) { - GLTF_LOG( "GLTF: Error parsing %s, error: %s", jsonFile.c_str(), err.c_str()); + GLTF_LOG("GLTF: Error parsing %s, error: %s", jsonFile.c_str(), err.c_str()); return; } else { - GLTF_LOG( "GLTF: %s loaded, size = %d", jsonFile.c_str(), int(jsonBuffer.size())); + GLTF_LOG("GLTF: %s loaded, size = %d", jsonFile.c_str(), int(jsonBuffer.size())); } } bool glTF::ParseJSON() { - if (!jsonNode.is()) + if(!jsonNode.is()) { return false; } @@ -218,212 +209,211 @@ bool glTF::ParseJSON() mNodes.emplace_back(); // Sources for textures to be resolved later - std::vector textureSources{}; + std::vector textureSources{}; std::vector images{}; - for( auto& val : jsonNode.get() ) + for(auto& val : jsonNode.get()) { - GLTF_LOG( "node: %s", val.first.c_str()); + GLTF_LOG("node: %s", val.first.c_str()); // Parse bufferviews - if( val.first == "bufferViews" ) + if(val.first == "bufferViews") { auto bufferViews = val.second; - for( auto& view : bufferViews.get() ) + for(auto& view : bufferViews.get()) { auto bufferIndex = uint32_t(view.get("buffer").get()); - auto byteLength = uint32_t(view.get("byteLength").get()); - auto byteOffset = uint32_t(view.get("byteOffset").get()); + auto byteLength = uint32_t(view.get("byteLength").get()); + auto byteOffset = uint32_t(view.get("byteOffset").get()); glTF_BufferView bufferView{}; bufferView.bufferIndex = bufferIndex; - bufferView.byteLength = byteLength; - bufferView.byteOffset = byteOffset; + bufferView.byteLength = byteLength; + bufferView.byteOffset = byteOffset; - mBufferViews.emplace_back( bufferView ); + mBufferViews.emplace_back(bufferView); } } // parse accessors - else if( val.first == "accessors" ) + else if(val.first == "accessors") { - for( const auto& accessor : val.second.get() ) + for(const auto& accessor : val.second.get()) { - auto gltfAccessor = glTF_Accessor{}; - gltfAccessor.bufferView = uint32_t(accessor.get( "bufferView" ).get()); - gltfAccessor.componentType = uint32_t(accessor.get( "componentType" ).get()); - gltfAccessor.count = uint32_t(accessor.get( "count" ).get()); - gltfAccessor.type = accessor.get( "type" ).get(); - gltfAccessor.componentSize = glTFComponentTypeStrToNum( gltfAccessor.type ); - mAccessors.emplace_back( gltfAccessor ); + auto gltfAccessor = glTF_Accessor{}; + gltfAccessor.bufferView = uint32_t(accessor.get("bufferView").get()); + gltfAccessor.componentType = uint32_t(accessor.get("componentType").get()); + gltfAccessor.count = uint32_t(accessor.get("count").get()); + gltfAccessor.type = accessor.get("type").get(); + gltfAccessor.componentSize = glTFComponentTypeStrToNum(gltfAccessor.type); + mAccessors.emplace_back(gltfAccessor); } } // parse meshes - else if( val.first == "meshes" ) + else if(val.first == "meshes") { - for( const auto& mesh : val.second.get() ) + for(const auto& mesh : val.second.get()) { glTF_Mesh gltfMesh{}; - gltfMesh.name = mesh.get( "name" ).get(); + gltfMesh.name = mesh.get("name").get(); // get primitives (in this implementation assuming single mesh consists of // one and only one primitive) const auto& primitive = mesh.get("primitives").get()[0]; - const auto& attrs = primitive.get("attributes").get(); - for( const auto& attr : attrs ) + const auto& attrs = primitive.get("attributes").get(); + for(const auto& attr : attrs) { - auto type = glTFAttributeTypeStrToEnum( attr.first ); + auto type = glTFAttributeTypeStrToEnum(attr.first); auto bvIndex = uint32_t(attr.second.get()); - gltfMesh.attributes.emplace_back( std::make_pair( type, bvIndex ) ); + gltfMesh.attributes.emplace_back(std::make_pair(type, bvIndex)); GLTF_LOG("GLTF: ATTR: type: %d, index: %d", int(type), int(bvIndex)); } - gltfMesh.indices = uint32_t(primitive.get("indices").get()); + gltfMesh.indices = uint32_t(primitive.get("indices").get()); gltfMesh.material = uint32_t(primitive.get("material").get()); - mMeshes.emplace_back( gltfMesh ); + mMeshes.emplace_back(gltfMesh); } } // parse cameras - else if( val.first == "cameras" ) + else if(val.first == "cameras") { glTF_Camera tgifCamera{}; - for( const auto& camera : val.second.get() ) + for(const auto& camera : val.second.get()) { - tgifCamera.name = camera.get( "name" ).to_str(); - tgifCamera.isPerspective = (camera.get( "type" ).to_str() == "perspective" ); + tgifCamera.name = camera.get("name").to_str(); + tgifCamera.isPerspective = (camera.get("type").to_str() == "perspective"); if(tgifCamera.isPerspective) { - const auto& perspective = camera.get( "perspective" ); - tgifCamera.yfov = static_cast(perspective.get( "yfov" ).get()); - tgifCamera.zfar = static_cast(perspective.get( "zfar" ).get()); - tgifCamera.znear = static_cast(perspective.get( "znear" ).get()); + const auto& perspective = camera.get("perspective"); + tgifCamera.yfov = static_cast(perspective.get("yfov").get()); + tgifCamera.zfar = static_cast(perspective.get("zfar").get()); + tgifCamera.znear = static_cast(perspective.get("znear").get()); } - mCameras.emplace_back( tgifCamera ); + mCameras.emplace_back(tgifCamera); } } // parse nodes - else if( val.first == "nodes" ) + else if(val.first == "nodes") { auto nodeIndex = 1u; - for( const auto& node : val.second.get() ) + for(const auto& node : val.second.get()) { glTF_Node gltfNode{}; - gltfNode.name = node.get( "name" ).to_str(); - auto rotation = JsonGetArray( node, "rotation", {0.0f, 0.0f, 0.0f, 1.0f} ); - auto translation = JsonGetArray( node, "translation", {0.0f, 0.0f, 0.0f} ); - auto scale = JsonGetArray( node, "scale", {1.0f, 1.0f, 1.0f} ); - std::copy( rotation.result.begin(), rotation.result.end(), gltfNode.rotationQuaternion ); - std::copy( translation.result.begin(), translation.result.end(), gltfNode.translation ); - std::copy( scale.result.begin(), scale.result.end(), gltfNode.scale ); - - auto children = JsonGetArray( node, "children" ); + gltfNode.name = node.get("name").to_str(); + auto rotation = JsonGetArray(node, "rotation", {0.0f, 0.0f, 0.0f, 1.0f}); + auto translation = JsonGetArray(node, "translation", {0.0f, 0.0f, 0.0f}); + auto scale = JsonGetArray(node, "scale", {1.0f, 1.0f, 1.0f}); + std::copy(rotation.result.begin(), rotation.result.end(), gltfNode.rotationQuaternion); + std::copy(translation.result.begin(), translation.result.end(), gltfNode.translation); + std::copy(scale.result.begin(), scale.result.end(), gltfNode.scale); + + auto children = JsonGetArray(node, "children"); if(children.success) { gltfNode.children = std::move(children.result); } - gltfNode.index = nodeIndex; + gltfNode.index = nodeIndex; gltfNode.cameraId = 0xffffffff; - gltfNode.meshId = 0xffffffff; + gltfNode.meshId = 0xffffffff; - auto cameraId = JsonGetValue( node, "camera", 0xffffffff ); - if( cameraId.success ) + auto cameraId = JsonGetValue(node, "camera", 0xffffffff); + if(cameraId.success) { gltfNode.cameraId = cameraId.result; } - auto meshId = JsonGetValue( node, "mesh", 0xffffffff ); - if( meshId.success ) + auto meshId = JsonGetValue(node, "mesh", 0xffffffff); + if(meshId.success) { gltfNode.meshId = meshId.result; } - mNodes.emplace_back( gltfNode ); + mNodes.emplace_back(gltfNode); ++nodeIndex; } - } // parse scenes, note: only first scene is being parsed - else if( val.first == "scenes" ) + else if(val.first == "scenes") { - auto& sceneNode = mNodes[0]; - const auto& scene = val.second.get()[0]; - sceneNode.name = JsonGetValue( scene, "name", std::string() ); - auto result = JsonGetArray( scene, "nodes" ); - sceneNode.children = result.result; - sceneNode.index = 0; + auto& sceneNode = mNodes[0]; + const auto& scene = val.second.get()[0]; + sceneNode.name = JsonGetValue(scene, "name", std::string()); + auto result = JsonGetArray(scene, "nodes"); + sceneNode.children = result.result; + sceneNode.index = 0; } - else if( val.first == "materials" ) + else if(val.first == "materials") { - for( const auto& node : val.second.get() ) + for(const auto& node : val.second.get()) { // Get pbr material, base color texture glTF_Material material{}; - material.doubleSided = JsonGetValue( node, "doubleSided", false ).result; - material.name = JsonGetValue( node, "name", std::string() ).result; - if( node.contains("pbrMetallicRoughness") ) + material.doubleSided = JsonGetValue(node, "doubleSided", false).result; + material.name = JsonGetValue(node, "name", std::string()).result; + if(node.contains("pbrMetallicRoughness")) { const auto& node0 = node.get("pbrMetallicRoughness"); if(node0.contains("baseColorTexture")) { - const auto& node1 = node0.get("baseColorTexture"); - auto index = uint32_t(node1.get("index").get()); - auto texCoord = uint32_t(node1.get("texCoord").get()); - material.pbrMetallicRoughness.enabled = true; - material.pbrMetallicRoughness.baseTextureColor.index = index; + const auto& node1 = node0.get("baseColorTexture"); + auto index = uint32_t(node1.get("index").get()); + auto texCoord = uint32_t(node1.get("texCoord").get()); + material.pbrMetallicRoughness.enabled = true; + material.pbrMetallicRoughness.baseTextureColor.index = index; material.pbrMetallicRoughness.baseTextureColor.texCoord = texCoord; } } - mMaterials.emplace_back( material ); + mMaterials.emplace_back(material); } } - else if( val.first == "textures" ) + else if(val.first == "textures") { - for(const auto& item : val.second.get() ) + for(const auto& item : val.second.get()) { - auto source = JsonGetValue( item, "source", 0xffffffff ); - textureSources.emplace_back( source.result ); + auto source = JsonGetValue(item, "source", 0xffffffff); + textureSources.emplace_back(source.result); } } - else if( val.first == "images" ) + else if(val.first == "images") { - for(const auto& item : val.second.get() ) + for(const auto& item : val.second.get()) { glTF_Texture tex{}; - JsonGetValueOut( item, "name", tex.name ); - JsonGetValueOut( item, "uri", tex.uri ); - images.emplace_back( tex ); + JsonGetValueOut(item, "name", tex.name); + JsonGetValueOut(item, "uri", tex.uri); + images.emplace_back(tex); } } } // Resolve cross-referencing - for( const auto& source : textureSources ) + for(const auto& source : textureSources) { - mTextures.emplace_back( images[source] ); + mTextures.emplace_back(images[source]); } return true; } -glTF_Buffer glTF::LoadFile( const std::string& filename ) +glTF_Buffer glTF::LoadFile(const std::string& filename) { - Dali::FileStream fileStream( filename.c_str(), Dali::FileStream::READ | Dali::FileStream::BINARY ); - FILE* fin = fileStream.GetFile(); + Dali::FileStream fileStream(filename.c_str(), Dali::FileStream::READ | Dali::FileStream::BINARY); + FILE* fin = fileStream.GetFile(); std::vector buffer; - if( fin ) + if(fin) { - if( fseek( fin, 0, SEEK_END ) ) + if(fseek(fin, 0, SEEK_END)) { return {}; } auto size = ftell(fin); - if( fseek( fin, 0, SEEK_SET ) ) + if(fseek(fin, 0, SEEK_SET)) { return {}; } buffer.resize(unsigned(size)); - auto result = fread( buffer.data(), 1, size_t(size), fin ); - if( result != size_t(size) ) + auto result = fread(buffer.data(), 1, size_t(size), fin); + if(result != size_t(size)) { GLTF_LOG("LoadFile: Result: %d", int(result)); // return empty buffer @@ -441,9 +431,9 @@ glTF_Buffer glTF::LoadFile( const std::string& filename ) std::vector glTF::GetMeshes() const { std::vector retval; - for( auto& mesh : mMeshes ) + for(auto& mesh : mMeshes) { - retval.emplace_back( &mesh ); + retval.emplace_back(&mesh); } return retval; } @@ -451,27 +441,27 @@ std::vector glTF::GetMeshes() const std::vector glTF::GetCameras() { std::vector cameras; - for( const auto& cam : mCameras ) + for(const auto& cam : mCameras) { - cameras.emplace_back( &cam ); + cameras.emplace_back(&cam); } return cameras; } -std::vector glTF::GetMeshAttributeBuffer( const glTF_Mesh& mesh, const std::vector& attrTypes ) +std::vector glTF::GetMeshAttributeBuffer(const glTF_Mesh& mesh, const std::vector& attrTypes) { // find buffer views struct Data { uint32_t accessorIndex{0u}; uint32_t byteStride{0u}; - char* srcPtr{ nullptr }; + char* srcPtr{nullptr}; }; std::vector data{}; - for( const auto& attrType : attrTypes ) + for(const auto& attrType : attrTypes) { - std::find_if( mesh.attributes.begin(), mesh.attributes.end(), [&data, &attrType]( const std::pair& item ){ - if( item.first == attrType ) + std::find_if(mesh.attributes.begin(), mesh.attributes.end(), [&data, &attrType](const std::pair& item) { + if(item.first == attrType) { data.emplace_back(); data.back().accessorIndex = item.second; @@ -491,32 +481,32 @@ std::vector glTF::GetMeshAttributeBuffer( const glTF_Mesh& mesh, glTF_Buffer retval{}; // data is interleaved - if( data.size() > 1 ) + if(data.size() > 1) { - auto attributeCount = mAccessors[data[0].accessorIndex].count;// / mAccessors[data[0].accessorIndex].componentSize; + auto attributeCount = mAccessors[data[0].accessorIndex].count; // / mAccessors[data[0].accessorIndex].componentSize; uint32_t attributeStride = 0; // now find buffer view stride for particular accessor - for( auto& item : data ) + for(auto& item : data) { auto& accessor = mAccessors[item.accessorIndex]; // Update byte stride for this buffer view auto& bufferView = mBufferViews[accessor.bufferView]; - item.byteStride = bufferView.byteLength / attributeCount; + item.byteStride = bufferView.byteLength / attributeCount; attributeStride += item.byteStride; item.srcPtr = reinterpret_cast(mBuffer.data()) + bufferView.byteOffset; } // now allocate final buffer and interleave data - retval.resize( attributeStride * attributeCount ); + retval.resize(attributeStride * attributeCount); auto* dstPtr = retval.data(); - for( auto i = 0u; i < attributeCount; ++i ) + for(auto i = 0u; i < attributeCount; ++i) { - for(auto& item : data ) + for(auto& item : data) { - std::copy( item.srcPtr, - item.srcPtr + item.byteStride, - reinterpret_cast(dstPtr) ); + std::copy(item.srcPtr, + item.srcPtr + item.byteStride, + reinterpret_cast(dstPtr)); dstPtr += item.byteStride; item.srcPtr += item.byteStride; } @@ -525,19 +515,17 @@ std::vector glTF::GetMeshAttributeBuffer( const glTF_Mesh& mesh, else // copy data directly as single buffer { auto& bufferView = mBufferViews[mAccessors[data[0].accessorIndex].bufferView]; - retval.resize( bufferView.byteLength ); - std::copy( mBuffer.begin() + bufferView.byteOffset, - mBuffer.begin() + bufferView.byteOffset + bufferView.byteLength, - retval.begin()); - + retval.resize(bufferView.byteLength); + std::copy(mBuffer.begin() + bufferView.byteOffset, + mBuffer.begin() + bufferView.byteOffset + bufferView.byteLength, + retval.begin()); } return retval; } - -const glTF_Mesh* glTF::FindMeshByName( const std::string& name ) const +const glTF_Mesh* glTF::FindMeshByName(const std::string& name) const { - for( const auto& mesh : mMeshes ) + for(const auto& mesh : mMeshes) { if(mesh.name == name) return &mesh; @@ -545,34 +533,32 @@ const glTF_Mesh* glTF::FindMeshByName( const std::string& name ) const return nullptr; } -uint32_t glTF::GetMeshAttributeCount( const glTF_Mesh* mesh ) const +uint32_t glTF::GetMeshAttributeCount(const glTF_Mesh* mesh) const { const auto& accessor = mAccessors[mesh->attributes[0].second]; - return accessor.count;// / accessor.componentSize; + return accessor.count; // / accessor.componentSize; } -std::vector glTF::GetMeshIndexBuffer( const glTF_Mesh* mesh ) const +std::vector glTF::GetMeshIndexBuffer(const glTF_Mesh* mesh) const { // check GL component type const auto& accessor = mAccessors[mesh->indices]; - if( accessor.componentType == 0x1403 ) // GL_UNSIGNED_SHORT + if(accessor.componentType == 0x1403) // GL_UNSIGNED_SHORT { std::vector retval{}; - retval.resize( accessor.count ); + retval.resize(accessor.count); const auto& bufferView = mBufferViews[accessor.bufferView]; - const auto* srcPtr = reinterpret_cast - (reinterpret_cast(mBuffer.data()) + bufferView.byteOffset); - std::copy( srcPtr, srcPtr + accessor.count, retval.data() ); + const auto* srcPtr = reinterpret_cast(reinterpret_cast(mBuffer.data()) + bufferView.byteOffset); + std::copy(srcPtr, srcPtr + accessor.count, retval.data()); return retval; } return {}; } -const glTF_Node* glTF::FindNodeByName( const std::string& name ) const +const glTF_Node* glTF::FindNodeByName(const std::string& name) const { - auto iter = std::find_if( mNodes.begin(), mNodes.end(), [name]( const glTF_Node& node ) - { - return !name.compare( node.name ); + auto iter = std::find_if(mNodes.begin(), mNodes.end(), [name](const glTF_Node& node) { + return !name.compare(node.name); }); if(iter == mNodes.end()) diff --git a/examples/reflection-demo/gltf-scene.h b/examples/reflection-demo/gltf-scene.h index 8dbefc4..d31270a 100644 --- a/examples/reflection-demo/gltf-scene.h +++ b/examples/reflection-demo/gltf-scene.h @@ -24,12 +24,15 @@ #include "pico-json.h" -#define GLTF_LOG(...) {Dali::Integration::Log::LogMessage( Dali::Integration::Log::DebugInfo, __VA_ARGS__ );} +#define GLTF_LOG(...) \ + { \ + Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, __VA_ARGS__); \ + } enum class glTFAttributeType { - POSITION = 0, - NORMAL = 1, + POSITION = 0, + NORMAL = 1, TEXCOORD_0 = 2, UNDEFINED, }; @@ -56,19 +59,19 @@ struct glTF_BufferView struct glTF_Accessor { - uint32_t bufferView; - uint32_t componentType; - uint32_t count; - uint32_t componentSize; + uint32_t bufferView; + uint32_t componentType; + uint32_t count; + uint32_t componentSize; std::string type; }; struct glTF_Mesh { - std::string name; + std::string name; std::vector> attributes; - uint32_t indices; - uint32_t material; + uint32_t indices; + uint32_t material; }; struct glTF_Texture @@ -79,11 +82,11 @@ struct glTF_Texture struct glTF_Material { - bool doubleSided; + bool doubleSided; std::string name; struct pbrMetallicRoughness { - bool enabled {false}; + bool enabled{false}; struct baseTextureColor { uint32_t index; @@ -94,17 +97,17 @@ struct glTF_Material struct glTF_Node { - uint32_t index{0u}; - std::string name{}; - uint32_t meshId { 0xffffffff }; - uint32_t cameraId{ 0xffffffff }; - glTF_Node* parent { nullptr }; - std::vector children {}; + uint32_t index{0u}; + std::string name{}; + uint32_t meshId{0xffffffff}; + uint32_t cameraId{0xffffffff}; + glTF_Node* parent{nullptr}; + std::vector children{}; // Transform - float rotationQuaternion[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; - float translation[3] = { 0.0f, 0.0f, 0.0f }; - float scale[3] = { 1.0f, 1.0f, 1.0f }; + float rotationQuaternion[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + float translation[3] = {0.0f, 0.0f, 0.0f}; + float scale[3] = {1.0f, 1.0f, 1.0f}; }; using glTF_Buffer = std::vector; @@ -116,8 +119,7 @@ using glTF_Buffer = std::vector; */ struct glTF { - - glTF( const std::string& filename ); + glTF(const std::string& filename); ~glTF() = default; std::vector GetMeshes() const; @@ -140,39 +142,37 @@ struct glTF * Returns a copy of attribute buffer * @return */ - std::vector GetMeshAttributeBuffer( const glTF_Mesh& mesh, const std::vector& attrTypes ); - uint32_t GetMeshAttributeCount( const glTF_Mesh* mesh ) const; - const glTF_Mesh* FindMeshByName( const std::string& name ) const; + std::vector GetMeshAttributeBuffer(const glTF_Mesh& mesh, const std::vector& attrTypes); + uint32_t GetMeshAttributeCount(const glTF_Mesh* mesh) const; + const glTF_Mesh* FindMeshByName(const std::string& name) const; /** * Returns a copy of index buffer * @return */ - std::vector GetMeshIndexBuffer( const glTF_Mesh* mesh ) const; + std::vector GetMeshIndexBuffer(const glTF_Mesh* mesh) const; - const glTF_Node* FindNodeByName( const std::string& name ) const; + const glTF_Node* FindNodeByName(const std::string& name) const; private: + void LoadFromFile(const std::string& filename); - void LoadFromFile( const std::string& filename ); - - glTF_Buffer LoadFile( const std::string& filename ); + glTF_Buffer LoadFile(const std::string& filename); bool ParseJSON(); - std::vector mMeshes; - std::vector mCameras; - std::vector mBufferViews; - std::vector mAccessors; - std::vector mNodes; - std::vector mMaterials; - std::vector mTextures; - glTF_Buffer mBuffer; - glTF_Buffer jsonBuffer; + std::vector mMeshes; + std::vector mCameras; + std::vector mBufferViews; + std::vector mAccessors; + std::vector mNodes; + std::vector mMaterials; + std::vector mTextures; + glTF_Buffer mBuffer; + glTF_Buffer jsonBuffer; // json nodes picojson::value jsonNode; }; - #endif //DALI_CMAKE_GLTF_SCENE_H diff --git a/examples/reflection-demo/pico-json.h b/examples/reflection-demo/pico-json.h index e4f28e9..e54263d 100644 --- a/examples/reflection-demo/pico-json.h +++ b/examples/reflection-demo/pico-json.h @@ -29,77 +29,83 @@ #define picojson_h #include +#include #include #include #include -#include #include #include #include #include #include #include -#include #include +#include // for isnan/isinf -#if __cplusplus>=201103L -# include +#if __cplusplus >= 201103L +#include +#else +extern "C" +{ +#ifdef _MSC_VER +#include +#elif defined(__INTEL_COMPILER) +#include #else -extern "C" { -# ifdef _MSC_VER -# include -# elif defined(__INTEL_COMPILER) -# include -# else -# include -# endif +#include +#endif } #endif #ifndef PICOJSON_USE_RVALUE_REFERENCE -# if (defined(__cpp_rvalue_references) && __cpp_rvalue_references >= 200610) || (defined(_MSC_VER) && _MSC_VER >= 1600) -# define PICOJSON_USE_RVALUE_REFERENCE 1 -# else -# define PICOJSON_USE_RVALUE_REFERENCE 0 -# endif -#endif//PICOJSON_USE_RVALUE_REFERENCE - +#if(defined(__cpp_rvalue_references) && __cpp_rvalue_references >= 200610) || (defined(_MSC_VER) && _MSC_VER >= 1600) +#define PICOJSON_USE_RVALUE_REFERENCE 1 +#else +#define PICOJSON_USE_RVALUE_REFERENCE 0 +#endif +#endif //PICOJSON_USE_RVALUE_REFERENCE // experimental support for int64_t (see README.mkdn for detail) #ifdef PICOJSON_USE_INT64 -# define __STDC_FORMAT_MACROS -# include -# include +#define __STDC_FORMAT_MACROS +#include +#include #endif // to disable the use of localeconv(3), set PICOJSON_USE_LOCALE to 0 #ifndef PICOJSON_USE_LOCALE -# define PICOJSON_USE_LOCALE 1 +#define PICOJSON_USE_LOCALE 1 #endif #if PICOJSON_USE_LOCALE -extern "C" { -# include +extern "C" +{ +#include } #endif #ifndef PICOJSON_ASSERT -# define PICOJSON_ASSERT(e) do { if (! (e)) throw std::runtime_error(#e); } while (0) +#define PICOJSON_ASSERT(e) \ + do \ + { \ + if(!(e)) throw std::runtime_error(#e); \ + } while(0) #endif #ifdef _MSC_VER #define SNPRINTF _snprintf_s - #pragma warning(push) - #pragma warning(disable : 4244) // conversion from int to char - #pragma warning(disable : 4127) // conditional expression is constant - #pragma warning(disable : 4702) // unreachable code +#pragma warning(push) +#pragma warning(disable : 4244) // conversion from int to char +#pragma warning(disable : 4127) // conditional expression is constant +#pragma warning(disable : 4702) // unreachable code #else #define SNPRINTF snprintf #endif -namespace picojson { - -enum { +namespace picojson +{ +enum +{ null_type, boolean_type, number_type, @@ -107,33 +113,41 @@ enum { array_type, object_type #ifdef PICOJSON_USE_INT64 - , int64_type + , + int64_type #endif }; -enum { +enum +{ INDENT_WIDTH = 2 }; -struct null {}; +struct null +{ +}; -class value { +class value +{ public: - typedef std::vector array; + typedef std::vector array; typedef std::map object; - union _storage { - bool boolean_; + union _storage + { + bool boolean_; double number_; #ifdef PICOJSON_USE_INT64 int64_t int64_; #endif std::string* string_; - array* array_; - object* object_; + array* array_; + object* object_; }; + protected: - int type_{}; - _storage u_ {}; + int type_{}; + _storage u_{}; + public: value(); value(int type, bool); @@ -151,44 +165,63 @@ public: value(const value& x); value& operator=(const value& x); #if PICOJSON_USE_RVALUE_REFERENCE - value(value&& x)throw(); - value& operator=(value&& x)throw(); + value(value&& x) throw(); + value& operator=(value&& x) throw(); #endif - void swap(value& x)throw(); - template bool is() const; - template const T& get() const; - template T& get(); - template void set(const T &); + void swap(value& x) throw(); + template + bool is() const; + template + const T& get() const; + template + T& get(); + template + void set(const T&); #if PICOJSON_USE_RVALUE_REFERENCE - template void set(T &&); + template + void set(T&&); #endif - bool evaluate_as_boolean() const; + bool evaluate_as_boolean() const; const value& get(size_t idx) const; const value& get(const std::string& key) const; - value& get(size_t idx); - value& get(const std::string& key); + value& get(size_t idx); + value& get(const std::string& key); - bool contains(size_t idx) const; - bool contains(const std::string& key) const; + bool contains(size_t idx) const; + bool contains(const std::string& key) const; std::string to_str() const; - template void serialize(Iter os, bool prettify = false) const; + template + void serialize(Iter os, bool prettify = false) const; std::string serialize(bool prettify = false) const; + private: - template value(const T*); // intentionally defined to block implicit conversion of pointer to bool - template static void _indent(Iter os, int indent); - template void _serialize(Iter os, int indent) const; + template + value(const T*); // intentionally defined to block implicit conversion of pointer to bool + template + static void _indent(Iter os, int indent); + template + void _serialize(Iter os, int indent) const; std::string _serialize(int indent) const; - void clear(); + void clear(); }; -typedef value::array array; +typedef value::array array; typedef value::object object; -inline value::value() : type_(null_type) {} +inline value::value() +: type_(null_type) +{ +} -inline value::value(int type, bool) : type_(type) { - switch (type) { -#define INIT(p, v) case p##type: u_.p = v; break +inline value::value(int type, bool) +: type_(type) +{ + switch(type) + { +#define INIT(p, v) \ + case p##type: \ + u_.p = v; \ + break INIT(boolean_, false); INIT(number_, 0.0); #ifdef PICOJSON_USE_INT64 @@ -198,73 +231,104 @@ inline value::value(int type, bool) : type_(type) { INIT(array_, new array()); INIT(object_, new object()); #undef INIT - default: break; + default: + break; } } -inline value::value(bool b) : type_(boolean_type) { +inline value::value(bool b) +: type_(boolean_type) +{ u_.boolean_ = b; } #ifdef PICOJSON_USE_INT64 -inline value::value(int64_t i) : type_(int64_type) { - u_.int64_ = i; - } +inline value::value(int64_t i) +: type_(int64_type) +{ + u_.int64_ = i; +} #endif -inline value::value(double n) : type_(number_type) { - if ( +inline value::value(double n) +: type_(number_type) +{ + if( #ifdef _MSC_VER -! _finite(n) -#elif __cplusplus>=201103L || !(defined(isnan) && defined(isinf)) -std::isnan(n) || std::isinf(n) + !_finite(n) +#elif __cplusplus >= 201103L || !(defined(isnan) && defined(isinf)) + std::isnan(n) || std::isinf(n) #else isnan(n) || isinf(n) #endif - ) { + ) + { throw std::overflow_error(""); } u_.number_ = n; } -inline value::value(const std::string& s) : type_(string_type) { +inline value::value(const std::string& s) +: type_(string_type) +{ u_.string_ = new std::string(s); } -inline value::value(const array& a) : type_(array_type) { +inline value::value(const array& a) +: type_(array_type) +{ u_.array_ = new array(a); } -inline value::value(const object& o) : type_(object_type) { +inline value::value(const object& o) +: type_(object_type) +{ u_.object_ = new object(o); } -inline value::value(const char* s) : type_(string_type) { +inline value::value(const char* s) +: type_(string_type) +{ u_.string_ = new std::string(s); } -inline value::value(const char* s, size_t len) : type_(string_type) { +inline value::value(const char* s, size_t len) +: type_(string_type) +{ u_.string_ = new std::string(s, len); } -inline void value::clear() { - switch (type_) { -#define DEINIT(p) case p##type: delete u_.p; break +inline void value::clear() +{ + switch(type_) + { +#define DEINIT(p) \ + case p##type: \ + delete u_.p; \ + break DEINIT(string_); DEINIT(array_); DEINIT(object_); #undef DEINIT - default: break; + default: + break; } } -inline value::~value() { +inline value::~value() +{ clear(); } -inline value::value(const value& x) : type_(x.type_) { - switch (type_) { -#define INIT(p, v) case p##type: u_.p = v; break +inline value::value(const value& x) +: type_(x.type_) +{ + switch(type_) + { +#define INIT(p, v) \ + case p##type: \ + u_.p = v; \ + break INIT(string_, new std::string(*x.u_.string_)); INIT(array_, new array(*x.u_.array_)); INIT(object_, new object(*x.u_.object_)); @@ -275,8 +339,10 @@ inline value::value(const value& x) : type_(x.type_) { } } -inline value& value::operator=(const value& x) { - if (this != &x) { +inline value& value::operator=(const value& x) +{ + if(this != &x) + { value t(x); swap(t); } @@ -284,22 +350,28 @@ inline value& value::operator=(const value& x) { } #if PICOJSON_USE_RVALUE_REFERENCE -inline value::value(value&& x)throw() : type_(null_type) { +inline value::value(value&& x) throw() +: type_(null_type) +{ swap(x); } -inline value& value::operator=(value&& x)throw() { +inline value& value::operator=(value&& x) throw() +{ swap(x); return *this; } #endif -inline void value::swap(value& x)throw() { +inline void value::swap(value& x) throw() +{ std::swap(type_, x.type_); std::swap(u_, x.u_); } -#define IS(ctype, jtype) \ - template <> inline bool value::is() const { \ - return type_ == jtype##_type; \ +#define IS(ctype, jtype) \ + template<> \ + inline bool value::is() const \ + { \ + return type_ == jtype##_type; \ } IS(null, null) IS(bool, boolean) @@ -310,24 +382,28 @@ IS(std::string, string) IS(array, array) IS(object, object) #undef IS -template <> inline bool value::is() const { +template<> +inline bool value::is() const +{ return type_ == number_type #ifdef PICOJSON_USE_INT64 - || type_ == int64_type + || type_ == int64_type #endif ; } -#define GET(ctype, var) \ - template <> inline const ctype& value::get() const { \ - PICOJSON_ASSERT("type mismatch! call is() before get()" \ - && is()); \ - return var; \ - } \ - template <> inline ctype& value::get() { \ - PICOJSON_ASSERT("type mismatch! call is() before get()" \ - && is()); \ - return var; \ +#define GET(ctype, var) \ + template<> \ + inline const ctype& value::get() const \ + { \ + PICOJSON_ASSERT("type mismatch! call is() before get()" && is()); \ + return var; \ + } \ + template<> \ + inline ctype& value::get() \ + { \ + PICOJSON_ASSERT("type mismatch! call is() before get()" && is()); \ + return var; \ } GET(bool, u_.boolean_) GET(std::string, *u_.string_) @@ -335,17 +411,19 @@ GET(array, *u_.array_) GET(object, *u_.object_) #ifdef PICOJSON_USE_INT64 GET(double, (type_ == int64_type && (const_cast(this)->type_ = number_type, const_cast(this)->u_.number_ = u_.int64_), u_.number_)) - GET(int64_t, u_.int64_) +GET(int64_t, u_.int64_) #else GET(double, u_.number_) #endif #undef GET -#define SET(ctype, jtype, setter) \ - template <> inline void value::set(const ctype &_val) { \ - clear(); \ - type_ = jtype##_type; \ - setter \ +#define SET(ctype, jtype, setter) \ + template<> \ + inline void value::set(const ctype& _val) \ + { \ + clear(); \ + type_ = jtype##_type; \ + setter \ } SET(bool, boolean, u_.boolean_ = _val;) SET(std::string, string, u_.string_ = new std::string(_val);) @@ -358,11 +436,13 @@ SET(int64_t, int64, u_.int64_ = _val;) #undef SET #if PICOJSON_USE_RVALUE_REFERENCE -#define MOVESET(ctype, jtype, setter) \ - template <> inline void value::set(ctype &&_val) { \ - clear(); \ - type_ = jtype##_type; \ - setter \ +#define MOVESET(ctype, jtype, setter) \ + template<> \ + inline void value::set(ctype && _val) \ + { \ + clear(); \ + type_ = jtype##_type; \ + setter \ } MOVESET(std::string, string, u_.string_ = new std::string(std::move(_val));) MOVESET(array, array, u_.array_ = new array(std::move(_val));) @@ -370,8 +450,10 @@ MOVESET(object, object, u_.object_ = new object(std::move(_val));) #undef MOVESET #endif -inline bool value::evaluate_as_boolean() const { - switch (type_) { +inline bool value::evaluate_as_boolean() const +{ + switch(type_) + { case null_type: return false; case boolean_type: @@ -383,70 +465,85 @@ inline bool value::evaluate_as_boolean() const { return u_.int64_ != 0; #endif case string_type: - return ! u_.string_->empty(); + return !u_.string_->empty(); default: return true; } } -inline const value& value::get(size_t idx) const { +inline const value& value::get(size_t idx) const +{ static value s_null; PICOJSON_ASSERT(is()); return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; } -inline value& value::get(size_t idx) { +inline value& value::get(size_t idx) +{ static value s_null; PICOJSON_ASSERT(is()); return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null; } -inline const value& value::get(const std::string& key) const { +inline const value& value::get(const std::string& key) const +{ static value s_null; PICOJSON_ASSERT(is()); object::const_iterator i = u_.object_->find(key); return i != u_.object_->end() ? i->second : s_null; } -inline value& value::get(const std::string& key) { +inline value& value::get(const std::string& key) +{ static value s_null; PICOJSON_ASSERT(is()); object::iterator i = u_.object_->find(key); return i != u_.object_->end() ? i->second : s_null; } -inline bool value::contains(size_t idx) const { +inline bool value::contains(size_t idx) const +{ PICOJSON_ASSERT(is()); return idx < u_.array_->size(); } -inline bool value::contains(const std::string& key) const { +inline bool value::contains(const std::string& key) const +{ PICOJSON_ASSERT(is()); object::const_iterator i = u_.object_->find(key); return i != u_.object_->end(); } -inline std::string value::to_str() const { - switch (type_) { - case null_type: return "null"; - case boolean_type: return u_.boolean_ ? "true" : "false"; +inline std::string value::to_str() const +{ + switch(type_) + { + case null_type: + return "null"; + case boolean_type: + return u_.boolean_ ? "true" : "false"; #ifdef PICOJSON_USE_INT64 - case int64_type: { + case int64_type: + { char buf[sizeof("-9223372036854775808")]; SNPRINTF(buf, sizeof(buf), "%" PRId64, u_.int64_); return buf; } #endif - case number_type: { - char buf[256]; + case number_type: + { + char buf[256]; double tmp; SNPRINTF(buf, sizeof(buf), fabs(u_.number_) < (1ULL << 53) && modf(u_.number_, &tmp) == 0 ? "%.f" : "%.17g", u_.number_); #if PICOJSON_USE_LOCALE - char *decimal_point = localeconv()->decimal_point; - if (strcmp(decimal_point, ".") != 0) { + char* decimal_point = localeconv()->decimal_point; + if(strcmp(decimal_point, ".") != 0) + { size_t decimal_point_len = strlen(decimal_point); - for (char *p = buf; *p != '\0'; ++p) { - if (strncmp(p, decimal_point, decimal_point_len) == 0) { + for(char* p = buf; *p != '\0'; ++p) + { + if(strncmp(p, decimal_point, decimal_point_len) == 0) + { return std::string(buf, p) + "." + (p + decimal_point_len); } } @@ -454,10 +551,14 @@ inline std::string value::to_str() const { #endif return buf; } - case string_type: return *u_.string_; - case array_type: return "array"; - case object_type: return "object"; - default: PICOJSON_ASSERT(0); + case string_type: + return *u_.string_; + case array_type: + return "array"; + case object_type: + return "object"; + default: + PICOJSON_ASSERT(0); #ifdef _MSC_VER __assume(0); #endif @@ -465,16 +566,24 @@ inline std::string value::to_str() const { return std::string(); } -template void copy(const std::string& s, Iter oi) { +template +void copy(const std::string& s, Iter oi) +{ std::copy(s.begin(), s.end(), oi); } -template -struct serialize_str_char { +template +struct serialize_str_char +{ Iter oi; - void operator()(char c) { - switch (c) { -#define MAP(val, sym) case val: copy(sym, oi); break + void operator()(char c) + { + switch(c) + { +#define MAP(val, sym) \ + case val: \ + copy(sym, oi); \ + break MAP('"', "\\\""); MAP('\\', "\\\\"); MAP('/', "\\/"); @@ -485,11 +594,14 @@ struct serialize_str_char { MAP('\t', "\\t"); #undef MAP default: - if (static_cast(c) < 0x20 || c == 0x7f) { + if(static_cast(c) < 0x20 || c == 0x7f) + { char buf[7]; SNPRINTF(buf, sizeof(buf), "\\u%04x", c & 0xff); copy(buf, buf + 6, oi); - } else { + } + else + { *oi++ = c; } break; @@ -497,82 +609,108 @@ struct serialize_str_char { } }; -template void serialize_str(const std::string& s, Iter oi) { - *oi++ = '"'; - serialize_str_char process_char = { oi }; +template +void serialize_str(const std::string& s, Iter oi) +{ + *oi++ = '"'; + serialize_str_char process_char = {oi}; std::for_each(s.begin(), s.end(), process_char); *oi++ = '"'; } -template void value::serialize(Iter oi, bool prettify) const { +template +void value::serialize(Iter oi, bool prettify) const +{ return _serialize(oi, prettify ? 0 : -1); } -inline std::string value::serialize(bool prettify) const { +inline std::string value::serialize(bool prettify) const +{ return _serialize(prettify ? 0 : -1); } -template void value::_indent(Iter oi, int indent) { +template +void value::_indent(Iter oi, int indent) +{ *oi++ = '\n'; - for (int i = 0; i < indent * INDENT_WIDTH; ++i) { + for(int i = 0; i < indent * INDENT_WIDTH; ++i) + { *oi++ = ' '; } } -template void value::_serialize(Iter oi, int indent) const { - switch (type_) { +template +void value::_serialize(Iter oi, int indent) const +{ + switch(type_) + { case string_type: serialize_str(*u_.string_, oi); break; - case array_type: { + case array_type: + { *oi++ = '['; - if (indent != -1) { + if(indent != -1) + { ++indent; } - for (array::const_iterator i = u_.array_->begin(); - i != u_.array_->end(); - ++i) { - if (i != u_.array_->begin()) { + for(array::const_iterator i = u_.array_->begin(); + i != u_.array_->end(); + ++i) + { + if(i != u_.array_->begin()) + { *oi++ = ','; } - if (indent != -1) { + if(indent != -1) + { _indent(oi, indent); } i->_serialize(oi, indent); } - if (indent != -1) { + if(indent != -1) + { --indent; - if (! u_.array_->empty()) { + if(!u_.array_->empty()) + { _indent(oi, indent); } } *oi++ = ']'; break; } - case object_type: { + case object_type: + { *oi++ = '{'; - if (indent != -1) { + if(indent != -1) + { ++indent; } - for (object::const_iterator i = u_.object_->begin(); - i != u_.object_->end(); - ++i) { - if (i != u_.object_->begin()) { + for(object::const_iterator i = u_.object_->begin(); + i != u_.object_->end(); + ++i) + { + if(i != u_.object_->begin()) + { *oi++ = ','; } - if (indent != -1) { + if(indent != -1) + { _indent(oi, indent); } serialize_str(i->first, oi); *oi++ = ':'; - if (indent != -1) { + if(indent != -1) + { *oi++ = ' '; } i->second._serialize(oi, indent); } - if (indent != -1) { + if(indent != -1) + { --indent; - if (! u_.object_->empty()) { + if(!u_.object_->empty()) + { _indent(oi, indent); } } @@ -583,72 +721,101 @@ template void value::_serialize(Iter oi, int indent) const { copy(to_str(), oi); break; } - if (indent == 0) { + if(indent == 0) + { *oi++ = '\n'; } } -inline std::string value::_serialize(int indent) const { +inline std::string value::_serialize(int indent) const +{ std::string s; _serialize(std::back_inserter(s), indent); return s; } -template class input { +template +class input +{ protected: Iter cur_, end_; bool consumed_; - int line_; + int line_; + public: - input(const Iter& first, const Iter& last) : cur_(first), end_(last), consumed_(false), line_(1) {} - int getc() { - if (consumed_) { - if (*cur_ == '\n') { + input(const Iter& first, const Iter& last) + : cur_(first), + end_(last), + consumed_(false), + line_(1) + { + } + int getc() + { + if(consumed_) + { + if(*cur_ == '\n') + { ++line_; } ++cur_; } - if (cur_ == end_) { + if(cur_ == end_) + { consumed_ = false; return -1; } consumed_ = true; return *cur_ & 0xff; } - void ungetc() { + void ungetc() + { consumed_ = false; } - Iter cur() const { - if (consumed_) { - input *self = const_cast*>(this); - self->consumed_ = false; + Iter cur() const + { + if(consumed_) + { + input* self = const_cast*>(this); + self->consumed_ = false; ++self->cur_; } return cur_; } - int line() const { return line_; } - void skip_ws() { - while (1) { + int line() const + { + return line_; + } + void skip_ws() + { + while(1) + { int ch = getc(); - if (! (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) { + if(!(ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) + { ungetc(); break; } } } - bool expect(int expect) { + bool expect(int expect) + { skip_ws(); - if (getc() != expect) { + if(getc() != expect) + { ungetc(); return false; } return true; } - bool match(const std::string& pattern) { - for (std::string::const_iterator pi(pattern.begin()); - pi != pattern.end(); - ++pi) { - if (getc() != *pi) { + bool match(const std::string& pattern) + { + for(std::string::const_iterator pi(pattern.begin()); + pi != pattern.end(); + ++pi) + { + if(getc() != *pi) + { ungetc(); return false; } @@ -657,19 +824,30 @@ public: } }; -template inline int _parse_quadhex(input &in) { +template +inline int _parse_quadhex(input& in) +{ int uni_ch = 0, hex; - for (int i = 0; i < 4; i++) { - if ((hex = in.getc()) == -1) { + for(int i = 0; i < 4; i++) + { + if((hex = in.getc()) == -1) + { return -1; } - if ('0' <= hex && hex <= '9') { + if('0' <= hex && hex <= '9') + { hex -= '0'; - } else if ('A' <= hex && hex <= 'F') { + } + else if('A' <= hex && hex <= 'F') + { hex -= 'A' - 0xa; - } else if ('a' <= hex && hex <= 'f') { + } + else if('a' <= hex && hex <= 'f') + { hex -= 'a' - 0xa; - } else { + } + else + { in.ungetc(); return -1; } @@ -678,37 +856,53 @@ template inline int _parse_quadhex(input &in) { return uni_ch; } -template inline bool _parse_codepoint(String& out, input& in) { +template +inline bool _parse_codepoint(String& out, input& in) +{ int uni_ch; - if ((uni_ch = _parse_quadhex(in)) == -1) { + if((uni_ch = _parse_quadhex(in)) == -1) + { return false; } - if (0xd800 <= uni_ch && uni_ch <= 0xdfff) { - if (0xdc00 <= uni_ch) { + if(0xd800 <= uni_ch && uni_ch <= 0xdfff) + { + if(0xdc00 <= uni_ch) + { // a second 16-bit of a surrogate pair appeared return false; } // first 16-bit of surrogate pair, get the next one - if (in.getc() != '\\' || in.getc() != 'u') { + if(in.getc() != '\\' || in.getc() != 'u') + { in.ungetc(); return false; } int second = _parse_quadhex(in); - if (! (0xdc00 <= second && second <= 0xdfff)) { + if(!(0xdc00 <= second && second <= 0xdfff)) + { return false; } uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff); uni_ch += 0x10000; } - if (uni_ch < 0x80) { + if(uni_ch < 0x80) + { out.push_back(uni_ch); - } else { - if (uni_ch < 0x800) { + } + else + { + if(uni_ch < 0x800) + { out.push_back(0xc0 | (uni_ch >> 6)); - } else { - if (uni_ch < 0x10000) { + } + else + { + if(uni_ch < 0x10000) + { out.push_back(0xe0 | (uni_ch >> 12)); - } else { + } + else + { out.push_back(0xf0 | (uni_ch >> 18)); out.push_back(0x80 | ((uni_ch >> 12) & 0x3f)); } @@ -719,20 +913,33 @@ template inline bool _parse_codepoint(String& ou return true; } -template inline bool _parse_string(String& out, input& in) { - while (1) { +template +inline bool _parse_string(String& out, input& in) +{ + while(1) + { int ch = in.getc(); - if (ch < ' ') { + if(ch < ' ') + { in.ungetc(); return false; - } else if (ch == '"') { + } + else if(ch == '"') + { return true; - } else if (ch == '\\') { - if ((ch = in.getc()) == -1) { + } + else if(ch == '\\') + { + if((ch = in.getc()) == -1) + { return false; } - switch (ch) { -#define MAP(sym, val) case sym: out.push_back(val); break + switch(ch) + { +#define MAP(sym, val) \ + case sym: \ + out.push_back(val); \ + break MAP('"', '\"'); MAP('\\', '\\'); MAP('/', '/'); @@ -743,72 +950,93 @@ template inline bool _parse_string(String& out, MAP('t', '\t'); #undef MAP case 'u': - if (! _parse_codepoint(out, in)) { + if(!_parse_codepoint(out, in)) + { return false; } break; default: return false; } - } else { + } + else + { out.push_back(ch); } } return false; } -template inline bool _parse_array(Context& ctx, input& in) { - if (! ctx.parse_array_start()) { +template +inline bool _parse_array(Context& ctx, input& in) +{ + if(!ctx.parse_array_start()) + { return false; } size_t idx = 0; - if (in.expect(']')) { + if(in.expect(']')) + { return ctx.parse_array_stop(idx); } - do { - if (! ctx.parse_array_item(in, idx)) { + do + { + if(!ctx.parse_array_item(in, idx)) + { return false; } idx++; - } while (in.expect(',')); + } while(in.expect(',')); return in.expect(']') && ctx.parse_array_stop(idx); } -template inline bool _parse_object(Context& ctx, input& in) { - if (! ctx.parse_object_start()) { +template +inline bool _parse_object(Context& ctx, input& in) +{ + if(!ctx.parse_object_start()) + { return false; } - if (in.expect('}')) { + if(in.expect('}')) + { return true; } - do { + do + { std::string key; - if (! in.expect('"') - || ! _parse_string(key, in) - || ! in.expect(':')) { + if(!in.expect('"') || !_parse_string(key, in) || !in.expect(':')) + { return false; } - if (! ctx.parse_object_item(in, key)) { + if(!ctx.parse_object_item(in, key)) + { return false; } - } while (in.expect(',')); + } while(in.expect(',')); return in.expect('}'); } -template inline std::string _parse_number(input& in) { +template +inline std::string _parse_number(input& in) +{ std::string num_str; - while (1) { + while(1) + { int ch = in.getc(); - if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' - || ch == 'e' || ch == 'E') { + if(('0' <= ch && ch <= '9') || ch == '+' || ch == '-' || ch == 'e' || ch == 'E') + { num_str.push_back(ch); - } else if (ch == '.') { + } + else if(ch == '.') + { #if PICOJSON_USE_LOCALE num_str += localeconv()->decimal_point; #else num_str.push_back('.'); #endif - } else { + } + else + { in.ungetc(); break; } @@ -816,16 +1044,23 @@ template inline std::string _parse_number(input& in) { return num_str; } -template inline bool _parse(Context& ctx, input& in) { +template +inline bool _parse(Context& ctx, input& in) +{ in.skip_ws(); int ch = in.getc(); - switch (ch) { -#define IS(ch, text, op) case ch: \ - if (in.match(text) && op) { \ - return true; \ - } else { \ - return false; \ - } + switch(ch) + { +#define IS(ch, text, op) \ + case ch: \ + if(in.match(text) && op) \ + { \ + return true; \ + } \ + else \ + { \ + return false; \ + } IS('n', "ull", ctx.set_null()); IS('f', "alse", ctx.set_bool(false)); IS('t', "rue", ctx.set_bool(true)); @@ -837,29 +1072,30 @@ template inline bool _parse(Context& ctx, inpu case '{': return _parse_object(ctx, in); default: - if (('0' <= ch && ch <= '9') || ch == '-') { + if(('0' <= ch && ch <= '9') || ch == '-') + { double f; - char *endp; + char* endp; in.ungetc(); std::string num_str = _parse_number(in); - if (num_str.empty()) { + if(num_str.empty()) + { return false; } #ifdef PICOJSON_USE_INT64 { - errno = 0; + errno = 0; intmax_t ival = strtoimax(num_str.c_str(), &endp, 10); - if (errno == 0 - && std::numeric_limits::min() <= ival - && ival <= std::numeric_limits::max() - && endp == num_str.c_str() + num_str.size()) { + if(errno == 0 && std::numeric_limits::min() <= ival && ival <= std::numeric_limits::max() && endp == num_str.c_str() + num_str.size()) + { ctx.set_int64(ival); return true; } } #endif f = strtod(num_str.c_str(), &endp); - if (endp == num_str.c_str() + num_str.size()) { + if(endp == num_str.c_str() + num_str.size()) + { ctx.set_number(f); return true; } @@ -871,127 +1107,222 @@ template inline bool _parse(Context& ctx, inpu return false; } -class deny_parse_context { +class deny_parse_context +{ public: - bool set_null() { return false; } - bool set_bool(bool) { return false; } + bool set_null() + { + return false; + } + bool set_bool(bool) + { + return false; + } #ifdef PICOJSON_USE_INT64 - bool set_int64(int64_t) { return false; } + bool set_int64(int64_t) + { + return false; + } #endif - bool set_number(double) { return false; } - template bool parse_string(input&) { return false; } - bool parse_array_start() { return false; } - template bool parse_array_item(input&, size_t) { + bool set_number(double) + { + return false; + } + template + bool parse_string(input&) + { + return false; + } + bool parse_array_start() + { return false; } - bool parse_array_stop(size_t) { return false; } - bool parse_object_start() { return false; } - template bool parse_object_item(input&, const std::string&) { + template + bool parse_array_item(input&, size_t) + { + return false; + } + bool parse_array_stop(size_t) + { + return false; + } + bool parse_object_start() + { + return false; + } + template + bool parse_object_item(input&, const std::string&) + { return false; } }; -class default_parse_context { +class default_parse_context +{ protected: value* out_; + public: - default_parse_context(value* out) : out_(out) {} - bool set_null() { + default_parse_context(value* out) + : out_(out) + { + } + bool set_null() + { *out_ = value(); return true; } - bool set_bool(bool b) { + bool set_bool(bool b) + { *out_ = value(b); return true; } #ifdef PICOJSON_USE_INT64 - bool set_int64(int64_t i) { - *out_ = value(i); - return true; - } + bool set_int64(int64_t i) + { + *out_ = value(i); + return true; + } #endif - bool set_number(double f) { + bool set_number(double f) + { *out_ = value(f); return true; } - template bool parse_string(input& in) { + template + bool parse_string(input& in) + { *out_ = value(string_type, false); return _parse_string(out_->get(), in); } - bool parse_array_start() { + bool parse_array_start() + { *out_ = value(array_type, false); return true; } - template bool parse_array_item(input& in, size_t) { + template + bool parse_array_item(input& in, size_t) + { array& a = out_->get(); a.push_back(value()); default_parse_context ctx(&a.back()); return _parse(ctx, in); } - bool parse_array_stop(size_t) { return true; } - bool parse_object_start() { + bool parse_array_stop(size_t) + { + return true; + } + bool parse_object_start() + { *out_ = value(object_type, false); return true; } - template bool parse_object_item(input& in, const std::string& key) { - object& o = out_->get(); + template + bool parse_object_item(input& in, const std::string& key) + { + object& o = out_->get(); default_parse_context ctx(&o[key]); return _parse(ctx, in); } + private: default_parse_context(const default_parse_context&); default_parse_context& operator=(const default_parse_context&); }; -class null_parse_context { +class null_parse_context +{ public: - struct dummy_str { - void push_back(int) {} + struct dummy_str + { + void push_back(int) + { + } }; + public: - null_parse_context() {} - bool set_null() { return true; } - bool set_bool(bool) { return true; } + null_parse_context() + { + } + bool set_null() + { + return true; + } + bool set_bool(bool) + { + return true; + } #ifdef PICOJSON_USE_INT64 - bool set_int64(int64_t) { return true; } + bool set_int64(int64_t) + { + return true; + } #endif - bool set_number(double) { return true; } - template bool parse_string(input& in) { + bool set_number(double) + { + return true; + } + template + bool parse_string(input& in) + { dummy_str s; return _parse_string(s, in); } - bool parse_array_start() { return true; } - template bool parse_array_item(input& in, size_t) { + bool parse_array_start() + { + return true; + } + template + bool parse_array_item(input& in, size_t) + { return _parse(*this, in); } - bool parse_array_stop(size_t) { return true; } - bool parse_object_start() { return true; } - template bool parse_object_item(input& in, const std::string&) { + bool parse_array_stop(size_t) + { + return true; + } + bool parse_object_start() + { + return true; + } + template + bool parse_object_item(input& in, const std::string&) + { return _parse(*this, in); } + private: null_parse_context(const null_parse_context&); null_parse_context& operator=(const null_parse_context&); }; // obsolete, use the version below -template inline std::string parse(value& out, Iter& pos, const Iter& last) { +template +inline std::string parse(value& out, Iter& pos, const Iter& last) +{ std::string err; pos = parse(out, pos, last, &err); return err; } -template inline Iter _parse(Context& ctx, const Iter& first, const Iter& last, std::string* err) { +template +inline Iter _parse(Context& ctx, const Iter& first, const Iter& last, std::string* err) +{ input in(first, last); - if (! _parse(ctx, in) && err != NULL) { + if(!_parse(ctx, in) && err != NULL) + { char buf[64]; SNPRINTF(buf, sizeof(buf), "syntax error at line %d near: ", in.line()); *err = buf; - while (1) { + while(1) + { int ch = in.getc(); - if (ch == -1 || ch == '\n') { + if(ch == -1 || ch == '\n') + { break; - } else if (ch >= ' ') { + } + else if(ch >= ' ') + { err->push_back(ch); } } @@ -999,43 +1330,52 @@ template inline Iter _parse(Context& ctx, cons return in.cur(); } -template inline Iter parse(value& out, const Iter& first, const Iter& last, std::string* err) { +template +inline Iter parse(value& out, const Iter& first, const Iter& last, std::string* err) +{ default_parse_context ctx(&out); return _parse(ctx, first, last, err); } -inline std::string parse(value& out, const std::string& s) { +inline std::string parse(value& out, const std::string& s) +{ std::string err; parse(out, s.begin(), s.end(), &err); return err; } -inline std::string parse(value& out, std::istream& is) { +inline std::string parse(value& out, std::istream& is) +{ std::string err; - parse(out, std::istreambuf_iterator(is.rdbuf()), - std::istreambuf_iterator(), &err); + parse(out, std::istreambuf_iterator(is.rdbuf()), std::istreambuf_iterator(), &err); return err; } -template struct last_error_t { +template +struct last_error_t +{ static std::string s; }; -template std::string last_error_t::s; +template +std::string last_error_t::s; -inline void set_last_error(const std::string& s) { +inline void set_last_error(const std::string& s) +{ last_error_t::s = s; } -inline const std::string& get_last_error() { +inline const std::string& get_last_error() +{ return last_error_t::s; } -inline bool operator==(const value& x, const value& y) { - if (x.is()) +inline bool operator==(const value& x, const value& y) +{ + if(x.is()) return y.is(); -#define PICOJSON_CMP(type) \ - if (x.is()) \ - return y.is() && x.get() == y.get() +#define PICOJSON_CMP(type) \ + if(x.is()) \ + return y.is() && x.get() == y.get() PICOJSON_CMP(bool); PICOJSON_CMP(double); PICOJSON_CMP(std::string); @@ -1049,25 +1389,29 @@ inline bool operator==(const value& x, const value& y) { return false; } -inline bool operator!=(const value& x, const value& y) { - return ! (x == y); -} +inline bool operator!=(const value& x, const value& y) +{ + return !(x == y); } +} // namespace picojson #if !PICOJSON_USE_RVALUE_REFERENCE -namespace std { - template<> inline void swap(picojson::value& x, picojson::value& y) - { - x.swap(y); - } +namespace std +{ +template<> +inline void swap(picojson::value& x, picojson::value& y) +{ + x.swap(y); } +} // namespace std #endif inline std::istream& operator>>(std::istream& is, picojson::value& x) { picojson::set_last_error(std::string()); std::string err = picojson::parse(x, is); - if (! err.empty()) { + if(!err.empty()) + { picojson::set_last_error(err); is.setstate(std::ios::failbit); } diff --git a/examples/reflection-demo/reflection-example.cpp b/examples/reflection-demo/reflection-example.cpp old mode 100755 new mode 100644 index 1f91e21..9de2407 --- a/examples/reflection-demo/reflection-example.cpp +++ b/examples/reflection-demo/reflection-example.cpp @@ -27,6 +27,7 @@ using namespace Dali; namespace { +// clang-format off const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec3 aPosition;\n @@ -160,47 +161,48 @@ const char* TEX_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( (texture2D(sTexture1, uv))) * intensity;\n }\n ); +// clang-format on struct Model { - Shader shader; - Geometry geometry; + Shader shader; + Geometry geometry; }; using ModelPtr = std::unique_ptr; -using ActorContainer = std::vector; -using CameraContainer = std::vector; -using ModelContainer = std::vector; +using ActorContainer = std::vector; +using CameraContainer = std::vector; +using ModelContainer = std::vector; using TextureSetContainer = std::vector; -const Vector3 DEFAULT_LIGHT_DIRECTION( 0.5, 0.5, -1 ); +const Vector3 DEFAULT_LIGHT_DIRECTION(0.5, 0.5, -1); template -bool LoadFile( const std::string& filename, std::vector& bytes ) +bool LoadFile(const std::string& filename, std::vector& bytes) { - Dali::FileStream fileStream( filename, Dali::FileStream::READ | Dali::FileStream::BINARY ); - FILE* fin = fileStream.GetFile(); + Dali::FileStream fileStream(filename, Dali::FileStream::READ | Dali::FileStream::BINARY); + FILE* fin = fileStream.GetFile(); - if( fin ) + if(fin) { - if( fseek( fin, 0, SEEK_END ) ) + if(fseek(fin, 0, SEEK_END)) { return false; } - bytes.resize( uint32_t(ftell( fin )) ); - std::fill( bytes.begin(), bytes.end(), 0 ); - if( fseek( fin, 0, SEEK_SET ) ) + bytes.resize(uint32_t(ftell(fin))); + std::fill(bytes.begin(), bytes.end(), 0); + if(fseek(fin, 0, SEEK_SET)) { return false; } - size_t result = fread( bytes.data(), 1, bytes.size(), fin ); - return ( result != 0 ); + size_t result = fread(bytes.data(), 1, bytes.size(), fin); + return (result != 0); } return false; } -Shader CreateShader( const std::string& vsh, const std::string& fsh ) +Shader CreateShader(const std::string& vsh, const std::string& fsh) { std::vector vshShaderSource; std::vector fshShaderSource; @@ -208,10 +210,10 @@ Shader CreateShader( const std::string& vsh, const std::string& fsh ) // VSH if(vsh[0] == '/') { - std::string vshPath( DEMO_GAME_DIR ); + std::string vshPath(DEMO_GAME_DIR); vshPath += '/'; vshPath += vsh; - LoadFile( vshPath, vshShaderSource ); + LoadFile(vshPath, vshShaderSource); } else { @@ -221,10 +223,10 @@ Shader CreateShader( const std::string& vsh, const std::string& fsh ) // FSH if(fsh[0] == '/') { - std::string fshPath( DEMO_GAME_DIR ); + std::string fshPath(DEMO_GAME_DIR); fshPath += '/'; fshPath += fsh; - LoadFile( fshPath, fshShaderSource ); + LoadFile(fshPath, fshShaderSource); } else { @@ -233,81 +235,77 @@ Shader CreateShader( const std::string& vsh, const std::string& fsh ) vshShaderSource.emplace_back(0); fshShaderSource.emplace_back(0); - return Shader::New( std::string(vshShaderSource.data()), std::string(fshShaderSource.data()) ); + return Shader::New(std::string(vshShaderSource.data()), std::string(fshShaderSource.data())); } ModelPtr CreateModel( - glTF& gltf, - const glTF_Mesh* mesh, - const std::string& vertexShaderSource, - const std::string& fragmentShaderSource ) + glTF& gltf, + const glTF_Mesh* mesh, + const std::string& vertexShaderSource, + const std::string& fragmentShaderSource) { /* * Obtain interleaved buffer for first mesh with position and normal attributes */ - auto positionBuffer = gltf.GetMeshAttributeBuffer( *mesh, - { - glTFAttributeType::POSITION, - glTFAttributeType::NORMAL, - glTFAttributeType::TEXCOORD_0 - } ); - - auto attributeCount = gltf.GetMeshAttributeCount( mesh ); + auto positionBuffer = gltf.GetMeshAttributeBuffer(*mesh, + {glTFAttributeType::POSITION, + glTFAttributeType::NORMAL, + glTFAttributeType::TEXCOORD_0}); + + auto attributeCount = gltf.GetMeshAttributeCount(mesh); /** * Create matching property buffer */ - auto vertexBuffer = VertexBuffer::New( Property::Map() - .Add("aPosition", Property::VECTOR3 ) - .Add("aNormal", Property::VECTOR3) - .Add("aTexCoord", Property::VECTOR2) - ); + auto vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3) + .Add("aNormal", Property::VECTOR3) + .Add("aTexCoord", Property::VECTOR2)); // set vertex data - vertexBuffer.SetData( positionBuffer.data(), attributeCount ); + vertexBuffer.SetData(positionBuffer.data(), attributeCount); auto geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - auto indexBuffer = gltf.GetMeshIndexBuffer( mesh ); - geometry.SetIndexBuffer( indexBuffer.data(), indexBuffer.size() ); - geometry.SetType( Geometry::Type::TRIANGLES ); - ModelPtr retval( new Model() ); - retval->shader = CreateShader( vertexShaderSource, fragmentShaderSource ); + geometry.AddVertexBuffer(vertexBuffer); + auto indexBuffer = gltf.GetMeshIndexBuffer(mesh); + geometry.SetIndexBuffer(indexBuffer.data(), indexBuffer.size()); + geometry.SetType(Geometry::Type::TRIANGLES); + ModelPtr retval(new Model()); + retval->shader = CreateShader(vertexShaderSource, fragmentShaderSource); retval->geometry = geometry; return retval; } -void ReplaceShader( Actor& actor, const std::string& vsh, const std::string& fsh ) +void ReplaceShader(Actor& actor, const std::string& vsh, const std::string& fsh) { auto renderer = actor.GetRendererAt(0); - auto shader = CreateShader(vsh, fsh); - renderer.SetShader( shader ); + auto shader = CreateShader(vsh, fsh); + renderer.SetShader(shader); } -void CreateTextureSetsFromGLTF( glTF* gltf, const std::string& basePath, TextureSetContainer& textureSets ) +void CreateTextureSetsFromGLTF(glTF* gltf, const std::string& basePath, TextureSetContainer& textureSets) { const auto& materials = gltf->GetMaterials(); - const auto& textures = gltf->GetTextures(); + const auto& textures = gltf->GetTextures(); std::map textureCache{}; - for(const auto& material : materials ) + for(const auto& material : materials) { TextureSet textureSet; if(material.pbrMetallicRoughness.enabled) { textureSet = TextureSet::New(); - std::string filename( basePath ); + std::string filename(basePath); filename += '/'; filename += textures[material.pbrMetallicRoughness.baseTextureColor.index].uri; - Dali::PixelData pixelData = Dali::Toolkit::SyncImageLoader::Load( filename ); + Dali::PixelData pixelData = Dali::Toolkit::SyncImageLoader::Load(filename); - auto cacheKey = textures[material.pbrMetallicRoughness.baseTextureColor.index].uri; - auto iter = textureCache.find(cacheKey); + auto cacheKey = textures[material.pbrMetallicRoughness.baseTextureColor.index].uri; + auto iter = textureCache.find(cacheKey); Texture texture; if(iter == textureCache.end()) { - texture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), - pixelData.GetHeight()); + texture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight()); texture.Upload(pixelData); texture.GenerateMipmaps(); textureCache[cacheKey] = texture; @@ -316,44 +314,43 @@ void CreateTextureSetsFromGLTF( glTF* gltf, const std::string& basePath, Texture { texture = iter->second; } - textureSet.SetTexture( 0, texture ); + textureSet.SetTexture(0, texture); Dali::Sampler sampler = Dali::Sampler::New(); - sampler.SetWrapMode( Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT ); - sampler.SetFilterMode( Dali::FilterMode::LINEAR_MIPMAP_LINEAR, Dali::FilterMode::LINEAR ); - textureSet.SetSampler( 0, sampler ); + sampler.SetWrapMode(Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT, Dali::WrapMode::REPEAT); + sampler.SetFilterMode(Dali::FilterMode::LINEAR_MIPMAP_LINEAR, Dali::FilterMode::LINEAR); + textureSet.SetSampler(0, sampler); } - textureSets.emplace_back( textureSet ); + textureSets.emplace_back(textureSet); } } - /** * Creates models from glTF */ -void CreateModelsFromGLTF( glTF* gltf, ModelContainer& models ) +void CreateModelsFromGLTF(glTF* gltf, ModelContainer& models) { const auto& meshes = gltf->GetMeshes(); - for( const auto& mesh : meshes ) + for(const auto& mesh : meshes) { // change shader to use texture if material indicates that if(mesh->material != 0xffffffff && gltf->GetMaterials()[mesh->material].pbrMetallicRoughness.enabled) { - models.emplace_back( CreateModel( *gltf, mesh, VERTEX_SHADER, TEXTURED_FRAGMENT_SHADER ) ); + models.emplace_back(CreateModel(*gltf, mesh, VERTEX_SHADER, TEXTURED_FRAGMENT_SHADER)); } else { - models.emplace_back( CreateModel( *gltf, mesh, VERTEX_SHADER, FRAGMENT_SHADER ) ); + models.emplace_back(CreateModel(*gltf, mesh, VERTEX_SHADER, FRAGMENT_SHADER)); } } } Actor CreateSceneFromGLTF( - Window window, - glTF* gltf, - ModelContainer& models, - ActorContainer& actors, - CameraContainer& cameras, - TextureSetContainer& textureSets ) + Window window, + glTF* gltf, + ModelContainer& models, + ActorContainer& actors, + CameraContainer& cameras, + TextureSetContainer& textureSets) { const auto& nodes = gltf->GetNodes(); @@ -361,23 +358,20 @@ Actor CreateSceneFromGLTF( // for each node create nodes and children // resolve parents later - actors.reserve( nodes.size() ); - for( const auto& node : nodes ) + actors.reserve(nodes.size()); + for(const auto& node : nodes) { - auto actor = node.cameraId != 0xffffffff ? CameraActor::New( window.GetSize() ) : Actor::New(); + auto actor = node.cameraId != 0xffffffff ? CameraActor::New(window.GetSize()) : Actor::New(); - actor.SetProperty( Actor::Property::SIZE, Vector3( 1, 1, 1 ) ); - actor.SetProperty( Dali::Actor::Property::NAME, node.name ); - actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - actor.SetProperty( Actor::Property::POSITION, Vector3( node.translation[0], node.translation[1], node.translation[2] )); - actor.SetProperty( Actor::Property::SCALE, Vector3( node.scale[0], node.scale[1], node.scale[2] ) ); - actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(node.rotationQuaternion[3], - node.rotationQuaternion[0], - node.rotationQuaternion[1], - node.rotationQuaternion[2])); + actor.SetProperty(Actor::Property::SIZE, Vector3(1, 1, 1)); + actor.SetProperty(Dali::Actor::Property::NAME, node.name); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + actor.SetProperty(Actor::Property::POSITION, Vector3(node.translation[0], node.translation[1], node.translation[2])); + actor.SetProperty(Actor::Property::SCALE, Vector3(node.scale[0], node.scale[1], node.scale[2])); + actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(node.rotationQuaternion[3], node.rotationQuaternion[0], node.rotationQuaternion[1], node.rotationQuaternion[2])); - actors.emplace_back( actor ); + actors.emplace_back(actor); // Initially add each actor to the very first one if(actors.size() > 1) @@ -388,67 +382,62 @@ Actor CreateSceneFromGLTF( // If mesh, create and add renderer if(node.meshId != 0xffffffff) { - const auto& model = models[node.meshId].get(); - auto renderer = Renderer::New( model->geometry, model->shader ); + const auto& model = models[node.meshId].get(); + auto renderer = Renderer::New(model->geometry, model->shader); // if textured, add texture set auto materialId = gltf->GetMeshes()[node.meshId]->material; - if( materialId != 0xffffffff ) + if(materialId != 0xffffffff) { - if( gltf->GetMaterials()[materialId].pbrMetallicRoughness.enabled ) + if(gltf->GetMaterials()[materialId].pbrMetallicRoughness.enabled) { - renderer.SetTextures( textureSets[materialId] ); + renderer.SetTextures(textureSets[materialId]); } } - actor.AddRenderer( renderer ); + actor.AddRenderer(renderer); } // Reset and attach main camera - if( node.cameraId != 0xffffffff ) + if(node.cameraId != 0xffffffff) { - cameraPosition = Vector3(node.translation[0], node.translation[1], node.translation[2]); - auto quatY = Quaternion( Degree(180.0f), Vector3( 0.0, 1.0, 0.0) ); - auto cameraActor = CameraActor::DownCast( actor ); - cameraActor.SetProperty( Actor::Property::ORIENTATION, Quaternion(node.rotationQuaternion[3], - node.rotationQuaternion[0], - node.rotationQuaternion[1], - node.rotationQuaternion[2] ) - * quatY - ); - cameraActor.SetProjectionMode( Camera::PERSPECTIVE_PROJECTION ); + cameraPosition = Vector3(node.translation[0], node.translation[1], node.translation[2]); + auto quatY = Quaternion(Degree(180.0f), Vector3(0.0, 1.0, 0.0)); + auto cameraActor = CameraActor::DownCast(actor); + cameraActor.SetProperty(Actor::Property::ORIENTATION, Quaternion(node.rotationQuaternion[3], node.rotationQuaternion[0], node.rotationQuaternion[1], node.rotationQuaternion[2]) * quatY); + cameraActor.SetProjectionMode(Camera::PERSPECTIVE_PROJECTION); const auto camera = gltf->GetCameras()[node.cameraId]; - cameraActor.SetNearClippingPlane( camera->znear ); - cameraActor.SetFarClippingPlane( camera->zfar ); - cameraActor.SetFieldOfView( camera->yfov ); + cameraActor.SetNearClippingPlane(camera->znear); + cameraActor.SetFarClippingPlane(camera->zfar); + cameraActor.SetFieldOfView(camera->yfov); - cameraActor.SetProperty( CameraActor::Property::INVERT_Y_AXIS, true); - cameraActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - cameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + cameraActor.SetProperty(CameraActor::Property::INVERT_Y_AXIS, true); + cameraActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + cameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - cameras.emplace_back( cameraActor ); + cameras.emplace_back(cameraActor); } } // Resolve hierarchy dependencies auto i = 0u; - for( const auto& node : nodes ) + for(const auto& node : nodes) { if(!node.children.empty()) { for(const auto& childId : node.children) { - actors[i].Add( actors[childId+1] ); + actors[i].Add(actors[childId + 1]); } } ++i; } - for( auto& actor : actors ) + for(auto& actor : actors) { - actor.RegisterProperty( "lightDir", DEFAULT_LIGHT_DIRECTION ); - actor.RegisterProperty( "eyePos", cameraPosition ); + actor.RegisterProperty("lightDir", DEFAULT_LIGHT_DIRECTION); + actor.RegisterProperty("eyePos", cameraPosition); } return actors[0]; @@ -461,36 +450,33 @@ Actor CreateSceneFromGLTF( class ReflectionExample : public ConnectionTracker { public: - - ReflectionExample( Application& application ) - : mApplication( application ) + ReflectionExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ReflectionExample::Create ); + mApplication.InitSignal().Connect(this, &ReflectionExample::Create); } ~ReflectionExample() = default; private: - // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window - Window window = application.GetWindow(); + Window window = application.GetWindow(); uint32_t windowWidth = uint32_t(window.GetSize().GetWidth()); uint32_t windowHeight = uint32_t(window.GetSize().GetHeight()); window.GetRenderTaskList().GetTask(0).SetClearEnabled(false); mLayer3D = Layer::New(); - mLayer3D.SetProperty( Actor::Property::SIZE, Vector2( windowWidth, windowHeight ) ); + mLayer3D.SetProperty(Actor::Property::SIZE, Vector2(windowWidth, windowHeight)); window.Add(mLayer3D); - mLayer3D.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLayer3D.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLayer3D.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); - mLayer3D.SetProperty( Layer::Property::DEPTH_TEST, true ); - + mLayer3D.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLayer3D.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLayer3D.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); + mLayer3D.SetProperty(Layer::Property::DEPTH_TEST, true); auto gltf = glTF(DEMO_GAME_DIR "/reflection"); @@ -499,135 +485,134 @@ private: /** * Instantiate texture sets */ - CreateTextureSetsFromGLTF( &gltf, DEMO_GAME_DIR, mTextureSets ); + CreateTextureSetsFromGLTF(&gltf, DEMO_GAME_DIR, mTextureSets); /** * Create models */ - CreateModelsFromGLTF( &gltf, mModels ); + CreateModelsFromGLTF(&gltf, mModels); /** * Create scene nodes & add to 3D Layer */ - mLayer3D.Add( CreateSceneFromGLTF( window, &gltf, mModels, mActors, mCameras, mTextureSets ) ); + mLayer3D.Add(CreateSceneFromGLTF(window, &gltf, mModels, mActors, mCameras, mTextureSets)); - auto planeActor = mLayer3D.FindChildByName( "Plane" ); - auto solarActor = mLayer3D.FindChildByName( "solar_root" ); - auto backgroundActor = mLayer3D.FindChildByName( "background" ); - ReplaceShader( backgroundActor, VERTEX_SHADER, FRAGMENT_SIMPLE_SHADER ); - mCenterActor = mLayer3D.FindChildByName( "center" ); - mCenterHorizActor = mLayer3D.FindChildByName( "center2" ); + auto planeActor = mLayer3D.FindChildByName("Plane"); + auto solarActor = mLayer3D.FindChildByName("solar_root"); + auto backgroundActor = mLayer3D.FindChildByName("background"); + ReplaceShader(backgroundActor, VERTEX_SHADER, FRAGMENT_SIMPLE_SHADER); + mCenterActor = mLayer3D.FindChildByName("center"); + mCenterHorizActor = mLayer3D.FindChildByName("center2"); // Prepare Sun - auto sun = mLayer3D.FindChildByName( "sun" ); - ReplaceShader( sun, VERTEX_SHADER, PLASMA_FRAGMENT_SHADER ); - mSunTimeUniformIndex = sun.RegisterProperty( "uTime", 0.0f ); - mSunKFactorUniformIndex = sun.RegisterProperty( "uKFactor", 0.0f ); + auto sun = mLayer3D.FindChildByName("sun"); + ReplaceShader(sun, VERTEX_SHADER, PLASMA_FRAGMENT_SHADER); + mSunTimeUniformIndex = sun.RegisterProperty("uTime", 0.0f); + mSunKFactorUniformIndex = sun.RegisterProperty("uKFactor", 0.0f); - mTickTimer = Timer::New( 16 ); - mTickTimer.TickSignal().Connect( this, &ReflectionExample::TickTimerSignal); + mTickTimer = Timer::New(16); + mTickTimer.TickSignal().Connect(this, &ReflectionExample::TickTimerSignal); // Milkyway - auto milkyway = mLayer3D.FindChildByName( "milkyway" ); - ReplaceShader( milkyway, VERTEX_SHADER, FRAGMENT_SHADER ); + auto milkyway = mLayer3D.FindChildByName("milkyway"); + ReplaceShader(milkyway, VERTEX_SHADER, FRAGMENT_SHADER); - auto renderTaskSourceActor = mLayer3D.FindChildByName( "RenderTaskSource" ); + auto renderTaskSourceActor = mLayer3D.FindChildByName("RenderTaskSource"); /** * Access camera (it's a child of "Camera" node) */ - auto camera = mLayer3D.FindChildByName( "Camera_Orientation" ); - auto cameraRef = mLayer3D.FindChildByName( "CameraReflection_Orientation" ); + auto camera = mLayer3D.FindChildByName("Camera_Orientation"); + auto cameraRef = mLayer3D.FindChildByName("CameraReflection_Orientation"); - auto cameraActor = CameraActor::DownCast( camera ); - mCamera3D = cameraActor; + auto cameraActor = CameraActor::DownCast(camera); + mCamera3D = cameraActor; - auto cameraRefActor = CameraActor::DownCast( cameraRef ); - cameraRefActor.SetProperty( DevelCameraActor::Property::REFLECTION_PLANE, Vector4(0.0f, -1.0f, 0.0f, 0.0f)); + auto cameraRefActor = CameraActor::DownCast(cameraRef); + cameraRefActor.SetProperty(DevelCameraActor::Property::REFLECTION_PLANE, Vector4(0.0f, -1.0f, 0.0f, 0.0f)); mReflectionCamera3D = cameraRefActor; auto task3D = window.GetRenderTaskList().CreateTask(); - task3D.SetSourceActor( mLayer3D ); - task3D.SetViewport( Rect(0, 0, windowWidth, windowHeight ) ); - task3D.SetCameraActor( cameraActor ); - task3D.SetClearColor( Color::BLACK ); - task3D.SetClearEnabled( true ); - task3D.SetExclusive( false ); - task3D.SetCameraActor( cameraActor ); + task3D.SetSourceActor(mLayer3D); + task3D.SetViewport(Rect(0, 0, windowWidth, windowHeight)); + task3D.SetCameraActor(cameraActor); + task3D.SetClearColor(Color::BLACK); + task3D.SetClearEnabled(true); + task3D.SetExclusive(false); + task3D.SetCameraActor(cameraActor); /** * Change shader to textured */ - Shader texShader = CreateShader( VERTEX_SHADER, TEX_FRAGMENT_SHADER ); - planeActor.RegisterProperty( "uScreenSize", Vector2(windowWidth, windowHeight) ); - auto renderer = planeActor.GetRendererAt(0); + Shader texShader = CreateShader(VERTEX_SHADER, TEX_FRAGMENT_SHADER); + planeActor.RegisterProperty("uScreenSize", Vector2(windowWidth, windowHeight)); + auto renderer = planeActor.GetRendererAt(0); auto textureSet = renderer.GetTextures(); - renderer.SetShader( texShader ); + renderer.SetShader(texShader); - Texture fbTexture = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, windowWidth, windowHeight ); - textureSet.SetTexture( 1u, fbTexture ); + Texture fbTexture = Texture::New(TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, windowWidth, windowHeight); + textureSet.SetTexture(1u, fbTexture); - auto fb = FrameBuffer::New(windowWidth, windowHeight, - FrameBuffer::Attachment::DEPTH ); + auto fb = FrameBuffer::New(windowWidth, windowHeight, FrameBuffer::Attachment::DEPTH); - fb.AttachColorTexture( fbTexture ); + fb.AttachColorTexture(fbTexture); auto renderTask = window.GetRenderTaskList().CreateTask(); - renderTask.SetFrameBuffer( fb ); - renderTask.SetSourceActor( renderTaskSourceActor ); - renderTask.SetViewport( Rect(0, 0, windowWidth, windowHeight ) ); - renderTask.SetCameraActor( cameraRefActor ); - renderTask.SetClearColor( Color::BLACK ); - renderTask.SetClearEnabled( true ); - renderTask.SetExclusive( false ); - - mAnimation = Animation::New(30.0f ); - mAnimation.AnimateBy(Property(solarActor, Actor::Property::ORIENTATION ), - Quaternion( Degree(359), Vector3(0.0, 1.0, 0.0))); - mAnimation.AnimateBy(Property(milkyway, Actor::Property::ORIENTATION ), - Quaternion( Degree(-359), Vector3(0.0, 1.0, 0.0))); - mAnimation.SetLooping(true ); + renderTask.SetFrameBuffer(fb); + renderTask.SetSourceActor(renderTaskSourceActor); + renderTask.SetViewport(Rect(0, 0, windowWidth, windowHeight)); + renderTask.SetCameraActor(cameraRefActor); + renderTask.SetClearColor(Color::BLACK); + renderTask.SetClearEnabled(true); + renderTask.SetExclusive(false); + + mAnimation = Animation::New(30.0f); + mAnimation.AnimateBy(Property(solarActor, Actor::Property::ORIENTATION), + Quaternion(Degree(359), Vector3(0.0, 1.0, 0.0))); + mAnimation.AnimateBy(Property(milkyway, Actor::Property::ORIENTATION), + Quaternion(Degree(-359), Vector3(0.0, 1.0, 0.0))); + mAnimation.SetLooping(true); mAnimation.Play(); - Actor panScreen = Actor::New(); + Actor panScreen = Actor::New(); Vector2 windowSize = window.GetSize(); - panScreen.SetProperty( Actor::Property::SIZE, windowSize ); - panScreen.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - panScreen.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + panScreen.SetProperty(Actor::Property::SIZE, windowSize); + panScreen.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + panScreen.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); auto camera2d = window.GetRenderTaskList().GetTask(0).GetCameraActor(); - panScreen.SetProperty( Actor::Property::POSITION, Vector3( 0, 0, camera2d.GetNearClippingPlane() )); + panScreen.SetProperty(Actor::Property::POSITION, Vector3(0, 0, camera2d.GetNearClippingPlane())); camera2d.Add(panScreen); - camera2d.RotateBy( Degree(180.0f), Vector3( 0.0, 1.0, 0.0 ) ); + camera2d.RotateBy(Degree(180.0f), Vector3(0.0, 1.0, 0.0)); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( panScreen ); - mPanGestureDetector.DetectedSignal().Connect( this, &ReflectionExample::OnPan ); + mPanGestureDetector.Attach(panScreen); + mPanGestureDetector.DetectedSignal().Connect(this, &ReflectionExample::OnPan); // Respond to key events - window.KeyEventSignal().Connect( this, &ReflectionExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &ReflectionExample::OnKeyEvent); mTickTimer.Start(); } - void OnPan( Actor actor, const PanGesture& panGesture ) + void OnPan(Actor actor, const PanGesture& panGesture) { const auto& displacement = panGesture.GetScreenDisplacement(); - mCenterActor.RotateBy( Degree( displacement.y *0.1f ), Vector3( 0.0, 0.0, 1.0) ); - mCenterActor.RotateBy( Degree( displacement.x *0.1f ), Vector3( 0.0, 1.0, 0.0) ); + mCenterActor.RotateBy(Degree(displacement.y * 0.1f), Vector3(0.0, 0.0, 1.0)); + mCenterActor.RotateBy(Degree(displacement.x * 0.1f), Vector3(0.0, 1.0, 0.0)); Quaternion q; - mCenterActor.GetProperty( Actor::Property::ORIENTATION ).Get(q); + mCenterActor.GetProperty(Actor::Property::ORIENTATION).Get(q); Matrix m = Matrix::IDENTITY; - m.SetTransformComponents( Vector3::ONE, q, Vector3::ZERO ); + m.SetTransformComponents(Vector3::ONE, q, Vector3::ZERO); auto yAxis = m.GetYAxis() * -1.0f; yAxis.Normalize(); - mReflectionCamera3D.SetProperty( DevelCameraActor::Property::REFLECTION_PLANE, Vector4(yAxis.x, yAxis.y, yAxis.z, 0.0f)); + mReflectionCamera3D.SetProperty(DevelCameraActor::Property::REFLECTION_PLANE, Vector4(yAxis.x, yAxis.y, yAxis.z, 0.0f)); } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -636,54 +621,53 @@ private: bool TickTimerSignal() { - auto root = mLayer3D; + auto root = mLayer3D; static float rotationAngle = 0.0f; const auto ROTATION_ANGLE_STEP = 0.05f; - const auto FRAME_DELTA_TIME = 0.016f; - const auto PLASMA_K_FACTOR = 12.0f; // 'granularity' of plasma effect + const auto FRAME_DELTA_TIME = 0.016f; + const auto PLASMA_K_FACTOR = 12.0f; // 'granularity' of plasma effect rotationAngle += ROTATION_ANGLE_STEP; mMockTime += FRAME_DELTA_TIME; mKFactor = PLASMA_K_FACTOR; - auto sun = root.FindChildByName( "sun" ); - sun.SetProperty( mSunTimeUniformIndex, mMockTime ); - sun.SetProperty( mSunKFactorUniformIndex, mKFactor ); - sun.SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian(Degree(rotationAngle)), Vector3(0.0, 1.0, 0.0))); + auto sun = root.FindChildByName("sun"); + sun.SetProperty(mSunTimeUniformIndex, mMockTime); + sun.SetProperty(mSunKFactorUniformIndex, mKFactor); + sun.SetProperty(Actor::Property::ORIENTATION, Quaternion(Radian(Degree(rotationAngle)), Vector3(0.0, 1.0, 0.0))); return true; } private: - - Application& mApplication; + Application& mApplication; Layer mLayer3D{}; - ActorContainer mActors {}; - CameraContainer mCameras {}; - ModelContainer mModels {}; - TextureSetContainer mTextureSets {}; + ActorContainer mActors{}; + CameraContainer mCameras{}; + ModelContainer mModels{}; + TextureSetContainer mTextureSets{}; - Animation mAnimation {}; - float mMockTime { 0.0f }; - float mKFactor { 0.0f }; - Property::Index mSunTimeUniformIndex {}; - Property::Index mSunKFactorUniformIndex {}; - PanGestureDetector mPanGestureDetector {}; + Animation mAnimation{}; + float mMockTime{0.0f}; + float mKFactor{0.0f}; + Property::Index mSunTimeUniformIndex{}; + Property::Index mSunKFactorUniformIndex{}; + PanGestureDetector mPanGestureDetector{}; - Timer mTickTimer {}; + Timer mTickTimer{}; - CameraActor mCamera3D {}; - CameraActor mReflectionCamera3D {}; - Actor mCenterActor {}; - Actor mCenterHorizActor {}; + CameraActor mCamera3D{}; + CameraActor mReflectionCamera3D{}; + Actor mCenterActor{}; + Actor mCenterHorizActor{}; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ReflectionExample test( application ); + Application application = Application::New(&argc, &argv); + ReflectionExample test(application); application.MainLoop(); return 0; } diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index b6eebe3..7587ffe 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -16,58 +16,56 @@ */ // EXTERNAL INCLUDES -#include #include -#include +#include #include +#include -#include -#include #include +#include +#include // INTERNAL INCLUDES -#include "shared/view.h" #include "shared/utility.h" +#include "shared/view.h" using namespace Dali; namespace { -const char * const APPLICATION_TITLE( "Refraction Effect" ); -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const CHANGE_TEXTURE_ICON( DEMO_IMAGE_DIR "icon-change.png" ); -const char * const CHANGE_TEXTURE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char * const CHANGE_MESH_ICON( DEMO_IMAGE_DIR "icon-replace.png" ); -const char * const CHANGE_MESH_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" ); +const char* const APPLICATION_TITLE("Refraction Effect"); +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const CHANGE_TEXTURE_ICON(DEMO_IMAGE_DIR "icon-change.png"); +const char* const CHANGE_TEXTURE_ICON_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* const CHANGE_MESH_ICON(DEMO_IMAGE_DIR "icon-replace.png"); +const char* const CHANGE_MESH_ICON_SELECTED(DEMO_IMAGE_DIR "icon-replace-selected.png"); const char* MESH_FILES[] = -{ - DEMO_MODEL_DIR "surface_pattern_v01.obj", - DEMO_MODEL_DIR "surface_pattern_v02.obj" -}; -const unsigned int NUM_MESH_FILES( sizeof( MESH_FILES ) / sizeof( MESH_FILES[0] ) ); + { + DEMO_MODEL_DIR "surface_pattern_v01.obj", + DEMO_MODEL_DIR "surface_pattern_v02.obj"}; +const unsigned int NUM_MESH_FILES(sizeof(MESH_FILES) / sizeof(MESH_FILES[0])); -const char* TEXTURE_IMAGES[]= -{ - DEMO_IMAGE_DIR "background-1.jpg", - DEMO_IMAGE_DIR "background-2.jpg", - DEMO_IMAGE_DIR "background-3.jpg", - DEMO_IMAGE_DIR "background-4.jpg" -}; -const unsigned int NUM_TEXTURE_IMAGES( sizeof( TEXTURE_IMAGES ) / sizeof( TEXTURE_IMAGES[0] ) ); +const char* TEXTURE_IMAGES[] = + { + DEMO_IMAGE_DIR "background-1.jpg", + DEMO_IMAGE_DIR "background-2.jpg", + DEMO_IMAGE_DIR "background-3.jpg", + DEMO_IMAGE_DIR "background-4.jpg"}; +const unsigned int NUM_TEXTURE_IMAGES(sizeof(TEXTURE_IMAGES) / sizeof(TEXTURE_IMAGES[0])); struct LightOffsetConstraint { - LightOffsetConstraint( float radius ) - : mRadius( radius ) + LightOffsetConstraint(float radius) + : mRadius(radius) { } - void operator()( Vector2& current, const PropertyInputContainer& inputs ) + void operator()(Vector2& current, const PropertyInputContainer& inputs) { float spinAngle = inputs[0]->GetFloat(); - current.x = cos( spinAngle ); - current.y = sin( spinAngle ); + current.x = cos(spinAngle); + current.y = sin(spinAngle); current *= mRadius; } @@ -85,16 +83,21 @@ struct Vertex Vector2 textureCoord; Vertex() - {} + { + } - Vertex( const Vector3& position, const Vector3& normal, const Vector2& textureCoord ) - : position( position ), normal( normal ), textureCoord( textureCoord ) - {} + Vertex(const Vector3& position, const Vector3& normal, const Vector2& textureCoord) + : position(position), + normal(normal), + textureCoord(textureCoord) + { + } }; /************************************************************************************************ *** The shader source is used when the MeshActor is not touched*** ************************************************************************************************/ +// clang-format off const char* VERTEX_SHADER_FLAT = DALI_COMPOSE_SHADER( attribute mediump vec3 aPosition;\n attribute mediump vec3 aNormal;\n @@ -200,18 +203,18 @@ void main()\n gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n }\n ); +// clang-format on } // namespace - /*************************************************/ /*Demo using RefractionEffect*****************/ /*************************************************/ class RefractionEffectExample : public ConnectionTracker { public: - RefractionEffectExample( Application &application ) - : mApplication( application ), + RefractionEffectExample(Application& application) + : mApplication(application), mContent(), mTextureSet(), mGeometry(), @@ -221,14 +224,14 @@ public: mShaderRefraction(), mLightAnimation(), mStrenghAnimation(), - mLightXYOffsetIndex( Property::INVALID_INDEX ), - mSpinAngleIndex( Property::INVALID_INDEX ), - mLightIntensityIndex( Property::INVALID_INDEX ), - mEffectStrengthIndex( Property::INVALID_INDEX ), + mLightXYOffsetIndex(Property::INVALID_INDEX), + mSpinAngleIndex(Property::INVALID_INDEX), + mLightIntensityIndex(Property::INVALID_INDEX), + mEffectStrengthIndex(Property::INVALID_INDEX), mChangeTextureButton(), mChangeMeshButton(), - mCurrentTextureId( 1 ), - mCurrentMeshId( 0 ) + mCurrentTextureId(1), + mCurrentMeshId(0) { // Connect to the Application's Init signal application.InitSignal().Connect(this, &RefractionEffectExample::Create); @@ -239,11 +242,10 @@ public: } private: - // The Init signal is received once (only) during the Application lifetime void Create(Application& application) { - Window window = application.GetWindow(); + Window window = application.GetWindow(); Vector2 windowSize = window.GetSize(); window.KeyEventSignal().Connect(this, &RefractionEffectExample::OnKeyEvent); @@ -251,126 +253,124 @@ private: // Creates a default view with a default tool bar. // The view is added to the window. Toolkit::ToolBar toolBar; - Toolkit::Control view; - mContent = DemoHelper::CreateView( application, - view, - toolBar, - "", - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + Toolkit::Control view; + mContent = DemoHelper::CreateView(application, + view, + toolBar, + "", + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Add a button to change background. (right of toolbar) mChangeTextureButton = Toolkit::PushButton::New(); - mChangeTextureButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON ); - mChangeTextureButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON_SELECTED ); - mChangeTextureButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeTexture ); - toolBar.AddControl( mChangeTextureButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_RIGHT, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mChangeTextureButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON); + mChangeTextureButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_TEXTURE_ICON_SELECTED); + mChangeTextureButton.ClickedSignal().Connect(this, &RefractionEffectExample::OnChangeTexture); + toolBar.AddControl(mChangeTextureButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_RIGHT, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Add a button to change mesh pattern. ( left of bar ) mChangeMeshButton = Toolkit::PushButton::New(); - mChangeMeshButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON ); - mChangeMeshButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON_SELECTED ); - mChangeMeshButton.ClickedSignal().Connect( this, &RefractionEffectExample::OnChangeMesh ); - toolBar.AddControl( mChangeMeshButton, - DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, - Toolkit::Alignment::HORIZONTAL_LEFT, - DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); - - + mChangeMeshButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON); + mChangeMeshButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_MESH_ICON_SELECTED); + mChangeMeshButton.ClickedSignal().Connect(this, &RefractionEffectExample::OnChangeMesh); + toolBar.AddControl(mChangeMeshButton, + DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, + Toolkit::Alignment::HORIZONTAL_LEFT, + DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // shader used when the screen is not touched, render a flat surface - mShaderFlat = Shader::New( VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT ); - mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] ); + mShaderFlat = Shader::New(VERTEX_SHADER_FLAT, FRAGMENT_SHADER_FLAT); + mGeometry = CreateGeometry(MESH_FILES[mCurrentMeshId]); - Texture texture = DemoHelper::LoadWindowFillingTexture( window.GetSize(), TEXTURE_IMAGES[mCurrentTextureId] ); - mTextureSet = TextureSet::New(); - mTextureSet.SetTexture( 0u, texture ); + Texture texture = DemoHelper::LoadWindowFillingTexture(window.GetSize(), TEXTURE_IMAGES[mCurrentTextureId]); + mTextureSet = TextureSet::New(); + mTextureSet.SetTexture(0u, texture); - mRenderer = Renderer::New( mGeometry, mShaderFlat ); - mRenderer.SetTextures( mTextureSet ); + mRenderer = Renderer::New(mGeometry, mShaderFlat); + mRenderer.SetTextures(mTextureSet); mMeshActor = Actor::New(); - mMeshActor.AddRenderer( mRenderer ); - mMeshActor.SetProperty( Actor::Property::SIZE, windowSize ); - mMeshActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mContent.Add( mMeshActor ); + mMeshActor.AddRenderer(mRenderer); + mMeshActor.SetProperty(Actor::Property::SIZE, windowSize); + mMeshActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mContent.Add(mMeshActor); // Connect the callback to the touch signal on the mesh actor - mContent.TouchedSignal().Connect( this, &RefractionEffectExample::OnTouch ); + mContent.TouchedSignal().Connect(this, &RefractionEffectExample::OnTouch); // shader used when the finger is touching the screen. render refraction effect - mShaderRefraction = Shader::New( VERTEX_SHADER_REFRACTION, FRAGMENT_SHADER_REFRACTION ); + mShaderRefraction = Shader::New(VERTEX_SHADER_REFRACTION, FRAGMENT_SHADER_REFRACTION); // register uniforms - mLightXYOffsetIndex = mMeshActor.RegisterProperty( "uLightXYOffset", Vector2::ZERO ); + mLightXYOffsetIndex = mMeshActor.RegisterProperty("uLightXYOffset", Vector2::ZERO); - mLightIntensityIndex = mMeshActor.RegisterProperty( "uLightIntensity", 2.5f ); + mLightIntensityIndex = mMeshActor.RegisterProperty("uLightIntensity", 2.5f); - mEffectStrengthIndex = mMeshActor.RegisterProperty( "uEffectStrength", 0.f ); + mEffectStrengthIndex = mMeshActor.RegisterProperty("uEffectStrength", 0.f); - Vector3 lightPosition( -windowSize.x*0.5f, -windowSize.y*0.5f, windowSize.x*0.5f ); // top_left - mMeshActor.RegisterProperty( "uLightPosition", lightPosition ); + Vector3 lightPosition(-windowSize.x * 0.5f, -windowSize.y * 0.5f, windowSize.x * 0.5f); // top_left + mMeshActor.RegisterProperty("uLightPosition", lightPosition); - Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty( "uLightSpinOffset", Vector2::ZERO ); + Property::Index lightSpinOffsetIndex = mMeshActor.RegisterProperty("uLightSpinOffset", Vector2::ZERO); - mSpinAngleIndex = mMeshActor.RegisterProperty("uSpinAngle", 0.f ); - Constraint constraint = Constraint::New( mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(windowSize.x*0.1f) ); - constraint.AddSource( LocalSource(mSpinAngleIndex) ); + mSpinAngleIndex = mMeshActor.RegisterProperty("uSpinAngle", 0.f); + Constraint constraint = Constraint::New(mMeshActor, lightSpinOffsetIndex, LightOffsetConstraint(windowSize.x * 0.1f)); + constraint.AddSource(LocalSource(mSpinAngleIndex)); constraint.Apply(); // the animation which spin the light around the finger touch position mLightAnimation = Animation::New(2.f); - mLightAnimation.AnimateTo( Property( mMeshActor, mSpinAngleIndex ), Math::PI*2.f ); - mLightAnimation.SetLooping( true ); + mLightAnimation.AnimateTo(Property(mMeshActor, mSpinAngleIndex), Math::PI * 2.f); + mLightAnimation.SetLooping(true); mLightAnimation.Pause(); } - void SetLightXYOffset( const Vector2& offset ) + void SetLightXYOffset(const Vector2& offset) { - mMeshActor.SetProperty( mLightXYOffsetIndex, offset ); + mMeshActor.SetProperty(mLightXYOffsetIndex, offset); } /** * Create a mesh actor with different geometry to replace the current one */ - bool OnChangeMesh( Toolkit::Button button ) + bool OnChangeMesh(Toolkit::Button button) { - mCurrentMeshId = ( mCurrentMeshId + 1 ) % NUM_MESH_FILES; - mGeometry = CreateGeometry( MESH_FILES[mCurrentMeshId] ); - mRenderer.SetGeometry( mGeometry ); + mCurrentMeshId = (mCurrentMeshId + 1) % NUM_MESH_FILES; + mGeometry = CreateGeometry(MESH_FILES[mCurrentMeshId]); + mRenderer.SetGeometry(mGeometry); return true; } - bool OnChangeTexture( Toolkit::Button button ) + bool OnChangeTexture(Toolkit::Button button) { - mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES; - Texture texture = DemoHelper::LoadWindowFillingTexture( mApplication.GetWindow().GetSize(), TEXTURE_IMAGES[mCurrentTextureId] ); - mTextureSet.SetTexture( 0u, texture ); + mCurrentTextureId = (mCurrentTextureId + 1) % NUM_TEXTURE_IMAGES; + Texture texture = DemoHelper::LoadWindowFillingTexture(mApplication.GetWindow().GetSize(), TEXTURE_IMAGES[mCurrentTextureId]); + mTextureSet.SetTexture(0u, texture); return true; } - bool OnTouch( Actor actor, const TouchEvent& event ) + bool OnTouch(Actor actor, const TouchEvent& event) { - switch( event.GetState( 0 ) ) + switch(event.GetState(0)) { case PointState::DOWN: { - mRenderer.SetShader( mShaderRefraction ); + mRenderer.SetShader(mShaderRefraction); - SetLightXYOffset( event.GetScreenPosition( 0 ) ); + SetLightXYOffset(event.GetScreenPosition(0)); mLightAnimation.Play(); - if( mStrenghAnimation ) + if(mStrenghAnimation) { mStrenghAnimation.Clear(); } - mStrenghAnimation= Animation::New(0.5f); - mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 1.f ); + mStrenghAnimation = Animation::New(0.5f); + mStrenghAnimation.AnimateTo(Property(mMeshActor, mEffectStrengthIndex), 1.f); mStrenghAnimation.Play(); break; @@ -378,7 +378,7 @@ private: case PointState::MOTION: { // make the light position following the finger movement - SetLightXYOffset( event.GetScreenPosition( 0 ) ); + SetLightXYOffset(event.GetScreenPosition(0)); break; } case PointState::UP: @@ -387,13 +387,13 @@ private: { mLightAnimation.Pause(); - if( mStrenghAnimation ) + if(mStrenghAnimation) { mStrenghAnimation.Clear(); } mStrenghAnimation = Animation::New(0.5f); - mStrenghAnimation.AnimateTo( Property( mMeshActor, mEffectStrengthIndex ), 0.f ); - mStrenghAnimation.FinishedSignal().Connect( this, &RefractionEffectExample::OnTouchFinished ); + mStrenghAnimation.AnimateTo(Property(mMeshActor, mEffectStrengthIndex), 0.f); + mStrenghAnimation.FinishedSignal().Connect(this, &RefractionEffectExample::OnTouchFinished); mStrenghAnimation.Play(); break; } @@ -406,112 +406,113 @@ private: return true; } - void OnTouchFinished( Animation& source ) + void OnTouchFinished(Animation& source) { - mRenderer.SetShader( mShaderFlat ); - SetLightXYOffset( Vector2::ZERO ); + mRenderer.SetShader(mShaderFlat); + SetLightXYOffset(Vector2::ZERO); } Geometry CreateGeometry(const std::string& objFileName) { std::vector vertexPositions; Vector faceIndices; - Vector boundingBox; + Vector boundingBox; // read the vertice and faces from the .obj file, and record the bounding box - ReadObjFile( objFileName, boundingBox, vertexPositions, faceIndices ); + ReadObjFile(objFileName, boundingBox, vertexPositions, faceIndices); std::vector textureCoordinates; // align the mesh, scale it to fit the screen size, and calculate the texture coordinate for each vertex - ShapeResizeAndTexureCoordinateCalculation( boundingBox, vertexPositions, textureCoordinates ); + ShapeResizeAndTexureCoordinateCalculation(boundingBox, vertexPositions, textureCoordinates); // re-organize the mesh, the vertices are duplicated, each vertex only belongs to one triangle. // Without sharing vertex between triangle, so we can manipulate the texture offset on each triangle conveniently. std::vector vertices; std::size_t size = faceIndices.Size(); - vertices.reserve( size ); + vertices.reserve(size); - for( std::size_t i=0; i 0 ) + if(normal.z > 0) { - vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) ); - vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[i+1] ] ) ); - vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) ); + vertices.push_back(Vertex(vertexPositions[faceIndices[i]], normal, textureCoordinates[faceIndices[i]])); + vertices.push_back(Vertex(vertexPositions[faceIndices[i + 1]], normal, textureCoordinates[faceIndices[i + 1]])); + vertices.push_back(Vertex(vertexPositions[faceIndices[i + 2]], normal, textureCoordinates[faceIndices[i + 2]])); } else { normal *= -1.f; - vertices.push_back( Vertex( vertexPositions[ faceIndices[i] ], normal, textureCoordinates[ faceIndices[i] ] ) ); - vertices.push_back( Vertex( vertexPositions[ faceIndices[i+2] ], normal, textureCoordinates[ faceIndices[i+2] ] ) ); - vertices.push_back( Vertex( vertexPositions[ faceIndices[i+1] ], normal, textureCoordinates[ faceIndices[i+1] ] ) ); + vertices.push_back(Vertex(vertexPositions[faceIndices[i]], normal, textureCoordinates[faceIndices[i]])); + vertices.push_back(Vertex(vertexPositions[faceIndices[i + 2]], normal, textureCoordinates[faceIndices[i + 2]])); + vertices.push_back(Vertex(vertexPositions[faceIndices[i + 1]], normal, textureCoordinates[faceIndices[i + 1]])); } } Property::Map vertexFormat; - vertexFormat["aPosition"] = Property::VECTOR3; - vertexFormat["aNormal"] = Property::VECTOR3; - vertexFormat["aTexCoord"] = Property::VECTOR2; - VertexBuffer surfaceVertices = VertexBuffer::New( vertexFormat ); - surfaceVertices.SetData( &vertices[0], vertices.size() ); + vertexFormat["aPosition"] = Property::VECTOR3; + vertexFormat["aNormal"] = Property::VECTOR3; + vertexFormat["aTexCoord"] = Property::VECTOR2; + VertexBuffer surfaceVertices = VertexBuffer::New(vertexFormat); + surfaceVertices.SetData(&vertices[0], vertices.size()); Geometry surface = Geometry::New(); - surface.AddVertexBuffer( surfaceVertices ); + surface.AddVertexBuffer(surfaceVertices); return surface; } - void ReadObjFile( const std::string& objFileName, - Vector& boundingBox, - std::vector& vertexPositions, - Vector& faceIndices) + void ReadObjFile(const std::string& objFileName, + Vector& boundingBox, + std::vector& vertexPositions, + Vector& faceIndices) { - std::streampos bufferSize = 0; + std::streampos bufferSize = 0; Dali::Vector fileBuffer; - if( !Dali::FileLoader::ReadFile( objFileName, bufferSize, fileBuffer, Dali::FileLoader::FileType::TEXT ) ) + if(!Dali::FileLoader::ReadFile(objFileName, bufferSize, fileBuffer, Dali::FileLoader::FileType::TEXT)) { - DALI_LOG_WARNING( "file open failed for: \"%s\"", objFileName.c_str() ); - return; + DALI_LOG_WARNING("file open failed for: \"%s\"", objFileName.c_str()); + return; } - fileBuffer.PushBack( '\0' ); + fileBuffer.PushBack('\0'); - std::stringstream iss( &fileBuffer[0], std::ios::in ); + std::stringstream iss(&fileBuffer[0], std::ios::in); - boundingBox.Resize( 6 ); - boundingBox[0]=boundingBox[2]=boundingBox[4] = std::numeric_limits::max(); - boundingBox[1]=boundingBox[3]=boundingBox[5] = -std::numeric_limits::max(); + boundingBox.Resize(6); + boundingBox[0] = boundingBox[2] = boundingBox[4] = std::numeric_limits::max(); + boundingBox[1] = boundingBox[3] = boundingBox[5] = -std::numeric_limits::max(); std::string line; - while( std::getline( iss, line ) ) + while(std::getline(iss, line)) { - if( line[0] == 'v' && std::isspace(line[1])) // vertex + if(line[0] == 'v' && std::isspace(line[1])) // vertex { std::istringstream iss(line.substr(2), std::istringstream::in); - unsigned int i = 0; - Vector3 vertex; - while( iss >> vertex[i++] && i < 3); - if( vertex.x < boundingBox[0] ) boundingBox[0] = vertex.x; - if( vertex.x > boundingBox[1] ) boundingBox[1] = vertex.x; - if( vertex.y < boundingBox[2] ) boundingBox[2] = vertex.y; - if( vertex.y > boundingBox[3] ) boundingBox[3] = vertex.y; - if( vertex.z < boundingBox[4] ) boundingBox[4] = vertex.z; - if( vertex.z > boundingBox[5] ) boundingBox[5] = vertex.z; - vertexPositions.push_back( vertex ); + unsigned int i = 0; + Vector3 vertex; + while(iss >> vertex[i++] && i < 3) + ; + if(vertex.x < boundingBox[0]) boundingBox[0] = vertex.x; + if(vertex.x > boundingBox[1]) boundingBox[1] = vertex.x; + if(vertex.y < boundingBox[2]) boundingBox[2] = vertex.y; + if(vertex.y > boundingBox[3]) boundingBox[3] = vertex.y; + if(vertex.z < boundingBox[4]) boundingBox[4] = vertex.z; + if(vertex.z > boundingBox[5]) boundingBox[5] = vertex.z; + vertexPositions.push_back(vertex); } - else if( line[0] == 'f' ) //face + else if(line[0] == 'f') //face { unsigned int numOfInt = 3; - while( true ) + while(true) { - std::size_t found = line.find('/'); - if( found == std::string::npos ) + std::size_t found = line.find('/'); + if(found == std::string::npos) { break; } @@ -519,37 +520,38 @@ private: numOfInt++; } - std::istringstream iss(line.substr(2), std::istringstream::in); + std::istringstream iss(line.substr(2), std::istringstream::in); Dali::Vector indices; indices.Resize(numOfInt); - unsigned int i=0; - while( iss >> indices[i++] && i < numOfInt); - unsigned int step = (i+1) / 3; - faceIndices.PushBack( indices[0]-1 ); - faceIndices.PushBack( indices[step]-1 ); - faceIndices.PushBack( indices[2*step]-1 ); + unsigned int i = 0; + while(iss >> indices[i++] && i < numOfInt) + ; + unsigned int step = (i + 1) / 3; + faceIndices.PushBack(indices[0] - 1); + faceIndices.PushBack(indices[step] - 1); + faceIndices.PushBack(indices[2 * step] - 1); } } } - void ShapeResizeAndTexureCoordinateCalculation( const Vector& boundingBox, - std::vector& vertexPositions, - std::vector& textureCoordinates) + void ShapeResizeAndTexureCoordinateCalculation(const Vector& boundingBox, + std::vector& vertexPositions, + std::vector& textureCoordinates) { - Vector3 bBoxSize( boundingBox[1] - boundingBox[0], boundingBox[3] - boundingBox[2], boundingBox[5] - boundingBox[4]); - Vector3 bBoxMinCorner( boundingBox[0], boundingBox[2], boundingBox[4] ); + Vector3 bBoxSize(boundingBox[1] - boundingBox[0], boundingBox[3] - boundingBox[2], boundingBox[5] - boundingBox[4]); + Vector3 bBoxMinCorner(boundingBox[0], boundingBox[2], boundingBox[4]); Vector2 windowSize = mApplication.GetWindow().GetSize(); - Vector3 scale( windowSize.x / bBoxSize.x, windowSize.y / bBoxSize.y, 1.f ); - scale.z = (scale.x + scale.y)/2.f; + Vector3 scale(windowSize.x / bBoxSize.x, windowSize.y / bBoxSize.y, 1.f); + scale.z = (scale.x + scale.y) / 2.f; textureCoordinates.reserve(vertexPositions.size()); - for( std::vector::iterator iter = vertexPositions.begin(); iter != vertexPositions.end(); iter++ ) + for(std::vector::iterator iter = vertexPositions.begin(); iter != vertexPositions.end(); iter++) { - Vector3 newPosition( (*iter) - bBoxMinCorner ) ; + Vector3 newPosition((*iter) - bBoxMinCorner); - textureCoordinates.push_back( Vector2( newPosition.x / bBoxSize.x, newPosition.y / bBoxSize.y ) ); + textureCoordinates.push_back(Vector2(newPosition.x / bBoxSize.x, newPosition.y / bBoxSize.y)); newPosition -= bBoxSize * 0.5f; (*iter) = newPosition * scale; @@ -563,7 +565,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -571,36 +573,35 @@ private: } private: + Application& mApplication; + Layer mContent; + TextureSet mTextureSet; + Geometry mGeometry; + Renderer mRenderer; + Actor mMeshActor; - Application& mApplication; - Layer mContent; - TextureSet mTextureSet; - Geometry mGeometry; - Renderer mRenderer; - Actor mMeshActor; - - Shader mShaderFlat; - Shader mShaderRefraction; + Shader mShaderFlat; + Shader mShaderRefraction; - Animation mLightAnimation; - Animation mStrenghAnimation; + Animation mLightAnimation; + Animation mStrenghAnimation; Property::Index mLightXYOffsetIndex; Property::Index mSpinAngleIndex; Property::Index mLightIntensityIndex; Property::Index mEffectStrengthIndex; - Toolkit::PushButton mChangeTextureButton; - Toolkit::PushButton mChangeMeshButton; - unsigned int mCurrentTextureId; - unsigned int mCurrentMeshId; + Toolkit::PushButton mChangeTextureButton; + Toolkit::PushButton mChangeMeshButton; + unsigned int mCurrentTextureId; + unsigned int mCurrentMeshId; }; /*****************************************************************************/ -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); RefractionEffectExample theApp(app); app.MainLoop(); return 0; diff --git a/examples/remote-image-loading/remote-image-loading-example.cpp b/examples/remote-image-loading/remote-image-loading-example.cpp index 8952d81..1063e1a 100644 --- a/examples/remote-image-loading/remote-image-loading-example.cpp +++ b/examples/remote-image-loading/remote-image-loading-example.cpp @@ -15,14 +15,12 @@ * */ - +#include +#include +#include #include #include #include -#include -#include -#include - using namespace Dali; using namespace Dali::Toolkit; @@ -32,7 +30,8 @@ using namespace Dali::Toolkit; class MyTester : public ConnectionTracker { public: - MyTester(Application &application) : mApplication(application) + MyTester(Application& application) + : mApplication(application) { // Connect to the Application's Init signal mApplication.InitSignal().Connect(this, &MyTester::Create); @@ -47,130 +46,129 @@ public: { control.TouchedSignal().Connect(this, &MyTester::OnControlTouch); - control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true); + control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); control.KeyEventSignal().Connect(this, &MyTester::OnControlKeyEvent); control.KeyInputFocusGainedSignal().Connect(this, &MyTester::OnFocusSet); control.KeyInputFocusLostSignal().Connect(this, &MyTester::OnFocusUnSet); } // The Init signal is received once (only) during the Application lifetime - void Create(Application &application) + void Create(Application& application) { mWindow = application.GetWindow(); mWindow.SetBackgroundColor(Color::BLACK); mWindow.KeyEventSignal().Connect(this, &MyTester::OnKey); mWindow.TouchedSignal().Connect(this, &MyTester::OnTouch); - TextLabel rubric = TextLabel::New( "You will need a working internet connection to see the images below"); - rubric.SetProperty( TextLabel::Property::MULTI_LINE, true ); - rubric.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - rubric.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - rubric.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - rubric.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - rubric.SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_CENTER ); - mWindow.Add( rubric ); + TextLabel rubric = TextLabel::New("You will need a working internet connection to see the images below"); + rubric.SetProperty(TextLabel::Property::MULTI_LINE, true); + rubric.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + rubric.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + rubric.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + rubric.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + rubric.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_CENTER); + mWindow.Add(rubric); mImageView1 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/293/259/19/520_000000000000293259191500x1500_72dpi_RGB_q70.jpg"); - mImageView1.SetProperty( Dali::Actor::Property::NAME,"mImageView1"); - mImageView1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mImageView1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); + mImageView1.SetProperty(Dali::Actor::Property::NAME, "mImageView1"); + mImageView1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mImageView1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); mImageView1.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false); - mImageView1.SetProperty( Actor::Property::POSITION, Vector2(0, 100)); + mImageView1.SetProperty(Actor::Property::POSITION, Vector2(0, 100)); mImageView1.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f)); mWindow.Add(mImageView1); mImageView2 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/651/88/520_000000000000212651881500x1500_72dpi_RGB_q70.jpg"); - mImageView2.SetProperty( Dali::Actor::Property::NAME,"mImageView2"); - mImageView2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mImageView2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); + mImageView2.SetProperty(Dali::Actor::Property::NAME, "mImageView2"); + mImageView2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mImageView2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); mImageView2.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false); - mImageView2.SetProperty( Actor::Property::POSITION, Vector2(400, 100)); + mImageView2.SetProperty(Actor::Property::POSITION, Vector2(400, 100)); mImageView2.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f)); mWindow.Add(mImageView2); mImageView3 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/353/21/520_000000000000212353211500x1500_72dpi_RGB_q70.jpg"); - mImageView3.SetProperty( Dali::Actor::Property::NAME,"mImageView3"); - mImageView3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mImageView3.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); + mImageView3.SetProperty(Dali::Actor::Property::NAME, "mImageView3"); + mImageView3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mImageView3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); mImageView3.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false); - mImageView3.SetProperty( Actor::Property::POSITION, Vector2(0, 400)); + mImageView3.SetProperty(Actor::Property::POSITION, Vector2(0, 400)); mImageView3.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f)); mWindow.Add(mImageView3); mImageView4 = Toolkit::ImageView::New("http://d2k43l0oslhof9.cloudfront.net/platform/image/contents/vc/20/01/58/20170629100630071189_0bf6b911-a847-cba4-e518-be40fe2f579420170629192203240.jpg"); - mImageView4.SetProperty( Dali::Actor::Property::NAME,"mImageView4"); - mImageView4.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mImageView4.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); + mImageView4.SetProperty(Dali::Actor::Property::NAME, "mImageView4"); + mImageView4.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mImageView4.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); mImageView4.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false); - mImageView4.SetProperty( Actor::Property::POSITION, Vector2(400, 400)); + mImageView4.SetProperty(Actor::Property::POSITION, Vector2(400, 400)); mImageView4.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f)); mWindow.Add(mImageView4); mImageView5 = Toolkit::ImageView::New("http://static.midomi.com/h/images/w/weather_sunny.png"); - mImageView5.SetProperty( Dali::Actor::Property::NAME,"mImageView5"); - mImageView4.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mImageView5.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER); + mImageView5.SetProperty(Dali::Actor::Property::NAME, "mImageView5"); + mImageView4.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mImageView5.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); mImageView5.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false); - mImageView5.SetProperty( Actor::Property::POSITION, Vector2(800, 100)); + mImageView5.SetProperty(Actor::Property::POSITION, Vector2(800, 100)); mImageView5.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f)); mWindow.Add(mImageView5); // Tie-in input event handlers: - mWindow.KeyEventSignal().Connect( this, &MyTester::OnKeyEvent ); + mWindow.KeyEventSignal().Connect(this, &MyTester::OnKeyEvent); } - void OnAnimationEnd(Animation &source) + void OnAnimationEnd(Animation& source) { - std::cout<<"OnAnimationEnd" << std::endl; + std::cout << "OnAnimationEnd" << std::endl; } void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } } } - void OnKey(const KeyEvent &event) + void OnKey(const KeyEvent& event) { - if (event.GetState() == KeyEvent::DOWN) + if(event.GetState() == KeyEvent::DOWN) { - std::cout<<"Window key : " << event.GetKeyCode() << std::endl; + std::cout << "Window key : " << event.GetKeyCode() << std::endl; } } - void OnTouch(const TouchEvent &touch) + void OnTouch(const TouchEvent& touch) { - if (touch.GetState(0) == PointState::DOWN) + if(touch.GetState(0) == PointState::DOWN) { - std::cout<<"Window touch" << std::endl; + std::cout << "Window touch" << std::endl; } } - bool OnControlKeyEvent(Toolkit::Control control, const KeyEvent &event) + bool OnControlKeyEvent(Toolkit::Control control, const KeyEvent& event) { - if (event.GetState() == KeyEvent::DOWN) + if(event.GetState() == KeyEvent::DOWN) { - std::cout<<"Control down key : " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", keyCode : " << event.GetKeyCode() << std::endl; + std::cout << "Control down key : " << control.GetProperty(Dali::Actor::Property::NAME) << ", keyCode : " << event.GetKeyCode() << std::endl; } else { - std::cout<<"Control up key : " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", keyCode : " << event.GetKeyCode() << std::endl; + std::cout << "Control up key : " << control.GetProperty(Dali::Actor::Property::NAME) << ", keyCode : " << event.GetKeyCode() << std::endl; } return false; } - bool OnControlTouch(Actor actor, const TouchEvent &touch) + bool OnControlTouch(Actor actor, const TouchEvent& touch) { - if (touch.GetState(0) == PointState::DOWN) + if(touch.GetState(0) == PointState::DOWN) { - - std::cout<<"Control touch " << actor.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", parent " << actor.GetParent().GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl; + std::cout << "Control touch " << actor.GetProperty(Dali::Actor::Property::NAME) << ", parent " << actor.GetParent().GetProperty(Dali::Actor::Property::NAME) << std::endl; } return false; @@ -178,40 +176,39 @@ public: void OnFocusSet(Control control) { - std::cout<<"OnFocusSet " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl; + std::cout << "OnFocusSet " << control.GetProperty(Dali::Actor::Property::NAME) << std::endl; } void OnFocusUnSet(Control control) { - std::cout<<"OnFocusUnSet " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl; + std::cout << "OnFocusUnSet " << control.GetProperty(Dali::Actor::Property::NAME) << std::endl; } private: - Window mWindow; - Application &mApplication; + Window mWindow; + Application& mApplication; - Control mControl1; - Control mControl2; + Control mControl1; + Control mControl2; ImageView mImageView1; ImageView mImageView2; ImageView mImageView3; ImageView mImageView4; ImageView mImageView5; - TextLabel mTextLabel1; - TextLabel mTextLabel2; - TextField mTextField; + TextLabel mTextLabel1; + TextLabel mTextLabel2; + TextField mTextField; TextEditor mTextEditor; Animation mAnimation; Timer mTimer; - }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { Application application = Application::New(&argc, &argv, ""); - MyTester test(application); + MyTester test(application); application.MainLoop(); return 0; } diff --git a/examples/renderer-stencil/renderer-stencil-example.cpp b/examples/renderer-stencil/renderer-stencil-example.cpp index 86e006b..f324ea7 100644 --- a/examples/renderer-stencil/renderer-stencil-example.cpp +++ b/examples/renderer-stencil/renderer-stencil-example.cpp @@ -20,43 +20,42 @@ // INTERNAL INCLUDES #include "renderer-stencil-shaders.h" -#include "shared/view.h" #include "shared/utility.h" +#include "shared/view.h" using namespace Dali; namespace { - // Constants: // Application constants: -const char * const APPLICATION_TITLE( "Renderer Stencil API Demo" ); -const char * const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-gradient.jpg" ); +const char* const APPLICATION_TITLE("Renderer Stencil API Demo"); +const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-gradient.jpg"); // Texture filenames: -const char * const CUBE_TEXTURE( DEMO_IMAGE_DIR "people-medium-1.jpg" ); -const char * const FLOOR_TEXTURE( DEMO_IMAGE_DIR "wood.png" ); +const char* const CUBE_TEXTURE(DEMO_IMAGE_DIR "people-medium-1.jpg"); +const char* const FLOOR_TEXTURE(DEMO_IMAGE_DIR "wood.png"); // Scale dimensions: These values are relative to the window size. EG. width = 0.32f * windowSize. -const float CUBE_WIDTH_SCALE( 0.32f ); ///< The width (and height + depth) of the main and reflection cubes. -const Vector2 FLOOR_DIMENSION_SCALE( 0.67f, 0.017f ); ///< The width and height of the floor object. +const float CUBE_WIDTH_SCALE(0.32f); ///< The width (and height + depth) of the main and reflection cubes. +const Vector2 FLOOR_DIMENSION_SCALE(0.67f, 0.017f); ///< The width and height of the floor object. // Configurable animation characteristics: -const float ANIMATION_ROTATION_DURATION( 10.0f ); ///< Time in seconds to rotate the scene 360 degrees around Y. -const float ANIMATION_BOUNCE_TOTAL_TIME( 1.6f ); ///< Time in seconds to perform 1 full bounce animation cycle. -const float ANIMATION_BOUNCE_DEFORMATION_TIME( 0.4f ); ///< Time in seconds that the cube deformation animation will occur for (on contact with the floor). -const float ANIMATION_BOUNCE_DEFORMATION_PERCENT( 20.0f ); ///< Percentage (of the cube's size) to deform the cube by (on contact with floor). -const float ANIMATION_BOUNCE_HEIGHT_PERCENT( 40.0f ); ///< Percentage (of the cube's size) to bounce up in to the air by. +const float ANIMATION_ROTATION_DURATION(10.0f); ///< Time in seconds to rotate the scene 360 degrees around Y. +const float ANIMATION_BOUNCE_TOTAL_TIME(1.6f); ///< Time in seconds to perform 1 full bounce animation cycle. +const float ANIMATION_BOUNCE_DEFORMATION_TIME(0.4f); ///< Time in seconds that the cube deformation animation will occur for (on contact with the floor). +const float ANIMATION_BOUNCE_DEFORMATION_PERCENT(20.0f); ///< Percentage (of the cube's size) to deform the cube by (on contact with floor). +const float ANIMATION_BOUNCE_HEIGHT_PERCENT(40.0f); ///< Percentage (of the cube's size) to bounce up in to the air by. // Base colors for the objects: -const Vector4 TEXT_COLOR( 1.0f, 1.0f, 1.0f, 1.0f ); ///< White. -const Vector4 CUBE_COLOR( 1.0f, 1.0f, 1.0f, 1.0f ); ///< White. -const Vector4 FLOOR_COLOR( 1.0f, 1.0f, 1.0f, 1.0f ); ///< White. -const Vector4 REFLECTION_COLOR( 0.6f, 0.6f, 0.6f, 0.6f ); ///< Note that alpha is not 1.0f, to make the blend more photo-realistic. +const Vector4 TEXT_COLOR(1.0f, 1.0f, 1.0f, 1.0f); ///< White. +const Vector4 CUBE_COLOR(1.0f, 1.0f, 1.0f, 1.0f); ///< White. +const Vector4 FLOOR_COLOR(1.0f, 1.0f, 1.0f, 1.0f); ///< White. +const Vector4 REFLECTION_COLOR(0.6f, 0.6f, 0.6f, 0.6f); ///< Note that alpha is not 1.0f, to make the blend more photo-realistic. // We need to control the draw order as we are controlling both the stencil and depth buffer per renderer. -const int DEPTH_INDEX_GRANULARITY( 10000 ); ///< This value is the gap in depth-index in-between each renderer. +const int DEPTH_INDEX_GRANULARITY(10000); ///< This value is the gap in depth-index in-between each renderer. } // Anonymous namespace @@ -66,16 +65,15 @@ const int DEPTH_INDEX_GRANULARITY( 10000 ); ///< This value is th class RendererStencilExample : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application The DALi application object */ - RendererStencilExample( Application& application ) - : mApplication( application ) + RendererStencilExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal. - mApplication.InitSignal().Connect( this, &RendererStencilExample::Create ); + mApplication.InitSignal().Connect(this, &RendererStencilExample::Create); } /** @@ -86,7 +84,6 @@ public: } private: - /** * @brief Enum to facilitate more readable use of the cube array. */ @@ -111,157 +108,150 @@ private: * This is called via the Init signal which is received once (only) during the Application lifetime. * @param[in] application The DALi application object */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); // Use a gradient visual to render the background gradient. Toolkit::Control background = Dali::Toolkit::Control::New(); - background.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - background.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - background.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); + background.SetProperty(Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + background.SetProperty(Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + background.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); // Set up the background gradient. Property::Array stopOffsets; - stopOffsets.PushBack( 0.0f ); - stopOffsets.PushBack( 1.0f ); + stopOffsets.PushBack(0.0f); + stopOffsets.PushBack(1.0f); Property::Array stopColors; - stopColors.PushBack( Vector4( 0.17f, 0.24f, 0.35f, 1.0f ) ); // Dark, medium saturated blue ( top of screen) - stopColors.PushBack( Vector4( 0.45f, 0.70f, 0.80f, 1.0f ) ); // Medium bright, pastel blue (bottom of screen) + stopColors.PushBack(Vector4(0.17f, 0.24f, 0.35f, 1.0f)); // Dark, medium saturated blue ( top of screen) + stopColors.PushBack(Vector4(0.45f, 0.70f, 0.80f, 1.0f)); // Medium bright, pastel blue (bottom of screen) const float percentageWindowHeight = window.GetSize().GetHeight() * 0.7f; - background.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map() - .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::GRADIENT ) - .Add( Toolkit::GradientVisual::Property::STOP_OFFSET, stopOffsets ) - .Add( Toolkit::GradientVisual::Property::STOP_COLOR, stopColors ) - .Add( Toolkit::GradientVisual::Property::START_POSITION, Vector2( 0.0f, -percentageWindowHeight ) ) - .Add( Toolkit::GradientVisual::Property::END_POSITION, Vector2( 0.0f, percentageWindowHeight ) ) - .Add( Toolkit::GradientVisual::Property::UNITS, Toolkit::GradientVisual::Units::USER_SPACE ) ); + background.SetProperty(Toolkit::Control::Property::BACKGROUND, Dali::Property::Map().Add(Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::GRADIENT).Add(Toolkit::GradientVisual::Property::STOP_OFFSET, stopOffsets).Add(Toolkit::GradientVisual::Property::STOP_COLOR, stopColors).Add(Toolkit::GradientVisual::Property::START_POSITION, Vector2(0.0f, -percentageWindowHeight)).Add(Toolkit::GradientVisual::Property::END_POSITION, Vector2(0.0f, percentageWindowHeight)).Add(Toolkit::GradientVisual::Property::UNITS, Toolkit::GradientVisual::Units::USER_SPACE)); - window.Add( background ); + window.Add(background); // Create a TextLabel for the application title. - Toolkit::TextLabel label = Toolkit::TextLabel::New( APPLICATION_TITLE ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); + Toolkit::TextLabel label = Toolkit::TextLabel::New(APPLICATION_TITLE); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); // Set the parent origin to a small percentage below the top (so the demo will scale for different resolutions). - label.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.03f, 0.5f ) ); - label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, TEXT_COLOR ); - window.Add( label ); + label.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 0.03f, 0.5f)); + label.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + label.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, TEXT_COLOR); + window.Add(label); // Layer to hold the 3D scene. Layer layer = Layer::New(); - layer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); // Set the parent origin to a small percentage below the center (so the demo will scale for different resolutions). - layer.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.58f, 0.5f ) ); - layer.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_UI ); - layer.SetProperty( Layer::Property::DEPTH_TEST, true ); - window.Add( layer ); + layer.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 0.58f, 0.5f)); + layer.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI); + layer.SetProperty(Layer::Property::DEPTH_TEST, true); + window.Add(layer); // Main cube: // Make the demo scalable with different resolutions by basing // the cube size on a percentage of the window size. Vector2 windowSize = window.GetSize(); - float scaleSize( std::min( windowSize.width, windowSize.height ) ); - float cubeWidth( scaleSize * CUBE_WIDTH_SCALE ); - Vector3 cubeSize( cubeWidth, cubeWidth, cubeWidth ); + float scaleSize(std::min(windowSize.width, windowSize.height)); + float cubeWidth(scaleSize * CUBE_WIDTH_SCALE); + Vector3 cubeSize(cubeWidth, cubeWidth, cubeWidth); // Create the geometry for the cube, and the texture. - Geometry cubeGeometry = CreateCubeVertices( Vector3::ONE, false ); - TextureSet cubeTextureSet = CreateTextureSet( CUBE_TEXTURE ); + Geometry cubeGeometry = CreateCubeVertices(Vector3::ONE, false); + TextureSet cubeTextureSet = CreateTextureSet(CUBE_TEXTURE); // Create the cube object and add it. // Note: The cube is anchored around its base for animation purposes, so the position can be zero. - mCubes[ MAIN_CUBE ] = CreateMainCubeObject( cubeGeometry, cubeSize, cubeTextureSet ); - layer.Add( mCubes[ MAIN_CUBE ] ); + mCubes[MAIN_CUBE] = CreateMainCubeObject(cubeGeometry, cubeSize, cubeTextureSet); + layer.Add(mCubes[MAIN_CUBE]); // Floor: - float floorWidth( scaleSize * FLOOR_DIMENSION_SCALE.x ); - Vector3 floorSize( floorWidth, scaleSize * FLOOR_DIMENSION_SCALE.y, floorWidth ); + float floorWidth(scaleSize * FLOOR_DIMENSION_SCALE.x); + Vector3 floorSize(floorWidth, scaleSize * FLOOR_DIMENSION_SCALE.y, floorWidth); // Create the floor object using the cube geometry with a new size, and add it. - Actor floorObject( CreateFloorObject( cubeGeometry, floorSize ) ); - layer.Add( floorObject ); + Actor floorObject(CreateFloorObject(cubeGeometry, floorSize)); + layer.Add(floorObject); // Stencil: - Vector3 planeSize( floorWidth, floorWidth, 0.0f ); + Vector3 planeSize(floorWidth, floorWidth, 0.0f); // Create the stencil plane object, and add it. - Actor stencilPlaneObject( CreateStencilPlaneObject( planeSize ) ); - layer.Add( stencilPlaneObject ); + Actor stencilPlaneObject(CreateStencilPlaneObject(planeSize)); + layer.Add(stencilPlaneObject); // Reflection cube: // Create the reflection cube object and add it. // Note: The cube is anchored around its base for animation purposes, so the position can be zero. - mCubes[ REFLECTION_CUBE ] = CreateReflectionCubeObject( cubeSize, cubeTextureSet ); - layer.Add( mCubes[ REFLECTION_CUBE ] ); + mCubes[REFLECTION_CUBE] = CreateReflectionCubeObject(cubeSize, cubeTextureSet); + layer.Add(mCubes[REFLECTION_CUBE]); // Rotate the layer so we can see some of the top of the cube for a more 3D effect. - layer.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( -24.0f ), Degree( 0.0f ), Degree( 0.0f ) ) ); + layer.SetProperty(Actor::Property::ORIENTATION, Quaternion(Degree(-24.0f), Degree(0.0f), Degree(0.0f))); // Set up the rotation on the Y axis. - mRotationAnimation = Animation::New( ANIMATION_ROTATION_DURATION ); + mRotationAnimation = Animation::New(ANIMATION_ROTATION_DURATION); float fullRotation = 360.0f; - mRotationAnimation.AnimateBy( Property( mCubes[ MAIN_CUBE ], Actor::Property::ORIENTATION ), - Quaternion( Degree( 0.0f ), Degree( fullRotation ), Degree( 0.0f ) ) ); - mRotationAnimation.AnimateBy( Property( floorObject, Actor::Property::ORIENTATION ), - Quaternion( Degree( 0.0f ), Degree( fullRotation ), Degree( 0.0f ) ) ); + mRotationAnimation.AnimateBy(Property(mCubes[MAIN_CUBE], Actor::Property::ORIENTATION), + Quaternion(Degree(0.0f), Degree(fullRotation), Degree(0.0f))); + mRotationAnimation.AnimateBy(Property(floorObject, Actor::Property::ORIENTATION), + Quaternion(Degree(0.0f), Degree(fullRotation), Degree(0.0f))); // Note the stencil is pre-rotated by 90 degrees on X, so we rotate relatively on its Z axis for an equivalent Y rotation. - mRotationAnimation.AnimateBy( Property( stencilPlaneObject, Actor::Property::ORIENTATION ), - Quaternion( Degree( 0.0f ), Degree( 0.0f ), Degree( fullRotation ) ) ); - mRotationAnimation.AnimateBy( Property( mCubes[ REFLECTION_CUBE ], Actor::Property::ORIENTATION ), - Quaternion( Degree( 0.0f ), Degree( fullRotation ), Degree( 0.0f ) ) ); - mRotationAnimation.SetLooping( true ); + mRotationAnimation.AnimateBy(Property(stencilPlaneObject, Actor::Property::ORIENTATION), + Quaternion(Degree(0.0f), Degree(0.0f), Degree(fullRotation))); + mRotationAnimation.AnimateBy(Property(mCubes[REFLECTION_CUBE], Actor::Property::ORIENTATION), + Quaternion(Degree(0.0f), Degree(fullRotation), Degree(0.0f))); + mRotationAnimation.SetLooping(true); // Set up the cube bouncing animation. - float totalTime = ANIMATION_BOUNCE_TOTAL_TIME; + float totalTime = ANIMATION_BOUNCE_TOTAL_TIME; float deformationTime = ANIMATION_BOUNCE_DEFORMATION_TIME; // Percentage based amounts allows the bounce and deformation to scale for different resolution screens. float deformationAmount = ANIMATION_BOUNCE_DEFORMATION_PERCENT / 100.0f; - float heightChange = ( cubeSize.y * ANIMATION_BOUNCE_HEIGHT_PERCENT ) / 100.0f; + float heightChange = (cubeSize.y * ANIMATION_BOUNCE_HEIGHT_PERCENT) / 100.0f; // Animation pre-calculations: - float halfTime = totalTime / 2.0f; + float halfTime = totalTime / 2.0f; float halfDeformationTime = deformationTime / 2.0f; // First position the cubes at the top of the animation cycle. - mCubes[ MAIN_CUBE ].SetProperty( Actor::Property::POSITION_Y, -heightChange ); - mCubes[ REFLECTION_CUBE ].SetProperty( Actor::Property::POSITION_Y, heightChange ); + mCubes[MAIN_CUBE].SetProperty(Actor::Property::POSITION_Y, -heightChange); + mCubes[REFLECTION_CUBE].SetProperty(Actor::Property::POSITION_Y, heightChange); - mBounceAnimation = Animation::New( totalTime ); + mBounceAnimation = Animation::New(totalTime); // The animations for the main and reflected cubes are almost identical, so we combine the code to do both. - for( int cube = 0; cube < 2; ++cube ) + for(int cube = 0; cube < 2; ++cube) { // If iterating on the reflection cube, adjust the heightChange variable so the below code can be reused. - if( cube == 1 ) + if(cube == 1) { heightChange = -heightChange; } // 1st TimePeriod: Start moving down with increasing speed, until it is time to distort the cube due to impact. - mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::POSITION_Y ), heightChange, AlphaFunction::EASE_IN_SQUARE, TimePeriod( 0.0f, halfTime - halfDeformationTime ) ); + mBounceAnimation.AnimateBy(Property(mCubes[cube], Actor::Property::POSITION_Y), heightChange, AlphaFunction::EASE_IN_SQUARE, TimePeriod(0.0f, halfTime - halfDeformationTime)); // 2nd TimePeriod: The cube is touching the floor, start deforming it - then un-deform it again. - mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::SCALE_X ), deformationAmount, AlphaFunction::BOUNCE, TimePeriod( halfTime - halfDeformationTime, deformationTime ) ); - mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::SCALE_Z ), deformationAmount, AlphaFunction::BOUNCE, TimePeriod( halfTime - halfDeformationTime, deformationTime ) ); - mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::SCALE_Y ), -deformationAmount, AlphaFunction::BOUNCE, TimePeriod( halfTime - halfDeformationTime, deformationTime ) ); + mBounceAnimation.AnimateBy(Property(mCubes[cube], Actor::Property::SCALE_X), deformationAmount, AlphaFunction::BOUNCE, TimePeriod(halfTime - halfDeformationTime, deformationTime)); + mBounceAnimation.AnimateBy(Property(mCubes[cube], Actor::Property::SCALE_Z), deformationAmount, AlphaFunction::BOUNCE, TimePeriod(halfTime - halfDeformationTime, deformationTime)); + mBounceAnimation.AnimateBy(Property(mCubes[cube], Actor::Property::SCALE_Y), -deformationAmount, AlphaFunction::BOUNCE, TimePeriod(halfTime - halfDeformationTime, deformationTime)); // 3rd TimePeriod: Start moving up with decreasing speed, until at the apex of the animation. - mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::POSITION_Y ), -heightChange, AlphaFunction::EASE_OUT_SQUARE, TimePeriod( halfTime + halfDeformationTime, halfTime - halfDeformationTime ) ); + mBounceAnimation.AnimateBy(Property(mCubes[cube], Actor::Property::POSITION_Y), -heightChange, AlphaFunction::EASE_OUT_SQUARE, TimePeriod(halfTime + halfDeformationTime, halfTime - halfDeformationTime)); } - mBounceAnimation.SetLooping( true ); + mBounceAnimation.SetLooping(true); // Start the animations. mRotationAnimation.Play(); mBounceAnimation.Play(); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &RendererStencilExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &RendererStencilExample::OnTouch); // Connect signals to allow Back and Escape to exit. - window.KeyEventSignal().Connect( this, &RendererStencilExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &RendererStencilExample::OnKeyEvent); } private: - // Methods to setup each component of the 3D scene: /** @@ -273,32 +263,32 @@ private: * @param[in] textureSet A pre-existing TextureSet with a texture set up, to be applied to the cube * @return An actor set-up containing the main cube object */ - Actor CreateMainCubeObject( Geometry& geometry, Vector3 size, TextureSet& textureSet ) + Actor CreateMainCubeObject(Geometry& geometry, Vector3 size, TextureSet& textureSet) { Toolkit::Control container = Toolkit::Control::New(); - container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - container.SetProperty( Actor::Property::SIZE, Vector2( size ) ); - container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + container.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + container.SetProperty(Actor::Property::SIZE, Vector2(size)); + container.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); // Create a renderer from the geometry and add the texture. - Renderer renderer = CreateRenderer( geometry, size, true, CUBE_COLOR ); - renderer.SetTextures( textureSet ); + Renderer renderer = CreateRenderer(geometry, size, true, CUBE_COLOR); + renderer.SetTextures(textureSet); // Setup the renderer properties: // We are writing to the color buffer & culling back faces (no stencil is used for the main cube). - renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR ); - renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR); + renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); // We do need to write to the depth buffer as other objects need to appear underneath this cube. - renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON ); + renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON); // We do not need to test the depth buffer as we are culling the back faces. - renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF ); + renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF); // This object must be rendered 1st. - renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 0 * DEPTH_INDEX_GRANULARITY ); + renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 0 * DEPTH_INDEX_GRANULARITY); - container.AddRenderer( renderer ); + container.AddRenderer(renderer); return container; } @@ -310,33 +300,33 @@ private: * @param[in] size The desired floor size * @return An actor set-up containing the floor object */ - Actor CreateFloorObject( Geometry& geometry, Vector3 size ) + Actor CreateFloorObject(Geometry& geometry, Vector3 size) { Toolkit::Control container = Toolkit::Control::New(); - container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - container.SetProperty( Actor::Property::SIZE, Vector2( size ) ); - container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + container.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + container.SetProperty(Actor::Property::SIZE, Vector2(size)); + container.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); // Create a renderer from the geometry and add the texture. - TextureSet planeTextureSet = CreateTextureSet( FLOOR_TEXTURE ); - Renderer renderer = CreateRenderer( geometry, size, true, FLOOR_COLOR ); - renderer.SetTextures( planeTextureSet ); + TextureSet planeTextureSet = CreateTextureSet(FLOOR_TEXTURE); + Renderer renderer = CreateRenderer(geometry, size, true, FLOOR_COLOR); + renderer.SetTextures(planeTextureSet); // Setup the renderer properties: // We are writing to the color buffer & culling back faces as we are NOT doing depth write (no stencil is used for the floor). - renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR ); - renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR); + renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); // We do not write to the depth buffer as its not needed. - renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF ); + renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF); // We do need to test the depth buffer as we need the floor to be underneath the cube. - renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON ); + renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON); // This object must be rendered 2nd. - renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 * DEPTH_INDEX_GRANULARITY ); + renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1 * DEPTH_INDEX_GRANULARITY); - container.AddRenderer( renderer ); + container.AddRenderer(renderer); return container; } @@ -348,43 +338,43 @@ private: * @param[in] size The desired plane size * @return An actor set-up containing the stencil-plane object */ - Actor CreateStencilPlaneObject( Vector3 size ) + Actor CreateStencilPlaneObject(Vector3 size) { Toolkit::Control container = Toolkit::Control::New(); - container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - container.SetProperty( Actor::Property::SIZE, Vector2( size ) ); - container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + container.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + container.SetProperty(Actor::Property::SIZE, Vector2(size)); + container.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); // We rotate the plane as the geometry is created flat in X & Y. We want it to span X & Z axis. - container.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( -90.0f ), Degree( 0.0f ), Degree( 0.0f ) ) ); + container.SetProperty(Actor::Property::ORIENTATION, Quaternion(Degree(-90.0f), Degree(0.0f), Degree(0.0f))); // Create geometry for a flat plane. - Geometry planeGeometry = CreatePlaneVertices( Vector2::ONE ); + Geometry planeGeometry = CreatePlaneVertices(Vector2::ONE); // Create a renderer from the geometry. - Renderer renderer = CreateRenderer( planeGeometry, size, false, Vector4::ONE ); + Renderer renderer = CreateRenderer(planeGeometry, size, false, Vector4::ONE); // Setup the renderer properties: // The stencil plane is only for stencilling. - renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL ); + renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL); - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS ); - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1 ); - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, 0xFF ); - renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP ); - renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP ); - renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::REPLACE ); - renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF ); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, 0xFF); + renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP); + renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP); + renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::REPLACE); + renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF); // We don't want to write to the depth buffer, as this would block the reflection being drawn. - renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF ); + renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF); // We test the depth buffer as we want the stencil to only exist underneath the cube. - renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON ); + renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON); // This object must be rendered 3rd. - renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 2 * DEPTH_INDEX_GRANULARITY ); + renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 2 * DEPTH_INDEX_GRANULARITY); - container.AddRenderer( renderer ); + container.AddRenderer(renderer); return container; } @@ -397,50 +387,50 @@ private: * @param[in] textureSet A pre-existing TextureSet with a texture set up, to be applied to the cube * @return An actor set-up containing the reflection cube object */ - Actor CreateReflectionCubeObject( Vector3 size, TextureSet& textureSet ) + Actor CreateReflectionCubeObject(Vector3 size, TextureSet& textureSet) { Toolkit::Control container = Toolkit::Control::New(); - container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - container.SetProperty( Actor::Property::SIZE, Vector2( size ) ); - container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); + container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + container.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + container.SetProperty(Actor::Property::SIZE, Vector2(size)); + container.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); // Create the cube geometry of unity size. // The "true" specifies we want the texture UVs flipped vertically as this is the reflection cube. - Geometry reflectedCubeGeometry = CreateCubeVertices( Vector3::ONE, true ); + Geometry reflectedCubeGeometry = CreateCubeVertices(Vector3::ONE, true); // Create a renderer from the geometry and add the texture. - Renderer renderer = CreateRenderer( reflectedCubeGeometry, size, true, REFLECTION_COLOR ); - renderer.SetTextures( textureSet ); + Renderer renderer = CreateRenderer(reflectedCubeGeometry, size, true, REFLECTION_COLOR); + renderer.SetTextures(textureSet); // Setup the renderer properties: // Write to color buffer so reflection is visible. // Also enable the stencil buffer, as we will be testing against it to only draw to areas within the stencil. - renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL ); + renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL); // We cull to skip drawing the back faces. - renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); // We use blending to blend the reflection with the floor texture. - renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); - renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD ); - renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD ); - renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE ); + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON); + renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD); + renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD); + renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE); // Enable stencil. Here we only draw to areas within the stencil. - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::EQUAL ); - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1 ); - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, 0xff ); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::EQUAL); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, 0xff); // Don't write to the stencil. - renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 ); + renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00); // We don't need to write to the depth buffer, as we are culling. - renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF ); + renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF); // We need to test the depth buffer as we need the reflection to be underneath the cube. - renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON ); + renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON); // This object must be rendered last. - renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 3 * DEPTH_INDEX_GRANULARITY ); + renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 3 * DEPTH_INDEX_GRANULARITY); - container.AddRenderer( renderer ); + container.AddRenderer(renderer); return container; } @@ -452,22 +442,22 @@ private: * @param[in] indices The object indices * @return A geometry object */ - Geometry CreateTexturedGeometry( Vector& vertices, Vector& indices ) + Geometry CreateTexturedGeometry(Vector& vertices, Vector& indices) { // Vertices Property::Map vertexFormat; vertexFormat[POSITION] = Property::VECTOR3; - vertexFormat[NORMAL] = Property::VECTOR3; - vertexFormat[TEXTURE] = Property::VECTOR2; + vertexFormat[NORMAL] = Property::VECTOR3; + vertexFormat[TEXTURE] = Property::VECTOR2; - VertexBuffer surfaceVertices = VertexBuffer::New( vertexFormat ); - surfaceVertices.SetData( &vertices[0u], vertices.Size() ); + VertexBuffer surfaceVertices = VertexBuffer::New(vertexFormat); + surfaceVertices.SetData(&vertices[0u], vertices.Size()); Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( surfaceVertices ); + geometry.AddVertexBuffer(surfaceVertices); // Indices for triangle formulation - geometry.SetIndexBuffer( &indices[0u], indices.Size() ); + geometry.SetIndexBuffer(&indices[0u], indices.Size()); return geometry; } @@ -479,28 +469,28 @@ private: * @param[in] color The base color for the renderer * @return A renderer object */ - Renderer CreateRenderer( Geometry geometry, Vector3 dimensions, bool textured, Vector4 color ) + Renderer CreateRenderer(Geometry geometry, Vector3 dimensions, bool textured, Vector4 color) { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - Shader shader; + Shader shader; - if( textured ) + if(textured) { - shader = Shader::New( VERTEX_SHADER_TEXTURED, FRAGMENT_SHADER_TEXTURED ); + shader = Shader::New(VERTEX_SHADER_TEXTURED, FRAGMENT_SHADER_TEXTURED); } else { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + shader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); } // Here we modify the light position based on half the window size as a pre-calculation step. // This avoids the work having to be done in the shader. - shader.RegisterProperty( LIGHT_POSITION_UNIFORM_NAME, Vector3( -windowSize.width / 2.0f, -windowSize.width / 2.0f, 1000.0f ) ); - shader.RegisterProperty( COLOR_UNIFORM_NAME, color ); - shader.RegisterProperty( OBJECT_DIMENSIONS_UNIFORM_NAME, dimensions ); + shader.RegisterProperty(LIGHT_POSITION_UNIFORM_NAME, Vector3(-windowSize.width / 2.0f, -windowSize.width / 2.0f, 1000.0f)); + shader.RegisterProperty(COLOR_UNIFORM_NAME, color); + shader.RegisterProperty(OBJECT_DIMENSIONS_UNIFORM_NAME, dimensions); - return Renderer::New( geometry, shader ); + return Renderer::New(geometry, shader); } /** @@ -508,16 +498,16 @@ private: * @param[in] url An image URL * @return A TextureSet object */ - TextureSet CreateTextureSet( const char* url ) + TextureSet CreateTextureSet(const char* url) { TextureSet textureSet = TextureSet::New(); - if( textureSet ) + if(textureSet) { - Texture texture = DemoHelper::LoadTexture( url ); - if( texture ) + Texture texture = DemoHelper::LoadTexture(url); + if(texture) { - textureSet.SetTexture( 0u, texture ); + textureSet.SetTexture(0u, texture); } } @@ -532,29 +522,29 @@ private: * @param[in] dimensions The desired plane dimensions * @return A Geometry object */ - Geometry CreatePlaneVertices( Vector2 dimensions ) + Geometry CreatePlaneVertices(Vector2 dimensions) { Vector vertices; Vector indices; - vertices.Resize( 4u ); - indices.Resize( 6u ); + vertices.Resize(4u); + indices.Resize(6u); float scaledX = 0.5f * dimensions.x; float scaledY = 0.5f * dimensions.y; - vertices[0].position = Vector3( -scaledX, -scaledY, 0.0f ); - vertices[0].textureCoord = Vector2( 0.0, 0.0f ); - vertices[1].position = Vector3( scaledX, -scaledY, 0.0f ); - vertices[1].textureCoord = Vector2( 1.0, 0.0f ); - vertices[2].position = Vector3( scaledX, scaledY, 0.0f ); - vertices[2].textureCoord = Vector2( 1.0, 1.0f ); - vertices[3].position = Vector3( -scaledX, scaledY, 0.0f ); - vertices[3].textureCoord = Vector2( 0.0, 1.0f ); + vertices[0].position = Vector3(-scaledX, -scaledY, 0.0f); + vertices[0].textureCoord = Vector2(0.0, 0.0f); + vertices[1].position = Vector3(scaledX, -scaledY, 0.0f); + vertices[1].textureCoord = Vector2(1.0, 0.0f); + vertices[2].position = Vector3(scaledX, scaledY, 0.0f); + vertices[2].textureCoord = Vector2(1.0, 1.0f); + vertices[3].position = Vector3(-scaledX, scaledY, 0.0f); + vertices[3].textureCoord = Vector2(0.0, 1.0f); // All vertices have the same normal. - for( int i = 0; i < 4; ++i ) + for(int i = 0; i < 4; ++i) { - vertices[i].normal = Vector3( 0.0f, 0.0f, -1.0f ); + vertices[i].normal = Vector3(0.0f, 0.0f, -1.0f); } indices[0] = 0; @@ -565,7 +555,7 @@ private: indices[5] = 0; // Use the helper method to create the geometry object. - return CreateTexturedGeometry( vertices, indices ); + return CreateTexturedGeometry(vertices, indices); } /** @@ -574,55 +564,55 @@ private: * @param[in] reflectVerticalUVs Set to True to force the UVs to be vertically flipped * @return A Geometry object */ - Geometry CreateCubeVertices( Vector3 dimensions, bool reflectVerticalUVs ) + Geometry CreateCubeVertices(Vector3 dimensions, bool reflectVerticalUVs) { Vector vertices; Vector indices; - int vertexIndex = 0u; // Tracks progress through vertices. - float scaledX = 0.5f * dimensions.x; - float scaledY = 0.5f * dimensions.y; - float scaledZ = 0.5f * dimensions.z; - float verticalTextureCoord = reflectVerticalUVs ? 0.0f : 1.0f; - - vertices.Resize( 4u * 6u ); // 4 vertices x 6 faces - - Vector positions; // Stores vertex positions, which are shared between vertexes at the same position but with a different normal. - positions.Resize( 8u ); - Vector normals; // Stores normals, which are shared between vertexes of the same face. - normals.Resize( 6u ); - - positions[0] = Vector3( -scaledX, scaledY, -scaledZ ); - positions[1] = Vector3( scaledX, scaledY, -scaledZ ); - positions[2] = Vector3( scaledX, scaledY, scaledZ ); - positions[3] = Vector3( -scaledX, scaledY, scaledZ ); - positions[4] = Vector3( -scaledX, -scaledY, -scaledZ ); - positions[5] = Vector3( scaledX, -scaledY, -scaledZ ); - positions[6] = Vector3( scaledX, -scaledY, scaledZ ); - positions[7] = Vector3( -scaledX, -scaledY, scaledZ ); - - normals[0] = Vector3( 0, 1, 0 ); - normals[1] = Vector3( 0, 0, -1 ); - normals[2] = Vector3( 1, 0, 0 ); - normals[3] = Vector3( 0, 0, 1 ); - normals[4] = Vector3( -1, 0, 0 ); - normals[5] = Vector3( 0, -1, 0 ); + int vertexIndex = 0u; // Tracks progress through vertices. + float scaledX = 0.5f * dimensions.x; + float scaledY = 0.5f * dimensions.y; + float scaledZ = 0.5f * dimensions.z; + float verticalTextureCoord = reflectVerticalUVs ? 0.0f : 1.0f; + + vertices.Resize(4u * 6u); // 4 vertices x 6 faces + + Vector positions; // Stores vertex positions, which are shared between vertexes at the same position but with a different normal. + positions.Resize(8u); + Vector normals; // Stores normals, which are shared between vertexes of the same face. + normals.Resize(6u); + + positions[0] = Vector3(-scaledX, scaledY, -scaledZ); + positions[1] = Vector3(scaledX, scaledY, -scaledZ); + positions[2] = Vector3(scaledX, scaledY, scaledZ); + positions[3] = Vector3(-scaledX, scaledY, scaledZ); + positions[4] = Vector3(-scaledX, -scaledY, -scaledZ); + positions[5] = Vector3(scaledX, -scaledY, -scaledZ); + positions[6] = Vector3(scaledX, -scaledY, scaledZ); + positions[7] = Vector3(-scaledX, -scaledY, scaledZ); + + normals[0] = Vector3(0, 1, 0); + normals[1] = Vector3(0, 0, -1); + normals[2] = Vector3(1, 0, 0); + normals[3] = Vector3(0, 0, 1); + normals[4] = Vector3(-1, 0, 0); + normals[5] = Vector3(0, -1, 0); // Top face, upward normals. - for( int i = 0; i < 4; ++i, ++vertexIndex ) + for(int i = 0; i < 4; ++i, ++vertexIndex) { vertices[vertexIndex].position = positions[i]; - vertices[vertexIndex].normal = normals[0]; + vertices[vertexIndex].normal = normals[0]; // The below logic forms the correct U/V pairs for a quad when "i" goes from 0 to 3. - vertices[vertexIndex].textureCoord = Vector2( ( i == 1 || i == 2 ) ? 1.0f : 0.0f, ( i == 2 || i == 3 ) ? 1.0f : 0.0f ); + vertices[vertexIndex].textureCoord = Vector2((i == 1 || i == 2) ? 1.0f : 0.0f, (i == 2 || i == 3) ? 1.0f : 0.0f); } // Top face, outward normals. - for( int i = 0; i < 4; ++i, vertexIndex += 2 ) + for(int i = 0; i < 4; ++i, vertexIndex += 2) { vertices[vertexIndex].position = positions[i]; - vertices[vertexIndex].normal = normals[i + 1]; + vertices[vertexIndex].normal = normals[i + 1]; - if( i == 3 ) + if(i == 3) { // End, so loop around. vertices[vertexIndex + 1].position = positions[0]; @@ -633,20 +623,20 @@ private: } vertices[vertexIndex + 1].normal = normals[i + 1]; - vertices[vertexIndex].textureCoord = Vector2( 0.0f, verticalTextureCoord ); - vertices[vertexIndex+1].textureCoord = Vector2( 1.0f, verticalTextureCoord ); + vertices[vertexIndex].textureCoord = Vector2(0.0f, verticalTextureCoord); + vertices[vertexIndex + 1].textureCoord = Vector2(1.0f, verticalTextureCoord); } // Flip the vertical texture coord for the UV values of the bottom points. verticalTextureCoord = 1.0f - verticalTextureCoord; // Bottom face, outward normals. - for( int i = 0; i < 4; ++i, vertexIndex += 2 ) + for(int i = 0; i < 4; ++i, vertexIndex += 2) { vertices[vertexIndex].position = positions[i + 4]; - vertices[vertexIndex].normal = normals[i + 1]; + vertices[vertexIndex].normal = normals[i + 1]; - if( i == 3 ) + if(i == 3) { // End, so loop around. vertices[vertexIndex + 1].position = positions[4]; @@ -657,26 +647,26 @@ private: } vertices[vertexIndex + 1].normal = normals[i + 1]; - vertices[vertexIndex].textureCoord = Vector2( 0.0f, verticalTextureCoord ); - vertices[vertexIndex+1].textureCoord = Vector2( 1.0f, verticalTextureCoord ); + vertices[vertexIndex].textureCoord = Vector2(0.0f, verticalTextureCoord); + vertices[vertexIndex + 1].textureCoord = Vector2(1.0f, verticalTextureCoord); } // Bottom face, downward normals. - for( int i = 0; i < 4; ++i, ++vertexIndex ) + for(int i = 0; i < 4; ++i, ++vertexIndex) { // Reverse positions for bottom face to keep triangles clockwise (for culling). - vertices[vertexIndex].position = positions[ 7 - i ]; - vertices[vertexIndex].normal = normals[5]; + vertices[vertexIndex].position = positions[7 - i]; + vertices[vertexIndex].normal = normals[5]; // The below logic forms the correct U/V pairs for a quad when "i" goes from 0 to 3. - vertices[vertexIndex].textureCoord = Vector2( ( i == 1 || i == 2 ) ? 1.0f : 0.0f, ( i == 2 || i == 3 ) ? 1.0f : 0.0f ); + vertices[vertexIndex].textureCoord = Vector2((i == 1 || i == 2) ? 1.0f : 0.0f, (i == 2 || i == 3) ? 1.0f : 0.0f); } // Create cube indices. - int triangleIndex = 0u; //Track progress through indices. - indices.Resize( 3u * 12u ); // 3 points x 12 triangles. + int triangleIndex = 0u; //Track progress through indices. + indices.Resize(3u * 12u); // 3 points x 12 triangles. // Top face. - indices[triangleIndex] = 0; + indices[triangleIndex] = 0; indices[triangleIndex + 1] = 1; indices[triangleIndex + 2] = 2; indices[triangleIndex + 3] = 2; @@ -684,13 +674,13 @@ private: indices[triangleIndex + 5] = 0; triangleIndex += 6; - int topFaceStart = 4u; + int topFaceStart = 4u; int bottomFaceStart = topFaceStart + 8u; // Side faces. - for( int i = 0; i < 8; i += 2, triangleIndex += 6 ) + for(int i = 0; i < 8; i += 2, triangleIndex += 6) { - indices[triangleIndex ] = i + topFaceStart; + indices[triangleIndex] = i + topFaceStart; indices[triangleIndex + 1] = i + bottomFaceStart + 1; indices[triangleIndex + 2] = i + topFaceStart + 1; indices[triangleIndex + 3] = i + topFaceStart; @@ -699,7 +689,7 @@ private: } // Bottom face. - indices[triangleIndex] = 20; + indices[triangleIndex] = 20; indices[triangleIndex + 1] = 21; indices[triangleIndex + 2] = 22; indices[triangleIndex + 3] = 22; @@ -707,7 +697,7 @@ private: indices[triangleIndex + 5] = 20; // Use the helper method to create the geometry object. - return CreateTexturedGeometry( vertices, indices ); + return CreateTexturedGeometry(vertices, indices); } // Signal handlers: @@ -718,7 +708,7 @@ private: * @param[in] touch The touch information * @return True if the event has been handled */ - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // Quit the application. mApplication.Quit(); @@ -729,11 +719,11 @@ private: * @brief OnKeyEvent signal handler. * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -741,21 +731,20 @@ private: } private: - // Member variables: - Application& mApplication; ///< The DALi application object - Toolkit::Control mView; ///< The view used to show the background + Application& mApplication; ///< The DALi application object + Toolkit::Control mView; ///< The view used to show the background - Animation mRotationAnimation; ///< The animation to spin the cube & floor - Animation mBounceAnimation; ///< The animation to bounce the cube - Actor mCubes[2]; ///< The cube object containers + Animation mRotationAnimation; ///< The animation to spin the cube & floor + Animation mBounceAnimation; ///< The animation to bounce the cube + Actor mCubes[2]; ///< The cube object containers }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - RendererStencilExample example( application ); + Application application = Application::New(&argc, &argv); + RendererStencilExample example(application); application.MainLoop(); return 0; } diff --git a/examples/renderer-stencil/renderer-stencil-shaders.h b/examples/renderer-stencil/renderer-stencil-shaders.h index d82b0d1..68c4dc1 100644 --- a/examples/renderer-stencil/renderer-stencil-shaders.h +++ b/examples/renderer-stencil/renderer-stencil-shaders.h @@ -21,12 +21,14 @@ #include // Shader uniforms: -const char * const COLOR_UNIFORM_NAME( "uColor" ); -const char * const OBJECT_DIMENSIONS_UNIFORM_NAME( "uObjectDimensions" ); -const char * const LIGHT_POSITION_UNIFORM_NAME = "uLightPosition"; -const char * const POSITION( "aPosition"); -const char * const NORMAL( "aNormal" ); -const char * const TEXTURE( "aTexCoord" ); +const char* const COLOR_UNIFORM_NAME("uColor"); +const char* const OBJECT_DIMENSIONS_UNIFORM_NAME("uObjectDimensions"); +const char* const LIGHT_POSITION_UNIFORM_NAME = "uLightPosition"; +const char* const POSITION("aPosition"); +const char* const NORMAL("aNormal"); +const char* const TEXTURE("aTexCoord"); + +// clang-format off // Shader for basic, per-vertex lighting (vertex): const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( @@ -121,4 +123,6 @@ const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER( } ); +// clang-format on + #endif // DALI_DEMO_RENDERER_STENCIL_SHADERS_H diff --git a/examples/rendering-basic-light/rendering-basic-light-example.cpp b/examples/rendering-basic-light/rendering-basic-light-example.cpp index b82d38d..6d92c0d 100644 --- a/examples/rendering-basic-light/rendering-basic-light-example.cpp +++ b/examples/rendering-basic-light/rendering-basic-light-example.cpp @@ -15,8 +15,8 @@ * */ -#include #include +#include using namespace Dali; using namespace Toolkit; @@ -25,49 +25,49 @@ using namespace Toolkit; namespace { - -const char* BASIC_LIGHT_THEME( DEMO_STYLE_DIR "basic-light-theme.json" ); +const char* BASIC_LIGHT_THEME(DEMO_STYLE_DIR "basic-light-theme.json"); const char* const CUSTOM_BASIC_LIGHT_THEME = "BasicLightButton"; struct Material { - const char *name; - Vector3 ambient; - Vector3 diffuse; - Vector3 specular; - float shininess; + const char* name; + Vector3 ambient; + Vector3 diffuse; + Vector3 specular; + float shininess; }; Material material[] = -{ - {"Emerald", Vector3( 0.0215f, 0.1745f, 0.0215f ), Vector3( 0.07568f, 0.61424f, 0.07568f ), Vector3( 0.633, 0.727811f, 0.633f ), 0.6f }, - {"Jade", Vector3( 0.135f, 0.2225f, 0.1575f ), Vector3( 0.54f, 0.89f, 0.63f ), Vector3( 0.316228f, 0.316228f, 0.316228f ), 0.1f }, - {"Obsidian", Vector3( 0.05375f, 0.05f, 0.06625f ), Vector3( 0.18275f, 0.17f, 0.22525f ), Vector3( 0.332741f, 0.328634f, 0.346435f ), 0.3f }, - {"Perl", Vector3( 0.25f, 0.20725f, 0.20725f ), Vector3( 1.0f, 0.829f, 0.829f ), Vector3( 0.296648f, 0.296648f, 0.296648f ), 0.088f }, - {"Ruby", Vector3( 0.1745f, 0.01175f, 0.01175f ), Vector3( 0.61424f, 0.04136f, 0.04136f ), Vector3( 0.727811f, 0.626959f, 0.626959f ), 0.6f }, - {"Turquoise", Vector3( 0.1f, 0.18725f, 0.1745f ), Vector3( 0.396f, 0.74151f, 0.69102f ), Vector3( 0.297254, 0.30829f, 0.306678f ), 0.1f }, - {"Brass", Vector3( 0.329412f, 0.223529f, 0.027451f ), Vector3( 0.780392f, 0.568627f, 0.113725f ), Vector3( 0.992157f, 0.941176f, 0.807843f ), 0.21794872f }, - {"Bronze", Vector3( 0.2125f, 0.1275f, 0.054f ), Vector3( 0.714f, 0.4284f, 0.18144f ), Vector3( 0.393548f, 0.271906f, 0.166721f ), 0.2f }, - {"Chrome", Vector3( 0.25f, 0.25f, 0.25f ), Vector3( 0.4f, 0.4f, 0.4f), Vector3( 0.774597f, 0.774597f, 0.774597f ), 0.6f }, - {"Copper", Vector3( 0.19125f, 0.0735f, 0.0225f ), Vector3( 0.7038f, 0.27048f, 0.0828f ), Vector3( 0.256777f, 0.137622f, 0.086014f ), 0.1f }, - {"Gold", Vector3( 0.24725f, 0.1995f, 0.0745f ), Vector3( 0.75164f, 0.60648f, 0.22648f ), Vector3( 0.628281f, 0.555802f, 0.366065f ), 0.4f }, - {"Silver", Vector3( 0.19225f, 0.19225f, 0.19225f ), Vector3( 0.50754f, 0.50754f, 0.50754f ), Vector3( 0.508273f, 0.508273f, 0.508273f ), 0.4f }, - {"Black plastic", Vector3( 0.0f, 0.0f, 0.0f ), Vector3( 0.01f, 0.01f, 0.01f ), Vector3( 0.50f, 0.50f, 0.50f ), 0.25f }, - {"Cyan plastic", Vector3( 0.0f, 0.1f, 0.06f ), Vector3( 0.0f, 0.50980392f, 0.50980392f ), Vector3( 0.50196078f, 0.50196078f, 0.50196078f ), 0.25f }, - {"Green plastic", Vector3( 0.0f, 0.0f, 0.0f ), Vector3( 0.1f, 0.35f, 0.1f ), Vector3( 0.45, 0.55, 0.45 ), 0.25f }, - {"Red plastic", Vector3( 0.0f, 0.0f, 0.0f ), Vector3( 0.5f, 0.0f, 0.0f ), Vector3( 0.7f, 0.6f, 0.6f ), 0.25f }, - {"White plastic", Vector3( 0.0f, 0.0f, 0.0f ), Vector3( 0.55f, 0.55f, 0.55f ), Vector3( 0.7f, 0.7f, 0.7f ), 0.25f }, - {"Yellow plastic", Vector3( 0.0f, 0.0f, 0.0f ), Vector3( 0.5f, 0.5f, 0.0f ), Vector3( 0.6f, 0.6f, 0.5f ), 0.25f }, - {"Black rubber", Vector3( 0.02f, 0.02f, 0.02f ), Vector3( 0.01f, 0.01f, 0.01f ), Vector3( 0.4f, 0.4f, 0.4f ), 0.078125f }, - {"Cyan rubber", Vector3( 0.0f, 0.05f, 0.05f ), Vector3( 0.4f, 0.5f, 0.5f ), Vector3( 0.04f, 0.7f, 0.7f ), 0.078125f }, - {"Green rubber", Vector3( 0.0f, 0.05f, 0.0f ), Vector3( 0.4f, 0.5f, 0.4f ), Vector3( 0.04f, 0.7f, 0.04f ), 0.078125f }, - {"Red rubber", Vector3( 0.05f, 0.0f, 0.0f ), Vector3( 0.5f, 0.4f, 0.4f ), Vector3( 0.7f, 0.04f, 0.04f ), 0.078125f }, - {"White rubber", Vector3( 0.05f, 0.05f, 0.05f ), Vector3( 0.5f, 0.5f, 0.5f ), Vector3( 0.7f, 0.7f, 0.7f ), 0.078125f }, - {"Yellow rubber", Vector3( 0.05f, 0.05f, 0.0f ), Vector3( 0.5f, 0.5f, 0.4f ), Vector3( 0.7f, 0.7f, 0.04f ), 0.078125f } -}; + { + {"Emerald", Vector3(0.0215f, 0.1745f, 0.0215f), Vector3(0.07568f, 0.61424f, 0.07568f), Vector3(0.633, 0.727811f, 0.633f), 0.6f}, + {"Jade", Vector3(0.135f, 0.2225f, 0.1575f), Vector3(0.54f, 0.89f, 0.63f), Vector3(0.316228f, 0.316228f, 0.316228f), 0.1f}, + {"Obsidian", Vector3(0.05375f, 0.05f, 0.06625f), Vector3(0.18275f, 0.17f, 0.22525f), Vector3(0.332741f, 0.328634f, 0.346435f), 0.3f}, + {"Perl", Vector3(0.25f, 0.20725f, 0.20725f), Vector3(1.0f, 0.829f, 0.829f), Vector3(0.296648f, 0.296648f, 0.296648f), 0.088f}, + {"Ruby", Vector3(0.1745f, 0.01175f, 0.01175f), Vector3(0.61424f, 0.04136f, 0.04136f), Vector3(0.727811f, 0.626959f, 0.626959f), 0.6f}, + {"Turquoise", Vector3(0.1f, 0.18725f, 0.1745f), Vector3(0.396f, 0.74151f, 0.69102f), Vector3(0.297254, 0.30829f, 0.306678f), 0.1f}, + {"Brass", Vector3(0.329412f, 0.223529f, 0.027451f), Vector3(0.780392f, 0.568627f, 0.113725f), Vector3(0.992157f, 0.941176f, 0.807843f), 0.21794872f}, + {"Bronze", Vector3(0.2125f, 0.1275f, 0.054f), Vector3(0.714f, 0.4284f, 0.18144f), Vector3(0.393548f, 0.271906f, 0.166721f), 0.2f}, + {"Chrome", Vector3(0.25f, 0.25f, 0.25f), Vector3(0.4f, 0.4f, 0.4f), Vector3(0.774597f, 0.774597f, 0.774597f), 0.6f}, + {"Copper", Vector3(0.19125f, 0.0735f, 0.0225f), Vector3(0.7038f, 0.27048f, 0.0828f), Vector3(0.256777f, 0.137622f, 0.086014f), 0.1f}, + {"Gold", Vector3(0.24725f, 0.1995f, 0.0745f), Vector3(0.75164f, 0.60648f, 0.22648f), Vector3(0.628281f, 0.555802f, 0.366065f), 0.4f}, + {"Silver", Vector3(0.19225f, 0.19225f, 0.19225f), Vector3(0.50754f, 0.50754f, 0.50754f), Vector3(0.508273f, 0.508273f, 0.508273f), 0.4f}, + {"Black plastic", Vector3(0.0f, 0.0f, 0.0f), Vector3(0.01f, 0.01f, 0.01f), Vector3(0.50f, 0.50f, 0.50f), 0.25f}, + {"Cyan plastic", Vector3(0.0f, 0.1f, 0.06f), Vector3(0.0f, 0.50980392f, 0.50980392f), Vector3(0.50196078f, 0.50196078f, 0.50196078f), 0.25f}, + {"Green plastic", Vector3(0.0f, 0.0f, 0.0f), Vector3(0.1f, 0.35f, 0.1f), Vector3(0.45, 0.55, 0.45), 0.25f}, + {"Red plastic", Vector3(0.0f, 0.0f, 0.0f), Vector3(0.5f, 0.0f, 0.0f), Vector3(0.7f, 0.6f, 0.6f), 0.25f}, + {"White plastic", Vector3(0.0f, 0.0f, 0.0f), Vector3(0.55f, 0.55f, 0.55f), Vector3(0.7f, 0.7f, 0.7f), 0.25f}, + {"Yellow plastic", Vector3(0.0f, 0.0f, 0.0f), Vector3(0.5f, 0.5f, 0.0f), Vector3(0.6f, 0.6f, 0.5f), 0.25f}, + {"Black rubber", Vector3(0.02f, 0.02f, 0.02f), Vector3(0.01f, 0.01f, 0.01f), Vector3(0.4f, 0.4f, 0.4f), 0.078125f}, + {"Cyan rubber", Vector3(0.0f, 0.05f, 0.05f), Vector3(0.4f, 0.5f, 0.5f), Vector3(0.04f, 0.7f, 0.7f), 0.078125f}, + {"Green rubber", Vector3(0.0f, 0.05f, 0.0f), Vector3(0.4f, 0.5f, 0.4f), Vector3(0.04f, 0.7f, 0.04f), 0.078125f}, + {"Red rubber", Vector3(0.05f, 0.0f, 0.0f), Vector3(0.5f, 0.4f, 0.4f), Vector3(0.7f, 0.04f, 0.04f), 0.078125f}, + {"White rubber", Vector3(0.05f, 0.05f, 0.05f), Vector3(0.5f, 0.5f, 0.5f), Vector3(0.7f, 0.7f, 0.7f), 0.078125f}, + {"Yellow rubber", Vector3(0.05f, 0.05f, 0.0f), Vector3(0.5f, 0.5f, 0.4f), Vector3(0.7f, 0.7f, 0.04f), 0.078125f}}; int MaterialID = 0; +// clang-format off + /* * Vertex shader */ @@ -133,20 +133,20 @@ void main()\n gl_FragColor = vec4(result, 1.0);\n }\n ); +// clang-format on -} +} // namespace // This example shows per-pixel lighting of materials with different ambient, diffuse, specular and shininess parameters // class BasicLightController : public ConnectionTracker { public: - - BasicLightController( Application& application ) - : mApplication( application ) + BasicLightController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &BasicLightController::Create ); + mApplication.InitSignal().Connect(this, &BasicLightController::Create); } ~BasicLightController() @@ -155,27 +155,27 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::BLACK ); - mLabel = TextLabel::New( material[MaterialID].name ); - mLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mLabel.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.0f, 0.5f ) ); - mLabel.SetProperty( Actor::Property::SIZE, Vector2( window.GetSize().GetWidth() * 0.5f, window.GetSize().GetHeight() * 0.083f ) ); - mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f )); - window.Add( mLabel ); + window.SetBackgroundColor(Color::BLACK); + mLabel = TextLabel::New(material[MaterialID].name); + mLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mLabel.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 0.0f, 0.5f)); + mLabel.SetProperty(Actor::Property::SIZE, Vector2(window.GetSize().GetWidth() * 0.5f, window.GetSize().GetHeight() * 0.083f)); + mLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Vector4(1.0f, 1.0f, 1.0f, 1.0f)); + window.Add(mLabel); mButton = PushButton::New(); - mButton.SetProperty( Button::Property::LABEL, "Exit" ); - mButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mButton.ClickedSignal().Connect( this, &BasicLightController::OnExit ); - mButton.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.1f, 0.5f ) ); + mButton.SetProperty(Button::Property::LABEL, "Exit"); + mButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mButton.ClickedSignal().Connect(this, &BasicLightController::OnExit); + mButton.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 0.1f, 0.5f)); mButton.SetStyleName(CUSTOM_BASIC_LIGHT_THEME); - mButton.SetProperty( Actor::Property::COLOR, Vector4( material[MaterialID].diffuse) + Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) ); + mButton.SetProperty(Actor::Property::COLOR, Vector4(material[MaterialID].diffuse) + Vector4(0.0f, 0.0f, 0.0f, 1.0f)); window.Add(mButton); // Step 1. Create shader @@ -194,28 +194,28 @@ public: PlayAnimation(); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &BasicLightController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &BasicLightController::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &BasicLightController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &BasicLightController::OnKeyEvent); } /** * This function will change the material of the cube when touched */ - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { if(touch.GetState(0) == PointState::UP) { - MaterialID++; - MaterialID %= MATERIALS_MAX; - - mShader.SetProperty( mShader.GetPropertyIndex( "material.ambient" ), material[MaterialID].ambient ); - mShader.SetProperty( mShader.GetPropertyIndex( "material.diffuse" ), material[MaterialID].diffuse ); - mShader.SetProperty( mShader.GetPropertyIndex( "material.specular" ), material[MaterialID].specular ); - mShader.SetProperty( mShader.GetPropertyIndex( "material.shininess" ), material[MaterialID].shininess * 128.0f ); - mLabel.SetProperty( TextLabel::Property::TEXT, material[MaterialID].name ); - mButton.SetProperty( Actor::Property::COLOR, Vector4(material[MaterialID].diffuse) + Vector4(0.0f, 0.0f, 0.0f, 1.0f) ); + MaterialID++; + MaterialID %= MATERIALS_MAX; + + mShader.SetProperty(mShader.GetPropertyIndex("material.ambient"), material[MaterialID].ambient); + mShader.SetProperty(mShader.GetPropertyIndex("material.diffuse"), material[MaterialID].diffuse); + mShader.SetProperty(mShader.GetPropertyIndex("material.specular"), material[MaterialID].specular); + mShader.SetProperty(mShader.GetPropertyIndex("material.shininess"), material[MaterialID].shininess * 128.0f); + mLabel.SetProperty(TextLabel::Property::TEXT, material[MaterialID].name); + mButton.SetProperty(Actor::Property::COLOR, Vector4(material[MaterialID].diffuse) + Vector4(0.0f, 0.0f, 0.0f, 1.0f)); } return true; } @@ -223,10 +223,10 @@ public: /** * This function will the terminate the application when the exit button is pressed */ - bool OnExit( Button button ) + bool OnExit(Button button) { - mApplication.Quit(); - return true; + mApplication.Quit(); + return true; } /** @@ -235,11 +235,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -258,81 +258,68 @@ public: Vector3 aNormal; }; - const Vector3 NORMAL0(-1.0f, 0.0f, 0.0f ); - const Vector3 NORMAL1( 0.0f, 1.0f, 0.0f ); - const Vector3 NORMAL2( 0.0f,-1.0f, 0.0f ); - const Vector3 NORMAL3( 0.0f, 0.0f, 1.0f ); - const Vector3 NORMAL4( 1.0f, 0.0f, 0.0f ); - const Vector3 NORMAL5( 0.0f, 0.0f,-1.0f ); + const Vector3 NORMAL0(-1.0f, 0.0f, 0.0f); + const Vector3 NORMAL1(0.0f, 1.0f, 0.0f); + const Vector3 NORMAL2(0.0f, -1.0f, 0.0f); + const Vector3 NORMAL3(0.0f, 0.0f, 1.0f); + const Vector3 NORMAL4(1.0f, 0.0f, 0.0f); + const Vector3 NORMAL5(0.0f, 0.0f, -1.0f); Vertex vertices[] = { - { Vector3( 1.0f,-1.0f,-1.0f ), NORMAL5 }, - { Vector3( -1.0f, 1.0f,-1.0f ), NORMAL5 }, - { Vector3( 1.0f, 1.0f,-1.0f ), NORMAL5 }, - { Vector3( -1.0f, 1.0f, 1.0f ), NORMAL3 }, - { Vector3( 1.0f,-1.0f, 1.0f ), NORMAL3 }, - { Vector3( 1.0f, 1.0f, 1.0f ), NORMAL3 }, - { Vector3( 1.0f, 1.0f, 1.0f ), NORMAL4 }, - { Vector3( 1.0f,-1.0f,-1.0f ), NORMAL4 }, - { Vector3( 1.0f, 1.0f,-1.0f ), NORMAL4 }, - { Vector3( 1.0f,-1.0f, 1.0f ), NORMAL1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), NORMAL1 }, - { Vector3( 1.0f,-1.0f,-1.0f ), NORMAL1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), NORMAL0 }, - { Vector3( -1.0f, 1.0f, 1.0f ), NORMAL0 }, - { Vector3( -1.0f, 1.0f,-1.0f ), NORMAL0 }, - { Vector3( 1.0f, 1.0f,-1.0f ), NORMAL2 }, - { Vector3( -1.0f, 1.0f, 1.0f ), NORMAL2 }, - { Vector3( 1.0f, 1.0f, 1.0f ), NORMAL2 }, - { Vector3( 1.0f,-1.0f,-1.0f ), NORMAL5 }, - { Vector3( -1.0f,-1.0f,-1.0f ), NORMAL5 }, - { Vector3( -1.0f, 1.0f,-1.0f ), NORMAL5 }, - { Vector3( -1.0f, 1.0f, 1.0f ), NORMAL3 }, - { Vector3( -1.0f,-1.0f, 1.0f ), NORMAL3 }, - { Vector3( 1.0f,-1.0f, 1.0f ), NORMAL3 }, - { Vector3( 1.0f, 1.0f, 1.0f ), NORMAL4 }, - { Vector3( 1.0f,-1.0f, 1.0f ), NORMAL4 }, - { Vector3( 1.0f,-1.0f,-1.0f ), NORMAL4 }, - { Vector3( 1.0f,-1.0f, 1.0f ), NORMAL1 }, - { Vector3( -1.0f,-1.0f, 1.0f ), NORMAL1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), NORMAL1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), NORMAL0 }, - { Vector3( -1.0f,-1.0f, 1.0f ), NORMAL0 }, - { Vector3( -1.0f, 1.0f, 1.0f ), NORMAL0 }, - { Vector3( 1.0f, 1.0f,-1.0f ), NORMAL2 }, - { Vector3( -1.0f, 1.0f,-1.0f ), NORMAL2 }, - { Vector3( -1.0f, 1.0f, 1.0f ), NORMAL2 }, + {Vector3(1.0f, -1.0f, -1.0f), NORMAL5}, + {Vector3(-1.0f, 1.0f, -1.0f), NORMAL5}, + {Vector3(1.0f, 1.0f, -1.0f), NORMAL5}, + {Vector3(-1.0f, 1.0f, 1.0f), NORMAL3}, + {Vector3(1.0f, -1.0f, 1.0f), NORMAL3}, + {Vector3(1.0f, 1.0f, 1.0f), NORMAL3}, + {Vector3(1.0f, 1.0f, 1.0f), NORMAL4}, + {Vector3(1.0f, -1.0f, -1.0f), NORMAL4}, + {Vector3(1.0f, 1.0f, -1.0f), NORMAL4}, + {Vector3(1.0f, -1.0f, 1.0f), NORMAL1}, + {Vector3(-1.0f, -1.0f, -1.0f), NORMAL1}, + {Vector3(1.0f, -1.0f, -1.0f), NORMAL1}, + {Vector3(-1.0f, -1.0f, -1.0f), NORMAL0}, + {Vector3(-1.0f, 1.0f, 1.0f), NORMAL0}, + {Vector3(-1.0f, 1.0f, -1.0f), NORMAL0}, + {Vector3(1.0f, 1.0f, -1.0f), NORMAL2}, + {Vector3(-1.0f, 1.0f, 1.0f), NORMAL2}, + {Vector3(1.0f, 1.0f, 1.0f), NORMAL2}, + {Vector3(1.0f, -1.0f, -1.0f), NORMAL5}, + {Vector3(-1.0f, -1.0f, -1.0f), NORMAL5}, + {Vector3(-1.0f, 1.0f, -1.0f), NORMAL5}, + {Vector3(-1.0f, 1.0f, 1.0f), NORMAL3}, + {Vector3(-1.0f, -1.0f, 1.0f), NORMAL3}, + {Vector3(1.0f, -1.0f, 1.0f), NORMAL3}, + {Vector3(1.0f, 1.0f, 1.0f), NORMAL4}, + {Vector3(1.0f, -1.0f, 1.0f), NORMAL4}, + {Vector3(1.0f, -1.0f, -1.0f), NORMAL4}, + {Vector3(1.0f, -1.0f, 1.0f), NORMAL1}, + {Vector3(-1.0f, -1.0f, 1.0f), NORMAL1}, + {Vector3(-1.0f, -1.0f, -1.0f), NORMAL1}, + {Vector3(-1.0f, -1.0f, -1.0f), NORMAL0}, + {Vector3(-1.0f, -1.0f, 1.0f), NORMAL0}, + {Vector3(-1.0f, 1.0f, 1.0f), NORMAL0}, + {Vector3(1.0f, 1.0f, -1.0f), NORMAL2}, + {Vector3(-1.0f, 1.0f, -1.0f), NORMAL2}, + {Vector3(-1.0f, 1.0f, 1.0f), NORMAL2}, }; Property::Map property; - property.Insert( "aPosition", Property::VECTOR3 ); - property.Insert( "aNormal", Property::VECTOR3 ); + property.Insert("aPosition", Property::VECTOR3); + property.Insert("aNormal", Property::VECTOR3); - VertexBuffer vertexBuffer = VertexBuffer::New( property ); + VertexBuffer vertexBuffer = VertexBuffer::New(property); - vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vertex) ); + vertexBuffer.SetData(vertices, sizeof(vertices) / sizeof(Vertex)); // create indices const unsigned short INDEX_CUBE[] = { - 2, 1, 0, - 5, 4, 3, - 8, 7, 6, - 11, 10, 9, - 14, 13, 12, - 17, 16, 15, - 20, 19, 18, - 23, 22, 21, - 26, 25, 24, - 29, 28, 27, - 32, 31, 30, - 35, 34, 33 - }; + 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21, 26, 25, 24, 29, 28, 27, 32, 31, 30, 35, 34, 33}; mGeometry = Geometry::New(); - mGeometry.AddVertexBuffer( vertexBuffer ); - mGeometry.SetIndexBuffer( INDEX_CUBE, - sizeof(INDEX_CUBE)/sizeof(INDEX_CUBE[0]) - ); - mGeometry.SetType( Geometry::TRIANGLES ); + mGeometry.AddVertexBuffer(vertexBuffer); + mGeometry.SetIndexBuffer(INDEX_CUBE, + sizeof(INDEX_CUBE) / sizeof(INDEX_CUBE[0])); + mGeometry.SetType(Geometry::TRIANGLES); } /** @@ -343,17 +330,17 @@ public: */ void CreateCubeShader() { - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); float scale = 120.0f; - mShader.RegisterProperty( "light.position",Vector3( 1.2 * scale, scale, 2.0 * scale ) ); - mShader.RegisterProperty( "light.color", Vector3( 1.0f, 1.0f, 1.0f ) ); - mShader.RegisterProperty( "viewPos", Vector3( 0, 0, 3.0 * scale ) ); - - mShader.RegisterProperty( "material.ambient", material[MaterialID].ambient ); - mShader.RegisterProperty( "material.diffuse", material[MaterialID].diffuse ); - mShader.RegisterProperty( "material.specular", material[MaterialID].specular ); - mShader.RegisterProperty( "material.shininess", material[MaterialID].shininess * 128.0f ); + mShader.RegisterProperty("light.position", Vector3(1.2 * scale, scale, 2.0 * scale)); + mShader.RegisterProperty("light.color", Vector3(1.0f, 1.0f, 1.0f)); + mShader.RegisterProperty("viewPos", Vector3(0, 0, 3.0 * scale)); + + mShader.RegisterProperty("material.ambient", material[MaterialID].ambient); + mShader.RegisterProperty("material.diffuse", material[MaterialID].diffuse); + mShader.RegisterProperty("material.specular", material[MaterialID].specular); + mShader.RegisterProperty("material.shininess", material[MaterialID].shininess * 128.0f); } /** @@ -361,11 +348,11 @@ public: */ void CreateRenderer() { - mRenderer = Renderer::New( mGeometry, mShader ); + mRenderer = Renderer::New(mGeometry, mShader); // Face culling is enabled to hide the backwards facing sides of the cube // This is sufficient to render a single object; for more complex scenes depth-testing might be required - mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + mRenderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); } /** @@ -376,13 +363,13 @@ public: Window window = mApplication.GetWindow(); float quarterWindowWidth = window.GetSize().GetWidth() * 0.25f; - mActor = Actor::New(); - mActor.SetProperty( Actor::Property::COLOR, Vector4( 1.0f, 1.0f, 0.6f, 1.0f ) ); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::SIZE, Vector3( quarterWindowWidth, quarterWindowWidth, quarterWindowWidth ) ); - mActor.AddRenderer( mRenderer ); - window.Add( mActor ); + mActor = Actor::New(); + mActor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 1.0f, 0.6f, 1.0f)); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowWidth, quarterWindowWidth, quarterWindowWidth)); + mActor.AddRenderer(mRenderer); + window.Add(mActor); } /** @@ -390,29 +377,29 @@ public: */ void PlayAnimation() { - mAnimation = Animation::New( 15.0f ); - mAnimation.SetLooping( true ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::ZAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::XAXIS ) ); + mAnimation = Animation::New(15.0f); + mAnimation.SetLooping(true); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::ZAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::YAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::XAXIS)); mAnimation.Play(); } private: - Application& mApplication; - TextLabel mLabel; - PushButton mButton; - Renderer mRenderer; - Shader mShader; - Geometry mGeometry; - Actor mActor; - Animation mAnimation; + Application& mApplication; + TextLabel mLabel; + PushButton mButton; + Renderer mRenderer; + Shader mShader; + Geometry mGeometry; + Actor mActor; + Animation mAnimation; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, BASIC_LIGHT_THEME); - BasicLightController test( application ); + Application application = Application::New(&argc, &argv, BASIC_LIGHT_THEME); + BasicLightController test(application); application.MainLoop(); return 0; } diff --git a/examples/rendering-basic-pbr/ktx-loader.cpp b/examples/rendering-basic-pbr/ktx-loader.cpp index 13e767c..5b34fda 100644 --- a/examples/rendering-basic-pbr/ktx-loader.cpp +++ b/examples/rendering-basic-pbr/ktx-loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,31 +19,30 @@ #include "ktx-loader.h" // EXTERNAL INCLUDES +#include +#include #include -#include #include -#include -#include +#include namespace PbrDemo { - struct KtxFileHeader { - char identifier[12]; - uint32_t endianness; - uint32_t glType; //(UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5, etc.) - uint32_t glTypeSize; - uint32_t glFormat; //(RGB, RGBA, BGRA, etc.) - uint32_t glInternalFormat; //For uncompressed textures, specifies the internalformat parameter passed to glTexStorage*D or glTexImage*D - uint32_t glBaseInternalFormat; - uint32_t pixelWidth; - uint32_t pixelHeight; - uint32_t pixelDepth; - uint32_t numberOfArrayElements; - uint32_t numberOfFaces; //Cube map faces are stored in the order: +X, -X, +Y, -Y, +Z, -Z. - uint32_t numberOfMipmapLevels; - uint32_t bytesOfKeyValueData; + char identifier[12]; + uint32_t endianness; + uint32_t glType; //(UNSIGNED_BYTE, UNSIGNED_SHORT_5_6_5, etc.) + uint32_t glTypeSize; + uint32_t glFormat; //(RGB, RGBA, BGRA, etc.) + uint32_t glInternalFormat; //For uncompressed textures, specifies the internalformat parameter passed to glTexStorage*D or glTexImage*D + uint32_t glBaseInternalFormat; + uint32_t pixelWidth; + uint32_t pixelHeight; + uint32_t pixelDepth; + uint32_t numberOfArrayElements; + uint32_t numberOfFaces; //Cube map faces are stored in the order: +X, -X, +Y, -Y, +Z, -Z. + uint32_t numberOfMipmapLevels; + uint32_t bytesOfKeyValueData; }; /** @@ -51,14 +50,14 @@ struct KtxFileHeader */ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& format) { - switch( ktxPixelFormat ) + switch(ktxPixelFormat) { case 0x93B0: // GL_COMPRESSED_RGBA_ASTC_4x4_KHR { format = Dali::Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR; break; } - case 0x881B:// GL_RGB16F + case 0x881B: // GL_RGB16F { format = Dali::Pixel::RGB16F; break; @@ -92,55 +91,55 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& form return true; } -bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) +bool LoadCubeMapFromKtxFile(const std::string& path, CubeData& cubedata) { - std::unique_ptr fp(fopen(path.c_str(), "rb"), [](FILE* fp) { - if (fp) + std::unique_ptr fp(fopen(path.c_str(), "rb"), [](FILE* fp) { + if(fp) { fclose(fp); } }); - if (!fp) + if(!fp) { return false; } KtxFileHeader header; - int result = fread(&header, sizeof(KtxFileHeader), 1u, fp.get()); - if (0 == result) + int result = fread(&header, sizeof(KtxFileHeader), 1u, fp.get()); + if(0 == result) { return false; } // Skip the key-values: - if (fseek(fp.get(), header.bytesOfKeyValueData, SEEK_CUR)) + if(fseek(fp.get(), header.bytesOfKeyValueData, SEEK_CUR)) { return false; } cubedata.img.resize(header.numberOfFaces); - for (unsigned int face = 0; face < header.numberOfFaces; ++face) //array_element must be 0 or 1 + for(unsigned int face = 0; face < header.numberOfFaces; ++face) //array_element must be 0 or 1 { cubedata.img[face].resize(header.numberOfMipmapLevels); } - if (0 == header.numberOfMipmapLevels) + if(0 == header.numberOfMipmapLevels) { header.numberOfMipmapLevels = 1u; } - if (0 == header.numberOfArrayElements) + if(0 == header.numberOfArrayElements) { header.numberOfArrayElements = 1u; } - if (0 == header.pixelDepth) + if(0 == header.pixelDepth) { header.pixelDepth = 1u; } - if (0 == header.pixelHeight) + if(0 == header.pixelHeight) { header.pixelHeight = 1u; } @@ -149,25 +148,25 @@ bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ) ConvertPixelFormat(header.glInternalFormat, daliformat); - for (unsigned int mipmapLevel = 0; mipmapLevel < header.numberOfMipmapLevels; ++mipmapLevel) + for(unsigned int mipmapLevel = 0; mipmapLevel < header.numberOfMipmapLevels; ++mipmapLevel) { uint32_t byteSize = 0; - if (fread(&byteSize, sizeof(byteSize), 1u, fp.get()) != 1) + if(fread(&byteSize, sizeof(byteSize), 1u, fp.get()) != 1) { return false; } - if (0 != byteSize % 4u) + if(0 != byteSize % 4u) { byteSize += 4u - byteSize % 4u; } - for (unsigned int arrayElement = 0; arrayElement < header.numberOfArrayElements; ++arrayElement) // arrayElement must be 0 or 1 + for(unsigned int arrayElement = 0; arrayElement < header.numberOfArrayElements; ++arrayElement) // arrayElement must be 0 or 1 { - for (unsigned int face = 0; face < header.numberOfFaces; ++face) + for(unsigned int face = 0; face < header.numberOfFaces; ++face) { - std::unique_ptr img(static_cast(malloc(byteSize)), free); // resources will be freed when the PixelData is destroyed. - if (fread(img.get(), byteSize, 1u, fp.get()) != 1) + std::unique_ptr img(static_cast(malloc(byteSize)), free); // resources will be freed when the PixelData is destroyed. + if(fread(img.get(), byteSize, 1u, fp.get()) != 1) { return false; } diff --git a/examples/rendering-basic-pbr/ktx-loader.h b/examples/rendering-basic-pbr/ktx-loader.h index c805f89..771edde 100644 --- a/examples/rendering-basic-pbr/ktx-loader.h +++ b/examples/rendering-basic-pbr/ktx-loader.h @@ -2,7 +2,7 @@ #define KTX_LOADER_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,13 +26,12 @@ using namespace Dali; namespace PbrDemo { - /** * @brief Stores the pixel data objects for each face of the cube texture and their mipmaps. */ struct CubeData { - std::vector< std::vector > img; + std::vector > img; }; /** @@ -41,7 +40,7 @@ struct CubeData * @param[in] path The file path. * @param[out] cubedata The data structure with all pixel data objects. */ -bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata ); +bool LoadCubeMapFromKtxFile(const std::string& path, CubeData& cubedata); } // namespace PbrDemo diff --git a/examples/rendering-basic-pbr/model-pbr.cpp b/examples/rendering-basic-pbr/model-pbr.cpp index d570b73..094d4d4 100644 --- a/examples/rendering-basic-pbr/model-pbr.cpp +++ b/examples/rendering-basic-pbr/model-pbr.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,8 @@ // EXTERNAL INCLUDES #include -#include #include +#include // INTERNAL INCLUDES #include "obj-loader.h" @@ -40,7 +40,6 @@ struct Vertices } // namespace - ModelPbr::ModelPbr() { } @@ -49,32 +48,32 @@ ModelPbr::~ModelPbr() { } -void ModelPbr::Init( Shader shader, const std::string& modelUrl, const Vector3& position, const Vector3& size ) +void ModelPbr::Init(Shader shader, const std::string& modelUrl, const Vector3& position, const Vector3& size) { Geometry geometry; - geometry = CreateGeometry( modelUrl ); + geometry = CreateGeometry(modelUrl); - Renderer renderer = Renderer::New( geometry, shader ); + Renderer renderer = Renderer::New(geometry, shader); - if( mTextureSet ) + if(mTextureSet) { - renderer.SetTextures( mTextureSet ); + renderer.SetTextures(mTextureSet); } // Face culling is enabled to hide the backwards facing sides of the model // This is sufficient to render a single object; for more complex scenes depth-testing might be required - renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON ); - renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON ); - renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL ); - renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON); + renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON); + renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL); + renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); mActor = Actor::New(); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::POSITION, position ); - mActor.SetProperty( Actor::Property::SIZE, size ); - mActor.AddRenderer( renderer ); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::POSITION, position); + mActor.SetProperty(Actor::Property::SIZE, size); + mActor.AddRenderer(renderer); } /** @@ -83,15 +82,15 @@ void ModelPbr::Init( Shader shader, const std::string& modelUrl, const Vector3& void ModelPbr::InitTexture(Texture albedoM, Texture normalR, Texture texDiffuse, Texture texSpecular) { mTextureSet = TextureSet::New(); - mTextureSet.SetTexture( 0u, albedoM ); - mTextureSet.SetTexture( 1u, normalR ); - mTextureSet.SetTexture( 2u, texDiffuse ); - mTextureSet.SetTexture( 3u, texSpecular ); + mTextureSet.SetTexture(0u, albedoM); + mTextureSet.SetTexture(1u, normalR); + mTextureSet.SetTexture(2u, texDiffuse); + mTextureSet.SetTexture(3u, texSpecular); Sampler sampler = Sampler::New(); - sampler.SetWrapMode(WrapMode::CLAMP_TO_EDGE,WrapMode::CLAMP_TO_EDGE,WrapMode::CLAMP_TO_EDGE); - sampler.SetFilterMode(FilterMode::LINEAR_MIPMAP_LINEAR,FilterMode::LINEAR); - mTextureSet.SetSampler(3,sampler); + sampler.SetWrapMode(WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE); + sampler.SetFilterMode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR); + mTextureSet.SetSampler(3, sampler); } Actor& ModelPbr::GetActor() @@ -102,21 +101,21 @@ Actor& ModelPbr::GetActor() /** * Create geometry from OBJ path file */ -Geometry ModelPbr::CreateGeometry( const std::string& url ) +Geometry ModelPbr::CreateGeometry(const std::string& url) { - std::streampos fileSize; + std::streampos fileSize; Dali::Vector fileContent; Geometry geometry; - if( FileLoader::ReadFile( url, fileSize, fileContent, FileLoader::TEXT ) ) + if(FileLoader::ReadFile(url, fileSize, fileContent, FileLoader::TEXT)) { PbrDemo::ObjLoader objLoader; objLoader.ClearArrays(); - objLoader.LoadObject( fileContent.Begin(), fileSize ); + objLoader.LoadObject(fileContent.Begin(), fileSize); - geometry = objLoader.CreateGeometry( PbrDemo::ObjLoader::TEXTURE_COORDINATES | PbrDemo::ObjLoader::TANGENTS, true ); + geometry = objLoader.CreateGeometry(PbrDemo::ObjLoader::TEXTURE_COORDINATES | PbrDemo::ObjLoader::TANGENTS, true); } return geometry; diff --git a/examples/rendering-basic-pbr/model-pbr.h b/examples/rendering-basic-pbr/model-pbr.h index 9cc956a..32cee9a 100644 --- a/examples/rendering-basic-pbr/model-pbr.h +++ b/examples/rendering-basic-pbr/model-pbr.h @@ -2,7 +2,7 @@ #define DALI_DEMO_MODELPBR_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ public: * @param[in] position The position of the actor. * @param[in] size The size of the actor. */ - void Init( Shader shader, const std::string& modelUrl, const Vector3& position, const Vector3& size ); + void Init(Shader shader, const std::string& modelUrl, const Vector3& position, const Vector3& size); /** * @brief Initializes the @p mTextureSet member with the needed textures for Physically Based Rendering. @@ -67,17 +67,16 @@ public: * @param[in] diffuseTexture The diffuse texture. * @param[in] specularTexture The specular texture. */ - void InitTexture( Texture albedoMetalTexture, Texture normalRoughTexture, Texture diffuseTexture, Texture specularTexture ); + void InitTexture(Texture albedoMetalTexture, Texture normalRoughTexture, Texture diffuseTexture, Texture specularTexture); /** * @brief Retrieves the actor created by calling the Init() method. * * @return The Actor for the Physically Based Rendering. */ - Actor &GetActor(); + Actor& GetActor(); private: - /** * @brief Creates a geometry from a @e obj model. * @@ -85,11 +84,10 @@ private: * * @return The geometry. */ - Geometry CreateGeometry( const std::string& url ); + Geometry CreateGeometry(const std::string& url); - Actor mActor; + Actor mActor; TextureSet mTextureSet; }; #endif // DALI_DEMO_MODELPBR_H - diff --git a/examples/rendering-basic-pbr/model-skybox.cpp b/examples/rendering-basic-pbr/model-skybox.cpp index d3296d2..31cc654 100644 --- a/examples/rendering-basic-pbr/model-skybox.cpp +++ b/examples/rendering-basic-pbr/model-skybox.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,16 @@ // EXTERNAL INCLUDES #include -#include #include +#include // INTERNAL INCLUDES #include "obj-loader.h" namespace { +// clang-format off + /* * Vertex shader for a skybox */ @@ -61,10 +63,10 @@ void main()\n gl_FragColor = texColor;\n }\n ); +// clang-format on } // namespace - ModelSkybox::ModelSkybox() { } @@ -73,31 +75,30 @@ ModelSkybox::~ModelSkybox() { } -void ModelSkybox::Init( const Vector3& size ) +void ModelSkybox::Init(const Vector3& size) { - Geometry geometry = CreateGeometry(); - Shader shader = Shader::New( VERTEX_SHADER_SKYBOX, FRAGMENT_SHADER_SKYBOX ); + Shader shader = Shader::New(VERTEX_SHADER_SKYBOX, FRAGMENT_SHADER_SKYBOX); - Renderer renderer = Renderer::New( geometry, shader ); + Renderer renderer = Renderer::New(geometry, shader); - if( mTextureSet ) + if(mTextureSet) { - renderer.SetTextures( mTextureSet ); + renderer.SetTextures(mTextureSet); } // Face culling is enabled to hide the backwards facing sides of the model // This is sufficient to render a single object; for more complex scenes depth-testing might be required - renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON ); - renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON ); - renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL ); - renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON); + renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON); + renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL); + renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); mActor = Actor::New(); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::SIZE, size ); - mActor.AddRenderer( renderer ); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::SIZE, size); + mActor.AddRenderer(renderer); } /** @@ -106,12 +107,12 @@ void ModelSkybox::Init( const Vector3& size ) void ModelSkybox::InitTexture(Texture texSkybox) { mTextureSet = TextureSet::New(); - mTextureSet.SetTexture( 0u, texSkybox ); + mTextureSet.SetTexture(0u, texSkybox); Sampler sampler = Sampler::New(); - sampler.SetWrapMode(WrapMode::CLAMP_TO_EDGE,WrapMode::CLAMP_TO_EDGE,WrapMode::CLAMP_TO_EDGE); - sampler.SetFilterMode(FilterMode::LINEAR_MIPMAP_LINEAR,FilterMode::LINEAR); - mTextureSet.SetSampler(0,sampler); + sampler.SetWrapMode(WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE); + sampler.SetFilterMode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR); + mTextureSet.SetSampler(0, sampler); } Actor& ModelSkybox::GetActor() @@ -119,7 +120,6 @@ Actor& ModelSkybox::GetActor() return mActor; } - /** * @brief CreateGeometry * This function creates a cube geometry including texture coordinates. @@ -134,61 +134,60 @@ Geometry ModelSkybox::CreateGeometry() }; Vertex skyboxVertices[] = { - // back - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - - // left - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( -1.0f, -1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, 1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - - // right - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - - // front - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( -1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, -1.0f, 1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - - // botton - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( 1.0f, 1.0f, -1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( -1.0f, 1.0f, 1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - - // top - { Vector3( -1.0f, -1.0f, -1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( 1.0f, -1.0f, 1.0f ) } - }; - - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR3 ) ); - vertexBuffer.SetData( skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex) ); + // back + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + + // left + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(-1.0f, -1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, 1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + + // right + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + + // front + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(-1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, -1.0f, 1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + + // botton + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(1.0f, 1.0f, -1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(-1.0f, 1.0f, 1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + + // top + {Vector3(-1.0f, -1.0f, -1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(1.0f, -1.0f, 1.0f)}}; + + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3)); + vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex)); geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLES ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLES); return geometry; } diff --git a/examples/rendering-basic-pbr/model-skybox.h b/examples/rendering-basic-pbr/model-skybox.h index befddff..2c52f37 100644 --- a/examples/rendering-basic-pbr/model-skybox.h +++ b/examples/rendering-basic-pbr/model-skybox.h @@ -2,7 +2,7 @@ #define DALI_DEMO_MODELSKYBOX_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ public: * @param[in] position The position of the actor. * @param[in] size The size of the actor. */ - void Init( const Vector3& size ); + void Init(const Vector3& size); /** * @brief Initializes the @p mTextureSet member with the needed textures for Physically Based Rendering. @@ -67,17 +67,16 @@ public: * @param[in] diffuseTexture The diffuse texture. * @param[in] specularTexture The specular texture. */ - void InitTexture( Texture texSkybox ); + void InitTexture(Texture texSkybox); /** * @brief Retrieves the actor created by calling the Init() method. * * @return The Actor for the Physically Based Rendering. */ - Actor &GetActor(); + Actor& GetActor(); private: - /** * @brief Creates a geometry from a @e obj model. * @@ -87,9 +86,8 @@ private: */ Geometry CreateGeometry(); - Actor mActor; + Actor mActor; TextureSet mTextureSet; }; #endif // DALI_DEMO_MODELSKYBOX_H - diff --git a/examples/rendering-basic-pbr/obj-loader.cpp b/examples/rendering-basic-pbr/obj-loader.cpp index 82ffa6a..32947e1 100644 --- a/examples/rendering-basic-pbr/obj-loader.cpp +++ b/examples/rendering-basic-pbr/obj-loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,24 +20,23 @@ // EXTERNAL INCLUDES #include -#include #include +#include namespace PbrDemo { - namespace { const int MAX_POINT_INDICES = 4; } ObjLoader::ObjLoader() -: mSceneLoaded( false ), - mMaterialLoaded( false ), - mHasTextureUv( false ), - mHasDiffuseMap( false ), - mHasNormalMap( false ), - mHasSpecularMap( false ) +: mSceneLoaded(false), + mMaterialLoaded(false), + mHasTextureUv(false), + mHasDiffuseMap(false), + mHasNormalMap(false), + mHasSpecularMap(false) { mSceneAABB.Init(); } @@ -57,17 +56,16 @@ bool ObjLoader::IsMaterialLoaded() return mMaterialLoaded; } -void ObjLoader::CalculateHardFaceNormals( const Dali::Vector& points, Dali::Vector& triangles, - Dali::Vector& normals ) +void ObjLoader::CalculateHardFaceNormals(const Dali::Vector& points, Dali::Vector& triangles, Dali::Vector& normals) { - int numFaceVertices = 3 * triangles.Size(); //Vertices per face, as each vertex has different normals instance for each face. - int normalIndex = 0; //Tracks progress through the array of normals. + int numFaceVertices = 3 * triangles.Size(); //Vertices per face, as each vertex has different normals instance for each face. + int normalIndex = 0; //Tracks progress through the array of normals. normals.Clear(); - normals.Resize( numFaceVertices ); + normals.Resize(numFaceVertices); //For each triangle, calculate the normal by crossing two vectors on the triangle's plane. - for( unsigned long i = 0; i < triangles.Size(); i++ ) + for(unsigned long i = 0; i < triangles.Size(); i++) { //Triangle vertices. const Vector3& v0 = points[triangles[i].pointIndex[0]]; @@ -83,25 +81,24 @@ void ObjLoader::CalculateHardFaceNormals( const Dali::Vector& points, D normalVector.Normalize(); //Assign normal index to triangle vertex and set the normal vector to the list of normals. - for( unsigned long j = 0; j < 3; j++, normalIndex++ ) + for(unsigned long j = 0; j < 3; j++, normalIndex++) { triangles[i].normalIndex[j] = normalIndex; - normals[normalIndex] = normalVector; + normals[normalIndex] = normalVector; } } } -void ObjLoader::CalculateSoftFaceNormals( const Dali::Vector& points, Dali::Vector& triangles, - Dali::Vector& normals ) +void ObjLoader::CalculateSoftFaceNormals(const Dali::Vector& points, Dali::Vector& triangles, Dali::Vector& normals) { - int normalIndex = 0; //Tracks progress through the array of normals. + int normalIndex = 0; //Tracks progress through the array of normals. normals.Clear(); - normals.Resize( points.Size() ); //One (averaged) normal per point. + normals.Resize(points.Size()); //One (averaged) normal per point. //For each triangle, calculate the normal by crossing two vectors on the triangle's plane //We then add the triangle's normal to the cumulative normals at each point of it - for( unsigned long i = 0; i < triangles.Size(); i++ ) + for(unsigned long i = 0; i < triangles.Size(); i++) { //Triangle points. const Vector3& v0 = points[triangles[i].pointIndex[0]]; @@ -116,16 +113,16 @@ void ObjLoader::CalculateSoftFaceNormals( const Dali::Vector& points, D Vector3 normalVector = edge1.Cross(edge2); //Add this triangle's normal to the cumulative normal of each constituent triangle point and set the index of the normal accordingly. - for( unsigned long j = 0; j < 3; j++) + for(unsigned long j = 0; j < 3; j++) { - normalIndex = triangles[i].pointIndex[j]; + normalIndex = triangles[i].pointIndex[j]; triangles[i].normalIndex[j] = normalIndex; //Normal index matches up to vertex index, as one normal per vertex. normals[normalIndex] += normalVector; } } //Normalise the normals. - for( unsigned long i = 0; i < normals.Size(); i++ ) + for(unsigned long i = 0; i < normals.Size(); i++) { normals[i].Normalize(); } @@ -135,10 +132,10 @@ void ObjLoader::CalculateTangentFrame() { //Reset tangent vector to hold new values. mTangents.Clear(); - mTangents.Resize( mNormals.Size() ); + mTangents.Resize(mNormals.Size()); //For each triangle, calculate the tangent vector and then add it to the total tangent vector of each normal. - for ( unsigned long a = 0; a < mTriangles.Size(); a++ ) + for(unsigned long a = 0; a < mTriangles.Size(); a++) { Vector3 tangentVector; @@ -162,9 +159,9 @@ void ObjLoader::CalculateTangentFrame() // as a weight of the tangent vector and it is fixed when it is normalised. float f = (deltaU1 * deltaV2 - deltaU2 * deltaV1); - tangentVector.x = f * ( deltaV2 * edge1.x - deltaV1 * edge2.x ); - tangentVector.y = f * ( deltaV2 * edge1.y - deltaV1 * edge2.y ); - tangentVector.z = f * ( deltaV2 * edge1.z - deltaV1 * edge2.z ); + tangentVector.x = f * (deltaV2 * edge1.x - deltaV1 * edge2.x); + tangentVector.y = f * (deltaV2 * edge1.y - deltaV1 * edge2.y); + tangentVector.z = f * (deltaV2 * edge1.z - deltaV1 * edge2.z); mTangents[mTriangles[a].normalIndex[0]] += tangentVector; mTangents[mTriangles[a].normalIndex[1]] += tangentVector; @@ -172,7 +169,7 @@ void ObjLoader::CalculateTangentFrame() } //Orthogonalize tangents. - for ( unsigned long a = 0; a < mTangents.Size(); a++ ) + for(unsigned long a = 0; a < mTangents.Size(); a++) { const Vector3& n = mNormals[a]; const Vector3& t = mTangents[a]; @@ -183,24 +180,24 @@ void ObjLoader::CalculateTangentFrame() } } -void ObjLoader::CenterAndScale( bool center, Dali::Vector& points ) +void ObjLoader::CenterAndScale(bool center, Dali::Vector& points) { BoundingVolume newAABB; Vector3 sceneSize = GetSize(); float biggestDimension = sceneSize.x; - if( sceneSize.y > biggestDimension ) + if(sceneSize.y > biggestDimension) { biggestDimension = sceneSize.y; } - if( sceneSize.z > biggestDimension ) + if(sceneSize.z > biggestDimension) { biggestDimension = sceneSize.z; } newAABB.Init(); - for( unsigned int ui = 0; ui < points.Size(); ++ui ) + for(unsigned int ui = 0; ui < points.Size(); ++ui) { points[ui] = points[ui] - GetCenter(); points[ui] = points[ui] / biggestDimension; @@ -210,15 +207,15 @@ void ObjLoader::CenterAndScale( bool center, Dali::Vector& points ) mSceneAABB = newAABB; } -void ObjLoader::CreateGeometryArray( Dali::Vector& positions, - Dali::Vector& normals, - Dali::Vector& tangents, - Dali::Vector& textures, - Dali::Vector & indices, - bool useSoftNormals ) +void ObjLoader::CreateGeometryArray(Dali::Vector& positions, + Dali::Vector& normals, + Dali::Vector& tangents, + Dali::Vector& textures, + Dali::Vector& indices, + bool useSoftNormals) { //We must calculate the tangents if they weren't supplied, or if they don't match up. - bool mustCalculateTangents = ( mTangents.Size() == 0 ) || ( mTangents.Size() != mNormals.Size() ); + bool mustCalculateTangents = (mTangents.Size() == 0) || (mTangents.Size() != mNormals.Size()); //However, we don't need to do this if the object doesn't use textures to begin with. mustCalculateTangents &= mHasTextureUv; @@ -227,44 +224,44 @@ void ObjLoader::CreateGeometryArray( Dali::Vector& positions, // Use the normals provided by the file to make the tangent calculation per normal, // the correct results depends of normal generated by file, otherwise we need to recalculate // the normal programmatically. - if( ( ( mNormals.Size() == 0 ) && mustCalculateTangents ) || !useSoftNormals ) + if(((mNormals.Size() == 0) && mustCalculateTangents) || !useSoftNormals) { - if( useSoftNormals ) + if(useSoftNormals) { - CalculateSoftFaceNormals( mPoints, mTriangles, mNormals ); + CalculateSoftFaceNormals(mPoints, mTriangles, mNormals); } else { - CalculateHardFaceNormals( mPoints, mTriangles, mNormals ); + CalculateHardFaceNormals(mPoints, mTriangles, mNormals); } } - if( mHasTextureUv && mustCalculateTangents ) + if(mHasTextureUv && mustCalculateTangents) { CalculateTangentFrame(); } bool mapsCorrespond; //True if the sizes of the arrays necessary to draw the object match. - if ( mHasTextureUv ) + if(mHasTextureUv) { - mapsCorrespond = ( mPoints.Size() == mTextureUv.Size() ) && ( mTextureUv.Size() == mNormals.Size() ); + mapsCorrespond = (mPoints.Size() == mTextureUv.Size()) && (mTextureUv.Size() == mNormals.Size()); } else { - mapsCorrespond = ( mPoints.Size() == mNormals.Size() ); + mapsCorrespond = (mPoints.Size() == mNormals.Size()); } //Check the number of points textures and normals - if ( mapsCorrespond ) + if(mapsCorrespond) { - int numPoints = mPoints.Size(); + int numPoints = mPoints.Size(); int numIndices = 3 * mTriangles.Size(); - positions.Resize( numPoints ); - normals.Resize( numPoints ); - tangents.Resize( numPoints ); - textures.Resize( numPoints ); - indices.Resize( numIndices ); + positions.Resize(numPoints); + normals.Resize(numPoints); + tangents.Resize(numPoints); + textures.Resize(numPoints); + indices.Resize(numIndices); //We create the vertices array. For now we just copy points info positions = mPoints; @@ -272,16 +269,16 @@ void ObjLoader::CreateGeometryArray( Dali::Vector& positions, int indiceIndex = 0; //We copy the indices - for ( unsigned int ui = 0 ; ui < mTriangles.Size() ; ++ui ) + for(unsigned int ui = 0; ui < mTriangles.Size(); ++ui) { - for ( int j = 0 ; j < 3 ; ++j ) + for(int j = 0; j < 3; ++j) { indices[indiceIndex] = mTriangles[ui].pointIndex[j]; indiceIndex++; normals[mTriangles[ui].pointIndex[j]] = mNormals[mTriangles[ui].normalIndex[j]]; - if ( mHasTextureUv ) + if(mHasTextureUv) { textures[mTriangles[ui].pointIndex[j]] = mTextureUv[mTriangles[ui].textureIndex[j]]; tangents[mTriangles[ui].pointIndex[j]] = mTangents[mTriangles[ui].normalIndex[j]]; @@ -292,22 +289,22 @@ void ObjLoader::CreateGeometryArray( Dali::Vector& positions, else { int numVertices = 3 * mTriangles.Size(); - positions.Resize( numVertices ); - normals.Resize( numVertices ); - textures.Resize( numVertices ); - tangents.Resize( numVertices ); + positions.Resize(numVertices); + normals.Resize(numVertices); + textures.Resize(numVertices); + tangents.Resize(numVertices); int index = 0; //We have to normalize the arrays so we can draw we just one index array - for( unsigned int ui = 0; ui < mTriangles.Size(); ++ui ) + for(unsigned int ui = 0; ui < mTriangles.Size(); ++ui) { - for ( int j = 0 ; j < 3 ; ++j ) + for(int j = 0; j < 3; ++j) { positions[index] = mPoints[mTriangles[ui].pointIndex[j]]; - normals[index] = mNormals[mTriangles[ui].normalIndex[j]]; + normals[index] = mNormals[mTriangles[ui].normalIndex[j]]; - if( mHasTextureUv ) + if(mHasTextureUv) { textures[index] = mTextureUv[mTriangles[ui].textureIndex[j]]; tangents[index] = mTangents[mTriangles[ui].normalIndex[j]]; @@ -319,95 +316,94 @@ void ObjLoader::CreateGeometryArray( Dali::Vector& positions, } } -bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize ) +bool ObjLoader::LoadObject(char* objBuffer, std::streampos fileSize) { - Vector3 point; - Vector2 texture; + Vector3 point; + Vector2 texture; std::string vet[MAX_POINT_INDICES], name; - int ptIdx[MAX_POINT_INDICES]; - int nrmIdx[MAX_POINT_INDICES]; - int texIdx[MAX_POINT_INDICES]; - TriIndex triangle,triangle2; - int pntAcum = 0, texAcum = 0, nrmAcum = 0; - bool iniObj = false; - bool hasTexture = false; - int face = 0; + int ptIdx[MAX_POINT_INDICES]; + int nrmIdx[MAX_POINT_INDICES]; + int texIdx[MAX_POINT_INDICES]; + TriIndex triangle, triangle2; + int pntAcum = 0, texAcum = 0, nrmAcum = 0; + bool iniObj = false; + bool hasTexture = false; + int face = 0; //Init AABB for the file mSceneAABB.Init(); std::string strMatActual; - std::string input( objBuffer, fileSize ); + std::string input(objBuffer, fileSize); std::istringstream ss(input); - ss.imbue( std::locale( "C" ) ); - + ss.imbue(std::locale("C")); std::string line; - std::getline( ss, line ); + std::getline(ss, line); - while ( std::getline( ss, line ) ) + while(std::getline(ss, line)) { - std::istringstream isline( line, std::istringstream::in ); - std::string tag; + std::istringstream isline(line, std::istringstream::in); + std::string tag; isline >> tag; - if ( tag == "v" ) + if(tag == "v") { //Two different objects in the same file isline >> point.x; isline >> point.y; isline >> point.z; - mPoints.PushBack( point ); + mPoints.PushBack(point); - mSceneAABB.ConsiderNewPointInVolume( point ); + mSceneAABB.ConsiderNewPointInVolume(point); } - else if ( tag == "vn" ) + else if(tag == "vn") { isline >> point.x; isline >> point.y; isline >> point.z; - mNormals.PushBack( point ); + mNormals.PushBack(point); } - else if ( tag == "#_#tangent" ) + else if(tag == "#_#tangent") { isline >> point.x; isline >> point.y; isline >> point.z; - mTangents.PushBack( point ); + mTangents.PushBack(point); } - else if ( tag == "#_#binormal" ) + else if(tag == "#_#binormal") { isline >> point.x; isline >> point.y; isline >> point.z; - mBiTangents.PushBack( point ); + mBiTangents.PushBack(point); } - else if ( tag == "vt" ) + else if(tag == "vt") { isline >> texture.x; isline >> texture.y; - texture.y = 1.0-texture.y; - mTextureUv.PushBack( texture ); + texture.y = 1.0 - texture.y; + mTextureUv.PushBack(texture); } - else if ( tag == "#_#vt1" ) + else if(tag == "#_#vt1") { isline >> texture.x; isline >> texture.y; - texture.y = 1.0-texture.y; - mTextureUv2.PushBack( texture ); + texture.y = 1.0 - texture.y; + mTextureUv2.PushBack(texture); } - else if ( tag == "s" ) + else if(tag == "s") { } - else if ( tag == "f" ) + else if(tag == "f") { - if ( !iniObj ) + if(!iniObj) { //name assign @@ -415,7 +411,7 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize ) } int numIndices = 0; - while( ( numIndices < MAX_POINT_INDICES ) && ( isline >> vet[numIndices] ) ) + while((numIndices < MAX_POINT_INDICES) && (isline >> vet[numIndices])) { numIndices++; } @@ -424,26 +420,26 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize ) char separator; char separator2; - const char * subString; //A pointer to the position in the string as we move through it. + const char* subString; //A pointer to the position in the string as we move through it. - subString = strstr( vet[0].c_str(),"/" ); //Search for the first '/' + subString = strstr(vet[0].c_str(), "/"); //Search for the first '/' - if( subString ) + if(subString) { - if( subString[1] == '/' ) // Of the form A//C, so has points and normals but no texture coordinates. + if(subString[1] == '/') // Of the form A//C, so has points and normals but no texture coordinates. { - for( int i = 0 ; i < numIndices; i++) + for(int i = 0; i < numIndices; i++) { - std::istringstream isindex( vet[i] ); + std::istringstream isindex(vet[i]); isindex >> ptIdx[i] >> separator >> separator2 >> nrmIdx[i]; texIdx[i] = 0; } } - else if( strstr( subString, "/" ) ) // Of the form A/B/C, so has points, textures and normals. + else if(strstr(subString, "/")) // Of the form A/B/C, so has points, textures and normals. { - for( int i = 0 ; i < numIndices; i++ ) + for(int i = 0; i < numIndices; i++) { - std::istringstream isindex( vet[i] ); + std::istringstream isindex(vet[i]); isindex >> ptIdx[i] >> separator >> texIdx[i] >> separator2 >> nrmIdx[i]; } @@ -451,9 +447,9 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize ) } else // Of the form A/B, so has points and textures but no normals. { - for( int i = 0 ; i < numIndices; i++ ) + for(int i = 0; i < numIndices; i++) { - std::istringstream isindex( vet[i] ); + std::istringstream isindex(vet[i]); isindex >> ptIdx[i] >> separator >> texIdx[i]; nrmIdx[i] = 0; } @@ -463,9 +459,9 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize ) } else // Simply of the form A, as in, point indices only. { - for( int i = 0 ; i < numIndices; i++ ) + for(int i = 0; i < numIndices; i++) { - std::istringstream isindex( vet[i] ); + std::istringstream isindex(vet[i]); isindex >> ptIdx[i]; texIdx[i] = 0; nrmIdx[i] = 0; @@ -473,58 +469,58 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize ) } //If it is a triangle - if( numIndices == 3 ) + if(numIndices == 3) { - for( int i = 0 ; i < 3; i++ ) + for(int i = 0; i < 3; i++) { - triangle.pointIndex[i] = ptIdx[i] - 1 - pntAcum; - triangle.normalIndex[i] = nrmIdx[i] - 1 - nrmAcum; + triangle.pointIndex[i] = ptIdx[i] - 1 - pntAcum; + triangle.normalIndex[i] = nrmIdx[i] - 1 - nrmAcum; triangle.textureIndex[i] = texIdx[i] - 1 - texAcum; } - mTriangles.PushBack( triangle ); + mTriangles.PushBack(triangle); face++; } //If on the other hand it is a quad, we will create two triangles - else if( numIndices == 4 ) + else if(numIndices == 4) { - for( int i = 0 ; i < 3; i++ ) + for(int i = 0; i < 3; i++) { - triangle.pointIndex[i] = ptIdx[i] - 1 - pntAcum; - triangle.normalIndex[i] = nrmIdx[i] - 1 - nrmAcum; + triangle.pointIndex[i] = ptIdx[i] - 1 - pntAcum; + triangle.normalIndex[i] = nrmIdx[i] - 1 - nrmAcum; triangle.textureIndex[i] = texIdx[i] - 1 - texAcum; } - mTriangles.PushBack( triangle ); + mTriangles.PushBack(triangle); face++; - for( int i = 0 ; i < 3; i++ ) + for(int i = 0; i < 3; i++) { - int idx = ( i + 2 ) % numIndices; - triangle2.pointIndex[i] = ptIdx[idx] - 1 - pntAcum; - triangle2.normalIndex[i] = nrmIdx[idx] - 1 - nrmAcum; + int idx = (i + 2) % numIndices; + triangle2.pointIndex[i] = ptIdx[idx] - 1 - pntAcum; + triangle2.normalIndex[i] = nrmIdx[idx] - 1 - nrmAcum; triangle2.textureIndex[i] = texIdx[idx] - 1 - texAcum; } - mTriangles.PushBack( triangle2 ); + mTriangles.PushBack(triangle2); face++; } } - else if ( tag == "usemtl" ) + else if(tag == "usemtl") { isline >> strMatActual; } - else if ( tag == "mtllib" ) + else if(tag == "mtllib") { isline >> strMatActual; } - else if ( tag == "g" ) + else if(tag == "g") { isline >> name; } } - if ( iniObj ) + if(iniObj) { - CenterAndScale( true, mPoints ); - mSceneLoaded = true; + CenterAndScale(true, mPoints); + mSceneLoaded = true; mHasTextureUv = hasTexture; return true; } @@ -532,65 +528,65 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize ) return false; } -void ObjLoader::LoadMaterial( char* objBuffer, - std::streampos fileSize, - std::string& diffuseTextureUrl, - std::string& normalTextureUrl, - std::string& glossTextureUrl ) +void ObjLoader::LoadMaterial(char* objBuffer, + std::streampos fileSize, + std::string& diffuseTextureUrl, + std::string& normalTextureUrl, + std::string& glossTextureUrl) { - float fR,fG,fB; + float fR, fG, fB; std::string info; - std::string input = objBuffer; + std::string input = objBuffer; std::istringstream ss(input); ss.imbue(std::locale("C")); std::string line; - std::getline( ss, line ); + std::getline(ss, line); - while ( std::getline( ss, line ) ) + while(std::getline(ss, line)) { - std::istringstream isline( line, std::istringstream::in ); - std::string tag; + std::istringstream isline(line, std::istringstream::in); + std::string tag; isline >> tag; - if ( tag == "newmtl" ) //name of the material + if(tag == "newmtl") //name of the material { isline >> info; } - else if ( tag == "Ka" ) //ambient color + else if(tag == "Ka") //ambient color { isline >> fR >> fG >> fB; } - else if ( tag == "Kd" ) //diffuse color + else if(tag == "Kd") //diffuse color { isline >> fR >> fG >> fB; } - else if ( tag == "Ks" ) //specular color + else if(tag == "Ks") //specular color { isline >> fR >> fG >> fB; } - else if ( tag == "Tf" ) //color + else if(tag == "Tf") //color { } - else if ( tag == "Ni" ) + else if(tag == "Ni") { } - else if ( tag == "map_Kd" ) + else if(tag == "map_Kd") { isline >> info; diffuseTextureUrl = info; - mHasDiffuseMap = true; + mHasDiffuseMap = true; } - else if ( tag == "bump" ) + else if(tag == "bump") { isline >> info; normalTextureUrl = info; - mHasNormalMap = true; + mHasNormalMap = true; } - else if ( tag == "map_Ks" ) + else if(tag == "map_Ks") { isline >> info; glossTextureUrl = info; @@ -601,59 +597,59 @@ void ObjLoader::LoadMaterial( char* objBuffer, mMaterialLoaded = true; } -Geometry ObjLoader::CreateGeometry( int objectProperties, bool useSoftNormals ) +Geometry ObjLoader::CreateGeometry(int objectProperties, bool useSoftNormals) { Geometry surface = Geometry::New(); - Dali::Vector positions; - Dali::Vector normals; - Dali::Vector tangents; - Dali::Vector textures; + Dali::Vector positions; + Dali::Vector normals; + Dali::Vector tangents; + Dali::Vector textures; Dali::Vector indices; - CreateGeometryArray( positions, normals, tangents, textures, indices, useSoftNormals ); + CreateGeometryArray(positions, normals, tangents, textures, indices, useSoftNormals); //All vertices need at least Position and Normal Property::Map positionMap; - positionMap["aPosition"] = Property::VECTOR3; - VertexBuffer positionBuffer = VertexBuffer::New( positionMap ); - positionBuffer.SetData( positions.Begin(), positions.Count() ); + positionMap["aPosition"] = Property::VECTOR3; + VertexBuffer positionBuffer = VertexBuffer::New(positionMap); + positionBuffer.SetData(positions.Begin(), positions.Count()); Property::Map normalMap; - normalMap["aNormal"] = Property::VECTOR3; - VertexBuffer normalBuffer = VertexBuffer::New( normalMap ); - normalBuffer.SetData( normals.Begin(), normals.Count() ); + normalMap["aNormal"] = Property::VECTOR3; + VertexBuffer normalBuffer = VertexBuffer::New(normalMap); + normalBuffer.SetData(normals.Begin(), normals.Count()); - surface.AddVertexBuffer( positionBuffer ); - surface.AddVertexBuffer( normalBuffer ); + surface.AddVertexBuffer(positionBuffer); + surface.AddVertexBuffer(normalBuffer); //Some need tangent - if( ( objectProperties & TANGENTS ) && mHasTextureUv ) + if((objectProperties & TANGENTS) && mHasTextureUv) { Property::Map tangentMap; - tangentMap["aTangent"] = Property::VECTOR3; - VertexBuffer tangentBuffer = VertexBuffer::New( tangentMap ); - tangentBuffer.SetData( tangents.Begin(), tangents.Count() ); + tangentMap["aTangent"] = Property::VECTOR3; + VertexBuffer tangentBuffer = VertexBuffer::New(tangentMap); + tangentBuffer.SetData(tangents.Begin(), tangents.Count()); - surface.AddVertexBuffer( tangentBuffer ); + surface.AddVertexBuffer(tangentBuffer); } //Some need texture coordinates - if( ( objectProperties & TEXTURE_COORDINATES ) && mHasTextureUv ) + if((objectProperties & TEXTURE_COORDINATES) && mHasTextureUv) { Property::Map textCoordMap; - textCoordMap["aTexCoord"] = Property::VECTOR2; - VertexBuffer texCoordBuffer = VertexBuffer::New( textCoordMap ); - texCoordBuffer.SetData( textures.Begin(), textures.Count() ); + textCoordMap["aTexCoord"] = Property::VECTOR2; + VertexBuffer texCoordBuffer = VertexBuffer::New(textCoordMap); + texCoordBuffer.SetData(textures.Begin(), textures.Count()); - surface.AddVertexBuffer( texCoordBuffer ); + surface.AddVertexBuffer(texCoordBuffer); } //If indices are required, we set them. - if ( indices.Size() ) + if(indices.Size()) { - surface.SetIndexBuffer ( &indices[0], indices.Size() ); + surface.SetIndexBuffer(&indices[0], indices.Size()); } return surface; diff --git a/examples/rendering-basic-pbr/obj-loader.h b/examples/rendering-basic-pbr/obj-loader.h index 11d289c..26f45b4 100644 --- a/examples/rendering-basic-pbr/obj-loader.h +++ b/examples/rendering-basic-pbr/obj-loader.h @@ -2,7 +2,7 @@ #define DALI_DEMO_PBR_OBJ_LOADER_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,11 +26,9 @@ using namespace Dali; namespace PbrDemo { - class ObjLoader { public: - struct TriIndex { int pointIndex[3]; @@ -42,19 +40,19 @@ public: { void Init() { - pointMin = Vector3( std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max() ); - pointMax = Vector3( std::numeric_limits::min(), std::numeric_limits::min(), std::numeric_limits::min() ); + pointMin = Vector3(std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()); + pointMax = Vector3(std::numeric_limits::min(), std::numeric_limits::min(), std::numeric_limits::min()); } - void ConsiderNewPointInVolume( const Vector3& position ) + void ConsiderNewPointInVolume(const Vector3& position) { - pointMin.x = std::min( position.x, pointMin.x ); - pointMin.y = std::min( position.y, pointMin.y ); - pointMin.z = std::min( position.z, pointMin.z ); + pointMin.x = std::min(position.x, pointMin.x); + pointMin.y = std::min(position.y, pointMin.y); + pointMin.z = std::min(position.z, pointMin.z); - pointMax.x = std::max( position.x, pointMax.x ); - pointMax.y = std::max( position.y, pointMax.y ); - pointMax.z = std::max( position.z, pointMax.z ); + pointMax.x = std::max(position.x, pointMax.x); + pointMax.y = std::max(position.y, pointMax.y); + pointMax.z = std::max(position.z, pointMax.z); } Vector3 pointMin; @@ -65,35 +63,33 @@ public: enum ObjectProperties { TEXTURE_COORDINATES = 1 << 0, - TANGENTS = 1 << 1, - BINORMALS = 1 << 2 + TANGENTS = 1 << 1, + BINORMALS = 1 << 2 }; ObjLoader(); virtual ~ObjLoader(); - bool IsSceneLoaded(); - bool IsMaterialLoaded(); + bool IsSceneLoaded(); + bool IsMaterialLoaded(); - bool LoadObject( char* objBuffer, std::streampos fileSize ); + bool LoadObject(char* objBuffer, std::streampos fileSize); - void LoadMaterial( char* objBuffer, std::streampos fileSize, std::string& diffuseTextureUrl, - std::string& normalTextureUrl, std::string& glossTextureUrl ); + void LoadMaterial(char* objBuffer, std::streampos fileSize, std::string& diffuseTextureUrl, std::string& normalTextureUrl, std::string& glossTextureUrl); - Geometry CreateGeometry( int objectProperties, bool useSoftNormals ); + Geometry CreateGeometry(int objectProperties, bool useSoftNormals); - Vector3 GetCenter(); - Vector3 GetSize(); + Vector3 GetCenter(); + Vector3 GetSize(); - void ClearArrays(); + void ClearArrays(); - bool IsTexturePresent(); - bool IsDiffuseMapPresent(); - bool IsNormalMapPresent(); - bool IsSpecularMapPresent(); + bool IsTexturePresent(); + bool IsDiffuseMapPresent(); + bool IsNormalMapPresent(); + bool IsSpecularMapPresent(); private: - Dali::Vector mPoints; Dali::Vector mTextureUv; Dali::Vector mTextureUv2; @@ -122,9 +118,9 @@ private: * @param[in, out] triangles The triangles that form the faces. The normals of each triangle will be updated. * @param[in, out] normals The normals to be calculated. */ - void CalculateHardFaceNormals( const Dali::Vector& vertices, - Dali::Vector& triangles, - Dali::Vector& normals ); + void CalculateHardFaceNormals(const Dali::Vector& vertices, + Dali::Vector& triangles, + Dali::Vector& normals); /** * @brief Calculates smoothed normals for each point. @@ -135,9 +131,9 @@ private: * @param[in, out] triangles The triangles that form the faces. The normals of each triangle will be updated. * @param[in, out] normals The normals to be calculated. */ - void CalculateSoftFaceNormals( const Dali::Vector& vertices, - Dali::Vector& triangles, - Dali::Vector& normals ); + void CalculateSoftFaceNormals(const Dali::Vector& vertices, + Dali::Vector& triangles, + Dali::Vector& normals); /** * @brief Calculates tangents and bitangents for each point of the object. @@ -146,7 +142,7 @@ private: */ void CalculateTangentFrame(); - void CenterAndScale( bool center, Dali::Vector& points ); + void CenterAndScale(bool center, Dali::Vector& points); /** * @brief Using the data loaded from the file, create arrays of data to be used in creating the geometry. @@ -158,13 +154,12 @@ private: * @param[out] indices Indices of corresponding values to match triangles to their respective data. * @param[in] useSoftNormals Indicates whether we should average the normals at each point to smooth the surface or not. */ - void CreateGeometryArray( Dali::Vector& positions, - Dali::Vector& normals, - Dali::Vector& tangents, - Dali::Vector& textures, - Dali::Vector& indices, - bool useSoftNormals ); - + void CreateGeometryArray(Dali::Vector& positions, + Dali::Vector& normals, + Dali::Vector& tangents, + Dali::Vector& textures, + Dali::Vector& indices, + bool useSoftNormals); }; } // namespace PbrDemo diff --git a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp index 38c3ce2..6b00413 100644 --- a/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp +++ b/examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp @@ -22,11 +22,11 @@ #include // INTERNAL INCLUDES +#include +#include #include "ktx-loader.h" -#include "model-skybox.h" #include "model-pbr.h" -#include -#include +#include "model-skybox.h" using namespace Dali; using namespace Toolkit; @@ -42,28 +42,27 @@ using namespace Toolkit; namespace { - -const char* NORMAL_ROUGH_TEXTURE_URL = DEMO_IMAGE_DIR "Test_100_normal_roughness.png"; -const char* ALBEDO_METAL_TEXTURE_URL = DEMO_IMAGE_DIR "Test_wblue_100_albedo_metal.png"; +const char* NORMAL_ROUGH_TEXTURE_URL = DEMO_IMAGE_DIR "Test_100_normal_roughness.png"; +const char* ALBEDO_METAL_TEXTURE_URL = DEMO_IMAGE_DIR "Test_wblue_100_albedo_metal.png"; const char* CUBEMAP_SPECULAR_TEXTURE_URL = DEMO_IMAGE_DIR "papermill_pmrem.ktx"; -const char* CUBEMAP_DIFFUSE_TEXTURE_URL = DEMO_IMAGE_DIR "papermill_E_diffuse-64.ktx"; +const char* CUBEMAP_DIFFUSE_TEXTURE_URL = DEMO_IMAGE_DIR "papermill_E_diffuse-64.ktx"; const char* SPHERE_URL = DEMO_MODEL_DIR "sphere.obj"; const char* TEAPOT_URL = DEMO_MODEL_DIR "teapot.obj"; -const char* VERTEX_SHADER_URL = DEMO_SHADER_DIR "pbr_shader.vsh"; +const char* VERTEX_SHADER_URL = DEMO_SHADER_DIR "pbr_shader.vsh"; const char* FRAGMENT_SHADER_URL = DEMO_SHADER_DIR "pbr_shader.fsh"; -const Vector3 SKYBOX_SCALE( 1.0f, 1.0f, 1.0f ); -const Vector3 SPHERE_SCALE( 1.5f, 1.5f, 1.5f ); -const Vector3 TEAPOT_SCALE( 2.0f, 2.0f, 2.0f ); +const Vector3 SKYBOX_SCALE(1.0f, 1.0f, 1.0f); +const Vector3 SPHERE_SCALE(1.5f, 1.5f, 1.5f); +const Vector3 TEAPOT_SCALE(2.0f, 2.0f, 2.0f); -const float CAMERA_DEFAULT_FOV( 60.0f ); -const float CAMERA_DEFAULT_NEAR( 0.1f ); -const float CAMERA_DEFAULT_FAR( 1000.0f ); -const Vector3 CAMERA_DEFAULT_POSITION( 0.0f, 0.0f, 3.5f ); +const float CAMERA_DEFAULT_FOV(60.0f); +const float CAMERA_DEFAULT_NEAR(0.1f); +const float CAMERA_DEFAULT_FAR(1000.0f); +const Vector3 CAMERA_DEFAULT_POSITION(0.0f, 0.0f, 3.5f); -} +} // namespace /* * @@ -79,21 +78,20 @@ const Vector3 CAMERA_DEFAULT_POSITION( 0.0f, 0.0f, 3.5f ); class BasicPbrController : public ConnectionTracker { public: - - BasicPbrController( Application& application ) - : mApplication( application ), + BasicPbrController(Application& application) + : mApplication(application), mLabel(), m3dRoot(), mUiRoot(), mDoubleTapTime(), mModelOrientation(), - mRoughness( 1.f ), - mMetalness( 0.f ), + mRoughness(1.f), + mMetalness(0.f), mDoubleTap(false), mTeapotView(true) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &BasicPbrController::Create ); + mApplication.InitSignal().Connect(this, &BasicPbrController::Create); } ~BasicPbrController() @@ -102,20 +100,20 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::BLACK ); - mAnimation = Animation::New( 1.0f ); - mLabel = TextLabel::New( "R:1 M:0" ); - mLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mLabel.SetProperty( Actor::Property::SIZE, Vector2( window.GetSize().GetWidth() * 0.5f, window.GetSize().GetHeight() * 0.083f ) ); - mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mLabel.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f ); + window.SetBackgroundColor(Color::BLACK); + mAnimation = Animation::New(1.0f); + mLabel = TextLabel::New("R:1 M:0"); + mLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mLabel.SetProperty(Actor::Property::SIZE, Vector2(window.GetSize().GetWidth() * 0.5f, window.GetSize().GetHeight() * 0.083f)); + mLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + mLabel.SetProperty(Actor::Property::COLOR_ALPHA, 0.0f); // Step 1. Create shader CreateModelShader(); @@ -126,16 +124,15 @@ public: InitActors(); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &BasicPbrController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &BasicPbrController::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &BasicPbrController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &BasicPbrController::OnKeyEvent); mDoubleTapTime = Timer::New(150); - mDoubleTapTime.TickSignal().Connect( this, &BasicPbrController::OnDoubleTapTime ); + mDoubleTapTime.TickSignal().Connect(this, &BasicPbrController::OnDoubleTapTime); } - bool OnDoubleTapTime() { mDoubleTap = false; @@ -145,11 +142,11 @@ public: /** * This function will change the material Roughness, Metalness or the model orientation when touched */ - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - const PointState::Type state = touch.GetState( 0 ); + const PointState::Type state = touch.GetState(0); - switch( state ) + switch(state) { case PointState::DOWN: { @@ -161,67 +158,69 @@ public: } mDoubleTapTime.Stop(); mStartTouch = touch.GetScreenPosition(0); - mPointZ = mStartTouch; + mPointZ = mStartTouch; mAnimation.Stop(); - mLabel.SetProperty( Actor::Property::COLOR_ALPHA, 1.0f ); + mLabel.SetProperty(Actor::Property::COLOR_ALPHA, 1.0f); break; } case PointState::MOTION: { - const Window window = mApplication.GetWindow(); - const Size size = window.GetSize(); - const float scaleX = size.width; - const float scaleY = size.height; - const Vector2 point = touch.GetScreenPosition(0); - bool process = false; - if( ( mStartTouch.x < ( scaleX * 0.3f ) ) && ( point.x < ( scaleX * 0.3f ) ) ) + const Window window = mApplication.GetWindow(); + const Size size = window.GetSize(); + const float scaleX = size.width; + const float scaleY = size.height; + const Vector2 point = touch.GetScreenPosition(0); + bool process = false; + if((mStartTouch.x < (scaleX * 0.3f)) && (point.x < (scaleX * 0.3f))) { - mRoughness += ( mStartTouch.y - point.y ) / ( scaleY * 0.9f ); + mRoughness += (mStartTouch.y - point.y) / (scaleY * 0.9f); //Clamp Roughness to 0.0 to 1.0 - mRoughness = std::max( 0.f, std::min( 1.f, mRoughness ) ); + mRoughness = std::max(0.f, std::min(1.f, mRoughness)); - mShader.SetProperty( mShader.GetPropertyIndex( "uRoughness" ), mRoughness ); + mShader.SetProperty(mShader.GetPropertyIndex("uRoughness"), mRoughness); std::ostringstream oss; oss.precision(2); - oss << " R:" << mRoughness<< "," << " M:" << mMetalness; - mLabel.SetProperty( TextLabel::Property::TEXT, oss.str() ); + oss << " R:" << mRoughness << "," + << " M:" << mMetalness; + mLabel.SetProperty(TextLabel::Property::TEXT, oss.str()); mStartTouch = point; - process = true; + process = true; } - if( ( mStartTouch.x > ( scaleX * 0.7f ) ) && ( point.x > ( scaleX * 0.7f ) ) ) + if((mStartTouch.x > (scaleX * 0.7f)) && (point.x > (scaleX * 0.7f))) { - mMetalness += ( mStartTouch.y - point.y ) / ( scaleY * 0.9f ); + mMetalness += (mStartTouch.y - point.y) / (scaleY * 0.9f); //Clamp Metalness to 0.0 to 1.0 - mMetalness = std::max( 0.f, std::min( 1.f, mMetalness ) ); + mMetalness = std::max(0.f, std::min(1.f, mMetalness)); - mShader.SetProperty( mShader.GetPropertyIndex( "uMetallic" ), mMetalness ); + mShader.SetProperty(mShader.GetPropertyIndex("uMetallic"), mMetalness); std::ostringstream oss; oss.precision(2); - oss << " R:" << mRoughness<< "," << " M:" << mMetalness; - mLabel.SetProperty( TextLabel::Property::TEXT, oss.str() ); + oss << " R:" << mRoughness << "," + << " M:" << mMetalness; + mLabel.SetProperty(TextLabel::Property::TEXT, oss.str()); mStartTouch = point; - process = true; + process = true; } //If the touch is not processed above, then change the model orientation - if( !process ) + if(!process) { - process = true; - const float angle1 = ( ( mPointZ.y - point.y ) / scaleY ); - const float angle2 = ( ( mPointZ.x - point.x ) / scaleX ); - Actor actor1 = mModel[0].GetActor(); - Actor actor2 = mModel[1].GetActor(); + process = true; + const float angle1 = ((mPointZ.y - point.y) / scaleY); + const float angle2 = ((mPointZ.x - point.x) / scaleX); + Actor actor1 = mModel[0].GetActor(); + Actor actor2 = mModel[1].GetActor(); Quaternion modelOrientation = mModelOrientation; modelOrientation.Conjugate(); - const Quaternion pitchRot(Radian(Degree(angle1 * -200.0f)), modelOrientation.Rotate( Vector3::XAXIS ) ); - const Quaternion yawRot(Radian(Degree(angle2 * -200.0f)), modelOrientation.Rotate( Vector3::YAXIS ) ); + const Quaternion pitchRot(Radian(Degree(angle1 * -200.0f)), modelOrientation.Rotate(Vector3::XAXIS)); + const Quaternion yawRot(Radian(Degree(angle2 * -200.0f)), modelOrientation.Rotate(Vector3::YAXIS)); - mModelOrientation = mModelOrientation * yawRot * pitchRot ; - mSkybox.GetActor().SetProperty( Actor::Property::ORIENTATION, mModelOrientation ); - actor1.SetProperty( Actor::Property::ORIENTATION, mModelOrientation ); - actor2.SetProperty( Actor::Property::ORIENTATION, mModelOrientation ); + mModelOrientation = mModelOrientation * yawRot * pitchRot; + mSkybox.GetActor().SetProperty(Actor::Property::ORIENTATION, mModelOrientation); + actor1.SetProperty(Actor::Property::ORIENTATION, mModelOrientation); + actor2.SetProperty(Actor::Property::ORIENTATION, mModelOrientation); mPointZ = point; } @@ -231,7 +230,7 @@ public: { mDoubleTapTime.Start(); mDoubleTap = true; - mAnimation.AnimateTo( Property( mLabel, Actor::Property::COLOR_ALPHA ), 0.0f, TimePeriod( 0.5f, 1.0f ) ); + mAnimation.AnimateTo(Property(mLabel, Actor::Property::COLOR_ALPHA), 0.0f, TimePeriod(0.5f, 1.0f)); mAnimation.Play(); break; } @@ -250,11 +249,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -266,58 +265,56 @@ public: */ void InitActors() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - mSkybox.Init( SKYBOX_SCALE ); - mModel[0].Init( mShader, SPHERE_URL, Vector3::ZERO, SPHERE_SCALE ); - mModel[1].Init( mShader, TEAPOT_URL, Vector3::ZERO, TEAPOT_SCALE ); + mSkybox.Init(SKYBOX_SCALE); + mModel[0].Init(mShader, SPHERE_URL, Vector3::ZERO, SPHERE_SCALE); + mModel[1].Init(mShader, TEAPOT_URL, Vector3::ZERO, TEAPOT_SCALE); // Hide the model according with mTeapotView variable mModel[0].GetActor().SetProperty(Dali::Actor::Property::VISIBLE, !mTeapotView); - mModel[1].GetActor().SetProperty(Dali::Actor::Property::VISIBLE, mTeapotView); + mModel[1].GetActor().SetProperty(Dali::Actor::Property::VISIBLE, mTeapotView); // Creating root and camera actor for rendertask for 3D Scene rendering - mUiRoot = Actor::New(); - m3dRoot = Actor::New(); + mUiRoot = Actor::New(); + m3dRoot = Actor::New(); CameraActor cameraUi = CameraActor::New(window.GetSize()); - cameraUi.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - cameraUi.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + cameraUi.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + cameraUi.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); RenderTask rendertask = window.GetRenderTaskList().CreateTask(); - rendertask.SetCameraActor( cameraUi ); - rendertask.SetSourceActor( mUiRoot ); + rendertask.SetCameraActor(cameraUi); + rendertask.SetSourceActor(mUiRoot); - mUiRoot.SetProperty(Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT); - mUiRoot.SetProperty(Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); - mUiRoot.SetProperty(Actor::Property::SIZE, Vector2(window.GetSize()) ); + mUiRoot.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mUiRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mUiRoot.SetProperty(Actor::Property::SIZE, Vector2(window.GetSize())); - m3dRoot.SetProperty(Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - m3dRoot.SetProperty(Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + m3dRoot.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + m3dRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); // Setting camera parameters for 3D Scene - mSkybox.GetActor().SetProperty( Actor::Property::POSITION, CAMERA_DEFAULT_POSITION ); + mSkybox.GetActor().SetProperty(Actor::Property::POSITION, CAMERA_DEFAULT_POSITION); CameraActor camera3d = window.GetRenderTaskList().GetTask(0).GetCameraActor(); - camera3d.SetInvertYAxis( true ); - camera3d.SetProperty( Actor::Property::POSITION, CAMERA_DEFAULT_POSITION ); - camera3d.SetNearClippingPlane( CAMERA_DEFAULT_NEAR ); - camera3d.SetFarClippingPlane( CAMERA_DEFAULT_FAR ); - camera3d.SetFieldOfView( Radian( Degree( CAMERA_DEFAULT_FOV ) ) ); + camera3d.SetInvertYAxis(true); + camera3d.SetProperty(Actor::Property::POSITION, CAMERA_DEFAULT_POSITION); + camera3d.SetNearClippingPlane(CAMERA_DEFAULT_NEAR); + camera3d.SetFarClippingPlane(CAMERA_DEFAULT_FAR); + camera3d.SetFieldOfView(Radian(Degree(CAMERA_DEFAULT_FOV))); - window.Add( cameraUi ); - window.Add( mUiRoot ); - window.Add( m3dRoot ); + window.Add(cameraUi); + window.Add(mUiRoot); + window.Add(m3dRoot); - m3dRoot.Add( mSkybox.GetActor() ); - m3dRoot.Add( mModel[0].GetActor() ); - m3dRoot.Add( mModel[1].GetActor() ); + m3dRoot.Add(mSkybox.GetActor()); + m3dRoot.Add(mModel[0].GetActor()); + m3dRoot.Add(mModel[1].GetActor()); - - if( (windowSize.x > 360.0f) && (windowSize.y > 360.0f) ) + if((windowSize.x > 360.0f) && (windowSize.y > 360.0f)) { - mUiRoot.Add( mLabel ); + mUiRoot.Add(mLabel); } - } /** @@ -325,16 +322,16 @@ public: */ void CreateModelShader() { - const std::string mCurrentVShaderFile( VERTEX_SHADER_URL ); - const std::string mCurrentFShaderFile( FRAGMENT_SHADER_URL ); + const std::string mCurrentVShaderFile(VERTEX_SHADER_URL); + const std::string mCurrentFShaderFile(FRAGMENT_SHADER_URL); - mShader = LoadShaders( mCurrentVShaderFile, mCurrentFShaderFile ); + mShader = LoadShaders(mCurrentVShaderFile, mCurrentFShaderFile); // Initialise shader uniforms // Level 8 because the environment texture has 6 levels plus 2 are missing (2x2 and 1x1) - mShader.RegisterProperty( "uMaxLOD", 8.0f ); - mShader.RegisterProperty( "uRoughness", 1.0f ); - mShader.RegisterProperty( "uMetallic" , 0.0f ); + mShader.RegisterProperty("uMaxLOD", 8.0f); + mShader.RegisterProperty("uRoughness", 1.0f); + mShader.RegisterProperty("uMetallic", 0.0f); } /** @@ -342,43 +339,43 @@ public: */ void CreateTexture() { - PixelData albeldoPixelData = SyncImageLoader::Load( ALBEDO_METAL_TEXTURE_URL ); - Texture textureAlbedoMetal = Texture::New( TextureType::TEXTURE_2D, albeldoPixelData.GetPixelFormat(), albeldoPixelData.GetWidth(), albeldoPixelData.GetHeight() ); - textureAlbedoMetal.Upload( albeldoPixelData, 0, 0, 0, 0, albeldoPixelData.GetWidth(), albeldoPixelData.GetHeight() ); + PixelData albeldoPixelData = SyncImageLoader::Load(ALBEDO_METAL_TEXTURE_URL); + Texture textureAlbedoMetal = Texture::New(TextureType::TEXTURE_2D, albeldoPixelData.GetPixelFormat(), albeldoPixelData.GetWidth(), albeldoPixelData.GetHeight()); + textureAlbedoMetal.Upload(albeldoPixelData, 0, 0, 0, 0, albeldoPixelData.GetWidth(), albeldoPixelData.GetHeight()); - PixelData normalPixelData = SyncImageLoader::Load( NORMAL_ROUGH_TEXTURE_URL ); - Texture textureNormalRough = Texture::New( TextureType::TEXTURE_2D, normalPixelData.GetPixelFormat(), normalPixelData.GetWidth(), normalPixelData.GetHeight() ); - textureNormalRough.Upload( normalPixelData, 0, 0, 0, 0, normalPixelData.GetWidth(), normalPixelData.GetHeight() ); + PixelData normalPixelData = SyncImageLoader::Load(NORMAL_ROUGH_TEXTURE_URL); + Texture textureNormalRough = Texture::New(TextureType::TEXTURE_2D, normalPixelData.GetPixelFormat(), normalPixelData.GetWidth(), normalPixelData.GetHeight()); + textureNormalRough.Upload(normalPixelData, 0, 0, 0, 0, normalPixelData.GetWidth(), normalPixelData.GetHeight()); // This texture should have 6 faces and only one mipmap PbrDemo::CubeData diffuse; - PbrDemo::LoadCubeMapFromKtxFile( CUBEMAP_DIFFUSE_TEXTURE_URL, diffuse ); + PbrDemo::LoadCubeMapFromKtxFile(CUBEMAP_DIFFUSE_TEXTURE_URL, diffuse); - Texture diffuseTexture = Texture::New( TextureType::TEXTURE_CUBE, diffuse.img[0][0].GetPixelFormat(), diffuse.img[0][0].GetWidth(), diffuse.img[0][0].GetHeight() ); - for( unsigned int midmapLevel = 0; midmapLevel < diffuse.img[0].size(); ++midmapLevel ) + Texture diffuseTexture = Texture::New(TextureType::TEXTURE_CUBE, diffuse.img[0][0].GetPixelFormat(), diffuse.img[0][0].GetWidth(), diffuse.img[0][0].GetHeight()); + for(unsigned int midmapLevel = 0; midmapLevel < diffuse.img[0].size(); ++midmapLevel) { - for( unsigned int i = 0; i < diffuse.img.size(); ++i ) + for(unsigned int i = 0; i < diffuse.img.size(); ++i) { - diffuseTexture.Upload( diffuse.img[i][midmapLevel], CubeMapLayer::POSITIVE_X + i, midmapLevel, 0, 0, diffuse.img[i][midmapLevel].GetWidth(), diffuse.img[i][midmapLevel].GetHeight() ); + diffuseTexture.Upload(diffuse.img[i][midmapLevel], CubeMapLayer::POSITIVE_X + i, midmapLevel, 0, 0, diffuse.img[i][midmapLevel].GetWidth(), diffuse.img[i][midmapLevel].GetHeight()); } } // This texture should have 6 faces and 6 mipmaps PbrDemo::CubeData specular; - PbrDemo::LoadCubeMapFromKtxFile( CUBEMAP_SPECULAR_TEXTURE_URL, specular); + PbrDemo::LoadCubeMapFromKtxFile(CUBEMAP_SPECULAR_TEXTURE_URL, specular); - Texture specularTexture = Texture::New( TextureType::TEXTURE_CUBE, specular.img[0][0].GetPixelFormat(), specular.img[0][0].GetWidth(), specular.img[0][0].GetHeight() ); - for( unsigned int midmapLevel = 0; midmapLevel < specular.img[0].size(); ++midmapLevel ) + Texture specularTexture = Texture::New(TextureType::TEXTURE_CUBE, specular.img[0][0].GetPixelFormat(), specular.img[0][0].GetWidth(), specular.img[0][0].GetHeight()); + for(unsigned int midmapLevel = 0; midmapLevel < specular.img[0].size(); ++midmapLevel) { - for( unsigned int i = 0; i < specular.img.size(); ++i ) + for(unsigned int i = 0; i < specular.img.size(); ++i) { - specularTexture.Upload( specular.img[i][midmapLevel], CubeMapLayer::POSITIVE_X + i, midmapLevel, 0, 0, specular.img[i][midmapLevel].GetWidth(), specular.img[i][midmapLevel].GetHeight() ); + specularTexture.Upload(specular.img[i][midmapLevel], CubeMapLayer::POSITIVE_X + i, midmapLevel, 0, 0, specular.img[i][midmapLevel].GetWidth(), specular.img[i][midmapLevel].GetHeight()); } } - mModel[0].InitTexture( textureAlbedoMetal, textureNormalRough, diffuseTexture, specularTexture ); - mModel[1].InitTexture( textureAlbedoMetal, textureNormalRough, diffuseTexture, specularTexture ); - mSkybox.InitTexture( specularTexture ); + mModel[0].InitTexture(textureAlbedoMetal, textureNormalRough, diffuseTexture, specularTexture); + mModel[1].InitTexture(textureAlbedoMetal, textureNormalRough, diffuseTexture, specularTexture); + mSkybox.InitTexture(specularTexture); } /** @@ -387,28 +384,28 @@ public: * @param[out] The contents of file * @return True if the source was read successfully */ - bool LoadShaderCode( const std::string& fullpath, std::vector& output ) + bool LoadShaderCode(const std::string& fullpath, std::vector& output) { - Dali::FileStream fileStream( fullpath, FileStream::READ | FileStream::BINARY ); - FILE* file = fileStream.GetFile(); - if( NULL == file ) + Dali::FileStream fileStream(fullpath, FileStream::READ | FileStream::BINARY); + FILE* file = fileStream.GetFile(); + if(NULL == file) { return false; } bool retValue = false; - if( ! fseek( file, 0, SEEK_END ) ) + if(!fseek(file, 0, SEEK_END)) { - long int size = ftell( file ); + long int size = ftell(file); - if( ( size != -1L ) && - ( ! fseek( file, 0, SEEK_SET ) ) ) + if((size != -1L) && + (!fseek(file, 0, SEEK_SET))) { - output.resize( size + 1 ); - std::fill( output.begin(), output.end(), 0 ); - ssize_t result = fread( output.data(), size, 1, file ); + output.resize(size + 1); + std::fill(output.begin(), output.end(), 0); + ssize_t result = fread(output.data(), size, 1, file); - retValue = ( result >= 0 ); + retValue = (result >= 0); } } @@ -421,16 +418,16 @@ public: * @param[in] shaderFragFileName is the filepath of Fragment shader * @return the Dali::Shader object */ - Shader LoadShaders( const std::string& shaderVertexFileName, const std::string& shaderFragFileName ) + Shader LoadShaders(const std::string& shaderVertexFileName, const std::string& shaderFragFileName) { - Shader shader; + Shader shader; std::vector bufV, bufF; - if( LoadShaderCode( shaderVertexFileName.c_str(), bufV ) ) + if(LoadShaderCode(shaderVertexFileName.c_str(), bufV)) { - if( LoadShaderCode( shaderFragFileName.c_str(), bufF ) ) + if(LoadShaderCode(shaderFragFileName.c_str(), bufF)) { - shader = Shader::New( bufV.data() , bufF.data() ); + shader = Shader::New(bufV.data(), bufF.data()); } } return shader; @@ -438,31 +435,30 @@ public: private: Application& mApplication; - TextLabel mLabel; - Actor m3dRoot; - Actor mUiRoot; - Shader mShader; - Animation mAnimation; - Timer mDoubleTapTime; + TextLabel mLabel; + Actor m3dRoot; + Actor mUiRoot; + Shader mShader; + Animation mAnimation; + Timer mDoubleTapTime; ModelSkybox mSkybox; - ModelPbr mModel[2]; + ModelPbr mModel[2]; Vector2 mPointZ; Vector2 mStartTouch; Quaternion mModelOrientation; - float mRoughness; - float mMetalness; - bool mDoubleTap; - bool mTeapotView; - + float mRoughness; + float mMetalness; + bool mDoubleTap; + bool mTeapotView; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv); - BasicPbrController test( application ); + Application application = Application::New(&argc, &argv); + BasicPbrController test(application); application.MainLoop(); return 0; } diff --git a/examples/rendering-cube/rendering-cube.cpp b/examples/rendering-cube/rendering-cube.cpp index 23bf056..756e841 100644 --- a/examples/rendering-cube/rendering-cube.cpp +++ b/examples/rendering-cube/rendering-cube.cpp @@ -15,14 +15,15 @@ * */ -#include #include +#include using namespace Dali; using namespace Toolkit; namespace { +// clang-format off /* * Vertex shader @@ -55,20 +56,20 @@ void main()\n gl_FragColor = vColor;\n }\n ); +// clang-format on -} +} // namespace // This example shows how to create a cube with colors on each side // class DrawCubeController : public ConnectionTracker { public: - - DrawCubeController( Application& application ) - : mApplication( application ) + DrawCubeController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &DrawCubeController::Create ); + mApplication.InitSignal().Connect(this, &DrawCubeController::Create); } ~DrawCubeController() @@ -77,11 +78,11 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Step 1. Create shader CreateCubeShader(); @@ -99,13 +100,13 @@ public: PlayAnimation(); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &DrawCubeController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &DrawCubeController::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &DrawCubeController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &DrawCubeController::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -118,11 +119,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -141,78 +142,65 @@ public: Vector3 aColor; }; - const Vector3 COLOR0( 1.0f, 1.0f, 0.0f ); - const Vector3 COLOR1( 0.0f, 1.0f, 1.0f ); - const Vector3 COLOR2( 1.0f, 0.0f, 1.0f ); - const Vector3 COLOR3( 0.0f, 1.0f, 0.0f ); - const Vector3 COLOR4( 0.0f, 0.0f, 1.0f ); - const Vector3 COLOR5( 1.0f, 0.0f, 0.0f ); + const Vector3 COLOR0(1.0f, 1.0f, 0.0f); + const Vector3 COLOR1(0.0f, 1.0f, 1.0f); + const Vector3 COLOR2(1.0f, 0.0f, 1.0f); + const Vector3 COLOR3(0.0f, 1.0f, 0.0f); + const Vector3 COLOR4(0.0f, 0.0f, 1.0f); + const Vector3 COLOR5(1.0f, 0.0f, 0.0f); Vertex vertices[] = { - { Vector3( 1.0f,-1.0f,-1.0f ), COLOR5 }, - { Vector3( -1.0f, 1.0f,-1.0f ), COLOR5 }, - { Vector3( 1.0f, 1.0f,-1.0f ), COLOR5 }, - { Vector3( -1.0f, 1.0f, 1.0f ), COLOR3 }, - { Vector3( 1.0f,-1.0f, 1.0f ), COLOR3 }, - { Vector3( 1.0f, 1.0f, 1.0f ), COLOR3 }, - { Vector3( 1.0f, 1.0f, 1.0f ), COLOR4 }, - { Vector3( 1.0f,-1.0f,-1.0f ), COLOR4 }, - { Vector3( 1.0f, 1.0f,-1.0f ), COLOR4 }, - { Vector3( 1.0f,-1.0f, 1.0f ), COLOR1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), COLOR1 }, - { Vector3( 1.0f,-1.0f,-1.0f ), COLOR1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), COLOR0 }, - { Vector3( -1.0f, 1.0f, 1.0f ), COLOR0 }, - { Vector3( -1.0f, 1.0f,-1.0f ), COLOR0 }, - { Vector3( 1.0f, 1.0f,-1.0f ), COLOR2 }, - { Vector3( -1.0f, 1.0f, 1.0f ), COLOR2 }, - { Vector3( 1.0f, 1.0f, 1.0f ), COLOR2 }, - { Vector3( 1.0f,-1.0f,-1.0f ), COLOR5 }, - { Vector3( -1.0f,-1.0f,-1.0f ), COLOR5 }, - { Vector3( -1.0f, 1.0f,-1.0f ), COLOR5 }, - { Vector3( -1.0f, 1.0f, 1.0f ), COLOR3 }, - { Vector3( -1.0f,-1.0f, 1.0f ), COLOR3 }, - { Vector3( 1.0f,-1.0f, 1.0f ), COLOR3 }, - { Vector3( 1.0f, 1.0f, 1.0f ), COLOR4 }, - { Vector3( 1.0f,-1.0f, 1.0f ), COLOR4 }, - { Vector3( 1.0f,-1.0f,-1.0f ), COLOR4 }, - { Vector3( 1.0f,-1.0f, 1.0f ), COLOR1 }, - { Vector3( -1.0f,-1.0f, 1.0f ), COLOR1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), COLOR1 }, - { Vector3( -1.0f,-1.0f,-1.0f ), COLOR0 }, - { Vector3( -1.0f,-1.0f, 1.0f ), COLOR0 }, - { Vector3( -1.0f, 1.0f, 1.0f ), COLOR0 }, - { Vector3( 1.0f, 1.0f,-1.0f ), COLOR2 }, - { Vector3( -1.0f, 1.0f,-1.0f ), COLOR2 }, - { Vector3( -1.0f, 1.0f, 1.0f ), COLOR2 }, + {Vector3(1.0f, -1.0f, -1.0f), COLOR5}, + {Vector3(-1.0f, 1.0f, -1.0f), COLOR5}, + {Vector3(1.0f, 1.0f, -1.0f), COLOR5}, + {Vector3(-1.0f, 1.0f, 1.0f), COLOR3}, + {Vector3(1.0f, -1.0f, 1.0f), COLOR3}, + {Vector3(1.0f, 1.0f, 1.0f), COLOR3}, + {Vector3(1.0f, 1.0f, 1.0f), COLOR4}, + {Vector3(1.0f, -1.0f, -1.0f), COLOR4}, + {Vector3(1.0f, 1.0f, -1.0f), COLOR4}, + {Vector3(1.0f, -1.0f, 1.0f), COLOR1}, + {Vector3(-1.0f, -1.0f, -1.0f), COLOR1}, + {Vector3(1.0f, -1.0f, -1.0f), COLOR1}, + {Vector3(-1.0f, -1.0f, -1.0f), COLOR0}, + {Vector3(-1.0f, 1.0f, 1.0f), COLOR0}, + {Vector3(-1.0f, 1.0f, -1.0f), COLOR0}, + {Vector3(1.0f, 1.0f, -1.0f), COLOR2}, + {Vector3(-1.0f, 1.0f, 1.0f), COLOR2}, + {Vector3(1.0f, 1.0f, 1.0f), COLOR2}, + {Vector3(1.0f, -1.0f, -1.0f), COLOR5}, + {Vector3(-1.0f, -1.0f, -1.0f), COLOR5}, + {Vector3(-1.0f, 1.0f, -1.0f), COLOR5}, + {Vector3(-1.0f, 1.0f, 1.0f), COLOR3}, + {Vector3(-1.0f, -1.0f, 1.0f), COLOR3}, + {Vector3(1.0f, -1.0f, 1.0f), COLOR3}, + {Vector3(1.0f, 1.0f, 1.0f), COLOR4}, + {Vector3(1.0f, -1.0f, 1.0f), COLOR4}, + {Vector3(1.0f, -1.0f, -1.0f), COLOR4}, + {Vector3(1.0f, -1.0f, 1.0f), COLOR1}, + {Vector3(-1.0f, -1.0f, 1.0f), COLOR1}, + {Vector3(-1.0f, -1.0f, -1.0f), COLOR1}, + {Vector3(-1.0f, -1.0f, -1.0f), COLOR0}, + {Vector3(-1.0f, -1.0f, 1.0f), COLOR0}, + {Vector3(-1.0f, 1.0f, 1.0f), COLOR0}, + {Vector3(1.0f, 1.0f, -1.0f), COLOR2}, + {Vector3(-1.0f, 1.0f, -1.0f), COLOR2}, + {Vector3(-1.0f, 1.0f, 1.0f), COLOR2}, }; - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR3 ) - .Add( "aColor", Property::VECTOR3 ) ); - vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vertex) ); + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3) + .Add("aColor", Property::VECTOR3)); + vertexBuffer.SetData(vertices, sizeof(vertices) / sizeof(Vertex)); // create indices const unsigned short INDEX_CUBE[] = { - 2, 1, 0, - 5, 4, 3, - 8, 7, 6, - 11, 10, 9, - 14, 13, 12, - 17, 16, 15, - 20, 19, 18, - 23, 22, 21, - 26, 25, 24, - 29, 28, 27, - 32, 31, 30, - 35, 34, 33 - }; + 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21, 26, 25, 24, 29, 28, 27, 32, 31, 30, 35, 34, 33}; mGeometry = Geometry::New(); - mGeometry.AddVertexBuffer( vertexBuffer ); - mGeometry.SetIndexBuffer( INDEX_CUBE, - sizeof(INDEX_CUBE)/sizeof(INDEX_CUBE[0]) - ); - mGeometry.SetType( Geometry::TRIANGLES ); + mGeometry.AddVertexBuffer(vertexBuffer); + mGeometry.SetIndexBuffer(INDEX_CUBE, + sizeof(INDEX_CUBE) / sizeof(INDEX_CUBE[0])); + mGeometry.SetType(Geometry::TRIANGLES); } /** @@ -223,7 +211,7 @@ public: */ void CreateCubeShader() { - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); } /** @@ -231,11 +219,11 @@ public: */ void CreateRenderer() { - mRenderer = Renderer::New( mGeometry, mShader ); + mRenderer = Renderer::New(mGeometry, mShader); // Face culling is enabled to hide the backwards facing sides of the cube // This is sufficient to render a single object; for more complex scenes depth-testing might be required - mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + mRenderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); } /** @@ -246,13 +234,13 @@ public: Window window = mApplication.GetWindow(); float quarterWindowWidth = window.GetSize().GetWidth() * 0.25f; - mActor = Actor::New(); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); - mActor.SetProperty( Actor::Property::SIZE, Vector3( quarterWindowWidth, quarterWindowWidth, quarterWindowWidth ) ); - mActor.AddRenderer( mRenderer ); - window.Add( mActor ); + mActor = Actor::New(); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); + mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowWidth, quarterWindowWidth, quarterWindowWidth)); + mActor.AddRenderer(mRenderer); + window.Add(mActor); } /** @@ -260,28 +248,28 @@ public: */ void PlayAnimation() { - mAnimation = Animation::New( 5.0f ); - mAnimation.SetLooping( true ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::ZAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::XAXIS ) ); + mAnimation = Animation::New(5.0f); + mAnimation.SetLooping(true); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::ZAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::YAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::XAXIS)); mAnimation.Play(); } private: - Application& mApplication; + Application& mApplication; - Renderer mRenderer; - Shader mShader; - Geometry mGeometry; - Actor mActor; + Renderer mRenderer; + Shader mShader; + Geometry mGeometry; + Actor mActor; Animation mAnimation; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - DrawCubeController test( application ); + Application application = Application::New(&argc, &argv); + DrawCubeController test(application); application.MainLoop(); return 0; } diff --git a/examples/rendering-line/rendering-line.cpp b/examples/rendering-line/rendering-line.cpp index cd60254..8925047 100644 --- a/examples/rendering-line/rendering-line.cpp +++ b/examples/rendering-line/rendering-line.cpp @@ -15,14 +15,15 @@ * */ -#include #include +#include using namespace Dali; using namespace Toolkit; namespace { +// clang-format off /* * Vertex shader @@ -51,20 +52,20 @@ void main()\n gl_FragColor = uColor;\n }\n ); +// clang-format on -} +} // namespace // This example shows how to draw a line in actor's color // class DrawLineController : public ConnectionTracker { public: - - DrawLineController( Application& application ) - : mApplication( application ) + DrawLineController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &DrawLineController::Create ); + mApplication.InitSignal().Connect(this, &DrawLineController::Create); } ~DrawLineController() @@ -73,11 +74,11 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Step 1. Create shader CreateLineShader(); @@ -92,13 +93,13 @@ public: CreateActor(); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &DrawLineController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &DrawLineController::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &DrawLineController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &DrawLineController::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -111,11 +112,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -129,17 +130,16 @@ public: void CreateLineGeometry() { Vector2 vertices[] = { - Vector2( -1.0f, -1.0f ), - Vector2( 1.0f, 1.0f ) - }; + Vector2(-1.0f, -1.0f), + Vector2(1.0f, 1.0f)}; - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR2 ) ); - vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vector2) ); + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR2)); + vertexBuffer.SetData(vertices, sizeof(vertices) / sizeof(Vector2)); mGeometry = Geometry::New(); - mGeometry.AddVertexBuffer( vertexBuffer ); - mGeometry.SetType( Geometry::LINES ); + mGeometry.AddVertexBuffer(vertexBuffer); + mGeometry.SetType(Geometry::LINES); } /** @@ -149,7 +149,7 @@ public: */ void CreateLineShader() { - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); } /** @@ -157,7 +157,7 @@ public: */ void CreateRenderer() { - mRenderer = Renderer::New( mGeometry, mShader ); + mRenderer = Renderer::New(mGeometry, mShader); } /** @@ -166,30 +166,30 @@ public: void CreateActor() { Window window = mApplication.GetWindow(); - Size size = Vector2(window.GetSize()) * 0.25f; - mActor = Actor::New(); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); - mActor.SetProperty( Actor::Property::COLOR, Color::BLACK ); - mActor.SetProperty( Actor::Property::SIZE, Vector3( size.x, size.x, size.x ) ); - mActor.AddRenderer( mRenderer ); - window.Add( mActor ); + Size size = Vector2(window.GetSize()) * 0.25f; + mActor = Actor::New(); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); + mActor.SetProperty(Actor::Property::COLOR, Color::BLACK); + mActor.SetProperty(Actor::Property::SIZE, Vector3(size.x, size.x, size.x)); + mActor.AddRenderer(mRenderer); + window.Add(mActor); } private: - Application& mApplication; + Application& mApplication; Renderer mRenderer; - Shader mShader; + Shader mShader; Geometry mGeometry; - Actor mActor; + Actor mActor; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - DrawLineController test( application ); + Application application = Application::New(&argc, &argv); + DrawLineController test(application); application.MainLoop(); return 0; } diff --git a/examples/rendering-radial-progress/radial-progress.cpp b/examples/rendering-radial-progress/radial-progress.cpp index 614123d..675b690 100644 --- a/examples/rendering-radial-progress/radial-progress.cpp +++ b/examples/rendering-radial-progress/radial-progress.cpp @@ -15,22 +15,22 @@ * */ -#include #include +#include using namespace Dali; namespace // unnamed namespace { - -const char* TEXTURE_URL = DEMO_IMAGE_DIR "RadialEffect-280x280.png"; -const unsigned int TEXTURE_WIDTH = 280; +const char* TEXTURE_URL = DEMO_IMAGE_DIR "RadialEffect-280x280.png"; +const unsigned int TEXTURE_WIDTH = 280; const unsigned int TEXTURE_HEIGHT = 280; -const int NUMBER_OF_SIDES( 64 ); // number of sides of the polygon used as a stencil -const float INITIAL_DELAY( 2.0f ); // initial delay before showing the circle -const float PROGRESS_DURATION( 0.5f ); // number of seconds to fully show the circle +const int NUMBER_OF_SIDES(64); // number of sides of the polygon used as a stencil +const float INITIAL_DELAY(2.0f); // initial delay before showing the circle +const float PROGRESS_DURATION(0.5f); // number of seconds to fully show the circle +// clang-format off /* * Vertex shader for textured quad @@ -99,21 +99,20 @@ void main()\n gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );\n }\n ); +// clang-format on } // unnamed namespace - // This example shows how to render a radial progress indicator // class RadialProgressController : public ConnectionTracker { public: - - RadialProgressController( Application& application ) - : mApplication( application ) + RadialProgressController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &RadialProgressController::Create ); + mApplication.InitSignal().Connect(this, &RadialProgressController::Create); } ~RadialProgressController() @@ -122,40 +121,40 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); - window.SetBackgroundColor( Color::BLACK ); + window.SetBackgroundColor(Color::BLACK); // Connect to the window's key signal to allow Back and Escape to exit. - window.KeyEventSignal().Connect( this, &RadialProgressController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &RadialProgressController::OnKeyEvent); // 1. Create actor to show the effect mActor = Actor::New(); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::SIZE, Vector2( TEXTURE_WIDTH, TEXTURE_HEIGHT ) ); - mActor.RegisterProperty("uProgress", float(1.0f) ); - window.Add( mActor ); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::SIZE, Vector2(TEXTURE_WIDTH, TEXTURE_HEIGHT)); + mActor.RegisterProperty("uProgress", float(1.0f)); + window.Add(mActor); // 1. Create stencil renderer i.e. a triangle fan in the shape of a circle - Renderer stencilRenderer = CreatePolygon( NUMBER_OF_SIDES ); - mActor.AddRenderer( stencilRenderer ); + Renderer stencilRenderer = CreatePolygon(NUMBER_OF_SIDES); + mActor.AddRenderer(stencilRenderer); // 2. Create textured quad renderer - Renderer texturedQuad = CreateTexturedQuad( TEXTURE_URL ); - mActor.AddRenderer( texturedQuad ); + Renderer texturedQuad = CreateTexturedQuad(TEXTURE_URL); + mActor.AddRenderer(texturedQuad); // 5. Animate the progress uniform - Animation animation = Animation::New( PROGRESS_DURATION + INITIAL_DELAY ); - animation.AnimateTo( Property(mActor,"uProgress"), float(NUMBER_OF_SIDES+1), TimePeriod(INITIAL_DELAY, PROGRESS_DURATION) ); + Animation animation = Animation::New(PROGRESS_DURATION + INITIAL_DELAY); + animation.AnimateTo(Property(mActor, "uProgress"), float(NUMBER_OF_SIDES + 1), TimePeriod(INITIAL_DELAY, PROGRESS_DURATION)); animation.Play(); // 6. Exit the application when touched - window.GetRootLayer().TouchedSignal().Connect( this, &RadialProgressController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &RadialProgressController::OnTouch); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -167,62 +166,62 @@ public: * a triangle fan and occupies square 2.0x2.0. * @param[in] numberOfSides The more subdivisions the more smooth mask animation. */ - Renderer CreatePolygon( unsigned int numberOfSides ) + Renderer CreatePolygon(unsigned int numberOfSides) { - float count( numberOfSides ); + float count(numberOfSides); // compute radial step in radians - const float STEP( (2.0f * M_PI) / count ); - float angle( 0.0f ); + const float STEP((2.0f * M_PI) / count); + float angle(0.0f); - std::vector< Vector3 > vertices; - vertices.push_back( Vector3::ZERO ); + std::vector vertices; + vertices.push_back(Vector3::ZERO); - for( size_t i = 0; i <= numberOfSides; ++i ) + for(size_t i = 0; i <= numberOfSides; ++i) { - vertices.push_back( Vector3( -0.5f * cos( angle ), -0.5f * sin( angle ), i+1 ) ); + vertices.push_back(Vector3(-0.5f * cos(angle), -0.5f * sin(angle), i + 1)); angle += STEP; } Property::Map vertexFormat; - vertexFormat[ "aPosition" ] = Property::VECTOR3; + vertexFormat["aPosition"] = Property::VECTOR3; // describe vertex format ( only 2-dimensional positions ) - VertexBuffer vertexBuffer = VertexBuffer::New( vertexFormat ); - vertexBuffer.SetData( vertices.data(), vertices.size() ); + VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat); + vertexBuffer.SetData(vertices.data(), vertices.size()); // create geometry Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLE_FAN ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLE_FAN); - Shader shader = Shader::New( VERTEX_SHADER_BASIC, FRAGMENT_SHADER_BASIC ); - Renderer renderer = Renderer::New( geometry, shader ); + Shader shader = Shader::New(VERTEX_SHADER_BASIC, FRAGMENT_SHADER_BASIC); + Renderer renderer = Renderer::New(geometry, shader); // Setting stencil data. We don't want to render to the color buffer so // with use of RenderMode property we specify that only stencil buffer will // be affected. - renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL ); + renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL); // Set stencil function - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS ); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS); // Stencil function reference - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1 ); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1); // Stencil function mask - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, 0xFF ); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, 0xFF); // Set stencil operations - renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP ); - renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP ); - renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::REPLACE ); + renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP); + renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP); + renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::REPLACE); // Stencil mask to write - renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF ); + renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF); // Set depth index lower than textured quad renderer, so stencil will render first - renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 ); + renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1); return renderer; } @@ -230,58 +229,57 @@ public: /** * Creates textured quad renderer */ - Renderer CreateTexturedQuad( const char* url ) + Renderer CreateTexturedQuad(const char* url) { // Create shader & geometry needed by Renderer - Shader shader = Shader::New( VERTEX_SHADER_TEXTURED, FRAGMENT_SHADER_TEXTURED ); + Shader shader = Shader::New(VERTEX_SHADER_TEXTURED, FRAGMENT_SHADER_TEXTURED); Property::Map vertexFormat; vertexFormat["aPosition"] = Property::VECTOR2; - VertexBuffer vertexBuffer = VertexBuffer::New( vertexFormat ); + VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat); - const float P( 0.5f ); + const float P(0.5f); const Vector2 vertices[] = { - Vector2( -P, -P ), - Vector2( +P, -P ), - Vector2( -P, +P ), - Vector2( +P, +P ) - }; + Vector2(-P, -P), + Vector2(+P, -P), + Vector2(-P, +P), + Vector2(+P, +P)}; - vertexBuffer.SetData( vertices, 4 ); + vertexBuffer.SetData(vertices, 4); // Instantiate quad geometry Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLE_STRIP ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLE_STRIP); // Load texture - PixelData pixelData = Toolkit::SyncImageLoader::Load( url ); - Texture texture = Texture::New( TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight() ); - texture.Upload( pixelData ); + PixelData pixelData = Toolkit::SyncImageLoader::Load(url); + Texture texture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight()); + texture.Upload(pixelData); texture.GenerateMipmaps(); // Create texture set TextureSet textureSet = TextureSet::New(); - textureSet.SetTexture( 0, texture ); + textureSet.SetTexture(0, texture); // Create renderer - Renderer renderer = Renderer::New( geometry, shader ); - renderer.SetTextures( textureSet ); + Renderer renderer = Renderer::New(geometry, shader); + renderer.SetTextures(textureSet); // Set mode indicating we will use both stencil and color buffers - renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL ); + renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL); // Stencil function - expecing drawing only when function mask matches exactly - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::EQUAL ); - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1 ); - renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, 0xFF ); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::EQUAL); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, 1); + renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, 0xFF); // We don't want to draw to the stencil, so setting stencil draw mask to 0 - renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 ); + renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00); // Make sure the quad will render after drawing to stencil buffer - renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 2 ); + renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 2); return renderer; } @@ -292,11 +290,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -304,16 +302,15 @@ public: } private: - - Application& mApplication; + Application& mApplication; Actor mActor; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - RadialProgressController test( application ); + Application application = Application::New(&argc, &argv); + RadialProgressController test(application); application.MainLoop(); return 0; } diff --git a/examples/rendering-skybox/look-camera.cpp b/examples/rendering-skybox/look-camera.cpp index 00f38fc..39636db 100644 --- a/examples/rendering-skybox/look-camera.cpp +++ b/examples/rendering-skybox/look-camera.cpp @@ -17,9 +17,9 @@ #include "look-camera.h" +#include #include #include -#include using namespace Dali; @@ -27,52 +27,52 @@ namespace { // Input sensitivity, the larger value, the more sensitive input // Default value has been chosen empirically -const float CAMERA_SENSITIVITY ( 90.0f ); +const float CAMERA_SENSITIVITY(90.0f); // Vertical angle limit of the camera -const float CAMERA_VERTICAL_LIMIT ( 80.0f ); +const float CAMERA_VERTICAL_LIMIT(80.0f); // Position where camera is instantiated by default -const Vector3 CAMERA_DEFAULT_POSITION ( 0.0f, 0.0f, 3.0f ); +const Vector3 CAMERA_DEFAULT_POSITION(0.0f, 0.0f, 3.0f); // Field-of-View in degrees -const float CAMERA_DEFAULT_FOV ( 60.0f ); +const float CAMERA_DEFAULT_FOV(60.0f); // Near plane -const float CAMERA_DEFAULT_NEAR ( 0.1f ); +const float CAMERA_DEFAULT_NEAR(0.1f); // Far plane -const float CAMERA_DEFAULT_FAR ( 100.0f ); +const float CAMERA_DEFAULT_FAR(100.0f); // Default forward vector -const Vector3 CAMERA_FORWARD ( 0.0f, 0.0f, 1.0f ); +const Vector3 CAMERA_FORWARD(0.0f, 0.0f, 1.0f); // Default up vector -const Vector3 CAMERA_UP ( Vector3::YAXIS ); -} +const Vector3 CAMERA_UP(Vector3::YAXIS); +} // namespace LookCamera::LookCamera() -: mCameraYawPitch( 0.0f, 180.0f ), - mFovY( CAMERA_DEFAULT_FOV ), - mNear( CAMERA_DEFAULT_NEAR ), - mFar( CAMERA_DEFAULT_FAR ), - mCameraPosition( CAMERA_DEFAULT_POSITION ) +: mCameraYawPitch(0.0f, 180.0f), + mFovY(CAMERA_DEFAULT_FOV), + mNear(CAMERA_DEFAULT_NEAR), + mFar(CAMERA_DEFAULT_FAR), + mCameraPosition(CAMERA_DEFAULT_POSITION) { } LookCamera::~LookCamera() { mTimer.Stop(); - mCameraActor.Remove( mInterceptorActor ); + mCameraActor.Remove(mInterceptorActor); } -void LookCamera::Initialise( Window window, const Vector3& position, float fovY, float near, float far ) +void LookCamera::Initialise(Window window, const Vector3& position, float fovY, float near, float far) { mWindow = window; mFovY = fovY; mNear = near; - mFar = far; + mFar = far; // Camera position is shadowed in order to avoid using.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) mCameraPosition = position; @@ -84,8 +84,8 @@ void LookCamera::Initialise( Window window, const Vector3& position, float fovY, CreateInterceptorActor(); // Start timer - mTimer = Timer::New( 16 ); - mTimer.TickSignal().Connect( this, &LookCamera::OnTick ); + mTimer = Timer::New(16); + mTimer.TickSignal().Connect(this, &LookCamera::OnTick); mTimer.Start(); } @@ -95,24 +95,24 @@ bool LookCamera::OnTick() // --------------------------------------------------------------------- // update rotation - Vector2 tmp( mScreenLookDelta ); + Vector2 tmp(mScreenLookDelta); mScreenLookDelta = Vector2::ZERO; - float yaw = ( (tmp.y / windowSize.x ) * CAMERA_SENSITIVITY ); - float pitch = ( (tmp.x / windowSize.y ) * CAMERA_SENSITIVITY ); + float yaw = ((tmp.y / windowSize.x) * CAMERA_SENSITIVITY); + float pitch = ((tmp.x / windowSize.y) * CAMERA_SENSITIVITY); mCameraYawPitch.x -= yaw; mCameraYawPitch.y -= pitch; - if( abs( mCameraYawPitch.x ) > CAMERA_VERTICAL_LIMIT ) + if(abs(mCameraYawPitch.x) > CAMERA_VERTICAL_LIMIT) { - mCameraYawPitch.x = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.x < 0) ? -1.0f : 1.0f ); + mCameraYawPitch.x = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.x < 0) ? -1.0f : 1.0f); } Quaternion rotation; - Quaternion rotX( Degree( mCameraYawPitch.x), Vector3( 1.0f, 0.0f, 0.0f ) ); - Quaternion rotY( Degree( mCameraYawPitch.y), Vector3( 0.0f, 1.0f, 0.0f ) ); - rotation = ( rotY * rotX ); + Quaternion rotX(Degree(mCameraYawPitch.x), Vector3(1.0f, 0.0f, 0.0f)); + Quaternion rotY(Degree(mCameraYawPitch.y), Vector3(0.0f, 1.0f, 0.0f)); + rotation = (rotY * rotX); - mCameraActor.SetProperty( Actor::Property::ORIENTATION, rotation ); + mCameraActor.SetProperty(Actor::Property::ORIENTATION, rotation); return true; } @@ -120,15 +120,15 @@ bool LookCamera::OnTick() void LookCamera::InitialiseDefaultCamera() { mCameraActor = mWindow.GetRenderTaskList().GetTask(0).GetCameraActor(); - mCameraActor.SetProperty( Dali::Actor::Property::NAME, "LookCamera" ); - mCameraActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mCameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCameraActor.SetFieldOfView( Radian( Degree( mFovY ) ) ); + mCameraActor.SetProperty(Dali::Actor::Property::NAME, "LookCamera"); + mCameraActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCameraActor.SetFieldOfView(Radian(Degree(mFovY))); // should be read from file - mCameraActor.SetNearClippingPlane( mNear ); - mCameraActor.SetFarClippingPlane( mFar ); - mCameraActor.SetProperty( Actor::Property::POSITION, mCameraPosition ); + mCameraActor.SetNearClippingPlane(mNear); + mCameraActor.SetFarClippingPlane(mFar); + mCameraActor.SetProperty(Actor::Property::POSITION, mCameraPosition); } void LookCamera::CreateInterceptorActor() @@ -136,40 +136,39 @@ void LookCamera::CreateInterceptorActor() Vector2 windowSize = mWindow.GetSize(); mInterceptorActor = Actor::New(); - mInterceptorActor.SetProperty( Dali::Actor::Property::NAME, "InputInterceptor" ); - mInterceptorActor.SetProperty( Actor::Property::SIZE, Vector3( windowSize.width, windowSize.height, 1 ) ); - mInterceptorActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0, 0.0, 1.0 ) ); - mInterceptorActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mInterceptorActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCameraActor.Add( mInterceptorActor ); + mInterceptorActor.SetProperty(Dali::Actor::Property::NAME, "InputInterceptor"); + mInterceptorActor.SetProperty(Actor::Property::SIZE, Vector3(windowSize.width, windowSize.height, 1)); + mInterceptorActor.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 1.0)); + mInterceptorActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mInterceptorActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCameraActor.Add(mInterceptorActor); // Connect TouchedSignal to interceptor actor - mInterceptorActor.TouchedSignal().Connect( this, &LookCamera::OnTouch ); + mInterceptorActor.TouchedSignal().Connect(this, &LookCamera::OnTouch); } -bool LookCamera::OnTouch( Actor actor, const TouchEvent& touch ) +bool LookCamera::OnTouch(Actor actor, const TouchEvent& touch) { - for( int i = 0; i < (int)touch.GetPointCount() && i < 3; ++i ) + for(int i = 0; i < (int)touch.GetPointCount() && i < 3; ++i) { - Vector2 position( touch.GetScreenPosition( i ) ); + Vector2 position(touch.GetScreenPosition(i)); // touch started - if( touch.GetState( i ) == PointState::STARTED ) + if(touch.GetState(i) == PointState::STARTED) { mOldTouchLookPosition = position; } - else if( touch.GetState( i ) == PointState::FINISHED || - touch.GetState( i ) == PointState::LEAVE || - touch.GetState( i ) == PointState::INTERRUPTED - ) + else if(touch.GetState(i) == PointState::FINISHED || + touch.GetState(i) == PointState::LEAVE || + touch.GetState(i) == PointState::INTERRUPTED) { - mScreenLookDelta = Vector2::ZERO; + mScreenLookDelta = Vector2::ZERO; mOldTouchLookPosition = Vector2::ZERO; } else // on motion { - mScreenLookDelta.x += ( position.x - mOldTouchLookPosition.x ); - mScreenLookDelta.y += ( position.y - mOldTouchLookPosition.y ); + mScreenLookDelta.x += (position.x - mOldTouchLookPosition.x); + mScreenLookDelta.y += (position.y - mOldTouchLookPosition.y); mOldTouchLookPosition = position; } } diff --git a/examples/rendering-skybox/look-camera.h b/examples/rendering-skybox/look-camera.h index 4ab6fee..5d63287 100644 --- a/examples/rendering-skybox/look-camera.h +++ b/examples/rendering-skybox/look-camera.h @@ -31,7 +31,6 @@ class LookCamera : public Dali::ConnectionTracker { public: - /** * Creates an instance of LookCamera */ @@ -50,7 +49,7 @@ public: * @param[in] near Near plane * @param[in] far Far Plane */ - void Initialise( Dali::Window window, const Dali::Vector3& position, float fov, float near, float far ); + void Initialise(Dali::Window window, const Dali::Vector3& position, float fov, float near, float far); /** * Retrieves actor associated with camera object @@ -59,7 +58,6 @@ public: Dali::CameraActor GetCameraActor(); private: - /** * Sets up a perspective camera using Dali default camera */ @@ -77,7 +75,7 @@ private: * @param[in] actor Actor receiving signal * @param[in] touch Touch data */ - bool OnTouch( Dali::Actor actor, const Dali::TouchEvent& touch ); + bool OnTouch(Dali::Actor actor, const Dali::TouchEvent& touch); /** * Handles camera tick() update @@ -86,22 +84,21 @@ private: bool OnTick(); private: - Dali::Window mWindow; /// The window the camera belongs to - Dali::CameraActor mCameraActor; /// Camera actor - Dali::Actor mInterceptorActor; /// Actor intercepting user input + Dali::CameraActor mCameraActor; /// Camera actor + Dali::Actor mInterceptorActor; /// Actor intercepting user input Dali::Timer mTimer; /// Per-frame timer - Dali::Vector2 mScreenLookDelta; /// Look delta vector in screen space + Dali::Vector2 mScreenLookDelta; /// Look delta vector in screen space Dali::Vector2 mOldTouchLookPosition; /// Previous look vector in screen space Dali::Vector2 mCameraYawPitch; /// Camera yaw-pitch angles float mFovY; /// Camera field-of-view float mNear; /// Near plane - float mFar; /// Far plane + float mFar; /// Far plane Dali::Vector3 mCameraPosition; /// Current camera position ( shadowing the actor position ) }; diff --git a/examples/rendering-skybox/rendering-skybox.cpp b/examples/rendering-skybox/rendering-skybox.cpp index 4e48b48..d2d0f29 100644 --- a/examples/rendering-skybox/rendering-skybox.cpp +++ b/examples/rendering-skybox/rendering-skybox.cpp @@ -15,8 +15,8 @@ * */ -#include #include +#include #include "look-camera.h" @@ -25,7 +25,7 @@ using namespace Toolkit; namespace { - +// clang-format off /* * Vertex shader for a textured cube */ @@ -94,15 +94,16 @@ void main()\n gl_FragColor = texColor;\n }\n ); +// clang-format on -const float CAMERA_DEFAULT_FOV( 60.0f ); -const float CAMERA_DEFAULT_NEAR( 0.1f ); -const float CAMERA_DEFAULT_FAR( 1000.0f ); -const Vector3 CAMERA_DEFAULT_POSITION( 0.0f, 0.0f, 100.0f ); +const float CAMERA_DEFAULT_FOV(60.0f); +const float CAMERA_DEFAULT_NEAR(0.1f); +const float CAMERA_DEFAULT_FAR(1000.0f); +const Vector3 CAMERA_DEFAULT_POSITION(0.0f, 0.0f, 100.0f); const char* TEXTURE_URL = DEMO_IMAGE_DIR "wood.png"; -const unsigned int SKYBOX_FACE_COUNT = 6; +const unsigned int SKYBOX_FACE_COUNT = 6; const unsigned int SKYBOX_FACE_WIDTH = 2048; const unsigned int SKYBOX_FACE_HEIGHT = 2048; @@ -112,17 +113,16 @@ const unsigned int SKYBOX_FACE_HEIGHT = 2048; * The images are licensed under the terms of the CC BY 4.0 license: * https://creativecommons.org/licenses/by/4.0/ */ -const char* SKYBOX_FACES[ SKYBOX_FACE_COUNT ] = -{ - DEMO_IMAGE_DIR "lake_right.jpg", - DEMO_IMAGE_DIR "lake_left.jpg", - DEMO_IMAGE_DIR "lake_top.jpg", - DEMO_IMAGE_DIR "lake_bottom.jpg", - DEMO_IMAGE_DIR "lake_back.jpg", - DEMO_IMAGE_DIR "lake_front.jpg" -}; +const char* SKYBOX_FACES[SKYBOX_FACE_COUNT] = + { + DEMO_IMAGE_DIR "lake_right.jpg", + DEMO_IMAGE_DIR "lake_left.jpg", + DEMO_IMAGE_DIR "lake_top.jpg", + DEMO_IMAGE_DIR "lake_bottom.jpg", + DEMO_IMAGE_DIR "lake_back.jpg", + DEMO_IMAGE_DIR "lake_front.jpg"}; -} +} // namespace // This example shows how to create a skybox // @@ -131,12 +131,11 @@ const char* SKYBOX_FACES[ SKYBOX_FACE_COUNT ] = class TexturedCubeController : public ConnectionTracker { public: - - TexturedCubeController( Application& application ) - : mApplication( application ) + TexturedCubeController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TexturedCubeController::Create ); + mApplication.InitSignal().Connect(this, &TexturedCubeController::Create); } ~TexturedCubeController() @@ -145,11 +144,11 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Step 1. Setup camera SetupCamera(); @@ -175,7 +174,7 @@ public: PlayAnimation(); // Respond to key events - window.KeyEventSignal().Connect( this, &TexturedCubeController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &TexturedCubeController::OnKeyEvent); } /** @@ -184,11 +183,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -202,10 +201,10 @@ public: { Window window = mApplication.GetWindow(); - RenderTask renderTask = window.GetRenderTaskList().GetTask( 0 ); - renderTask.SetCullMode( false ); // avoid frustum culling affecting the skybox + RenderTask renderTask = window.GetRenderTaskList().GetTask(0); + renderTask.SetCullMode(false); // avoid frustum culling affecting the skybox - mCamera.Initialise( window, CAMERA_DEFAULT_POSITION, CAMERA_DEFAULT_FOV, CAMERA_DEFAULT_NEAR, CAMERA_DEFAULT_FAR ); + mCamera.Initialise(window, CAMERA_DEFAULT_POSITION, CAMERA_DEFAULT_FOV, CAMERA_DEFAULT_NEAR, CAMERA_DEFAULT_FAR); } /** @@ -216,8 +215,8 @@ public: */ void CreateShaders() { - mShaderCube = Shader::New( VERTEX_SHADER_CUBE, FRAGMENT_SHADER_CUBE ); - mShaderSkybox = Shader::New( VERTEX_SHADER_SKYBOX, FRAGMENT_SHADER_SKYBOX ); + mShaderCube = Shader::New(VERTEX_SHADER_CUBE, FRAGMENT_SHADER_CUBE); + mShaderSkybox = Shader::New(VERTEX_SHADER_SKYBOX, FRAGMENT_SHADER_SKYBOX); } /** @@ -234,70 +233,58 @@ public: }; Vertex vertices[] = { - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, }; - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR3 ) - .Add( "aTexCoord", Property::VECTOR2 ) ); - vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vertex) ); + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3) + .Add("aTexCoord", Property::VECTOR2)); + vertexBuffer.SetData(vertices, sizeof(vertices) / sizeof(Vertex)); // create indices const unsigned short INDEX_CUBE[] = { - 2, 1, 0, - 5, 4, 3, - 8, 7, 6, - 11, 10, 9, - 14, 13, 12, - 17, 16, 15, - 20, 19, 18, - 23, 22, 21, - 26, 25, 24, - 29, 28, 27, - 32, 31, 30, - 35, 34, 33 - }; + 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21, 26, 25, 24, 29, 28, 27, 32, 31, 30, 35, 34, 33}; mGeometry = Geometry::New(); - mGeometry.AddVertexBuffer( vertexBuffer ); - mGeometry.SetIndexBuffer( INDEX_CUBE, - sizeof(INDEX_CUBE)/sizeof(INDEX_CUBE[0]) ); - mGeometry.SetType( Geometry::TRIANGLES ); + mGeometry.AddVertexBuffer(vertexBuffer); + mGeometry.SetIndexBuffer(INDEX_CUBE, + sizeof(INDEX_CUBE) / sizeof(INDEX_CUBE[0])); + mGeometry.SetType(Geometry::TRIANGLES); } /** @@ -313,62 +300,61 @@ public: }; Vertex skyboxVertices[] = { - // back - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - - // left - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( -1.0f, -1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( -1.0f, 1.0f, 1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - - // right - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - - // front - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( -1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, -1.0f, 1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - - // botton - { Vector3( -1.0f, 1.0f, -1.0f ) }, - { Vector3( 1.0f, 1.0f, -1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( 1.0f, 1.0f, 1.0f ) }, - { Vector3( -1.0f, 1.0f, 1.0f ) }, - { Vector3( -1.0f, 1.0f, -1.0f ) }, - - // top - { Vector3( -1.0f, -1.0f, -1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( 1.0f, -1.0f, -1.0f ) }, - { Vector3( -1.0f, -1.0f, 1.0f ) }, - { Vector3( 1.0f, -1.0f, 1.0f ) } - }; - - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR3 ) ); - vertexBuffer.SetData( skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex) ); + // back + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + + // left + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(-1.0f, -1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(-1.0f, 1.0f, 1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + + // right + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + + // front + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(-1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, -1.0f, 1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + + // botton + {Vector3(-1.0f, 1.0f, -1.0f)}, + {Vector3(1.0f, 1.0f, -1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(1.0f, 1.0f, 1.0f)}, + {Vector3(-1.0f, 1.0f, 1.0f)}, + {Vector3(-1.0f, 1.0f, -1.0f)}, + + // top + {Vector3(-1.0f, -1.0f, -1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(1.0f, -1.0f, -1.0f)}, + {Vector3(-1.0f, -1.0f, 1.0f)}, + {Vector3(1.0f, -1.0f, 1.0f)}}; + + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3)); + vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex)); mSkyboxGeometry = Geometry::New(); - mSkyboxGeometry.AddVertexBuffer( vertexBuffer ); - mSkyboxGeometry.SetType( Geometry::TRIANGLES ); + mSkyboxGeometry.AddVertexBuffer(vertexBuffer); + mSkyboxGeometry.SetType(Geometry::TRIANGLES); } /** @@ -377,35 +363,35 @@ public: void DisplayCube() { // Load image from file - PixelData pixels = SyncImageLoader::Load( TEXTURE_URL ); + PixelData pixels = SyncImageLoader::Load(TEXTURE_URL); - Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() ); - texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() ); + Texture texture = Texture::New(TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight()); + texture.Upload(pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight()); // create TextureSet mTextureSet = TextureSet::New(); - mTextureSet.SetTexture( 0, texture ); + mTextureSet.SetTexture(0, texture); - mRenderer = Renderer::New( mGeometry, mShaderCube ); - mRenderer.SetTextures( mTextureSet ); - mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1.0f ); + mRenderer = Renderer::New(mGeometry, mShaderCube); + mRenderer.SetTextures(mTextureSet); + mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1.0f); // A further optimization would be to enable debug testing instead - mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + mRenderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); // Enables the write on the depth buffer. - mRenderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON ); + mRenderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON); mActor = Actor::New(); - mActor.SetProperty( Dali::Actor::Property::NAME, "Cube" ); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.AddRenderer( mRenderer ); + mActor.SetProperty(Dali::Actor::Property::NAME, "Cube"); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.AddRenderer(mRenderer); - mActor.SetProperty( Actor::Property::SIZE, Vector3( 10.f, 10.f, 10.f ) ); + mActor.SetProperty(Actor::Property::SIZE, Vector3(10.f, 10.f, 10.f)); Window window = mApplication.GetWindow(); - window.Add( mActor ); + window.Add(mActor); } /** @@ -414,36 +400,36 @@ public: void DisplaySkybox() { // Load skybox faces from file - Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, SKYBOX_FACE_WIDTH, SKYBOX_FACE_HEIGHT ); - for (unsigned int i = 0; i < SKYBOX_FACE_COUNT; i++) + Texture texture = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, SKYBOX_FACE_WIDTH, SKYBOX_FACE_HEIGHT); + for(unsigned int i = 0; i < SKYBOX_FACE_COUNT; i++) { - PixelData pixels = SyncImageLoader::Load( SKYBOX_FACES[i] ); - texture.Upload( pixels, CubeMapLayer::POSITIVE_X + i, 0, 0, 0, SKYBOX_FACE_WIDTH, SKYBOX_FACE_HEIGHT ); + PixelData pixels = SyncImageLoader::Load(SKYBOX_FACES[i]); + texture.Upload(pixels, CubeMapLayer::POSITIVE_X + i, 0, 0, 0, SKYBOX_FACE_WIDTH, SKYBOX_FACE_HEIGHT); } // create TextureSet mSkyboxTextures = TextureSet::New(); - mSkyboxTextures.SetTexture( 0, texture ); + mSkyboxTextures.SetTexture(0, texture); - mSkyboxRenderer = Renderer::New( mSkyboxGeometry, mShaderSkybox ); - mSkyboxRenderer.SetTextures( mSkyboxTextures ); - mSkyboxRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, 2.0f ); + mSkyboxRenderer = Renderer::New(mSkyboxGeometry, mShaderSkybox); + mSkyboxRenderer.SetTextures(mSkyboxTextures); + mSkyboxRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 2.0f); // Enables the depth test. - mSkyboxRenderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON ); + mSkyboxRenderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON); // The fragment shader will run only is those pixels that have the max depth value. - mSkyboxRenderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL ); + mSkyboxRenderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL); Window window = mApplication.GetWindow(); mSkyboxActor = Actor::New(); - mSkyboxActor.SetProperty( Dali::Actor::Property::NAME, "SkyBox" ); - mSkyboxActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mSkyboxActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mSkyboxActor.SetProperty( Actor::Property::POSITION, CAMERA_DEFAULT_POSITION ); - mSkyboxActor.AddRenderer( mSkyboxRenderer ); - window.Add( mSkyboxActor ); + mSkyboxActor.SetProperty(Dali::Actor::Property::NAME, "SkyBox"); + mSkyboxActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mSkyboxActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSkyboxActor.SetProperty(Actor::Property::POSITION, CAMERA_DEFAULT_POSITION); + mSkyboxActor.AddRenderer(mSkyboxRenderer); + window.Add(mSkyboxActor); } /** @@ -451,38 +437,38 @@ public: */ void PlayAnimation() { - mAnimation = Animation::New( 5.0f ); - mAnimation.SetLooping( true ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::ZAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::XAXIS ) ); + mAnimation = Animation::New(5.0f); + mAnimation.SetLooping(true); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::ZAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::YAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::XAXIS)); mAnimation.Play(); } private: - Application& mApplication; + Application& mApplication; LookCamera mCamera; Shader mShaderCube; Shader mShaderSkybox; - Geometry mGeometry; + Geometry mGeometry; TextureSet mTextureSet; - Renderer mRenderer; - Actor mActor; - Animation mAnimation; + Renderer mRenderer; + Actor mActor; + Animation mAnimation; - Geometry mSkyboxGeometry; + Geometry mSkyboxGeometry; TextureSet mSkyboxTextures; - Renderer mSkyboxRenderer; - Actor mSkyboxActor; + Renderer mSkyboxRenderer; + Actor mSkyboxActor; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - TexturedCubeController test( application ); + Application application = Application::New(&argc, &argv); + TexturedCubeController test(application); application.MainLoop(); return 0; } diff --git a/examples/rendering-textured-cube/rendering-textured-cube.cpp b/examples/rendering-textured-cube/rendering-textured-cube.cpp index b5f6430..e3df9de 100644 --- a/examples/rendering-textured-cube/rendering-textured-cube.cpp +++ b/examples/rendering-textured-cube/rendering-textured-cube.cpp @@ -15,14 +15,15 @@ * */ -#include #include +#include using namespace Dali; using namespace Toolkit; namespace { +// clang-format off /* * Vertex shader @@ -56,22 +57,22 @@ void main()\n gl_FragColor = texColor;\n }\n ); +// clang-format on const char* TEXTURE_URL = DEMO_IMAGE_DIR "wood.png"; -} +} // namespace // This example shows how to create textured cube // class TexturedCubeController : public ConnectionTracker { public: - - TexturedCubeController( Application& application ) - : mApplication( application ) + TexturedCubeController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TexturedCubeController::Create ); + mApplication.InitSignal().Connect(this, &TexturedCubeController::Create); } ~TexturedCubeController() @@ -80,11 +81,11 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Step 1. Create shader CreateCubeShader(); @@ -105,13 +106,13 @@ public: PlayAnimation(); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &TexturedCubeController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &TexturedCubeController::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &TexturedCubeController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &TexturedCubeController::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -124,11 +125,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -149,69 +150,57 @@ public: }; Vertex vertices[] = { - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 0.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, - { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, - { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 1.0, 0.0 ) }, - { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(0.0, 1.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, -1.0f, 1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(0.0, 0.0)}, + {Vector3(-1.0f, -1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, -1.0f, 1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, + {Vector3(1.0f, 1.0f, -1.0f), Vector2(1.0, 1.0)}, + {Vector3(-1.0f, 1.0f, -1.0f), Vector2(1.0, 0.0)}, + {Vector3(-1.0f, 1.0f, 1.0f), Vector2(0.0, 0.0)}, }; - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR3 ) - .Add( "aTexCoord", Property::VECTOR2 ) ); - vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vertex) ); + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3) + .Add("aTexCoord", Property::VECTOR2)); + vertexBuffer.SetData(vertices, sizeof(vertices) / sizeof(Vertex)); // create indices const unsigned short INDEX_CUBE[] = { - 2, 1, 0, - 5, 4, 3, - 8, 7, 6, - 11, 10, 9, - 14, 13, 12, - 17, 16, 15, - 20, 19, 18, - 23, 22, 21, - 26, 25, 24, - 29, 28, 27, - 32, 31, 30, - 35, 34, 33 - }; + 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21, 26, 25, 24, 29, 28, 27, 32, 31, 30, 35, 34, 33}; mGeometry = Geometry::New(); - mGeometry.AddVertexBuffer( vertexBuffer ); - mGeometry.SetIndexBuffer( INDEX_CUBE, - sizeof(INDEX_CUBE)/sizeof(INDEX_CUBE[0]) ); - mGeometry.SetType( Geometry::TRIANGLES ); + mGeometry.AddVertexBuffer(vertexBuffer); + mGeometry.SetIndexBuffer(INDEX_CUBE, + sizeof(INDEX_CUBE) / sizeof(INDEX_CUBE[0])); + mGeometry.SetType(Geometry::TRIANGLES); } /** @@ -222,7 +211,7 @@ public: */ void CreateCubeShader() { - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); } /** @@ -233,14 +222,14 @@ public: void CreateTexture() { // Load image from file - PixelData pixels = SyncImageLoader::Load( TEXTURE_URL ); + PixelData pixels = SyncImageLoader::Load(TEXTURE_URL); - Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() ); - texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() ); + Texture texture = Texture::New(TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight()); + texture.Upload(pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight()); // create TextureSet mTextureSet = TextureSet::New(); - mTextureSet.SetTexture( 0, texture ); + mTextureSet.SetTexture(0, texture); } /** @@ -248,12 +237,12 @@ public: */ void CreateRenderer() { - mRenderer = Renderer::New( mGeometry, mShader ); - mRenderer.SetTextures( mTextureSet ); + mRenderer = Renderer::New(mGeometry, mShader); + mRenderer.SetTextures(mTextureSet); // Face culling is enabled to hide the backwards facing sides of the cube // This is sufficient to render a single object; for more complex scenes depth-testing might be required - mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); + mRenderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK); } /** @@ -264,13 +253,13 @@ public: Window window = mApplication.GetWindow(); float quarterWindowWidth = window.GetSize().GetWidth() * 0.25f; - mActor = Actor::New(); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); - mActor.SetProperty( Actor::Property::SIZE, Vector3( quarterWindowWidth, quarterWindowWidth, quarterWindowWidth ) ); - mActor.AddRenderer( mRenderer ); - window.Add( mActor ); + mActor = Actor::New(); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); + mActor.SetProperty(Actor::Property::SIZE, Vector3(quarterWindowWidth, quarterWindowWidth, quarterWindowWidth)); + mActor.AddRenderer(mRenderer); + window.Add(mActor); } /** @@ -278,29 +267,29 @@ public: */ void PlayAnimation() { - mAnimation = Animation::New( 5.0f ); - mAnimation.SetLooping( true ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::ZAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ) ); - mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::XAXIS ) ); + mAnimation = Animation::New(5.0f); + mAnimation.SetLooping(true); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::ZAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::YAXIS)); + mAnimation.AnimateBy(Property(mActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360)), Vector3::XAXIS)); mAnimation.Play(); } private: - Application& mApplication; + Application& mApplication; - Renderer mRenderer; - Shader mShader; - Geometry mGeometry; + Renderer mRenderer; + Shader mShader; + Geometry mGeometry; TextureSet mTextureSet; - Actor mActor; - Animation mAnimation; + Actor mActor; + Animation mAnimation; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - TexturedCubeController test( application ); + Application application = Application::New(&argc, &argv); + TexturedCubeController test(application); application.MainLoop(); return 0; } diff --git a/examples/rendering-triangle/rendering-triangle.cpp b/examples/rendering-triangle/rendering-triangle.cpp index 9a2b022..1b5ef12 100644 --- a/examples/rendering-triangle/rendering-triangle.cpp +++ b/examples/rendering-triangle/rendering-triangle.cpp @@ -15,14 +15,15 @@ * */ -#include #include +#include using namespace Dali; using namespace Toolkit; namespace { +// clang-format off /* * Vertex shader @@ -51,20 +52,20 @@ void main()\n gl_FragColor = uColor;\n }\n ); +// clang-format on -} +} // namespace // This example shows how to draw a triangle in actor's color // class DrawTriangleController : public ConnectionTracker { public: - - DrawTriangleController( Application& application ) - : mApplication( application ) + DrawTriangleController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &DrawTriangleController::Create ); + mApplication.InitSignal().Connect(this, &DrawTriangleController::Create); } ~DrawTriangleController() @@ -73,11 +74,11 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Step 1. Create shader CreateTriangleShader(); @@ -92,13 +93,13 @@ public: CreateActor(); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &DrawTriangleController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &DrawTriangleController::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &DrawTriangleController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &DrawTriangleController::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -111,11 +112,11 @@ public: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -129,18 +130,17 @@ public: void CreateTriangleGeometry() { Vector2 vertices[] = { - Vector2( -1.0f, -1.0f ), - Vector2( 1.0f, 1.0f ), - Vector2( -1.0f, 1.0f ) - }; + Vector2(-1.0f, -1.0f), + Vector2(1.0f, 1.0f), + Vector2(-1.0f, 1.0f)}; - VertexBuffer vertexBuffer = VertexBuffer::New( Property::Map() - .Add( "aPosition", Property::VECTOR2 ) ); - vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vector2) ); + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR2)); + vertexBuffer.SetData(vertices, sizeof(vertices) / sizeof(Vector2)); mGeometry = Geometry::New(); - mGeometry.AddVertexBuffer( vertexBuffer ); - mGeometry.SetType( Geometry::TRIANGLES ); + mGeometry.AddVertexBuffer(vertexBuffer); + mGeometry.SetType(Geometry::TRIANGLES); } /** @@ -150,7 +150,7 @@ public: */ void CreateTriangleShader() { - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); } /** @@ -158,7 +158,7 @@ public: */ void CreateRenderer() { - mRenderer = Renderer::New( mGeometry, mShader ); + mRenderer = Renderer::New(mGeometry, mShader); } /** @@ -167,30 +167,30 @@ public: void CreateActor() { Window window = mApplication.GetWindow(); - Size size = Vector2(window.GetSize()) * 0.25f; - mActor = Actor::New(); - mActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); - mActor.SetProperty( Actor::Property::COLOR, Color::RED ); - mActor.SetProperty( Actor::Property::SIZE, Vector3( size.x, size.x, size.x ) ); - mActor.AddRenderer( mRenderer ); - window.Add( mActor ); + Size size = Vector2(window.GetSize()) * 0.25f; + mActor = Actor::New(); + mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); + mActor.SetProperty(Actor::Property::COLOR, Color::RED); + mActor.SetProperty(Actor::Property::SIZE, Vector3(size.x, size.x, size.x)); + mActor.AddRenderer(mRenderer); + window.Add(mActor); } private: - Application& mApplication; + Application& mApplication; Renderer mRenderer; - Shader mShader; + Shader mShader; Geometry mGeometry; - Actor mActor; + Actor mActor; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - DrawTriangleController test( application ); + Application application = Application::New(&argc, &argv); + DrawTriangleController test(application); application.MainLoop(); return 0; } diff --git a/examples/scroll-view/scroll-view-example.cpp b/examples/scroll-view/scroll-view-example.cpp index effe458..1f62db9 100644 --- a/examples/scroll-view/scroll-view-example.cpp +++ b/examples/scroll-view/scroll-view-example.cpp @@ -19,99 +19,97 @@ #include // INTERNAL INCLUDES -#include "shared/view.h" -#include #include +#include +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; namespace { -const char * const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-default.png" ); -const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char * const APPLICATION_TITLE( "ScrollView" ); -const char * const EFFECT_CAROUSEL_IMAGE( DEMO_IMAGE_DIR "icon-scroll-view-carousel.png" ); -const char * const EFFECT_CAROUSEL_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-scroll-view-carousel-selected.png" ); -const char * const EFFECT_CUBE_IMAGE( DEMO_IMAGE_DIR "icon-scroll-view-inner-cube.png" ); -const char * const EFFECT_CUBE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-scroll-view-inner-cube-selected.png" ); -const char * const EFFECT_SPIRAL_IMAGE( DEMO_IMAGE_DIR "icon-scroll-view-spiral.png" ); -const char * const EFFECT_SPIRAL_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-scroll-view-spiral-selected.png" ); -const char * const EFFECT_WAVE_IMAGE( DEMO_IMAGE_DIR "icon-effect-wave.png" ); -const char * const EFFECT_WAVE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-wave-selected.png" ); +const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-default.png"); +const char* const TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* const APPLICATION_TITLE("ScrollView"); +const char* const EFFECT_CAROUSEL_IMAGE(DEMO_IMAGE_DIR "icon-scroll-view-carousel.png"); +const char* const EFFECT_CAROUSEL_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-scroll-view-carousel-selected.png"); +const char* const EFFECT_CUBE_IMAGE(DEMO_IMAGE_DIR "icon-scroll-view-inner-cube.png"); +const char* const EFFECT_CUBE_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-scroll-view-inner-cube-selected.png"); +const char* const EFFECT_SPIRAL_IMAGE(DEMO_IMAGE_DIR "icon-scroll-view-spiral.png"); +const char* const EFFECT_SPIRAL_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-scroll-view-spiral-selected.png"); +const char* const EFFECT_WAVE_IMAGE(DEMO_IMAGE_DIR "icon-effect-wave.png"); +const char* const EFFECT_WAVE_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-effect-wave-selected.png"); const Vector3 ICON_SIZE(100.0f, 100.0f, 0.0f); const char* EFFECT_MODE_NAME[] = { - "PageCarousel", - "PageCube", - "PageSpiral", - "PageWave" -}; - -const char * const IMAGE_PATHS[] = { - DEMO_IMAGE_DIR "gallery-medium-1.jpg", - DEMO_IMAGE_DIR "gallery-medium-2.jpg", - DEMO_IMAGE_DIR "gallery-medium-3.jpg", - DEMO_IMAGE_DIR "gallery-medium-4.jpg", - DEMO_IMAGE_DIR "gallery-medium-5.jpg", - DEMO_IMAGE_DIR "gallery-medium-6.jpg", - DEMO_IMAGE_DIR "gallery-medium-7.jpg", - DEMO_IMAGE_DIR "gallery-medium-8.jpg", - DEMO_IMAGE_DIR "gallery-medium-9.jpg", - DEMO_IMAGE_DIR "gallery-medium-10.jpg", - DEMO_IMAGE_DIR "gallery-medium-11.jpg", - DEMO_IMAGE_DIR "gallery-medium-12.jpg", - DEMO_IMAGE_DIR "gallery-medium-13.jpg", - DEMO_IMAGE_DIR "gallery-medium-14.jpg", - DEMO_IMAGE_DIR "gallery-medium-15.jpg", - DEMO_IMAGE_DIR "gallery-medium-16.jpg", - DEMO_IMAGE_DIR "gallery-medium-17.jpg", - DEMO_IMAGE_DIR "gallery-medium-18.jpg", - DEMO_IMAGE_DIR "gallery-medium-19.jpg", - DEMO_IMAGE_DIR "gallery-medium-20.jpg", - DEMO_IMAGE_DIR "gallery-medium-21.jpg", - DEMO_IMAGE_DIR "gallery-medium-22.jpg", - DEMO_IMAGE_DIR "gallery-medium-23.jpg", - DEMO_IMAGE_DIR "gallery-medium-24.jpg", - DEMO_IMAGE_DIR "gallery-medium-25.jpg", - DEMO_IMAGE_DIR "gallery-medium-26.jpg", - DEMO_IMAGE_DIR "gallery-medium-27.jpg", - DEMO_IMAGE_DIR "gallery-medium-28.jpg", - DEMO_IMAGE_DIR "gallery-medium-29.jpg", - DEMO_IMAGE_DIR "gallery-medium-30.jpg", - DEMO_IMAGE_DIR "gallery-medium-31.jpg", - DEMO_IMAGE_DIR "gallery-medium-32.jpg", - DEMO_IMAGE_DIR "gallery-medium-33.jpg", - DEMO_IMAGE_DIR "gallery-medium-34.jpg", - DEMO_IMAGE_DIR "gallery-medium-35.jpg", - DEMO_IMAGE_DIR "gallery-medium-36.jpg", - DEMO_IMAGE_DIR "gallery-medium-37.jpg", - DEMO_IMAGE_DIR "gallery-medium-38.jpg", - DEMO_IMAGE_DIR "gallery-medium-39.jpg", - DEMO_IMAGE_DIR "gallery-medium-40.jpg", - DEMO_IMAGE_DIR "gallery-medium-41.jpg", - DEMO_IMAGE_DIR "gallery-medium-42.jpg", - DEMO_IMAGE_DIR "gallery-medium-43.jpg", - DEMO_IMAGE_DIR "gallery-medium-44.jpg", - DEMO_IMAGE_DIR "gallery-medium-45.jpg", - DEMO_IMAGE_DIR "gallery-medium-46.jpg", - DEMO_IMAGE_DIR "gallery-medium-47.jpg", - DEMO_IMAGE_DIR "gallery-medium-48.jpg", - DEMO_IMAGE_DIR "gallery-medium-49.jpg", - DEMO_IMAGE_DIR "gallery-medium-50.jpg", - DEMO_IMAGE_DIR "gallery-medium-51.jpg", - DEMO_IMAGE_DIR "gallery-medium-52.jpg", - DEMO_IMAGE_DIR "gallery-medium-53.jpg", - - NULL -}; - -const char * const GetNextImagePath() + "PageCarousel", + "PageCube", + "PageSpiral", + "PageWave"}; + +const char* const IMAGE_PATHS[] = { + DEMO_IMAGE_DIR "gallery-medium-1.jpg", + DEMO_IMAGE_DIR "gallery-medium-2.jpg", + DEMO_IMAGE_DIR "gallery-medium-3.jpg", + DEMO_IMAGE_DIR "gallery-medium-4.jpg", + DEMO_IMAGE_DIR "gallery-medium-5.jpg", + DEMO_IMAGE_DIR "gallery-medium-6.jpg", + DEMO_IMAGE_DIR "gallery-medium-7.jpg", + DEMO_IMAGE_DIR "gallery-medium-8.jpg", + DEMO_IMAGE_DIR "gallery-medium-9.jpg", + DEMO_IMAGE_DIR "gallery-medium-10.jpg", + DEMO_IMAGE_DIR "gallery-medium-11.jpg", + DEMO_IMAGE_DIR "gallery-medium-12.jpg", + DEMO_IMAGE_DIR "gallery-medium-13.jpg", + DEMO_IMAGE_DIR "gallery-medium-14.jpg", + DEMO_IMAGE_DIR "gallery-medium-15.jpg", + DEMO_IMAGE_DIR "gallery-medium-16.jpg", + DEMO_IMAGE_DIR "gallery-medium-17.jpg", + DEMO_IMAGE_DIR "gallery-medium-18.jpg", + DEMO_IMAGE_DIR "gallery-medium-19.jpg", + DEMO_IMAGE_DIR "gallery-medium-20.jpg", + DEMO_IMAGE_DIR "gallery-medium-21.jpg", + DEMO_IMAGE_DIR "gallery-medium-22.jpg", + DEMO_IMAGE_DIR "gallery-medium-23.jpg", + DEMO_IMAGE_DIR "gallery-medium-24.jpg", + DEMO_IMAGE_DIR "gallery-medium-25.jpg", + DEMO_IMAGE_DIR "gallery-medium-26.jpg", + DEMO_IMAGE_DIR "gallery-medium-27.jpg", + DEMO_IMAGE_DIR "gallery-medium-28.jpg", + DEMO_IMAGE_DIR "gallery-medium-29.jpg", + DEMO_IMAGE_DIR "gallery-medium-30.jpg", + DEMO_IMAGE_DIR "gallery-medium-31.jpg", + DEMO_IMAGE_DIR "gallery-medium-32.jpg", + DEMO_IMAGE_DIR "gallery-medium-33.jpg", + DEMO_IMAGE_DIR "gallery-medium-34.jpg", + DEMO_IMAGE_DIR "gallery-medium-35.jpg", + DEMO_IMAGE_DIR "gallery-medium-36.jpg", + DEMO_IMAGE_DIR "gallery-medium-37.jpg", + DEMO_IMAGE_DIR "gallery-medium-38.jpg", + DEMO_IMAGE_DIR "gallery-medium-39.jpg", + DEMO_IMAGE_DIR "gallery-medium-40.jpg", + DEMO_IMAGE_DIR "gallery-medium-41.jpg", + DEMO_IMAGE_DIR "gallery-medium-42.jpg", + DEMO_IMAGE_DIR "gallery-medium-43.jpg", + DEMO_IMAGE_DIR "gallery-medium-44.jpg", + DEMO_IMAGE_DIR "gallery-medium-45.jpg", + DEMO_IMAGE_DIR "gallery-medium-46.jpg", + DEMO_IMAGE_DIR "gallery-medium-47.jpg", + DEMO_IMAGE_DIR "gallery-medium-48.jpg", + DEMO_IMAGE_DIR "gallery-medium-49.jpg", + DEMO_IMAGE_DIR "gallery-medium-50.jpg", + DEMO_IMAGE_DIR "gallery-medium-51.jpg", + DEMO_IMAGE_DIR "gallery-medium-52.jpg", + DEMO_IMAGE_DIR "gallery-medium-53.jpg", + + NULL}; + +const char* const GetNextImagePath() { - static const char * const * imagePtr = &IMAGE_PATHS[0]; + static const char* const* imagePtr = &IMAGE_PATHS[0]; - if ( *(++imagePtr) == NULL ) + if(*(++imagePtr) == NULL) { imagePtr = &IMAGE_PATHS[0]; } @@ -119,17 +117,17 @@ const char * const GetNextImagePath() return *imagePtr; } -const int PAGE_COLUMNS = 10; ///< Number of Pages going across (columns) -const int PAGE_ROWS = 1; ///< Number of Pages going down (rows) -const int IMAGE_ROWS = 5; ///< Number of Images going down (rows) with a Page +const int PAGE_COLUMNS = 10; ///< Number of Pages going across (columns) +const int PAGE_ROWS = 1; ///< Number of Pages going down (rows) +const int IMAGE_ROWS = 5; ///< Number of Images going down (rows) with a Page -const unsigned int IMAGE_THUMBNAIL_WIDTH = 256; ///< Width of Thumbnail Image in texels -const unsigned int IMAGE_THUMBNAIL_HEIGHT = 256; ///< Height of Thumbnail Image in texels +const unsigned int IMAGE_THUMBNAIL_WIDTH = 256; ///< Width of Thumbnail Image in texels +const unsigned int IMAGE_THUMBNAIL_HEIGHT = 256; ///< Height of Thumbnail Image in texels -const float SPIN_DURATION = 1.0f; ///< Times to spin an Image by upon touching, each spin taking a second. +const float SPIN_DURATION = 1.0f; ///< Times to spin an Image by upon touching, each spin taking a second. -const float EFFECT_SNAP_DURATION(0.66f); ///< Scroll Snap Duration for Effects -const float EFFECT_FLICK_DURATION(0.5f); ///< Scroll Flick Duration for Effects +const float EFFECT_SNAP_DURATION(0.66f); ///< Scroll Snap Duration for Effects +const float EFFECT_FLICK_DURATION(0.5f); ///< Scroll Flick Duration for Effects } // unnamed namespace @@ -139,13 +137,12 @@ const float EFFECT_FLICK_DURATION(0.5f); ///< class ExampleController : public ConnectionTracker { public: - /** * Constructor * @param application class, stored as reference */ - ExampleController( Application& application ) - : mApplication( application ), + ExampleController(Application& application) + : mApplication(application), mView(), mScrolling(false), mEffectMode(PageCarouselEffect) @@ -169,66 +166,65 @@ public: // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( app, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); - - mEffectIcon[ PageCarouselEffect ] = EFFECT_CAROUSEL_IMAGE; - mEffectIconSelected[ PageCarouselEffect ] = EFFECT_CAROUSEL_IMAGE_SELECTED; - mEffectIcon[ PageCubeEffect ] = EFFECT_CUBE_IMAGE; - mEffectIconSelected[ PageCubeEffect ] = EFFECT_CUBE_IMAGE_SELECTED; - mEffectIcon[ PageSpiralEffect ] = EFFECT_SPIRAL_IMAGE; - mEffectIconSelected[ PageSpiralEffect ] = EFFECT_SPIRAL_IMAGE_SELECTED; - mEffectIcon[ PageWaveEffect ] = EFFECT_WAVE_IMAGE; - mEffectIconSelected[ PageWaveEffect ] = EFFECT_WAVE_IMAGE_SELECTED; + mContentLayer = DemoHelper::CreateView(app, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); + + mEffectIcon[PageCarouselEffect] = EFFECT_CAROUSEL_IMAGE; + mEffectIconSelected[PageCarouselEffect] = EFFECT_CAROUSEL_IMAGE_SELECTED; + mEffectIcon[PageCubeEffect] = EFFECT_CUBE_IMAGE; + mEffectIconSelected[PageCubeEffect] = EFFECT_CUBE_IMAGE_SELECTED; + mEffectIcon[PageSpiralEffect] = EFFECT_SPIRAL_IMAGE; + mEffectIconSelected[PageSpiralEffect] = EFFECT_SPIRAL_IMAGE_SELECTED; + mEffectIcon[PageWaveEffect] = EFFECT_WAVE_IMAGE; + mEffectIconSelected[PageWaveEffect] = EFFECT_WAVE_IMAGE_SELECTED; // Create a effect change button. (right of toolbar) mEffectChangeButton = Toolkit::PushButton::New(); - mEffectChangeButton.ClickedSignal().Connect( this, &ExampleController::OnEffectTouched ); - mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mEffectChangeButton.ClickedSignal().Connect(this, &ExampleController::OnEffectTouched); + mToolBar.AddControl(mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create the content layer. AddContentLayer(); // Hack to force screen refresh. Animation animation = Animation::New(1.0f); - animation.AnimateTo(Property(mContentLayer, Actor::Property::POSITION), Vector3::ZERO ); + animation.AnimateTo(Property(mContentLayer, Actor::Property::POSITION), Vector3::ZERO); animation.Play(); } private: - /** * Adds content to the ContentLayer. This is everything we see * excluding the toolbar at the top. */ void AddContentLayer() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); mScrollView = ScrollView::New(); - mScrollView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - mScrollView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mContentLayer.Add( mScrollView ); - mScrollView.SetProperty( Actor::Property::SIZE, windowSize ); - mScrollView.SetAxisAutoLock( true ); - mScrollView.SetAxisAutoLockGradient( 1.0f ); + mScrollView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mScrollView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mContentLayer.Add(mScrollView); + mScrollView.SetProperty(Actor::Property::SIZE, windowSize); + mScrollView.SetAxisAutoLock(true); + mScrollView.SetAxisAutoLockGradient(1.0f); - mScrollView.ScrollStartedSignal().Connect( this, &ExampleController::OnScrollStarted ); - mScrollView.ScrollCompletedSignal().Connect( this, &ExampleController::OnScrollCompleted ); + mScrollView.ScrollStartedSignal().Connect(this, &ExampleController::OnScrollStarted); + mScrollView.ScrollCompletedSignal().Connect(this, &ExampleController::OnScrollCompleted); - for(int row = 0;row::iterator pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter) + for(std::vector::iterator pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter) { Actor page = *pageIter; - ApplyEffectToPage( page, pageCount++ ); + ApplyEffectToPage(page, pageCount++); } } @@ -272,33 +268,33 @@ private: Actor CreatePage() { Actor page = Actor::New(); - page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - page.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - page.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + page.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + page.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + page.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); const float margin = 10.0f; // Calculate the number of images going across (columns) within a page, according to the screen resolution - int imageColumns = round(IMAGE_ROWS * (windowSize.x / windowSize.y)); + int imageColumns = round(IMAGE_ROWS * (windowSize.x / windowSize.y)); const Vector3 imageSize((windowSize.x / imageColumns) - margin, (windowSize.y / IMAGE_ROWS) - margin, 0.0f); - for(int row = 0;rowSetDomain(RulerDomain(0.0f, windowSize.x * PAGE_COLUMNS, false)); rulerY->Disable(); - Dali::Path path = Dali::Path::New(); + Dali::Path path = Dali::Path::New(); Dali::Property::Array points; - points.Resize(3); + points.Resize(3); Dali::Property::Array controlPoints; - controlPoints.Resize(4); + controlPoints.Resize(4); Vector3 forward; - if( mEffectMode == PageCarouselEffect) + if(mEffectMode == PageCarouselEffect) { + points[0] = Vector3(windowSize.x * 0.75, 0.0f, -windowSize.x * 0.75f); + points[1] = Vector3(0.0f, 0.0f, 0.0f); + points[2] = Vector3(-windowSize.x * 0.75f, 0.0f, -windowSize.x * 0.75f); + path.SetProperty(Path::Property::POINTS, points); - points[0] = Vector3( windowSize.x*0.75, 0.0f, -windowSize.x*0.75f); - points[1] = Vector3( 0.0f, 0.0f, 0.0f ); - points[2] = Vector3( -windowSize.x*0.75f, 0.0f, -windowSize.x*0.75f); - path.SetProperty( Path::Property::POINTS, points ); - - controlPoints[0] = Vector3( windowSize.x*0.5f, 0.0f, 0.0f ); - controlPoints[1] = Vector3( windowSize.x*0.5f, 0.0f, 0.0f ); - controlPoints[2] = Vector3(-windowSize.x*0.5f, 0.0f, 0.0f ); - controlPoints[3] = Vector3(-windowSize.x*0.5f, 0.0f, 0.0f ); - path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); + controlPoints[0] = Vector3(windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[1] = Vector3(windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[2] = Vector3(-windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[3] = Vector3(-windowSize.x * 0.5f, 0.0f, 0.0f); + path.SetProperty(Path::Property::CONTROL_POINTS, controlPoints); forward = Vector3::ZERO; } - else if( mEffectMode == PageCubeEffect) + else if(mEffectMode == PageCubeEffect) { - points[0] = Vector3( windowSize.x*0.5, 0.0f, windowSize.x*0.5f); - points[1] = Vector3( 0.0f, 0.0f, 0.0f ); - points[2] = Vector3( -windowSize.x*0.5f, 0.0f, windowSize.x*0.5f); - path.SetProperty( Path::Property::POINTS, points ); - - controlPoints[0] = Vector3( windowSize.x*0.5f, 0.0f, windowSize.x*0.3f ); - controlPoints[1] = Vector3( windowSize.x*0.3f, 0.0f, 0.0f ); - controlPoints[2] = Vector3(-windowSize.x*0.3f, 0.0f, 0.0f ); - controlPoints[3] = Vector3(-windowSize.x*0.5f, 0.0f, windowSize.x*0.3f ); - path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); - - forward = Vector3(-1.0f,0.0f,0.0f); + points[0] = Vector3(windowSize.x * 0.5, 0.0f, windowSize.x * 0.5f); + points[1] = Vector3(0.0f, 0.0f, 0.0f); + points[2] = Vector3(-windowSize.x * 0.5f, 0.0f, windowSize.x * 0.5f); + path.SetProperty(Path::Property::POINTS, points); + + controlPoints[0] = Vector3(windowSize.x * 0.5f, 0.0f, windowSize.x * 0.3f); + controlPoints[1] = Vector3(windowSize.x * 0.3f, 0.0f, 0.0f); + controlPoints[2] = Vector3(-windowSize.x * 0.3f, 0.0f, 0.0f); + controlPoints[3] = Vector3(-windowSize.x * 0.5f, 0.0f, windowSize.x * 0.3f); + path.SetProperty(Path::Property::CONTROL_POINTS, controlPoints); + + forward = Vector3(-1.0f, 0.0f, 0.0f); } - else if( mEffectMode == PageSpiralEffect) + else if(mEffectMode == PageSpiralEffect) { - points[0] = Vector3( windowSize.x*0.5, 0.0f, -windowSize.x*0.5f); - points[1] = Vector3( 0.0f, 0.0f, 0.0f ); - points[2] = Vector3( -windowSize.x*0.5f, 0.0f, -windowSize.x*0.5f); - path.SetProperty( Path::Property::POINTS, points ); - - controlPoints[0] = Vector3( windowSize.x*0.5f, 0.0f, 0.0f ); - controlPoints[1] = Vector3( windowSize.x*0.5f, 0.0f, 0.0f ); - controlPoints[2] = Vector3(-windowSize.x*0.5f, 0.0f, 0.0f ); - controlPoints[3] = Vector3(-windowSize.x*0.5f, 0.0f, 0.0f ); - path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); - - forward = Vector3(-1.0f,0.0f,0.0f); + points[0] = Vector3(windowSize.x * 0.5, 0.0f, -windowSize.x * 0.5f); + points[1] = Vector3(0.0f, 0.0f, 0.0f); + points[2] = Vector3(-windowSize.x * 0.5f, 0.0f, -windowSize.x * 0.5f); + path.SetProperty(Path::Property::POINTS, points); + + controlPoints[0] = Vector3(windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[1] = Vector3(windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[2] = Vector3(-windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[3] = Vector3(-windowSize.x * 0.5f, 0.0f, 0.0f); + path.SetProperty(Path::Property::CONTROL_POINTS, controlPoints); + + forward = Vector3(-1.0f, 0.0f, 0.0f); } - else if( mEffectMode == PageWaveEffect) + else if(mEffectMode == PageWaveEffect) { - points[0] = Vector3( windowSize.x, 0.0f, -windowSize.x); - points[1] = Vector3( 0.0f, 0.0f, 0.0f ); - points[2] = Vector3( -windowSize.x, 0.0f, -windowSize.x); - path.SetProperty( Path::Property::POINTS, points ); - - controlPoints[0] = Vector3( 0.0f, 0.0f, -windowSize.x ); - controlPoints[1] = Vector3( windowSize.x*0.5f, 0.0f, 0.0f ); - controlPoints[2] = Vector3( -windowSize.x*0.5f, 0.0f, 0.0f); - controlPoints[3] = Vector3(0.0f, 0.0f,-windowSize.x ); - path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); - - forward = Vector3(-1.0f,0.0f,0.0f); + points[0] = Vector3(windowSize.x, 0.0f, -windowSize.x); + points[1] = Vector3(0.0f, 0.0f, 0.0f); + points[2] = Vector3(-windowSize.x, 0.0f, -windowSize.x); + path.SetProperty(Path::Property::POINTS, points); + + controlPoints[0] = Vector3(0.0f, 0.0f, -windowSize.x); + controlPoints[1] = Vector3(windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[2] = Vector3(-windowSize.x * 0.5f, 0.0f, 0.0f); + controlPoints[3] = Vector3(0.0f, 0.0f, -windowSize.x); + path.SetProperty(Path::Property::CONTROL_POINTS, controlPoints); + + forward = Vector3(-1.0f, 0.0f, 0.0f); } - mScrollViewEffect = ScrollViewPagePathEffect::New(path, forward,Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(windowSize.x,windowSize.y,0.0f),PAGE_COLUMNS); + mScrollViewEffect = ScrollViewPagePathEffect::New(path, forward, Toolkit::ScrollView::Property::SCROLL_FINAL_X, Vector3(windowSize.x, windowSize.y, 0.0f), PAGE_COLUMNS); mScrollView.SetScrollSnapDuration(EFFECT_SNAP_DURATION); mScrollView.SetScrollFlickDuration(EFFECT_FLICK_DURATION); mScrollView.SetScrollSnapAlphaFunction(AlphaFunction::EASE_OUT); @@ -398,19 +393,19 @@ private: mScrollView.RemoveConstraintsFromChildren(); rulerX = CreateRuler(snap ? windowSize.width * 0.5f : 0.0f); - rulerX->SetDomain( RulerDomain( 0.0f, windowSize.x * 0.5f * PAGE_COLUMNS, false ) ); + rulerX->SetDomain(RulerDomain(0.0f, windowSize.x * 0.5f * PAGE_COLUMNS, false)); unsigned int currentPage = mScrollView.GetCurrentPage(); - if( mScrollViewEffect ) + if(mScrollViewEffect) { mScrollView.ApplyEffect(mScrollViewEffect); } - mScrollView.SetWrapMode( true ); - mScrollView.SetRulerX( rulerX ); - mScrollView.SetRulerY( rulerY ); + mScrollView.SetWrapMode(true); + mScrollView.SetRulerX(rulerX); + mScrollView.SetRulerY(rulerY); - mScrollView.ScrollTo( currentPage, 0.0f ); + mScrollView.ScrollTo(currentPage, 0.0f); } /** @@ -426,7 +421,7 @@ private: { if(gridSize <= Math::MACHINE_EPSILON_0) { - return new DefaultRuler(); + return new DefaultRuler(); } return new FixedRuler(gridSize); } @@ -437,14 +432,14 @@ private: * * @param[in] page The page Actor to apply effect to. */ - void ApplyEffectToPage(Actor page, unsigned int pageOrder ) - { - page.RemoveConstraints(); - page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + void ApplyEffectToPage(Actor page, unsigned int pageOrder) + { + page.RemoveConstraints(); + page.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - ScrollViewPagePathEffect effect = ScrollViewPagePathEffect::DownCast( mScrollViewEffect ); - effect.ApplyToPage( page, pageOrder ); - } + ScrollViewPagePathEffect effect = ScrollViewPagePathEffect::DownCast(mScrollViewEffect); + effect.ApplyToPage(page, pageOrder); + } /** * Creates an Image (Helper) @@ -453,23 +448,23 @@ private: * @param[in] width the width of the image in texels * @param[in] height the height of the image in texels. */ - ImageView CreateImage( const std::string& filename, int width = IMAGE_THUMBNAIL_WIDTH, int height = IMAGE_THUMBNAIL_HEIGHT ) + ImageView CreateImage(const std::string& filename, int width = IMAGE_THUMBNAIL_WIDTH, int height = IMAGE_THUMBNAIL_HEIGHT) { - ImageView actor = ImageView::New(); + ImageView actor = ImageView::New(); Property::Map map; - map[Visual::Property::TYPE] = Visual::IMAGE; - map[ImageVisual::Property::URL] = filename; - map[ImageVisual::Property::DESIRED_WIDTH] = width; + map[Visual::Property::TYPE] = Visual::IMAGE; + map[ImageVisual::Property::URL] = filename; + map[ImageVisual::Property::DESIRED_WIDTH] = width; map[ImageVisual::Property::DESIRED_HEIGHT] = height; - map[ImageVisual::Property::FITTING_MODE] = FittingMode::SCALE_TO_FILL; - map[ImageVisual::Property::SAMPLING_MODE] = SamplingMode::BOX_THEN_LINEAR; - actor.SetProperty( ImageView::Property::IMAGE, map ); + map[ImageVisual::Property::FITTING_MODE] = FittingMode::SCALE_TO_FILL; + map[ImageVisual::Property::SAMPLING_MODE] = SamplingMode::BOX_THEN_LINEAR; + actor.SetProperty(ImageView::Property::IMAGE, map); - actor.SetProperty( Dali::Actor::Property::NAME, filename ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); + actor.SetProperty(Dali::Actor::Property::NAME, filename); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - actor.TouchedSignal().Connect( this, &ExampleController::OnTouchImage ); + actor.TouchedSignal().Connect(this, &ExampleController::OnTouchImage); return actor; } @@ -478,7 +473,7 @@ private: * note this state (mScrolling = true) * @param[in] position Current Scroll Position */ - void OnScrollStarted( const Vector2& position ) + void OnScrollStarted(const Vector2& position) { mScrolling = true; } @@ -488,7 +483,7 @@ private: * note this state (mScrolling = false) * @param[in] position Current Scroll Position */ - void OnScrollCompleted( const Vector2& position ) + void OnScrollCompleted(const Vector2& position) { mScrolling = false; } @@ -499,15 +494,15 @@ private: * @param[in] actor The actor touched * @param[in] event The touch information. */ - bool OnTouchImage( Actor actor, const TouchEvent& event ) + bool OnTouchImage(Actor actor, const TouchEvent& event) { - if( (event.GetPointCount() > 0) && (!mScrolling) ) + if((event.GetPointCount() > 0) && (!mScrolling)) { - if( event.GetState( 0 ) == PointState::UP ) + if(event.GetState(0) == PointState::UP) { // Spin the Image a few times. Animation animation = Animation::New(SPIN_DURATION); - animation.AnimateBy( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(360.0f * SPIN_DURATION) ), Vector3::XAXIS ), AlphaFunction::EASE_OUT ); + animation.AnimateBy(Property(actor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f * SPIN_DURATION)), Vector3::XAXIS), AlphaFunction::EASE_OUT); animation.Play(); } } @@ -534,12 +529,12 @@ private: { if(!mTitleActor) { - mTitleActor = DemoHelper::CreateToolBarLabel( "" ); + mTitleActor = DemoHelper::CreateToolBarLabel(""); // Add title to the tool bar. - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER ); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER); } - mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, title ); + mTitleActor.SetProperty(Toolkit::TextLabel::Property::TEXT, title); } /** @@ -549,7 +544,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -557,40 +552,39 @@ private: } private: - - Application& mApplication; ///< Application instance - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - TextLabel mTitleActor; ///< The Toolbar's Title. - Layer mContentLayer; ///< The content layer (contains game actors) - ScrollView mScrollView; ///< ScrollView UI Component - bool mScrolling; ///< ScrollView scrolling state (true = scrolling, false = stationary) - ScrollViewEffect mScrollViewEffect; ///< ScrollView Effect instance. - std::vector< Actor > mPages; ///< Keeps track of all the pages for applying effects. + Application& mApplication; ///< Application instance + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + TextLabel mTitleActor; ///< The Toolbar's Title. + Layer mContentLayer; ///< The content layer (contains game actors) + ScrollView mScrollView; ///< ScrollView UI Component + bool mScrolling; ///< ScrollView scrolling state (true = scrolling, false = stationary) + ScrollViewEffect mScrollViewEffect; ///< ScrollView Effect instance. + std::vector mPages; ///< Keeps track of all the pages for applying effects. /** * Enumeration of different effects this scrollview can operate under. */ enum EffectMode { - PageCarouselEffect, ///< Page carousel effect - PageCubeEffect, ///< Page cube effect - PageSpiralEffect, ///< Page spiral effect - PageWaveEffect, ///< Page wave effect + PageCarouselEffect, ///< Page carousel effect + PageCubeEffect, ///< Page cube effect + PageSpiralEffect, ///< Page spiral effect + PageWaveEffect, ///< Page wave effect Total }; - EffectMode mEffectMode; ///< Current Effect mode + EffectMode mEffectMode; ///< Current Effect mode - std::string mEffectIcon[Total]; ///< Icons for the effect button - std::string mEffectIconSelected[Total]; ///< Icons for the effect button when its selected - Toolkit::PushButton mEffectChangeButton; ///< Effect Change Button + std::string mEffectIcon[Total]; ///< Icons for the effect button + std::string mEffectIconSelected[Total]; ///< Icons for the effect button when its selected + Toolkit::PushButton mEffectChangeButton; ///< Effect Change Button }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ExampleController test(app); app.MainLoop(); return 0; diff --git a/examples/shadows-and-lights/shadows-and-lights-example.cpp b/examples/shadows-and-lights/shadows-and-lights-example.cpp old mode 100755 new mode 100644 index 1141704..8c3ec13 --- a/examples/shadows-and-lights/shadows-and-lights-example.cpp +++ b/examples/shadows-and-lights/shadows-and-lights-example.cpp @@ -18,9 +18,9 @@ // INTERNAL INCLUDES #include "shared/view.h" -#include #include #include +#include #include @@ -31,39 +31,39 @@ using namespace DemoHelper; namespace { -const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-default.png" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); - -const char* APPLICATION_TITLE_PAN_LIGHT( "Lighting: Pan Light" ); -const char* APPLICATION_TITLE_ROTATE_OBJECT( "Lighting: Rotate Object" ); -const char* APPLICATION_TITLE_PAN_SCENE( "Lighting: Pan Scene" ); -const char* APPLICATION_TITLE_ROTATE_SCENE( "Lighting: Rotate Scene" ); -const char* CHANGE_EFFECT_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* CHANGE_EFFECT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char* RESET_ICON( DEMO_IMAGE_DIR "icon-reset.png" ); -const char* RESET_ICON_SELECTED( DEMO_IMAGE_DIR "icon-reset-selected.png" ); - -const char* SCENE_IMAGE_1( DEMO_IMAGE_DIR "gallery-small-10.jpg"); -const char* SCENE_IMAGE_2( DEMO_IMAGE_DIR "gallery-small-42.jpg"); -const char* SCENE_IMAGE_3( DEMO_IMAGE_DIR "gallery-small-48.jpg"); - -const float MIN_PINCH_SCALE( 0.3f ); -const float MAX_PINCH_SCALE( 2.05f ); - -const float R3_2(0.8660254); -const Vector3 TOP_POINT( 0.0f, -1.0f, 0.0f); -const Vector3 LEFT_POINT( -R3_2, 0.5f, 0.0f); -const Vector3 RIGHT_POINT( R3_2, 0.5f, 0.0f); -const Vector3 FRONT_POINT( 0.0f, 0.0f, 20.0f); - -const Vector2 DEFAULT_WINDOW_SIZE( 480.0f, 800.0f ); - -const float X_ROTATION_DISPLACEMENT_FACTOR = 60.f; -const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.f; -const float LIGHT_PAN_X_DISPLACEMENT_FACTOR = 1/360.f; -const float LIGHT_PAN_Y_DISPLACEMENT_FACTOR = 1/360.f; +const char* BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-default.png"); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); -} +const char* APPLICATION_TITLE_PAN_LIGHT("Lighting: Pan Light"); +const char* APPLICATION_TITLE_ROTATE_OBJECT("Lighting: Rotate Object"); +const char* APPLICATION_TITLE_PAN_SCENE("Lighting: Pan Scene"); +const char* APPLICATION_TITLE_ROTATE_SCENE("Lighting: Rotate Scene"); +const char* CHANGE_EFFECT_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* CHANGE_EFFECT_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* RESET_ICON(DEMO_IMAGE_DIR "icon-reset.png"); +const char* RESET_ICON_SELECTED(DEMO_IMAGE_DIR "icon-reset-selected.png"); + +const char* SCENE_IMAGE_1(DEMO_IMAGE_DIR "gallery-small-10.jpg"); +const char* SCENE_IMAGE_2(DEMO_IMAGE_DIR "gallery-small-42.jpg"); +const char* SCENE_IMAGE_3(DEMO_IMAGE_DIR "gallery-small-48.jpg"); + +const float MIN_PINCH_SCALE(0.3f); +const float MAX_PINCH_SCALE(2.05f); + +const float R3_2(0.8660254); +const Vector3 TOP_POINT(0.0f, -1.0f, 0.0f); +const Vector3 LEFT_POINT(-R3_2, 0.5f, 0.0f); +const Vector3 RIGHT_POINT(R3_2, 0.5f, 0.0f); +const Vector3 FRONT_POINT(0.0f, 0.0f, 20.0f); + +const Vector2 DEFAULT_WINDOW_SIZE(480.0f, 800.0f); + +const float X_ROTATION_DISPLACEMENT_FACTOR = 60.f; +const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.f; +const float LIGHT_PAN_X_DISPLACEMENT_FACTOR = 1 / 360.f; +const float LIGHT_PAN_Y_DISPLACEMENT_FACTOR = 1 / 360.f; + +} // namespace /** * This example shows a fixed point light onto an animating set of images @@ -73,19 +73,18 @@ const float LIGHT_PAN_Y_DISPLACEMENT_FACTOR = 1/360.f; class TestApp : public ConnectionTracker { public: - /** * Constructor * @param application class, stored as reference */ - TestApp(Application &app) + TestApp(Application& app) : mApp(app), mView(), mContents(), mSceneActor(), mAnimation(), mSceneAnimation(), - mPaused( false ), + mPaused(false), mShadowView(), mShadowPlaneBg(), mShadowPlane(), @@ -97,19 +96,19 @@ public: mPanGestureDetector(), mPinchGestureDetector(), mTapGestureDetector(), - mTranslation( 22.0f, -1.0f, 0.0f ), - mSceneXRotation( Degree(-6.0f) ), // Initial values give a reasonable off-straight view. - mSceneYRotation( Degree(20.0f) ), - mLightXRotation( Degree(-1.5f) ), - mLightYRotation( Degree(-9.5f) ), + mTranslation(22.0f, -1.0f, 0.0f), + mSceneXRotation(Degree(-6.0f)), // Initial values give a reasonable off-straight view. + mSceneYRotation(Degree(20.0f)), + mLightXRotation(Degree(-1.5f)), + mLightYRotation(Degree(-9.5f)), mObjectXRotation(0.0f), mObjectYRotation(0.0f), mPinchScale(0.6f), mScaleAtPinchStart(0.6f), - mAngle1Index( Property::INVALID_INDEX ), - mAngle3Index( Property::INVALID_INDEX ), + mAngle1Index(Property::INVALID_INDEX), + mAngle3Index(Property::INVALID_INDEX), mTitleActor(), - mPanState( PAN_LIGHT ) + mPanState(PAN_LIGHT) { app.InitSignal().Connect(this, &TestApp::Create); app.TerminateSignal().Connect(this, &TestApp::Terminate); @@ -121,7 +120,6 @@ public: } public: - struct RotationConstraint { RotationConstraint(float sign) @@ -129,10 +127,10 @@ public: { } - void operator()( Quaternion& current, const PropertyInputContainer& inputs ) + void operator()(Quaternion& current, const PropertyInputContainer& inputs) { - Radian angle( inputs[0]->GetFloat() ); - current = Quaternion( angle * mSign, Vector3::YAXIS ); + Radian angle(inputs[0]->GetFloat()); + current = Quaternion(angle * mSign, Vector3::YAXIS); } float mSign; @@ -157,170 +155,167 @@ public: // Creates a default view with a default tool bar. // The view is added to the window. Toolkit::ToolBar toolBar; - mContents = DemoHelper::CreateView( app, - mView, - toolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); + mContents = DemoHelper::CreateView(app, + mView, + toolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); // Add an effect-changing button on the right of the tool bar. Toolkit::PushButton effectChangeButton = Toolkit::PushButton::New(); - effectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_EFFECT_IMAGE ); - effectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_EFFECT_IMAGE_SELECTED ); - effectChangeButton.ClickedSignal().Connect( this, &TestApp::OnEffectButtonClicked ); - toolBar.AddControl( effectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + effectChangeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_EFFECT_IMAGE); + effectChangeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_EFFECT_IMAGE_SELECTED); + effectChangeButton.ClickedSignal().Connect(this, &TestApp::OnEffectButtonClicked); + toolBar.AddControl(effectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Add title to the tool bar. - mTitleActor = DemoHelper::CreateToolBarLabel( "" ); - toolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER ); + mTitleActor = DemoHelper::CreateToolBarLabel(""); + toolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER); // Set Title text - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_LIGHT) ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_LIGHT)); //Add a reset button Toolkit::PushButton resetButton = Toolkit::PushButton::New(); - resetButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, RESET_ICON ); - resetButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, RESET_ICON_SELECTED ); - resetButton.ClickedSignal().Connect( this, &TestApp::OnResetPressed ); - toolBar.AddControl( resetButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING ); + resetButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, RESET_ICON); + resetButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, RESET_ICON_SELECTED); + resetButton.ClickedSignal().Connect(this, &TestApp::OnResetPressed); + toolBar.AddControl(resetButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING); // Setup - mView.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 0.0f ) ); + mView.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f)); - mContents.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); - mContents.SetProperty( Actor::Property::POSITION, mTranslation ); - mContents.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); - mContents.SetProperty( Actor::Property::SCALE, Vector3( mPinchScale, mPinchScale, mPinchScale ) ); + mContents.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D); + mContents.SetProperty(Actor::Property::POSITION, mTranslation); + mContents.SetProperty(Actor::Property::ORIENTATION, CalculateWorldRotation(mSceneXRotation, mSceneYRotation)); + mContents.SetProperty(Actor::Property::SCALE, Vector3(mPinchScale, mPinchScale, mPinchScale)); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( mView ); + mPanGestureDetector.Attach(mView); mPanGestureDetector.DetectedSignal().Connect(this, &TestApp::OnPan); mPinchGestureDetector = PinchGestureDetector::New(); - mPinchGestureDetector.Attach( mView ); + mPinchGestureDetector.Attach(mView); mPinchGestureDetector.DetectedSignal().Connect(this, &TestApp::OnPinch); mTapGestureDetector = TapGestureDetector::New(); - mTapGestureDetector.Attach( mView ); + mTapGestureDetector.Attach(mView); mTapGestureDetector.DetectedSignal().Connect(this, &TestApp::OnTap); } - - void CreateShadowViewAndLights() { mShadowView = Toolkit::ShadowView::New(); - mShadowView.SetProperty( Dali::Actor::Property::NAME,"Container"); - mShadowView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mShadowView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - mShadowView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mShadowView.SetPointLightFieldOfView( Math::PI / 2.0f); + mShadowView.SetProperty(Dali::Actor::Property::NAME, "Container"); + mShadowView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mShadowView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mShadowView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mShadowView.SetPointLightFieldOfView(Math::PI / 2.0f); mContents.Add(mShadowView); - mShadowPlaneBg = ImageView::New( DEMO_IMAGE_DIR "brick-wall.jpg" ); - mShadowPlaneBg.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mShadowPlaneBg.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - mShadowPlaneBg.SetProperty( Dali::Actor::Property::NAME,"Plane"); - mShadowPlaneBg.SetProperty( Actor::Property::SIZE, Vector2(1000.0f, 1000.0f) ); + mShadowPlaneBg = ImageView::New(DEMO_IMAGE_DIR "brick-wall.jpg"); + mShadowPlaneBg.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mShadowPlaneBg.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mShadowPlaneBg.SetProperty(Dali::Actor::Property::NAME, "Plane"); + mShadowPlaneBg.SetProperty(Actor::Property::SIZE, Vector2(1000.0f, 1000.0f)); mContents.Add(mShadowPlaneBg); - mShadowPlaneBg.SetProperty( Actor::Property::POSITION, Vector3(50.0f, 50.0f, -200.0f)); + mShadowPlaneBg.SetProperty(Actor::Property::POSITION, Vector3(50.0f, 50.0f, -200.0f)); mShadowView.SetShadowPlaneBackground(mShadowPlaneBg); mShadowView.Activate(); mLightAnchor = Actor::New(); - mLightAnchor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mLightAnchor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - mLightAnchor.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mLightXRotation, mLightYRotation ) ); + mLightAnchor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLightAnchor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLightAnchor.SetProperty(Actor::Property::ORIENTATION, CalculateWorldRotation(mLightXRotation, mLightYRotation)); // Work out a scaling factor as the initial light position was calculated for desktop // Need to scale light position as scene actor size is based on window size (i.e. much bigger on device) - Vector2 windowSize( mApp.GetWindow().GetSize() ); - float scaleFactor = windowSize.x / DEFAULT_WINDOW_SIZE.x; + Vector2 windowSize(mApp.GetWindow().GetSize()); + float scaleFactor = windowSize.x / DEFAULT_WINDOW_SIZE.x; mCastingLight = Actor::New(); - mCastingLight.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); - mCastingLight.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER); - mCastingLight.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 800.0f ) * scaleFactor ); + mCastingLight.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCastingLight.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCastingLight.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 800.0f) * scaleFactor); - TextLabel text = TextLabel::New( "Light" ); - text.SetProperty( TextLabel::Property::POINT_SIZE, 20.0f ); - text.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Actor::Property::COLOR, Color::BLUE ); + TextLabel text = TextLabel::New("Light"); + text.SetProperty(TextLabel::Property::POINT_SIZE, 20.0f); + text.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + text.SetProperty(Actor::Property::COLOR, Color::BLUE); mCastingLight.Add(text); mLightAnchor.Add(mCastingLight); mShadowPlaneBg.Add(mLightAnchor); - text.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); mShadowView.SetPointLight(mCastingLight); } void CreateScene() { mSceneActor = Actor::New(); - mSceneActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mSceneActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); // Create and add images to the scene actor: - mImageActor1 = ImageView::New( SCENE_IMAGE_1 ); - mImageActor2 = ImageView::New( SCENE_IMAGE_2 ); - mImageActor3 = ImageView::New( SCENE_IMAGE_3 ); + mImageActor1 = ImageView::New(SCENE_IMAGE_1); + mImageActor2 = ImageView::New(SCENE_IMAGE_2); + mImageActor3 = ImageView::New(SCENE_IMAGE_3); - mImageActor1.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mImageActor2.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mImageActor3.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mImageActor1.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mImageActor2.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mImageActor3.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); - mImageActor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mImageActor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - mImageActor1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER_LEFT); - mImageActor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_RIGHT); + mImageActor1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT); + mImageActor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_RIGHT); - mImageActor3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER_RIGHT); - mImageActor3.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER_LEFT); + mImageActor3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT); + mImageActor3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); mSceneActor.Add(mImageActor2); mImageActor2.Add(mImageActor1); mImageActor2.Add(mImageActor3); - Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value( Dali::ANGLE_30 ) ); - Source angleSrc( mImageActor2, angleIndex ); + Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value(Dali::ANGLE_30)); + Source angleSrc(mImageActor2, angleIndex); - Constraint constraint = Constraint::New( mImageActor1, Actor::Property::ORIENTATION, RotationConstraint(-1.0f) ); - constraint.AddSource( angleSrc ); + Constraint constraint = Constraint::New(mImageActor1, Actor::Property::ORIENTATION, RotationConstraint(-1.0f)); + constraint.AddSource(angleSrc); constraint.Apply(); - constraint = Constraint::New( mImageActor3, Actor::Property::ORIENTATION, RotationConstraint(+1.0f) ); - constraint.AddSource( angleSrc ); + constraint = Constraint::New(mImageActor3, Actor::Property::ORIENTATION, RotationConstraint(+1.0f)); + constraint.AddSource(angleSrc); constraint.Apply(); mSceneAnimation = Animation::New(2.5f); // Want to animate angle from 30 => -30 and back again smoothly. - mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-Dali::ANGLE_30), AlphaFunction::SIN ); + mSceneAnimation.AnimateTo(Property(mImageActor2, angleIndex), Property::Value(-Dali::ANGLE_30), AlphaFunction::SIN); mSceneAnimation.SetLooping(true); mSceneAnimation.Play(); - mSceneActor.SetProperty( Actor::Property::SIZE, Vector2( 250.0f, 250.0f ) ); - mSceneActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 130.0f ) ); + mSceneActor.SetProperty(Actor::Property::SIZE, Vector2(250.0f, 250.0f)); + mSceneActor.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, 130.0f)); mShadowView.Add(mSceneActor); } - - Quaternion CalculateWorldRotation( Radian XRotation, Radian YRotation ) + Quaternion CalculateWorldRotation(Radian XRotation, Radian YRotation) { - Quaternion p( XRotation, Vector3::XAXIS ); - Quaternion q( YRotation, Vector3::YAXIS ); - return p*q; + Quaternion p(XRotation, Vector3::XAXIS); + Quaternion q(YRotation, Vector3::YAXIS); + return p * q; } void OnTap(Dali::Actor actor, const TapGesture& gesture) { - if( mSceneAnimation ) + if(mSceneAnimation) { - if( ! mPaused ) + if(!mPaused) { mSceneAnimation.Pause(); mPaused = true; @@ -335,7 +330,7 @@ public: void OnPan(Actor actor, const PanGesture& gesture) { - switch (gesture.GetState()) + switch(gesture.GetState()) { case GestureState::CONTINUING: { @@ -345,27 +340,27 @@ public: case PAN_LIGHT: { mLightXRotation = mLightXRotation - displacement.y * LIGHT_PAN_X_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis - mLightXRotation = Clamp(mLightXRotation, -Dali::ANGLE_45, Dali::ANGLE_45 ); + mLightXRotation = Clamp(mLightXRotation, -Dali::ANGLE_45, Dali::ANGLE_45); mLightYRotation = mLightYRotation + displacement.x * LIGHT_PAN_Y_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis - mLightYRotation = Clamp(mLightYRotation, -Dali::ANGLE_45, Dali::ANGLE_45 ); - mLightAnchor.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mLightXRotation, mLightYRotation ) ); + mLightYRotation = Clamp(mLightYRotation, -Dali::ANGLE_45, Dali::ANGLE_45); + mLightAnchor.SetProperty(Actor::Property::ORIENTATION, CalculateWorldRotation(mLightXRotation, mLightYRotation)); break; } case PAN_SCENE: { mTranslation += Vector3(displacement.x, displacement.y, 0.f); - mContents.SetProperty( Actor::Property::POSITION, mTranslation ); + mContents.SetProperty(Actor::Property::POSITION, mTranslation); break; } case ROTATE_SCENE: { mSceneXRotation = mSceneXRotation - displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis - mSceneXRotation = Clamp( mSceneXRotation, -Dali::ANGLE_90, Dali::ANGLE_90 ); + mSceneXRotation = Clamp(mSceneXRotation, -Dali::ANGLE_90, Dali::ANGLE_90); mSceneYRotation = mSceneYRotation + displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis - mSceneYRotation = Clamp( mSceneYRotation, -Dali::ANGLE_90, Dali::ANGLE_90 ); - mContents.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); + mSceneYRotation = Clamp(mSceneYRotation, -Dali::ANGLE_90, Dali::ANGLE_90); + mContents.SetProperty(Actor::Property::ORIENTATION, CalculateWorldRotation(mSceneXRotation, mSceneYRotation)); break; } @@ -373,7 +368,7 @@ public: { mObjectXRotation = mObjectXRotation - displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis mObjectYRotation = mObjectYRotation + displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis - mSceneActor.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mObjectXRotation, mObjectYRotation ) ); + mSceneActor.SetProperty(Actor::Property::ORIENTATION, CalculateWorldRotation(mObjectXRotation, mObjectYRotation)); break; } } @@ -391,22 +386,22 @@ public: void OnPinch(Actor actor, const PinchGesture& gesture) { - if (gesture.GetState() == GestureState::STARTED) + if(gesture.GetState() == GestureState::STARTED) { - mScaleAtPinchStart = mContents.GetCurrentProperty< Vector3 >( Actor::Property::SCALE ).x; + mScaleAtPinchStart = mContents.GetCurrentProperty(Actor::Property::SCALE).x; } mPinchScale = Clamp(mScaleAtPinchStart * gesture.GetScale(), MIN_PINCH_SCALE, MAX_PINCH_SCALE); - mContents.SetProperty( Actor::Property::SCALE, Vector3( mPinchScale, mPinchScale, mPinchScale ) ); + mContents.SetProperty(Actor::Property::SCALE, Vector3(mPinchScale, mPinchScale, mPinchScale)); } void Terminate(Application& app) { - if( mSceneActor ) + if(mSceneActor) { mApp.GetWindow().Remove(mSceneActor); } - if( mView ) + if(mView) { mApp.GetWindow().Remove(mView); } @@ -416,32 +411,32 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApp.Quit(); } } } - bool OnEffectButtonClicked( Toolkit::Button button ) + bool OnEffectButtonClicked(Toolkit::Button button) { switch(mPanState) { case PAN_LIGHT: mPanState = ROTATE_OBJECT; - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_ROTATE_OBJECT) ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_ROTATE_OBJECT)); break; case ROTATE_OBJECT: mPanState = ROTATE_SCENE; - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_ROTATE_SCENE) ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_ROTATE_SCENE)); break; case ROTATE_SCENE: mPanState = PAN_SCENE; - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_SCENE) ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_SCENE)); break; case PAN_SCENE: mPanState = PAN_LIGHT; - mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_LIGHT) ); + mTitleActor.SetProperty(TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_LIGHT)); break; default: break; @@ -450,53 +445,53 @@ public: return true; } - bool OnResetPressed( Toolkit::Button button ) + bool OnResetPressed(Toolkit::Button button) { // Reset translation mTranslation = Vector3::ZERO; - mContents.SetProperty( Actor::Property::POSITION, mTranslation ); + mContents.SetProperty(Actor::Property::POSITION, mTranslation); // Align scene so that light anchor orientation is Z Axis mSceneXRotation = -mLightXRotation; mSceneYRotation = -mLightYRotation; - mContents.SetProperty( Actor::Property::ORIENTATION, CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) ); + mContents.SetProperty(Actor::Property::ORIENTATION, CalculateWorldRotation(mSceneXRotation, mSceneYRotation)); return true; } private: - Application& mApp; - Toolkit::Control mView; - Layer mContents; - Actor mSceneActor; - Animation mAnimation; - Animation mSceneAnimation; - bool mPaused; - Toolkit::ShadowView mShadowView; - ImageView mShadowPlaneBg; - ImageView mShadowPlane; - Actor mCastingLight; - Actor mLightAnchor; - ImageView mImageActor1; - ImageView mImageActor2; - ImageView mImageActor3; - PanGestureDetector mPanGestureDetector; - PinchGestureDetector mPinchGestureDetector; - TapGestureDetector mTapGestureDetector; - Vector3 mTranslation; - Radian mSceneXRotation; - Radian mSceneYRotation; - Radian mLightXRotation; - Radian mLightYRotation; - Radian mObjectXRotation; - Radian mObjectYRotation; - float mPinchScale; - float mScaleAtPinchStart; - - Property::Index mAngle1Index; - Property::Index mAngle3Index; - - Toolkit::TextLabel mTitleActor; + Application& mApp; + Toolkit::Control mView; + Layer mContents; + Actor mSceneActor; + Animation mAnimation; + Animation mSceneAnimation; + bool mPaused; + Toolkit::ShadowView mShadowView; + ImageView mShadowPlaneBg; + ImageView mShadowPlane; + Actor mCastingLight; + Actor mLightAnchor; + ImageView mImageActor1; + ImageView mImageActor2; + ImageView mImageActor3; + PanGestureDetector mPanGestureDetector; + PinchGestureDetector mPinchGestureDetector; + TapGestureDetector mTapGestureDetector; + Vector3 mTranslation; + Radian mSceneXRotation; + Radian mSceneYRotation; + Radian mLightXRotation; + Radian mLightYRotation; + Radian mObjectXRotation; + Radian mObjectYRotation; + float mPinchScale; + float mScaleAtPinchStart; + + Property::Index mAngle1Index; + Property::Index mAngle3Index; + + Toolkit::TextLabel mTitleActor; enum PanState { @@ -506,15 +501,15 @@ private: ROTATE_OBJECT }; - PanState mPanState; + PanState mPanState; }; /*****************************************************************************/ -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); - TestApp theApp(app); + TestApp theApp(app); app.MainLoop(); return 0; } diff --git a/examples/simple-bitmap-font-text-label/simple-text-label-example.cpp b/examples/simple-bitmap-font-text-label/simple-text-label-example.cpp index a7f6ff0..1e7cdf3 100644 --- a/examples/simple-bitmap-font-text-label/simple-text-label-example.cpp +++ b/examples/simple-bitmap-font-text-label/simple-text-label-example.cpp @@ -23,9 +23,9 @@ // EXTERNAL INCLUDES #include -#include -#include #include +#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -36,12 +36,11 @@ using namespace Dali::Toolkit; class SimpleTextLabelExample : public ConnectionTracker { public: - - SimpleTextLabelExample( Application& application ) - : mApplication( application ) + SimpleTextLabelExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &SimpleTextLabelExample::Create ); + mApplication.InitSignal().Connect(this, &SimpleTextLabelExample::Create); } ~SimpleTextLabelExample() @@ -52,7 +51,7 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); @@ -61,111 +60,109 @@ public: TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); DevelText::BitmapFontDescription fontDescription; - fontDescription.name = "Digits"; - fontDescription.underlinePosition = 0.f; + fontDescription.name = "Digits"; + fontDescription.underlinePosition = 0.f; fontDescription.underlineThickness = 0.f; - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0030.png", "0", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0031.png", "1", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0032.png", "2", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0033.png", "3", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0034.png", "4", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0035.png", "5", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0036.png", "6", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0037.png", "7", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0038.png", "8", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0039.png", "9", 34.f, 0.f } ); - fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u003a.png", ":", 34.f, 0.f } ); - + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0030.png", "0", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0031.png", "1", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0032.png", "2", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0033.png", "3", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0034.png", "4", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0035.png", "5", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0036.png", "6", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0037.png", "7", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0038.png", "8", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0039.png", "9", 34.f, 0.f}); + fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u003a.png", ":", 34.f, 0.f}); DevelText::BitmapFontDescription colorFontDescription; - colorFontDescription.name = "DigitsColor"; - colorFontDescription.underlinePosition = 0.f; + colorFontDescription.name = "DigitsColor"; + colorFontDescription.underlinePosition = 0.f; colorFontDescription.underlineThickness = 0.f; - colorFontDescription.isColorFont = true; - - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0030_color.png", "0", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0031_color.png", "1", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0032_color.png", "2", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0033_color.png", "3", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0034_color.png", "4", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0035_color.png", "5", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0036_color.png", "6", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0037_color.png", "7", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0038_color.png", "8", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0039_color.png", "9", 34.f, 0.f } ); - colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u003a_color.png", ":", 34.f, 0.f } ); + colorFontDescription.isColorFont = true; + + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0030_color.png", "0", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0031_color.png", "1", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0032_color.png", "2", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0033_color.png", "3", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0034_color.png", "4", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0035_color.png", "5", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0036_color.png", "6", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0037_color.png", "7", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0038_color.png", "8", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0039_color.png", "9", 34.f, 0.f}); + colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u003a_color.png", ":", 34.f, 0.f}); TextAbstraction::BitmapFont bitmapFont; TextAbstraction::BitmapFont bitmapColorFont; - DevelText::CreateBitmapFont( fontDescription, bitmapFont ); - DevelText::CreateBitmapFont( colorFontDescription, bitmapColorFont ); + DevelText::CreateBitmapFont(fontDescription, bitmapFont); + DevelText::CreateBitmapFont(colorFontDescription, bitmapColorFont); - fontClient.GetFontId( bitmapFont ); - fontClient.GetFontId( bitmapColorFont ); + fontClient.GetFontId(bitmapFont); + fontClient.GetFontId(bitmapColorFont); TextLabel label01 = TextLabel::New(); - label01.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - label01.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - label01.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 50.f ) ); - label01.SetProperty( Actor::Property::POSITION, Vector2( 0.f, -100.f )); - label01.SetProperty( TextLabel::Property::MULTI_LINE, true ); - - label01.SetProperty( TextLabel::Property::ENABLE_MARKUP, true ); - label01.SetProperty( TextLabel::Property::TEXT, "0123456789:" ); - label01.SetProperty( TextLabel::Property::TEXT_COLOR, Color::RED ); - label01.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" ); + label01.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + label01.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + label01.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f)); + label01.SetProperty(Actor::Property::POSITION, Vector2(0.f, -100.f)); + label01.SetProperty(TextLabel::Property::MULTI_LINE, true); - label01.SetBackgroundColor( Color::BLACK ); + label01.SetProperty(TextLabel::Property::ENABLE_MARKUP, true); + label01.SetProperty(TextLabel::Property::TEXT, "0123456789:"); + label01.SetProperty(TextLabel::Property::TEXT_COLOR, Color::RED); + label01.SetProperty(TextLabel::Property::FONT_FAMILY, "Digits"); - window.Add( label01 ); + label01.SetBackgroundColor(Color::BLACK); + window.Add(label01); - TextLabel label02 = TextLabel::New(); - label02.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - label02.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - label02.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 50.f ) ); - label02.SetProperty( Actor::Property::POSITION, Vector2( 0.f, -50.f )); - label02.SetProperty( TextLabel::Property::MULTI_LINE, true ); + TextLabel label02 = TextLabel::New(); + label02.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + label02.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + label02.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f)); + label02.SetProperty(Actor::Property::POSITION, Vector2(0.f, -50.f)); + label02.SetProperty(TextLabel::Property::MULTI_LINE, true); - label02.SetProperty( TextLabel::Property::TEXT, "0123456789:" ); - label02.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - label02.SetProperty( TextLabel::Property::FONT_FAMILY, "DigitsColor" ); + label02.SetProperty(TextLabel::Property::TEXT, "0123456789:"); + label02.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + label02.SetProperty(TextLabel::Property::FONT_FAMILY, "DigitsColor"); - label02.SetBackgroundColor( Color::BLACK ); + label02.SetBackgroundColor(Color::BLACK); - window.Add( label02 ); + window.Add(label02); - TextLabel label03 = TextLabel::New(); - label03.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - label03.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - label03.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 50.f ) ); - label03.SetProperty( Actor::Property::POSITION, Vector2( 0.f, 0.f )); - label03.SetProperty( TextLabel::Property::MULTI_LINE, true ); + TextLabel label03 = TextLabel::New(); + label03.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + label03.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + label03.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f)); + label03.SetProperty(Actor::Property::POSITION, Vector2(0.f, 0.f)); + label03.SetProperty(TextLabel::Property::MULTI_LINE, true); - label03.SetProperty( TextLabel::Property::TEXT, "0123456789:" ); - label03.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" ); + label03.SetProperty(TextLabel::Property::TEXT, "0123456789:"); + label03.SetProperty(TextLabel::Property::FONT_FAMILY, "Digits"); - label03.SetBackgroundColor( Color::WHITE ); + label03.SetBackgroundColor(Color::WHITE); - window.Add( label03 ); + window.Add(label03); - TextLabel label04 = TextLabel::New(); - label04.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - label04.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - label04.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 50.f ) ); - label04.SetProperty( Actor::Property::POSITION, Vector2( 0.f, 50.f )); - label04.SetProperty( TextLabel::Property::MULTI_LINE, true ); + TextLabel label04 = TextLabel::New(); + label04.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + label04.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + label04.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f)); + label04.SetProperty(Actor::Property::POSITION, Vector2(0.f, 50.f)); + label04.SetProperty(TextLabel::Property::MULTI_LINE, true); - label04.SetProperty( TextLabel::Property::TEXT, "0123456789:" ); - label04.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" ); - label04.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); + label04.SetProperty(TextLabel::Property::TEXT, "0123456789:"); + label04.SetProperty(TextLabel::Property::FONT_FAMILY, "Digits"); + label04.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); - label04.SetBackgroundColor( Color::BLACK ); + label04.SetBackgroundColor(Color::BLACK); - window.Add( label04 ); - } + window.Add(label04); + } /** * Main key event handler @@ -174,7 +171,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -182,23 +179,22 @@ public: } private: - Application& mApplication; }; -void RunTest( Application& application ) +void RunTest(Application& application) { - SimpleTextLabelExample test( application ); + SimpleTextLabelExample test(application); application.MainLoop(); } /** Entry point for Linux & Tizen applications */ -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - RunTest( application ); + RunTest(application); return 0; } diff --git a/examples/simple-scroll-view/simple-scroll-view-example.cpp b/examples/simple-scroll-view/simple-scroll-view-example.cpp index b69bd98..1a01c44 100644 --- a/examples/simple-scroll-view/simple-scroll-view-example.cpp +++ b/examples/simple-scroll-view/simple-scroll-view-example.cpp @@ -16,8 +16,8 @@ */ // EXTERNAL INCLUDES -#include #include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -37,13 +37,12 @@ const float DISTANCE_BETWEEN_IMAGES = 6.0f; ///< The distance between the images class ExampleController : public ConnectionTracker { public: - /** * Constructor * @param application class, stored as reference */ - ExampleController( Application& application ) - : mApplication( application ) + ExampleController(Application& application) + : mApplication(application) { // Connect to the Application's Init and orientation changed signal mApplication.InitSignal().Connect(this, &ExampleController::OnInit); @@ -52,15 +51,14 @@ public: ~ExampleController() = default; private: - /** * This method gets called once the main loop of application is up and running */ void OnInit(Application& app) { - Window window = app.GetWindow(); + Window window = app.GetWindow(); Vector2 windowSize = window.GetSize(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); window.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); // Make the scroll view's size a certain percentage of the window @@ -68,76 +66,76 @@ private: // Create a scroll view and set our desired properties ScrollView scrollView = ScrollView::New(); - scrollView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - scrollView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - scrollView.SetProperty( Actor::Property::SIZE, pageSize ); - scrollView.SetAxisAutoLock( true ); - window.Add( scrollView ); + scrollView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + scrollView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + scrollView.SetProperty(Actor::Property::SIZE, pageSize); + scrollView.SetAxisAutoLock(true); + window.Add(scrollView); // We want to the scroll-view so only one page is shown - scrollView.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + scrollView.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX); // Create rulers for the X and Y domains, we want to disable vertical scrolling but enable horizontal scrolling - RulerPtr rulerX = new FixedRuler( pageSize.width ); // Snaps to a multiple of this when flicking + RulerPtr rulerX = new FixedRuler(pageSize.width); // Snaps to a multiple of this when flicking RulerPtr rulerY = new DefaultRuler; - rulerX->SetDomain( RulerDomain( 0.0f, pageSize.width * NUMBER_OF_PAGES, true ) ); // Set the domain to equal the number of pages used + rulerX->SetDomain(RulerDomain(0.0f, pageSize.width * NUMBER_OF_PAGES, true)); // Set the domain to equal the number of pages used rulerY->Disable(); - scrollView.SetRulerX( rulerX ); - scrollView.SetRulerY( rulerY ); + scrollView.SetRulerX(rulerX); + scrollView.SetRulerY(rulerY); // Populate the Pages - for( int column = 0, textNumber = 0; column < NUMBER_OF_PAGES; column++ ) + for(int column = 0, textNumber = 0; column < NUMBER_OF_PAGES; column++) { - Actor page = CreatePage( pageSize, textNumber ); - page.SetProperty( Actor::Property::POSITION, Vector2( column * pageSize.x, 0.0f )); - scrollView.Add( page ); + Actor page = CreatePage(pageSize, textNumber); + page.SetProperty(Actor::Property::POSITION, Vector2(column * pageSize.x, 0.0f)); + scrollView.Add(page); } // Do a little animation from the last page to the first page on load - scrollView.ScrollTo( NUMBER_OF_PAGES - 1, 0.0f ); - scrollView.ScrollTo( 0 ); + scrollView.ScrollTo(NUMBER_OF_PAGES - 1, 0.0f); + scrollView.ScrollTo(0); } /** * Creates a page using a source of images. */ - Actor CreatePage( const Vector2& pageSize, int& textNumber ) + Actor CreatePage(const Vector2& pageSize, int& textNumber) { Actor page = Actor::New(); - page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - page.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - page.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + page.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + page.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + page.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); Window window = mApplication.GetWindow(); // Calculate the number of images going across (columns) within a page, the image size and the size of the text - const int imageColumns = round( ROWS_PER_PAGE * ( pageSize.width ) / ( pageSize.height ) ); - const Vector3 imageSize( ( pageSize.width / imageColumns ) - DISTANCE_BETWEEN_IMAGES, - ( pageSize.height / ROWS_PER_PAGE) - DISTANCE_BETWEEN_IMAGES, - 0.0f); - const float textPixelSize = imageSize.width / 3.0f; + const int imageColumns = round(ROWS_PER_PAGE * (pageSize.width) / (pageSize.height)); + const Vector3 imageSize((pageSize.width / imageColumns) - DISTANCE_BETWEEN_IMAGES, + (pageSize.height / ROWS_PER_PAGE) - DISTANCE_BETWEEN_IMAGES, + 0.0f); + const float textPixelSize = imageSize.width / 3.0f; // Populate the page - for( int row = 0; row < ROWS_PER_PAGE; row++ ) + for(int row = 0; row < ROWS_PER_PAGE; row++) { - for( int column = 0; column < imageColumns; column++ ) + for(int column = 0; column < imageColumns; column++) { - const Vector3 position( DISTANCE_BETWEEN_IMAGES * 0.5f + ( imageSize.x + DISTANCE_BETWEEN_IMAGES ) * column - pageSize.width * 0.5f, - DISTANCE_BETWEEN_IMAGES * 0.5f + ( imageSize.y + DISTANCE_BETWEEN_IMAGES ) * row - pageSize.height * 0.5f, - 0.0f); - - Control item = TextLabel::New( std::to_string( textNumber++ ) ); - item.SetProperty( Actor::Property::POSITION, position + imageSize * 0.5f ); - item.SetProperty( Actor::Property::SIZE, imageSize ); - item.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - item.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - item.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); - item.SetProperty( TextLabel::Property::PIXEL_SIZE, textPixelSize ); - item.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER ); - item.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER ); - item.SetProperty( TextLabel::Property::OUTLINE, Property::Map{ { "width", 2 }, { "color", Color::WHITE } } ); - item.SetProperty( Control::Property::BACKGROUND, Vector4( Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), Random::Range( 0.0f, 1.0f ), 0.7f ) ); + const Vector3 position(DISTANCE_BETWEEN_IMAGES * 0.5f + (imageSize.x + DISTANCE_BETWEEN_IMAGES) * column - pageSize.width * 0.5f, + DISTANCE_BETWEEN_IMAGES * 0.5f + (imageSize.y + DISTANCE_BETWEEN_IMAGES) * row - pageSize.height * 0.5f, + 0.0f); + + Control item = TextLabel::New(std::to_string(textNumber++)); + item.SetProperty(Actor::Property::POSITION, position + imageSize * 0.5f); + item.SetProperty(Actor::Property::SIZE, imageSize); + item.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + item.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + item.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLACK); + item.SetProperty(TextLabel::Property::PIXEL_SIZE, textPixelSize); + item.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER); + item.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER); + item.SetProperty(TextLabel::Property::OUTLINE, Property::Map{{"width", 2}, {"color", Color::WHITE}}); + item.SetProperty(Control::Property::BACKGROUND, Vector4(Random::Range(0.0f, 1.0f), Random::Range(0.0f, 1.0f), Random::Range(0.0f, 1.0f), 0.7f)); page.Add(item); } } @@ -152,7 +150,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -163,9 +161,9 @@ private: Application& mApplication; ///< Application instance }; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { - Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); ExampleController test(app); app.MainLoop(); return 0; diff --git a/examples/simple-text-field/simple-text-field.cpp b/examples/simple-text-field/simple-text-field.cpp index dd730e5..948279a 100644 --- a/examples/simple-text-field/simple-text-field.cpp +++ b/examples/simple-text-field/simple-text-field.cpp @@ -27,19 +27,17 @@ using namespace Dali; using namespace Dali::Toolkit; - /** * @brief The main class of the demo. */ class SimpleTextFieldExample : public ConnectionTracker { public: - - SimpleTextFieldExample( Application& application ) - : mApplication( application ) + SimpleTextFieldExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &SimpleTextFieldExample::Create ); + mApplication.InitSignal().Connect(this, &SimpleTextFieldExample::Create); } ~SimpleTextFieldExample() @@ -50,23 +48,23 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &SimpleTextFieldExample::OnKeyEvent); - window.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) ); + window.SetBackgroundColor(Vector4(0.04f, 0.345f, 0.392f, 1.0f)); TextField field = TextField::New(); - field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 60.f ) ); - field.SetBackgroundColor( Color::WHITE ); - field.SetBackgroundColor( Vector4( 1.f, 1.f, 1.f, 0.15f ) ); + field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + field.SetProperty(Actor::Property::SIZE, Vector2(300.f, 60.f)); + field.SetBackgroundColor(Color::WHITE); + field.SetBackgroundColor(Vector4(1.f, 1.f, 1.f, 0.15f)); - field.SetProperty( TextField::Property::TEXT_COLOR, Color::BLACK ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder" ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name." ); + field.SetProperty(TextField::Property::TEXT_COLOR, Color::BLACK); + field.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder"); + field.SetProperty(TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name."); - window.Add( field ); + window.Add(field); } /** @@ -76,7 +74,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -84,24 +82,23 @@ public: } private: - Application& mApplication; }; -void RunTest( Application& application ) +void RunTest(Application& application) { - SimpleTextFieldExample test( application ); + SimpleTextFieldExample test(application); application.MainLoop(); } /** Entry point for Linux & Tizen applications */ -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { // DALI_DEMO_THEME_PATH not passed to Application so TextField example uses default Toolkit style sheet. - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - RunTest( application ); + RunTest(application); return 0; } diff --git a/examples/simple-text-label/simple-text-label-example.cpp b/examples/simple-text-label/simple-text-label-example.cpp index 433edb2..c4c8c51 100644 --- a/examples/simple-text-label/simple-text-label-example.cpp +++ b/examples/simple-text-label/simple-text-label-example.cpp @@ -32,12 +32,11 @@ using namespace Dali::Toolkit; class SimpleTextLabelExample : public ConnectionTracker { public: - - SimpleTextLabelExample( Application& application ) - : mApplication( application ) + SimpleTextLabelExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &SimpleTextLabelExample::Create ); + mApplication.InitSignal().Connect(this, &SimpleTextLabelExample::Create); } ~SimpleTextLabelExample() @@ -48,22 +47,22 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &SimpleTextLabelExample::OnKeyEvent); - mLabel = TextLabel::New( "A Quick Brown Fox Jumps Over The Lazy Dog" ); - mLabel.SetProperty( Dali::Actor::Property::NAME, "SimpleTextLabel" ); - mLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLabel.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 400.f ) ); - mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true ); - mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); - mLabel.SetBackgroundColor( Color::WHITE ); + mLabel = TextLabel::New("A Quick Brown Fox Jumps Over The Lazy Dog"); + mLabel.SetProperty(Dali::Actor::Property::NAME, "SimpleTextLabel"); + mLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLabel.SetProperty(Actor::Property::SIZE, Vector2(400.f, 400.f)); + mLabel.SetProperty(TextLabel::Property::MULTI_LINE, true); + mLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLACK); + mLabel.SetBackgroundColor(Color::WHITE); - window.Add( mLabel ); + window.Add(mLabel); } /** @@ -73,7 +72,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -81,25 +80,24 @@ public: } private: - Application& mApplication; TextLabel mLabel; }; -void RunTest( Application& application ) +void RunTest(Application& application) { - SimpleTextLabelExample test( application ); + SimpleTextLabelExample test(application); application.MainLoop(); } /** Entry point for Linux & Tizen applications */ -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - RunTest( application ); + RunTest(application); return 0; } diff --git a/examples/simple-text-renderer/simple-text-renderer-example.cpp b/examples/simple-text-renderer/simple-text-renderer-example.cpp index 6f7dc21..23654a0 100644 --- a/examples/simple-text-renderer/simple-text-renderer-example.cpp +++ b/examples/simple-text-renderer/simple-text-renderer-example.cpp @@ -21,10 +21,10 @@ */ // EXTERNAL INCLUDES -#include #include #include #include +#include using namespace std; using namespace Dali; @@ -32,11 +32,10 @@ using namespace Dali::Toolkit; namespace { - const std::string IMAGE1 = DEMO_IMAGE_DIR "application-icon-1.png"; const std::string IMAGE2 = DEMO_IMAGE_DIR "application-icon-6.png"; -#define MAKE_SHADER(A)#A +#define MAKE_SHADER(A) #A const std::string VERSION_3_ES = "#version 300 es\n"; @@ -51,15 +50,13 @@ const char* VERTEX_SHADER = MAKE_SHADER( uniform vec3 uSize; uniform mat4 uMvpMatrix; - void main() - { + void main() { vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); vertexPosition.xyz *= uSize; gl_Position = uMvpMatrix * vertexPosition; vUV = aTexCoord; - } -); + }); const char* FRAGMENT_SHADER = MAKE_SHADER( precision mediump float; @@ -69,14 +66,12 @@ const char* FRAGMENT_SHADER = MAKE_SHADER( out vec4 FragColor; uniform sampler2D sAlbedo; - uniform vec4 uColor; + uniform vec4 uColor; - void main() - { - vec4 color = texture( sAlbedo, vUV ); - FragColor = vec4( color.rgb, uColor.a * color.a ); - } -); + void main() { + vec4 color = texture(sAlbedo, vUV); + FragColor = vec4(color.rgb, uColor.a * color.a); + }); Renderer CreateRenderer() { @@ -87,10 +82,10 @@ Renderer CreateRenderer() Dali::Vector2 texCoord; }; - static const Vertex vertices[] = {{ Dali::Vector2( -0.5f, -0.5f ), Dali::Vector2( 0.0f, 0.0f ) }, - { Dali::Vector2( 0.5f, -0.5f ), Dali::Vector2( 1.0f, 0.0f ) }, - { Dali::Vector2( -0.5f, 0.5f ), Dali::Vector2( 0.0f, 1.0f ) }, - { Dali::Vector2( 0.5f, 0.5f ), Dali::Vector2( 1.0f, 1.0f ) }}; + static const Vertex vertices[] = {{Dali::Vector2(-0.5f, -0.5f), Dali::Vector2(0.0f, 0.0f)}, + {Dali::Vector2(0.5f, -0.5f), Dali::Vector2(1.0f, 0.0f)}, + {Dali::Vector2(-0.5f, 0.5f), Dali::Vector2(0.0f, 1.0f)}, + {Dali::Vector2(0.5f, 0.5f), Dali::Vector2(1.0f, 1.0f)}}; Property::Map property; property.Add("aPosition", Property::VECTOR2).Add("aTexCoord", Property::VECTOR2); @@ -105,123 +100,121 @@ Renderer CreateRenderer() geometry.SetType(Geometry::TRIANGLE_STRIP); // Create the shader - Shader shader = Shader::New( VERSION_3_ES + VERTEX_SHADER, VERSION_3_ES + FRAGMENT_SHADER ); + Shader shader = Shader::New(VERSION_3_ES + VERTEX_SHADER, VERSION_3_ES + FRAGMENT_SHADER); // Create the renderer - Renderer renderer = Renderer::New( geometry, shader ); + Renderer renderer = Renderer::New(geometry, shader); return renderer; } -TextureSet CreateTextureSet( const Dali::Toolkit::DevelText::RendererParameters& textParameters, const std::vector& embeddedItems ) +TextureSet CreateTextureSet(const Dali::Toolkit::DevelText::RendererParameters& textParameters, const std::vector& embeddedItems) { - Dali::Vector embeddedItemLayout; - Devel::PixelBuffer pixelBuffer = Toolkit::DevelText::Render( textParameters, embeddedItemLayout ); - + Devel::PixelBuffer pixelBuffer = Toolkit::DevelText::Render(textParameters, embeddedItemLayout); - const int dstWidth = static_cast( pixelBuffer.GetWidth() ); - const int dstHeight = static_cast( pixelBuffer.GetHeight() ); + const int dstWidth = static_cast(pixelBuffer.GetWidth()); + const int dstHeight = static_cast(pixelBuffer.GetHeight()); unsigned int index = 0u; - for( const auto& itemLayout : embeddedItemLayout ) + for(const auto& itemLayout : embeddedItemLayout) { - int width = static_cast( itemLayout.size.width ); - int height = static_cast( itemLayout.size.height ); - int x = static_cast( itemLayout.position.x ); - int y = static_cast( itemLayout.position.y ); + int width = static_cast(itemLayout.size.width); + int height = static_cast(itemLayout.size.height); + int x = static_cast(itemLayout.position.x); + int y = static_cast(itemLayout.position.y); - Dali::Devel::PixelBuffer itemPixelBuffer = Dali::LoadImageFromFile( embeddedItems[index++] ); - itemPixelBuffer.Resize( width, height ); - itemPixelBuffer.Rotate( itemLayout.angle ); + Dali::Devel::PixelBuffer itemPixelBuffer = Dali::LoadImageFromFile(embeddedItems[index++]); + itemPixelBuffer.Resize(width, height); + itemPixelBuffer.Rotate(itemLayout.angle); - width = static_cast( itemPixelBuffer.GetWidth() ); - height = static_cast( itemPixelBuffer.GetHeight() ); + width = static_cast(itemPixelBuffer.GetWidth()); + height = static_cast(itemPixelBuffer.GetHeight()); Dali::Pixel::Format itemPixelFormat = itemPixelBuffer.GetPixelFormat(); // Check if the item is out of the buffer. - if( ( x + width < 0 ) || - ( x > dstWidth ) || - ( y < 0 ) || - ( y - height > dstHeight ) ) + if((x + width < 0) || + (x > dstWidth) || + (y < 0) || + (y - height > dstHeight)) { // The embedded item is completely out of the buffer. continue; } // Crop if it exceeds the boundaries of the destination buffer. - int layoutX = 0; - int layoutY = 0; - int cropX = 0; - int cropY = 0; - int newWidth = width; + int layoutX = 0; + int layoutY = 0; + int cropX = 0; + int cropY = 0; + int newWidth = width; int newHeight = height; bool crop = false; - if( 0 > x ) + if(0 > x) { newWidth += x; - cropX = std::abs( x ); - crop = true; + cropX = std::abs(x); + crop = true; } else { layoutX = x; } - if( cropX + newWidth > dstWidth ) + if(cropX + newWidth > dstWidth) { crop = true; - newWidth -= ( ( cropX + newWidth ) - dstWidth ); + newWidth -= ((cropX + newWidth) - dstWidth); } layoutY = y; - if( 0.f > layoutY ) + if(0.f > layoutY) { newHeight += layoutY; cropY = std::abs(layoutY); - crop = true; + crop = true; } - if( cropY + newHeight > dstHeight ) + if(cropY + newHeight > dstHeight) { crop = true; - newHeight -= ( ( cropY + newHeight ) - dstHeight ); + newHeight -= ((cropY + newHeight) - dstHeight); } - uint16_t uiCropX = static_cast(cropX); - uint16_t uiCropY = static_cast(cropY); - uint16_t uiNewWidth = static_cast(newWidth); + uint16_t uiCropX = static_cast(cropX); + uint16_t uiCropY = static_cast(cropY); + uint16_t uiNewWidth = static_cast(newWidth); uint16_t uiNewHeight = static_cast(newHeight); - if( crop ) + if(crop) { - itemPixelBuffer.Crop( uiCropX, uiCropY, uiNewWidth, uiNewHeight ); + itemPixelBuffer.Crop(uiCropX, uiCropY, uiNewWidth, uiNewHeight); } // Blend the item pixel buffer with the text's color according its blending mode. - if( Dali::TextAbstraction::ColorBlendingMode::MULTIPLY == itemLayout.colorBlendingMode ) + if(Dali::TextAbstraction::ColorBlendingMode::MULTIPLY == itemLayout.colorBlendingMode) { - Dali::Devel::PixelBuffer buffer = Dali::Devel::PixelBuffer::New( uiNewWidth, - uiNewHeight, - itemPixelFormat ); + Dali::Devel::PixelBuffer buffer = Dali::Devel::PixelBuffer::New(uiNewWidth, + uiNewHeight, + itemPixelFormat); - unsigned char* bufferPtr = buffer.GetBuffer(); + unsigned char* bufferPtr = buffer.GetBuffer(); const unsigned char* itemBufferPtr = itemPixelBuffer.GetBuffer(); - const unsigned int bytesPerPixel = Dali::Pixel::GetBytesPerPixel(itemPixelFormat); - const unsigned int size = uiNewWidth * uiNewHeight * bytesPerPixel; + const unsigned int bytesPerPixel = Dali::Pixel::GetBytesPerPixel(itemPixelFormat); + const unsigned int size = uiNewWidth * uiNewHeight * bytesPerPixel; - for (unsigned int i = 0u; i < size; i += bytesPerPixel) + for(unsigned int i = 0u; i < size; i += bytesPerPixel) { - *(bufferPtr + 0u) = static_cast( static_cast( *(itemBufferPtr + 0u) ) * textParameters.textColor.r ); - *(bufferPtr + 1u) = static_cast( static_cast( *(itemBufferPtr + 1u) ) * textParameters.textColor.g ); - *(bufferPtr + 2u) = static_cast( static_cast( *(itemBufferPtr + 2u) ) * textParameters.textColor.b ); - *(bufferPtr + 3u) = static_cast( static_cast( *(itemBufferPtr + 3u) ) * textParameters.textColor.a ); + *(bufferPtr + 0u) = static_cast(static_cast(*(itemBufferPtr + 0u)) * textParameters.textColor.r); + *(bufferPtr + 1u) = static_cast(static_cast(*(itemBufferPtr + 1u)) * textParameters.textColor.g); + *(bufferPtr + 2u) = static_cast(static_cast(*(itemBufferPtr + 2u)) * textParameters.textColor.b); + *(bufferPtr + 3u) = static_cast(static_cast(*(itemBufferPtr + 3u)) * textParameters.textColor.a); itemBufferPtr += bytesPerPixel; bufferPtr += bytesPerPixel; @@ -233,35 +226,33 @@ TextureSet CreateTextureSet( const Dali::Toolkit::DevelText::RendererParameters& Dali::Toolkit::DevelText::UpdateBuffer(itemPixelBuffer, pixelBuffer, layoutX, layoutY, true); } - PixelData pixelData = Devel::PixelBuffer::Convert( pixelBuffer ); + PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer); - Texture texture = Texture::New( TextureType::TEXTURE_2D, - pixelData.GetPixelFormat(), - pixelData.GetWidth(), - pixelData.GetHeight() ); + Texture texture = Texture::New(TextureType::TEXTURE_2D, + pixelData.GetPixelFormat(), + pixelData.GetWidth(), + pixelData.GetHeight()); texture.Upload(pixelData); TextureSet textureSet = TextureSet::New(); - textureSet.SetTexture( 0u, texture ); + textureSet.SetTexture(0u, texture); return textureSet; } } // namespace - /** * @brief The main class of the demo. */ class SimpleTextRendererExample : public ConnectionTracker { public: - - SimpleTextRendererExample( Application& application ) - : mApplication( application ) + SimpleTextRendererExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &SimpleTextRendererExample::Create ); + mApplication.InitSignal().Connect(this, &SimpleTextRendererExample::Create); } ~SimpleTextRendererExample() @@ -272,11 +263,11 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); - window.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) ); + window.SetBackgroundColor(Color::WHITE); + window.SetBackgroundColor(Vector4(0.04f, 0.345f, 0.392f, 1.0f)); window.KeyEventSignal().Connect(this, &SimpleTextRendererExample::OnKeyEvent); @@ -284,42 +275,42 @@ public: const std::string image2 = ""; Dali::Toolkit::DevelText::RendererParameters textParameters; - textParameters.text = "Hello " + image1 + " world " + image2 + " this " + image1 + " is " + image2 + " a " + image1 + " demo " + image2 + " of " + image1 + " circular " + image2 + " text " + image1 + " width " + image2 + " icons."; + textParameters.text = "Hello " + image1 + " world " + image2 + " this " + image1 + " is " + image2 + " a " + image1 + " demo " + image2 + " of " + image1 + " circular " + image2 + " text " + image1 + " width " + image2 + " icons."; textParameters.horizontalAlignment = "center"; - textParameters.verticalAlignment = "center"; - textParameters.circularAlignment = "center"; - textParameters.fontFamily = "SamsungUI"; - textParameters.fontWeight = ""; - textParameters.fontWidth = ""; - textParameters.fontSlant = ""; - textParameters.layout = "circular"; - textParameters.textColor = Color::BLACK; - textParameters.fontSize = 25.f; - textParameters.textWidth = 360u; - textParameters.textHeight = 360u; - textParameters.radius = 180u; - textParameters.beginAngle = 15.f; - textParameters.incrementAngle = 360.f; - textParameters.ellipsisEnabled = true; - textParameters.markupEnabled = true; - - std::vector embeddedItems = { IMAGE2, IMAGE2, IMAGE2, IMAGE2, IMAGE2 }; - - TextureSet textureSet = CreateTextureSet( textParameters, embeddedItems ); + textParameters.verticalAlignment = "center"; + textParameters.circularAlignment = "center"; + textParameters.fontFamily = "SamsungUI"; + textParameters.fontWeight = ""; + textParameters.fontWidth = ""; + textParameters.fontSlant = ""; + textParameters.layout = "circular"; + textParameters.textColor = Color::BLACK; + textParameters.fontSize = 25.f; + textParameters.textWidth = 360u; + textParameters.textHeight = 360u; + textParameters.radius = 180u; + textParameters.beginAngle = 15.f; + textParameters.incrementAngle = 360.f; + textParameters.ellipsisEnabled = true; + textParameters.markupEnabled = true; + + std::vector embeddedItems = {IMAGE2, IMAGE2, IMAGE2, IMAGE2, IMAGE2}; + + TextureSet textureSet = CreateTextureSet(textParameters, embeddedItems); Renderer renderer = CreateRenderer(); - renderer.SetTextures( textureSet ); + renderer.SetTextures(textureSet); Actor actor = Actor::New(); - actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - actor.SetProperty( Actor::Property::POSITION, Vector2( 0.f, 0.f)); - actor.SetProperty( Actor::Property::SIZE, Vector2( 360.f, 360.f ) ); - actor.SetProperty( Actor::Property::COLOR, Color::WHITE ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + actor.SetProperty(Actor::Property::POSITION, Vector2(0.f, 0.f)); + actor.SetProperty(Actor::Property::SIZE, Vector2(360.f, 360.f)); + actor.SetProperty(Actor::Property::COLOR, Color::WHITE); - actor.AddRenderer( renderer ); + actor.AddRenderer(renderer); - window.Add( actor ); + window.Add(actor); } /** @@ -329,7 +320,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -337,16 +328,15 @@ public: } private: - Application& mApplication; }; /** Entry point for Linux & Tizen applications */ -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - SimpleTextRendererExample test( application ); + SimpleTextRendererExample test(application); application.MainLoop(); diff --git a/examples/simple-text-visual/simple-text-visual-example.cpp b/examples/simple-text-visual/simple-text-visual-example.cpp index f3dfdb0..7279bf4 100644 --- a/examples/simple-text-visual/simple-text-visual-example.cpp +++ b/examples/simple-text-visual/simple-text-visual-example.cpp @@ -32,12 +32,11 @@ using namespace Dali::Toolkit; class TextVisualExample : public ConnectionTracker { public: - - TextVisualExample( Application& application ) - : mApplication( application ) + TextVisualExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextVisualExample::Create ); + mApplication.InitSignal().Connect(this, &TextVisualExample::Create); } ~TextVisualExample() @@ -48,31 +47,24 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &TextVisualExample::OnKeyEvent); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); Dali::Toolkit::Control control = Dali::Toolkit::ImageView::New(); - control.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - const std::string markupText( "Hello world" ); + const std::string markupText("Hello world"); Dali::Property::Map map; - map.Add( Dali::Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::TEXT ). - Add( Dali::Toolkit::TextVisual::Property::ENABLE_MARKUP, true ). - Add( Dali::Toolkit::TextVisual::Property::TEXT, markupText ). - Add( Dali::Toolkit::TextVisual::Property::TEXT_COLOR, Dali::Vector4( 0.25f, 0.25f, 0.5f, 1.f ) ). - Add( Dali::Toolkit::TextVisual::Property::FONT_FAMILY, "TizenSansRegular" ). - Add( Dali::Toolkit::TextVisual::Property::POINT_SIZE, 30.f ). - Add( Dali::Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "END" ). - Add( Dali::Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "CENTER" ); - - control.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map ); - - window.Add( control ); + map.Add(Dali::Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::TEXT).Add(Dali::Toolkit::TextVisual::Property::ENABLE_MARKUP, true).Add(Dali::Toolkit::TextVisual::Property::TEXT, markupText).Add(Dali::Toolkit::TextVisual::Property::TEXT_COLOR, Dali::Vector4(0.25f, 0.25f, 0.5f, 1.f)).Add(Dali::Toolkit::TextVisual::Property::FONT_FAMILY, "TizenSansRegular").Add(Dali::Toolkit::TextVisual::Property::POINT_SIZE, 30.f).Add(Dali::Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "END").Add(Dali::Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "CENTER"); + + control.SetProperty(Dali::Toolkit::Control::Property::BACKGROUND, map); + + window.Add(control); } /** @@ -82,7 +74,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -90,25 +82,24 @@ public: } private: - Application& mApplication; TextLabel mLabel; }; -void RunTest( Application& application ) +void RunTest(Application& application) { - TextVisualExample test( application ); + TextVisualExample test(application); application.MainLoop(); } /** Entry point for Linux & Tizen applications */ -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - RunTest( application ); + RunTest(application); return 0; } diff --git a/examples/simple-visuals-control/my-control-impl.cpp b/examples/simple-visuals-control/my-control-impl.cpp index 84e0acd..6e2b6ed 100644 --- a/examples/simple-visuals-control/my-control-impl.cpp +++ b/examples/simple-visuals-control/my-control-impl.cpp @@ -20,11 +20,11 @@ // EXTERNAL INCLUDES -#include #include +#include #include #include -#include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -33,11 +33,8 @@ namespace Demo { namespace Internal { - namespace { - - Dali::BaseHandle Create() { return Demo::MyControl::New(); @@ -45,31 +42,29 @@ Dali::BaseHandle Create() // Required code for Property set up. -DALI_TYPE_REGISTRATION_BEGIN( MyControl, Dali::Toolkit::Control, Create ); +DALI_TYPE_REGISTRATION_BEGIN(MyControl, Dali::Toolkit::Control, Create); -DALI_PROPERTY_REGISTRATION( Demo, MyControl, "iconVisual", MAP, ICON_VISUAL ) +DALI_PROPERTY_REGISTRATION(Demo, MyControl, "iconVisual", MAP, ICON_VISUAL) DALI_TYPE_REGISTRATION_END(); // Add an enum to string conversion entry for the control's visuals. In this case just the icon visual. // Enables Setting of the property using enums or strings. -DALI_ENUM_TO_STRING_TABLE_BEGIN( VISUAL_PROPERTIES ) -{ "iconVisual", Demo::MyControl::Property::ICON_VISUAL }, -DALI_ENUM_TO_STRING_TABLE_END( VISUAL_PROPERTIES ) - +DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_PROPERTIES) + {"iconVisual", Demo::MyControl::Property::ICON_VISUAL}, +DALI_ENUM_TO_STRING_TABLE_END(VISUAL_PROPERTIES) } // anonymous namespace - Internal::MyControl::MyControl() -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ) +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)) { } Demo::MyControl Internal::MyControl::New() { - IntrusivePtr impl = new Internal::MyControl(); - Demo::MyControl handle = Demo::MyControl( *impl ); + IntrusivePtr impl = new Internal::MyControl(); + Demo::MyControl handle = Demo::MyControl(*impl); impl->Initialize(); return handle; } @@ -77,31 +72,31 @@ Demo::MyControl Internal::MyControl::New() void MyControl::OnInitialize() { Dali::Actor self = Self(); - self.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true ); + self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); } -void MyControl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void MyControl::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value) { - Demo::MyControl myControl = Demo::MyControl::DownCast( Dali::BaseHandle( object ) ); + Demo::MyControl myControl = Demo::MyControl::DownCast(Dali::BaseHandle(object)); - if( myControl ) + if(myControl) { - MyControl& impl = GetImpl( myControl ); - switch ( index ) + MyControl& impl = GetImpl(myControl); + switch(index) { case Demo::MyControl::Property::ICON_VISUAL: { - Toolkit::Visual::Base iconVisual; + Toolkit::Visual::Base iconVisual; Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); - Property::Map *map = value.GetMap(); - if( map && !map->Empty() ) + Property::Map* map = value.GetMap(); + if(map && !map->Empty()) { - iconVisual = visualFactory.CreateVisual( *map ); + iconVisual = visualFactory.CreateVisual(*map); } - if ( iconVisual ) + if(iconVisual) { - DevelControl::RegisterVisual( impl, index, iconVisual ); + DevelControl::RegisterVisual(impl, index, iconVisual); } break; } @@ -109,24 +104,24 @@ void MyControl::SetProperty( BaseObject* object, Property::Index index, const Pr } } -Property::Value MyControl::GetProperty( BaseObject* object, Property::Index propertyIndex ) +Property::Value MyControl::GetProperty(BaseObject* object, Property::Index propertyIndex) { Property::Value value; - Demo::MyControl myControl = Demo::MyControl::DownCast( Dali::BaseHandle( object ) ); + Demo::MyControl myControl = Demo::MyControl::DownCast(Dali::BaseHandle(object)); - if ( myControl ) + if(myControl) { - switch ( propertyIndex ) + switch(propertyIndex) { case Demo::MyControl::Property::ICON_VISUAL: { - Property::Map map; - MyControl& impl = GetImpl( myControl ); - Toolkit::Visual::Base visual = DevelControl::GetVisual( impl, propertyIndex ); - if ( visual ) + Property::Map map; + MyControl& impl = GetImpl(myControl); + Toolkit::Visual::Base visual = DevelControl::GetVisual(impl, propertyIndex); + if(visual) { - visual.CreatePropertyMap( map ); // Creates a Property map containing the Visual that ICON_VISUAL currently is. Can change if state changes. + visual.CreatePropertyMap(map); // Creates a Property map containing the Visual that ICON_VISUAL currently is. Can change if state changes. value = map; } break; @@ -139,5 +134,5 @@ Property::Value MyControl::GetProperty( BaseObject* object, Property::Index prop return value; } -} // Internal -} // Demo +} // namespace Internal +} // namespace Demo diff --git a/examples/simple-visuals-control/my-control-impl.h b/examples/simple-visuals-control/my-control-impl.h index 76d8428..6a10730 100644 --- a/examples/simple-visuals-control/my-control-impl.h +++ b/examples/simple-visuals-control/my-control-impl.h @@ -2,7 +2,7 @@ #define DALI_DEMO_INTERNAL_MY_CONTROL_IMPL_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,13 @@ #include "my-control.h" // EXTERNAL INCLUDES -#include #include +#include namespace Demo { - namespace Internal // To use TypeRegistry, handle and body classes need the same name { - /** * @brief A Simple Control to show use of visuals with a style sheet and changing visuals with a state change */ @@ -47,7 +45,7 @@ public: */ MyControl(); -public: // Properties +public: // Properties /** * @brief Called when a property of an object of this type is set. * @@ -55,7 +53,7 @@ public: // Properties * @param[in] index The property index. * @param[in] value The new property value. */ - static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); + static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value); /** * @brief Called to retrieve a property of an object of this type. @@ -64,7 +62,7 @@ public: // Properties * @param[in] index The property index. * @return The current value of the property. */ - static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex ); + static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex); private: // From Control /** @@ -76,28 +74,28 @@ private: /** * undefined constructor and operator= */ - MyControl( const MyControl& ); - MyControl& operator=( const MyControl& ); + MyControl(const MyControl&); + MyControl& operator=(const MyControl&); private: }; -} // Internal +} // namespace Internal -inline Internal::MyControl& GetImpl( Demo::MyControl& handle ) +inline Internal::MyControl& GetImpl(Demo::MyControl& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -inline const Internal::MyControl& GetImpl( const Demo::MyControl& handle ) +inline const Internal::MyControl& GetImpl(const Demo::MyControl& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); const Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -} // Demo +} // namespace Demo #endif // DALI_DEMO_INTERNAL_MY_CONTROL_IMPL_H diff --git a/examples/simple-visuals-control/my-control.cpp b/examples/simple-visuals-control/my-control.cpp index 65f5c28..66e74f7 100644 --- a/examples/simple-visuals-control/my-control.cpp +++ b/examples/simple-visuals-control/my-control.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,21 +22,20 @@ namespace Demo { - MyControl::MyControl() { } -MyControl::MyControl( const MyControl& control ) -: Control( control ) +MyControl::MyControl(const MyControl& control) +: Control(control) { } -MyControl& MyControl::operator= ( const MyControl& rhs ) +MyControl& MyControl::operator=(const MyControl& rhs) { - if( &rhs != this ) + if(&rhs != this) { - Control::operator=( rhs ); + Control::operator=(rhs); } return *this; } @@ -51,21 +50,20 @@ MyControl MyControl::New() return control; } -MyControl MyControl::DownCast( BaseHandle handle ) +MyControl MyControl::DownCast(BaseHandle handle) { - return Control::DownCast< MyControl, Internal::MyControl > ( handle ); + return Control::DownCast(handle); } -MyControl::MyControl( Internal::MyControl& implementation ) -: Control( implementation ) +MyControl::MyControl(Internal::MyControl& implementation) +: Control(implementation) { } -MyControl::MyControl( Dali::Internal::CustomActor* internal ) -: Control( internal ) +MyControl::MyControl(Dali::Internal::CustomActor* internal) +: Control(internal) { - VerifyCustomActorPointer< Internal::MyControl >( internal ) ; + VerifyCustomActorPointer(internal); } - } //namespace Demo diff --git a/examples/simple-visuals-control/my-control.h b/examples/simple-visuals-control/my-control.h index 3517b81..f380601 100644 --- a/examples/simple-visuals-control/my-control.h +++ b/examples/simple-visuals-control/my-control.h @@ -2,7 +2,7 @@ #define DALI_DEMO_MY_CONTROL_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ namespace Demo { - namespace Internal { class MyControl; @@ -42,7 +41,6 @@ class MyControl; class MyControl : public Dali::Toolkit::Control { public: - /** * The start and end property ranges for this Control * My control can use properties from Toolkit::Control as it is derived from it. As control is derived from Actor, MyControl can also use Dali::Actor Properties. @@ -58,10 +56,10 @@ public: */ enum PropertyRange { - PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, - PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, + PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ANIMATABLE_PROPERTY_START_INDEX = Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, - ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX+1000 + ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX + 1000 }; struct Property @@ -77,7 +75,6 @@ public: }; public: // Construction / destruction - /** * @brief Create an uninitialized handle */ @@ -98,35 +95,33 @@ public: // Construction / destruction * * @param[in] shadowButton the handle of the control to copy */ - MyControl( const MyControl& shadowButton ); + MyControl(const MyControl& shadowButton); /** * @brief Assignment Operator * * @param[in] shadowButton the source of the assignment */ - MyControl& operator=( const MyControl& shadowButton ); + MyControl& operator=(const MyControl& shadowButton); /** * @brief Downcast * * @param[in] shadowButton the handle of control to downcast to MyControl */ - static MyControl DownCast( BaseHandle handle ); - + static MyControl DownCast(BaseHandle handle); public: // // Not intended for application developers - /// @cond internal /** * @brief Create a handle from an implementation */ - MyControl( Internal::MyControl& implementation ); + MyControl(Internal::MyControl& implementation); /** * @brief Allow the creation of an ShadowButton handle from an internal CustomActor pointer */ - MyControl( Dali::Internal::CustomActor* internal ); + MyControl(Dali::Internal::CustomActor* internal); /// @endcond }; diff --git a/examples/simple-visuals-control/simple-visuals-application.cpp b/examples/simple-visuals-control/simple-visuals-application.cpp index f20ffc7..2a9b0d3 100644 --- a/examples/simple-visuals-control/simple-visuals-application.cpp +++ b/examples/simple-visuals-control/simple-visuals-application.cpp @@ -33,33 +33,31 @@ using namespace Dali::Toolkit; namespace { - } namespace Demo { +const char* ICON_IMAGE(DEMO_IMAGE_DIR "application-icon-13.png"); -const char* ICON_IMAGE( DEMO_IMAGE_DIR "application-icon-13.png" ); - -SimpleVisualsApplication::SimpleVisualsApplication( Application& application ) -: mApplication( application ), +SimpleVisualsApplication::SimpleVisualsApplication(Application& application) +: mApplication(application), mMyControl() { - application.InitSignal().Connect( this, &SimpleVisualsApplication::Create ); + application.InitSignal().Connect(this, &SimpleVisualsApplication::Create); } -Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction ) +Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction) { Actor nextFocusActor = proposed; - if( !current && !proposed ) + if(!current && !proposed) { // Set the initial focus to the first tile in the current page should be focused. nextFocusActor = mMyControl; } else { - if ( current == mMyControl ) + if(current == mMyControl) { nextFocusActor = mMyControl2; } @@ -72,68 +70,67 @@ Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange( Dali::Actor curr return nextFocusActor; } - -void SimpleVisualsApplication::OnKeyEvent( const KeyEvent& keyEvent ) +void SimpleVisualsApplication::OnKeyEvent(const KeyEvent& keyEvent) { static int keyPressed = 0; - if( keyEvent.GetState() == KeyEvent::DOWN) + if(keyEvent.GetState() == KeyEvent::DOWN) { - if( keyPressed == 0 ) // Is this the first down event? + if(keyPressed == 0) // Is this the first down event? { - printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode() ); + printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode()); - if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) ) + if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK)) { mApplication.Quit(); } - else if( keyEvent.GetKeyName().compare("Return") == 0 ) + else if(keyEvent.GetKeyName().compare("Return") == 0) { } } keyPressed = 1; } - else if( keyEvent.GetState() == KeyEvent::UP ) + else if(keyEvent.GetState() == KeyEvent::UP) { keyPressed = 0; } } -void SimpleVisualsApplication::Create( Application& application ) +void SimpleVisualsApplication::Create(Application& application) { Window window = application.GetWindow(); - window.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) ); + window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f)); // Connect to key events so can quit application window.KeyEventSignal().Connect(this, &SimpleVisualsApplication::OnKeyEvent); // Create a table view to parent the 2 MyControls - TableView contentLayout = TableView::New( 2, 2 ); - contentLayout.SetProperty( Dali::Actor::Property::NAME,"ContentLayout"); - contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - contentLayout.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); - contentLayout.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 1.0f, .5f, 1.0f ) ); - contentLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - contentLayout.SetCellPadding( Vector2( 50.0f, 15.0f ) ); - contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) ); + TableView contentLayout = TableView::New(2, 2); + contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout"); + contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + contentLayout.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT); + contentLayout.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(1.0f, .5f, 1.0f)); + contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + contentLayout.SetCellPadding(Vector2(50.0f, 15.0f)); + contentLayout.SetBackgroundColor(Vector4(0.949, 0.949, 0.949, 1.0)); // Listen to focus change so can see Visual change from NORMAL to FOCUSED state - KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &SimpleVisualsApplication::OnKeyboardPreFocusChange ); + KeyboardFocusManager::Get().PreFocusChangeSignal().Connect(this, &SimpleVisualsApplication::OnKeyboardPreFocusChange); - window.Add( contentLayout ); + window.Add(contentLayout); // Create 2 MyControls and add to table view. mMyControl = MyControl::New(); - mMyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mMyControl.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT); + mMyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mMyControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); mMyControl2 = MyControl::New(); - mMyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mMyControl2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + mMyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mMyControl2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); - contentLayout.AddChild( mMyControl2, TableView::CellPosition(0, 0) ); - contentLayout.AddChild( mMyControl, TableView::CellPosition(0, 1) ); + contentLayout.AddChild(mMyControl2, TableView::CellPosition(0, 0)); + contentLayout.AddChild(mMyControl, TableView::CellPosition(0, 1)); } } // namespace Demo diff --git a/examples/simple-visuals-control/simple-visuals-application.h b/examples/simple-visuals-control/simple-visuals-application.h index b0e5982..344a378 100644 --- a/examples/simple-visuals-control/simple-visuals-application.h +++ b/examples/simple-visuals-control/simple-visuals-application.h @@ -2,7 +2,7 @@ #define DALI_DEMO_SIMPLE_VISUALS_APPLICATION_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ using namespace Dali::Toolkit; namespace Demo { - /** * @brief An application that uses the my-control to display 2 icons, if focus is allowed ( by using a keyboard or remote ) then the icons will change * depending on which one is focused. @@ -39,16 +38,13 @@ namespace Demo */ class SimpleVisualsApplication : public ConnectionTracker { - public: - /** * @brief Constructor. * * @param[in] application A reference to the Application class. */ - SimpleVisualsApplication( Application& application ); - + SimpleVisualsApplication(Application& application); private: /** @@ -57,33 +53,29 @@ private: * @param[in] proposed New actor that is requesting to be focused * @param[in] direction The direction of the focus event from current actor */ - Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction ); + Dali::Actor OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction); /** * @brief Derived from control, enables capture of key presses * * @param[in] event In incoming key event */ - void OnKeyEvent( const KeyEvent& event ); + void OnKeyEvent(const KeyEvent& event); /** * @brief Called to initialise the application content * * @param[in] application A reference to the Application class. */ - void Create( Application& application ); - + void Create(Application& application); private: - - Application& mApplication; // Handle to the application that is created and passed in. + Application& mApplication; // Handle to the application that is created and passed in. MyControl mMyControl; // Handle to first instance of MyControl MyControl mMyControl2; // Handle to second instance of MyControl - }; } // Namespace Demo - #endif // DALI_DEMO_SIMPLE_VISUALS_APPLICATION_H diff --git a/examples/simple-visuals-control/simple-visuals-example.cpp b/examples/simple-visuals-control/simple-visuals-example.cpp index 4c20557..535063a 100644 --- a/examples/simple-visuals-control/simple-visuals-example.cpp +++ b/examples/simple-visuals-control/simple-visuals-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,13 +28,13 @@ namespace { // Style sheet to be used by this application -const char* SIMPLE_DEMO_THEME( DEMO_STYLE_DIR "simple-example-theme.json" ); -} +const char* SIMPLE_DEMO_THEME(DEMO_STYLE_DIR "simple-example-theme.json"); +} // namespace -int DALI_EXPORT_API main( int argc, char** argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, SIMPLE_DEMO_THEME ); // Use the above defined style sheet for this application. - Demo::SimpleVisualsApplication simpleVisualsApplication( application ); + Application application = Application::New(&argc, &argv, SIMPLE_DEMO_THEME); // Use the above defined style sheet for this application. + Demo::SimpleVisualsApplication simpleVisualsApplication(application); application.MainLoop(); return 0; } diff --git a/examples/size-negotiation/size-negotiation-example.cpp b/examples/size-negotiation/size-negotiation-example.cpp index fbfc121..0dc96e3 100644 --- a/examples/size-negotiation/size-negotiation-example.cpp +++ b/examples/size-negotiation/size-negotiation-example.cpp @@ -15,12 +15,12 @@ * */ -#include "shared/view.h" -#include #include #include #include #include +#include +#include "shared/view.h" using namespace Dali; @@ -34,74 +34,70 @@ struct ButtonItem namespace { - const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg"; -const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; -const char* const IMAGE = DEMO_IMAGE_DIR "background-magnifier.jpg"; +const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; +const char* const IMAGE = DEMO_IMAGE_DIR "background-magnifier.jpg"; const char* const TOOLBAR_TITLE = "Negotiate Size"; // This example contains size negotiation tests for TableView and Popup. -const char* const TABLEVIEW_BUTTON_1CELL_ID = "TABLEVIEW_BUTTON_1CELL"; -const char* const TABLEVIEW_BUTTON_3CELL_ID = "TABLEVIEW_BUTTON_3CELL"; -const char* const TABLEVIEW_BUTTON_3X3CELL_ID = "TABLEVIEW_BUTTON_3X3CELL"; -const char* const TABLEVIEW_BUTTON_FIXED1_ID = "TABLEVIEW_BUTTON_FIXED1"; -const char* const TABLEVIEW_BUTTON_FIXED2_ID = "TABLEVIEW_BUTTON_FIXED2"; -const char* const TABLEVIEW_BUTTON_FIT1_ID = "TABLEVIEW_BUTTON_FIT1"; -const char* const TABLEVIEW_BUTTON_FIT2_ID = "TABLEVIEW_BUTTON_FIT2"; -const char* const TABLEVIEW_BUTTON_NATURAL1_ID = "TABLEVIEW_BUTTON_NATURAL1"; -const char* const TABLEVIEW_BUTTON_NATURAL2_ID = "TABLEVIEW_BUTTON_NATURAL2"; -const char* const TABLEVIEW_BUTTON_NATURAL3_ID = "TABLEVIEW_BUTTON_NATURAL3"; +const char* const TABLEVIEW_BUTTON_1CELL_ID = "TABLEVIEW_BUTTON_1CELL"; +const char* const TABLEVIEW_BUTTON_3CELL_ID = "TABLEVIEW_BUTTON_3CELL"; +const char* const TABLEVIEW_BUTTON_3X3CELL_ID = "TABLEVIEW_BUTTON_3X3CELL"; +const char* const TABLEVIEW_BUTTON_FIXED1_ID = "TABLEVIEW_BUTTON_FIXED1"; +const char* const TABLEVIEW_BUTTON_FIXED2_ID = "TABLEVIEW_BUTTON_FIXED2"; +const char* const TABLEVIEW_BUTTON_FIT1_ID = "TABLEVIEW_BUTTON_FIT1"; +const char* const TABLEVIEW_BUTTON_FIT2_ID = "TABLEVIEW_BUTTON_FIT2"; +const char* const TABLEVIEW_BUTTON_NATURAL1_ID = "TABLEVIEW_BUTTON_NATURAL1"; +const char* const TABLEVIEW_BUTTON_NATURAL2_ID = "TABLEVIEW_BUTTON_NATURAL2"; +const char* const TABLEVIEW_BUTTON_NATURAL3_ID = "TABLEVIEW_BUTTON_NATURAL3"; const char* const POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID = "POPUP_BUTTON_CONTENT_IMAGE_SCALE"; -const char* const POPUP_BUTTON_CONTENT_IMAGE_FIT_ID = "POPUP_BUTTON_CONTENT_IMAGE_FIT"; -const char* const POPUP_BUTTON_CONTENT_IMAGE_FILL_ID = "POPUP_BUTTON_CONTENT_IMAGE_FILL"; +const char* const POPUP_BUTTON_CONTENT_IMAGE_FIT_ID = "POPUP_BUTTON_CONTENT_IMAGE_FIT"; +const char* const POPUP_BUTTON_CONTENT_IMAGE_FILL_ID = "POPUP_BUTTON_CONTENT_IMAGE_FILL"; const ButtonItem TABLEVIEW_BUTTON_ITEMS[] = { - { TABLEVIEW_BUTTON_1CELL_ID, "1 Cell" }, - { TABLEVIEW_BUTTON_3CELL_ID, "3 Cell" }, - { TABLEVIEW_BUTTON_3X3CELL_ID, "3x3 Cells" }, - { TABLEVIEW_BUTTON_FIXED1_ID, "Fixed 1" }, - { TABLEVIEW_BUTTON_FIXED2_ID, "Fixed 2" }, - { TABLEVIEW_BUTTON_FIT1_ID, "Fit Top Bottom" }, - { TABLEVIEW_BUTTON_FIT2_ID, "Fit Middle" }, - { TABLEVIEW_BUTTON_NATURAL1_ID, "Natural 1" }, - { TABLEVIEW_BUTTON_NATURAL2_ID, "Natural 2" }, - { TABLEVIEW_BUTTON_NATURAL3_ID, "Natural 3" }, - { POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID, "Image Scale" }, - { POPUP_BUTTON_CONTENT_IMAGE_FIT_ID, "Image Fit" }, - { POPUP_BUTTON_CONTENT_IMAGE_FILL_ID, "Image Fill" }, + {TABLEVIEW_BUTTON_1CELL_ID, "1 Cell"}, + {TABLEVIEW_BUTTON_3CELL_ID, "3 Cell"}, + {TABLEVIEW_BUTTON_3X3CELL_ID, "3x3 Cells"}, + {TABLEVIEW_BUTTON_FIXED1_ID, "Fixed 1"}, + {TABLEVIEW_BUTTON_FIXED2_ID, "Fixed 2"}, + {TABLEVIEW_BUTTON_FIT1_ID, "Fit Top Bottom"}, + {TABLEVIEW_BUTTON_FIT2_ID, "Fit Middle"}, + {TABLEVIEW_BUTTON_NATURAL1_ID, "Natural 1"}, + {TABLEVIEW_BUTTON_NATURAL2_ID, "Natural 2"}, + {TABLEVIEW_BUTTON_NATURAL3_ID, "Natural 3"}, + {POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID, "Image Scale"}, + {POPUP_BUTTON_CONTENT_IMAGE_FIT_ID, "Image Fit"}, + {POPUP_BUTTON_CONTENT_IMAGE_FILL_ID, "Image Fill"}, }; -const unsigned int TABLEVIEW_BUTTON_ITEMS_COUNT = sizeof( TABLEVIEW_BUTTON_ITEMS ) / sizeof( TABLEVIEW_BUTTON_ITEMS[0] ); - +const unsigned int TABLEVIEW_BUTTON_ITEMS_COUNT = sizeof(TABLEVIEW_BUTTON_ITEMS) / sizeof(TABLEVIEW_BUTTON_ITEMS[0]); -Actor CreateSolidColor( Vector4 color ) +Actor CreateSolidColor(Vector4 color) { Toolkit::Control control = Toolkit::Control::New(); Property::Map map; - map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; - map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; - control.SetProperty( Toolkit::Control::Property::BACKGROUND, map ); + map[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::COLOR; + map[Toolkit::ColorVisual::Property::MIX_COLOR] = color; + control.SetProperty(Toolkit::Control::Property::BACKGROUND, map); return control; } -} // anonymous namespace - +} // anonymous namespace /** * This example shows the usage of size negotiation. */ -class SizeNegotiationController: public ConnectionTracker, public Toolkit::ItemFactory +class SizeNegotiationController : public ConnectionTracker, public Toolkit::ItemFactory { public: - - SizeNegotiationController( Application& application ) - : mApplication( application ) + SizeNegotiationController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &SizeNegotiationController::Create ); + mApplication.InitSignal().Connect(this, &SizeNegotiationController::Create); } ~SizeNegotiationController() @@ -109,7 +105,7 @@ public: // Nothing to do here } - void Create( Application& application ) + void Create(Application& application) { // The Init signal is received once (only) during the Application lifetime Window window = application.GetWindow(); @@ -119,56 +115,56 @@ public: // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - std::string("") ); + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + std::string("")); - mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" ); - mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE ); + mTitleActor = DemoHelper::CreateToolBarLabel("CUSTOM_TOOLBAR_TITLE"); + mTitleActor.SetProperty(Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE); // Add title to the tool bar. - const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding ); - mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER, Toolkit::Alignment::Padding( padding, padding, padding, padding ) ); + const float padding(DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding); + mToolBar.AddControl(mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER, Toolkit::Alignment::Padding(padding, padding, padding, padding)); - mItemView = Toolkit::ItemView::New( *this ); - mItemView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mItemView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mItemView = Toolkit::ItemView::New(*this); + mItemView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mItemView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mItemView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); // Use a grid layout for tests - Vector2 windowSize = window.GetSize(); - Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST ); - Vector3 itemSize; - gridLayout->GetItemSize( 0, Vector3( windowSize ), itemSize ); + Vector2 windowSize = window.GetSize(); + Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New(Toolkit::DefaultItemLayout::LIST); + Vector3 itemSize; + gridLayout->GetItemSize(0, Vector3(windowSize), itemSize); itemSize.height = windowSize.y / 10; - gridLayout->SetItemSize( itemSize ); - mItemView.AddLayout( *gridLayout ); + gridLayout->SetItemSize(itemSize); + mItemView.AddLayout(*gridLayout); - mItemView.ActivateLayout( 0, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f ); + mItemView.ActivateLayout(0, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f); - mContentLayer.Add( mItemView ); + mContentLayer.Add(mItemView); } - void ShowPopup( Toolkit::Popup popup ) + void ShowPopup(Toolkit::Popup popup) { - mApplication.GetWindow().Add( popup ); - popup.SetDisplayState( Toolkit::Popup::SHOWN ); + mApplication.GetWindow().Add(popup); + popup.SetDisplayState(Toolkit::Popup::SHOWN); } void OnPopupOutsideTouched() { - if( mPopup ) + if(mPopup) { - mPopup.SetDisplayState( Toolkit::Popup::HIDDEN ); + mPopup.SetDisplayState(Toolkit::Popup::HIDDEN); } } void PopupHidden() { - if( mPopup ) + if(mPopup) { mPopup.Unparent(); mPopup.Reset(); @@ -177,597 +173,597 @@ public: Toolkit::Popup CreatePopup() { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); const float POPUP_WIDTH_DP = window.GetSize().GetWidth() * 0.75f; Toolkit::Popup popup = Toolkit::Popup::New(); - popup.SetProperty( Dali::Actor::Property::NAME, "popup" ); - popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - popup.SetProperty( Actor::Property::SIZE, Vector2( POPUP_WIDTH_DP, 0.0f ) ); - popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false ); + popup.SetProperty(Dali::Actor::Property::NAME, "popup"); + popup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + popup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + popup.SetProperty(Actor::Property::SIZE, Vector2(POPUP_WIDTH_DP, 0.0f)); + popup.SetProperty(Toolkit::Popup::Property::TAIL_VISIBILITY, false); - popup.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::OnPopupOutsideTouched ); - popup.HiddenSignal().Connect( this, &SizeNegotiationController::PopupHidden ); + popup.OutsideTouchedSignal().Connect(this, &SizeNegotiationController::OnPopupOutsideTouched); + popup.HiddenSignal().Connect(this, &SizeNegotiationController::PopupHidden); return popup; } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { - if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_1CELL_ID ) + if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_1CELL_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::TableView table = Toolkit::TableView::New( 0, 0 ); - table.SetProperty( Dali::Actor::Property::NAME, "TABLEVIEW_BUTTON_1CELL_ID" ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Toolkit::TableView table = Toolkit::TableView::New(0, 0); + table.SetProperty(Dali::Actor::Property::NAME, "TABLEVIEW_BUTTON_1CELL_ID"); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.Add( backing ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.Add(backing); - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_3CELL_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_3CELL_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(0, 0)); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(1, 0)); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(2, 0)); } - mPopup.SetContent( table ); + mPopup.SetContent(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_3X3CELL_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_3X3CELL_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::TableView table = Toolkit::TableView::New( 3, 3 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Toolkit::TableView table = Toolkit::TableView::New(3, 3); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); // Column 0 { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(0, 0)); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(1, 0)); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(2, 0)); } // Column 1 { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 1.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(0, 1)); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 1.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(1, 1)); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 0.0f, 1.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(2, 1)); } // Column 2 { - Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(0, 2)); } { - Actor backing = CreateSolidColor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) ); + Actor backing = CreateSolidColor(Vector4(0.5f, 0.5f, 0.5f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(1, 2)); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.5f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.AddChild(backing, Toolkit::TableView::CellPosition(2, 2)); } - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIXED1_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_FIXED1_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); - - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.SetFixedHeight( 0, 50.0f ); - - { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - backing.Add( text ); - table.Add( backing ); - } - { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - backing.Add( text ); - table.Add( backing ); - } - { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - backing.Add( text ); - table.Add( backing ); - } - - mPopup.Add( table ); - - ShowPopup( mPopup ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); + + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.SetFixedHeight(0, 50.0f); + + { + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fixed"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + backing.Add(text); + table.Add(backing); + } + { + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fill"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + backing.Add(text); + table.Add(backing); + } + { + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fill"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + backing.Add(text); + table.Add(backing); + } + + mPopup.Add(table); + + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIXED2_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_FIXED2_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.SetFixedHeight( 0, 50.0f ); - table.SetFixedHeight( 2, 50.0f ); + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.SetFixedHeight(0, 50.0f); + table.SetFixedHeight(2, 50.0f); { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fixed"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); - table.Add( backing ); + backing.Add(text); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fill"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); - table.Add( backing ); + backing.Add(text); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fixed"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); - table.Add( backing ); + backing.Add(text); + table.Add(backing); } - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIT1_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_FIT1_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.SetFitHeight( 0 ); - table.SetFitHeight( 2 ); + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.SetFitHeight(0); + table.SetFitHeight(2); { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 100.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fill"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 100.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIT2_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_FIT2_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - table.SetFitHeight( 1 ); + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + table.SetFitHeight(1); { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fill"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 200.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - backing.Add( text ); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fill"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_NATURAL1_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_NATURAL1_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 1.0f, 1.0f ) ); - mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 1.0f, 1.0f)); + mPopup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - table.SetFitHeight( 0 ); - table.SetFitHeight( 1 ); - table.SetFitHeight( 2 ); + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + table.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + table.SetFitHeight(0); + table.SetFitHeight(1); + table.SetFitHeight(2); { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 100.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 200.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 300.0f ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 300.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_NATURAL2_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_NATURAL2_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 1.0f, 1.0f ) ); - mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 1.0f, 1.0f)); + mPopup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - table.SetFitHeight( 0 ); - table.SetFitHeight( 1 ); + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + table.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + table.SetFitHeight(0); + table.SetFitHeight(1); { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetResizePolicy(ResizePolicy::FIXED, Dimension::HEIGHT); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 100.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 200.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_NATURAL3_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == TABLEVIEW_BUTTON_NATURAL3_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 1.0f, 1.0f ) ); - mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 1.0f, 1.0f)); + mPopup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); - Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); - table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - table.SetFixedHeight( 0, 20.0f ); - table.SetFitHeight( 1 ); + Toolkit::TableView table = Toolkit::TableView::New(3, 1); + table.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + table.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + table.SetFixedHeight(0, 20.0f); + table.SetFitHeight(1); { - Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Actor backing = CreateSolidColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fixed"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } { - Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); - backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) ); + Actor backing = CreateSolidColor(Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + backing.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + backing.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 200.0f)); - Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" ); - text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + Toolkit::TextLabel text = Toolkit::TextLabel::New("Fit"); + text.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + text.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + text.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + text.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + text.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); - backing.Add( text ); + backing.Add(text); - table.Add( backing ); + table.Add(backing); } - mPopup.Add( table ); + mPopup.Add(table); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE ); - image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Toolkit::ImageView image = Toolkit::ImageView::New(IMAGE); + image.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); - mPopup.Add( image ); + mPopup.Add(image); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE ); - image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - image.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); + Toolkit::ImageView image = Toolkit::ImageView::New(IMAGE); + image.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + image.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); - mPopup.Add( image ); + mPopup.Add(image); - ShowPopup( mPopup ); + ShowPopup(mPopup); } - else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID ) + else if(button.GetProperty(Dali::Actor::Property::NAME) == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID) { mPopup = CreatePopup(); - mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) ); + mPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 0.5f, 1.0f)); - Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE ); - image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - image.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FILL_WITH_ASPECT_RATIO ); + Toolkit::ImageView image = Toolkit::ImageView::New(IMAGE); + image.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + image.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FILL_WITH_ASPECT_RATIO); - mPopup.Add( image ); + mPopup.Add(image); - ShowPopup( mPopup ); + ShowPopup(mPopup); } return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { // Exit application when click back or escape. mApplication.Quit(); @@ -776,7 +772,6 @@ public: } public: // From ItemFactory - /** * @brief Return the number of items to display in the item view * @@ -796,34 +791,32 @@ public: // From ItemFactory virtual Actor NewItem(unsigned int itemId) { Toolkit::PushButton popupButton = Toolkit::PushButton::New(); - popupButton.SetProperty( Dali::Actor::Property::NAME, TABLEVIEW_BUTTON_ITEMS[ itemId ].name ); - popupButton.SetProperty( Toolkit::Button::Property::LABEL, TABLEVIEW_BUTTON_ITEMS[ itemId ].text ); - popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + popupButton.SetProperty(Dali::Actor::Property::NAME, TABLEVIEW_BUTTON_ITEMS[itemId].name); + popupButton.SetProperty(Toolkit::Button::Property::LABEL, TABLEVIEW_BUTTON_ITEMS[itemId].text); + popupButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); - popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + popupButton.ClickedSignal().Connect(this, &SizeNegotiationController::OnButtonClicked); return popupButton; } private: + Application& mApplication; + Toolkit::Control mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer. - Application& mApplication; - Toolkit::Control mView; ///< The View instance. - Toolkit::ToolBar mToolBar; ///< The View's Toolbar. - Layer mContentLayer; ///< Content layer. - - Toolkit::TextLabel mTitleActor; ///< Title text. - Toolkit::Popup mMenu; ///< The navigation menu. - Toolkit::Popup mPopup; ///< The current example popup. - - Toolkit::ItemView mItemView; ///< ItemView to hold test images. + Toolkit::TextLabel mTitleActor; ///< Title text. + Toolkit::Popup mMenu; ///< The navigation menu. + Toolkit::Popup mPopup; ///< The current example popup. + Toolkit::ItemView mItemView; ///< ItemView to hold test images. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - SizeNegotiationController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + SizeNegotiationController test(application); application.MainLoop(); return 0; } diff --git a/examples/sparkle/sparkle-effect-example.cpp b/examples/sparkle/sparkle-effect-example.cpp old mode 100755 new mode 100644 index 61b6789..cac0e40 --- a/examples/sparkle/sparkle-effect-example.cpp +++ b/examples/sparkle/sparkle-effect-example.cpp @@ -15,14 +15,14 @@ * */ -#include #include +#include -#include #include +#include // std::chrono::system_clock #include -#include // std::default_random_engine -#include // std::chrono::system_clock +#include // std::default_random_engine +#include #include "shared/utility.h" #include "sparkle-effect.h" @@ -34,30 +34,29 @@ using namespace SparkleEffect; namespace // unnamed namespace { - //background image for normal status -const char * const CIRCLE_BACKGROUND_IMAGE( DEMO_IMAGE_DIR "sparkle_normal_background.png" ); +const char* const CIRCLE_BACKGROUND_IMAGE(DEMO_IMAGE_DIR "sparkle_normal_background.png"); //particle shape image -const char * const PARTICLE_IMAGE( DEMO_IMAGE_DIR "sparkle_particle.png" ); +const char* const PARTICLE_IMAGE(DEMO_IMAGE_DIR "sparkle_particle.png"); -float EaseOutSquare( float progress ) +float EaseOutSquare(float progress) { - return 1.0f - (1.0f-progress) * (1.0f-progress); + return 1.0f - (1.0f - progress) * (1.0f - progress); } -float CustomBounce( float progress ) +float CustomBounce(float progress) { - float p = 1.f-progress; - p *=p; - return 17.68f*p*p*p*progress; + float p = 1.f - progress; + p *= p; + return 17.68f * p * p * p * progress; } -float Mix( const Vector2& range, float a ) +float Mix(const Vector2& range, float a) { - return range.x * a + range.y*(1.f-a)-0.001f; + return range.x * a + range.y * (1.f - a) - 0.001f; } -const Vector4 BACKGROUND_COLOR( 0.f, 0.f, 0.05f, 1.f ); +const Vector4 BACKGROUND_COLOR(0.f, 0.f, 0.05f, 1.f); } // unnamed namespace @@ -66,55 +65,53 @@ const Vector4 BACKGROUND_COLOR( 0.f, 0.f, 0.05f, 1.f ); class SparkleEffectExample : public ConnectionTracker { public: - /** * Create the SparkleEffectExample * @param[in] application The DALi application instance */ - SparkleEffectExample( Application& application ) - : mApplication( application ), - mAnimationIndex( 0u ), - mShaking( false ) + SparkleEffectExample(Application& application) + : mApplication(application), + mAnimationIndex(0u), + mShaking(false) { - mApplication.InitSignal().Connect( this, &SparkleEffectExample::OnInit ); + mApplication.InitSignal().Connect(this, &SparkleEffectExample::OnInit); } private: - /** * Initialize the SparkleEffectExample * @param[in] application The DALi application instance */ - void OnInit( Application& application ) + void OnInit(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &SparkleEffectExample::OnKeyEvent); - window.SetBackgroundColor( BACKGROUND_COLOR ); + window.SetBackgroundColor(BACKGROUND_COLOR); - mCircleBackground = ImageView::New( CIRCLE_BACKGROUND_IMAGE ); - mCircleBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCircleBackground.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mCircleBackground = ImageView::New(CIRCLE_BACKGROUND_IMAGE); + mCircleBackground.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCircleBackground.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - window.Add( mCircleBackground ); + window.Add(mCircleBackground); mEffect = SparkleEffect::New(); mMeshActor = CreateMeshActor(); - window.Add( mMeshActor ); + window.Add(mMeshActor); - mMeshActor.SetProperty( Actor::Property::POSITION, ACTOR_POSITION ); - mMeshActor.SetProperty( Actor::Property::SCALE, ACTOR_SCALE ); + mMeshActor.SetProperty(Actor::Property::POSITION, ACTOR_POSITION); + mMeshActor.SetProperty(Actor::Property::SCALE, ACTOR_SCALE); mTapDetector = TapGestureDetector::New(); mTapDetector.Attach(mCircleBackground); - mTapDetector.DetectedSignal().Connect( this, &SparkleEffectExample::OnTap ); + mTapDetector.DetectedSignal().Connect(this, &SparkleEffectExample::OnTap); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.DetectedSignal().Connect( this, &SparkleEffectExample::OnPan ); - mPanGestureDetector.Attach( mCircleBackground ); + mPanGestureDetector.DetectedSignal().Connect(this, &SparkleEffectExample::OnPan); + mPanGestureDetector.Attach(mCircleBackground); - PlayWanderAnimation( 35.f ); + PlayWanderAnimation(35.f); } /** @@ -124,28 +121,28 @@ private: { // shuffling to assign the color in random order unsigned int* shuffleArray = new unsigned int[NUM_PARTICLE]; - for( unsigned int i = 0; i vertices; - std::vector< unsigned short > faces; + std::vector vertices; + std::vector faces; - for( unsigned int i = 0; i(thereshold-particleIndex)/PARTICLE_COLORS[i].numParticle ); + return i + Mix(PARTICLE_COLORS[i].AlphaRange, static_cast(thereshold - particleIndex) / PARTICLE_COLORS[i].numParticle); } } - return NUM_COLOR-1; + return NUM_COLOR - 1; } /** @@ -212,35 +209,35 @@ private: * color index, particle index and textureCoor( (0,0) or (1,0) or (0,1) or (1,1) ) * ---- package these info into texCood attribute as: (+-colorIndex, +-particleIndex) */ - void AddParticletoMesh( std::vector< Vertex >& vertices, - std::vector< unsigned short >& faces, - MovingPath& movingPath, - float colorIndex ) + void AddParticletoMesh(std::vector& vertices, + std::vector& faces, + MovingPath& movingPath, + float colorIndex) { unsigned int idx = vertices.size(); // store the path into position and normal, which would be decoded inside the shader - Vector2 particlePath0( movingPath[0], movingPath[1] ); - Vector2 particlePath1( movingPath[2], movingPath[3] ); - Vector2 particlePath2( movingPath[4], movingPath[5] ); - Vector2 particlePath3( movingPath[6], movingPath[7] ); - Vector2 particlePath4( movingPath[8], movingPath[9] ); - Vector2 particlePath5( movingPath[10], movingPath[11] ); - - float particleIdx = static_cast(idx/4 + 1); // count from 1 - float colorIdx = colorIndex+1.f; // count from 1 - vertices.push_back( Vertex( Vector2(-colorIdx, -particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); - vertices.push_back( Vertex( Vector2(-colorIdx, particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); - vertices.push_back( Vertex( Vector2( colorIdx, particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); - vertices.push_back( Vertex( Vector2( colorIdx, -particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5 ) ); + Vector2 particlePath0(movingPath[0], movingPath[1]); + Vector2 particlePath1(movingPath[2], movingPath[3]); + Vector2 particlePath2(movingPath[4], movingPath[5]); + Vector2 particlePath3(movingPath[6], movingPath[7]); + Vector2 particlePath4(movingPath[8], movingPath[9]); + Vector2 particlePath5(movingPath[10], movingPath[11]); + + float particleIdx = static_cast(idx / 4 + 1); // count from 1 + float colorIdx = colorIndex + 1.f; // count from 1 + vertices.push_back(Vertex(Vector2(-colorIdx, -particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5)); + vertices.push_back(Vertex(Vector2(-colorIdx, particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5)); + vertices.push_back(Vertex(Vector2(colorIdx, particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5)); + vertices.push_back(Vertex(Vector2(colorIdx, -particleIdx), particlePath0, particlePath1, particlePath2, particlePath3, particlePath4, particlePath5)); faces.push_back(idx); - faces.push_back(idx+1); - faces.push_back(idx+2); + faces.push_back(idx + 1); + faces.push_back(idx + 2); faces.push_back(idx); - faces.push_back(idx+2); - faces.push_back(idx+3); + faces.push_back(idx + 2); + faces.push_back(idx + 3); } /* @@ -250,7 +247,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -260,7 +257,7 @@ private: /** * Callback of the TapGesture */ - void OnTap( Actor actor, const TapGesture& tap ) + void OnTap(Actor actor, const TapGesture& tap) { { PlayTapAnimation(5.f, tap.GetLocalPoint()); @@ -270,34 +267,34 @@ private: /** * Callback of the PanGesture */ - void OnPan( Actor actor, const PanGesture& gesture ) + void OnPan(Actor actor, const PanGesture& gesture) { - if( gesture.GetState() == GestureState::FINISHED ) + if(gesture.GetState() == GestureState::FINISHED) { switch(mAnimationIndex) { - case 0: - { - PlayParticleFadeAnimation(0, NUM_PARTICLE, 0.f, 3.f ); - break; + case 0: + { + PlayParticleFadeAnimation(0, NUM_PARTICLE, 0.f, 3.f); + break; + } + case 1: + { + PlayBreakAnimation(2.0f); + break; + } + case 2: + { + PlayShakeAnimation(0.5f, 2.5f); + break; + } + default: + { + break; + } } - case 1: - { - PlayBreakAnimation(2.0f); - break; - } - case 2: - { - PlayShakeAnimation(0.5f, 2.5f); - break; - } - default: - { - break; - } - } - mAnimationIndex = (mAnimationIndex+1)%3; + mAnimationIndex = (mAnimationIndex + 1) % 3; } } @@ -306,10 +303,10 @@ private: * @param[in] duration The duration for the particle to move a cycle on the path. the bigger this value the slower the floating movement. * @param[in] looping Infinite playing or not */ - void PlayWanderAnimation( float duration, bool looping = true ) + void PlayWanderAnimation(float duration, bool looping = true) { - Animation wanderAnimation= Animation::New(duration); - wanderAnimation.AnimateTo( Property( mEffect, PERCENTAGE_UNIFORM_NAME ), 1.f ); + Animation wanderAnimation = Animation::New(duration); + wanderAnimation.AnimateTo(Property(mEffect, PERCENTAGE_UNIFORM_NAME), 1.f); wanderAnimation.SetLooping(looping); // infinite playing wanderAnimation.Play(); @@ -320,19 +317,19 @@ private: * @param[in] cycle How many extra cycles to move during the animation * @param[in] duration The duration for the animation */ - void PlayShakeAnimation( float cycle, float duration ) + void PlayShakeAnimation(float cycle, float duration) { - if( mShaking ) + if(mShaking) { return; } - DestroyAnimation( mTapAnimationAux ); + DestroyAnimation(mTapAnimationAux); - float accelaration = GetFloatUniformValue( ACCELARATION_UNIFORM_NAME ); - mEffect.SetProperty( mEffect.GetPropertyIndex(ACCELARATION_UNIFORM_NAME), accelaration - int( accelaration) ); // Set the value as its fractional part + float accelaration = GetFloatUniformValue(ACCELARATION_UNIFORM_NAME); + mEffect.SetProperty(mEffect.GetPropertyIndex(ACCELARATION_UNIFORM_NAME), accelaration - int(accelaration)); // Set the value as its fractional part Animation shakeAnimation = Animation::New(duration); - shakeAnimation.AnimateBy( Property( mEffect, ACCELARATION_UNIFORM_NAME ), cycle, AlphaFunction::EASE_OUT ); - shakeAnimation.FinishedSignal().Connect( this, &SparkleEffectExample::OnShakeAnimationFinished ); + shakeAnimation.AnimateBy(Property(mEffect, ACCELARATION_UNIFORM_NAME), cycle, AlphaFunction::EASE_OUT); + shakeAnimation.FinishedSignal().Connect(this, &SparkleEffectExample::OnShakeAnimationFinished); shakeAnimation.Play(); mShaking = true; @@ -342,40 +339,40 @@ private: * Animate the particles to appear from center and spread all over around * @param[in] duration The duration for the animation */ - void PlayBreakAnimation( float duration ) + void PlayBreakAnimation(float duration) { - if( GetFloatUniformValue(BREAK_UNIFORM_NAME) > 0.f ) + if(GetFloatUniformValue(BREAK_UNIFORM_NAME) > 0.f) { return; } // Stop the fading / tap animation before the breaking - DestroyAnimation( mFadeAnimation); + DestroyAnimation(mFadeAnimation); mTapIndices.x = mTapIndices.y; - mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices ); - mEffect.SetProperty( mEffect.GetPropertyIndex( ACCELARATION_UNIFORM_NAME ), 0.f ); + mEffect.SetProperty(mEffect.GetPropertyIndex(TAP_INDICES_UNIFORM_NAME), mTapIndices); + mEffect.SetProperty(mEffect.GetPropertyIndex(ACCELARATION_UNIFORM_NAME), 0.f); // prepare the animation by setting the uniform to the required value - mEffect.SetProperty( mEffect.GetPropertyIndex( BREAK_UNIFORM_NAME ), 1.f ); - mMeshActor.SetProperty( Actor::Property::SCALE,0.01f); - mEffect.SetProperty( mEffect.GetPropertyIndex( "uScale" ), 0.01f ); - mMeshActor.SetProperty( Actor::Property::POSITION, Vector3( 0.f, 0.f, 1.f ) ); - - Animation breakAnimation = Animation::New(duration*1.5f); - breakAnimation.AnimateTo( Property(mMeshActor, Actor::Property::SCALE), Vector3(ACTOR_SCALE,ACTOR_SCALE,ACTOR_SCALE), EaseOutSquare); - breakAnimation.AnimateTo( Property( mEffect, "uScale" ), ACTOR_SCALE, EaseOutSquare); - breakAnimation.AnimateTo( Property(mMeshActor, Actor::Property::POSITION), ACTOR_POSITION, EaseOutSquare); - breakAnimation.FinishedSignal().Connect( this, &SparkleEffectExample::OnBreakAnimationFinished ); - - float timeUnit = duration/ (NUM_PARTICLE+1) /(NUM_PARTICLE+1) ; + mEffect.SetProperty(mEffect.GetPropertyIndex(BREAK_UNIFORM_NAME), 1.f); + mMeshActor.SetProperty(Actor::Property::SCALE, 0.01f); + mEffect.SetProperty(mEffect.GetPropertyIndex("uScale"), 0.01f); + mMeshActor.SetProperty(Actor::Property::POSITION, Vector3(0.f, 0.f, 1.f)); + + Animation breakAnimation = Animation::New(duration * 1.5f); + breakAnimation.AnimateTo(Property(mMeshActor, Actor::Property::SCALE), Vector3(ACTOR_SCALE, ACTOR_SCALE, ACTOR_SCALE), EaseOutSquare); + breakAnimation.AnimateTo(Property(mEffect, "uScale"), ACTOR_SCALE, EaseOutSquare); + breakAnimation.AnimateTo(Property(mMeshActor, Actor::Property::POSITION), ACTOR_POSITION, EaseOutSquare); + breakAnimation.FinishedSignal().Connect(this, &SparkleEffectExample::OnBreakAnimationFinished); + + float timeUnit = duration / (NUM_PARTICLE + 1) / (NUM_PARTICLE + 1); std::ostringstream oss; - for(unsigned int i = 0; i 0.f ) + if(GetFloatUniformValue(BREAK_UNIFORM_NAME) > 0.f) { return; } // start the opacity animation one particle after another gradually - float timeSlice = duration / (numParticle+1); - float fadeDuration = timeSlice>0.5f ? timeSlice : 0.5f; + float timeSlice = duration / (numParticle + 1); + float fadeDuration = timeSlice > 0.5f ? timeSlice : 0.5f; - Animation fadeAnimation= Animation::New(duration+fadeDuration*2.f); + Animation fadeAnimation = Animation::New(duration + fadeDuration * 2.f); std::ostringstream oss; - for(unsigned int i = startIndex; i=NUM_PARTICLE ) break; // out of bound + if(i >= NUM_PARTICLE) break; // out of bound oss.str(""); - oss<< OPACITY_UNIFORM_NAME<< i << "]"; - fadeAnimation.AnimateTo(Property( mEffect, oss.str()), targetValue, TimePeriod( timeSlice*i, fadeDuration*2.f )); + oss << OPACITY_UNIFORM_NAME << i << "]"; + fadeAnimation.AnimateTo(Property(mEffect, oss.str()), targetValue, TimePeriod(timeSlice * i, fadeDuration * 2.f)); } fadeAnimation.Play(); mFadeAnimation = fadeAnimation; - mFadeAnimation.FinishedSignal().Connect( this, &SparkleEffectExample::OnFadeAnimationFinished ); + mFadeAnimation.FinishedSignal().Connect(this, &SparkleEffectExample::OnFadeAnimationFinished); } /** @@ -421,44 +418,44 @@ private: * @param[in] duration The duration for the animation * @param[in] tapPoint The position of the tap point */ - void PlayTapAnimation(float duration, const Vector2& tapPoint ) + void PlayTapAnimation(float duration, const Vector2& tapPoint) { - if( mTapIndices.y > mTapIndices.x && mTapAnimation.GetCurrentProgress() < 0.2f) + if(mTapIndices.y > mTapIndices.x && mTapAnimation.GetCurrentProgress() < 0.2f) { return; } - Animation animation= Animation::New(duration); - int idx = int(mTapIndices.y)%MAXIMUM_ANIMATION_COUNT; + Animation animation = Animation::New(duration); + int idx = int(mTapIndices.y) % MAXIMUM_ANIMATION_COUNT; mTapIndices.y += 1.f; std::ostringstream oss; - oss<< TAP_OFFSET_UNIFORM_NAME<< idx << "]"; - mEffect.SetProperty( mEffect.GetPropertyIndex( oss.str() ), 0.f); - animation.AnimateTo( Property( mEffect, oss.str() ), 0.75f, CustomBounce); + oss << TAP_OFFSET_UNIFORM_NAME << idx << "]"; + mEffect.SetProperty(mEffect.GetPropertyIndex(oss.str()), 0.f); + animation.AnimateTo(Property(mEffect, oss.str()), 0.75f, CustomBounce); oss.str(""); - oss<< TAP_POINT_UNIFORM_NAME<< idx << "]"; - mEffect.SetProperty( mEffect.GetPropertyIndex( oss.str() ), tapPoint/ACTOR_SCALE); + oss << TAP_POINT_UNIFORM_NAME << idx << "]"; + mEffect.SetProperty(mEffect.GetPropertyIndex(oss.str()), tapPoint / ACTOR_SCALE); - mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices); + mEffect.SetProperty(mEffect.GetPropertyIndex(TAP_INDICES_UNIFORM_NAME), mTapIndices); if(!mShaking) { - mTapAnimationAux = Animation::New(duration*0.2f); - mTapAnimationAux.AnimateBy( Property( mEffect, ACCELARATION_UNIFORM_NAME ), 0.15f, AlphaFunction::EASE_IN_OUT ); + mTapAnimationAux = Animation::New(duration * 0.2f); + mTapAnimationAux.AnimateBy(Property(mEffect, ACCELARATION_UNIFORM_NAME), 0.15f, AlphaFunction::EASE_IN_OUT); mTapAnimationAux.Play(); } animation.Play(); - mTapAnimationIndexPair[animation] = static_cast(mTapIndices.y -1.f); - animation.FinishedSignal().Connect( this, &SparkleEffectExample::OnTapAnimationFinished ); + mTapAnimationIndexPair[animation] = static_cast(mTapIndices.y - 1.f); + animation.FinishedSignal().Connect(this, &SparkleEffectExample::OnTapAnimationFinished); mTapAnimation = animation; } /** * Callback of the animation finished signal */ - void OnShakeAnimationFinished( Animation& animation) + void OnShakeAnimationFinished(Animation& animation) { mShaking = false; } @@ -466,7 +463,7 @@ private: /** * Callback of the animation finished signal */ - void OnFadeAnimationFinished( Animation& animation) + void OnFadeAnimationFinished(Animation& animation) { mFadeAnimation.Clear(); mFadeAnimation.Reset(); @@ -475,31 +472,31 @@ private: /** * Callback of the animation finished signal */ - void OnBreakAnimationFinished( Animation& animation) + void OnBreakAnimationFinished(Animation& animation) { - mEffect.SetProperty( mEffect.GetPropertyIndex( BREAK_UNIFORM_NAME ), 0.f ); + mEffect.SetProperty(mEffect.GetPropertyIndex(BREAK_UNIFORM_NAME), 0.f); } /** * Callback of the animation finished signal */ - void OnTapAnimationFinished( Animation& animation ) + void OnTapAnimationFinished(Animation& animation) { - if( mTapAnimationIndexPair[animation] == static_cast(mTapIndices.x) ) + if(mTapAnimationIndexPair[animation] == static_cast(mTapIndices.x)) { mTapIndices.x += 1.f; - if( mTapIndices.x >= mTapIndices.y ) + if(mTapIndices.x >= mTapIndices.y) { mTapIndices = Vector2::ZERO; } - mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices); + mEffect.SetProperty(mEffect.GetPropertyIndex(TAP_INDICES_UNIFORM_NAME), mTapIndices); } - mTapAnimationIndexPair.erase( animation ); - if( mTapAnimationIndexPair.size() < 1 && mTapIndices != Vector2::ZERO) + mTapAnimationIndexPair.erase(animation); + if(mTapAnimationIndexPair.size() < 1 && mTapIndices != Vector2::ZERO) { mTapIndices = Vector2::ZERO; - mEffect.SetProperty( mEffect.GetPropertyIndex( TAP_INDICES_UNIFORM_NAME ), mTapIndices); + mEffect.SetProperty(mEffect.GetPropertyIndex(TAP_INDICES_UNIFORM_NAME), mTapIndices); } animation.Clear(); @@ -511,7 +508,7 @@ private: * @param[in] uniformName The uniform * @return The float value */ - float GetFloatUniformValue( const std::string& uniformName ) + float GetFloatUniformValue(const std::string& uniformName) { float value; mEffect.GetProperty(mEffect.GetPropertyIndex(uniformName)).Get(value); @@ -521,9 +518,9 @@ private: /** * Terminate the given animation */ - void DestroyAnimation( Animation& animation ) + void DestroyAnimation(Animation& animation) { - if( animation ) + if(animation) { animation.Clear(); animation.Reset(); @@ -531,30 +528,29 @@ private: } private: - - Application& mApplication; - Shader mEffect; - ImageView mCircleBackground; - Actor mMeshActor; + Application& mApplication; + Shader mEffect; + ImageView mCircleBackground; + Actor mMeshActor; PanGestureDetector mPanGestureDetector; TapGestureDetector mTapDetector; - Animation mFadeAnimation; - Animation mTapAnimation; - Animation mTapAnimationAux; + Animation mFadeAnimation; + Animation mTapAnimation; + Animation mTapAnimationAux; - Vector2 mTapIndices; - unsigned int mAnimationIndex; - bool mShaking; + Vector2 mTapIndices; + unsigned int mAnimationIndex; + bool mShaking; - std::map< Animation, int > mTapAnimationIndexPair; + std::map mTapAnimationIndexPair; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - SparkleEffectExample theApp( application ); + Application application = Application::New(&argc, &argv); + SparkleEffectExample theApp(application); application.MainLoop(); return 0; } diff --git a/examples/sparkle/sparkle-effect.h b/examples/sparkle/sparkle-effect.h index f37e1e6..5cc6827 100644 --- a/examples/sparkle/sparkle-effect.h +++ b/examples/sparkle/sparkle-effect.h @@ -2,7 +2,7 @@ #define DALI_SPARKLE_EFFECT_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,8 @@ * */ -#include #include +#include using namespace Dali; using Dali::Toolkit::ImageView; @@ -30,207 +30,207 @@ using Dali::Toolkit::ImageView; namespace SparkleEffect { - // uniform which controls the position of particle on the path - const std::string PERCENTAGE_UNIFORM_NAME( "uPercentage" ); - // uniform array of particle color, set their value as the PARTICLE_COLORS given below - const std::string PARTICLE_COLOR_UNIFORM_NAME("uParticleColors["); - // uniform array of particle opacity - const std::string OPACITY_UNIFORM_NAME("uOpacity["); - // uniform which offsets the path control point, with this values >=0, the paths are squeezed towards the GatheringPoint - const std::string ACCELARATION_UNIFORM_NAME("uAcceleration"); - // uniform which indicates the ongoing tap animations - const std::string TAP_INDICES_UNIFORM_NAME("uTapIndices"); - // uniform which controls how much the offset of the midpoints relative to the start/end points of the cubic bezier curve when the path is squeezed for tap animation - const std::string TAP_OFFSET_UNIFORM_NAME("uTapOffset["); - // uniform which gives the position of the tapping, in this way the particles will be pushed away from this point - const std::string TAP_POINT_UNIFORM_NAME("uTapPoint["); - // uniform which trigger the break animation, set to 1.0 when break animation is playing, otherwise set to 0.0 - const std::string BREAK_UNIFORM_NAME("uBreak"); +// uniform which controls the position of particle on the path +const std::string PERCENTAGE_UNIFORM_NAME("uPercentage"); +// uniform array of particle color, set their value as the PARTICLE_COLORS given below +const std::string PARTICLE_COLOR_UNIFORM_NAME("uParticleColors["); +// uniform array of particle opacity +const std::string OPACITY_UNIFORM_NAME("uOpacity["); +// uniform which offsets the path control point, with this values >=0, the paths are squeezed towards the GatheringPoint +const std::string ACCELARATION_UNIFORM_NAME("uAcceleration"); +// uniform which indicates the ongoing tap animations +const std::string TAP_INDICES_UNIFORM_NAME("uTapIndices"); +// uniform which controls how much the offset of the midpoints relative to the start/end points of the cubic bezier curve when the path is squeezed for tap animation +const std::string TAP_OFFSET_UNIFORM_NAME("uTapOffset["); +// uniform which gives the position of the tapping, in this way the particles will be pushed away from this point +const std::string TAP_POINT_UNIFORM_NAME("uTapPoint["); +// uniform which trigger the break animation, set to 1.0 when break animation is playing, otherwise set to 0.0 +const std::string BREAK_UNIFORM_NAME("uBreak"); - /****************particle colors******************/ +/****************particle colors******************/ - struct ParticleColor - { - Vector3 RGB; - Vector2 AlphaRange; - unsigned int numParticle; - }; +struct ParticleColor +{ + Vector3 RGB; + Vector2 AlphaRange; + unsigned int numParticle; +}; - ParticleColor PARTICLE_COLORS[]= +ParticleColor PARTICLE_COLORS[] = { - { Vector3( 0.f, 240.f, 255.f )/255.f, Vector2( 0.2f, 1.f ), 22 }, // 00f0ff, opacity 20%~100% - { Vector3( 89.f, 151.f, 239.f )/255.f, Vector2( 0.2f, 0.5f ), 12 }, // 5997ef, opacity 20%~50% - { Vector3( 181.f, 181.f, 207.f )/255.f, Vector2( 0.5f, 1.f ), 22 }, // b5b5cf, opacity 50%~100% - { Vector3( 147.f, 147.f, 170.f )/255.f, Vector2( 0.5f, 0.5f ), 22 }, // 9393aa, opacity 50%~50% - { Vector3( 145.f, 145.f, 201.f )/255.f, Vector2( 1.f, 1.f ), 12 }, // 91bdc9, opacity 100%~100% - { Vector3( 145.f, 145.f, 201.f )/255.f, Vector2( 0.2f, 0.2f ), 21 } // 91bdc9, opacity 20%~20% - }; - const unsigned int NUM_COLOR( sizeof( PARTICLE_COLORS ) / sizeof( PARTICLE_COLORS[0] ) ); + {Vector3(0.f, 240.f, 255.f) / 255.f, Vector2(0.2f, 1.f), 22}, // 00f0ff, opacity 20%~100% + {Vector3(89.f, 151.f, 239.f) / 255.f, Vector2(0.2f, 0.5f), 12}, // 5997ef, opacity 20%~50% + {Vector3(181.f, 181.f, 207.f) / 255.f, Vector2(0.5f, 1.f), 22}, // b5b5cf, opacity 50%~100% + {Vector3(147.f, 147.f, 170.f) / 255.f, Vector2(0.5f, 0.5f), 22}, // 9393aa, opacity 50%~50% + {Vector3(145.f, 145.f, 201.f) / 255.f, Vector2(1.f, 1.f), 12}, // 91bdc9, opacity 100%~100% + {Vector3(145.f, 145.f, 201.f) / 255.f, Vector2(0.2f, 0.2f), 21} // 91bdc9, opacity 20%~20% +}; +const unsigned int NUM_COLOR(sizeof(PARTICLE_COLORS) / sizeof(PARTICLE_COLORS[0])); - /***************particle moving paths********************/ +/***************particle moving paths********************/ - typedef int MovingPath[12]; +typedef int MovingPath[12]; - // these paths are defined inside the circle which has the center at (250, 250) and the radius as 250 - MovingPath PATHS[]= +// these paths are defined inside the circle which has the center at (250, 250) and the radius as 250 +MovingPath PATHS[] = { // each path is composed of two cubic b-curves: (p0, p1, p2, p3) & (p3, p4, p5, p0) // p0 p1 p2 p3 p4 p5 - { 280,273, 386,41, 489,141, 491,199, 494,256, 230,394 }, - { 129,226, 357,120, 150,491, 291,406, 433,320, 47,283 }, - { 96,264, 356,133, 446,196, 370,297, 294,399, -169,384 }, - { 345,110, 359,186, 14,393, 4,247, -6,101, 321,-28 }, - { 166,161, 128,353, 566,200, 487,304, 413,403, 203,-32 }, - { 193,286, 106,331, 206,569, 334,477, 462,385, 279,240 }, - { 336,247, 293,232, 301,465, 346,479, 390,493, 374,261 }, - { 250,72, 314,72, 332,495, 250,497, 168,499, 161,72 }, - { 48,387, 32,241, 452,558, 433,358, 411,121, 62,523 }, - { 300,32, 159,27, 442,568, 186,492, -70,415, 551,41 }, - { 479,150, 503,203, 216,403, 163,298, 110,193, 448,78 }, - { 346,75, 311,97, 336,196, 389,160, 442,123, 383,51 }, - { 90,61, 54,96, 218,373, 294,300, 370,227, 141,11 }, - { 126,225, 240,280, 378,29, 221,16, 64,4, 11,170 }, - { 308,101, 243,22, -10,271, 22,352, 49,422, 396,208 }, - { 193,188, 174,302, 502,389, 500,250, 498,111, 212,72 }, - { 227,3, 16,35, 577,309, 428,423, 279,537, 438,-28 }, - { 410,58, 387,18, 22,179, 154,277, 286,374, 459,142 }, - { 178,272, 109,299, 144,429, 218,396, 293,362, 221,254 }, - { 247,46, 98,5, -91,357, 160,431, 412,505, 397,88 }, - { 41,112, 22,144, 123,273, 158,187, 192,101, 75,56 }, - { 8,300, 23,340, 267,294, 238,218, 209,142, -20,226 }, - { 112,256, 24,270, -1,470, 154,433, 308,396, 201,242 }, - { 212,277, 267,346, 509,202, 452,103, 398,8, 150,199 }, - { 154,205, 146,287, 496,282, 492,194, 488,107, 160,140 }, - { 281,350, 365,318, 415,476, 332,482, 248,489, 204,379 }, - { 327,23, 346,81, 154,319, 123,207, 92,95, 313,-21 }, - { 323,233, 283,307, 454,420, 478,354, 501,288, 374,136 }, - { 318,186, 311,252, 488,248, 481,168, 474,87, 328,76 }, - { 7,192, -10,270, 249,398, 269,307, 290,216, 25,111 }, - { 148,22, 98,22, 25,458, 125,458, 225,458, 198,22 }, - { 349,32, 307,39, 492,416, 399,446, 305,477, 460,16 }, - { 147,474, 222,554, 392,154, 486,240, 581,325, 73,394 }, - { 57,186, 13,200, 51,398, 114,374, 178,349, 97,174 }, - { 257,192, 198,188, 162,345, 240,349, 319,354, 316,197 }, - { 242,4, 283,21, 30,172, 81,215, 133,257, 209,-10 }, - { 149,408, 165,442, 472,340, 444,275, 416,210, 120,348 }, - { 106,271, 136,359, 483,370, 422,186, 360,2, 76,186 }, - { 120,146, 29,224, 469,262, 346,390, 222,518, 393,-87 }, - { 318,265, 415,280, 398,537, 247,491, 96,446, 222,249 }, - { 171,275, 207,246, 274,469, 237,497, 199,525, 139,300 }, - { 196,84, 135,105, 256,510, 334,486, 412,462, 280,55 }, - { 485,314, 452,170, 158,606, 111,411, 55,179, 515,446 }, - { 134,54, 266,4, 175,607, 392,451, 609,296, -100,144 }, - { 3,229, -1,287, 334,383, 350,267, 366,150, 10,151 }, - { 105,115, 146,125, 154,227, 92,209, 30,192, 62,105 }, - { 343,20, 388,42, 323,357, 228,313, 132,269, 278,-10 }, - { 362,186, 271,274, 60,82, 204,19, 349,-44, 453,97 }, - { 145,128, 181,32, 501,185, 498,272, 495,347, 97,257 }, - { 286,172, 342,274, 59,463, 16,331, -27,198, 231,69 }, - { 194,7, 404,-32, -38,410, 140,469, 317,528, -16,45 }, - { 39,120, 48,74, 445,109, 352,244, 259,379, 20,215 }, - { 328,247, 402,250, 411,384, 330,377, 248,370, 281,244 }, - { 189,56, 317,-31, 610,240, 396,392, 183,543, 61,144 }, - { 402,53, 430,77, 376,231, 315,161, 255,91, 351,10 }, - { 496,218, 494,260, 249,296, 251,214, 254,133, 498,139 }, - { 381,210, 469,195, 557,376, 399,391, 241,407, 292,226 }, - { 297,263, 267,346, -8,289, 14,176, 35,69, 331,168 }, - { 329,187, 363,263, 30,371, 5,287, -19,203, 302,128 }, - { 257,354, 168,351, 171,516, 252,496, 333,475, 340,356 }, - { 106,60, 107,121, 366,284, 359,168, 352,52, 105,14 }, - { 178,257, 240,314, 115,476, 71,421, 28,367, 98,182 }, - { 163,213, 191,273, 22,327, 3,248, -17,170, 118,113 }, - { 459,117, 500,185, 297,390, 248,311, 199,232, 416,46 }, - { 270,3, 317,-14, 528,375, 434,407, 339,440, 223,19 }, - { 88,76, 130,68, 78,485, 176,483, 274,482, -22,96 }, - { 422,428, 378,528, 88,205, 26,317, -36,428, 467,328 }, - { 414,127, 460,125, 489,325, 421,322, 353,320, 372,128 }, - { 227,197, 281,174, 367,311, 294,340, 221,370, 173,220 }, - { 180,14, 147,44, 436,104, 401,161, 366,219, 207,-10 }, - { 400,367, 395,404, 71,406, 77,336, 82,265, 407,300 }, - { 396,222, 396,316, 71,439, 70,245, 68,51, 396,132 }, - { 342,109, 454,153, 49,332, 208,413, 367,494, 8,-23 }, - { 147,167, 222,137, 266,169, 231,199, 197,229, 129,178 }, - { 227,272, 310,243, 277,313, 322,266, 367,219, 207,313 }, - { 279,192, 339,233, 396,211, 367,182, 338,152, 228,194 }, - { 236,20, 283,75, 346,26, 338,71, 330,116, 207,17 }, - { 129,83, 164,23, 158,14, 179,11, 200,8, 91,78 }, - { 86,231, 129,293, 164,421, 104,348, 44,275, 66,200 }, - { 193,328, 197,278, 240,348, 276,305, 311,263, 199,354 }, - { 231,364, 241,209, 309,104, 326,236, 342,367, 225,424 }, - { 414,230, 398,328, 446,445, 467,363, 489,281, 373,254 }, - { 289,122, 332,123, 348,161, 322,158, 297,156, 275,125 }, - { 142,235, 199,308, 402,229, 283,218, 164,206, 130,206 }, - { 174,396, 210,387, 328,501, 246,455, 165,409, 138,394 }, - { 288,388, 366,357, 372,458, 393,400, 414,343, 249,431 }, - { 351,278, 409,369, 497,316, 437,288, 376,260, 351,243 }, - { 87,134, 181,77, 311,121, 206,140, 101,160, 61,159 }, - { 95,195, 126,208, 133,258, 110,236, 88,215, 95,195 }, - { 140,293, 158,330, 169,275, 184,299, 198,323, 126,313 }, - { 336,319, 383,357, 388,278, 393,333, 397,388, 311,325 }, - { 338,107, 434,209, -37,469, 151,287, 338,104, 285,50 }, - { 403,134, 446,182, 378,318, 386,233, 393,149, 360,98 }, - { 366,82, 413,93, 416,158, 390,118, 364,78, 336,75 }, - { 448,188, 448,230, 465,269, 470,225, 474,181, 448,177 }, - { 121,398, 142,418, 126,475, 111,436, 96,396, 100,382 }, - { 40,296, 90,352, 170,310, 143,350, 116,391, 7,300 }, - { 25,203, 45,241, 70,204, 45,248, 19,293, 4,204 }, - { 243,222, 225,275, 345,256, 296,237, 247,218, 249,199 }, - { 159,149, 282,133, 284,199, 226,191, 169,184, 147,160 }, - { 149,257, 290,322, 151,374, 166,338, 182,302, 116,263 }, - { 255,285, 354,327, 234,287, 279,327, 323,367, 193,290 }, - { 188,220, 353,190, 290,354, 348,293, 407,231, 152,248 }, - { 305,122, 382,174, 402,229, 366,198, 329,167, 297,127 }, - { 378,260, 406,267, 390,330, 384,293, 377,257, 366,263 }, - { 178,396, 357,365, 273,461, 248,431, 223,401, 157,412 }, - { 180,89, 258,88, 302,94, 255,115, 207,136, 166,96 }, - { 81,197, 139,232, 39,257, 94,259, 150,261, 58,200 }, - { 314,89, 378,40, 383,38, 389,42, 395,45, 267,90 }, - { 371,141, 482,233, 508,244, 498,272, 488,299, 307,157 }, - { 339,348, 361,465, 382,477, 406,442, 430,406, 269,369 } - }; - const unsigned int NUM_PARTICLE( sizeof( PATHS ) / sizeof( PATHS[0] ) ); + {280, 273, 386, 41, 489, 141, 491, 199, 494, 256, 230, 394}, + {129, 226, 357, 120, 150, 491, 291, 406, 433, 320, 47, 283}, + {96, 264, 356, 133, 446, 196, 370, 297, 294, 399, -169, 384}, + {345, 110, 359, 186, 14, 393, 4, 247, -6, 101, 321, -28}, + {166, 161, 128, 353, 566, 200, 487, 304, 413, 403, 203, -32}, + {193, 286, 106, 331, 206, 569, 334, 477, 462, 385, 279, 240}, + {336, 247, 293, 232, 301, 465, 346, 479, 390, 493, 374, 261}, + {250, 72, 314, 72, 332, 495, 250, 497, 168, 499, 161, 72}, + {48, 387, 32, 241, 452, 558, 433, 358, 411, 121, 62, 523}, + {300, 32, 159, 27, 442, 568, 186, 492, -70, 415, 551, 41}, + {479, 150, 503, 203, 216, 403, 163, 298, 110, 193, 448, 78}, + {346, 75, 311, 97, 336, 196, 389, 160, 442, 123, 383, 51}, + {90, 61, 54, 96, 218, 373, 294, 300, 370, 227, 141, 11}, + {126, 225, 240, 280, 378, 29, 221, 16, 64, 4, 11, 170}, + {308, 101, 243, 22, -10, 271, 22, 352, 49, 422, 396, 208}, + {193, 188, 174, 302, 502, 389, 500, 250, 498, 111, 212, 72}, + {227, 3, 16, 35, 577, 309, 428, 423, 279, 537, 438, -28}, + {410, 58, 387, 18, 22, 179, 154, 277, 286, 374, 459, 142}, + {178, 272, 109, 299, 144, 429, 218, 396, 293, 362, 221, 254}, + {247, 46, 98, 5, -91, 357, 160, 431, 412, 505, 397, 88}, + {41, 112, 22, 144, 123, 273, 158, 187, 192, 101, 75, 56}, + {8, 300, 23, 340, 267, 294, 238, 218, 209, 142, -20, 226}, + {112, 256, 24, 270, -1, 470, 154, 433, 308, 396, 201, 242}, + {212, 277, 267, 346, 509, 202, 452, 103, 398, 8, 150, 199}, + {154, 205, 146, 287, 496, 282, 492, 194, 488, 107, 160, 140}, + {281, 350, 365, 318, 415, 476, 332, 482, 248, 489, 204, 379}, + {327, 23, 346, 81, 154, 319, 123, 207, 92, 95, 313, -21}, + {323, 233, 283, 307, 454, 420, 478, 354, 501, 288, 374, 136}, + {318, 186, 311, 252, 488, 248, 481, 168, 474, 87, 328, 76}, + {7, 192, -10, 270, 249, 398, 269, 307, 290, 216, 25, 111}, + {148, 22, 98, 22, 25, 458, 125, 458, 225, 458, 198, 22}, + {349, 32, 307, 39, 492, 416, 399, 446, 305, 477, 460, 16}, + {147, 474, 222, 554, 392, 154, 486, 240, 581, 325, 73, 394}, + {57, 186, 13, 200, 51, 398, 114, 374, 178, 349, 97, 174}, + {257, 192, 198, 188, 162, 345, 240, 349, 319, 354, 316, 197}, + {242, 4, 283, 21, 30, 172, 81, 215, 133, 257, 209, -10}, + {149, 408, 165, 442, 472, 340, 444, 275, 416, 210, 120, 348}, + {106, 271, 136, 359, 483, 370, 422, 186, 360, 2, 76, 186}, + {120, 146, 29, 224, 469, 262, 346, 390, 222, 518, 393, -87}, + {318, 265, 415, 280, 398, 537, 247, 491, 96, 446, 222, 249}, + {171, 275, 207, 246, 274, 469, 237, 497, 199, 525, 139, 300}, + {196, 84, 135, 105, 256, 510, 334, 486, 412, 462, 280, 55}, + {485, 314, 452, 170, 158, 606, 111, 411, 55, 179, 515, 446}, + {134, 54, 266, 4, 175, 607, 392, 451, 609, 296, -100, 144}, + {3, 229, -1, 287, 334, 383, 350, 267, 366, 150, 10, 151}, + {105, 115, 146, 125, 154, 227, 92, 209, 30, 192, 62, 105}, + {343, 20, 388, 42, 323, 357, 228, 313, 132, 269, 278, -10}, + {362, 186, 271, 274, 60, 82, 204, 19, 349, -44, 453, 97}, + {145, 128, 181, 32, 501, 185, 498, 272, 495, 347, 97, 257}, + {286, 172, 342, 274, 59, 463, 16, 331, -27, 198, 231, 69}, + {194, 7, 404, -32, -38, 410, 140, 469, 317, 528, -16, 45}, + {39, 120, 48, 74, 445, 109, 352, 244, 259, 379, 20, 215}, + {328, 247, 402, 250, 411, 384, 330, 377, 248, 370, 281, 244}, + {189, 56, 317, -31, 610, 240, 396, 392, 183, 543, 61, 144}, + {402, 53, 430, 77, 376, 231, 315, 161, 255, 91, 351, 10}, + {496, 218, 494, 260, 249, 296, 251, 214, 254, 133, 498, 139}, + {381, 210, 469, 195, 557, 376, 399, 391, 241, 407, 292, 226}, + {297, 263, 267, 346, -8, 289, 14, 176, 35, 69, 331, 168}, + {329, 187, 363, 263, 30, 371, 5, 287, -19, 203, 302, 128}, + {257, 354, 168, 351, 171, 516, 252, 496, 333, 475, 340, 356}, + {106, 60, 107, 121, 366, 284, 359, 168, 352, 52, 105, 14}, + {178, 257, 240, 314, 115, 476, 71, 421, 28, 367, 98, 182}, + {163, 213, 191, 273, 22, 327, 3, 248, -17, 170, 118, 113}, + {459, 117, 500, 185, 297, 390, 248, 311, 199, 232, 416, 46}, + {270, 3, 317, -14, 528, 375, 434, 407, 339, 440, 223, 19}, + {88, 76, 130, 68, 78, 485, 176, 483, 274, 482, -22, 96}, + {422, 428, 378, 528, 88, 205, 26, 317, -36, 428, 467, 328}, + {414, 127, 460, 125, 489, 325, 421, 322, 353, 320, 372, 128}, + {227, 197, 281, 174, 367, 311, 294, 340, 221, 370, 173, 220}, + {180, 14, 147, 44, 436, 104, 401, 161, 366, 219, 207, -10}, + {400, 367, 395, 404, 71, 406, 77, 336, 82, 265, 407, 300}, + {396, 222, 396, 316, 71, 439, 70, 245, 68, 51, 396, 132}, + {342, 109, 454, 153, 49, 332, 208, 413, 367, 494, 8, -23}, + {147, 167, 222, 137, 266, 169, 231, 199, 197, 229, 129, 178}, + {227, 272, 310, 243, 277, 313, 322, 266, 367, 219, 207, 313}, + {279, 192, 339, 233, 396, 211, 367, 182, 338, 152, 228, 194}, + {236, 20, 283, 75, 346, 26, 338, 71, 330, 116, 207, 17}, + {129, 83, 164, 23, 158, 14, 179, 11, 200, 8, 91, 78}, + {86, 231, 129, 293, 164, 421, 104, 348, 44, 275, 66, 200}, + {193, 328, 197, 278, 240, 348, 276, 305, 311, 263, 199, 354}, + {231, 364, 241, 209, 309, 104, 326, 236, 342, 367, 225, 424}, + {414, 230, 398, 328, 446, 445, 467, 363, 489, 281, 373, 254}, + {289, 122, 332, 123, 348, 161, 322, 158, 297, 156, 275, 125}, + {142, 235, 199, 308, 402, 229, 283, 218, 164, 206, 130, 206}, + {174, 396, 210, 387, 328, 501, 246, 455, 165, 409, 138, 394}, + {288, 388, 366, 357, 372, 458, 393, 400, 414, 343, 249, 431}, + {351, 278, 409, 369, 497, 316, 437, 288, 376, 260, 351, 243}, + {87, 134, 181, 77, 311, 121, 206, 140, 101, 160, 61, 159}, + {95, 195, 126, 208, 133, 258, 110, 236, 88, 215, 95, 195}, + {140, 293, 158, 330, 169, 275, 184, 299, 198, 323, 126, 313}, + {336, 319, 383, 357, 388, 278, 393, 333, 397, 388, 311, 325}, + {338, 107, 434, 209, -37, 469, 151, 287, 338, 104, 285, 50}, + {403, 134, 446, 182, 378, 318, 386, 233, 393, 149, 360, 98}, + {366, 82, 413, 93, 416, 158, 390, 118, 364, 78, 336, 75}, + {448, 188, 448, 230, 465, 269, 470, 225, 474, 181, 448, 177}, + {121, 398, 142, 418, 126, 475, 111, 436, 96, 396, 100, 382}, + {40, 296, 90, 352, 170, 310, 143, 350, 116, 391, 7, 300}, + {25, 203, 45, 241, 70, 204, 45, 248, 19, 293, 4, 204}, + {243, 222, 225, 275, 345, 256, 296, 237, 247, 218, 249, 199}, + {159, 149, 282, 133, 284, 199, 226, 191, 169, 184, 147, 160}, + {149, 257, 290, 322, 151, 374, 166, 338, 182, 302, 116, 263}, + {255, 285, 354, 327, 234, 287, 279, 327, 323, 367, 193, 290}, + {188, 220, 353, 190, 290, 354, 348, 293, 407, 231, 152, 248}, + {305, 122, 382, 174, 402, 229, 366, 198, 329, 167, 297, 127}, + {378, 260, 406, 267, 390, 330, 384, 293, 377, 257, 366, 263}, + {178, 396, 357, 365, 273, 461, 248, 431, 223, 401, 157, 412}, + {180, 89, 258, 88, 302, 94, 255, 115, 207, 136, 166, 96}, + {81, 197, 139, 232, 39, 257, 94, 259, 150, 261, 58, 200}, + {314, 89, 378, 40, 383, 38, 389, 42, 395, 45, 267, 90}, + {371, 141, 482, 233, 508, 244, 498, 272, 488, 299, 307, 157}, + {339, 348, 361, 465, 382, 477, 406, 442, 430, 406, 269, 369}}; +const unsigned int NUM_PARTICLE(sizeof(PATHS) / sizeof(PATHS[0])); - const float PARTICLE_SIZE = 13.f; +const float PARTICLE_SIZE = 13.f; - const float ACTOR_SCALE = 0.704f; // resize 500*500 to 352*352, a bit smaller than 360*360 - const Vector3 ACTOR_POSITION( -176.f, -176.f, 1.f); +const float ACTOR_SCALE = 0.704f; // resize 500*500 to 352*352, a bit smaller than 360*360 +const Vector3 ACTOR_POSITION(-176.f, -176.f, 1.f); - const int MAXIMUM_ANIMATION_COUNT = 30; +const int MAXIMUM_ANIMATION_COUNT = 30; - // Geometry format used by the SparkeEffect - struct Vertex +// Geometry format used by the SparkeEffect +struct Vertex +{ + Vertex(const Vector2& texCoord, + const Vector2& aParticlePath0, + const Vector2& aParticlePath1, + const Vector2& aParticlePath2, + const Vector2& aParticlePath3, + const Vector2& aParticlePath4, + const Vector2& aParticlePath5) + : aTexCoord(texCoord), + aParticlePath0(aParticlePath0), + aParticlePath1(aParticlePath1), + aParticlePath2(aParticlePath2), + aParticlePath3(aParticlePath3), + aParticlePath4(aParticlePath4), + aParticlePath5(aParticlePath5) { - Vertex( const Vector2& texCoord, - const Vector2& aParticlePath0, - const Vector2& aParticlePath1, - const Vector2& aParticlePath2, - const Vector2& aParticlePath3, - const Vector2& aParticlePath4, - const Vector2& aParticlePath5 ) - : aTexCoord( texCoord ), - aParticlePath0( aParticlePath0 ), - aParticlePath1( aParticlePath1 ), - aParticlePath2( aParticlePath2 ), - aParticlePath3( aParticlePath3 ), - aParticlePath4( aParticlePath4 ), - aParticlePath5( aParticlePath5 ) - { - } + } - Vector2 aTexCoord; - Vector2 aParticlePath0; - Vector2 aParticlePath1; - Vector2 aParticlePath2; - Vector2 aParticlePath3; - Vector2 aParticlePath4; - Vector2 aParticlePath5; - }; + Vector2 aTexCoord; + Vector2 aParticlePath0; + Vector2 aParticlePath1; + Vector2 aParticlePath2; + Vector2 aParticlePath3; + Vector2 aParticlePath4; + Vector2 aParticlePath5; +}; - /** +/** * Create a SparkleEffect object. * @return A handle to a newly allocated SparkleEffect */ - Shader New() - { +Shader New() +{ + // clang-format off std::string vertexShader = DALI_COMPOSE_SHADER( precision highp float;\n \n @@ -340,54 +340,55 @@ namespace SparkleEffect gl_FragColor.a *= texture2D(sTexture, vTexCoord).a;\n }\n ); + // clang-format on - std::ostringstream vertexShaderStringStream; - vertexShaderStringStream<< "#define NUM_COLOR "<< NUM_COLOR << "\n" - << "#define NUM_PARTICLE "<< NUM_PARTICLE << "\n" - << "#define PARTICLE_HALF_SIZE "<< PARTICLE_SIZE*ACTOR_SCALE/2.f << "\n" - << "#define MAXIMUM_ANIMATION_COUNT "< - using namespace Dali; // Needed for macros namespace Demo { namespace Internal { - namespace { +// clang-format off const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord;\n @@ -44,33 +43,33 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(mixColor,1.0) * uColor * vec4(uChannels, 1.0) ;\n }\n ); +// clang-format on Dali::BaseHandle Create() { return Demo::ImageChannelControl::New(); } -DALI_TYPE_REGISTRATION_BEGIN( ImageChannelControl, Dali::Toolkit::Control, Create ); +DALI_TYPE_REGISTRATION_BEGIN(ImageChannelControl, Dali::Toolkit::Control, Create); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "url", STRING, RESOURCE_URL ); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "redChannel", FLOAT, RED_CHANNEL ); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "greenChannel", FLOAT, GREEN_CHANNEL ); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "blueChannel", FLOAT, BLUE_CHANNEL ); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "url", STRING, RESOURCE_URL); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "redChannel", FLOAT, RED_CHANNEL); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "greenChannel", FLOAT, GREEN_CHANNEL); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "blueChannel", FLOAT, BLUE_CHANNEL); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "visibility", BOOLEAN, VISIBILITY ); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "enableVisibilityTransition", ARRAY, ENABLE_VISIBILITY_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "disableVisibilityTransition", ARRAY, DISABLE_VISIBILITY_TRANSITION ); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "visibility", BOOLEAN, VISIBILITY); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "enableVisibilityTransition", ARRAY, ENABLE_VISIBILITY_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "disableVisibilityTransition", ARRAY, DISABLE_VISIBILITY_TRANSITION); -DALI_PROPERTY_REGISTRATION( Demo, ImageChannelControl, "imageVisual", MAP, IMAGE_VISUAL ); +DALI_PROPERTY_REGISTRATION(Demo, ImageChannelControl, "imageVisual", MAP, IMAGE_VISUAL); DALI_TYPE_REGISTRATION_END(); } // anonymous namespace - Internal::ImageChannelControl::ImageChannelControl() -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), - mChannels( 1.0f, 1.0f, 1.0f ), - mChannelIndex( Property::INVALID_INDEX ), +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), + mChannels(1.0f, 1.0f, 1.0f), + mChannelIndex(Property::INVALID_INDEX), mVisibility(true), mTargetVisibility(true) { @@ -82,13 +81,13 @@ Internal::ImageChannelControl::~ImageChannelControl() Demo::ImageChannelControl Internal::ImageChannelControl::New() { - IntrusivePtr impl = new Internal::ImageChannelControl(); - Demo::ImageChannelControl handle = Demo::ImageChannelControl( *impl ); + IntrusivePtr impl = new Internal::ImageChannelControl(); + Demo::ImageChannelControl handle = Demo::ImageChannelControl(*impl); impl->Initialize(); return handle; } -void ImageChannelControl::SetImage( const std::string& url ) +void ImageChannelControl::SetImage(const std::string& url) { mUrl = url; @@ -97,49 +96,49 @@ void ImageChannelControl::SetImage( const std::string& url ) Property::Map properties; Property::Map shader; shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = FRAGMENT_SHADER; - properties[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE; - properties[Dali::Toolkit::Visual::Property::SHADER]=shader; - properties[Dali::Toolkit::ImageVisual::Property::URL] = url; + properties[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE; + properties[Dali::Toolkit::Visual::Property::SHADER] = shader; + properties[Dali::Toolkit::ImageVisual::Property::URL] = url; - mVisual = Toolkit::VisualFactory::Get().CreateVisual( properties ); - Toolkit::DevelControl::RegisterVisual( *this, Demo::ImageChannelControl::Property::IMAGE_VISUAL, mVisual ); + mVisual = Toolkit::VisualFactory::Get().CreateVisual(properties); + Toolkit::DevelControl::RegisterVisual(*this, Demo::ImageChannelControl::Property::IMAGE_VISUAL, mVisual); mVisual.SetName("imageVisual"); RelayoutRequest(); } -void ImageChannelControl::SetVisibility( bool visibility ) +void ImageChannelControl::SetVisibility(bool visibility) { - printf("ImageChannelControl %s: SetVisibility( %s )\n", Self().GetProperty< std::string >( Dali::Actor::Property::NAME ).c_str(), visibility?"T":"F" ); + printf("ImageChannelControl %s: SetVisibility( %s )\n", Self().GetProperty(Dali::Actor::Property::NAME).c_str(), visibility ? "T" : "F"); - if( mAnimation ) + if(mAnimation) { mAnimation.Stop(); - mAnimation.FinishedSignal().Disconnect( this, &ImageChannelControl::OnStateChangeAnimationFinished ); + mAnimation.FinishedSignal().Disconnect(this, &ImageChannelControl::OnStateChangeAnimationFinished); OnStateChangeAnimationFinished(mAnimation); } - if( mVisibility != visibility ) + if(mVisibility != visibility) { - if( mVisibility ) + if(mVisibility) { - if( mDisableVisibilityTransition.Count() > 0 ) + if(mDisableVisibilityTransition.Count() > 0) { - mAnimation = Toolkit::DevelControl::CreateTransition( *this, mDisableVisibilityTransition ); + mAnimation = Toolkit::DevelControl::CreateTransition(*this, mDisableVisibilityTransition); } } else { - if( mEnableVisibilityTransition.Count() > 0 ) + if(mEnableVisibilityTransition.Count() > 0) { - mAnimation = Toolkit::DevelControl::CreateTransition( *this, mEnableVisibilityTransition ); + mAnimation = Toolkit::DevelControl::CreateTransition(*this, mEnableVisibilityTransition); } } } - if( mAnimation ) + if(mAnimation) { - mAnimation.FinishedSignal().Connect( this, &ImageChannelControl::OnStateChangeAnimationFinished ); + mAnimation.FinishedSignal().Connect(this, &ImageChannelControl::OnStateChangeAnimationFinished); mAnimation.Play(); mTargetVisibility = visibility; } @@ -149,20 +148,20 @@ void ImageChannelControl::SetVisibility( bool visibility ) } } -void ImageChannelControl::OnStateChangeAnimationFinished( Animation& src ) +void ImageChannelControl::OnStateChangeAnimationFinished(Animation& src) { mVisibility = mTargetVisibility; } void ImageChannelControl::OnInitialize() { - Actor self = Self(); - mChannelIndex = self.RegisterProperty( "uChannels", Vector3(1.0f, 1.0f, 1.0f) ); + Actor self = Self(); + mChannelIndex = self.RegisterProperty("uChannels", Vector3(1.0f, 1.0f, 1.0f)); } -void ImageChannelControl::OnSceneConnection( int depth ) +void ImageChannelControl::OnSceneConnection(int depth) { - Control::OnSceneConnection( depth ); + Control::OnSceneConnection(depth); } void ImageChannelControl::OnSceneDisconnection() @@ -170,29 +169,29 @@ void ImageChannelControl::OnSceneDisconnection() Control::OnSceneDisconnection(); } -void ImageChannelControl::OnSizeSet( const Vector3& targetSize ) +void ImageChannelControl::OnSizeSet(const Vector3& targetSize) { - Control::OnSizeSet( targetSize ); + Control::OnSizeSet(targetSize); - if( mVisual ) + if(mVisual) { - Vector2 size( targetSize ); + Vector2 size(targetSize); Property::Map transformMap; transformMap - .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) ) - .Add( Toolkit::Visual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) ) - .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::CENTER ) - .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER ) - .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ) - .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) ); - - mVisual.SetTransformAndSize( transformMap, size ); + .Add(Toolkit::Visual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f)) + .Add(Toolkit::Visual::Transform::Property::SIZE, Vector2(1.0f, 1.0f)) + .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::CENTER) + .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER) + .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE)) + .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE)); + + mVisual.SetTransformAndSize(transformMap, size); } } Vector3 ImageChannelControl::GetNaturalSize() { - if( mVisual ) + if(mVisual) { Vector2 naturalSize; mVisual.GetNaturalSize(naturalSize); @@ -201,104 +200,103 @@ Vector3 ImageChannelControl::GetNaturalSize() return Vector3::ZERO; } -void ImageChannelControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) +void ImageChannelControl::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) { // Chain up. - Control::OnStyleChange( styleManager, change ); + Control::OnStyleChange(styleManager, change); } - /////////////////////////////////////////////////////////// // // Properties // -void ImageChannelControl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void ImageChannelControl::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value) { - Demo::ImageChannelControl imageChannelControl = Demo::ImageChannelControl::DownCast( Dali::BaseHandle( object ) ); + Demo::ImageChannelControl imageChannelControl = Demo::ImageChannelControl::DownCast(Dali::BaseHandle(object)); - if( imageChannelControl ) + if(imageChannelControl) { - ImageChannelControl& impl = GetImpl( imageChannelControl ); - Actor self = impl.Self(); - switch ( index ) + ImageChannelControl& impl = GetImpl(imageChannelControl); + Actor self = impl.Self(); + switch(index) { case Demo::ImageChannelControl::Property::RESOURCE_URL: { - impl.SetImage( value.Get() ); + impl.SetImage(value.Get()); break; } case Demo::ImageChannelControl::Property::IMAGE_VISUAL: { Property::Map* map = value.GetMap(); - if( map ) + if(map) { - impl.mVisual = Toolkit::VisualFactory::Get().CreateVisual( *map ); - Toolkit::DevelControl::RegisterVisual( impl, Demo::ImageChannelControl::Property::IMAGE_VISUAL, impl.mVisual ); + impl.mVisual = Toolkit::VisualFactory::Get().CreateVisual(*map); + Toolkit::DevelControl::RegisterVisual(impl, Demo::ImageChannelControl::Property::IMAGE_VISUAL, impl.mVisual); } break; } case Demo::ImageChannelControl::Property::VISIBILITY: { - impl.SetVisibility( value.Get() ); + impl.SetVisibility(value.Get()); break; } case Demo::ImageChannelControl::Property::ENABLE_VISIBILITY_TRANSITION: { - if( value.GetType() == Property::ARRAY ) + if(value.GetType() == Property::ARRAY) { - impl.mEnableVisibilityTransition = Toolkit::TransitionData::New( *value.GetArray()); + impl.mEnableVisibilityTransition = Toolkit::TransitionData::New(*value.GetArray()); } - else if( value.GetType() == Property::MAP ) + else if(value.GetType() == Property::MAP) { - impl.mEnableVisibilityTransition = Toolkit::TransitionData::New( *value.GetMap() ); + impl.mEnableVisibilityTransition = Toolkit::TransitionData::New(*value.GetMap()); } break; } case Demo::ImageChannelControl::Property::DISABLE_VISIBILITY_TRANSITION: { - if( value.GetType() == Property::ARRAY ) + if(value.GetType() == Property::ARRAY) { - impl.mDisableVisibilityTransition = Toolkit::TransitionData::New( *value.GetArray()); + impl.mDisableVisibilityTransition = Toolkit::TransitionData::New(*value.GetArray()); } - else if( value.GetType() == Property::MAP ) + else if(value.GetType() == Property::MAP) { - impl.mDisableVisibilityTransition = Toolkit::TransitionData::New( *value.GetMap() ); + impl.mDisableVisibilityTransition = Toolkit::TransitionData::New(*value.GetMap()); } break; } case Demo::ImageChannelControl::Property::RED_CHANNEL: { impl.mChannels[0] = value.Get(); - self.SetProperty( impl.mChannelIndex, impl.mChannels ); + self.SetProperty(impl.mChannelIndex, impl.mChannels); break; } case Demo::ImageChannelControl::Property::GREEN_CHANNEL: { impl.mChannels[1] = value.Get(); - self.SetProperty( impl.mChannelIndex, impl.mChannels ); + self.SetProperty(impl.mChannelIndex, impl.mChannels); break; } case Demo::ImageChannelControl::Property::BLUE_CHANNEL: { impl.mChannels[2] = value.Get(); - self.SetProperty( impl.mChannelIndex, impl.mChannels ); + self.SetProperty(impl.mChannelIndex, impl.mChannels); break; } } } } -Property::Value ImageChannelControl::GetProperty( BaseObject* object, Property::Index propertyIndex ) +Property::Value ImageChannelControl::GetProperty(BaseObject* object, Property::Index propertyIndex) { Property::Value value; - Demo::ImageChannelControl imageChannelControl = Demo::ImageChannelControl::DownCast( Dali::BaseHandle( object ) ); + Demo::ImageChannelControl imageChannelControl = Demo::ImageChannelControl::DownCast(Dali::BaseHandle(object)); - if ( imageChannelControl ) + if(imageChannelControl) { - ImageChannelControl& impl = GetImpl( imageChannelControl ); - switch ( propertyIndex ) + ImageChannelControl& impl = GetImpl(imageChannelControl); + switch(propertyIndex) { case Demo::ImageChannelControl::Property::RED_CHANNEL: { @@ -328,5 +326,5 @@ Property::Value ImageChannelControl::GetProperty( BaseObject* object, Property:: return value; } -} // Internal -} // Demo +} // namespace Internal +} // namespace Demo diff --git a/examples/styling/image-channel-control-impl.h b/examples/styling/image-channel-control-impl.h index a2edfee..09693df 100644 --- a/examples/styling/image-channel-control-impl.h +++ b/examples/styling/image-channel-control-impl.h @@ -17,18 +17,16 @@ * limitations under the License. */ -#include "image-channel-control.h" -#include -#include -#include #include +#include +#include +#include +#include "image-channel-control.h" namespace Demo { - namespace Internal // To use TypeRegistry, handle and body classes need the same name { - class ImageChannelControl : public Dali::Toolkit::Internal::Control { public: @@ -43,21 +41,21 @@ public: // API /** * @copydoc ImageChannelControl::SetImage */ - void SetImage( const std::string& url ); + void SetImage(const std::string& url); /** * @copydoc ImageChannelControl::SetVisibility */ - void SetVisibility( bool visibility ); + void SetVisibility(bool visibility); -public: // Properties +public: // Properties /** * Called when a property of an object of this type is set. * @param[in] object The object whose property is set. * @param[in] index The property index. * @param[in] value The new property value. */ - static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); + static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value); /** * Called to retrieve a property of an object of this type. @@ -65,7 +63,7 @@ public: // Properties * @param[in] index The property index. * @return The current value of the property. */ - static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex ); + static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex); private: // From Control /** @@ -76,7 +74,7 @@ private: // From Control /** * @copydoc Toolkit::Control::OnSceneConnection() */ - virtual void OnSceneConnection( int depth ); + virtual void OnSceneConnection(int depth); /** * @copydoc Toolkit::Control::OnSceneDisconnection() @@ -86,7 +84,7 @@ private: // From Control /** * @copydoc Toolkit::Control::OnSizeSet() */ - virtual void OnSizeSet( const Dali::Vector3& targetSize ); + virtual void OnSizeSet(const Dali::Vector3& targetSize); /** * @copydoc Toolkit::Control::GetNaturalSize @@ -96,45 +94,45 @@ private: // From Control /** * @copydoc Toolkit::Control::OnStyleChange */ - virtual void OnStyleChange( Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change ); + virtual void OnStyleChange(Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change); private: void OnStateChangeAnimationFinished(Dali::Animation& handle); private: //undefined - ImageChannelControl( const ImageChannelControl& ); - ImageChannelControl& operator=( const ImageChannelControl& ); + ImageChannelControl(const ImageChannelControl&); + ImageChannelControl& operator=(const ImageChannelControl&); private: // Implementation details - std::string mUrl; - Dali::Toolkit::Visual::Base mVisual; - Dali::Vector3 mChannels; + std::string mUrl; + Dali::Toolkit::Visual::Base mVisual; + Dali::Vector3 mChannels; Dali::Toolkit::TransitionData mEnableVisibilityTransition; Dali::Toolkit::TransitionData mDisableVisibilityTransition; - Dali::Animation mAnimation; - Dali::Property::Index mChannelIndex; - bool mVisibility:1; - bool mTargetVisibility:1; + Dali::Animation mAnimation; + Dali::Property::Index mChannelIndex; + bool mVisibility : 1; + bool mTargetVisibility : 1; }; -} // Internal +} // namespace Internal -inline Internal::ImageChannelControl& GetImpl( Demo::ImageChannelControl& handle ) +inline Internal::ImageChannelControl& GetImpl(Demo::ImageChannelControl& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -inline const Internal::ImageChannelControl& GetImpl( const Demo::ImageChannelControl& handle ) +inline const Internal::ImageChannelControl& GetImpl(const Demo::ImageChannelControl& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); const Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -} // Demo +} // namespace Demo #endif // DALI_DEMO_IMAGE_CHANNEL_CONTROL_IMPL_H diff --git a/examples/styling/image-channel-control.cpp b/examples/styling/image-channel-control.cpp index 45a0b29..c6254e3 100644 --- a/examples/styling/image-channel-control.cpp +++ b/examples/styling/image-channel-control.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,21 +19,20 @@ namespace Demo { - ImageChannelControl::ImageChannelControl() { } -ImageChannelControl::ImageChannelControl( const ImageChannelControl& imageChannelControl ) -: Control( imageChannelControl ) +ImageChannelControl::ImageChannelControl(const ImageChannelControl& imageChannelControl) +: Control(imageChannelControl) { } -ImageChannelControl& ImageChannelControl::operator= ( const ImageChannelControl& rhs ) +ImageChannelControl& ImageChannelControl::operator=(const ImageChannelControl& rhs) { - if( &rhs != this ) + if(&rhs != this) { - Control::operator=( rhs ); + Control::operator=(rhs); } return *this; } @@ -48,38 +47,37 @@ ImageChannelControl ImageChannelControl::New() return imageChannelControl; } -ImageChannelControl ImageChannelControl::New( const std::string& url ) +ImageChannelControl ImageChannelControl::New(const std::string& url) { ImageChannelControl imageChannelControl = Internal::ImageChannelControl::New(); - imageChannelControl.SetImage( url ); + imageChannelControl.SetImage(url); return imageChannelControl; } -ImageChannelControl ImageChannelControl::DownCast( BaseHandle handle ) +ImageChannelControl ImageChannelControl::DownCast(BaseHandle handle) { - return Control::DownCast< ImageChannelControl, Internal::ImageChannelControl > ( handle ); + return Control::DownCast(handle); } -void ImageChannelControl::SetImage( const std::string& url ) +void ImageChannelControl::SetImage(const std::string& url) { - GetImpl( *this ).SetImage( url ); + GetImpl(*this).SetImage(url); } -void ImageChannelControl::SetVisibility( bool visibility ) +void ImageChannelControl::SetVisibility(bool visibility) { - GetImpl( *this ).SetVisibility( visibility ); + GetImpl(*this).SetVisibility(visibility); } -ImageChannelControl::ImageChannelControl( Internal::ImageChannelControl& implementation ) -: Control( implementation ) +ImageChannelControl::ImageChannelControl(Internal::ImageChannelControl& implementation) +: Control(implementation) { } -ImageChannelControl::ImageChannelControl( Dali::Internal::CustomActor* internal ) -: Control( internal ) +ImageChannelControl::ImageChannelControl(Dali::Internal::CustomActor* internal) +: Control(internal) { - VerifyCustomActorPointer< Internal::ImageChannelControl >( internal ) ; + VerifyCustomActorPointer(internal); } - } //namespace Demo diff --git a/examples/styling/image-channel-control.h b/examples/styling/image-channel-control.h index e48c21d..cd153ed 100644 --- a/examples/styling/image-channel-control.h +++ b/examples/styling/image-channel-control.h @@ -2,7 +2,7 @@ #define DALI_DEMO_IMAGE_CHANNEL_CONTROL_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,11 @@ namespace Demo { - namespace Internal { // All type registered types need to have the same name for the body and the handle class ImageChannelControl; -} +} // namespace Internal /** * Control that allows the RGB channels of an image to be altered. @@ -40,10 +39,10 @@ public: */ enum PropertyRange { - PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, - PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, + PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ANIMATABLE_PROPERTY_START_INDEX = Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, - ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX+1000 + ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX + 1000 }; struct Property @@ -62,7 +61,6 @@ public: }; public: // Construction / destruction - /** * Create an uninitialized handle */ @@ -77,7 +75,7 @@ public: // Construction / destruction /** * Create a new image channel control from a given URL */ - static ImageChannelControl New( const std::string& url ); + static ImageChannelControl New(const std::string& url); /** * Destructor. This is non-virtual since derived Handle types must not @@ -88,41 +86,40 @@ public: // Construction / destruction /** * Copy Constructor */ - ImageChannelControl( const ImageChannelControl& imageChannelControl ); + ImageChannelControl(const ImageChannelControl& imageChannelControl); /** * Assignment Operator */ - ImageChannelControl& operator=( const ImageChannelControl& imageChannelControl ); + ImageChannelControl& operator=(const ImageChannelControl& imageChannelControl); /** * Downcast */ - static ImageChannelControl DownCast( BaseHandle handle ); + static ImageChannelControl DownCast(BaseHandle handle); public: // API - /** * Set the image for this ImageChannelControl * @param[in] url The url of the image resource */ - void SetImage( const std::string& url ); + void SetImage(const std::string& url); /** * Set the visibility of this control */ - void SetVisibility( bool visibility ); + void SetVisibility(bool visibility); public: // Not for public use /** * Create a handle from an implementation */ - ImageChannelControl( Internal::ImageChannelControl& implementation ); + ImageChannelControl(Internal::ImageChannelControl& implementation); /** * Allow the creation of an ImageChannelControl handle from an internal CustomActor pointer */ - ImageChannelControl( Dali::Internal::CustomActor* internal ); + ImageChannelControl(Dali::Internal::CustomActor* internal); }; } // namespace Demo diff --git a/examples/styling/style-example.cpp b/examples/styling/style-example.cpp index dfd2d11..e1a89ab 100644 --- a/examples/styling/style-example.cpp +++ b/examples/styling/style-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,27 +25,26 @@ // Internal includes #include "styling-application.h" - -int DALI_EXPORT_API main( int argc, char** argv ) +int DALI_EXPORT_API main(int argc, char** argv) { const char* themeName = Demo::StylingApplication::DEMO_THEME_ONE_PATH; - if( argc > 1 ) + if(argc > 1) { int theme = atoi(argv[1]); - if( theme == 2 ) + if(theme == 2) { themeName = Demo::StylingApplication::DEMO_THEME_TWO_PATH; } - else if( theme == 3 ) + else if(theme == 3) { themeName = Demo::StylingApplication::DEMO_THEME_THREE_PATH; } } - Application application = Application::New( &argc, &argv, themeName ); + Application application = Application::New(&argc, &argv, themeName); { - Demo::StylingApplication stylingApplication( application ); + Demo::StylingApplication stylingApplication(application); application.MainLoop(); } return 0; diff --git a/examples/styling/styling-application.cpp b/examples/styling/styling-application.cpp old mode 100755 new mode 100644 index 197d559..c2161d8 --- a/examples/styling/styling-application.cpp +++ b/examples/styling/styling-application.cpp @@ -23,13 +23,13 @@ #include "styling-application.h" // External includes -#include #include #include #include -#include "image-channel-control.h" +#include #include #include +#include "image-channel-control.h" // Internal includes @@ -38,26 +38,25 @@ using namespace Dali::Toolkit; namespace Demo { - -const char* StylingApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" ); -const char* StylingApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" ); -const char* StylingApplication::DEMO_THEME_THREE_PATH( DEMO_STYLE_DIR "style-example-theme-three.json" ); +const char* StylingApplication::DEMO_THEME_ONE_PATH(DEMO_STYLE_DIR "style-example-theme-one.json"); +const char* StylingApplication::DEMO_THEME_TWO_PATH(DEMO_STYLE_DIR "style-example-theme-two.json"); +const char* StylingApplication::DEMO_THEME_THREE_PATH(DEMO_STYLE_DIR "style-example-theme-three.json"); namespace { #define DP(x) x -const char* DEFAULT_CONTROL_AREA_IMAGE_PATH( DEMO_IMAGE_DIR "popup_button_background.9.png" ); +const char* DEFAULT_CONTROL_AREA_IMAGE_PATH(DEMO_IMAGE_DIR "popup_button_background.9.png"); -const char* POPUP_CONTROL_OK_NAME( "PopupControlOk" ); -const char* POPUP_CONTROL_CANCEL_NAME( "PopupControlCancel" ); -const char* BORDER_IMAGE( DEMO_IMAGE_DIR "border-4px.9.png" ); -const char* RESIZE_HANDLE_IMAGE( DEMO_IMAGE_DIR "resize-handle.png" ); +const char* POPUP_CONTROL_OK_NAME("PopupControlOk"); +const char* POPUP_CONTROL_CANCEL_NAME("PopupControlCancel"); +const char* BORDER_IMAGE(DEMO_IMAGE_DIR "border-4px.9.png"); +const char* RESIZE_HANDLE_IMAGE(DEMO_IMAGE_DIR "resize-handle.png"); const int NUMBER_OF_THEMES(3); // The default theme is considered. -const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f ); -const int BORDER_WIDTH( 4 ); +const Vector4 BACKGROUND_COLOUR(1.0f, 1.0f, 1.0f, 0.15f); +const int BORDER_WIDTH(4); const char* const SMALL_IMAGE_1 = DEMO_IMAGE_DIR "gallery-small-14.jpg"; const char* const BIG_IMAGE_1 = DEMO_IMAGE_DIR "gallery-large-4.jpg"; @@ -71,325 +70,339 @@ const char* const BIG_IMAGE_3 = DEMO_IMAGE_DIR "gallery-large-11.jpg"; // Layout const int MARGIN_SIZE = 10; -const int RADIO_LABEL_THUMBNAIL_SIZE = 60; +const int RADIO_LABEL_THUMBNAIL_SIZE = 60; const int RADIO_LABEL_THUMBNAIL_SIZE_SMALL = 40; -const int RADIO_IMAGE_SPACING = 8; -const int BUTTON_HEIGHT = 48; +const int RADIO_IMAGE_SPACING = 8; +const int BUTTON_HEIGHT = 48; -Property::Index GetChannelProperty( int index ) +Property::Index GetChannelProperty(int index) { Property::Index channelIndex = Property::INVALID_INDEX; switch(index) { - case 0: { channelIndex = ImageChannelControl::Property::RED_CHANNEL; break; } - case 1: { channelIndex = ImageChannelControl::Property::GREEN_CHANNEL; break; } - case 2: { channelIndex = ImageChannelControl::Property::BLUE_CHANNEL; break; } + case 0: + { + channelIndex = ImageChannelControl::Property::RED_CHANNEL; + break; + } + case 1: + { + channelIndex = ImageChannelControl::Property::GREEN_CHANNEL; + break; + } + case 2: + { + channelIndex = ImageChannelControl::Property::BLUE_CHANNEL; + break; + } } return channelIndex; } } // anonymous namespace - - -StylingApplication::StylingApplication( Application& application ) -: mApplication( application ), - mCurrentTheme( 0 ) +StylingApplication::StylingApplication(Application& application) +: mApplication(application), + mCurrentTheme(0) { - application.InitSignal().Connect( this, &StylingApplication::Create ); + application.InitSignal().Connect(this, &StylingApplication::Create); } StylingApplication::~StylingApplication() { } -void StylingApplication::Create( Application& application ) +void StylingApplication::Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &StylingApplication::OnKeyEvent); - window.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) ); + window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f)); mContentPane = CreateContentPane(); - window.Add( mContentPane ); - mContentPane.SetProperty( Actor::Property::SIZE, Vector2(window.GetSize()) ); + window.Add(mContentPane); + mContentPane.SetProperty(Actor::Property::SIZE, Vector2(window.GetSize())); // Content panes: - TableView contentLayout = TableView::New( 5, 1 ); - contentLayout.SetProperty( Dali::Actor::Property::NAME,"ContentLayout"); - contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - contentLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - contentLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); + TableView contentLayout = TableView::New(5, 1); + contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout"); + contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + contentLayout.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); // Assign all rows the size negotiation property of fitting to children - for( unsigned int i = 0; i < contentLayout.GetRows(); ++i ) + for(unsigned int i = 0; i < contentLayout.GetRows(); ++i) { - if( i != 1 ) + if(i != 1) { contentLayout.SetFitHeight(i); // Row 1 should fill } } - mContentPane.Add( contentLayout ); + mContentPane.Add(contentLayout); - mTitle = TextLabel::New( "Styling Example" ); - mTitle.SetProperty( Dali::Actor::Property::NAME, "Title" ); + mTitle = TextLabel::New("Styling Example"); + mTitle.SetProperty(Dali::Actor::Property::NAME, "Title"); mTitle.SetStyleName("Title"); - mTitle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mTitle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - contentLayout.Add( mTitle ); + mTitle.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mTitle.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mTitle.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mTitle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mTitle.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + contentLayout.Add(mTitle); // Buttons: - TableView imageSelectLayout = TableView::New( 1, 2 ); - imageSelectLayout.SetProperty( Dali::Actor::Property::NAME,"ImageSelectLayout"); + TableView imageSelectLayout = TableView::New(1, 2); + imageSelectLayout.SetProperty(Dali::Actor::Property::NAME, "ImageSelectLayout"); - imageSelectLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - imageSelectLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); - imageSelectLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - imageSelectLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - imageSelectLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); + imageSelectLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + imageSelectLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); + imageSelectLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + imageSelectLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + imageSelectLayout.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); // Fit radio button column to child width, leave image to fill remainder - imageSelectLayout.SetFitWidth( 0 ); + imageSelectLayout.SetFitWidth(0); - contentLayout.Add( imageSelectLayout ); + contentLayout.Add(imageSelectLayout); - TableView radioButtonsLayout = TableView::New( 3, 2 ); - radioButtonsLayout.SetProperty( Dali::Actor::Property::NAME,"RadioButtonsLayout"); - radioButtonsLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); + TableView radioButtonsLayout = TableView::New(3, 2); + radioButtonsLayout.SetProperty(Dali::Actor::Property::NAME, "RadioButtonsLayout"); + radioButtonsLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); // Leave each row to fill to parent height // Set each column to fit to child width radioButtonsLayout.SetFitWidth(0); radioButtonsLayout.SetFitWidth(1); - radioButtonsLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) ); + radioButtonsLayout.SetCellPadding(Vector2(6.0f, 0.0f)); - imageSelectLayout.AddChild( radioButtonsLayout, TableView::CellPosition(0, 0) ); - imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); + imageSelectLayout.AddChild(radioButtonsLayout, TableView::CellPosition(0, 0)); + imageSelectLayout.SetCellAlignment(TableView::CellPosition(0, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); - const char* images[] = { SMALL_IMAGE_1, SMALL_IMAGE_2, SMALL_IMAGE_3 }; + const char* images[] = {SMALL_IMAGE_1, SMALL_IMAGE_2, SMALL_IMAGE_3}; - for( int i=0; i<3; ++i ) + for(int i = 0; i < 3; ++i) { - std::ostringstream thumbnailName; thumbnailName << "thumbnail" << i+1; - ImageView image = ImageView::New( images[i] ); - image.SetProperty( Dali::Actor::Property::NAME, thumbnailName.str() ); - image.SetProperty( Actor::Property::SIZE, Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); - - std::ostringstream label; label << (i+1); + std::ostringstream thumbnailName; + thumbnailName << "thumbnail" << i + 1; + ImageView image = ImageView::New(images[i]); + image.SetProperty(Dali::Actor::Property::NAME, thumbnailName.str()); + image.SetProperty(Actor::Property::SIZE, Vector2(DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE))); + + std::ostringstream label; + label << (i + 1); std::ostringstream radioButtonStyleName; - radioButtonStyleName << "imageSelectButton" << i+1; - mRadioButtons[i] = RadioButton::New( label.str() ); - mRadioButtons[i].SetProperty( Dali::Actor::Property::NAME, radioButtonStyleName.str() ); - mRadioButtons[i].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mRadioButtons[i].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mRadioButtons[i].SetProperty( Button::Property::SELECTED, false ); - mRadioButtons[i].StateChangedSignal().Connect( this, &StylingApplication::OnButtonStateChange ); - - radioButtonsLayout.AddChild( mRadioButtons[i], TableView::CellPosition( i, 0 ) ); - radioButtonsLayout.AddChild( image, TableView::CellPosition( i, 1 ) ); - radioButtonsLayout.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - radioButtonsLayout.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + radioButtonStyleName << "imageSelectButton" << i + 1; + mRadioButtons[i] = RadioButton::New(label.str()); + mRadioButtons[i].SetProperty(Dali::Actor::Property::NAME, radioButtonStyleName.str()); + mRadioButtons[i].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mRadioButtons[i].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mRadioButtons[i].SetProperty(Button::Property::SELECTED, false); + mRadioButtons[i].StateChangedSignal().Connect(this, &StylingApplication::OnButtonStateChange); + + radioButtonsLayout.AddChild(mRadioButtons[i], TableView::CellPosition(i, 0)); + radioButtonsLayout.AddChild(image, TableView::CellPosition(i, 1)); + radioButtonsLayout.SetCellAlignment(TableView::CellPosition(i, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + radioButtonsLayout.SetCellAlignment(TableView::CellPosition(i, 1), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); } - mRadioButtons[0].SetProperty( Button::Property::SELECTED, true ); + mRadioButtons[0].SetProperty(Button::Property::SELECTED, true); mImagePlacement = Actor::New(); - mImagePlacement.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mImagePlacement.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mImagePlacement.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - imageSelectLayout.AddChild( mImagePlacement, TableView::CellPosition( 0, 1 ) ); - imageSelectLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER ); - - mIcc1 = ImageChannelControl::New( BIG_IMAGE_1 ); - mIcc1.SetProperty( Dali::Actor::Property::NAME,"ICC1"); - mIcc1.SetResizePolicy( ResizePolicy::FILL_TO_PARENT , Dimension::ALL_DIMENSIONS ); - mIcc1.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - mIcc1.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mIcc1.SetVisibility( true ); - - mImagePlacement.Add( mIcc1 ); - - mIcc2 = ImageChannelControl::New( BIG_IMAGE_2 ); - mIcc2.SetProperty( Dali::Actor::Property::NAME,"ICC2"); - mIcc2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT , Dimension::ALL_DIMENSIONS ); - mIcc2.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - mIcc2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mIcc2.SetVisibility( false ); - - mImagePlacement.Add( mIcc2 ); - - mIcc3 = ImageChannelControl::New( BIG_IMAGE_3 ); - mIcc3.SetProperty( Dali::Actor::Property::NAME,"ICC3"); - mIcc3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT , Dimension::ALL_DIMENSIONS ); - mIcc3.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); - mIcc3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mIcc3.SetVisibility( false ); - - mImagePlacement.Add( mIcc3 ); + mImagePlacement.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mImagePlacement.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mImagePlacement.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + imageSelectLayout.AddChild(mImagePlacement, TableView::CellPosition(0, 1)); + imageSelectLayout.SetCellAlignment(TableView::CellPosition(0, 1), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER); + + mIcc1 = ImageChannelControl::New(BIG_IMAGE_1); + mIcc1.SetProperty(Dali::Actor::Property::NAME, "ICC1"); + mIcc1.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mIcc1.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + mIcc1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mIcc1.SetVisibility(true); + + mImagePlacement.Add(mIcc1); + + mIcc2 = ImageChannelControl::New(BIG_IMAGE_2); + mIcc2.SetProperty(Dali::Actor::Property::NAME, "ICC2"); + mIcc2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mIcc2.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + mIcc2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mIcc2.SetVisibility(false); + + mImagePlacement.Add(mIcc2); + + mIcc3 = ImageChannelControl::New(BIG_IMAGE_3); + mIcc3.SetProperty(Dali::Actor::Property::NAME, "ICC3"); + mIcc3.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mIcc3.SetProperty(Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO); + mIcc3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mIcc3.SetVisibility(false); + + mImagePlacement.Add(mIcc3); mImageChannelControl = mIcc1; - TableView channelSliderLayout = TableView::New( 3, 3 ); - channelSliderLayout.SetProperty( Dali::Actor::Property::NAME,"ChannelSliderLayout"); + TableView channelSliderLayout = TableView::New(3, 3); + channelSliderLayout.SetProperty(Dali::Actor::Property::NAME, "ChannelSliderLayout"); // Contains a column of check buttons and a column of sliders for R/G/B - channelSliderLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - channelSliderLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - channelSliderLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - channelSliderLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - channelSliderLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); + channelSliderLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + channelSliderLayout.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + channelSliderLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + channelSliderLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + channelSliderLayout.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); // Set each row to fit to child height - channelSliderLayout.SetFitHeight( 0 ); - channelSliderLayout.SetFitHeight( 1 ); - channelSliderLayout.SetFitHeight( 2 ); + channelSliderLayout.SetFitHeight(0); + channelSliderLayout.SetFitHeight(1); + channelSliderLayout.SetFitHeight(2); // Set each column to fit to child width - channelSliderLayout.SetFitWidth( 0 ); - channelSliderLayout.SetFitWidth( 1 ); + channelSliderLayout.SetFitWidth(0); + channelSliderLayout.SetFitWidth(1); - contentLayout.Add( channelSliderLayout ); - const char *checkboxLabels[3] = {"R", "G", "B"}; + contentLayout.Add(channelSliderLayout); + const char* checkboxLabels[3] = {"R", "G", "B"}; - for( int i=0; i<3; ++i ) + for(int i = 0; i < 3; ++i) { std::ostringstream checkBoxStyleName; - checkBoxStyleName << "channelActiveCheckBox" << i+1; + checkBoxStyleName << "channelActiveCheckBox" << i + 1; mCheckButtons[i] = CheckBoxButton::New(); - mCheckButtons[i].SetProperty( Dali::Actor::Property::NAME, checkBoxStyleName.str() ); - mCheckButtons[i].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mCheckButtons[i].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mCheckButtons[i].SetProperty( Button::Property::SELECTED, true ); - - mCheckButtons[i].StateChangedSignal().Connect( this, &StylingApplication::OnCheckButtonChange ); - mCheckButtons[i].RegisterProperty( "channel", i, Property::READ_WRITE ); - - channelSliderLayout.AddChild( mCheckButtons[i], TableView::CellPosition( i, 0 ) ); - channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - - TextLabel label = TextLabel::New( checkboxLabels[i] ); - std::ostringstream labelStyleName; labelStyleName << "ColorLabel" << i+1; - label.SetProperty( Dali::Actor::Property::NAME, labelStyleName.str() ); - label.SetStyleName( labelStyleName.str() ); - label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); - label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - - channelSliderLayout.AddChild( label, TableView::CellPosition( i, 1 ) ); - channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + mCheckButtons[i].SetProperty(Dali::Actor::Property::NAME, checkBoxStyleName.str()); + mCheckButtons[i].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mCheckButtons[i].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mCheckButtons[i].SetProperty(Button::Property::SELECTED, true); + + mCheckButtons[i].StateChangedSignal().Connect(this, &StylingApplication::OnCheckButtonChange); + mCheckButtons[i].RegisterProperty("channel", i, Property::READ_WRITE); + + channelSliderLayout.AddChild(mCheckButtons[i], TableView::CellPosition(i, 0)); + channelSliderLayout.SetCellAlignment(TableView::CellPosition(i, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + + TextLabel label = TextLabel::New(checkboxLabels[i]); + std::ostringstream labelStyleName; + labelStyleName << "ColorLabel" << i + 1; + label.SetProperty(Dali::Actor::Property::NAME, labelStyleName.str()); + label.SetStyleName(labelStyleName.str()); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + label.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH); + label.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + + channelSliderLayout.AddChild(label, TableView::CellPosition(i, 1)); + channelSliderLayout.SetCellAlignment(TableView::CellPosition(i, 1), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); mChannelSliders[i] = Slider::New(); - std::ostringstream sliderStyleName; sliderStyleName << "ColorSlider" << i+1; - mChannelSliders[i].SetProperty( Dali::Actor::Property::NAME, sliderStyleName.str() ); - mChannelSliders[i].SetStyleName( sliderStyleName.str() ); - mChannelSliders[i].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mChannelSliders[i].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mChannelSliders[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mChannelSliders[i].SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN , Dimension::HEIGHT ); - mChannelSliders[i].SetProperty( Slider::Property::LOWER_BOUND, 0.0f ); - mChannelSliders[i].SetProperty( Slider::Property::UPPER_BOUND, 100.0f ); - mChannelSliders[i].SetProperty( Slider::Property::VALUE_PRECISION, 0 ); - mChannelSliders[i].SetProperty( Slider::Property::VALUE, 100.0f ); - mChannelSliders[i].SetProperty( Slider::Property::SHOW_POPUP, true ); - mChannelSliders[i].SetProperty( Slider::Property::SHOW_VALUE, true ); - - mChannelSliders[i].RegisterProperty( "channel", i, Property::READ_WRITE ); - - channelSliderLayout.AddChild( mChannelSliders[i], TableView::CellPosition( i, 2 ) ); - channelSliderLayout.SetCellAlignment( TableView::CellPosition( i, 2 ), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER ); - - mChannelSliders[i].ValueChangedSignal().Connect( this, &StylingApplication::OnSliderChanged ); + std::ostringstream sliderStyleName; + sliderStyleName << "ColorSlider" << i + 1; + mChannelSliders[i].SetProperty(Dali::Actor::Property::NAME, sliderStyleName.str()); + mChannelSliders[i].SetStyleName(sliderStyleName.str()); + mChannelSliders[i].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mChannelSliders[i].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mChannelSliders[i].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mChannelSliders[i].SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + mChannelSliders[i].SetProperty(Slider::Property::LOWER_BOUND, 0.0f); + mChannelSliders[i].SetProperty(Slider::Property::UPPER_BOUND, 100.0f); + mChannelSliders[i].SetProperty(Slider::Property::VALUE_PRECISION, 0); + mChannelSliders[i].SetProperty(Slider::Property::VALUE, 100.0f); + mChannelSliders[i].SetProperty(Slider::Property::SHOW_POPUP, true); + mChannelSliders[i].SetProperty(Slider::Property::SHOW_VALUE, true); + + mChannelSliders[i].RegisterProperty("channel", i, Property::READ_WRITE); + + channelSliderLayout.AddChild(mChannelSliders[i], TableView::CellPosition(i, 2)); + channelSliderLayout.SetCellAlignment(TableView::CellPosition(i, 2), HorizontalAlignment::RIGHT, VerticalAlignment::CENTER); + + mChannelSliders[i].ValueChangedSignal().Connect(this, &StylingApplication::OnSliderChanged); } mResetButton = PushButton::New(); - mResetButton.SetProperty( Toolkit::Button::Property::LABEL, "Reset" ); - mResetButton.SetProperty( Dali::Actor::Property::NAME,"ResetButton"); - mResetButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mResetButton.ClickedSignal().Connect( this, &StylingApplication::OnResetClicked ); - - contentLayout.Add( mResetButton ); - contentLayout.SetCellAlignment( TableView::CellPosition( 3, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - - TableView themeButtonLayout = TableView::New( 1, 4 ); - themeButtonLayout.SetProperty( Dali::Actor::Property::NAME,"ThemeButtonsLayout"); - themeButtonLayout.SetCellPadding( Vector2( 6.0f, 0.0f ) ); - - themeButtonLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - themeButtonLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - themeButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - themeButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); - themeButtonLayout.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) ); - themeButtonLayout.SetFitHeight( 0 ); - - TextLabel label = TextLabel::New( "Theme: "); - label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mResetButton.SetProperty(Toolkit::Button::Property::LABEL, "Reset"); + mResetButton.SetProperty(Dali::Actor::Property::NAME, "ResetButton"); + mResetButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mResetButton.ClickedSignal().Connect(this, &StylingApplication::OnResetClicked); + + contentLayout.Add(mResetButton); + contentLayout.SetCellAlignment(TableView::CellPosition(3, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + + TableView themeButtonLayout = TableView::New(1, 4); + themeButtonLayout.SetProperty(Dali::Actor::Property::NAME, "ThemeButtonsLayout"); + themeButtonLayout.SetCellPadding(Vector2(6.0f, 0.0f)); + + themeButtonLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + themeButtonLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + themeButtonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + themeButtonLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + themeButtonLayout.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE)); + themeButtonLayout.SetFitHeight(0); + + TextLabel label = TextLabel::New("Theme: "); + label.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); label.SetStyleName("ThemeLabel"); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - themeButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) ); - themeButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + themeButtonLayout.AddChild(label, TableView::CellPosition(0, 0)); + themeButtonLayout.SetCellAlignment(TableView::CellPosition(0, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); - for( int i=0; i<3; ++i ) + for(int i = 0; i < 3; ++i) { mThemeButtons[i] = PushButton::New(); - mThemeButtons[i].SetProperty( Dali::Actor::Property::NAME,"ThemeButton"); + mThemeButtons[i].SetProperty(Dali::Actor::Property::NAME, "ThemeButton"); mThemeButtons[i].SetStyleName("ThemeButton"); - mThemeButtons[i].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mThemeButtons[i].SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::CENTER ); - mThemeButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mThemeButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mThemeButtons[i].RegisterProperty( "theme", i, Property::READ_WRITE ); - mThemeButtons[i].ClickedSignal().Connect( this, &StylingApplication::OnThemeButtonClicked ); - themeButtonLayout.AddChild( mThemeButtons[i], TableView::CellPosition( 0, 1+i ) ); + mThemeButtons[i].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mThemeButtons[i].SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::CENTER); + mThemeButtons[i].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mThemeButtons[i].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mThemeButtons[i].RegisterProperty("theme", i, Property::READ_WRITE); + mThemeButtons[i].ClickedSignal().Connect(this, &StylingApplication::OnThemeButtonClicked); + themeButtonLayout.AddChild(mThemeButtons[i], TableView::CellPosition(0, 1 + i)); } - mThemeButtons[0].SetProperty( Toolkit::Button::Property::LABEL, "Lite" ); // Lightweight changes on top of Dali - mThemeButtons[1].SetProperty( Toolkit::Button::Property::LABEL, "App1" ); // Different application style - mThemeButtons[2].SetProperty( Toolkit::Button::Property::LABEL, "App2" ); + mThemeButtons[0].SetProperty(Toolkit::Button::Property::LABEL, "Lite"); // Lightweight changes on top of Dali + mThemeButtons[1].SetProperty(Toolkit::Button::Property::LABEL, "App1"); // Different application style + mThemeButtons[2].SetProperty(Toolkit::Button::Property::LABEL, "App2"); - contentLayout.Add( themeButtonLayout ); + contentLayout.Add(themeButtonLayout); } Actor StylingApplication::CreateContentPane() { - Toolkit::ImageView contentPane = Toolkit::ImageView::New( BORDER_IMAGE ); - contentPane.SetProperty( Dali::Actor::Property::NAME,"ContentPane"); - contentPane.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - contentPane.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - contentPane.SetProperty( Actor::Property::PADDING, Padding( BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH ) ); + Toolkit::ImageView contentPane = Toolkit::ImageView::New(BORDER_IMAGE); + contentPane.SetProperty(Dali::Actor::Property::NAME, "ContentPane"); + contentPane.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + contentPane.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + contentPane.SetProperty(Actor::Property::PADDING, Padding(BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH)); return contentPane; } Actor StylingApplication::CreateResizableContentPane() { - Toolkit::ImageView contentPane = Toolkit::ImageView::New( BORDER_IMAGE ); - contentPane.SetProperty( Dali::Actor::Property::NAME,"ContentPane"); - contentPane.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - contentPane.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - contentPane.SetProperty( Actor::Property::PADDING, Padding( BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH ) ); - - Toolkit::ImageView grabHandle = Toolkit::ImageView::New( RESIZE_HANDLE_IMAGE ); - grabHandle.SetProperty( Dali::Actor::Property::NAME,"GrabHandle"); - grabHandle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - grabHandle.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); - grabHandle.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); - grabHandle.SetProperty( Actor::Property::POSITION, Vector2( -BORDER_WIDTH, -BORDER_WIDTH )); - grabHandle.SetProperty( Actor::Property::OPACITY, 0.6f ); + Toolkit::ImageView contentPane = Toolkit::ImageView::New(BORDER_IMAGE); + contentPane.SetProperty(Dali::Actor::Property::NAME, "ContentPane"); + contentPane.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + contentPane.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + contentPane.SetProperty(Actor::Property::PADDING, Padding(BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH, BORDER_WIDTH)); + + Toolkit::ImageView grabHandle = Toolkit::ImageView::New(RESIZE_HANDLE_IMAGE); + grabHandle.SetProperty(Dali::Actor::Property::NAME, "GrabHandle"); + grabHandle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + grabHandle.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + grabHandle.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + grabHandle.SetProperty(Actor::Property::POSITION, Vector2(-BORDER_WIDTH, -BORDER_WIDTH)); + grabHandle.SetProperty(Actor::Property::OPACITY, 0.6f); Layer grabCornerLayer = Layer::New(); - grabCornerLayer.SetProperty( Dali::Actor::Property::NAME,"GrabCornerLayer"); - grabCornerLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); - grabCornerLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); - grabCornerLayer.Add( grabHandle ); - contentPane.Add( grabCornerLayer ); + grabCornerLayer.SetProperty(Dali::Actor::Property::NAME, "GrabCornerLayer"); + grabCornerLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + grabCornerLayer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT); + grabCornerLayer.Add(grabHandle); + contentPane.Add(grabCornerLayer); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( grabHandle ); - mPanGestureDetector.DetectedSignal().Connect( this, &StylingApplication::OnPan ); + mPanGestureDetector.Attach(grabHandle); + mPanGestureDetector.DetectedSignal().Connect(this, &StylingApplication::OnPan); return contentPane; } @@ -398,146 +411,145 @@ Popup StylingApplication::CreateResetPopup() { Window window = mApplication.GetWindow(); - Popup popup= Popup::New(); - popup.SetProperty( Dali::Actor::Property::NAME,"ResetPopup"); + Popup popup = Popup::New(); + popup.SetProperty(Dali::Actor::Property::NAME, "ResetPopup"); popup.SetStyleName("ResetPopup"); - popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - popup.SetProperty( Actor::Property::SIZE, Vector2( window.GetSize().GetWidth() * 0.75f, 0.0f ) ); - popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false ); - popup.OutsideTouchedSignal().Connect( this, &StylingApplication::HidePopup ); - popup.HiddenSignal().Connect( this, &StylingApplication::PopupHidden ); - - popup.SetTitle( CreateTitle( "Reset channels" ) ); - - TextLabel text = TextLabel::New( "This will reset the channel data to full value. Are you sure?" ); - text.SetProperty( Dali::Actor::Property::NAME, "PopupContentText" ); - text.SetStyleName( "PopupBody" ); - text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - text.SetProperty( TextLabel::Property::MULTI_LINE, true ); - text.SetProperty( Actor::Property::PADDING, Padding( 10.0f, 10.0f, 20.0f, 0.0f ) ); - popup.SetContent( text ); - - ImageView footer = ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH ); - footer.SetProperty( Dali::Actor::Property::NAME, "PopupFooter" ); - footer.SetStyleName( "PopupFooter" ); - footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT ); - footer.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 80.0f ) ); - footer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - footer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - - TableView footerLayout = TableView::New( 1, 2 ); - footerLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - footerLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - footerLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + popup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + popup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + popup.SetProperty(Actor::Property::SIZE, Vector2(window.GetSize().GetWidth() * 0.75f, 0.0f)); + popup.SetProperty(Popup::Property::TAIL_VISIBILITY, false); + popup.OutsideTouchedSignal().Connect(this, &StylingApplication::HidePopup); + popup.HiddenSignal().Connect(this, &StylingApplication::PopupHidden); + + popup.SetTitle(CreateTitle("Reset channels")); + + TextLabel text = TextLabel::New("This will reset the channel data to full value. Are you sure?"); + text.SetProperty(Dali::Actor::Property::NAME, "PopupContentText"); + text.SetStyleName("PopupBody"); + text.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + text.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + text.SetProperty(TextLabel::Property::MULTI_LINE, true); + text.SetProperty(Actor::Property::PADDING, Padding(10.0f, 10.0f, 20.0f, 0.0f)); + popup.SetContent(text); + + ImageView footer = ImageView::New(DEFAULT_CONTROL_AREA_IMAGE_PATH); + footer.SetProperty(Dali::Actor::Property::NAME, "PopupFooter"); + footer.SetStyleName("PopupFooter"); + footer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + footer.SetResizePolicy(ResizePolicy::FIXED, Dimension::HEIGHT); + footer.SetProperty(Actor::Property::SIZE, Vector2(0.0f, 80.0f)); + footer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + footer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + + TableView footerLayout = TableView::New(1, 2); + footerLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + footerLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + footerLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); PushButton okayButton = PushButton::New(); - okayButton.SetProperty( Dali::Actor::Property::NAME, POPUP_CONTROL_OK_NAME ); - okayButton.SetStyleName( POPUP_CONTROL_OK_NAME ); - okayButton.SetProperty( Toolkit::Button::Property::LABEL, "Ok!" ); - okayButton.ClickedSignal().Connect( this, &StylingApplication::OnReset ); - okayButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - okayButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - okayButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); - okayButton.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( -20.0f, -20.0f, 0.0f ) ); + okayButton.SetProperty(Dali::Actor::Property::NAME, POPUP_CONTROL_OK_NAME); + okayButton.SetStyleName(POPUP_CONTROL_OK_NAME); + okayButton.SetProperty(Toolkit::Button::Property::LABEL, "Ok!"); + okayButton.ClickedSignal().Connect(this, &StylingApplication::OnReset); + okayButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + okayButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + okayButton.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS); + okayButton.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(-20.0f, -20.0f, 0.0f)); PushButton cancelButton = PushButton::New(); - cancelButton.SetProperty( Dali::Actor::Property::NAME, POPUP_CONTROL_CANCEL_NAME ); - cancelButton.SetStyleName( POPUP_CONTROL_CANCEL_NAME ); - cancelButton.SetProperty( Toolkit::Button::Property::LABEL, "Cancel" ); - cancelButton.ClickedSignal().Connect( this, &StylingApplication::OnResetCancelled ); - cancelButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - cancelButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); - cancelButton.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( -20.0f, -20.0f, 0.0f ) ); - - footerLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - footerLayout.SetCellAlignment( TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); - footerLayout.AddChild( okayButton, TableView::CellPosition( 0, 0 ) ); - footerLayout.AddChild( cancelButton, TableView::CellPosition( 0, 1 ) ); - footerLayout.SetCellPadding( Size( 10.f, 10.f ) ); - footer.Add( footerLayout ); - - popup.SetFooter( footer ); + cancelButton.SetProperty(Dali::Actor::Property::NAME, POPUP_CONTROL_CANCEL_NAME); + cancelButton.SetStyleName(POPUP_CONTROL_CANCEL_NAME); + cancelButton.SetProperty(Toolkit::Button::Property::LABEL, "Cancel"); + cancelButton.ClickedSignal().Connect(this, &StylingApplication::OnResetCancelled); + cancelButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + cancelButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + cancelButton.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS); + cancelButton.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(-20.0f, -20.0f, 0.0f)); + + footerLayout.SetCellAlignment(TableView::CellPosition(0, 0), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + footerLayout.SetCellAlignment(TableView::CellPosition(0, 1), HorizontalAlignment::CENTER, VerticalAlignment::CENTER); + footerLayout.AddChild(okayButton, TableView::CellPosition(0, 0)); + footerLayout.AddChild(cancelButton, TableView::CellPosition(0, 1)); + footerLayout.SetCellPadding(Size(10.f, 10.f)); + footer.Add(footerLayout); + + popup.SetFooter(footer); return popup; } -TextLabel StylingApplication::CreateTitle( std::string title ) +TextLabel StylingApplication::CreateTitle(std::string title) { - TextLabel titleActor = TextLabel::New( title ); - titleActor.SetProperty( Dali::Actor::Property::NAME, "titleActor" ); - titleActor.SetStyleName( "PopupTitle" ); - titleActor.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - titleActor.SetProperty( TextLabel::Property::MULTI_LINE, false ); + TextLabel titleActor = TextLabel::New(title); + titleActor.SetProperty(Dali::Actor::Property::NAME, "titleActor"); + titleActor.SetStyleName("PopupTitle"); + titleActor.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + titleActor.SetProperty(TextLabel::Property::MULTI_LINE, false); return titleActor; } -bool StylingApplication::OnButtonStateChange( Button button ) +bool StylingApplication::OnButtonStateChange(Button button) { // On button press, called twice, once to tell new button it's selected, // once to tell old button it isn't selected? -// Todo: save / restore slider states per image + // Todo: save / restore slider states per image - if( button.GetProperty(Button::Property::SELECTED) ) + if(button.GetProperty(Button::Property::SELECTED)) { - ImageChannelControl prevIcc = mImageChannelControl; - if( mRadioButtons[0].GetProperty(Button::Property::SELECTED) ) + if(mRadioButtons[0].GetProperty(Button::Property::SELECTED)) { mImageChannelControl = mIcc1; } - else if( mRadioButtons[1].GetProperty(Button::Property::SELECTED) ) + else if(mRadioButtons[1].GetProperty(Button::Property::SELECTED)) { mImageChannelControl = mIcc2; } - else if( mRadioButtons[2].GetProperty(Button::Property::SELECTED) ) + else if(mRadioButtons[2].GetProperty(Button::Property::SELECTED)) { mImageChannelControl = mIcc3; } - if( prevIcc ) + if(prevIcc) { - prevIcc.SetVisibility( false ); + prevIcc.SetVisibility(false); } - if( mImageChannelControl ) + if(mImageChannelControl) { - mImageChannelControl.SetVisibility( true ); + mImageChannelControl.SetVisibility(true); } } return true; } -bool StylingApplication::OnCheckButtonChange( Button button ) +bool StylingApplication::OnCheckButtonChange(Button button) { Property::Index index = button.GetPropertyIndex("channel"); - if( index != Property::INVALID_INDEX ) + if(index != Property::INVALID_INDEX) { - int channel = button["channel"]; - float value = mChannelSliders[channel][Slider::Property::VALUE]; - if( !button[Button::Property::SELECTED] ) + int channel = button["channel"]; + float value = mChannelSliders[channel][Slider::Property::VALUE]; + if(!button[Button::Property::SELECTED]) { // "Turn off" the channel's contribution value = 0.0f; } - Property::Index channelIndex = GetChannelProperty( channel ); - mImageChannelControl.SetProperty(channelIndex, value/100.0f); + Property::Index channelIndex = GetChannelProperty(channel); + mImageChannelControl.SetProperty(channelIndex, value / 100.0f); } return true; } -bool StylingApplication::OnThemeButtonClicked( Button button ) +bool StylingApplication::OnThemeButtonClicked(Button button) { - int theme = button.GetProperty(button.GetPropertyIndex("theme")); - const char* themePath=NULL; + int theme = button.GetProperty(button.GetPropertyIndex("theme")); + const char* themePath = NULL; - switch( theme ) + switch(theme) { case 0: { @@ -556,52 +568,52 @@ bool StylingApplication::OnThemeButtonClicked( Button button ) } } - StyleManager::Get().ApplyTheme( themePath ); + StyleManager::Get().ApplyTheme(themePath); return true; } -bool StylingApplication::OnResetClicked( Button button ) +bool StylingApplication::OnResetClicked(Button button) { - if( ! mResetPopup ) + if(!mResetPopup) { - mResetPopup = CreateResetPopup (); + mResetPopup = CreateResetPopup(); } - mApplication.GetWindow().Add( mResetPopup ); + mApplication.GetWindow().Add(mResetPopup); - mResetPopup.SetDisplayState( Popup::SHOWN ); + mResetPopup.SetDisplayState(Popup::SHOWN); return true; } -bool StylingApplication::OnReset( Button button ) +bool StylingApplication::OnReset(Button button) { // todo: Reset the sliders for this image - for( int i=0; i<3; ++i ) + for(int i = 0; i < 3; ++i) { - mChannelSliders[i].SetProperty( Slider::Property::VALUE, 100.0f ); + mChannelSliders[i].SetProperty(Slider::Property::VALUE, 100.0f); } HidePopup(); return true; } -bool StylingApplication::OnResetCancelled( Button button ) +bool StylingApplication::OnResetCancelled(Button button) { HidePopup(); return true; } -bool StylingApplication::OnSliderChanged( Slider slider, float value ) +bool StylingApplication::OnSliderChanged(Slider slider, float value) { // todo - change color channel's saturation Property::Index index = slider.GetPropertyIndex("channel"); - if( index != Property::INVALID_INDEX ) + if(index != Property::INVALID_INDEX) { int channel = slider["channel"]; - if( mCheckButtons[channel]["selected"]) + if(mCheckButtons[channel]["selected"]) { - Property::Index channelIndex = GetChannelProperty( channel ); - mImageChannelControl.SetProperty(channelIndex, value/100.0f); + Property::Index channelIndex = GetChannelProperty(channel); + mImageChannelControl.SetProperty(channelIndex, value / 100.0f); } } return true; @@ -609,15 +621,15 @@ bool StylingApplication::OnSliderChanged( Slider slider, float value ) void StylingApplication::HidePopup() { - if( mResetPopup ) + if(mResetPopup) { - mResetPopup.SetDisplayState( Popup::HIDDEN ); + mResetPopup.SetDisplayState(Popup::HIDDEN); } } void StylingApplication::PopupHidden() { - if( mResetPopup ) + if(mResetPopup) { // Clear down resources mResetPopup.Unparent(); @@ -625,43 +637,43 @@ void StylingApplication::PopupHidden() } } -void StylingApplication::OnPan( Actor actor, const PanGesture& gesture ) +void StylingApplication::OnPan(Actor actor, const PanGesture& gesture) { Vector3 size = mContentPane.GetTargetSize(); - mContentPane.SetProperty( Actor::Property::SIZE, Vector2( size.GetVectorXY() + gesture.GetDisplacement() * 2.0f ) ); + mContentPane.SetProperty(Actor::Property::SIZE, Vector2(size.GetVectorXY() + gesture.GetDisplacement() * 2.0f)); } -void StylingApplication::OnKeyEvent( const KeyEvent& keyEvent ) +void StylingApplication::OnKeyEvent(const KeyEvent& keyEvent) { static int keyPressed = 0; - if( keyEvent.GetState() == KeyEvent::DOWN) + if(keyEvent.GetState() == KeyEvent::DOWN) { - if( keyPressed == 0 ) // Is this the first down event? + if(keyPressed == 0) // Is this the first down event? { - printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode() ); + printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode()); - if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) ) + if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK)) { mApplication.Quit(); } - else if( keyEvent.GetKeyName().compare("Return") == 0 ) + else if(keyEvent.GetKeyName().compare("Return") == 0) { mCurrentTheme++; mCurrentTheme %= NUMBER_OF_THEMES; StyleManager styleManager = StyleManager::Get(); - switch( mCurrentTheme ) + switch(mCurrentTheme) { case 0: { - styleManager.ApplyTheme( DEMO_THEME_ONE_PATH ); + styleManager.ApplyTheme(DEMO_THEME_ONE_PATH); printf("Changing to theme One\n"); break; } case 1: { - styleManager.ApplyTheme( DEMO_THEME_TWO_PATH ); + styleManager.ApplyTheme(DEMO_THEME_TWO_PATH); printf("Changing to theme Two\n"); break; } @@ -676,7 +688,7 @@ void StylingApplication::OnKeyEvent( const KeyEvent& keyEvent ) } keyPressed = 1; } - else if( keyEvent.GetState() == KeyEvent::UP ) + else if(keyEvent.GetState() == KeyEvent::UP) { keyPressed = 0; } diff --git a/examples/styling/styling-application.h b/examples/styling/styling-application.h index ad7af1b..ebf2113 100644 --- a/examples/styling/styling-application.h +++ b/examples/styling/styling-application.h @@ -2,7 +2,7 @@ #define DALI_DEMO_STYLING_APPLICATION_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,9 @@ #include //#include #include -#include "image-channel-control.h" #include #include +#include "image-channel-control.h" // Internal includes @@ -32,36 +32,35 @@ using namespace Dali::Toolkit; namespace Demo { - class StylingApplication : public ConnectionTracker { public: // Constructor - StylingApplication( Application& application ); + StylingApplication(Application& application); // Destructor ~StylingApplication(); // Init signal handler - void Create( Application& application ); + void Create(Application& application); // Create the GUI components - Actor CreateContentPane(); - Actor CreateResizableContentPane(); - Toolkit::Popup CreateResetPopup(); - Toolkit::TextLabel CreateTitle( std::string title ); + Actor CreateContentPane(); + Actor CreateResizableContentPane(); + Toolkit::Popup CreateResetPopup(); + Toolkit::TextLabel CreateTitle(std::string title); // Key event handler - void OnKeyEvent( const KeyEvent& event ); + void OnKeyEvent(const KeyEvent& event); // Button event handlers - bool OnButtonStateChange( Toolkit::Button button ); - bool OnCheckButtonChange( Toolkit::Button button ); - bool OnResetClicked( Toolkit::Button button ); - bool OnThemeButtonClicked( Toolkit::Button button ); + bool OnButtonStateChange(Toolkit::Button button); + bool OnCheckButtonChange(Toolkit::Button button); + bool OnResetClicked(Toolkit::Button button); + bool OnThemeButtonClicked(Toolkit::Button button); // Slider event handler - bool OnSliderChanged( Toolkit::Slider slider, float value ); + bool OnSliderChanged(Toolkit::Slider slider, float value); // Popup event handlers void HidePopup(); @@ -70,32 +69,31 @@ public: bool OnResetCancelled(Button button); // Grab handle handler - void OnPan( Actor actor, const PanGesture& gesture ); + void OnPan(Actor actor, const PanGesture& gesture); static const char* DEMO_THEME_ONE_PATH; static const char* DEMO_THEME_TWO_PATH; static const char* DEMO_THEME_THREE_PATH; private: - Application& mApplication; - int mCurrentTheme; - Actor mContentPane; - TextLabel mTitle; - RadioButton mRadioButtons[3]; // 3 demo images - CheckBoxButton mCheckButtons[3]; // rgb buttons - Slider mChannelSliders[3]; // rgb sliders - PushButton mThemeButtons[3]; - PushButton mResetButton; + Application& mApplication; + int mCurrentTheme; + Actor mContentPane; + TextLabel mTitle; + RadioButton mRadioButtons[3]; // 3 demo images + CheckBoxButton mCheckButtons[3]; // rgb buttons + Slider mChannelSliders[3]; // rgb sliders + PushButton mThemeButtons[3]; + PushButton mResetButton; ImageChannelControl mImageChannelControl; ImageChannelControl mIcc1; ImageChannelControl mIcc2; ImageChannelControl mIcc3; - Actor mImagePlacement; - Popup mResetPopup; - PanGestureDetector mPanGestureDetector; + Actor mImagePlacement; + Popup mResetPopup; + PanGestureDetector mPanGestureDetector; }; } // Namespace Demo - #endif // DALI_DEMO_STYLING_APPLICATION_H diff --git a/examples/super-blur-view/super-blur-view-example.cpp b/examples/super-blur-view/super-blur-view-example.cpp index 6089199..7e3db09 100644 --- a/examples/super-blur-view/super-blur-view-example.cpp +++ b/examples/super-blur-view/super-blur-view-example.cpp @@ -15,9 +15,9 @@ * */ -#include #include #include +#include using namespace Dali; using Dali::Toolkit::Button; @@ -26,12 +26,11 @@ using Dali::Toolkit::SuperBlurView; namespace { - -const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-4.jpg" ); +const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-4.jpg"); const unsigned int DEFAULT_BLUR_LEVEL(5u); ///< The default blur level when creating SuperBlurView from the type registry -} +} // namespace /** * This example shows a background image which is "super blurred" while the push-button control is pressed. @@ -39,61 +38,59 @@ const unsigned int DEFAULT_BLUR_LEVEL(5u); ///< The default blur level when crea class SuperBlurViewExample : public ConnectionTracker { public: - - SuperBlurViewExample( Application& application ) - : mApplication( application ) + SuperBlurViewExample(Application& application) + : mApplication(application) { - mApplication.InitSignal().Connect( this, &SuperBlurViewExample::Create ); + mApplication.InitSignal().Connect(this, &SuperBlurViewExample::Create); } ~SuperBlurViewExample() = default; private: - - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); - window.KeyEventSignal().Connect( this, &SuperBlurViewExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &SuperBlurViewExample::OnKeyEvent); - mSuperBlurView = SuperBlurView::New( DEFAULT_BLUR_LEVEL ); - mSuperBlurView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mSuperBlurView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mSuperBlurView.SetProperty( Actor::Property::SIZE, Vector2( 800, 1280 ) ); - mSuperBlurView.SetProperty( SuperBlurView::Property::IMAGE_URL, BACKGROUND_IMAGE ); - window.Add( mSuperBlurView ); + mSuperBlurView = SuperBlurView::New(DEFAULT_BLUR_LEVEL); + mSuperBlurView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mSuperBlurView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mSuperBlurView.SetProperty(Actor::Property::SIZE, Vector2(800, 1280)); + mSuperBlurView.SetProperty(SuperBlurView::Property::IMAGE_URL, BACKGROUND_IMAGE); + window.Add(mSuperBlurView); mBlurAnimation = Animation::New(1.0f); - mBlurAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 1.0f ); + mBlurAnimation.AnimateTo(Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 1.0f); mClearAnimation = Animation::New(1.0f); - mClearAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 0.0f ); + mClearAnimation.AnimateTo(Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 0.0f); mPushButton = PushButton::New(); - mPushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mPushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mPushButton.SetProperty( Button::Property::LABEL, "Blur" ); - mPushButton.PressedSignal().Connect( this, &SuperBlurViewExample::OnButtonPressed ); - mPushButton.ReleasedSignal().Connect( this, &SuperBlurViewExample::OnButtonReleased ); - window.Add( mPushButton ); + mPushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mPushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mPushButton.SetProperty(Button::Property::LABEL, "Blur"); + mPushButton.PressedSignal().Connect(this, &SuperBlurViewExample::OnButtonPressed); + mPushButton.ReleasedSignal().Connect(this, &SuperBlurViewExample::OnButtonReleased); + window.Add(mPushButton); } - bool OnButtonPressed( Button button ) + bool OnButtonPressed(Button button) { mBlurAnimation.Play(); return true; } - bool OnButtonReleased( Button button ) + bool OnButtonReleased(Button button) { mClearAnimation.Play(); return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if ( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -101,8 +98,7 @@ private: } private: - - Application& mApplication; + Application& mApplication; SuperBlurView mSuperBlurView; @@ -112,11 +108,11 @@ private: Animation mClearAnimation; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - SuperBlurViewExample test( application ); + SuperBlurViewExample test(application); application.MainLoop(); diff --git a/examples/text-editor/text-editor-example.cpp b/examples/text-editor/text-editor-example.cpp index 35b8e60..d291bbb 100644 --- a/examples/text-editor/text-editor-example.cpp +++ b/examples/text-editor/text-editor-example.cpp @@ -33,27 +33,26 @@ using namespace Dali::Toolkit; namespace { - -const char * const THEME_PATH( DEMO_STYLE_DIR "text-editor-example-theme.json" ); ///< The theme used for this example -const Vector4 BACKGROUND_COLOR( 0.04f, 0.345f, 0.392f, 1.0f ); ///< The background color. -const char* TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; ///< The tool-bar image. -const float TOOLBAR_BUTTON_PERCENTAGE = 0.1f; ///< The button's space width as a percentage of the toolbar's width. -const float TOOLBAR_TITLE_PERCENTAGE = 0.7f; ///< The title's width as a percentage of the toolbar's width. -const float TOOLBAR_HEIGHT_PERCENTAGE = 0.05f; ///< The toolbar's height as a percentage of the window's height. -const float TOOLBAR_PADDING = 4.f; ///< The padding in pixels. -const float BUTTON_PERCENTAGE = 0.8f; ///< The button's height as a percentage of the space for the buttons in the toolbar. -const Vector3 TEXT_EDITOR_RELATIVE_SIZE( 0.9f, 0.5f, 1.0f ); ///< The size of the text editor as a percentage of the window's size. -const Vector4 TEXT_EDITOR_BACKGROUND_COLOR( 1.f, 1.f, 1.f, 0.15f ); ///< The background color of the text editor. - -const Vector4 COLORS[] = { Color::RED, - Color::GREEN, - Color::BLUE, - Color::YELLOW, - Color::CYAN, - Color::MAGENTA, - Color::WHITE, - Color::BLACK }; -const unsigned int NUMBER_OF_COLORS = sizeof( COLORS ) / sizeof( Vector4 ); +const char* const THEME_PATH(DEMO_STYLE_DIR "text-editor-example-theme.json"); ///< The theme used for this example +const Vector4 BACKGROUND_COLOR(0.04f, 0.345f, 0.392f, 1.0f); ///< The background color. +const char* TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png"; ///< The tool-bar image. +const float TOOLBAR_BUTTON_PERCENTAGE = 0.1f; ///< The button's space width as a percentage of the toolbar's width. +const float TOOLBAR_TITLE_PERCENTAGE = 0.7f; ///< The title's width as a percentage of the toolbar's width. +const float TOOLBAR_HEIGHT_PERCENTAGE = 0.05f; ///< The toolbar's height as a percentage of the window's height. +const float TOOLBAR_PADDING = 4.f; ///< The padding in pixels. +const float BUTTON_PERCENTAGE = 0.8f; ///< The button's height as a percentage of the space for the buttons in the toolbar. +const Vector3 TEXT_EDITOR_RELATIVE_SIZE(0.9f, 0.5f, 1.0f); ///< The size of the text editor as a percentage of the window's size. +const Vector4 TEXT_EDITOR_BACKGROUND_COLOR(1.f, 1.f, 1.f, 0.15f); ///< The background color of the text editor. + +const Vector4 COLORS[] = {Color::RED, + Color::GREEN, + Color::BLUE, + Color::YELLOW, + Color::CYAN, + Color::MAGENTA, + Color::WHITE, + Color::BLACK}; +const unsigned int NUMBER_OF_COLORS = sizeof(COLORS) / sizeof(Vector4); } // Unnamed namespace @@ -63,11 +62,11 @@ const unsigned int NUMBER_OF_COLORS = sizeof( COLORS ) / sizeof( Vector4 ); class TextEditorExample : public ConnectionTracker { public: - TextEditorExample( Application& application ) - : mApplication( application ) + TextEditorExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextEditorExample::Create ); + mApplication.InitSignal().Connect(this, &TextEditorExample::Create); } ~TextEditorExample() @@ -78,7 +77,7 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); @@ -86,7 +85,7 @@ public: window.KeyEventSignal().Connect(this, &TextEditorExample::OnKeyEvent); // Set a background color. - window.SetBackgroundColor( BACKGROUND_COLOR ); + window.SetBackgroundColor(BACKGROUND_COLOR); // The window size. const Vector2 windowSize = window.GetSize(); @@ -95,134 +94,134 @@ public: // The view is added to the window. // Set the toolbar style - const float toolBarHeight = TOOLBAR_HEIGHT_PERCENTAGE * windowSize.height; - const DemoHelper::ViewStyle viewStyle( TOOLBAR_BUTTON_PERCENTAGE, - TOOLBAR_TITLE_PERCENTAGE, - toolBarHeight, - TOOLBAR_PADDING ); - - Layer contents = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - "", - TOOLBAR_IMAGE, - "", - viewStyle ); + const float toolBarHeight = TOOLBAR_HEIGHT_PERCENTAGE * windowSize.height; + const DemoHelper::ViewStyle viewStyle(TOOLBAR_BUTTON_PERCENTAGE, + TOOLBAR_TITLE_PERCENTAGE, + toolBarHeight, + TOOLBAR_PADDING); + + Layer contents = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + "", + TOOLBAR_IMAGE, + "", + viewStyle); // Create a label for the color selection button. // The button will be a child of this, so as to be placed next to it. - TextLabel colorLabel = TextLabel::New( "Text Color: " ); - colorLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); - colorLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); - colorLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + TextLabel colorLabel = TextLabel::New("Text Color: "); + colorLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH); + colorLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); + colorLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); // Create a container for the color button, to layout the drop-down list below it. mColorContainer = Control::New(); - mColorContainer.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH ); - mColorContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); - mColorContainer.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.0f, BUTTON_PERCENTAGE, 0.0f ) ); + mColorContainer.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH); + mColorContainer.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT); + mColorContainer.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.0f, BUTTON_PERCENTAGE, 0.0f)); // Place to right of parent. - mColorContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT ); - mColorContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); - colorLabel.Add( mColorContainer ); + mColorContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT); + mColorContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT); + colorLabel.Add(mColorContainer); // Add border to highlight harder-to-see colors. // We use a color rather than border visual as the container will always be behind the button. Property::Map colorMap; - colorMap.Insert( Toolkit::Visual::Property::TYPE, Visual::COLOR); - colorMap.Insert( ColorVisual::Property::MIX_COLOR, Color::BLACK ); - mColorContainer.SetProperty( Control::Property::BACKGROUND, colorMap ); + colorMap.Insert(Toolkit::Visual::Property::TYPE, Visual::COLOR); + colorMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLACK); + mColorContainer.SetProperty(Control::Property::BACKGROUND, colorMap); // Create a 'select color' button. mColorButtonOption = Toolkit::PushButton::New(); - mColorButtonOption.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mColorButtonOption.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.9f, 0.9f, 0.0f ) ); // Smaller than container to show border. - mColorButtonOption.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mColorButtonOption.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mColorButtonOption.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mColorButtonOption.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.9f, 0.9f, 0.0f)); // Smaller than container to show border. + mColorButtonOption.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mColorButtonOption.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - SetButtonColor( mColorButtonOption, Color::BLACK ); + SetButtonColor(mColorButtonOption, Color::BLACK); - mColorButtonOption.ClickedSignal().Connect( this, &TextEditorExample::OnChangeColorButtonClicked ); - mColorContainer.Add( mColorButtonOption ); + mColorButtonOption.ClickedSignal().Connect(this, &TextEditorExample::OnChangeColorButtonClicked); + mColorContainer.Add(mColorButtonOption); //Add label to toolbar, which will also add the color button next to it. - mToolBar.AddControl( colorLabel, viewStyle.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + mToolBar.AddControl(colorLabel, viewStyle.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create the text editor. mEditor = TextEditor::New(); - mEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mEditor.SetProperty( Actor::Property::POSITION, Vector3( 0.f, toolBarHeight * 2.0f, 0.f )); - mEditor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mEditor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, TEXT_EDITOR_RELATIVE_SIZE ); - - mEditor.SetBackgroundColor( TEXT_EDITOR_BACKGROUND_COLOR ); - - const Size boundingBoxSize( windowSize * TEXT_EDITOR_RELATIVE_SIZE.GetVectorXY() ); - Rect boundingBox( 0, - static_cast( toolBarHeight ), - static_cast( boundingBoxSize.width ), - static_cast( boundingBoxSize.height - toolBarHeight ) ); - - mEditor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, boundingBox ); - mEditor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::BLACK ); - mEditor.SetProperty( TextEditor::Property::TEXT, - "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n" - "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n" - "Ne nec nulla regione albucius, mea doctus delenit ad!\n" - "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n" - "Quidam corpora at duo. An eos possim scripserit?\n\n" - "Aťqui dicant sěnťenťíae aň vel!\n" - "Vis viris médiocrem elaboraret ét, verear civibus moderatius ex duo!\n" - "Án veri laborě iňtěgré quó, mei aď poššit lobortis, mei prompťa čonsťitůťó eů.\n" - "Aliquip sanctůs delicáta quí ěá, et natum aliquam est?\n" - "Asšúm sapěret usu ůť.\n" - "Síť ut apeirián laboramúš percipitur, sůas hařum ín éos?\n" ); - - mEditor.InputStyleChangedSignal().Connect( this, &TextEditorExample::OnTextInputStyleChanged ); - - contents.Add( mEditor ); + mEditor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mEditor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mEditor.SetProperty(Actor::Property::POSITION, Vector3(0.f, toolBarHeight * 2.0f, 0.f)); + mEditor.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mEditor.SetProperty(Actor::Property::SIZE_MODE_FACTOR, TEXT_EDITOR_RELATIVE_SIZE); + + mEditor.SetBackgroundColor(TEXT_EDITOR_BACKGROUND_COLOR); + + const Size boundingBoxSize(windowSize * TEXT_EDITOR_RELATIVE_SIZE.GetVectorXY()); + Rect boundingBox(0, + static_cast(toolBarHeight), + static_cast(boundingBoxSize.width), + static_cast(boundingBoxSize.height - toolBarHeight)); + + mEditor.SetProperty(TextEditor::Property::DECORATION_BOUNDING_BOX, boundingBox); + mEditor.SetProperty(TextEditor::Property::TEXT_COLOR, Color::BLACK); + mEditor.SetProperty(TextEditor::Property::TEXT, + "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n" + "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n" + "Ne nec nulla regione albucius, mea doctus delenit ad!\n" + "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n" + "Quidam corpora at duo. An eos possim scripserit?\n\n" + "Aťqui dicant sěnťenťíae aň vel!\n" + "Vis viris médiocrem elaboraret ét, verear civibus moderatius ex duo!\n" + "Án veri laborě iňtěgré quó, mei aď poššit lobortis, mei prompťa čonsťitůťó eů.\n" + "Aliquip sanctůs delicáta quí ěá, et natum aliquam est?\n" + "Asšúm sapěret usu ůť.\n" + "Síť ut apeirián laboramúš percipitur, sůas hařum ín éos?\n"); + + mEditor.InputStyleChangedSignal().Connect(this, &TextEditorExample::OnTextInputStyleChanged); + + contents.Add(mEditor); StyleManager styleManager = StyleManager::Get(); - styleManager.ApplyTheme( THEME_PATH ); + styleManager.ApplyTheme(THEME_PATH); } void CreateButtonContainer() { - mButtonContainer = Toolkit::TableView::New( NUMBER_OF_COLORS, 1u ); - mButtonContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mButtonContainer.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 1.0f, NUMBER_OF_COLORS, 1.0f ) ); + mButtonContainer = Toolkit::TableView::New(NUMBER_OF_COLORS, 1u); + mButtonContainer.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + mButtonContainer.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(1.0f, NUMBER_OF_COLORS, 1.0f)); // Place below color selection button. - mButtonContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mButtonContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mButtonContainer.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 2.f * TOOLBAR_PADDING, 0.f )); - mColorContainer.Add( mButtonContainer ); + mButtonContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mButtonContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mButtonContainer.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 2.f * TOOLBAR_PADDING, 0.f)); + mColorContainer.Add(mButtonContainer); - const Vector3 buttonPercentage( 1.f, 0.8f / static_cast( NUMBER_OF_COLORS ), 1.f ); - for( unsigned int index = 0u; index < NUMBER_OF_COLORS; ++index ) + const Vector3 buttonPercentage(1.f, 0.8f / static_cast(NUMBER_OF_COLORS), 1.f); + for(unsigned int index = 0u; index < NUMBER_OF_COLORS; ++index) { Toolkit::PushButton button = Toolkit::PushButton::New(); - button.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - button.SetProperty( Actor::Property::SIZE_MODE_FACTOR, buttonPercentage ); + button.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + button.SetProperty(Actor::Property::SIZE_MODE_FACTOR, buttonPercentage); std::ostringstream s; s << "color" << index; - button.SetProperty( Dali::Actor::Property::NAME, s.str() ); + button.SetProperty(Dali::Actor::Property::NAME, s.str()); - SetButtonColor( button, COLORS[index] ); + SetButtonColor(button, COLORS[index]); - button.ClickedSignal().Connect( this, &TextEditorExample::OnColorButtonClicked ); + button.ClickedSignal().Connect(this, &TextEditorExample::OnColorButtonClicked); - mButtonContainer.Add( button ); + mButtonContainer.Add(button); } } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { // Exit application when click back or escape. mApplication.Quit(); @@ -230,61 +229,60 @@ public: } } - bool OnChangeColorButtonClicked( Button button ) + bool OnChangeColorButtonClicked(Button button) { - if( !mButtonContainer ) + if(!mButtonContainer) { CreateButtonContainer(); } - mButtonContainer.SetProperty( Actor::Property::VISIBLE, true ); - mButtonContainer.SetProperty( Actor::Property::SENSITIVE, true ); + mButtonContainer.SetProperty(Actor::Property::VISIBLE, true); + mButtonContainer.SetProperty(Actor::Property::SENSITIVE, true); return true; } - bool OnColorButtonClicked( Button button ) + bool OnColorButtonClicked(Button button) { - const std::string& name = button.GetProperty< std::string >( Dali::Actor::Property::NAME ); + const std::string& name = button.GetProperty(Dali::Actor::Property::NAME); Vector4 color; - if( "color" == name.substr( 0u, 5u ) ) + if("color" == name.substr(0u, 5u)) { - const unsigned int index = strtoul( name.substr( 5u, 1u ).c_str(), NULL, 10u ); - color = COLORS[index]; - mEditor.SetProperty( TextEditor::Property::INPUT_COLOR, color ); + const unsigned int index = strtoul(name.substr(5u, 1u).c_str(), NULL, 10u); + color = COLORS[index]; + mEditor.SetProperty(TextEditor::Property::INPUT_COLOR, color); } - SetButtonColor( mColorButtonOption, color ); + SetButtonColor(mColorButtonOption, color); - mButtonContainer.SetProperty( Actor::Property::VISIBLE, false ); - mButtonContainer.SetProperty( Actor::Property::SENSITIVE, false ); + mButtonContainer.SetProperty(Actor::Property::VISIBLE, false); + mButtonContainer.SetProperty(Actor::Property::SENSITIVE, false); return true; } - void OnTextInputStyleChanged( TextEditor editor, TextEditor::InputStyle::Mask mask ) + void OnTextInputStyleChanged(TextEditor editor, TextEditor::InputStyle::Mask mask) { - if( TextEditor::InputStyle::NONE != static_cast( mask & TextEditor::InputStyle::COLOR ) ) + if(TextEditor::InputStyle::NONE != static_cast(mask & TextEditor::InputStyle::COLOR)) { - const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get(); - SetButtonColor( mColorButtonOption, color ); + const Vector4 color = editor.GetProperty(TextEditor::Property::INPUT_COLOR).Get(); + SetButtonColor(mColorButtonOption, color); } editor.Reset(); } - void SetButtonColor( Button& button, const Vector4& color ) + void SetButtonColor(Button& button, const Vector4& color) { Property::Map colorVisualMap; - colorVisualMap.Add( Toolkit::Visual::Property::TYPE, Visual::COLOR ) - .Add( ColorVisual::Property::MIX_COLOR, color ); + colorVisualMap.Add(Toolkit::Visual::Property::TYPE, Visual::COLOR) + .Add(ColorVisual::Property::MIX_COLOR, color); - button.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, colorVisualMap ); - button.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, colorVisualMap ); + button.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, colorVisualMap); + button.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, colorVisualMap); } private: - Application& mApplication; Toolkit::Control mView; @@ -295,11 +293,11 @@ private: Toolkit::TableView mButtonContainer; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { // DALI_DEMO_THEME_PATH not passed to Application so TextEditor example uses default Toolkit style sheet. - Application application = Application::New( &argc, &argv ); - TextEditorExample test( application ); + Application application = Application::New(&argc, &argv); + TextEditorExample test(application); application.MainLoop(); return 0; } diff --git a/examples/text-field/text-field-example.cpp b/examples/text-field/text-field-example.cpp index 751380b..307c0df 100644 --- a/examples/text-field/text-field-example.cpp +++ b/examples/text-field/text-field-example.cpp @@ -35,11 +35,10 @@ using namespace MultiLanguageStrings; namespace { +const char* const FOLDER_ICON_IMAGE = DEMO_IMAGE_DIR "folder_appicon_empty_bg.png"; +const char* const FOLDER_OPEN_ICON_IMAGE = DEMO_IMAGE_DIR "folder_appicon_empty_open_bg.png"; - const char* const FOLDER_ICON_IMAGE = DEMO_IMAGE_DIR "folder_appicon_empty_bg.png"; - const char* const FOLDER_OPEN_ICON_IMAGE = DEMO_IMAGE_DIR "folder_appicon_empty_open_bg.png"; - - const float BORDER_WIDTH = 4.0f; +const float BORDER_WIDTH = 4.0f; } // unnamed namespace @@ -49,12 +48,11 @@ namespace class TextFieldExample : public ConnectionTracker { public: - - TextFieldExample( Application& application ) - : mApplication( application ) + TextFieldExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextFieldExample::Create ); + mApplication.InitSignal().Connect(this, &TextFieldExample::Create); } ~TextFieldExample() @@ -65,58 +63,58 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); - window.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) ); + window.SetBackgroundColor(Vector4(0.04f, 0.345f, 0.392f, 1.0f)); window.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); mButton = CreateFolderButton(); - mButton.ClickedSignal().Connect( this, &TextFieldExample::OnButtonClicked ); - window.Add( mButton ); + mButton.ClickedSignal().Connect(this, &TextFieldExample::OnButtonClicked); + window.Add(mButton); } PushButton CreateFolderButton() { PushButton button = PushButton::New(); - button.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FOLDER_ICON_IMAGE ); - button.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FOLDER_OPEN_ICON_IMAGE ); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + button.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FOLDER_ICON_IMAGE); + button.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FOLDER_OPEN_ICON_IMAGE); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); return button; } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { - Window window = mApplication.GetWindow(); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); // Remove previously hidden pop-up UnparentAndReset(mPopup); // Launch a pop-up containing TextField - mField = CreateTextField( windowSize, mButtonLabel ); + mField = CreateTextField(windowSize, mButtonLabel); mPopup = CreatePopup(); - mPopup.Add( mField ); - mPopup.OutsideTouchedSignal().Connect( this, &TextFieldExample::OnPopupOutsideTouched ); - window.Add( mPopup ); - mPopup.SetDisplayState( Popup::SHOWN ); + mPopup.Add(mField); + mPopup.OutsideTouchedSignal().Connect(this, &TextFieldExample::OnPopupOutsideTouched); + window.Add(mPopup); + mPopup.SetDisplayState(Popup::SHOWN); return true; } - TextField CreateTextField( const Vector2& windowSize, const std::string& text ) + TextField CreateTextField(const Vector2& windowSize, const std::string& text) { TextField field = TextField::New(); - field.SetProperty( Dali::Actor::Property::NAME,"textField"); - field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - field.SetProperty( TextField::Property::TEXT, text ); - field.SetProperty( TextField::Property::TEXT_COLOR, Vector4( 0.0f, 1.0f, 1.0f, 1.0f ) ); // CYAN - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder" ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name." ); - field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( BORDER_WIDTH, BORDER_WIDTH, windowSize.width - BORDER_WIDTH*2, windowSize.height - BORDER_WIDTH*2 ) ); + field.SetProperty(Dali::Actor::Property::NAME, "textField"); + field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + field.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + field.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + field.SetProperty(TextField::Property::TEXT, text); + field.SetProperty(TextField::Property::TEXT_COLOR, Vector4(0.0f, 1.0f, 1.0f, 1.0f)); // CYAN + field.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder"); + field.SetProperty(TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name."); + field.SetProperty(TextField::Property::DECORATION_BOUNDING_BOX, Rect(BORDER_WIDTH, BORDER_WIDTH, windowSize.width - BORDER_WIDTH * 2, windowSize.height - BORDER_WIDTH * 2)); return field; } @@ -124,11 +122,11 @@ public: Popup CreatePopup() { Popup popup = Popup::New(); - popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH ); - popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); - popup.TouchedSignal().Connect( this, &TextFieldExample::OnPopupTouched ); + popup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + popup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + popup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH); + popup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + popup.TouchedSignal().Connect(this, &TextFieldExample::OnPopupTouched); return popup; } @@ -136,36 +134,36 @@ public: void OnPopupOutsideTouched() { // Update the folder text - if( mButton && mField ) + if(mButton && mField) { - Property::Value text = mField.GetProperty( TextField::Property::TEXT ); - mButtonLabel = text.Get< std::string >(); - mButton.SetProperty( Toolkit::Button::Property::LABEL, mButtonLabel ); + Property::Value text = mField.GetProperty(TextField::Property::TEXT); + mButtonLabel = text.Get(); + mButton.SetProperty(Toolkit::Button::Property::LABEL, mButtonLabel); } // Hide & discard the pop-up - if( mPopup ) + if(mPopup) { - mPopup.SetDisplayState( Popup::HIDDEN ); + mPopup.SetDisplayState(Popup::HIDDEN); } mField.Reset(); } - bool OnPopupTouched( Actor actor, const TouchEvent& event ) + bool OnPopupTouched(Actor actor, const TouchEvent& event) { // End edit mode for TextField if parent Popup touched. if((event.GetPointCount() > 0) && (mPopup == event.GetHitActor(0))) { - switch( event.GetState( 0 ) ) + switch(event.GetState(0)) { case PointState::DOWN: { // Update the folder text and lose focus for Key events - if( mButton && mField ) + if(mButton && mField) { - Property::Value text = mField.GetProperty( TextField::Property::TEXT ); - mButtonLabel = text.Get< std::string >(); - mButton.SetProperty( Toolkit::Button::Property::LABEL, mButtonLabel ); + Property::Value text = mField.GetProperty(TextField::Property::TEXT); + mButtonLabel = text.Get(); + mButton.SetProperty(Toolkit::Button::Property::LABEL, mButtonLabel); mField.ClearKeyInputFocus(); } break; @@ -187,7 +185,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -195,23 +193,22 @@ public: } private: - Application& mApplication; // This button launches a pop-up containing TextField - PushButton mButton; + PushButton mButton; std::string mButtonLabel; // Pop-up contents TextField mField; - Popup mPopup; + Popup mPopup; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { // DALI_DEMO_THEME_PATH not passed to Application so TextField example uses default Toolkit style sheet. - Application application = Application::New( &argc, &argv ); - TextFieldExample test( application ); + Application application = Application::New(&argc, &argv); + TextFieldExample test(application); application.MainLoop(); return 0; } diff --git a/examples/text-fonts/text-fonts-example.cpp b/examples/text-fonts/text-fonts-example.cpp index 211bd98..72e9e6e 100644 --- a/examples/text-fonts/text-fonts-example.cpp +++ b/examples/text-fonts/text-fonts-example.cpp @@ -40,10 +40,10 @@ using namespace MultiLanguageStrings; namespace { - const char* const LABEL_TEXT = "A Quick Fox"; - const char* const LABEL_TEXT_MIXED = "Fox 구미호"; - const char* const LABEL_TEXT_KOREAN = "구미호"; -} +const char* const LABEL_TEXT = "A Quick Fox"; +const char* const LABEL_TEXT_MIXED = "Fox 구미호"; +const char* const LABEL_TEXT_KOREAN = "구미호"; +} // namespace /** * @brief The main class of the demo. @@ -51,13 +51,12 @@ namespace class TextFontsExample : public ConnectionTracker { public: - - TextFontsExample( Application& application ) - : mApplication( application ), + TextFontsExample(Application& application) + : mApplication(application), mToggle(true) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextFontsExample::Create ); + mApplication.InitSignal().Connect(this, &TextFontsExample::Create); } ~TextFontsExample() @@ -65,80 +64,80 @@ public: // Nothing to do here. } - void CreateTextLabel( TextLabel& textLabel, std::string textString, const Vector4& color, bool infoLabel=false ) + void CreateTextLabel(TextLabel& textLabel, std::string textString, const Vector4& color, bool infoLabel = false) { - textLabel = TextLabel::New( textString ); - textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); - textLabel.SetProperty( TextLabel::Property::MULTI_LINE, true ); - if ( infoLabel ) + textLabel = TextLabel::New(textString); + textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); + textLabel.SetProperty(TextLabel::Property::MULTI_LINE, true); + if(infoLabel) { - textLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - textLabel.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f ); - textLabel.SetProperty( TextLabel::Property::FONT_FAMILY, "SamsungOneUI" ); + textLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + textLabel.SetProperty(TextLabel::Property::POINT_SIZE, 12.0f); + textLabel.SetProperty(TextLabel::Property::FONT_FAMILY, "SamsungOneUI"); } else { Property::Map shadowMap; - shadowMap.Insert( "color", Color::BLACK ); - shadowMap.Insert( "offset", Vector2( 0.3f, 0.3f ) ); - textLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); - textLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE ); + shadowMap.Insert("color", Color::BLACK); + shadowMap.Insert("offset", Vector2(0.3f, 0.3f)); + textLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); + textLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLUE); } - textLabel.SetBackgroundColor( color ); + textLabel.SetBackgroundColor(color); } - void CreateContainer( Control& container, const Vector2 size ) + void CreateContainer(Control& container, const Vector2 size) { container = Control::New(); - container.SetProperty( Actor::Property::SIZE, size ); - container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - container.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D ); + container.SetProperty(Actor::Property::SIZE, size); + container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + container.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); } - void CreateFolderButton( PushButton& button ) + void CreateFolderButton(PushButton& button) { button = PushButton::New(); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - button.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) ); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + button.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + button.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f)); } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { - if ( mLabel4 ) + if(mLabel4) { - UnparentAndReset( mLabel4 ); + UnparentAndReset(mLabel4); } - if ( !mContainer4 ) + if(!mContainer4) { - CreateContainer ( mContainer4 , mLayoutSize); - Window window = mApplication.GetWindow(); + CreateContainer(mContainer4, mLayoutSize); + Window window = mApplication.GetWindow(); Vector2 windowSize = window.GetSize(); - mContainer4.SetProperty( Actor::Property::POSITION, Vector2( 0, windowSize.height*0.25f*3 )); - window.Add( mContainer4 ); + mContainer4.SetProperty(Actor::Property::POSITION, Vector2(0, windowSize.height * 0.25f * 3)); + window.Add(mContainer4); // Info - CreateContainer ( mContainer4Info , mLayoutSize ); - mContainer4Info.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - mContainer4.Add( mContainer4Info ); - CreateTextLabel ( mLabel4Info, "system free", Color::BLACK, true ); - mContainer4Info.Add ( mLabel4Info ); + CreateContainer(mContainer4Info, mLayoutSize); + mContainer4Info.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + mContainer4.Add(mContainer4Info); + CreateTextLabel(mLabel4Info, "system free", Color::BLACK, true); + mContainer4Info.Add(mLabel4Info); } - if ( mToggle ) + if(mToggle) { - CreateTextLabel ( mLabel4, LABEL_TEXT_KOREAN, Color::WHITE ); + CreateTextLabel(mLabel4, LABEL_TEXT_KOREAN, Color::WHITE); mToggle = false; } else { - CreateTextLabel ( mLabel4, LABEL_TEXT_MIXED, Color::WHITE ); + CreateTextLabel(mLabel4, LABEL_TEXT_MIXED, Color::WHITE); mToggle = true; } - mContainer4.Add( mLabel4 ); + mContainer4.Add(mLabel4); return true; } @@ -146,59 +145,59 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { - Window window = application.GetWindow(); + Window window = application.GetWindow(); Vector2 windowSize = window.GetSize(); window.KeyEventSignal().Connect(this, &TextFontsExample::OnKeyEvent); - CreateFolderButton ( mButton ); - mButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mButton.ClickedSignal().Connect( this, &TextFontsExample::OnButtonClicked ); - window.Add( mButton ); + CreateFolderButton(mButton); + mButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mButton.ClickedSignal().Connect(this, &TextFontsExample::OnButtonClicked); + window.Add(mButton); - mLayoutSize = Vector2( windowSize.width*0.5f, windowSize.height*0.10f ); - CreateContainer ( mContainer , mLayoutSize); - CreateContainer ( mContainer2 , mLayoutSize ); - CreateContainer ( mContainer3 , mLayoutSize ); + mLayoutSize = Vector2(windowSize.width * 0.5f, windowSize.height * 0.10f); + CreateContainer(mContainer, mLayoutSize); + CreateContainer(mContainer2, mLayoutSize); + CreateContainer(mContainer3, mLayoutSize); // Info about Text Label and if font should be fixed or free to change with system - CreateContainer ( mContainerInfo , mLayoutSize ); - CreateContainer ( mContainer2Info , mLayoutSize ); - CreateContainer ( mContainer3Info , mLayoutSize ); - mContainerInfo.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - mContainer2Info.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - mContainer3Info.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - mContainer.Add( mContainerInfo ); - mContainer2.Add( mContainer2Info ); - mContainer3.Add( mContainer3Info ); - CreateTextLabel ( mLabelInfo, "system free", Color::BLACK, true ); - CreateTextLabel ( mLabel2Info, "json fixed", Color::BLACK, true ); - CreateTextLabel ( mLabel3Info, "SetProp fixed", Color::BLACK, true ); - mContainerInfo.Add( mLabelInfo ); - mContainer2Info.Add( mLabel2Info ); - mContainer3Info.Add( mLabel3Info ); - - window.Add( mContainer ); - window.Add( mContainer2 ); - window.Add( mContainer3 ); - - CreateTextLabel ( mLabel, LABEL_TEXT, Color::WHITE ); - - CreateTextLabel ( mLabel2, LABEL_TEXT, Color::WHITE ); + CreateContainer(mContainerInfo, mLayoutSize); + CreateContainer(mContainer2Info, mLayoutSize); + CreateContainer(mContainer3Info, mLayoutSize); + mContainerInfo.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + mContainer2Info.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + mContainer3Info.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + mContainer.Add(mContainerInfo); + mContainer2.Add(mContainer2Info); + mContainer3.Add(mContainer3Info); + CreateTextLabel(mLabelInfo, "system free", Color::BLACK, true); + CreateTextLabel(mLabel2Info, "json fixed", Color::BLACK, true); + CreateTextLabel(mLabel3Info, "SetProp fixed", Color::BLACK, true); + mContainerInfo.Add(mLabelInfo); + mContainer2Info.Add(mLabel2Info); + mContainer3Info.Add(mLabel3Info); + + window.Add(mContainer); + window.Add(mContainer2); + window.Add(mContainer3); + + CreateTextLabel(mLabel, LABEL_TEXT, Color::WHITE); + + CreateTextLabel(mLabel2, LABEL_TEXT, Color::WHITE); mLabel2.SetStyleName("TextLabelRosemary"); - CreateTextLabel ( mLabel3, LABEL_TEXT, Color::WHITE ); - mLabel3.SetProperty( TextLabel::Property::FONT_FAMILY, "SamsungOneUI" ); + CreateTextLabel(mLabel3, LABEL_TEXT, Color::WHITE); + mLabel3.SetProperty(TextLabel::Property::FONT_FAMILY, "SamsungOneUI"); - mContainer.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 )); - mContainer2.SetProperty( Actor::Property::POSITION, Vector2( 0, windowSize.height*0.25f )); - mContainer3.SetProperty( Actor::Property::POSITION, Vector2( 0, windowSize.height*0.25f*2 )); + mContainer.SetProperty(Actor::Property::POSITION, Vector2(0, 0)); + mContainer2.SetProperty(Actor::Property::POSITION, Vector2(0, windowSize.height * 0.25f)); + mContainer3.SetProperty(Actor::Property::POSITION, Vector2(0, windowSize.height * 0.25f * 2)); - mContainer.Add( mLabel ); - mContainer2.Add( mLabel2 ); - mContainer3.Add( mLabel3 ); + mContainer.Add(mLabel); + mContainer2.Add(mLabel2); + mContainer3.Add(mLabel3); } /** @@ -208,7 +207,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -216,7 +215,6 @@ public: } private: - Application& mApplication; PushButton mButton; @@ -247,10 +245,10 @@ private: bool mToggle; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - TextFontsExample test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + TextFontsExample test(application); application.MainLoop(); return 0; } diff --git a/examples/text-label-emojis/emoji-strings.h b/examples/text-label-emojis/emoji-strings.h index 99822a8..49e1b51 100644 --- a/examples/text-label-emojis/emoji-strings.h +++ b/examples/text-label-emojis/emoji-strings.h @@ -2,7 +2,7 @@ #define DALI_DEMO_EMOJI_STRINGS_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,39 +23,39 @@ namespace EmojiStrings { - struct Emoji - { - uint32_t mUnicode; - std::string mUTF8; - std::string mDescription; - }; +struct Emoji +{ + uint32_t mUnicode; + std::string mUTF8; + std::string mDescription; +}; - const Emoji EMOJIS[] = { +const Emoji EMOJIS[] = { - { 0x1F601,"\xF0\x9F\x98\x81","grinning face with smiling eyes" }, - { 0x1F602,"\xF0\x9F\x98\x82","face with tears of joy" }, - //{ 0x1F603,"\xF0\x9F\x98\x83","smiling face with open mouth" }, - //{ 0x1F604,"\xF0\x9F\x98\x84","smiling face with open mouth and smiling eyes" }, - { 0x1F605,"\xF0\x9F\x98\x85","smiling face with open mouth and cold sweat" }, - //{ 0x1F606,"\xF0\x9F\x98\x86","smiling face with open mouth and tightly-closed eyes" }, - { 0x1F609,"\xF0\x9F\x98\x89","winking face" }, - { 0x1F60A,"\xF0\x9F\x98\x8A","smiling face with smiling eyes" }, - { 0x1F60B,"\xF0\x9F\x98\x8B","face savouring delicious food" }, - { 0x1F60C,"\xF0\x9F\x98\x8C","relieved face" }, - { 0x1F60D,"\xF0\x9F\x98\x8D","smiling face with heart-shaped eyes" }, - { 0x1F60F,"\xF0\x9F\x98\x8F","smirking face" }, - //{ 0x1F612,"\xF0\x9F\x98\x92","unamused face" }, - //{ 0x1F613,"\xF0\x9F\x98\x93","face with cold sweat" }, - //{ 0x1F614,"\xF0\x9F\x98\x94","pensive face" }, - //{ 0x1F616,"\xF0\x9F\x98\x96","confounded face" }, - { 0x1F618,"\xF0\x9F\x98\x98","face throwing a kiss" }, - { 0x1F61A,"\xF0\x9F\x98\x9A","kissing face with closed eyes" }, - //{ 0x1F61C,"\xF0\x9F\x98\x9C","face with stuck-out tongue and winking eye" }, - //{ 0x1F61D,"\xF0\x9F\x98\x9D","face with stuck-out tongue and tightly-closed eyes" }, - //{ 0x1F61E,"\xF0\x9F\x98\x9E","disappointed face" }, - { 0x1F620,"\xF0\x9F\x98\xA0","angry face" }, + {0x1F601, "\xF0\x9F\x98\x81", "grinning face with smiling eyes"}, + {0x1F602, "\xF0\x9F\x98\x82", "face with tears of joy"}, + //{ 0x1F603,"\xF0\x9F\x98\x83","smiling face with open mouth" }, + //{ 0x1F604,"\xF0\x9F\x98\x84","smiling face with open mouth and smiling eyes" }, + {0x1F605, "\xF0\x9F\x98\x85", "smiling face with open mouth and cold sweat"}, + //{ 0x1F606,"\xF0\x9F\x98\x86","smiling face with open mouth and tightly-closed eyes" }, + {0x1F609, "\xF0\x9F\x98\x89", "winking face"}, + {0x1F60A, "\xF0\x9F\x98\x8A", "smiling face with smiling eyes"}, + {0x1F60B, "\xF0\x9F\x98\x8B", "face savouring delicious food"}, + {0x1F60C, "\xF0\x9F\x98\x8C", "relieved face"}, + {0x1F60D, "\xF0\x9F\x98\x8D", "smiling face with heart-shaped eyes"}, + {0x1F60F, "\xF0\x9F\x98\x8F", "smirking face"}, + //{ 0x1F612,"\xF0\x9F\x98\x92","unamused face" }, + //{ 0x1F613,"\xF0\x9F\x98\x93","face with cold sweat" }, + //{ 0x1F614,"\xF0\x9F\x98\x94","pensive face" }, + //{ 0x1F616,"\xF0\x9F\x98\x96","confounded face" }, + {0x1F618, "\xF0\x9F\x98\x98", "face throwing a kiss"}, + {0x1F61A, "\xF0\x9F\x98\x9A", "kissing face with closed eyes"}, + //{ 0x1F61C,"\xF0\x9F\x98\x9C","face with stuck-out tongue and winking eye" }, + //{ 0x1F61D,"\xF0\x9F\x98\x9D","face with stuck-out tongue and tightly-closed eyes" }, + //{ 0x1F61E,"\xF0\x9F\x98\x9E","disappointed face" }, + {0x1F620, "\xF0\x9F\x98\xA0", "angry face"}, - /* + /* { "POUTING FACE", { "CRYING FACE", { "PERSEVERING FACE", @@ -94,10 +94,10 @@ namespace EmojiStrings { "PERSON WITH FOLDED HANDS", */ - }; +}; - const unsigned int NUMBER_OF_EMOJIS = 12; +const unsigned int NUMBER_OF_EMOJIS = 12; -} // EmojiStrings +} // namespace EmojiStrings #endif // DALI_DEMO_EMOJI_STRINGS_H diff --git a/examples/text-label-emojis/text-label-emojis.cpp b/examples/text-label-emojis/text-label-emojis.cpp index a9801e4..21f5907 100644 --- a/examples/text-label-emojis/text-label-emojis.cpp +++ b/examples/text-label-emojis/text-label-emojis.cpp @@ -27,7 +27,7 @@ using namespace Dali; using namespace Dali::Toolkit; using namespace EmojiStrings; - // TODO Need to expose Text::RENDER..... +// TODO Need to expose Text::RENDER..... const int ATLAS_RENDERER = 0; // This example shows how to create and display Hello World! using a simple TextActor @@ -35,17 +35,16 @@ const int ATLAS_RENDERER = 0; class EmojiExample : public ConnectionTracker { public: - typedef uint32_t SizeType; - EmojiExample( Application& application ) - : mApplication( application ), - mLastPoint( 0.0f ) + EmojiExample(Application& application) + : mApplication(application), + mLastPoint(0.0f) { std::cout << "EmoticonController::EmoticonController" << std::endl; // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &EmojiExample::Create ); + mApplication.InitSignal().Connect(this, &EmojiExample::Create); } ~EmojiExample() @@ -54,54 +53,54 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); window.KeyEventSignal().Connect(this, &EmojiExample::OnKeyEvent); - mTableView = Toolkit::TableView::New( NUMBER_OF_EMOJIS, 1 ); - mTableView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mTableView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mTableView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mTableView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mTableView.TouchedSignal().Connect( this, &EmojiExample::OnTouch ); - window.Add( mTableView ); + mTableView = Toolkit::TableView::New(NUMBER_OF_EMOJIS, 1); + mTableView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mTableView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mTableView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mTableView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mTableView.TouchedSignal().Connect(this, &EmojiExample::OnTouch); + window.Add(mTableView); - for( unsigned int index = 0u; index < NUMBER_OF_EMOJIS; ++index ) + for(unsigned int index = 0u; index < NUMBER_OF_EMOJIS; ++index) { - const Emoji& emoji = EMOJIS[index]; - const std::string text = emoji.mUTF8 + " " + emoji.mDescription; + const Emoji& emoji = EMOJIS[index]; + const std::string text = emoji.mUTF8 + " " + emoji.mDescription; - TextLabel label = TextLabel::New( text ); - label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - label.SetProperty( TextLabel::Property::MULTI_LINE, true ); + TextLabel label = TextLabel::New(text); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + label.SetProperty(TextLabel::Property::MULTI_LINE, true); - mTableView.SetFitHeight( index ); - mTableView.AddChild( label, Toolkit::TableView::CellPosition( index, 0 ) ); + mTableView.SetFitHeight(index); + mTableView.AddChild(label, Toolkit::TableView::CellPosition(index, 0)); } } - bool OnTouch( Actor actor, const TouchEvent& event ) + bool OnTouch(Actor actor, const TouchEvent& event) { - if( 1u == event.GetPointCount() ) + if(1u == event.GetPointCount()) { - const PointState::Type state = event.GetState( 0 ); + const PointState::Type state = event.GetState(0); // Clamp to integer values; this is to reduce flicking due to pixel misalignment - const float localPoint = static_cast( static_cast( event.GetLocalPosition( 0 ).y ) ); + const float localPoint = static_cast(static_cast(event.GetLocalPosition(0).y)); - if( PointState::DOWN == state ) + if(PointState::DOWN == state) { mLastPoint = localPoint; - mAnimation = Animation::New( 0.25f ); + mAnimation = Animation::New(0.25f); } - else if( PointState::MOTION == state ) + else if(PointState::MOTION == state) { - if( mAnimation ) + if(mAnimation) { - mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR ); + mAnimation.AnimateBy(Property(mTableView, Actor::Property::POSITION), Vector3(0.f, localPoint - mLastPoint, 0.f), AlphaFunction::LINEAR); mAnimation.Play(); mLastPoint = localPoint; } @@ -118,25 +117,24 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } } } - private: - Application& mApplication; - TableView mTableView; - Animation mAnimation; - float mLastPoint; + Application& mApplication; + TableView mTableView; + Animation mAnimation; + float mLastPoint; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - EmojiExample test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + EmojiExample test(application); application.MainLoop(); return 0; } diff --git a/examples/text-label-multi-language/text-label-multi-language-example.cpp b/examples/text-label-multi-language/text-label-multi-language-example.cpp index abe62fe..82cc902 100644 --- a/examples/text-label-multi-language/text-label-multi-language-example.cpp +++ b/examples/text-label-multi-language/text-label-multi-language-example.cpp @@ -38,13 +38,12 @@ using namespace MultiLanguageStrings; class TextLabelMultiLanguageExample : public ConnectionTracker { public: - - TextLabelMultiLanguageExample( Application& application ) - : mApplication( application ), - mLastPoint( 0.f ) + TextLabelMultiLanguageExample(Application& application) + : mApplication(application), + mLastPoint(0.f) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextLabelMultiLanguageExample::Create ); + mApplication.InitSignal().Connect(this, &TextLabelMultiLanguageExample::Create); } ~TextLabelMultiLanguageExample() @@ -55,55 +54,55 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); - mTableView = Toolkit::TableView::New( NUMBER_OF_LANGUAGES, 1 ); - mTableView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mTableView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mTableView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mTableView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mTableView.TouchedSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouch ); - window.Add( mTableView ); + mTableView = Toolkit::TableView::New(NUMBER_OF_LANGUAGES, 1); + mTableView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mTableView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mTableView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mTableView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mTableView.TouchedSignal().Connect(this, &TextLabelMultiLanguageExample::OnTouch); + window.Add(mTableView); - for( unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index ) + for(unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index) { const Language& language = LANGUAGES[index]; TextLabel label = TextLabel::New(); - label.SetProperty( TextLabel::Property::MULTI_LINE, true ); + label.SetProperty(TextLabel::Property::MULTI_LINE, true); const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text; - label.SetProperty( TextLabel::Property::TEXT, text ); + label.SetProperty(TextLabel::Property::TEXT, text); - mTableView.SetFitHeight( index ); - mTableView.AddChild( label, Toolkit::TableView::CellPosition( index, 0 ) ); + mTableView.SetFitHeight(index); + mTableView.AddChild(label, Toolkit::TableView::CellPosition(index, 0)); } } - bool OnTouch( Actor actor, const TouchEvent& event ) + bool OnTouch(Actor actor, const TouchEvent& event) { - if( 1u == event.GetPointCount() ) + if(1u == event.GetPointCount()) { - const PointState::Type state = event.GetState( 0 ); + const PointState::Type state = event.GetState(0); // Clamp to integer values; this is to reduce flicking due to pixel misalignment - const float localPoint = static_cast( static_cast( event.GetLocalPosition( 0 ).y ) ); + const float localPoint = static_cast(static_cast(event.GetLocalPosition(0).y)); - if( PointState::DOWN == state ) + if(PointState::DOWN == state) { mLastPoint = localPoint; - mAnimation = Animation::New( 0.25f ); + mAnimation = Animation::New(0.25f); } - else if( PointState::MOTION == state ) + else if(PointState::MOTION == state) { - if( mAnimation ) + if(mAnimation) { - mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR ); + mAnimation.AnimateBy(Property(mTableView, Actor::Property::POSITION), Vector3(0.f, localPoint - mLastPoint, 0.f), AlphaFunction::LINEAR); mAnimation.Play(); mLastPoint = localPoint; } @@ -120,7 +119,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -128,17 +127,16 @@ public: } private: - - Application& mApplication; - TableView mTableView; - Animation mAnimation; - float mLastPoint; + Application& mApplication; + TableView mTableView; + Animation mAnimation; + float mLastPoint; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - TextLabelMultiLanguageExample test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + TextLabelMultiLanguageExample test(application); application.MainLoop(); return 0; } diff --git a/examples/text-label/expanding-buttons-impl.cpp b/examples/text-label/expanding-buttons-impl.cpp index 73003fc..1adc86e 100644 --- a/examples/text-label/expanding-buttons-impl.cpp +++ b/examples/text-label/expanding-buttons-impl.cpp @@ -27,33 +27,30 @@ namespace Demo { namespace Internal { - namespace { - const unsigned int GAP_BETWEEN_BUTTONS = 3; -const char* const STYLES_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_Main.png"; +const char* const STYLES_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_Main.png"; const char* const TICK_IMAGE_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_02.png"; /** * Unparent the given number of registered controls from the supplied Vector of controls. */ -void ResetControls( std::vector< WeakHandle< Control > > controls, unsigned int numberOfButtons ) +void ResetControls(std::vector > controls, unsigned int numberOfButtons) { - for( unsigned int index = 0; index < numberOfButtons; index++) + for(unsigned int index = 0; index < numberOfButtons; index++) { Dali::Toolkit::Control control = controls[index].GetHandle(); - UnparentAndReset( control ); + UnparentAndReset(control); } } } // anonymous namespace - Internal::ExpandingButtons::ExpandingButtons() -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), - mStyleButtonsHidden( false ) +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), + mStyleButtonsHidden(false) { } @@ -63,8 +60,8 @@ Internal::ExpandingButtons::~ExpandingButtons() Demo::ExpandingButtons Internal::ExpandingButtons::New() { - IntrusivePtr impl = new Internal::ExpandingButtons(); - Demo::ExpandingButtons handle = Demo::ExpandingButtons( *impl ); + IntrusivePtr impl = new Internal::ExpandingButtons(); + Demo::ExpandingButtons handle = Demo::ExpandingButtons(*impl); impl->Initialize(); return handle; } @@ -73,43 +70,43 @@ void ExpandingButtons::OnInitialize() { mExpandButton = PushButton::New(); - mExpandButton.ClickedSignal().Connect( this, &ExpandingButtons::OnExpandButtonClicked ); - mExpandButton.SetProperty( Button::Property::TOGGLABLE, true ); - mExpandButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, STYLES_IMAGE ); // Default for Styles - mExpandButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TICK_IMAGE_IMAGE ); - mExpandButton.SetProperty( Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - Self().Add( mExpandButton ); + mExpandButton.ClickedSignal().Connect(this, &ExpandingButtons::OnExpandButtonClicked); + mExpandButton.SetProperty(Button::Property::TOGGLABLE, true); + mExpandButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, STYLES_IMAGE); // Default for Styles + mExpandButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TICK_IMAGE_IMAGE); + mExpandButton.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + Self().Add(mExpandButton); } -void ExpandingButtons::OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container ) +void ExpandingButtons::OnRelayout(const Dali::Vector2& targetSize, Dali::RelayoutContainer& container) { mButtonSize = targetSize; - mExpandButton.SetProperty( Actor::Property::SIZE, targetSize ); + mExpandButton.SetProperty(Actor::Property::SIZE, targetSize); } -void ExpandingButtons::RegisterButton( Dali::Toolkit::Control& control ) +void ExpandingButtons::RegisterButton(Dali::Toolkit::Control& control) { - mExpandingControls.push_back( control ); + mExpandingControls.push_back(control); } void ExpandingButtons::Expand() { - if ( !mExpandCollapseAnimation ) + if(!mExpandCollapseAnimation) { - mExpandCollapseAnimation = Animation::New( 0.2f ); - mExpandCollapseAnimation.FinishedSignal().Connect( this, &ExpandingButtons::OnExpandAnimationFinished ); + mExpandCollapseAnimation = Animation::New(0.2f); + mExpandCollapseAnimation.FinishedSignal().Connect(this, &ExpandingButtons::OnExpandAnimationFinished); } unsigned int numberOfControls = mExpandingControls.size(); - for( unsigned int index = 0; index < numberOfControls; index++ ) + for(unsigned int index = 0; index < numberOfControls; index++) { Dali::Toolkit::Control control = mExpandingControls[index].GetHandle(); - if ( control ) + if(control) { - Self().Add( control ); - AlphaFunction focusedAlphaFunction = AlphaFunction( Vector2 ( 0.32f, 0.08f ), Vector2( 0.38f, 1.72f ) ); - mExpandCollapseAnimation.AnimateTo( Property( control, Actor::Property::POSITION_X ), mButtonSize.width + ( mButtonSize.width + GAP_BETWEEN_BUTTONS ) * (index) , focusedAlphaFunction ); + Self().Add(control); + AlphaFunction focusedAlphaFunction = AlphaFunction(Vector2(0.32f, 0.08f), Vector2(0.38f, 1.72f)); + mExpandCollapseAnimation.AnimateTo(Property(control, Actor::Property::POSITION_X), mButtonSize.width + (mButtonSize.width + GAP_BETWEEN_BUTTONS) * (index), focusedAlphaFunction); } } Self().RaiseToTop(); @@ -117,12 +114,12 @@ void ExpandingButtons::Expand() mExpandCollapseAnimation.Play(); } -void ExpandingButtons::OnExpandAnimationFinished( Animation& animation ) +void ExpandingButtons::OnExpandAnimationFinished(Animation& animation) { - if ( mStyleButtonsHidden ) + if(mStyleButtonsHidden) { unsigned int numberOfControls = mExpandingControls.size(); - ResetControls( mExpandingControls, numberOfControls ); + ResetControls(mExpandingControls, numberOfControls); animation.Clear(); animation.Reset(); } @@ -130,22 +127,22 @@ void ExpandingButtons::OnExpandAnimationFinished( Animation& animation ) void ExpandingButtons::Collapse() { - Demo::ExpandingButtons handle( GetOwner() ); - mCollapsedSignal.Emit( handle ); + Demo::ExpandingButtons handle(GetOwner()); + mCollapsedSignal.Emit(handle); mStyleButtonsHidden = true; - mExpandButton.SetProperty(Button::Property::SELECTED, false ); + mExpandButton.SetProperty(Button::Property::SELECTED, false); - if ( mExpandCollapseAnimation ) + if(mExpandCollapseAnimation) { unsigned int numberOfControls = mExpandingControls.size(); - for ( unsigned int index = 0; index < numberOfControls; index++ ) + for(unsigned int index = 0; index < numberOfControls; index++) { Dali::Toolkit::Control control = mExpandingControls[index].GetHandle(); - if ( control ) + if(control) { - mExpandCollapseAnimation.AnimateTo( Property( control, Actor::Property::POSITION_X ), 0.0f ); + mExpandCollapseAnimation.AnimateTo(Property(control, Actor::Property::POSITION_X), 0.0f); } } mExpandCollapseAnimation.Play(); @@ -153,9 +150,9 @@ void ExpandingButtons::Collapse() } // Hide or show (expand) buttons if expand button pressed -bool ExpandingButtons::OnExpandButtonClicked( Toolkit::Button button ) +bool ExpandingButtons::OnExpandButtonClicked(Toolkit::Button button) { - if ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get() ) + if(button.GetProperty(Toolkit::Button::Property::SELECTED).Get()) { Expand(); } @@ -167,11 +164,10 @@ bool ExpandingButtons::OnExpandButtonClicked( Toolkit::Button button ) return true; } - Demo::ExpandingButtons::ExpandingButtonsSignalType& ExpandingButtons::CollapsingSignal() { return mCollapsedSignal; } -} // Internal -} // Demo +} // namespace Internal +} // namespace Demo diff --git a/examples/text-label/expanding-buttons-impl.h b/examples/text-label/expanding-buttons-impl.h index a432914..9413390 100644 --- a/examples/text-label/expanding-buttons-impl.h +++ b/examples/text-label/expanding-buttons-impl.h @@ -2,7 +2,7 @@ #define DALI_DEMO_INTERNAL_EXPANDING_BUTTONS_IMPL_H /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +17,17 @@ * limitations under the License. */ -#include "expanding-buttons.h" #include #include +#include "expanding-buttons.h" namespace Demo { - namespace Internal // To use TypeRegistry, handle and body classes need the same name { - class ExpandingButtons : public Dali::Toolkit::Internal::Control { public: - /** * Instantiate a new ExpandingButtons object */ @@ -47,19 +44,16 @@ public: ~ExpandingButtons(); public: // API - - void RegisterButton( Dali::Toolkit::Control& control ); + void RegisterButton(Dali::Toolkit::Control& control); void Expand(); void Collapse(); public: // Signals - Demo::ExpandingButtons::ExpandingButtonsSignalType& CollapsingSignal(); private: // From Control - /** * @copydoc Toolkit::Control::OnInitialize() */ @@ -68,29 +62,26 @@ private: // From Control /** * @copydoc Toolkit::Control::OnRelayout() */ - virtual void OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container ) override; + virtual void OnRelayout(const Dali::Vector2& targetSize, Dali::RelayoutContainer& container) override; private: - /** * Callback when expand or collapse animation ends. */ - void OnExpandAnimationFinished( Dali::Animation& animation ); + void OnExpandAnimationFinished(Dali::Animation& animation); /** * Called when the main button clicked. */ - bool OnExpandButtonClicked( Dali::Toolkit::Button button ); - + bool OnExpandButtonClicked(Dali::Toolkit::Button button); private: //undefined - ExpandingButtons( const ExpandingButtons& ); - ExpandingButtons& operator=( const ExpandingButtons& ); + ExpandingButtons(const ExpandingButtons&); + ExpandingButtons& operator=(const ExpandingButtons&); private: - - std::vector< Dali::WeakHandle< Dali::Toolkit::Control> > mExpandingControls; + std::vector > mExpandingControls; Dali::Animation mExpandCollapseAnimation; @@ -103,22 +94,22 @@ private: Demo::ExpandingButtons::ExpandingButtonsSignalType mCollapsedSignal; }; -} // Internal +} // namespace Internal -inline Internal::ExpandingButtons& GetImpl( Demo::ExpandingButtons& handle ) +inline Internal::ExpandingButtons& GetImpl(Demo::ExpandingButtons& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -inline const Internal::ExpandingButtons& GetImpl( const Demo::ExpandingButtons& handle ) +inline const Internal::ExpandingButtons& GetImpl(const Demo::ExpandingButtons& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); const Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -} // Demo +} // namespace Demo #endif // DALI_DEMO_INTERNAL_EXPANDING_BUTTONS_IMPL_H diff --git a/examples/text-label/expanding-buttons.cpp b/examples/text-label/expanding-buttons.cpp index d733182..ec7dff6 100644 --- a/examples/text-label/expanding-buttons.cpp +++ b/examples/text-label/expanding-buttons.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,25 @@ * limitations under the License. */ -#include "expanding-buttons-impl.h" #include "expanding-buttons.h" +#include "expanding-buttons-impl.h" namespace Demo { - ExpandingButtons::ExpandingButtons() { } -ExpandingButtons::ExpandingButtons( const ExpandingButtons& expandingButtons ) -: Control( expandingButtons ) +ExpandingButtons::ExpandingButtons(const ExpandingButtons& expandingButtons) +: Control(expandingButtons) { } -ExpandingButtons& ExpandingButtons::operator= ( const ExpandingButtons& rhs ) +ExpandingButtons& ExpandingButtons::operator=(const ExpandingButtons& rhs) { - if( &rhs != this ) + if(&rhs != this) { - Control::operator=( rhs ); + Control::operator=(rhs); } return *this; } @@ -48,14 +47,14 @@ ExpandingButtons ExpandingButtons::New() return expandingButtons; } -ExpandingButtons ExpandingButtons::DownCast( BaseHandle handle ) +ExpandingButtons ExpandingButtons::DownCast(BaseHandle handle) { - return Control::DownCast< ExpandingButtons, Internal::ExpandingButtons > ( handle ); + return Control::DownCast(handle); } -void ExpandingButtons::RegisterButton( Control& control ) +void ExpandingButtons::RegisterButton(Control& control) { - GetImpl(*this).RegisterButton( control ); + GetImpl(*this).RegisterButton(control); } void ExpandingButtons::Expand() @@ -72,16 +71,15 @@ Demo::ExpandingButtons::ExpandingButtonsSignalType& ExpandingButtons::Collapsing return GetImpl(*this).CollapsingSignal(); } -ExpandingButtons::ExpandingButtons( Internal::ExpandingButtons& implementation ) -: Control( implementation ) +ExpandingButtons::ExpandingButtons(Internal::ExpandingButtons& implementation) +: Control(implementation) { } -ExpandingButtons::ExpandingButtons( Dali::Internal::CustomActor* internal ) -: Control( internal ) +ExpandingButtons::ExpandingButtons(Dali::Internal::CustomActor* internal) +: Control(internal) { - VerifyCustomActorPointer< Internal::ExpandingButtons >( internal ) ; + VerifyCustomActorPointer(internal); } - } //namespace Demo diff --git a/examples/text-label/expanding-buttons.h b/examples/text-label/expanding-buttons.h index 1ccede8..4a78270 100644 --- a/examples/text-label/expanding-buttons.h +++ b/examples/text-label/expanding-buttons.h @@ -2,7 +2,7 @@ #define DALI_DEMO_EXPANDING_BUTTONS_CONTROL_H /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ namespace Demo { - namespace Internal { class ExpandingButtons; @@ -32,10 +31,7 @@ class ExpandingButtons; */ class ExpandingButtons : public Dali::Toolkit::Control { - - public: // Construction / destruction - /** * Create an uninitialized handle */ @@ -55,24 +51,23 @@ public: // Construction / destruction /** * Copy Constructor */ - ExpandingButtons( const ExpandingButtons& expandingButtons ); + ExpandingButtons(const ExpandingButtons& expandingButtons); /** * Assignment Operator */ - ExpandingButtons& operator=( const ExpandingButtons& expandingButtons ); + ExpandingButtons& operator=(const ExpandingButtons& expandingButtons); /** * Downcast */ - static ExpandingButtons DownCast( BaseHandle handle ); + static ExpandingButtons DownCast(BaseHandle handle); public: // API - /** * Add a control (button) to the Expanding button bar. Will be displayed in order of addition. */ - void RegisterButton( Control& control ); + void RegisterButton(Control& control); /** * Expand the registered buttons out from the main button. @@ -85,11 +80,10 @@ public: // API void Collapse(); public: // Signals - - /** + /** * ExpandingButtons signal type */ - typedef Dali::Signal< bool ( ExpandingButtons ) > ExpandingButtonsSignalType; + typedef Dali::Signal ExpandingButtonsSignalType; /** * This signal is emitted when the button is going to collapse. @@ -97,16 +91,15 @@ public: // Signals ExpandingButtonsSignalType& CollapsingSignal(); public: // Not for public use - /** * Create a handle from an implementation */ - ExpandingButtons( Internal::ExpandingButtons& implementation ); + ExpandingButtons(Internal::ExpandingButtons& implementation); /** * Allow the creation of an ExpandingButtons handle from an internal CustomActor pointer */ - ExpandingButtons( Dali::Internal::CustomActor* internal ); + ExpandingButtons(Dali::Internal::CustomActor* internal); }; } // namespace Demo diff --git a/examples/text-label/text-label-example.cpp b/examples/text-label/text-label-example.cpp old mode 100755 new mode 100644 index e50579d..ff9db66 --- a/examples/text-label/text-label-example.cpp +++ b/examples/text-label/text-label-example.cpp @@ -21,17 +21,17 @@ */ // EXTERNAL INCLUDES -#include -#include +#include #include #include -#include +#include +#include #include // INTERNAL INCLUDES +#include "expanding-buttons.h" #include "shared/multi-language-strings.h" #include "shared/view.h" -#include "expanding-buttons.h" using namespace Dali; using namespace Dali::Toolkit; @@ -39,47 +39,44 @@ using namespace MultiLanguageStrings; namespace { -const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png"; +const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png"; const char* const STYLE_SELECTED_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_03.png"; const char* BUTTON_IMAGES[] = -{ - DEMO_IMAGE_DIR "FontStyleButton_Colour.png", - DEMO_IMAGE_DIR "FontStyleButton_Outline.png", - DEMO_IMAGE_DIR "FontStyleButton_Shadow.png", - DEMO_IMAGE_DIR "FontStyleButton_Background.png" -}; - -const unsigned int KEY_ZERO = 10; -const unsigned int KEY_ONE = 11; -const unsigned int KEY_A = 38; -const unsigned int KEY_F = 41; -const unsigned int KEY_H = 43; -const unsigned int KEY_U = 30; -const unsigned int KEY_V = 55; -const unsigned int KEY_M = 58; -const unsigned int KEY_L = 46; -const unsigned int KEY_S = 39; -const unsigned int KEY_PLUS = 21; + { + DEMO_IMAGE_DIR "FontStyleButton_Colour.png", + DEMO_IMAGE_DIR "FontStyleButton_Outline.png", + DEMO_IMAGE_DIR "FontStyleButton_Shadow.png", + DEMO_IMAGE_DIR "FontStyleButton_Background.png"}; + +const unsigned int KEY_ZERO = 10; +const unsigned int KEY_ONE = 11; +const unsigned int KEY_A = 38; +const unsigned int KEY_F = 41; +const unsigned int KEY_H = 43; +const unsigned int KEY_U = 30; +const unsigned int KEY_V = 55; +const unsigned int KEY_M = 58; +const unsigned int KEY_L = 46; +const unsigned int KEY_S = 39; +const unsigned int KEY_PLUS = 21; const unsigned int KEY_MINUS = 20; const char* H_ALIGNMENT_STRING_TABLE[] = -{ - "BEGIN", - "CENTER", - "END" -}; + { + "BEGIN", + "CENTER", + "END"}; -const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof( H_ALIGNMENT_STRING_TABLE ) / sizeof( H_ALIGNMENT_STRING_TABLE[0u] ); +const unsigned int H_ALIGNMENT_STRING_COUNT = sizeof(H_ALIGNMENT_STRING_TABLE) / sizeof(H_ALIGNMENT_STRING_TABLE[0u]); const char* V_ALIGNMENT_STRING_TABLE[] = -{ - "TOP", - "CENTER", - "BOTTOM" -}; + { + "TOP", + "CENTER", + "BOTTOM"}; -const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof( V_ALIGNMENT_STRING_TABLE ) / sizeof( V_ALIGNMENT_STRING_TABLE[0u] ); +const unsigned int V_ALIGNMENT_STRING_COUNT = sizeof(V_ALIGNMENT_STRING_TABLE) / sizeof(V_ALIGNMENT_STRING_TABLE[0u]); enum StyleType { @@ -91,15 +88,15 @@ enum StyleType }; const Vector4 AVAILABLE_COLORS[] = -{ - Color::GREEN, - Color::BLUE, - Color::RED, - Color::CYAN, - Color::WHITE // Used as clear + { + Color::GREEN, + Color::BLUE, + Color::RED, + Color::CYAN, + Color::WHITE // Used as clear }; -const unsigned int NUMBER_OF_COLORS = sizeof( AVAILABLE_COLORS ) / sizeof( AVAILABLE_COLORS[0u] ); +const unsigned int NUMBER_OF_COLORS = sizeof(AVAILABLE_COLORS) / sizeof(AVAILABLE_COLORS[0u]); int ConvertToEven(int value) { @@ -115,16 +112,16 @@ struct HSVColorConstraint { } - void operator()(Vector3& current, const PropertyInputContainer& inputs ) + void operator()(Vector3& current, const PropertyInputContainer& inputs) { current = hsv2rgb(Vector3(inputs[0]->GetFloat(), saturation, value)); } Vector3 hsv2rgb(Vector3 colorHSV) { - float r=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x)-1)); - float g=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x-2.09439)-1)); - float b=colorHSV.z*(1+colorHSV.y*(cos(colorHSV.x+2.09439)-1)); + float r = colorHSV.z * (1 + colorHSV.y * (cos(colorHSV.x) - 1)); + float g = colorHSV.z * (1 + colorHSV.y * (cos(colorHSV.x - 2.09439) - 1)); + float b = colorHSV.z * (1 + colorHSV.y * (cos(colorHSV.x + 2.09439) - 1)); return Vector3(r, g, b); } float hue; @@ -132,12 +129,11 @@ struct HSVColorConstraint float value; }; -const float STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW = 0.9f; -const float BUTTON_SIZE_RATIO_TO_WINDOW = 0.1f; -const float OUTLINE_WIDTH = 2.0f; -const Vector2 SHADOW_OFFSET = Vector2( 2.0f, 2.0f ); -const int GAP_BETWEEN_BUTTONS = 3; - +const float STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW = 0.9f; +const float BUTTON_SIZE_RATIO_TO_WINDOW = 0.1f; +const float OUTLINE_WIDTH = 2.0f; +const Vector2 SHADOW_OFFSET = Vector2(2.0f, 2.0f); +const int GAP_BETWEEN_BUTTONS = 3; } // anonymous namespace @@ -147,32 +143,31 @@ const int GAP_BETWEEN_BUTTONS = 3; class TextLabelExample : public ConnectionTracker { public: - - TextLabelExample( Application& application ) - : mApplication( application ), + TextLabelExample(Application& application) + : mApplication(application), mLabel(), mSelectedColor(AVAILABLE_COLORS[0]), - mStyleActivatedForColor( NUMBER_OF_STYLES ), + mStyleActivatedForColor(NUMBER_OF_STYLES), mContainer(), mGrabCorner(), mBorder(), mPanGestureDetector(), mLayoutSize(), - mLanguageId( 0u ), - mAlignment( 0u ), - mHueAngleIndex( Property::INVALID_INDEX ), - mOverrideMixColorIndex( Property::INVALID_INDEX ), - mColorButtonsHidden( true ), - mCollapseColorsAndStyles( false ) + mLanguageId(0u), + mAlignment(0u), + mHueAngleIndex(Property::INVALID_INDEX), + mOverrideMixColorIndex(Property::INVALID_INDEX), + mColorButtonsHidden(true), + mCollapseColorsAndStyles(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextLabelExample::Create ); + mApplication.InitSignal().Connect(this, &TextLabelExample::Create); // Set Style flags to inactive - for ( unsigned int i = TEXT_COLOR; i < NUMBER_OF_STYLES; i++ ) + for(unsigned int i = TEXT_COLOR; i < NUMBER_OF_STYLES; i++) { - mStyleActiveState[ i ] = false; - mCurrentStyleColor[i] = AVAILABLE_COLORS[ NUMBER_OF_COLORS - 1 ]; + mStyleActiveState[i] = false; + mCurrentStyleColor[i] = AVAILABLE_COLORS[NUMBER_OF_COLORS - 1]; } } @@ -182,89 +177,89 @@ public: } // Clicking the expanding button shows the registered style buttons. - void SetUpExpandingStyleButtons( Vector2 position ) + void SetUpExpandingStyleButtons(Vector2 position) { mExpandingButtons = Demo::ExpandingButtons::New(); - mExpandingButtons.SetProperty( Actor::Property::POSITION, Vector2( mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW )); - mExpandingButtons.CollapsingSignal().Connect( this, &TextLabelExample::OnExpandingButtonCollapsing ); - mExpandingButtons.SetProperty( Actor::Property::SIZE, mButtonSize ); + mExpandingButtons.SetProperty(Actor::Property::POSITION, Vector2(mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW)); + mExpandingButtons.CollapsingSignal().Connect(this, &TextLabelExample::OnExpandingButtonCollapsing); + mExpandingButtons.SetProperty(Actor::Property::SIZE, mButtonSize); // Creates the buttons to be expanded CreateStyleButtons(); // Register the created buttons with the ExpandingButtons. - for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ ) + for(unsigned int index = 0; index < NUMBER_OF_STYLES; index++) { - mExpandingButtons.RegisterButton( mStyleButtons[index] ); + mExpandingButtons.RegisterButton(mStyleButtons[index]); } } /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent); mWindowSize = window.GetSize(); - mButtonSize = Size( mWindowSize.height * 0.1, mWindowSize.height * 0.1 ); // Button size 1/10 of window height + mButtonSize = Size(mWindowSize.height * 0.1, mWindowSize.height * 0.1); // Button size 1/10 of window height mContainer = Control::New(); - mContainer.SetProperty( Dali::Actor::Property::NAME, "Container" ); - mContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mLayoutSize = Vector2(mWindowSize.width*0.6f, mWindowSize.width*0.6f); - mContainer.SetProperty( Actor::Property::SIZE, mLayoutSize ); - window.Add( mContainer ); + mContainer.SetProperty(Dali::Actor::Property::NAME, "Container"); + mContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mLayoutSize = Vector2(mWindowSize.width * 0.6f, mWindowSize.width * 0.6f); + mContainer.SetProperty(Actor::Property::SIZE, mLayoutSize); + window.Add(mContainer); // Resize the center layout when the corner is grabbed - mGrabCorner = ImageView::New( BACKGROUND_IMAGE ); - mGrabCorner.SetProperty( Dali::Actor::Property::NAME, "GrabCorner" ); - mGrabCorner.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - mGrabCorner.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT ); - mGrabCorner.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mContainer.Add( mGrabCorner ); + mGrabCorner = ImageView::New(BACKGROUND_IMAGE); + mGrabCorner.SetProperty(Dali::Actor::Property::NAME, "GrabCorner"); + mGrabCorner.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + mGrabCorner.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT); + mGrabCorner.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mContainer.Add(mGrabCorner); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( mGrabCorner ); - mPanGestureDetector.DetectedSignal().Connect( this, &TextLabelExample::OnPan ); + mPanGestureDetector.Attach(mGrabCorner); + mPanGestureDetector.DetectedSignal().Connect(this, &TextLabelExample::OnPan); - mLabel = TextLabel::New( "\xF0\x9F\x98\x89 A Quick Brown Fox Jumps Over The Lazy Dog" ); + mLabel = TextLabel::New("\xF0\x9F\x98\x89 A Quick Brown Fox Jumps Over The Lazy Dog"); - mLabel.SetProperty( Dali::Actor::Property::NAME, "TextLabel" ); - mLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mLabel.SetProperty( Actor::Property::SIZE, mLayoutSize ); - mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true ); - mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::GREEN ); - mLabel.SetBackgroundColor( Color::WHITE ); - mContainer.Add( mLabel ); + mLabel.SetProperty(Dali::Actor::Property::NAME, "TextLabel"); + mLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mLabel.SetProperty(Actor::Property::SIZE, mLayoutSize); + mLabel.SetProperty(TextLabel::Property::MULTI_LINE, true); + mLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::GREEN); + mLabel.SetBackgroundColor(Color::WHITE); + mContainer.Add(mLabel); // Clicking ExpandingButton shows the Registered Style buttons, clicking again hides them. - Vector2 expandingButtonPosition( mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW ); - SetUpExpandingStyleButtons( expandingButtonPosition ); - window.Add( mExpandingButtons ); + Vector2 expandingButtonPosition(mButtonSize.width, mWindowSize.height * STYLE_BUTTON_POSTION_RELATIVE_TO_WINDOW); + SetUpExpandingStyleButtons(expandingButtonPosition); + window.Add(mExpandingButtons); // Add a border for the container so you can see the container is being resized while grabbing the handle. mBorder = Control::New(); - mBorder.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mBorder.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); + mBorder.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mBorder.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mBorder.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); Dali::Property::Map border; - border.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER ); - border.Insert( BorderVisual::Property::COLOR, Color::WHITE ); - border.Insert( BorderVisual::Property::SIZE, 3.f ); - mBorder.SetProperty( Control::Property::BACKGROUND, border ); - mContainer.Add( mBorder ); - mBorder.SetProperty( Actor::Property::VISIBLE,false); + border.Insert(Toolkit::Visual::Property::TYPE, Visual::BORDER); + border.Insert(BorderVisual::Property::COLOR, Color::WHITE); + border.Insert(BorderVisual::Property::SIZE, 3.f); + mBorder.SetProperty(Control::Property::BACKGROUND, border); + mContainer.Add(mBorder); + mBorder.SetProperty(Actor::Property::VISIBLE, false); mGrabCorner.RaiseToTop(); - mHueAngleIndex = mLabel.RegisterProperty( "hue", 0.0f ); - Renderer bgRenderer = mLabel.GetRendererAt(0); - mOverrideMixColorIndex = bgRenderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR ); + mHueAngleIndex = mLabel.RegisterProperty("hue", 0.0f); + Renderer bgRenderer = mLabel.GetRendererAt(0); + mOverrideMixColorIndex = bgRenderer.GetPropertyIndex(ColorVisual::Property::MIX_COLOR); - Constraint constraint = Constraint::New( bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f)); - constraint.AddSource( Source( mLabel, mHueAngleIndex ) ); - constraint.SetRemoveAction( Constraint::DISCARD ); + Constraint constraint = Constraint::New(bgRenderer, mOverrideMixColorIndex, HSVColorConstraint(0.0f, 0.5f, 0.8f)); + constraint.AddSource(Source(mLabel, mHueAngleIndex)); + constraint.SetRemoveAction(Constraint::DISCARD); constraint.Apply(); Animation anim = Animation::New(50.0f); @@ -275,12 +270,12 @@ public: mContainer.RaiseToTop(); mGrabCorner.RaiseToTop(); - Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT ); - std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl; + Property::Value labelText = mLabel.GetProperty(TextLabel::Property::TEXT); + std::cout << "Displaying text: \"" << labelText.Get() << "\"" << std::endl; } // If the styling buttons should colapse (hide) then the color buttons should also hide. - bool OnExpandingButtonCollapsing( Demo::ExpandingButtons button ) + bool OnExpandingButtonCollapsing(Demo::ExpandingButtons button) { mCollapseColorsAndStyles = true; HideColorButtons(); @@ -288,19 +283,19 @@ public: } // Get the style type from the given button - StyleType GetStyleTypeFromButton( Toolkit::Button button ) + StyleType GetStyleTypeFromButton(Toolkit::Button button) { StyleType style = StyleType::TEXT_COLOR; - if( button == mStyleButtons[ StyleType::OUTLINE ] ) + if(button == mStyleButtons[StyleType::OUTLINE]) { style = StyleType::OUTLINE; } - else if( button == mStyleButtons[ StyleType::SHADOW ] ) + else if(button == mStyleButtons[StyleType::SHADOW]) { style = StyleType::SHADOW; } - else if( button == mStyleButtons[ StyleType::BACKGROUND ] ) + else if(button == mStyleButtons[StyleType::BACKGROUND]) { style = StyleType::BACKGROUND; } @@ -308,101 +303,101 @@ public: } // Style selected, show color buttons - bool OnStyleButtonClicked( Toolkit::Button button ) + bool OnStyleButtonClicked(Toolkit::Button button) { - StyleType selectedStyle = GetStyleTypeFromButton( button ); - if ( mStyleActivatedForColor == selectedStyle ) + StyleType selectedStyle = GetStyleTypeFromButton(button); + if(mStyleActivatedForColor == selectedStyle) { HideColorButtons(); } else { - ResetColorButtons( mColorButtons, NUMBER_OF_COLORS ); - ShowColorButtons( selectedStyle); + ResetColorButtons(mColorButtons, NUMBER_OF_COLORS); + ShowColorButtons(selectedStyle); } return true; } // Set style to selected color - bool OnColorSelected( Toolkit::Button button ) + bool OnColorSelected(Toolkit::Button button) { - for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++) + for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++) { - if ( mColorButtons[index] == button ) + if(mColorButtons[index] == button) { - mSelectedColor = AVAILABLE_COLORS[ index ]; + mSelectedColor = AVAILABLE_COLORS[index]; } } - switch ( mStyleActivatedForColor ) + switch(mStyleActivatedForColor) { - case TEXT_COLOR : + case TEXT_COLOR: { - Animation animation = Animation::New( 1.f ); - animation.AnimateTo( Property( mLabel, TextLabel::Property::TEXT_COLOR ), mSelectedColor, AlphaFunction::LINEAR ); - mCurrentStyleColor[ TEXT_COLOR ] = mSelectedColor; + Animation animation = Animation::New(1.f); + animation.AnimateTo(Property(mLabel, TextLabel::Property::TEXT_COLOR), mSelectedColor, AlphaFunction::LINEAR); + mCurrentStyleColor[TEXT_COLOR] = mSelectedColor; animation.Play(); break; } - case OUTLINE : + case OUTLINE: { Property::Map outlineMap; - float outlineWidth = OUTLINE_WIDTH; + float outlineWidth = OUTLINE_WIDTH; - if( mStyleActiveState[ OUTLINE ] ) + if(mStyleActiveState[OUTLINE]) { - outlineWidth = ( Color::WHITE == mSelectedColor ) ? 0.0f : OUTLINE_WIDTH ; // toggles outline on/off + outlineWidth = (Color::WHITE == mSelectedColor) ? 0.0f : OUTLINE_WIDTH; // toggles outline on/off } - mStyleActiveState[ OUTLINE ] = ( outlineWidth > 0.0f ) ? true : false; + mStyleActiveState[OUTLINE] = (outlineWidth > 0.0f) ? true : false; - outlineMap["color"] = mSelectedColor; - outlineMap["width"] = outlineWidth; - mCurrentStyleColor[ OUTLINE ] = mSelectedColor; - mLabel.SetProperty( TextLabel::Property::OUTLINE, outlineMap ); + outlineMap["color"] = mSelectedColor; + outlineMap["width"] = outlineWidth; + mCurrentStyleColor[OUTLINE] = mSelectedColor; + mLabel.SetProperty(TextLabel::Property::OUTLINE, outlineMap); break; } - case SHADOW : + case SHADOW: { - Vector2 shadowOffset( SHADOW_OFFSET ); // Will be set to zeros if color already set - Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW ); - Vector4 currentShadowColor; - value.Get( currentShadowColor ); + Vector2 shadowOffset(SHADOW_OFFSET); // Will be set to zeros if color already set + Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW); + Vector4 currentShadowColor; + value.Get(currentShadowColor); - if ( mStyleActiveState[ SHADOW ] ) + if(mStyleActiveState[SHADOW]) { // toggle shadow off ( zero offset ) if color is already set - shadowOffset = ( Color::WHITE == mSelectedColor ) ? Vector2::ZERO : Vector2( SHADOW_OFFSET ); + shadowOffset = (Color::WHITE == mSelectedColor) ? Vector2::ZERO : Vector2(SHADOW_OFFSET); } - mStyleActiveState[ SHADOW ] = ( shadowOffset == Vector2::ZERO ) ? false : true; - mCurrentStyleColor[ SHADOW ] = mSelectedColor; + mStyleActiveState[SHADOW] = (shadowOffset == Vector2::ZERO) ? false : true; + mCurrentStyleColor[SHADOW] = mSelectedColor; Property::Map shadowMap; - shadowMap.Insert( "offset", shadowOffset ); - shadowMap.Insert( "color", mSelectedColor ); - mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", shadowOffset); + shadowMap.Insert("color", mSelectedColor); + mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } - case BACKGROUND : + case BACKGROUND: { Property::Map backgroundMap; - auto backgroundEnabled(true); + auto backgroundEnabled(true); - if( mStyleActiveState[ BACKGROUND ] ) + if(mStyleActiveState[BACKGROUND]) { - backgroundEnabled = ( Color::WHITE != mSelectedColor ); // toggles background on/off + backgroundEnabled = (Color::WHITE != mSelectedColor); // toggles background on/off } - mStyleActiveState[ BACKGROUND ] = backgroundEnabled; + mStyleActiveState[BACKGROUND] = backgroundEnabled; - backgroundMap["color"] = mSelectedColor; - backgroundMap["enable"] = backgroundEnabled; - mCurrentStyleColor[ BACKGROUND ] = mSelectedColor; - mLabel.SetProperty( DevelTextLabel::Property::BACKGROUND, backgroundMap ); + backgroundMap["color"] = mSelectedColor; + backgroundMap["enable"] = backgroundEnabled; + mCurrentStyleColor[BACKGROUND] = mSelectedColor; + mLabel.SetProperty(DevelTextLabel::Property::BACKGROUND, backgroundMap); break; } - default : + default: break; } @@ -411,17 +406,17 @@ public: // Set the inital color button that should be be selected. // If the style already has a color set then that should be used - void SetInitialSelectedColorButton( StyleType styleButtonIndex ) + void SetInitialSelectedColorButton(StyleType styleButtonIndex) { - Vector4 selectedColor = mCurrentStyleColor[ styleButtonIndex ]; + Vector4 selectedColor = mCurrentStyleColor[styleButtonIndex]; - for ( unsigned int i = 0; i < NUMBER_OF_COLORS; i++ ) + for(unsigned int i = 0; i < NUMBER_OF_COLORS; i++) { - if ( AVAILABLE_COLORS[i] == selectedColor ) + if(AVAILABLE_COLORS[i] == selectedColor) { - if ( mColorButtons[i] ) + if(mColorButtons[i]) { - mColorButtons[ i ].SetProperty( Toolkit::Button::Property::SELECTED, true ); + mColorButtons[i].SetProperty(Toolkit::Button::Property::SELECTED, true); } break; } @@ -429,70 +424,63 @@ public: } // Create a bar of color buttons that the user can select. - void ShowColorButtons( StyleType styleButtonIndex ) + void ShowColorButtons(StyleType styleButtonIndex) { mCollapseColorsAndStyles = false; // Request to show colors so reset flag - mStyleActivatedForColor = styleButtonIndex; + mStyleActivatedForColor = styleButtonIndex; - for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++) + for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++) { - if( !mColorButtonsAnimation ) + if(!mColorButtonsAnimation) { - mColorButtonsAnimation = Animation::New( 0.15f ); - mColorButtonsAnimation.FinishedSignal().Connect( this, &TextLabelExample::OnColorButtonAnimationFinished ); + mColorButtonsAnimation = Animation::New(0.15f); + mColorButtonsAnimation.FinishedSignal().Connect(this, &TextLabelExample::OnColorButtonAnimationFinished); } // Create a color button - if ( ! mColorButtons[index] ) + if(!mColorButtons[index]) { mColorButtons[index] = RadioButton::New(); - mColorButtons[index].SetProperty( Actor::Property::SIZE, mButtonSize ); - mColorButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnColorSelected ); - mColorButtons[index].SetProperty( Button::Property::TOGGLABLE, true ); + mColorButtons[index].SetProperty(Actor::Property::SIZE, mButtonSize); + mColorButtons[index].ClickedSignal().Connect(this, &TextLabelExample::OnColorSelected); + mColorButtons[index].SetProperty(Button::Property::TOGGLABLE, true); Property::Map propertyMap; - propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); - propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]); - mColorButtons[index].SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap ); - mColorButtons[index].SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap ); - mColorButtons[index].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mColorButtons[index].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[index]); + mColorButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap); + mColorButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap); + mColorButtons[index].SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mColorButtons[index].SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); - propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); - propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[ index ]); - mColorButtons[index].SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, propertyMap ); + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, AVAILABLE_COLORS[index]); + mColorButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, propertyMap); - mColorButtons[index].SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, - Property::Map().Add( Visual::Property::TYPE, Visual::BORDER ) - .Add( BorderVisual::Property::COLOR, Color::WHITE ) - .Add( BorderVisual::Property::SIZE, 4.0f ) - .Add( BorderVisual::Property::ANTI_ALIASING, true ) ); + mColorButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_VISUAL, + Property::Map().Add(Visual::Property::TYPE, Visual::BORDER).Add(BorderVisual::Property::COLOR, Color::WHITE).Add(BorderVisual::Property::SIZE, 4.0f).Add(BorderVisual::Property::ANTI_ALIASING, true)); // Use a white button with 50% transparency as a clear color button - if ( Color::WHITE == AVAILABLE_COLORS[ index ] && styleButtonIndex != StyleType::TEXT_COLOR ) + if(Color::WHITE == AVAILABLE_COLORS[index] && styleButtonIndex != StyleType::TEXT_COLOR) { - mColorButtons[index].SetProperty( Actor::Property::OPACITY,0.5f); - - mColorButtons[index].SetProperty( Toolkit::Button::Property::LABEL, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ) - .Add( Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER ) - .Add( Toolkit::TextVisual::Property::TEXT, "off") ); + mColorButtons[index].SetProperty(Actor::Property::OPACITY, 0.5f); + mColorButtons[index].SetProperty(Toolkit::Button::Property::LABEL, + Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER).Add(Toolkit::TextVisual::Property::TEXT, "off")); } } - SetInitialSelectedColorButton( mStyleActivatedForColor ); + SetInitialSelectedColorButton(mStyleActivatedForColor); mColorButtons[index].Unparent(); - mStyleButtons[styleButtonIndex].Add( mColorButtons[index] ); + mStyleButtons[styleButtonIndex].Add(mColorButtons[index]); mColorButtons[index].Lower(); // Position button using nice animation - mColorButtons[index].SetProperty( Actor::Property::POSITION_Y, -GAP_BETWEEN_BUTTONS ); - float desiredPosition = -( mButtonSize.height + GAP_BETWEEN_BUTTONS ) * (index); - AlphaFunction focusedAlphaFunction = AlphaFunction( Vector2 ( 0.32f, 0.08f ), Vector2( 0.38f, 1.72f ) ); - mColorButtonsAnimation.AnimateBy( Property( mColorButtons[index], Actor::Property::POSITION_Y ), desiredPosition, focusedAlphaFunction ); + mColorButtons[index].SetProperty(Actor::Property::POSITION_Y, -GAP_BETWEEN_BUTTONS); + float desiredPosition = -(mButtonSize.height + GAP_BETWEEN_BUTTONS) * (index); + AlphaFunction focusedAlphaFunction = AlphaFunction(Vector2(0.32f, 0.08f), Vector2(0.38f, 1.72f)); + mColorButtonsAnimation.AnimateBy(Property(mColorButtons[index], Actor::Property::POSITION_Y), desiredPosition, focusedAlphaFunction); } mColorButtonsHidden = false; @@ -500,22 +488,22 @@ public: } // Remove the color buttons when not being shown. - void ResetColorButtons( Button buttons[], unsigned int numberOfButtons ) + void ResetColorButtons(Button buttons[], unsigned int numberOfButtons) { - for( unsigned int index = 0; index < numberOfButtons; index++) + for(unsigned int index = 0; index < numberOfButtons; index++) { - UnparentAndReset( buttons[index] ); + UnparentAndReset(buttons[index]); } } - void OnColorButtonAnimationFinished( Animation& animation ) + void OnColorButtonAnimationFinished(Animation& animation) { animation.Clear(); - if ( mColorButtonsHidden ) + if(mColorButtonsHidden) { - ResetColorButtons( mColorButtons, NUMBER_OF_COLORS ); + ResetColorButtons(mColorButtons, NUMBER_OF_COLORS); animation.Reset(); // Handle reset - if ( mCollapseColorsAndStyles ) + if(mCollapseColorsAndStyles) { mExpandingButtons.Collapse(); } @@ -525,16 +513,16 @@ public: // Create the style buttons that will expand from the expanding button. void CreateStyleButtons() { - for ( unsigned int index = 0; index < NUMBER_OF_STYLES; index++ ) + for(unsigned int index = 0; index < NUMBER_OF_STYLES; index++) { - if ( ! mStyleButtons[index] ) + if(!mStyleButtons[index]) { mStyleButtons[index] = PushButton::New(); - mStyleButtons[index].SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[ index ] ); - mStyleButtons[index].SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE ); - mStyleButtons[index].SetProperty( Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mStyleButtons[index].SetProperty( Actor::Property::SIZE, mButtonSize ); - mStyleButtons[index].ClickedSignal().Connect( this, &TextLabelExample::OnStyleButtonClicked ); + mStyleButtons[index].SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BUTTON_IMAGES[index]); + mStyleButtons[index].SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STYLE_SELECTED_IMAGE); + mStyleButtons[index].SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mStyleButtons[index].SetProperty(Actor::Property::SIZE, mButtonSize); + mStyleButtons[index].ClickedSignal().Connect(this, &TextLabelExample::OnStyleButtonClicked); } } } @@ -542,11 +530,11 @@ public: // Animate away the color bar. void HideColorButtons() { - if ( ! mColorButtonsHidden ) + if(!mColorButtonsHidden) { - for( unsigned int index = 0; index < NUMBER_OF_COLORS; index++) + for(unsigned int index = 0; index < NUMBER_OF_COLORS; index++) { - mColorButtonsAnimation.AnimateTo( Property( mColorButtons[index], Actor::Property::POSITION_Y ), 0.0f ); + mColorButtonsAnimation.AnimateTo(Property(mColorButtons[index], Actor::Property::POSITION_Y), 0.0f); } mColorButtonsHidden = true; mColorButtonsAnimation.Play(); @@ -558,7 +546,7 @@ public: void HideStyleAndColorButtons() { mCollapseColorsAndStyles = true; - if ( mColorButtonsHidden ) + if(mColorButtonsHidden) { mExpandingButtons.Collapse(); } @@ -569,24 +557,24 @@ public: } // Resize the text-label with pan gesture - void OnPan( Actor actor, const PanGesture& gesture ) + void OnPan(Actor actor, const PanGesture& gesture) { // Reset mLayoutSize when the pan starts GestureState state = gesture.GetState(); - if( state == GestureState::STARTED ) + if(state == GestureState::STARTED) { - if( mLayoutSize.x < 2.0f ) + if(mLayoutSize.x < 2.0f) { mLayoutSize.x = 2.0f; } - if( mLayoutSize.y < 2.0f ) + if(mLayoutSize.y < 2.0f) { mLayoutSize.y = 2.0f; } // Only show the border during the panning - mBorder.SetProperty( Actor::Property::VISIBLE,true); + mBorder.SetProperty(Actor::Property::VISIBLE, true); HideStyleAndColorButtons(); } @@ -595,24 +583,24 @@ public: mLayoutSize.x += displacement.x * 2.0f; mLayoutSize.y += displacement.y * 2.0f; - if( mLayoutSize.x >= 2.0f || - mLayoutSize.y >= 2.0f ) + if(mLayoutSize.x >= 2.0f || + mLayoutSize.y >= 2.0f) { - mLayoutSize.x = std::min ( mLayoutSize.x, mWindowSize.width ); - mLayoutSize.y = std::min ( mLayoutSize.y, mWindowSize.height*.9f ); + mLayoutSize.x = std::min(mLayoutSize.x, mWindowSize.width); + mLayoutSize.y = std::min(mLayoutSize.y, mWindowSize.height * .9f); // Avoid pixel mis-alignment issue - Vector2 clampedSize = Vector2( std::max( ConvertToEven( static_cast( mLayoutSize.x )), 2 ), - std::max( ConvertToEven( static_cast( mLayoutSize.y )), 2 ) ); + Vector2 clampedSize = Vector2(std::max(ConvertToEven(static_cast(mLayoutSize.x)), 2), + std::max(ConvertToEven(static_cast(mLayoutSize.y)), 2)); - mContainer.SetProperty( Actor::Property::SIZE, clampedSize ); + mContainer.SetProperty(Actor::Property::SIZE, clampedSize); } - if( state == GestureState::CANCELLED || state == GestureState::FINISHED ) + if(state == GestureState::CANCELLED || state == GestureState::FINISHED) { // Resize the text label to match the container size when panning is finished - mLabel.SetProperty( Actor::Property::SIZE, mLayoutSize ); - mBorder.SetProperty( Actor::Property::VISIBLE,false); + mLabel.SetProperty(Actor::Property::SIZE, mLayoutSize); + mBorder.SetProperty(Actor::Property::VISIBLE, false); } } @@ -623,74 +611,74 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } - else if( event.IsCtrlModifier() ) + else if(event.IsCtrlModifier()) { - switch( event.GetKeyCode() ) + switch(event.GetKeyCode()) { // Select rendering back-end case KEY_ZERO: // fall through case KEY_ONE: { - mLabel.SetProperty( DevelTextLabel::Property::RENDERING_BACKEND, event.GetKeyCode() - 10 ); + mLabel.SetProperty(DevelTextLabel::Property::RENDERING_BACKEND, event.GetKeyCode() - 10); break; } case KEY_A: // Animate text colour { - Animation animation = Animation::New( 2.f ); - animation.AnimateTo( Property( mLabel, TextLabel::Property::TEXT_COLOR ), Color::RED, AlphaFunction::SIN ); - animation.SetLoopCount( 3 ); + Animation animation = Animation::New(2.f); + animation.AnimateTo(Property(mLabel, TextLabel::Property::TEXT_COLOR), Color::RED, AlphaFunction::SIN); + animation.SetLoopCount(3); animation.Play(); break; } case KEY_F: // Fill vertically { - if( ResizePolicy::DIMENSION_DEPENDENCY == mLabel.GetResizePolicy(Dimension::HEIGHT) ) + if(ResizePolicy::DIMENSION_DEPENDENCY == mLabel.GetResizePolicy(Dimension::HEIGHT)) { - mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); + mLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); } else { - mLabel.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); + mLabel.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); } break; } case KEY_H: // Horizontal alignment { - if( ++mAlignment >= H_ALIGNMENT_STRING_COUNT ) + if(++mAlignment >= H_ALIGNMENT_STRING_COUNT) { mAlignment = 0u; } - mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[ mAlignment ] ); + mLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, H_ALIGNMENT_STRING_TABLE[mAlignment]); break; } case KEY_V: // Vertical alignment { - if( ++mAlignment >= V_ALIGNMENT_STRING_COUNT ) + if(++mAlignment >= V_ALIGNMENT_STRING_COUNT) { mAlignment = 0u; } - mLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[ mAlignment ] ); + mLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, V_ALIGNMENT_STRING_TABLE[mAlignment]); break; } case KEY_M: // Multi-line { - bool multiLine = mLabel.GetProperty( TextLabel::Property::MULTI_LINE ); - mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine ); + bool multiLine = mLabel.GetProperty(TextLabel::Property::MULTI_LINE); + mLabel.SetProperty(TextLabel::Property::MULTI_LINE, !multiLine); break; } case KEY_L: // Language { - const Language& language = LANGUAGES[ mLanguageId ]; + const Language& language = LANGUAGES[mLanguageId]; - mLabel.SetProperty( TextLabel::Property::TEXT, language.text ); + mLabel.SetProperty(TextLabel::Property::TEXT, language.text); - if( ++mLanguageId >= NUMBER_OF_LANGUAGES ) + if(++mLanguageId >= NUMBER_OF_LANGUAGES) { mLanguageId = 0u; } @@ -698,73 +686,71 @@ public: } case KEY_S: // Shadow color { - Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW ); - Vector4 shadowColor; - value.Get( shadowColor ); + Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW); + Vector4 shadowColor; + value.Get(shadowColor); Property::Map shadowMap; - if( Color::BLACK == shadowColor ) + if(Color::BLACK == shadowColor) { - shadowMap.Insert( "color", Color::RED ); - mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("color", Color::RED); + mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); } else { - shadowMap.Insert( "color", Color::BLACK ); - mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("color", Color::BLACK); + mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); } break; } case KEY_U: // Markup { - mLabel.SetProperty( TextLabel::Property::ENABLE_MARKUP, true ); - mLabel.SetProperty( TextLabel::Property::TEXT, "Hello world demo" ); + mLabel.SetProperty(TextLabel::Property::ENABLE_MARKUP, true); + mLabel.SetProperty(TextLabel::Property::TEXT, "Hello world demo"); break; } case KEY_PLUS: // Increase shadow offset { - Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW ); - Vector2 shadowOffset; - value.Get( shadowOffset ); - shadowOffset += Vector2( 1.0f, 1.0f ); + Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW); + Vector2 shadowOffset; + value.Get(shadowOffset); + shadowOffset += Vector2(1.0f, 1.0f); Property::Map shadowMap; - shadowMap.Insert( "offset", shadowOffset ); - mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", shadowOffset); + mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case KEY_MINUS: // Decrease shadow offset { - Property::Value value = mLabel.GetProperty( TextLabel::Property::SHADOW ); - Vector2 shadowOffset; - value.Get( shadowOffset ); - shadowOffset -= Vector2( 1.0f, 1.0f ); + Property::Value value = mLabel.GetProperty(TextLabel::Property::SHADOW); + Vector2 shadowOffset; + value.Get(shadowOffset); + shadowOffset -= Vector2(1.0f, 1.0f); Property::Map shadowMap; - shadowMap.Insert( "offset", shadowOffset ); - mLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", shadowOffset); + mLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } - } } } } private: - Application& mApplication; TextLabel mLabel; Demo::ExpandingButtons mExpandingButtons; - PushButton mStyleButtons[ NUMBER_OF_STYLES ]; - bool mStyleActiveState[ NUMBER_OF_STYLES ]; + PushButton mStyleButtons[NUMBER_OF_STYLES]; + bool mStyleActiveState[NUMBER_OF_STYLES]; - Vector4 mCurrentStyleColor[NUMBER_OF_STYLES ]; + Vector4 mCurrentStyleColor[NUMBER_OF_STYLES]; Vector4 mSelectedColor; - Button mColorButtons[ NUMBER_OF_COLORS ]; + Button mColorButtons[NUMBER_OF_COLORS]; StyleType mStyleActivatedForColor; // The style that the color bar is connected to @@ -781,8 +767,8 @@ private: Size mWindowSize; Size mButtonSize; - unsigned int mLanguageId; - unsigned int mAlignment; + unsigned int mLanguageId; + unsigned int mAlignment; Property::Index mHueAngleIndex; Property::Index mOverrideMixColorIndex; @@ -790,10 +776,10 @@ private: bool mCollapseColorsAndStyles; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - TextLabelExample test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + TextLabelExample test(application); application.MainLoop(); return 0; } diff --git a/examples/text-memory-profiling/text-memory-profiling-example.cpp b/examples/text-memory-profiling/text-memory-profiling-example.cpp index bf8681a..c40ce46 100644 --- a/examples/text-memory-profiling/text-memory-profiling-example.cpp +++ b/examples/text-memory-profiling/text-memory-profiling-example.cpp @@ -21,9 +21,9 @@ */ // EXTERNAL INCLUDES -#include #include #include +#include // INTERNAL INCLUDES #include "shared/view.h" @@ -33,7 +33,6 @@ using namespace Dali::Toolkit; namespace { - enum TextType { SINGLE_COLOR_TEXT, @@ -48,26 +47,25 @@ enum TextType NUMBER_OF_TYPES }; -std::string TEXT_TYPE_STRING[ NUMBER_OF_TYPES ] = -{ - "Single color text", - "Single color text with style", - "Single color text with emoji", - "Single color text with style and emoji", - "Multi color text", - "Multi color text with style", - "Multi color text with emoji", - "Multi color text with style and emoji", - "Small text in large Text Label" -}; +std::string TEXT_TYPE_STRING[NUMBER_OF_TYPES] = + { + "Single color text", + "Single color text with style", + "Single color text with emoji", + "Single color text with style and emoji", + "Multi color text", + "Multi color text with style", + "Multi color text with emoji", + "Multi color text with style and emoji", + "Small text in large Text Label"}; const int NUMBER_OF_LABELS = 500; -const char* BACKGROUND_IMAGE( "" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* BACK_IMAGE( DEMO_IMAGE_DIR "icon-change.png" ); -const char* BACK_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); -const char* INDICATOR_IMAGE( DEMO_IMAGE_DIR "loading.png" ); +const char* BACKGROUND_IMAGE(""); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* BACK_IMAGE(DEMO_IMAGE_DIR "icon-change.png"); +const char* BACK_IMAGE_SELECTED(DEMO_IMAGE_DIR "icon-change-selected.png"); +const char* INDICATOR_IMAGE(DEMO_IMAGE_DIR "loading.png"); } // anonymous namespace @@ -77,13 +75,12 @@ const char* INDICATOR_IMAGE( DEMO_IMAGE_DIR "loading.png" ); class TextMemoryProfilingExample : public ConnectionTracker, public Toolkit::ItemFactory { public: - - TextMemoryProfilingExample( Application& application ) - : mApplication( application ), - mCurrentTextStyle( SINGLE_COLOR_TEXT ) + TextMemoryProfilingExample(Application& application) + : mApplication(application), + mCurrentTextStyle(SINGLE_COLOR_TEXT) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextMemoryProfilingExample::Create ); + mApplication.InitSignal().Connect(this, &TextMemoryProfilingExample::Create); } ~TextMemoryProfilingExample() @@ -94,94 +91,94 @@ public: /** * @brief Create a text label in the given type */ - TextLabel SetupTextLabel( int type ) + TextLabel SetupTextLabel(int type) { TextLabel label = TextLabel::New(); - label.SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - label.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); - label.SetProperty( TextLabel::Property::POINT_SIZE, 12.0f ); + label.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_LEFT); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + label.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLACK); + label.SetProperty(TextLabel::Property::POINT_SIZE, 12.0f); Property::Map shadowMap; - shadowMap.Insert( "color", Color::YELLOW ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); - label.SetProperty( TextLabel::Property::ENABLE_MARKUP, true ); + shadowMap.Insert("color", Color::YELLOW); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); + label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true); Vector2 windowSize = mApplication.GetWindow().GetSize(); - label.SetProperty( Actor::Property::POSITION, Vector3( Random::Range( 0.0f, windowSize.x ), Random::Range( 0.0f, windowSize.y ), 0.0f) ); + label.SetProperty(Actor::Property::POSITION, Vector3(Random::Range(0.0f, windowSize.x), Random::Range(0.0f, windowSize.y), 0.0f)); - switch ( type ) + switch(type) { case SINGLE_COLOR_TEXT: { - label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 0.0f, 0.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(0.0f, 0.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case SINGLE_COLOR_TEXT_WITH_STYLE: { - label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 2.0f, 2.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(2.0f, 2.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case SINGLE_COLOR_TEXT_WITH_EMOJI: { - label.SetProperty( TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 0.0f, 0.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(0.0f, 0.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case SINGLE_COLOR_TEXT_WITH_STYLE_EMOJI: { - label.SetProperty( TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, "\xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 2.0f, 2.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(2.0f, 2.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case MULTI_COLOR_TEXT: { - label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 0.0f, 0.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(0.0f, 0.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case MULTI_COLOR_TEXT_WITH_STYLE: { - label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 2.0f, 2.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(2.0f, 2.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case MULTI_COLOR_TEXT_WITH_EMOJI: { - label.SetProperty( TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 0.0f, 0.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(0.0f, 0.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case MULTI_COLOR_TEXT_WITH_STYLE_EMOJI: { - label.SetProperty( TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, " \xF0\x9F\x98\x81 A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 2.0f, 2.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("offset", Vector2(2.0f, 2.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); break; } case SMALL_TEXT_IN_LARGE_TEXT_LABEL: { - label.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); + label.SetProperty(TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog"); - shadowMap.Insert( "offset", Vector2( 0.0f, 0.0f ) ); - label.SetProperty( TextLabel::Property::SHADOW, shadowMap ); - label.SetProperty( Actor::Property::SIZE, Vector2(windowSize.x, windowSize.y * 0.25f) ); // Set the text label in larger size + shadowMap.Insert("offset", Vector2(0.0f, 0.0f)); + label.SetProperty(TextLabel::Property::SHADOW, shadowMap); + label.SetProperty(Actor::Property::SIZE, Vector2(windowSize.x, windowSize.y * 0.25f)); // Set the text label in larger size break; } default: @@ -199,21 +196,21 @@ public: Vector2 windowSize = mApplication.GetWindow().GetSize(); mTapDetector = TapGestureDetector::New(); - mTapDetector.DetectedSignal().Connect( this, &TextMemoryProfilingExample::OnTap ); + mTapDetector.DetectedSignal().Connect(this, &TextMemoryProfilingExample::OnTap); // Create an item view for the main menu - mItemView = ItemView::New( *this ); + mItemView = ItemView::New(*this); - mItemView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mItemView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + mItemView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mItemView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); - mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST ); - mLayout->SetItemSize( Vector3( windowSize.width, 60.0f, 0.0f ) ); + mLayout = DefaultItemLayout::New(DefaultItemLayout::LIST); + mLayout->SetItemSize(Vector3(windowSize.width, 60.0f, 0.0f)); - mItemView.AddLayout( *mLayout ); + mItemView.AddLayout(*mLayout); // Activate the layout - mItemView.ActivateLayout( 0, Vector3( windowSize ), 0.0f ); + mItemView.ActivateLayout(0, Vector3(windowSize), 0.0f); } /** @@ -227,14 +224,14 @@ public: /** * @brief Create new item for the main menu */ - virtual Actor NewItem( unsigned int itemId ) + virtual Actor NewItem(unsigned int itemId) { - TextLabel label = TextLabel::New( TEXT_TYPE_STRING[itemId] ); - label.SetStyleName( "BuilderLabel" ); - label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + TextLabel label = TextLabel::New(TEXT_TYPE_STRING[itemId]); + label.SetStyleName("BuilderLabel"); + label.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); // Hook up tap detector - mTapDetector.Attach( label ); + mTapDetector.Attach(label); return label; } @@ -242,96 +239,96 @@ public: /** * @brief Create text labels for memory profiling */ - void CreateTextLabels( int type ) + void CreateTextLabels(int type) { // Delete any existing text labels unsigned int numChildren = mLayer.GetChildCount(); - for( unsigned int i = 0; i < numChildren; ++i ) + for(unsigned int i = 0; i < numChildren; ++i) { - mLayer.Remove( mLayer.GetChildAt( 0 ) ); + mLayer.Remove(mLayer.GetChildAt(0)); } - mLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mLayer.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::HEIGHT ); - mLayer.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.0f, -DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight, 0.0f ) ); + mLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mLayer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mLayer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mLayer.SetResizePolicy(ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::HEIGHT); + mLayer.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.0f, -DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight, 0.0f)); - mNavigationView.Push( mLayer ); + mNavigationView.Push(mLayer); // Create new text labels - for ( int i = 0; i < NUMBER_OF_LABELS; i++ ) + for(int i = 0; i < NUMBER_OF_LABELS; i++) { - TextLabel label = SetupTextLabel( type ); - mLayer.Add( label ); + TextLabel label = SetupTextLabel(type); + mLayer.Add(label); } - mTitle.SetProperty( TextLabel::Property::TEXT, "Run memps on target" ); + mTitle.SetProperty(TextLabel::Property::TEXT, "Run memps on target"); } /** * @brief One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &TextMemoryProfilingExample::OnKeyEvent); - Layer contents = DemoHelper::CreateView( mApplication, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - "" ); + Layer contents = DemoHelper::CreateView(mApplication, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + ""); - mTitle = DemoHelper::CreateToolBarLabel( "" ); - mTitle.SetProperty( TextLabel::Property::TEXT, "Select the type of text" ); + mTitle = DemoHelper::CreateToolBarLabel(""); + mTitle.SetProperty(TextLabel::Property::TEXT, "Select the type of text"); // Add title to the tool bar. - mToolBar.AddControl( mTitle, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER ); + mToolBar.AddControl(mTitle, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HORIZONTAL_CENTER); // Create a layer to contain dynamically created text labels mLayer = Layer::New(); mIndicator = Toolkit::ImageView::New(INDICATOR_IMAGE); - mIndicator.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mIndicator.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mIndicator.SetProperty( Actor::Property::VISIBLE, false ); + mIndicator.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mIndicator.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mIndicator.SetProperty(Actor::Property::VISIBLE, false); // Create a back button in the left of toolbar PushButton backButton = PushButton::New(); - backButton.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, BACK_IMAGE ); - backButton.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, BACK_IMAGE_SELECTED ); - backButton.ClickedSignal().Connect( this, &TextMemoryProfilingExample::OnBackButtonPressed ); - backButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true ); - mToolBar.AddControl( backButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + backButton.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, BACK_IMAGE); + backButton.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, BACK_IMAGE_SELECTED); + backButton.ClickedSignal().Connect(this, &TextMemoryProfilingExample::OnBackButtonPressed); + backButton.SetProperty(Actor::Property::LEAVE_REQUIRED, true); + mToolBar.AddControl(backButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Alignment::HORIZONTAL_LEFT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING); // Create a navigation view to navigate different types of text labels mNavigationView = NavigationView::New(); - mNavigationView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mNavigationView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mNavigationView.SetBackgroundColor( Color::WHITE ); - window.Add( mNavigationView ); + mNavigationView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mNavigationView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mNavigationView.SetBackgroundColor(Color::WHITE); + window.Add(mNavigationView); CreateMainMenu(); - mNavigationView.Push( mItemView ); + mNavigationView.Push(mItemView); mItemView.Add(mIndicator); - PropertyNotification notification = mIndicator.AddPropertyNotification( Actor::Property::VISIBLE, GreaterThanCondition(0.01f) ); - notification.NotifySignal().Connect( this, &TextMemoryProfilingExample::OnIndicatorVisible ); + PropertyNotification notification = mIndicator.AddPropertyNotification(Actor::Property::VISIBLE, GreaterThanCondition(0.01f)); + notification.NotifySignal().Connect(this, &TextMemoryProfilingExample::OnIndicatorVisible); } /** * @brief Main key event handler */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { ReturnToPreviousScreen(); } @@ -341,41 +338,41 @@ public: /** * @brief Tap gesture handler */ - void OnTap( Actor actor, const TapGesture& tap ) + void OnTap(Actor actor, const TapGesture& tap) { - mCurrentTextStyle = mItemView.GetItemId( actor ); + mCurrentTextStyle = mItemView.GetItemId(actor); // Show the loading indicator - mIndicator.SetProperty( Actor::Property::VISIBLE, true ); + mIndicator.SetProperty(Actor::Property::VISIBLE, true); - if ( mAnimation ) + if(mAnimation) { mAnimation.Clear(); mAnimation.Reset(); } - mAnimation = Animation::New( 0.8f ); - mAnimation.AnimateBy( Property( mIndicator, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree(180.0f) ), Vector3::ZAXIS ) ); - mAnimation.SetLooping( true ); + mAnimation = Animation::New(0.8f); + mAnimation.AnimateBy(Property(mIndicator, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(180.0f)), Vector3::ZAXIS)); + mAnimation.SetLooping(true); mAnimation.Play(); } /** * @brief Property notification handler */ - void OnIndicatorVisible( PropertyNotification& source ) + void OnIndicatorVisible(PropertyNotification& source) { - CreateTextLabels( mCurrentTextStyle ); + CreateTextLabels(mCurrentTextStyle); // Hide the loading indicator mAnimation.Stop(); - mIndicator.SetProperty( Actor::Property::VISIBLE, false ); + mIndicator.SetProperty(Actor::Property::VISIBLE, false); } /** * @brief Button signal handler */ - bool OnBackButtonPressed( Toolkit::Button button ) + bool OnBackButtonPressed(Toolkit::Button button) { ReturnToPreviousScreen(); return true; @@ -386,7 +383,7 @@ public: */ void ReturnToPreviousScreen() { - if ( mItemView.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) + if(mItemView.GetProperty(Actor::Property::CONNECTED_TO_SCENE)) { // Quit the application if it is in the main menu mApplication.Quit(); @@ -396,20 +393,19 @@ public: // Return to the main menu mNavigationView.Pop(); - mTitle.SetProperty( TextLabel::Property::TEXT, "Select type of text to test" ); + mTitle.SetProperty(TextLabel::Property::TEXT, "Select type of text to test"); } } private: - Application& mApplication; - ItemLayoutPtr mLayout; - ItemView mItemView; + ItemLayoutPtr mLayout; + ItemView mItemView; NavigationView mNavigationView; - Control mView; - ToolBar mToolBar; + Control mView; + ToolBar mToolBar; TextLabel mTitle; ImageView mIndicator; Animation mAnimation; @@ -421,10 +417,10 @@ private: unsigned int mCurrentTextStyle; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - TextMemoryProfilingExample test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + TextMemoryProfilingExample test(application); application.MainLoop(); return 0; } diff --git a/examples/text-overlap/text-overlap-example.cpp b/examples/text-overlap/text-overlap-example.cpp old mode 100755 new mode 100644 index a7c64a2..4c03fe1 --- a/examples/text-overlap/text-overlap-example.cpp +++ b/examples/text-overlap/text-overlap-example.cpp @@ -1,7 +1,23 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "text-overlap-example.h" #include #include -#include "text-overlap-example.h" #include @@ -10,95 +26,91 @@ using namespace Dali::Toolkit; static const int NUMBER_OF_LABELS(2); - - namespace Demo { - -TextOverlapController::TextOverlapController( Application& app ) -: mApplication( app ), - mTopmostLabel( 1 ) +TextOverlapController::TextOverlapController(Application& app) +: mApplication(app), + mTopmostLabel(1) { - app.InitSignal().Connect( this, &TextOverlapController::Create ); - app.TerminateSignal().Connect( this, &TextOverlapController::Destroy ); + app.InitSignal().Connect(this, &TextOverlapController::Create); + app.TerminateSignal().Connect(this, &TextOverlapController::Destroy); } -void TextOverlapController::Create( Application& app ) +void TextOverlapController::Create(Application& app) { Window window = app.GetWindow(); - window.KeyEventSignal().Connect( this, &TextOverlapController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &TextOverlapController::OnKeyEvent); Vector2 windowSize = window.GetSize(); mLabels[0] = TextLabel::New("Text Label 1"); mLabels[1] = TextLabel::New("Text Label 2"); - mLabels[0].SetProperty( Dali::Actor::Property::NAME,"Label1"); - mLabels[1].SetProperty( Dali::Actor::Property::NAME,"Label2"); + mLabels[0].SetProperty(Dali::Actor::Property::NAME, "Label1"); + mLabels[1].SetProperty(Dali::Actor::Property::NAME, "Label2"); - mLabels[0].SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 1 ); - mLabels[1].SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 ); + mLabels[0].SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 1); + mLabels[1].SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2); - mLabels[0].SetProperty( Control::Property::BACKGROUND, Color::RED ); - mLabels[1].SetProperty( Control::Property::BACKGROUND, Color::YELLOW ); + mLabels[0].SetProperty(Control::Property::BACKGROUND, Color::RED); + mLabels[1].SetProperty(Control::Property::BACKGROUND, Color::YELLOW); - for(int i=0; i( Actor::Property::POSITION ); - Vector3 size = mLabels[i].GetCurrentProperty< Vector3 >( Actor::Property::SIZE ); - if( gesturePosition.y > position.y - size.y * 0.5f && - gesturePosition.y <= position.y + size.y * 0.5f ) + Vector3 position = mLabels[i].GetCurrentProperty(Actor::Property::POSITION); + Vector3 size = mLabels[i].GetCurrentProperty(Actor::Property::SIZE); + if(gesturePosition.y > position.y - size.y * 0.5f && + gesturePosition.y <= position.y + size.y * 0.5f) { mGrabbedActor = mLabels[i]; break; } } } - else if( mGrabbedActor && state == GestureState::CONTINUING ) + else if(mGrabbedActor && state == GestureState::CONTINUING) { - Vector2 windowSize = mApplication.GetWindow().GetSize(); - Vector3 size = mGrabbedActor.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ); + Vector2 windowSize = mApplication.GetWindow().GetSize(); + Vector3 size = mGrabbedActor.GetCurrentProperty(Actor::Property::SIZE); const Vector2& gesturePosition = gesture.GetPosition(); - float y = Clamp( gesturePosition.y, size.y * 0.5f, windowSize.y - size.y*0.5f ); - mGrabbedActor.SetProperty( Actor::Property::POSITION, Vector2( 0, y )); + float y = Clamp(gesturePosition.y, size.y * 0.5f, windowSize.y - size.y * 0.5f); + mGrabbedActor.SetProperty(Actor::Property::POSITION, Vector2(0, y)); } else { @@ -106,7 +118,7 @@ void TextOverlapController::OnPan( Actor actor, const PanGesture& gesture ) } } -void TextOverlapController::Destroy( Application& app ) +void TextOverlapController::Destroy(Application& app) { mPanDetector.DetachAll(); UnparentAndReset(mLabels[0]); @@ -114,39 +126,37 @@ void TextOverlapController::Destroy( Application& app ) mGrabbedActor.Reset(); } -bool TextOverlapController::OnClicked( Button button ) +bool TextOverlapController::OnClicked(Button button) { - mTopmostLabel = 1-mTopmostLabel; // toggles between 0 and 1 + mTopmostLabel = 1 - mTopmostLabel; // toggles between 0 and 1 mLabels[mTopmostLabel].RaiseToTop(); return false; } - -void TextOverlapController::OnKeyEvent( const KeyEvent& keyEvent ) +void TextOverlapController::OnKeyEvent(const KeyEvent& keyEvent) { - if( keyEvent.GetState() == KeyEvent::DOWN && - ( IsKey( keyEvent, DALI_KEY_BACK ) || - IsKey( keyEvent, DALI_KEY_ESCAPE ) ) ) + if(keyEvent.GetState() == KeyEvent::DOWN && + (IsKey(keyEvent, DALI_KEY_BACK) || + IsKey(keyEvent, DALI_KEY_ESCAPE))) { mApplication.Quit(); } else { - Dali::Layer l = mApplication.GetWindow().GetRootLayer(); - int so = l.GetProperty(Dali::DevelActor::Property::SIBLING_ORDER); - l.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, so+1); + Dali::Layer l = mApplication.GetWindow().GetRootLayer(); + int so = l.GetProperty(Dali::DevelActor::Property::SIBLING_ORDER); + l.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, so + 1); } } - } // namespace Demo -int DALI_EXPORT_API main( int argc, char** argv ) +int DALI_EXPORT_API main(int argc, char** argv) { { - Application app = Application::New( &argc, &argv ); - Demo::TextOverlapController controller( app ); + Application app = Application::New(&argc, &argv); + Demo::TextOverlapController controller(app); app.MainLoop(); } - exit( 0 ); + exit(0); } diff --git a/examples/text-overlap/text-overlap-example.h b/examples/text-overlap/text-overlap-example.h index b15f67d..11f4249 100644 --- a/examples/text-overlap/text-overlap-example.h +++ b/examples/text-overlap/text-overlap-example.h @@ -1,28 +1,45 @@ #pragma once +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + namespace Demo { - class TextOverlapController : public Dali::ConnectionTracker { public: - TextOverlapController( Dali::Application& app ); + TextOverlapController(Dali::Application& app); private: - void Create( Dali::Application& app ); + void Create(Dali::Application& app); void Create2(); - void Destroy( Dali::Application& app ); - void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture ); - void OnKeyEvent( const Dali::KeyEvent& keyEvent ); - bool OnClicked( Dali::Toolkit::Button button ); + void Destroy(Dali::Application& app); + void OnPan(Dali::Actor actor, const Dali::PanGesture& gesture); + void OnKeyEvent(const Dali::KeyEvent& keyEvent); + bool OnClicked(Dali::Toolkit::Button button); private: - Dali::Application& mApplication; + Dali::Application& mApplication; Dali::Toolkit::TextLabel mLabels[2]; Dali::PanGestureDetector mPanDetector; - Dali::Actor mGrabbedActor; - Dali::Toolkit::Button mSwapButton; - int mTopmostLabel; + Dali::Actor mGrabbedActor; + Dali::Toolkit::Button mSwapButton; + int mTopmostLabel; }; -} +} // namespace Demo diff --git a/examples/text-scrolling/text-scrolling-example.cpp b/examples/text-scrolling/text-scrolling-example.cpp old mode 100755 new mode 100644 index 9930073..85f92cd --- a/examples/text-scrolling/text-scrolling-example.cpp +++ b/examples/text-scrolling/text-scrolling-example.cpp @@ -28,44 +28,42 @@ using namespace Dali::Toolkit; namespace { -const float WINDOW_HEIGHT_MULTIPLIER( 1.5f ); -const Vector2 BOX_SIZE( Vector2(330.0f, 80.0f ) ); -const Vector2 SCROLLING_BOX_SIZE( Vector2(330.0f, 40.0f ) ); -const float MAX_OFFSCREEN_RENDERING_SIZE = 2048.f; -const float SCREEN_BORDER = 5.0f; // Border around screen that Popups and handles will not exceed +const float WINDOW_HEIGHT_MULTIPLIER(1.5f); +const Vector2 BOX_SIZE(Vector2(330.0f, 80.0f)); +const Vector2 SCROLLING_BOX_SIZE(Vector2(330.0f, 40.0f)); +const float MAX_OFFSCREEN_RENDERING_SIZE = 2048.f; +const float SCREEN_BORDER = 5.0f; // Border around screen that Popups and handles will not exceed -const char * ALIGNMENT_TABLE[] = -{ - "BEGIN", - "CENTER", - "END" -}; -const unsigned int ALIGNMENT_TABLE_COUNT = sizeof( ALIGNMENT_TABLE ) / sizeof( ALIGNMENT_TABLE[ 0 ] ); +const char* ALIGNMENT_TABLE[] = + { + "BEGIN", + "CENTER", + "END"}; +const unsigned int ALIGNMENT_TABLE_COUNT = sizeof(ALIGNMENT_TABLE) / sizeof(ALIGNMENT_TABLE[0]); enum Labels { - SMALL = 1u, - RTL = 1u << 1, - LARGE = 1u << 2, + SMALL = 1u, + RTL = 1u << 1, + LARGE = 1u << 2, RTL_LONG = 1u << 4, - NONE = 1u << 6, + NONE = 1u << 6, }; -} +} // namespace /** * @brief The main class of the demo. */ class TextScrollingExample : public ConnectionTracker { public: - - TextScrollingExample( Application& application ) - : mApplication( application ), + TextScrollingExample(Application& application) + : mApplication(application), mTargetActorPosition(), mTargetActorSize(), - mToggleColor( false ) + mToggleColor(false) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextScrollingExample::Create ); + mApplication.InitSignal().Connect(this, &TextScrollingExample::Create); } ~TextScrollingExample() @@ -73,79 +71,77 @@ public: // Nothing to do here. } - - void CreateBox( const std::string& name, Actor& box, Actor parent, const Vector2& size ) + void CreateBox(const std::string& name, Actor& box, Actor parent, const Vector2& size) { - box.SetProperty( Dali::Actor::Property::NAME,name); - box.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - box.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - box.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); - box.SetResizePolicy( ResizePolicy::FIXED, Dimension::WIDTH ); - box.SetProperty( Actor::Property::SIZE, Vector2( size.width, 0.f ) ); - parent.Add( box ); + box.SetProperty(Dali::Actor::Property::NAME, name); + box.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + box.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + box.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + box.SetResizePolicy(ResizePolicy::FIXED, Dimension::WIDTH); + box.SetProperty(Actor::Property::SIZE, Vector2(size.width, 0.f)); + parent.Add(box); Dali::Property::Map border; - border.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER ); - border.Insert( BorderVisual::Property::COLOR, Color::BLUE ); - border.Insert( BorderVisual::Property::SIZE, 1.f ); - box.SetProperty( Control::Property::BACKGROUND, border ); + border.Insert(Toolkit::Visual::Property::TYPE, Visual::BORDER); + border.Insert(BorderVisual::Property::COLOR, Color::BLUE); + border.Insert(BorderVisual::Property::SIZE, 1.f); + box.SetProperty(Control::Property::BACKGROUND, border); } - void CreateLabel( Actor& label, const std::string text, Actor parent, bool scrollOnStart, PushButton button ) + void CreateLabel(Actor& label, const std::string text, Actor parent, bool scrollOnStart, PushButton button) { - label = TextLabel::New( text ); - label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - label.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - label.SetProperty( Actor::Property::PADDING, Padding( 1.0f, 1.0f, 1.0f, 1.0f ) ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - parent.Add( label ); - - if ( scrollOnStart ) + label = TextLabel::New(text); + label.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + label.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + label.SetProperty(Actor::Property::PADDING, Padding(1.0f, 1.0f, 1.0f, 1.0f)); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + parent.Add(label); + + if(scrollOnStart) { label.SetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL, true); } - button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - button.SetProperty( Actor::Property::SIZE, Vector2(BOX_SIZE.height,BOX_SIZE.height) ); - button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT ); - button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + button.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + button.SetProperty(Actor::Property::SIZE, Vector2(BOX_SIZE.height, BOX_SIZE.height)); + button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); parent.Add(button); } - /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); - mWindowSize = window.GetSize(); + mWindowSize = window.GetSize(); window.KeyEventSignal().Connect(this, &TextScrollingExample::OnKeyEvent); // Create Root actor Actor rootActor = Actor::New(); - rootActor.SetProperty( Dali::Actor::Property::NAME,"rootActor"); - rootActor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - rootActor.SetProperty( Actor::Property::SIZE, mWindowSize ); - rootActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + rootActor.SetProperty(Dali::Actor::Property::NAME, "rootActor"); + rootActor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + rootActor.SetProperty(Actor::Property::SIZE, mWindowSize); + rootActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); - window.Add( rootActor ); + window.Add(rootActor); - mAnimation = Animation::New( 1.0f ); + mAnimation = Animation::New(1.0f); - const Size mTargetActorSize( mWindowSize.width, mWindowSize.height * WINDOW_HEIGHT_MULTIPLIER ); + const Size mTargetActorSize(mWindowSize.width, mWindowSize.height * WINDOW_HEIGHT_MULTIPLIER); // Create Desktop Control desktop = Control::New(); - desktop.SetBackgroundColor( Color::WHITE ); - desktop.SetProperty( Dali::Actor::Property::NAME,"desktopActor"); - desktop.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - desktop.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - desktop.SetProperty( Actor::Property::SIZE, mTargetActorSize ); + desktop.SetBackgroundColor(Color::WHITE); + desktop.SetProperty(Dali::Actor::Property::NAME, "desktopActor"); + desktop.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + desktop.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + desktop.SetProperty(Actor::Property::SIZE, mTargetActorSize); - rootActor.Add( desktop ); // Add desktop (content) to offscreen actor + rootActor.Add(desktop); // Add desktop (content) to offscreen actor // Create Boxes Control boxA = Control::New(); @@ -154,165 +150,165 @@ public: Control boxD = Control::New(); Control boxE = Control::New(); - CreateBox( "boxA", boxA, desktop, BOX_SIZE ); - boxA.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -500.0f, 1.0f )); + CreateBox("boxA", boxA, desktop, BOX_SIZE); + boxA.SetProperty(Actor::Property::POSITION, Vector3(0.0f, -500.0f, 1.0f)); // Create TextField TextField field = TextField::New(); - field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - field.SetProperty( Actor::Property::PADDING, Padding( 1.0f, 1.0f, 1.0f, 1.0f ) ); - field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Enter Folder Name" ); - field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( SCREEN_BORDER, SCREEN_BORDER, mWindowSize.width - SCREEN_BORDER*2, mWindowSize.height - SCREEN_BORDER*2 ) ); - boxA.Add( field ); - boxA.SetProperty( Actor::Property::SIZE, BOX_SIZE); - - CreateBox( "boxB", boxB, desktop, SCROLLING_BOX_SIZE ); - boxB.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -400.0f, 1.0f )); + field.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + field.SetProperty(Actor::Property::PADDING, Padding(1.0f, 1.0f, 1.0f, 1.0f)); + field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + field.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Enter Folder Name"); + field.SetProperty(TextField::Property::DECORATION_BOUNDING_BOX, Rect(SCREEN_BORDER, SCREEN_BORDER, mWindowSize.width - SCREEN_BORDER * 2, mWindowSize.height - SCREEN_BORDER * 2)); + boxA.Add(field); + boxA.SetProperty(Actor::Property::SIZE, BOX_SIZE); + + CreateBox("boxB", boxB, desktop, SCROLLING_BOX_SIZE); + boxB.SetProperty(Actor::Property::POSITION, Vector3(0.0f, -400.0f, 1.0f)); Toolkit::PushButton scrollLargeButton = Toolkit::PushButton::New(); - scrollLargeButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedLarge ); - CreateLabel( mLargeLabel, "A Quick Brown Fox Jumps Over The Lazy Dog", boxB, false ,scrollLargeButton ); + scrollLargeButton.ClickedSignal().Connect(this, &TextScrollingExample::OnButtonClickedLarge); + CreateLabel(mLargeLabel, "A Quick Brown Fox Jumps Over The Lazy Dog", boxB, false, scrollLargeButton); - CreateBox( "boxC", boxC, desktop, SCROLLING_BOX_SIZE ); - boxC.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -300.0f, 1.0f )); + CreateBox("boxC", boxC, desktop, SCROLLING_BOX_SIZE); + boxC.SetProperty(Actor::Property::POSITION, Vector3(0.0f, -300.0f, 1.0f)); Toolkit::PushButton scrollSmallButton = Toolkit::PushButton::New(); - scrollSmallButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedSmall ); - CreateLabel( mSmallLabel, "Hello Text", boxC , true, scrollSmallButton ); - mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK ); + scrollSmallButton.ClickedSignal().Connect(this, &TextScrollingExample::OnButtonClickedSmall); + CreateLabel(mSmallLabel, "Hello Text", boxC, true, scrollSmallButton); + mSmallLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLACK); Property::Map shadowMap; - shadowMap.Insert( "color", Color::CYAN ); - shadowMap.Insert( "offset", Vector2( 1.0f, 1.0f ) ); - mSmallLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); + shadowMap.Insert("color", Color::CYAN); + shadowMap.Insert("offset", Vector2(1.0f, 1.0f)); + mSmallLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); - CreateBox( "boxD", boxD, desktop, SCROLLING_BOX_SIZE ); - boxD.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -200.0f, 1.0f )); + CreateBox("boxD", boxD, desktop, SCROLLING_BOX_SIZE); + boxD.SetProperty(Actor::Property::POSITION, Vector3(0.0f, -200.0f, 1.0f)); Toolkit::PushButton scrollRtlButton = Toolkit::PushButton::New(); - scrollRtlButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedRtl ); - CreateLabel( mRtlLabel, "مرحبا بالعالم", boxD , true, scrollRtlButton ); - mRtlLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_STOP_MODE, TextLabel::AutoScrollStopMode::IMMEDIATE ); - mRtlLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_LOOP_DELAY, 0.3f ); + scrollRtlButton.ClickedSignal().Connect(this, &TextScrollingExample::OnButtonClickedRtl); + CreateLabel(mRtlLabel, "مرحبا بالعالم", boxD, true, scrollRtlButton); + mRtlLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_STOP_MODE, TextLabel::AutoScrollStopMode::IMMEDIATE); + mRtlLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_LOOP_DELAY, 0.3f); - CreateBox( "boxE", boxE, desktop, SCROLLING_BOX_SIZE ); - boxE.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, -100.0f, 1.0f )); + CreateBox("boxE", boxE, desktop, SCROLLING_BOX_SIZE); + boxE.SetProperty(Actor::Property::POSITION, Vector3(0.0f, -100.0f, 1.0f)); Toolkit::PushButton scrollRtlLongButton = Toolkit::PushButton::New(); - scrollRtlLongButton.ClickedSignal().Connect( this, &TextScrollingExample::OnButtonClickedRtlLong ); - CreateLabel( mRtlLongLabel, " مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم", boxE , false, scrollRtlLongButton ); + scrollRtlLongButton.ClickedSignal().Connect(this, &TextScrollingExample::OnButtonClickedRtlLong); + CreateLabel(mRtlLongLabel, " مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم مرحبا بالعالم", boxE, false, scrollRtlLongButton); mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_SPEED, 500); mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_GAP, 500); mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_LOOP_COUNT, 3); - mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_STOP_MODE, TextLabel::AutoScrollStopMode::FINISH_LOOP ); + mRtlLongLabel.SetProperty(TextLabel::Property::AUTO_SCROLL_STOP_MODE, TextLabel::AutoScrollStopMode::FINISH_LOOP); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.DetectedSignal().Connect(this, &TextScrollingExample::OnPanGesture ); - mPanGestureDetector.Attach( desktop ); + mPanGestureDetector.DetectedSignal().Connect(this, &TextScrollingExample::OnPanGesture); + mPanGestureDetector.Attach(desktop); Toolkit::PushButton colorButton = Toolkit::PushButton::New(); - colorButton.SetProperty( Button::Property::TOGGLABLE, true ); - colorButton.SetProperty( Button::Property::UNSELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Toolkit::Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::RED ) ); - colorButton.SetProperty( Button::Property::SELECTED_BACKGROUND_VISUAL, Property::Map().Add ( Toolkit::Visual::Property::TYPE, Visual::COLOR ).Add( ColorVisual::Property::MIX_COLOR, Color::BLACK ) ); - colorButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - colorButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - colorButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - colorButton.SetProperty( Actor::Property::SIZE, Vector2(BOX_SIZE.height,BOX_SIZE.height) ); - colorButton.ClickedSignal().Connect( this, &TextScrollingExample::OnColorButtonClicked ); - rootActor.Add( colorButton ); - - for( unsigned int i = 0; i < ALIGNMENT_TABLE_COUNT; ++i ) + colorButton.SetProperty(Button::Property::TOGGLABLE, true); + colorButton.SetProperty(Button::Property::UNSELECTED_BACKGROUND_VISUAL, Property::Map().Add(Toolkit::Visual::Property::TYPE, Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::RED)); + colorButton.SetProperty(Button::Property::SELECTED_BACKGROUND_VISUAL, Property::Map().Add(Toolkit::Visual::Property::TYPE, Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::BLACK)); + colorButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + colorButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + colorButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + colorButton.SetProperty(Actor::Property::SIZE, Vector2(BOX_SIZE.height, BOX_SIZE.height)); + colorButton.ClickedSignal().Connect(this, &TextScrollingExample::OnColorButtonClicked); + rootActor.Add(colorButton); + + for(unsigned int i = 0; i < ALIGNMENT_TABLE_COUNT; ++i) { - Toolkit::RadioButton alignButton = Toolkit::RadioButton::New( ALIGNMENT_TABLE[ i ] ); - alignButton.ClickedSignal().Connect( this, &TextScrollingExample::OnAlignButtonClicked ); - alignButton.SetProperty( Dali::Actor::Property::NAME, ALIGNMENT_TABLE[ i ] ); + Toolkit::RadioButton alignButton = Toolkit::RadioButton::New(ALIGNMENT_TABLE[i]); + alignButton.ClickedSignal().Connect(this, &TextScrollingExample::OnAlignButtonClicked); + alignButton.SetProperty(Dali::Actor::Property::NAME, ALIGNMENT_TABLE[i]); // Place first button to left aligned, second center aligned and third right aligned - alignButton.SetProperty( Actor::Property::ANCHOR_POINT, Vector3( i * 0.5f, 0.0f, 0.5f ) ); - alignButton.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( i * 0.5f, 0.0f, 0.5f ) ); + alignButton.SetProperty(Actor::Property::ANCHOR_POINT, Vector3(i * 0.5f, 0.0f, 0.5f)); + alignButton.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(i * 0.5f, 0.0f, 0.5f)); - rootActor.Add( alignButton ); + rootActor.Add(alignButton); - if( i == 0 ) + if(i == 0) { // Set the first button as selected - alignButton.SetProperty( Button::Property::SELECTED, true ); + alignButton.SetProperty(Button::Property::SELECTED, true); } } } - void EnableScrolling( Labels labels ) + void EnableScrolling(Labels labels) + { + Actor label; + switch(labels) { - Actor label; - switch( labels ) + case LARGE: { - case LARGE: - { - label = mLargeLabel; - break; - } - case RTL: - { - label = mRtlLabel; - break; - } - case SMALL: - { - label = mSmallLabel; - break; - } - case RTL_LONG: - { - label = mRtlLongLabel; - break; - } - case NONE: - { - return; - } + label = mLargeLabel; + break; } + case RTL: + { + label = mRtlLabel; + break; + } + case SMALL: + { + label = mSmallLabel; + break; + } + case RTL_LONG: + { + label = mRtlLongLabel; + break; + } + case NONE: + { + return; + } + } - if ( labels != NONE ) + if(labels != NONE) + { + Property::Value value = label.GetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL); + if(value.Get()) { - Property::Value value = label.GetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL); - if (value.Get< bool >()) - { - label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, false ); - } - else - { - label.SetProperty( TextLabel::Property::ENABLE_AUTO_SCROLL, true ); - } + label.SetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL, false); + } + else + { + label.SetProperty(TextLabel::Property::ENABLE_AUTO_SCROLL, true); } } + } - bool OnButtonClickedSmall( Toolkit::Button button ) + bool OnButtonClickedSmall(Toolkit::Button button) { - EnableScrolling( SMALL ); + EnableScrolling(SMALL); return true; } - bool OnButtonClickedLarge( Toolkit::Button button ) + bool OnButtonClickedLarge(Toolkit::Button button) { - EnableScrolling( LARGE ); + EnableScrolling(LARGE); return true; } - bool OnButtonClickedRtl( Toolkit::Button button ) + bool OnButtonClickedRtl(Toolkit::Button button) { - EnableScrolling( RTL ); + EnableScrolling(RTL); return true; } - bool OnButtonClickedRtlLong( Toolkit::Button button ) + bool OnButtonClickedRtlLong(Toolkit::Button button) { - EnableScrolling( RTL_LONG ); + EnableScrolling(RTL_LONG); return true; } - bool OnColorButtonClicked( Toolkit::Button button ) + bool OnColorButtonClicked(Toolkit::Button button) { Vector4 color = Color::RED; - if ( mToggleColor ) + if(mToggleColor) { - color = Color::BLACK; + color = Color::BLACK; mToggleColor = false; } else @@ -321,27 +317,27 @@ public: } Property::Map shadowMap; - shadowMap.Insert( "color", Color::BLACK ); - mSmallLabel.SetProperty( TextLabel::Property::SHADOW, shadowMap ); - mSmallLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); - mRtlLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); - mLargeLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); - mRtlLongLabel.SetProperty( TextLabel::Property::TEXT_COLOR, color ); + shadowMap.Insert("color", Color::BLACK); + mSmallLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap); + mSmallLabel.SetProperty(TextLabel::Property::TEXT_COLOR, color); + mRtlLabel.SetProperty(TextLabel::Property::TEXT_COLOR, color); + mLargeLabel.SetProperty(TextLabel::Property::TEXT_COLOR, color); + mRtlLongLabel.SetProperty(TextLabel::Property::TEXT_COLOR, color); return true; } - bool OnAlignButtonClicked( Toolkit::Button button ) + bool OnAlignButtonClicked(Toolkit::Button button) { - for( unsigned int index = 0; index < ALIGNMENT_TABLE_COUNT; ++index ) + for(unsigned int index = 0; index < ALIGNMENT_TABLE_COUNT; ++index) { - const std::string& buttonName = button.GetProperty< std::string >( Dali::Actor::Property::NAME ); - if( buttonName == ALIGNMENT_TABLE[ index ] ) + const std::string& buttonName = button.GetProperty(Dali::Actor::Property::NAME); + if(buttonName == ALIGNMENT_TABLE[index]) { - mSmallLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); - mRtlLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); - mLargeLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); - mRtlLongLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[ index ] ); + mSmallLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[index]); + mRtlLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[index]); + mLargeLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[index]); + mRtlLongLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_TABLE[index]); break; } } @@ -356,18 +352,18 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } else { - if ( event.GetKeyName() == "2" ) + if(event.GetKeyName() == "2") { - mAnimation.AnimateTo( Property( mSmallLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); - mAnimation.AnimateTo( Property( mLargeLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); - mAnimation.AnimateTo( Property( mRtlLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); - mAnimation.AnimateTo( Property( mRtlLongLabel, Actor::Property::SCALE ), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod( 1.0f, 1.0f ) ); + mAnimation.AnimateTo(Property(mSmallLabel, Actor::Property::SCALE), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(1.0f, 1.0f)); + mAnimation.AnimateTo(Property(mLargeLabel, Actor::Property::SCALE), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(1.0f, 1.0f)); + mAnimation.AnimateTo(Property(mRtlLabel, Actor::Property::SCALE), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(1.0f, 1.0f)); + mAnimation.AnimateTo(Property(mRtlLongLabel, Actor::Property::SCALE), Vector3(1.2f, 1.2f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(1.0f, 1.0f)); mAnimation.Play(); } @@ -375,20 +371,19 @@ public: } } - void OnPanGesture( Actor actor, const PanGesture& gesture ) + void OnPanGesture(Actor actor, const PanGesture& gesture) { - if( gesture.GetState() == GestureState::CONTINUING ) + if(gesture.GetState() == GestureState::CONTINUING) { mTargetActorPosition.y = mTargetActorPosition.y + gesture.GetDisplacement().y; - mTargetActorPosition.y = std::min( mTargetActorPosition.y, -mTargetActorSize.height ); - mTargetActorPosition.y = std::max( mTargetActorPosition.y, ( mTargetActorSize.height - mWindowSize.height*0.25f ) ); - actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, mTargetActorPosition.y )); + mTargetActorPosition.y = std::min(mTargetActorPosition.y, -mTargetActorSize.height); + mTargetActorPosition.y = std::max(mTargetActorPosition.y, (mTargetActorSize.height - mWindowSize.height * 0.25f)); + actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, mTargetActorPosition.y)); } } private: - - Application& mApplication; + Application& mApplication; PanGestureDetector mPanGestureDetector; Vector2 mTargetActorPosition; @@ -405,10 +400,10 @@ private: bool mToggleColor; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - TextScrollingExample test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + TextScrollingExample test(application); application.MainLoop(); return 0; } diff --git a/examples/textured-mesh/textured-mesh-example.cpp b/examples/textured-mesh/textured-mesh-example.cpp index 923aa08..9927620 100644 --- a/examples/textured-mesh/textured-mesh-example.cpp +++ b/examples/textured-mesh/textured-mesh-example.cpp @@ -19,47 +19,43 @@ #include // INTERNAL INCLUDES -#include "shared/view.h" #include "shared/utility.h" +#include "shared/view.h" using namespace Dali; namespace { -const char* MATERIAL_SAMPLE( DEMO_IMAGE_DIR "gallery-small-48.jpg" ); -const char* MATERIAL_SAMPLE2( DEMO_IMAGE_DIR "gallery-medium-19.jpg" ); +const char* MATERIAL_SAMPLE(DEMO_IMAGE_DIR "gallery-small-48.jpg"); +const char* MATERIAL_SAMPLE2(DEMO_IMAGE_DIR "gallery-medium-19.jpg"); -#define MAKE_SHADER(A)#A +#define MAKE_SHADER(A) #A const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aPosition; -attribute highp vec2 aTexCoord; -varying mediump vec2 vTexCoord; -uniform mediump mat4 uMvpMatrix; -uniform mediump vec3 uSize; -uniform lowp vec4 uFadeColor; - -void main() -{ - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); - vertexPosition.xyz *= uSize; - vertexPosition = uMvpMatrix * vertexPosition; - vTexCoord = aTexCoord; - gl_Position = vertexPosition; -} -); + attribute mediump vec2 aPosition; + attribute highp vec2 aTexCoord; + varying mediump vec2 vTexCoord; + uniform mediump mat4 uMvpMatrix; + uniform mediump vec3 uSize; + uniform lowp vec4 uFadeColor; + + void main() { + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); + vertexPosition.xyz *= uSize; + vertexPosition = uMvpMatrix * vertexPosition; + vTexCoord = aTexCoord; + gl_Position = vertexPosition; + }); const char* FRAGMENT_SHADER = MAKE_SHADER( -varying mediump vec2 vTexCoord; -uniform lowp vec4 uColor; -uniform sampler2D sTexture; -uniform lowp vec4 uFadeColor; + varying mediump vec2 vTexCoord; + uniform lowp vec4 uColor; + uniform sampler2D sTexture; + uniform lowp vec4 uFadeColor; -void main() -{ - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * uFadeColor; -} -); + void main() { + gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * uFadeColor; + }); /** * Sinusoidal curve starting at zero with 2 cycles @@ -76,16 +72,15 @@ float AlphaFunctionSineX2(float progress) class ExampleController : public ConnectionTracker { public: - /** * The example controller constructor. * @param[in] application The application instance */ - ExampleController( Application& application ) - : mApplication( application ) + ExampleController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ExampleController::Create ); + mApplication.InitSignal().Connect(this, &ExampleController::Create); } /** @@ -100,7 +95,7 @@ public: * Invoked upon creation of application * @param[in] application The application instance */ - void Create( Application& application ) + void Create(Application& application) { // The Init signal is received once (only) during the Application lifetime @@ -109,61 +104,61 @@ public: mWindowSize = window.GetSize(); - Texture texture1 = DemoHelper::LoadTexture( MATERIAL_SAMPLE ); - Texture texture2 = DemoHelper::LoadTexture( MATERIAL_SAMPLE2 ); + Texture texture1 = DemoHelper::LoadTexture(MATERIAL_SAMPLE); + Texture texture2 = DemoHelper::LoadTexture(MATERIAL_SAMPLE2); - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New(VERTEX_SHADER, FRAGMENT_SHADER); mTextureSet1 = TextureSet::New(); - mTextureSet1.SetTexture( 0u, texture1 ); + mTextureSet1.SetTexture(0u, texture1); mTextureSet2 = TextureSet::New(); - mTextureSet2.SetTexture( 0u, texture2 ); + mTextureSet2.SetTexture(0u, texture2); mGeometry = DemoHelper::CreateTexturedQuad(); - mRenderer = Renderer::New( mGeometry, mShader ); - mRenderer.SetTextures( mTextureSet1 ); + mRenderer = Renderer::New(mGeometry, mShader); + mRenderer.SetTextures(mTextureSet1); mMeshActor = Actor::New(); - mMeshActor.AddRenderer( mRenderer ); - mMeshActor.SetProperty( Actor::Property::SIZE, Vector2(400, 400) ); + mMeshActor.AddRenderer(mRenderer); + mMeshActor.SetProperty(Actor::Property::SIZE, Vector2(400, 400)); - Property::Index fadeColorIndex = mRenderer.RegisterProperty( "uFadeColor", Color::MAGENTA ); - mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, 0 ); + Property::Index fadeColorIndex = mRenderer.RegisterProperty("uFadeColor", Color::MAGENTA); + mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 0); - mMeshActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - mMeshActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - window.Add( mMeshActor ); + mMeshActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + mMeshActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + window.Add(mMeshActor); - mRenderer2 = Renderer::New( mGeometry, mShader ); - mRenderer2.SetTextures( mTextureSet2 ); + mRenderer2 = Renderer::New(mGeometry, mShader); + mRenderer2.SetTextures(mTextureSet2); mMeshActor2 = Actor::New(); - mMeshActor2.AddRenderer( mRenderer2 ); - mMeshActor2.SetProperty( Actor::Property::SIZE, Vector2(400, 400) ); + mMeshActor2.AddRenderer(mRenderer2); + mMeshActor2.SetProperty(Actor::Property::SIZE, Vector2(400, 400)); - mMeshActor2.RegisterProperty( "anotherProperty", Color::GREEN ); + mMeshActor2.RegisterProperty("anotherProperty", Color::GREEN); - mRenderer2.RegisterProperty( "anotherProperty", Vector3::ZERO ); - mRenderer2.RegisterProperty( "aCoefficient", 0.008f ); - Property::Index fadeColorIndex2 = mRenderer2.RegisterProperty( "uFadeColor", Color::BLUE ); - mRenderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 0 ); + mRenderer2.RegisterProperty("anotherProperty", Vector3::ZERO); + mRenderer2.RegisterProperty("aCoefficient", 0.008f); + Property::Index fadeColorIndex2 = mRenderer2.RegisterProperty("uFadeColor", Color::BLUE); + mRenderer2.SetProperty(Renderer::Property::DEPTH_INDEX, 0); - mMeshActor2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER ); - mMeshActor2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - window.Add( mMeshActor2 ); + mMeshActor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER); + mMeshActor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + window.Add(mMeshActor2); - Animation animation = Animation::New(5); + Animation animation = Animation::New(5); KeyFrames keyFrames = KeyFrames::New(); keyFrames.Add(0.0f, Vector4::ZERO); - keyFrames.Add(1.0f, Vector4( Color::GREEN )); + keyFrames.Add(1.0f, Vector4(Color::GREEN)); KeyFrames keyFrames2 = KeyFrames::New(); keyFrames2.Add(0.0f, Vector4::ZERO); keyFrames2.Add(1.0f, Color::MAGENTA); - animation.AnimateBetween( Property( mRenderer, fadeColorIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); - animation.AnimateBetween( Property( mRenderer2, fadeColorIndex2 ), keyFrames2, AlphaFunction(AlphaFunctionSineX2) ); + animation.AnimateBetween(Property(mRenderer, fadeColorIndex), keyFrames, AlphaFunction(AlphaFunction::SIN)); + animation.AnimateBetween(Property(mRenderer2, fadeColorIndex2), keyFrames2, AlphaFunction(AlphaFunctionSineX2)); animation.SetLooping(true); animation.Play(); @@ -174,7 +169,7 @@ public: * Invoked whenever the quit button is clicked * @param[in] button the quit button */ - bool OnQuitButtonClicked( Toolkit::Button button ) + bool OnQuitButtonClicked(Toolkit::Button button) { // quit the application mApplication.Quit(); @@ -185,7 +180,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -193,25 +188,24 @@ public: } private: + Application& mApplication; ///< Application instance + Vector3 mWindowSize; ///< The size of the window - Application& mApplication; ///< Application instance - Vector3 mWindowSize; ///< The size of the window - - Shader mShader; + Shader mShader; TextureSet mTextureSet1; TextureSet mTextureSet2; - Geometry mGeometry; - Renderer mRenderer; - Actor mMeshActor; - Renderer mRenderer2; - Actor mMeshActor2; - Timer mChangeImageTimer; + Geometry mGeometry; + Renderer mRenderer; + Actor mMeshActor; + Renderer mRenderer2; + Actor mMeshActor2; + Timer mChangeImageTimer; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ExampleController test( application ); + Application application = Application::New(&argc, &argv); + ExampleController test(application); application.MainLoop(); return 0; } diff --git a/examples/tilt/tilt-example.cpp b/examples/tilt/tilt-example.cpp index d9dd48b..959b782 100644 --- a/examples/tilt/tilt-example.cpp +++ b/examples/tilt/tilt-example.cpp @@ -26,11 +26,11 @@ using Dali::Toolkit::TextLabel; class TiltController : public ConnectionTracker { public: - TiltController( Application& application ) - : mApplication( application ) + TiltController(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TiltController::Create ); + mApplication.InitSignal().Connect(this, &TiltController::Create); } ~TiltController() @@ -39,42 +39,42 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::BLUE); - - mTextLabel = TextLabel::New( "Tilt Sensor Demo" ); - mTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mTextLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - mTextLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - mTextLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mTextLabel.SetProperty( TextLabel::Property::POINT_SIZE, 15.0f ); - mTextLabel.SetProperty( Dali::Actor::Property::NAME, "tiltLabel" ); - window.Add( mTextLabel ); + window.SetBackgroundColor(Color::BLUE); + + mTextLabel = TextLabel::New("Tilt Sensor Demo"); + mTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mTextLabel.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + mTextLabel.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + mTextLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE); + mTextLabel.SetProperty(TextLabel::Property::POINT_SIZE, 15.0f); + mTextLabel.SetProperty(Dali::Actor::Property::NAME, "tiltLabel"); + window.Add(mTextLabel); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &TiltController::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &TiltController::OnTouch); CreateSensor(); // Connect signals to allow Back and Escape to exit. - window.KeyEventSignal().Connect( this, &TiltController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &TiltController::OnKeyEvent); } void CreateSensor() { mTiltSensor = TiltSensor::Get(); - if ( mTiltSensor.Start() ) + if(mTiltSensor.Start()) { // Get notifications when the device is tilted - mTiltSensor.TiltedSignal().Connect( this, &TiltController::OnTilted ); + mTiltSensor.TiltedSignal().Connect(this, &TiltController::OnTilted); } } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -86,20 +86,21 @@ public: Quaternion pitchRot(Radian(Degree(sensor.GetPitch() * 90.0f)), Vector3(1, 0, 0)); Quaternion rollRot(Radian(Degree(sensor.GetRoll() * 90.0f)), Vector3(0, 1, 0)); - mTextLabel.SetProperty( Actor::Property::ORIENTATION, Quaternion() ); + mTextLabel.SetProperty(Actor::Property::ORIENTATION, Quaternion()); mTextLabel.RotateBy(rollRot); - mTextLabel.RotateBy(pitchRot);; + mTextLabel.RotateBy(pitchRot); + ; } /** * @brief OnKeyEvent signal handler. * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -107,15 +108,15 @@ public: } private: - Application& mApplication; - TiltSensor mTiltSensor; - TextLabel mTextLabel; + Application& mApplication; + TiltSensor mTiltSensor; + TextLabel mTextLabel; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - TiltController test( application ); + Application application = Application::New(&argc, &argv); + TiltController test(application); application.MainLoop(); return 0; diff --git a/examples/tooltip/tooltip-example.cpp b/examples/tooltip/tooltip-example.cpp index 279b00e..ab1223a 100644 --- a/examples/tooltip/tooltip-example.cpp +++ b/examples/tooltip/tooltip-example.cpp @@ -24,9 +24,9 @@ using namespace Dali::Toolkit; namespace { -const Vector4 WINDOW_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the window -const char * const THEME_PATH( DEMO_STYLE_DIR "tooltip-example-theme.json" ); ///< The theme used for this example -const float POSITION_INCREMENTER( 0.2f ); ///< The position difference between the controls along the Y-Axis. +const Vector4 WINDOW_COLOR(211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f); ///< The color of the window +const char* const THEME_PATH(DEMO_STYLE_DIR "tooltip-example-theme.json"); ///< The theme used for this example +const float POSITION_INCREMENTER(0.2f); ///< The position difference between the controls along the Y-Axis. } // unnamed namespace /** @@ -38,75 +38,72 @@ const float POSITION_INCREMENTER( 0.2f ); ///< The position difference between t class TooltipController : public ConnectionTracker { public: - - TooltipController( Application& application ) - : mApplication( application ), - previousPosition( 0.0f ) + TooltipController(Application& application) + : mApplication(application), + previousPosition(0.0f) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TooltipController::Create ); + mApplication.InitSignal().Connect(this, &TooltipController::Create); } private: - // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Set the window background color and connect to the window's key signal to allow Back and Escape to exit. Window window = application.GetWindow(); - window.SetBackgroundColor( WINDOW_COLOR ); - window.KeyEventSignal().Connect( this, &TooltipController::OnKeyEvent ); + window.SetBackgroundColor(WINDOW_COLOR); + window.KeyEventSignal().Connect(this, &TooltipController::OnKeyEvent); const Vector2 windowSize = window.GetSize(); // Add a text label at the top for information purposes - Control label = TextLabel::New( "Hover over buttons to see tooltip" ); - label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "Center" ); - window.Add( label ); + Control label = TextLabel::New("Hover over buttons to see tooltip"); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + label.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "Center"); + window.Add(label); // Simple tooltip from stylesheet Control simple = PushButton::New(); - simple.SetStyleName( "TooltipTextOnly" ); - SetLabel( simple, "Simple" ); - Layout( simple, windowSize ); - window.Add( simple ); + simple.SetStyleName("TooltipTextOnly"); + SetLabel(simple, "Simple"); + Layout(simple, windowSize); + window.Add(simple); // Tooltip with icon and text, from stylesheet Control iconWithText = PushButton::New(); - iconWithText.SetStyleName( "TooltipArray" ); - SetLabel( iconWithText, "Icon with Text" ); - Layout( iconWithText, windowSize ); - window.Add( iconWithText ); + iconWithText.SetStyleName("TooltipArray"); + SetLabel(iconWithText, "Icon with Text"); + Layout(iconWithText, windowSize); + window.Add(iconWithText); // Tooltip with custom style, from stylesheet Control customFromStylesheet = PushButton::New(); - customFromStylesheet.SetStyleName( "TooltipCustom" ); - SetLabel( customFromStylesheet, "Custom From Stylesheet" ); - Layout( customFromStylesheet, windowSize ); - window.Add( customFromStylesheet ); + customFromStylesheet.SetStyleName("TooltipCustom"); + SetLabel(customFromStylesheet, "Custom From Stylesheet"); + Layout(customFromStylesheet, windowSize); + window.Add(customFromStylesheet); // Tooltip with custom style, from code Control customFromCode = PushButton::New(); - SetLabel( customFromCode, "Custom From Code" ); - Layout( customFromCode, windowSize ); - customFromCode.SetProperty( DevelControl::Property::TOOLTIP, - { { Tooltip::Property::CONTENT, - Property::Array{ { { { Toolkit::Visual::Property::TYPE, Visual::IMAGE }, - { ImageVisual::Property::URL, DEMO_IMAGE_DIR "Logo-for-demo.png" } } }, - { { { Toolkit::Visual::Property::TYPE, Visual::TEXT }, - { TextVisual::Property::TEXT_COLOR, Color::WHITE }, - { TextVisual::Property::TEXT, "Custom coded style\nat hover point" }, - { TextVisual::Property::MULTI_LINE, true }, - { TextVisual::Property::HORIZONTAL_ALIGNMENT, "CENTER" }, - { TextVisual::Property::POINT_SIZE, 16 } } } } }, - { Tooltip::Property::LAYOUT, Vector2( 2, 1 ) }, - { Tooltip::Property::POSITION, Tooltip::Position::HOVER_POINT }, - { Tooltip::Property::BACKGROUND, - { { Tooltip::Background::Property::VISUAL, DEMO_IMAGE_DIR "tooltip.9.png" }, - { Tooltip::Background::Property::BORDER, Rect< int >( 1, 5, 5, 1 ) } } } - } ); - window.Add( customFromCode ); + SetLabel(customFromCode, "Custom From Code"); + Layout(customFromCode, windowSize); + customFromCode.SetProperty(DevelControl::Property::TOOLTIP, + {{Tooltip::Property::CONTENT, + Property::Array{{{{Toolkit::Visual::Property::TYPE, Visual::IMAGE}, + {ImageVisual::Property::URL, DEMO_IMAGE_DIR "Logo-for-demo.png"}}}, + {{{Toolkit::Visual::Property::TYPE, Visual::TEXT}, + {TextVisual::Property::TEXT_COLOR, Color::WHITE}, + {TextVisual::Property::TEXT, "Custom coded style\nat hover point"}, + {TextVisual::Property::MULTI_LINE, true}, + {TextVisual::Property::HORIZONTAL_ALIGNMENT, "CENTER"}, + {TextVisual::Property::POINT_SIZE, 16}}}}}, + {Tooltip::Property::LAYOUT, Vector2(2, 1)}, + {Tooltip::Property::POSITION, Tooltip::Position::HOVER_POINT}, + {Tooltip::Property::BACKGROUND, + {{Tooltip::Background::Property::VISUAL, DEMO_IMAGE_DIR "tooltip.9.png"}, + {Tooltip::Background::Property::BORDER, Rect(1, 5, 5, 1)}}}}); + window.Add(customFromCode); } /** @@ -115,11 +112,11 @@ private: * Will use this to quit the application if Back or the Escape key is received * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -130,13 +127,12 @@ private: * @brief Sets the label on the control. * @param[in] label The label to set. */ - void SetLabel( Control control, std::string label ) + void SetLabel(Control control, std::string label) { - if( control ) + if(control) { - control.SetProperty( Button::Property::LABEL, - Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::TEXT ) - .Add( TextVisual::Property::TEXT, label ) ); + control.SetProperty(Button::Property::LABEL, + Property::Map().Add(Toolkit::Visual::Property::TYPE, Visual::TEXT).Add(TextVisual::Property::TEXT, label)); } } @@ -145,29 +141,29 @@ private: * @param[in] control The control to layout. * @param[in] windowSize The size of the window, passing it in so we don't have to retrieve it every time. */ - void Layout( Control control, const Vector2& windowSize ) + void Layout(Control control, const Vector2& windowSize) { - if( control ) + if(control) { previousPosition += POSITION_INCREMENTER; - control.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - control.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75, 0.1, 1.0 ) ); - control.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - control.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER ); - control.SetProperty( Actor::Property::POSITION_Y, windowSize.height * previousPosition ); + control.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + control.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75, 0.1, 1.0)); + control.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + control.SetProperty(Actor::Property::POSITION_Y, windowSize.height * previousPosition); } } private: - Application& mApplication; - float previousPosition; + Application& mApplication; + float previousPosition; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, THEME_PATH ); + Application application = Application::New(&argc, &argv, THEME_PATH); - TooltipController test( application ); + TooltipController test(application); application.MainLoop(); diff --git a/examples/transitions/shadow-button-impl.cpp b/examples/transitions/shadow-button-impl.cpp index 51867d6..1b1ece8 100644 --- a/examples/transitions/shadow-button-impl.cpp +++ b/examples/transitions/shadow-button-impl.cpp @@ -16,9 +16,9 @@ #include "shadow-button-impl.h" #include -#include -#include #include +#include +#include #include @@ -29,58 +29,54 @@ namespace Demo { namespace Internal { - namespace { - - Dali::BaseHandle Create() { return Demo::ShadowButton::New(); } -DALI_TYPE_REGISTRATION_BEGIN( ShadowButton, Dali::Toolkit::Button, Create ); +DALI_TYPE_REGISTRATION_BEGIN(ShadowButton, Dali::Toolkit::Button, Create); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "activeTransition", ARRAY, ACTIVE_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "inactiveTransition", ARRAY, INACTIVE_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "checkTransition", ARRAY, CHECK_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "uncheckTransition", ARRAY, UNCHECK_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "backgroundVisual", MAP, BACKGROUND_VISUAL ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "checkboxBgVisual", MAP, CHECKBOX_BG_VISUAL ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "checkboxFgVisual", MAP, CHECKBOX_FG_VISUAL ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "labelVisual", MAP, LABEL_VISUAL ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "checkState", BOOLEAN, ACTIVE_STATE ); -DALI_PROPERTY_REGISTRATION( Demo, ShadowButton, "checkState", BOOLEAN, CHECK_STATE ); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "activeTransition", ARRAY, ACTIVE_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "inactiveTransition", ARRAY, INACTIVE_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "checkTransition", ARRAY, CHECK_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "uncheckTransition", ARRAY, UNCHECK_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "backgroundVisual", MAP, BACKGROUND_VISUAL); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "checkboxBgVisual", MAP, CHECKBOX_BG_VISUAL); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "checkboxFgVisual", MAP, CHECKBOX_FG_VISUAL); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "labelVisual", MAP, LABEL_VISUAL); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "checkState", BOOLEAN, ACTIVE_STATE); +DALI_PROPERTY_REGISTRATION(Demo, ShadowButton, "checkState", BOOLEAN, CHECK_STATE); DALI_TYPE_REGISTRATION_END(); -DALI_ENUM_TO_STRING_TABLE_BEGIN( VISUAL_PROPERTIES ) -{ "backgroundVisual", Demo::ShadowButton::Property::BACKGROUND_VISUAL }, -{ "checkboxBgVisual", Demo::ShadowButton::Property::CHECKBOX_BG_VISUAL}, -{ "checkboxFgVisual", Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL}, -{ "labelVisual", Demo::ShadowButton::Property::LABEL_VISUAL} -DALI_ENUM_TO_STRING_TABLE_END( VISUAL_PROPERTIES ) +DALI_ENUM_TO_STRING_TABLE_BEGIN(VISUAL_PROPERTIES) + {"backgroundVisual", Demo::ShadowButton::Property::BACKGROUND_VISUAL}, + {"checkboxBgVisual", Demo::ShadowButton::Property::CHECKBOX_BG_VISUAL}, + {"checkboxFgVisual", Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL}, + {"labelVisual", Demo::ShadowButton::Property::LABEL_VISUAL} +DALI_ENUM_TO_STRING_TABLE_END(VISUAL_PROPERTIES) -Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& value ) +Toolkit::TransitionData ConvertPropertyToTransition(const Property::Value& value) { Toolkit::TransitionData transitionData; - if( value.GetType() == Property::ARRAY ) + if(value.GetType() == Property::ARRAY) { - transitionData = Toolkit::TransitionData::New( *value.GetArray()); + transitionData = Toolkit::TransitionData::New(*value.GetArray()); } - else if( value.GetType() == Property::MAP ) + else if(value.GetType() == Property::MAP) { - transitionData = Toolkit::TransitionData::New( *value.GetMap() ); + transitionData = Toolkit::TransitionData::New(*value.GetMap()); } return transitionData; } } // anonymous namespace - Internal::ShadowButton::ShadowButton() -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), mCheckState(false), mActiveState(false) { @@ -92,24 +88,24 @@ Internal::ShadowButton::~ShadowButton() Demo::ShadowButton Internal::ShadowButton::New() { - IntrusivePtr impl = new Internal::ShadowButton(); - Demo::ShadowButton handle = Demo::ShadowButton( *impl ); + IntrusivePtr impl = new Internal::ShadowButton(); + Demo::ShadowButton handle = Demo::ShadowButton(*impl); impl->Initialize(); return handle; } -void ShadowButton::SetActiveState( bool active ) +void ShadowButton::SetActiveState(bool active) { - if( active != mActiveState ) + if(active != mActiveState) { mActiveState = active; - if( active ) + if(active) { - StartTransition( Demo::ShadowButton::Property::ACTIVE_TRANSITION ); + StartTransition(Demo::ShadowButton::Property::ACTIVE_TRANSITION); } else { - StartTransition( Demo::ShadowButton::Property::INACTIVE_TRANSITION ); + StartTransition(Demo::ShadowButton::Property::INACTIVE_TRANSITION); } } } @@ -119,19 +115,19 @@ bool ShadowButton::GetActiveState() return mActiveState; } -void ShadowButton::SetCheckState( bool checkState ) +void ShadowButton::SetCheckState(bool checkState) { mCheckState = checkState; - DevelControl::EnableVisual( *this, Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL, true ); - if( Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) ) + DevelControl::EnableVisual(*this, Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL, true); + if(Self().GetProperty(Actor::Property::CONNECTED_TO_SCENE)) { - if( checkState ) + if(checkState) { - StartTransition( Demo::ShadowButton::Property::CHECK_TRANSITION ); + StartTransition(Demo::ShadowButton::Property::CHECK_TRANSITION); } else { - StartTransition( Demo::ShadowButton::Property::UNCHECK_TRANSITION ); + StartTransition(Demo::ShadowButton::Property::UNCHECK_TRANSITION); } } RelayoutRequest(); @@ -142,38 +138,38 @@ bool ShadowButton::GetCheckState() return mCheckState; } -void ShadowButton::StartTransition( Property::Index transitionId ) +void ShadowButton::StartTransition(Property::Index transitionId) { - Transitions::iterator iter = FindTransition( transitionId ); - if( iter != mTransitions.end() ) + Transitions::iterator iter = FindTransition(transitionId); + if(iter != mTransitions.end()) { - if( iter->mAnimation ) + if(iter->mAnimation) { iter->mAnimation.Stop(); iter->mPlaying = false; - iter->mAnimation.FinishedSignal().Disconnect( this, &ShadowButton::OnTransitionFinished ); + iter->mAnimation.FinishedSignal().Disconnect(this, &ShadowButton::OnTransitionFinished); } - iter->mAnimation = DevelControl::CreateTransition( *this, iter->mTransitionData ); - StoreTargetLayouts( iter->mTransitionData ); + iter->mAnimation = DevelControl::CreateTransition(*this, iter->mTransitionData); + StoreTargetLayouts(iter->mTransitionData); - iter->mAnimation.FinishedSignal().Connect( this, &ShadowButton::OnTransitionFinished ); + iter->mAnimation.FinishedSignal().Connect(this, &ShadowButton::OnTransitionFinished); iter->mAnimation.Play(); iter->mPlaying = true; } } -void ShadowButton::OnTransitionFinished( Animation& src ) +void ShadowButton::OnTransitionFinished(Animation& src) { ShadowButton::Transitions::iterator iter = mTransitions.begin(); - for( ; iter != mTransitions.end(); ++iter ) + for(; iter != mTransitions.end(); ++iter) { - if( iter->mAnimation == src ) + if(iter->mAnimation == src) { iter->mPlaying = false; iter->mAnimation.Reset(); // Remove the animation when it's finished. - switch( iter->mTransitionId ) + switch(iter->mTransitionId) { case Demo::ShadowButton::Property::ACTIVE_TRANSITION: { @@ -187,7 +183,7 @@ void ShadowButton::OnTransitionFinished( Animation& src ) } case Demo::ShadowButton::Property::UNCHECK_TRANSITION: { - DevelControl::EnableVisual( *this, Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL, false ); + DevelControl::EnableVisual(*this, Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL, false); break; } } @@ -201,9 +197,9 @@ void ShadowButton::OnInitialize() Actor self = Self(); } -void ShadowButton::OnSceneConnection( int depth ) +void ShadowButton::OnSceneConnection(int depth) { - Control::OnSceneConnection( depth ); + Control::OnSceneConnection(depth); } void ShadowButton::OnSceneDisconnection() @@ -211,55 +207,56 @@ void ShadowButton::OnSceneDisconnection() Control::OnSceneDisconnection(); } -void ShadowButton::OnSizeSet( const Vector3& targetSize ) +void ShadowButton::OnSizeSet(const Vector3& targetSize) { - Control::OnSizeSet( targetSize ); - RelayoutVisuals( Vector2( targetSize ) ); + Control::OnSizeSet(targetSize); + RelayoutVisuals(Vector2(targetSize)); } -void ShadowButton::OnRelayout( const Vector2& targetSize, RelayoutContainer& container ) +void ShadowButton::OnRelayout(const Vector2& targetSize, RelayoutContainer& container) { - RelayoutVisuals( targetSize ); + RelayoutVisuals(targetSize); } -void ShadowButton::RelayoutVisuals( const Vector2& targetSize ) +void ShadowButton::RelayoutVisuals(const Vector2& targetSize) { - bool transitioning = false; - ShadowButton::Transitions::iterator iter = mTransitions.begin(); - for( ; iter != mTransitions.end(); ++iter ) + bool transitioning = false; + ShadowButton::Transitions::iterator iter = mTransitions.begin(); + for(; iter != mTransitions.end(); ++iter) { - if( iter->mPlaying == true ) + if(iter->mPlaying == true) { transitioning = true; break; } } - if( ! transitioning ) + if(!transitioning) { - for( ShadowButton::Transforms::iterator iter = mTransforms.begin(); - iter != mTransforms.end(); ++iter ) + for(ShadowButton::Transforms::iterator iter = mTransforms.begin(); + iter != mTransforms.end(); + ++iter) { - switch( iter->mTransformId ) + switch(iter->mTransformId) { case Demo::ShadowButton::Property::BACKGROUND_VISUAL: { - mBackgroundVisual.SetTransformAndSize( iter->mTransform, targetSize ); + mBackgroundVisual.SetTransformAndSize(iter->mTransform, targetSize); break; } case Demo::ShadowButton::Property::CHECKBOX_BG_VISUAL: { - mCheckboxBgVisual.SetTransformAndSize( iter->mTransform, targetSize ); + mCheckboxBgVisual.SetTransformAndSize(iter->mTransform, targetSize); break; } case Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL: { - mCheckboxFgVisual.SetTransformAndSize( iter->mTransform, targetSize ); + mCheckboxFgVisual.SetTransformAndSize(iter->mTransform, targetSize); break; } case Demo::ShadowButton::Property::LABEL_VISUAL: { - mLabelVisual.SetTransformAndSize( iter->mTransform, targetSize ); + mLabelVisual.SetTransformAndSize(iter->mTransform, targetSize); break; } } @@ -275,54 +272,54 @@ Vector3 ShadowButton::GetNaturalSize() Vector2 checkboxBgSize; Vector2 checkboxFgSize; Vector2 labelSize; - mCheckboxBgVisual.GetNaturalSize( checkboxBgSize ); - mCheckboxFgVisual.GetNaturalSize( checkboxFgSize ); - mLabelVisual.GetNaturalSize( labelSize ); + mCheckboxBgVisual.GetNaturalSize(checkboxBgSize); + mCheckboxFgVisual.GetNaturalSize(checkboxFgSize); + mLabelVisual.GetNaturalSize(labelSize); - width = std::max( checkboxBgSize.x, checkboxFgSize.x ) + labelSize.x; - height = std::max( std::max( checkboxFgSize.y, checkboxBgSize.y ), labelSize.y ); + width = std::max(checkboxBgSize.x, checkboxFgSize.x) + labelSize.x; + height = std::max(std::max(checkboxFgSize.y, checkboxBgSize.y), labelSize.y); - return Vector3( width, height, height ); + return Vector3(width, height, height); } -void ShadowButton::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) +void ShadowButton::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) { // Chain up. - Control::OnStyleChange( styleManager, change ); + Control::OnStyleChange(styleManager, change); } -ShadowButton::Transitions::iterator ShadowButton::FindTransition( Property::Index index ) +ShadowButton::Transitions::iterator ShadowButton::FindTransition(Property::Index index) { - bool found = false; - ShadowButton::Transitions::iterator iter = mTransitions.begin(); - for( ; iter != mTransitions.end(); ++iter ) + bool found = false; + ShadowButton::Transitions::iterator iter = mTransitions.begin(); + for(; iter != mTransitions.end(); ++iter) { - if( iter->mTransitionId == index ) + if(iter->mTransitionId == index) { found = true; break; } } - if( ! found ) + if(!found) { iter = mTransitions.end(); } return iter; } -ShadowButton::Transforms::iterator ShadowButton::FindTransform( Property::Index index ) +ShadowButton::Transforms::iterator ShadowButton::FindTransform(Property::Index index) { - bool found = false; - ShadowButton::Transforms::iterator iter = mTransforms.begin(); - for( ; iter != mTransforms.end(); ++iter ) + bool found = false; + ShadowButton::Transforms::iterator iter = mTransforms.begin(); + for(; iter != mTransforms.end(); ++iter) { - if( iter->mTransformId == index ) + if(iter->mTransformId == index) { found = true; break; } } - if( ! found ) + if(!found) { iter = mTransforms.end(); } @@ -332,74 +329,74 @@ ShadowButton::Transforms::iterator ShadowButton::FindTransform( Property::Index void ShadowButton::ResetVisual( Property::Index index, Visual::Base& visual, - const Property::Value& value ) + const Property::Value& value) { - if( visual ) + if(visual) { // we are replacing an existing visual, so force relayout RelayoutRequest(); } Property::Map* map = value.GetMap(); - if( map ) + if(map) { - visual = Toolkit::VisualFactory::Get().CreateVisual( *map ); + visual = Toolkit::VisualFactory::Get().CreateVisual(*map); // Set the appropriate depth index. // @todo Should be able to set this from the style sheet - switch( index ) + switch(index) { case Demo::ShadowButton::Property::BACKGROUND_VISUAL: { - DevelControl::RegisterVisual( *this, index, visual, 0 ); + DevelControl::RegisterVisual(*this, index, visual, 0); break; } case Demo::ShadowButton::Property::CHECKBOX_BG_VISUAL: { - DevelControl::RegisterVisual( *this, index, visual, 1 ); + DevelControl::RegisterVisual(*this, index, visual, 1); break; } case Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL: { - DevelControl::RegisterVisual( *this, index, visual, mCheckState, 2 ); + DevelControl::RegisterVisual(*this, index, visual, mCheckState, 2); break; } case Demo::ShadowButton::Property::LABEL_VISUAL: { - DevelControl::RegisterVisual( *this, index, visual, 1 ); + DevelControl::RegisterVisual(*this, index, visual, 1); break; } } // Extract transform maps out of the visual definition and store them - Property::Value* value = map->Find( Visual::Property::TRANSFORM, "transform"); - if( value ) + Property::Value* value = map->Find(Visual::Property::TRANSFORM, "transform"); + if(value) { Property::Map* transformMap = value->GetMap(); - if( transformMap ) + if(transformMap) { - ShadowButton::Transforms::iterator iter = FindTransform( index ); - if( iter != mTransforms.end() ) + ShadowButton::Transforms::iterator iter = FindTransform(index); + if(iter != mTransforms.end()) { iter->mTransform = *transformMap; } else { - mTransforms.push_back( Transform( index, *transformMap ) ); + mTransforms.push_back(Transform(index, *transformMap)); } } } } } -bool IsTransformProperty( const std::string& property ) +bool IsTransformProperty(const std::string& property) { - const char* transformProperties[]= { "size", "offset", "origin", "anchorPoint", "offsetPolicy", "sizePolicy" }; - const int NUM_TRANSFORM_PROPERTIES = sizeof( transformProperties ) / sizeof( const char * ); + const char* transformProperties[] = {"size", "offset", "origin", "anchorPoint", "offsetPolicy", "sizePolicy"}; + const int NUM_TRANSFORM_PROPERTIES = sizeof(transformProperties) / sizeof(const char*); - bool found=false; - for( int i=0; i{animator{"property"}} = animator{"targetValue"} - - for( unsigned int i=0; i < transitionData.Count(); ++i ) + for(unsigned int i = 0; i < transitionData.Count(); ++i) { - Property::Map animator = transitionData.GetAnimatorAt(i); - Property::Value* target = animator.Find( "target" ); - if( target ) + Property::Map animator = transitionData.GetAnimatorAt(i); + Property::Value* target = animator.Find("target"); + if(target) { // Convert to index Property::Index index = Property::INVALID_INDEX; - if( Scripting::GetEnumerationProperty( *target, VISUAL_PROPERTIES_TABLE, VISUAL_PROPERTIES_TABLE_COUNT, index ) ) + if(Scripting::GetEnumerationProperty(*target, VISUAL_PROPERTIES_TABLE, VISUAL_PROPERTIES_TABLE_COUNT, index)) { - ShadowButton::Transforms::iterator iter = FindTransform( index ); - if( iter != mTransforms.end() ) + ShadowButton::Transforms::iterator iter = FindTransform(index); + if(iter != mTransforms.end()) { - Property::Value* property = animator.Find( "property" ); - if( property ) + Property::Value* property = animator.Find("property"); + if(property) { std::string propertyString; property->Get(propertyString); - if( IsTransformProperty( propertyString ) ) + if(IsTransformProperty(propertyString)) { - Property::Value* targetValue = animator.Find( "targetValue" ); - if( targetValue ) + Property::Value* targetValue = animator.Find("targetValue"); + if(targetValue) { - iter->mTransform[ propertyString ] = *targetValue; + iter->mTransform[propertyString] = *targetValue; } } } @@ -453,49 +449,48 @@ void ShadowButton::ResetTransition( Property::Index index, const Property::Value& value) { - ShadowButton::Transitions::iterator iter = FindTransition( index ); - if( iter != mTransitions.end() ) + ShadowButton::Transitions::iterator iter = FindTransition(index); + if(iter != mTransitions.end()) { // Already exists - iter->mTransitionData = ConvertPropertyToTransition( value ); + iter->mTransitionData = ConvertPropertyToTransition(value); iter->mAnimation.Stop(); iter->mAnimation.Clear(); } else { - mTransitions.push_back( Transition( index, ConvertPropertyToTransition( value ) ) ); + mTransitions.push_back(Transition(index, ConvertPropertyToTransition(value))); } } - -void ShadowButton::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void ShadowButton::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value) { - Demo::ShadowButton shadowButton = Demo::ShadowButton::DownCast( Dali::BaseHandle( object ) ); + Demo::ShadowButton shadowButton = Demo::ShadowButton::DownCast(Dali::BaseHandle(object)); - if( shadowButton ) + if(shadowButton) { - ShadowButton& impl = GetImpl( shadowButton ); - switch ( index ) + ShadowButton& impl = GetImpl(shadowButton); + switch(index) { case Demo::ShadowButton::Property::BACKGROUND_VISUAL: { - impl.ResetVisual( index, impl.mBackgroundVisual, value ); + impl.ResetVisual(index, impl.mBackgroundVisual, value); break; } case Demo::ShadowButton::Property::CHECKBOX_BG_VISUAL: { - impl.ResetVisual( index, impl.mCheckboxBgVisual, value ); + impl.ResetVisual(index, impl.mCheckboxBgVisual, value); break; } case Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL: { - impl.ResetVisual( index, impl.mCheckboxFgVisual, value ); - DevelControl::EnableVisual( impl, Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL, impl.mCheckState ); + impl.ResetVisual(index, impl.mCheckboxFgVisual, value); + DevelControl::EnableVisual(impl, Demo::ShadowButton::Property::CHECKBOX_FG_VISUAL, impl.mCheckState); break; } case Demo::ShadowButton::Property::LABEL_VISUAL: { - impl.ResetVisual( index, impl.mLabelVisual, value ); + impl.ResetVisual(index, impl.mLabelVisual, value); break; } case Demo::ShadowButton::Property::ACTIVE_TRANSITION: @@ -503,23 +498,23 @@ void ShadowButton::SetProperty( BaseObject* object, Property::Index index, const case Demo::ShadowButton::Property::CHECK_TRANSITION: case Demo::ShadowButton::Property::UNCHECK_TRANSITION: { - impl.ResetTransition( index, value ); + impl.ResetTransition(index, value); break; } } } } -Property::Value ShadowButton::GetProperty( BaseObject* object, Property::Index propertyIndex ) +Property::Value ShadowButton::GetProperty(BaseObject* object, Property::Index propertyIndex) { Property::Value value; - Demo::ShadowButton shadowButton = Demo::ShadowButton::DownCast( Dali::BaseHandle( object ) ); + Demo::ShadowButton shadowButton = Demo::ShadowButton::DownCast(Dali::BaseHandle(object)); - if ( shadowButton ) + if(shadowButton) { - ShadowButton& impl = GetImpl( shadowButton ); - switch ( propertyIndex ) + ShadowButton& impl = GetImpl(shadowButton); + switch(propertyIndex) { case Demo::ShadowButton::Property::BACKGROUND_VISUAL: { @@ -558,6 +553,5 @@ Property::Value ShadowButton::GetProperty( BaseObject* object, Property::Index p return value; } - -} // Internal -} // Demo +} // namespace Internal +} // namespace Demo diff --git a/examples/transitions/shadow-button-impl.h b/examples/transitions/shadow-button-impl.h index bb0ed9a..0c504d8 100644 --- a/examples/transitions/shadow-button-impl.h +++ b/examples/transitions/shadow-button-impl.h @@ -17,18 +17,16 @@ * limitations under the License. */ -#include "shadow-button.h" -#include -#include -#include #include +#include +#include +#include +#include "shadow-button.h" namespace Demo { - namespace Internal // To use TypeRegistry, handle and body classes need the same name { - class ShadowButton : public Dali::Toolkit::Internal::Control { public: @@ -46,7 +44,7 @@ public: // API * The button will perform a transition if there is a state change. * @param[in] active The active state */ - void SetActiveState( bool active ); + void SetActiveState(bool active); /** * Get the active state @@ -58,7 +56,7 @@ public: // API * Set the check state * @param[in] checkState The state of the checkbox */ - void SetCheckState( bool checkState ); + void SetCheckState(bool checkState); /** * Get the check state @@ -66,14 +64,14 @@ public: // API */ bool GetCheckState(); -public: // Properties +public: // Properties /** * Called when a property of an object of this type is set. * @param[in] object The object whose property is set. * @param[in] index The property index. * @param[in] value The new property value. */ - static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); + static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value); /** * Called to retrieve a property of an object of this type. @@ -81,7 +79,7 @@ public: // Properties * @param[in] index The property index. * @return The current value of the property. */ - static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex ); + static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex); private: // From Control /** @@ -92,7 +90,7 @@ private: // From Control /** * @copydoc Toolkit::Button::OnSceneConnection() */ - virtual void OnSceneConnection( int depth ); + virtual void OnSceneConnection(int depth); /** * @copydoc Toolkit::Button::OnSceneDisconnection() @@ -102,12 +100,12 @@ private: // From Control /** * @copydoc Toolkit::Button::OnSizeSet() */ - virtual void OnSizeSet( const Dali::Vector3& targetSize ); + virtual void OnSizeSet(const Dali::Vector3& targetSize); /** * @copydoc Toolkit::Button::OnRelayout() */ - virtual void OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container ); + virtual void OnRelayout(const Dali::Vector2& targetSize, Dali::RelayoutContainer& container); /** * @copydoc Toolkit::Button::GetNaturalSize */ @@ -116,22 +114,23 @@ private: // From Control /** * @copydoc Toolkit::Button::OnStyleChange */ - virtual void OnStyleChange( Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change ); + virtual void OnStyleChange(Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change); private: struct Transition { - Dali::Property::Index mTransitionId; + Dali::Property::Index mTransitionId; Dali::Toolkit::TransitionData mTransitionData; - Dali::Animation mAnimation; - bool mPlaying; + Dali::Animation mAnimation; + bool mPlaying; - Transition( Dali::Property::Index index, Dali::Toolkit::TransitionData transitionData ) - : mTransitionId( index ), - mTransitionData( transitionData ), + Transition(Dali::Property::Index index, Dali::Toolkit::TransitionData transitionData) + : mTransitionId(index), + mTransitionData(transitionData), mPlaying(false) { } + private: Transition(); }; @@ -143,48 +142,48 @@ private: Dali::Property::Index mTransformId; Dali::Property::Map mTransform; - Transform( Dali::Property::Index index, Dali::Property::Map& map ) + Transform(Dali::Property::Index index, Dali::Property::Map& map) : mTransformId(index), - mTransform( map ) + mTransform(map) { } }; typedef std::vector Transforms; private: - void StartTransition( Dali::Property::Index transitionId ); + void StartTransition(Dali::Property::Index transitionId); - void OnTransitionFinished( Dali::Animation& handle ); + void OnTransitionFinished(Dali::Animation& handle); - Transitions::iterator FindTransition( Dali::Property::Index index ); + Transitions::iterator FindTransition(Dali::Property::Index index); - Transforms::iterator FindTransform( Dali::Property::Index index ); + Transforms::iterator FindTransform(Dali::Property::Index index); /** * Relayout the visuals as a result of size negotiation using * the transforms provided in the stylesheet */ - void RelayoutVisuals( const Dali::Vector2& targetSize ); + void RelayoutVisuals(const Dali::Vector2& targetSize); /** * Relayout the visuals as a result of size negotiation using * programmatically generated transforms */ - void RelayoutVisualsManually( const Dali::Vector2& targetSize ); + void RelayoutVisualsManually(const Dali::Vector2& targetSize); - void ResetVisual( Dali::Property::Index index, - Dali::Toolkit::Visual::Base& visual, - const Dali::Property::Value& value ); + void ResetVisual(Dali::Property::Index index, + Dali::Toolkit::Visual::Base& visual, + const Dali::Property::Value& value); - void ResetTransition( Dali::Property::Index index, - const Dali::Property::Value& value ); + void ResetTransition(Dali::Property::Index index, + const Dali::Property::Value& value); - void StoreTargetLayouts( Dali::Toolkit::TransitionData transitionData ); + void StoreTargetLayouts(Dali::Toolkit::TransitionData transitionData); private: // undefined - ShadowButton( const ShadowButton& ); - ShadowButton& operator=( const ShadowButton& ); + ShadowButton(const ShadowButton&); + ShadowButton& operator=(const ShadowButton&); private: // Data @@ -199,22 +198,22 @@ private: bool mActiveState; }; -} // Internal +} // namespace Internal -inline Internal::ShadowButton& GetImpl( Demo::ShadowButton& handle ) +inline Internal::ShadowButton& GetImpl(Demo::ShadowButton& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -inline const Internal::ShadowButton& GetImpl( const Demo::ShadowButton& handle ) +inline const Internal::ShadowButton& GetImpl(const Demo::ShadowButton& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); const Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -} // Demo +} // namespace Demo #endif // DALI_DEMO_SHADOW_BUTTON_IMPL_H diff --git a/examples/transitions/shadow-button.cpp b/examples/transitions/shadow-button.cpp index 13de599..32bb8cb 100644 --- a/examples/transitions/shadow-button.cpp +++ b/examples/transitions/shadow-button.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,21 +19,20 @@ namespace Demo { - ShadowButton::ShadowButton() { } -ShadowButton::ShadowButton( const ShadowButton& control ) -: Control( control ) +ShadowButton::ShadowButton(const ShadowButton& control) +: Control(control) { } -ShadowButton& ShadowButton::operator= ( const ShadowButton& rhs ) +ShadowButton& ShadowButton::operator=(const ShadowButton& rhs) { - if( &rhs != this ) + if(&rhs != this) { - Control::operator=( rhs ); + Control::operator=(rhs); } return *this; } @@ -48,20 +47,20 @@ ShadowButton ShadowButton::New() return control; } -ShadowButton ShadowButton::New( const std::string& url ) +ShadowButton ShadowButton::New(const std::string& url) { ShadowButton control = Internal::ShadowButton::New(); return control; } -ShadowButton ShadowButton::DownCast( BaseHandle handle ) +ShadowButton ShadowButton::DownCast(BaseHandle handle) { - return Control::DownCast< ShadowButton, Internal::ShadowButton > ( handle ); + return Control::DownCast(handle); } -void ShadowButton::SetActiveState( bool active ) +void ShadowButton::SetActiveState(bool active) { - GetImpl(*this).SetActiveState( active ); + GetImpl(*this).SetActiveState(active); } bool ShadowButton::GetActiveState() @@ -69,9 +68,9 @@ bool ShadowButton::GetActiveState() return GetImpl(*this).GetActiveState(); } -void ShadowButton::SetCheckState( bool checkState ) +void ShadowButton::SetCheckState(bool checkState) { - GetImpl(*this).SetCheckState( checkState ); + GetImpl(*this).SetCheckState(checkState); } bool ShadowButton::GetCheckState() @@ -79,16 +78,15 @@ bool ShadowButton::GetCheckState() return GetImpl(*this).GetCheckState(); } -ShadowButton::ShadowButton( Internal::ShadowButton& implementation ) -: Control( implementation ) +ShadowButton::ShadowButton(Internal::ShadowButton& implementation) +: Control(implementation) { } -ShadowButton::ShadowButton( Dali::Internal::CustomActor* internal ) -: Control( internal ) +ShadowButton::ShadowButton(Dali::Internal::CustomActor* internal) +: Control(internal) { - VerifyCustomActorPointer< Internal::ShadowButton >( internal ) ; + VerifyCustomActorPointer(internal); } - } //namespace Demo diff --git a/examples/transitions/shadow-button.h b/examples/transitions/shadow-button.h index e06b3db..9b8199b 100644 --- a/examples/transitions/shadow-button.h +++ b/examples/transitions/shadow-button.h @@ -2,7 +2,7 @@ #define DALI_DEMO_SHADOW_BUTTON_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ namespace Demo { - // All type registered controls need to have the same name for the body // and the handle namespace Internal @@ -41,10 +40,10 @@ public: */ enum PropertyRange { - PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, - PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, + PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ANIMATABLE_PROPERTY_START_INDEX = Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, - ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX+1000 + ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX + 1000 }; struct Property @@ -65,7 +64,6 @@ public: }; public: // Construction / destruction - /** * Create an uninitialized handle */ @@ -80,7 +78,7 @@ public: // Construction / destruction /** * Create a new image channel button from a given URL */ - static ShadowButton New( const std::string& url ); + static ShadowButton New(const std::string& url); /** * Destructor. This is non-virtual since derived Handle types must not @@ -91,27 +89,26 @@ public: // Construction / destruction /** * Copy Constructor */ - ShadowButton( const ShadowButton& shadowButton ); + ShadowButton(const ShadowButton& shadowButton); /** * Assignment Operator */ - ShadowButton& operator=( const ShadowButton& shadowButton ); + ShadowButton& operator=(const ShadowButton& shadowButton); /** * Downcast */ - static ShadowButton DownCast( BaseHandle handle ); + static ShadowButton DownCast(BaseHandle handle); public: // API - /** * @brief Set the button to be active or inactive. * * The button will perform a transition if there is a state change. * @param[in] active The active state */ - void SetActiveState( bool active ); + void SetActiveState(bool active); /** * @brief Get the button's active state @@ -124,7 +121,7 @@ public: // API * Set the check state * @param[in] checkState The state of the checkbox */ - void SetCheckState( bool checkState ); + void SetCheckState(bool checkState); /** * Get the check state @@ -136,12 +133,12 @@ public: // Not for public use /** * Create a handle from an implementation */ - ShadowButton( Internal::ShadowButton& implementation ); + ShadowButton(Internal::ShadowButton& implementation); /** * Allow the creation of an ShadowButton handle from an internal CustomActor pointer */ - ShadowButton( Dali::Internal::CustomActor* internal ); + ShadowButton(Dali::Internal::CustomActor* internal); }; } // namespace Demo diff --git a/examples/transitions/transition-application.cpp b/examples/transitions/transition-application.cpp index 1a3c291..d8e2ae2 100644 --- a/examples/transitions/transition-application.cpp +++ b/examples/transitions/transition-application.cpp @@ -26,9 +26,9 @@ #include #include #include -#include "shadow-button.h" #include #include +#include "shadow-button.h" // Internal includes @@ -37,147 +37,144 @@ using namespace Dali::Toolkit; namespace { - -void SetLabelText( Button button, const char* label ) +void SetLabelText(Button button, const char* label) { - button.SetProperty( Toolkit::Button::Property::LABEL, label ); + button.SetProperty(Toolkit::Button::Property::LABEL, label); } -} +} // namespace namespace Demo { +const char* TransitionApplication::DEMO_THEME_ONE_PATH(DEMO_STYLE_DIR "style-example-theme-one.json"); +const char* TransitionApplication::DEMO_THEME_TWO_PATH(DEMO_STYLE_DIR "style-example-theme-two.json"); -const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" ); -const char* TransitionApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" ); - - -TransitionApplication::TransitionApplication( Application& application ) -: mApplication( application ), +TransitionApplication::TransitionApplication(Application& application) +: mApplication(application), mTitle(), mShadowButton(), mActionButtons(), - mVisualIndex( Property::INVALID_INDEX ), - mActionIndex( Property::INVALID_INDEX ) + mVisualIndex(Property::INVALID_INDEX), + mActionIndex(Property::INVALID_INDEX) { - application.InitSignal().Connect( this, &TransitionApplication::Create ); + application.InitSignal().Connect(this, &TransitionApplication::Create); } TransitionApplication::~TransitionApplication() { } -void TransitionApplication::Create( Application& application ) +void TransitionApplication::Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent); - window.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) ); + window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f)); // Content panes: - TableView contentLayout = TableView::New( 3, 1 ); - contentLayout.SetProperty( Dali::Actor::Property::NAME,"ContentLayout"); - contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - contentLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) ); - contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) ); + TableView contentLayout = TableView::New(3, 1); + contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout"); + contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + contentLayout.SetCellPadding(Vector2(0.0f, 5.0f)); + contentLayout.SetBackgroundColor(Vector4(0.949, 0.949, 0.949, 1.0)); // Assign all rows the size negotiation property of fitting to children - window.Add( contentLayout ); + window.Add(contentLayout); - mTitle = TextLabel::New( "Custom Control Transition Example" ); - mTitle.SetProperty( Dali::Actor::Property::NAME, "Title" ); + mTitle = TextLabel::New("Custom Control Transition Example"); + mTitle.SetProperty(Dali::Actor::Property::NAME, "Title"); mTitle.SetStyleName("Title"); - mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - contentLayout.Add( mTitle ); + mTitle.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mTitle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mTitle.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + contentLayout.Add(mTitle); contentLayout.SetFitHeight(0); // Fill width // Provide some padding around the center cell - TableView buttonLayout = TableView::New( 3, 3 ); - buttonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - buttonLayout.SetFixedHeight(1, 100 ); - buttonLayout.SetFixedWidth(1, 350 ); - contentLayout.Add( buttonLayout ); + TableView buttonLayout = TableView::New(3, 3); + buttonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + buttonLayout.SetFixedHeight(1, 100); + buttonLayout.SetFixedWidth(1, 350); + contentLayout.Add(buttonLayout); mShadowButton = ShadowButton::New(); - mShadowButton.SetProperty( Dali::Actor::Property::NAME,"ShadowButton"); - mShadowButton.SetActiveState( false ); - mShadowButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mShadowButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mShadowButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED ); - mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" ); - - buttonLayout.AddChild( mShadowButton, TableView::CellPosition(1, 1) ); - - TableView actionButtonLayout = TableView::New( 1, NUMBER_OF_ACTION_BUTTONS+1 ); - actionButtonLayout.SetProperty( Dali::Actor::Property::NAME,"ThemeButtonsLayout"); - actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); - actionButtonLayout.SetFitHeight( 0 ); - - TextLabel label = TextLabel::New( "Action: "); - label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + mShadowButton.SetProperty(Dali::Actor::Property::NAME, "ShadowButton"); + mShadowButton.SetActiveState(false); + mShadowButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mShadowButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mShadowButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::DISABLED); + mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "UNCHECKED"); + + buttonLayout.AddChild(mShadowButton, TableView::CellPosition(1, 1)); + + TableView actionButtonLayout = TableView::New(1, NUMBER_OF_ACTION_BUTTONS + 1); + actionButtonLayout.SetProperty(Dali::Actor::Property::NAME, "ThemeButtonsLayout"); + actionButtonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + actionButtonLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + actionButtonLayout.SetFitHeight(0); + + TextLabel label = TextLabel::New("Action: "); + label.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); label.SetStyleName("ActionLabel"); - actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) ); - actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER ); + actionButtonLayout.AddChild(label, TableView::CellPosition(0, 0)); + actionButtonLayout.SetCellAlignment(TableView::CellPosition(0, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER); - for( int i=0; i( mActionIndex ); - switch( action ) + int action = button.GetProperty(mActionIndex); + switch(action) { case 0: { bool activeState = mShadowButton.GetActiveState(); - mShadowButton.SetActiveState( ! activeState ); - if( activeState ) + mShadowButton.SetActiveState(!activeState); + if(activeState) { - SetLabelText( button, "Enable" ); - mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED ); + SetLabelText(button, "Enable"); + mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::DISABLED); } else { - SetLabelText( button, "Disable" ); - mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL ); + SetLabelText(button, "Disable"); + mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL); } - mActionButtons[1].SetProperty( Button::Property::DISABLED, activeState ); + mActionButtons[1].SetProperty(Button::Property::DISABLED, activeState); break; } case 1: { bool checkState = mShadowButton.GetCheckState(); - mShadowButton.SetCheckState( ! checkState ); - if( checkState ) + mShadowButton.SetCheckState(!checkState); + if(checkState) { - SetLabelText( button, "Check" ); - mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" ); + SetLabelText(button, "Check"); + mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "UNCHECKED"); } else { - SetLabelText( button, "Uncheck" ); - mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "CHECKED" ); + SetLabelText(button, "Uncheck"); + mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "CHECKED"); } break; } @@ -194,27 +191,27 @@ bool TransitionApplication::OnActionButtonClicked( Button button ) return true; } -void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent ) +void TransitionApplication::OnKeyEvent(const KeyEvent& keyEvent) { static int keyPressed = 0; - if( keyEvent.GetState() == KeyEvent::DOWN) + if(keyEvent.GetState() == KeyEvent::DOWN) { - if( keyPressed == 0 ) // Is this the first down event? + if(keyPressed == 0) // Is this the first down event? { - printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode() ); + printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode()); - if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) ) + if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK)) { mApplication.Quit(); } - else if( keyEvent.GetKeyName().compare("Return") == 0 ) + else if(keyEvent.GetKeyName().compare("Return") == 0) { } } keyPressed = 1; } - else if( keyEvent.GetState() == KeyEvent::UP ) + else if(keyEvent.GetState() == KeyEvent::UP) { keyPressed = 0; } diff --git a/examples/transitions/transition-application.h b/examples/transitions/transition-application.h index f694c8d..84ba5c0 100644 --- a/examples/transitions/transition-application.h +++ b/examples/transitions/transition-application.h @@ -2,7 +2,7 @@ #define DALI_DEMO_TRANSITION_APPLICATION_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ // External includes #include -#include "shadow-button.h" #include #include +#include "shadow-button.h" // Internal includes @@ -30,51 +30,48 @@ using namespace Dali::Toolkit; namespace Demo { - class TransitionApplication : public ConnectionTracker { public: - static const int NUMBER_OF_ACTION_BUTTONS=2; + static const int NUMBER_OF_ACTION_BUTTONS = 2; public: // Constructor - TransitionApplication( Application& application ); + TransitionApplication(Application& application); // Destructor ~TransitionApplication(); // Init signal handler - void Create( Application& application ); + void Create(Application& application); // Create the GUI components - Toolkit::TextLabel CreateTitle( std::string title ); - Actor CreateContentPane(); + Toolkit::TextLabel CreateTitle(std::string title); + Actor CreateContentPane(); // Key event handler - void OnKeyEvent( const KeyEvent& event ); + void OnKeyEvent(const KeyEvent& event); - bool OnActionButtonClicked( Button button ); + bool OnActionButtonClicked(Button button); static const char* DEMO_THEME_ONE_PATH; static const char* DEMO_THEME_TWO_PATH; private: - /** Create a visual map * * @param[in] index The index of the visual to create * @param[out] map The map to generate */ - Application& mApplication; - TextLabel mTitle; - ShadowButton mShadowButton; - PushButton mActionButtons[NUMBER_OF_ACTION_BUTTONS]; + Application& mApplication; + TextLabel mTitle; + ShadowButton mShadowButton; + PushButton mActionButtons[NUMBER_OF_ACTION_BUTTONS]; Property::Index mVisualIndex; Property::Index mActionIndex; }; } // Namespace Demo - #endif // DALI_DEMO_TRANSITION_APPLICATION_H diff --git a/examples/transitions/transition-example.cpp b/examples/transitions/transition-example.cpp index 0047bfb..42bbf6a 100644 --- a/examples/transitions/transition-example.cpp +++ b/examples/transitions/transition-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,12 @@ // Internal includes #include "transition-application.h" - -int DALI_EXPORT_API main( int argc, char** argv ) +int DALI_EXPORT_API main(int argc, char** argv) { const char* themeName = Demo::TransitionApplication::DEMO_THEME_ONE_PATH; - Application application = Application::New( &argc, &argv, themeName ); - Demo::TransitionApplication transitionApplication( application ); + Application application = Application::New(&argc, &argv, themeName); + Demo::TransitionApplication transitionApplication(application); application.MainLoop(); return 0; } diff --git a/examples/video-view/video-view-example.cpp b/examples/video-view/video-view-example.cpp old mode 100755 new mode 100644 index 087930b..a65790b --- a/examples/video-view/video-view-example.cpp +++ b/examples/video-view/video-view-example.cpp @@ -15,41 +15,40 @@ * */ -#include #include +#include using namespace Dali; using namespace Toolkit; namespace { - const int SEEK_POS( 5000 ); - const int INIT_WIDTH( 600 ); - const int INIT_HEIGHT( 400 ); - const int BUTTON_SIZE( 80 ); +const int SEEK_POS(5000); +const int INIT_WIDTH(600); +const int INIT_HEIGHT(400); +const int BUTTON_SIZE(80); - const char* const PLAY_FILE = DEMO_VIDEO_DIR "demoVideo.mp4"; - const char* const PLAY_IMAGE = DEMO_IMAGE_DIR "icon-play.png"; - const char* const PAUSE_IMAGE = DEMO_IMAGE_DIR "Pause.png"; - const char* const CHANGE_IMAGE = DEMO_IMAGE_DIR "icon-change.png"; - const char* const FORWARD_IMAGE = DEMO_IMAGE_DIR "Forward.png"; - const char* const BACKWARD_IMAGE = DEMO_IMAGE_DIR "Backward.png"; +const char* const PLAY_FILE = DEMO_VIDEO_DIR "demoVideo.mp4"; +const char* const PLAY_IMAGE = DEMO_IMAGE_DIR "icon-play.png"; +const char* const PAUSE_IMAGE = DEMO_IMAGE_DIR "Pause.png"; +const char* const CHANGE_IMAGE = DEMO_IMAGE_DIR "icon-change.png"; +const char* const FORWARD_IMAGE = DEMO_IMAGE_DIR "Forward.png"; +const char* const BACKWARD_IMAGE = DEMO_IMAGE_DIR "Backward.png"; -} // namespace +} // namespace -class VideoViewController: public ConnectionTracker +class VideoViewController : public ConnectionTracker { - public: - - VideoViewController( Application& application ) - : mApplication( application ), - mIsPlay( false ), - mIsFullScreen( false ), - mScale( 1.f ), - mPinchStartScale( 1.0f ) +public: + VideoViewController(Application& application) + : mApplication(application), + mIsPlay(false), + mIsFullScreen(false), + mScale(1.f), + mPinchStartScale(1.0f) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &VideoViewController::Create ); + mApplication.InitSignal().Connect(this, &VideoViewController::Create); } ~VideoViewController() @@ -57,207 +56,206 @@ class VideoViewController: public ConnectionTracker mVideoView.Stop(); } - void Create( Application& application ) + void Create(Application& application) { Window window = application.GetWindow(); - mWindowSize = window.GetSize(); + mWindowSize = window.GetSize(); mVideoView = Toolkit::VideoView::New(); - window.Add( mVideoView ); - mVideoView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mVideoView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mVideoView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - mVideoView.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, INIT_HEIGHT ) ); - mVideoView.SetProperty( VideoView::Property::LOOPING, true ); - mVideoView.SetProperty( VideoView::Property::MUTED, false ); - mVideoView.SetProperty( VideoView::Property::VIDEO, PLAY_FILE ); + window.Add(mVideoView); + mVideoView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mVideoView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mVideoView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mVideoView.SetProperty(Actor::Property::SIZE, Vector2(INIT_WIDTH, INIT_HEIGHT)); + mVideoView.SetProperty(VideoView::Property::LOOPING, true); + mVideoView.SetProperty(VideoView::Property::MUTED, false); + mVideoView.SetProperty(VideoView::Property::VIDEO, PLAY_FILE); mMenu = Layer::New(); - mMenu.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT ); - mMenu.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); - mMenu.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - mMenu.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, 120 ) ); - mVideoView.Add( mMenu ); + mMenu.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT); + mMenu.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT); + mMenu.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + mMenu.SetProperty(Actor::Property::SIZE, Vector2(INIT_WIDTH, 120)); + mVideoView.Add(mMenu); mPlayButton = PushButton::New(); - mPlayButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mPlayButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mPlayButton.SetProperty( Dali::Actor::Property::NAME, "Play" ); - mPlayButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - mPlayButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) ); - mPlayButton.SetProperty( Actor::Property::POSITION, Vector2( 40, 10 )); - mPlayButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked ); + mPlayButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mPlayButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mPlayButton.SetProperty(Dali::Actor::Property::NAME, "Play"); + mPlayButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + mPlayButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE)); + mPlayButton.SetProperty(Actor::Property::POSITION, Vector2(40, 10)); + mPlayButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked); mPauseButton = PushButton::New(); - mPauseButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mPauseButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mPauseButton.SetProperty( Dali::Actor::Property::NAME, "Pause" ); - mPauseButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - mPauseButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) ); - mPauseButton.SetProperty( Actor::Property::POSITION, Vector2( 40, 10 )); - mPauseButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked ); + mPauseButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mPauseButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mPauseButton.SetProperty(Dali::Actor::Property::NAME, "Pause"); + mPauseButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + mPauseButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE)); + mPauseButton.SetProperty(Actor::Property::POSITION, Vector2(40, 10)); + mPauseButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked); mChangeButton = PushButton::New(); - mChangeButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mChangeButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mChangeButton.SetProperty( Dali::Actor::Property::NAME, "Change" ); - mChangeButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - mChangeButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) ); - mChangeButton.SetProperty( Actor::Property::POSITION, Vector2( 140, 10 )); - mChangeButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked ); + mChangeButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mChangeButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mChangeButton.SetProperty(Dali::Actor::Property::NAME, "Change"); + mChangeButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + mChangeButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE)); + mChangeButton.SetProperty(Actor::Property::POSITION, Vector2(140, 10)); + mChangeButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked); mBackwardButton = PushButton::New(); - mBackwardButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mBackwardButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mBackwardButton.SetProperty( Dali::Actor::Property::NAME, "Backward" ); - mBackwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - mBackwardButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) ); - mBackwardButton.SetProperty( Actor::Property::POSITION, Vector2( 240, 10 )); - mBackwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked ); + mBackwardButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mBackwardButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mBackwardButton.SetProperty(Dali::Actor::Property::NAME, "Backward"); + mBackwardButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + mBackwardButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE)); + mBackwardButton.SetProperty(Actor::Property::POSITION, Vector2(240, 10)); + mBackwardButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked); mForwardButton = PushButton::New(); - mForwardButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - mForwardButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mForwardButton.SetProperty( Dali::Actor::Property::NAME, "Forward" ); - mForwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - mForwardButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) ); - mForwardButton.SetProperty( Actor::Property::POSITION, Vector2( 340, 10 )); - mForwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked ); - - mMenu.Add( mPlayButton ); - mMenu.Add( mPauseButton ); - mMenu.Add( mChangeButton ); - mMenu.Add( mBackwardButton ); - mMenu.Add( mForwardButton ); - - mPauseButton.SetProperty( Actor::Property::VISIBLE, false ); - mPauseButton.SetProperty( Button::Property::DISABLED, true ); - mPlayButton.SetProperty( Actor::Property::VISIBLE, true ); - mPlayButton.SetProperty( Button::Property::DISABLED, false ); - mChangeButton.SetProperty( Actor::Property::VISIBLE, true ); - mChangeButton.SetProperty( Button::Property::DISABLED, false ); - - mPlayButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_IMAGE ); - mPlayButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_IMAGE ); - mPauseButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE ); - mPauseButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE ); - - mChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE ); - mChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE ); - - mBackwardButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE ); - mBackwardButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE ); - mForwardButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE ); - mForwardButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE ); + mForwardButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mForwardButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mForwardButton.SetProperty(Dali::Actor::Property::NAME, "Forward"); + mForwardButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + mForwardButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE)); + mForwardButton.SetProperty(Actor::Property::POSITION, Vector2(340, 10)); + mForwardButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked); + + mMenu.Add(mPlayButton); + mMenu.Add(mPauseButton); + mMenu.Add(mChangeButton); + mMenu.Add(mBackwardButton); + mMenu.Add(mForwardButton); + + mPauseButton.SetProperty(Actor::Property::VISIBLE, false); + mPauseButton.SetProperty(Button::Property::DISABLED, true); + mPlayButton.SetProperty(Actor::Property::VISIBLE, true); + mPlayButton.SetProperty(Button::Property::DISABLED, false); + mChangeButton.SetProperty(Actor::Property::VISIBLE, true); + mChangeButton.SetProperty(Button::Property::DISABLED, false); + + mPlayButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_IMAGE); + mPlayButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_IMAGE); + mPauseButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE); + mPauseButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE); + + mChangeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE); + mChangeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE); + + mBackwardButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE); + mBackwardButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE); + mForwardButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE); + mForwardButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE); mPanGestureDetector = PanGestureDetector::New(); - mPanGestureDetector.Attach( mVideoView ); - mPanGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnPan ); + mPanGestureDetector.Attach(mVideoView); + mPanGestureDetector.DetectedSignal().Connect(this, &VideoViewController::OnPan); mPinchGestureDetector = PinchGestureDetector::New(); - mPinchGestureDetector.Attach( mVideoView ); - mPinchGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnPinch ); + mPinchGestureDetector.Attach(mVideoView); + mPinchGestureDetector.DetectedSignal().Connect(this, &VideoViewController::OnPinch); mTapGestureDetector = TapGestureDetector::New(); - mTapGestureDetector.Attach( mVideoView ); - mTapGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnTap ); + mTapGestureDetector.Attach(mVideoView); + mTapGestureDetector.DetectedSignal().Connect(this, &VideoViewController::OnTap); mRotationAnimation = Animation::New(2.f); - mRotationAnimation.AnimateBy( Property(mVideoView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f)) ); + mRotationAnimation.AnimateBy(Property(mVideoView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f))); mRotationAnimation.SetLooping(false); - window.KeyEventSignal().Connect( this, &VideoViewController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &VideoViewController::OnKeyEvent); } - bool OnButtonClicked( Button button ) + bool OnButtonClicked(Button button) { - if( mPauseButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID )) + if(mPauseButton.GetProperty(Actor::Property::ID) == button.GetProperty(Actor::Property::ID)) { - if( mIsPlay ) + if(mIsPlay) { - mPauseButton.SetProperty( Actor::Property::VISIBLE, false ); - mPauseButton.SetProperty( Button::Property::DISABLED, true ); - mPlayButton.SetProperty( Actor::Property::VISIBLE, true ); - mPlayButton.SetProperty( Button::Property::DISABLED, false ); + mPauseButton.SetProperty(Actor::Property::VISIBLE, false); + mPauseButton.SetProperty(Button::Property::DISABLED, true); + mPlayButton.SetProperty(Actor::Property::VISIBLE, true); + mPlayButton.SetProperty(Button::Property::DISABLED, false); mIsPlay = false; mVideoView.Pause(); } } - else if( mPlayButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID )) + else if(mPlayButton.GetProperty(Actor::Property::ID) == button.GetProperty(Actor::Property::ID)) { - mPauseButton.SetProperty( Actor::Property::VISIBLE, true ); - mPauseButton.SetProperty( Button::Property::DISABLED, false ); - mPlayButton.SetProperty( Actor::Property::VISIBLE, false ); - mPlayButton.SetProperty( Button::Property::DISABLED, true ); + mPauseButton.SetProperty(Actor::Property::VISIBLE, true); + mPauseButton.SetProperty(Button::Property::DISABLED, false); + mPlayButton.SetProperty(Actor::Property::VISIBLE, false); + mPlayButton.SetProperty(Button::Property::DISABLED, true); mIsPlay = true; mVideoView.Play(); } - else if( mChangeButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID )) + else if(mChangeButton.GetProperty(Actor::Property::ID) == button.GetProperty(Actor::Property::ID)) { bool underlay = false; - underlay = mVideoView.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >(); - if( underlay ) + underlay = mVideoView.GetProperty(Toolkit::VideoView::Property::UNDERLAY).Get(); + if(underlay) { - mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false ); + mVideoView.SetProperty(Toolkit::VideoView::Property::UNDERLAY, false); } else { - mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, true ); + mVideoView.SetProperty(Toolkit::VideoView::Property::UNDERLAY, true); } } - else if( mBackwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID )) + else if(mBackwardButton.GetProperty(Actor::Property::ID) == button.GetProperty(Actor::Property::ID)) { - mVideoView.Backward( SEEK_POS ); + mVideoView.Backward(SEEK_POS); } - else if( mForwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID )) + else if(mForwardButton.GetProperty(Actor::Property::ID) == button.GetProperty(Actor::Property::ID)) { - mVideoView.Forward( SEEK_POS ); + mVideoView.Forward(SEEK_POS); } return true; } - void OnPan( Actor actor, const PanGesture& gesture ) + void OnPan(Actor actor, const PanGesture& gesture) { - if( !mIsFullScreen && gesture.GetState() == GestureState::CONTINUING ) + if(!mIsFullScreen && gesture.GetState() == GestureState::CONTINUING) { - mVideoView.TranslateBy( Vector3( gesture.GetDisplacement() ) ); + mVideoView.TranslateBy(Vector3(gesture.GetDisplacement())); } } - void OnPinch( Actor actor, const PinchGesture& gesture ) + void OnPinch(Actor actor, const PinchGesture& gesture) { GestureState state = gesture.GetState(); - if( state == GestureState::STARTED ) + if(state == GestureState::STARTED) { mPinchStartScale = mScale; } - if( state == GestureState::FINISHED ) + if(state == GestureState::FINISHED) { mScale = mPinchStartScale * gesture.GetScale(); - mVideoView.SetProperty( Actor::Property::SCALE, mScale ); + mVideoView.SetProperty(Actor::Property::SCALE, mScale); } } - void OnTap( Actor actor, const TapGesture& tapGesture ) + void OnTap(Actor actor, const TapGesture& tapGesture) { - if( !mIsFullScreen ) + if(!mIsFullScreen) { - mVideoView.SetProperty( Actor::Property::SIZE, mWindowSize ); + mVideoView.SetProperty(Actor::Property::SIZE, mWindowSize); mIsFullScreen = true; } else { - mVideoView.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, INIT_HEIGHT ) ); + mVideoView.SetProperty(Actor::Property::SIZE, Vector2(INIT_WIDTH, INIT_HEIGHT)); mIsFullScreen = false; } } private: - /** * Main key event handler */ @@ -265,7 +263,7 @@ private: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -273,10 +271,10 @@ private: } private: - Application& mApplication; - VideoView mVideoView; - Layer mMenu; - Vector2 mWindowSize; + Application& mApplication; + VideoView mVideoView; + Layer mMenu; + Vector2 mWindowSize; bool mIsPlay; bool mIsFullScreen; @@ -288,19 +286,19 @@ private: PushButton mBackwardButton; PushButton mForwardButton; - PanGestureDetector mPanGestureDetector; + PanGestureDetector mPanGestureDetector; PinchGestureDetector mPinchGestureDetector; - TapGestureDetector mTapGestureDetector; - float mScale; - float mPinchStartScale; + TapGestureDetector mTapGestureDetector; + float mScale; + float mPinchStartScale; Animation mRotationAnimation; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv, DEMO_THEME_PATH ); - VideoViewController test( application ); + Application application = Application::New(&argc, &argv, DEMO_THEME_PATH); + VideoViewController test(application); application.MainLoop(); return 0; } diff --git a/examples/visual-fitting-mode/visual-fitting-mode-example.cpp b/examples/visual-fitting-mode/visual-fitting-mode-example.cpp index b9ca324..f82369a 100644 --- a/examples/visual-fitting-mode/visual-fitting-mode-example.cpp +++ b/examples/visual-fitting-mode/visual-fitting-mode-example.cpp @@ -15,78 +15,70 @@ * */ -#include #include #include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { -const char * const IMAGE_NAME = DEMO_IMAGE_DIR "gallery-medium-1.jpg"; ///< The image to use. -const Vector3 IMAGE_SIZE = Vector3( 300, 200, 0 ); ///< The size of the image-views. - -const float BORDER_SIZE = 2.0f; ///< The size of the border. -const Property::Value BORDER ///< The border to use for each image-view. -{ - { Visual::Property::TYPE, Visual::BORDER }, - { BorderVisual::Property::COLOR, Color::RED }, - { BorderVisual::Property::SIZE, BORDER_SIZE } -}; -const Extents LARGE_PADDING( 100.0f, 100.0f, 2.0f, 2.0f ); ///< The large padding extents. -const Extents BORDER_ONLY_PADDING( BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE ); ///< The border only padding extents. +const char* const IMAGE_NAME = DEMO_IMAGE_DIR "gallery-medium-1.jpg"; ///< The image to use. +const Vector3 IMAGE_SIZE = Vector3(300, 200, 0); ///< The size of the image-views. -const std::string INSTRUCTIONS_TEXT = "\n(Tap or Key Press To Change)"; ///< Instructions on how to change the padding mode. -const std::string LARGE_PADDING_TEXT( "Padding: Left/Right Large" + INSTRUCTIONS_TEXT ); ///< Label to shown when large padding enabled. -const std::string BORDER_ONLY_PADDING_TEXT( "Padding: Border Only" + INSTRUCTIONS_TEXT ); ///< Label to shown when border-only padding enabled. -const std::string FILL_LABEL( "FILL" ); -const std::string FIT_KEEP_ASPECT_LABEL( "FIT\nKEEP ASPECT" ); +const float BORDER_SIZE = 2.0f; ///< The size of the border. +const Property::Value BORDER ///< The border to use for each image-view. + { + {Visual::Property::TYPE, Visual::BORDER}, + {BorderVisual::Property::COLOR, Color::RED}, + {BorderVisual::Property::SIZE, BORDER_SIZE}}; +const Extents LARGE_PADDING(100.0f, 100.0f, 2.0f, 2.0f); ///< The large padding extents. +const Extents BORDER_ONLY_PADDING(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE); ///< The border only padding extents. + +const std::string INSTRUCTIONS_TEXT = "\n(Tap or Key Press To Change)"; ///< Instructions on how to change the padding mode. +const std::string LARGE_PADDING_TEXT("Padding: Left/Right Large" + INSTRUCTIONS_TEXT); ///< Label to shown when large padding enabled. +const std::string BORDER_ONLY_PADDING_TEXT("Padding: Border Only" + INSTRUCTIONS_TEXT); ///< Label to shown when border-only padding enabled. +const std::string FILL_LABEL("FILL"); +const std::string FIT_KEEP_ASPECT_LABEL("FIT\nKEEP ASPECT"); const Property::Map TEXT_LABEL_PROPERTIES ///< All the properties of the Large Text Label shown in the example. -{ - { Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER }, - { Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER }, - { Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT }, - { Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT }, - { Control::Property::BACKGROUND, - { - { Toolkit::Visual::Property::TYPE, Visual::GRADIENT }, - { GradientVisual::Property::STOP_COLOR, Property::Array{ Vector4( 167.0f, 207.0f, 223.0f, 255.0f ) / 255.0f, - Vector4( 0.0f, 64.0f, 137.0f, 255.0f ) / 255.0f } }, - { GradientVisual::Property::START_POSITION, Vector2( 0.0f, -0.5f ) }, - { GradientVisual::Property::END_POSITION, Vector2( 0.0f, 0.5f ) } - } - }, - { TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER }, - { TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER }, - { TextLabel::Property::MULTI_LINE, true } -}; + { + {Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER}, + {Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER}, + {Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT}, + {Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT}, + {Control::Property::BACKGROUND, + {{Toolkit::Visual::Property::TYPE, Visual::GRADIENT}, + {GradientVisual::Property::STOP_COLOR, Property::Array{Vector4(167.0f, 207.0f, 223.0f, 255.0f) / 255.0f, Vector4(0.0f, 64.0f, 137.0f, 255.0f) / 255.0f}}, + {GradientVisual::Property::START_POSITION, Vector2(0.0f, -0.5f)}, + {GradientVisual::Property::END_POSITION, Vector2(0.0f, 0.5f)}}}, + {TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER}, + {TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER}, + {TextLabel::Property::MULTI_LINE, true}}; const Property::Map FILL_IMAGE_PROPERTIES ///< The basic properties of the Fill image view. -{ - { Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER }, - { Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER }, - { Actor::Property::SIZE, IMAGE_SIZE }, - { Control::Property::BACKGROUND, BORDER } -}; + { + {Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER}, + {Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER}, + {Actor::Property::SIZE, IMAGE_SIZE}, + {Control::Property::BACKGROUND, BORDER}}; const Property::Map FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES ///< The basic properties of the Fit Keep Aspect image view. -{ - { Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER }, - { Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER }, - { Actor::Property::SIZE, IMAGE_SIZE }, - { Control::Property::BACKGROUND, BORDER } -}; + { + {Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER}, + {Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER}, + {Actor::Property::SIZE, IMAGE_SIZE}, + {Control::Property::BACKGROUND, BORDER}}; const Property::Map OVERLAY_LABEL_PROPERTIES ///< The image view overlay label properties -{ - { TextLabel::Property::TEXT_COLOR, Color::WHITE }, - { TextLabel::Property::OUTLINE, { { "color", Color::BLACK }, { "width", 1.0f } } }, - { TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER }, - { TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER }, - { TextLabel::Property::MULTI_LINE, true }, -}; + { + {TextLabel::Property::TEXT_COLOR, Color::WHITE}, + {TextLabel::Property::OUTLINE, {{"color", Color::BLACK}, {"width", 1.0f}}}, + {TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER}, + {TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER}, + {TextLabel::Property::MULTI_LINE, true}, + }; } // unnamed namespace /** @@ -95,70 +87,66 @@ const Property::Map OVERLAY_LABEL_PROPERTIES ///< The image view overlay label p class VisualFittingModeController : public ConnectionTracker { public: - /** * @brief Constructor. * @param[in] application A reference to the Application class. */ - VisualFittingModeController( Application& application ) - : mApplication( application ), - mLargePadding( true ) + VisualFittingModeController(Application& application) + : mApplication(application), + mLargePadding(true) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &VisualFittingModeController::Create ); + mApplication.InitSignal().Connect(this, &VisualFittingModeController::Create); } private: - /** * @brief Called to initialise the application content * @param[in] application A reference to the Application class. */ - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); // Text Label filling the entire screen, with a background - mTextLabel = Handle::New< TextLabel >( TEXT_LABEL_PROPERTIES ); - window.Add( mTextLabel ); + mTextLabel = Handle::New(TEXT_LABEL_PROPERTIES); + window.Add(mTextLabel); // We want to change the padding when tapping mTapDetector = TapGestureDetector::New(); - mTapDetector.Attach( mTextLabel ); - mTapDetector.DetectedSignal().Connect( this, &VisualFittingModeController::OnTap ); + mTapDetector.Attach(mTextLabel); + mTapDetector.DetectedSignal().Connect(this, &VisualFittingModeController::OnTap); // Create an ImageView with the default behaviour, i.e. image fills to control size - mFillImage = ImageView::New( IMAGE_NAME ); - mFillImage.SetProperties( FILL_IMAGE_PROPERTIES ); - window.Add( mFillImage ); + mFillImage = ImageView::New(IMAGE_NAME); + mFillImage.SetProperties(FILL_IMAGE_PROPERTIES); + window.Add(mFillImage); // Create an ImageView that Keeps the aspect ratio while fitting within the given size - mFitKeepAspectRatioImage = Handle::New< ImageView >( FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES ); - mFitKeepAspectRatioImage.SetProperty( ImageView::Property::IMAGE, - Property::Map - { - { Visual::Property::TYPE, Visual::IMAGE }, - { ImageVisual::Property::URL, IMAGE_NAME }, - { DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FIT_KEEP_ASPECT_RATIO } - } ); - window.Add( mFitKeepAspectRatioImage ); + mFitKeepAspectRatioImage = Handle::New(FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES); + mFitKeepAspectRatioImage.SetProperty(ImageView::Property::IMAGE, + Property::Map{ + {Visual::Property::TYPE, Visual::IMAGE}, + {ImageVisual::Property::URL, IMAGE_NAME}, + {DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FIT_KEEP_ASPECT_RATIO}}); + window.Add(mFitKeepAspectRatioImage); // Create an overlay label for fill image - Actor fillLabel = TextLabel::New( FILL_LABEL ); - fillLabel.SetProperties( FILL_IMAGE_PROPERTIES ); - fillLabel.SetProperties( OVERLAY_LABEL_PROPERTIES ); - window.Add( fillLabel ); + Actor fillLabel = TextLabel::New(FILL_LABEL); + fillLabel.SetProperties(FILL_IMAGE_PROPERTIES); + fillLabel.SetProperties(OVERLAY_LABEL_PROPERTIES); + window.Add(fillLabel); // Create an overlay label for the Fit/Keep Aspect image - Actor fitLabel = TextLabel::New( FIT_KEEP_ASPECT_LABEL ); - fitLabel.SetProperties( FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES ); - fitLabel.SetProperties( OVERLAY_LABEL_PROPERTIES ); - window.Add( fitLabel ); + Actor fitLabel = TextLabel::New(FIT_KEEP_ASPECT_LABEL); + fitLabel.SetProperties(FIT_KEEP_ASPECT_RATIO_IMAGE_BASIC_PROPERTIES); + fitLabel.SetProperties(OVERLAY_LABEL_PROPERTIES); + window.Add(fitLabel); // Respond to key events, exit if ESC/Back, change the padding if anything else - window.KeyEventSignal().Connect( this, &VisualFittingModeController::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &VisualFittingModeController::OnKeyEvent); // Set the initial padding ChangePadding(); @@ -171,11 +159,11 @@ private: { mLargePadding = !mLargePadding; - const Extents padding( mLargePadding ? LARGE_PADDING : BORDER_ONLY_PADDING ); - mFitKeepAspectRatioImage.SetProperty( Control::Property::PADDING, padding ); - mFillImage.SetProperty( Control::Property::PADDING, padding ); + const Extents padding(mLargePadding ? LARGE_PADDING : BORDER_ONLY_PADDING); + mFitKeepAspectRatioImage.SetProperty(Control::Property::PADDING, padding); + mFillImage.SetProperty(Control::Property::PADDING, padding); - mTextLabel.SetProperty( TextLabel::Property::TEXT, mLargePadding ? LARGE_PADDING_TEXT : BORDER_ONLY_PADDING_TEXT ); + mTextLabel.SetProperty(TextLabel::Property::TEXT, mLargePadding ? LARGE_PADDING_TEXT : BORDER_ONLY_PADDING_TEXT); } /** @@ -183,7 +171,7 @@ private: * * We just want to change the padding when this happens. */ - void OnTap( Actor /* actor */, const TapGesture& /* tap */ ) + void OnTap(Actor /* actor */, const TapGesture& /* tap */) { ChangePadding(); } @@ -195,11 +183,11 @@ private: * the padding if any other key. * @param[in] event The key event information */ - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -211,18 +199,18 @@ private: } private: - Application& mApplication; ///< Reference to the application class. - Actor mFillImage; ///< An image-view that fills to the control size. - Actor mFitKeepAspectRatioImage; ///< An image-view that fits within the given size & keeps the aspect ratio. - Actor mTextLabel; ///< A text label to show the current padding mode. - TapGestureDetector mTapDetector; ///< A tap detector to change the padding mode. - bool mLargePadding; ///< If true, the large padding values are used. When false, only the border padding is applied. + Application& mApplication; ///< Reference to the application class. + Actor mFillImage; ///< An image-view that fills to the control size. + Actor mFitKeepAspectRatioImage; ///< An image-view that fits within the given size & keeps the aspect ratio. + Actor mTextLabel; ///< A text label to show the current padding mode. + TapGestureDetector mTapDetector; ///< A tap detector to change the padding mode. + bool mLargePadding; ///< If true, the large padding values are used. When false, only the border padding is applied. }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - VisualFittingModeController visualFittingModeController( application ); + Application application = Application::New(&argc, &argv); + VisualFittingModeController visualFittingModeController(application); application.MainLoop(); return 0; } diff --git a/examples/visual-transitions/beat-control-impl.cpp b/examples/visual-transitions/beat-control-impl.cpp index 956fe11..770b4c6 100644 --- a/examples/visual-transitions/beat-control-impl.cpp +++ b/examples/visual-transitions/beat-control-impl.cpp @@ -26,46 +26,42 @@ namespace Demo { namespace Internal { - namespace { - const int BOUNCE_ANIMATION_RUNNING(0x0001); -const int FADE_ANIMATION_RUNNING (0x0002); -const int X_ANIMATION_RUNNING (0x0004); -const int Y_ANIMATION_RUNNING (0x0008); - +const int FADE_ANIMATION_RUNNING(0x0002); +const int X_ANIMATION_RUNNING(0x0004); +const int Y_ANIMATION_RUNNING(0x0008); Dali::BaseHandle Create() { return Demo::BeatControl::New(); } -DALI_TYPE_REGISTRATION_BEGIN( BeatControl, Dali::Toolkit::Control, Create ); +DALI_TYPE_REGISTRATION_BEGIN(BeatControl, Dali::Toolkit::Control, Create); -DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "bounceTransition", STRING, BOUNCE_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "leftTransition", STRING, LEFT_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "upTransition", STRING, UP_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "fadeTransition", STRING, FADE_TRANSITION ); -DALI_PROPERTY_REGISTRATION( Demo, BeatControl, "beatVisual", MAP, BEAT_VISUAL ); +DALI_PROPERTY_REGISTRATION(Demo, BeatControl, "bounceTransition", STRING, BOUNCE_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, BeatControl, "leftTransition", STRING, LEFT_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, BeatControl, "upTransition", STRING, UP_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, BeatControl, "fadeTransition", STRING, FADE_TRANSITION); +DALI_PROPERTY_REGISTRATION(Demo, BeatControl, "beatVisual", MAP, BEAT_VISUAL); DALI_TYPE_REGISTRATION_END(); - -Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& value ) +Toolkit::TransitionData ConvertPropertyToTransition(const Property::Value& value) { Toolkit::TransitionData transitionData; const Property::Array* array = value.GetArray(); - if( array ) + if(array) { - transitionData = Toolkit::TransitionData::New( *array ); + transitionData = Toolkit::TransitionData::New(*array); } else { const Property::Map* map = value.GetMap(); - if( map ) + if(map) { - transitionData = Toolkit::TransitionData::New( *map ); + transitionData = Toolkit::TransitionData::New(*map); } } return transitionData; @@ -73,9 +69,8 @@ Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& valu } // anonymous namespace - Internal::BeatControl::BeatControl() -: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), mTransformSize(1.0f, 1.0f), mTransformOrigin(Align::CENTER), mTransformAnchorPoint(Align::CENTER), @@ -89,87 +84,85 @@ Internal::BeatControl::~BeatControl() Demo::BeatControl Internal::BeatControl::New() { - IntrusivePtr impl = new Internal::BeatControl(); - Demo::BeatControl handle = Demo::BeatControl( *impl ); + IntrusivePtr impl = new Internal::BeatControl(); + Demo::BeatControl handle = Demo::BeatControl(*impl); impl->Initialize(); return handle; } - void BeatControl::StartBounceAnimation() { - if( mAnimation ) + if(mAnimation) { mAnimation.Stop(); - mAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnBounceAnimationFinished ); + mAnimation.FinishedSignal().Disconnect(this, &BeatControl::OnBounceAnimationFinished); OnBounceAnimationFinished(mAnimation); } - mAnimation = DevelControl::CreateTransition( *this, mBounceTransition ); - mAnimation.FinishedSignal().Connect( this, &BeatControl::OnBounceAnimationFinished ); + mAnimation = DevelControl::CreateTransition(*this, mBounceTransition); + mAnimation.FinishedSignal().Connect(this, &BeatControl::OnBounceAnimationFinished); mAnimation.Play(); mAnimationPlaying |= BOUNCE_ANIMATION_RUNNING; } - void BeatControl::StartXAnimation() { - if( mXAnimation ) + if(mXAnimation) { mXAnimation.Stop(); - mXAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnXAnimationFinished ); + mXAnimation.FinishedSignal().Disconnect(this, &BeatControl::OnXAnimationFinished); OnXAnimationFinished(mXAnimation); } - mXAnimation = DevelControl::CreateTransition( *this, mLeftTransition ); - mXAnimation.FinishedSignal().Connect( this, &BeatControl::OnXAnimationFinished ); + mXAnimation = DevelControl::CreateTransition(*this, mLeftTransition); + mXAnimation.FinishedSignal().Connect(this, &BeatControl::OnXAnimationFinished); mXAnimation.Play(); mAnimationPlaying |= X_ANIMATION_RUNNING; } void BeatControl::StartYAnimation() { - if( mYAnimation ) + if(mYAnimation) { mYAnimation.Stop(); - mYAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnYAnimationFinished ); + mYAnimation.FinishedSignal().Disconnect(this, &BeatControl::OnYAnimationFinished); OnYAnimationFinished(mYAnimation); } - mYAnimation = DevelControl::CreateTransition( *this, mUpTransition ); - mYAnimation.FinishedSignal().Connect( this, &BeatControl::OnYAnimationFinished ); + mYAnimation = DevelControl::CreateTransition(*this, mUpTransition); + mYAnimation.FinishedSignal().Connect(this, &BeatControl::OnYAnimationFinished); mYAnimation.Play(); mAnimationPlaying |= Y_ANIMATION_RUNNING; } void BeatControl::StartFadeAnimation() { - if( mFadeAnimation ) + if(mFadeAnimation) { mFadeAnimation.Stop(); - mFadeAnimation.FinishedSignal().Disconnect( this, &BeatControl::OnFadeAnimationFinished ); + mFadeAnimation.FinishedSignal().Disconnect(this, &BeatControl::OnFadeAnimationFinished); OnFadeAnimationFinished(mFadeAnimation); } - mFadeAnimation = DevelControl::CreateTransition( *this, mFadeTransition ); - mFadeAnimation.FinishedSignal().Connect( this, &BeatControl::OnFadeAnimationFinished ); + mFadeAnimation = DevelControl::CreateTransition(*this, mFadeTransition); + mFadeAnimation.FinishedSignal().Connect(this, &BeatControl::OnFadeAnimationFinished); mFadeAnimation.Play(); mAnimationPlaying |= FADE_ANIMATION_RUNNING; } -void BeatControl::OnBounceAnimationFinished( Animation& src ) +void BeatControl::OnBounceAnimationFinished(Animation& src) { mAnimationPlaying &= ~BOUNCE_ANIMATION_RUNNING; } -void BeatControl::OnXAnimationFinished( Animation& src ) +void BeatControl::OnXAnimationFinished(Animation& src) { mAnimationPlaying &= ~X_ANIMATION_RUNNING; } -void BeatControl::OnYAnimationFinished( Animation& src ) +void BeatControl::OnYAnimationFinished(Animation& src) { mAnimationPlaying &= ~Y_ANIMATION_RUNNING; } -void BeatControl::OnFadeAnimationFinished( Animation& src ) +void BeatControl::OnFadeAnimationFinished(Animation& src) { mAnimationPlaying &= ~FADE_ANIMATION_RUNNING; } @@ -179,9 +172,9 @@ void BeatControl::OnInitialize() Actor self = Self(); } -void BeatControl::OnSceneConnection( int depth ) +void BeatControl::OnSceneConnection(int depth) { - Control::OnSceneConnection( depth ); + Control::OnSceneConnection(depth); } void BeatControl::OnSceneDisconnection() @@ -189,38 +182,38 @@ void BeatControl::OnSceneDisconnection() Control::OnSceneDisconnection(); } -void BeatControl::OnSizeSet( const Vector3& targetSize ) +void BeatControl::OnSizeSet(const Vector3& targetSize) { - Control::OnSizeSet( targetSize ); - RelayoutVisuals( Vector2( targetSize ) ); + Control::OnSizeSet(targetSize); + RelayoutVisuals(Vector2(targetSize)); } -void BeatControl::OnRelayout( const Vector2& targetSize, RelayoutContainer& container ) +void BeatControl::OnRelayout(const Vector2& targetSize, RelayoutContainer& container) { - RelayoutVisuals( targetSize ); + RelayoutVisuals(targetSize); } -void BeatControl::RelayoutVisuals( const Vector2& targetSize ) +void BeatControl::RelayoutVisuals(const Vector2& targetSize) { - if( mVisual ) + if(mVisual) { - if( (mAnimationPlaying & (X_ANIMATION_RUNNING | Y_ANIMATION_RUNNING)) == 0) + if((mAnimationPlaying & (X_ANIMATION_RUNNING | Y_ANIMATION_RUNNING)) == 0) { - Vector2 size( targetSize ); + Vector2 size(targetSize); Property::Map transformMap; // Make the visual half the size of the control, but leave // origin and anchor point at center, position is relative, but Zer0 - transformMap[ Visual::Transform::Property::SIZE ] = mTransformSize; - transformMap[ Visual::Transform::Property::ORIGIN ] = mTransformOrigin; - transformMap[ Visual::Transform::Property::ANCHOR_POINT ] = mTransformAnchorPoint; - mVisual.SetTransformAndSize( transformMap, size ); + transformMap[Visual::Transform::Property::SIZE] = mTransformSize; + transformMap[Visual::Transform::Property::ORIGIN] = mTransformOrigin; + transformMap[Visual::Transform::Property::ANCHOR_POINT] = mTransformAnchorPoint; + mVisual.SetTransformAndSize(transformMap, size); } } } Vector3 BeatControl::GetNaturalSize() { - if( mVisual ) + if(mVisual) { Vector2 naturalSize; mVisual.GetNaturalSize(naturalSize); @@ -229,27 +222,26 @@ Vector3 BeatControl::GetNaturalSize() return Vector3::ZERO; } -void BeatControl::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) +void BeatControl::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) { // Chain up. - Control::OnStyleChange( styleManager, change ); + Control::OnStyleChange(styleManager, change); } - /////////////////////////////////////////////////////////// // // Properties // -void BeatControl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void BeatControl::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value) { - Demo::BeatControl beatControl = Demo::BeatControl::DownCast( Dali::BaseHandle( object ) ); + Demo::BeatControl beatControl = Demo::BeatControl::DownCast(Dali::BaseHandle(object)); - if( beatControl ) + if(beatControl) { - BeatControl& impl = GetImpl( beatControl ); - Actor self = impl.Self(); - switch ( index ) + BeatControl& impl = GetImpl(beatControl); + Actor self = impl.Self(); + switch(index) { case Demo::BeatControl::Property::BEAT_VISUAL: { @@ -258,59 +250,59 @@ void BeatControl::SetProperty( BaseObject* object, Property::Index index, const // Determine if a transform.size property exists in the map, and // save it. Property::Map* map = value.GetMap(); - if( map ) + if(map) { - Property::Value* value = map->Find( Visual::Property::TRANSFORM, "transform" ); - if( value ) + Property::Value* value = map->Find(Visual::Property::TRANSFORM, "transform"); + if(value) { Property::Map* transformMap = value->GetMap(); - if( transformMap ) + if(transformMap) { // We'll increment this whenever SIZE, ORIGIN or ANCHOR_POINT's are modified as we won't need to create a new visual if only these properties are used // If there are more properties in the transform map, then we need to create a new visual unsigned int sizeAndPositionPropertyCount = 0; - Property::Value* sizeValue = transformMap->Find( Visual::Transform::Property::SIZE, "size" ); - if( sizeValue ) + Property::Value* sizeValue = transformMap->Find(Visual::Transform::Property::SIZE, "size"); + if(sizeValue) { - sizeValue->Get( impl.mTransformSize ); + sizeValue->Get(impl.mTransformSize); ++sizeAndPositionPropertyCount; } - Property::Value* originValue = transformMap->Find( Visual::Transform::Property::ORIGIN, "origin" ); - if( originValue ) + Property::Value* originValue = transformMap->Find(Visual::Transform::Property::ORIGIN, "origin"); + if(originValue) { int intValue = 0; - if( originValue->Get( intValue ) ) + if(originValue->Get(intValue)) { - impl.mTransformOrigin = static_cast< Toolkit::Align::Type >( intValue ); + impl.mTransformOrigin = static_cast(intValue); ++sizeAndPositionPropertyCount; } } - Property::Value* anchorPointValue = transformMap->Find( Visual::Transform::Property::ANCHOR_POINT, "anchorPoint" ); - if( anchorPointValue ) + Property::Value* anchorPointValue = transformMap->Find(Visual::Transform::Property::ANCHOR_POINT, "anchorPoint"); + if(anchorPointValue) { int intValue = 0; - if( anchorPointValue->Get( intValue ) ) + if(anchorPointValue->Get(intValue)) { - impl.mTransformAnchorPoint = static_cast< Toolkit::Align::Type >( intValue ); + impl.mTransformAnchorPoint = static_cast(intValue); ++sizeAndPositionPropertyCount; } } // If the only properties that the application is overriding are the size and the position properties, then we do not need to create another visual. - if( map->Count() == 1 && transformMap->Count() == sizeAndPositionPropertyCount ) + if(map->Count() == 1 && transformMap->Count() == sizeAndPositionPropertyCount) { sizeAndPositionOnly = true; } } } - if( ! sizeAndPositionOnly ) + if(!sizeAndPositionOnly) { // Only register a visual if there is more than just a size setting - impl.mVisual = Toolkit::VisualFactory::Get().CreateVisual( *map ); - DevelControl::RegisterVisual( impl, Demo::BeatControl::Property::BEAT_VISUAL, impl.mVisual ); + impl.mVisual = Toolkit::VisualFactory::Get().CreateVisual(*map); + DevelControl::RegisterVisual(impl, Demo::BeatControl::Property::BEAT_VISUAL, impl.mVisual); // We have registered a new visual: must trigger size negotiation // in order to call SetTransformAndSize on the visual with the right size: @@ -321,42 +313,42 @@ void BeatControl::SetProperty( BaseObject* object, Property::Index index, const } case Demo::BeatControl::Property::BOUNCE_TRANSITION: { - impl.mBounceTransition = ConvertPropertyToTransition( value ); + impl.mBounceTransition = ConvertPropertyToTransition(value); break; } case Demo::BeatControl::Property::LEFT_TRANSITION: { - impl.mLeftTransition = ConvertPropertyToTransition( value ); + impl.mLeftTransition = ConvertPropertyToTransition(value); break; } case Demo::BeatControl::Property::UP_TRANSITION: { - impl.mUpTransition = ConvertPropertyToTransition( value ); + impl.mUpTransition = ConvertPropertyToTransition(value); break; } case Demo::BeatControl::Property::FADE_TRANSITION: { - impl.mFadeTransition = ConvertPropertyToTransition( value ); + impl.mFadeTransition = ConvertPropertyToTransition(value); break; } } } } -Property::Value BeatControl::GetProperty( BaseObject* object, Property::Index propertyIndex ) +Property::Value BeatControl::GetProperty(BaseObject* object, Property::Index propertyIndex) { Property::Value value; - Demo::BeatControl beatControl = Demo::BeatControl::DownCast( Dali::BaseHandle( object ) ); + Demo::BeatControl beatControl = Demo::BeatControl::DownCast(Dali::BaseHandle(object)); - if ( beatControl ) + if(beatControl) { - BeatControl& impl = GetImpl( beatControl ); - switch ( propertyIndex ) + BeatControl& impl = GetImpl(beatControl); + switch(propertyIndex) { case Demo::BeatControl::Property::BEAT_VISUAL: { - if( impl.mVisual ) + if(impl.mVisual) { Property::Map map; impl.mVisual.CreatePropertyMap(map); @@ -376,6 +368,5 @@ Property::Value BeatControl::GetProperty( BaseObject* object, Property::Index pr return value; } - -} // Internal -} // Demo +} // namespace Internal +} // namespace Demo diff --git a/examples/visual-transitions/beat-control-impl.h b/examples/visual-transitions/beat-control-impl.h index 87bc457..aaf37b0 100644 --- a/examples/visual-transitions/beat-control-impl.h +++ b/examples/visual-transitions/beat-control-impl.h @@ -17,19 +17,17 @@ * limitations under the License. */ -#include "beat-control.h" -#include -#include -#include #include +#include #include +#include +#include +#include "beat-control.h" namespace Demo { - namespace Internal // To use TypeRegistry, handle and body classes need the same name { - class BeatControl : public Dali::Toolkit::Internal::Control { public: @@ -49,14 +47,14 @@ public: // API void StartFadeAnimation(); -public: // Properties +public: // Properties /** * Called when a property of an object of this type is set. * @param[in] object The object whose property is set. * @param[in] index The property index. * @param[in] value The new property value. */ - static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); + static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value); /** * Called to retrieve a property of an object of this type. @@ -64,7 +62,7 @@ public: // Properties * @param[in] index The property index. * @return The current value of the property. */ - static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex ); + static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex); private: // From Control /** @@ -75,7 +73,7 @@ private: // From Control /** * @copydoc Toolkit::Control::OnSceneConnection() */ - virtual void OnSceneConnection( int depth ); + virtual void OnSceneConnection(int depth); /** * @copydoc Toolkit::Control::OnSceneDisconnection() @@ -85,12 +83,12 @@ private: // From Control /** * @copydoc Toolkit::Control::OnSizeSet() */ - virtual void OnSizeSet( const Dali::Vector3& targetSize ); + virtual void OnSizeSet(const Dali::Vector3& targetSize); /** * @copydoc Toolkit::Control::OnRelayout() */ - virtual void OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container ); + virtual void OnRelayout(const Dali::Vector2& targetSize, Dali::RelayoutContainer& container); /** * @copydoc Toolkit::Control::GetNaturalSize */ @@ -99,57 +97,57 @@ private: // From Control /** * @copydoc Toolkit::Control::OnStyleChange */ - virtual void OnStyleChange( Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change ); + virtual void OnStyleChange(Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change); private: - void OnBounceAnimationFinished( Dali::Animation& handle ); - void OnXAnimationFinished( Dali::Animation& src ); - void OnYAnimationFinished( Dali::Animation& src ); - void OnFadeAnimationFinished( Dali::Animation& src ); + void OnBounceAnimationFinished(Dali::Animation& handle); + void OnXAnimationFinished(Dali::Animation& src); + void OnYAnimationFinished(Dali::Animation& src); + void OnFadeAnimationFinished(Dali::Animation& src); /** * Relayout the visuals as a result of size negotiation */ - void RelayoutVisuals( const Dali::Vector2& targetSize ); + void RelayoutVisuals(const Dali::Vector2& targetSize); private: //undefined - BeatControl( const BeatControl& ); - BeatControl& operator=( const BeatControl& ); + BeatControl(const BeatControl&); + BeatControl& operator=(const BeatControl&); private: // Implementation details - Dali::Toolkit::Visual::Base mVisual; + Dali::Toolkit::Visual::Base mVisual; Dali::Toolkit::TransitionData mBounceTransition; Dali::Toolkit::TransitionData mLeftTransition; Dali::Toolkit::TransitionData mUpTransition; Dali::Toolkit::TransitionData mFadeTransition; - Dali::Animation mAnimation; - Dali::Animation mXAnimation; - Dali::Animation mYAnimation; - Dali::Animation mFadeAnimation; - Dali::Vector2 mTransformSize; - Dali::Toolkit::Align::Type mTransformOrigin; - Dali::Toolkit::Align::Type mTransformAnchorPoint; - int mAnimationPlaying; + Dali::Animation mAnimation; + Dali::Animation mXAnimation; + Dali::Animation mYAnimation; + Dali::Animation mFadeAnimation; + Dali::Vector2 mTransformSize; + Dali::Toolkit::Align::Type mTransformOrigin; + Dali::Toolkit::Align::Type mTransformAnchorPoint; + int mAnimationPlaying; }; -} // Internal +} // namespace Internal -inline Internal::BeatControl& GetImpl( Demo::BeatControl& handle ) +inline Internal::BeatControl& GetImpl(Demo::BeatControl& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -inline const Internal::BeatControl& GetImpl( const Demo::BeatControl& handle ) +inline const Internal::BeatControl& GetImpl(const Demo::BeatControl& handle) { - DALI_ASSERT_ALWAYS( handle ); + DALI_ASSERT_ALWAYS(handle); const Dali::RefObject& object = handle.GetImplementation(); return static_cast(object); } -} // Demo +} // namespace Demo #endif // DALI_DEMO_BEAT_CONTROL_IMPL_H diff --git a/examples/visual-transitions/beat-control.cpp b/examples/visual-transitions/beat-control.cpp index 2dc16fd..a64e3f8 100644 --- a/examples/visual-transitions/beat-control.cpp +++ b/examples/visual-transitions/beat-control.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,21 +19,20 @@ namespace Demo { - BeatControl::BeatControl() { } -BeatControl::BeatControl( const BeatControl& beatControl ) -: Control( beatControl ) +BeatControl::BeatControl(const BeatControl& beatControl) +: Control(beatControl) { } -BeatControl& BeatControl::operator= ( const BeatControl& rhs ) +BeatControl& BeatControl::operator=(const BeatControl& rhs) { - if( &rhs != this ) + if(&rhs != this) { - Control::operator=( rhs ); + Control::operator=(rhs); } return *this; } @@ -48,15 +47,15 @@ BeatControl BeatControl::New() return beatControl; } -BeatControl BeatControl::New( const std::string& url ) +BeatControl BeatControl::New(const std::string& url) { BeatControl beatControl = Internal::BeatControl::New(); return beatControl; } -BeatControl BeatControl::DownCast( BaseHandle handle ) +BeatControl BeatControl::DownCast(BaseHandle handle) { - return Control::DownCast< BeatControl, Internal::BeatControl > ( handle ); + return Control::DownCast(handle); } void BeatControl::StartBounceAnimation() @@ -77,16 +76,15 @@ void BeatControl::StartFadeAnimation() GetImpl(*this).StartFadeAnimation(); } -BeatControl::BeatControl( Internal::BeatControl& implementation ) -: Control( implementation ) +BeatControl::BeatControl(Internal::BeatControl& implementation) +: Control(implementation) { } -BeatControl::BeatControl( Dali::Internal::CustomActor* internal ) -: Control( internal ) +BeatControl::BeatControl(Dali::Internal::CustomActor* internal) +: Control(internal) { - VerifyCustomActorPointer< Internal::BeatControl >( internal ) ; + VerifyCustomActorPointer(internal); } - } //namespace Demo diff --git a/examples/visual-transitions/beat-control.h b/examples/visual-transitions/beat-control.h index f0e6e00..b488d67 100644 --- a/examples/visual-transitions/beat-control.h +++ b/examples/visual-transitions/beat-control.h @@ -2,7 +2,7 @@ #define DALI_DEMO_BEAT_CONTROL_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,11 @@ namespace Demo { - namespace Internal { // All type registered types need to have the same name for the body and the handle class BeatControl; -} +} // namespace Internal /** * Control that allows the RGB channels of an image to be altered. @@ -40,10 +39,10 @@ public: */ enum PropertyRange { - PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, - PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, + PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ANIMATABLE_PROPERTY_START_INDEX = Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, - ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX+1000 + ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX + 1000 }; struct Property @@ -59,7 +58,6 @@ public: }; public: // Construction / destruction - /** * Create an uninitialized handle */ @@ -74,7 +72,7 @@ public: // Construction / destruction /** * Create a new image channel control from a given URL */ - static BeatControl New( const std::string& url ); + static BeatControl New(const std::string& url); /** * Destructor. This is non-virtual since derived Handle types must not @@ -85,20 +83,19 @@ public: // Construction / destruction /** * Copy Constructor */ - BeatControl( const BeatControl& beatControl ); + BeatControl(const BeatControl& beatControl); /** * Assignment Operator */ - BeatControl& operator=( const BeatControl& beatControl ); + BeatControl& operator=(const BeatControl& beatControl); /** * Downcast */ - static BeatControl DownCast( BaseHandle handle ); + static BeatControl DownCast(BaseHandle handle); public: // API - void StartBounceAnimation(); void StartXAnimation(); @@ -111,12 +108,12 @@ public: // Not for public use /** * Create a handle from an implementation */ - BeatControl( Internal::BeatControl& implementation ); + BeatControl(Internal::BeatControl& implementation); /** * Allow the creation of an BeatControl handle from an internal CustomActor pointer */ - BeatControl( Dali::Internal::CustomActor* internal ); + BeatControl(Dali::Internal::CustomActor* internal); }; } // namespace Demo diff --git a/examples/visual-transitions/transition-application.cpp b/examples/visual-transitions/transition-application.cpp index be75a63..04838e4 100644 --- a/examples/visual-transitions/transition-application.cpp +++ b/examples/visual-transitions/transition-application.cpp @@ -24,10 +24,10 @@ // External includes #include -#include "beat-control.h" +#include #include #include -#include +#include "beat-control.h" // Internal includes @@ -36,209 +36,204 @@ using namespace Dali::Toolkit; namespace { - -void SetLabelText( Button button, const char* label ) +void SetLabelText(Button button, const char* label) { - button.SetProperty( Toolkit::Button::Property::LABEL, label ); + button.SetProperty(Toolkit::Button::Property::LABEL, label); } -} +} // namespace namespace Demo { +const char* TransitionApplication::DEMO_THEME_ONE_PATH(DEMO_STYLE_DIR "style-example-theme-one.json"); +const char* DALI_LOGO_PATH(DEMO_IMAGE_DIR "Logo-for-demo.png"); +const char* DALI_ROBOT_MODEL_PATH(DEMO_MODEL_DIR "ToyRobot-Metal.obj"); +const char* DALI_ROBOT_MATERIAL_PATH(DEMO_MODEL_DIR "ToyRobot-Metal.mtl"); -const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" ); -const char* DALI_LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" ); -const char* DALI_ROBOT_MODEL_PATH( DEMO_MODEL_DIR "ToyRobot-Metal.obj" ); -const char* DALI_ROBOT_MATERIAL_PATH( DEMO_MODEL_DIR "ToyRobot-Metal.mtl" ); - -TransitionApplication::TransitionApplication( Application& application ) -: mApplication( application ), +TransitionApplication::TransitionApplication(Application& application) +: mApplication(application), mTitle(), mBeatControl(), mActionButtons(), - mVisualIndex( Property::INVALID_INDEX ), - mActionIndex( Property::INVALID_INDEX ) + mVisualIndex(Property::INVALID_INDEX), + mActionIndex(Property::INVALID_INDEX) { - application.InitSignal().Connect( this, &TransitionApplication::Create ); + application.InitSignal().Connect(this, &TransitionApplication::Create); } TransitionApplication::~TransitionApplication() { } -void TransitionApplication::Create( Application& application ) +void TransitionApplication::Create(Application& application) { Window window = application.GetWindow(); window.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent); - window.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) ); + window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f)); // Content panes: - TableView contentLayout = TableView::New( 4, 1 ); - contentLayout.SetProperty( Dali::Actor::Property::NAME,"ContentLayout"); - contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - contentLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); - contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) ); + TableView contentLayout = TableView::New(4, 1); + contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout"); + contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + contentLayout.SetCellPadding(Vector2(0.0f, 5.0f)); // Assign all rows the size negotiation property of fitting to children - window.Add( contentLayout ); + window.Add(contentLayout); - mTitle = TextLabel::New( "Custom Control Transition Example" ); - mTitle.SetProperty( Dali::Actor::Property::NAME, "Title" ); + mTitle = TextLabel::New("Custom Control Transition Example"); + mTitle.SetProperty(Dali::Actor::Property::NAME, "Title"); mTitle.SetStyleName("Title"); - mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); - mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - contentLayout.Add( mTitle ); + mTitle.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mTitle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT); + mTitle.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + contentLayout.Add(mTitle); contentLayout.SetFitHeight(0); // Fill width mBeatControl = BeatControl::New(); - mBeatControl.SetProperty( Dali::Actor::Property::NAME,"BeatControl"); - mBeatControl.SetProperty( BeatControl::Property::BEAT_VISUAL, Property::Map() - .Add( Visual::Property::TRANSFORM, Property::Map() - .Add( Visual::Transform::Property::SIZE, Vector2(0.5f, 0.5f) ) ) ); - - mBeatControl.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - mBeatControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mBeatControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - contentLayout.Add( mBeatControl ); + mBeatControl.SetProperty(Dali::Actor::Property::NAME, "BeatControl"); + mBeatControl.SetProperty(BeatControl::Property::BEAT_VISUAL, Property::Map().Add(Visual::Property::TRANSFORM, Property::Map().Add(Visual::Transform::Property::SIZE, Vector2(0.5f, 0.5f)))); + + mBeatControl.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + mBeatControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mBeatControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + contentLayout.Add(mBeatControl); // beat control should fill the tableview cell, so no change to default parameters - TableView visualTypeLayout = TableView::New( 1, NUMBER_OF_VISUAL_BUTTONS ); - visualTypeLayout.SetProperty( Dali::Actor::Property::NAME,"VisualTypeLayout"); - visualTypeLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - visualTypeLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); - visualTypeLayout.SetFitHeight( 0 ); + TableView visualTypeLayout = TableView::New(1, NUMBER_OF_VISUAL_BUTTONS); + visualTypeLayout.SetProperty(Dali::Actor::Property::NAME, "VisualTypeLayout"); + visualTypeLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + visualTypeLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + visualTypeLayout.SetFitHeight(0); - contentLayout.Add( visualTypeLayout ); + contentLayout.Add(visualTypeLayout); contentLayout.SetFitHeight(2); - for( int i=0; i( mVisualIndex ); + int visual = actor.GetProperty(mVisualIndex); Property::Map map; - CreateVisualMap( visual, map ); - map.Add( Visual::Property::TRANSFORM, Property::Map() - .Add( Visual::Transform::Property::SIZE, Vector2( 0.5f, 0.5f ) ) ); - mBeatControl.SetProperty( BeatControl::Property::BEAT_VISUAL, map ); + CreateVisualMap(visual, map); + map.Add(Visual::Property::TRANSFORM, Property::Map().Add(Visual::Transform::Property::SIZE, Vector2(0.5f, 0.5f))); + mBeatControl.SetProperty(BeatControl::Property::BEAT_VISUAL, map); } return true; } -bool TransitionApplication::OnActionButtonClicked( Button button ) +bool TransitionApplication::OnActionButtonClicked(Button button) { - int action = button.GetProperty( mActionIndex ); - switch( action ) + int action = button.GetProperty(mActionIndex); + switch(action) { case 0: { @@ -320,27 +314,27 @@ bool TransitionApplication::OnActionButtonClicked( Button button ) return true; } -void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent ) +void TransitionApplication::OnKeyEvent(const KeyEvent& keyEvent) { static int keyPressed = 0; - if( keyEvent.GetState() == KeyEvent::DOWN) + if(keyEvent.GetState() == KeyEvent::DOWN) { - if( keyPressed == 0 ) // Is this the first down event? + if(keyPressed == 0) // Is this the first down event? { - printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode() ); + printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode()); - if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) ) + if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK)) { mApplication.Quit(); } - else if( keyEvent.GetKeyName().compare("Return") == 0 ) + else if(keyEvent.GetKeyName().compare("Return") == 0) { } } keyPressed = 1; } - else if( keyEvent.GetState() == KeyEvent::UP ) + else if(keyEvent.GetState() == KeyEvent::UP) { keyPressed = 0; } diff --git a/examples/visual-transitions/transition-application.h b/examples/visual-transitions/transition-application.h index 6f6e722..8a2a906 100644 --- a/examples/visual-transitions/transition-application.h +++ b/examples/visual-transitions/transition-application.h @@ -21,9 +21,9 @@ #include //#include #include -#include "beat-control.h" #include #include +#include "beat-control.h" // Internal includes @@ -32,54 +32,51 @@ using namespace Dali::Toolkit; namespace Demo { - class TransitionApplication : public ConnectionTracker { public: - static const int NUMBER_OF_ACTION_BUTTONS=4; - static const int NUMBER_OF_VISUAL_BUTTONS=10; + static const int NUMBER_OF_ACTION_BUTTONS = 4; + static const int NUMBER_OF_VISUAL_BUTTONS = 10; public: // Constructor - TransitionApplication( Application& application ); + TransitionApplication(Application& application); // Destructor ~TransitionApplication(); // Init signal handler - void Create( Application& application ); + void Create(Application& application); // Create the GUI components - Toolkit::TextLabel CreateTitle( std::string title ); - Actor CreateContentPane(); + Toolkit::TextLabel CreateTitle(std::string title); + Actor CreateContentPane(); // Key event handler - void OnKeyEvent( const KeyEvent& event ); + void OnKeyEvent(const KeyEvent& event); - bool OnActionButtonClicked( Button button ); - bool OnVisualButtonClicked( Actor actor, const TouchEvent& touch ); + bool OnActionButtonClicked(Button button); + bool OnVisualButtonClicked(Actor actor, const TouchEvent& touch); static const char* DEMO_THEME_ONE_PATH; private: - /** Create a visual map * * @param[in] index The index of the visual to create * @param[out] map The map to generate */ - void CreateVisualMap( int index, Property::Map& map ); + void CreateVisualMap(int index, Property::Map& map); - Application& mApplication; - TextLabel mTitle; - BeatControl mBeatControl; - PushButton mActionButtons[NUMBER_OF_ACTION_BUTTONS]; - BeatControl mVisualButtons[NUMBER_OF_VISUAL_BUTTONS]; + Application& mApplication; + TextLabel mTitle; + BeatControl mBeatControl; + PushButton mActionButtons[NUMBER_OF_ACTION_BUTTONS]; + BeatControl mVisualButtons[NUMBER_OF_VISUAL_BUTTONS]; Property::Index mVisualIndex; Property::Index mActionIndex; }; } // Namespace Demo - #endif // DALI_DEMO_TRANSITION_APPLICATION_H diff --git a/examples/visual-transitions/transition-example.cpp b/examples/visual-transitions/transition-example.cpp index 0047bfb..42bbf6a 100644 --- a/examples/visual-transitions/transition-example.cpp +++ b/examples/visual-transitions/transition-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,12 @@ // Internal includes #include "transition-application.h" - -int DALI_EXPORT_API main( int argc, char** argv ) +int DALI_EXPORT_API main(int argc, char** argv) { const char* themeName = Demo::TransitionApplication::DEMO_THEME_ONE_PATH; - Application application = Application::New( &argc, &argv, themeName ); - Demo::TransitionApplication transitionApplication( application ); + Application application = Application::New(&argc, &argv, themeName); + Demo::TransitionApplication transitionApplication(application); application.MainLoop(); return 0; } diff --git a/examples/web-view/web-view-example.cpp b/examples/web-view/web-view-example.cpp index 7d48243..b1aed6f 100644 --- a/examples/web-view/web-view-example.cpp +++ b/examples/web-view/web-view-example.cpp @@ -16,25 +16,24 @@ */ #include -#include "dali-toolkit/devel-api/controls/web-view/web-view.h" #include +#include "dali-toolkit/devel-api/controls/web-view/web-view.h" using namespace Dali; -namespace{ - +namespace +{ } class WebViewController : public ConnectionTracker { public: - - WebViewController( Application& application ) - : mApplication( application ) - , mUrlPointer( 0 ) + WebViewController(Application& application) + : mApplication(application), + mUrlPointer(0) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &WebViewController::Create ); + mApplication.InitSignal().Connect(this, &WebViewController::Create); } ~WebViewController() @@ -44,79 +43,78 @@ public: const char* GetNextUrl() { - static const unsigned int kUrlSize = 3; - static const char* kUrls[kUrlSize] = { + static const unsigned int kUrlSize = 3; + static const char* kUrls[kUrlSize] = { "https://webkit.org/blog-files/3d-transforms/poster-circle.html", "https://www.amazon.com", - "https://www.google.com" - }; + "https://www.google.com"}; mUrlPointer %= kUrlSize; return kUrls[mUrlPointer++]; } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Vector4(0.2, 0.6, 1, 1) ); + window.SetBackgroundColor(Vector4(0.2, 0.6, 1, 1)); - float width = window.GetSize().GetWidth(); - float height = window.GetSize().GetHeight(); + float width = window.GetSize().GetWidth(); + float height = window.GetSize().GetHeight(); float fontSize = width * 0.02f; - mWebView = Toolkit::WebView::New( "ko-KR", "Asia/Seoul" ); - mWebView.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - mWebView.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - mWebView.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 )); - mWebView.SetProperty( Actor::Property::SIZE, Vector2( width, height ) ); - mWebView.PageLoadStartedSignal().Connect( this, &WebViewController::OnPageLoadStarted ); - mWebView.PageLoadFinishedSignal().Connect( this, &WebViewController::OnPageLoadFinished ); + mWebView = Toolkit::WebView::New("ko-KR", "Asia/Seoul"); + mWebView.SetProperty(Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + mWebView.SetProperty(Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + mWebView.SetProperty(Actor::Property::POSITION, Vector2(0, 0)); + mWebView.SetProperty(Actor::Property::SIZE, Vector2(width, height)); + mWebView.PageLoadStartedSignal().Connect(this, &WebViewController::OnPageLoadStarted); + mWebView.PageLoadFinishedSignal().Connect(this, &WebViewController::OnPageLoadFinished); std::string url = GetNextUrl(); - mWebView.LoadUrl( url ); + mWebView.LoadUrl(url); window.Add(mWebView); - mAddressLabel = Toolkit::TextLabel::New( url ); - mAddressLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); - mAddressLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, fontSize ); - mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - mAddressLabel.SetBackgroundColor( Vector4( 0, 0, 0, 0.5f ) ); - mAddressLabel.TouchedSignal().Connect( this, &WebViewController::OnTouchText ); - window.Add( mAddressLabel ); + mAddressLabel = Toolkit::TextLabel::New(url); + mAddressLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + mAddressLabel.SetProperty(Toolkit::TextLabel::Property::POINT_SIZE, fontSize); + mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + mAddressLabel.SetBackgroundColor(Vector4(0, 0, 0, 0.5f)); + mAddressLabel.TouchedSignal().Connect(this, &WebViewController::OnTouchText); + window.Add(mAddressLabel); // Respond to key events - window.KeyEventSignal().Connect( this, &WebViewController::OnKeyEvent ); - Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor( mWebView ); + window.KeyEventSignal().Connect(this, &WebViewController::OnKeyEvent); + Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(mWebView); } - void OnPageLoadStarted( Toolkit::WebView view, const std::string& url ) + void OnPageLoadStarted(Toolkit::WebView view, const std::string& url) { - mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, "Loading" ); + mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Loading"); } - void OnPageLoadFinished( Toolkit::WebView view, const std::string& url ) + void OnPageLoadFinished(Toolkit::WebView view, const std::string& url) { - mAddressLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, url.c_str() ); + mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, url.c_str()); } - bool OnTouchText( Actor actor, const TouchEvent& touch ) + bool OnTouchText(Actor actor, const TouchEvent& touch) { - if ( touch.GetState( 0 ) == PointState::UP ) + if(touch.GetState(0) == PointState::UP) { std::string url = GetNextUrl(); - mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Waiting" ); - mWebView.LoadUrl( url ); + mAddressLabel.SetProperty(Toolkit::TextLabel::Property::TEXT, "Waiting"); + mWebView.LoadUrl(url); } return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -124,16 +122,16 @@ public: } private: - Application& mApplication; - Toolkit::WebView mWebView; + Application& mApplication; + Toolkit::WebView mWebView; Toolkit::TextLabel mAddressLabel; - unsigned int mUrlPointer; + unsigned int mUrlPointer; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - WebViewController test( application ); + Application application = Application::New(&argc, &argv); + WebViewController test(application); application.MainLoop(); return 0; } diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index 08290a1..3569020 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,207 +34,207 @@ extern "C" #ifdef INTERNATIONALIZATION_ENABLED -#define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES") -#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES") -#define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES") -#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU") -#define DALI_DEMO_STR_TITLE_ARC_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ARC_VISUAL") -#define DALI_DEMO_STR_TITLE_BASIC_LIGHT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BASIC_LIGHT") -#define DALI_DEMO_STR_TITLE_BENCHMARK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BENCHMARK") -#define DALI_DEMO_STR_TITLE_BEZIER_CURVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BEZIER_CURVE") -#define DALI_DEMO_STR_TITLE_BLOCKS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOCKS") -#define DALI_DEMO_STR_TITLE_BLOOM_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOOM_VIEW") -#define DALI_DEMO_STR_TITLE_BUBBLES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUBBLES") -#define DALI_DEMO_STR_TITLE_BUTTONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUTTONS") -#define DALI_DEMO_STR_TITLE_CALL_ACTIVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CALL_ACTIVE") -#define DALI_DEMO_STR_TITLE_CARD_ACTIVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CARD_ACTIVE") -#define DALI_DEMO_STR_TITLE_CLIPPING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CLIPPING") -#define DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER") -#define DALI_DEMO_STR_TITLE_COLOR_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COLOR_VISUAL") -#define DALI_DEMO_STR_TITLE_DEFERRED_SHADING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DEFERRED_SHADING") -#define DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW") -#define DALI_DEMO_STR_TITLE_GESTURES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_GESTURES") -#define DALI_DEMO_STR_TITLE_COLOR_GRADIENT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COLOR_GRADIENT") -#define DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS") -#define DALI_DEMO_STR_TITLE_CONTACT_CARDS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CONTACT_CARDS") -#define DALI_DEMO_STR_TITLE_CUBE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CUBE_TRANSITION") -#define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION") -#define DALI_DEMO_STR_TITLE_DRAG_AND_DROP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DRAG_AND_DROP") -#define DALI_DEMO_STR_TITLE_EFFECTS_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EFFECTS_VIEW") -#define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") -#define DALI_DEMO_STR_TITLE_FPP_GAME dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FPP_GAME") -#define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND") -#define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION") -#define DALI_DEMO_STR_TITLE_FRAME_CALLBACK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FRAME_CALLBACK") -#define DALI_DEMO_STR_TITLE_HELLO_WORLD dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_HELLO_WORLD") -#define DALI_DEMO_STR_TITLE_HOMESCREEN dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_HOMESCREEN") -#define DALI_DEMO_STR_TITLE_IMAGE_POLICIES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_POLICIES") -#define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING") -#define DALI_DEMO_STR_TITLE_IMAGE_SCALING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_SCALING") -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW") -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING") -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA") -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_SVG dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_SVG") -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_URL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_URL") -#define DALI_DEMO_STR_TITLE_ITEM_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ITEM_VIEW") -#define DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS") -#define DALI_DEMO_STR_TITLE_LINE_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LINE_MESH") -#define DALI_DEMO_STR_TITLE_MAGNIFIER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MAGNIFIER") -#define DALI_DEMO_STR_TITLE_MESH_MORPH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MESH_MORPH") -#define DALI_DEMO_STR_TITLE_MESH_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MESH_VISUAL") -#define DALI_DEMO_STR_TITLE_METABALL_EXPLOSION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_METABALL_EXPLOSION") -#define DALI_DEMO_STR_TITLE_METABALL_REFRAC dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_METABALL_REFRAC") -#define DALI_DEMO_STR_TITLE_MOTION_BLUR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_BLUR") -#define DALI_DEMO_STR_TITLE_MOTION_STRETCH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_STRETCH") -#define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE") -#define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE") -#define DALI_DEMO_STR_TITLE_PAGE_TURN dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PAGE_TURN") -#define DALI_DEMO_STR_TITLE_PBR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PBR") -#define DALI_DEMO_STR_TITLE_PERF_SCROLL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PERF_SCROLL") -#define DALI_DEMO_STR_TITLE_POINT_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POINT_MESH") -#define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP") -#define DALI_DEMO_STR_TITLE_PIVOT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PIVOT") -#define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK") -#define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") -#define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") -#define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION") -#define DALI_DEMO_STR_TITLE_REFLECTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFLECTION") -#define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") -#define DALI_DEMO_STR_TITLE_REMOTE_IMAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REMOTE_IMAGE") -#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE") -#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE") -#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE") -#define DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE") -#define DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS") -#define DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING") -#define DALI_DEMO_STR_TITLE_RENDERER_STENCIL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERER_STENCIL") -#define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") -#define DALI_DEMO_STR_TITLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCROLL_VIEW") -#define DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW") -#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL") -#define DALI_DEMO_STR_TITLE_SKYBOX dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SKYBOX") -#define DALI_DEMO_STR_TITLE_SPARKLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SPARKLE") -#define DALI_DEMO_STR_TITLE_STYLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_STYLING") -#define DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW") -#define DALI_DEMO_STR_TITLE_TEXTURED_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXTURED_MESH") -#define DALI_DEMO_STR_TITLE_TEXT_EDITOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_EDITOR") -#define DALI_DEMO_STR_TITLE_TEXT_FIELD dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_FIELD") -#define DALI_DEMO_STR_TITLE_TEXT_FONTS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_FONTS") -#define DALI_DEMO_STR_TITLE_TEXT_LABEL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL") -#define DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING") -#define DALI_DEMO_STR_TITLE_TEXT_OVERLAP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_OVERLAP") -#define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE") -#define DALI_DEMO_STR_TITLE_TEXT_SCROLLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_SCROLLING") -#define DALI_DEMO_STR_TITLE_TILT_SENSOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TILT_SENSOR") -#define DALI_DEMO_STR_TITLE_TOOLTIP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TOOLTIP") -#define DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE") -#define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS") -#define DALI_DEMO_STR_TITLE_WEB_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_WEB_VIEW") -#define DALI_DEMO_STR_TITLE_TEXT_RENDERER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_RENDERER") -#define DALI_DEMO_STR_TITLE_TEXT_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_VISUAL") -#define DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT") +#define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES") +#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES") +#define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES") +#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU") +#define DALI_DEMO_STR_TITLE_ARC_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ARC_VISUAL") +#define DALI_DEMO_STR_TITLE_BASIC_LIGHT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BASIC_LIGHT") +#define DALI_DEMO_STR_TITLE_BENCHMARK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BENCHMARK") +#define DALI_DEMO_STR_TITLE_BEZIER_CURVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BEZIER_CURVE") +#define DALI_DEMO_STR_TITLE_BLOCKS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOCKS") +#define DALI_DEMO_STR_TITLE_BLOOM_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOOM_VIEW") +#define DALI_DEMO_STR_TITLE_BUBBLES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUBBLES") +#define DALI_DEMO_STR_TITLE_BUTTONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUTTONS") +#define DALI_DEMO_STR_TITLE_CALL_ACTIVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CALL_ACTIVE") +#define DALI_DEMO_STR_TITLE_CARD_ACTIVE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CARD_ACTIVE") +#define DALI_DEMO_STR_TITLE_CLIPPING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CLIPPING") +#define DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER") +#define DALI_DEMO_STR_TITLE_COLOR_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COLOR_VISUAL") +#define DALI_DEMO_STR_TITLE_DEFERRED_SHADING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DEFERRED_SHADING") +#define DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW") +#define DALI_DEMO_STR_TITLE_GESTURES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_GESTURES") +#define DALI_DEMO_STR_TITLE_COLOR_GRADIENT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COLOR_GRADIENT") +#define DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS") +#define DALI_DEMO_STR_TITLE_CONTACT_CARDS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CONTACT_CARDS") +#define DALI_DEMO_STR_TITLE_CUBE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CUBE_TRANSITION") +#define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION") +#define DALI_DEMO_STR_TITLE_DRAG_AND_DROP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DRAG_AND_DROP") +#define DALI_DEMO_STR_TITLE_EFFECTS_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EFFECTS_VIEW") +#define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") +#define DALI_DEMO_STR_TITLE_FPP_GAME dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FPP_GAME") +#define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND") +#define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION") +#define DALI_DEMO_STR_TITLE_FRAME_CALLBACK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FRAME_CALLBACK") +#define DALI_DEMO_STR_TITLE_HELLO_WORLD dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_HELLO_WORLD") +#define DALI_DEMO_STR_TITLE_HOMESCREEN dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_HOMESCREEN") +#define DALI_DEMO_STR_TITLE_IMAGE_POLICIES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_POLICIES") +#define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING") +#define DALI_DEMO_STR_TITLE_IMAGE_SCALING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_SCALING") +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW") +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING") +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA") +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_SVG dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_SVG") +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_URL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_VIEW_URL") +#define DALI_DEMO_STR_TITLE_ITEM_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ITEM_VIEW") +#define DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS") +#define DALI_DEMO_STR_TITLE_LINE_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_LINE_MESH") +#define DALI_DEMO_STR_TITLE_MAGNIFIER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MAGNIFIER") +#define DALI_DEMO_STR_TITLE_MESH_MORPH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MESH_MORPH") +#define DALI_DEMO_STR_TITLE_MESH_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MESH_VISUAL") +#define DALI_DEMO_STR_TITLE_METABALL_EXPLOSION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_METABALL_EXPLOSION") +#define DALI_DEMO_STR_TITLE_METABALL_REFRAC dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_METABALL_REFRAC") +#define DALI_DEMO_STR_TITLE_MOTION_BLUR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_BLUR") +#define DALI_DEMO_STR_TITLE_MOTION_STRETCH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_STRETCH") +#define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE") +#define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE") +#define DALI_DEMO_STR_TITLE_PAGE_TURN dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PAGE_TURN") +#define DALI_DEMO_STR_TITLE_PBR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PBR") +#define DALI_DEMO_STR_TITLE_PERF_SCROLL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PERF_SCROLL") +#define DALI_DEMO_STR_TITLE_POINT_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POINT_MESH") +#define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP") +#define DALI_DEMO_STR_TITLE_PIVOT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PIVOT") +#define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK") +#define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") +#define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") +#define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION") +#define DALI_DEMO_STR_TITLE_REFLECTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFLECTION") +#define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") +#define DALI_DEMO_STR_TITLE_REMOTE_IMAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REMOTE_IMAGE") +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE") +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE") +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE") +#define DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE") +#define DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS") +#define DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING") +#define DALI_DEMO_STR_TITLE_RENDERER_STENCIL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERER_STENCIL") +#define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") +#define DALI_DEMO_STR_TITLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCROLL_VIEW") +#define DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW") +#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL") +#define DALI_DEMO_STR_TITLE_SKYBOX dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SKYBOX") +#define DALI_DEMO_STR_TITLE_SPARKLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SPARKLE") +#define DALI_DEMO_STR_TITLE_STYLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_STYLING") +#define DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW") +#define DALI_DEMO_STR_TITLE_TEXTURED_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXTURED_MESH") +#define DALI_DEMO_STR_TITLE_TEXT_EDITOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_EDITOR") +#define DALI_DEMO_STR_TITLE_TEXT_FIELD dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_FIELD") +#define DALI_DEMO_STR_TITLE_TEXT_FONTS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_FONTS") +#define DALI_DEMO_STR_TITLE_TEXT_LABEL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL") +#define DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING") +#define DALI_DEMO_STR_TITLE_TEXT_OVERLAP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_OVERLAP") +#define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE") +#define DALI_DEMO_STR_TITLE_TEXT_SCROLLING dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_SCROLLING") +#define DALI_DEMO_STR_TITLE_TILT_SENSOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TILT_SENSOR") +#define DALI_DEMO_STR_TITLE_TOOLTIP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TOOLTIP") +#define DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE") +#define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS") +#define DALI_DEMO_STR_TITLE_WEB_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_WEB_VIEW") +#define DALI_DEMO_STR_TITLE_TEXT_RENDERER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_RENDERER") +#define DALI_DEMO_STR_TITLE_TEXT_VISUAL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_VISUAL") +#define DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT") #else // !INTERNATIONALIZATION_ENABLED -#define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES "Animated Images" -#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES "Animated Shapes" -#define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES "Animated Vector Images" -#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU "CPU Alpha Blending" -#define DALI_DEMO_STR_TITLE_ARC_VISUAL "Arc Visual" -#define DALI_DEMO_STR_TITLE_BASIC_LIGHT "Basic Light" -#define DALI_DEMO_STR_TITLE_BENCHMARK "ImageView Benchmark" -#define DALI_DEMO_STR_TITLE_BEZIER_CURVE "Alpha Function Bezier Curve" -#define DALI_DEMO_STR_TITLE_BLOCKS "Blocks" -#define DALI_DEMO_STR_TITLE_BLOOM_VIEW "Bloom" -#define DALI_DEMO_STR_TITLE_BUBBLES "Bubbles" -#define DALI_DEMO_STR_TITLE_BUTTONS "Buttons" -#define DALI_DEMO_STR_TITLE_CALL_ACTIVE "Call Active" -#define DALI_DEMO_STR_TITLE_CARD_ACTIVE "Card Active" -#define DALI_DEMO_STR_TITLE_CLIPPING "Clipping" -#define DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER "Clipping Draw Order" -#define DALI_DEMO_STR_TITLE_COLOR_VISUAL "Color Visual" -#define DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW "Gaussian Blur" -#define DALI_DEMO_STR_TITLE_GESTURES "Gestures" -#define DALI_DEMO_STR_TITLE_COLOR_GRADIENT "Color Gradient" -#define DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS "Compressed Texture Formats" -#define DALI_DEMO_STR_TITLE_CONTACT_CARDS "Contact Cards" -#define DALI_DEMO_STR_TITLE_CUBE_TRANSITION "Cube Effect" -#define DALI_DEMO_STR_TITLE_DEFERRED_SHADING "Deferred Shading" -#define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION "Dissolve Effect" -#define DALI_DEMO_STR_TITLE_DRAG_AND_DROP "Drag and Drop" -#define DALI_DEMO_STR_TITLE_EFFECTS_VIEW "Effects View" -#define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" -#define DALI_DEMO_STR_TITLE_FPP_GAME "First Person Game" -#define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND "Flexbox Playground" -#define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION "Focus Integration" -#define DALI_DEMO_STR_TITLE_FRAME_CALLBACK "Frame Callback" -#define DALI_DEMO_STR_TITLE_HELLO_WORLD "Hello World" -#define DALI_DEMO_STR_TITLE_HOMESCREEN "Homescreen Benchmark" -#define DALI_DEMO_STR_TITLE_IMAGE_POLICIES "Image Policies" -#define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING "Image Fitting and Sampling" -#define DALI_DEMO_STR_TITLE_IMAGE_SCALING "Image Scaling Grid" -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW "Image View" -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING "Image View Alpha Blending" -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA "Image View Pixel Area" -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_SVG "Image View SVG" -#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_URL "Image View URL" -#define DALI_DEMO_STR_TITLE_ITEM_VIEW "Item View" -#define DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS "Lights and shadows" -#define DALI_DEMO_STR_TITLE_LINE_MESH "Mesh Line" -#define DALI_DEMO_STR_TITLE_MAGNIFIER "Magnifier" -#define DALI_DEMO_STR_TITLE_MESH_MORPH "Mesh Morph" -#define DALI_DEMO_STR_TITLE_MESH_VISUAL "Mesh Visual" -#define DALI_DEMO_STR_TITLE_METABALL_EXPLOSION "Metaball Explosion" -#define DALI_DEMO_STR_TITLE_METABALL_REFRAC "Metaball Refractions" -#define DALI_DEMO_STR_TITLE_MOTION_BLUR "Motion Blur" -#define DALI_DEMO_STR_TITLE_MOTION_STRETCH "Motion Stretch" -#define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE "Native Image Source" -#define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size" -#define DALI_DEMO_STR_TITLE_PAGE_TURN "Page Turn" -#define DALI_DEMO_STR_TITLE_PBR "PBR" -#define DALI_DEMO_STR_TITLE_PERF_SCROLL "Scrolling Performance" -#define DALI_DEMO_STR_TITLE_POINT_MESH "Point Mesh" -#define DALI_DEMO_STR_TITLE_POPUP "Popup" -#define DALI_DEMO_STR_TITLE_PIVOT "Pivot" -#define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK "Pre Render Callback" -#define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" -#define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" -#define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION "Property Notification" -#define DALI_DEMO_STR_TITLE_REFLECTION "Reflection" -#define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect" -#define DALI_DEMO_STR_TITLE_REMOTE_IMAGE "Remote Image" -#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line" -#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE "Draw Triangle" -#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE "Draw Cube" -#define DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE "Textured Cube" -#define DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING "Ray Marching" -#define DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS "Radial Progress" -#define DALI_DEMO_STR_TITLE_RENDERER_STENCIL "Renderer Stencils" -#define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI "Script Based UI" -#define DALI_DEMO_STR_TITLE_SCROLL_VIEW "Scroll View" -#define DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW "Simple Scroll View" -#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL "Simple Visuals Control" -#define DALI_DEMO_STR_TITLE_SKYBOX "Skybox" -#define DALI_DEMO_STR_TITLE_SPARKLE "Sparkle" -#define DALI_DEMO_STR_TITLE_STYLING "Styling" -#define DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW "Super Blur" -#define DALI_DEMO_STR_TITLE_TEXTURED_MESH "Mesh Texture" -#define DALI_DEMO_STR_TITLE_TEXT_EDITOR "Text Editor" -#define DALI_DEMO_STR_TITLE_TEXT_FIELD "Text Field" -#define DALI_DEMO_STR_TITLE_TEXT_FONTS "Text Fonts" -#define DALI_DEMO_STR_TITLE_TEXT_LABEL "Text Label" -#define DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING "Text Memory Profiling" -#define DALI_DEMO_STR_TITLE_TEXT_OVERLAP "Text Overlap" -#define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE "Text Scripts" -#define DALI_DEMO_STR_TITLE_TEXT_SCROLLING "Text Scrolling" -#define DALI_DEMO_STR_TITLE_TILT_SENSOR "Tilt Sensor" -#define DALI_DEMO_STR_TITLE_TOOLTIP "Tooltip" -#define DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE "Visual Fitting Mode" -#define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS "Visual Transitions" -#define DALI_DEMO_STR_TITLE_WEB_VIEW "Web View" -#define DALI_DEMO_STR_TITLE_TEXT_RENDERER "Text Renderer" -#define DALI_DEMO_STR_TITLE_TEXT_VISUAL "Text Visual" -#define DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT "Text Bitmap Font" +#define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES "Animated Images" +#define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES "Animated Shapes" +#define DALI_DEMO_STR_TITLE_ANIMATED_VECTOR_IMAGES "Animated Vector Images" +#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU "CPU Alpha Blending" +#define DALI_DEMO_STR_TITLE_ARC_VISUAL "Arc Visual" +#define DALI_DEMO_STR_TITLE_BASIC_LIGHT "Basic Light" +#define DALI_DEMO_STR_TITLE_BENCHMARK "ImageView Benchmark" +#define DALI_DEMO_STR_TITLE_BEZIER_CURVE "Alpha Function Bezier Curve" +#define DALI_DEMO_STR_TITLE_BLOCKS "Blocks" +#define DALI_DEMO_STR_TITLE_BLOOM_VIEW "Bloom" +#define DALI_DEMO_STR_TITLE_BUBBLES "Bubbles" +#define DALI_DEMO_STR_TITLE_BUTTONS "Buttons" +#define DALI_DEMO_STR_TITLE_CALL_ACTIVE "Call Active" +#define DALI_DEMO_STR_TITLE_CARD_ACTIVE "Card Active" +#define DALI_DEMO_STR_TITLE_CLIPPING "Clipping" +#define DALI_DEMO_STR_TITLE_CLIPPING_DRAW_ORDER "Clipping Draw Order" +#define DALI_DEMO_STR_TITLE_COLOR_VISUAL "Color Visual" +#define DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW "Gaussian Blur" +#define DALI_DEMO_STR_TITLE_GESTURES "Gestures" +#define DALI_DEMO_STR_TITLE_COLOR_GRADIENT "Color Gradient" +#define DALI_DEMO_STR_TITLE_COMPRESSED_TEXTURE_FORMATS "Compressed Texture Formats" +#define DALI_DEMO_STR_TITLE_CONTACT_CARDS "Contact Cards" +#define DALI_DEMO_STR_TITLE_CUBE_TRANSITION "Cube Effect" +#define DALI_DEMO_STR_TITLE_DEFERRED_SHADING "Deferred Shading" +#define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION "Dissolve Effect" +#define DALI_DEMO_STR_TITLE_DRAG_AND_DROP "Drag and Drop" +#define DALI_DEMO_STR_TITLE_EFFECTS_VIEW "Effects View" +#define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" +#define DALI_DEMO_STR_TITLE_FPP_GAME "First Person Game" +#define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND "Flexbox Playground" +#define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION "Focus Integration" +#define DALI_DEMO_STR_TITLE_FRAME_CALLBACK "Frame Callback" +#define DALI_DEMO_STR_TITLE_HELLO_WORLD "Hello World" +#define DALI_DEMO_STR_TITLE_HOMESCREEN "Homescreen Benchmark" +#define DALI_DEMO_STR_TITLE_IMAGE_POLICIES "Image Policies" +#define DALI_DEMO_STR_TITLE_IMAGE_FITTING_SAMPLING "Image Fitting and Sampling" +#define DALI_DEMO_STR_TITLE_IMAGE_SCALING "Image Scaling Grid" +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW "Image View" +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_ALPHA_BLENDING "Image View Alpha Blending" +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_PIXEL_AREA "Image View Pixel Area" +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_SVG "Image View SVG" +#define DALI_DEMO_STR_TITLE_IMAGE_VIEW_URL "Image View URL" +#define DALI_DEMO_STR_TITLE_ITEM_VIEW "Item View" +#define DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS "Lights and shadows" +#define DALI_DEMO_STR_TITLE_LINE_MESH "Mesh Line" +#define DALI_DEMO_STR_TITLE_MAGNIFIER "Magnifier" +#define DALI_DEMO_STR_TITLE_MESH_MORPH "Mesh Morph" +#define DALI_DEMO_STR_TITLE_MESH_VISUAL "Mesh Visual" +#define DALI_DEMO_STR_TITLE_METABALL_EXPLOSION "Metaball Explosion" +#define DALI_DEMO_STR_TITLE_METABALL_REFRAC "Metaball Refractions" +#define DALI_DEMO_STR_TITLE_MOTION_BLUR "Motion Blur" +#define DALI_DEMO_STR_TITLE_MOTION_STRETCH "Motion Stretch" +#define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE "Native Image Source" +#define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size" +#define DALI_DEMO_STR_TITLE_PAGE_TURN "Page Turn" +#define DALI_DEMO_STR_TITLE_PBR "PBR" +#define DALI_DEMO_STR_TITLE_PERF_SCROLL "Scrolling Performance" +#define DALI_DEMO_STR_TITLE_POINT_MESH "Point Mesh" +#define DALI_DEMO_STR_TITLE_POPUP "Popup" +#define DALI_DEMO_STR_TITLE_PIVOT "Pivot" +#define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK "Pre Render Callback" +#define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" +#define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" +#define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION "Property Notification" +#define DALI_DEMO_STR_TITLE_REFLECTION "Reflection" +#define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect" +#define DALI_DEMO_STR_TITLE_REMOTE_IMAGE "Remote Image" +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line" +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE "Draw Triangle" +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE "Draw Cube" +#define DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE "Textured Cube" +#define DALI_DEMO_STR_TITLE_RENDERING_RAY_MARCHING "Ray Marching" +#define DALI_DEMO_STR_TITLE_RENDERING_RADIAL_PROGRESS "Radial Progress" +#define DALI_DEMO_STR_TITLE_RENDERER_STENCIL "Renderer Stencils" +#define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI "Script Based UI" +#define DALI_DEMO_STR_TITLE_SCROLL_VIEW "Scroll View" +#define DALI_DEMO_STR_TITLE_SIMPLE_SCROLL_VIEW "Simple Scroll View" +#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL "Simple Visuals Control" +#define DALI_DEMO_STR_TITLE_SKYBOX "Skybox" +#define DALI_DEMO_STR_TITLE_SPARKLE "Sparkle" +#define DALI_DEMO_STR_TITLE_STYLING "Styling" +#define DALI_DEMO_STR_TITLE_SUPER_BLUR_VIEW "Super Blur" +#define DALI_DEMO_STR_TITLE_TEXTURED_MESH "Mesh Texture" +#define DALI_DEMO_STR_TITLE_TEXT_EDITOR "Text Editor" +#define DALI_DEMO_STR_TITLE_TEXT_FIELD "Text Field" +#define DALI_DEMO_STR_TITLE_TEXT_FONTS "Text Fonts" +#define DALI_DEMO_STR_TITLE_TEXT_LABEL "Text Label" +#define DALI_DEMO_STR_TITLE_TEXT_MEMORY_PROFILING "Text Memory Profiling" +#define DALI_DEMO_STR_TITLE_TEXT_OVERLAP "Text Overlap" +#define DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE "Text Scripts" +#define DALI_DEMO_STR_TITLE_TEXT_SCROLLING "Text Scrolling" +#define DALI_DEMO_STR_TITLE_TILT_SENSOR "Tilt Sensor" +#define DALI_DEMO_STR_TITLE_TOOLTIP "Tooltip" +#define DALI_DEMO_STR_TITLE_VISUAL_FITTING_MODE "Visual Fitting Mode" +#define DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS "Visual Transitions" +#define DALI_DEMO_STR_TITLE_WEB_VIEW "Web View" +#define DALI_DEMO_STR_TITLE_TEXT_RENDERER "Text Renderer" +#define DALI_DEMO_STR_TITLE_TEXT_VISUAL "Text Visual" +#define DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT "Text Bitmap Font" #endif #ifdef __cplusplus diff --git a/shared/dali-table-view.cpp b/shared/dali-table-view.cpp index 11f0c97..88ca5a5 100644 --- a/shared/dali-table-view.cpp +++ b/shared/dali-table-view.cpp @@ -19,15 +19,15 @@ #include "dali-table-view.h" // EXTERNAL INCLUDES -#include -#include -#include -#include -#include #include -#include #include #include +#include +#include +#include +#include +#include +#include // INTERNAL INCLUDES #include "shared/execute-process.h" @@ -41,55 +41,52 @@ using namespace Dali::Toolkit; namespace { - -const std::string LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" ); +const std::string LOGO_PATH(DEMO_IMAGE_DIR "Logo-for-demo.png"); // Keyboard focus effect constants. -const float KEYBOARD_FOCUS_ANIMATION_DURATION = 1.0f; ///< The total duration of the keyboard focus animation -const int32_t KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT = 5; ///< The number of loops for the keyboard focus animation -const float KEYBOARD_FOCUS_FINAL_SCALE_FLOAT = 1.05f; ///< The final scale of the focus highlight -const float KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT = 1.18f; ///< The scale of the focus highlight during the animation -const float KEYBOARD_FOCUS_FINAL_ALPHA = 0.7f; ///< The final alpha of the focus highlight -const float KEYBOARD_FOCUS_ANIMATING_ALPHA = 0.0f; ///< The alpha of the focus highlight during the animation -const float KEYBOARD_FOCUS_FADE_PERCENTAGE = 0.16f; ///< The duration of the fade (from translucent to the final-alpha) as a percentage of the overall animation duration -const Vector3 KEYBOARD_FOCUS_FINAL_SCALE( KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT ); ///< @see KEYBOARD_FOCUS_START_SCALE_FLOAT -const Vector3 FOCUS_INDICATOR_ANIMATING_SCALE( KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT ); ///< @see KEYBOARD_FOCUS_END_SCALE_FLOAT -const float KEYBOARD_FOCUS_MID_KEY_FRAME_TIME = KEYBOARD_FOCUS_ANIMATION_DURATION - ( KEYBOARD_FOCUS_ANIMATION_DURATION * KEYBOARD_FOCUS_FADE_PERCENTAGE ); ///< Time of the mid key-frame - -const float TILE_LABEL_PADDING = 8.0f; ///< Border between edge of tile and the example text -const float BUTTON_PRESS_ANIMATION_TIME = 0.35f; ///< Time to perform button scale effect. -const float ROTATE_ANIMATION_TIME = 0.5f; ///< Time to perform rotate effect. -const int MAX_PAGES = 256; ///< Maximum pages (arbitrary safety limit) -const int EXAMPLES_PER_ROW = 3; -const int ROWS_PER_PAGE = 3; -const int EXAMPLES_PER_PAGE = EXAMPLES_PER_ROW * ROWS_PER_PAGE; -const float LOGO_MARGIN_RATIO = 0.1f / 0.3f; -const float BOTTOM_PADDING_RATIO = 0.4f / 0.9f; -const Vector3 SCROLLVIEW_RELATIVE_SIZE(0.9f, 1.0f, 0.8f ); ///< ScrollView's relative size to its parent -const Vector3 TABLE_RELATIVE_SIZE(0.95f, 0.9f, 0.8f ); ///< TableView's relative size to the entire stage. The Y value means sum of the logo and table relative heights. -const float STENCIL_RELATIVE_SIZE = 1.0f; - -const float EFFECT_SNAP_DURATION = 0.66f; ///< Scroll Snap Duration for Effects -const float EFFECT_FLICK_DURATION = 0.5f; ///< Scroll Flick Duration for Effects +const float KEYBOARD_FOCUS_ANIMATION_DURATION = 1.0f; ///< The total duration of the keyboard focus animation +const int32_t KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT = 5; ///< The number of loops for the keyboard focus animation +const float KEYBOARD_FOCUS_FINAL_SCALE_FLOAT = 1.05f; ///< The final scale of the focus highlight +const float KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT = 1.18f; ///< The scale of the focus highlight during the animation +const float KEYBOARD_FOCUS_FINAL_ALPHA = 0.7f; ///< The final alpha of the focus highlight +const float KEYBOARD_FOCUS_ANIMATING_ALPHA = 0.0f; ///< The alpha of the focus highlight during the animation +const float KEYBOARD_FOCUS_FADE_PERCENTAGE = 0.16f; ///< The duration of the fade (from translucent to the final-alpha) as a percentage of the overall animation duration +const Vector3 KEYBOARD_FOCUS_FINAL_SCALE(KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT); ///< @see KEYBOARD_FOCUS_START_SCALE_FLOAT +const Vector3 FOCUS_INDICATOR_ANIMATING_SCALE(KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT); ///< @see KEYBOARD_FOCUS_END_SCALE_FLOAT +const float KEYBOARD_FOCUS_MID_KEY_FRAME_TIME = KEYBOARD_FOCUS_ANIMATION_DURATION - (KEYBOARD_FOCUS_ANIMATION_DURATION * KEYBOARD_FOCUS_FADE_PERCENTAGE); ///< Time of the mid key-frame + +const float TILE_LABEL_PADDING = 8.0f; ///< Border between edge of tile and the example text +const float BUTTON_PRESS_ANIMATION_TIME = 0.35f; ///< Time to perform button scale effect. +const float ROTATE_ANIMATION_TIME = 0.5f; ///< Time to perform rotate effect. +const int MAX_PAGES = 256; ///< Maximum pages (arbitrary safety limit) +const int EXAMPLES_PER_ROW = 3; +const int ROWS_PER_PAGE = 3; +const int EXAMPLES_PER_PAGE = EXAMPLES_PER_ROW * ROWS_PER_PAGE; +const float LOGO_MARGIN_RATIO = 0.1f / 0.3f; +const float BOTTOM_PADDING_RATIO = 0.4f / 0.9f; +const Vector3 SCROLLVIEW_RELATIVE_SIZE(0.9f, 1.0f, 0.8f); ///< ScrollView's relative size to its parent +const Vector3 TABLE_RELATIVE_SIZE(0.95f, 0.9f, 0.8f); ///< TableView's relative size to the entire stage. The Y value means sum of the logo and table relative heights. +const float STENCIL_RELATIVE_SIZE = 1.0f; + +const float EFFECT_SNAP_DURATION = 0.66f; ///< Scroll Snap Duration for Effects +const float EFFECT_FLICK_DURATION = 0.5f; ///< Scroll Flick Duration for Effects const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f); -const char * const BUBBLE_COLOR_STYLE_NAME[] = -{ - "BubbleColor1", - "BubbleColor2", - "BubbleColor3", - "BubbleColor4" -}; -const int NUMBER_OF_BUBBLE_COLORS( sizeof( BUBBLE_COLOR_STYLE_NAME ) / sizeof( BUBBLE_COLOR_STYLE_NAME[ 0 ] ) ); +const char* const BUBBLE_COLOR_STYLE_NAME[] = + { + "BubbleColor1", + "BubbleColor2", + "BubbleColor3", + "BubbleColor4"}; +const int NUMBER_OF_BUBBLE_COLORS(sizeof(BUBBLE_COLOR_STYLE_NAME) / sizeof(BUBBLE_COLOR_STYLE_NAME[0])); -const char * const SHAPE_IMAGE_TABLE[] = -{ - DEMO_IMAGE_DIR "shape-circle.png", - DEMO_IMAGE_DIR "shape-bubble.png" -}; -const int NUMBER_OF_SHAPE_IMAGES( sizeof( SHAPE_IMAGE_TABLE ) / sizeof( SHAPE_IMAGE_TABLE[0] ) ); +const char* const SHAPE_IMAGE_TABLE[] = + { + DEMO_IMAGE_DIR "shape-circle.png", + DEMO_IMAGE_DIR "shape-bubble.png"}; +const int NUMBER_OF_SHAPE_IMAGES(sizeof(SHAPE_IMAGE_TABLE) / sizeof(SHAPE_IMAGE_TABLE[0])); -const int NUM_BACKGROUND_IMAGES = 18; +const int NUM_BACKGROUND_IMAGES = 18; const float BACKGROUND_SPREAD_SCALE = 1.5f; const unsigned int BACKGROUND_ANIMATION_DURATION = 15000; // 15 secs @@ -97,19 +94,19 @@ const unsigned int BACKGROUND_ANIMATION_DURATION = 15000; // 15 secs const float BUBBLE_MIN_Z = -1.0; const float BUBBLE_MAX_Z = 0.0f; -const char * const DEMO_BUILD_DATE = __DATE__ " " __TIME__; +const char* const DEMO_BUILD_DATE = __DATE__ " " __TIME__; /** * Creates the background image */ -Control CreateBackground( std::string stylename ) +Control CreateBackground(std::string stylename) { Control background = Control::New(); - background.SetStyleName( stylename ); - background.SetProperty( Actor::Property::NAME, "BACKGROUND" ); - background.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - background.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - background.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + background.SetStyleName(stylename); + background.SetProperty(Actor::Property::NAME, "BACKGROUND"); + background.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + background.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + background.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); return background; } @@ -119,25 +116,25 @@ Control CreateBackground( std::string stylename ) struct AnimateBubbleConstraint { public: - AnimateBubbleConstraint( const Vector3& initialPos, float scale ) - : mInitialX( initialPos.x ), - mScale( scale ) + AnimateBubbleConstraint(const Vector3& initialPos, float scale) + : mInitialX(initialPos.x), + mScale(scale) { } - void operator()( Vector3& position, const PropertyInputContainer& inputs ) + void operator()(Vector3& position, const PropertyInputContainer& inputs) { const Vector3& parentSize = inputs[1]->GetVector3(); - const Vector3& childSize = inputs[2]->GetVector3(); + const Vector3& childSize = inputs[2]->GetVector3(); // Wrap bubbles vertically. float range = parentSize.y + childSize.y; // This performs a float mod (we don't use fmod as we want the arithmetic modulus as opposed to the remainder). - position.y -= range * ( floor( position.y / range ) + 0.5f ); + position.y -= range * (floor(position.y / range) + 0.5f); // Bubbles X position moves parallax to horizontal // panning by a scale factor unique to each bubble. - position.x = mInitialX + ( inputs[0]->GetVector2().x * mScale ); + position.x = mInitialX + (inputs[0]->GetVector2().x * mScale); } private: @@ -151,21 +148,21 @@ private: */ struct TileShaderPositionConstraint { - TileShaderPositionConstraint( float pageWidth, float tileXOffset ) - : mPageWidth( pageWidth ), - mTileXOffset( tileXOffset ) + TileShaderPositionConstraint(float pageWidth, float tileXOffset) + : mPageWidth(pageWidth), + mTileXOffset(tileXOffset) { } - void operator()( Vector3& position, const PropertyInputContainer& inputs ) + void operator()(Vector3& position, const PropertyInputContainer& inputs) { // Set up position.x as the tiles X offset (0.0 -> 1.0). position.x = mTileXOffset; // Set up position.z as the linear scroll-view X offset (0.0 -> 1.0). - position.z = 1.0f * ( -fmod( inputs[0]->GetVector2().x, mPageWidth ) / mPageWidth ); + position.z = 1.0f * (-fmod(inputs[0]->GetVector2().x, mPageWidth) / mPageWidth); // Set up position.y as a rectified version of the scroll-views X offset. // IE. instead of 0.0 -> 1.0, it moves between 0.0 -> 0.5 -> 0.0 within the same span. - if( position.z > 0.5f ) + if(position.z > 0.5f) { position.y = 1.0f - position.z; } @@ -180,15 +177,15 @@ private: float mTileXOffset; }; -bool CompareByTitle( const Example& lhs, const Example& rhs ) +bool CompareByTitle(const Example& lhs, const Example& rhs) { return lhs.title < rhs.title; } } // namespace -DaliTableView::DaliTableView( Application& application ) -: mApplication( application ), +DaliTableView::DaliTableView(Application& application) +: mApplication(application), mRootActor(), mRotateAnimation(), mPressedAnimation(), @@ -203,81 +200,81 @@ DaliTableView::DaliTableView( Application& application ) mPages(), mBackgroundAnimations(), mExampleList(), - mPageWidth( 0.0f ), + mPageWidth(0.0f), mTotalPages(), - mScrolling( false ), - mSortAlphabetically( false ), - mBackgroundAnimsPlaying( false ) + mScrolling(false), + mSortAlphabetically(false), + mBackgroundAnimsPlaying(false) { - application.InitSignal().Connect( this, &DaliTableView::Initialize ); + application.InitSignal().Connect(this, &DaliTableView::Initialize); } DaliTableView::~DaliTableView() { } -void DaliTableView::AddExample( Example example ) +void DaliTableView::AddExample(Example example) { - mExampleList.push_back( example ); + mExampleList.push_back(example); } -void DaliTableView::SortAlphabetically( bool sortAlphabetically ) +void DaliTableView::SortAlphabetically(bool sortAlphabetically) { mSortAlphabetically = sortAlphabetically; } -void DaliTableView::Initialize( Application& application ) +void DaliTableView::Initialize(Application& application) { Window window = application.GetWindow(); - window.KeyEventSignal().Connect( this, &DaliTableView::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &DaliTableView::OnKeyEvent); const Window::WindowSize windowSize = window.GetSize(); // Background - mRootActor = CreateBackground( "LauncherBackground" ); - window.Add( mRootActor ); + mRootActor = CreateBackground("LauncherBackground"); + window.Add(mRootActor); // Add logo - ImageView logo = ImageView::New( LOGO_PATH ); - logo.SetProperty( Actor::Property::NAME, "LOGO_IMAGE" ); - logo.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER ); - logo.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.1f, 0.5f ) ); - logo.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + ImageView logo = ImageView::New(LOGO_PATH); + logo.SetProperty(Actor::Property::NAME, "LOGO_IMAGE"); + logo.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + logo.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 0.1f, 0.5f)); + logo.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); // The logo should appear on top of everything. - logo.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D ); - mRootActor.Add( logo ); + logo.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D); + mRootActor.Add(logo); // Show version in a popup when log is tapped mLogoTapDetector = TapGestureDetector::New(); - mLogoTapDetector.Attach( logo ); - mLogoTapDetector.DetectedSignal().Connect( this, &DaliTableView::OnLogoTapped ); + mLogoTapDetector.Attach(logo); + mLogoTapDetector.DetectedSignal().Connect(this, &DaliTableView::OnLogoTapped); // Scrollview occupying the majority of the screen mScrollView = ScrollView::New(); - mScrollView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); - mScrollView.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 1.0f - 0.05f, 0.5f ) ); - mScrollView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - mScrollView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); - mScrollView.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.0f, 0.6f, 0.0f ) ); + mScrollView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER); + mScrollView.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 1.0f - 0.05f, 0.5f)); + mScrollView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + mScrollView.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT); + mScrollView.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.0f, 0.6f, 0.0f)); - const float buttonsPageMargin = ( 1.0f - TABLE_RELATIVE_SIZE.x ) * 0.5f * windowSize.GetWidth(); - mScrollView.SetProperty( Actor::Property::PADDING, Padding( buttonsPageMargin, buttonsPageMargin, 0.0f, 0.0f ) ); + const float buttonsPageMargin = (1.0f - TABLE_RELATIVE_SIZE.x) * 0.5f * windowSize.GetWidth(); + mScrollView.SetProperty(Actor::Property::PADDING, Padding(buttonsPageMargin, buttonsPageMargin, 0.0f, 0.0f)); - mScrollView.SetAxisAutoLock( true ); - mScrollView.ScrollCompletedSignal().Connect( this, &DaliTableView::OnScrollComplete ); - mScrollView.ScrollStartedSignal().Connect( this, &DaliTableView::OnScrollStart ); - mScrollView.TouchedSignal().Connect( this, &DaliTableView::OnScrollTouched ); + mScrollView.SetAxisAutoLock(true); + mScrollView.ScrollCompletedSignal().Connect(this, &DaliTableView::OnScrollComplete); + mScrollView.ScrollStartedSignal().Connect(this, &DaliTableView::OnScrollStart); + mScrollView.TouchedSignal().Connect(this, &DaliTableView::OnScrollTouched); mPageWidth = windowSize.GetWidth() * TABLE_RELATIVE_SIZE.x * 0.5f; // Populate background and bubbles - needs to be scrollViewLayer so scroll ends show Actor bubbleContainer = Actor::New(); - bubbleContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - bubbleContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - bubbleContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - SetupBackground( bubbleContainer ); + bubbleContainer.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + bubbleContainer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + bubbleContainer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + SetupBackground(bubbleContainer); - mRootActor.Add( bubbleContainer ); - mRootActor.Add( mScrollView ); + mRootActor.Add(bubbleContainer); + mRootActor.Add(mScrollView); // Add scroll view effect and setup constraints on pages ApplyScrollViewEffect(); @@ -290,28 +287,28 @@ void DaliTableView::Initialize( Application& application ) Dali::Window winHandle = application.GetWindow(); - if( windowSize.GetWidth() <= windowSize.GetHeight() ) + if(windowSize.GetWidth() <= windowSize.GetHeight()) { - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT ); - winHandle.RemoveAvailableOrientation( Dali::Window::LANDSCAPE ); - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); - winHandle.RemoveAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); + winHandle.AddAvailableOrientation(Dali::Window::PORTRAIT); + winHandle.RemoveAvailableOrientation(Dali::Window::LANDSCAPE); + winHandle.AddAvailableOrientation(Dali::Window::PORTRAIT_INVERSE); + winHandle.RemoveAvailableOrientation(Dali::Window::LANDSCAPE_INVERSE); } else { - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE ); - winHandle.RemoveAvailableOrientation( Dali::Window::PORTRAIT ); - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); - winHandle.RemoveAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); + winHandle.AddAvailableOrientation(Dali::Window::LANDSCAPE); + winHandle.RemoveAvailableOrientation(Dali::Window::PORTRAIT); + winHandle.AddAvailableOrientation(Dali::Window::LANDSCAPE_INVERSE); + winHandle.RemoveAvailableOrientation(Dali::Window::PORTRAIT_INVERSE); } // Set initial orientation unsigned int degrees = 0; - Rotate( degrees ); + Rotate(degrees); // Background animation - mAnimationTimer = Timer::New( BACKGROUND_ANIMATION_DURATION ); - mAnimationTimer.TickSignal().Connect( this, &DaliTableView::PauseBackgroundAnimation ); + mAnimationTimer = Timer::New(BACKGROUND_ANIMATION_DURATION); + mAnimationTimer.TickSignal().Connect(this, &DaliTableView::PauseBackgroundAnimation); mAnimationTimer.Start(); mBackgroundAnimsPlaying = true; @@ -322,77 +319,77 @@ void DaliTableView::CreateFocusEffect() { // Hook the required signals to manage the focus. auto keyboardFocusManager = KeyboardFocusManager::Get(); - keyboardFocusManager.PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange ); - keyboardFocusManager.FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated ); - AccessibilityManager::Get().FocusedActorActivatedSignal().Connect( this, &DaliTableView::OnFocusedActorActivated ); + keyboardFocusManager.PreFocusChangeSignal().Connect(this, &DaliTableView::OnKeyboardPreFocusChange); + keyboardFocusManager.FocusedActorEnterKeySignal().Connect(this, &DaliTableView::OnFocusedActorActivated); + AccessibilityManager::Get().FocusedActorActivatedSignal().Connect(this, &DaliTableView::OnFocusedActorActivated); // Loop to create both actors for the focus highlight effect. - for( unsigned int i = 0; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i ) + for(unsigned int i = 0; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i) { mFocusEffect[i].actor = ImageView::New(); - mFocusEffect[i].actor.SetStyleName( "FocusActor" ); - mFocusEffect[i].actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mFocusEffect[i].actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mFocusEffect[i].actor.SetProperty( Actor::Property::INHERIT_SCALE, false ); - mFocusEffect[i].actor.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_COLOR ); + mFocusEffect[i].actor.SetStyleName("FocusActor"); + mFocusEffect[i].actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mFocusEffect[i].actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mFocusEffect[i].actor.SetProperty(Actor::Property::INHERIT_SCALE, false); + mFocusEffect[i].actor.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_COLOR); KeyFrames alphaKeyFrames = KeyFrames::New(); - alphaKeyFrames.Add( 0.0f, KEYBOARD_FOCUS_FINAL_ALPHA ); - alphaKeyFrames.Add( KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, KEYBOARD_FOCUS_ANIMATING_ALPHA ); - alphaKeyFrames.Add( KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_ALPHA ); + alphaKeyFrames.Add(0.0f, KEYBOARD_FOCUS_FINAL_ALPHA); + alphaKeyFrames.Add(KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, KEYBOARD_FOCUS_ANIMATING_ALPHA); + alphaKeyFrames.Add(KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_ALPHA); KeyFrames scaleKeyFrames = KeyFrames::New(); - scaleKeyFrames.Add( 0.0f, KEYBOARD_FOCUS_FINAL_SCALE ); - scaleKeyFrames.Add( KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, FOCUS_INDICATOR_ANIMATING_SCALE ); - scaleKeyFrames.Add( KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_SCALE ); + scaleKeyFrames.Add(0.0f, KEYBOARD_FOCUS_FINAL_SCALE); + scaleKeyFrames.Add(KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, FOCUS_INDICATOR_ANIMATING_SCALE); + scaleKeyFrames.Add(KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_SCALE); - mFocusEffect[i].animation = Animation::New( KEYBOARD_FOCUS_ANIMATION_DURATION ); - mFocusEffect[i].animation.AnimateBetween( Property( mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA ), alphaKeyFrames ); - mFocusEffect[i].animation.AnimateBetween( Property( mFocusEffect[i].actor, Actor::Property::SCALE ), scaleKeyFrames ); + mFocusEffect[i].animation = Animation::New(KEYBOARD_FOCUS_ANIMATION_DURATION); + mFocusEffect[i].animation.AnimateBetween(Property(mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA), alphaKeyFrames); + mFocusEffect[i].animation.AnimateBetween(Property(mFocusEffect[i].actor, Actor::Property::SCALE), scaleKeyFrames); - mFocusEffect[i].animation.SetLoopCount( KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT ); + mFocusEffect[i].animation.SetLoopCount(KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT); } // Parent the secondary effect from the primary. - mFocusEffect[0].actor.Add( mFocusEffect[1].actor ); + mFocusEffect[0].actor.Add(mFocusEffect[1].actor); - keyboardFocusManager.SetFocusIndicatorActor( mFocusEffect[0].actor ); + keyboardFocusManager.SetFocusIndicatorActor(mFocusEffect[0].actor); // Connect to the on & off scene signals of the indicator which represents when it is enabled & disabled respectively - mFocusEffect[0].actor.OnSceneSignal().Connect( this, &DaliTableView::OnFocusIndicatorEnabled ); - mFocusEffect[0].actor.OffSceneSignal().Connect( this, &DaliTableView::OnFocusIndicatorDisabled ); + mFocusEffect[0].actor.OnSceneSignal().Connect(this, &DaliTableView::OnFocusIndicatorEnabled); + mFocusEffect[0].actor.OffSceneSignal().Connect(this, &DaliTableView::OnFocusIndicatorDisabled); } -void DaliTableView::OnFocusIndicatorEnabled( Actor /* actor */ ) +void DaliTableView::OnFocusIndicatorEnabled(Actor /* actor */) { // Play the animation on the 1st glow object. mFocusEffect[0].animation.Play(); // Stagger the animation on the 2nd glow object half way through. - mFocusEffect[1].animation.PlayFrom( KEYBOARD_FOCUS_ANIMATION_DURATION / 2.0f ); + mFocusEffect[1].animation.PlayFrom(KEYBOARD_FOCUS_ANIMATION_DURATION / 2.0f); } -void DaliTableView::OnFocusIndicatorDisabled( Dali::Actor /* actor */ ) +void DaliTableView::OnFocusIndicatorDisabled(Dali::Actor /* actor */) { // Stop the focus effect animations - for( auto i = 0u; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i ) + for(auto i = 0u; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i) { - mFocusEffect[ i ].animation.Stop(); + mFocusEffect[i].animation.Stop(); } } void DaliTableView::ApplyCubeEffectToPages() { - ScrollViewPagePathEffect effect = ScrollViewPagePathEffect::DownCast( mScrollViewEffect ); - unsigned int pageCount(0); - for( std::vector< Actor >::iterator pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter ) + ScrollViewPagePathEffect effect = ScrollViewPagePathEffect::DownCast(mScrollViewEffect); + unsigned int pageCount(0); + for(std::vector::iterator pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter) { Actor page = *pageIter; - effect.ApplyToPage( page, pageCount++ ); + effect.ApplyToPage(page, pageCount++); } } -void DaliTableView::OnButtonsPageRelayout( const Dali::Actor& actor ) +void DaliTableView::OnButtonsPageRelayout(const Dali::Actor& actor) { } @@ -400,69 +397,67 @@ void DaliTableView::Populate() { const Window::WindowSize windowSize = mApplication.GetWindow().GetSize(); - mTotalPages = ( mExampleList.size() + EXAMPLES_PER_PAGE - 1 ) / EXAMPLES_PER_PAGE; + mTotalPages = (mExampleList.size() + EXAMPLES_PER_PAGE - 1) / EXAMPLES_PER_PAGE; // Populate ScrollView. - if( mExampleList.size() > 0 ) + if(mExampleList.size() > 0) { - if( mSortAlphabetically ) + if(mSortAlphabetically) { - sort( mExampleList.begin(), mExampleList.end(), CompareByTitle ); + sort(mExampleList.begin(), mExampleList.end(), CompareByTitle); } - unsigned int exampleCount = 0; - ExampleListConstIter iter = mExampleList.begin(); + unsigned int exampleCount = 0; + ExampleListConstIter iter = mExampleList.begin(); - for( int t = 0; t < mTotalPages; t++ ) + for(int t = 0; t < mTotalPages; t++) { // Create Table - TableView page = TableView::New( ROWS_PER_PAGE, EXAMPLES_PER_ROW ); - page.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - page.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - page.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - mScrollView.Add( page ); + TableView page = TableView::New(ROWS_PER_PAGE, EXAMPLES_PER_ROW); + page.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + page.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + page.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + mScrollView.Add(page); // Calculate the number of images going across (columns) within a page, according to the screen resolution and dpi. - const float margin = 2.0f; + const float margin = 2.0f; const float tileParentMultiplier = 1.0f / EXAMPLES_PER_ROW; for(int row = 0; row < ROWS_PER_PAGE; row++) { for(int column = 0; column < EXAMPLES_PER_ROW; column++) { - const Example& example = ( *iter ); + const Example& example = (*iter); // Calculate the tiles relative position on the page (between 0 & 1 in each dimension). - Vector2 position( static_cast( column ) / ( EXAMPLES_PER_ROW - 1.0f ), static_cast( row ) / ( EXAMPLES_PER_ROW - 1.0f ) ); - Actor tile = CreateTile( example.name, example.title, Vector3( tileParentMultiplier, tileParentMultiplier, 1.0f ), position ); + Vector2 position(static_cast(column) / (EXAMPLES_PER_ROW - 1.0f), static_cast(row) / (EXAMPLES_PER_ROW - 1.0f)); + Actor tile = CreateTile(example.name, example.title, Vector3(tileParentMultiplier, tileParentMultiplier, 1.0f), position); AccessibilityManager accessibilityManager = AccessibilityManager::Get(); - accessibilityManager.SetFocusOrder( tile, ++exampleCount ); - accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL, - example.title ); - accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT, "Tile" ); - accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_HINT, - "You can run this example" ); + accessibilityManager.SetFocusOrder(tile, ++exampleCount); + accessibilityManager.SetAccessibilityAttribute(tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL, example.title); + accessibilityManager.SetAccessibilityAttribute(tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT, "Tile"); + accessibilityManager.SetAccessibilityAttribute(tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_HINT, "You can run this example"); - tile.SetProperty( Actor::Property::PADDING, Padding( margin, margin, margin, margin ) ); - page.AddChild( tile, TableView::CellPosition( row, column ) ); + tile.SetProperty(Actor::Property::PADDING, Padding(margin, margin, margin, margin)); + page.AddChild(tile, TableView::CellPosition(row, column)); iter++; - if( iter == mExampleList.end() ) + if(iter == mExampleList.end()) { break; } } - if( iter == mExampleList.end() ) + if(iter == mExampleList.end()) { break; } } - mPages.push_back( page ); + mPages.push_back(page); - if( iter == mExampleList.end() ) + if(iter == mExampleList.end()) { break; } @@ -470,121 +465,121 @@ void DaliTableView::Populate() } // Update Ruler info. - mScrollRulerX = new FixedRuler( mPageWidth ); + mScrollRulerX = new FixedRuler(mPageWidth); mScrollRulerY = new DefaultRuler(); - mScrollRulerX->SetDomain( RulerDomain( 0.0f, (mTotalPages+1) * windowSize.GetWidth() * TABLE_RELATIVE_SIZE.x * 0.5f, true ) ); + mScrollRulerX->SetDomain(RulerDomain(0.0f, (mTotalPages + 1) * windowSize.GetWidth() * TABLE_RELATIVE_SIZE.x * 0.5f, true)); mScrollRulerY->Disable(); - mScrollView.SetRulerX( mScrollRulerX ); - mScrollView.SetRulerY( mScrollRulerY ); + mScrollView.SetRulerX(mScrollRulerX); + mScrollView.SetRulerY(mScrollRulerY); } -void DaliTableView::Rotate( unsigned int degrees ) +void DaliTableView::Rotate(unsigned int degrees) { // Resize the root actor const Window::WindowSize windowSize = mApplication.GetWindow().GetSize(); - const Vector2 originalSize( windowSize.GetWidth(), windowSize.GetHeight() ); - Vector3 targetSize( originalSize.x, originalSize.y, 1.0f ); + const Vector2 originalSize(windowSize.GetWidth(), windowSize.GetHeight()); + Vector3 targetSize(originalSize.x, originalSize.y, 1.0f); - if( degrees == 90 || degrees == 270 ) + if(degrees == 90 || degrees == 270) { - targetSize = Vector3( originalSize.y, originalSize.x, 1.0f ); + targetSize = Vector3(originalSize.y, originalSize.x, 1.0f); } - if( mRotateAnimation ) + if(mRotateAnimation) { mRotateAnimation.Stop(); mRotateAnimation.Clear(); } - mRotateAnimation = Animation::New( ROTATE_ANIMATION_TIME ); - mRotateAnimation.AnimateTo( Property( mRootActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 - degrees ) ), Vector3::ZAXIS ), AlphaFunction::EASE_OUT ); - mRotateAnimation.AnimateTo( Property( mRootActor, Actor::Property::SIZE ), targetSize, AlphaFunction::EASE_OUT ); + mRotateAnimation = Animation::New(ROTATE_ANIMATION_TIME); + mRotateAnimation.AnimateTo(Property(mRootActor, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360 - degrees)), Vector3::ZAXIS), AlphaFunction::EASE_OUT); + mRotateAnimation.AnimateTo(Property(mRootActor, Actor::Property::SIZE), targetSize, AlphaFunction::EASE_OUT); mRotateAnimation.Play(); } -Actor DaliTableView::CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Vector2& position ) +Actor DaliTableView::CreateTile(const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Vector2& position) { Toolkit::ImageView focusableTile = ImageView::New(); - focusableTile.SetStyleName( "DemoTile" ); - focusableTile.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - focusableTile.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS ); - focusableTile.SetProperty( Actor::Property::SIZE_MODE_FACTOR, sizeMultiplier ); - focusableTile.SetProperty( Actor::Property::NAME, name ); + focusableTile.SetStyleName("DemoTile"); + focusableTile.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + focusableTile.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS); + focusableTile.SetProperty(Actor::Property::SIZE_MODE_FACTOR, sizeMultiplier); + focusableTile.SetProperty(Actor::Property::NAME, name); // Set the tile to be keyboard focusable - focusableTile.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true ); + focusableTile.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader. - Property::Value value = Vector3( 0.0f, 0.0f, 0.0f ); - Property::Index propertyIndex = focusableTile.RegisterProperty( "uCustomPosition", value ); + Property::Value value = Vector3(0.0f, 0.0f, 0.0f); + Property::Index propertyIndex = focusableTile.RegisterProperty("uCustomPosition", value); // We create a constraint to perform a precalculation on the scroll-view X offset // and pass it to the shader uniform, along with the tile's position. - Constraint shaderPosition = Constraint::New < Vector3 > ( focusableTile, propertyIndex, TileShaderPositionConstraint( mPageWidth, position.x ) ); - shaderPosition.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) ); - shaderPosition.SetRemoveAction( Constraint::DISCARD ); + Constraint shaderPosition = Constraint::New(focusableTile, propertyIndex, TileShaderPositionConstraint(mPageWidth, position.x)); + shaderPosition.AddSource(Source(mScrollView, ScrollView::Property::SCROLL_POSITION)); + shaderPosition.SetRemoveAction(Constraint::DISCARD); shaderPosition.Apply(); //focusableTile.Add( tileContent ); // Create an ImageView for the 9-patch border around the tile. ImageView borderImage = ImageView::New(); borderImage.SetStyleName("DemoTileBorder"); - borderImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - borderImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - borderImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - borderImage.SetProperty( Actor::Property::OPACITY, 0.8f ); - focusableTile.Add( borderImage ); + borderImage.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + borderImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + borderImage.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); + borderImage.SetProperty(Actor::Property::OPACITY, 0.8f); + focusableTile.Add(borderImage); TextLabel label = TextLabel::New(); - label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); - label.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - label.SetStyleName( "LauncherLabel" ); - label.SetProperty( TextLabel::Property::MULTI_LINE, true ); - label.SetProperty( TextLabel::Property::TEXT, title ); - label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - label.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + label.SetStyleName("LauncherLabel"); + label.SetProperty(TextLabel::Property::MULTI_LINE, true); + label.SetProperty(TextLabel::Property::TEXT, title); + label.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + label.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + label.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT); // Pad around the label as its size is the same as the 9-patch border. It will overlap it without padding. - label.SetProperty( Actor::Property::PADDING, Padding( TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING ) ); - focusableTile.Add( label ); + label.SetProperty(Actor::Property::PADDING, Padding(TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING)); + focusableTile.Add(label); // Connect to the touch events - focusableTile.TouchedSignal().Connect( this, &DaliTableView::OnTilePressed ); - focusableTile.HoveredSignal().Connect( this, &DaliTableView::OnTileHovered ); + focusableTile.TouchedSignal().Connect(this, &DaliTableView::OnTilePressed); + focusableTile.HoveredSignal().Connect(this, &DaliTableView::OnTileHovered); return focusableTile; } -bool DaliTableView::OnTilePressed( Actor actor, const TouchEvent& event ) +bool DaliTableView::OnTilePressed(Actor actor, const TouchEvent& event) { - return DoTilePress( actor, event.GetState( 0 ) ); + return DoTilePress(actor, event.GetState(0)); } -bool DaliTableView::DoTilePress( Actor actor, PointState::Type pointState ) +bool DaliTableView::DoTilePress(Actor actor, PointState::Type pointState) { bool consumed = false; - if( PointState::DOWN == pointState ) + if(PointState::DOWN == pointState) { mPressedActor = actor; - consumed = true; + consumed = true; } // A button press is only valid if the Down & Up events // both occurred within the button. - if( ( PointState::UP == pointState ) && - ( mPressedActor == actor ) ) + if((PointState::UP == pointState) && + (mPressedActor == actor)) { // ignore Example button presses when scrolling or button animating. - if( ( !mScrolling ) && ( !mPressedAnimation ) ) + if((!mScrolling) && (!mPressedAnimation)) { - std::string name = actor.GetProperty< std::string >( Dali::Actor::Property::NAME ); - const ExampleListIter end = mExampleList.end(); - for( ExampleListIter iter = mExampleList.begin(); iter != end; ++iter ) + std::string name = actor.GetProperty(Dali::Actor::Property::NAME); + const ExampleListIter end = mExampleList.end(); + for(ExampleListIter iter = mExampleList.begin(); iter != end; ++iter) { - if( (*iter).name == name ) + if((*iter).name == name) { // do nothing, until pressed animation finished. consumed = true; @@ -593,60 +588,58 @@ bool DaliTableView::DoTilePress( Actor actor, PointState::Type pointState ) } } - if( consumed ) + if(consumed) { - mPressedAnimation = Animation::New( BUTTON_PRESS_ANIMATION_TIME ); - mPressedAnimation.SetEndAction( Animation::DISCARD ); + mPressedAnimation = Animation::New(BUTTON_PRESS_ANIMATION_TIME); + mPressedAnimation.SetEndAction(Animation::DISCARD); // scale the content actor within the Tile, as to not affect the placement within the Table. Actor content = actor.GetChildAt(0); - mPressedAnimation.AnimateTo( Property( content, Actor::Property::SCALE ), Vector3( 0.7f, 0.7f, 1.0f ), AlphaFunction::EASE_IN_OUT, - TimePeriod( 0.0f, BUTTON_PRESS_ANIMATION_TIME * 0.5f ) ); - mPressedAnimation.AnimateTo( Property( content, Actor::Property::SCALE ), Vector3::ONE, AlphaFunction::EASE_IN_OUT, - TimePeriod( BUTTON_PRESS_ANIMATION_TIME * 0.5f, BUTTON_PRESS_ANIMATION_TIME * 0.5f ) ); + mPressedAnimation.AnimateTo(Property(content, Actor::Property::SCALE), Vector3(0.7f, 0.7f, 1.0f), AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, BUTTON_PRESS_ANIMATION_TIME * 0.5f)); + mPressedAnimation.AnimateTo(Property(content, Actor::Property::SCALE), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod(BUTTON_PRESS_ANIMATION_TIME * 0.5f, BUTTON_PRESS_ANIMATION_TIME * 0.5f)); // Rotate button on the Y axis when pressed. - mPressedAnimation.AnimateBy( Property( content, Actor::Property::ORIENTATION ), Quaternion( Degree( 0.0f ), Degree( 180.0f ), Degree( 0.0f ) ) ); + mPressedAnimation.AnimateBy(Property(content, Actor::Property::ORIENTATION), Quaternion(Degree(0.0f), Degree(180.0f), Degree(0.0f))); mPressedAnimation.Play(); - mPressedAnimation.FinishedSignal().Connect( this, &DaliTableView::OnPressedAnimationFinished ); + mPressedAnimation.FinishedSignal().Connect(this, &DaliTableView::OnPressedAnimationFinished); } } return consumed; } -void DaliTableView::OnPressedAnimationFinished( Dali::Animation& source ) +void DaliTableView::OnPressedAnimationFinished(Dali::Animation& source) { mPressedAnimation.Reset(); - if( mPressedActor ) + if(mPressedActor) { - std::string name = mPressedActor.GetProperty< std::string >( Dali::Actor::Property::NAME ); + std::string name = mPressedActor.GetProperty(Dali::Actor::Property::NAME); - ExecuteProcess( name, mApplication ); + ExecuteProcess(name, mApplication); mPressedActor.Reset(); } } -void DaliTableView::OnScrollStart( const Dali::Vector2& position ) +void DaliTableView::OnScrollStart(const Dali::Vector2& position) { mScrolling = true; PlayAnimation(); } -void DaliTableView::OnScrollComplete( const Dali::Vector2& position ) +void DaliTableView::OnScrollComplete(const Dali::Vector2& position) { mScrolling = false; // move focus to 1st item of new page AccessibilityManager accessibilityManager = AccessibilityManager::Get(); - accessibilityManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0) ); + accessibilityManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0)); } -bool DaliTableView::OnScrollTouched( Actor actor, const TouchEvent& event ) +bool DaliTableView::OnScrollTouched(Actor actor, const TouchEvent& event) { - if( PointState::DOWN == event.GetState( 0 ) ) + if(PointState::DOWN == event.GetState(0)) { mPressedActor = actor; } @@ -658,56 +651,56 @@ void DaliTableView::ApplyScrollViewEffect() { // Remove old effect if exists. - if( mScrollViewEffect ) + if(mScrollViewEffect) { - mScrollView.RemoveEffect( mScrollViewEffect ); + mScrollView.RemoveEffect(mScrollViewEffect); } // Just one effect for now SetupInnerPageCubeEffect(); - mScrollView.ApplyEffect( mScrollViewEffect ); + mScrollView.ApplyEffect(mScrollViewEffect); } void DaliTableView::SetupInnerPageCubeEffect() { const Window::WindowSize windowDimensions = mApplication.GetWindow().GetSize(); - const Vector2 windowSize(windowDimensions.GetWidth(), windowDimensions.GetHeight()); + const Vector2 windowSize(windowDimensions.GetWidth(), windowDimensions.GetHeight()); - Dali::Path path = Dali::Path::New(); + Dali::Path path = Dali::Path::New(); Dali::Property::Array points; points.Resize(3); - points[0] = Vector3( windowSize.x*0.5, 0.0f, windowSize.x*0.5f); - points[1] = Vector3( 0.0f, 0.0f, 0.0f ); - points[2] = Vector3( -windowSize.x*0.5f, 0.0f, windowSize.x*0.5f); - path.SetProperty( Path::Property::POINTS, points ); + points[0] = Vector3(windowSize.x * 0.5, 0.0f, windowSize.x * 0.5f); + points[1] = Vector3(0.0f, 0.0f, 0.0f); + points[2] = Vector3(-windowSize.x * 0.5f, 0.0f, windowSize.x * 0.5f); + path.SetProperty(Path::Property::POINTS, points); Dali::Property::Array controlPoints; controlPoints.Resize(4); - controlPoints[0] = Vector3( windowSize.x*0.5f, 0.0f, windowSize.x*0.3f ); - controlPoints[1] = Vector3( windowSize.x*0.3f, 0.0f, 0.0f ); - controlPoints[2] = Vector3(-windowSize.x*0.3f, 0.0f, 0.0f ); - controlPoints[3] = Vector3(-windowSize.x*0.5f, 0.0f, windowSize.x*0.3f ); - path.SetProperty( Path::Property::CONTROL_POINTS, controlPoints ); - + controlPoints[0] = Vector3(windowSize.x * 0.5f, 0.0f, windowSize.x * 0.3f); + controlPoints[1] = Vector3(windowSize.x * 0.3f, 0.0f, 0.0f); + controlPoints[2] = Vector3(-windowSize.x * 0.3f, 0.0f, 0.0f); + controlPoints[3] = Vector3(-windowSize.x * 0.5f, 0.0f, windowSize.x * 0.3f); + path.SetProperty(Path::Property::CONTROL_POINTS, controlPoints); mScrollViewEffect = ScrollViewPagePathEffect::New(path, - Vector3(-1.0f,0.0f,0.0f), + Vector3(-1.0f, 0.0f, 0.0f), Toolkit::ScrollView::Property::SCROLL_FINAL_X, - Vector3(windowSize.x*TABLE_RELATIVE_SIZE.x,windowSize.y*TABLE_RELATIVE_SIZE.y,0.0f),mTotalPages); + Vector3(windowSize.x * TABLE_RELATIVE_SIZE.x, windowSize.y * TABLE_RELATIVE_SIZE.y, 0.0f), + mTotalPages); } -void DaliTableView::OnKeyEvent( const KeyEvent& event ) +void DaliTableView::OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::DOWN ) + if(event.GetState() == KeyEvent::DOWN) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { // If there's a Popup, Hide it if it's contributing to the display in any way (EG. transitioning in or out). // Otherwise quit. - if ( mVersionPopup && ( mVersionPopup.GetDisplayState() != Toolkit::Popup::HIDDEN ) ) + if(mVersionPopup && (mVersionPopup.GetDisplayState() != Toolkit::Popup::HIDDEN)) { - mVersionPopup.SetDisplayState( Popup::HIDDEN ); + mVersionPopup.SetDisplayState(Popup::HIDDEN); } else { @@ -717,14 +710,14 @@ void DaliTableView::OnKeyEvent( const KeyEvent& event ) } } -void DaliTableView::SetupBackground( Actor bubbleContainer ) +void DaliTableView::SetupBackground(Actor bubbleContainer) { // Add bubbles to the bubbleContainer. // Note: The bubbleContainer is parented externally to this function. - AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES ); + AddBackgroundActors(bubbleContainer, NUM_BACKGROUND_IMAGES); } -void DaliTableView::InitialiseBackgroundActors( Actor actor ) +void DaliTableView::InitialiseBackgroundActors(Actor actor) { // Delete current animations mBackgroundAnimations.clear(); @@ -732,59 +725,59 @@ void DaliTableView::InitialiseBackgroundActors( Actor actor ) // Create new animations const Vector3 size = actor.GetTargetSize(); - for( unsigned int i = 0, childCount = actor.GetChildCount(); i < childCount; ++i ) + for(unsigned int i = 0, childCount = actor.GetChildCount(); i < childCount; ++i) { - Actor child = actor.GetChildAt( i ); + Actor child = actor.GetChildAt(i); // Calculate a random position - Vector3 childPos( Random::Range( -size.x * 0.5f * BACKGROUND_SPREAD_SCALE, size.x * 0.85f * BACKGROUND_SPREAD_SCALE ), - Random::Range( -size.y, size.y ), - Random::Range( BUBBLE_MIN_Z, BUBBLE_MAX_Z ) ); + Vector3 childPos(Random::Range(-size.x * 0.5f * BACKGROUND_SPREAD_SCALE, size.x * 0.85f * BACKGROUND_SPREAD_SCALE), + Random::Range(-size.y, size.y), + Random::Range(BUBBLE_MIN_Z, BUBBLE_MAX_Z)); - child.SetProperty( Actor::Property::POSITION, childPos ); + child.SetProperty(Actor::Property::POSITION, childPos); // Define bubble horizontal parallax and vertical wrapping - Constraint animConstraint = Constraint::New < Vector3 > ( child, Actor::Property::POSITION, AnimateBubbleConstraint( childPos, Random::Range( -0.85f, 0.25f ) ) ); - animConstraint.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) ); - animConstraint.AddSource( Dali::ParentSource( Dali::Actor::Property::SIZE ) ); - animConstraint.AddSource( Dali::LocalSource( Dali::Actor::Property::SIZE ) ); - animConstraint.SetRemoveAction( Constraint::DISCARD ); + Constraint animConstraint = Constraint::New(child, Actor::Property::POSITION, AnimateBubbleConstraint(childPos, Random::Range(-0.85f, 0.25f))); + animConstraint.AddSource(Source(mScrollView, ScrollView::Property::SCROLL_POSITION)); + animConstraint.AddSource(Dali::ParentSource(Dali::Actor::Property::SIZE)); + animConstraint.AddSource(Dali::LocalSource(Dali::Actor::Property::SIZE)); + animConstraint.SetRemoveAction(Constraint::DISCARD); animConstraint.Apply(); // Kickoff animation - Animation animation = Animation::New( Random::Range( 30.0f, 160.0f ) ); - animation.AnimateBy( Property( child, Actor::Property::POSITION ), Vector3( 0.0f, -2000.0f, 0.0f ), AlphaFunction::LINEAR ); - animation.SetLooping( true ); + Animation animation = Animation::New(Random::Range(30.0f, 160.0f)); + animation.AnimateBy(Property(child, Actor::Property::POSITION), Vector3(0.0f, -2000.0f, 0.0f), AlphaFunction::LINEAR); + animation.SetLooping(true); animation.Play(); - mBackgroundAnimations.push_back( animation ); + mBackgroundAnimations.push_back(animation); } } -void DaliTableView::AddBackgroundActors( Actor layer, int count ) +void DaliTableView::AddBackgroundActors(Actor layer, int count) { - for( int i = 0; i < count; ++i ) + for(int i = 0; i < count; ++i) { - float randSize = Random::Range( 10.0f, 400.0f ); - int shapeType = static_cast( Random::Range( 0.0f, NUMBER_OF_SHAPE_IMAGES - 1 ) + 0.5f ); + float randSize = Random::Range(10.0f, 400.0f); + int shapeType = static_cast(Random::Range(0.0f, NUMBER_OF_SHAPE_IMAGES - 1) + 0.5f); ImageView dfActor = ImageView::New(); - dfActor.SetProperty( Actor::Property::SIZE, Vector2( randSize, randSize ) ); - dfActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + dfActor.SetProperty(Actor::Property::SIZE, Vector2(randSize, randSize)); + dfActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); // Set the Image URL and the custom shader at the same time Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect(); - Property::Map imageMap; - imageMap.Add( ImageVisual::Property::URL, SHAPE_IMAGE_TABLE[ shapeType ] ); - imageMap.Add( Toolkit::Visual::Property::SHADER, effect ); - dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap ); + Property::Map imageMap; + imageMap.Add(ImageVisual::Property::URL, SHAPE_IMAGE_TABLE[shapeType]); + imageMap.Add(Toolkit::Visual::Property::SHADER, effect); + dfActor.SetProperty(Toolkit::ImageView::Property::IMAGE, imageMap); - dfActor.SetStyleName( BUBBLE_COLOR_STYLE_NAME[ i%NUMBER_OF_BUBBLE_COLORS ] ); + dfActor.SetStyleName(BUBBLE_COLOR_STYLE_NAME[i % NUMBER_OF_BUBBLE_COLORS]); - layer.Add( dfActor ); + layer.Add(dfActor); } // Positioning will occur when the layer is relaid out - layer.OnRelayoutSignal().Connect( this, &DaliTableView::InitialiseBackgroundActors ); + layer.OnRelayoutSignal().Connect(this, &DaliTableView::InitialiseBackgroundActors); } bool DaliTableView::PauseBackgroundAnimation() @@ -796,9 +789,9 @@ bool DaliTableView::PauseBackgroundAnimation() void DaliTableView::PauseAnimation() { - if( mBackgroundAnimsPlaying ) + if(mBackgroundAnimsPlaying) { - for( AnimationListIter animIter = mBackgroundAnimations.begin(); animIter != mBackgroundAnimations.end(); ++animIter ) + for(AnimationListIter animIter = mBackgroundAnimations.begin(); animIter != mBackgroundAnimations.end(); ++animIter) { Animation anim = *animIter; @@ -811,9 +804,9 @@ void DaliTableView::PauseAnimation() void DaliTableView::PlayAnimation() { - if ( !mBackgroundAnimsPlaying ) + if(!mBackgroundAnimsPlaying) { - for( AnimationListIter animIter = mBackgroundAnimations.begin(); animIter != mBackgroundAnimations.end(); ++animIter ) + for(AnimationListIter animIter = mBackgroundAnimations.begin(); animIter != mBackgroundAnimations.end(); ++animIter) { Animation anim = *animIter; @@ -823,40 +816,41 @@ void DaliTableView::PlayAnimation() mBackgroundAnimsPlaying = true; } - mAnimationTimer.SetInterval( BACKGROUND_ANIMATION_DURATION ); + mAnimationTimer.SetInterval(BACKGROUND_ANIMATION_DURATION); } -Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction ) +Dali::Actor DaliTableView::OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction) { Actor nextFocusActor = proposed; - if( !current && !proposed ) + if(!current && !proposed) { // Set the initial focus to the first tile in the current page should be focused. nextFocusActor = mPages[mScrollView.GetCurrentPage()].GetChildAt(0); } - else if( !proposed ) + else if(!proposed) { // ScrollView is being focused but nothing in the current page can be focused further // in the given direction. We should work out which page to scroll to next. int currentPage = mScrollView.GetCurrentPage(); - int newPage = currentPage; - if( direction == Dali::Toolkit::Control::KeyboardFocus::LEFT ) + int newPage = currentPage; + if(direction == Dali::Toolkit::Control::KeyboardFocus::LEFT) { newPage--; } - else if( direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT ) + else if(direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT) { newPage++; } newPage = std::max(0, std::min(mTotalPages - 1, newPage)); - if( newPage == currentPage ) + if(newPage == currentPage) { - if( direction == Dali::Toolkit::Control::KeyboardFocus::LEFT ) + if(direction == Dali::Toolkit::Control::KeyboardFocus::LEFT) { newPage = mTotalPages - 1; - } else if( direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT ) + } + else if(direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT) { newPage = 0; } @@ -865,12 +859,12 @@ Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali:: // Scroll to the page in the given direction mScrollView.ScrollTo(newPage); - if( direction == Dali::Toolkit::Control::KeyboardFocus::LEFT ) + if(direction == Dali::Toolkit::Control::KeyboardFocus::LEFT) { // Work out the cell position for the last tile int remainingExamples = mExampleList.size() - newPage * EXAMPLES_PER_PAGE; - int rowPos = (remainingExamples >= EXAMPLES_PER_PAGE) ? ROWS_PER_PAGE - 1 : ( (remainingExamples % EXAMPLES_PER_PAGE + EXAMPLES_PER_ROW) / EXAMPLES_PER_ROW - 1 ); - int colPos = remainingExamples >= EXAMPLES_PER_PAGE ? EXAMPLES_PER_ROW - 1 : ( remainingExamples % EXAMPLES_PER_PAGE - rowPos * EXAMPLES_PER_ROW - 1 ); + int rowPos = (remainingExamples >= EXAMPLES_PER_PAGE) ? ROWS_PER_PAGE - 1 : ((remainingExamples % EXAMPLES_PER_PAGE + EXAMPLES_PER_ROW) / EXAMPLES_PER_ROW - 1); + int colPos = remainingExamples >= EXAMPLES_PER_PAGE ? EXAMPLES_PER_ROW - 1 : (remainingExamples % EXAMPLES_PER_PAGE - rowPos * EXAMPLES_PER_ROW - 1); // Move the focus to the last tile in the new page. nextFocusActor = mPages[newPage].GetChildAt(rowPos * EXAMPLES_PER_ROW + colPos); @@ -885,70 +879,74 @@ Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali:: return nextFocusActor; } -void DaliTableView::OnFocusedActorActivated( Dali::Actor activatedActor ) +void DaliTableView::OnFocusedActorActivated(Dali::Actor activatedActor) { if(activatedActor) { mPressedActor = activatedActor; // Activate the current focused actor; - DoTilePress( mPressedActor, PointState::UP ); + DoTilePress(mPressedActor, PointState::UP); } } -bool DaliTableView::OnTileHovered( Actor actor, const HoverEvent& event ) +bool DaliTableView::OnTileHovered(Actor actor, const HoverEvent& event) { - KeyboardFocusManager::Get().SetCurrentFocusActor( actor ); + KeyboardFocusManager::Get().SetCurrentFocusActor(actor); return true; } -void DaliTableView::OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap ) +void DaliTableView::OnLogoTapped(Dali::Actor actor, const Dali::TapGesture& tap) { // Only show if currently fully hidden. If transitioning-out, the transition will not be interrupted. - if ( !mVersionPopup || ( mVersionPopup.GetDisplayState() == Toolkit::Popup::HIDDEN ) ) + if(!mVersionPopup || (mVersionPopup.GetDisplayState() == Toolkit::Popup::HIDDEN)) { - if ( !mVersionPopup ) + if(!mVersionPopup) { std::ostringstream stream; - stream << "DALi Core: " << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl << "(" << CORE_BUILD_DATE << ")\n"; - stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl << "(" << ADAPTOR_BUILD_DATE << ")\n"; - stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl << "(" << TOOLKIT_BUILD_DATE << ")\n"; - stream << "DALi Demo:" << "\n(" << DEMO_BUILD_DATE << ")\n"; + stream << "DALi Core: " << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl + << "(" << CORE_BUILD_DATE << ")\n"; + stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl + << "(" << ADAPTOR_BUILD_DATE << ")\n"; + stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl + << "(" << TOOLKIT_BUILD_DATE << ")\n"; + stream << "DALi Demo:" + << "\n(" << DEMO_BUILD_DATE << ")\n"; mVersionPopup = Dali::Toolkit::Popup::New(); - Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Version information" ); - titleActor.SetProperty( Actor::Property::NAME, "titleActor" ); - titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER ); - titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); + Toolkit::TextLabel titleActor = Toolkit::TextLabel::New("Version information"); + titleActor.SetProperty(Actor::Property::NAME, "titleActor"); + titleActor.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER); + titleActor.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); - Toolkit::TextLabel contentActor = Toolkit::TextLabel::New( stream.str() ); - contentActor.SetProperty( Actor::Property::NAME, "contentActor" ); - contentActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); - contentActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER ); - contentActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE ); - contentActor.SetProperty( Actor::Property::PADDING, Padding( 0.0f, 0.0f, 20.0f, 0.0f ) ); + Toolkit::TextLabel contentActor = Toolkit::TextLabel::New(stream.str()); + contentActor.SetProperty(Actor::Property::NAME, "contentActor"); + contentActor.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true); + contentActor.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER); + contentActor.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE); + contentActor.SetProperty(Actor::Property::PADDING, Padding(0.0f, 0.0f, 20.0f, 0.0f)); - mVersionPopup.SetTitle( titleActor ); - mVersionPopup.SetContent( contentActor ); + mVersionPopup.SetTitle(titleActor); + mVersionPopup.SetContent(contentActor); - mVersionPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH ); - mVersionPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 1.0f, 1.0f ) ); - mVersionPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); + mVersionPopup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH); + mVersionPopup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 1.0f, 1.0f)); + mVersionPopup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); - mVersionPopup.OutsideTouchedSignal().Connect( this, &DaliTableView::HideVersionPopup ); - mApplication.GetWindow().Add( mVersionPopup ); + mVersionPopup.OutsideTouchedSignal().Connect(this, &DaliTableView::HideVersionPopup); + mApplication.GetWindow().Add(mVersionPopup); } - mVersionPopup.SetDisplayState( Popup::SHOWN ); + mVersionPopup.SetDisplayState(Popup::SHOWN); } } void DaliTableView::HideVersionPopup() { // Only hide if currently fully shown. If transitioning-in, the transition will not be interrupted. - if ( mVersionPopup && ( mVersionPopup.GetDisplayState() == Toolkit::Popup::SHOWN ) ) + if(mVersionPopup && (mVersionPopup.GetDisplayState() == Toolkit::Popup::SHOWN)) { - mVersionPopup.SetDisplayState( Popup::HIDDEN ); + mVersionPopup.SetDisplayState(Popup::HIDDEN); } } diff --git a/shared/dali-table-view.h b/shared/dali-table-view.h index aa94d38..44a81dd 100644 --- a/shared/dali-table-view.h +++ b/shared/dali-table-view.h @@ -18,18 +18,18 @@ * */ -#include #include #include +#include class Example; -typedef std::vector ExampleList; -typedef ExampleList::iterator ExampleListIter; +typedef std::vector ExampleList; +typedef ExampleList::iterator ExampleListIter; typedef ExampleList::const_iterator ExampleListConstIter; -typedef std::vector AnimationList; -typedef AnimationList::iterator AnimationListIter; +typedef std::vector AnimationList; +typedef AnimationList::iterator AnimationListIter; typedef AnimationList::const_iterator AnimationListConstIter; /** @@ -57,24 +57,20 @@ struct Example // Data - std::string name; ///< unique name of example - std::string title; ///< title (caption) of example to appear on tile button. + std::string name; ///< unique name of example + std::string title; ///< title (caption) of example to appear on tile button. }; - - /** * Dali-Demo instance */ class DaliTableView : public Dali::ConnectionTracker { public: - DaliTableView(Dali::Application& application); ~DaliTableView(); public: - /** * Adds an Example to our demo showcase * @@ -92,10 +88,9 @@ public: * @note Should be called before the Application MainLoop is started. * @note By default the examples are NOT sorted alphabetically by Title. */ - void SortAlphabetically( bool sortAlphabetically ); - -private: // Application callbacks & implementation + void SortAlphabetically(bool sortAlphabetically); +private: // Application callbacks & implementation static const unsigned int FOCUS_ANIMATION_ACTOR_NUMBER = 2; ///< The number of elements used to form the custom focus effect /** @@ -112,7 +107,7 @@ private: // Application callbacks & implementation * * @param[in] app Application instance */ - void Initialize( Dali::Application& app ); + void Initialize(Dali::Application& app); /** * Populates the contents (ScrollView) with all the @@ -126,7 +121,7 @@ private: // Application callbacks & implementation * * @param[in] degrees The requested angle. */ - void Rotate( unsigned int degrees ); + void Rotate(unsigned int degrees); /** * Creates a tile for the main menu. @@ -138,7 +133,7 @@ private: // Application callbacks & implementation * * @return The Actor for the created tile. */ - Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Dali::Vector2& position ); + Dali::Actor CreateTile(const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Dali::Vector2& position); // Signal handlers @@ -150,7 +145,7 @@ private: // Application callbacks & implementation * * @return Consume flag */ - bool OnTilePressed( Dali::Actor actor, const Dali::TouchEvent& event ); + bool OnTilePressed(Dali::Actor actor, const Dali::TouchEvent& event); /** * Called by OnTilePressed & Accessibility to do the appropriate action. @@ -160,7 +155,7 @@ private: // Application callbacks & implementation * * @return Consume flag */ - bool DoTilePress( Dali::Actor actor, Dali::PointState::Type state ); + bool DoTilePress(Dali::Actor actor, Dali::PointState::Type state); /** * Signal emitted when any tile has been hovered @@ -170,7 +165,7 @@ private: // Application callbacks & implementation * * @return Consume flag */ - bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event ); + bool OnTileHovered(Dali::Actor actor, const Dali::HoverEvent& event); /** * Signal emitted when the pressed animation has completed. @@ -186,7 +181,7 @@ private: // Application callbacks & implementation * * @return Consume flag */ - bool OnButtonClicked( Dali::Toolkit::Button& button ); + bool OnButtonClicked(Dali::Toolkit::Button& button); /** * Signal emitted when scrolling has started. @@ -211,7 +206,7 @@ private: // Application callbacks & implementation * * @return Consume flag */ - bool OnScrollTouched( Dali::Actor actor, const Dali::TouchEvent& event ); + bool OnScrollTouched(Dali::Actor actor, const Dali::TouchEvent& event); /** * Setup the effect on the scroll view @@ -241,14 +236,14 @@ private: // Application callbacks & implementation /** * Key event handler */ - void OnKeyEvent( const Dali::KeyEvent& event ); + void OnKeyEvent(const Dali::KeyEvent& event); /** * Create a depth field background * * @param[in] bubbleLayer Add the graphics to this layer */ - void SetupBackground( Dali::Actor bubbleLayer ); + void SetupBackground(Dali::Actor bubbleLayer); /** * Create background actors for the given layer @@ -256,7 +251,7 @@ private: // Application callbacks & implementation * @param[in] layer The layer to add the actors to * @param[in] count The number of actors to generate */ - void AddBackgroundActors( Dali::Actor layer, int count ); + void AddBackgroundActors(Dali::Actor layer, int count); /** * Timer handler for ending background animation @@ -288,28 +283,28 @@ private: // Application callbacks & implementation * @param[in] direction The direction to move the focus * @return The actor to move the keyboard focus to. */ - Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction ); + Dali::Actor OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction); /** * Callback when the keyboard focused actor is activated. * * @param[in] activatedActor The activated actor */ - void OnFocusedActorActivated( Dali::Actor activatedActor ); + void OnFocusedActorActivated(Dali::Actor activatedActor); /** * Callback when the keyboard focus indicator is enabled. * * @param[in] actor The keyboard focus indicator. */ - void OnFocusIndicatorEnabled( Dali::Actor actor ); + void OnFocusIndicatorEnabled(Dali::Actor actor); /** * Callback when the keyboard focus indicator is disabled. * * @param[in] actor The keyboard focus indicator. */ - void OnFocusIndicatorDisabled( Dali::Actor actor ); + void OnFocusIndicatorDisabled(Dali::Actor actor); /** * Called when the logo is tapped @@ -317,69 +312,67 @@ private: // Application callbacks & implementation * @param[in] actor The tapped actor * @param[in] tap The tap information. */ - void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap ); + void OnLogoTapped(Dali::Actor actor, const Dali::TapGesture& tap); /** * Hides the popup */ void HideVersionPopup(); - /* + /* * @brief Callback called when the buttons page actor is relaid out * * @param[in] actor The page actor */ - void OnButtonsPageRelayout( const Dali::Actor& actor ); + void OnButtonsPageRelayout(const Dali::Actor& actor); - /** + /** * @brief The is connected to the keyboard focus highlight actor, and called when it is placed on the scene. * @param[in] actor The actor that has been placed on the scene. */ - void OnSceneConnect( Dali::Actor actor ); + void OnSceneConnect(Dali::Actor actor); - /** + /** * @brief Callback called to set up background actors * * @param[in] actor The actor raising the callback */ - void InitialiseBackgroundActors( Dali::Actor actor ); + void InitialiseBackgroundActors(Dali::Actor actor); private: - - Dali::Application& mApplication; ///< Application instance. - Dali::Toolkit::Control mRootActor; ///< All content (excluding background is anchored to this Actor) - Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor. - Dali::Animation mPressedAnimation; ///< Button press scaling animation. - Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples) - Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view - Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler - Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler - Dali::Actor mPressedActor; ///< The currently pressed actor. - Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period - Dali::TapGestureDetector mLogoTapDetector; ///< To detect taps on the logo - Dali::Toolkit::Popup mVersionPopup; ///< Displays DALi library version information + Dali::Application& mApplication; ///< Application instance. + Dali::Toolkit::Control mRootActor; ///< All content (excluding background is anchored to this Actor) + Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor. + Dali::Animation mPressedAnimation; ///< Button press scaling animation. + Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples) + Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view + Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler + Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler + Dali::Actor mPressedActor; ///< The currently pressed actor. + Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period + Dali::TapGestureDetector mLogoTapDetector; ///< To detect taps on the logo + Dali::Toolkit::Popup mVersionPopup; ///< Displays DALi library version information /** * This struct encapsulates all data relevant to each of the elements used within the custom keyboard focus effect. */ struct FocusEffect { - Dali::Toolkit::ImageView actor; ///< The parent keyboard focus highlight actor - Dali::Animation animation; ///< The animation for the parent keyboard focus highlight actor + Dali::Toolkit::ImageView actor; ///< The parent keyboard focus highlight actor + Dali::Animation animation; ///< The animation for the parent keyboard focus highlight actor }; - FocusEffect mFocusEffect[FOCUS_ANIMATION_ACTOR_NUMBER]; ///< The elements used to create the custom focus effect - - std::vector< Dali::Actor > mPages; ///< List of pages. - AnimationList mBackgroundAnimations; ///< List of background bubble animations - ExampleList mExampleList; ///< List of examples. + FocusEffect mFocusEffect[FOCUS_ANIMATION_ACTOR_NUMBER]; ///< The elements used to create the custom focus effect - float mPageWidth; ///< The width of a page within the scroll-view, used to calculate the domain - int mTotalPages; ///< Total pages within scrollview. + std::vector mPages; ///< List of pages. + AnimationList mBackgroundAnimations; ///< List of background bubble animations + ExampleList mExampleList; ///< List of examples. - bool mScrolling:1; ///< Flag indicating whether view is currently being scrolled - bool mSortAlphabetically:1; ///< Sort examples alphabetically. - bool mBackgroundAnimsPlaying:1; ///< Are background animations playing + float mPageWidth; ///< The width of a page within the scroll-view, used to calculate the domain + int mTotalPages; ///< Total pages within scrollview. + bool mScrolling : 1; ///< Flag indicating whether view is currently being scrolled + bool mSortAlphabetically : 1; ///< Sort examples alphabetically. + bool mBackgroundAnimsPlaying : 1; ///< Are background animations playing }; #endif // DALI_DEMO_TABLEVIEW_H diff --git a/shared/execute-process-android.cpp b/shared/execute-process-android.cpp index 2b91241..59bc63b 100644 --- a/shared/execute-process-android.cpp +++ b/shared/execute-process-android.cpp @@ -15,24 +15,24 @@ * */ - // FILE HEADER +// FILE HEADER #include "execute-process.h" - // EXTERNAL INCLUDES -#include +// EXTERNAL INCLUDES #include +#include -#include -#include #include +#include +#include #include #include -void ExecuteProcess( const std::string& processName, Dali::Application& application ) +void ExecuteProcess(const std::string& processName, Dali::Application& application) { struct android_app* nativeApp = Dali::Integration::AndroidFramework::Get().GetNativeApplication(); - if (!nativeApp) + if(!nativeApp) { DALI_LOG_ERROR("Couldn't get native app."); return; diff --git a/shared/execute-process-unix.cpp b/shared/execute-process-unix.cpp index aa77771..7e547b2 100644 --- a/shared/execute-process-unix.cpp +++ b/shared/execute-process-unix.cpp @@ -15,22 +15,22 @@ * */ - // FILE HEADER +// FILE HEADER #include "execute-process.h" - // EXTERNAL INCLUDES -#include -#include +// EXTERNAL INCLUDES #include +#include +#include -void ExecuteProcess( const std::string& processName, Dali::Application& application ) +void ExecuteProcess(const std::string& processName, Dali::Application& application) { std::stringstream stream; stream << DEMO_EXAMPLE_BIN << processName.c_str(); pid_t pid = fork(); - if( pid == 0 ) + if(pid == 0) { - execlp( stream.str().c_str(), processName.c_str(), NULL ); + execlp(stream.str().c_str(), processName.c_str(), NULL); DALI_ASSERT_ALWAYS(false && "exec failed!"); } } diff --git a/shared/execute-process-win.cpp b/shared/execute-process-win.cpp index 4bbc672..64a4a0a 100644 --- a/shared/execute-process-win.cpp +++ b/shared/execute-process-win.cpp @@ -15,47 +15,47 @@ * */ - // FILE HEADER +// FILE HEADER #include "execute-process.h" - // EXTERNAL INCLUDES -#include +// EXTERNAL INCLUDES #include +#include namespace { -const std::string PATH_SEPARATOR( "\\" ); +const std::string PATH_SEPARATOR("\\"); } -void ExecuteProcess( const std::string& processName, Dali::Application& application ) +void ExecuteProcess(const std::string& processName, Dali::Application& application) { std::string processPathName; const bool isRelativePath = '.' == DEMO_EXAMPLE_BIN[0]; - if (isRelativePath) + if(isRelativePath) { - char currentPath[MAX_PATH]; - DWORD numberOfCharacters = GetCurrentDirectory( MAX_PATH, currentPath ); + char currentPath[MAX_PATH]; + DWORD numberOfCharacters = GetCurrentDirectory(MAX_PATH, currentPath); - if( 0u == numberOfCharacters ) + if(0u == numberOfCharacters) { - DALI_ASSERT_ALWAYS( !"Failed to retrieve the current working directory" ); + DALI_ASSERT_ALWAYS(!"Failed to retrieve the current working directory"); } currentPath[numberOfCharacters] = '\0'; - processPathName = std::string(currentPath) + PATH_SEPARATOR + DEMO_EXAMPLE_BIN + PATH_SEPARATOR + processName + ".exe"; + processPathName = std::string(currentPath) + PATH_SEPARATOR + DEMO_EXAMPLE_BIN + PATH_SEPARATOR + processName + ".exe"; } else { processPathName = DEMO_EXAMPLE_BIN + PATH_SEPARATOR + processName + ".exe"; } - STARTUPINFO info = { sizeof( info ) }; + STARTUPINFO info = {sizeof(info)}; PROCESS_INFORMATION processInfo; - if( CreateProcess( processPathName.c_str(), nullptr, nullptr, nullptr, TRUE, 0, nullptr, nullptr, &info, &processInfo ) ) + if(CreateProcess(processPathName.c_str(), nullptr, nullptr, nullptr, TRUE, 0, nullptr, nullptr, &info, &processInfo)) { - WaitForSingleObject( processInfo.hProcess, INFINITE ); - CloseHandle( processInfo.hProcess ); - CloseHandle( processInfo.hThread ); + WaitForSingleObject(processInfo.hProcess, INFINITE); + CloseHandle(processInfo.hProcess); + CloseHandle(processInfo.hThread); } } diff --git a/shared/execute-process.h b/shared/execute-process.h index c3d11cd..70adb5d 100644 --- a/shared/execute-process.h +++ b/shared/execute-process.h @@ -18,11 +18,10 @@ * */ - // EXTERNAL INCLUDES -#include +// EXTERNAL INCLUDES #include +#include -void ExecuteProcess( const std::string& processName, Dali::Application& application ); - +void ExecuteProcess(const std::string& processName, Dali::Application& application); #endif // DALI_DEMO_EXECUTE_PROCESS_H diff --git a/shared/multi-language-strings.h b/shared/multi-language-strings.h index 5879d03..6aa727f 100644 --- a/shared/multi-language-strings.h +++ b/shared/multi-language-strings.h @@ -2,7 +2,7 @@ #define DALI_DEMO_MULTI_LANGUAGE_STRINGS_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,208 +23,131 @@ namespace MultiLanguageStrings { - struct Language - { - std::string languageName; - std::string languageRomanName; - std::string text; - }; +struct Language +{ + std::string languageName; + std::string languageRomanName; + std::string text; +}; - const Language LANGUAGES[] = { - { - "العَرَبِيةُ", - "(Arabic)", - "لإعادة ترتيب الشاشات، يجب تغيير نوع العرض إلى شبكة قابلة للتخصيص." - }, - { - "অসমীয়া লিপি", - "(Assamese)", - "পৃষ্ঠাসমূহ পুনঃব্যৱস্থিত কৰিবলৈ, আপুনি দৰ্শনৰ প্ৰকাৰ এটা অনুকূলনযোগ্য গ্ৰীডলৈ পৰিৱৰ্তন কৰাটো আৱশ্যক৷" - }, - { - "বাংলা", - "(Bengali)", - "তথ্য লোড করতে অক্ষম৷ পুনরায় চেষ্টা করতে ট্যাপ করুন৷" - }, - { - "English", - "(English)", - "A Quick Brown Fox Jumps Over The Lazy Dog" - }, - { - "Español", - "(Spanish)", - "No se puede añadir más aplicaciones. Se alcanzó la cantidad máxima." - }, - { - "فارسی", - "(Persian)", - "برای مرتب کردن مجدد صفحه‌ها، باید نوع نمایش را به یک نمای شبکه‌ای قابل تنظیم تغییر دهید." - }, - { - "Français", - "(French)", - "La nouvelle page sera composée des Dynamic Box S Planner, Tâches et S Memo" - }, - { - "ગુજરાતી લિપિ", - "(Gujarati)", - "પૃષ્ઠોને ફરીથી ગોઠવવા માટે, તમારે દૃશ્ય પ્રકારને કસ્ટમાઇઝેશન યોગ્ય ગ્રિડ પર બદલવાની જરૂર છે." - }, - { - "हिन्दी", - "(Hindi)", - "पेज पुनः व्यवस्थित करने के लिए, आपको दृश्य प्रकार को अनुकूलित करने योग्य ग्रिड में बदलना होगा।" - }, - { - "Bahasa Indonesia", - "(Indonesian)", - "Tidak dapat menambahkan aplikasi lagi. Jumlah maksimum aplikasi tercapai." - }, - { - "ខេមរភាសា", - "(Cambodian)", - "ដើម្បី​រៀបចំ​ទំព័រ​ឡើងវិញ អ្នក​ត្រូវ​ប្ដូរ​ប្រភេទ​បង្ហាញ​ទៅ​ក្រឡាចត្រង្គ​ដែល​អាច​ប្ដូរ​តាមបំណង។" - }, - { - "ಕನ್ನಡ ", - "(Kannada)", - "ಪುಟಗಳನ್ನು ಮರುವ್ಯವಸ್ಥಿತವಾಗಿ ಇರಿಸಲು, ನೀವು ವೀಕ್ಷಣೆ ವಿಧವನ್ನು ಗ್ರಾಹಕೀಕರಿಸಬಲ್ಲ ಗ್ರಿಡ್‌ಗೆ ಬದಲಾಯಿಸುವುದು ಅಗತ್ಯವಿದೆ." - }, - { - "한국어", - "(Korean)", - "페이지 순서를 변경하려면 보기 방식을 격자 보기(직접 설정)로 변경하세요." - }, - { - "ພາສາລາວ", - "(Lao)", - "ເພື່ອຈັດລຽງໜ້າຄືນ, ທ່ານຈໍາເປັນຕ້ອງປ່ຽນຊະນິດຂອງມຸມມອງໄປຫາຕາຕະລາງທີ່ກຳນົດເອງໄດ້." - }, - { - "മലയാളം", - "(Malayalam)", - "പേജുകൾ പുനഃക്രമീകരിക്കുന്നതിന്, ഇഷ്ടാനുസൃതമാക്കാവുന്ന ഗ്രിഡിലേക്ക് കാഴ്ചയുടെ തരം നിങ്ങൾ മാറ്റേണ്ടതുണ്ട്." - }, - { - "मराठी", - "(Marathi)", - "पृष्‍ठांची पुनर्रचना करा, आपण सानुकूलित करण्‍यायोग्‍य ग्रिडमध्‍ये व्‍ह्यू प्रकार बदलणे गरजेचे आहे." - }, - { - "Bahasa Melayu", - "(Malay)", - "Tidak boleh menambah aplikasi lagi. Bilangan maksimum aplikasi dicapai." - }, - { - "မြန်မာဘာသာ", - "(Burmese)", - "စာမ်က္ႏွာမ်ား ျပန္စီစဥ္ရန္ အျမင္ပံုစံကို စိတ္ၾကိဳက္လုပ္ႏိုင္ေသာ ဂရစ္ တစ္ခုသို႔ ေျပာင္းဖို႔လိုသည္။" - }, - { - "नेपाली", - "(Nepali)", - "थप अनुप्रयोगहरू थप्न सकिएन। अनुप्रयोगहरूको अधिकतम संख्या पुग्यो।" - }, - { - "ଓଡ଼ିଆ", - "(Oriya)", - "ପରବର୍ତ୍ତୀ ପୃଷ୍ଠା ଦେଖିବା ପାଇଁ ଦୁଇ ଆଙ୍ଗୁଠିରେ ସ୍ୱାଇପ୍ କରନ୍ତୁ।" - }, - { - "ਗੁਰਮੁਖੀ", - "(Punjabi)", - "ਇਹ ਫੋਲਡਰ ਅਤੇ ਇਸ ਵਿੱਚ ਸ਼ਾਮਲ ਸਾਰੇ ਆਈਟਮਾਂ ਨੂੰ ਮਿਟਾ ਦੇਵੇਗਾ।" - }, - { - "Português", - "(Portuguese)", - "Para reorganizar páginas, é necessário alterar o tipo de exibição para uma grade personalizável." - }, - { - "සිංහල", - "(Sinhala)", - "පිටු නැවත පෙළ ගැස්වීම සඳහා ඔබ විසින් දසුන් ප්‍රවර්ගය අභිමතීකෘත්‍ය ජාලයකට වෙනස් කළ යුතුය." - }, - { - "தமிழ்", - "(Tamil)", - "பக்கங்களை மறுஒழுங்குபடுத்தவென காட்சி வகையை தனிப்பயனாக்கத்தக்க கட்டமைப்பிற்கு மாற்ற வேண்டியுள்ளது." - }, - { - "తెలుగు", - "(Telugu)", - "మరిన్ని అప్లికేషన్‌లను జోడించడం సాధ్యం కాలేదు. గరిష్ట అప్లికేషన్‌ల సంఖ్యను చేరుకున్నాయి." - }, - { - "ภาษาไทย", - "(Thai)", - "คุณต้องเปลี่ยนชนิดการแสดง เป็นตารางที่กำหนดเองได้ เพื่อจัดหน้าใหม่" - }, - { - "Tagalog", - "(Tagalog)", - "Hindi makapagdagdag ng extra na linya dahil sa paghihigpit sa espasyo" - }, - { - "Türkçe", - "(Turkish)", - "Sayfaları yeniden düzenlemek için özelleştirilebilir kılavuzun görünüm tipini değiştirmeniz gerekir." - }, - { - "اُردُو", - "(Urdu)", - "صفحات کو دوبارہ ترتیب دینے کے لئے، آپ کو منظر کی قسم کو ایک حسب ضرورت گرڈ میں تبدیل کرنا ہوگا۔" - }, - { - "tiếng Việt", - "(Vietnamese)", - "Để sắp xếp lại các trang, bạn cần thay đổi kiểu xem sang dạng lưới tùy chỉnh." - }, - { - "漢語", - "(Chinese)", - "若要重新排列页面,您需要将视图类型更改为可自定义网格。" - }, - { - "ꦧꦱꦗꦮ, basa Jawa", - "(Javanese)", - "ꦧꦱꦗꦮ ꦕꦫꦗꦮ ꦲꦏ꧀ꦱꦫꦗꦮ ꦲꦤꦕꦫꦏ ꧋ꦱꦧꦼꦤ꧀ꦲꦸꦮꦺꦴꦁꦏꦭꦲꦶꦫꦏꦺꦏꦤ꧀ꦛꦶꦩꦂꦢꦶꦏꦭꦤ꧀ꦢꦂꦧꦺꦩꦂꦠꦧꦠ꧀ꦭꦤ꧀ꦲꦏ꧀ꦲꦏ꧀ꦏꦁꦥꦝ꧉" - }, - { - "Basa Sunda, ᮘᮞ ᮞᮥᮔ᮪ᮓ", - "(Sundanese)", - "ᮃᮊ᮪ᮞᮛ ᮞᮥᮔ᮪ᮓ ᮀᮁᮂᮃᮄᮅᮆᮇᮈᮉᮊᮋᮌᮍᮎᮏᮐᮑᮒᮓᮔᮕᮖᮗᮘᮙᮚᮛᮜᮝᮞᮟᮠᮡᮢᮣᮤᮥᮦᮧᮨᮩ᮪᮫ᮬᮭᮮᮯ᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹ᮺᮻᮼᮽᮾᮿ᳀᳁᳂᳃᳄᳅᳆᳇" - }, - { - "isiZulu", - "(Zulu)", - "Sawubona Mhlaba" - }, - { - "isiXhosa", - "(Xhosa)", - "Molo Lizwe" - }, - { - "አማርኛ", - "(Amharic)", - "ያስገቡት PIN ትክክለኛ አይደለም። እባክዎ እንደገና ይሞክሩ።" - }, - { - "ᱚᱞ ᱪᱤᱠᱤ", - "(Ol Chiki)", - "ᱥᱟᱱᱛᱟᱞᱤ ᱵᱟᱝᱞᱟᱫᱮᱥ ᱵᱷᱩᱴᱟᱱ ᱱᱮᱯᱟᱲ" - }, - { - "ꯃꯤꯇꯩ ꯃꯌꯦꯛ", - "(Meitei)", - "ꯅꯡ ꯀꯗꯥꯏꯗꯒꯤꯅꯣ ꯁꯣꯝꯒ ꯎꯟꯅꯖꯕ ꯁꯦ ꯌꯥꯝ ꯅꯨꯉꯥꯏꯖꯩ ꯎꯗꯕ ꯀꯨꯏꯔꯦ" - } - }; +const Language LANGUAGES[] = { + {"العَرَبِيةُ", + "(Arabic)", + "لإعادة ترتيب الشاشات، يجب تغيير نوع العرض إلى شبكة قابلة للتخصيص."}, + {"অসমীয়া লিপি", + "(Assamese)", + "পৃষ্ঠাসমূহ পুনঃব্যৱস্থিত কৰিবলৈ, আপুনি দৰ্শনৰ প্ৰকাৰ এটা অনুকূলনযোগ্য গ্ৰীডলৈ পৰিৱৰ্তন কৰাটো আৱশ্যক৷"}, + {"বাংলা", + "(Bengali)", + "তথ্য লোড করতে অক্ষম৷ পুনরায় চেষ্টা করতে ট্যাপ করুন৷"}, + {"English", + "(English)", + "A Quick Brown Fox Jumps Over The Lazy Dog"}, + {"Español", + "(Spanish)", + "No se puede añadir más aplicaciones. Se alcanzó la cantidad máxima."}, + {"فارسی", + "(Persian)", + "برای مرتب کردن مجدد صفحه‌ها، باید نوع نمایش را به یک نمای شبکه‌ای قابل تنظیم تغییر دهید."}, + {"Français", + "(French)", + "La nouvelle page sera composée des Dynamic Box S Planner, Tâches et S Memo"}, + {"ગુજરાતી લિપિ", + "(Gujarati)", + "પૃષ્ઠોને ફરીથી ગોઠવવા માટે, તમારે દૃશ્ય પ્રકારને કસ્ટમાઇઝેશન યોગ્ય ગ્રિડ પર બદલવાની જરૂર છે."}, + {"हिन्दी", + "(Hindi)", + "पेज पुनः व्यवस्थित करने के लिए, आपको दृश्य प्रकार को अनुकूलित करने योग्य ग्रिड में बदलना होगा।"}, + {"Bahasa Indonesia", + "(Indonesian)", + "Tidak dapat menambahkan aplikasi lagi. Jumlah maksimum aplikasi tercapai."}, + {"ខេមរភាសា", + "(Cambodian)", + "ដើម្បី​រៀបចំ​ទំព័រ​ឡើងវិញ អ្នក​ត្រូវ​ប្ដូរ​ប្រភេទ​បង្ហាញ​ទៅ​ក្រឡាចត្រង្គ​ដែល​អាច​ប្ដូរ​តាមបំណង។"}, + {"ಕನ್ನಡ ", + "(Kannada)", + "ಪುಟಗಳನ್ನು ಮರುವ್ಯವಸ್ಥಿತವಾಗಿ ಇರಿಸಲು, ನೀವು ವೀಕ್ಷಣೆ ವಿಧವನ್ನು ಗ್ರಾಹಕೀಕರಿಸಬಲ್ಲ ಗ್ರಿಡ್‌ಗೆ ಬದಲಾಯಿಸುವುದು ಅಗತ್ಯವಿದೆ."}, + {"한국어", + "(Korean)", + "페이지 순서를 변경하려면 보기 방식을 격자 보기(직접 설정)로 변경하세요."}, + {"ພາສາລາວ", + "(Lao)", + "ເພື່ອຈັດລຽງໜ້າຄືນ, ທ່ານຈໍາເປັນຕ້ອງປ່ຽນຊະນິດຂອງມຸມມອງໄປຫາຕາຕະລາງທີ່ກຳນົດເອງໄດ້."}, + {"മലയാളം", + "(Malayalam)", + "പേജുകൾ പുനഃക്രമീകരിക്കുന്നതിന്, ഇഷ്ടാനുസൃതമാക്കാവുന്ന ഗ്രിഡിലേക്ക് കാഴ്ചയുടെ തരം നിങ്ങൾ മാറ്റേണ്ടതുണ്ട്."}, + {"मराठी", + "(Marathi)", + "पृष्‍ठांची पुनर्रचना करा, आपण सानुकूलित करण्‍यायोग्‍य ग्रिडमध्‍ये व्‍ह्यू प्रकार बदलणे गरजेचे आहे."}, + {"Bahasa Melayu", + "(Malay)", + "Tidak boleh menambah aplikasi lagi. Bilangan maksimum aplikasi dicapai."}, + {"မြန်မာဘာသာ", + "(Burmese)", + "စာမ်က္ႏွာမ်ား ျပန္စီစဥ္ရန္ အျမင္ပံုစံကို စိတ္ၾကိဳက္လုပ္ႏိုင္ေသာ ဂရစ္ တစ္ခုသို႔ ေျပာင္းဖို႔လိုသည္။"}, + {"नेपाली", + "(Nepali)", + "थप अनुप्रयोगहरू थप्न सकिएन। अनुप्रयोगहरूको अधिकतम संख्या पुग्यो।"}, + {"ଓଡ଼ିଆ", + "(Oriya)", + "ପରବର୍ତ୍ତୀ ପୃଷ୍ଠା ଦେଖିବା ପାଇଁ ଦୁଇ ଆଙ୍ଗୁଠିରେ ସ୍ୱାଇପ୍ କରନ୍ତୁ।"}, + {"ਗੁਰਮੁਖੀ", + "(Punjabi)", + "ਇਹ ਫੋਲਡਰ ਅਤੇ ਇਸ ਵਿੱਚ ਸ਼ਾਮਲ ਸਾਰੇ ਆਈਟਮਾਂ ਨੂੰ ਮਿਟਾ ਦੇਵੇਗਾ।"}, + {"Português", + "(Portuguese)", + "Para reorganizar páginas, é necessário alterar o tipo de exibição para uma grade personalizável."}, + {"සිංහල", + "(Sinhala)", + "පිටු නැවත පෙළ ගැස්වීම සඳහා ඔබ විසින් දසුන් ප්‍රවර්ගය අභිමතීකෘත්‍ය ජාලයකට වෙනස් කළ යුතුය."}, + {"தமிழ்", + "(Tamil)", + "பக்கங்களை மறுஒழுங்குபடுத்தவென காட்சி வகையை தனிப்பயனாக்கத்தக்க கட்டமைப்பிற்கு மாற்ற வேண்டியுள்ளது."}, + {"తెలుగు", + "(Telugu)", + "మరిన్ని అప్లికేషన్‌లను జోడించడం సాధ్యం కాలేదు. గరిష్ట అప్లికేషన్‌ల సంఖ్యను చేరుకున్నాయి."}, + {"ภาษาไทย", + "(Thai)", + "คุณต้องเปลี่ยนชนิดการแสดง เป็นตารางที่กำหนดเองได้ เพื่อจัดหน้าใหม่"}, + {"Tagalog", + "(Tagalog)", + "Hindi makapagdagdag ng extra na linya dahil sa paghihigpit sa espasyo"}, + {"Türkçe", + "(Turkish)", + "Sayfaları yeniden düzenlemek için özelleştirilebilir kılavuzun görünüm tipini değiştirmeniz gerekir."}, + {"اُردُو", + "(Urdu)", + "صفحات کو دوبارہ ترتیب دینے کے لئے، آپ کو منظر کی قسم کو ایک حسب ضرورت گرڈ میں تبدیل کرنا ہوگا۔"}, + {"tiếng Việt", + "(Vietnamese)", + "Để sắp xếp lại các trang, bạn cần thay đổi kiểu xem sang dạng lưới tùy chỉnh."}, + {"漢語", + "(Chinese)", + "若要重新排列页面,您需要将视图类型更改为可自定义网格。"}, + {"ꦧꦱꦗꦮ, basa Jawa", + "(Javanese)", + "ꦧꦱꦗꦮ ꦕꦫꦗꦮ ꦲꦏ꧀ꦱꦫꦗꦮ ꦲꦤꦕꦫꦏ ꧋ꦱꦧꦼꦤ꧀ꦲꦸꦮꦺꦴꦁꦏꦭꦲꦶꦫꦏꦺꦏꦤ꧀ꦛꦶꦩꦂꦢꦶꦏꦭꦤ꧀ꦢꦂꦧꦺꦩꦂꦠꦧꦠ꧀ꦭꦤ꧀ꦲꦏ꧀ꦲꦏ꧀ꦏꦁꦥꦝ꧉"}, + {"Basa Sunda, ᮘᮞ ᮞᮥᮔ᮪ᮓ", + "(Sundanese)", + "ᮃᮊ᮪ᮞᮛ ᮞᮥᮔ᮪ᮓ ᮀᮁᮂᮃᮄᮅᮆᮇᮈᮉᮊᮋᮌᮍᮎᮏᮐᮑᮒᮓᮔᮕᮖᮗᮘᮙᮚᮛᮜᮝᮞᮟᮠᮡᮢᮣᮤᮥᮦᮧᮨᮩ᮪᮫ᮬᮭᮮᮯ᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹ᮺᮻᮼᮽᮾᮿ᳀᳁᳂᳃᳄᳅᳆᳇"}, + {"isiZulu", + "(Zulu)", + "Sawubona Mhlaba"}, + {"isiXhosa", + "(Xhosa)", + "Molo Lizwe"}, + {"አማርኛ", + "(Amharic)", + "ያስገቡት PIN ትክክለኛ አይደለም። እባክዎ እንደገና ይሞክሩ።"}, + {"ᱚᱞ ᱪᱤᱠᱤ", + "(Ol Chiki)", + "ᱥᱟᱱᱛᱟᱞᱤ ᱵᱟᱝᱞᱟᱫᱮᱥ ᱵᱷᱩᱴᱟᱱ ᱱᱮᱯᱟᱲ"}, + {"ꯃꯤꯇꯩ ꯃꯌꯦꯛ", + "(Meitei)", + "ꯅꯡ ꯀꯗꯥꯏꯗꯒꯤꯅꯣ ꯁꯣꯝꯒ ꯎꯟꯅꯖꯕ ꯁꯦ ꯌꯥꯝ ꯅꯨꯉꯥꯏꯖꯩ ꯎꯗꯕ ꯀꯨꯏꯔꯦ"}}; - const unsigned int NUMBER_OF_LANGUAGES = 38u; +const unsigned int NUMBER_OF_LANGUAGES = 38u; -} // MultiLanguageStrings +} // namespace MultiLanguageStrings #endif // DALI_DEMO_MULTI_LANGUAGE_STRINGS_H diff --git a/shared/utility.h b/shared/utility.h index 8295b23..71d7a55 100644 --- a/shared/utility.h +++ b/shared/utility.h @@ -19,35 +19,34 @@ */ #include +#include +#include #include #include -#include -#include namespace DemoHelper { - -Dali::Texture LoadTexture( const char* imagePath, - Dali::ImageDimensions size = Dali::ImageDimensions(), - Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT, - Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT, - bool orientationCorrection = true ) +Dali::Texture LoadTexture(const char* imagePath, + Dali::ImageDimensions size = Dali::ImageDimensions(), + Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT, + Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT, + bool orientationCorrection = true) { - Dali::Devel::PixelBuffer pixelBuffer = LoadImageFromFile(imagePath, size, fittingMode, samplingMode, orientationCorrection ); - Dali::Texture texture = Dali::Texture::New( Dali::TextureType::TEXTURE_2D, - pixelBuffer.GetPixelFormat(), - pixelBuffer.GetWidth(), - pixelBuffer.GetHeight() ); + Dali::Devel::PixelBuffer pixelBuffer = LoadImageFromFile(imagePath, size, fittingMode, samplingMode, orientationCorrection); + Dali::Texture texture = Dali::Texture::New(Dali::TextureType::TEXTURE_2D, + pixelBuffer.GetPixelFormat(), + pixelBuffer.GetWidth(), + pixelBuffer.GetHeight()); Dali::PixelData pixelData = Dali::Devel::PixelBuffer::Convert(pixelBuffer); - texture.Upload( pixelData ); + texture.Upload(pixelData); return texture; } -Dali::Texture LoadWindowFillingTexture( Dali::Uint16Pair size, const char* imagePath ) +Dali::Texture LoadWindowFillingTexture(Dali::Uint16Pair size, const char* imagePath) { - return LoadTexture( imagePath, size, Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); + return LoadTexture(imagePath, size, Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR); } Dali::Geometry CreateTexturedQuad() @@ -58,27 +57,27 @@ Dali::Geometry CreateTexturedQuad() Dali::Vector2 texCoord; }; - static const Vertex data[] = {{ Dali::Vector2( -0.5f, -0.5f ), Dali::Vector2( 0.0f, 0.0f ) }, - { Dali::Vector2( 0.5f, -0.5f ), Dali::Vector2( 1.0f, 0.0f ) }, - { Dali::Vector2( -0.5f, 0.5f ), Dali::Vector2( 0.0f, 1.0f ) }, - { Dali::Vector2( 0.5f, 0.5f ), Dali::Vector2( 1.0f, 1.0f ) }}; + static const Vertex data[] = {{Dali::Vector2(-0.5f, -0.5f), Dali::Vector2(0.0f, 0.0f)}, + {Dali::Vector2(0.5f, -0.5f), Dali::Vector2(1.0f, 0.0f)}, + {Dali::Vector2(-0.5f, 0.5f), Dali::Vector2(0.0f, 1.0f)}, + {Dali::Vector2(0.5f, 0.5f), Dali::Vector2(1.0f, 1.0f)}}; - Dali::VertexBuffer vertexBuffer; + Dali::VertexBuffer vertexBuffer; Dali::Property::Map vertexFormat; vertexFormat["aPosition"] = Dali::Property::VECTOR2; vertexFormat["aTexCoord"] = Dali::Property::VECTOR2; //Create a vertex buffer for vertex positions and texture coordinates - vertexBuffer = Dali::VertexBuffer::New( vertexFormat ); - vertexBuffer.SetData( data, 4u ); + vertexBuffer = Dali::VertexBuffer::New(vertexFormat); + vertexBuffer.SetData(data, 4u); //Create the geometry Dali::Geometry geometry = Dali::Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType(Dali::Geometry::TRIANGLE_STRIP ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Dali::Geometry::TRIANGLE_STRIP); return geometry; } -} // DemoHelper +} // namespace DemoHelper #endif // DALI_DEMO_UTILITY_H diff --git a/shared/view.h b/shared/view.h index 08342be..36f42bd 100644 --- a/shared/view.h +++ b/shared/view.h @@ -21,21 +21,20 @@ #include #include - namespace DemoHelper { - /** * Provide a style for the view and its tool bar. */ struct ViewStyle { - ViewStyle( float toolBarButtonPercentage, float toolBarTitlePercentage, float toolBarHeight, float toolBarPadding ) - : mToolBarButtonPercentage( toolBarButtonPercentage ), - mToolBarTitlePercentage( toolBarTitlePercentage ), - mToolBarHeight( toolBarHeight ), - mToolBarPadding( toolBarPadding ) - {} + ViewStyle(float toolBarButtonPercentage, float toolBarTitlePercentage, float toolBarHeight, float toolBarPadding) + : mToolBarButtonPercentage(toolBarButtonPercentage), + mToolBarTitlePercentage(toolBarTitlePercentage), + mToolBarHeight(toolBarHeight), + mToolBarPadding(toolBarPadding) + { + } float mToolBarButtonPercentage; ///< The tool bar button width is a percentage of the tool bar width. float mToolBarTitlePercentage; ///< The tool bar title width is a percentage of the tool bar width. @@ -43,122 +42,122 @@ struct ViewStyle float mToolBarPadding; ///< The tool bar padding (in pixels).. }; -const ViewStyle DEFAULT_VIEW_STYLE( 0.1f, 0.7f, 80.f, 4.f ); +const ViewStyle DEFAULT_VIEW_STYLE(0.1f, 0.7f, 80.f, 4.f); -const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue"); -const float DEFAULT_TEXT_STYLE_POINT_SIZE( 8.0f ); +const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue"); +const float DEFAULT_TEXT_STYLE_POINT_SIZE(8.0f); const Dali::Toolkit::Alignment::Padding DEFAULT_PLAY_PADDING(12.0f, 12.0f, 12.0f, 12.0f); const Dali::Toolkit::Alignment::Padding DEFAULT_MODE_SWITCH_PADDING(8.0f, 8.0f, 8.0f, 8.0f); -Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, - const std::string& toolbarImagePath, - const std::string& title, - const ViewStyle& style ) +Dali::Layer CreateToolbar(Dali::Toolkit::ToolBar& toolBar, + const std::string& toolbarImagePath, + const std::string& title, + const ViewStyle& style) { Dali::Layer toolBarLayer = Dali::Layer::New(); - toolBarLayer.SetProperty( Dali::Actor::Property::NAME, "TOOLBAR_LAYER" ); - toolBarLayer.SetProperty( Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::TOP_CENTER ); - toolBarLayer.SetProperty( Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::TOP_CENTER ); - toolBarLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::WIDTH ); - toolBarLayer.SetProperty( Dali::Actor::Property::SIZE, Dali::Vector2( 0.0f, style.mToolBarHeight ) ); + toolBarLayer.SetProperty(Dali::Actor::Property::NAME, "TOOLBAR_LAYER"); + toolBarLayer.SetProperty(Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::TOP_CENTER); + toolBarLayer.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::TOP_CENTER); + toolBarLayer.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::WIDTH); + toolBarLayer.SetProperty(Dali::Actor::Property::SIZE, Dali::Vector2(0.0f, style.mToolBarHeight)); // Raise tool bar layer to the top. toolBarLayer.RaiseToTop(); // Tool bar toolBar = Dali::Toolkit::ToolBar::New(); - toolBar.SetProperty( Dali::Actor::Property::NAME, "TOOLBAR" ); + toolBar.SetProperty(Dali::Actor::Property::NAME, "TOOLBAR"); Dali::Property::Map background; background["url"] = toolbarImagePath; - toolBar.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, background ); - toolBar.SetProperty( Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::TOP_CENTER ); - toolBar.SetProperty( Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::TOP_CENTER ); - toolBar.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); + toolBar.SetProperty(Dali::Toolkit::Control::Property::BACKGROUND, background); + toolBar.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::TOP_CENTER); + toolBar.SetProperty(Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::TOP_CENTER); + toolBar.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); // Add the tool bar to the tool bar layer. - toolBarLayer.Add( toolBar ); + toolBarLayer.Add(toolBar); // Tool bar text. - if( !title.empty() ) + if(!title.empty()) { Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New(); - label.SetProperty( Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::TOP_LEFT ); - label.SetStyleName( "ToolbarLabel" ); - label.SetProperty( Dali::Toolkit::TextLabel::Property::TEXT, title ); - label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT ); + label.SetProperty(Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::TOP_LEFT); + label.SetStyleName("ToolbarLabel"); + label.SetProperty(Dali::Toolkit::TextLabel::Property::TEXT, title); + label.SetProperty(Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + label.SetProperty(Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + label.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT); // Add title to the tool bar. - const float padding( style.mToolBarPadding ); - toolBar.AddControl( label, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HORIZONTAL_CENTER, Dali::Toolkit::Alignment::Padding( padding, padding, padding, padding ) ); + const float padding(style.mToolBarPadding); + toolBar.AddControl(label, style.mToolBarTitlePercentage, Dali::Toolkit::Alignment::HORIZONTAL_CENTER, Dali::Toolkit::Alignment::Padding(padding, padding, padding, padding)); } return toolBarLayer; } -Dali::Layer CreateView( Dali::Application& application, - Dali::Toolkit::Control& view, - Dali::Toolkit::ToolBar& toolBar, - const std::string& backgroundImagePath, - const std::string& toolbarImagePath, - const std::string& title, - const ViewStyle& style = DEFAULT_VIEW_STYLE ) +Dali::Layer CreateView(Dali::Application& application, + Dali::Toolkit::Control& view, + Dali::Toolkit::ToolBar& toolBar, + const std::string& backgroundImagePath, + const std::string& toolbarImagePath, + const std::string& title, + const ViewStyle& style = DEFAULT_VIEW_STYLE) { Dali::Window window = application.GetWindow(); // Create default View. view = Dali::Toolkit::Control::New(); - view.SetProperty( Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - view.SetProperty( Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - view.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); + view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + view.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); // Add the view to the window before setting the background. - window.Add( view ); + window.Add(view); // Set background image, loading it at screen resolution: - if ( !backgroundImagePath.empty() ) + if(!backgroundImagePath.empty()) { Dali::Property::Map map; - map[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE; - map[Dali::Toolkit::ImageVisual::Property::URL] = backgroundImagePath; - map[Dali::Toolkit::ImageVisual::Property::DESIRED_WIDTH] = window.GetSize().GetWidth(); - map[Dali::Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = window.GetSize().GetHeight(); - map[Dali::Toolkit::ImageVisual::Property::FITTING_MODE] = Dali::FittingMode::SCALE_TO_FILL; - map[Dali::Toolkit::ImageVisual::Property::SAMPLING_MODE] = Dali::SamplingMode::BOX_THEN_LINEAR; + map[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE; + map[Dali::Toolkit::ImageVisual::Property::URL] = backgroundImagePath; + map[Dali::Toolkit::ImageVisual::Property::DESIRED_WIDTH] = window.GetSize().GetWidth(); + map[Dali::Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = window.GetSize().GetHeight(); + map[Dali::Toolkit::ImageVisual::Property::FITTING_MODE] = Dali::FittingMode::SCALE_TO_FILL; + map[Dali::Toolkit::ImageVisual::Property::SAMPLING_MODE] = Dali::SamplingMode::BOX_THEN_LINEAR; map[Dali::Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = true; - view.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map ); + view.SetProperty(Dali::Toolkit::Control::Property::BACKGROUND, map); } // Create default ToolBar - Dali::Layer toolBarLayer = CreateToolbar( toolBar, toolbarImagePath, title, style ); + Dali::Layer toolBarLayer = CreateToolbar(toolBar, toolbarImagePath, title, style); // Add tool bar layer to the view. - view.Add( toolBarLayer ); + view.Add(toolBarLayer); // Create a content layer. Dali::Layer contentLayer = Dali::Layer::New(); - contentLayer.SetProperty( Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - contentLayer.SetProperty( Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - contentLayer.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); - view.Add( contentLayer ); - contentLayer.LowerBelow( toolBarLayer ); + contentLayer.SetProperty(Dali::Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + contentLayer.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + contentLayer.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); + view.Add(contentLayer); + contentLayer.LowerBelow(toolBarLayer); return contentLayer; } -Dali::Toolkit::TextLabel CreateToolBarLabel( const std::string& text ) +Dali::Toolkit::TextLabel CreateToolBarLabel(const std::string& text) { - Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New( text ); - label.SetStyleName( "ToolbarLabel" ); - label.SetProperty( Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); - label.SetProperty( Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); - label.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT ); + Dali::Toolkit::TextLabel label = Dali::Toolkit::TextLabel::New(text); + label.SetStyleName("ToolbarLabel"); + label.SetProperty(Dali::Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + label.SetProperty(Dali::Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER"); + label.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT); return label; } -} // DemoHelper +} // namespace DemoHelper #endif // DALI_DEMO_HELPER_VIEW_H diff --git a/tests-reel/dali-tests-reel.cpp b/tests-reel/dali-tests-reel.cpp index 7abe064..0cf9935 100644 --- a/tests-reel/dali-tests-reel.cpp +++ b/tests-reel/dali-tests-reel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,12 @@ #include // INTERNAL INCLUDES -#include "shared/dali-table-view.h" #include "shared/dali-demo-strings.h" +#include "shared/dali-table-view.h" using namespace Dali; -int DALI_EXPORT_API main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char** argv) { // Configure gettext for internalization #if INTERNATIONALIZATION_ENABLED @@ -32,7 +32,7 @@ int DALI_EXPORT_API main(int argc, char **argv) textdomain(DALI_DEMO_DOMAIN_LOCAL); setlocale(LC_ALL, DEMO_LANG); #endif - Application app = Application::New( &argc, &argv, DEMO_STYLE_DIR "/tests-theme.json" ); + Application app = Application::New(&argc, &argv, DEMO_STYLE_DIR "/tests-theme.json"); // Create the demo launcher DaliTableView demo(app); @@ -57,7 +57,7 @@ int DALI_EXPORT_API main(int argc, char **argv) demo.AddExample(Example("simple-text-visual.example", DALI_DEMO_STR_TITLE_TEXT_VISUAL)); demo.AddExample(Example("simple-bitmap-font-text-label.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_BITMAP_FONT)); - demo.SortAlphabetically( true ); + demo.SortAlphabetically(true); // Start the event loop app.MainLoop(); -- 2.7.4