1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
/**
* $Id: GPU_Engine.cpp,v 1.5 2004/03/22 22:01:42 jesterking Exp $
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <assert.h>
#include <unistd.h>
#include "GPU_Engine.h"
#include "GPC_MouseDevice.h"
#include "GPU_Canvas.h"
#include "GPU_KeyboardDevice.h"
#include "GPU_System.h"
#include "BLI_blenlib.h"
#include "BLO_readfile.h"
#include "SND_DeviceManager.h"
#include "NG_NetworkScene.h"
#include "NG_LoopBackNetworkDeviceInterface.h"
#include "SND_DeviceManager.h"
#include "KX_BlenderSceneConverter.h"
#ifdef USE_SUMO_SOLID
#include "SM_Scene.h"
#endif
#include "KX_KetsjiEngine.h"
#include "GPC_RenderTools.h"
#include "GPC_RawImage.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
void Redraw(GPU_Engine *engine); // -the- redraw function
// callback functions
/*
void RedrawCallback(Widget, XtPointer closure, XEvent *, Boolean *continue_to_dispatch);
void KeyDownCallback(Widget w, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch);
void KeyUpCallback(Widget w, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch);
void ButtonPressReleaseCallback(Widget w, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch);
void PointerMotionCallback(Widget w, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch);
void TimeOutCallback(XtPointer closure, XtIntervalId *id);
*/
GPU_Engine::GPU_Engine(char *customLoadingAnimationURL,
int foregroundColor, int backgroundColor, int frameRate) :
GPC_Engine(customLoadingAnimationURL, foregroundColor, backgroundColor,
frameRate), m_timerTimeOutMsecs(10)
{
}
GPU_Engine::~GPU_Engine()
{
}
/*
bool GPU_Engine::Initialize(Display *display, Window window, int width, int height)
{
SND_DeviceManager::Subscribe();
m_audiodevice = SND_DeviceManager::Instance();
m_keyboarddev = new GPU_KeyboardDevice();
m_mousedev = new GPC_MouseDevice();
// constructor only initializes data
// m_canvas = new GPU_Canvas(display, window, width, height);
//m_canvas->Init(); // create the actual visual and rendering context
//cout << "GPU_Canvas created and initialized, m_canvas " << m_canvas << endl;
//AddEventHandlers(); // done here (in GPU_Engine) since the event handlers need access to 'this', ie the engine
// put the Blender logo in the topleft corner
if(m_BlenderLogo != 0)
// adding a banner automatically enables them
m_BlenderLogoId = m_canvas->AddBanner(m_BlenderLogo->Width(), m_BlenderLogo->Height(),
m_BlenderLogo->Width(), m_BlenderLogo->Height(),
m_BlenderLogo->Data(), GPC_Canvas::alignTopLeft);
// put the Blender3D logo in the bottom right corner
if(m_Blender3DLogo != 0)
// adding a banner automatically enables them
m_Blender3DLogoId = m_canvas->AddBanner(m_Blender3DLogo->Width(), m_Blender3DLogo->Height(),
m_Blender3DLogo->Width(), m_Blender3DLogo->Height(),
m_Blender3DLogo->Data(), GPC_Canvas::alignTopLeft);
#if 0
// put the NaN logo in the bottom right corner
if(m_NaNLogo != 0)
// adding a banner automatically enables them
m_NaNLogoId = m_canvas->AddBanner(m_NaNLogo->Width(), m_NaNLogo->Height(),
m_NaNLogo->Width(), m_NaNLogo->Height(),
m_NaNLogo->Data(), GPC_Canvas::alignBottomRight);
#endif
// enable the display of all banners
m_canvas->SetBannerDisplayEnabled(true);
m_rendertools = new GPC_RenderTools();
m_networkdev = new NG_LoopBackNetworkDeviceInterface();
assert(m_networkdev);
// creation of system needs 'current rendering context', this is taken care
// of by the GPU_Canvas::Init()
m_system = new GPU_System();
m_system->SetKeyboardDevice((GPU_KeyboardDevice *)m_keyboarddev);
m_system->SetMouseDevice(m_mousedev);
m_system->SetNetworkDevice(m_networkdev);
m_initialized = true;
return m_initialized;
}
*/
/*
void GPU_Engine::HandleNewWindow(Window window)
{
// everything only if it's really a new window
if(window != ((GPU_Canvas *)m_canvas)->GetWindow())
{
cout << "GPU_Engine::HandleNewWindow(), new window so calling SetNewWindowMakeNewWidgetAndMakeCurrent()" << endl;
// We don't have to remove the event handlers ourselves, they are destroyed by X11
// make canvas aware of new window, and make it current
((GPU_Canvas *)m_canvas)->SetNewWindowMakeNewWidgetAndMakeCurrent(window);
// and add event handlers to new widget
AddEventHandlers();
cout << "GPU_Engine::HandleNewWindow(), event handlers added" << endl;
}
}
*/
/*
void GPU_Engine::AddEventHandlers(void)
{
Widget widget = ((GPU_Canvas *)m_canvas)->GetWidget();
// redraw
// MUST be the *Raw* event handler, the normal one doesn't work!
XtAddRawEventHandler(widget, ExposureMask, FALSE, RedrawCallback, this);
#if 0
// key down
XtAddRawEventHandler(widget, KeyPressMask, FALSE, KeyDownCallback, this);
// key up
XtAddRawEventHandler(widget, KeyReleaseMask, FALSE, KeyUpCallback, this);
// mouse button press
XtAddRawEventHandler(widget, ButtonPressMask, FALSE, ButtonPressReleaseCallback, this);
// mouse button release
XtAddRawEventHandler(widget, ButtonReleaseMask, FALSE, ButtonPressReleaseCallback, this);
// mouse motion
XtAddRawEventHandler(widget, PointerMotionMask, FALSE, PointerMotionCallback, this);
#endif
#if 0
// time out, not a real timer. New time out will be set in callback
m_timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(widget),
m_timerTimeOutMsecs, TimeOutCallback, this);
#endif
}
*/
void Redraw(GPU_Engine *engine)
{
/* if(engine->Running())
{
if(engine->Loading())
{
engine->UpdateLoadingAnimation();
}
engine->m_system->DoMainLoopCallback();
}*/
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* Callback functions
+++++++++++++++++++++++++++++++++++++++++++++++++*/
void RedrawCallback(Widget, XtPointer closure, XEvent *, Boolean *continue_to_dispatch)
{
GPU_Engine *engine = (GPU_Engine *)closure;
Redraw(engine);
*continue_to_dispatch = True;
}
void KeyDownCallback(Widget, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch)
{
/* GPU_Engine *engine = (GPU_Engine *)closure;
XKeyEvent *keyEvent = (XKeyEvent *)event;
if(engine->Running())
engine->m_system->AddKey(int(keyEvent->keycode), 1);
*continue_to_dispatch = True;*/
}
void KeyUpCallback(Widget, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch)
{
/* GPU_Engine *engine = (GPU_Engine *)closure;
XKeyEvent *keyEvent = (XKeyEvent *)event;
if(engine->Running())
engine->m_system->AddKey(int(keyEvent->keycode), 0);
*continue_to_dispatch = True;*/
}
void ButtonPressReleaseCallback(Widget, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch)
{
GPU_Engine *engine = (GPU_Engine *)closure;
XButtonEvent *buttonEvent = (XButtonEvent *)event;
bool isDown;
GPC_MouseDevice::TButtonId button;
if(engine->Running())
{
// determine type of event, press or release
isDown = false;
if(buttonEvent->type == ButtonPress)
isDown = true;
// determine which button exactly generated this event
switch(buttonEvent->button)
{
case 1:
button = GPC_MouseDevice::buttonLeft;
break;
case 2:
button = GPC_MouseDevice::buttonMiddle;
break;
case 3:
button = GPC_MouseDevice::buttonRight;
break;
}
engine->m_mousedev->ConvertButtonEvent(button,
isDown, buttonEvent->x, buttonEvent->y);
}
*continue_to_dispatch = True;
}
void PointerMotionCallback(Widget w, XtPointer closure, XEvent *event, Boolean *continue_to_dispatch)
{
GPU_Engine *engine = (GPU_Engine *)closure;
XButtonEvent *buttonEvent = (XButtonEvent *)event;
if(engine->Running())
{
engine->m_mousedev->ConvertMoveEvent(buttonEvent->x, buttonEvent->y);
}
*continue_to_dispatch = True;
}
/*
void TimeOutCallback(XtPointer closure, XtIntervalId *id)
{
GPU_Engine *engine = (GPU_Engine *)closure;
Redraw(engine);
// add a new time out since there is no real timer for X (not a simple one like under windows)
// TODO Have to get faster timer !
if(engine->Running())
engine->m_timerId = XtAppAddTimeOut(XtWidgetToApplicationContext(
((GPU_Canvas *)engine->m_canvas)->GetWidget()),
engine->m_timerTimeOutMsecs, TimeOutCallback,
closure);
}
*/
|