Commit 2cf3c424846a9260c8c0cde8a9d054e23909bf97
1 parent
ee796c0c
added builder demo
Change-Id: I0818d9afbe73108005b04f1f046fc41284b07442 Signed-off-by: Lee Morgan <Lee.morgan@partner.samsung.com>
Showing
16 changed files
with
1665 additions
and
1 deletions
.gitignore
build/tizen/demo/Makefile.am
| ... | ... | @@ -25,8 +25,17 @@ dalidemoimages_DATA = $(demo_image_files) |
| 25 | 25 | dalidemomodelsdir = $(appdatadir)/models/ |
| 26 | 26 | dalidemomodels_DATA = $(demo_model_files) |
| 27 | 27 | |
| 28 | +dalidemoshadersdir = $(appdatadir)/shaders/ | |
| 29 | +dalidemoshaders_DATA = $(demo_shader_files) | |
| 30 | + | |
| 31 | +dalidemoscriptsdir = $(appdatadir)/scripts/ | |
| 32 | +dalidemoscripts_DATA = $(demo_script_files) | |
| 33 | + | |
| 34 | + | |
| 28 | 35 | DEMO_CXXFLAGS = -DDALI_IMAGE_DIR="\"$(dalidemoimagesdir)\"" \ |
| 29 | 36 | -DDALI_MODEL_DIR="\"$(dalidemomodelsdir)\"" \ |
| 37 | + -DDALI_SCRIPT_DIR="\"$(dalidemoscriptsdir)\"" \ | |
| 38 | + -DDALI_SHADER_DIR="\"$(dalidemoshadersdir)\"" \ | |
| 30 | 39 | -DDALI_EXAMPLE_BIN="\"$(exedir)\"" \ |
| 31 | 40 | -I../../../demo -I../../.. \ |
| 32 | 41 | $(DALIDEMO_CFLAGS) \ | ... | ... |
build/tizen/examples/Makefile.am
| ... | ... | @@ -29,14 +29,19 @@ bin_PROGRAMS = \ |
| 29 | 29 | page-turn-view.example \ |
| 30 | 30 | radial-menu.example \ |
| 31 | 31 | scroll-view.example \ |
| 32 | - shadow-bone-lighting.example | |
| 32 | + shadow-bone-lighting.example \ | |
| 33 | + dali-builder \ | |
| 34 | + builder.example | |
| 35 | + | |
| 33 | 36 | |
| 34 | 37 | daliimagedir = $(appdatadir)/images/ |
| 35 | 38 | dalimodeldir = $(appdatadir)/models/ |
| 39 | +daliscriptdir = $(appdatadir)/scripts/ | |
| 36 | 40 | |
| 37 | 41 | BASE_CXXFLAGS = -I../../../examples \ |
| 38 | 42 | -DDALI_IMAGE_DIR="\"${daliimagedir}\"" \ |
| 39 | 43 | -DDALI_MODEL_DIR="\"${dalimodeldir}\"" \ |
| 44 | + -DDALI_SCRIPT_DIR="\"${daliscriptdir}\"" \ | |
| 40 | 45 | $(DALIDEMO_CFLAGS) \ |
| 41 | 46 | $(ECORE_X_CFLAGS) \ |
| 42 | 47 | $(CAPI_MEDIA_PLAYER_CFLAGS) \ |
| ... | ... | @@ -125,3 +130,13 @@ shadow_bone_lighting_example_SOURCES = $(examples_src_dir)/shadows/shadow-bone-l |
| 125 | 130 | shadow_bone_lighting_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) |
| 126 | 131 | shadow_bone_lighting_example_DEPENDENCIES = $(EXAMPLE_DEPS) |
| 127 | 132 | shadow_bone_lighting_example_LDADD = $(EXAMPLE_LDADD) |
| 133 | + | |
| 134 | +dali_builder_SOURCES = $(examples_src_dir)/builder/dali-builder.cpp | |
| 135 | +dali_builder_CXXFLAGS = $(EXAMPLE_CXXFLAGS) | |
| 136 | +dali_builder_DEPENDENCIES = $(EXAMPLE_DEPS) | |
| 137 | +dali_builder_LDADD = $(EXAMPLE_LDADD) | |
| 138 | + | |
| 139 | +builder_example_SOURCES = $(examples_src_dir)/builder/examples.cpp | |
| 140 | +builder_example_CXXFLAGS = $(EXAMPLE_CXXFLAGS) | |
| 141 | +builder_example_DEPENDENCIES = $(EXAMPLE_DEPS) | |
| 142 | +builder_example_LDADD = $(EXAMPLE_LDADD) | ... | ... |
demo/dali-demo.cpp
| ... | ... | @@ -38,6 +38,7 @@ int main(int argc, char **argv) |
| 38 | 38 | demo.AddExample(Example("radial-menu.example", "Radial Menu")); |
| 39 | 39 | demo.AddExample(Example("scroll-view.example", "Scroll View")); |
| 40 | 40 | demo.AddExample(Example("shadow-bone-lighting.example", "Lights and shadows")); |
| 41 | + demo.AddExample(Example("builder.example", "Script Based UI")); | |
| 41 | 42 | app.MainLoop(); |
| 42 | 43 | |
| 43 | 44 | return 0; | ... | ... |
demo/file.list
demo/scripts/animation.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + // library of styles | |
| 19 | + "styles": { | |
| 20 | + "red-theme": { | |
| 21 | + "color": [1, 0, 0, 1] | |
| 22 | + }, | |
| 23 | + "basic-text": { | |
| 24 | + "parent-origin": "CENTER" | |
| 25 | + } | |
| 26 | + }, | |
| 27 | + // library of animations | |
| 28 | + "animations": { | |
| 29 | + "animate": { | |
| 30 | + "duration": 10.0, | |
| 31 | + "properties": [{ | |
| 32 | + "actor": "greeting", // referenced actors must exist on stage | |
| 33 | + "property": "position", | |
| 34 | + "value": [300, 300, -1000], | |
| 35 | + "alpha-function": "EASE_IN_OUT", | |
| 36 | + "time-period": { | |
| 37 | + "delay": 0, | |
| 38 | + "duration": 3 | |
| 39 | + } | |
| 40 | + }, { | |
| 41 | + "actor": "greeting", // referenced actors must exist on stage | |
| 42 | + "property": "scale", | |
| 43 | + "value": [5, 5, 1], | |
| 44 | + "time-period": { | |
| 45 | + "delay": 2, | |
| 46 | + "duration": 3 | |
| 47 | + } | |
| 48 | + }] | |
| 49 | + }, | |
| 50 | + "rotate": { | |
| 51 | + "duration": 10.0, | |
| 52 | + "properties": [{ | |
| 53 | + "actor": "image", // referenced actors must exist on stage | |
| 54 | + "property": "rotation", | |
| 55 | + "value": [0, 0, -45], | |
| 56 | + "alpha-function": "EASE_IN_OUT", | |
| 57 | + "time-period": { | |
| 58 | + "delay": 0, | |
| 59 | + "duration": 3 | |
| 60 | + } | |
| 61 | + }] | |
| 62 | + } | |
| 63 | + }, | |
| 64 | + // a tree of actors | |
| 65 | + "stage": [{ | |
| 66 | + "name": "greeting", | |
| 67 | + "type": "TextView", | |
| 68 | + "text": "Touch me", | |
| 69 | + "styles": ["basic-text"], | |
| 70 | + "position": [0, -120, 0], | |
| 71 | + "size": [200, 200, 1], | |
| 72 | + "rotation": [0, 0, 30], | |
| 73 | + "signals": [{ | |
| 74 | + "name": "touched", | |
| 75 | + "action": "play", | |
| 76 | + "animation": "animate" | |
| 77 | + }] | |
| 78 | + }, { | |
| 79 | + "type": "TextView", // styles can be additive | |
| 80 | + "parent-origin": "CENTER", | |
| 81 | + "anchor-point": "CENTER", | |
| 82 | + "size": [200, 200, 1], | |
| 83 | + "text": "or the image.." | |
| 84 | + }, { | |
| 85 | + "name": "image", | |
| 86 | + "type": "ImageActor", | |
| 87 | + "image": { | |
| 88 | + "filename": "{DALI_IMAGE_DIR}gallery-large-21.jpg" | |
| 89 | + }, | |
| 90 | + "position": [0, 200, 0], | |
| 91 | + "size": [200, 200, 1], | |
| 92 | + "signals": [{ | |
| 93 | + "name": "touched", | |
| 94 | + "action": "play", | |
| 95 | + "animation": "rotate" | |
| 96 | + }], | |
| 97 | + "position-inheritance": "DONT_INHERIT_POSITION" | |
| 98 | + }] | |
| 99 | +} | ... | ... |
demo/scripts/background-color.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + "stage": [ | |
| 19 | + // A TextView with a red background | |
| 20 | + { | |
| 21 | + "type": "TextView", | |
| 22 | + "text": "Hello World", | |
| 23 | + "parent-origin": "TOP_CENTER", | |
| 24 | + "anchor-point": "TOP_CENTER", | |
| 25 | + "background-color": [1, 0, 0, 1], | |
| 26 | + "size": [400, 150, 1] | |
| 27 | + }, | |
| 28 | + | |
| 29 | + // A container with a yellow background | |
| 30 | + { | |
| 31 | + "type": "Control", | |
| 32 | + "parent-origin": "CENTER", | |
| 33 | + "anchor-point": "BOTTOM_CENTER", | |
| 34 | + "background-color": [1, 1, 0, 1], | |
| 35 | + "size": [400, 150, 1] | |
| 36 | + }, | |
| 37 | + | |
| 38 | + // A container with an image | |
| 39 | + { | |
| 40 | + "type": "Control", | |
| 41 | + "parent-origin": "CENTER", | |
| 42 | + "anchor-point": "TOP_CENTER", | |
| 43 | + "size": [400, 150, 1], | |
| 44 | + "background": { | |
| 45 | + "image": { | |
| 46 | + "filename": "{DALI_IMAGE_DIR}button-background.png" | |
| 47 | + } | |
| 48 | + } | |
| 49 | + }, | |
| 50 | + | |
| 51 | + // A container with the same image blended in with a blue background | |
| 52 | + { | |
| 53 | + "type": "Control", | |
| 54 | + "parent-origin": "BOTTOM_CENTER", | |
| 55 | + "anchor-point": "BOTTOM_CENTER", | |
| 56 | + "size": [400, 150, 1], | |
| 57 | + "background-color": [0, 0, 1, 1], | |
| 58 | + "background": { | |
| 59 | + "image": { | |
| 60 | + "filename": "{DALI_IMAGE_DIR}button-background.png" | |
| 61 | + } | |
| 62 | + } | |
| 63 | + } | |
| 64 | + ] | |
| 65 | +} | ... | ... |
demo/scripts/button.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + "constants": { | |
| 19 | + "CONFIG_SCRIPT_LOG_LEVEL": "Verbose" | |
| 20 | + }, | |
| 21 | + "stage": [ | |
| 22 | + // First Button | |
| 23 | + { | |
| 24 | + "type": "PushButton", | |
| 25 | + "parent-origin": "TOP_CENTER", | |
| 26 | + "anchor-point": "TOP_CENTER", | |
| 27 | + "position": [0, 0, 0], | |
| 28 | + "size": [0, 200, 0], | |
| 29 | + "normal-state-actor": { | |
| 30 | + "type": "ImageActor", | |
| 31 | + "image": { | |
| 32 | + "filename": "{DALI_IMAGE_DIR}blocks-brick-1.png" | |
| 33 | + } | |
| 34 | + }, | |
| 35 | + "pressed-state-actor": { | |
| 36 | + "type": "ImageActor", | |
| 37 | + "image": { | |
| 38 | + "filename": "{DALI_IMAGE_DIR}blocks-brick-2.png" | |
| 39 | + } | |
| 40 | + }, | |
| 41 | + "label-actor": { | |
| 42 | + "type": "TextView", | |
| 43 | + "text": "Normal" | |
| 44 | + } | |
| 45 | + }, | |
| 46 | + | |
| 47 | + // Second Button | |
| 48 | + { | |
| 49 | + "type": "PushButton", | |
| 50 | + "parent-origin": "CENTER", | |
| 51 | + "anchor-point": "CENTER", | |
| 52 | + "position": [0, 0, 0], | |
| 53 | + "size": [0, 200, 0], | |
| 54 | + "label-actor": { | |
| 55 | + "type": "TextView", | |
| 56 | + "text": "Dimmed" | |
| 57 | + }, | |
| 58 | + "dimmed": true, | |
| 59 | + "normal-state-actor": { | |
| 60 | + "type": "ImageActor", | |
| 61 | + "image": { | |
| 62 | + "filename": "{DALI_IMAGE_DIR}blocks-brick-1.png" | |
| 63 | + } | |
| 64 | + }, | |
| 65 | + "pressed-state-actor": { | |
| 66 | + "type": "ImageActor", | |
| 67 | + "image": { | |
| 68 | + "filename": "{DALI_IMAGE_DIR}blocks-brick-2.png" | |
| 69 | + } | |
| 70 | + }, | |
| 71 | + "dimmed-state-actor": { | |
| 72 | + "type": "ImageActor", | |
| 73 | + "image": { | |
| 74 | + "filename": "{DALI_IMAGE_DIR}blocks-brick-3.png" | |
| 75 | + } | |
| 76 | + } | |
| 77 | + }, | |
| 78 | + | |
| 79 | + // Third Button | |
| 80 | + { | |
| 81 | + "type": "PushButton", | |
| 82 | + "name": "toggle-button", | |
| 83 | + "parent-origin": "BOTTOM_CENTER", | |
| 84 | + "anchor-point": "BOTTOM_CENTER", | |
| 85 | + "position": [0, 0, 0], | |
| 86 | + "size": [0, 200, 0], | |
| 87 | + "label-actor": { | |
| 88 | + "type": "TextView", | |
| 89 | + "text": "Toggle" | |
| 90 | + }, | |
| 91 | + "togglable": true, | |
| 92 | + "normal-state-actor": { | |
| 93 | + "type": "ImageActor", | |
| 94 | + "style": "STYLE_NINE_PATCH", | |
| 95 | + "border": [26, 24, 26, 23], | |
| 96 | + "image": { | |
| 97 | + "filename": "{DALI_IMAGE_DIR}blocks-brick-1.png" | |
| 98 | + } | |
| 99 | + }, | |
| 100 | + "pressed-state-actor": { | |
| 101 | + "type": "ImageActor", | |
| 102 | + "style": "STYLE_NINE_PATCH", | |
| 103 | + "border": [26, 24, 26, 23], | |
| 104 | + "image": { | |
| 105 | + "filename": "{DALI_IMAGE_DIR}blocks-paddle.png" | |
| 106 | + } | |
| 107 | + }, | |
| 108 | + "signals": [{ | |
| 109 | + "name": "toggled", | |
| 110 | + "action": "set", | |
| 111 | + "actor": "toggle-button", | |
| 112 | + "property": "label-actor", | |
| 113 | + "value": { | |
| 114 | + "type": "TextView", | |
| 115 | + "text": "Using a 9-patch image" | |
| 116 | + } | |
| 117 | + }] | |
| 118 | + } | |
| 119 | + ] | |
| 120 | +} | ... | ... |
demo/scripts/formatted-text.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + // a tree of actors | |
| 19 | + "stage": [{ | |
| 20 | + "type": "Actor", | |
| 21 | + "size": [400, 400, 1], | |
| 22 | + "parent-origin": "CENTER", | |
| 23 | + "actors": [{ | |
| 24 | + "type": "TextView", | |
| 25 | + "size": [400, 400, 1], | |
| 26 | + "text": "<font size='8>Text with<br>\n<b>'markup-enabled':true</b></font>", | |
| 27 | + "markup-enabled": true, | |
| 28 | + "multiline-policy": "SplitByNewLineChar", | |
| 29 | + "horizontal-alignment": "HorizontalCenter", | |
| 30 | + "vertical-alignment": "VerticalBottom", | |
| 31 | + "width-exceed-policy": "Fade", | |
| 32 | + "line-justification": "Center", | |
| 33 | + "fade-boundary": [50, 50, 0, 0], | |
| 34 | + "line-height-offset": 25.0, | |
| 35 | + "parent-origin": "TOP_CENTER" | |
| 36 | + }, { | |
| 37 | + "type": "TextView", | |
| 38 | + "size": [400, 400, 1], | |
| 39 | + "text": "<font size='16'>Text with\n<b>'markup-enabled':false</b></font>", | |
| 40 | + "markup-enabled": false, | |
| 41 | + "multiline-policy": "SplitByWord", | |
| 42 | + "horizontal-alignment": "HorizontalLeft", | |
| 43 | + "vertical-alignment": "VerticalTop", | |
| 44 | + "width-exceed-policy": "ShrinkToFit", | |
| 45 | + "height-exceed-policy": "Original", | |
| 46 | + "line-justification": "Right", | |
| 47 | + "line-height-offset": 5.0, | |
| 48 | + "parent-origin": "BOTTOM_CENTER" | |
| 49 | + }] | |
| 50 | + }] | |
| 51 | +} | ... | ... |
demo/scripts/hello-world.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + // a tree of actors | |
| 19 | + "stage": [{ | |
| 20 | + "type": "TextView", | |
| 21 | + "text": "Hello World", | |
| 22 | + "parent-origin": "CENTER" | |
| 23 | + }] | |
| 24 | +} | ... | ... |
demo/scripts/navigation.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + "stage": [{ | |
| 19 | + "type": "NavigationControl", | |
| 20 | + "name": "navigation", | |
| 21 | + "parent-origin": "CENTER", | |
| 22 | + "signals": [{ | |
| 23 | + "name": "on-stage", | |
| 24 | + "actor": "navigation", | |
| 25 | + "action": "push", | |
| 26 | + "parameters": ["page1"] | |
| 27 | + }], | |
| 28 | + "actors": [{ | |
| 29 | + "type": "Page", | |
| 30 | + "name": "page1", | |
| 31 | + "title": "title", | |
| 32 | + "sub-title": "sub title", | |
| 33 | + "actors": [{ | |
| 34 | + "type": "TextView", // styles can be additive | |
| 35 | + "parent-origin": [0.5, 0.5, 0], | |
| 36 | + "anchor-point": [0.5, 0.5, 0], | |
| 37 | + "size": [200, 200, 1], | |
| 38 | + "text": "Touch to push new item!", | |
| 39 | + "signals": [{ | |
| 40 | + "name": "touched", | |
| 41 | + "actor": "navigation", | |
| 42 | + "action": "push", | |
| 43 | + "parameters": ["page2"] | |
| 44 | + }] | |
| 45 | + }] | |
| 46 | + }, { | |
| 47 | + "type": "Page", | |
| 48 | + "name": "page2", | |
| 49 | + "actors": [{ | |
| 50 | + "type": "TextView", // styles can be additive | |
| 51 | + "parent-origin": [0.5, 0.5, 0.5], | |
| 52 | + "anchor-point": [0.5, 0.5, 0.5], | |
| 53 | + "size": [200, 200, 1], | |
| 54 | + "text": "Hello World!" | |
| 55 | + }, { | |
| 56 | + "type": "TextView", // styles can be additive | |
| 57 | + "parent-origin": [0.0, 0.0, 0.5], | |
| 58 | + "anchor-point": [0.0, 0.0, 0.5], | |
| 59 | + "size": [200, 200, 1], | |
| 60 | + "text": "Back", | |
| 61 | + "signals": [{ | |
| 62 | + "name": "touched", | |
| 63 | + "actor": "navigation", | |
| 64 | + "action": "pop" | |
| 65 | + }] | |
| 66 | + }, { | |
| 67 | + "type": "TextView", // styles can be additive | |
| 68 | + "parent-origin": [1.0, 1.0, 0.5], | |
| 69 | + "anchor-point": [1.0, 1.0, 0.5], | |
| 70 | + "size": [200, 200, 1], | |
| 71 | + "text": "Quit", | |
| 72 | + "signals": [{ | |
| 73 | + "name": "touched", | |
| 74 | + "action": "quit" | |
| 75 | + }] | |
| 76 | + }] | |
| 77 | + }] | |
| 78 | + }] | |
| 79 | +} | ... | ... |
demo/scripts/slider-test-style.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +//****************************************************************************** | |
| 18 | +// | |
| 19 | +// Default style theme for Tizen Light theme, The values should come from | |
| 20 | +// UX design document. | |
| 21 | +// | |
| 22 | +//****************************************************************************** | |
| 23 | +{ | |
| 24 | + "styles": { | |
| 25 | + "slider": { | |
| 26 | + "anchor-point": [0.5, 0.0, 0.0], | |
| 27 | + "parent-origin": [0.5, 0.0, 0.0], | |
| 28 | + "position": [0, 300, 0], | |
| 29 | + "size": [480, 72, 1], | |
| 30 | + "lower-bound": 0, | |
| 31 | + "upper-bound": 10, | |
| 32 | + "show-popup": true, | |
| 33 | + "show-value": true, | |
| 34 | + "value-precision": 2, | |
| 35 | + "value": 0.0, | |
| 36 | + "popup-text-color": [0.0, 1.0, 1.0, 1.0] | |
| 37 | + } | |
| 38 | + } | |
| 39 | +} | ... | ... |
demo/scripts/slider.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + "stage": [{ | |
| 19 | + "type": "Slider", | |
| 20 | + "parent-origin": "TOP_CENTER", | |
| 21 | + "position": [0, 144, 0], | |
| 22 | + "size": [480, 72, 1], | |
| 23 | + "lower-bound": 0, | |
| 24 | + "upper-bound": 1, | |
| 25 | + "show-popup": true, | |
| 26 | + "show-value": true, | |
| 27 | + "value-precision": 2, | |
| 28 | + "value": 0.0 | |
| 29 | + }, { | |
| 30 | + "type": "Slider", | |
| 31 | + "parent-origin": "TOP_CENTER", | |
| 32 | + "position": [0, 224, 0], | |
| 33 | + "size": [300, 72, 1], | |
| 34 | + "lower-bound": 1, | |
| 35 | + "upper-bound": 10, | |
| 36 | + "show-popup": false, | |
| 37 | + "show-value": true, | |
| 38 | + "value-precision": 0, | |
| 39 | + "value": 5.0 | |
| 40 | + }, { | |
| 41 | + "type": "Slider", | |
| 42 | + "parent-origin": "TOP_CENTER", | |
| 43 | + "position": [0, 304, 0], | |
| 44 | + "size": [300, 72, 1], | |
| 45 | + "lower-bound": 0, | |
| 46 | + "upper-bound": 5, | |
| 47 | + "show-popup": false, | |
| 48 | + "show-value": false, | |
| 49 | + "value": 0.0, | |
| 50 | + "mark-tolerance": 0.1, | |
| 51 | + "marks": [0, 1, 2, 3, 4, 5] | |
| 52 | + }, { | |
| 53 | + "type": "Slider", | |
| 54 | + "parent-origin": "TOP_CENTER", | |
| 55 | + "position": [0, 384, 0], | |
| 56 | + "size": [480, 72, 1], | |
| 57 | + "lower-bound": 0, | |
| 58 | + "upper-bound": 5, | |
| 59 | + "show-popup": false, | |
| 60 | + "show-value": false, | |
| 61 | + "value": 0.0, | |
| 62 | + "mark-tolerance": 0.1, | |
| 63 | + "snap-to-marks": true, | |
| 64 | + "marks": [0, 1, 2, 3, 4, 5] | |
| 65 | + }, { | |
| 66 | + "type": "Slider", | |
| 67 | + "parent-origin": "TOP_CENTER", | |
| 68 | + "position": [0, 464, 0], | |
| 69 | + "size": [480, 72, 1], | |
| 70 | + "lower-bound": 5, | |
| 71 | + "upper-bound": 100, | |
| 72 | + "show-popup": true, | |
| 73 | + "show-value": true, | |
| 74 | + "value-precision": 0, | |
| 75 | + "value": 50.0, | |
| 76 | + "popup-text-color": [1, 0, 0, 1], | |
| 77 | + "hit-region": [0, 48], | |
| 78 | + "backing-region": [0, 10], | |
| 79 | + "handle-region": [48, 48] | |
| 80 | + }, { | |
| 81 | + "type": "Slider", | |
| 82 | + "parent-origin": "TOP_CENTER", | |
| 83 | + "position": [0, 544, 0], | |
| 84 | + "size": [480, 72, 1], | |
| 85 | + "lower-bound": 10, | |
| 86 | + "upper-bound": 100, | |
| 87 | + "show-popup": true, | |
| 88 | + "show-value": true, | |
| 89 | + "value-prescision": 0, | |
| 90 | + "value": 100.0, | |
| 91 | + "hit-region": [0, 48], | |
| 92 | + "backing-region": [0, 10], | |
| 93 | + "handle-region": [48, 48], | |
| 94 | + "backing-image-name": "{DALI_IMAGE_DIR}circle_point_32x32.png", | |
| 95 | + "handle-image-name": "{DALI_IMAGE_DIR}circle_point_shadow_32x32.png", | |
| 96 | + "progress-image-name": "{DALI_IMAGE_DIR}circle_point.png", | |
| 97 | + "backing-scale9-border": [16, 0, 16, 0], | |
| 98 | + "progress-scale9-border": [16, 0, 16, 0] | |
| 99 | + }, { | |
| 100 | + "type": "Slider", | |
| 101 | + "parent-origin": "TOP_CENTER", | |
| 102 | + "position": [0, 624, 0], | |
| 103 | + "size": [480, 72, 1], | |
| 104 | + "lower-bound": 10, | |
| 105 | + "upper-bound": 100, | |
| 106 | + "show-popup": true, | |
| 107 | + "show-value": true, | |
| 108 | + "value-precision": 0, | |
| 109 | + "value": 50.0, | |
| 110 | + "hit-region": [0, 48], | |
| 111 | + "backing-region": [0, 10], | |
| 112 | + "handle-region": [48, 48], | |
| 113 | + "enabled": false | |
| 114 | + }, { | |
| 115 | + "type": "Slider", | |
| 116 | + "parent-origin": "TOP_CENTER", | |
| 117 | + "position": [0, 704, 0], | |
| 118 | + "size": [480, 72, 1], | |
| 119 | + "lower-bound": 10, | |
| 120 | + "upper-bound": 100, | |
| 121 | + "show-popup": true, | |
| 122 | + "show-value": true, | |
| 123 | + "value-precision": 0, | |
| 124 | + "value": 50.0, | |
| 125 | + "hit-region": [0, 48], | |
| 126 | + "backing-region": [0, 10], | |
| 127 | + "handle-region": [48, 48], | |
| 128 | + "enabled": false, | |
| 129 | + "disable-color": [1, 0, 0, 1] | |
| 130 | + }] | |
| 131 | +} | ... | ... |
demo/scripts/super-blur-view.json
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +{ | |
| 18 | + "constants": { | |
| 19 | + "TEXT_VIEW_SIZE": [200, 150, 1] | |
| 20 | + }, | |
| 21 | + "animations": { | |
| 22 | + "blur": { | |
| 23 | + "duration": 1, | |
| 24 | + "properties": [{ | |
| 25 | + "actor": "super-blur", | |
| 26 | + "property": "blur-strength", | |
| 27 | + "value": 1, | |
| 28 | + "time-period": { | |
| 29 | + "delay": 0, | |
| 30 | + "duration": 1 | |
| 31 | + } | |
| 32 | + }] | |
| 33 | + }, | |
| 34 | + "clear": { | |
| 35 | + "duration": 1, | |
| 36 | + "properties": [{ | |
| 37 | + "actor": "super-blur", | |
| 38 | + "property": "blur-strength", | |
| 39 | + "value": 0, | |
| 40 | + "time-period": { | |
| 41 | + "delay": 0, | |
| 42 | + "duration": 1 | |
| 43 | + } | |
| 44 | + }] | |
| 45 | + } | |
| 46 | + }, | |
| 47 | + "stage": [ | |
| 48 | + // SuperBlurView | |
| 49 | + { | |
| 50 | + "type": "SuperBlurView", | |
| 51 | + "name": "super-blur", | |
| 52 | + "parent-origin": "TOP_CENTER", | |
| 53 | + "anchor-point": "TOP_CENTER", | |
| 54 | + "position": [0, 10, 0], | |
| 55 | + "size": [460, 600, 0], | |
| 56 | + "image": { | |
| 57 | + "filename": "{DALI_IMAGE_DIR}background-4.jpg" | |
| 58 | + } | |
| 59 | + }, | |
| 60 | + | |
| 61 | + // Button to blur/clear | |
| 62 | + { | |
| 63 | + "type": "PushButton", | |
| 64 | + "name": "toggle-button", | |
| 65 | + "parent-origin": "BOTTOM_CENTER", | |
| 66 | + "anchor-point": "BOTTOM_CENTER", | |
| 67 | + "position": [0, 0, 0], | |
| 68 | + "size": [0, 100, 0], | |
| 69 | + "label-actor": { | |
| 70 | + "type": "TextView", | |
| 71 | + "text": "Blur" | |
| 72 | + }, | |
| 73 | + "normal-state-actor": { | |
| 74 | + "type": "ImageActor", | |
| 75 | + "style": "STYLE_NINE_PATCH", | |
| 76 | + "border": [26, 24, 26, 23], | |
| 77 | + "image": { | |
| 78 | + "filename": "{DALI_IMAGE_DIR}button-background.png" | |
| 79 | + } | |
| 80 | + }, | |
| 81 | + "pressed-state-actor": { | |
| 82 | + "type": "ImageActor", | |
| 83 | + "style": "STYLE_NINE_PATCH", | |
| 84 | + "border": [26, 24, 26, 23], | |
| 85 | + "image": { | |
| 86 | + "filename": "{DALI_IMAGE_DIR}button-background.png" | |
| 87 | + } | |
| 88 | + }, | |
| 89 | + "signals": [{ | |
| 90 | + "name": "pressed", | |
| 91 | + "action": "play", | |
| 92 | + "animation": "blur" | |
| 93 | + }, { | |
| 94 | + "name": "released", | |
| 95 | + "action": "play", | |
| 96 | + "animation": "clear" | |
| 97 | + }] | |
| 98 | + } | |
| 99 | + ] | |
| 100 | +} | ... | ... |
examples/builder/dali-builder.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +//------------------------------------------------------------------------------ | |
| 18 | +// | |
| 19 | +// Run a json script layout file | |
| 20 | +// | |
| 21 | +// - watches an named file and reloads actor tree if the file changes | |
| 22 | +// ie run | |
| 23 | +// builder-run layout.json | |
| 24 | +// | |
| 25 | +// and edit layout.json in a text editor saving to trigger the reload | |
| 26 | +// | |
| 27 | +//------------------------------------------------------------------------------ | |
| 28 | + | |
| 29 | +#include <dali/dali.h> | |
| 30 | +#include <dali-toolkit/dali-toolkit.h> | |
| 31 | +#include <dali-toolkit/public-api/builder/builder.h> | |
| 32 | +#include <dali-toolkit/public-api/builder/tree-node.h> | |
| 33 | +#include <map> | |
| 34 | +#include <string> | |
| 35 | +#include <fstream> | |
| 36 | +#include <streambuf> | |
| 37 | +#include <boost/scoped_ptr.hpp> | |
| 38 | + | |
| 39 | +//#include <boost/regex.hpp> | |
| 40 | +#include "sys/stat.h" | |
| 41 | +#include <ctime> | |
| 42 | + | |
| 43 | +#include <dali/integration-api/debug.h> | |
| 44 | + | |
| 45 | +#define TOKEN_STRING(x) #x | |
| 46 | + | |
| 47 | +using namespace Dali; | |
| 48 | +using namespace Dali::Toolkit; | |
| 49 | + | |
| 50 | +namespace | |
| 51 | +{ | |
| 52 | + | |
| 53 | +std::string JSON_BROKEN(" \ | |
| 54 | +{ \ | |
| 55 | + 'stage': \ | |
| 56 | + [ \ | |
| 57 | + { \ | |
| 58 | + 'type':'TextActor', \ | |
| 59 | + 'size': [50,50,1], \ | |
| 60 | + 'parent-origin': 'CENTER', \ | |
| 61 | + 'text':'COULD NOT LOAD JSON FILE' \ | |
| 62 | + } \ | |
| 63 | + ] \ | |
| 64 | +} \ | |
| 65 | +"); | |
| 66 | + | |
| 67 | +std::string ReplaceQuotes(const std::string &single_quoted) | |
| 68 | +{ | |
| 69 | + std::string s(single_quoted); | |
| 70 | + | |
| 71 | + // wrong as no embedded quote but had regex link problems | |
| 72 | + std::replace(s.begin(), s.end(), '\'', '"'); | |
| 73 | + | |
| 74 | + return s; | |
| 75 | +} | |
| 76 | + | |
| 77 | +} // anon namespace | |
| 78 | + | |
| 79 | + | |
| 80 | +//------------------------------------------------------------------------------ | |
| 81 | +// | |
| 82 | +// | |
| 83 | +// | |
| 84 | +//------------------------------------------------------------------------------ | |
| 85 | +class FileWatcher | |
| 86 | +{ | |
| 87 | +public: | |
| 88 | + FileWatcher(void); | |
| 89 | + ~FileWatcher(void); | |
| 90 | + explicit FileWatcher(const std::string &fn) { SetFilename(fn) ; }; | |
| 91 | + | |
| 92 | + void SetFilename(const std::string &fn); | |
| 93 | + std::string GetFilename(); | |
| 94 | + | |
| 95 | + bool FileHasChanged(void); | |
| 96 | + std::string GetFileContents(void) { return GetFileContents(mstringPath) ; }; | |
| 97 | + | |
| 98 | +private: | |
| 99 | + // compiler does | |
| 100 | + // FileWatcher(const FileWatcher&); | |
| 101 | + // FileWatcher &operator=(const FileWatcher &); | |
| 102 | + | |
| 103 | + std::time_t mLastTime; | |
| 104 | + std::string mstringPath; | |
| 105 | + | |
| 106 | + std::string GetFileContents(const std::string &fn) | |
| 107 | + { | |
| 108 | + std::ifstream t(fn.c_str()); | |
| 109 | + return std::string((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>()); | |
| 110 | + }; | |
| 111 | +}; | |
| 112 | + | |
| 113 | +FileWatcher::FileWatcher(void) : mLastTime(0) | |
| 114 | +{ | |
| 115 | +} | |
| 116 | + | |
| 117 | +bool FileWatcher::FileHasChanged(void) | |
| 118 | +{ | |
| 119 | + struct stat buf; | |
| 120 | + | |
| 121 | + if(0 != stat(mstringPath.c_str(), &buf)) | |
| 122 | + { | |
| 123 | + DALI_LOG_WARNING("File does not exist '%s'\n", mstringPath.c_str()); | |
| 124 | + return false; | |
| 125 | + } | |
| 126 | + else | |
| 127 | + { | |
| 128 | + if(buf.st_mtime > mLastTime) | |
| 129 | + { | |
| 130 | + mLastTime = buf.st_mtime; | |
| 131 | + return true; | |
| 132 | + } | |
| 133 | + else | |
| 134 | + { | |
| 135 | + mLastTime = buf.st_mtime; | |
| 136 | + return false; | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + return false; | |
| 141 | +} | |
| 142 | + | |
| 143 | +FileWatcher::~FileWatcher() | |
| 144 | +{ | |
| 145 | +} | |
| 146 | + | |
| 147 | +void FileWatcher::SetFilename(const std::string &fn) | |
| 148 | +{ | |
| 149 | + mstringPath = fn; | |
| 150 | +} | |
| 151 | + | |
| 152 | +std::string FileWatcher::GetFilename(void) | |
| 153 | +{ | |
| 154 | + return mstringPath; | |
| 155 | +} | |
| 156 | + | |
| 157 | + | |
| 158 | +//------------------------------------------------------------------------------ | |
| 159 | +// | |
| 160 | +// | |
| 161 | +// | |
| 162 | +//------------------------------------------------------------------------------ | |
| 163 | +class ExampleApp : public ConnectionTracker | |
| 164 | +{ | |
| 165 | +public: | |
| 166 | + ExampleApp(Application &app) : mApp(app) | |
| 167 | + { | |
| 168 | + app.InitSignal().Connect(this, &ExampleApp::Create); | |
| 169 | + | |
| 170 | + } | |
| 171 | + | |
| 172 | + ~ExampleApp() {} | |
| 173 | + | |
| 174 | +public: | |
| 175 | + void SetJSONFilename(std::string const &fn) { fw.SetFilename(fn) ; }; | |
| 176 | + | |
| 177 | + void Create(Application& app) | |
| 178 | + { | |
| 179 | + mTimer = Timer::New( 500 ); // ms | |
| 180 | + mTimer.TickSignal().Connect( this, &ExampleApp::OnTimer); | |
| 181 | + mTimer.Start(); | |
| 182 | + | |
| 183 | + // Connect to key events in order to exit | |
| 184 | + Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleApp::OnKeyEvent); | |
| 185 | + } | |
| 186 | + | |
| 187 | +private: | |
| 188 | + Application& mApp; | |
| 189 | + Layer mRootLayer; | |
| 190 | + | |
| 191 | + FileWatcher fw; | |
| 192 | + Timer mTimer; | |
| 193 | + | |
| 194 | + void ReloadJsonFile(Builder& builder, Layer& layer) | |
| 195 | + { | |
| 196 | + Stage stage = Stage::GetCurrent(); | |
| 197 | + | |
| 198 | + builder = Builder::New(); | |
| 199 | + | |
| 200 | + PropertyValueMap defaultDirs; | |
| 201 | + defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR; | |
| 202 | + defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ] = DALI_MODEL_DIR; | |
| 203 | + defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR; | |
| 204 | + | |
| 205 | + builder.AddConstants( defaultDirs ); | |
| 206 | + | |
| 207 | + if(!layer) | |
| 208 | + { | |
| 209 | + layer = Layer::New(); | |
| 210 | + layer.SetParentOrigin(ParentOrigin::CENTER); | |
| 211 | + layer.SetAnchorPoint(AnchorPoint::CENTER); | |
| 212 | + layer.SetSize( stage.GetRootLayer().GetCurrentSize() ); | |
| 213 | + stage.GetRootLayer().Add(layer); | |
| 214 | + | |
| 215 | + // render tasks may have been setup last load so remove them | |
| 216 | + RenderTaskList taskList = stage.GetRenderTaskList(); | |
| 217 | + if( taskList.GetTaskCount() > 1 ) | |
| 218 | + { | |
| 219 | + typedef std::vector<RenderTask> Collection; | |
| 220 | + typedef Collection::iterator ColIter; | |
| 221 | + Collection tasks; | |
| 222 | + | |
| 223 | + for(unsigned int i = 1; i < taskList.GetTaskCount(); ++i) | |
| 224 | + { | |
| 225 | + tasks.push_back( taskList.GetTask(i) ); | |
| 226 | + } | |
| 227 | + | |
| 228 | + for(ColIter iter = tasks.begin(); iter != tasks.end(); ++iter) | |
| 229 | + { | |
| 230 | + taskList.RemoveTask(*iter); | |
| 231 | + } | |
| 232 | + | |
| 233 | + RenderTask defaultTask = taskList.GetTask(0); | |
| 234 | + defaultTask.SetSourceActor( stage.GetRootLayer() ); | |
| 235 | + defaultTask.SetTargetFrameBuffer( FrameBufferImage() ); | |
| 236 | + } | |
| 237 | + } | |
| 238 | + | |
| 239 | + unsigned int numChildren = layer.GetChildCount(); | |
| 240 | + | |
| 241 | + for(unsigned int i=0; i<numChildren; ++i) | |
| 242 | + { | |
| 243 | + layer.Remove( layer.GetChildAt(0) ); | |
| 244 | + } | |
| 245 | + | |
| 246 | + std::string data(fw.GetFileContents()); | |
| 247 | + | |
| 248 | + try | |
| 249 | + { | |
| 250 | + builder.LoadFromString(data); | |
| 251 | + } | |
| 252 | + catch(...) | |
| 253 | + { | |
| 254 | + builder.LoadFromString(ReplaceQuotes(JSON_BROKEN)); | |
| 255 | + } | |
| 256 | + | |
| 257 | + builder.AddActors( layer ); | |
| 258 | + | |
| 259 | + } | |
| 260 | + | |
| 261 | + | |
| 262 | + bool OnTimer(void) | |
| 263 | + { | |
| 264 | + if(fw.FileHasChanged()) | |
| 265 | + { | |
| 266 | + ReloadJsonFile( mBuilder, mRootLayer ); | |
| 267 | + } | |
| 268 | + | |
| 269 | + return true; | |
| 270 | + } | |
| 271 | + | |
| 272 | + // Process Key events to Quit on back-key | |
| 273 | + void OnKeyEvent( const KeyEvent& event ) | |
| 274 | + { | |
| 275 | + if( event.state == KeyEvent::Down ) | |
| 276 | + { | |
| 277 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) | |
| 278 | + { | |
| 279 | + Application::Get().Quit(); | |
| 280 | + } | |
| 281 | + } | |
| 282 | + } | |
| 283 | + | |
| 284 | + Builder mBuilder; | |
| 285 | +}; | |
| 286 | + | |
| 287 | +//------------------------------------------------------------------------------ | |
| 288 | +// | |
| 289 | +// | |
| 290 | +// | |
| 291 | +//------------------------------------------------------------------------------ | |
| 292 | +int main(int argc, char **argv) | |
| 293 | +{ | |
| 294 | + Application dali_app = Application::New(&argc, &argv); | |
| 295 | + | |
| 296 | + ExampleApp app(dali_app); | |
| 297 | + | |
| 298 | + | |
| 299 | + if(argc > 1) | |
| 300 | + { | |
| 301 | + std::cout << "Loading file:" << argc << " " << argv[1] << std::endl; | |
| 302 | + app.SetJSONFilename(argv[1]); | |
| 303 | + } | |
| 304 | + else | |
| 305 | + { | |
| 306 | + DALI_ASSERT_ALWAYS(!"Specify JSON file on command line\n"); | |
| 307 | + } | |
| 308 | + | |
| 309 | + dali_app.MainLoop(); | |
| 310 | + | |
| 311 | + return 0; | |
| 312 | +} | ... | ... |
examples/builder/examples.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +//------------------------------------------------------------------------------ | |
| 19 | +// | |
| 20 | +// | |
| 21 | +//------------------------------------------------------------------------------ | |
| 22 | + | |
| 23 | +#include "dali.h" | |
| 24 | +#include <dali-toolkit/dali-toolkit.h> | |
| 25 | +#include <dali-toolkit/public-api/builder/builder.h> | |
| 26 | +#include <dali-toolkit/public-api/builder/tree-node.h> | |
| 27 | +#include <dali-toolkit/public-api/builder/json-parser.h> | |
| 28 | +#include <map> | |
| 29 | +#include <string> | |
| 30 | +#include <fstream> | |
| 31 | +#include <streambuf> | |
| 32 | +#include <sstream> | |
| 33 | +#include <boost/scoped_ptr.hpp> | |
| 34 | +#include <dirent.h> | |
| 35 | +#include <stdio.h> | |
| 36 | + | |
| 37 | +//#include <boost/regex.hpp> | |
| 38 | +#include "sys/stat.h" | |
| 39 | +#include <ctime> | |
| 40 | + | |
| 41 | +#include <dali/integration-api/debug.h> | |
| 42 | +#include "../shared/view.h" | |
| 43 | + | |
| 44 | +#define TOKEN_STRING(x) #x | |
| 45 | + | |
| 46 | +using namespace Dali; | |
| 47 | +using namespace Dali::Toolkit; | |
| 48 | + | |
| 49 | +namespace | |
| 50 | +{ | |
| 51 | + | |
| 52 | +const char* BACKGROUND_IMAGE( "" ); | |
| 53 | +const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" ); | |
| 54 | +const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-change.png" ); | |
| 55 | + | |
| 56 | +std::string USER_DIRECTORY; | |
| 57 | + | |
| 58 | +std::string JSON_BROKEN(" \ | |
| 59 | +{ \ | |
| 60 | + 'stage': \ | |
| 61 | + [ \ | |
| 62 | + { \ | |
| 63 | + 'type':'TextView', \ | |
| 64 | + 'size': [50,50,1], \ | |
| 65 | + 'parent-origin': 'CENTER', \ | |
| 66 | + 'text':'COULD NOT LOAD JSON FILE' \ | |
| 67 | + } \ | |
| 68 | + ] \ | |
| 69 | +} \ | |
| 70 | +"); | |
| 71 | + | |
| 72 | +std::string ReplaceQuotes(const std::string &single_quoted) | |
| 73 | +{ | |
| 74 | + std::string s(single_quoted); | |
| 75 | + | |
| 76 | + // wrong as no embedded quote but had regex link problems | |
| 77 | + std::replace(s.begin(), s.end(), '\'', '"'); | |
| 78 | + | |
| 79 | + return s; | |
| 80 | +} | |
| 81 | + | |
| 82 | +std::string GetFileContents(const std::string &fn) | |
| 83 | +{ | |
| 84 | + std::ifstream t(fn.c_str()); | |
| 85 | + return std::string((std::istreambuf_iterator<char>(t)), | |
| 86 | + std::istreambuf_iterator<char>()); | |
| 87 | +}; | |
| 88 | + | |
| 89 | +typedef std::vector<std::string> FileList; | |
| 90 | + | |
| 91 | +void DirectoryFileList(const std::string& directory, FileList& files) | |
| 92 | +{ | |
| 93 | + DIR *d; | |
| 94 | + struct dirent *dir; | |
| 95 | + d = opendir(directory.c_str()); | |
| 96 | + if (d) | |
| 97 | + { | |
| 98 | + while ((dir = readdir(d)) != NULL) | |
| 99 | + { | |
| 100 | + if (dir->d_type == DT_REG) | |
| 101 | + { | |
| 102 | + files.push_back( directory + std::string(dir->d_name) ); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + | |
| 106 | + closedir(d); | |
| 107 | + } | |
| 108 | +} | |
| 109 | + | |
| 110 | +void DirectoryFilesByType(const std::string& dir, const std::string& fileType /* ie "json" */, FileList& files) | |
| 111 | +{ | |
| 112 | + typedef FileList Collection; | |
| 113 | + typedef FileList::iterator Iter; | |
| 114 | + | |
| 115 | + Collection allFiles; | |
| 116 | + DirectoryFileList(dir, allFiles); | |
| 117 | + | |
| 118 | + for(Iter iter = allFiles.begin(); iter != allFiles.end(); ++iter) | |
| 119 | + { | |
| 120 | + size_t pos = (*iter).rfind( '.' ); | |
| 121 | + if( pos != std::string::npos ) | |
| 122 | + { | |
| 123 | + if( (*iter).substr( pos+1 ) == fileType ) | |
| 124 | + { | |
| 125 | + files.push_back( (*iter) ); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + } | |
| 129 | +} | |
| 130 | + | |
| 131 | +const std::string ShortName( const std::string& name ) | |
| 132 | +{ | |
| 133 | + size_t pos = name.rfind( '/' ); | |
| 134 | + | |
| 135 | + if( pos != std::string::npos ) | |
| 136 | + { | |
| 137 | + return name.substr( pos ); | |
| 138 | + } | |
| 139 | + else | |
| 140 | + { | |
| 141 | + return name; | |
| 142 | + } | |
| 143 | +} | |
| 144 | + | |
| 145 | +static Vector3 SetItemSize(unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing) | |
| 146 | +{ | |
| 147 | + return Vector3(layoutWidth, 50, 1); | |
| 148 | +} | |
| 149 | + | |
| 150 | +//------------------------------------------------------------------------------ | |
| 151 | +// | |
| 152 | +// | |
| 153 | +// | |
| 154 | +//------------------------------------------------------------------------------ | |
| 155 | +class FileWatcher | |
| 156 | +{ | |
| 157 | +public: | |
| 158 | + FileWatcher(void); | |
| 159 | + ~FileWatcher(void); | |
| 160 | + explicit FileWatcher(const std::string &fn) { SetFilename(fn) ; }; | |
| 161 | + | |
| 162 | + void SetFilename(const std::string &fn); | |
| 163 | + std::string GetFilename() const; | |
| 164 | + | |
| 165 | + bool FileHasChanged(void); | |
| 166 | + std::string GetFileContents(void) const { return ::GetFileContents(mstringPath) ; }; | |
| 167 | + | |
| 168 | +private: | |
| 169 | + // compiler does | |
| 170 | + // FileWatcher(const FileWatcher&); | |
| 171 | + // FileWatcher &operator=(const FileWatcher &); | |
| 172 | + | |
| 173 | + std::time_t mLastTime; | |
| 174 | + std::string mstringPath; | |
| 175 | + | |
| 176 | +}; | |
| 177 | + | |
| 178 | +FileWatcher::FileWatcher(void) : mLastTime(0) | |
| 179 | +{ | |
| 180 | +} | |
| 181 | + | |
| 182 | +bool FileWatcher::FileHasChanged(void) | |
| 183 | +{ | |
| 184 | + struct stat buf; | |
| 185 | + | |
| 186 | + if(0 != stat(mstringPath.c_str(), &buf)) | |
| 187 | + { | |
| 188 | + return false; | |
| 189 | + } | |
| 190 | + else | |
| 191 | + { | |
| 192 | + if(buf.st_mtime > mLastTime) | |
| 193 | + { | |
| 194 | + mLastTime = buf.st_mtime; | |
| 195 | + return true; | |
| 196 | + } | |
| 197 | + else | |
| 198 | + { | |
| 199 | + mLastTime = buf.st_mtime; | |
| 200 | + return false; | |
| 201 | + } | |
| 202 | + } | |
| 203 | + | |
| 204 | + return false; | |
| 205 | +} | |
| 206 | + | |
| 207 | +FileWatcher::~FileWatcher() | |
| 208 | +{ | |
| 209 | +} | |
| 210 | + | |
| 211 | +void FileWatcher::SetFilename(const std::string &fn) | |
| 212 | +{ | |
| 213 | + mstringPath = fn; | |
| 214 | + FileHasChanged(); // update last time | |
| 215 | +} | |
| 216 | + | |
| 217 | +std::string FileWatcher::GetFilename(void) const | |
| 218 | +{ | |
| 219 | + return mstringPath; | |
| 220 | +} | |
| 221 | + | |
| 222 | + | |
| 223 | +} // anon namespace | |
| 224 | + | |
| 225 | + | |
| 226 | +//------------------------------------------------------------------------------ | |
| 227 | +// | |
| 228 | +// | |
| 229 | +// | |
| 230 | +//------------------------------------------------------------------------------ | |
| 231 | +class ExampleApp : public ConnectionTracker, public Toolkit::ItemFactory | |
| 232 | +{ | |
| 233 | +public: | |
| 234 | + ExampleApp(Application &app) : mApp(app) | |
| 235 | + { | |
| 236 | + app.InitSignal().Connect(this, &ExampleApp::Create); | |
| 237 | + } | |
| 238 | + | |
| 239 | + ~ExampleApp() {} | |
| 240 | + | |
| 241 | +public: | |
| 242 | + | |
| 243 | + void SetTitle(const std::string& title) | |
| 244 | + { | |
| 245 | + if(!mTitleActor) | |
| 246 | + { | |
| 247 | + mTitleActor = TextView::New(); | |
| 248 | + // Add title to the tool bar. | |
| 249 | + mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter ); | |
| 250 | + } | |
| 251 | + | |
| 252 | + Font font = Font::New(); | |
| 253 | + mTitleActor.SetText( title ); | |
| 254 | + mTitleActor.SetSize( font.MeasureText( title ) ); | |
| 255 | + mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle()); | |
| 256 | + } | |
| 257 | + | |
| 258 | + bool OnToolSelectLayout( Toolkit::Button button ) | |
| 259 | + { | |
| 260 | + bool on = mItemView.IsVisible(); | |
| 261 | + | |
| 262 | + if( on ) | |
| 263 | + { | |
| 264 | + LeaveSelection(); | |
| 265 | + } | |
| 266 | + else | |
| 267 | + { | |
| 268 | + EnterSelection(); | |
| 269 | + } | |
| 270 | + | |
| 271 | + return true; | |
| 272 | + } | |
| 273 | + | |
| 274 | + void LeaveSelection() | |
| 275 | + { | |
| 276 | + | |
| 277 | + } | |
| 278 | + | |
| 279 | + void EnterSelection() | |
| 280 | + { | |
| 281 | + Stage stage = Stage::GetCurrent(); | |
| 282 | + | |
| 283 | + if( mItemView ) | |
| 284 | + { | |
| 285 | + stage.Remove( mItemView ); | |
| 286 | + } | |
| 287 | + | |
| 288 | + mFiles.clear(); | |
| 289 | + | |
| 290 | + mItemView = ItemView::New(*this); | |
| 291 | + stage.Add( mItemView ); | |
| 292 | + mItemView.SetParentOrigin(ParentOrigin::CENTER); | |
| 293 | + mItemView.SetAnchorPoint(AnchorPoint::CENTER); | |
| 294 | + mGridLayout = GridLayout::New(); | |
| 295 | + mGridLayout->SetNumberOfColumns(1); | |
| 296 | + | |
| 297 | + mGridLayout->SetItemSizeFunction(SetItemSize); | |
| 298 | + | |
| 299 | + mGridLayout->SetTopMargin(DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight); | |
| 300 | + | |
| 301 | + mItemView.AddLayout(*mGridLayout); | |
| 302 | + | |
| 303 | + Vector3 size(stage.GetSize()); | |
| 304 | + mItemView.ActivateLayout(0, size, 0.0f/*immediate*/); | |
| 305 | + mItemView.SetKeyboardFocusable( true ); | |
| 306 | + | |
| 307 | + mFiles.clear(); | |
| 308 | + FileList files; | |
| 309 | + | |
| 310 | + if( USER_DIRECTORY.size() ) | |
| 311 | + { | |
| 312 | + DirectoryFilesByType( USER_DIRECTORY, "json", files ); | |
| 313 | + } | |
| 314 | + else | |
| 315 | + { | |
| 316 | + DirectoryFilesByType( DALI_SCRIPT_DIR, "json", files ); | |
| 317 | + } | |
| 318 | + | |
| 319 | + std::sort(files.begin(), files.end()); | |
| 320 | + | |
| 321 | + ItemId itemId = 0; | |
| 322 | + for(FileList::iterator iter = files.begin(); iter != files.end(); ++iter) | |
| 323 | + { | |
| 324 | + JsonParser parser = JsonParser::New(); | |
| 325 | + | |
| 326 | + std::string data( GetFileContents( *iter ) ); | |
| 327 | + | |
| 328 | + parser.Parse( data ); | |
| 329 | + | |
| 330 | + if( parser.ParseError() ) | |
| 331 | + { | |
| 332 | + std::cout << "Parser Error:" << *iter << std::endl; | |
| 333 | + std::cout << parser.GetErrorLineNumber() << "(" << parser.GetErrorColumn() << "):" << parser.GetErrorDescription() << std::endl; | |
| 334 | + exit(1); | |
| 335 | + } | |
| 336 | + | |
| 337 | + if( parser.GetRoot() ) | |
| 338 | + { | |
| 339 | + if( const TreeNode* node = parser.GetRoot()->Find("stage") ) | |
| 340 | + { | |
| 341 | + // only those with a stage section | |
| 342 | + if( node->Size() ) | |
| 343 | + { | |
| 344 | + mFiles.push_back( *iter ); | |
| 345 | + | |
| 346 | + mItemView.InsertItem( Item(itemId, | |
| 347 | + MenuItem( ShortName( *iter ) ) ), | |
| 348 | + 0.5f ); | |
| 349 | + | |
| 350 | + itemId++; | |
| 351 | + } | |
| 352 | + else | |
| 353 | + { | |
| 354 | + std::cout << "Ignored file (stage has no nodes?):" << *iter << std::endl; | |
| 355 | + } | |
| 356 | + } | |
| 357 | + else | |
| 358 | + { | |
| 359 | + std::cout << "Ignored file (no stage section):" << *iter << std::endl; | |
| 360 | + } | |
| 361 | + } | |
| 362 | + } | |
| 363 | + | |
| 364 | + mTapDetector = TapGestureDetector::New(); | |
| 365 | + | |
| 366 | + for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i ) | |
| 367 | + { | |
| 368 | + mTapDetector.Attach( mItemView.GetChildAt(i) ); | |
| 369 | + } | |
| 370 | + | |
| 371 | + mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap ); | |
| 372 | + | |
| 373 | + // Display item view on the stage | |
| 374 | + stage.Add( mItemView ); | |
| 375 | + | |
| 376 | + mItemView.SetVisible( true ); | |
| 377 | + mBuilderLayer.SetVisible( false ); | |
| 378 | + | |
| 379 | + SetTitle("Select"); | |
| 380 | + | |
| 381 | + // Itemview renderes the previous items unless its scrolled. Not sure why at the moment so we force a scroll | |
| 382 | + mItemView.ScrollToItem(0, 0); | |
| 383 | + | |
| 384 | + } | |
| 385 | + | |
| 386 | + void ExitSelection() | |
| 387 | + { | |
| 388 | + mTapDetector.Reset(); | |
| 389 | + | |
| 390 | + mItemView.SetVisible( false ); | |
| 391 | + mBuilderLayer.SetVisible( true ); | |
| 392 | + | |
| 393 | + SetTitle("View"); | |
| 394 | + } | |
| 395 | + | |
| 396 | + void OnTap( Actor actor, TapGesture tap ) | |
| 397 | + { | |
| 398 | + ItemId id = mItemView.GetItemId( actor ); | |
| 399 | + | |
| 400 | + LoadFromFileList( id ); | |
| 401 | + } | |
| 402 | + | |
| 403 | + Actor MenuItem(const std::string& text) | |
| 404 | + { | |
| 405 | + TextView t = TextView::New(); | |
| 406 | + t.SetMarkupProcessingEnabled(true); | |
| 407 | + t.SetText( std::string("<font size=6>") + ShortName( text ) + std::string("</font>") ); | |
| 408 | + t.SetTextAlignment( Alignment::HorizontalLeft ); | |
| 409 | + return t; | |
| 410 | + } | |
| 411 | + | |
| 412 | + bool OnTimer() | |
| 413 | + { | |
| 414 | + if( mFileWatcher.FileHasChanged() ) | |
| 415 | + { | |
| 416 | + LoadFromFile( mFileWatcher.GetFilename() ); | |
| 417 | + } | |
| 418 | + | |
| 419 | + return true; | |
| 420 | + } | |
| 421 | + | |
| 422 | + void ReloadJsonFile(const std::string& filename, Builder& builder, Layer& layer) | |
| 423 | + { | |
| 424 | + Stage stage = Stage::GetCurrent(); | |
| 425 | + | |
| 426 | + builder = Builder::New(); | |
| 427 | + | |
| 428 | + PropertyValueMap defaultDirs; | |
| 429 | + defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR; | |
| 430 | + defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ] = DALI_MODEL_DIR; | |
| 431 | + defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR; | |
| 432 | + | |
| 433 | + builder.AddConstants( defaultDirs ); | |
| 434 | + | |
| 435 | + // render tasks may have been setup last load so remove them | |
| 436 | + RenderTaskList taskList = stage.GetRenderTaskList(); | |
| 437 | + if( taskList.GetTaskCount() > 1 ) | |
| 438 | + { | |
| 439 | + typedef std::vector<RenderTask> Collection; | |
| 440 | + typedef Collection::iterator ColIter; | |
| 441 | + Collection tasks; | |
| 442 | + | |
| 443 | + for(unsigned int i = 1; i < taskList.GetTaskCount(); ++i) | |
| 444 | + { | |
| 445 | + tasks.push_back( taskList.GetTask(i) ); | |
| 446 | + } | |
| 447 | + | |
| 448 | + for(ColIter iter = tasks.begin(); iter != tasks.end(); ++iter) | |
| 449 | + { | |
| 450 | + taskList.RemoveTask(*iter); | |
| 451 | + } | |
| 452 | + | |
| 453 | + RenderTask defaultTask = taskList.GetTask(0); | |
| 454 | + defaultTask.SetSourceActor( stage.GetRootLayer() ); | |
| 455 | + defaultTask.SetTargetFrameBuffer( FrameBufferImage() ); | |
| 456 | + } | |
| 457 | + | |
| 458 | + unsigned int numChildren = layer.GetChildCount(); | |
| 459 | + | |
| 460 | + for(unsigned int i=0; i<numChildren; ++i) | |
| 461 | + { | |
| 462 | + layer.Remove( layer.GetChildAt(0) ); | |
| 463 | + } | |
| 464 | + | |
| 465 | + std::string data(GetFileContents(filename)); | |
| 466 | + | |
| 467 | + try | |
| 468 | + { | |
| 469 | + builder.LoadFromString(data); | |
| 470 | + } | |
| 471 | + catch(...) | |
| 472 | + { | |
| 473 | + builder.LoadFromString(ReplaceQuotes(JSON_BROKEN)); | |
| 474 | + } | |
| 475 | + | |
| 476 | + builder.AddActors( layer ); | |
| 477 | + | |
| 478 | + } | |
| 479 | + | |
| 480 | + | |
| 481 | + void LoadFromFileList( size_t index ) | |
| 482 | + { | |
| 483 | + if( index < mFiles.size()) | |
| 484 | + { | |
| 485 | + const std::string& name = mFiles[index]; | |
| 486 | + mFileWatcher.SetFilename( name ); | |
| 487 | + LoadFromFile( name ); | |
| 488 | + } | |
| 489 | + } | |
| 490 | + | |
| 491 | + void LoadFromFile( const std::string& name ) | |
| 492 | + { | |
| 493 | + ReloadJsonFile( name, mBuilder, mBuilderLayer ); | |
| 494 | + | |
| 495 | + // do this here as GetCurrentSize() | |
| 496 | + mBuilderLayer.SetParentOrigin(ParentOrigin::CENTER); | |
| 497 | + mBuilderLayer.SetAnchorPoint(AnchorPoint::CENTER); | |
| 498 | + Dali::Vector3 size = Stage::GetCurrent().GetRootLayer().GetCurrentSize(); | |
| 499 | + size.y -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight; | |
| 500 | + mBuilderLayer.SetSize( size ); | |
| 501 | + | |
| 502 | + mBuilderLayer.LowerToBottom(); | |
| 503 | + Stage::GetCurrent().GetRootLayer().RaiseToTop(); | |
| 504 | + | |
| 505 | + ExitSelection(); | |
| 506 | + } | |
| 507 | + | |
| 508 | + void Create(Application& app) | |
| 509 | + { | |
| 510 | + Stage stage = Stage::GetCurrent(); | |
| 511 | + | |
| 512 | + Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleApp::OnKeyEvent); | |
| 513 | + | |
| 514 | + Layer contents = DemoHelper::CreateView( app, | |
| 515 | + mView, | |
| 516 | + mToolBar, | |
| 517 | + BACKGROUND_IMAGE, | |
| 518 | + TOOLBAR_IMAGE, | |
| 519 | + "" ); | |
| 520 | + | |
| 521 | + SetTitle("Builder"); | |
| 522 | + | |
| 523 | + mBuilderLayer = Layer::New(); | |
| 524 | + stage.GetRootLayer().Add(mBuilderLayer); | |
| 525 | + | |
| 526 | + | |
| 527 | + // Create an edit mode button. (left of toolbar) | |
| 528 | + Toolkit::PushButton editButton = Toolkit::PushButton::New(); | |
| 529 | + editButton.SetBackgroundImage( Image::New( EDIT_IMAGE ) ); | |
| 530 | + editButton.ClickedSignal().Connect( this, &ExampleApp::OnToolSelectLayout); | |
| 531 | + editButton.SetLeaveRequired( true ); | |
| 532 | + mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | |
| 533 | + | |
| 534 | + EnterSelection(); | |
| 535 | + | |
| 536 | + mTimer = Timer::New( 500 ); // ms | |
| 537 | + mTimer.TickSignal().Connect( this, &ExampleApp::OnTimer); | |
| 538 | + mTimer.Start(); | |
| 539 | + | |
| 540 | + } // Create(app) | |
| 541 | + | |
| 542 | + virtual unsigned int GetNumberOfItems() | |
| 543 | + { | |
| 544 | + return mFiles.size(); | |
| 545 | + } | |
| 546 | + | |
| 547 | + virtual Actor NewItem(unsigned int itemId) | |
| 548 | + { | |
| 549 | + DALI_ASSERT_DEBUG( itemId < mFiles.size() ); | |
| 550 | + return MenuItem( ShortName( mFiles[itemId] ) ); | |
| 551 | + } | |
| 552 | + | |
| 553 | + /** | |
| 554 | + * Main key event handler | |
| 555 | + */ | |
| 556 | + void OnKeyEvent(const KeyEvent& event) | |
| 557 | + { | |
| 558 | + if(event.state == KeyEvent::Down) | |
| 559 | + { | |
| 560 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | |
| 561 | + { | |
| 562 | + mApp.Quit(); | |
| 563 | + } | |
| 564 | + } | |
| 565 | + } | |
| 566 | + | |
| 567 | +private: | |
| 568 | + Application& mApp; | |
| 569 | + | |
| 570 | + GridLayoutPtr mGridLayout; | |
| 571 | + ItemView mItemView; | |
| 572 | + | |
| 573 | + Toolkit::View mView; | |
| 574 | + unsigned int mOrientation; | |
| 575 | + | |
| 576 | + Toolkit::ToolBar mToolBar; | |
| 577 | + TextView mTitleActor; ///< The Toolbar's Title. | |
| 578 | + | |
| 579 | + Layer mBuilderLayer; | |
| 580 | + | |
| 581 | + Toolkit::Popup mMenu; | |
| 582 | + | |
| 583 | + TapGestureDetector mTapDetector; | |
| 584 | + | |
| 585 | + // builder | |
| 586 | + Builder mBuilder; | |
| 587 | + | |
| 588 | + FileList mFiles; | |
| 589 | + | |
| 590 | + FileWatcher mFileWatcher; | |
| 591 | + Timer mTimer; | |
| 592 | + | |
| 593 | + | |
| 594 | +}; | |
| 595 | + | |
| 596 | +//------------------------------------------------------------------------------ | |
| 597 | +// | |
| 598 | +// | |
| 599 | +// | |
| 600 | +//------------------------------------------------------------------------------ | |
| 601 | +int main(int argc, char **argv) | |
| 602 | +{ | |
| 603 | + if(argc > 1) | |
| 604 | + { | |
| 605 | + USER_DIRECTORY = argv[1]; | |
| 606 | + } | |
| 607 | + | |
| 608 | + Application app = Application::New(&argc, &argv); | |
| 609 | + | |
| 610 | + ExampleApp dali_app(app); | |
| 611 | + | |
| 612 | + app.MainLoop(); | |
| 613 | + | |
| 614 | + return 0; | |
| 615 | +} | ... | ... |