Loading [MathJax]/extensions/TeX/AMSmath.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
40 namespace open3d {
41 namespace visualization {
42 namespace gui {
43 
44 class Dialog;
45 class Menu;
46 class Renderer;
47 struct Theme;
48 
49 class Window {
50  friend class Application;
51  friend class Renderer;
52 
53 public:
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 
151  void ShowDialog(std::shared_ptr<Dialog> dlg);
153  void CloseDialog();
154 
155  void ShowMessageBox(const char* title, const char* message);
156 
159  void DestroyWindow();
160 
161  // Override to handle menu items
162  virtual void OnMenuItemSelected(Menu::ItemId item_id);
163 
164  // Override to handle drag and drop on the windows.
165  virtual void OnDragDropped(const char* path);
166 
167  // Shows or hides the menubar, except on macOS when using real windows.
168  // This is intended to be used when using HeadlessWindowSystem but may
169  // be useful in other circumstances.
170  void ShowMenu(bool show);
171 
172  int GetMouseMods() const; // internal, for WindowSystem
173 
177  std::string GetWebRTCUID() const;
178 
179 protected:
185  virtual Size CalcPreferredSize();
186 
190  virtual void Layout(const LayoutContext& context);
191 
193 
194  const std::vector<std::shared_ptr<Widget>>& GetChildren() const;
195 
196 public:
197  // these are intended for internal delivery of events
198  void OnDraw();
199  void OnResize();
200  void OnMouseEvent(const MouseEvent& e);
201  void OnKeyEvent(const KeyEvent& e);
202  void OnTextInput(const TextInputEvent& e);
203  void OnTickEvent(const TickEvent& e);
204 
206 
207 private:
208  void CreateRenderer();
209  Widget::DrawResult DrawOnce(bool is_layout_pass);
210  void* MakeDrawContextCurrent() const;
211  void RestoreDrawContext(void* old_context) const;
212 
213 private:
214  struct Impl;
215  std::unique_ptr<Impl> impl_;
216 };
217 
218 } // namespace gui
219 } // namespace visualization
220 } // namespace open3d
friend class Renderer
Definition: Window.h:51
Rect GetOSFrame() const
Definition: Window.cpp:469
void OnTextInput(const TextInputEvent &e)
Definition: Window.cpp:1203
Definition: Theme.h:39
Definition: Application.h:58
int height
Definition: FilePCD.cpp:72
std::string GetWebRTCUID() const
Definition: Window.cpp:436
Definition: Window.h:49
void ShowMessageBox(const char *title, const char *message)
Definition: Window.cpp:675
virtual ~Window()
Definition: Window.cpp:418
void RaiseToTop() const
Definition: Window.cpp:603
Point GlobalToWindowCoord(int global_x, int global_y)
Returns the global point (in OS pixels) in window local coordinates.
Definition: Window.cpp:561
void ShowMenu(bool show)
Definition: Window.cpp:688
void SetTitle(const char *title)
Definition: Window.cpp:484
virtual Size CalcPreferredSize()
Definition: Window.cpp:493
WindowSystem::OSWindow GetOSWindow() const
Definition: Window.cpp:715
void OnKeyEvent(const KeyEvent &e)
Definition: Window.cpp:1167
visualization::rendering::Renderer & GetRenderer() const
Definition: Window.cpp:465
Definition: Widget.h:68
void Close()
Definition: Window.cpp:577
int ItemId
Definition: MenuBase.h:47
void SetOSFrame(const Rect &r)
Definition: Window.cpp:476
void SetFocusWidget(Widget *w)
Sets.
Definition: Window.cpp:613
void SetOnClose(std::function< bool()> callback)
Definition: Window.cpp:629
void CloseDialog()
Closes the dialog.
Definition: Window.cpp:662
void DestroyWindow()
Definition: Window.cpp:427
void SetNeedsLayout()
Instructs the window to relayout before the next draw.
Definition: Window.cpp:589
void SizeToFit()
Definition: Window.cpp:518
ImGuiContext * context
Definition: Window.cpp:95
void SetSize(const Size &size)
Sets the size of the window in pixels. Includes menubar on Linux.
Definition: Window.cpp:526
bool IsActiveWindow() const
Definition: Window.cpp:608
Window(const std::string &title, int flags=0)
Definition: Window.cpp:255
const Theme & GetTheme() const
Definition: Window.cpp:463
void PostRedraw()
Definition: Window.cpp:591
const char * GetTitle() const
Definition: Window.cpp:482
bool IsVisible() const
Definition: Window.cpp:567
static const int FLAG_HIDDEN
Definition: Window.h:54
virtual void OnDragDropped(const char *path)
Definition: Window.cpp:1232
float GetScaling() const
Returns the scaling factor from OS pixels to device pixels.
Definition: Window.cpp:556
virtual void OnMenuItemSelected(Menu::ItemId item_id)
Definition: Window.cpp:707
Size GetSize() const
Definition: Window.cpp:539
static const int FLAG_TOPMOST
Definition: Window.h:55
void AddChild(std::shared_ptr< Widget > w)
Definition: Window.cpp:615
Definition: PinholeCameraIntrinsic.cpp:35
void OnMouseEvent(const MouseEvent &e)
Definition: Window.cpp:1048
void OnTickEvent(const TickEvent &e)
Definition: Window.cpp:1212
void Show(bool vis=true)
Definition: Window.cpp:572
void * OSWindow
Definition: WindowSystem.h:48
void SetOnMenuItemActivated(Menu::ItemId item_id, std::function< void()> callback)
Definition: Window.cpp:620
Rect GetContentRect() const
Definition: Window.cpp:544
void OnDraw()
Definition: Window.cpp:939
const std::vector< std::shared_ptr< Widget > > & GetChildren() const
Definition: Window.cpp:449
LayoutContext GetLayoutContext()
Definition: Window.cpp:693
Definition: Events.h:210
void SetOnTickEvent(std::function< bool()> callback)
Definition: Window.cpp:625
virtual void Layout(const LayoutContext &context)
Definition: Window.cpp:695
void ShowDialog(std::shared_ptr< Dialog > dlg)
Definition: Window.cpp:633
DrawResult
Definition: Widget.h:114
int GetMouseMods() const
Definition: Window.cpp:434
int size
Definition: FilePCD.cpp:59
void OnResize()
Definition: Window.cpp:970
int width
Definition: FilePCD.cpp:71
std::function< void(std::shared_ptr< core::Tensor >)> callback
Definition: FilamentRenderer.cpp:227