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