Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / controls / default-controls / solid-color-actor.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
18
19 // INTERNAL INCLUDES
20
21 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
22 #include <dali/public-api/images/bitmap-image.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace
31 {
32 const unsigned int MAX_BORDER_SIZE( 9 );
33 }
34
35 ImageActor CreateSolidColorActor( const Vector4& color, bool border, const Vector4& borderColor, const unsigned int borderSize )
36 {
37   ImageActor image;
38   if( borderSize > MAX_BORDER_SIZE )
39   {
40     return image;
41   }
42
43   const unsigned int bitmapWidth = borderSize * 2 + 2;
44   BitmapImage imageData = BitmapImage::New( bitmapWidth, bitmapWidth, Pixel::RGBA8888 );
45
46   // Create the image
47   PixelBuffer* pixbuf = imageData.GetBuffer();
48   Vector4 outerColor = color;
49   if ( border )
50   {
51     outerColor = borderColor;
52   }
53
54   // Using a (2 + border) x (2 + border) image gives a better blend with the GL implementation
55   // than a (1 + border) x (1 + border) image
56   const unsigned int bitmapSize = bitmapWidth * bitmapWidth;
57   const unsigned int topLeft = bitmapWidth * borderSize + borderSize;
58   const unsigned int topRight = topLeft + 1;
59   const unsigned int bottomLeft = bitmapWidth * (borderSize + 1) + borderSize;
60   const unsigned int bottomRight = bottomLeft + 1;
61
62   for( size_t i = 0; i < bitmapSize; ++i )
63   {
64     if( i == topLeft ||
65         i == topRight ||
66         i == bottomLeft ||
67         i == bottomRight )
68     {
69       pixbuf[i*4+0] = 0xFF * color.r;
70       pixbuf[i*4+1] = 0xFF * color.g;
71       pixbuf[i*4+2] = 0xFF * color.b;
72       pixbuf[i*4+3] = 0xFF * color.a;
73     }
74     else
75     {
76       pixbuf[i*4+0] = 0xFF * outerColor.r;
77       pixbuf[i*4+1] = 0xFF * outerColor.g;
78       pixbuf[i*4+2] = 0xFF * outerColor.b;
79       pixbuf[i*4+3] = 0xFF * outerColor.a;
80     }
81   }
82
83   imageData.Update();
84   image = ImageActor::New( imageData );
85   image.SetAnchorPoint( AnchorPoint::CENTER );
86   image.SetParentOrigin( ParentOrigin::CENTER );
87
88   if( border )
89   {
90     image.SetStyle( ImageActor::STYLE_NINE_PATCH );
91     image.SetNinePatchBorder( Vector4::ONE * (float)borderSize * 2.0f );
92   }
93
94   return image;
95 }
96
97 } // namespace Toolkit
98
99 } // namespace Dali