Initial revision
[blender.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
35 #include <assert.h>
36
37 #include "GHOST_ISystem.h"
38
39
40 GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
41 : GPC_Canvas(0, 0), m_window(window)
42 {
43         if (m_window)
44         {
45                 GHOST_Rect bnds;
46                 m_window->getClientBounds(bnds);
47                 this->Resize(bnds.getWidth(), bnds.getHeight());
48         }
49 }
50
51
52 GPG_Canvas::~GPG_Canvas(void)
53 {
54 }
55
56
57 void GPG_Canvas::Init()
58 {
59         if (m_window)
60         {
61                 GHOST_TSuccess success;
62                 success = m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
63                 assert(success == GHOST_kSuccess);
64         }
65 }
66
67 void GPG_Canvas::SetMousePosition(int x, int y)
68 {
69         GHOST_ISystem* system = GHOST_ISystem::getSystem();
70         if (system && m_window)
71         {
72                 GHOST_TInt32 gx = (GHOST_TInt32)x;
73                 GHOST_TInt32 gy = (GHOST_TInt32)y;
74                 GHOST_TInt32 cx;
75                 GHOST_TInt32 cy;
76                 m_window->clientToScreen(gx, gy, cx, cy);
77                 system->setCursorPosition(cx, cy);
78         }
79 }
80
81
82 void GPG_Canvas::SetMouseState(RAS_MouseState mousestate)
83 {
84         if (m_window)
85         {
86                 switch (mousestate)
87                 {
88                 case MOUSE_INVISIBLE:
89                         m_window->setCursorVisibility(false);
90                         break;
91                 case MOUSE_WAIT:
92                         m_window->setCursorShape(GHOST_kStandardCursorWait);
93                         m_window->setCursorVisibility(true);
94                         break;
95                 case MOUSE_NORMAL:
96                         m_window->setCursorShape(GHOST_kStandardCursorRightArrow);
97                         m_window->setCursorVisibility(true);
98                         break;
99                 }
100         }
101 }
102
103
104 void GPG_Canvas::SwapBuffers()
105 {
106         if (m_window)
107         {
108                 m_window->swapBuffers();
109         }
110 }