From 2cf3c424846a9260c8c0cde8a9d054e23909bf97 Mon Sep 17 00:00:00 2001 From: Lee Morgan Date: Tue, 15 Jul 2014 16:58:56 +0100 Subject: [PATCH] added builder demo Change-Id: I0818d9afbe73108005b04f1f046fc41284b07442 Signed-off-by: Lee Morgan --- .gitignore | 1 + build/tizen/demo/Makefile.am | 9 + build/tizen/examples/Makefile.am | 17 +- demo/dali-demo.cpp | 1 + demo/file.list | 3 + demo/scripts/animation.json | 99 ++++++ demo/scripts/background-color.json | 65 ++++ demo/scripts/button.json | 120 +++++++ demo/scripts/formatted-text.json | 51 +++ demo/scripts/hello-world.json | 24 ++ demo/scripts/navigation.json | 79 +++++ demo/scripts/slider-test-style.json | 39 +++ demo/scripts/slider.json | 131 ++++++++ demo/scripts/super-blur-view.json | 100 ++++++ examples/builder/dali-builder.cpp | 312 ++++++++++++++++++ examples/builder/examples.cpp | 615 ++++++++++++++++++++++++++++++++++++ 16 files changed, 1665 insertions(+), 1 deletion(-) create mode 100644 demo/scripts/animation.json create mode 100644 demo/scripts/background-color.json create mode 100644 demo/scripts/button.json create mode 100644 demo/scripts/formatted-text.json create mode 100644 demo/scripts/hello-world.json create mode 100644 demo/scripts/navigation.json create mode 100644 demo/scripts/slider-test-style.json create mode 100644 demo/scripts/slider.json create mode 100644 demo/scripts/super-blur-view.json create mode 100644 examples/builder/dali-builder.cpp create mode 100644 examples/builder/examples.cpp diff --git a/.gitignore b/.gitignore index 44e674b..2168e3c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ BROWSE *.fodt *.test *.example +dali-builder *.a *.apk *.ap_ diff --git a/build/tizen/demo/Makefile.am b/build/tizen/demo/Makefile.am index dc0abe5..a1713fe 100644 --- a/build/tizen/demo/Makefile.am +++ b/build/tizen/demo/Makefile.am @@ -25,8 +25,17 @@ dalidemoimages_DATA = $(demo_image_files) dalidemomodelsdir = $(appdatadir)/models/ dalidemomodels_DATA = $(demo_model_files) +dalidemoshadersdir = $(appdatadir)/shaders/ +dalidemoshaders_DATA = $(demo_shader_files) + +dalidemoscriptsdir = $(appdatadir)/scripts/ +dalidemoscripts_DATA = $(demo_script_files) + + DEMO_CXXFLAGS = -DDALI_IMAGE_DIR="\"$(dalidemoimagesdir)\"" \ -DDALI_MODEL_DIR="\"$(dalidemomodelsdir)\"" \ + -DDALI_SCRIPT_DIR="\"$(dalidemoscriptsdir)\"" \ + -DDALI_SHADER_DIR="\"$(dalidemoshadersdir)\"" \ -DDALI_EXAMPLE_BIN="\"$(exedir)\"" \ -I../../../demo -I../../.. \ $(DALIDEMO_CFLAGS) \ diff --git a/build/tizen/examples/Makefile.am b/build/tizen/examples/Makefile.am index a5fc698..cdae333 100644 --- a/build/tizen/examples/Makefile.am +++ b/build/tizen/examples/Makefile.am @@ -29,14 +29,19 @@ bin_PROGRAMS = \ page-turn-view.example \ radial-menu.example \ scroll-view.example \ - shadow-bone-lighting.example + shadow-bone-lighting.example \ + dali-builder \ + builder.example + daliimagedir = $(appdatadir)/images/ dalimodeldir = $(appdatadir)/models/ +daliscriptdir = $(appdatadir)/scripts/ BASE_CXXFLAGS = -I../../../examples \ -DDALI_IMAGE_DIR="\"${daliimagedir}\"" \ -DDALI_MODEL_DIR="\"${dalimodeldir}\"" \ + -DDALI_SCRIPT_DIR="\"${daliscriptdir}\"" \ $(DALIDEMO_CFLAGS) \ $(ECORE_X_CFLAGS) \ $(CAPI_MEDIA_PLAYER_CFLAGS) \ @@ -125,3 +130,13 @@ shadow_bone_lighting_example_SOURCES = $(examples_src_dir)/shadows/shadow-bone-l shadow_bone_lighting_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) shadow_bone_lighting_example_DEPENDENCIES = $(EXAMPLE_DEPS) shadow_bone_lighting_example_LDADD = $(EXAMPLE_LDADD) + +dali_builder_SOURCES = $(examples_src_dir)/builder/dali-builder.cpp +dali_builder_CXXFLAGS = $(EXAMPLE_CXXFLAGS) +dali_builder_DEPENDENCIES = $(EXAMPLE_DEPS) +dali_builder_LDADD = $(EXAMPLE_LDADD) + +builder_example_SOURCES = $(examples_src_dir)/builder/examples.cpp +builder_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) +builder_example_DEPENDENCIES = $(EXAMPLE_DEPS) +builder_example_LDADD = $(EXAMPLE_LDADD) diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index fa43081..0dfc11c 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -38,6 +38,7 @@ int main(int argc, char **argv) demo.AddExample(Example("radial-menu.example", "Radial Menu")); demo.AddExample(Example("scroll-view.example", "Scroll View")); demo.AddExample(Example("shadow-bone-lighting.example", "Lights and shadows")); + demo.AddExample(Example("builder.example", "Script Based UI")); app.MainLoop(); return 0; diff --git a/demo/file.list b/demo/file.list index 2c9f10f..e661847 100644 --- a/demo/file.list +++ b/demo/file.list @@ -15,3 +15,6 @@ demo_image_files = \ demo_model_files = \ $(demo_src_dir)/models/* + +demo_script_files = \ + $(demo_src_dir)/scripts/* diff --git a/demo/scripts/animation.json b/demo/scripts/animation.json new file mode 100644 index 0000000..906648c --- /dev/null +++ b/demo/scripts/animation.json @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + // library of styles + "styles": { + "red-theme": { + "color": [1, 0, 0, 1] + }, + "basic-text": { + "parent-origin": "CENTER" + } + }, + // library of animations + "animations": { + "animate": { + "duration": 10.0, + "properties": [{ + "actor": "greeting", // referenced actors must exist on stage + "property": "position", + "value": [300, 300, -1000], + "alpha-function": "EASE_IN_OUT", + "time-period": { + "delay": 0, + "duration": 3 + } + }, { + "actor": "greeting", // referenced actors must exist on stage + "property": "scale", + "value": [5, 5, 1], + "time-period": { + "delay": 2, + "duration": 3 + } + }] + }, + "rotate": { + "duration": 10.0, + "properties": [{ + "actor": "image", // referenced actors must exist on stage + "property": "rotation", + "value": [0, 0, -45], + "alpha-function": "EASE_IN_OUT", + "time-period": { + "delay": 0, + "duration": 3 + } + }] + } + }, + // a tree of actors + "stage": [{ + "name": "greeting", + "type": "TextView", + "text": "Touch me", + "styles": ["basic-text"], + "position": [0, -120, 0], + "size": [200, 200, 1], + "rotation": [0, 0, 30], + "signals": [{ + "name": "touched", + "action": "play", + "animation": "animate" + }] + }, { + "type": "TextView", // styles can be additive + "parent-origin": "CENTER", + "anchor-point": "CENTER", + "size": [200, 200, 1], + "text": "or the image.." + }, { + "name": "image", + "type": "ImageActor", + "image": { + "filename": "{DALI_IMAGE_DIR}gallery-large-21.jpg" + }, + "position": [0, 200, 0], + "size": [200, 200, 1], + "signals": [{ + "name": "touched", + "action": "play", + "animation": "rotate" + }], + "position-inheritance": "DONT_INHERIT_POSITION" + }] +} diff --git a/demo/scripts/background-color.json b/demo/scripts/background-color.json new file mode 100644 index 0000000..d8d97b8 --- /dev/null +++ b/demo/scripts/background-color.json @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + "stage": [ + // A TextView with a red background + { + "type": "TextView", + "text": "Hello World", + "parent-origin": "TOP_CENTER", + "anchor-point": "TOP_CENTER", + "background-color": [1, 0, 0, 1], + "size": [400, 150, 1] + }, + + // A container with a yellow background + { + "type": "Control", + "parent-origin": "CENTER", + "anchor-point": "BOTTOM_CENTER", + "background-color": [1, 1, 0, 1], + "size": [400, 150, 1] + }, + + // A container with an image + { + "type": "Control", + "parent-origin": "CENTER", + "anchor-point": "TOP_CENTER", + "size": [400, 150, 1], + "background": { + "image": { + "filename": "{DALI_IMAGE_DIR}button-background.png" + } + } + }, + + // A container with the same image blended in with a blue background + { + "type": "Control", + "parent-origin": "BOTTOM_CENTER", + "anchor-point": "BOTTOM_CENTER", + "size": [400, 150, 1], + "background-color": [0, 0, 1, 1], + "background": { + "image": { + "filename": "{DALI_IMAGE_DIR}button-background.png" + } + } + } + ] +} diff --git a/demo/scripts/button.json b/demo/scripts/button.json new file mode 100644 index 0000000..4a010cd --- /dev/null +++ b/demo/scripts/button.json @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + "constants": { + "CONFIG_SCRIPT_LOG_LEVEL": "Verbose" + }, + "stage": [ + // First Button + { + "type": "PushButton", + "parent-origin": "TOP_CENTER", + "anchor-point": "TOP_CENTER", + "position": [0, 0, 0], + "size": [0, 200, 0], + "normal-state-actor": { + "type": "ImageActor", + "image": { + "filename": "{DALI_IMAGE_DIR}blocks-brick-1.png" + } + }, + "pressed-state-actor": { + "type": "ImageActor", + "image": { + "filename": "{DALI_IMAGE_DIR}blocks-brick-2.png" + } + }, + "label-actor": { + "type": "TextView", + "text": "Normal" + } + }, + + // Second Button + { + "type": "PushButton", + "parent-origin": "CENTER", + "anchor-point": "CENTER", + "position": [0, 0, 0], + "size": [0, 200, 0], + "label-actor": { + "type": "TextView", + "text": "Dimmed" + }, + "dimmed": true, + "normal-state-actor": { + "type": "ImageActor", + "image": { + "filename": "{DALI_IMAGE_DIR}blocks-brick-1.png" + } + }, + "pressed-state-actor": { + "type": "ImageActor", + "image": { + "filename": "{DALI_IMAGE_DIR}blocks-brick-2.png" + } + }, + "dimmed-state-actor": { + "type": "ImageActor", + "image": { + "filename": "{DALI_IMAGE_DIR}blocks-brick-3.png" + } + } + }, + + // Third Button + { + "type": "PushButton", + "name": "toggle-button", + "parent-origin": "BOTTOM_CENTER", + "anchor-point": "BOTTOM_CENTER", + "position": [0, 0, 0], + "size": [0, 200, 0], + "label-actor": { + "type": "TextView", + "text": "Toggle" + }, + "togglable": true, + "normal-state-actor": { + "type": "ImageActor", + "style": "STYLE_NINE_PATCH", + "border": [26, 24, 26, 23], + "image": { + "filename": "{DALI_IMAGE_DIR}blocks-brick-1.png" + } + }, + "pressed-state-actor": { + "type": "ImageActor", + "style": "STYLE_NINE_PATCH", + "border": [26, 24, 26, 23], + "image": { + "filename": "{DALI_IMAGE_DIR}blocks-paddle.png" + } + }, + "signals": [{ + "name": "toggled", + "action": "set", + "actor": "toggle-button", + "property": "label-actor", + "value": { + "type": "TextView", + "text": "Using a 9-patch image" + } + }] + } + ] +} diff --git a/demo/scripts/formatted-text.json b/demo/scripts/formatted-text.json new file mode 100644 index 0000000..82dac7c --- /dev/null +++ b/demo/scripts/formatted-text.json @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + // a tree of actors + "stage": [{ + "type": "Actor", + "size": [400, 400, 1], + "parent-origin": "CENTER", + "actors": [{ + "type": "TextView", + "size": [400, 400, 1], + "text": "", + "markup-enabled": true, + "multiline-policy": "SplitByNewLineChar", + "horizontal-alignment": "HorizontalCenter", + "vertical-alignment": "VerticalBottom", + "width-exceed-policy": "Fade", + "line-justification": "Center", + "fade-boundary": [50, 50, 0, 0], + "line-height-offset": 25.0, + "parent-origin": "TOP_CENTER" + }, { + "type": "TextView", + "size": [400, 400, 1], + "text": "Text with\n'markup-enabled':false", + "markup-enabled": false, + "multiline-policy": "SplitByWord", + "horizontal-alignment": "HorizontalLeft", + "vertical-alignment": "VerticalTop", + "width-exceed-policy": "ShrinkToFit", + "height-exceed-policy": "Original", + "line-justification": "Right", + "line-height-offset": 5.0, + "parent-origin": "BOTTOM_CENTER" + }] + }] +} diff --git a/demo/scripts/hello-world.json b/demo/scripts/hello-world.json new file mode 100644 index 0000000..abbeb5e --- /dev/null +++ b/demo/scripts/hello-world.json @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + // a tree of actors + "stage": [{ + "type": "TextView", + "text": "Hello World", + "parent-origin": "CENTER" + }] +} diff --git a/demo/scripts/navigation.json b/demo/scripts/navigation.json new file mode 100644 index 0000000..f54a71b --- /dev/null +++ b/demo/scripts/navigation.json @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + "stage": [{ + "type": "NavigationControl", + "name": "navigation", + "parent-origin": "CENTER", + "signals": [{ + "name": "on-stage", + "actor": "navigation", + "action": "push", + "parameters": ["page1"] + }], + "actors": [{ + "type": "Page", + "name": "page1", + "title": "title", + "sub-title": "sub title", + "actors": [{ + "type": "TextView", // styles can be additive + "parent-origin": [0.5, 0.5, 0], + "anchor-point": [0.5, 0.5, 0], + "size": [200, 200, 1], + "text": "Touch to push new item!", + "signals": [{ + "name": "touched", + "actor": "navigation", + "action": "push", + "parameters": ["page2"] + }] + }] + }, { + "type": "Page", + "name": "page2", + "actors": [{ + "type": "TextView", // styles can be additive + "parent-origin": [0.5, 0.5, 0.5], + "anchor-point": [0.5, 0.5, 0.5], + "size": [200, 200, 1], + "text": "Hello World!" + }, { + "type": "TextView", // styles can be additive + "parent-origin": [0.0, 0.0, 0.5], + "anchor-point": [0.0, 0.0, 0.5], + "size": [200, 200, 1], + "text": "Back", + "signals": [{ + "name": "touched", + "actor": "navigation", + "action": "pop" + }] + }, { + "type": "TextView", // styles can be additive + "parent-origin": [1.0, 1.0, 0.5], + "anchor-point": [1.0, 1.0, 0.5], + "size": [200, 200, 1], + "text": "Quit", + "signals": [{ + "name": "touched", + "action": "quit" + }] + }] + }] + }] +} diff --git a/demo/scripts/slider-test-style.json b/demo/scripts/slider-test-style.json new file mode 100644 index 0000000..e08ceb0 --- /dev/null +++ b/demo/scripts/slider-test-style.json @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014 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. + * + */ +//****************************************************************************** +// +// Default style theme for Tizen Light theme, The values should come from +// UX design document. +// +//****************************************************************************** +{ + "styles": { + "slider": { + "anchor-point": [0.5, 0.0, 0.0], + "parent-origin": [0.5, 0.0, 0.0], + "position": [0, 300, 0], + "size": [480, 72, 1], + "lower-bound": 0, + "upper-bound": 10, + "show-popup": true, + "show-value": true, + "value-precision": 2, + "value": 0.0, + "popup-text-color": [0.0, 1.0, 1.0, 1.0] + } + } +} diff --git a/demo/scripts/slider.json b/demo/scripts/slider.json new file mode 100644 index 0000000..8d4a4a7 --- /dev/null +++ b/demo/scripts/slider.json @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + "stage": [{ + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 144, 0], + "size": [480, 72, 1], + "lower-bound": 0, + "upper-bound": 1, + "show-popup": true, + "show-value": true, + "value-precision": 2, + "value": 0.0 + }, { + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 224, 0], + "size": [300, 72, 1], + "lower-bound": 1, + "upper-bound": 10, + "show-popup": false, + "show-value": true, + "value-precision": 0, + "value": 5.0 + }, { + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 304, 0], + "size": [300, 72, 1], + "lower-bound": 0, + "upper-bound": 5, + "show-popup": false, + "show-value": false, + "value": 0.0, + "mark-tolerance": 0.1, + "marks": [0, 1, 2, 3, 4, 5] + }, { + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 384, 0], + "size": [480, 72, 1], + "lower-bound": 0, + "upper-bound": 5, + "show-popup": false, + "show-value": false, + "value": 0.0, + "mark-tolerance": 0.1, + "snap-to-marks": true, + "marks": [0, 1, 2, 3, 4, 5] + }, { + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 464, 0], + "size": [480, 72, 1], + "lower-bound": 5, + "upper-bound": 100, + "show-popup": true, + "show-value": true, + "value-precision": 0, + "value": 50.0, + "popup-text-color": [1, 0, 0, 1], + "hit-region": [0, 48], + "backing-region": [0, 10], + "handle-region": [48, 48] + }, { + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 544, 0], + "size": [480, 72, 1], + "lower-bound": 10, + "upper-bound": 100, + "show-popup": true, + "show-value": true, + "value-prescision": 0, + "value": 100.0, + "hit-region": [0, 48], + "backing-region": [0, 10], + "handle-region": [48, 48], + "backing-image-name": "{DALI_IMAGE_DIR}circle_point_32x32.png", + "handle-image-name": "{DALI_IMAGE_DIR}circle_point_shadow_32x32.png", + "progress-image-name": "{DALI_IMAGE_DIR}circle_point.png", + "backing-scale9-border": [16, 0, 16, 0], + "progress-scale9-border": [16, 0, 16, 0] + }, { + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 624, 0], + "size": [480, 72, 1], + "lower-bound": 10, + "upper-bound": 100, + "show-popup": true, + "show-value": true, + "value-precision": 0, + "value": 50.0, + "hit-region": [0, 48], + "backing-region": [0, 10], + "handle-region": [48, 48], + "enabled": false + }, { + "type": "Slider", + "parent-origin": "TOP_CENTER", + "position": [0, 704, 0], + "size": [480, 72, 1], + "lower-bound": 10, + "upper-bound": 100, + "show-popup": true, + "show-value": true, + "value-precision": 0, + "value": 50.0, + "hit-region": [0, 48], + "backing-region": [0, 10], + "handle-region": [48, 48], + "enabled": false, + "disable-color": [1, 0, 0, 1] + }] +} diff --git a/demo/scripts/super-blur-view.json b/demo/scripts/super-blur-view.json new file mode 100644 index 0000000..873af00 --- /dev/null +++ b/demo/scripts/super-blur-view.json @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2014 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. + * + */ +{ + "constants": { + "TEXT_VIEW_SIZE": [200, 150, 1] + }, + "animations": { + "blur": { + "duration": 1, + "properties": [{ + "actor": "super-blur", + "property": "blur-strength", + "value": 1, + "time-period": { + "delay": 0, + "duration": 1 + } + }] + }, + "clear": { + "duration": 1, + "properties": [{ + "actor": "super-blur", + "property": "blur-strength", + "value": 0, + "time-period": { + "delay": 0, + "duration": 1 + } + }] + } + }, + "stage": [ + // SuperBlurView + { + "type": "SuperBlurView", + "name": "super-blur", + "parent-origin": "TOP_CENTER", + "anchor-point": "TOP_CENTER", + "position": [0, 10, 0], + "size": [460, 600, 0], + "image": { + "filename": "{DALI_IMAGE_DIR}background-4.jpg" + } + }, + + // Button to blur/clear + { + "type": "PushButton", + "name": "toggle-button", + "parent-origin": "BOTTOM_CENTER", + "anchor-point": "BOTTOM_CENTER", + "position": [0, 0, 0], + "size": [0, 100, 0], + "label-actor": { + "type": "TextView", + "text": "Blur" + }, + "normal-state-actor": { + "type": "ImageActor", + "style": "STYLE_NINE_PATCH", + "border": [26, 24, 26, 23], + "image": { + "filename": "{DALI_IMAGE_DIR}button-background.png" + } + }, + "pressed-state-actor": { + "type": "ImageActor", + "style": "STYLE_NINE_PATCH", + "border": [26, 24, 26, 23], + "image": { + "filename": "{DALI_IMAGE_DIR}button-background.png" + } + }, + "signals": [{ + "name": "pressed", + "action": "play", + "animation": "blur" + }, { + "name": "released", + "action": "play", + "animation": "clear" + }] + } + ] +} diff --git a/examples/builder/dali-builder.cpp b/examples/builder/dali-builder.cpp new file mode 100644 index 0000000..29f5134 --- /dev/null +++ b/examples/builder/dali-builder.cpp @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2014 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. + * + */ +//------------------------------------------------------------------------------ +// +// Run a json script layout file +// +// - watches an named file and reloads actor tree if the file changes +// ie run +// builder-run layout.json +// +// and edit layout.json in a text editor saving to trigger the reload +// +//------------------------------------------------------------------------------ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include +#include "sys/stat.h" +#include + +#include + +#define TOKEN_STRING(x) #x + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace +{ + +std::string JSON_BROKEN(" \ +{ \ + 'stage': \ + [ \ + { \ + 'type':'TextActor', \ + 'size': [50,50,1], \ + 'parent-origin': 'CENTER', \ + 'text':'COULD NOT LOAD JSON FILE' \ + } \ + ] \ +} \ +"); + +std::string ReplaceQuotes(const std::string &single_quoted) +{ + std::string s(single_quoted); + + // wrong as no embedded quote but had regex link problems + std::replace(s.begin(), s.end(), '\'', '"'); + + return s; +} + +} // anon namespace + + +//------------------------------------------------------------------------------ +// +// +// +//------------------------------------------------------------------------------ +class FileWatcher +{ +public: + FileWatcher(void); + ~FileWatcher(void); + explicit FileWatcher(const std::string &fn) { SetFilename(fn) ; }; + + void SetFilename(const std::string &fn); + std::string GetFilename(); + + bool FileHasChanged(void); + std::string GetFileContents(void) { return GetFileContents(mstringPath) ; }; + +private: + // compiler does + // FileWatcher(const FileWatcher&); + // FileWatcher &operator=(const FileWatcher &); + + std::time_t mLastTime; + std::string mstringPath; + + std::string GetFileContents(const std::string &fn) + { + std::ifstream t(fn.c_str()); + return std::string((std::istreambuf_iterator(t)), std::istreambuf_iterator()); + }; +}; + +FileWatcher::FileWatcher(void) : mLastTime(0) +{ +} + +bool FileWatcher::FileHasChanged(void) +{ + struct stat buf; + + if(0 != stat(mstringPath.c_str(), &buf)) + { + DALI_LOG_WARNING("File does not exist '%s'\n", mstringPath.c_str()); + return false; + } + else + { + if(buf.st_mtime > mLastTime) + { + mLastTime = buf.st_mtime; + return true; + } + else + { + mLastTime = buf.st_mtime; + return false; + } + } + + return false; +} + +FileWatcher::~FileWatcher() +{ +} + +void FileWatcher::SetFilename(const std::string &fn) +{ + mstringPath = fn; +} + +std::string FileWatcher::GetFilename(void) +{ + return mstringPath; +} + + +//------------------------------------------------------------------------------ +// +// +// +//------------------------------------------------------------------------------ +class ExampleApp : public ConnectionTracker +{ +public: + ExampleApp(Application &app) : mApp(app) + { + app.InitSignal().Connect(this, &ExampleApp::Create); + + } + + ~ExampleApp() {} + +public: + 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.Start(); + + // Connect to key events in order to exit + Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleApp::OnKeyEvent); + } + +private: + Application& mApp; + Layer mRootLayer; + + FileWatcher fw; + Timer mTimer; + + void ReloadJsonFile(Builder& builder, Layer& layer) + { + Stage stage = Stage::GetCurrent(); + + builder = Builder::New(); + + PropertyValueMap defaultDirs; + defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR; + defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ] = DALI_MODEL_DIR; + defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR; + + builder.AddConstants( defaultDirs ); + + if(!layer) + { + layer = Layer::New(); + layer.SetParentOrigin(ParentOrigin::CENTER); + layer.SetAnchorPoint(AnchorPoint::CENTER); + layer.SetSize( stage.GetRootLayer().GetCurrentSize() ); + stage.GetRootLayer().Add(layer); + + // render tasks may have been setup last load so remove them + RenderTaskList taskList = stage.GetRenderTaskList(); + if( taskList.GetTaskCount() > 1 ) + { + typedef std::vector Collection; + typedef Collection::iterator ColIter; + Collection tasks; + + for(unsigned int i = 1; i < taskList.GetTaskCount(); ++i) + { + tasks.push_back( taskList.GetTask(i) ); + } + + for(ColIter iter = tasks.begin(); iter != tasks.end(); ++iter) + { + taskList.RemoveTask(*iter); + } + + RenderTask defaultTask = taskList.GetTask(0); + defaultTask.SetSourceActor( stage.GetRootLayer() ); + defaultTask.SetTargetFrameBuffer( FrameBufferImage() ); + } + } + + unsigned int numChildren = layer.GetChildCount(); + + for(unsigned int i=0; i 1) + { + std::cout << "Loading file:" << argc << " " << argv[1] << std::endl; + app.SetJSONFilename(argv[1]); + } + else + { + DALI_ASSERT_ALWAYS(!"Specify JSON file on command line\n"); + } + + dali_app.MainLoop(); + + return 0; +} diff --git a/examples/builder/examples.cpp b/examples/builder/examples.cpp new file mode 100644 index 0000000..d3c7f05 --- /dev/null +++ b/examples/builder/examples.cpp @@ -0,0 +1,615 @@ +/* + * Copyright (c) 2014 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 "dali.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include +#include "sys/stat.h" +#include + +#include +#include "../shared/view.h" + +#define TOKEN_STRING(x) #x + +using namespace Dali; +using namespace Dali::Toolkit; + +namespace +{ + +const char* BACKGROUND_IMAGE( "" ); +const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); +const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); + +std::string USER_DIRECTORY; + +std::string JSON_BROKEN(" \ +{ \ + 'stage': \ + [ \ + { \ + 'type':'TextView', \ + 'size': [50,50,1], \ + 'parent-origin': 'CENTER', \ + 'text':'COULD NOT LOAD JSON FILE' \ + } \ + ] \ +} \ +"); + +std::string ReplaceQuotes(const std::string &single_quoted) +{ + std::string s(single_quoted); + + // wrong as no embedded quote but had regex link problems + std::replace(s.begin(), s.end(), '\'', '"'); + + return s; +} + +std::string GetFileContents(const std::string &fn) +{ + std::ifstream t(fn.c_str()); + return std::string((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); +}; + +typedef std::vector FileList; + +void DirectoryFileList(const std::string& directory, FileList& files) +{ + DIR *d; + struct dirent *dir; + d = opendir(directory.c_str()); + if (d) + { + while ((dir = readdir(d)) != NULL) + { + if (dir->d_type == DT_REG) + { + files.push_back( directory + std::string(dir->d_name) ); + } + } + + closedir(d); + } +} + +void DirectoryFilesByType(const std::string& dir, const std::string& fileType /* ie "json" */, FileList& files) +{ + typedef FileList Collection; + typedef FileList::iterator Iter; + + Collection allFiles; + DirectoryFileList(dir, allFiles); + + for(Iter iter = allFiles.begin(); iter != allFiles.end(); ++iter) + { + size_t pos = (*iter).rfind( '.' ); + if( pos != std::string::npos ) + { + if( (*iter).substr( pos+1 ) == fileType ) + { + files.push_back( (*iter) ); + } + } + } +} + +const std::string ShortName( const std::string& name ) +{ + size_t pos = name.rfind( '/' ); + + if( pos != std::string::npos ) + { + return name.substr( pos ); + } + else + { + return name; + } +} + +static Vector3 SetItemSize(unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing) +{ + return Vector3(layoutWidth, 50, 1); +} + +//------------------------------------------------------------------------------ +// +// +// +//------------------------------------------------------------------------------ +class FileWatcher +{ +public: + FileWatcher(void); + ~FileWatcher(void); + explicit FileWatcher(const std::string &fn) { SetFilename(fn) ; }; + + void SetFilename(const std::string &fn); + std::string GetFilename() const; + + bool FileHasChanged(void); + std::string GetFileContents(void) const { return ::GetFileContents(mstringPath) ; }; + +private: + // compiler does + // FileWatcher(const FileWatcher&); + // FileWatcher &operator=(const FileWatcher &); + + std::time_t mLastTime; + std::string mstringPath; + +}; + +FileWatcher::FileWatcher(void) : mLastTime(0) +{ +} + +bool FileWatcher::FileHasChanged(void) +{ + struct stat buf; + + if(0 != stat(mstringPath.c_str(), &buf)) + { + return false; + } + else + { + if(buf.st_mtime > mLastTime) + { + mLastTime = buf.st_mtime; + return true; + } + else + { + mLastTime = buf.st_mtime; + return false; + } + } + + return false; +} + +FileWatcher::~FileWatcher() +{ +} + +void FileWatcher::SetFilename(const std::string &fn) +{ + mstringPath = fn; + FileHasChanged(); // update last time +} + +std::string FileWatcher::GetFilename(void) const +{ + return mstringPath; +} + + +} // anon namespace + + +//------------------------------------------------------------------------------ +// +// +// +//------------------------------------------------------------------------------ +class ExampleApp : public ConnectionTracker, public Toolkit::ItemFactory +{ +public: + ExampleApp(Application &app) : mApp(app) + { + app.InitSignal().Connect(this, &ExampleApp::Create); + } + + ~ExampleApp() {} + +public: + + void SetTitle(const std::string& title) + { + if(!mTitleActor) + { + mTitleActor = TextView::New(); + // Add title to the tool bar. + mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); + } + + Font font = Font::New(); + mTitleActor.SetText( title ); + mTitleActor.SetSize( font.MeasureText( title ) ); + mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); + } + + bool OnToolSelectLayout( Toolkit::Button button ) + { + bool on = mItemView.IsVisible(); + + if( on ) + { + LeaveSelection(); + } + else + { + EnterSelection(); + } + + return true; + } + + void LeaveSelection() + { + + } + + void EnterSelection() + { + Stage stage = Stage::GetCurrent(); + + if( mItemView ) + { + stage.Remove( mItemView ); + } + + mFiles.clear(); + + mItemView = ItemView::New(*this); + stage.Add( mItemView ); + mItemView.SetParentOrigin(ParentOrigin::CENTER); + mItemView.SetAnchorPoint(AnchorPoint::CENTER); + mGridLayout = GridLayout::New(); + mGridLayout->SetNumberOfColumns(1); + + mGridLayout->SetItemSizeFunction(SetItemSize); + + mGridLayout->SetTopMargin(DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight); + + mItemView.AddLayout(*mGridLayout); + + Vector3 size(stage.GetSize()); + mItemView.ActivateLayout(0, size, 0.0f/*immediate*/); + mItemView.SetKeyboardFocusable( true ); + + mFiles.clear(); + FileList files; + + if( USER_DIRECTORY.size() ) + { + DirectoryFilesByType( USER_DIRECTORY, "json", files ); + } + else + { + DirectoryFilesByType( DALI_SCRIPT_DIR, "json", files ); + } + + std::sort(files.begin(), files.end()); + + ItemId itemId = 0; + for(FileList::iterator iter = files.begin(); iter != files.end(); ++iter) + { + JsonParser parser = JsonParser::New(); + + std::string data( GetFileContents( *iter ) ); + + parser.Parse( data ); + + 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( const TreeNode* node = parser.GetRoot()->Find("stage") ) + { + // only those with a stage section + if( node->Size() ) + { + mFiles.push_back( *iter ); + + mItemView.InsertItem( Item(itemId, + MenuItem( ShortName( *iter ) ) ), + 0.5f ); + + itemId++; + } + else + { + std::cout << "Ignored file (stage has no nodes?):" << *iter << std::endl; + } + } + else + { + std::cout << "Ignored file (no stage section):" << *iter << std::endl; + } + } + } + + mTapDetector = TapGestureDetector::New(); + + for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) + { + mTapDetector.Attach( mItemView.GetChildAt(i) ); + } + + mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap ); + + // Display item view on the stage + stage.Add( mItemView ); + + mItemView.SetVisible( true ); + mBuilderLayer.SetVisible( false ); + + SetTitle("Select"); + + // Itemview renderes the previous items unless its scrolled. Not sure why at the moment so we force a scroll + mItemView.ScrollToItem(0, 0); + + } + + void ExitSelection() + { + mTapDetector.Reset(); + + mItemView.SetVisible( false ); + mBuilderLayer.SetVisible( true ); + + SetTitle("View"); + } + + void OnTap( Actor actor, TapGesture tap ) + { + ItemId id = mItemView.GetItemId( actor ); + + LoadFromFileList( id ); + } + + Actor MenuItem(const std::string& text) + { + TextView t = TextView::New(); + t.SetMarkupProcessingEnabled(true); + t.SetText( std::string("") + ShortName( text ) + std::string("") ); + t.SetTextAlignment( Alignment::HorizontalLeft ); + return t; + } + + bool OnTimer() + { + if( mFileWatcher.FileHasChanged() ) + { + LoadFromFile( mFileWatcher.GetFilename() ); + } + + return true; + } + + void ReloadJsonFile(const std::string& filename, Builder& builder, Layer& layer) + { + Stage stage = Stage::GetCurrent(); + + builder = Builder::New(); + + PropertyValueMap defaultDirs; + defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR; + defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ] = DALI_MODEL_DIR; + defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR; + + builder.AddConstants( defaultDirs ); + + // render tasks may have been setup last load so remove them + RenderTaskList taskList = stage.GetRenderTaskList(); + if( taskList.GetTaskCount() > 1 ) + { + typedef std::vector Collection; + typedef Collection::iterator ColIter; + Collection tasks; + + for(unsigned int i = 1; i < taskList.GetTaskCount(); ++i) + { + tasks.push_back( taskList.GetTask(i) ); + } + + for(ColIter iter = tasks.begin(); iter != tasks.end(); ++iter) + { + taskList.RemoveTask(*iter); + } + + RenderTask defaultTask = taskList.GetTask(0); + defaultTask.SetSourceActor( stage.GetRootLayer() ); + defaultTask.SetTargetFrameBuffer( FrameBufferImage() ); + } + + unsigned int numChildren = layer.GetChildCount(); + + for(unsigned int i=0; i 1) + { + USER_DIRECTORY = argv[1]; + } + + Application app = Application::New(&argc, &argv); + + ExampleApp dali_app(app); + + app.MainLoop(); + + return 0; +} -- 2.7.4