Experimental option to allow moving the mouse outside the view, "Continuous Grab...
[blender.git] / intern / ghost / intern / GHOST_Window.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /**
30  * Copyright (C) 2001 NaN Technologies B.V.
31  * @author      Maarten Gribnau
32  * @date        May 10, 2001
33  */
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #include "GHOST_Window.h"
40
41
42 GHOST_Window::GHOST_Window(
43         const STR_String& /*title*/,
44         GHOST_TInt32 /*left*/, GHOST_TInt32 /*top*/, GHOST_TUns32 width, GHOST_TUns32 height,
45         GHOST_TWindowState state,
46         GHOST_TDrawingContextType type,
47         const bool stereoVisual)
48 :
49         m_drawingContextType(type),
50         m_cursorVisible(true),
51         m_cursorGrabbed(false),
52         m_cursorWarp(false),
53         m_cursorShape(GHOST_kStandardCursorDefault),
54         m_stereoVisual(stereoVisual)
55 {
56         m_isUnsavedChanges = false;
57         
58     m_cursorWarpAccumPos[0] = 0;
59     m_cursorWarpAccumPos[1] = 0;
60
61     m_fullScreen = state == GHOST_kWindowStateFullScreen;
62     if (m_fullScreen) {
63         m_fullScreenWidth = width;
64         m_fullScreenHeight = height;
65     }
66 }
67
68
69 GHOST_Window::~GHOST_Window()
70 {
71 }
72
73
74 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
75 {
76         GHOST_TSuccess success = GHOST_kSuccess;
77         if (type != m_drawingContextType) {
78                 success = removeDrawingContext();
79                 if (success) {
80                         success = installDrawingContext(type);
81                         m_drawingContextType = type;
82                 }
83                 else {
84                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
85                 }
86         }
87         return success;
88 }
89
90 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
91 {
92         if (setWindowCursorVisibility(visible)) {
93                 m_cursorVisible = visible;
94                 return GHOST_kSuccess;
95         }
96         else {
97                 return GHOST_kFailure;
98         }
99 }
100
101 GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab, bool warp)
102 {
103         if(m_cursorGrabbed == grab)
104                 return GHOST_kSuccess;
105
106         if (setWindowCursorGrab(grab, warp)) {
107                 m_cursorGrabbed = grab;
108                 return GHOST_kSuccess;
109         }
110         else {
111                 return GHOST_kFailure;
112         }
113 }
114
115 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
116 {
117         if (setWindowCursorShape(cursorShape)) {
118                 m_cursorShape = cursorShape;
119                 return GHOST_kSuccess;
120         }
121         else {
122                 return GHOST_kFailure;
123         }
124 }
125
126 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
127                                                                                                          int hotX, int hotY)
128 {
129         return setCustomCursorShape( (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 
130                                                                         16, 16, hotX, hotY, 0, 1 );
131 }
132
133 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, 
134                                                                                                         int sizex, int sizey, int hotX, int hotY,
135                                                                                                         int fg_color, int bg_color )
136 {
137         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey,hotX, hotY, fg_color, bg_color)) {
138                 m_cursorShape = GHOST_kStandardCursorCustom;
139                 return GHOST_kSuccess;
140         }
141         else {
142                 return GHOST_kFailure;
143         }
144 }
145
146
147 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
148 {
149         m_isUnsavedChanges = isUnsavedChanges;
150         
151         return GHOST_kSuccess;
152 }
153
154 bool GHOST_Window::getModifiedState()
155 {
156         return m_isUnsavedChanges;
157 }