Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_BlenderMouseDevice.cpp

Go to the documentation of this file.
00001 
00002 #ifdef WIN32
00003 // annoying warnings about truncated STL debug info
00004 #pragma warning (disable :4786)
00005 #endif 
00006 
00007 #include "KX_BlenderMouseDevice.h"
00008 
00009 KX_BlenderMouseDevice::KX_BlenderMouseDevice()

00010 {
00011 
00012 }
00013 KX_BlenderMouseDevice::~KX_BlenderMouseDevice()

00014 {
00015 
00016 }
00017 
00021 
00022 bool KX_BlenderMouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)

00023 {
00024         const SCA_InputEvent & inevent =  m_eventStatusTables[m_currentTable][inputcode];
00025         bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 
00026                 inevent.m_status == SCA_InputEvent::KX_ACTIVE);
00027         return pressed;
00028 }
00029 /*const SCA_InputEvent& KX_BlenderMouseDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)

00030 {

00031         return m_eventStatusTables[m_currentTable][inputcode];

00032 }

00033 */
00034 
00040 void    KX_BlenderMouseDevice::NextFrame()

00041 {
00042         SCA_IInputDevice::NextFrame();
00043         
00044         // now convert justpressed keyevents into regular (active) keyevents
00045         int previousTable = 1-m_currentTable;
00046         for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS;mouseevent++)
00047         {
00048                 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent];
00049                 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
00050                         oldevent.m_status == SCA_InputEvent::KX_ACTIVE  )
00051                 {
00052                         m_eventStatusTables[m_currentTable][mouseevent] = oldevent;
00053                         m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE;
00054                 }
00055         }
00056         for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE;mousemove++)
00057         {
00058                 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove];
00059                 m_eventStatusTables[m_currentTable][mousemove] = oldevent;
00060                 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
00061                         oldevent.m_status == SCA_InputEvent::KX_ACTIVE  )
00062                 {
00063                         
00064                         m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED;
00065                 } else
00066                 {
00067                         if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED)
00068                         {
00069                                 
00070                                 m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS ;
00071                         }
00072                 }
00073         }
00074 }
00075 
00076 
00077 // get rid of this later, put it in the 2d canvas !
00078 extern "C" int BL_GetWindowWidth();
00079 extern "C" int BL_GetWindowHeight();
00080 extern "C" int BL_GetWindowMinY();
00081 extern "C" int BL_GetWindowMinX();
00082 
00087 
00088 
00089 bool    KX_BlenderMouseDevice::ConvertBlenderEvent(unsigned short incode,short val)

00090 {
00091         bool result = false;
00092         
00093         // convert event
00094         KX_EnumInputs kxevent = this->ToNative(incode);
00095 
00096         // only process it, if it's a key
00097         if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSE)
00098         {
00099                 int previousTable = 1-m_currentTable;
00100 
00101 
00102                 if (val > 0)
00103                 {
00104                         // todo: convert val ??
00105                         switch (kxevent)
00106                         {
00107                         case SCA_IInputDevice::KX_MOUSEX:
00108                                 {
00109                                         val = val-BL_GetWindowMinX();
00110                                         break;
00111                                 }
00112                         case SCA_IInputDevice::KX_MOUSEY:
00113                         {
00114                                 val = BL_GetWindowHeight() - (val - BL_GetWindowMinY());
00115                                 break;
00116                         }
00117                         default:
00118                                 {
00119                                 }
00120 
00121                         }
00122 
00123                         m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
00124 
00125                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
00126                         {
00127                         
00128                         case SCA_InputEvent::KX_ACTIVE:
00129                         case SCA_InputEvent::KX_JUSTACTIVATED:
00130                                 {
00131                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
00132                                         break;
00133                                 }
00134                         case SCA_InputEvent::KX_JUSTRELEASED:
00135                                 {
00136                                         if ( kxevent > KX_BEGINMOUSEBUTTONS && kxevent < KX_ENDMOUSEBUTTONS)
00137                                         {
00138                                                 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
00139                                         } else
00140                                         {
00141                                                 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
00142                                                 
00143                                         }
00144                                         break;
00145                                 }
00146                         default:
00147                                 {
00148                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
00149                                 }
00150                         }
00151                         
00152                 } else
00153                 {
00154                         // blender eventval == 0
00155                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
00156                         {
00157                         case SCA_InputEvent::KX_JUSTACTIVATED:
00158                         case SCA_InputEvent::KX_ACTIVE:
00159                                 {
00160                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
00161                                         break;
00162                                 }
00163                         default:
00164                                 {
00165                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
00166                                 }
00167                         }
00168                 }
00169         }
00170         return result;
00171 }

Generated at Thu Feb 1 13:03:04 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000