67f16e9dfb7cabaa4d2ce40da61a38965543b2e6
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / controls / default-controls / push-button-factory.cpp
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 #include <dali-toolkit/public-api/controls/alignment/alignment.h>
19 #include <dali-toolkit/public-api/controls/default-controls/push-button-factory.h>
20
21 // EXTERNAL INCLUDES
22 // INTERNAL INCLUDES
23
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace
32 {
33
34 Alignment CreateAlignedImage( Actor image )
35 {
36   Alignment alignmentContainer = Toolkit::Alignment::New();
37   alignmentContainer.SetScaling( Toolkit::Alignment::ShrinkToFitKeepAspect );
38
39   alignmentContainer.Add( image );
40
41   return alignmentContainer;
42 }
43
44 Alignment CreateAlignedImage( const std::string& imagePath )
45 {
46   Image image = Image::New( imagePath );
47   return CreateAlignedImage( ImageActor::New( image ) );
48 }
49
50 } // namespace
51
52
53 PushButton CreatePushButton( const std::string& releasedImagePath, const std::string& pressedImagePath, const std::string& backgroundImagePath,
54                              const std::string& dimmedReleasedImagePath, const std::string& dimmedBackgroundImagePath )
55 {
56   PushButton button = Toolkit::PushButton::New();
57
58   if( !releasedImagePath.empty() )
59   {
60     button.SetButtonImage( CreateAlignedImage( releasedImagePath ) );
61   }
62
63   if( !pressedImagePath.empty() )
64   {
65     button.SetPressedImage( CreateAlignedImage( pressedImagePath ) );
66   }
67
68   if( !backgroundImagePath.empty() )
69   {
70     button.SetBackgroundImage( CreateAlignedImage( backgroundImagePath ) );
71   }
72
73   if( !dimmedReleasedImagePath.empty() )
74   {
75     button.SetDimmedImage( CreateAlignedImage( dimmedReleasedImagePath ) );
76   }
77
78   if( !dimmedBackgroundImagePath.empty() )
79   {
80     button.SetDimmedBackgroundImage( CreateAlignedImage( dimmedBackgroundImagePath ) );
81   }
82
83   return button;
84 }
85
86 PushButton CreatePushButton( Actor releasedImageActor, Actor pressedImageActor, Actor backgroundImageActor,
87                              Actor dimmedReleasedImageActor, Actor dimmedBackgroundImageActor )
88 {
89   PushButton button = Toolkit::PushButton::New();
90
91   if( releasedImageActor )
92   {
93     button.SetButtonImage( CreateAlignedImage( releasedImageActor ) );
94   }
95
96   if( pressedImageActor )
97   {
98     button.SetPressedImage( CreateAlignedImage( pressedImageActor ) );
99   }
100
101   if( backgroundImageActor )
102   {
103     button.SetBackgroundImage( CreateAlignedImage( backgroundImageActor ) );
104   }
105
106   if( dimmedReleasedImageActor )
107   {
108     button.SetDimmedImage( CreateAlignedImage( dimmedReleasedImageActor ) );
109   }
110
111   if( dimmedBackgroundImageActor )
112   {
113     button.SetDimmedBackgroundImage( CreateAlignedImage( dimmedBackgroundImageActor ) );
114   }
115
116   return button;
117 }
118
119 PushButton CreatePushButton( const std::string& backgroundImagePath )
120 {
121   PushButton button = Toolkit::PushButton::New();
122
123   if( !backgroundImagePath.empty() )
124   {
125     button.SetBackgroundImage( CreateAlignedImage( backgroundImagePath ) );
126   }
127
128   return button;
129 }
130
131 PushButton CreatePushButton( Actor backgroundImageActor )
132 {
133   PushButton button = Toolkit::PushButton::New();
134
135   if( backgroundImageActor )
136   {
137     button.SetBackgroundImage( CreateAlignedImage( backgroundImageActor ) );
138   }
139
140   return button;
141 }
142
143 } // namespace Toolkit
144
145 } // namespace Dali