[dali_1.0.8] Merge branch 'tizen'
[platform/core/uifw/dali-adaptor.git] / adaptors / mobile / mobile-color-controller-impl.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 <common/color-controller-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <efl_assist_theme.h>
25
26 // INTERNAL INCLUDES
27 #include <singleton-service-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 namespace
39 {
40
41 BaseHandle Create()
42 {
43   return ColorController::Get();
44 }
45 Dali::TypeRegistration COLOR_CONTROLLER_TYPE( typeid(Dali::ColorController), typeid(Dali::BaseHandle), Create );
46
47 }
48
49 Dali::ColorController ColorController::Get()
50 {
51   Dali::ColorController colorController;
52
53   Dali::SingletonService service( SingletonService::Get() );
54   if ( service )
55   {
56     // Check whether the singleton is already created
57     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ColorController ) );
58     if(handle)
59     {
60       // If so, downcast the handle
61       colorController = Dali::ColorController( dynamic_cast< ColorController* >( handle.GetObjectPtr() ) );
62     }
63     else
64     {
65       colorController = Dali::ColorController( new ColorController( ) );
66       service.Register( typeid( colorController ), colorController );
67     }
68   }
69
70   return colorController;
71
72 }
73
74 ColorController::ColorController()
75 {
76 }
77
78 ColorController::~ColorController()
79 {
80 }
81
82 bool ColorController::RetrieveColor( const std::string& colorCode, Vector4& colorValue )
83 {
84   int R = 0;
85   int G = 0;
86   int B = 0;
87   int A = 0;
88
89   if( ea_theme_color_get(colorCode.c_str(), &R, &G, &B, &A, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) )
90   {
91     colorValue.r = (float) (R) / 255.0f;
92     colorValue.g = (float) (G) / 255.0f;
93     colorValue.b = (float) (B) / 255.0f;
94     colorValue.a = (float) (A) / 255.0f;
95
96     return true;
97   }
98
99   return false;
100 }
101
102 bool ColorController::RetrieveColor( const std::string& colorCode , Vector4& textColor, Vector4& textOutlineColor, Vector4& textShadowColor)
103 {
104   int R = 0;
105   int G = 0;
106   int B = 0;
107   int A = 0;
108
109   int outlineR = 0;
110   int outlineG = 0;
111   int outlineB = 0;
112   int outlineA = 0;
113
114   int shadowR = 0;
115   int shadowG = 0;
116   int shadowB = 0;
117   int shadowA = 0;
118
119   if( ea_theme_color_get(colorCode.c_str(), &R, &G, &B, &A, &outlineR, &outlineG, &outlineB, &outlineA, &shadowR, &shadowG, &shadowB, &shadowA) )
120   {
121     textColor.r = (float) (R) / 255.0f;
122     textColor.g = (float) (G) / 255.0f;
123     textColor.b = (float) (B) / 255.0f;
124     textColor.a = (float) (A) / 255.0f;
125
126     textOutlineColor.r = (float) (outlineR) / 255.0f;
127     textOutlineColor.g = (float) (outlineG) / 255.0f;
128     textOutlineColor.b = (float) (outlineB) / 255.0f;
129     textOutlineColor.a = (float) (outlineA) / 255.0f;
130
131     textShadowColor.r = (float) (shadowR) / 255.0f;
132     textShadowColor.g = (float) (shadowG) / 255.0f;
133     textShadowColor.b = (float) (shadowB) / 255.0f;
134     textShadowColor.a = (float) (shadowA) / 255.0f;
135
136     return true;
137   }
138
139   return false;
140 }
141
142 } // namespace Adaptor
143
144 } // namespace Internal
145
146 } // namespace Dali