mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
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
This commit is contained in:
parent
2742be1c2e
commit
48533bb3db
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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<ControllerInterface::Device*>& 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
|
@ -0,0 +1,68 @@
|
||||
#ifndef _CIFACE_OSX_H_
|
||||
#define _CIFACE_OSX_H_
|
||||
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
void Init( std::vector<ControllerInterface::Device*>& 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
|
@ -0,0 +1,3 @@
|
||||
|
||||
void OSX_Init(void *_View);
|
||||
void OSX_UpdateKeys( int max, char* keys );
|
@ -0,0 +1,38 @@
|
||||
#import <AppKit/NSWindow.h>
|
||||
#import <AppKit/NSView.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#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];
|
||||
}
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user