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