BGE: Adding a render.setFullScreen() and a render.getFullScreen() to allow fulscreeni...
[blender.git] / source / gameengine / GamePlayer / ghost / GPG_Canvas.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file gameengine/GamePlayer/ghost/GPG_Canvas.cpp
29  *  \ingroup player
30  */
31
32
33 #include "GPG_Canvas.h"
34 #include <assert.h>
35 #include "GHOST_ISystem.h"
36
37 GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
38 : GPC_Canvas(0, 0), m_window(window)
39 {
40         if (m_window)
41         {
42                 GHOST_Rect bnds;
43                 m_window->getClientBounds(bnds);
44                 this->Resize(bnds.getWidth(), bnds.getHeight());
45         }
46 }
47
48
49 GPG_Canvas::~GPG_Canvas(void)
50 {
51 }
52
53
54 void GPG_Canvas::Init()
55 {
56         if (m_window)
57         {
58                 GHOST_TSuccess success;
59                 success = m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
60                 assert(success == GHOST_kSuccess);
61         }
62 }
63
64 void GPG_Canvas::SetMousePosition(int x, int y)
65 {
66         GHOST_ISystem* system = GHOST_ISystem::getSystem();
67         if (system && m_window)
68         {
69                 GHOST_TInt32 gx = (GHOST_TInt32)x;
70                 GHOST_TInt32 gy = (GHOST_TInt32)y;
71                 GHOST_TInt32 cx;
72                 GHOST_TInt32 cy;
73                 m_window->clientToScreen(gx, gy, cx, cy);
74                 system->setCursorPosition(cx, cy);
75         }
76 }
77
78
79 void GPG_Canvas::SetMouseState(RAS_MouseState mousestate)
80 {
81         m_mousestate = mousestate;
82
83         if (m_window)
84         {
85                 switch (mousestate)
86                 {
87                 case MOUSE_INVISIBLE:
88                         m_window->setCursorVisibility(false);
89                         break;
90                 case MOUSE_WAIT:
91                         m_window->setCursorShape(GHOST_kStandardCursorWait);
92                         m_window->setCursorVisibility(true);
93                         break;
94                 case MOUSE_NORMAL:
95                         m_window->setCursorShape(GHOST_kStandardCursorRightArrow);
96                         m_window->setCursorVisibility(true);
97                         break;
98                 }
99         }
100 }
101
102
103 void GPG_Canvas::SwapBuffers()
104 {
105         if (m_window)
106         {
107                 m_window->swapBuffers();
108         }
109 }
110
111 void GPG_Canvas::ResizeWindow(int width, int height)
112 {
113         if (m_window->getState() == GHOST_kWindowStateFullScreen)
114         {
115                 GHOST_ISystem* system = GHOST_ISystem::getSystem();
116                 GHOST_DisplaySetting setting;
117                 setting.xPixels = width;
118                 setting.yPixels = height;
119                 //XXX allow these to be changed or kept from previous state
120                 setting.bpp = 32;
121                 setting.frequency = 60;
122
123                 system->updateFullScreen(setting, &m_window);
124         }
125
126         m_window->setClientSize(width, height);
127
128         Resize(width, height);
129 }
130
131 void GPG_Canvas::SetFullScreen(bool enable)
132 {
133         if (enable)
134                 m_window->setState(GHOST_kWindowStateFullScreen);
135         else
136                 m_window->setState(GHOST_kWindowStateNormal);
137 }
138
139 bool GPG_Canvas::GetFullScreen()
140 {
141         return m_window->getState() == GHOST_kWindowStateFullScreen;
142 }
143
144 float GPG_Canvas::GetMouseNormalizedX(int x)
145 {
146         return float(x)/this->GetWidth();
147 }
148
149 float GPG_Canvas::GetMouseNormalizedY(int y)
150 {
151         return float(y)/this->GetHeight();
152 }