Cleanup: remove contributors for CMake files
[blender.git] / intern / ghost / intern / GHOST_Window.cpp
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
20 /** \file ghost/intern/GHOST_Window.cpp
21  *  \ingroup GHOST
22  */
23
24
25 /**
26  * Copyright (C) 2001 NaN Technologies B.V.
27  */
28
29 #include "GHOST_Window.h"
30
31 #include "GHOST_ContextNone.h"
32
33 #include <assert.h>
34
35 GHOST_Window::GHOST_Window(
36         GHOST_TUns32 width, GHOST_TUns32 height,
37         GHOST_TWindowState state,
38         const bool wantStereoVisual,
39         const bool /*exclusive*/,
40         const GHOST_TUns16 wantNumOfAASamples)
41     : m_drawingContextType(GHOST_kDrawingContextTypeNone),
42       m_cursorVisible(true),
43       m_cursorGrab(GHOST_kGrabDisable),
44       m_cursorShape(GHOST_kStandardCursorDefault),
45       m_wantStereoVisual(wantStereoVisual),
46       m_wantNumOfAASamples(wantNumOfAASamples),
47       m_context(new GHOST_ContextNone(false, 0))
48 {
49         m_isUnsavedChanges = false;
50         m_canAcceptDragOperation = false;
51
52         m_progressBarVisible = false;
53
54         m_cursorGrabAccumPos[0] = 0;
55         m_cursorGrabAccumPos[1] = 0;
56
57         m_nativePixelSize = 1.0f;
58
59         m_fullScreen = state == GHOST_kWindowStateFullScreen;
60         if (m_fullScreen) {
61                 m_fullScreenWidth = width;
62                 m_fullScreenHeight = height;
63         }
64 }
65
66
67 GHOST_Window::~GHOST_Window()
68 {
69         delete m_context;
70 }
71
72 void *GHOST_Window::getOSWindow() const
73 {
74         return NULL;
75 }
76
77 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
78 {
79         if (type != m_drawingContextType) {
80                 delete m_context;
81                 m_context = NULL;
82
83                 if (type != GHOST_kDrawingContextTypeNone)
84                         m_context = newDrawingContext(type);
85
86                 if (m_context != NULL) {
87                         m_drawingContextType = type;
88                 }
89                 else {
90                         m_context = new GHOST_ContextNone(m_wantStereoVisual, m_wantNumOfAASamples);
91                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
92                 }
93
94                 return (type == m_drawingContextType) ? GHOST_kSuccess : GHOST_kFailure;
95         }
96         else {
97                 return GHOST_kSuccess;
98         }
99 }
100
101 GHOST_TSuccess GHOST_Window::swapBuffers()
102 {
103         return m_context->swapBuffers();
104 }
105
106 GHOST_TSuccess GHOST_Window::setSwapInterval(int interval)
107 {
108         return m_context->setSwapInterval(interval);
109 }
110
111 GHOST_TSuccess GHOST_Window::getSwapInterval(int& intervalOut)
112 {
113         return m_context->getSwapInterval(intervalOut);
114 }
115
116 GHOST_TUns16 GHOST_Window::getNumOfAASamples()
117 {
118         return m_context->getNumOfAASamples();
119 }
120
121 GHOST_TSuccess GHOST_Window::activateDrawingContext()
122 {
123         return m_context->activateDrawingContext();
124 }
125
126 GHOST_TSuccess GHOST_Window::updateDrawingContext()
127 {
128         return m_context->updateDrawingContext();
129 }
130
131 GHOST_TSuccess GHOST_Window::releaseNativeHandles()
132 {
133         return m_context->releaseNativeHandles();
134 }
135
136 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
137 {
138         if (setWindowCursorVisibility(visible)) {
139                 m_cursorVisible = visible;
140                 return GHOST_kSuccess;
141         }
142         else {
143                 return GHOST_kFailure;
144         }
145 }
146
147 GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds, GHOST_TInt32 mouse_ungrab_xy[2])
148 {
149         if (m_cursorGrab == mode)
150                 return GHOST_kSuccess;
151
152         /* override with new location */
153         if (mouse_ungrab_xy) {
154                 assert(mode == GHOST_kGrabDisable);
155                 m_cursorGrabInitPos[0] = mouse_ungrab_xy[0];
156                 m_cursorGrabInitPos[1] = mouse_ungrab_xy[1];
157         }
158
159         if (setWindowCursorGrab(mode)) {
160
161                 if (mode == GHOST_kGrabDisable)
162                         m_cursorGrabBounds.m_l = m_cursorGrabBounds.m_r = -1;
163                 else if (bounds) {
164                         m_cursorGrabBounds = *bounds;
165                 }
166                 else {  /* if bounds not defined, use window */
167                         getClientBounds(m_cursorGrabBounds);
168                 }
169                 m_cursorGrab = mode;
170                 return GHOST_kSuccess;
171         }
172         else {
173                 return GHOST_kFailure;
174         }
175 }
176
177 GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect& bounds)
178 {
179         bounds = m_cursorGrabBounds;
180         return (bounds.m_l == -1 && bounds.m_r == -1) ? GHOST_kFailure : GHOST_kSuccess;
181 }
182
183 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
184 {
185         if (setWindowCursorShape(cursorShape)) {
186                 m_cursorShape = cursorShape;
187                 return GHOST_kSuccess;
188         }
189         else {
190                 return GHOST_kFailure;
191         }
192 }
193
194 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
195                                                   int hotX, int hotY)
196 {
197         return setCustomCursorShape((GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask,
198                                     16, 16, hotX, hotY, 0, 1);
199 }
200
201 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
202                                                   int sizex, int sizey, int hotX, int hotY,
203                                                   int fg_color, int bg_color)
204 {
205         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, fg_color, bg_color)) {
206                 m_cursorShape = GHOST_kStandardCursorCustom;
207                 return GHOST_kSuccess;
208         }
209         else {
210                 return GHOST_kFailure;
211         }
212 }
213
214 void GHOST_Window::setAcceptDragOperation(bool canAccept)
215 {
216         m_canAcceptDragOperation = canAccept;
217 }
218
219 bool GHOST_Window::canAcceptDragOperation() const
220 {
221         return m_canAcceptDragOperation;
222 }
223
224 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
225 {
226         m_isUnsavedChanges = isUnsavedChanges;
227
228         return GHOST_kSuccess;
229 }
230
231 bool GHOST_Window::getModifiedState()
232 {
233         return m_isUnsavedChanges;
234 }