License conversion from Flora to Apache 2.0
[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
48   return CreateAlignedImage( ImageActor::New( image ) );
49 }
50
51 } // namespace
52
53
54 PushButton CreatePushButton( const std::string& releasedImagePath, const std::string& pressedImagePath, const std::string& backgroundImagePath,
55                              const std::string& dimmedReleasedImagePath, const std::string& dimmedBackgroundImagePath )
56 {
57   PushButton button = Toolkit::PushButton::New();
58
59   if( !releasedImagePath.empty() )
60   {
61     button.SetButtonImage( CreateAlignedImage( releasedImagePath ) );
62   }
63
64   if( !pressedImagePath.empty() )
65   {
66     button.SetPressedImage( CreateAlignedImage( pressedImagePath ) );
67   }
68
69   if( !backgroundImagePath.empty() )
70   {
71     button.SetBackgroundImage( CreateAlignedImage( backgroundImagePath ) );
72   }
73
74   if( !dimmedReleasedImagePath.empty() )
75   {
76     button.SetDimmedImage( CreateAlignedImage( dimmedReleasedImagePath ) );
77   }
78
79   if( !dimmedBackgroundImagePath.empty() )
80   {
81     button.SetDimmedBackgroundImage( CreateAlignedImage( dimmedBackgroundImagePath ) );
82   }
83
84   return button;
85 }
86
87 PushButton CreatePushButton( Actor releasedImageActor, Actor pressedImageActor, Actor backgroundImageActor,
88                              Actor dimmedReleasedImageActor, Actor dimmedBackgroundImageActor )
89 {
90   PushButton button = Toolkit::PushButton::New();
91
92   if( releasedImageActor )
93   {
94     button.SetButtonImage( CreateAlignedImage( releasedImageActor ) );
95   }
96
97   if( pressedImageActor )
98   {
99     button.SetPressedImage( CreateAlignedImage( pressedImageActor ) );
100   }
101
102   if( backgroundImageActor )
103   {
104     button.SetBackgroundImage( CreateAlignedImage( backgroundImageActor ) );
105   }
106
107   if( dimmedReleasedImageActor )
108   {
109     button.SetDimmedImage( CreateAlignedImage( dimmedReleasedImageActor ) );
110   }
111
112   if( dimmedBackgroundImageActor )
113   {
114     button.SetDimmedBackgroundImage( CreateAlignedImage( dimmedBackgroundImageActor ) );
115   }
116
117   return button;
118 }
119
120 PushButton CreatePushButton( const std::string& backgroundImagePath )
121 {
122   PushButton button = Toolkit::PushButton::New();
123
124   if( !backgroundImagePath.empty() )
125   {
126     button.SetBackgroundImage( CreateAlignedImage( backgroundImagePath ) );
127   }
128
129   return button;
130 }
131
132 PushButton CreatePushButton( Actor backgroundImageActor )
133 {
134   PushButton button = Toolkit::PushButton::New();
135
136   if( backgroundImageActor )
137   {
138     button.SetBackgroundImage( CreateAlignedImage( backgroundImageActor ) );
139   }
140
141   return button;
142 }
143
144 } // namespace Toolkit
145
146 } // namespace Dali