Commit d23323bc5b8e876b1b873eef2f53b47aa97d318d
1 parent
a523d825
A simple control using visuals
Example code for creating a control using visuals with states defined in the stylesheet Change-Id: Ief41cfad7c3eeb8d78bd6540db36e4b761b28e5f
Showing
16 changed files
with
867 additions
and
0 deletions
build/tizen/CMakeLists.txt
| ... | ... | @@ -103,6 +103,7 @@ CONFIGURE_FILE( resources-location.in ${DEMO_SHARED}/resources-location.cpp ) |
| 103 | 103 | CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/demo-theme.json.in ${LOCAL_STYLE_DIR}/demo-theme.json ) |
| 104 | 104 | CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/contact-cards-example-theme.json.in ${LOCAL_STYLE_DIR}/contact-cards-example-theme.json ) |
| 105 | 105 | CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/progress-bar-example-theme.json.in ${LOCAL_STYLE_DIR}/progress-bar-example-theme.json ) |
| 106 | +CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/simple-example-theme.json.in ${LOCAL_STYLE_DIR}/simple-example-theme.json ) | |
| 106 | 107 | CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/style-example-theme-one.json.in ${LOCAL_STYLE_DIR}/style-example-theme-one.json ) |
| 107 | 108 | CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/style-example-theme-two.json.in ${LOCAL_STYLE_DIR}/style-example-theme-two.json ) |
| 108 | 109 | CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/style-example-theme-three.json.in ${LOCAL_STYLE_DIR}/style-example-theme-three.json ) | ... | ... |
com.samsung.dali-demo.xml
| ... | ... | @@ -32,6 +32,9 @@ |
| 32 | 32 | <ui-application appid="cube-transition-effect.example" exec="/usr/apps/com.samsung.dali-demo/bin/cube-transition-effect.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 33 | 33 | <label>Cube transition effect</label> |
| 34 | 34 | </ui-application> |
| 35 | + <ui-application appid="simple-visuals-control.example" exec="/usr/apps/com.samsung.dali-demo/bin/simple-visuals-control.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | |
| 36 | + <label>Simple Control</label> | |
| 37 | + </ui-application> | |
| 35 | 38 | <ui-application appid="dissolve-effect.example" exec="/usr/apps/com.samsung.dali-demo/bin/dissolve-effect.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 36 | 39 | <label>Dissolve effect</label> |
| 37 | 40 | </ui-application> | ... | ... |
examples/simple-visuals-control/my-control-impl.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 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 | +// CLASS HEADER | |
| 18 | + | |
| 19 | +#include "my-control-impl.h" | |
| 20 | + | |
| 21 | +// EXTERNAL INCLUDES | |
| 22 | + | |
| 23 | +#include <dali/public-api/object/type-registry-helper.h> | |
| 24 | +#include <dali/devel-api/scripting/enum-helper.h> | |
| 25 | +#include <dali-toolkit/dali-toolkit.h> | |
| 26 | +#include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h> | |
| 27 | +#include <dali-toolkit/devel-api/visual-factory/visual-factory.h> | |
| 28 | +#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> | |
| 29 | + | |
| 30 | +using namespace Dali; | |
| 31 | +using namespace Dali::Toolkit; | |
| 32 | + | |
| 33 | +namespace Demo | |
| 34 | +{ | |
| 35 | +namespace Internal | |
| 36 | +{ | |
| 37 | + | |
| 38 | +namespace | |
| 39 | +{ | |
| 40 | + | |
| 41 | + | |
| 42 | +Dali::BaseHandle Create() | |
| 43 | +{ | |
| 44 | + return Demo::MyControl::New(); | |
| 45 | +} | |
| 46 | + | |
| 47 | +// Required code for Property set up. | |
| 48 | + | |
| 49 | +DALI_TYPE_REGISTRATION_BEGIN( MyControl, Dali::Toolkit::Control, Create ); | |
| 50 | + | |
| 51 | +DALI_PROPERTY_REGISTRATION( Demo, MyControl, "iconVisual", MAP, ICON_VISUAL ) | |
| 52 | + | |
| 53 | +DALI_TYPE_REGISTRATION_END(); | |
| 54 | + | |
| 55 | +// Add an enum to string conversion entry for the control's visuals. In this case just the icon visual. | |
| 56 | +// Enables Setting of the property using enums or strings. | |
| 57 | +DALI_ENUM_TO_STRING_TABLE_BEGIN( VISUAL_PROPERTIES ) | |
| 58 | +{ "iconVisual", Demo::MyControl::Property::ICON_VISUAL }, | |
| 59 | +DALI_ENUM_TO_STRING_TABLE_END( VISUAL_PROPERTIES ) | |
| 60 | + | |
| 61 | + | |
| 62 | +} // anonymous namespace | |
| 63 | + | |
| 64 | + | |
| 65 | +Internal::MyControl::MyControl() | |
| 66 | +: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ) | |
| 67 | +{ | |
| 68 | +} | |
| 69 | + | |
| 70 | +Demo::MyControl Internal::MyControl::New() | |
| 71 | +{ | |
| 72 | + IntrusivePtr<Internal::MyControl> impl = new Internal::MyControl(); | |
| 73 | + Demo::MyControl handle = Demo::MyControl( *impl ); | |
| 74 | + impl->Initialize(); | |
| 75 | + return handle; | |
| 76 | +} | |
| 77 | + | |
| 78 | +void MyControl::OnInitialize() | |
| 79 | +{ | |
| 80 | + Dali::Actor self = Self(); | |
| 81 | + self.SetKeyboardFocusable( true ); | |
| 82 | +} | |
| 83 | + | |
| 84 | +void MyControl::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) | |
| 85 | +{ | |
| 86 | + Demo::MyControl myControl = Demo::MyControl::DownCast( Dali::BaseHandle( object ) ); | |
| 87 | + | |
| 88 | + if( myControl ) | |
| 89 | + { | |
| 90 | + MyControl& impl = GetImpl( myControl ); | |
| 91 | + switch ( index ) | |
| 92 | + { | |
| 93 | + case Demo::MyControl::Property::ICON_VISUAL: | |
| 94 | + { | |
| 95 | + Toolkit::Visual::Base iconVisual; | |
| 96 | + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); | |
| 97 | + Property::Map *map = value.GetMap(); | |
| 98 | + if( map && !map->Empty() ) | |
| 99 | + { | |
| 100 | + iconVisual = visualFactory.CreateVisual( *map ); | |
| 101 | + } | |
| 102 | + | |
| 103 | + if ( iconVisual ) | |
| 104 | + { | |
| 105 | + impl.RegisterVisual( index, iconVisual ); | |
| 106 | + } | |
| 107 | + break; | |
| 108 | + } | |
| 109 | + } | |
| 110 | + } | |
| 111 | +} | |
| 112 | + | |
| 113 | +Property::Value MyControl::GetProperty( BaseObject* object, Property::Index propertyIndex ) | |
| 114 | +{ | |
| 115 | + Property::Value value; | |
| 116 | + | |
| 117 | + Demo::MyControl myControl = Demo::MyControl::DownCast( Dali::BaseHandle( object ) ); | |
| 118 | + | |
| 119 | + if ( myControl ) | |
| 120 | + { | |
| 121 | + switch ( propertyIndex ) | |
| 122 | + { | |
| 123 | + case Demo::MyControl::Property::ICON_VISUAL: | |
| 124 | + { | |
| 125 | + Property::Map map; | |
| 126 | + Toolkit::Visual::Base visual = GetImpl( myControl ).GetVisual( propertyIndex ); | |
| 127 | + if ( visual ) | |
| 128 | + { | |
| 129 | + visual.CreatePropertyMap( map ); // Creates a Property map containing the Visual that ICON_VISUAL currently is. Can change if state changes. | |
| 130 | + value = map; | |
| 131 | + } | |
| 132 | + break; | |
| 133 | + } | |
| 134 | + default: | |
| 135 | + break; | |
| 136 | + } | |
| 137 | + } | |
| 138 | + | |
| 139 | + return value; | |
| 140 | +} | |
| 141 | + | |
| 142 | +} // Internal | |
| 143 | +} // Demo | ... | ... |
examples/simple-visuals-control/my-control-impl.h
0 → 100644
| 1 | +#ifndef DALI_DEMO_INTERNAL_MY_CONTROL_IMPL_H | |
| 2 | +#define DALI_DEMO_INTERNAL_MY_CONTROL_IMPL_H | |
| 3 | + | |
| 4 | +/* | |
| 5 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 6 | + * | |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | + * you may not use this file except in compliance with the License. | |
| 9 | + * You may obtain a copy of the License at | |
| 10 | + * | |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | + * | |
| 13 | + * Unless required by applicable law or agreed to in writing, software | |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | + * See the License for the specific language governing permissions and | |
| 17 | + * limitations under the License. | |
| 18 | + */ | |
| 19 | + | |
| 20 | +// CLASS HEADER | |
| 21 | +#include "my-control.h" | |
| 22 | + | |
| 23 | +// EXTERNAL INCLUDES | |
| 24 | +#include <dali-toolkit/public-api/controls/control-impl.h> | |
| 25 | +#include <dali-toolkit/devel-api/visual-factory/visual-base.h> | |
| 26 | + | |
| 27 | +namespace Demo | |
| 28 | +{ | |
| 29 | + | |
| 30 | +namespace Internal // To use TypeRegistry, handle and body classes need the same name | |
| 31 | +{ | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * @brief A Simple Control to show use of visuals with a style sheet and changing visuals with a state change | |
| 35 | + */ | |
| 36 | + | |
| 37 | +class MyControl : public Dali::Toolkit::Internal::Control | |
| 38 | +{ | |
| 39 | +public: | |
| 40 | + /** | |
| 41 | + * @brief Instantiate a new ContentView object | |
| 42 | + */ | |
| 43 | + static Demo::MyControl New(); | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @brief Default constructor | |
| 47 | + */ | |
| 48 | + MyControl(); | |
| 49 | + | |
| 50 | +public: // Properties | |
| 51 | + /** | |
| 52 | + * @brief Called when a property of an object of this type is set. | |
| 53 | + * | |
| 54 | + * @param[in] object The object whose property is set. | |
| 55 | + * @param[in] index The property index. | |
| 56 | + * @param[in] value The new property value. | |
| 57 | + */ | |
| 58 | + static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value ); | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * @brief Called to retrieve a property of an object of this type. | |
| 62 | + * | |
| 63 | + * @param[in] object The object whose property is to be retrieved. | |
| 64 | + * @param[in] index The property index. | |
| 65 | + * @return The current value of the property. | |
| 66 | + */ | |
| 67 | + static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex ); | |
| 68 | + | |
| 69 | +private: // From Control | |
| 70 | + /** | |
| 71 | + * @copydoc Toolkit::Control::OnInitialize() | |
| 72 | + */ | |
| 73 | + virtual void OnInitialize(); | |
| 74 | + | |
| 75 | +private: | |
| 76 | + /** | |
| 77 | + * undefined constructor and operator= | |
| 78 | + */ | |
| 79 | + MyControl( const MyControl& ); | |
| 80 | + MyControl& operator=( const MyControl& ); | |
| 81 | + | |
| 82 | +private: | |
| 83 | +}; | |
| 84 | + | |
| 85 | +} // Internal | |
| 86 | + | |
| 87 | +inline Internal::MyControl& GetImpl( Demo::MyControl& handle ) | |
| 88 | +{ | |
| 89 | + DALI_ASSERT_ALWAYS( handle ); | |
| 90 | + Dali::RefObject& object = handle.GetImplementation(); | |
| 91 | + return static_cast<Internal::MyControl&>(object); | |
| 92 | +} | |
| 93 | + | |
| 94 | +inline const Internal::MyControl& GetImpl( const Demo::MyControl& handle ) | |
| 95 | +{ | |
| 96 | + DALI_ASSERT_ALWAYS( handle ); | |
| 97 | + const Dali::RefObject& object = handle.GetImplementation(); | |
| 98 | + return static_cast<const Internal::MyControl&>(object); | |
| 99 | +} | |
| 100 | + | |
| 101 | +} // Demo | |
| 102 | + | |
| 103 | +#endif // DALI_DEMO_INTERNAL_MY_CONTROL_IMPL_H | ... | ... |
examples/simple-visuals-control/my-control.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 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 | +// CLASS HEADER | |
| 18 | +#include "my-control.h" | |
| 19 | + | |
| 20 | +// INTERNAL INCLUDES | |
| 21 | +#include "my-control-impl.h" | |
| 22 | + | |
| 23 | +namespace Demo | |
| 24 | +{ | |
| 25 | + | |
| 26 | +MyControl::MyControl() | |
| 27 | +{ | |
| 28 | +} | |
| 29 | + | |
| 30 | +MyControl::MyControl( const MyControl& control ) | |
| 31 | +: Control( control ) | |
| 32 | +{ | |
| 33 | +} | |
| 34 | + | |
| 35 | +MyControl& MyControl::operator= ( const MyControl& rhs ) | |
| 36 | +{ | |
| 37 | + if( &rhs != this ) | |
| 38 | + { | |
| 39 | + Control::operator=( rhs ); | |
| 40 | + } | |
| 41 | + return *this; | |
| 42 | +} | |
| 43 | + | |
| 44 | +MyControl::~MyControl() | |
| 45 | +{ | |
| 46 | +} | |
| 47 | + | |
| 48 | +MyControl MyControl::New() | |
| 49 | +{ | |
| 50 | + MyControl control = Internal::MyControl::New(); | |
| 51 | + return control; | |
| 52 | +} | |
| 53 | + | |
| 54 | +MyControl MyControl::DownCast( BaseHandle handle ) | |
| 55 | +{ | |
| 56 | + return Control::DownCast< MyControl, Internal::MyControl > ( handle ); | |
| 57 | +} | |
| 58 | + | |
| 59 | +MyControl::MyControl( Internal::MyControl& implementation ) | |
| 60 | +: Control( implementation ) | |
| 61 | +{ | |
| 62 | +} | |
| 63 | + | |
| 64 | +MyControl::MyControl( Dali::Internal::CustomActor* internal ) | |
| 65 | +: Control( internal ) | |
| 66 | +{ | |
| 67 | + VerifyCustomActorPointer< Internal::MyControl >( internal ) ; | |
| 68 | +} | |
| 69 | + | |
| 70 | + | |
| 71 | +} //namespace Demo | ... | ... |
examples/simple-visuals-control/my-control.h
0 → 100644
| 1 | +#ifndef DALI_DEMO_MY_CONTROL_H | |
| 2 | +#define DALI_DEMO_MY_CONTROL_H | |
| 3 | + | |
| 4 | +/* | |
| 5 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 6 | + * | |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | + * you may not use this file except in compliance with the License. | |
| 9 | + * You may obtain a copy of the License at | |
| 10 | + * | |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | + * | |
| 13 | + * Unless required by applicable law or agreed to in writing, software | |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | + * See the License for the specific language governing permissions and | |
| 17 | + * limitations under the License. | |
| 18 | + */ | |
| 19 | + | |
| 20 | +#include <dali-toolkit/dali-toolkit.h> | |
| 21 | +#include <string> | |
| 22 | + | |
| 23 | +namespace Demo | |
| 24 | +{ | |
| 25 | + | |
| 26 | +namespace Internal | |
| 27 | +{ | |
| 28 | +class MyControl; | |
| 29 | +} | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * @brief MyControl is an example control, | |
| 33 | + * | |
| 34 | + * @details It's purpose is to show how to create a simple control to work with the style sheet and state changes. | |
| 35 | + * States changes includes Normal, Focused and Disabled, this example uses the style sheet to set visuals for Normal and Focused states. | |
| 36 | + * When the Focus manager changes the control to be focused the visual displayed is changed and vice versa. | |
| 37 | + * | |
| 38 | + * The visual has the property name ICON_VISUAL with the style sheet string equivalent of "iconVisual" | |
| 39 | + * | |
| 40 | + */ | |
| 41 | + | |
| 42 | +class MyControl : public Dali::Toolkit::Control | |
| 43 | +{ | |
| 44 | +public: | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * The start and end property ranges for this Control | |
| 48 | + * My control can use properties from Toolkit::Control as it is derived from it. As control is derived from Actor, MyControl can also use Dali::Actor Properties. | |
| 49 | + * | |
| 50 | + * To ensure that the Property indexes from MyControl do not shadow any from Control we start it's index from the end of Toolkit::Control's indexes. | |
| 51 | + * | |
| 52 | + * Toolkit::Control would have done the same with Actor. | |
| 53 | + * | |
| 54 | + * The end index for this control is set to the start index + 1000 hence MyControl can have 1000 property indexes. | |
| 55 | + * | |
| 56 | + * PROPERTY_END_INDEX for MyControl is public, if another control is derived from it then if can specify MyControl::PROPERTY_END_INDEX+1 to start it's | |
| 57 | + * indexing after MyControls last index. | |
| 58 | + */ | |
| 59 | + enum PropertyRange | |
| 60 | + { | |
| 61 | + PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1, | |
| 62 | + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, | |
| 63 | + ANIMATABLE_PROPERTY_START_INDEX = Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, | |
| 64 | + ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX+1000 | |
| 65 | + }; | |
| 66 | + | |
| 67 | + struct Property | |
| 68 | + { | |
| 69 | + enum | |
| 70 | + { | |
| 71 | + /** | |
| 72 | + * @brief name "iconVisual", type string if it is a url, map otherwise | |
| 73 | + * @details Sets the icon visual to be displayed by the control | |
| 74 | + */ | |
| 75 | + ICON_VISUAL = PROPERTY_START_INDEX | |
| 76 | + }; | |
| 77 | + }; | |
| 78 | + | |
| 79 | +public: // Construction / destruction | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @brief Create an uninitialized handle | |
| 83 | + */ | |
| 84 | + MyControl(); | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @brief Create a new MyControl | |
| 88 | + */ | |
| 89 | + static MyControl New(); | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * @brief Destructor. This is non-virtual since derived Handle types must not contain data or virtual methods | |
| 93 | + */ | |
| 94 | + ~MyControl(); | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * @brief Copy Constructor | |
| 98 | + * | |
| 99 | + * @param[in] shadowButton the handle of the control to copy | |
| 100 | + */ | |
| 101 | + MyControl( const MyControl& shadowButton ); | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * @brief Assignment Operator | |
| 105 | + * | |
| 106 | + * @param[in] shadowButton the source of the assignment | |
| 107 | + */ | |
| 108 | + MyControl& operator=( const MyControl& shadowButton ); | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * @brief Downcast | |
| 112 | + * | |
| 113 | + * @param[in] shadowButton the handle of control to downcast to MyControl | |
| 114 | + */ | |
| 115 | + static MyControl DownCast( BaseHandle handle ); | |
| 116 | + | |
| 117 | + | |
| 118 | +public: // // Not intended for application developers | |
| 119 | + | |
| 120 | + /// @cond internal | |
| 121 | + /** | |
| 122 | + * @brief Create a handle from an implementation | |
| 123 | + */ | |
| 124 | + MyControl( Internal::MyControl& implementation ); | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * @brief Allow the creation of an ShadowButton handle from an internal CustomActor pointer | |
| 128 | + */ | |
| 129 | + MyControl( Dali::Internal::CustomActor* internal ); | |
| 130 | + /// @endcond | |
| 131 | +}; | |
| 132 | + | |
| 133 | +} // namespace Demo | |
| 134 | + | |
| 135 | +#endif // DALI_DEMO_MY_CONTROL_H | ... | ... |
examples/simple-visuals-control/simple-visuals-application.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 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 | +// CLASS HEADER | |
| 18 | +#include "my-control.h" | |
| 19 | + | |
| 20 | +// EXTERNAL INCLUDES | |
| 21 | +#include <dali-toolkit/dali-toolkit.h> | |
| 22 | +#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> | |
| 23 | +#include <dali-toolkit/devel-api/visuals/text-visual-properties.h> | |
| 24 | +#include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h> | |
| 25 | +#include <dali/integration-api/events/touch-event-integ.h> | |
| 26 | +#include <cstdio> | |
| 27 | +#include <sstream> | |
| 28 | + | |
| 29 | +// INTERNAL INCLUDES | |
| 30 | +#include "simple-visuals-application.h" | |
| 31 | + | |
| 32 | +using namespace Dali; | |
| 33 | +using namespace Dali::Toolkit; | |
| 34 | + | |
| 35 | +namespace | |
| 36 | +{ | |
| 37 | + | |
| 38 | +} | |
| 39 | + | |
| 40 | +namespace Demo | |
| 41 | +{ | |
| 42 | + | |
| 43 | +const char* ICON_IMAGE( DEMO_IMAGE_DIR "application-icon-13.png" ); | |
| 44 | + | |
| 45 | +SimpleVisualsApplication::SimpleVisualsApplication( Application& application ) | |
| 46 | +: mApplication( application ), | |
| 47 | + mMyControl() | |
| 48 | +{ | |
| 49 | + application.InitSignal().Connect( this, &SimpleVisualsApplication::Create ); | |
| 50 | +} | |
| 51 | + | |
| 52 | +Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction ) | |
| 53 | +{ | |
| 54 | + Actor nextFocusActor = proposed; | |
| 55 | + | |
| 56 | + if( !current && !proposed ) | |
| 57 | + { | |
| 58 | + // Set the initial focus to the first tile in the current page should be focused. | |
| 59 | + nextFocusActor = mMyControl; | |
| 60 | + } | |
| 61 | + else | |
| 62 | + { | |
| 63 | + if ( current == mMyControl ) | |
| 64 | + { | |
| 65 | + nextFocusActor = mMyControl2; | |
| 66 | + } | |
| 67 | + else | |
| 68 | + { | |
| 69 | + nextFocusActor = mMyControl; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + return nextFocusActor; | |
| 74 | +} | |
| 75 | + | |
| 76 | + | |
| 77 | +void SimpleVisualsApplication::OnKeyEvent( const KeyEvent& keyEvent ) | |
| 78 | +{ | |
| 79 | + static int keyPressed = 0; | |
| 80 | + | |
| 81 | + if( keyEvent.state == KeyEvent::Down) | |
| 82 | + { | |
| 83 | + if( keyPressed == 0 ) // Is this the first down event? | |
| 84 | + { | |
| 85 | + printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode ); | |
| 86 | + | |
| 87 | + if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) ) | |
| 88 | + { | |
| 89 | + mApplication.Quit(); | |
| 90 | + } | |
| 91 | + else if( keyEvent.keyPressedName.compare("Return") == 0 ) | |
| 92 | + { | |
| 93 | + } | |
| 94 | + } | |
| 95 | + keyPressed = 1; | |
| 96 | + } | |
| 97 | + else if( keyEvent.state == KeyEvent::Up ) | |
| 98 | + { | |
| 99 | + keyPressed = 0; | |
| 100 | + } | |
| 101 | +} | |
| 102 | + | |
| 103 | +void SimpleVisualsApplication::Create( Application& application ) | |
| 104 | +{ | |
| 105 | + Stage stage = Stage::GetCurrent(); | |
| 106 | + stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) ); | |
| 107 | + | |
| 108 | + // Connect to key events so can quit application | |
| 109 | + stage.KeyEventSignal().Connect(this, &SimpleVisualsApplication::OnKeyEvent); | |
| 110 | + | |
| 111 | + // Hide the indicator bar | |
| 112 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | |
| 113 | + | |
| 114 | + // Create a table view to parent the 2 MyControls | |
| 115 | + TableView contentLayout = TableView::New( 2, 2 ); | |
| 116 | + contentLayout.SetName("ContentLayout"); | |
| 117 | + contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); | |
| 118 | + contentLayout.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); | |
| 119 | + contentLayout.SetSizeModeFactor( Vector3( 1.0f, .5f, 1.0f ) ); | |
| 120 | + contentLayout.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 121 | + contentLayout.SetParentOrigin( ParentOrigin::CENTER ); | |
| 122 | + contentLayout.SetCellPadding( Vector2( 50.0f, 15.0f ) ); | |
| 123 | + contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) ); | |
| 124 | + | |
| 125 | + // Listen to focus change so can see Visual change from NORMAL to FOCUSED state | |
| 126 | + KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &SimpleVisualsApplication::OnKeyboardPreFocusChange ); | |
| 127 | + | |
| 128 | + stage.Add( contentLayout ); | |
| 129 | + | |
| 130 | + // Create 2 MyControls and add to table view. | |
| 131 | + mMyControl = MyControl::New(); | |
| 132 | + mMyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 133 | + mMyControl.SetParentOrigin(ParentOrigin::TOP_LEFT); | |
| 134 | + | |
| 135 | + mMyControl2 = MyControl::New(); | |
| 136 | + mMyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 137 | + mMyControl2.SetParentOrigin(ParentOrigin::CENTER); | |
| 138 | + | |
| 139 | + contentLayout.AddChild( mMyControl2, TableView::CellPosition(0, 0) ); | |
| 140 | + contentLayout.AddChild( mMyControl, TableView::CellPosition(0, 1) ); | |
| 141 | +} | |
| 142 | + | |
| 143 | +} // namespace Demo | ... | ... |
examples/simple-visuals-control/simple-visuals-application.h
0 → 100644
| 1 | +#ifndef DALI_DEMO_SIMPLE_VISUALS_APPLICATION_H | |
| 2 | +#define DALI_DEMO_SIMPLE_VISUALS_APPLICATION_H | |
| 3 | + | |
| 4 | +/* | |
| 5 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 6 | + * | |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | + * you may not use this file except in compliance with the License. | |
| 9 | + * You may obtain a copy of the License at | |
| 10 | + * | |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | + * | |
| 13 | + * Unless required by applicable law or agreed to in writing, software | |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | + * See the License for the specific language governing permissions and | |
| 17 | + * limitations under the License. | |
| 18 | + */ | |
| 19 | + | |
| 20 | +// EXTERNAL INCLUDES | |
| 21 | +#include <dali-toolkit/dali-toolkit.h> | |
| 22 | +#include <cstdio> | |
| 23 | +#include <sstream> | |
| 24 | + | |
| 25 | +// INTERNAL INCLUDES | |
| 26 | +#include "my-control.h" | |
| 27 | + | |
| 28 | +using namespace Dali; | |
| 29 | +using namespace Dali::Toolkit; | |
| 30 | + | |
| 31 | +namespace Demo | |
| 32 | +{ | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * @brief An application that uses the my-control to display 2 icons, if focus is allowed ( by using a keyboard or remote ) then the icons will change | |
| 36 | + * depending on which one is focused. | |
| 37 | + * | |
| 38 | + * Inherits from connection tracker to manage connection and disconnection of signals, In this case PreFocusChangeSignal | |
| 39 | + */ | |
| 40 | +class SimpleVisualsApplication : public ConnectionTracker | |
| 41 | +{ | |
| 42 | + | |
| 43 | +public: | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @brief Constructor. | |
| 47 | + * | |
| 48 | + * @param[in] application A reference to the Application class. | |
| 49 | + */ | |
| 50 | + SimpleVisualsApplication( Application& application ); | |
| 51 | + | |
| 52 | + | |
| 53 | +private: | |
| 54 | + /** | |
| 55 | + * @brief Listen to Focus change signal | |
| 56 | + * @param[in] current Current focused Actor | |
| 57 | + * @param[in] proposed New actor that is requesting to be focused | |
| 58 | + * @param[in] direction The direction of the focus event from current actor | |
| 59 | + */ | |
| 60 | + Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction ); | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * @brief Derived from control, enables capture of key presses | |
| 64 | + * | |
| 65 | + * @param[in] event In incoming key event | |
| 66 | + */ | |
| 67 | + void OnKeyEvent( const KeyEvent& event ); | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * @brief Called to initialise the application content | |
| 71 | + * | |
| 72 | + * @param[in] application A reference to the Application class. | |
| 73 | + */ | |
| 74 | + void Create( Application& application ); | |
| 75 | + | |
| 76 | + | |
| 77 | +private: | |
| 78 | + | |
| 79 | + Application& mApplication; // Handle to the application that is created and passed in. | |
| 80 | + | |
| 81 | + MyControl mMyControl; // Handle to first instance of MyControl | |
| 82 | + MyControl mMyControl2; // Handle to second instance of MyControl | |
| 83 | + | |
| 84 | +}; | |
| 85 | + | |
| 86 | +} // Namespace Demo | |
| 87 | + | |
| 88 | + | |
| 89 | +#endif // DALI_DEMO_SIMPLE_VISUALS_APPLICATION_H | ... | ... |
examples/simple-visuals-control/simple-visuals-example.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 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 | + * @file transition-example.cpp | |
| 19 | + * @brief Example of a control built with visuals | |
| 20 | + */ | |
| 21 | + | |
| 22 | +// EXTERNAL INCLUDES | |
| 23 | +#include <dali/dali.h> | |
| 24 | + | |
| 25 | +// INTERNAL INCLUDES | |
| 26 | +#include "simple-visuals-application.h" | |
| 27 | + | |
| 28 | +namespace | |
| 29 | +{ | |
| 30 | +// Style sheet to be used by this application | |
| 31 | +const char* SIMPLE_DEMO_THEME( DEMO_STYLE_DIR "simple-example-theme.json" ); | |
| 32 | +} | |
| 33 | + | |
| 34 | +/// Entry point for applications | |
| 35 | +int DALI_EXPORT_API main( int argc, char** argv ) | |
| 36 | +{ | |
| 37 | + Application application = Application::New( &argc, &argv, SIMPLE_DEMO_THEME ); // Use the above defined style sheet for this application. | |
| 38 | + Demo::SimpleVisualsApplication simpleVisualsApplication( application ); | |
| 39 | + application.MainLoop(); | |
| 40 | + return 0; | |
| 41 | +} | ... | ... |
resources/po/en_GB.po
| ... | ... | @@ -109,6 +109,9 @@ msgstr "Refraction" |
| 109 | 109 | msgid "DALI_DEMO_STR_TITLE_RENDERER_STENCIL" |
| 110 | 110 | msgstr "Renderer Stencil" |
| 111 | 111 | |
| 112 | +msgid "DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL" | |
| 113 | +msgstr "Simple Visuals Control" | |
| 114 | + | |
| 112 | 115 | msgid "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI" |
| 113 | 116 | msgstr "Script-based UI" |
| 114 | 117 | ... | ... |
resources/po/en_US.po
| ... | ... | @@ -109,6 +109,9 @@ msgstr "Refraction" |
| 109 | 109 | msgid "DALI_DEMO_STR_TITLE_RENDERER_STENCIL" |
| 110 | 110 | msgstr "Renderer Stencil" |
| 111 | 111 | |
| 112 | +msgid "DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL" | |
| 113 | +msgstr "Simple Visuals Control" | |
| 114 | + | |
| 112 | 115 | msgid "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI" |
| 113 | 116 | msgstr "Script-based UI" |
| 114 | 117 | ... | ... |
resources/style/.gitignore
resources/style/demo-theme.json.in
| ... | ... | @@ -183,6 +183,35 @@ |
| 183 | 183 | "units": "USER_SPACE", |
| 184 | 184 | "stopColor": [[0.247,0.38,0.52,1.0],[0.055,0.18,0.286,1.0]] |
| 185 | 185 | } |
| 186 | + }, | |
| 187 | +// | |
| 188 | +// Simple Visuals Application Style section | |
| 189 | +// | |
| 190 | + "MyControl": | |
| 191 | + { | |
| 192 | + "states": | |
| 193 | + { | |
| 194 | + "NORMAL": | |
| 195 | + { | |
| 196 | + "visuals": | |
| 197 | + { | |
| 198 | + "iconVisual": | |
| 199 | + { | |
| 200 | + "url":"{APPLICATION_RESOURCE_PATH}/images/application-icon-13.png" | |
| 201 | + } | |
| 202 | + } | |
| 203 | + }, | |
| 204 | + "FOCUSED": | |
| 205 | + { | |
| 206 | + "visuals": | |
| 207 | + { | |
| 208 | + "iconVisual": | |
| 209 | + { | |
| 210 | + "url":"{APPLICATION_RESOURCE_PATH}/images/application-icon-83.png" | |
| 211 | + } | |
| 212 | + } | |
| 213 | + } | |
| 214 | + } | |
| 186 | 215 | } |
| 187 | 216 | } |
| 188 | 217 | } | ... | ... |
resources/style/mobile/simple-example-theme.json.in
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2000-2017 Samsung Electronics Co., Ltd | |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | + * you may not use this file except in compliance with the License. | |
| 5 | + * You may obtain a copy of the License at | |
| 6 | + * | |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | + * | |
| 9 | + * Unless required by applicable law or agreed to in writing, software | |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | + * See the License for the specific language governing permissions and | |
| 13 | + * limitations under the License. | |
| 14 | + * | |
| 15 | + */ | |
| 16 | + | |
| 17 | +{ | |
| 18 | + "styles": | |
| 19 | + { | |
| 20 | + // | |
| 21 | + // Simple Visuals Application styling | |
| 22 | + // | |
| 23 | + "MyControl": | |
| 24 | + { | |
| 25 | + "states": | |
| 26 | + { | |
| 27 | + "NORMAL": | |
| 28 | + { | |
| 29 | + "visuals": | |
| 30 | + { | |
| 31 | + "iconVisual": | |
| 32 | + { | |
| 33 | + "url":"{APPLICATION_RESOURCE_PATH}/images/application-icon-13.png" | |
| 34 | + } | |
| 35 | + } | |
| 36 | + }, | |
| 37 | + "FOCUSED": | |
| 38 | + { | |
| 39 | + "visuals": | |
| 40 | + { | |
| 41 | + "iconVisual": | |
| 42 | + { | |
| 43 | + "url":"{APPLICATION_RESOURCE_PATH}/images/application-icon-83.png" | |
| 44 | + } | |
| 45 | + } | |
| 46 | + } | |
| 47 | + } | |
| 48 | + } | |
| 49 | + } | |
| 50 | +} | ... | ... |
resources/style/simple-example-theme.json.in
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2000-2017 Samsung Electronics Co., Ltd | |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | + * you may not use this file except in compliance with the License. | |
| 5 | + * You may obtain a copy of the License at | |
| 6 | + * | |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | + * | |
| 9 | + * Unless required by applicable law or agreed to in writing, software | |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | + * See the License for the specific language governing permissions and | |
| 13 | + * limitations under the License. | |
| 14 | + * | |
| 15 | + */ | |
| 16 | + | |
| 17 | +{ | |
| 18 | + "styles": | |
| 19 | + { | |
| 20 | + // | |
| 21 | + // Simple Visuals Application styling | |
| 22 | + // | |
| 23 | + "MyControl": | |
| 24 | + { | |
| 25 | + "states": | |
| 26 | + { | |
| 27 | + "NORMAL": | |
| 28 | + { | |
| 29 | + "visuals": | |
| 30 | + { | |
| 31 | + "iconVisual": | |
| 32 | + { | |
| 33 | + "url":"{APPLICATION_RESOURCE_PATH}/images/application-icon-13.png" | |
| 34 | + } | |
| 35 | + } | |
| 36 | + }, | |
| 37 | + "FOCUSED": | |
| 38 | + { | |
| 39 | + "visuals": | |
| 40 | + { | |
| 41 | + "iconVisual": | |
| 42 | + { | |
| 43 | + "url":"{APPLICATION_RESOURCE_PATH}/images/application-icon-83.png" | |
| 44 | + } | |
| 45 | + } | |
| 46 | + } | |
| 47 | + } | |
| 48 | + } | |
| 49 | + } | |
| 50 | +} | ... | ... |
shared/dali-demo-strings.h
| ... | ... | @@ -69,6 +69,7 @@ extern "C" |
| 69 | 69 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") |
| 70 | 70 | #define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") |
| 71 | 71 | #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERER_STENCIL") |
| 72 | +#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SIMPLE_VISUALS") | |
| 72 | 73 | #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") |
| 73 | 74 | #define DALI_DEMO_STR_TITLE_SCROLL_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCROLL_VIEW") |
| 74 | 75 | #define DALI_DEMO_STR_TITLE_SPARKLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SPARKLE") |
| ... | ... | @@ -122,6 +123,7 @@ extern "C" |
| 122 | 123 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" |
| 123 | 124 | #define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect" |
| 124 | 125 | #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL "Renderer Stencils" |
| 126 | +#define DALI_DEMO_STR_TITLE_SIMPLE_VISUALS_CONTROL "Simple Visuals Control" | |
| 125 | 127 | #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI "Script Based UI" |
| 126 | 128 | #define DALI_DEMO_STR_TITLE_SCROLL_VIEW "Scroll View" |
| 127 | 129 | #define DALI_DEMO_STR_TITLE_SPARKLE "Sparkle" | ... | ... |