Blender V2.61 - r43446

LOD_GhostTestApp.cpp

Go to the documentation of this file.
00001 
00028 #define TRUE 1
00029 #define FALSE 0
00030 
00031 #include "LOD_GhostTestApp.h"
00032 
00033 #include "GHOST_ISystem.h"
00034 #include "GHOST_IWindow.h"
00035 #include "common/GlutDrawer.h"
00036 #include "common/GlutKeyboardManager.h"
00037 #include "common/GlutMouseManager.h"
00038 
00039 using namespace std;
00040 
00041 LOD_GhostTestApp::
00042 LOD_GhostTestApp(
00043 ):
00044     m_window(NULL),
00045     m_system(NULL),
00046     m_finish_me_off (false)
00047 {
00048 }
00049 
00050 // initialize the applicaton
00051 
00052     bool
00053 LOD_GhostTestApp::
00054 InitApp(
00055 ){
00056 
00057     // create a system and window with opengl
00058     // rendering context.
00059 
00060     GHOST_TSuccess success = GHOST_ISystem::createSystem();
00061     if (success == GHOST_kFailure) return false;
00062 
00063     m_system = GHOST_ISystem::getSystem();
00064     if (m_system == NULL) return false;
00065 
00066     m_system->addEventConsumer(this);
00067     
00068     m_window = m_system->createWindow(
00069         "GHOST crud!",
00070         100,100,640,480,GHOST_kWindowStateNormal,
00071         GHOST_kDrawingContextTypeOpenGL,
00072         FALSE
00073     );
00074 
00075     if (
00076         m_window == NULL
00077     ) {
00078         m_system = NULL;
00079         GHOST_ISystem::disposeSystem();
00080         return false;
00081     }
00082 
00083     return true;
00084 }
00085 
00086 // Run the application untill internal return.
00087     void
00088 LOD_GhostTestApp::
00089 Run(
00090 ){
00091     if (m_system == NULL) {
00092         return;
00093     }
00094 
00095     while (!m_finish_me_off) {
00096         m_system->processEvents(TRUE);
00097         m_system->dispatchEvents();
00098     };
00099 }
00100 
00101 LOD_GhostTestApp::
00102 ~LOD_GhostTestApp(
00103 ){
00104     if (m_window) {
00105         m_system->disposeWindow(m_window);
00106         m_window = NULL;
00107         GHOST_ISystem::disposeSystem();
00108         m_system = NULL;
00109     }
00110 };
00111 
00112 
00113     bool 
00114 LOD_GhostTestApp::
00115 processEvent(
00116     GHOST_IEvent* event
00117 ){
00118 
00119     // map ghost events to the glut schmuk handlers.
00120     bool handled = false;
00121 
00122     switch(event->getType()) {
00123         case GHOST_kEventWindowSize:
00124         case GHOST_kEventWindowActivate:
00125         case GHOST_kEventWindowUpdate:
00126             GlutDrawManager::Draw();
00127             static_cast<GHOST_TEventWindowData *>(event->getData())->window->swapBuffers();
00128 
00129             handled = true;
00130             break;
00131         case GHOST_kEventButtonDown:
00132         {
00133             int x,y;
00134             m_system->getCursorPosition(x,y);
00135     
00136             int wx,wy;
00137             m_window->screenToClient(x,y,wx,wy);
00138 
00139             GHOST_TButtonMask button = 
00140                 static_cast<GHOST_TEventButtonData *>(event->getData())->button;
00141             GlutMouseManager::ButtonDown(m_window,button,wx,wy);
00142         }
00143         handled = true;
00144         break;
00145 
00146         case GHOST_kEventButtonUp:
00147         {
00148             int x,y;
00149             m_system->getCursorPosition(x,y);
00150     
00151             int wx,wy;
00152             m_window->screenToClient(x,y,wx,wy);
00153 
00154             GHOST_TButtonMask button = 
00155                 static_cast<GHOST_TEventButtonData *>(event->getData())->button;
00156             GlutMouseManager::ButtonUp(m_window,button,wx,wy);
00157         }
00158         handled = true;
00159         break;
00160 
00161         case GHOST_kEventCursorMove:
00162         {   
00163             int x,y;
00164             m_system->getCursorPosition(x,y);
00165     
00166             int wx,wy;
00167             m_window->screenToClient(x,y,wx,wy);
00168 
00169             GlutMouseManager::Motion(m_window,wx,wy);
00170     
00171         }   
00172         handled = true;
00173         break;
00174 
00175         case GHOST_kEventKeyDown :
00176         {
00177             GHOST_TEventKeyData *kd = 
00178                 static_cast<GHOST_TEventKeyData *>(event->getData());
00179 
00180             int x,y;
00181             m_system->getCursorPosition(x,y);
00182     
00183             int wx,wy;
00184             m_window->screenToClient(x,y,wx,wy);
00185 
00186             GlutKeyboardManager::HandleKeyboard(kd->key,wx,wy);
00187         }       
00188         handled = true;
00189         break;
00190     
00191         default :
00192             break;
00193     }
00194 
00195     return handled;
00196 }