cmil::SDL::SDLMice Class Reference

#include <SDLTranslator.h>

Inheritance diagram for cmil::SDL::SDLMice:

Inheritance graph
[legend]
Collaboration diagram for cmil::SDL::SDLMice:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SDLMice (System *const sys)
 SDL provides event signals for 1-255 buttons and one coord.
virtual ~SDLMice ()
CoordgetPositioner () const
void setPositioner (InputData *const coord)
DeviceRegistrygetDevices ()
std::string getName () const
bool translate (const SDL_Event &input_event)
 This should return a boolean as to whether or not translation was successful.

Private Member Functions

void assign_inputs ()
 This should be limited to constructor use.

Private Attributes

Mousem_mouse
DeviceRegistry m_registry
tInputIndex< Pressm_buttons
Coordm_positioner
 Unallocation is handled externally via cleanup() of device by registry.

Detailed Description

Definition at line 183 of file SDLTranslator.h.


Constructor & Destructor Documentation

cmil::SDL::SDLMice::SDLMice ( System *const   sys  ) 

SDL provides event signals for 1-255 buttons and one coord.

Definition at line 337 of file SDLTranslator.cpp.

00337                                       : 
00338       tDeviceTranslator<Mouse>(sys),
00339       m_mouse(NULL),  
00340       m_positioner(NULL) {}

virtual cmil::SDL::SDLMice::~SDLMice (  )  [inline, virtual]

Definition at line 187 of file SDLTranslator.h.

References m_mouse.

00187                            {
00188           if(m_mouse) {
00189             delete m_mouse;
00190           }
00191         };


Member Function Documentation

void cmil::SDL::SDLMice::assign_inputs (  )  [private]

This should be limited to constructor use.

Definition at line 342 of file SDLTranslator.cpp.

References cmil::InputDevice::getData(), Logger::log_debug(), m_buttons, cmil::Mouse::m_buttons, m_mouse, setPositioner(), and cmil::DeviceInputs::use_base.

Referenced by getDevices().

00342                                 {
00343       log_debug("assign_inputs()");
00344       
00345       std::ostringstream input_ss;
00346 
00347       for(unsigned int nbutton = 0; nbutton < m_mouse->m_buttons.getSize(); ++nbutton) {
00348         input_ss << "button" << nbutton;
00349         m_buttons.addData( m_mouse->getData(DeviceInputs::use_base, input_ss.str()) );
00350         input_ss.str("");
00351       }
00352 
00353       setPositioner(m_mouse->getData(DeviceInputs::use_base, "coord0"));
00354 
00355       log_debug("finishing assign_inputs()");
00356     }

Here is the call graph for this function:

Here is the caller graph for this function:

DeviceRegistry & cmil::SDL::SDLMice::getDevices (  )  [virtual]

This retrieves a registry of devices provided by this translator, for instance, if there were only 1 joystick attached, it should return a registry containing just that joystick.

Implements cmil::SDL::tDeviceTranslator< DeviceBase >.

Definition at line 358 of file SDLTranslator.cpp.

References assign_inputs(), cmil::InputDevice::cleanup(), cmil::DeviceRegistry::clear(), cmil::DeviceRegistry::getSize(), Logger::log_debug(), Logger::log_error(), cmil::SDL::tDeviceTranslator< DeviceBase >::m_custom_devices, m_mouse, m_registry, and cmil::DeviceRegistry::registerDevice().

00358                                         {
00359       if(m_registry.getSize())  
00360         m_registry.clear();
00361 
00362       log_debug("getDevices()");
00363       std::list<Mouse*>::const_iterator i; 
00364       InputDevice* clone = NULL;
00365 
00366       DefaultMouse comparison_mouse;
00367 
00368       for(i = m_custom_devices.begin() ; i != m_custom_devices.end(); ++i) {
00369         log_debug ("getDevices() loop iterating...");
00370 
00372         if(*(*i) == comparison_mouse) {
00373           log_debug("getDevices() cloning custom device");
00374           clone = ((*i)->clone());
00375 
00376           if(!(m_mouse = dynamic_cast<Mouse*>(clone))) {
00377             log_error("getDevices() casting failure of cloned InputDevice");
00378             clone->cleanup();
00379             delete clone;
00380           }
00381           else continue;
00382         }
00383         else
00384           log_error("getDevices() custom Mouse didn't match the default.");
00385       }
00386 
00387       if(!m_mouse) {
00388         log_debug("getDevices() No valid custom devices provided, using DefaultMouse"); 
00389         m_mouse = new Mouse(comparison_mouse);
00390       }
00391       else 
00392         comparison_mouse.cleanup();
00393 
00394       assign_inputs();
00395 
00396       m_registry.registerDevice(*m_mouse);
00397 
00398       return m_registry;
00399     }

