lottie/example: Added image_test.json(resource with image resource )
[platform/core/uifw/lottie-player.git] / src / vector / vbrush.cpp
1 /* 
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  * 
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "vbrush.h"
20
21 V_BEGIN_NAMESPACE
22
23 VGradient::VGradient(VGradient::Type type)
24     : mType(type),
25       mSpread(VGradient::Spread::Pad),
26       mMode(VGradient::Mode::Absolute)
27 {
28 }
29
30 void VGradient::setStops(const VGradientStops &stops)
31 {
32     mStops = stops;
33 }
34
35 VLinearGradient::VLinearGradient(const VPointF &start, const VPointF &stop)
36     : VGradient(VGradient::Type::Linear)
37 {
38     linear.x1 = start.x();
39     linear.y1 = start.y();
40     linear.x1 = stop.x();
41     linear.y1 = stop.y();
42 }
43
44 VLinearGradient::VLinearGradient(float xStart, float yStart, float xStop,
45                                  float yStop)
46     : VGradient(VGradient::Type::Linear)
47 {
48     linear.x1 = xStart;
49     linear.y1 = yStart;
50     linear.x1 = xStop;
51     linear.y1 = yStop;
52 }
53
54 VRadialGradient::VRadialGradient(const VPointF &center, float cradius,
55                                  const VPointF &focalPoint, float fradius)
56     : VGradient(VGradient::Type::Radial)
57 {
58     radial.cx = center.x();
59     radial.cy = center.y();
60     radial.fx = focalPoint.x();
61     radial.fy = focalPoint.y();
62     radial.cradius = cradius;
63     radial.fradius = fradius;
64 }
65
66 VRadialGradient::VRadialGradient(float cx, float cy, float cradius, float fx,
67                                  float fy, float fradius)
68     : VGradient(VGradient::Type::Radial)
69 {
70     radial.cx = cx;
71     radial.cy = cy;
72     radial.fx = fx;
73     radial.fy = fy;
74     radial.cradius = cradius;
75     radial.fradius = fradius;
76 }
77
78 VBrush::VBrush(const VColor &color) : mType(VBrush::Type::Solid), mColor(color)
79 {
80 }
81
82 VBrush::VBrush(int r, int g, int b, int a)
83     : mType(VBrush::Type::Solid), mColor(r, g, b, a)
84
85 {
86 }
87
88 VBrush::VBrush(const VGradient *gradient)
89 {
90     if (!gradient) return;
91
92     mGradient = gradient;
93
94     if (gradient->mType == VGradient::Type::Linear) {
95         mType = VBrush::Type::LinearGradient;
96     } else if (gradient->mType == VGradient::Type::Radial) {
97         mType = VBrush::Type::RadialGradient;
98     }
99 }
100
101 VBrush::VBrush(const VBitmap &texture)
102 {
103     if (!texture.valid()) return;
104
105     mType = VBrush::Type::Texture;
106     mTexture = texture;
107 }
108
109 void VBrush::setMatrix(const VMatrix &m)
110 {
111     mMatrix = m;
112 }
113
114 V_END_NAMESPACE