Last of the config.h mods...
[blender-staging.git] / source / gameengine / GamePlayer / ghost / GPG_Canvas.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include "GPG_Canvas.h"
34 #include <assert.h>
35 #include "GHOST_ISystem.h"
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
42 : GPC_Canvas(0, 0), m_window(window)
43 {
44         if (m_window)
45         {
46                 GHOST_Rect bnds;
47                 m_window->getClientBounds(bnds);
48                 this->Resize(bnds.getWidth(), bnds.getHeight());
49         }
50 }
51
52
53 GPG_Canvas::~GPG_Canvas(void)
54 {
55 }
56
57
58 void GPG_Canvas::Init()
59 {
60         if (m_window)
61         {
62                 GHOST_TSuccess success;
63                 success = m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
64                 assert(success == GHOST_kSuccess);
65         }
66 }
67
68 void GPG_Canvas::SetMousePosition(int x, int y)
69 {
70         GHOST_ISystem* system = GHOST_ISystem::getSystem();
71         if (system && m_window)
72         {
73                 GHOST_TInt32 gx = (GHOST_TInt32)x;
74                 GHOST_TInt32 gy = (GHOST_TInt32)y;
75                 GHOST_TInt32 cx;
76                 GHOST_TInt32 cy;
77                 m_window->clientToScreen(gx, gy, cx, cy);
78                 system->setCursorPosition(cx, cy);
79         }
80 }
81
82
83 void GPG_Canvas::SetMouseState(RAS_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 }