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 "KX_BlenderCanvas.h" 00034 #include "DNA_screen_types.h" 00035 #include <stdio.h> 00036 00037 00038 KX_BlenderCanvas::KX_BlenderCanvas(struct wmWindow *win, RAS_Rect &rect, struct ARegion *ar) : 00039 m_win(win), 00040 m_frame_rect(rect) 00041 { 00042 // area boundaries needed for mouse coordinates in Letterbox framing mode 00043 m_area_left = ar->winrct.xmin; 00044 m_area_top = ar->winrct.ymax; 00045 } 00046 00047 KX_BlenderCanvas::~KX_BlenderCanvas() 00048 { 00049 } 00050 00051 void KX_BlenderCanvas::Init() 00052 { 00053 glDepthFunc(GL_LEQUAL); 00054 } 00055 00056 00057 void KX_BlenderCanvas::SwapBuffers() 00058 { 00059 BL_SwapBuffers(m_win); 00060 } 00061 00062 void KX_BlenderCanvas::BeginFrame() 00063 { 00064 glEnable(GL_DEPTH_TEST); 00065 glDepthFunc(GL_LEQUAL); 00066 00067 } 00068 00069 00070 void KX_BlenderCanvas::EndFrame() 00071 { 00072 // this is needed, else blender distorts a lot 00073 glPopAttrib(); 00074 glPushAttrib(GL_ALL_ATTRIB_BITS); 00075 00076 glDisable(GL_FOG); 00077 } 00078 00079 00080 00081 void KX_BlenderCanvas::ClearColor(float r,float g,float b,float a) 00082 { 00083 glClearColor(r,g,b,a); 00084 } 00085 00086 00087 00088 void KX_BlenderCanvas::ClearBuffer(int type) 00089 { 00090 int ogltype = 0; 00091 00092 if (type & RAS_ICanvas::COLOR_BUFFER ) 00093 ogltype |= GL_COLOR_BUFFER_BIT; 00094 00095 if (type & RAS_ICanvas::DEPTH_BUFFER ) 00096 ogltype |= GL_DEPTH_BUFFER_BIT; 00097 glClear(ogltype); 00098 } 00099 00100 int KX_BlenderCanvas::GetWidth( 00101 ) const { 00102 return m_frame_rect.GetWidth(); 00103 } 00104 00105 int KX_BlenderCanvas::GetHeight( 00106 ) const { 00107 return m_frame_rect.GetHeight(); 00108 } 00109 00110 int KX_BlenderCanvas::GetMouseX(int x) 00111 { 00112 float left = GetWindowArea().GetLeft(); 00113 return float(x - (left - m_area_left)); 00114 } 00115 00116 int KX_BlenderCanvas::GetMouseY(int y) 00117 { 00118 float top = GetWindowArea().GetTop(); 00119 return float(y - (m_area_top - top)); 00120 } 00121 00122 float KX_BlenderCanvas::GetMouseNormalizedX(int x) 00123 { 00124 int can_x = GetMouseX(x); 00125 return float(can_x)/this->GetWidth(); 00126 } 00127 00128 float KX_BlenderCanvas::GetMouseNormalizedY(int y) 00129 { 00130 int can_y = GetMouseY(y); 00131 return float(can_y)/this->GetHeight(); 00132 } 00133 00134 RAS_Rect & 00135 KX_BlenderCanvas:: 00136 GetWindowArea( 00137 ){ 00138 return m_area_rect; 00139 } 00140 00141 void 00142 KX_BlenderCanvas:: 00143 SetViewPort( 00144 int x1, int y1, 00145 int x2, int y2 00146 ){ 00147 /* x1 and y1 are the min pixel coordinate (e.g. 0) 00148 x2 and y2 are the max pixel coordinate 00149 the width,height is calculated including both pixels 00150 therefore: max - min + 1 00151 */ 00152 int vp_width = (x2 - x1) + 1; 00153 int vp_height = (y2 - y1) + 1; 00154 int minx = m_frame_rect.GetLeft(); 00155 int miny = m_frame_rect.GetBottom(); 00156 00157 m_area_rect.SetLeft(minx + x1); 00158 m_area_rect.SetBottom(miny + y1); 00159 m_area_rect.SetRight(minx + x2); 00160 m_area_rect.SetTop(miny + y2); 00161 00162 glViewport(minx + x1, miny + y1, vp_width, vp_height); 00163 glScissor(minx + x1, miny + y1, vp_width, vp_height); 00164 } 00165 00166 00167 void KX_BlenderCanvas::SetMouseState(RAS_MouseState mousestate) 00168 { 00169 m_mousestate = mousestate; 00170 00171 switch (mousestate) 00172 { 00173 case MOUSE_INVISIBLE: 00174 { 00175 BL_HideMouse(m_win); 00176 break; 00177 } 00178 case MOUSE_WAIT: 00179 { 00180 BL_WaitMouse(m_win); 00181 break; 00182 } 00183 case MOUSE_NORMAL: 00184 { 00185 BL_NormalMouse(m_win); 00186 break; 00187 } 00188 default: 00189 { 00190 } 00191 } 00192 } 00193 00194 00195 00196 // (0,0) is top left, (width,height) is bottom right 00197 void KX_BlenderCanvas::SetMousePosition(int x,int y) 00198 { 00199 int winX = m_frame_rect.GetLeft(); 00200 int winY = m_frame_rect.GetBottom(); 00201 int winH = m_frame_rect.GetHeight(); 00202 00203 BL_warp_pointer(m_win, winX + x, winY + (winH-y)); 00204 } 00205 00206 00207 00208 void KX_BlenderCanvas::MakeScreenShot(const char* filename) 00209 { 00210 ScrArea area_dummy= {0}; 00211 area_dummy.totrct.xmin = m_frame_rect.GetLeft(); 00212 area_dummy.totrct.xmax = m_frame_rect.GetRight(); 00213 area_dummy.totrct.ymin = m_frame_rect.GetBottom(); 00214 area_dummy.totrct.ymax = m_frame_rect.GetTop(); 00215 00216 BL_MakeScreenShot(&area_dummy, filename); 00217 }