AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
Document.hpp
1/*
2Copyright (C) 2019,2020,2023,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGUI_DOCUMENT_H
17#define AEONGUI_DOCUMENT_H
18#include <cstdint>
19#include <vector>
20#include <memory>
21#include <functional>
22#include <algorithm>
23#include "aeongui/Platform.hpp"
24#include "aeongui/Canvas.hpp"
25#include "aeongui/StyleSheet.hpp"
26#include "aeongui/dom/Node.hpp"
27#include "aeongui/dom/DOMString.hpp"
28#include "aeongui/dom/USVString.hpp"
29#include "aeongui/dom/Element.hpp"
30namespace AeonGUI
31{
32 namespace DOM
33 {
39 class Document : public Node
40 {
41 public:
43 DLL Document();
47 DLL void Load ( const USVString& aFilename );
49 DLL ~Document();
53 DLL void Draw ( Canvas& aCanvas ) const;
62 DLL void Draw ( Canvas& aCanvas, const std::function<void ( const Node& ) >& aPreDraw ) const;
66 DLL void AdvanceTime ( double aDeltaTime );
70 DLL const USVString& url() const;
74 DLL NodeType nodeType() const final;
80 DLL Element* getElementById ( const DOMString& aElementId ) const;
84 DLL css_stylesheet* GetStyleSheet() const;
89 void MarkDirty()
90 {
91 mFullDirty = true;
92 }
93
100 void MarkElementDirty ( Element* aElement )
101 {
102 mDirtyElements.push_back ( aElement );
103 }
104
107 bool IsDirty() const
108 {
109 return mFullDirty || !mDirtyElements.empty();
110 }
111
114 bool IsFullDirty() const
115 {
116 return mFullDirty;
117 }
118
121 const std::vector<Element*>& GetDirtyElements() const
122 {
123 return mDirtyElements;
124 }
125
127 {
128 mFullDirty = false;
129 mDirtyElements.clear();
130 }
131
132 private:
133 void Load ();
134 void Unload ();
135 //Element* mDocumentElement{};
136 StyleSheetPtr mStyleSheet{};
137 USVString mUrl{};
138 double mDocumentTime{0.0};
139 bool mFullDirty{true};
140 std::vector<Element*> mDirtyElements{};
141 };
142 }
143}
144#endif
Platform-specific DLL import/export macros and compiler helpers.
Abstract 2D rendering surface.
Definition Canvas.hpp:40
void MarkDirty()
Mark the entire document as needing a full redraw.
Definition Document.hpp:89
Element * getElementById(const DOMString &aElementId) const
Find an element by its ID attribute.
Definition Document.cpp:260
~Document()
Destructor. Unloads the document.
Definition Document.cpp:220
bool IsFullDirty() const
Check whether a full (non-partial) redraw is needed.
Definition Document.hpp:114
void AdvanceTime(double aDeltaTime)
Advance animation time and update all animations.
Definition Document.cpp:225
void Draw(Canvas &aCanvas) const
Draw the document onto a canvas.
Definition Document.cpp:235
bool IsDirty() const
Check whether the document needs redrawing.
Definition Document.hpp:107
css_stylesheet * GetStyleSheet() const
Get the document-level CSS stylesheet.
Definition Document.cpp:197
void Load(const USVString &aFilename)
Load a document from a file.
Definition Document.cpp:109
Document()
Default constructor. Creates an empty document.
void ClearDirty()
Clear the dirty flag after a redraw.
Definition Document.hpp:126
const USVString & url() const
Get the document URL.
Definition Document.cpp:192
const std::vector< Element * > & GetDirtyElements() const
Get the list of elements dirtied since the last draw.
Definition Document.hpp:121
void MarkElementDirty(Element *aElement)
Mark a specific element as needing redraw.
Definition Document.hpp:100
NodeType nodeType() const final
Get the node type (always DOCUMENT_NODE).
Definition Document.cpp:98
Base class for DOM elements.
Definition Element.hpp:46
NodeType
DOM node type constants.
Definition Node.hpp:46
Node(Node *aParent=nullptr)
Construct a node with an optional parent.
Definition Node.cpp:29