summaryrefslogtreecommitdiff
path: root/include/mbgl/style/style_properties.hpp
blob: c0ecc35201e9157427ffe0766f5cb76327e2581b (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef MBGL_STYLE_STYLE_PROPERTIES
#define MBGL_STYLE_STYLE_PROPERTIES

#include <mapbox/variant.hpp>

#include <mbgl/style/types.hpp>

#include <array>
#include <string>
#include <type_traits>
#include <memory>
#include <vector>

namespace mbgl {

struct FillProperties {
    FillProperties() {}
    bool antialias = true;
    float opacity = 1.0f;
    Color fill_color = {{ 0, 0, 0, 1 }};
    Color stroke_color = {{ 0, 0, 0, -1 }};
    std::array<float, 2> translate = {{ 0, 0 }};
    TranslateAnchorType translateAnchor = TranslateAnchorType::Map;
    Faded<std::string> image;

    inline bool isVisible() const {
        return opacity > 0 && (fill_color[3] > 0 || stroke_color[3] > 0);
    }
};

struct LineProperties {
    inline LineProperties() {}
    float opacity = 1.0f;
    Color color = {{ 0, 0, 0, 1 }};
    std::array<float, 2> translate = {{ 0, 0 }};
    TranslateAnchorType translateAnchor = TranslateAnchorType::Map;
    float width = 1;
    float gap_width = 0;
    float blur = 0;
    Faded<std::vector<float>> dash_array;
    float dash_line_width = 1;
    Faded<std::string> image;

    inline bool isVisible() const {
        return opacity > 0 && color[3] > 0 && width > 0;
    }
};

struct CircleProperties {
    inline CircleProperties() {}
    float radius = 5.0f;
    Color color = {{ 0, 0, 0, 1 }};
    float opacity = 1.0f;
    std::array<float, 2> translate = {{ 0, 0 }};
    TranslateAnchorType translateAnchor = TranslateAnchorType::Map;
    float blur = 0;

    inline bool isVisible() const {
        return radius > 0 && color[3] > 0 && opacity > 0;
    }
};

struct SymbolProperties {
    inline SymbolProperties() {}

    struct {
        float opacity = 1.0f;
        float size = 1.0f;
        Color color = {{ 0, 0, 0, 1 }};
        Color halo_color = {{ 0, 0, 0, 0 }};
        float halo_width = 0.0f;
        float halo_blur = 0.0f;
        std::array<float, 2> translate = {{ 0, 0 }};
        TranslateAnchorType translate_anchor = TranslateAnchorType::Map;
    } icon;

    struct {
        float opacity = 1.0f;
        float size = 16.0f;
        Color color = {{ 0, 0, 0, 1 }};
        Color halo_color = {{ 0, 0, 0, 0 }};
        float halo_width = 0.0f;
        float halo_blur = 0.0f;
        std::array<float, 2> translate = {{ 0, 0 }};
        TranslateAnchorType translate_anchor = TranslateAnchorType::Map;
    } text;

    inline bool isVisible() const {
        return (icon.opacity > 0 && (icon.color[3] > 0 || icon.halo_color[3] > 0) && icon.size > 0) ||
               (text.opacity > 0 && (text.color[3] > 0 || text.halo_color[3] > 0) && text.size > 0);
    }
};

struct RasterProperties {
    inline RasterProperties() {}
    float opacity = 1.0f;
    float hue_rotate = 0.0f;
    std::array<float, 2> brightness = {{ 0, 1 }};
    float saturation = 0.0f;
    float contrast = 0.0f;
    float fade = 0.0f;

    inline bool isVisible() const {
        return opacity > 0;
    }
};

struct BackgroundProperties {
    inline BackgroundProperties() {}
    float opacity = 1.0f;
    Color color = {{ 0, 0, 0, 1 }};
    Faded<std::string> image;
};

typedef mapbox::util::variant<
    FillProperties,
    LineProperties,
    CircleProperties,
    SymbolProperties,
    RasterProperties,
    BackgroundProperties,
    std::false_type
> StyleProperties;

template <typename T>
const T &defaultStyleProperties();

}

#endif