MercuryInputFB.cpp

Go to the documentation of this file.
00001 #include "MercuryInputFB.h"
00002 #include "MercuryLog.h"
00003 
00004 #include <unistd.h>
00005 #include <fcntl.h>
00006 #include <sys/types.h>
00007 #include <sys/stat.h>
00008 
00009 
00010 CursorDevice * DefaultCursorDevice = new FBMouse;
00011 bool FBKBResponce = AutoInputDeviceTracker.AddDevice( "KBFB", new DeviceKeyboardFB );
00012 
00013 void DeviceKeyboardFB::Init( MString Name ) 
00014 {
00015     int length = 512;
00016     m_iNumkeys = length;
00017     m_vKeys = new unsigned char[length];
00018     memset( m_bAllKeys, 0, 512 );
00019 }
00020 
00021 InputEvent RemapFBKB( InputEvent & ie )
00022 {   
00023     return ie;
00024 }
00025 
00026 bool DeviceKeyboardFB::IsButtonDown( int ButtonNumber ) 
00027 {
00028     if ( ( ButtonNumber >= 0 ) && ( ButtonNumber < 512 ) )
00029         return m_bAllKeys[ButtonNumber];
00030     else
00031         return false;
00032 }
00033 
00034 int DeviceKeyboardFB::NumButtons() 
00035 {
00036     return 512;
00037 }
00038 
00039 void DeviceKeyboardFB::Update( ) 
00040 {
00041     if( m_bAllKeys[1] != ( (FBMouse*) DefaultCursorDevice )->buttons & 1 )
00042     {
00043         if( m_bAllKeys[1] )
00044             m_sEvents.push_back( InputEvent( 0, 1, IET_RELEASE ) );
00045         else
00046             m_sEvents.push_back( InputEvent( 0, 1, IET_DOWN ) );
00047         m_bAllKeys[1] = ( (FBMouse*) DefaultCursorDevice )->buttons & 1;
00048     }
00049 //  InputEvent tmp
00050 //  m_sEvents.push_back(
00051 }
00052 
00053 InputEvent DeviceKeyboardFB::PopLastEvent() 
00054 { 
00055     if ( m_sEvents.empty() )
00056         return InputEvent( 0,0,IET_NONE);
00057     InputEvent ret = m_sEvents.front();
00058     m_sEvents.pop_front();
00059     return ret;
00060 }
00061 
00062 FBMouse::FBMouse( )
00063     :CursorDevice()
00064 {
00065     m_x = 0;
00066     m_y = 0;
00067     fMouse = open( "/dev/input/mice", O_RDONLY | O_NONBLOCK );
00068     if( ! fMouse )
00069     {
00070         LOG.Warn( "Could not acquire mouse!" );
00071     }
00072 }
00073 
00074 FBMouse::~FBMouse( )
00075 {
00076 }
00077 
00078 void FBMouse::GetPosition( int &x, int &y )
00079 {
00080     x = m_x;
00081     y = m_y;
00082 }
00083 
00084 void FBMouse::Update(  )
00085 {
00086     int x,y;
00087     x = y = 0;
00088 //  fd_set  *scks = new fd_set;
00089 //  timeval times;
00090 //  times.tv_sec = 0;
00091 //  times.tv_usec = 0;
00092 
00093     char c[3];
00094     if( fMouse )
00095     {
00096         int readbytes;
00097         if( readbytes = read( fMouse, c, 3 ) > 0)
00098         {   
00099             buttons = c[0] & 0x07;
00100             x = c[1];
00101             y = c[2];
00102             if( x > 128 ) x=-(256-x);
00103             if( y > 128 ) y=-(256-y);
00104             y = -y;
00105         }
00106     }
00107 
00108     m_x += (x);
00109     m_y += (y);
00110 }
00111 
00112 void FBMouse::UpdateFocus( const MString &message, void* data, PStack& info )
00113 {
00114 }
00115 
00116 /* 
00117  * Copyright (c) 2005-2006, Joshua Allen, Charles Lohr
00118  * All rights reserved.
00119  *
00120  * Redistribution and use in source and binary forms, with or
00121  * without modification, are permitted provided that the following
00122  * conditions are met:
00123  *  -   Redistributions of source code must retain the above
00124  *      copyright notice, this list of conditions and the following disclaimer.
00125  *  -   Redistributions in binary form must reproduce the above copyright
00126  *      notice, this list of conditions and the following disclaimer in
00127  *      the documentation and/or other materials provided with the distribution.
00128  *  -   Neither the name of the Mercury Engine nor the names of its
00129  *      contributors may be used to endorse or promote products derived from
00130  *      this software without specific prior written permission.
00131  *
00132  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00133  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00134  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00135  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00136  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00137  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00138  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00139  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00140  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00141  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00142  */

Hosted by SourceForge.net Logo