summaryrefslogtreecommitdiff
path: root/vcl/inc/SceneGraphNodes.hxx
blob: 8c08a108b4a10ed952431ed4e5be1a064d17785f (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#ifndef VCL_INC_SCENEGRAPHNODES_HXX
#define VCL_INC_SCENEGRAPHNODES_HXX

#include <vcl/SceneGraph.hxx>

#include <glm/glm.hpp>
#include <basegfx/range/b2drange.hxx>
#include <o3tl/make_unique.hxx>

namespace vcl
{
namespace sg
{

class VCL_DLLPUBLIC ClippingNode : public Node
{
public:
    ClippingNode()
        : Node(NodeType::CLIPPING)
    {}

    basegfx::B2DRange maClipBox;
};

class VCL_DLLPUBLIC TransformNode : public Node
{
public:
    glm::mat4 maMatrix;

    TransformNode(glm::mat4 aMatrix)
        : Node(NodeType::TRANSFORM)
        , maMatrix(aMatrix)
    {}
};

enum class GeometryNodeType
{
    RECTANGLE,
    POLYPOLYGON,
    BITMAP
};

class VCL_DLLPUBLIC GeometryNode : public Node
{
public:
    GeometryNodeType meGeometryType;
    bool mbNormalized;

    GeometryNode(GeometryNodeType eGeometryType)
        : Node(NodeType::GEOMETRY)
        , meGeometryType(eGeometryType)
        , mbNormalized(false)
    {}


protected:
    void markAsModified()
    {}
};

struct GeometryAttributes
{
    SalColor maLineColor;
    SalColor maFillColor;

    GeometryAttributes(SalColor aLineColor = SALCOLOR_NONE, SalColor aFillColor = SALCOLOR_NONE)
        : maLineColor(aLineColor)
        , maFillColor(aFillColor)
    {}
};

class VCL_DLLPUBLIC RectangleNode : public GeometryNode
{
private:
    basegfx::B2DRange maRectangle;
    GeometryAttributes maAttributes;

public:
    RectangleNode(const basegfx::B2DRange& rRectangle, const GeometryAttributes& rAttributes)
        : GeometryNode(GeometryNodeType::RECTANGLE)
        , maRectangle(rRectangle)
        , maAttributes(rAttributes)
    {}

    const GeometryAttributes& getAttributes()
    {
        return maAttributes;
    }

    const basegfx::B2DRange& getRectangle()
    {
        return maRectangle;
    }

    void modifyAttributes(GeometryAttributes& rAttributes)
    {
        maAttributes = rAttributes;
        markAsModified();
    }
};

class VCL_DLLPUBLIC PolyPolygonNode : public GeometryNode
{
private:
    basegfx::B2DPolyPolygon maPolyPolygon;
    GeometryAttributes maAttributes;

public:
    PolyPolygonNode(const basegfx::B2DPolyPolygon& rPolyPolygon, const GeometryAttributes& rAttributes)
        : GeometryNode(GeometryNodeType::POLYPOLYGON)
        , maPolyPolygon(rPolyPolygon)
        , maAttributes(rAttributes)
    {}

    const GeometryAttributes& getAttributes()
    {
        return maAttributes;
    }

    const basegfx::B2DPolyPolygon& getPolyPolygon()
    {
        return maPolyPolygon;
    }

    void modifyAttributes(GeometryAttributes& rAttributes)
    {
        maAttributes = rAttributes;
        markAsModified();
    }
};

class VCL_DLLPUBLIC BitmapNode : public GeometryNode
{
public:
    Bitmap maBitmap;
    basegfx::B2DRange maRectangle;

    BitmapNode(Bitmap aBitmap, basegfx::B2DRange aRectangle)
        : GeometryNode(GeometryNodeType::BITMAP)
        , maBitmap(aBitmap)
        , maRectangle(aRectangle)
    {}
};

class SceneGraphFactory
{
private:
    std::vector<std::shared_ptr<Node>> maNodeStack;

public:
    SceneGraphFactory(const std::shared_ptr<Node>& pRootNode)
        : maNodeStack({pRootNode})
    {}

    Node& getCurrent()
    {
        return *maNodeStack.back().get();
    }

    void pushTransform(glm::mat4 aMatrix, const OUString& rName)
    {
        auto pTransformNode = std::make_shared<vcl::sg::TransformNode>(aMatrix);
        pTransformNode->setName(rName);
        getCurrent().mChildren.push_back(pTransformNode);
        maNodeStack.push_back(pTransformNode);
    }

    void pop()
    {
        maNodeStack.pop_back();
    }

    void addRectangle(const basegfx::B2DRange& rRange, SalColor nLineColor, SalColor nFillColor)
    {
        GeometryAttributes aAttributes(nLineColor, nFillColor);
        getCurrent().mChildren.push_back(std::make_shared<RectangleNode>(rRange, aAttributes));
    }

    void addNormalizedRectangle(const basegfx::B2DRange& rRange, SalColor nLineColor, SalColor nFillColor)
    {
        addRectangle(rRange, nLineColor, nFillColor);
        std::static_pointer_cast<RectangleNode>(getCurrent().mChildren.back())->mbNormalized = true;
    }

    void addBitmap(Bitmap& rBitmap, const basegfx::B2DRange& rRange)
    {
        getCurrent().mChildren.push_back(std::make_shared<BitmapNode>(rBitmap, rRange));
    }

    void addPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, SalColor nLineColor, SalColor nFillColor)
    {
        GeometryAttributes aAttributes(nLineColor, nFillColor);
        getCurrent().mChildren.push_back(std::make_shared<PolyPolygonNode>(rPolyPolygon, aAttributes));
    }
};

}} // end vcl::sg namespace

#endif // INCLUDED_VCL_INC_SCENEGRAPH_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */