From 48533bb3dbc7a7cc6d90f57e86d007f111aebeb9 Mon Sep 17 00:00:00 2001 From: Sonicadvance1 Date: Fri, 2 Apr 2010 09:41:43 +0000 Subject: [PATCH] Start work of OSX keyboard input, doesn't work, so it's currently disabled, but it's a beginning. Also changed variable 'id' to 'cid' because id is a object type in Obj-C, which I was running in to problems with, kept it that way just in case. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5269 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../ControllerInterface.cpp | 23 ++-- .../ControllerInterface/ControllerInterface.h | 9 +- .../Src/ControllerInterface/OSX/OSX.cpp | 101 ++++++++++++++++++ .../Src/ControllerInterface/OSX/OSX.h | 68 ++++++++++++ .../Src/ControllerInterface/OSX/OSXPrivate.h | 3 + .../Src/ControllerInterface/OSX/OSXPrivate.mm | 38 +++++++ Source/Plugins/Plugin_GCPadNew/Src/SConscript | 4 +- 7 files changed, 236 insertions(+), 10 deletions(-) create mode 100644 Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.cpp create mode 100644 Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.h create mode 100644 Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.h create mode 100644 Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.mm diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.cpp b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.cpp index 96f1e19759..448e7ee0cc 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.cpp +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.cpp @@ -1,5 +1,7 @@ #include "ControllerInterface.h" +namespace ciface { +} #ifdef CIFACE_USE_XINPUT #include "XInput/XInput.h" #endif @@ -9,6 +11,9 @@ #ifdef CIFACE_USE_XLIB #include "Xlib/Xlib.h" #endif +#ifdef CIFACE_USE_OSX + #include "OSX/OSX.h" +#endif #ifdef CIFACE_USE_SDL #include "SDL/SDL.h" #endif @@ -37,6 +42,9 @@ void ControllerInterface::Init() #ifdef CIFACE_USE_XLIB ciface::XLIB::Init( m_devices, m_hwnd ); #endif +#ifdef CIFACE_USE_OSX + ciface::OSX::Init( m_devices, m_hwnd ); +#endif #ifdef CIFACE_USE_SDL ciface::SDL::Init( m_devices ); #endif @@ -80,6 +88,9 @@ void ControllerInterface::DeInit() #ifdef CIFACE_USE_XLIB // nothing needed #endif +#ifdef CIFACE_USE_OSX + // nothing needed +#endif #ifdef CIFACE_USE_SDL // there seems to be some sort of memory leak with SDL, quit isn't freeing everything up SDL_Quit(); @@ -299,12 +310,12 @@ ControlState ControllerInterface::OutputReference::State( const ControlState sta // std::string ControllerInterface::DeviceQualifier::ToString() const { - if ( source.empty() && (id < 0) && name.empty() ) + if ( source.empty() && (cid < 0) && name.empty() ) return ""; std::ostringstream ss; ss << source << '/'; - if ( id > -1 ) - ss << id; + if ( cid > -1 ) + ss << cid; ss << '/' << name; return ss.str(); } @@ -324,7 +335,7 @@ void ControllerInterface::DeviceQualifier::FromString(const std::string& str) // dum std::getline( ss, name, '/' ); - std::istringstream(name) >> (id = -1); + std::istringstream(name) >> (cid = -1); // good std::getline( ss, name = ""); @@ -338,7 +349,7 @@ void ControllerInterface::DeviceQualifier::FromString(const std::string& str) void ControllerInterface::DeviceQualifier::FromDevice(const ControllerInterface::Device* const dev) { name = dev->GetName(); - id = dev->GetId(); + cid = dev->GetId(); source= dev->GetSource(); } @@ -350,7 +361,7 @@ void ControllerInterface::DeviceQualifier::FromDevice(const ControllerInterface: bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface::Device* const dev) const { if ( dev->GetName() == name ) - if ( dev->GetId() == id ) + if ( dev->GetId() == cid ) if ( dev->GetSource() == source ) return true; return false; diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.h b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.h index f5eeec8417..f75f5863a9 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.h +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/ControllerInterface.h @@ -21,6 +21,9 @@ #ifndef CIFACE_USE_DIRECTINPUT_JOYSTICK #define CIFACE_USE_SDL #endif +#if defined(__APPLE__) + #define CIFACE_USE_OSX +#endif // idk in case i wanted to change it to double or somethin, idk what's best typedef float ControlState; @@ -109,16 +112,16 @@ public: class DeviceQualifier { public: - DeviceQualifier() : id(-1){} + DeviceQualifier() : cid(-1){} DeviceQualifier( const std::string& _source, const int _id, const std::string& _name ) - : source(_source), id(_id), name(_name) {} + : source(_source), cid(_id), name(_name) {} bool operator==(const Device* const dev) const; void FromDevice(const Device* const dev); void FromString(const std::string& str); std::string ToString() const; std::string source; - int id; + int cid; std::string name; }; diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.cpp b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.cpp new file mode 100644 index 0000000000..50d07c0121 --- /dev/null +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.cpp @@ -0,0 +1,101 @@ +#include "../ControllerInterface.h" + +#ifdef CIFACE_USE_OSX + +#include "OSX.h" +#include "OSXPrivate.h" + +namespace ciface +{ + namespace OSX + { + + + void Init( std::vector& devices, void* hwnd ) + { + // mouse will be added to this, Keyboard class will be turned into KeyboardMouse + // single device for combined keyboard/mouse, this will allow combinations like shift+click more easily + //devices.push_back( new Keyboard( hwnd ) ); + } + + Keyboard::Keyboard( void *View ) + { + + memset( &m_state, 0, sizeof(m_state) ); + OSX_Init(View); + // This is REALLY dumb right here + // Should REALLY cover the entire UTF-8 Range + for (int a = 0; a < 256; ++a) + inputs.push_back( new Key( (char)a ) ); + } + + + Keyboard::~Keyboard() + { + // might not need this func + } + + + ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input ) + { + return ((Input*)input)->GetState( &m_state ); + } + + void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ) + { + + } + + bool Keyboard::UpdateInput() + { + memset(m_state.keyboard, 0, 256); + OSX_UpdateKeys(256, m_state.keyboard ); + + // mouse stuff in here too + + return true; + } + + bool Keyboard::UpdateOutput() + { + return true; + } + + + std::string Keyboard::GetName() const + { + return "Keyboard"; + //return "Keyboard Mouse"; // change to this later + } + + std::string Keyboard::GetSource() const + { + return "OSX"; + } + + int Keyboard::GetId() const + { + return 0; + } + + + ControlState Keyboard::Key::GetState( State* const state ) + { + for(unsigned int a = 0; a < 256; ++a) + if(state->keyboard[a] == m_index) + return true; + return false; + } + + std::string Keyboard::Key::GetName() const + { + char temp[16]; + sprintf(temp, "Key:%c", m_index); + return std::string(temp); + } + + + } +} + +#endif diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.h b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.h new file mode 100644 index 0000000000..e24194cd84 --- /dev/null +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSX.h @@ -0,0 +1,68 @@ +#ifndef _CIFACE_OSX_H_ +#define _CIFACE_OSX_H_ + +#include "../ControllerInterface.h" + +namespace ciface +{ + namespace OSX + { + + void Init( std::vector& devices, void* hwnd ); + + class Keyboard : public ControllerInterface::Device + { + friend class ControllerInterface; + friend class ControllerInterface::ControlReference; + + protected: + + struct State + { + char keyboard[256]; // really dumb + // mouse crap will go here + }; + + class Input : public ControllerInterface::Device::Input + { + friend class Keyboard; + protected: + Input( const unsigned char index ) : m_index(index) {} + virtual ControlState GetState( State* const js ) = 0; + + const unsigned char m_index; + }; + + class Key : public Input + { + friend class Keyboard; + public: + std::string GetName() const; + protected: + Key( const unsigned char key ) : Input(key) {} + ControlState GetState( State* const js ); + + }; + + bool UpdateInput(); + bool UpdateOutput(); + + ControlState GetInputState( const ControllerInterface::Device::Input* const input ); + void SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ); + + public: + Keyboard( void* view ); + ~Keyboard(); + + std::string GetName() const; + std::string GetSource() const; + int GetId() const; + + private: + State m_state; + }; + + } +} + +#endif diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.h b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.h new file mode 100644 index 0000000000..a1ad184f67 --- /dev/null +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.h @@ -0,0 +1,3 @@ + +void OSX_Init(void *_View); +void OSX_UpdateKeys( int max, char* keys ); \ No newline at end of file diff --git a/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.mm b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.mm new file mode 100644 index 0000000000..590f50e25c --- /dev/null +++ b/Source/Plugins/Plugin_GCPadNew/Src/ControllerInterface/OSX/OSXPrivate.mm @@ -0,0 +1,38 @@ +#import +#import +#import + +#include "OSXPrivate.h" +NSWindow* m_Window; +void OSX_Init(void *_View) +{ + // _View is really a wxNSView + //m_Window is really a wxNSWindow + NSView *View = (NSView*)_View; + m_Window = [View window]; +} + +void OSX_UpdateKeys( int max, char* keys ) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSEvent *event = [[NSEvent alloc] init]; + + /*event = [m_Window nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ]; + + if ( event != nil ) { + switch ([event type]) { + case NSKeyDown: + //case NSKeyUp: + //case NSFlagsChanged: // For Command + memcpy(keys, [[event characters] UTF8String], max); + break; + default: + [m_Window sendEvent:event]; + break; + } + }*/ + + [event release]; + [pool release]; +} \ No newline at end of file diff --git a/Source/Plugins/Plugin_GCPadNew/Src/SConscript b/Source/Plugins/Plugin_GCPadNew/Src/SConscript index 353fe18191..e4506c63ab 100644 --- a/Source/Plugins/Plugin_GCPadNew/Src/SConscript +++ b/Source/Plugins/Plugin_GCPadNew/Src/SConscript @@ -17,6 +17,8 @@ files = [ if padenv['HAVE_SDL']: files += [ 'ControllerInterface/SDL/SDL.cpp' ] +if sys.platform == 'darwin': + files += [ 'ControllerInterface/OSX/OSX.cpp', 'ControllerInterface/OSX/OSXPrivate.mm' ] if padenv['HAVE_WX']: files += [ @@ -29,6 +31,6 @@ padenv.Append( ) if sys.platform == 'darwin': - padenv['FRAMEWORKS'] = ['CoreFoundation', 'System' ] + padenv['FRAMEWORKS'] = ['CoreFoundation', 'System', 'Cocoa', ] padenv.SharedLibrary(env['plugin_dir']+name, files)