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