libvwad: updated -- vwadwrite: free file buffers on close (otherwise archive creation...
[k8vavoom.git] / source / widgets / ui_root.h
blobbae041d0f9e43bd637ef94f6eced0e37b16d9db5
1 //**************************************************************************
2 //**
3 //** ## ## ## ## ## #### #### ### ###
4 //** ## ## ## ## ## ## ## ## ## ## #### ####
5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ##
6 //** ## ## ######## ## ## ## ## ## ## ## ### ##
7 //** ### ## ## ### ## ## ## ## ## ##
8 //** # ## ## # #### #### ## ##
9 //**
10 //** Copyright (C) 1999-2006 Jānis Legzdiņš
11 //** Copyright (C) 2018-2023 Ketmar Dark
12 //**
13 //** This program is free software: you can redistribute it and/or modify
14 //** it under the terms of the GNU General Public License as published by
15 //** the Free Software Foundation, version 3 of the License ONLY.
16 //**
17 //** This program is distributed in the hope that it will be useful,
18 //** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 //** GNU General Public License for more details.
21 //**
22 //** You should have received a copy of the GNU General Public License
23 //** along with this program. If not, see <http://www.gnu.org/licenses/>.
24 //**
25 //**************************************************************************
26 #ifndef VAVOOM_UIWIDGETS_ROOT_HEADER
27 #define VAVOOM_UIWIDGETS_ROOT_HEADER
30 class VRootWidget : public VWidget {
31 DECLARE_CLASS(VRootWidget, VWidget, 0)
32 NO_DEFAULT_CONSTRUCTOR(VRootWidget)
34 private:
35 struct SavedEventParts {
36 int type; // 0: none; 1: x,y; 2: d/m
37 int x, y, dx, dy, msx, msy;
40 private:
41 enum {
42 // true if mouse cursor is currently enabled
43 RWF_MouseEnabled = 1u<<0,
44 RWF_MouseForced = 1u<<1, // set if any child want mouse input
46 vuint32 RootFlags;
48 // current mouse cursor position (screen coords)
49 vint32 MouseX;
50 vint32 MouseY;
52 // current mouse cursor graphic
53 vint32 MouseCursorPic;
55 private:
56 // used in `InternalResponder()`
57 // [0] is the topmost widget, [1] is child, and so on
58 TArray<VWidget *> EventPath;
60 private:
61 void UpdateMouseForced ();
63 // this generates mouse leave/enter
64 void MouseMoveEvent (const event_t *evt, int OldMouseX, int OldMouseY);
66 void MouseClickEvent (const event_t *evt);
68 // adds `lastOne` if it is not the last one already
69 void BuildEventPath (VWidget *lastOne=nullptr) noexcept;
71 // the path should be already built
72 // returns `true` if any handler returned `true`
73 // sets `eaten` if any handler returned `true`
74 bool DispatchEvent (event_t *evt);
76 void UpdateMousePosition (int NewX, int NewY) noexcept;
78 void FixEventCoords (VWidget *w, event_t *evt, SavedEventParts &svparts) noexcept;
79 void RestoreEventCoords (event_t *evt, const SavedEventParts &svparts) noexcept;
81 // this is called by the engine to dispatch the event
82 bool InternalResponder (event_t *evt);
84 public:
85 void Init ();
86 virtual void Init (VWidget *) override { Sys_Error("Root cannot have a parent"); }
88 void DrawWidgets ();
89 void TickWidgets (float DeltaTime);
91 // this is called by the engine to dispatch the event
92 bool Responder (event_t *evt);
94 void SetMouse (bool MouseOn);
95 inline bool IsMouseAllowed () const noexcept { return !!(RootFlags&RWF_MouseEnabled); }
97 void RefreshScale ();
99 // can return `none` if coords are out of any widget
100 VWidget *GetWidgetAtScreenXY (int x, int y, bool allowDisabled=false) noexcept;
102 static void StaticInit ();
104 DECLARE_FUNCTION(SetMouse)
105 DECLARE_FUNCTION(GetWidgetAtScreenXY)
108 extern VRootWidget *GRoot;
111 #endif