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

SCA_MouseSensor.cpp

Go to the documentation of this file.
00001 
00007 
00008 #include "SCA_MouseSensor.h"
00009 #include "SCA_EventManager.h"
00010 #include "SCA_MouseManager.h"
00011 #include "SCA_LogicManager.h"
00012 #include "SCA_IInputDevice.h"
00013 #include "ConstExpr.h"
00014 #include <iostream>
00015 
00016 /* ------------------------------------------------------------------------- */
00017 /* Native functions                                                          */
00018 /* ------------------------------------------------------------------------- */
00019 
00020 SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, 
00021                                                                  int startx,int starty,
00022                                                            short int mousemode,
00023                                                            SCA_IObject* gameobj, 
00024                                                            PyTypeObject* T)
00025     : SCA_ISensor(gameobj,eventmgr, T),
00026         m_pMouseMgr(eventmgr),
00027         m_x(startx),
00028         m_y(starty)

00029 {
00030         m_mousemode   = mousemode;
00031         m_triggermode = true;
00032         m_val         = 0; /* stores the latest attribute */
00033 
00034         switch (m_mousemode) {
00035         case KX_MOUSESENSORMODE_LEFTBUTTON:
00036                 m_hotkey = SCA_IInputDevice::KX_LEFTMOUSE;
00037                 break;
00038         case KX_MOUSESENSORMODE_MIDDLEBUTTON:
00039                 m_hotkey = SCA_IInputDevice::KX_MIDDLEMOUSE;
00040                 break;
00041         case KX_MOUSESENSORMODE_RIGHTBUTTON:
00042                 m_hotkey = SCA_IInputDevice::KX_RIGHTMOUSE;
00043                 break;
00044         default:
00045                 ; /* ignore, no hotkey */
00046         }
00047 
00048 }
00049 
00050 SCA_MouseSensor::~SCA_MouseSensor() 

00051 {
00052     /* Nothing to be done here. */
00053 }
00054 
00055 bool SCA_MouseSensor::Evaluate(CValue* event)

