AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
Window.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_WINDOW_H
17#define AEONGUI_WINDOW_H
18#include <cstdint>
19#include <array>
20#include <memory>
21#include <unordered_map>
22#include <string>
23#include "aeongui/Platform.hpp"
24#include "aeongui/Canvas.hpp"
25#include "aeongui/dom/EventTarget.hpp"
26#include "aeongui/dom/USVString.hpp"
27#include "aeongui/dom/DOMString.hpp"
28#include "aeongui/dom/Location.hpp"
29#include "aeongui/dom/Document.hpp"
30
31namespace AeonGUI
32{
33 namespace DOM
34 {
35 class Document;
43 class Window : public EventTarget
44 {
45 public:
47 DLL Window ();
52 DLL Window ( uint32_t aWidth, uint32_t aHeight );
54 DLL ~Window () override final;
59 DLL void ResizeViewport ( uint32_t aWidth, uint32_t aHeight );
63 DLL const uint8_t* GetPixels() const;
66 DLL size_t GetWidth() const;
69 DLL size_t GetHeight() const;
72 DLL size_t GetStride() const;
76 DLL bool Draw();
80 DLL void Update ( double aDeltaTime );
85 DLL const Document* document() const;
89 DLL Location& location() const;
101 DLL void HandleMouseMove ( double aX, double aY, unsigned short aButtons = 0,
102 bool aCtrlKey = false, bool aShiftKey = false,
103 bool aAltKey = false, bool aMetaKey = false );
114 DLL void HandleMouseDown ( double aX, double aY, short aButton = 0,
115 unsigned short aButtons = 0,
116 bool aCtrlKey = false, bool aShiftKey = false,
117 bool aAltKey = false, bool aMetaKey = false );
128 DLL void HandleMouseUp ( double aX, double aY, short aButton = 0,
129 unsigned short aButtons = 0,
130 bool aCtrlKey = false, bool aShiftKey = false,
131 bool aAltKey = false, bool aMetaKey = false );
142 DLL void HandleKeyDown ( const DOMString& aKey, const DOMString& aCode,
143 unsigned long aLocation = 0, bool aRepeat = false,
144 bool aCtrlKey = false, bool aShiftKey = false,
145 bool aAltKey = false, bool aMetaKey = false );
155 DLL void HandleKeyUp ( const DOMString& aKey, const DOMString& aCode,
156 unsigned long aLocation = 0,
157 bool aCtrlKey = false, bool aShiftKey = false,
158 bool aAltKey = false, bool aMetaKey = false );
171 DLL void HandleWheel ( double aX, double aY,
172 double aDeltaX, double aDeltaY,
173 unsigned long aDeltaMode = 0,
174 unsigned short aButtons = 0,
175 bool aCtrlKey = false, bool aShiftKey = false,
176 bool aAltKey = false, bool aMetaKey = false );
178 private:
179 void OnLocationChanged ( const Location& location );
180 Element* elementFromPoint ( double aX, double aY ) const;
181 void FullDraw();
182 void PartialDraw();
183 void AssignPickIds();
184 void CacheBounds();
185 Element* mFocusedElement{nullptr};
186 Element* mHoverElement{nullptr};
187 Element* mActiveElement{nullptr};
188 Location mLocation{std::bind ( &Window::OnLocationChanged, this, std::placeholders::_1 ) };
189 Document mDocument{};
190 std::unique_ptr<Canvas> mCanvas;
191 std::array<Element*, 256> mPickElements{};
192 uint8_t mPickIdCounter{0};
194 std::unordered_map<const Element*, Canvas::PickBounds> mCachedBounds{};
195 };
196 }
197}
198#endif
Platform-specific DLL import/export macros and compiler helpers.
Represents a DOM Document.
Definition Document.hpp:40
Base class for DOM elements.
Definition Element.hpp:46
Base class for objects that can receive DOM events.
Definition EventTarget.hpp:58
Represents the URL of the active document.
Definition Location.hpp:33
void HandleMouseDown(double aX, double aY, short aButton=0, unsigned short aButtons=0, bool aCtrlKey=false, bool aShiftKey=false, bool aAltKey=false, bool aMetaKey=false)
Handle a mouse button press event from the platform.
Definition Window.cpp:333
void HandleKeyUp(const DOMString &aKey, const DOMString &aCode, unsigned long aLocation=0, bool aCtrlKey=false, bool aShiftKey=false, bool aAltKey=false, bool aMetaKey=false)
Handle a keyboard key up event from the platform.
Definition Window.cpp:414
void HandleKeyDown(const DOMString &aKey, const DOMString &aCode, unsigned long aLocation=0, bool aRepeat=false, bool aCtrlKey=false, bool aShiftKey=false, bool aAltKey=false, bool aMetaKey=false)
Handle a keyboard key down event from the platform.
Definition Window.cpp:404
~Window() override final
Destructor.
size_t GetWidth() const
Get the window width in pixels.
Definition Window.cpp:92
Location & location() const
Get the Location object.
Definition Window.cpp:71
size_t GetHeight() const
Get the window height in pixels.
Definition Window.cpp:96
void HandleMouseUp(double aX, double aY, short aButton=0, unsigned short aButtons=0, bool aCtrlKey=false, bool aShiftKey=false, bool aAltKey=false, bool aMetaKey=false)
Handle a mouse button release event from the platform.
Definition Window.cpp:381
void Update(double aDeltaTime)
Advance animation time and update all animations.
Definition Window.cpp:243
void HandleWheel(double aX, double aY, double aDeltaX, double aDeltaY, unsigned long aDeltaMode=0, unsigned short aButtons=0, bool aCtrlKey=false, bool aShiftKey=false, bool aAltKey=false, bool aMetaKey=false)
Handle a wheel/scroll event from the platform.
Definition Window.cpp:424
const Document * document() const
Get the associated Document.
Definition Window.cpp:66
Window()
Default constructor. Creates an empty window.
Definition Window.cpp:46
size_t GetStride() const
Get the stride (bytes per row) of the pixel buffer.
Definition Window.cpp:100
void HandleMouseMove(double aX, double aY, unsigned short aButtons=0, bool aCtrlKey=false, bool aShiftKey=false, bool aAltKey=false, bool aMetaKey=false)
Handle a mouse move event from the platform.
Definition Window.cpp:254
bool Draw()
Render the current document to the internal canvas.
Definition Window.cpp:105
void ResizeViewport(uint32_t aWidth, uint32_t aHeight)
Resize the rendering viewport.
Definition Window.cpp:81
const uint8_t * GetPixels() const
Get a pointer to the rendered pixel data.
Definition Window.cpp:87