951c3bc381d3c88845ca3359ad88cfb035df2d75
[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(true),
52         m_cursorShape(GHOST_kStandardCursorDefault),
53         m_stereoVisual(stereoVisual)
54 {
55     m_fullScreen = state == GHOST_kWindowStateFullScreen;
56     if (m_fullScreen) {
57         m_fullScreenWidth = width;
58         m_fullScreenHeight = height;
59     }
60 }
61
62
63 GHOST_Window::~GHOST_Window()
64 {
65 }
66
67
68 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
69 {
70         GHOST_TSuccess success = GHOST_kSuccess;
71         if (type != m_drawingContextType) {
72                 success = removeDrawingContext();
73                 if (success) {
74                         success = installDrawingContext(type);
75                         m_drawingContextType = type;
76                 }
77                 else {
78                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
79                 }
80         }
81         return success;
82 }
83
84 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
85 {
86         if (setWindowCursorVisibility(visible)) {
87                 m_cursorVisible = visible;
88                 return GHOST_kSuccess;
89         }
90         else {
91                 return GHOST_kFailure;
92         }
93 }
94
95 GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab)
96 {
97         if(m_cursorGrabbed == grab)
98                 return GHOST_kSuccess;
99
100         if (setWindowCursorGrab(grab)) {
101                 m_cursorGrabbed = grab;
102                 return GHOST_kSuccess;
103         }
104         else {
105                 return GHOST_kFailure;
106         }
107 }
108
109 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
110 {
111         if (setWindowCursorShape(cursorShape)) {
112                 m_cursorShape = cursorShape;
113                 return GHOST_kSuccess;
114         }
115         else {
116                 return GHOST_kFailure;
117         }
118 }
119
120 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
121                                                                                                          int hotX, int hotY)
122 {
123         return setCustomCursorShape( (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 
124                                                                         16, 16, hotX, hotY, 0, 1 );
125 }
126
127 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, 
128                                                                                                         int sizex, int sizey, int hotX, int hotY,
129                                                                                                         int fg_color, int bg_color )
130 {
131         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey,hotX, hotY, fg_color, bg_color)) {
132                 m_cursorShape = GHOST_kStandardCursorCustom;
133                 return GHOST_kSuccess;
134         }
135         else {
136                 return GHOST_kFailure;
137         }
138 }
139