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