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