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