00056 {
00057         bool result = false;
00058         SCA_IInputDevice* mousedev = m_pMouseMgr->GetInputDevice();
00059 
00060         int mouseval;
00061 
00062 //      SCA_ILogicBrick::RegisterEvent(event);
00063 //      if (m_mousemode == KX_MOUSESENSORMODE_MOVEMENT) cout << "\nChecking for movement...";
00064 //CValue* val = event->GetProperty("val");
00065 
00066         /* both MOUSEX and MOUSEY. Treat all of these as key-presses.            */
00067         /* So, treat KX_MOUSESENSORMODE_POSITION as                              */
00068         /* KX_MOUSESENSORMODE_POSITIONX || KX_MOUSESENSORMODE_POSITIONY          */
00069 
00070         switch (m_mousemode) {
00071         case KX_MOUSESENSORMODE_LEFTBUTTON:
00072         case KX_MOUSESENSORMODE_MIDDLEBUTTON:
00073         case KX_MOUSESENSORMODE_RIGHTBUTTON:
00074                 {
00075                         const SCA_InputEvent& event = mousedev->GetEventValue(m_hotkey);
00076                         if (event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
00077                         {
00078                                 m_val = 1;
00079                                 result = true;
00080                         } else
00081                         {
00082                                 if (event.m_status == SCA_InputEvent::KX_JUSTRELEASED)
00083                                 {
00084                                         m_val = 0;
00085                                         result = true;
00086                                 }
00087                         }
00088                         break;
00089                 }
00090         case KX_MOUSESENSORMODE_MOVEMENT:
00091                 
00092                 {
00093                         const SCA_InputEvent& eventX = mousedev->GetEventValue(SCA_IInputDevice::KX_MOUSEX);
00094                         const SCA_InputEvent& eventY = mousedev->GetEventValue(SCA_IInputDevice::KX_MOUSEY);
00095 
00096                         if (eventX.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
00097                                 eventY.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
00098                                 eventX.m_status == SCA_InputEvent::KX_ACTIVE ||
00099                                 eventY.m_status == SCA_InputEvent::KX_ACTIVE)
00100                                 
00101                         {
00102                                 m_val = 1;
00103                                 result = true;
00104                         } else
00105                         {
00106                                 if (eventX.m_status == SCA_InputEvent::KX_JUSTRELEASED ||
00107                                         eventY.m_status == SCA_InputEvent::KX_JUSTRELEASED )
00108                                 {
00109                                         m_val = 0;
00110                                         result = true;
00111                                 }
00112                         }
00113                         break;
00114                 }
00115         default:
00116                 ; /* error */
00117         }
00118 
00119         return result;
00120 }
00121 
00122 void SCA_MouseSensor::setX(unsigned short x)

00123 {
00124         m_x = x;
00125 }
00126 
00127 void SCA_MouseSensor::setY(unsigned short y)

00128 {
00129         m_y = y;
00130 }
00131 
00132 bool SCA_MouseSensor::isValid(SCA_MouseSensor::KX_MOUSESENSORMODE m)

00133 {
00134         bool res = false;
00135 
00136         res = ((m > KX_MOUSESENSORMODE_NODEF) && (m < KX_MOUSESENSORMODE_MAX));
00137         
00138         return res;
00139 }
00140 
00141 /* ------------------------------------------------------------------------- */
00142 /* Python functions                                                          */
00143 /* ------------------------------------------------------------------------- */
00144 
00145 /* Integration hooks ------------------------------------------------------- */
00146 PyTypeObject SCA_MouseSensor::Type = {
00147         PyObject_HEAD_INIT(&PyType_Type)
00148         0,
00149         "SCA_MouseSensor",
00150         sizeof(SCA_MouseSensor),
00151         0,
00152         PyDestructor,
00153         0,
00154         __getattr,
00155         __setattr,
00156         0, //&MyPyCompare,
00157         __repr,
00158         0, //&cvalue_as_number,
00159         0,
00160         0,
00161         0,
00162         0
00163 };
00164 
00165 PyParentObject SCA_MouseSensor::Parents[] = {
00166         &SCA_MouseSensor::Type,
00167         &SCA_ISensor::Type,
00168         &SCA_ILogicBrick::Type,
00169         &CValue::Type,
00170         NULL
00171 };
00172 
00173 PyMethodDef SCA_MouseSensor::Methods[] = {
00174         {"getXPosition", (PyCFunction) SCA_MouseSensor::sPyGetXPosition, METH_VARARGS, GetXPosition_doc},
00175         {"getYPosition", (PyCFunction) SCA_MouseSensor::sPyGetYPosition, METH_VARARGS, GetYPosition_doc},
00176         {NULL,NULL} //Sentinel
00177 };
00178 
00179 PyObject* SCA_MouseSensor::_getattr(char* attr) {
00180         _getattr_up(SCA_ISensor);
00181 }
00182 
00183 /* get x position ---------------------------------------------------------- */
00184 char SCA_MouseSensor::GetXPosition_doc[] = 
00185 "getXPosition\n"
00186 "\tReturns the x-coordinate of the mouse sensor, in frame coordinates.\n"
00187 "\tThe lower-left corner is the origin. The coordinate is given in\n"
00188 "\tpixels\n";
00189 PyObject* SCA_MouseSensor::PyGetXPosition(PyObject* self, 
00190                                                                                  PyObject* args, 
00191                                                                                  PyObject* kwds) {
00192         return PyInt_FromLong(m_x);
00193 }
00194 
00195 /* get y position ---------------------------------------------------------- */
00196 char SCA_MouseSensor::GetYPosition_doc[] = 
00197 "getYPosition\n"
00198 "\tReturns the y-coordinate of the mouse sensor, in frame coordinates.\n"
00199 "\tThe lower-left corner is the origin. The coordinate is given in\n"
00200 "\tpixels\n";
00201 PyObject* SCA_MouseSensor::PyGetYPosition(PyObject* self, 
00202                                                                                  PyObject* args, 
00203                                                                                  PyObject* kwds) {
00204         return PyInt_FromLong(m_y);
00205 }
00206 
00207 /* eof */

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