File size: 1,518 Bytes
28958dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#include "diffvg.h"
#include "vector.h"
#include "ptr.h"

enum class ColorType {
    Constant,
    LinearGradient,
    RadialGradient
};

struct Constant {
    Vector4f color;

    ptr<void> get_ptr() {
        return ptr<void>(this);
    }
};

struct LinearGradient {
    LinearGradient(const Vector2f &begin,
                   const Vector2f &end,
                   int num_stops,
                   ptr<float> stop_offsets,
                   ptr<float> stop_colors)
        : begin(begin), end(end), num_stops(num_stops),
          stop_offsets(stop_offsets.get()), stop_colors(stop_colors.get()) {}

    ptr<void> get_ptr() {
        return ptr<void>(this);
    }

    void copy_to(ptr<float> stop_offset,
                 ptr<float> stop_colors) const;

    Vector2f begin, end;
    int num_stops;
    float *stop_offsets;
    float *stop_colors; // rgba
};

struct RadialGradient {
    RadialGradient(const Vector2f &center,
                   const Vector2f &radius,
                   int num_stops,
                   ptr<float> stop_offsets,
                   ptr<float> stop_colors)
        : center(center), radius(radius), num_stops(num_stops),
          stop_offsets(stop_offsets.get()), stop_colors(stop_colors.get()) {}

    ptr<void> get_ptr() {
        return ptr<void>(this);
    }

    void copy_to(ptr<float> stop_offset,
                 ptr<float> stop_colors) const;

    Vector2f center, radius;
    int num_stops;
    float *stop_offsets;
    float *stop_colors; // rgba
};