HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WindowWrapper.h
Go to the documentation of this file.
1 //
2 // TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3 // All rights reserved. See LICENSE.txt for license.
4 //
5 
6 #ifndef MATERIALX_WINDOWWRAPPER_H
7 #define MATERIALX_WINDOWWRAPPER_H
8 
9 #if defined(_WIN32)
10 #define WIN32_LEAN_AND_MEAN
11 #include <windows.h>
12 #elif defined(__linux__)
13 #include <X11/X.h> // for Window
14 #include <X11/Xlib.h> // for Display
15 using Widget = struct _WidgetRec*;
16 #endif
17 
18 #include <memory>
19 
20 namespace MaterialX
21 {
22 /// OS specific type windowing definitions
23 #if defined(_WIN32)
24 /// External handle is a window handle
25 using ExternalWindowHandle = HWND;
26 /// Internal handle is a device context
28 /// Display handle concept has no equivalence on Windows
29 using DisplayHandle = void*;
30 #elif defined(__linux__)
31 /// External handle is a widget
33 /// Internal handle is the window for the widget
34 using InternalWindowHandle = Window;
35 /// Display handle is the X display
36 using DisplayHandle = Display*;
37 /// Application shell
38 using Widget = struct _WidgetRec*;
39 #elif defined(__APPLE__)
40 /// External handle is a window handle
41 using ExternalWindowHandle = void*;
42 /// Internal handle concept has no equivalence on Mac
43 using InternalWindowHandle = void*;
44 /// Display handle concept has no equivalence on Mac
45 using DisplayHandle = void*;
46 #else
47 using Widget = void*;
48 using ExternalWindowHandle = void*;
49 using InternalWindowHandle = void*;
50 using DisplayHandle = void*;
51 #endif
52 
53 /// WindowWrapper shared pointer
54 using WindowWrapperPtr = std::shared_ptr<class WindowWrapper>;
55 
56 /// @class WindowWrapper
57 /// Generic wrapper for encapsulating a "window" construct
58 ///
59 /// Each supported platform will have specific storage and management logic.
61 {
62  public:
63  /// Create a new WindowWrapper
66  DisplayHandle display = {});
67 
68  // Default destructor
69  virtual ~WindowWrapper();
70 
71  /// Return "external" handle
73  {
74  return _externalHandle;
75  }
76 
77  /// Return "internal" handle
79  {
80  return _internalHandle;
81  }
82 
83  /// Check that there is a valid OS handle set.
84  /// It is sufficient to just check the internal handle.
85  bool isValid() const
86  {
87  return _internalHandle != 0;
88  }
89 
90  /// Release resources stored in wrapper
91  void release();
92 
93 #if defined(__linux__)
94  /// Return X display
95  Display* getXDisplay() const
96  {
97  return _xDisplay;
98  }
99 #endif
100 
101  protected:
104  DisplayHandle display);
105 
106  protected:
109 
110 #if defined(__linux__)
111  /// Window ID of framebuffer instance created in the wrapper
112  Window _framebufferWindow;
113  /// X Display
114  Display* _xDisplay;
115 #endif
116 };
117 
118 } // namespace MaterialX
119 
120 #endif
void * DisplayHandle
Definition: WindowWrapper.h:50
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(VOID)
void * Widget
OS specific type windowing definitions.
Definition: WindowWrapper.h:47
void * InternalWindowHandle
Definition: WindowWrapper.h:49
void release()
Release resources stored in wrapper.
void * ExternalWindowHandle
Definition: WindowWrapper.h:48
std::shared_ptr< class WindowWrapper > WindowWrapperPtr
WindowWrapper shared pointer.
Definition: WindowWrapper.h:54
WindowWrapper(ExternalWindowHandle externalHandle, InternalWindowHandle internalHandle, DisplayHandle display)
InternalWindowHandle _internalHandle
ExternalWindowHandle externalHandle() const
Return "external" handle.
Definition: WindowWrapper.h:72
InternalWindowHandle internalHandle() const
Return "internal" handle.
Definition: WindowWrapper.h:78
ExternalWindowHandle _externalHandle
static WindowWrapperPtr create(ExternalWindowHandle externalHandle={}, InternalWindowHandle internalHandle={}, DisplayHandle display={})
Create a new WindowWrapper.