Code cleanup: remove readblenfile module, only contained some utility functions
[blender-staging.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 /** \file gameengine/GamePlayer/ghost/GPG_Canvas.cpp
31  *  \ingroup player
32  */
33
34
35 #include "GPG_Canvas.h"
36 #include <assert.h>
37 #include "GHOST_ISystem.h"
38
39 GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
40 : GPC_Canvas(0, 0), m_window(window)
41 {
42         if (m_window)
43         {
44                 GHOST_Rect bnds;
45                 m_window->getClientBounds(bnds);
46                 this->Resize(bnds.getWidth(), bnds.getHeight());
47         }
48 }
49
50
51 GPG_Canvas::~GPG_Canvas(void)
52 {
53 }
54
55
56 void GPG_Canvas::Init()
57 {
58         if (m_window)
59         {
60                 GHOST_TSuccess success;
61                 success = m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
62                 assert(success == GHOST_kSuccess);
63         }
64 }
65
66 void GPG_Canvas::SetMousePosition(int x, int y)
67 {
68         GHOST_ISystem* system = GHOST_ISystem::getSystem();
69         if (system && m_window)
70         {
71                 GHOST_TInt32 gx = (GHOST_TInt32)x;
72                 GHOST_TInt32 gy = (GHOST_TInt32)y;
73                 GHOST_TInt32 cx;
74                 GHOST_TInt32 cy;
75                 m_window->clientToScreen(gx, gy, cx, cy);
76                 system->setCursorPosition(cx, cy);
77         }
78 }
79
80
81 void GPG_Canvas::SetMouseState(RAS_MouseState mousestate)
82 {
83         m_mousestate = mousestate;
84
85         if (m_window)
86         {
87                 switch (mousestate)
88                 {
89                 case MOUSE_INVISIBLE:
90                         m_window->setCursorVisibility(false);
91                         break;
92                 case MOUSE_WAIT:
93                         m_window->setCursorShape(GHOST_kStandardCursorWait);
94                         m_window->setCursorVisibility(true);
95                         break;
96                 case MOUSE_NORMAL:
97                         m_window->setCursorShape(GHOST_kStandardCursorRightArrow);
98                         m_window->setCursorVisibility(true);
99                         break;
100                 }
101         }
102 }
103
104
105 void GPG_Canvas::SwapBuffers()
106 {
107         if (m_window)
108         {
109                 m_window->swapBuffers();
110         }
111 }
112
113 float GPG_Canvas::GetMouseNormalizedX(int x)
114 {
115         return float(x)/this->GetWidth();
116 }
117
118 float GPG_Canvas::GetMouseNormalizedY(int y)
119 {
120         return float(y)/this->GetHeight();
121 }