Here is the call graph for this function:

std::string cmil::SDL::SDLMice::getName (  )  const [inline, virtual]

Reimplemented from cmil::SDL::tDeviceTranslator< DeviceBase >.

Definition at line 198 of file SDLTranslator.h.

00198                                   {
00199           return "SDLMice";
00200         }

Coord* cmil::SDL::SDLMice::getPositioner (  )  const [inline]

Definition at line 193 of file SDLTranslator.h.

References m_positioner.

Referenced by translate().

00193 { return m_positioner; }

Here is the caller graph for this function:

void cmil::SDL::SDLMice::setPositioner ( InputData *const   coord  ) 

Definition at line 401 of file SDLTranslator.cpp.

References Logger::log_error(), and m_positioner.

Referenced by assign_inputs().

00401                                                         {
00402       Coord* coord = NULL;
00403 
00404       if(input) {
00405         if( ( coord = dynamic_cast< Coord* >(input) ) != NULL) {
00406         m_positioner = coord;
00407         }
00408         else
00409           log_error(std::string("setPositioner() was unable to assign the input").append(input->getName()).append("due to cast type check failure.")); 
00410       }
00411       else
00412         log_error("setPositioner() was unable to set NULL Motion type");
00413     }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::SDL::SDLMice::translate ( const SDL_Event &  input_event  )  [virtual]

This should return a boolean as to whether or not translation was successful.

Implements cmil::SDL::tDeviceTranslator< DeviceBase >.

Definition at line 415 of file SDLTranslator.cpp.

References getPositioner(), Logger::log_error(), m_buttons, cmil::pressed, cmil::released, cmil::Coord::setCoord(), cmil::ModData::setState(), and cmil::SDL::Relay::UpdateSystem().

00415                                                         {
00416       Press* button = NULL;
00417       Coord* coord  = NULL;
00418 
00419       if(input_event.type == SDL_MOUSEMOTION) {
00420         coord = getPositioner();
00421         if(coord)
00422           coord->setCoord(input_event.motion.x, input_event.motion.y, input_event.motion.xrel, input_event.motion.yrel);
00423         else 
00424           return false;
00425 
00426         UpdateSystem(*coord);
00427         return true;
00428       }
00429       else if((input_event.type == SDL_MOUSEBUTTONDOWN) || (input_event.type == SDL_MOUSEBUTTONUP)) {
00430         button = m_buttons.getData(input_event.button.button);
00431 
00432         if(button) {
00433           if(input_event.type == SDL_MOUSEBUTTONDOWN)
00434             button->setState(pressed);
00435           else
00436             button->setState(released);
00437         }
00438         else {
00439           log_error("translate ( button)  unable to convert button due to no matching InputData available");
00440           return false;
00441         }
00442 
00443         UpdateSystem(*button);
00444         return true;
00445       }
00446 
00447       //log_debug("translate( mouse event ) event gone unhandled");
00448       return false;
00449     }

Here is the call graph for this function:


Member Data Documentation

tInputIndex<Press> cmil::SDL::SDLMice::m_buttons [private]

Definition at line 210 of file SDLTranslator.h.

Referenced by assign_inputs(), and translate().

Mouse* cmil::SDL::SDLMice::m_mouse [private]

Definition at line 208 of file SDLTranslator.h.

Referenced by assign_inputs(), getDevices(), and ~SDLMice().

Coord* cmil::SDL::SDLMice::m_positioner [private]

Unallocation is handled externally via cleanup() of device by registry.

Definition at line 213 of file SDLTranslator.h.

Referenced by getPositioner(), and setPositioner().

DeviceRegistry cmil::SDL::SDLMice::m_registry [private]

Definition at line 209 of file SDLTranslator.h.

Referenced by getDevices().


The documentation for this class was generated from the following files:
(c) 2006-2007 John P. Feltz
Generated on Wed Jul 25 16:08:03 2007 for Common Media Input Layer by doxygen 1.4.7

SourceForge.net Logo