Vital fix, now it compiles but some implementation is missing
This commit is contained in:
parent
560b09f92f
commit
99341c31db
@ -67,8 +67,6 @@ else() # MACOSX
|
|||||||
${SRCROOT}/OSX/cpp_objc_conversion.mm
|
${SRCROOT}/OSX/cpp_objc_conversion.mm
|
||||||
${SRCROOT}/OSX/cg_sf_conversion.hpp
|
${SRCROOT}/OSX/cg_sf_conversion.hpp
|
||||||
${SRCROOT}/OSX/cg_sf_conversion.cpp
|
${SRCROOT}/OSX/cg_sf_conversion.cpp
|
||||||
${SRCROOT}/OSX/Joystick.cpp
|
|
||||||
${SRCROOT}/OSX/Joystick.hpp
|
|
||||||
${SRCROOT}/OSX/InputImpl.cpp
|
${SRCROOT}/OSX/InputImpl.cpp
|
||||||
${SRCROOT}/OSX/InputImpl.hpp
|
${SRCROOT}/OSX/InputImpl.hpp
|
||||||
${SRCROOT}/OSX/JoystickImpl.cpp
|
${SRCROOT}/OSX/JoystickImpl.cpp
|
||||||
|
@ -1,371 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/Window/Joystick.hpp>
|
|
||||||
#include <SFML/System/Err.hpp>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
namespace priv
|
|
||||||
{
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Joystick::Joystick()
|
|
||||||
: myManager(0)
|
|
||||||
, myElements(0)
|
|
||||||
{
|
|
||||||
/* Nothing else */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Joystick::~Joystick()
|
|
||||||
{
|
|
||||||
FreeUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void Joystick::Initialize(unsigned int Index)
|
|
||||||
{
|
|
||||||
// Try to create a joystick manager.
|
|
||||||
if (!CreateManager()) return;
|
|
||||||
|
|
||||||
// Get the joysticks.
|
|
||||||
CFSetRef devices = CopyJoysticksOnly();
|
|
||||||
|
|
||||||
// If none exit the function.
|
|
||||||
if (devices == NULL) {
|
|
||||||
FreeUp();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is there enough joystick ?
|
|
||||||
CFIndex joysticksCount = CFSetGetCount(devices);
|
|
||||||
if (joysticksCount <= CFIndex(Index)) {
|
|
||||||
FreeUp();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a usable copy of the joysticks devices.
|
|
||||||
CFTypeRef devicesArray[joysticksCount];
|
|
||||||
CFSetGetValues(devices, devicesArray);
|
|
||||||
|
|
||||||
// Release unused stuff.
|
|
||||||
CFRelease(devices); // Maybe we should have a field for that and not release it here...
|
|
||||||
|
|
||||||
// Get the Index-th joystick.
|
|
||||||
IOHIDDeviceRef device = (IOHIDDeviceRef) devicesArray[Index];
|
|
||||||
|
|
||||||
// Retrive all connected elements to this joystick.
|
|
||||||
if (!RetriveElements(device)) {
|
|
||||||
FreeUp();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Happy end!
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
JoystickState Joystick::UpdateState()
|
|
||||||
{
|
|
||||||
// If we don't have any joystick we exit.
|
|
||||||
if (myElements == 0) return JoystickState();
|
|
||||||
|
|
||||||
// Fill a JoystickState instance with the current joystick state.
|
|
||||||
JoystickState s;
|
|
||||||
|
|
||||||
// Update the buttons.
|
|
||||||
for (ButtonsVector::size_type i = 0; i < myButtons.size(); ++i) {
|
|
||||||
IOHIDValueRef value = 0;
|
|
||||||
IOHIDDeviceGetValue(IOHIDElementGetDevice(myButtons[i]), myButtons[i], &value);
|
|
||||||
|
|
||||||
// Check for plug out.
|
|
||||||
if (!value) {
|
|
||||||
// No value ? Hum... Seems like the joystick is gone.
|
|
||||||
|
|
||||||
FreeUp();
|
|
||||||
return JoystickState();
|
|
||||||
}
|
|
||||||
|
|
||||||
s.Buttons[i] = IOHIDValueGetIntegerValue(value) == 1; // 1 means pressed, others mean released.
|
|
||||||
}
|
|
||||||
|
|
||||||
for (AxisMap::iterator it = myAxis.begin(); it != myAxis.end(); ++it) {
|
|
||||||
IOHIDValueRef value = 0;
|
|
||||||
IOHIDDeviceGetValue(IOHIDElementGetDevice(it->second), it->second, &value);
|
|
||||||
|
|
||||||
// Check for plug out.
|
|
||||||
if (!value) {
|
|
||||||
// No value ? Hum... Seems like the joystick is gone.
|
|
||||||
|
|
||||||
FreeUp();
|
|
||||||
return JoystickState();
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want to bind [physicalMin,physicalMax] to [-100=min,100=max].
|
|
||||||
//
|
|
||||||
// General formula to bind [a,b] to [c,d] with a linear progression :
|
|
||||||
//
|
|
||||||
// f : [a, b] -> [c, d]
|
|
||||||
// x |-> (x-a)(d-c)/(b-a)+c
|
|
||||||
//
|
|
||||||
// This method might not be very accurate (the "0 position" can be
|
|
||||||
// slightly shift with some device) but we don't care because most
|
|
||||||
// of devices are so sensitive that this is not relevant.
|
|
||||||
double physicalMax = IOHIDElementGetPhysicalMax(it->second);
|
|
||||||
double physicalMin = IOHIDElementGetPhysicalMin(it->second);
|
|
||||||
double scaledMin = -100;
|
|
||||||
double scaledMax = 100;
|
|
||||||
double physicalValue = IOHIDValueGetScaledValue(value, kIOHIDValueScaleTypePhysical);
|
|
||||||
float scaledValue = ((physicalValue - physicalMin) * (scaledMax - scaledMin) / (physicalMax - physicalMin)) + scaledMin;
|
|
||||||
s.Axis[it->first] = scaledValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool Joystick::HasAxis(Joy::Axis Axis) const
|
|
||||||
{
|
|
||||||
return myAxis.find(Axis) != myAxis.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int Joystick::GetButtonsCount() const
|
|
||||||
{
|
|
||||||
// Return number of supported buttons.
|
|
||||||
return myButtons.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CFDictionaryRef Joystick::DevicesMaskForManager(UInt32 page, UInt32 usage)
|
|
||||||
{
|
|
||||||
// Create the dictionary.
|
|
||||||
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
|
|
||||||
&kCFTypeDictionaryKeyCallBacks,
|
|
||||||
&kCFTypeDictionaryValueCallBacks);
|
|
||||||
|
|
||||||
// Add the page value.
|
|
||||||
CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
|
|
||||||
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), value);
|
|
||||||
CFRelease(value);
|
|
||||||
|
|
||||||
// Add the usage value (which is only valid if page value exists).
|
|
||||||
value = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
|
|
||||||
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), value);
|
|
||||||
CFRelease(value);
|
|
||||||
|
|
||||||
return dict;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool Joystick::CreateManager()
|
|
||||||
{
|
|
||||||
// Create HID Manager reference.
|
|
||||||
myManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
|
||||||
|
|
||||||
// Open a HID Manager reference.
|
|
||||||
IOReturn openStatus = IOHIDManagerOpen(myManager, kIOHIDOptionsTypeNone);
|
|
||||||
|
|
||||||
if (openStatus != kIOReturnSuccess) {
|
|
||||||
sf::Err() << "Error when opening the joystick manager : "
|
|
||||||
<< std::hex << openStatus << std::endl;
|
|
||||||
|
|
||||||
CFRelease(myManager);
|
|
||||||
myManager = 0;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Everything went fine.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CFSetRef Joystick::CopyJoysticksOnly()
|
|
||||||
{
|
|
||||||
// Create a mask to get only joystick devices.
|
|
||||||
CFDictionaryRef joysticksMask = DevicesMaskForManager(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
|
|
||||||
|
|
||||||
// Sets single matching criteria (dictionary) for device enumeration.
|
|
||||||
IOHIDManagerSetDeviceMatching(myManager, joysticksMask);
|
|
||||||
|
|
||||||
// No more needed -> free up.
|
|
||||||
CFRelease(joysticksMask);
|
|
||||||
|
|
||||||
// Retrieve devices.
|
|
||||||
CFSetRef devices = IOHIDManagerCopyDevices(myManager);
|
|
||||||
return devices; // The caller is responsible for releasing it.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool Joystick::RetriveElements(IOHIDDeviceRef device)
|
|
||||||
{
|
|
||||||
// Get a list of all elements attached to the device.
|
|
||||||
myElements = IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone);
|
|
||||||
|
|
||||||
if (myElements == NULL) {
|
|
||||||
// What is a joystick with no element ? Let the user know that.
|
|
||||||
sf::Err() << "No array of element for this device" << std::endl;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// How many elements are there ?
|
|
||||||
CFIndex elements_count = CFArrayGetCount(myElements);
|
|
||||||
|
|
||||||
if (elements_count == 0) {
|
|
||||||
// What is a joystick with no element ? Let the user know that.
|
|
||||||
sf::Err() << "No element attached to this device" << std::endl;
|
|
||||||
|
|
||||||
CFRelease(myElements);
|
|
||||||
myElements = 0;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go through all connected elements.
|
|
||||||
for (int i = 0; i < elements_count; ++i) {
|
|
||||||
IOHIDElementRef element = (IOHIDElementRef) CFArrayGetValueAtIndex(myElements, i);
|
|
||||||
|
|
||||||
switch (IOHIDElementGetType(element)) {
|
|
||||||
|
|
||||||
case kIOHIDElementTypeInput_Misc:
|
|
||||||
switch (IOHIDElementGetUsage(element)) {
|
|
||||||
|
|
||||||
case kHIDUsage_GD_X:
|
|
||||||
myAxis[Joy::AxisX] = element;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kHIDUsage_GD_Y:
|
|
||||||
myAxis[Joy::AxisY] = element;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kHIDUsage_GD_Z:
|
|
||||||
myAxis[Joy::AxisZ] = element;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kHIDUsage_GD_Rx:
|
|
||||||
myAxis[Joy::AxisU] = element; // use same binding as on Linux.
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kHIDUsage_GD_Ry:
|
|
||||||
myAxis[Joy::AxisV] = element; // use same binding as on Linux.
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kHIDUsage_GD_Rz:
|
|
||||||
myAxis[Joy::AxisR] = element; // use same binding as on Linux.
|
|
||||||
break;
|
|
||||||
|
|
||||||
// kHIDUsage_GD_Vx, kHIDUsage_GD_Vy, kHIDUsage_GD_Vz are ignored.
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kIOHIDElementTypeInput_Button:
|
|
||||||
if (myButtons.size() < Joy::ButtonCount) { // If we can managed this button through events...
|
|
||||||
myButtons.push_back(element); // ...we add this element to the list.
|
|
||||||
} else {
|
|
||||||
// Too many buttons. We ignore this one.
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // Make compiler happy.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note : Joy::AxisPOV not yet supported.
|
|
||||||
// Maybe kIOHIDElementTypeInput_Axis is the type but I can't test.
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void Joystick::FreeUp()
|
|
||||||
{
|
|
||||||
ReleaseElements();
|
|
||||||
|
|
||||||
ReleaseManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void Joystick::ReleaseManager()
|
|
||||||
{
|
|
||||||
if (myManager != 0) {
|
|
||||||
// Closes the IOHIDManager
|
|
||||||
IOReturn closeStatus = IOHIDManagerClose(myManager, kIOHIDOptionsTypeNone);
|
|
||||||
|
|
||||||
if (closeStatus != kIOReturnSuccess) {
|
|
||||||
// Closing the manager failed. We don't care that much about this.
|
|
||||||
// It often happens when the connection with the device is closed after
|
|
||||||
// the device is deconected from the computer.
|
|
||||||
|
|
||||||
/*
|
|
||||||
sf::Err() << "Error when closing the manager : "
|
|
||||||
<< std::hex << closeStatus << std::endl;
|
|
||||||
//*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// Release the manager.
|
|
||||||
CFRelease(myManager);
|
|
||||||
myManager = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void Joystick::ReleaseElements()
|
|
||||||
{
|
|
||||||
if (myElements != 0) {
|
|
||||||
// Release all elements.
|
|
||||||
CFRelease(myElements);
|
|
||||||
myElements = 0;
|
|
||||||
|
|
||||||
// Both myAxis and myButton contains only reference from myElements.
|
|
||||||
// Thus no special cleanup is required on these two.
|
|
||||||
myButtons.clear();
|
|
||||||
myAxis.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace priv
|
|
||||||
|
|
||||||
} // namespace sf
|
|
@ -1,176 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef SFML_JOYSTICKOSX_HPP
|
|
||||||
#define SFML_JOYSTICKOSX_HPP
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <IOKit/hid/IOHIDManager.h>
|
|
||||||
#include <IOKit/hid/IOHIDDevice.h>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
namespace priv
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief OSX implementation of Joystick
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
class Joystick
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Default constructor
|
|
||||||
///
|
|
||||||
/// This constructors initializes all members to 0.
|
|
||||||
/// That is, it does nothing.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
Joystick();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Destructor
|
|
||||||
///
|
|
||||||
/// Close all connections to any devices if required.
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
~Joystick();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Initialize the instance and bind it to a physical joystick
|
|
||||||
///
|
|
||||||
/// \param index Index of the physical joystick to bind to
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void Initialize(unsigned int index);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Update the current joystick and return its new state
|
|
||||||
///
|
|
||||||
/// \return Current state of the joystick
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
JoystickState UpdateState();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Check if the joystick supports the given axis
|
|
||||||
///
|
|
||||||
/// \param axis Axis to check
|
|
||||||
///
|
|
||||||
/// \return True of the axis is supported, false otherwise
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool HasAxis(Joy::Axis Axis) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Get the number of buttons supported by the joystick
|
|
||||||
///
|
|
||||||
/// \return Number of buttons
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
unsigned int GetButtonsCount() const;
|
|
||||||
|
|
||||||
private :
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create a mask (dictionary) for an IOHIDManager
|
|
||||||
///
|
|
||||||
/// \param page
|
|
||||||
/// \param usage
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
static CFDictionaryRef DevicesMaskForManager(UInt32 page, UInt32 usage);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Create and open the manager
|
|
||||||
///
|
|
||||||
/// \return Return false if someting went wrong
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool CreateManager();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Copy all connected joysticks to the manager
|
|
||||||
///
|
|
||||||
/// \return NULL or a valid (possibly empty) set of devices
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CFSetRef CopyJoysticksOnly();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Load all connected elements to the given device
|
|
||||||
///
|
|
||||||
/// \param device The desired joystick
|
|
||||||
/// \return False if something went wrong
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
bool RetriveElements(IOHIDDeviceRef device);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Release all resources
|
|
||||||
///
|
|
||||||
/// Close all connections to any devices, if required
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void FreeUp();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Close and release the manager
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void ReleaseManager();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Release all elements
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void ReleaseElements();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
typedef std::map<sf::Joy::Axis, IOHIDElementRef> AxisMap;
|
|
||||||
typedef std::vector<IOHIDElementRef> ButtonsVector;
|
|
||||||
|
|
||||||
AxisMap myAxis; ///< Axis (IOHIDElementRef) connected to the joystick.
|
|
||||||
ButtonsVector myButtons; ///< Buttons (IOHIDElementRef) connected to the joystick.
|
|
||||||
// Note : Both myAxis and myButton contains only reference from myElements.
|
|
||||||
// Thus no special cleanup is required on these two.
|
|
||||||
|
|
||||||
IOHIDManagerRef myManager; ///< HID Manager.
|
|
||||||
CFArrayRef myElements; ///< IOHIDElementRef connected to the joytick.
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace priv
|
|
||||||
|
|
||||||
} // namespace sf
|
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_JOYSTICKOSX_HPP
|
|
@ -39,6 +39,6 @@
|
|||||||
/// \brief Event processing
|
/// \brief Event processing
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
+(void)processEvent
|
+(void)processEvent;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -62,7 +62,7 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Try to convert a character into a SFML key code.
|
/// Try to convert a character into a SFML key code.
|
||||||
/// Return sf::Key::Count if it doesn't match any 'localized' keys.
|
/// Return sf::Keyboard::KeyCount if it doesn't match any 'localized' keys.
|
||||||
///
|
///
|
||||||
/// By 'localized' I mean keys that depend on the keyboard layout
|
/// By 'localized' I mean keys that depend on the keyboard layout
|
||||||
/// and might not be the same as the US keycode in some country
|
/// and might not be the same as the US keycode in some country
|
||||||
@ -70,14 +70,14 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||||||
/// US keyboard layouts.)
|
/// US keyboard layouts.)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::Key::Code LocalizedKeys(unichar ch);
|
sf::Keyboard::Key LocalizedKeys(unichar ch);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Try to convert a keycode into a SFML key code.
|
/// Try to convert a keycode into a SFML key code.
|
||||||
/// Return sf::Key::Count if the keycode is unknown.
|
/// Return sf::Keyboard::KeyCount if the keycode is unknown.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
sf::Keyboard::Key NonLocalizedKeys(unsigned short keycode);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// SFOpenGLView class : Privates Methods Declaration
|
/// SFOpenGLView class : Privates Methods Declaration
|
||||||
@ -119,7 +119,7 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
/// Convert a key down/up NSEvent into an SFML key event.
|
/// Convert a key down/up NSEvent into an SFML key event.
|
||||||
/// Based on LocalizedKeys and NonLocalizedKeys function.
|
/// Based on LocalizedKeys and NonLocalizedKeys function.
|
||||||
///
|
///
|
||||||
/// Return sf::Key::Count as Code if the key is unknown.
|
/// Return sf::Keyboard::KeyCount as Code if the key is unknown.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
+(sf::Event::KeyEvent)convertNSKeyEventToSFMLEvent:(NSEvent *)anEvent;
|
+(sf::Event::KeyEvent)convertNSKeyEventToSFMLEvent:(NSEvent *)anEvent;
|
||||||
@ -443,7 +443,7 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (myUseKeyRepeat || ![theEvent isARepeat]) {
|
if (myUseKeyRepeat || ![theEvent isARepeat]) {
|
||||||
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
|
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
|
||||||
|
|
||||||
if (key.Code != sf::Key::Count) { // The key is recognized.
|
if (key.Code != sf::Keyboard::KeyCount) { // The key is recognized.
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,7 +478,7 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
|
|
||||||
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
|
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
|
||||||
|
|
||||||
if (key.Code != sf::Key::Count) { // The key is recognized.
|
if (key.Code != sf::Keyboard::KeyCount) { // The key is recognized.
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -493,7 +493,7 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
|
|
||||||
// Setup a potential event key.
|
// Setup a potential event key.
|
||||||
sf::Event::KeyEvent key;
|
sf::Event::KeyEvent key;
|
||||||
key.Code = sf::Key::Count;
|
key.Code = sf::Keyboard::KeyCount;
|
||||||
key.Alt = modifiers & NSAlternateKeyMask;
|
key.Alt = modifiers & NSAlternateKeyMask;
|
||||||
key.Control = modifiers & NSControlKeyMask;
|
key.Control = modifiers & NSControlKeyMask;
|
||||||
key.Shift = modifiers & NSShiftKeyMask;
|
key.Shift = modifiers & NSShiftKeyMask;
|
||||||
@ -522,14 +522,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
// left shift released
|
// left shift released
|
||||||
leftShiftIsDown = NO;
|
leftShiftIsDown = NO;
|
||||||
|
|
||||||
key.Code = sf::Key::LShift;
|
key.Code = sf::Keyboard::LShift;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myRightShiftWasDown) {
|
if (!myRightShiftWasDown) {
|
||||||
// right shift pressed
|
// right shift pressed
|
||||||
|
|
||||||
key.Code = sf::Key::RShift;
|
key.Code = sf::Keyboard::RShift;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -543,14 +543,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
// right shift released
|
// right shift released
|
||||||
rightShiftIsDown = NO;
|
rightShiftIsDown = NO;
|
||||||
|
|
||||||
key.Code = sf::Key::RShift;
|
key.Code = sf::Keyboard::RShift;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myLeftShiftWasDown) {
|
if (!myLeftShiftWasDown) {
|
||||||
// left shift pressed
|
// left shift pressed
|
||||||
|
|
||||||
key.Code = sf::Key::LShift;
|
key.Code = sf::Keyboard::LShift;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,14 +564,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (!myRightShiftWasDown) {
|
if (!myRightShiftWasDown) {
|
||||||
// right shift pressed
|
// right shift pressed
|
||||||
|
|
||||||
key.Code = sf::Key::RShift;
|
key.Code = sf::Keyboard::RShift;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myLeftShiftWasDown) {
|
if (!myLeftShiftWasDown) {
|
||||||
// left shift pressed
|
// left shift pressed
|
||||||
|
|
||||||
key.Code = sf::Key::LShift;
|
key.Code = sf::Keyboard::LShift;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -583,14 +583,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (myRightShiftWasDown) {
|
if (myRightShiftWasDown) {
|
||||||
// right shift released
|
// right shift released
|
||||||
|
|
||||||
key.Code = sf::Key::RShift;
|
key.Code = sf::Keyboard::RShift;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myLeftShiftWasDown) {
|
if (myLeftShiftWasDown) {
|
||||||
// left shift released
|
// left shift released
|
||||||
|
|
||||||
key.Code = sf::Key::LShift;
|
key.Code = sf::Keyboard::LShift;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -609,14 +609,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
// left command released
|
// left command released
|
||||||
leftCommandIsDown = NO;
|
leftCommandIsDown = NO;
|
||||||
|
|
||||||
key.Code = sf::Key::LSystem;
|
key.Code = sf::Keyboard::LSystem;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myRightCommandWasDown) {
|
if (!myRightCommandWasDown) {
|
||||||
// right command pressed
|
// right command pressed
|
||||||
|
|
||||||
key.Code = sf::Key::RSystem;
|
key.Code = sf::Keyboard::RSystem;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -630,14 +630,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
// right command released
|
// right command released
|
||||||
rightCommandIsDown = NO;
|
rightCommandIsDown = NO;
|
||||||
|
|
||||||
key.Code = sf::Key::RSystem;
|
key.Code = sf::Keyboard::RSystem;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myLeftCommandWasDown) {
|
if (!myLeftCommandWasDown) {
|
||||||
// left command pressed
|
// left command pressed
|
||||||
|
|
||||||
key.Code = sf::Key::LSystem;
|
key.Code = sf::Keyboard::LSystem;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -651,14 +651,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (!myRightCommandWasDown) {
|
if (!myRightCommandWasDown) {
|
||||||
// right command pressed
|
// right command pressed
|
||||||
|
|
||||||
key.Code = sf::Key::RSystem;
|
key.Code = sf::Keyboard::RSystem;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myLeftCommandWasDown) {
|
if (!myLeftCommandWasDown) {
|
||||||
// left command pressed
|
// left command pressed
|
||||||
|
|
||||||
key.Code = sf::Key::LSystem;
|
key.Code = sf::Keyboard::LSystem;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -670,14 +670,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (myRightCommandWasDown) {
|
if (myRightCommandWasDown) {
|
||||||
// right command released
|
// right command released
|
||||||
|
|
||||||
key.Code = sf::Key::RSystem;
|
key.Code = sf::Keyboard::RSystem;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myLeftCommandWasDown) {
|
if (myLeftCommandWasDown) {
|
||||||
// left command released
|
// left command released
|
||||||
|
|
||||||
key.Code = sf::Key::LSystem;
|
key.Code = sf::Keyboard::LSystem;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -696,14 +696,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
// left alt released
|
// left alt released
|
||||||
leftAlternateIsDown = NO;
|
leftAlternateIsDown = NO;
|
||||||
|
|
||||||
key.Code = sf::Key::LAlt;
|
key.Code = sf::Keyboard::LAlt;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myRightAlternateWasDown) {
|
if (!myRightAlternateWasDown) {
|
||||||
// right alt pressed
|
// right alt pressed
|
||||||
|
|
||||||
key.Code = sf::Key::RAlt;
|
key.Code = sf::Keyboard::RAlt;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -717,14 +717,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
// right alt released
|
// right alt released
|
||||||
rightAlternateIsDown = NO;
|
rightAlternateIsDown = NO;
|
||||||
|
|
||||||
key.Code = sf::Key::RAlt;
|
key.Code = sf::Keyboard::RAlt;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myLeftAlternateWasDown) {
|
if (!myLeftAlternateWasDown) {
|
||||||
// left alt pressed
|
// left alt pressed
|
||||||
|
|
||||||
key.Code = sf::Key::LAlt;
|
key.Code = sf::Keyboard::LAlt;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -738,14 +738,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (!myRightAlternateWasDown) {
|
if (!myRightAlternateWasDown) {
|
||||||
// right alt pressed
|
// right alt pressed
|
||||||
|
|
||||||
key.Code = sf::Key::RAlt;
|
key.Code = sf::Keyboard::RAlt;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!myLeftAlternateWasDown) {
|
if (!myLeftAlternateWasDown) {
|
||||||
// left alt pressed
|
// left alt pressed
|
||||||
|
|
||||||
key.Code = sf::Key::LAlt;
|
key.Code = sf::Keyboard::LAlt;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -757,14 +757,14 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (myRightAlternateWasDown) {
|
if (myRightAlternateWasDown) {
|
||||||
// right alt released
|
// right alt released
|
||||||
|
|
||||||
key.Code = sf::Key::RAlt;
|
key.Code = sf::Keyboard::RAlt;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myLeftAlternateWasDown) {
|
if (myLeftAlternateWasDown) {
|
||||||
// left alt released
|
// left alt released
|
||||||
|
|
||||||
key.Code = sf::Key::LAlt;
|
key.Code = sf::Keyboard::LAlt;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -778,7 +778,7 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (!myControlWasDown) {
|
if (!myControlWasDown) {
|
||||||
// ctrl pressed
|
// ctrl pressed
|
||||||
|
|
||||||
key.Code = sf::Key::LControl;
|
key.Code = sf::Keyboard::LControl;
|
||||||
myRequester->KeyDown(key);
|
myRequester->KeyDown(key);
|
||||||
}
|
}
|
||||||
} else { // No control key down.
|
} else { // No control key down.
|
||||||
@ -787,7 +787,7 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
if (myControlWasDown) {
|
if (myControlWasDown) {
|
||||||
// ctrl released
|
// ctrl released
|
||||||
|
|
||||||
key.Code = sf::Key::LControl;
|
key.Code = sf::Keyboard::LControl;
|
||||||
myRequester->KeyUp(key);
|
myRequester->KeyUp(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -949,7 +949,7 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
key.System = modifierFlags & NSCommandKeyMask;
|
key.System = modifierFlags & NSCommandKeyMask;
|
||||||
|
|
||||||
// Key code.
|
// Key code.
|
||||||
key.Code = sf::Key::Count;
|
key.Code = sf::Keyboard::KeyCount;
|
||||||
// First we look if the key down is from a list of caracter that depend on keyboard localization.
|
// First we look if the key down is from a list of caracter that depend on keyboard localization.
|
||||||
NSString* string = [anEvent charactersIgnoringModifiers];
|
NSString* string = [anEvent charactersIgnoringModifiers];
|
||||||
if ([string length] > 0) {
|
if ([string length] > 0) {
|
||||||
@ -957,12 +957,12 @@ sf::Key::Code NonLocalizedKeys(unsigned short keycode);
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The key is not a localized one, the other keys.
|
// The key is not a localized one, the other keys.
|
||||||
if (key.Code == sf::Key::Count) {
|
if (key.Code == sf::Keyboard::KeyCount) {
|
||||||
key.Code = NonLocalizedKeys([anEvent keyCode]);
|
key.Code = NonLocalizedKeys([anEvent keyCode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SFML_DEBUG // We don't want to bother the final customer with anoying messages.
|
#ifdef SFML_DEBUG // We don't want to bother the final customer with annoying messages.
|
||||||
if (key.Code == sf::Key::Count) { // The key is unknown.
|
if (key.Code == sf::Keyboard::KeyCount) { // The key is unknown.
|
||||||
sf::Err()
|
sf::Err()
|
||||||
<< "This is an unknow key. Should not happen (?). Keycode is 0x"
|
<< "This is an unknow key. Should not happen (?). Keycode is 0x"
|
||||||
<< std::hex
|
<< std::hex
|
||||||
@ -997,255 +997,255 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask)
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
sf::Key::Code LocalizedKeys(unichar ch)
|
sf::Keyboard::Key LocalizedKeys(unichar ch)
|
||||||
{
|
{
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A': return sf::Key::A;
|
case 'A': return sf::Keyboard::A;
|
||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'B': return sf::Key::B;
|
case 'B': return sf::Keyboard::B;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'C': return sf::Key::C;
|
case 'C': return sf::Keyboard::C;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'D': return sf::Key::D;
|
case 'D': return sf::Keyboard::D;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E': return sf::Key::E;
|
case 'E': return sf::Keyboard::E;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
case 'F': return sf::Key::F;
|
case 'F': return sf::Keyboard::F;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G': return sf::Key::G;
|
case 'G': return sf::Keyboard::G;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'H': return sf::Key::H;
|
case 'H': return sf::Keyboard::H;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'I': return sf::Key::I;
|
case 'I': return sf::Keyboard::I;
|
||||||
|
|
||||||
case 'j':
|
case 'j':
|
||||||
case 'J': return sf::Key::J;
|
case 'J': return sf::Keyboard::J;
|
||||||
|
|
||||||
case 'k':
|
case 'k':
|
||||||
case 'K': return sf::Key::K;
|
case 'K': return sf::Keyboard::K;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'L': return sf::Key::L;
|
case 'L': return sf::Keyboard::L;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
case 'M': return sf::Key::M;
|
case 'M': return sf::Keyboard::M;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
case 'N': return sf::Key::N;
|
case 'N': return sf::Keyboard::N;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
case 'O': return sf::Key::O;
|
case 'O': return sf::Keyboard::O;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'P': return sf::Key::P;
|
case 'P': return sf::Keyboard::P;
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
case 'Q': return sf::Key::Q;
|
case 'Q': return sf::Keyboard::Q;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'R': return sf::Key::R;
|
case 'R': return sf::Keyboard::R;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
case 'S': return sf::Key::S;
|
case 'S': return sf::Keyboard::S;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
case 'T': return sf::Key::T;
|
case 'T': return sf::Keyboard::T;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
case 'U': return sf::Key::U;
|
case 'U': return sf::Keyboard::U;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
case 'V': return sf::Key::V;
|
case 'V': return sf::Keyboard::V;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
case 'W': return sf::Key::W;
|
case 'W': return sf::Keyboard::W;
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'X': return sf::Key::X;
|
case 'X': return sf::Keyboard::X;
|
||||||
|
|
||||||
case 'y':
|
case 'y':
|
||||||
case 'Y': return sf::Key::Y;
|
case 'Y': return sf::Keyboard::Y;
|
||||||
|
|
||||||
case 'z':
|
case 'z':
|
||||||
case 'Z': return sf::Key::Z;
|
case 'Z': return sf::Keyboard::Z;
|
||||||
|
|
||||||
// The kew is not 'localized'.
|
// The kew is not 'localized'.
|
||||||
default: return sf::Key::Count;
|
default: return sf::Keyboard::KeyCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
sf::Key::Code NonLocalizedKeys(unsigned short keycode)
|
sf::Keyboard::Key NonLocalizedKeys(unsigned short keycode)
|
||||||
{
|
{
|
||||||
// (Some) 0x code based on http://forums.macrumors.com/showthread.php?t=780577
|
// (Some) 0x code based on http://forums.macrumors.com/showthread.php?t=780577
|
||||||
// Some sf::Key are present twice.
|
// Some sf::Keyboard::Key are present twice.
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
// These cases should not be used but anyway...
|
// These cases should not be used but anyway...
|
||||||
case 0x00: return sf::Key::A;
|
case 0x00: return sf::Keyboard::A;
|
||||||
case 0x0b: return sf::Key::B;
|
case 0x0b: return sf::Keyboard::B;
|
||||||
case 0x08: return sf::Key::C;
|
case 0x08: return sf::Keyboard::C;
|
||||||
case 0x02: return sf::Key::D;
|
case 0x02: return sf::Keyboard::D;
|
||||||
case 0x0e: return sf::Key::E;
|
case 0x0e: return sf::Keyboard::E;
|
||||||
case 0x03: return sf::Key::F;
|
case 0x03: return sf::Keyboard::F;
|
||||||
case 0x05: return sf::Key::G;
|
case 0x05: return sf::Keyboard::G;
|
||||||
case 0x04: return sf::Key::H;
|
case 0x04: return sf::Keyboard::H;
|
||||||
case 0x22: return sf::Key::I;
|
case 0x22: return sf::Keyboard::I;
|
||||||
case 0x26: return sf::Key::J;
|
case 0x26: return sf::Keyboard::J;
|
||||||
case 0x28: return sf::Key::K;
|
case 0x28: return sf::Keyboard::K;
|
||||||
case 0x25: return sf::Key::L;
|
case 0x25: return sf::Keyboard::L;
|
||||||
case 0x2e: return sf::Key::M;
|
case 0x2e: return sf::Keyboard::M;
|
||||||
case 0x2d: return sf::Key::N;
|
case 0x2d: return sf::Keyboard::N;
|
||||||
case 0x1f: return sf::Key::O;
|
case 0x1f: return sf::Keyboard::O;
|
||||||
case 0x23: return sf::Key::P;
|
case 0x23: return sf::Keyboard::P;
|
||||||
case 0x0c: return sf::Key::Q;
|
case 0x0c: return sf::Keyboard::Q;
|
||||||
case 0x0f: return sf::Key::R;
|
case 0x0f: return sf::Keyboard::R;
|
||||||
case 0x01: return sf::Key::S;
|
case 0x01: return sf::Keyboard::S;
|
||||||
case 0x11: return sf::Key::T;
|
case 0x11: return sf::Keyboard::T;
|
||||||
case 0x20: return sf::Key::U;
|
case 0x20: return sf::Keyboard::U;
|
||||||
case 0x09: return sf::Key::V;
|
case 0x09: return sf::Keyboard::V;
|
||||||
case 0x0d: return sf::Key::W;
|
case 0x0d: return sf::Keyboard::W;
|
||||||
case 0x07: return sf::Key::X;
|
case 0x07: return sf::Keyboard::X;
|
||||||
case 0x10: return sf::Key::Y;
|
case 0x10: return sf::Keyboard::Y;
|
||||||
case 0x06: return sf::Key::Z;
|
case 0x06: return sf::Keyboard::Z;
|
||||||
|
|
||||||
// These cases should not be used but anyway...
|
// These cases should not be used but anyway...
|
||||||
case 0x1d: return sf::Key::Num0;
|
case 0x1d: return sf::Keyboard::Num0;
|
||||||
case 0x12: return sf::Key::Num1;
|
case 0x12: return sf::Keyboard::Num1;
|
||||||
case 0x13: return sf::Key::Num2;
|
case 0x13: return sf::Keyboard::Num2;
|
||||||
case 0x14: return sf::Key::Num3;
|
case 0x14: return sf::Keyboard::Num3;
|
||||||
case 0x15: return sf::Key::Num4;
|
case 0x15: return sf::Keyboard::Num4;
|
||||||
case 0x17: return sf::Key::Num5;
|
case 0x17: return sf::Keyboard::Num5;
|
||||||
case 0x16: return sf::Key::Num6;
|
case 0x16: return sf::Keyboard::Num6;
|
||||||
case 0x1a: return sf::Key::Num7;
|
case 0x1a: return sf::Keyboard::Num7;
|
||||||
case 0x1c: return sf::Key::Num8;
|
case 0x1c: return sf::Keyboard::Num8;
|
||||||
case 0x19: return sf::Key::Num9;
|
case 0x19: return sf::Keyboard::Num9;
|
||||||
|
|
||||||
case 0x35: return sf::Key::Escape;
|
case 0x35: return sf::Keyboard::Escape;
|
||||||
|
|
||||||
// Modifier keys : never happen with keyDown/keyUp methods (?)
|
// Modifier keys : never happen with keyDown/keyUp methods (?)
|
||||||
case 0x3b: return sf::Key::LControl;
|
case 0x3b: return sf::Keyboard::LControl;
|
||||||
case 0x38: return sf::Key::LShift;
|
case 0x38: return sf::Keyboard::LShift;
|
||||||
case 0x3a: return sf::Key::LAlt;
|
case 0x3a: return sf::Keyboard::LAlt;
|
||||||
case 0x37: return sf::Key::LSystem;
|
case 0x37: return sf::Keyboard::LSystem;
|
||||||
case 0x3e: return sf::Key::RControl;
|
case 0x3e: return sf::Keyboard::RControl;
|
||||||
case 0x3c: return sf::Key::RShift;
|
case 0x3c: return sf::Keyboard::RShift;
|
||||||
case 0x3d: return sf::Key::RAlt;
|
case 0x3d: return sf::Keyboard::RAlt;
|
||||||
case 0x36: return sf::Key::RSystem;
|
case 0x36: return sf::Keyboard::RSystem;
|
||||||
|
|
||||||
case NSMenuFunctionKey: return sf::Key::Menu;
|
case NSMenuFunctionKey: return sf::Keyboard::Menu;
|
||||||
|
|
||||||
case 0x21: return sf::Key::LBracket;
|
case 0x21: return sf::Keyboard::LBracket;
|
||||||
case 0x1e: return sf::Key::RBracket;
|
case 0x1e: return sf::Keyboard::RBracket;
|
||||||
case 0x29: return sf::Key::SemiColon;
|
case 0x29: return sf::Keyboard::SemiColon;
|
||||||
case 0x2b: return sf::Key::Comma;
|
case 0x2b: return sf::Keyboard::Comma;
|
||||||
case 0x2f: return sf::Key::Period;
|
case 0x2f: return sf::Keyboard::Period;
|
||||||
case 0x27: return sf::Key::Quote;
|
case 0x27: return sf::Keyboard::Quote;
|
||||||
case 0x2c: return sf::Key::Slash;
|
case 0x2c: return sf::Keyboard::Slash;
|
||||||
case 0x2a: return sf::Key::BackSlash;
|
case 0x2a: return sf::Keyboard::BackSlash;
|
||||||
|
|
||||||
#warning sf::Key::Tilde might be in conflict with some other key.
|
#warning sf::Keyboard::Tilde might be in conflict with some other key.
|
||||||
// 0x0a is for "Non-US Backslash" according to HID Calibrator,
|
// 0x0a is for "Non-US Backslash" according to HID Calibrator,
|
||||||
// a sample provided by Apple.
|
// a sample provided by Apple.
|
||||||
case 0x0a: return sf::Key::Tilde;
|
case 0x0a: return sf::Keyboard::Tilde;
|
||||||
|
|
||||||
case 0x18: return sf::Key::Equal;
|
case 0x18: return sf::Keyboard::Equal;
|
||||||
case 0x32: return sf::Key::Dash;
|
case 0x32: return sf::Keyboard::Dash;
|
||||||
case 0x31: return sf::Key::Space;
|
case 0x31: return sf::Keyboard::Space;
|
||||||
case 0x24: return sf::Key::Return;
|
case 0x24: return sf::Keyboard::Return;
|
||||||
case 0x33: return sf::Key::Back;
|
case 0x33: return sf::Keyboard::Back;
|
||||||
case 0x30: return sf::Key::Tab;
|
case 0x30: return sf::Keyboard::Tab;
|
||||||
|
|
||||||
// Duplicates (see next §).
|
// Duplicates (see next §).
|
||||||
case 0x74: return sf::Key::PageUp;
|
case 0x74: return sf::Keyboard::PageUp;
|
||||||
case 0x79: return sf::Key::PageDown;
|
case 0x79: return sf::Keyboard::PageDown;
|
||||||
case 0x77: return sf::Key::End;
|
case 0x77: return sf::Keyboard::End;
|
||||||
case 0x73: return sf::Key::Home;
|
case 0x73: return sf::Keyboard::Home;
|
||||||
|
|
||||||
case NSPageUpFunctionKey: return sf::Key::PageUp;
|
case NSPageUpFunctionKey: return sf::Keyboard::PageUp;
|
||||||
case NSPageDownFunctionKey: return sf::Key::PageDown;
|
case NSPageDownFunctionKey: return sf::Keyboard::PageDown;
|
||||||
case NSEndFunctionKey: return sf::Key::End;
|
case NSEndFunctionKey: return sf::Keyboard::End;
|
||||||
case NSHomeFunctionKey: return sf::Key::Home;
|
case NSHomeFunctionKey: return sf::Keyboard::Home;
|
||||||
|
|
||||||
case NSInsertFunctionKey: return sf::Key::Insert;
|
case NSInsertFunctionKey: return sf::Keyboard::Insert;
|
||||||
case NSDeleteFunctionKey: return sf::Key::Delete;
|
case NSDeleteFunctionKey: return sf::Keyboard::Delete;
|
||||||
|
|
||||||
case 0x45: return sf::Key::Add;
|
case 0x45: return sf::Keyboard::Add;
|
||||||
case 0x4e: return sf::Key::Subtract;
|
case 0x4e: return sf::Keyboard::Subtract;
|
||||||
case 0x43: return sf::Key::Multiply;
|
case 0x43: return sf::Keyboard::Multiply;
|
||||||
case 0x4b: return sf::Key::Divide;
|
case 0x4b: return sf::Keyboard::Divide;
|
||||||
|
|
||||||
// Duplicates (see next §).
|
// Duplicates (see next §).
|
||||||
case 0x7b: return sf::Key::Left;
|
case 0x7b: return sf::Keyboard::Left;
|
||||||
case 0x7c: return sf::Key::Right;
|
case 0x7c: return sf::Keyboard::Right;
|
||||||
case 0x7e: return sf::Key::Up;
|
case 0x7e: return sf::Keyboard::Up;
|
||||||
case 0x7d: return sf::Key::Down;
|
case 0x7d: return sf::Keyboard::Down;
|
||||||
|
|
||||||
case NSLeftArrowFunctionKey: return sf::Key::Left;
|
case NSLeftArrowFunctionKey: return sf::Keyboard::Left;
|
||||||
case NSRightArrowFunctionKey: return sf::Key::Right;
|
case NSRightArrowFunctionKey: return sf::Keyboard::Right;
|
||||||
case NSUpArrowFunctionKey: return sf::Key::Up;
|
case NSUpArrowFunctionKey: return sf::Keyboard::Up;
|
||||||
case NSDownArrowFunctionKey: return sf::Key::Down;
|
case NSDownArrowFunctionKey: return sf::Keyboard::Down;
|
||||||
|
|
||||||
case 0x52: return sf::Key::Numpad0;
|
case 0x52: return sf::Keyboard::Numpad0;
|
||||||
case 0x53: return sf::Key::Numpad1;
|
case 0x53: return sf::Keyboard::Numpad1;
|
||||||
case 0x54: return sf::Key::Numpad2;
|
case 0x54: return sf::Keyboard::Numpad2;
|
||||||
case 0x55: return sf::Key::Numpad3;
|
case 0x55: return sf::Keyboard::Numpad3;
|
||||||
case 0x56: return sf::Key::Numpad4;
|
case 0x56: return sf::Keyboard::Numpad4;
|
||||||
case 0x57: return sf::Key::Numpad5;
|
case 0x57: return sf::Keyboard::Numpad5;
|
||||||
case 0x58: return sf::Key::Numpad6;
|
case 0x58: return sf::Keyboard::Numpad6;
|
||||||
case 0x59: return sf::Key::Numpad7;
|
case 0x59: return sf::Keyboard::Numpad7;
|
||||||
case 0x5b: return sf::Key::Numpad8;
|
case 0x5b: return sf::Keyboard::Numpad8;
|
||||||
case 0x5c: return sf::Key::Numpad9;
|
case 0x5c: return sf::Keyboard::Numpad9;
|
||||||
|
|
||||||
// Duplicates (see next §).
|
// Duplicates (see next §).
|
||||||
case 0x7a: return sf::Key::F1;
|
case 0x7a: return sf::Keyboard::F1;
|
||||||
case 0x78: return sf::Key::F2;
|
case 0x78: return sf::Keyboard::F2;
|
||||||
case 0x63: return sf::Key::F3;
|
case 0x63: return sf::Keyboard::F3;
|
||||||
case 0x76: return sf::Key::F4;
|
case 0x76: return sf::Keyboard::F4;
|
||||||
case 0x60: return sf::Key::F5;
|
case 0x60: return sf::Keyboard::F5;
|
||||||
case 0x61: return sf::Key::F6;
|
case 0x61: return sf::Keyboard::F6;
|
||||||
case 0x62: return sf::Key::F7;
|
case 0x62: return sf::Keyboard::F7;
|
||||||
case 0x64: return sf::Key::F8;
|
case 0x64: return sf::Keyboard::F8;
|
||||||
case 0x65: return sf::Key::F9;
|
case 0x65: return sf::Keyboard::F9;
|
||||||
case 0x6d: return sf::Key::F10;
|
case 0x6d: return sf::Keyboard::F10;
|
||||||
case 0x67: return sf::Key::F11;
|
case 0x67: return sf::Keyboard::F11;
|
||||||
case 0x6f: return sf::Key::F12;
|
case 0x6f: return sf::Keyboard::F12;
|
||||||
case 0x69: return sf::Key::F13;
|
case 0x69: return sf::Keyboard::F13;
|
||||||
case 0x6b: return sf::Key::F14;
|
case 0x6b: return sf::Keyboard::F14;
|
||||||
case 0x71: return sf::Key::F15;
|
case 0x71: return sf::Keyboard::F15;
|
||||||
|
|
||||||
case NSF1FunctionKey: return sf::Key::F1;
|
case NSF1FunctionKey: return sf::Keyboard::F1;
|
||||||
case NSF2FunctionKey: return sf::Key::F2;
|
case NSF2FunctionKey: return sf::Keyboard::F2;
|
||||||
case NSF3FunctionKey: return sf::Key::F3;
|
case NSF3FunctionKey: return sf::Keyboard::F3;
|
||||||
case NSF4FunctionKey: return sf::Key::F4;
|
case NSF4FunctionKey: return sf::Keyboard::F4;
|
||||||
case NSF5FunctionKey: return sf::Key::F5;
|
case NSF5FunctionKey: return sf::Keyboard::F5;
|
||||||
case NSF6FunctionKey: return sf::Key::F6;
|
case NSF6FunctionKey: return sf::Keyboard::F6;
|
||||||
case NSF7FunctionKey: return sf::Key::F7;
|
case NSF7FunctionKey: return sf::Keyboard::F7;
|
||||||
case NSF8FunctionKey: return sf::Key::F8;
|
case NSF8FunctionKey: return sf::Keyboard::F8;
|
||||||
case NSF9FunctionKey: return sf::Key::F9;
|
case NSF9FunctionKey: return sf::Keyboard::F9;
|
||||||
case NSF10FunctionKey: return sf::Key::F10;
|
case NSF10FunctionKey: return sf::Keyboard::F10;
|
||||||
case NSF11FunctionKey: return sf::Key::F11;
|
case NSF11FunctionKey: return sf::Keyboard::F11;
|
||||||
case NSF12FunctionKey: return sf::Key::F12;
|
case NSF12FunctionKey: return sf::Keyboard::F12;
|
||||||
case NSF13FunctionKey: return sf::Key::F13;
|
case NSF13FunctionKey: return sf::Keyboard::F13;
|
||||||
case NSF14FunctionKey: return sf::Key::F14;
|
case NSF14FunctionKey: return sf::Keyboard::F14;
|
||||||
case NSF15FunctionKey: return sf::Key::F15;
|
case NSF15FunctionKey: return sf::Keyboard::F15;
|
||||||
|
|
||||||
case NSPauseFunctionKey: return sf::Key::Pause;
|
case NSPauseFunctionKey: return sf::Keyboard::Pause;
|
||||||
|
|
||||||
#warning keycode 0x1b is not bound to any key.
|
#warning keycode 0x1b is not bound to any key.
|
||||||
// This key is ' on CH-FR, ) on FR and - on US layouts.
|
// This key is ' on CH-FR, ) on FR and - on US layouts.
|
||||||
|
|
||||||
// An unknown key.
|
// An unknown key.
|
||||||
default: return sf::Key::Count;
|
default: return sf::Keyboard::KeyCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)processEventWithBlockingMode:(BOOL)block
|
-(void)processEvent
|
||||||
{
|
{
|
||||||
sf::Err() << "Cannot process event from the view." << std::endl;
|
sf::Err() << "Cannot process event from the view." << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ namespace sf {
|
|||||||
/// Fetch new event
|
/// Fetch new event
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
-(void)processEventWithBlockingMode:(BOOL)block;
|
-(void)processEvent;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Apply a given context to an OpenGL view.
|
/// Apply a given context to an OpenGL view.
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <SFML/Window/WindowImpl.hpp>
|
#include <SFML/Window/WindowImpl.hpp>
|
||||||
#include <SFML/Window/Event.hpp>
|
#include <SFML/Window/Event.hpp>
|
||||||
#include <SFML/Window/JoystickManager.hpp>
|
#include <SFML/Window/JoystickManager.hpp>
|
||||||
|
#include <SFML/System/Sleep.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@ -43,8 +44,8 @@
|
|||||||
|
|
||||||
#elif defined(SFML_SYSTEM_MACOS)
|
#elif defined(SFML_SYSTEM_MACOS)
|
||||||
|
|
||||||
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
|
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
|
||||||
typedef sf::priv::WindowImplCocoa WindowImplType;
|
typedef sf::priv::WindowImplCocoa WindowImplType;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user