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