doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / GamePlayer / ghost / GPG_Canvas.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include "GPG_Canvas.h"
31 #include <assert.h>
32 #include "GHOST_ISystem.h"
33
34 GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
35 : GPC_Canvas(0, 0), m_window(window)
36 {
37         if (m_window)
38         {
39                 GHOST_Rect bnds;
40                 m_window->getClientBounds(bnds);
41                 this->Resize(bnds.getWidth(), bnds.getHeight());
42         }
43 }
44
45
46 GPG_Canvas::~GPG_Canvas(void)
47 {
48 }
49
50
51 void GPG_Canvas::Init()
52 {
53         if (m_window)
54         {
55                 GHOST_TSuccess success;
56                 success = m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
57                 assert(success == GHOST_kSuccess);
58         }
59 }
60
61 void GPG_Canvas::SetMousePosition(int x, int y)
62 {
63         GHOST_ISystem* system = GHOST_ISystem::getSystem();
64         if (system && m_window)
65         {
66                 GHOST_TInt32 gx = (GHOST_TInt32)x;
67                 GHOST_TInt32 gy = (GHOST_TInt32)y;
68                 GHOST_TInt32 cx;
69                 GHOST_TInt32 cy;
70                 m_window->clientToScreen(gx, gy, cx, cy);
71                 system->setCursorPosition(cx, cy);
72         }
73 }
74
75
76 void GPG_Canvas::SetMouseState(RAS_MouseState mousestate)
77 {
78         m_mousestate = mousestate;
79
80         if (m_window)
81         {
82                 switch (mousestate)
83                 {
84                 case MOUSE_INVISIBLE:
85                         m_window->setCursorVisibility(false);
86                         break;
87                 case MOUSE_WAIT:
88                         m_window->setCursorShape(GHOST_kStandardCursorWait);
89                         m_window->setCursorVisibility(true);
90                         break;
91                 case MOUSE_NORMAL:
92                         m_window->setCursorShape(GHOST_kStandardCursorRightArrow);
93                         m_window->setCursorVisibility(true);
94                         break;
95                 }
96         }
97 }
98
99
100 void GPG_Canvas::SwapBuffers()
101 {
102         if (m_window)
103         {
104                 m_window->swapBuffers();
105         }
106 }
107
108 float GPG_Canvas::GetMouseNormalizedX(int x)
109 {
110         return float(x)/this->GetWidth();
111 }
112
113 float GPG_Canvas::GetMouseNormalizedY(int y)
114 {
115         return float(y)/this->GetHeight();
116 }