Simple GUI Library
scene.h
Go to the documentation of this file.
1/**
2 * @author Nikita Mochalov (github.com/tralf-strues)
3 * @file scene.h
4 * @date 2021-11-06
5 *
6 * @copyright Copyright (c) 2021
7 */
8
9#pragma once
10
11#include "../events/gui_event_dispatching.h"
12#include "containers/menu_bar.h"
13
14namespace Sgl
15{
16 class Component;
17 class Parent;
18
19 class Scene : public Sml::EventTarget
20 {
21 public:
22 Scene(int32_t width, int32_t height);
23 Scene() = default;
24 ~Scene() = default;
25
26 void update();
27 void render(const Sml::Rectangle<int32_t>& targetRegion);
28 void proccessEvent(Sml::Event* event);
29
30 virtual Sml::EventDispatchChain* buildEventDispatchChain(Sml::EventDispatchChain* chain) override;
31 GuiEventDispatcher* getEventDispatcher();
32
33 Sml::Rectangle<int32_t> getLayoutRegion() const;
34
35 int32_t getWidth() const;
36 void setWidth(int32_t width);
37
38 int32_t getHeight() const;
39 void setHeight(int32_t height);
40
41 Parent* getRoot();
42 void setRoot(Parent* root);
43
44 Component* getFocusOwner();
45 void requestFocus(Component* component);
46
47 Component* getDragOwner();
48 void requestDrag(Component* component);
49 void finishDrag();
50
51 void registerContextMenu(ContextMenu* contextMenu);
52 void detachContextMenu(ContextMenu* contextMenu);
53
54 private:
55 GuiEventDispatcher m_Dispatcher;
56
57 int32_t m_Width = 0;
58 int32_t m_Height = 0;
59
60 Parent* m_Root = nullptr;
61 Component* m_FocusOwner = nullptr;
62 Component* m_HoverOwner = nullptr;
63 Component* m_DragOwner = nullptr;
64
65 std::list<ContextMenu*> m_ContextMenus;
66
67 Component* findHitComponentInContextMenus(int32_t x, int32_t y, ContextMenu** menu);
68 Component* findHitComponentInRoot(int32_t x, int32_t y);
69 void updateHoverOwner(Component* newHoverOwner, int32_t mouseX, int32_t mouseY);
70 void updateFocusOwner(Component* newFocusOwner);
71 void proccessKeyboardEvent(Sml::KeyEvent* keyEvent);
72 void proccessMouseEvent(Sml::MouseEvent* mouseEvent);
73 };
74}