Revert "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 Flora License, Version 1.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://floralicense.org/license/
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 #include <dali-toolkit/public-api/controls/alignment/alignment.h>
18 #include <dali-toolkit/public-api/controls/default-controls/push-button-factory.h>
19
20 // EXTERNAL INCLUDES
21 // INTERNAL INCLUDES
22
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace
31 {
32
33 Alignment CreateAlignedImage( Actor image )
34 {
35   Alignment alignmentContainer = Toolkit::Alignment::New();
36   alignmentContainer.SetScaling( Toolkit::Alignment::ShrinkToFitKeepAspect );
37
38   alignmentContainer.Add( image );
39
40   return alignmentContainer;
41 }
42
43 Alignment CreateAlignedImage( const std::string& imagePath )
44 {
45   Image image = Image::New( imagePath );
46
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