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