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