Fix SVACE error caused by uninitialised member
[platform/core/uifw/dali-demo.git] / examples / transitions / transition-application.cpp
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-application.cpp
19  * @brief Application class for showing stylable transitions
20  */
21
22 // Class include
23 #include "transition-application.h"
24
25 // External includes
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
28 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
29 #include "shadow-button.h"
30 #include <cstdio>
31 #include <sstream>
32
33 // Internal includes
34
35 using namespace Dali;
36 using namespace Dali::Toolkit;
37
38 namespace
39 {
40
41 void SetLabelText( Button button, const char* label )
42 {
43   button.SetProperty( Toolkit::Button::Property::LABEL, label );
44 }
45
46 }
47
48 namespace Demo
49 {
50
51 const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" );
52 const char* TransitionApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" );
53
54
55 TransitionApplication::TransitionApplication( Application& application )
56 : mApplication( application ),
57   mTitle(),
58   mShadowButton(),
59   mActionButtons(),
60   mVisualIndex( Property::INVALID_INDEX ),
61   mActionIndex( Property::INVALID_INDEX )
62 {
63   application.InitSignal().Connect( this, &TransitionApplication::Create );
64 }
65
66 TransitionApplication::~TransitionApplication()
67 {
68 }
69
70 void TransitionApplication::Create( Application& application )
71 {
72   Stage stage = Stage::GetCurrent();
73   stage.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
74   stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
75
76   // Hide the indicator bar
77   application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
78
79   // Content panes:
80   TableView contentLayout = TableView::New( 3, 1 );
81   contentLayout.SetName("ContentLayout");
82   contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
83   contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
84   contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
85   contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) );
86   contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
87   // Assign all rows the size negotiation property of fitting to children
88
89   stage.Add( contentLayout );
90
91   mTitle = TextLabel::New( "Custom Control Transition Example" );
92   mTitle.SetName( "Title" );
93   mTitle.SetStyleName("Title");
94   mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
95   mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
96   mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
97   contentLayout.Add( mTitle );
98   contentLayout.SetFitHeight(0); // Fill width
99
100   // Provide some padding around the center cell
101   TableView buttonLayout = TableView::New( 3, 3 );
102   buttonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
103   buttonLayout.SetFixedHeight(1, 100 );
104   buttonLayout.SetFixedWidth(1, 350 );
105   contentLayout.Add( buttonLayout );
106
107   mShadowButton = ShadowButton::New();
108   mShadowButton.SetName("ShadowButton");
109   mShadowButton.SetActiveState( false );
110   mShadowButton.SetAnchorPoint( AnchorPoint::CENTER );
111   mShadowButton.SetParentOrigin( ParentOrigin::CENTER );
112   mShadowButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
113   buttonLayout.AddChild( mShadowButton, TableView::CellPosition(1, 1) );
114
115   TableView actionButtonLayout = TableView::New( 1, NUMBER_OF_ACTION_BUTTONS+1 );
116   actionButtonLayout.SetName("ThemeButtonsLayout");
117   actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
118   actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
119   actionButtonLayout.SetFitHeight( 0 );
120
121   TextLabel label = TextLabel::New( "Action: ");
122   label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
123   label.SetStyleName("ActionLabel");
124   actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
125   actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
126
127   for( int i=0; i<NUMBER_OF_ACTION_BUTTONS; ++i )
128   {
129     mActionButtons[i] = PushButton::New();
130     mActionButtons[i].SetName("ActionButton");
131     mActionButtons[i].SetStyleName("ActionButton");
132     mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
133     mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
134     mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
135     mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
136     actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
137   }
138   SetLabelText( mActionButtons[0], "Activate" );
139   SetLabelText( mActionButtons[1], "Check" );
140   mActionButtons[1].SetProperty( Button::Property::DISABLED, true );
141
142   contentLayout.Add( actionButtonLayout );
143   contentLayout.SetFitHeight(2);
144 }
145
146 bool TransitionApplication::OnActionButtonClicked( Button button )
147 {
148   int action = button.GetProperty<int>( mActionIndex );
149   switch( action )
150   {
151     case 0:
152     {
153       bool activeState = mShadowButton.GetActiveState();
154       mShadowButton.SetActiveState( ! activeState );
155       if( activeState )
156       {
157         SetLabelText( button, "Activate" );
158       }
159       else
160       {
161         SetLabelText( button, "Deactivate" );
162       }
163       mActionButtons[1].SetProperty( Button::Property::DISABLED, activeState );
164       break;
165     }
166     case 1:
167     {
168       bool checkState = mShadowButton.GetCheckState();
169       mShadowButton.SetCheckState( ! checkState );
170       if( checkState )
171       {
172         SetLabelText( button, "Check" );
173       }
174       else
175       {
176         SetLabelText( button, "Uncheck" );
177       }
178       break;
179     }
180     case 2:
181     {
182       break;
183     }
184     case 3:
185     {
186       break;
187     }
188   }
189
190   return true;
191 }
192
193 void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
194 {
195   static int keyPressed = 0;
196
197   if( keyEvent.state == KeyEvent::Down)
198   {
199     if( keyPressed == 0 ) // Is this the first down event?
200     {
201       printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
202
203       if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
204       {
205         mApplication.Quit();
206       }
207       else if( keyEvent.keyPressedName.compare("Return") == 0 )
208       {
209       }
210     }
211     keyPressed = 1;
212   }
213   else if( keyEvent.state == KeyEvent::Up )
214   {
215     keyPressed = 0;
216   }
217 }
218
219 } // namespace Demo