Blender  V2.93
GHOST_Window.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
28 #include "GHOST_Window.h"
29 
30 #include "GHOST_ContextNone.h"
31 
32 #include <assert.h>
33 
37  const bool wantStereoVisual,
38  const bool /*exclusive*/)
39  : m_drawingContextType(GHOST_kDrawingContextTypeNone),
40  m_cursorVisible(true),
41  m_cursorGrab(GHOST_kGrabDisable),
42  m_cursorShape(GHOST_kStandardCursorDefault),
43  m_wantStereoVisual(wantStereoVisual),
44  m_context(new GHOST_ContextNone(false))
45 {
46  m_isUnsavedChanges = false;
48 
49  m_progressBarVisible = false;
50 
51  m_cursorGrabAccumPos[0] = 0;
52  m_cursorGrabAccumPos[1] = 0;
53 
54  m_nativePixelSize = 1.0f;
55 
57  if (m_fullScreen) {
60  }
61 }
62 
64 {
65  delete m_context;
66 }
67 
69 {
70  return NULL;
71 }
72 
74 {
75  if (type != m_drawingContextType) {
76  delete m_context;
77  m_context = NULL;
78 
80  m_context = newDrawingContext(type);
81 
82  if (m_context != NULL) {
84  }
85  else {
86  m_context = new GHOST_ContextNone(m_wantStereoVisual);
88  }
89 
91  }
92  else {
93  return GHOST_kSuccess;
94  }
95 }
96 
98 {
99  return m_context->swapBuffers();
100 }
101 
103 {
104  return m_context->setSwapInterval(interval);
105 }
106 
108 {
109  return m_context->getSwapInterval(intervalOut);
110 }
111 
113 {
114  return (m_context) ? m_context->getDefaultFramebuffer() : 0;
115 }
116 
118 {
119  return m_context->activateDrawingContext();
120 }
121 
123 {
124  return m_context->updateDrawingContext();
125 }
126 
128 {
129  return m_context->releaseNativeHandles();
130 }
131 
133 {
134  if (setWindowCursorVisibility(visible)) {
135  m_cursorVisible = visible;
136  return GHOST_kSuccess;
137  }
138  else {
139  return GHOST_kFailure;
140  }
141 }
142 
144  GHOST_TAxisFlag wrap_axis,
146  GHOST_TInt32 mouse_ungrab_xy[2])
147 {
148  if (m_cursorGrab == mode)
149  return GHOST_kSuccess;
150 
151  /* override with new location */
152  if (mouse_ungrab_xy) {
153  assert(mode == GHOST_kGrabDisable);
154  m_cursorGrabInitPos[0] = mouse_ungrab_xy[0];
155  m_cursorGrabInitPos[1] = mouse_ungrab_xy[1];
156  }
157 
158  if (setWindowCursorGrab(mode)) {
159 
160  if (mode == GHOST_kGrabDisable) {
162  }
163  else if (bounds) {
165  }
166  else { /* if bounds not defined, use window */
168  }
169  m_cursorGrab = mode;
170  m_cursorGrabAxis = wrap_axis;
171  return GHOST_kSuccess;
172  }
173  else {
174  return GHOST_kFailure;
175  }
176 }
177 
179 {
181  return (bounds.m_l == -1 && bounds.m_r == -1) ? GHOST_kFailure : GHOST_kSuccess;
182 }
183 
185 {
186  if (setWindowCursorShape(cursorShape)) {
187  m_cursorShape = cursorShape;
188  return GHOST_kSuccess;
189  }
190  else {
191  return GHOST_kFailure;
192  }
193 }
194 
196  GHOST_TUns8 *mask,
197  int sizex,
198  int sizey,
199  int hotX,
200  int hotY,
201  bool canInvertColor)
202 {
203  if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor)) {
205  return GHOST_kSuccess;
206  }
207  else {
208  return GHOST_kFailure;
209  }
210 }
211 
213 {
214  m_canAcceptDragOperation = canAccept;
215 }
216 
218 {
220 }
221 
223 {
224  m_isUnsavedChanges = isUnsavedChanges;
225 
226  return GHOST_kSuccess;
227 }
228 
230 {
231  return m_isUnsavedChanges;
232 }
KDTree *BLI_kdtree_nd_() new(unsigned int maxsize)
Definition: kdtree_impl.h:99
GHOST_TWindowState
Definition: GHOST_Types.h:144
@ GHOST_kWindowStateFullScreen
Definition: GHOST_Types.h:148
GHOST_TStandardCursor
Definition: GHOST_Types.h:222
@ GHOST_kStandardCursorCustom
Definition: GHOST_Types.h:262
@ GHOST_kStandardCursorDefault
Definition: GHOST_Types.h:224
unsigned int GHOST_TUns32
Definition: GHOST_Types.h:64
int GHOST_TInt32
Definition: GHOST_Types.h:63
GHOST_TAxisFlag
Definition: GHOST_Types.h:423
GHOST_TDrawingContextType
Definition: GHOST_Types.h:156
@ GHOST_kDrawingContextTypeNone
Definition: GHOST_Types.h:157
GHOST_TSuccess
Definition: GHOST_Types.h:91
@ GHOST_kFailure
Definition: GHOST_Types.h:91
@ GHOST_kSuccess
Definition: GHOST_Types.h:91
GHOST_TGrabCursorMode
Definition: GHOST_Types.h:412
@ GHOST_kGrabDisable
Definition: GHOST_Types.h:414
unsigned char GHOST_TUns8
Definition: GHOST_Types.h:60
_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
_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 height
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:96
virtual GHOST_TSuccess swapBuffers()=0
virtual GHOST_TSuccess updateDrawingContext()
Definition: GHOST_Context.h:80
virtual GHOST_TSuccess getSwapInterval(int &)
virtual unsigned int getDefaultFramebuffer()
virtual void getClientBounds(GHOST_Rect &bounds) const =0
GHOST_TInt32 m_l
Definition: GHOST_Rect.h:169
GHOST_TInt32 m_r
Definition: GHOST_Rect.h:173
GHOST_Rect m_cursorGrabBounds
Definition: GHOST_Window.h:378
virtual unsigned int getDefaultFramebuffer()
GHOST_Window(GHOST_TUns32 width, GHOST_TUns32 height, GHOST_TWindowState state, const bool wantStereoVisual=false, const bool exclusive=false)
GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds)
virtual bool getModifiedState()
GHOST_TSuccess getSwapInterval(int &intervalOut)
GHOST_TGrabCursorMode m_cursorGrab
Definition: GHOST_Window.h:366
GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
bool m_wantStereoVisual
Definition: GHOST_Window.h:396
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type)
GHOST_TUns32 m_fullScreenWidth
Definition: GHOST_Window.h:399
GHOST_TInt32 m_cursorGrabAccumPos[2]
Definition: GHOST_Window.h:375
GHOST_TStandardCursor m_cursorShape
Definition: GHOST_Window.h:381
bool m_cursorVisible
Definition: GHOST_Window.h:363
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode)
Definition: GHOST_Window.h:331
GHOST_TSuccess releaseNativeHandles()
virtual void * getOSWindow() const
GHOST_TAxisFlag m_cursorGrabAxis
Definition: GHOST_Window.h:369
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
GHOST_TInt32 m_cursorGrabInitPos[2]
Definition: GHOST_Window.h:372
GHOST_TUns32 m_fullScreenHeight
Definition: GHOST_Window.h:401
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible)=0
GHOST_TDrawingContextType m_drawingContextType
Definition: GHOST_Window.h:357
bool m_isUnsavedChanges
Definition: GHOST_Window.h:390
float m_nativePixelSize
Definition: GHOST_Window.h:404
GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_TAxisFlag wrap_axis, GHOST_Rect *bounds, GHOST_TInt32 mouse_ungrab_xy[2])
void setAcceptDragOperation(bool canAccept)
GHOST_TSuccess updateDrawingContext()
bool m_progressBarVisible
Definition: GHOST_Window.h:384
virtual ~GHOST_Window()
GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape)
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape)=0
bool m_canAcceptDragOperation
Definition: GHOST_Window.h:387
virtual GHOST_TSuccess activateDrawingContext()
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int szx, int szy, int hotX, int hotY, bool canInvertColor)=0
GHOST_TSuccess setCursorVisibility(bool visible)
static ulong state[N]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)