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_OpenGLDrawable;
22 class RE_WindowDrawable;
23 
24 class QWidget;
25 
26 
28 {
30  alwaysOnTop:1,
31  maximized:1,
32  fullscreen:1;
33 };
34 
35 /// ==========================================================================
36 /// For new 2D UI drawing.
37 ///
38 /// Abstract base class representing an owner of an RE_Window.
39 ///
41 {
42 public:
44  virtual ~RE_WindowOwner() {}
46 
47  virtual void render() = 0;
48  virtual bool shouldApplyDevicePixelRatio() const = 0;
49  virtual bool useHoloStyle() const = 0;
50  virtual bool hasPendingLayoutsForPaint() const = 0;
51  virtual void deferPaintForPendingLayouts() = 0;
52  virtual void processPendingLayoutsForPaint() = 0;
53  virtual void handleScreenChanged() = 0;
54 };
55 /// ==========================================================================
56 
58 {
59 public:
60  RE_Window(RE_Server *server,
62  RE_VisualType visType = RE_NORMAL_VIS,
63  RE_WindowOwner *owner = nullptr);
64 
65  virtual ~RE_Window();
66 
67  void setName(const char *name);
68  void setIconName(const char *name);
69 
70  void setParentWindow(RE_Window *parent);
71  const RE_Window *getParentWindow() const { return parentWindow; }
72 
73  void setDialogParentHint(RE_IDType parent_hint);
74 
75  // TODO: No need for getServer(). Move getVisual() to RE_GLDrawable.
76  RE_Server *getServer() { return myServer; }
78  { return myVisualResource; }
79 
80  RE_Render *getRender();
82  { myRender = std::move(r); }
83 
84  RE_IDType openWindow();
85  RE_IDType openWindow(bool show);
86  void showWindow();
87  void closeWindow();
88 
89  void initMaxSize(int w, int h );
90  void initMinSize(int w, int h );
91  void initVisual( RE_Visual *visual );
92  void setLimitPositions(bool limitpos)
93  { myLimitPositions = limitpos; }
94  bool getLimitPositions() const
95  { return myLimitPositions; }
96 
97  void moveWindow(int x, int y);
98  void sizeWindow(int w, int h);
99 
100  // Set the window's opacity (0.0 - 1.0).
101  // Values less than 1.0 will make the window translucent.
102  void setWindowOpacity(fpreal opacity);
103 
104 
105  // Maximize the window and/or mark it as maximized so that when openWindow
106  // is called, it can open the window maximized.
107  void maximizeWindow();
108  void restoreWindow();
109 
110  bool isMaximized() const;
111 
112  // Set the window as fullscreen. Depending on the windowing system, this
113  // either informs the window manager to set us as fullscreen or simply
114  // sets borders up so that higher-level classes can do the fullscreening
115  // themselves.
116  void fullscreenWindow(bool full);
117  bool isFullscreenWindow() const;
118  void lowerWindow();
119  void raiseWindow();
120 
121  // Show/Hide the Window Frame/ Titlebar
122  void setHasWindowFrame(bool b);
123  bool hasWindowFrame() const;
124 
125  int getBorderWidth() const
126  { return myLeftBorder+myRightBorder; }
127  int getBorderHeight() const
128  { return myTopBorder+myBottomBorder; }
129  int getBorderTopSize() const
130  { return myTopBorder; }
131  int getBorderLeftSize() const
132  { return myLeftBorder; }
134  { return myBottomBorder; }
135  int getBorderRightSize() const
136  { return myRightBorder; }
137 
138  UT_DimRect findLocation() const;
139  UT_DimRect getNormalGeometry() const;
140 
141  // Sets the window to sit on top of all other windows, or turns off that
142  // state, depending on whether newstate is true or false.
143  void setWindowAlwaysOnTop(bool newstate);
144  int getWindowAlwaysOnTop() const { return winFlags.alwaysOnTop; }
145 
146  void setWindowFloatOnTop(bool on_top);
147 
148  RE_DisplayMode getMode() const;
149 
151  { return myVisualType; }
152  void setVisualType(RE_VisualType t) { myVisualType = t; }
153 
154  // changes to the type will not occur until the window is opened again.
156  { myWindowType = t; }
157 
158  RE_WindowType getWindowType( bool extra=false) const;
159 
160 
161  void setWindowID(RE_IDType id) { myWindowID = id; }
163  { return myWindowID; }
164  int matchID( RE_IDType wid ) const
165  { return wid == myWindowID; }
166 
167  virtual RE_IDType getBufferID() const { return 0; }
168 
169  /// =====================================================================
170  /// For new 2D UI drawing.
171  bool needsOpenGL() const;
172 
173  // Methods to access and set the assigned OpenGL drawable.
174  RE_WindowDrawable *getDrawable() const { return myWindowDrawable; }
175  void setDrawable(RE_WindowDrawable *d);
176 
177  // Methods to access and set the assigned (new) OpenGL drawable.
179  { return myOpenGLDrawable; }
180  void setOpenGLDrawable(RE_OpenGLDrawable *d);
181 
182  // Methods to access and set the assigned plain (QPainter only) drawable.
184  { return myQPainterDrawable; }
185  void setQPainterDrawable(RE_QPainterDrawable *d);
186  /// =====================================================================
187 
188  /// =====================================================================
189  /// For OpenGL 2D UI drawing.
190  OGLDrawable getGraphicsDrawable() const { return myDrawable; }
191  void setGraphicsDrawable(OGLDrawable d) { myDrawable = d; }
192  /// =====================================================================
193 
194 
195  void setIMESupport(bool enable);
196 
197  /// Return the Qt main window.
198  static QWidget * mainQtWindow();
199 
200  /// Initialize the given widget window with the desired
201  /// Houdini window properties, look and feel.
202  static void initQtWindow(
203  QWidget &window, RE_WindowType win_type,
204  bool always_on_top);
205 
206  /// Create a Qt window widget for the given window type.
207  /// The caller takes ownership of the returned object.
208  static QWidget * createQtWindow(RE_WindowType win_type);
209 
210  /// Returns true if Houdini or any of its sub windows are focused
211  static bool appActive();
212 
213  /// Returns true if this window is the active window.
214  bool isActiveWindow() const;
215 
216  void setWindowBorders(int left, int right, int top, int bottom)
217  {
218  myLeftBorder = left;
219  myRightBorder = right;
220  myTopBorder = top;
221  myBottomBorder = bottom;
222  }
223 
224  // This is called by the native window to inform that it has changed its
225  // maximized state.
226  void updateMaximizedFlag(bool is_maximized)
227  {
228  winFlags.maximized = is_maximized;
229  }
230 
231  static bool isTabFocusEnabled();
232  static void enableTabFocus(bool enable);
233 
234  /// Return the string tag used to identify whether a Qt widget is the
235  /// window for an RE_Window object.
236  static const char * windowTag() { return "RE_Window"; }
237 
238  bool isQuadBufferStereo() const;
239 
240  /// Return the screen number containing this window.
241  /// If the underlying platform window has not been created
242  /// yet then return the primary screen number.
243  int screen() const;
244 
245  /// Get screen-to-window scale.
246  fpreal screenToDeviceScale() const;
247 
248  /// =====================================================================
249  /// For new 2D UI drawing.
250 
251  /// Request that the window render it's contents.
252  void requestRender(bool immediate = false);
253 
254  /// Return the window currently being immediately rendered, if any.
255  /// While set, no other window should paint.
256  static RE_Window *immediateRenderWindow();
257  static void setImmediateRenderWindow(RE_Window *window);
258 
259  /// Pass key class to help restrict method access to drawable classes.
261  {
262  private:
263  friend RE_OpenGLDrawable;
264  friend RE_QPainterDrawable;
265  friend RE_WindowDrawable;
266  DrawablePassKey() = default;
267  ~DrawablePassKey() = default;
268  };
269 
270  /// Render the window's contents.
271  /// This method is meant to be called only from RE drawable classes.
272  void render(const DrawablePassKey &k);
273 
274  /// Return true if the window's screen's device pixel ratio should be
275  /// applied when painting the windows contents. Return false otherwise.
276  virtual bool shouldApplyDevicePixelRatio() const;
277 
278  /// Return true if the drawable should use the holo style.
279  bool useHoloStyle() const;
280 
281  bool hasPendingLayoutsForPaint() const;
282  void deferPaintForPendingLayouts();
283  /// Process any pending UI layouts in the window.
284  void processPendingLayoutsForPaint();
285 
286  /// Handle when the window has moved to another screen.
287  void handleScreenChanged();
288  /// =====================================================================
289 
290  /// Get Default Window Border Sizes
291  static const int* getDefaultWindowBorderSizes();
292  static int getDefaultWindowTitleBarHeight();
293 
294 private:
295  /// Initialize window borders.
296  void initBorderSizes_();
297 
298  /// Move the underlying Qt window to the position specified by myFrame.
299  void moveQtWindow_();
300 
301 #if defined(WIN32)
302  /// Add the Always On Top menu item to the window's system menu.
303  void addAlwaysOnTopSystemMenuItem_();
304 #endif
305 
306 private:
307  /// =====================================================================
308  /// For new 2D UI drawing.
309  RE_WindowOwner *myOwner;
310  /// =====================================================================
311 
312  RE_Server *myServer;
313  UT_UniquePtr<RE_Render> myRender;
314  RE_Visual *myVisualResource;
315  RE_VisualType myVisualType;
316  RE_IDType myWindowID;
317 
318 #if defined(WIN32) || defined(USE_QT6)
319  // This widget is for stashing away the Qt window when it closes and
320  // detaches from its parent window. There's a limitation where a Qt
321  // window cannot gracefully detach itself from the parent. Doing so
322  // typically changes the child widget's window flags and creates
323  // unwanted system windows.
324  //
325  // The workaround is to instead reparent the Qt window instead of
326  // completely detaching it.
327  QWidget *myStashWidget;
328 #endif
329 
330  UT_String myName;
331  UT_String myIconName;
332 
333  // Window geometry in native screen coordinates and scaling.
334  UT_DimRect myFrame;
335 
336  using IntPair = std::pair<int, int>;
337 
338  // Window sizes in native screen scaling.
339  IntPair myMinSize;
340  IntPair myMaxSize;
341 
342  /// =====================================================================
343  /// For new 2D UI drawing.
344 
345  // Window drawable with support for OpenGL.
346  RE_WindowDrawable *myWindowDrawable;
347 
348  // Window drawable with OpenGL support. Supports both OpenGL
349  // and QPainter drawing.
350  RE_OpenGLDrawable *myOpenGLDrawable;
351 
352  // Window drawable without OpenGL support. Only supports QPainter drawing.
353  RE_QPainterDrawable *myQPainterDrawable;
354 
355  /// =====================================================================
356 
357  /// =====================================================================
358  /// For OpenGL 2D UI drawing.
359  OGLDrawable myDrawable;
360  /// =====================================================================
361 
362  unsigned long myIconPixmap;
363  RE_WindowFlags winFlags;
364  RE_Window *parentWindow;
365  RE_IDType myDialogParentHint;
366 
367  RE_WindowType myWindowType;
368 
369  int myLeftBorder;
370  int myTopBorder;
371  int myRightBorder;
372  int myBottomBorder;
373 
374  unsigned int myLimitPositions:1;
375 
376  fpreal myWindowOpacity;
377 
378 #if defined(WIN32)
379  bool myAddedAlwaysOnTopMenuItem;
380 #endif
381 
382  bool myIsResizing;
383 };
384 
386 {
387 public:
389  { }
391  { }
392 
393  void lock()
394  { myLock.lock(); }
395  void unlock()
396  { myLock.unlock(); }
398  { lock(); myWindows.append(w); unlock(); }
400  { lock(); myWindows.findAndRemove(w); unlock(); }
401  int getNumWindows() const
402  { return myWindows.entries(); }
404  { return myWindows(index); }
405  void removeWindow(RE_IDType wid);
406  RE_Window *isWindowHere(RE_IDType wid);
407 
408 private:
409  UT_ValArray<RE_Window *> myWindows;
410  UT_Lock myLock;
411 };
412 
413 #endif
void * RE_IDType
Definition: RE_IDType.h:20
void removeWindow(RE_Window *w)
Definition: RE_Window.h:399
RE_QPainterDrawable * getQPainterDrawable() const
Definition: RE_Window.h:183
const RE_Window * getParentWindow() const
Definition: RE_Window.h:71
bool isOriginReadjusted
Definition: RE_Window.h:29
#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:161
RE_VisualType getVisualType() const
Definition: RE_Window.h:150
==========================================================================
Definition: RE_Window.h:57
GLint left
Definition: glcorearb.h:2005
int getBorderLeftSize() const
Definition: RE_Window.h:131
int getBorderWidth() const
Definition: RE_Window.h:125
void setWindowType(RE_WindowType t)
Definition: RE_Window.h:155
GLdouble right
Definition: glad.h:2817
RE_OpenGLDrawable * getOpenGLDrawable() const
Definition: RE_Window.h:178
void addWindow(RE_Window *w)
Definition: RE_Window.h:397
GLint y
Definition: glcorearb.h:103
RE_Window * getWindow(int index) const
Definition: RE_Window.h:403
int getWindowAlwaysOnTop() const
Definition: RE_Window.h:144
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:29
OGLDrawable getGraphicsDrawable() const
=====================================================================
Definition: RE_Window.h:190
void setGraphicsDrawable(OGLDrawable d)
Definition: RE_Window.h:191
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
void unlock()
Definition: RE_Window.h:395
int getBorderBottomSize() const
Definition: RE_Window.h:133
void setVisualType(RE_VisualType t)
Definition: RE_Window.h:152
virtual RE_IDType getBufferID() const
Definition: RE_Window.h:167
int matchID(RE_IDType wid) const
Definition: RE_Window.h:164
int getNumWindows() const
Definition: RE_Window.h:401
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
RE_WindowDrawable * getDrawable() const
Definition: RE_Window.h:174
int getBorderRightSize() const
Definition: RE_Window.h:135
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:92
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:29
fpreal64 fpreal
Definition: SYS_Types.h:283
RE_Visual * getVisual()
Definition: RE_Window.h:77
int getBorderHeight() const
Definition: RE_Window.h:127
virtual ~RE_WindowOwner()
Definition: RE_Window.h:44
GLuint index
Definition: glcorearb.h:786
RE_VisualType
Definition: RE_Types.h:630
Window drawable that uses only QPainter for the new UI path.
void lock()
Definition: RE_Window.h:393
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
bool fullscreen
Definition: RE_Window.h:29
int getBorderTopSize() const
Definition: RE_Window.h:129
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void setRender(UT_UniquePtr< RE_Render > r)
Definition: RE_Window.h:81
GLboolean r
Definition: glcorearb.h:1222
void updateMaximizedFlag(bool is_maximized)
Definition: RE_Window.h:226
void setWindowBorders(int left, int right, int top, int bottom)
Definition: RE_Window.h:216
RE_WindowType
Definition: RE_Types.h:29
Pass key class to help restrict method access to drawable classes.
Definition: RE_Window.h:260
static const char * windowTag()
Definition: RE_Window.h:236
bool getLimitPositions() const
Definition: RE_Window.h:94
RE_IDType getWindowID() const
Definition: RE_Window.h:162
RE_Server * getServer()
Definition: RE_Window.h:76