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