HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Window.h
Go to the documentation of this file.
1 
2 #ifndef __RE_Window_h__
3 #define __RE_Window_h__
4 
5 #include "RE_API.h"
6 #include "RE_IDType.h"
7 #include "RE_Types.h"
8 
9 #include <UT/UT_Lock.h>
10 #include <UT/UT_NonCopyable.h>
11 #include <UT/UT_Rect.h>
12 #include <UT/UT_UniquePtr.h>
13 #include <UT/UT_ValArray.h>
14 
15 #include <utility>
16 
17 class RE_Render;
18 class RE_Server;
19 class RE_Visual;
20 class RE_WindowDrawable;
21 
22 class QWidget;
23 
24 
26 {
28  alwaysOnTop:1,
29  maximized:1,
30  fullscreen:1;
31 };
32 
33 /// ==========================================================================
34 /// For new 2D UI drawing.
35 ///
36 /// Abstract base class representing an owner of an RE_Window.
37 ///
39 {
40 public:
42  virtual ~RE_WindowOwner() {}
44 
45  virtual void initializeForRender() = 0;
46  virtual void render() = 0;
47 };
48 /// ==========================================================================
49 
51 {
52 public:
53  RE_Window(RE_Server *server,
55  RE_VisualType visType = RE_NORMAL_VIS,
56  RE_WindowOwner *owner = nullptr);
57 
58  virtual ~RE_Window();
59 
60  void setName(const char *name);
61  void setIconName(const char *name);
62 
63  void setParentWindow(RE_Window *parent);
64  const RE_Window *getParentWindow() const { return parentWindow; }
65 
66  void setDialogParentHint(RE_IDType parent_hint);
67 
68  // TODO: No need for getServer(). Move getVisual() to RE_GLDrawable.
69  RE_Server *getServer() { return myServer; }
71  { return myVisualResource; }
72 
73  RE_Render *getRender();
75  { myRender = std::move(r); }
76 
77  RE_IDType openWindow();
78  RE_IDType openWindow(bool show);
79  void showWindow();
80  void closeWindow();
81 
82  void initMaxSize(int w, int h );
83  void initMinSize(int w, int h );
84  void initVisual( RE_Visual *visual );
85  void setLimitPositions(bool limitpos)
86  { myLimitPositions = limitpos; }
87  bool getLimitPositions() const
88  { return myLimitPositions; }
89 
90  void moveWindow(int x, int y);
91  void sizeWindow(int w, int h);
92 
93  // Set the window's opacity (0.0 - 1.0).
94  // Values less than 1.0 will make the window translucent.
95  void setWindowOpacity(fpreal opacity);
96 
97 
98  // Maximize the window and/or mark it as maximized so that when openWindow
99  // is called, it can open the window maximized.
100  void maximizeWindow();
101  void restoreWindow();
102 
103  bool isMaximized() const;
104 
105  // Set the window as fullscreen. Depending on the windowing system, this
106  // either informs the window manager to set us as fullscreen or simply
107  // sets borders up so that higher-level classes can do the fullscreening
108  // themselves.
109  void fullscreenWindow(bool full);
110  bool isFullscreenWindow() const;
111  void lowerWindow();
112  void raiseWindow();
113 
114  // Show/Hide the Window Frame/ Titlebar
115  void setHasWindowFrame(bool b);
116  bool hasWindowFrame() const;
117 
118  int getBorderWidth() const
119  { return myLeftBorder+myRightBorder; }
120  int getBorderHeight() const
121  { return myTopBorder+myBottomBorder; }
122  int getBorderTopSize() const
123  { return myTopBorder; }
124  int getBorderLeftSize() const
125  { return myLeftBorder; }
127  { return myBottomBorder; }
128  int getBorderRightSize() const
129  { return myRightBorder; }
130 
131  UT_DimRect findLocation() const;
132  UT_DimRect getNormalGeometry() const;
133 
134  // Sets the window to sit on top of all other windows, or turns off that
135  // state, depending on whether newstate is true or false.
136  void setWindowAlwaysOnTop(bool newstate);
137  int getWindowAlwaysOnTop() const { return winFlags.alwaysOnTop; }
138 
139  void setWindowFloatOnTop(bool on_top);
140 
141  RE_DisplayMode getMode() const;
142 
144  { return myVisualType; }
145  void setVisualType(RE_VisualType t) { myVisualType = t; }
146 
147  // changes to the type will not occur until the window is opened again.
149  { myWindowType = t; }
150 
151  RE_WindowType getWindowType( bool extra=false) const;
152 
153 
154  void setWindowID(RE_IDType id) { myWindowID = id; }
156  { return myWindowID; }
157  int matchID( RE_IDType wid ) const
158  { return wid == myWindowID; }
159 
160  virtual RE_IDType getBufferID() const { return 0; }
161 
162  /// =====================================================================
163  /// For new 2D UI drawing.
164  RE_WindowDrawable *getDrawable() const { return myWindowDrawable; }
165  void setDrawable(RE_WindowDrawable *d);
166  /// =====================================================================
167 
168  /// =====================================================================
169  /// For OpenGL 2D UI drawing.
170  OGLDrawable getGraphicsDrawable() const { return myDrawable; }
171  void setGraphicsDrawable(OGLDrawable d) { myDrawable = d; }
172  /// =====================================================================
173 
174 
175  void setIMESupport(bool enable);
176 
177  /// Return the Qt main window.
178  static QWidget * mainQtWindow();
179 
180  /// Initialize the given widget window with the desired
181  /// Houdini window properties, look and feel.
182  static void initQtWindow(
183  QWidget &window, RE_WindowType win_type,
184  bool always_on_top);
185 
186  /// Create a Qt window widget for the given window type.
187  /// The caller takes ownership of the returned object.
188  static QWidget * createQtWindow(RE_WindowType win_type);
189 
190  /// Returns true if Houdini or any of its sub windows are focused
191  static bool appActive();
192 
193  void setWindowBorders(int left, int right, int top, int bottom)
194  {
195  myLeftBorder = left;
196  myRightBorder = right;
197  myTopBorder = top;
198  myBottomBorder = bottom;
199  }
200 
201  // This is called by the native window to inform that it has changed its
202  // maximized state.
203  void updateMaximizedFlag(bool is_maximized)
204  {
205  winFlags.maximized = is_maximized;
206  }
207 
208  static bool isTabFocusEnabled();
209  static void enableTabFocus(bool enable);
210 
211  /// Return the string tag used to identify whether a Qt widget is the
212  /// window for an RE_Window object.
213  static const char * windowTag() { return "RE_Window"; }
214 
215  bool isQuadBufferStereo() const;
216 
217  /// Return the screen number containing this window.
218  /// If the underlying platform window has not been created
219  /// yet then return the primary screen number.
220  int screen() const;
221 
222  /// Get screen-to-window scale.
223  fpreal screenToDeviceScale() const;
224 
225  /// =====================================================================
226  /// For new 2D UI drawing.
227 
228  /// Request that the window render it's contents.
229  void requestRender();
230 
231  /// Pass key class to help restrict method access to the RE_WindowDrawable
232  /// class.
234  {
235  private:
236  friend RE_WindowDrawable;
237  DrawablePassKey() = default;
238  ~DrawablePassKey() = default;
239  };
240 
241  /// Initialize the window in preparation of rendering the window's contents.
242  /// This method is meant to be called only from RE_WindowDrawable.
243  void initializeForRender(const DrawablePassKey &k);
244 
245  /// Render the window's contents.
246  /// This method is meant to be called only from RE_WindowDrawable.
247  void render(const DrawablePassKey &k);
248  /// =====================================================================
249 
250  /// Get Default Window Border Sizes
251  static const int* getDefaultWindowBorderSizes();
252  static int getDefaultWindowTitleBarHeight();
253 
254 private:
255  /// Initialize window borders.
256  void initBorderSizes_();
257 
258  /// Move the underlying Qt window to the position specified by myFrame.
259  void moveQtWindow_();
260 
261 #if defined(WIN32)
262  /// Add the Always On Top menu item to the window's system menu.
263  void addAlwaysOnTopSystemMenuItem_();
264 #endif
265 
266 private:
267  /// =====================================================================
268  /// For new 2D UI drawing.
269  RE_WindowOwner *myOwner;
270  /// =====================================================================
271 
272  RE_Server *myServer;
273  UT_UniquePtr<RE_Render> myRender;
274  RE_Visual *myVisualResource;
275  RE_VisualType myVisualType;
276  RE_IDType myWindowID;
277 
278 #if defined(WIN32) || defined(USE_QT6)
279  // This widget is for stashing away the Qt window when it closes and
280  // detaches from its parent window. There's a limitation where a Qt
281  // window cannot gracefully detach itself from the parent. Doing so
282  // typically changes the child widget's window flags and creates
283  // unwanted system windows.
284  //
285  // The workaround is to instead reparent the Qt window instead of
286  // completely detaching it.
287  QWidget *myStashWidget;
288 #endif
289 
290  UT_String myName;
291  UT_String myIconName;
292 
293  // Window geometry in native screen coordinates and scaling.
294  UT_DimRect myFrame;
295 
296  using IntPair = std::pair<int, int>;
297 
298  // Window sizes in native screen scaling.
299  IntPair myMinSize;
300  IntPair myMaxSize;
301 
302  /// =====================================================================
303  /// For new 2D UI drawing.
304  RE_WindowDrawable *myWindowDrawable;
305  /// =====================================================================
306 
307  /// =====================================================================
308  /// For OpenGL 2D UI drawing.
309  OGLDrawable myDrawable;
310  /// =====================================================================
311 
312  unsigned long myIconPixmap;
313  RE_WindowFlags winFlags;
314  RE_Window *parentWindow;
315  RE_IDType myDialogParentHint;
316 
317  RE_WindowType myWindowType;
318 
319  int myLeftBorder;
320  int myTopBorder;
321  int myRightBorder;
322  int myBottomBorder;
323 
324  unsigned int myLimitPositions:1;
325 
326  fpreal myWindowOpacity;
327 
328 #if defined(WIN32)
329  bool myAddedAlwaysOnTopMenuItem;
330 #endif
331 
332  bool myIsResizing;
333 };
334 
336 {
337 public:
339  { }
341  { }
342 
343  void lock()
344  { myLock.lock(); }
345  void unlock()
346  { myLock.unlock(); }
348  { lock(); myWindows.append(w); unlock(); }
350  { lock(); myWindows.findAndRemove(w); unlock(); }
351  int getNumWindows() const
352  { return myWindows.entries(); }
354  { return myWindows(index); }
355  void removeWindow(RE_IDType wid);
356  RE_Window *isWindowHere(RE_IDType wid);
357 
358 private:
359  UT_ValArray<RE_Window *> myWindows;
360  UT_Lock myLock;
361 };
362 
363 #endif
void * RE_IDType
Definition: RE_IDType.h:20
void removeWindow(RE_Window *w)
Definition: RE_Window.h:349
const RE_Window * getParentWindow() const
Definition: RE_Window.h:64
bool isOriginReadjusted
Definition: RE_Window.h:27
#define RE_API
Definition: RE_API.h:10
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
void setWindowID(RE_IDType id)
Definition: RE_Window.h:154
RE_VisualType getVisualType() const
Definition: RE_Window.h:143
==========================================================================
Definition: RE_Window.h:50
GLint left
Definition: glcorearb.h:2005
int getBorderLeftSize() const
Definition: RE_Window.h:124
int getBorderWidth() const
Definition: RE_Window.h:118
void setWindowType(RE_WindowType t)
Definition: RE_Window.h:148
GLdouble right
Definition: glad.h:2817
void addWindow(RE_Window *w)
Definition: RE_Window.h:347
GLint y
Definition: glcorearb.h:103
RE_Window * getWindow(int index) const
Definition: RE_Window.h:353
int getWindowAlwaysOnTop() const
Definition: RE_Window.h:137
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
bool alwaysOnTop
Definition: RE_Window.h:27
OGLDrawable getGraphicsDrawable() const
=====================================================================
Definition: RE_Window.h:170
void setGraphicsDrawable(OGLDrawable d)
Definition: RE_Window.h:171
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
void unlock()
Definition: RE_Window.h:345
int getBorderBottomSize() const
Definition: RE_Window.h:126
void setVisualType(RE_VisualType t)
Definition: RE_Window.h:145
virtual RE_IDType getBufferID() const
Definition: RE_Window.h:160
int matchID(RE_IDType wid) const
Definition: RE_Window.h:157
int getNumWindows() const
Definition: RE_Window.h:351
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
RE_WindowDrawable * getDrawable() const
Definition: RE_Window.h:164
int getBorderRightSize() const
Definition: RE_Window.h:128
GLuint id
Definition: glcorearb.h:655
GLuint const GLchar * name
Definition: glcorearb.h:786
RE_DisplayMode
Definition: RE_Types.h:580
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
void setLimitPositions(bool limitpos)
Definition: RE_Window.h:85
GLdouble t
Definition: glad.h:2397
GLint GLint bottom
Definition: glcorearb.h:2005
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
bool maximized
Definition: RE_Window.h:27
fpreal64 fpreal
Definition: SYS_Types.h:278
RE_Visual * getVisual()
Definition: RE_Window.h:70
int getBorderHeight() const
Definition: RE_Window.h:120
virtual ~RE_WindowOwner()
Definition: RE_Window.h:42
GLuint index
Definition: glcorearb.h:786
RE_VisualType
Definition: RE_Types.h:630
void lock()
Definition: RE_Window.h:343
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
bool fullscreen
Definition: RE_Window.h:27
int getBorderTopSize() const
Definition: RE_Window.h:122
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void setRender(UT_UniquePtr< RE_Render > r)
Definition: RE_Window.h:74
GLboolean r
Definition: glcorearb.h:1222
void updateMaximizedFlag(bool is_maximized)
Definition: RE_Window.h:203
void setWindowBorders(int left, int right, int top, int bottom)
Definition: RE_Window.h:193
RE_WindowType
Definition: RE_Types.h:29
static const char * windowTag()
Definition: RE_Window.h:213
bool getLimitPositions() const
Definition: RE_Window.h:87
RE_IDType getWindowID() const
Definition: RE_Window.h:155
RE_Server * getServer()
Definition: RE_Window.h:69