5715e49e6c9ebe8762513af8fa268e2faf22333e
[platform/core/uifw/dali-toolkit.git] / 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 #include <dali/public-api/actors/image-actor.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/public-api/controls/alignment/alignment.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& selectedImagePath, const std::string& disabledBackgroundImagePath, const std::string& disabledSelectedImagePath )
56 {
57   CheckBoxButton button = Toolkit::CheckBoxButton::New();
58
59   if( !backgroundImagePath.empty() )
60   {
61     button.SetBackgroundImage( CreateAlignedImage( backgroundImagePath ) );
62   }
63
64   if( !selectedImagePath.empty() )
65   {
66     button.SetSelectedImage( CreateAlignedImage( selectedImagePath ) );
67   }
68
69   if( !disabledBackgroundImagePath.empty() )
70   {
71     button.SetDisabledBackgroundImage( CreateAlignedImage( disabledBackgroundImagePath ) );
72   }
73
74   if( !disabledSelectedImagePath.empty() )
75   {
76     button.SetDisabledSelectedImage( CreateAlignedImage( disabledSelectedImagePath ) );
77   }
78
79   return button;
80 }
81
82 CheckBoxButton CreateCheckBoxButton( Actor backgroundImageActor, Actor selectedImageActor, Actor disabledBackgroundImageActor, Actor disabledSelectedImagActor )
83 {
84   CheckBoxButton button = Toolkit::CheckBoxButton::New();
85
86   if( backgroundImageActor )
87   {
88     button.SetBackgroundImage( CreateAlignedImage( backgroundImageActor ) );
89   }
90
91   if( selectedImageActor )
92   {
93     button.SetSelectedImage( CreateAlignedImage( selectedImageActor ) );
94   }
95
96   if( disabledBackgroundImageActor )
97   {
98     button.SetDisabledBackgroundImage( CreateAlignedImage( disabledBackgroundImageActor ) );
99   }
100
101   if( disabledSelectedImagActor )
102   {
103     button.SetDisabledSelectedImage( CreateAlignedImage( disabledSelectedImagActor ) );
104   }
105
106   return button;
107 }
108
109 CheckBoxButton CreateCheckBoxButton( const std::string& backgroundImagePath, const std::string& selectedImagePath )
110 {
111   CheckBoxButton button = Toolkit::CheckBoxButton::New();
112
113   if( !backgroundImagePath.empty() )
114   {
115     button.SetBackgroundImage( CreateAlignedImage( backgroundImagePath ) );
116   }
117
118   if( !selectedImagePath.empty() )
119   {
120     button.SetSelectedImage( CreateAlignedImage( selectedImagePath ) );
121   }
122
123   return button;
124 }
125
126 CheckBoxButton CreateCheckBoxButton( Actor backgroundImageActor, Actor selectedImageActor )
127 {
128   CheckBoxButton button = Toolkit::CheckBoxButton::New();
129
130   if( backgroundImageActor )
131   {
132     button.SetBackgroundImage( CreateAlignedImage( backgroundImageActor ) );
133   }
134
135   if( selectedImageActor )
136   {
137     button.SetSelectedImage( CreateAlignedImage( selectedImageActor ) );
138   }
139
140   return button;
141 }
142
143 } // namespace Toolkit
144
145 } // namespace Dali