Blender  V2.59
GPG_Canvas.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: GPG_Canvas.cpp 35170 2011-02-25 13:35:11Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include "GPG_Canvas.h"
00036 #include <assert.h>
00037 #include "GHOST_ISystem.h"
00038 
00039 GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
00040 : GPC_Canvas(0, 0), m_window(window)
00041 {
00042         if (m_window)
00043         {
00044                 GHOST_Rect bnds;
00045                 m_window->getClientBounds(bnds);
00046                 this->Resize(bnds.getWidth(), bnds.getHeight());
00047         }
00048 }
00049 
00050 
00051 GPG_Canvas::~GPG_Canvas(void)
00052 {
00053 }
00054 
00055 
00056 void GPG_Canvas::Init()
00057 {
00058         if (m_window)
00059         {
00060                 GHOST_TSuccess success;
00061                 success = m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
00062                 assert(success == GHOST_kSuccess);
00063         }
00064 }
00065 
00066 void GPG_Canvas::SetMousePosition(int x, int y)
00067 {
00068         GHOST_ISystem* system = GHOST_ISystem::getSystem();
00069         if (system && m_window)
00070         {
00071                 GHOST_TInt32 gx = (GHOST_TInt32)x;
00072                 GHOST_TInt32 gy = (GHOST_TInt32)y;
00073                 GHOST_TInt32 cx;
00074                 GHOST_TInt32 cy;
00075                 m_window->clientToScreen(gx, gy, cx, cy);
00076                 system->setCursorPosition(cx, cy);
00077         }
00078 }
00079 
00080 
00081 void GPG_Canvas::SetMouseState(RAS_MouseState mousestate)
00082 {
00083         m_mousestate = mousestate;
00084 
00085         if (m_window)
00086         {
00087                 switch (mousestate)
00088                 {
00089                 case MOUSE_INVISIBLE:
00090                         m_window->setCursorVisibility(false);
00091                         break;
00092                 case MOUSE_WAIT:
00093                         m_window->setCursorShape(GHOST_kStandardCursorWait);
00094                         m_window->setCursorVisibility(true);
00095                         break;
00096                 case MOUSE_NORMAL:
00097                         m_window->setCursorShape(GHOST_kStandardCursorRightArrow);
00098                         m_window->setCursorVisibility(true);
00099                         break;
00100                 }
00101         }
00102 }
00103 
00104 
00105 void GPG_Canvas::SwapBuffers()
00106 {
00107         if (m_window)
00108         {
00109                 m_window->swapBuffers();
00110         }
00111 }
00112 
00113 float GPG_Canvas::GetMouseNormalizedX(int x)
00114 {
00115         return float(x)/this->GetWidth();
00116 }
00117 
00118 float GPG_Canvas::GetMouseNormalizedY(int y)
00119 {
00120         return float(y)/this->GetHeight();
00121 }