VTK  9.7.1
vtkCocoaRenderWindow.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
30 #ifndef vtkCocoaRenderWindow_h
31 #define vtkCocoaRenderWindow_h
32 
33 #include "vtkOpenGLRenderWindow.h"
34 #include "vtkRenderingOpenGL2Module.h" // For export macro
35 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
36 #include <stack> // for ivar
37 
38 VTK_ABI_NAMESPACE_BEGIN
40 class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkCocoaRenderWindow : public vtkOpenGLRenderWindow
41 {
42 public:
43  static vtkCocoaRenderWindow* New();
47  void PrintSelf(ostream& os, vtkIndent indent) override;
48 
52  void Start() override;
53 
57  void Frame() override;
58 
62  virtual void WindowConfigure();
63 
72  void Initialize() override;
73 
80  void SetFullScreen(vtkTypeBool) override;
81 
85  void WindowRemap() override;
86 
91  virtual void PrefFullScreen();
92 
94 
102  void SetSize(int width, int height) override;
103  void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
105 
110  int* GetSize() VTK_SIZEHINT(2) override;
111 
113 
118  void SetPosition(int x, int y) override;
119  void SetPosition(int a[2]) override { this->SetPosition(a[0], a[1]); }
121 
126  int* GetScreenSize() VTK_SIZEHINT(2) override;
127 
132  int* GetPosition() VTK_SIZEHINT(2) override;
133 
138  void SetWindowName(const char*) override;
139 
140  void SetNextWindowInfo(const char*) override
141  {
142  vtkDebugMacro("SetNextWindowInfo not implemented (WindowRemap not implemented).");
143  }
144  void* GetGenericDrawable() override
145  {
146  vtkDebugMacro("Method not implemented.");
147  return nullptr;
148  }
149 
157  void SetDisplayId(void* displayId) override
158  {
159  this->DisplayIndex = displayId ? *(reinterpret_cast<int*>(displayId)) : 0;
160  }
161 
162  void* GetGenericDisplayId() override
163  {
164  vtkDebugMacro("Method not implemented.");
165  return nullptr;
166  }
167 
173  void SetWindowInfo(const char*) override;
174 
180  void SetParentInfo(const char*) override;
181 
182  void SetNextWindowId(void*) override
183  {
184  vtkDebugMacro("SetNextWindowId not implemented (WindowRemap not implemented).");
185  }
186 
191  bool InitializeFromCurrentContext() override;
192 
196  bool GetPlatformSupportsRenderWindowSharing() override { return true; }
197 
204  void SetStereoCapableWindow(vtkTypeBool capable) override;
205 
209  void MakeCurrent() override;
210 
214  void ReleaseCurrent() override;
215 
219  bool IsCurrent() override;
220 
224  void UpdateContext();
225 
229  const char* ReportCapabilities() override;
230 
234  vtkTypeBool IsDirect() override;
235 
241  void SetForceMakeCurrent() override;
242 
247  vtkTypeBool GetEventPending() override;
248 
250 
253  virtual void SetupPalette(void* hDC);
254  virtual void SetupPixelFormat(void* hDC, void* dwFlags, int debug, int bpp = 16, int zbpp = 16);
256 
260  void Finalize() override;
261 
263 
269  void HideCursor() override;
270  void ShowCursor() override;
271  void SetCursorPosition(int x, int y) override;
273 
277  void SetCurrentCursor(int) override;
278 
283  virtual vtkTypeBool GetViewCreated();
284 
289  virtual vtkTypeBool GetWindowCreated();
290 
292 
296  void SetContextId(void*);
298  void* GetContextId();
299  void* GetGenericContext() override { return this->GetContextId(); }
301 
313  virtual void SetRootWindow(void*);
314 
319  virtual void* GetRootWindow();
320 
332  void SetWindowId(void*) override;
333 
338  virtual void* GetWindowId();
339  void* GetGenericWindowId() override { return this->GetWindowId(); }
340 
348  void SetParentId(void* nsview) override;
349 
356  virtual void* GetParentId();
357  void* GetGenericParentId() override { return this->GetParentId(); }
358 
369  void SetWantsBestResolution(bool wantsBest);
370  bool GetWantsBestResolution();
371 
378  void SetConnectContextToNSView(bool connect);
379  bool GetConnectContextToNSView();
380 
382 
386  void SetPixelFormat(void* pixelFormat);
388  void* GetPixelFormat();
390 
392 
399  void PushContext() override;
400  void PopContext() override;
402 
403  void Render() override;
404 
405 protected:
407  ~vtkCocoaRenderWindow() override;
408 
409  std::stack<void*> ContextStack;
410 
411  void CreateGLContext();
412 
413  void CreateAWindow() override;
414  void DestroyWindow() override;
415  vtkTypeBool OnScreenInitialized;
416 
418 
422  void SetCocoaManager(void* manager);
423  void* GetCocoaManager();
425 
426  void SetCocoaServer(void* server); // Really a vtkCocoaServer*
427  void* GetCocoaServer();
428 
429 private:
430  vtkCocoaRenderWindow(const vtkCocoaRenderWindow&) = delete;
431  void operator=(const vtkCocoaRenderWindow&) = delete;
432 
433 private:
434  // Important: this class cannot contain Objective-C instance
435  // variables for 2 reasons:
436  // 1) C++ files include this header
437  // 2) because of garbage collection (the GC scanner does not scan objects create by C++'s new)
438  // Instead, use the CocoaManager dictionary to keep a collection
439  // of what would otherwise be Objective-C instance variables.
440  void* CocoaManager; // Really an NSMutableDictionary*
441 
442  vtkTypeBool WindowCreated;
443  vtkTypeBool ViewCreated;
444  vtkTypeBool CursorHidden;
445 
446  vtkTypeBool ForceMakeCurrent;
447 
448  bool WantsBestResolution;
449  bool ConnectContextToNSView;
450 
451  int DisplayIndex = 0;
452 };
453 
454 #define vtkCocoaRenderWindow_OVERRIDE_ATTRIBUTES vtkCocoaRenderWindow::CreateOverrideAttributes()
455 VTK_ABI_NAMESPACE_END
456 #endif
OpenGL rendering window.
virtual void SetCursorPosition(int, int)
Hide or Show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
Definition: vtkWindow.h:297
virtual void SetForceMakeCurrent()
If called, allow MakeCurrent() to skip cache-check when called.
Attribute for vtkObjectFactory overrides.
virtual void HideCursor()
Hide or Show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
Definition: vtkWindow.h:295
void * GetGenericDrawable() override
Dummy stubs for vtkWindow API.
virtual void SetFullScreen(vtkTypeBool)
Turn on/off rendering full screen window size.
virtual void WindowRemap()
Remap the rendering window.
Cocoa OpenGL rendering window.
bool InitializeFromCurrentContext() override
Initialize the render window from the information associated with the currently activated OpenGL cont...
void SetWindowInfo(const char *) override
Dummy stubs for vtkWindow API.
virtual bool IsCurrent()
Tells if this window is the current graphics context for the calling thread.
virtual void Finalize()
Finalize the rendering process.
void SetNextWindowId(void *) override
Dummy stubs for vtkWindow API.
int vtkTypeBool
Definition: vtkABI.h:64
virtual void SetStereoCapableWindow(vtkTypeBool capable)
Prescribe that the window be created in a stereo-capable mode.
void SetDisplayId(void *displayId) override
Set the index of the NSScreen on which the window should be created.
static vtkOpenGLRenderWindow * New()
void SetPosition(int a[2]) override
Set the position (x and y) of the rendering window in screen coordinates (in pixels).
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
a simple class to control print indentation
Definition: vtkIndent.h:28
void Start() override
Begin the rendering process.
void * GetGenericDisplayId() override
Dummy stubs for vtkWindow API.
virtual int * GetScreenSize()
Get the current size of the screen in pixels.
Definition: vtkWindow.h:110
void Initialize() override
Initialize the rendering window.
static vtkOverrideAttribute * CreateOverrideAttributes()
virtual void MakeCurrent()
Make the window current.
Definition: vtkWindow.h:255
#define VTK_SIZEHINT(...)
const char * ReportCapabilities() override
Get report of capabilities for the render window.
#define VTK_NEWINSTANCE
#define VTK_MARSHALEXCLUDE(reason)
void Frame() override
A termination method performed at the end of the rendering process to do things like swapping buffers...
virtual int * GetSize()
Get the size (width and height) of the rendering window in screen coordinates (in pixels)...
virtual vtkTypeBool GetEventPending()
Check to see if a mouse button has been pressed.
virtual void ReleaseCurrent()
Release the current context.
Definition: vtkWindow.h:261
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetSize(int a[2]) override
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
bool GetPlatformSupportsRenderWindowSharing() override
Does this platform support render window data sharing.
virtual void ShowCursor()
Hide or Show the mouse cursor, it is nice to be able to hide the default cursor if you want VTK to di...
Definition: vtkWindow.h:296
#define VTK_MARSHALAUTO
#define VTK_MARSHAL_EXCLUDE_REASON_NOT_SUPPORTED
void SetParentInfo(const char *) override
Dummy stubs for vtkWindow API.
virtual void SetCurrentCursor(int)
Change the shape of the cursor.
virtual vtkTypeBool IsDirect()
Is this render window using hardware acceleration? 0-false, 1-true.