Blender  V3.3
GHOST_Window.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
12 #include "GHOST_Window.h"
13 
14 #include "GHOST_ContextNone.h"
15 
16 #include <cassert>
17 
21  const bool wantStereoVisual,
22  const bool /*exclusive*/)
23  : m_drawingContextType(GHOST_kDrawingContextTypeNone),
24  m_cursorVisible(true),
25  m_cursorGrab(GHOST_kGrabDisable),
26  m_cursorGrabAxis(GHOST_kAxisNone),
27  m_cursorShape(GHOST_kStandardCursorDefault),
28  m_wantStereoVisual(wantStereoVisual),
29  m_context(new GHOST_ContextNone(false))
30 {
31  m_isUnsavedChanges = false;
33 
34  m_progressBarVisible = false;
35 
36  m_cursorGrabAccumPos[0] = 0;
37  m_cursorGrabAccumPos[1] = 0;
38 
39  m_nativePixelSize = 1.0f;
40 
42  if (m_fullScreen) {
45  }
46 }
47 
49 {
50  delete m_context;
51 }
52 
54 {
55  return nullptr;
56 }
57 
59 {
60  if (type != m_drawingContextType) {
61  delete m_context;
62  m_context = nullptr;
63 
65  m_context = newDrawingContext(type);
66  }
67  if (m_context != nullptr) {
69  }
70  else {
71  m_context = new GHOST_ContextNone(m_wantStereoVisual);
73  }
74 
76  }
77  return GHOST_kSuccess;
78 }
79 
81 {
82  return m_context->swapBuffers();
83 }
84 
86 {
87  return m_context->setSwapInterval(interval);
88 }
89 
91 {
92  return m_context->getSwapInterval(intervalOut);
93 }
94 
96 {
97  return (m_context) ? m_context->getDefaultFramebuffer() : 0;
98 }
99 
101 {
102  return m_context->activateDrawingContext();
103 }
104 
106 {
107  return m_context->updateDrawingContext();
108 }
109 
111 {
112  return m_context->releaseNativeHandles();
113 }
114 
116 {
117  if (setWindowCursorVisibility(visible)) {
118  m_cursorVisible = visible;
119  return GHOST_kSuccess;
120  }
121  return GHOST_kFailure;
122 }
123 
125  GHOST_TAxisFlag wrap_axis,
127  int32_t mouse_ungrab_xy[2])
128 {
129  if (m_cursorGrab == mode) {
130  return GHOST_kSuccess;
131  }
132  /* Override with new location. */
133  if (mouse_ungrab_xy) {
134  assert(mode == GHOST_kGrabDisable);
135  m_cursorGrabInitPos[0] = mouse_ungrab_xy[0];
136  m_cursorGrabInitPos[1] = mouse_ungrab_xy[1];
137  }
138 
139  if (setWindowCursorGrab(mode)) {
140 
141  if (mode == GHOST_kGrabDisable) {
143  }
144  else if (bounds) {
146  }
147  else { /* if bounds not defined, use window */
149  }
150  m_cursorGrab = mode;
151  m_cursorGrabAxis = wrap_axis;
152  return GHOST_kSuccess;
153  }
154  return GHOST_kFailure;
155 }
156 
158 {
159  if (m_cursorGrab != GHOST_kGrabWrap) {
160  return GHOST_kFailure;
161  }
163  return (bounds.m_l == -1 && bounds.m_r == -1) ? GHOST_kFailure : GHOST_kSuccess;
164 }
165 
167  GHOST_TAxisFlag &wrap_axis,
169  bool &use_software_cursor)
170 {
171  mode = m_cursorGrab;
172  if (m_cursorGrab == GHOST_kGrabWrap) {
174  wrap_axis = m_cursorGrabAxis;
175  }
176  else {
177  bounds.m_l = -1;
178  bounds.m_r = -1;
179  bounds.m_t = -1;
180  bounds.m_b = -1;
181  wrap_axis = GHOST_kAxisNone;
182  }
183  use_software_cursor = (m_cursorGrab != GHOST_kGrabDisable) ? getCursorGrabUseSoftwareDisplay() :
184  false;
185 }
186 
188 {
189  /* Sub-classes may override, by default don't use software cursor. */
190  return false;
191 }
192 
194 {
195  if (setWindowCursorShape(cursorShape)) {
196  m_cursorShape = cursorShape;
197  return GHOST_kSuccess;
198  }
199  return GHOST_kFailure;
200 }
201 
203  uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
204 {
205  if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor)) {
207  return GHOST_kSuccess;
208  }
209  return GHOST_kFailure;
210 }
211 
213 {
214  /* Sub-classes may override. */
215  return GHOST_kFailure;
216 }
217 
219 {
220  m_canAcceptDragOperation = canAccept;
221 }
222 
224 {
226 }
227 
229 {
230  m_isUnsavedChanges = isUnsavedChanges;
231 
232  return GHOST_kSuccess;
233 }
234 
236 {
237  return m_isUnsavedChanges;
238 }
KDTree *BLI_kdtree_nd_() new(unsigned int maxsize)
Definition: kdtree_impl.h:85
GHOST_TWindowState
Definition: GHOST_Types.h:129
@ GHOST_kWindowStateFullScreen
Definition: GHOST_Types.h:133
GHOST_TStandardCursor
Definition: GHOST_Types.h:214
@ GHOST_kStandardCursorCustom
Definition: GHOST_Types.h:254
@ GHOST_kStandardCursorDefault
Definition: GHOST_Types.h:216
GHOST_TAxisFlag
Definition: GHOST_Types.h:420
@ GHOST_kAxisNone
Definition: GHOST_Types.h:422
GHOST_TDrawingContextType
Definition: GHOST_Types.h:148
@ GHOST_kDrawingContextTypeNone
Definition: GHOST_Types.h:149
GHOST_TSuccess
Definition: GHOST_Types.h:74
@ GHOST_kFailure
Definition: GHOST_Types.h:74
@ GHOST_kSuccess
Definition: GHOST_Types.h:74
GHOST_TGrabCursorMode
Definition: GHOST_Types.h:404
@ GHOST_kGrabWrap
Definition: GHOST_Types.h:410
@ GHOST_kGrabDisable
Definition: GHOST_Types.h:406
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition: btDbvt.cpp:299
virtual GHOST_TSuccess activateDrawingContext()=0
virtual GHOST_TSuccess releaseNativeHandles()=0
virtual GHOST_TSuccess setSwapInterval(int)
Definition: GHOST_Context.h:80
virtual GHOST_TSuccess swapBuffers()=0
virtual GHOST_TSuccess updateDrawingContext()
Definition: GHOST_Context.h:64
virtual GHOST_TSuccess getSwapInterval(int &)
Definition: GHOST_Context.h:90
virtual unsigned int getDefaultFramebuffer()
virtual void getClientBounds(GHOST_Rect &bounds) const =0
int32_t m_l
Definition: GHOST_Rect.h:156
int32_t m_r
Definition: GHOST_Rect.h:160
GHOST_Rect m_cursorGrabBounds
Definition: GHOST_Window.h:371
bool getCursorGrabUseSoftwareDisplay()
GHOST_TSuccess setCustomCursorShape(uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
virtual unsigned int getDefaultFramebuffer()
GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds)
virtual bool getModifiedState()
GHOST_TSuccess getSwapInterval(int &intervalOut)
GHOST_TGrabCursorMode m_cursorGrab
Definition: GHOST_Window.h:359
int32_t m_cursorGrabAccumPos[2]
Definition: GHOST_Window.h:368
bool m_wantStereoVisual
Definition: GHOST_Window.h:389
int32_t m_cursorGrabInitPos[2]
Definition: GHOST_Window.h:365
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type)
GHOST_TStandardCursor m_cursorShape
Definition: GHOST_Window.h:374
bool m_cursorVisible
Definition: GHOST_Window.h:356
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode)
Definition: GHOST_Window.h:324
GHOST_TSuccess releaseNativeHandles()
virtual void * getOSWindow() const
GHOST_TAxisFlag m_cursorGrabAxis
Definition: GHOST_Window.h:362
virtual GHOST_TSuccess swapBuffers()
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges)
GHOST_TSuccess setSwapInterval(int interval)
virtual GHOST_Context * newDrawingContext(GHOST_TDrawingContextType type)=0
bool canAcceptDragOperation() const
virtual GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap, uint8_t *mask, int szx, int szy, int hotX, int hotY, bool canInvertColor)=0
GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_TAxisFlag wrap_axis, GHOST_Rect *bounds, int32_t mouse_ungrab_xy[2])
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible)=0
GHOST_TDrawingContextType m_drawingContextType
Definition: GHOST_Window.h:350
uint32_t m_fullScreenHeight
Definition: GHOST_Window.h:394
void getCursorGrabState(GHOST_TGrabCursorMode &mode, GHOST_TAxisFlag &axis_flag, GHOST_Rect &bounds, bool &use_software_cursor)
bool m_isUnsavedChanges
Definition: GHOST_Window.h:383
GHOST_Window(uint32_t width, uint32_t height, GHOST_TWindowState state, const bool wantStereoVisual=false, const bool exclusive=false)
float m_nativePixelSize
Definition: GHOST_Window.h:397
void setAcceptDragOperation(bool canAccept)
GHOST_TSuccess updateDrawingContext()
bool m_progressBarVisible
Definition: GHOST_Window.h:377
virtual ~GHOST_Window()
GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape)
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape)=0
bool m_canAcceptDragOperation
Definition: GHOST_Window.h:380
virtual GHOST_TSuccess activateDrawingContext()
GHOST_TSuccess setCursorVisibility(bool visible)
GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap)
uint32_t m_fullScreenWidth
Definition: GHOST_Window.h:392
const int state
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
unsigned int uint32_t
Definition: stdint.h:80
signed int int32_t
Definition: stdint.h:77
unsigned char uint8_t
Definition: stdint.h:78