Open3D (C++ API)  0.16.0
Window.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
29#include <functional>
30#include <memory>
31#include <string>
32
39
40namespace open3d {
41namespace visualization {
42namespace gui {
43
44class Dialog;
45class Menu;
46class Renderer;
47struct Theme;
48
49class Window {
50 friend class Application;
51 friend class Renderer;
52
53public:
54 static const int FLAG_HIDDEN;
55 static const int FLAG_TOPMOST;
56
60 explicit Window(const std::string& title, int flags = 0);
61
65 Window(const std::string& title,
66 int width,
67 int height,
68 int flags = 0); // centered
69
73 Window(const std::string& title,
74 int x,
75 int y,
76 int width,
77 int height,
78 int flags = 0);
79 virtual ~Window();
80
81 const Theme& GetTheme() const;
83
86 Rect GetOSFrame() const;
89 void SetOSFrame(const Rect& r);
90
91 const char* GetTitle() const;
92 void SetTitle(const char* title);
93
96 void SizeToFit();
97
99 void SetSize(const Size& size);
102 Size GetSize() const;
105 Rect GetContentRect() const;
107 float GetScaling() const;
109 Point GlobalToWindowCoord(int global_x, int global_y);
110
111 bool IsVisible() const;
112 void Show(bool vis = true);
115 void Close();
116
118 void SetNeedsLayout();
121 void PostRedraw();
122
123 void SetTopmost(bool topmost);
124 void RaiseToTop() const;
125
126 bool IsActiveWindow() const;
127
129 void SetFocusWidget(Widget* w);
130
131 void AddChild(std::shared_ptr<Widget> w);
132
137 std::function<void()> callback);
138
142 void SetOnTickEvent(std::function<bool()> callback);
143
147 void SetOnClose(std::function<bool()> callback);
148
152 void SetOnKeyEvent(std::function<bool(const KeyEvent&)> callback);
153
156 void ShowDialog(std::shared_ptr<Dialog> dlg);
158 void CloseDialog();
159
160 void ShowMessageBox(const char* title, const char* message);
161
164 void DestroyWindow();
165
166 // Override to handle menu items
167 virtual void OnMenuItemSelected(Menu::ItemId item_id);
168
169 // Override to handle drag and drop on the windows.
170 virtual void OnDragDropped(const char* path);
171
172 // Shows or hides the menubar, except on macOS when using real windows.
173 // This is intended to be used when using HeadlessWindowSystem but may
174 // be useful in other circumstances.
175 void ShowMenu(bool show);
176
177 int GetMouseMods() const; // internal, for WindowSystem
178
182 std::string GetWebRTCUID() const;
183
184protected:
190 virtual Size CalcPreferredSize();
191
195 virtual void Layout(const LayoutContext& context);
196
198
199 const std::vector<std::shared_ptr<Widget>>& GetChildren() const;
200
201public:
202 // these are intended for internal delivery of events
203 void OnDraw();
204 void OnResize();
205 void OnMouseEvent(const MouseEvent& e);
206 void OnKeyEvent(const KeyEvent& e);
207 void OnTextInput(const TextInputEvent& e);
208 void OnTickEvent(const TickEvent& e);
209
211
212private:
213 void CreateRenderer();
214 Widget::DrawResult DrawOnce(bool is_layout_pass);
215 void* MakeDrawContextCurrent() const;
216 void RestoreDrawContext(void* old_context) const;
217
218private:
219 struct Impl;
220 std::unique_ptr<Impl> impl_;
221};
222
223} // namespace gui
224} // namespace visualization
225} // namespace open3d
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:201
ImGuiContext * context
Definition: Window.cpp:95
Definition: Application.h:58
int ItemId
Definition: MenuBase.h:47
Definition: Widget.h:68
DrawResult
Definition: Widget.h:114
Definition: Window.h:49
WindowSystem::OSWindow GetOSWindow() const
Definition: Window.cpp:720
void SetOnMenuItemActivated(Menu::ItemId item_id, std::function< void()> callback)
Definition: Window.cpp:621
const Theme & GetTheme() const
Definition: Window.cpp:464
void OnMouseEvent(const MouseEvent &e)
Definition: Window.cpp:1053
void CloseDialog()
Closes the dialog.
Definition: Window.cpp:667
void SetTitle(const char *title)
Definition: Window.cpp:485
void SetOnKeyEvent(std::function< bool(const KeyEvent &)> callback)
Definition: Window.cpp:634
void PostRedraw()
Definition: Window.cpp:592
LayoutContext GetLayoutContext()
Definition: Window.cpp:698
void SetOnClose(std::function< bool()> callback)
Definition: Window.cpp:630
void AddChild(std::shared_ptr< Widget > w)
Definition: Window.cpp:616
const char * GetTitle() const
Definition: Window.cpp:483
void SetOSFrame(const Rect &r)
Definition: Window.cpp:477
std::string GetWebRTCUID() const
Definition: Window.cpp:437
friend class Renderer
Definition: Window.h:51
void ShowMessageBox(const char *title, const char *message)
Definition: Window.cpp:680
void ShowDialog(std::shared_ptr< Dialog > dlg)
Definition: Window.cpp:638
virtual void Layout(const LayoutContext &context)
Definition: Window.cpp:700
virtual void OnDragDropped(const char *path)
Definition: Window.cpp:1243
Size GetSize() const
Definition: Window.cpp:540
virtual Size CalcPreferredSize()
Definition: Window.cpp:494
int GetMouseMods() const
Definition: Window.cpp:435
void SetSize(const Size &size)
Sets the size of the window in pixels. Includes menubar on Linux.
Definition: Window.cpp:527
static const int FLAG_HIDDEN
Definition: Window.h:54
void Show(bool vis=true)
Definition: Window.cpp:573
visualization::rendering::Renderer & GetRenderer() const
Definition: Window.cpp:466
void OnResize()
Definition: Window.cpp:975
Rect GetOSFrame() const
Definition: Window.cpp:470
void Close()
Definition: Window.cpp:578
Point GlobalToWindowCoord(int global_x, int global_y)
Returns the global point (in OS pixels) in window local coordinates.
Definition: Window.cpp:562
void RaiseToTop() const
Definition: Window.cpp:604
const std::vector< std::shared_ptr< Widget > > & GetChildren() const
Definition: Window.cpp:450
void OnDraw()
Definition: Window.cpp:944
void SetNeedsLayout()
Instructs the window to relayout before the next draw.
Definition: Window.cpp:590
void DestroyWindow()
Definition: Window.cpp:428
bool IsVisible() const
Definition: Window.cpp:568
void OnTickEvent(const TickEvent &e)
Definition: Window.cpp:1223
bool IsActiveWindow() const
Definition: Window.cpp:609
void SetOnTickEvent(std::function< bool()> callback)
Definition: Window.cpp:626
static const int FLAG_TOPMOST
Definition: Window.h:55
float GetScaling() const
Returns the scaling factor from OS pixels to device pixels.
Definition: Window.cpp:557
virtual void OnMenuItemSelected(Menu::ItemId item_id)
Definition: Window.cpp:712
Rect GetContentRect() const
Definition: Window.cpp:545
void SetFocusWidget(Widget *w)
Sets.
Definition: Window.cpp:614
Window(const std::string &title, int flags=0)
Definition: Window.cpp:256
void ShowMenu(bool show)
Definition: Window.cpp:693
void OnTextInput(const TextInputEvent &e)
Definition: Window.cpp:1214
virtual ~Window()
Definition: Window.cpp:419
void SizeToFit()
Definition: Window.cpp:519
void OnKeyEvent(const KeyEvent &e)
Definition: Window.cpp:1173
void * OSWindow
Definition: WindowSystem.h:48
int width
Definition: FilePCD.cpp:71
int size
Definition: FilePCD.cpp:59
int height
Definition: FilePCD.cpp:72
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Events.h:222
Definition: Theme.h:39