mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Remove trailing spaces
This commit is contained in:
parent
c0f3587a7c
commit
2b8f20c89f
@ -42,15 +42,15 @@ struct SFMLmainWindow
|
||||
if (!logo.loadFromFile(resPath + "/logo.png")) {
|
||||
NSLog(@"Couldn't load the logo image");
|
||||
}
|
||||
|
||||
|
||||
logo.setSmooth(true);
|
||||
|
||||
|
||||
sprite.setTexture(logo, true);
|
||||
sf::FloatRect rect = sprite.getLocalBounds();
|
||||
sf::Vector2f size(rect.width, rect.height);
|
||||
sprite.setOrigin(size / 2.f);
|
||||
sprite.scale(0.3, 0.3);
|
||||
|
||||
|
||||
unsigned int ww = renderWindow.getSize().x;
|
||||
unsigned int wh = renderWindow.getSize().y;
|
||||
sprite.setPosition(sf::Vector2f(ww, wh) / 2.f);
|
||||
@ -58,11 +58,11 @@ struct SFMLmainWindow
|
||||
if (!font.loadFromFile(resPath + "/sansation.ttf")) {
|
||||
NSLog(@"Couldn't load the font");
|
||||
}
|
||||
|
||||
|
||||
text.setColor(sf::Color::White);
|
||||
text.setFont(font);
|
||||
}
|
||||
|
||||
|
||||
sf::RenderWindow renderWindow;
|
||||
sf::Font font;
|
||||
sf::Text text;
|
||||
@ -114,12 +114,12 @@ struct SFMLmainWindow
|
||||
self.mainWindow = new SFMLmainWindow(self.sfmlView);
|
||||
self.mainWindow->text.setString([self.textField.stringValue tostdwstring]);
|
||||
self.visible = YES;
|
||||
|
||||
|
||||
// Launch the timer to periodically display our stuff into the Cocoa view.
|
||||
self.renderTimer = [NSTimer timerWithTimeInterval:1.f/60.f
|
||||
target:self
|
||||
selector:@selector(renderMainWindow:)
|
||||
userInfo:nil
|
||||
userInfo:nil
|
||||
repeats:YES];
|
||||
[[NSRunLoop mainRunLoop] addTimer:self.renderTimer
|
||||
forMode:NSDefaultRunLoopMode];
|
||||
@ -133,7 +133,7 @@ struct SFMLmainWindow
|
||||
* while the second mode allows timer firing while he is using a slider
|
||||
* or a menu.
|
||||
*/
|
||||
|
||||
|
||||
self.initialized = YES;
|
||||
}
|
||||
}
|
||||
@ -142,15 +142,15 @@ struct SFMLmainWindow
|
||||
{
|
||||
[self.renderTimer invalidate];
|
||||
self.mainWindow->renderWindow.close();
|
||||
|
||||
|
||||
self.window = nil;
|
||||
self.sfmlView = nil;
|
||||
self.textField = nil;
|
||||
|
||||
|
||||
delete (SFMLmainWindow *) self.mainWindow;
|
||||
self.mainWindow = 0;
|
||||
self.renderTimer = nil;
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@ -166,18 +166,18 @@ struct SFMLmainWindow
|
||||
{
|
||||
self.mainWindow->sprite.scale(0.99f, 0.99f);
|
||||
}
|
||||
|
||||
|
||||
// Clear the window, display some stuff and display it into our view.
|
||||
|
||||
|
||||
self.mainWindow->renderWindow.clear(self.mainWindow->background);
|
||||
|
||||
|
||||
if (self.visible)
|
||||
{
|
||||
self.mainWindow->renderWindow.draw(self.mainWindow->sprite);
|
||||
}
|
||||
|
||||
|
||||
self.mainWindow->renderWindow.draw(self.mainWindow->text);
|
||||
|
||||
|
||||
self.mainWindow->renderWindow.display();
|
||||
}
|
||||
|
||||
@ -190,11 +190,11 @@ struct SFMLmainWindow
|
||||
if ([color isEqualToString:BLUE])
|
||||
{
|
||||
self.mainWindow->background = sf::Color::Blue;
|
||||
}
|
||||
}
|
||||
else if ([color isEqualToString:GREEN])
|
||||
{
|
||||
self.mainWindow->background = sf::Color::Green;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.mainWindow->background = sf::Color::Red;
|
||||
|
@ -32,10 +32,10 @@
|
||||
{
|
||||
std::string utf8;
|
||||
utf8.reserve(string.size() + 1);
|
||||
|
||||
|
||||
sf::Utf8::fromAnsi(string.begin(), string.end(), std::back_inserter(utf8));
|
||||
|
||||
NSString *str = [NSString stringWithCString:utf8.c_str()
|
||||
|
||||
NSString *str = [NSString stringWithCString:utf8.c_str()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
return str;
|
||||
}
|
||||
@ -45,7 +45,7 @@
|
||||
// Not sure about the encoding to use. Using [self UTF8String] doesn't
|
||||
// work for characters like é or à.
|
||||
const char *cstr = [self cStringUsingEncoding:NSISOLatin1StringEncoding];
|
||||
|
||||
|
||||
if (cstr != NULL)
|
||||
{
|
||||
std::string str(cstr);
|
||||
@ -61,7 +61,7 @@
|
||||
{
|
||||
char* data = (char *)string.data();
|
||||
unsigned size = string.size() * sizeof(wchar_t);
|
||||
|
||||
|
||||
NSString *str = [[[NSString alloc] initWithBytes:data length:size
|
||||
encoding:NSUTF32LittleEndianStringEncoding] autorelease];
|
||||
return str;
|
||||
@ -75,4 +75,4 @@
|
||||
return std::wstring((wchar_t *)[asData bytes], [asData length] / sizeof(wchar_t));
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -29,7 +29,7 @@
|
||||
/// Increment a retain count.
|
||||
/// See SPECIAL CONSIDERATION in implementation file.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
void retainPool(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -38,7 +38,7 @@ void retainPool(void);
|
||||
/// Drain the pool if it is no more needed (retain count is zero).
|
||||
/// See SPECIAL CONSIDERATION in implementation file.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
void releasePool(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -46,6 +46,6 @@ void releasePool(void);
|
||||
///
|
||||
/// releasePool must be called at least once before drainPool.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
void drainPool();
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Here we manage one and only one pool by thread. This prevents draining one
|
||||
/// Here we manage one and only one pool by thread. This prevents draining one
|
||||
/// pool and making other pools invalid which can lead to a crash on 10.5 and an
|
||||
/// annoying message on 10.6 (*** attempt to pop an unknown autorelease pool).
|
||||
///
|
||||
@ -59,39 +59,39 @@ namespace priv
|
||||
////////////////////////////////////////////////////////////
|
||||
class PoolWrapper : NonCopyable {
|
||||
public :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
PoolWrapper();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~PoolWrapper();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Increment retain count and allocate memory if needed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void retain();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decrement retain count and releasing memory if needed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void release();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Drain the pool
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Drain();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -103,7 +103,7 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
PoolWrapper::PoolWrapper()
|
||||
: m_count(0)
|
||||
, m_pool(0)
|
||||
, m_pool(0)
|
||||
{
|
||||
/* Nothing else */
|
||||
}
|
||||
@ -133,12 +133,12 @@ void PoolWrapper::retain()
|
||||
{
|
||||
// Increase counter.
|
||||
++m_count;
|
||||
|
||||
|
||||
// Allocate pool if required.
|
||||
if (m_pool == 0) {
|
||||
m_pool = [[NSAutoreleasePool alloc] init];
|
||||
}
|
||||
|
||||
|
||||
#ifdef SFML_DEBUG
|
||||
if (m_count <= 0) {
|
||||
sf::err() << "PoolWrapper::retain : m_count <= 0! " << std::endl;
|
||||
@ -152,12 +152,12 @@ void PoolWrapper::release()
|
||||
{
|
||||
// Decrease counter.
|
||||
--m_count;
|
||||
|
||||
|
||||
// Drain pool if required.
|
||||
if (m_count == 0) {
|
||||
Drain();
|
||||
}
|
||||
|
||||
|
||||
#ifdef SFML_DEBUG
|
||||
if (m_count < 0) {
|
||||
sf::err() << "PoolWrapper::release : m_count < 0! " << std::endl;
|
||||
@ -169,15 +169,15 @@ void PoolWrapper::Drain()
|
||||
{
|
||||
[m_pool drain];
|
||||
m_pool = 0;
|
||||
|
||||
|
||||
if (m_count != 0) {
|
||||
m_pool = [[NSAutoreleasePool alloc] init];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -197,7 +197,7 @@ void retainPool(void)
|
||||
if (localPool == NULL) {
|
||||
localPool = new sf::priv::PoolWrapper();
|
||||
}
|
||||
|
||||
|
||||
// Then retains!
|
||||
localPool->retain();
|
||||
}
|
||||
@ -213,10 +213,10 @@ void releasePool(void)
|
||||
<< std::endl;
|
||||
} else {
|
||||
#endif
|
||||
|
||||
|
||||
// Releases, that's all.
|
||||
localPool->release();
|
||||
|
||||
|
||||
#ifdef SFML_DEBUG
|
||||
}
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -51,7 +51,7 @@ namespace priv
|
||||
class HIDInputManager : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the unique instance of the class
|
||||
///
|
||||
@ -61,7 +61,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static HIDInputManager& getInstance();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a key is pressed
|
||||
///
|
||||
@ -71,7 +71,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isKeyPressed(Keyboard::Key key);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a mouse button is pressed
|
||||
///
|
||||
@ -83,7 +83,7 @@ public :
|
||||
bool isMouseButtonPressed(Mouse::Button button);
|
||||
|
||||
public :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the usb location ID of a given device
|
||||
///
|
||||
@ -94,7 +94,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static long getLocationID(IOHIDDeviceRef device);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a mask (dictionary) for an IOHIDManager
|
||||
///
|
||||
@ -104,7 +104,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static CFDictionaryRef copyDevicesMask(UInt32 page, UInt32 usage);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Try to convert a character into a SFML key code.
|
||||
///
|
||||
@ -117,7 +117,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Key localizedKeys(UniChar ch);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Try to convert a virtual keycode into a SFML key code.
|
||||
///
|
||||
@ -133,13 +133,13 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
HIDInputManager();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~HIDInputManager();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Initialize the keyboard part of this class
|
||||
///
|
||||
@ -147,7 +147,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void initializeKeyboard();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Initialize the mouse part of this class
|
||||
///
|
||||
@ -155,7 +155,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void initializeMouse();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the given keyboard into m_keys
|
||||
///
|
||||
@ -166,7 +166,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void loadKeyboard(IOHIDDeviceRef keyboard);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the given mouse into m_buttons
|
||||
///
|
||||
@ -177,7 +177,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void loadMouse(IOHIDDeviceRef mouse);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the given key into m_keys
|
||||
///
|
||||
@ -187,7 +187,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void loadKey(IOHIDElementRef key);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the given button into m_buttons
|
||||
///
|
||||
@ -197,7 +197,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void loadButton(IOHIDElementRef button);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Release all resources
|
||||
///
|
||||
@ -206,7 +206,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void freeUp();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Filter the devices and return them.
|
||||
///
|
||||
@ -218,7 +218,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CFSetRef copyDevices(UInt32 page, UInt32 usage);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a HID key usage to its corresponding virtual code
|
||||
///
|
||||
@ -232,7 +232,7 @@ private :
|
||||
static UInt8 usageToVirtualCode(UInt32 usage);
|
||||
|
||||
private :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -240,11 +240,11 @@ private :
|
||||
CFDataRef m_layoutData; ///< CFData containing the layout
|
||||
UCKeyboardLayout* m_layout; ///< Current Keyboard Layout
|
||||
IOHIDManagerRef m_manager; ///< HID Manager
|
||||
|
||||
|
||||
typedef std::vector<IOHIDElementRef> IOHIDElements;
|
||||
IOHIDElements m_keys[Keyboard::KeyCount]; ///< All the keys on any connected keyboard
|
||||
IOHIDElements m_buttons[Mouse::ButtonCount];///< All the buttons on any connected mouse
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// m_keys' index corresponds to sf::Keyboard::Key enum.
|
||||
/// if no key is assigned with key XYZ then m_keys[XYZ].size() == 0.
|
||||
@ -258,7 +258,7 @@ private :
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -49,38 +49,38 @@ bool HIDInputManager::isKeyPressed(Keyboard::Key key)
|
||||
sf::err() << "HIDInputManager is invalid." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// state = true if at least one corresponding HID key is pressed
|
||||
bool state = false;
|
||||
|
||||
|
||||
for (IOHIDElements::iterator it = m_keys[key].begin(); it != m_keys[key].end(); ++it) {
|
||||
|
||||
|
||||
IOHIDValueRef value = 0;
|
||||
|
||||
|
||||
IOHIDDeviceRef device = IOHIDElementGetDevice(*it);
|
||||
IOHIDDeviceGetValue(device, *it, &value);
|
||||
|
||||
|
||||
if (!value) {
|
||||
|
||||
|
||||
// This means some kind of error / deconnection so we remove this
|
||||
// element from our keys
|
||||
|
||||
|
||||
CFRelease(*it);
|
||||
it = m_keys[key].erase(it);
|
||||
|
||||
|
||||
} else if (IOHIDValueGetIntegerValue(value) == 1) {
|
||||
|
||||
|
||||
// This means the key is pressed
|
||||
state = true;
|
||||
break; // Stop here
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// This means the key is released
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -91,38 +91,38 @@ bool HIDInputManager::isMouseButtonPressed(Mouse::Button button)
|
||||
sf::err() << "HIDInputManager is invalid." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// state = true if at least one corresponding HID button is pressed
|
||||
bool state = false;
|
||||
|
||||
|
||||
for (IOHIDElements::iterator it = m_buttons[button].begin(); it != m_buttons[button].end(); ++it) {
|
||||
|
||||
|
||||
IOHIDValueRef value = 0;
|
||||
|
||||
|
||||
IOHIDDeviceRef device = IOHIDElementGetDevice(*it);
|
||||
IOHIDDeviceGetValue(device, *it, &value);
|
||||
|
||||
|
||||
if (!value) {
|
||||
|
||||
|
||||
// This means some kind of error / deconnection so we remove this
|
||||
// element from our buttons
|
||||
|
||||
|
||||
CFRelease(*it);
|
||||
it = m_buttons[button].erase(it);
|
||||
|
||||
|
||||
} else if (IOHIDValueGetIntegerValue(value) == 1) {
|
||||
|
||||
|
||||
// This means the button is pressed
|
||||
state = true;
|
||||
break; // Stop here
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// This means the button is released
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -131,20 +131,20 @@ bool HIDInputManager::isMouseButtonPressed(Mouse::Button button)
|
||||
long HIDInputManager::getLocationID(IOHIDDeviceRef device)
|
||||
{
|
||||
long loc = 0;
|
||||
|
||||
|
||||
// Get a unique ID : its usb location ID
|
||||
CFTypeRef typeRef = IOHIDDeviceGetProperty(device,
|
||||
CFTypeRef typeRef = IOHIDDeviceGetProperty(device,
|
||||
CFSTR(kIOHIDLocationIDKey));
|
||||
if (!typeRef || CFGetTypeID(typeRef) != CFNumberGetTypeID()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
CFNumberRef locRef = (CFNumberRef)typeRef;
|
||||
|
||||
|
||||
if (!CFNumberGetValue(locRef, kCFNumberLongType, &loc)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
@ -153,20 +153,20 @@ long HIDInputManager::getLocationID(IOHIDDeviceRef device)
|
||||
CFDictionaryRef HIDInputManager::copyDevicesMask(UInt32 page, UInt32 usage)
|
||||
{
|
||||
// Create the dictionary.
|
||||
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -179,46 +179,46 @@ HIDInputManager::HIDInputManager()
|
||||
, m_manager(0)
|
||||
{
|
||||
// Get the current keyboard layout
|
||||
TISInputSourceRef tis = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
m_layoutData = (CFDataRef)TISGetInputSourceProperty(tis,
|
||||
TISInputSourceRef tis = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
m_layoutData = (CFDataRef)TISGetInputSourceProperty(tis,
|
||||
kTISPropertyUnicodeKeyLayoutData);
|
||||
|
||||
|
||||
if (m_layoutData == 0) {
|
||||
sf::err() << "Cannot get the keyboard layout" << std::endl;
|
||||
freeUp();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Keep a reference for ourself
|
||||
CFRetain(m_layoutData);
|
||||
m_layout = (UCKeyboardLayout *)CFDataGetBytePtr(m_layoutData);
|
||||
|
||||
|
||||
// The TIS is no more needed
|
||||
CFRelease(tis);
|
||||
|
||||
|
||||
// Create an HID Manager reference
|
||||
m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
||||
|
||||
// Open the HID Manager reference
|
||||
IOReturn openStatus = IOHIDManagerOpen(m_manager, kIOHIDOptionsTypeNone);
|
||||
|
||||
|
||||
if (openStatus != kIOReturnSuccess) {
|
||||
sf::err() << "Error when opening the HID manager" << std::endl;
|
||||
|
||||
|
||||
freeUp();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Initialize the keyboard
|
||||
initializeKeyboard();
|
||||
|
||||
|
||||
if (!m_isValid) {
|
||||
return; // Something went wrong
|
||||
}
|
||||
|
||||
|
||||
// Initialize the mouse
|
||||
initializeMouse();
|
||||
|
||||
|
||||
if (!m_isValid) {
|
||||
return; // Something went wrong
|
||||
}
|
||||
@ -237,30 +237,30 @@ void HIDInputManager::initializeKeyboard()
|
||||
////////////////////////////////////////////////////////////
|
||||
// The purpose of this function is to initalize m_keys so we can get
|
||||
// the associate IOHIDElementRef with a sf::Keyboard::Key in ~constant~ time.
|
||||
|
||||
|
||||
// Get only keyboards
|
||||
CFSetRef keyboards = copyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
|
||||
if (keyboards == NULL) {
|
||||
freeUp();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CFIndex keyboardCount = CFSetGetCount(keyboards); // >= 1 (asserted by copyDevices)
|
||||
|
||||
|
||||
// Get an iterable array
|
||||
CFTypeRef devicesArray[keyboardCount];
|
||||
CFSetGetValues(keyboards, devicesArray);
|
||||
|
||||
|
||||
for (CFIndex i = 0; i < keyboardCount; ++i) {
|
||||
|
||||
|
||||
IOHIDDeviceRef keyboard = (IOHIDDeviceRef)devicesArray[i];
|
||||
|
||||
|
||||
loadKeyboard(keyboard);
|
||||
}
|
||||
|
||||
|
||||
// Release unused stuff
|
||||
CFRelease(keyboards);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// At this point m_keys is filled with as many IOHIDElementRef as possible
|
||||
}
|
||||
@ -272,36 +272,36 @@ void HIDInputManager::initializeMouse()
|
||||
////////////////////////////////////////////////////////////
|
||||
// The purpose of this function is to initalize m_buttons so we can get
|
||||
// the associate IOHIDElementRef with a sf::Mouse::Button in ~constant~ time.
|
||||
|
||||
|
||||
// Get only mouses
|
||||
CFSetRef mouses = copyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse);
|
||||
if (mouses == NULL) {
|
||||
freeUp();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CFIndex mouseCount = CFSetGetCount(mouses); // >= 1 (asserted by copyDevices)
|
||||
|
||||
|
||||
// Get an iterable array
|
||||
CFTypeRef devicesArray[mouseCount];
|
||||
CFSetGetValues(mouses, devicesArray);
|
||||
|
||||
|
||||
for (CFIndex i = 0; i < mouseCount; ++i) {
|
||||
|
||||
|
||||
IOHIDDeviceRef mouse = (IOHIDDeviceRef)devicesArray[i];
|
||||
|
||||
|
||||
loadMouse(mouse);
|
||||
}
|
||||
|
||||
|
||||
// Release unused stuff
|
||||
CFRelease(mouses);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// At this point m_buttons is filled with as many IOHIDElementRef as possible
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
void HIDInputManager::loadKeyboard(IOHIDDeviceRef keyboard)
|
||||
{
|
||||
CFArrayRef keys = IOHIDDeviceCopyMatchingElements(keyboard,
|
||||
@ -311,36 +311,36 @@ void HIDInputManager::loadKeyboard(IOHIDDeviceRef keyboard)
|
||||
sf::err() << "We got a keyboard without any keys (1)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// How many elements are there ?
|
||||
CFIndex keysCount = CFArrayGetCount(keys);
|
||||
|
||||
|
||||
if (keysCount == 0) {
|
||||
sf::err() << "We got a keyboard without any keys (2)" << std::endl;
|
||||
CFRelease(keys);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Go through all connected elements.
|
||||
for (CFIndex i = 0; i < keysCount; ++i) {
|
||||
|
||||
|
||||
IOHIDElementRef aKey = (IOHIDElementRef) CFArrayGetValueAtIndex(keys, i);
|
||||
|
||||
|
||||
// Skip non-matching keys elements
|
||||
if (IOHIDElementGetUsagePage(aKey) != kHIDPage_KeyboardOrKeypad) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
loadKey(aKey);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Release unused stuff
|
||||
CFRelease(keys);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
void HIDInputManager::loadMouse(IOHIDDeviceRef mouse)
|
||||
{
|
||||
CFArrayRef buttons = IOHIDDeviceCopyMatchingElements(mouse,
|
||||
@ -350,29 +350,29 @@ void HIDInputManager::loadMouse(IOHIDDeviceRef mouse)
|
||||
sf::err() << "We got a mouse without any buttons (1)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// How many elements are there ?
|
||||
CFIndex buttonCount = CFArrayGetCount(buttons);
|
||||
|
||||
|
||||
if (buttonCount == 0) {
|
||||
sf::err() << "We got a mouse without any buttons (2)" << std::endl;
|
||||
CFRelease(buttons);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Go through all connected elements.
|
||||
for (CFIndex i = 0; i < buttonCount; ++i) {
|
||||
|
||||
|
||||
IOHIDElementRef aButton = (IOHIDElementRef) CFArrayGetValueAtIndex(buttons, i);
|
||||
|
||||
|
||||
// Skip non-matching keys elements
|
||||
if (IOHIDElementGetUsagePage(aButton) != kHIDPage_Button) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
loadButton(aButton);
|
||||
}
|
||||
|
||||
|
||||
// Release unused stuff
|
||||
CFRelease(buttons);
|
||||
}
|
||||
@ -384,22 +384,22 @@ void HIDInputManager::loadKey(IOHIDElementRef key)
|
||||
// Get its virtual code
|
||||
UInt32 usageCode = IOHIDElementGetUsage(key);
|
||||
UInt8 virtualCode = usageToVirtualCode(usageCode);
|
||||
|
||||
|
||||
if (virtualCode == 0xff) {
|
||||
return; // no corresponding virtual code -> skip
|
||||
}
|
||||
|
||||
|
||||
// Now translate the virtual code to unicode according to
|
||||
// the current keyboard layout
|
||||
|
||||
|
||||
UInt32 deadKeyState = 0;
|
||||
// Unicode string length is usually less or equal to 4
|
||||
UniCharCount maxStringLength = 4;
|
||||
UniCharCount actualStringLength = 0;
|
||||
UniChar unicodeString[maxStringLength];
|
||||
|
||||
|
||||
OSStatus error;
|
||||
|
||||
|
||||
error = UCKeyTranslate(m_layout, // current layout
|
||||
virtualCode, // our key
|
||||
kUCKeyActionDown, // or kUCKeyActionUp ?
|
||||
@ -410,38 +410,38 @@ void HIDInputManager::loadKey(IOHIDElementRef key)
|
||||
maxStringLength, // our memory limit
|
||||
&actualStringLength, // length of what we get
|
||||
unicodeString); // what we get
|
||||
|
||||
|
||||
if (error == noErr) {
|
||||
// Translation went fine
|
||||
|
||||
|
||||
// The corresponding SFML key code
|
||||
Keyboard::Key code = Keyboard::Unknown; // KeyCound means 'none'
|
||||
|
||||
// First we look if the key down is from a list of characters
|
||||
|
||||
// First we look if the key down is from a list of characters
|
||||
// that depend on keyboard localization
|
||||
if (actualStringLength > 0) {
|
||||
code = localizedKeys(unicodeString[0]);
|
||||
}
|
||||
|
||||
|
||||
// The key is not a localized one so we try to find a
|
||||
// corresponding code through virtual key code
|
||||
if (code == Keyboard::Unknown) {
|
||||
code = nonLocalizedKeys(virtualCode);
|
||||
}
|
||||
|
||||
|
||||
// A code was found, wonderful!
|
||||
if (code != Keyboard::Unknown) {
|
||||
|
||||
// Ok, everything went fine. Now we have a unique
|
||||
|
||||
// Ok, everything went fine. Now we have a unique
|
||||
// corresponding sf::Keyboard::Key to one IOHIDElementRef
|
||||
|
||||
|
||||
m_keys[code].push_back(key);
|
||||
|
||||
|
||||
// And don't forget to keep the reference alive for our usage
|
||||
CFRetain(m_keys[code].back());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// These are known to be unbound :
|
||||
// Supposed Virtual | HID | Supposed Key
|
||||
@ -451,7 +451,7 @@ void HIDInputManager::loadKey(IOHIDElementRef key)
|
||||
// 0x47 | 0x53 | NumLock
|
||||
// 0x6e | 0x65 | Application
|
||||
// 0x4c | 0x77 | Select
|
||||
|
||||
|
||||
//if (code == Keyboard::Unknown) { // The key is unknown.
|
||||
// sf::err() << "This is an unknow key. Virtual key code is 0x"
|
||||
// << std::hex
|
||||
@ -462,10 +462,10 @@ void HIDInputManager::loadKey(IOHIDElementRef key)
|
||||
// << "."
|
||||
// << std::endl;
|
||||
//}
|
||||
|
||||
} /* if (error == noErr) */
|
||||
|
||||
} /* if (error == noErr) */
|
||||
else {
|
||||
|
||||
|
||||
sf::err() << "Cannot translate the virtual key code, error : "
|
||||
<< error
|
||||
<< std::endl;
|
||||
@ -479,10 +479,10 @@ void HIDInputManager::loadButton(IOHIDElementRef button)
|
||||
// Identify the button
|
||||
UInt32 usage = IOHIDElementGetUsage(button);
|
||||
Mouse::Button dest = Mouse::ButtonCount;
|
||||
|
||||
|
||||
// Extends kHIDUsage_Button_* enum with :
|
||||
#define kHIDUsage_Button_5 0x05
|
||||
|
||||
|
||||
switch (usage) {
|
||||
case kHIDUsage_Button_1: dest = Mouse::Left; break;
|
||||
case kHIDUsage_Button_2: dest = Mouse::Right; break;
|
||||
@ -491,12 +491,12 @@ void HIDInputManager::loadButton(IOHIDElementRef button)
|
||||
case kHIDUsage_Button_5: dest = Mouse::XButton2; break;
|
||||
default: dest = Mouse::ButtonCount; break;
|
||||
}
|
||||
|
||||
|
||||
if (dest != Mouse::ButtonCount) {
|
||||
// We know what kind of button it is!
|
||||
|
||||
|
||||
m_buttons[dest].push_back(button);
|
||||
|
||||
|
||||
// And don't forget to keep the reference alive for our usage
|
||||
CFRetain(m_buttons[dest].back());
|
||||
}
|
||||
@ -507,18 +507,18 @@ void HIDInputManager::loadButton(IOHIDElementRef button)
|
||||
void HIDInputManager::freeUp()
|
||||
{
|
||||
m_isValid = false;
|
||||
|
||||
|
||||
if (m_layoutData != 0) CFRelease(m_layoutData);
|
||||
// Do not release m_layout ! It is owned by m_layoutData.
|
||||
if (m_manager != 0) CFRelease(m_manager);
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < Keyboard::KeyCount; ++i) {
|
||||
for (IOHIDElements::iterator it = m_keys[i].begin(); it != m_keys[i].end(); ++it) {
|
||||
CFRelease(*it);
|
||||
}
|
||||
m_keys[i].clear();
|
||||
}
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < Mouse::ButtonCount; ++i) {
|
||||
for (IOHIDElements::iterator it = m_buttons[i].begin(); it != m_buttons[i].end(); ++it) {
|
||||
CFRelease(*it);
|
||||
@ -526,31 +526,31 @@ void HIDInputManager::freeUp()
|
||||
m_buttons[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
CFSetRef HIDInputManager::copyDevices(UInt32 page, UInt32 usage)
|
||||
{
|
||||
// Filter and keep only the requested devices
|
||||
CFDictionaryRef mask = copyDevicesMask(page, usage);
|
||||
|
||||
|
||||
IOHIDManagerSetDeviceMatching(m_manager, mask);
|
||||
|
||||
|
||||
CFRelease(mask);
|
||||
mask = 0;
|
||||
|
||||
|
||||
CFSetRef devices = IOHIDManagerCopyDevices(m_manager);
|
||||
if (devices == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Is there at least one device ?
|
||||
CFIndex deviceCount = CFSetGetCount(devices);
|
||||
if (deviceCount < 1) {
|
||||
CFRelease(devices);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
@ -564,7 +564,7 @@ UInt8 HIDInputManager::usageToVirtualCode(UInt32 usage)
|
||||
case kHIDUsage_KeyboardErrorRollOver: return 0xff;
|
||||
case kHIDUsage_KeyboardPOSTFail: return 0xff;
|
||||
case kHIDUsage_KeyboardErrorUndefined: return 0xff;
|
||||
|
||||
|
||||
case kHIDUsage_KeyboardA: return 0x00;
|
||||
case kHIDUsage_KeyboardB: return 0x0b;
|
||||
case kHIDUsage_KeyboardC: return 0x08;
|
||||
@ -741,9 +741,9 @@ UInt8 HIDInputManager::usageToVirtualCode(UInt32 usage)
|
||||
case kHIDUsage_KeyboardClearOrAgain: return 0xff;
|
||||
case kHIDUsage_KeyboardCrSelOrProps: return 0xff;
|
||||
case kHIDUsage_KeyboardExSel: return 0xff;
|
||||
|
||||
|
||||
/* 0xa5-0xdf Reserved */
|
||||
|
||||
|
||||
case kHIDUsage_KeyboardLeftControl: return 0x3b;
|
||||
case kHIDUsage_KeyboardLeftShift: return 0x38;
|
||||
case kHIDUsage_KeyboardLeftAlt: return 0x3a;
|
||||
@ -754,12 +754,12 @@ UInt8 HIDInputManager::usageToVirtualCode(UInt32 usage)
|
||||
case kHIDUsage_KeyboardRightGUI: return 0x36;
|
||||
|
||||
/* 0xe8-0xffff Reserved */
|
||||
|
||||
|
||||
case kHIDUsage_Keyboard_Reserved: return 0xff;
|
||||
default: return 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
Keyboard::Key HIDInputManager::localizedKeys(UniChar ch)
|
||||
@ -767,82 +767,82 @@ Keyboard::Key HIDInputManager::localizedKeys(UniChar ch)
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
case 'A': return sf::Keyboard::A;
|
||||
|
||||
|
||||
case 'b':
|
||||
case 'B': return sf::Keyboard::B;
|
||||
|
||||
|
||||
case 'c':
|
||||
case 'C': return sf::Keyboard::C;
|
||||
|
||||
|
||||
case 'd':
|
||||
case 'D': return sf::Keyboard::D;
|
||||
|
||||
|
||||
case 'e':
|
||||
case 'E': return sf::Keyboard::E;
|
||||
|
||||
|
||||
case 'f':
|
||||
case 'F': return sf::Keyboard::F;
|
||||
|
||||
|
||||
case 'g':
|
||||
case 'G': return sf::Keyboard::G;
|
||||
|
||||
|
||||
case 'h':
|
||||
case 'H': return sf::Keyboard::H;
|
||||
|
||||
|
||||
case 'i':
|
||||
case 'I': return sf::Keyboard::I;
|
||||
|
||||
|
||||
case 'j':
|
||||
case 'J': return sf::Keyboard::J;
|
||||
|
||||
|
||||
case 'k':
|
||||
case 'K': return sf::Keyboard::K;
|
||||
|
||||
|
||||
case 'l':
|
||||
case 'L': return sf::Keyboard::L;
|
||||
|
||||
|
||||
case 'm':
|
||||
case 'M': return sf::Keyboard::M;
|
||||
|
||||
|
||||
case 'n':
|
||||
case 'N': return sf::Keyboard::N;
|
||||
|
||||
|
||||
case 'o':
|
||||
case 'O': return sf::Keyboard::O;
|
||||
|
||||
|
||||
case 'p':
|
||||
case 'P': return sf::Keyboard::P;
|
||||
|
||||
|
||||
case 'q':
|
||||
case 'Q': return sf::Keyboard::Q;
|
||||
|
||||
|
||||
case 'r':
|
||||
case 'R': return sf::Keyboard::R;
|
||||
|
||||
|
||||
case 's':
|
||||
case 'S': return sf::Keyboard::S;
|
||||
|
||||
|
||||
case 't':
|
||||
case 'T': return sf::Keyboard::T;
|
||||
|
||||
|
||||
case 'u':
|
||||
case 'U': return sf::Keyboard::U;
|
||||
|
||||
|
||||
case 'v':
|
||||
case 'V': return sf::Keyboard::V;
|
||||
|
||||
|
||||
case 'w':
|
||||
case 'W': return sf::Keyboard::W;
|
||||
|
||||
|
||||
case 'x':
|
||||
case 'X': return sf::Keyboard::X;
|
||||
|
||||
|
||||
case 'y':
|
||||
case 'Y': return sf::Keyboard::Y;
|
||||
|
||||
|
||||
case 'z':
|
||||
case 'Z': return sf::Keyboard::Z;
|
||||
|
||||
|
||||
// The key is not 'localized'.
|
||||
default: return sf::Keyboard::Unknown;
|
||||
}
|
||||
@ -882,7 +882,7 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case 0x07: return sf::Keyboard::X;
|
||||
case 0x10: return sf::Keyboard::Y;
|
||||
case 0x06: return sf::Keyboard::Z;
|
||||
|
||||
|
||||
// These cases should not be used but anyway...
|
||||
case 0x1d: return sf::Keyboard::Num0;
|
||||
case 0x12: return sf::Keyboard::Num1;
|
||||
@ -894,9 +894,9 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case 0x1a: return sf::Keyboard::Num7;
|
||||
case 0x1c: return sf::Keyboard::Num8;
|
||||
case 0x19: return sf::Keyboard::Num9;
|
||||
|
||||
|
||||
case 0x35: return sf::Keyboard::Escape;
|
||||
|
||||
|
||||
// Modifier keys : never happen with keyDown/keyUp methods (?)
|
||||
case 0x3b: return sf::Keyboard::LControl;
|
||||
case 0x38: return sf::Keyboard::LShift;
|
||||
@ -906,10 +906,10 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case 0x3c: return sf::Keyboard::RShift;
|
||||
case 0x3d: return sf::Keyboard::RAlt;
|
||||
case 0x36: return sf::Keyboard::RSystem;
|
||||
|
||||
|
||||
case 0x7f: return sf::Keyboard::Menu;
|
||||
case NSMenuFunctionKey: return sf::Keyboard::Menu;
|
||||
|
||||
|
||||
case 0x21: return sf::Keyboard::LBracket;
|
||||
case 0x1e: return sf::Keyboard::RBracket;
|
||||
case 0x29: return sf::Keyboard::SemiColon;
|
||||
@ -919,7 +919,7 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case 0x27: return sf::Keyboard::Quote;
|
||||
case 0x2c: return sf::Keyboard::Slash;
|
||||
case 0x2a: return sf::Keyboard::BackSlash;
|
||||
|
||||
|
||||
#warning sf::Keyboard::Tilde might be in conflict with some other key.
|
||||
// 0x0a is for "Non-US Backslash" according to HID Calibrator,
|
||||
// a sample provided by Apple.
|
||||
@ -933,39 +933,39 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case 0x24: /* keyboard */ return sf::Keyboard::Return;
|
||||
case 0x33: return sf::Keyboard::BackSpace;
|
||||
case 0x30: return sf::Keyboard::Tab;
|
||||
|
||||
|
||||
// Duplicates (see next §).
|
||||
case 0x74: return sf::Keyboard::PageUp;
|
||||
case 0x79: return sf::Keyboard::PageDown;
|
||||
case 0x77: return sf::Keyboard::End;
|
||||
case 0x73: return sf::Keyboard::Home;
|
||||
|
||||
|
||||
case NSPageUpFunctionKey: return sf::Keyboard::PageUp;
|
||||
case NSPageDownFunctionKey: return sf::Keyboard::PageDown;
|
||||
case NSEndFunctionKey: return sf::Keyboard::End;
|
||||
case NSHomeFunctionKey: return sf::Keyboard::Home;
|
||||
|
||||
|
||||
case 0x72: return sf::Keyboard::Insert;
|
||||
case NSInsertFunctionKey: return sf::Keyboard::Insert;
|
||||
case 0x75: return sf::Keyboard::Delete;
|
||||
case NSDeleteFunctionKey: return sf::Keyboard::Delete;
|
||||
|
||||
|
||||
case 0x45: return sf::Keyboard::Add;
|
||||
case 0x4e: return sf::Keyboard::Subtract;
|
||||
case 0x43: return sf::Keyboard::Multiply;
|
||||
case 0x4b: return sf::Keyboard::Divide;
|
||||
|
||||
|
||||
// Duplicates (see next §).
|
||||
case 0x7b: return sf::Keyboard::Left;
|
||||
case 0x7c: return sf::Keyboard::Right;
|
||||
case 0x7e: return sf::Keyboard::Up;
|
||||
case 0x7d: return sf::Keyboard::Down;
|
||||
|
||||
|
||||
case NSLeftArrowFunctionKey: return sf::Keyboard::Left;
|
||||
case NSRightArrowFunctionKey: return sf::Keyboard::Right;
|
||||
case NSUpArrowFunctionKey: return sf::Keyboard::Up;
|
||||
case NSDownArrowFunctionKey: return sf::Keyboard::Down;
|
||||
|
||||
|
||||
case 0x52: return sf::Keyboard::Numpad0;
|
||||
case 0x53: return sf::Keyboard::Numpad1;
|
||||
case 0x54: return sf::Keyboard::Numpad2;
|
||||
@ -976,7 +976,7 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case 0x59: return sf::Keyboard::Numpad7;
|
||||
case 0x5b: return sf::Keyboard::Numpad8;
|
||||
case 0x5c: return sf::Keyboard::Numpad9;
|
||||
|
||||
|
||||
// Duplicates (see next §).
|
||||
case 0x7a: return sf::Keyboard::F1;
|
||||
case 0x78: return sf::Keyboard::F2;
|
||||
@ -993,7 +993,7 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case 0x69: return sf::Keyboard::F13;
|
||||
case 0x6b: return sf::Keyboard::F14;
|
||||
case 0x71: return sf::Keyboard::F15;
|
||||
|
||||
|
||||
case NSF1FunctionKey: return sf::Keyboard::F1;
|
||||
case NSF2FunctionKey: return sf::Keyboard::F2;
|
||||
case NSF3FunctionKey: return sf::Keyboard::F3;
|
||||
@ -1009,12 +1009,12 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
|
||||
case NSF13FunctionKey: return sf::Keyboard::F13;
|
||||
case NSF14FunctionKey: return sf::Keyboard::F14;
|
||||
case NSF15FunctionKey: return sf::Keyboard::F15;
|
||||
|
||||
|
||||
case NSPauseFunctionKey: return sf::Keyboard::Pause;
|
||||
|
||||
|
||||
#warning keycode 0x1b is not bound to any key.
|
||||
// This key is ' on CH-FR, ) on FR and - on US layouts.
|
||||
|
||||
|
||||
// An unknown key.
|
||||
default: return sf::Keyboard::Unknown;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -74,32 +74,32 @@ HIDJoystickManager::HIDJoystickManager()
|
||||
, m_joystickCount(0)
|
||||
{
|
||||
m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
|
||||
|
||||
|
||||
CFDictionaryRef mask0 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop,
|
||||
kHIDUsage_GD_Joystick);
|
||||
|
||||
|
||||
CFDictionaryRef mask1 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop,
|
||||
kHIDUsage_GD_GamePad);
|
||||
|
||||
|
||||
CFDictionaryRef maskArray[2];
|
||||
maskArray[0] = mask0;
|
||||
maskArray[1] = mask1;
|
||||
|
||||
|
||||
CFArrayRef mask = CFArrayCreate(NULL, (const void**)maskArray, 2, NULL);
|
||||
|
||||
|
||||
IOHIDManagerSetDeviceMatchingMultiple(m_manager, mask);
|
||||
CFRelease(mask);
|
||||
CFRelease(mask1);
|
||||
CFRelease(mask0);
|
||||
|
||||
|
||||
|
||||
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(m_manager, pluggedIn, this);
|
||||
IOHIDManagerRegisterDeviceRemovalCallback(m_manager, pluggedOut, this);
|
||||
|
||||
IOHIDManagerScheduleWithRunLoop(m_manager,
|
||||
CFRunLoopGetCurrent(),
|
||||
|
||||
IOHIDManagerScheduleWithRunLoop(m_manager,
|
||||
CFRunLoopGetCurrent(),
|
||||
RunLoopMode);
|
||||
|
||||
|
||||
IOHIDManagerOpen(m_manager, kIOHIDOptionsTypeNone);
|
||||
}
|
||||
|
||||
@ -107,13 +107,13 @@ HIDJoystickManager::HIDJoystickManager()
|
||||
////////////////////////////////////////////////////////////
|
||||
HIDJoystickManager::~HIDJoystickManager()
|
||||
{
|
||||
IOHIDManagerUnscheduleFromRunLoop(m_manager,
|
||||
CFRunLoopGetCurrent(),
|
||||
IOHIDManagerUnscheduleFromRunLoop(m_manager,
|
||||
CFRunLoopGetCurrent(),
|
||||
RunLoopMode);
|
||||
|
||||
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(m_manager, NULL, 0);
|
||||
IOHIDManagerRegisterDeviceRemovalCallback(m_manager, NULL, 0);
|
||||
|
||||
|
||||
IOHIDManagerClose(m_manager, kIOHIDOptionsTypeNone);
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ HIDJoystickManager::~HIDJoystickManager()
|
||||
void HIDJoystickManager::update()
|
||||
{
|
||||
SInt32 status = kCFRunLoopRunHandledSource;
|
||||
|
||||
|
||||
while (status == kCFRunLoopRunHandledSource) {
|
||||
status = CFRunLoopRunInMode(RunLoopMode, 0, true);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -46,7 +46,7 @@ namespace priv
|
||||
class HIDJoystickManager : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the unique instance of the class
|
||||
///
|
||||
@ -56,45 +56,45 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static HIDJoystickManager& getInstance();
|
||||
|
||||
|
||||
public :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of currently connected joystick
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int getJoystickCount();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy the devices assosiated with this HID manager
|
||||
///
|
||||
///
|
||||
/// \return a retained CFSetRef of IOHIDDeviceRef or NULL
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CFSetRef copyJoysticks();
|
||||
|
||||
|
||||
private :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
HIDJoystickManager();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~HIDJoystickManager();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Make sur all event have been processed in the run loop
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update();
|
||||
|
||||
|
||||
private :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Private "plug-in" callback
|
||||
/// \note Only 'context' parametre is used.
|
||||
@ -102,7 +102,7 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void pluggedIn(void * context, IOReturn, void *, IOHIDDeviceRef);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Private "plug-out" callback
|
||||
/// \note Only 'context' parametre is used.
|
||||
@ -110,9 +110,9 @@ private :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void pluggedOut(void * context, IOReturn, void *, IOHIDDeviceRef);
|
||||
|
||||
|
||||
private :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -122,7 +122,7 @@ private :
|
||||
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -39,7 +39,7 @@
|
||||
/// In order to keep track of the keyboard's state and mouse buttons' state
|
||||
/// we use the HID manager. Mouse position is handled differently.
|
||||
///
|
||||
/// NB : we probably could use
|
||||
/// NB : we probably could use
|
||||
/// NSEvent +addGlobalMonitorForEventsMatchingMask:handler: for mouse only.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -50,29 +50,29 @@ namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Extract the dedicated SFOpenGLView from the SFML window
|
||||
///
|
||||
///
|
||||
/// \param window a SFML window
|
||||
/// \return nil if something went wrong or a SFOpenGLView*.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const Window& window)
|
||||
{
|
||||
id nsHandle = (id)window.getSystemHandle();
|
||||
|
||||
|
||||
// Get our SFOpenGLView from ...
|
||||
SFOpenGLView* view = nil;
|
||||
|
||||
|
||||
if ([nsHandle isKindOfClass:[NSWindow class]]) {
|
||||
// If system handle is a window then from its content view.
|
||||
view = [nsHandle contentView];
|
||||
|
||||
|
||||
// Subview doesn't match ?
|
||||
if (![view isKindOfClass:[SFOpenGLView class]]) {
|
||||
sf::err() << "The content view is not a valid SFOpenGLView"
|
||||
sf::err() << "The content view is not a valid SFOpenGLView"
|
||||
<< std::endl;
|
||||
view = nil;
|
||||
}
|
||||
|
||||
|
||||
} else if ([nsHandle isKindOfClass:[NSView class]]) {
|
||||
// If system handle is a view then from a subview of kind SFOpenGLView.
|
||||
NSArray* subviews = [nsHandle subviews];
|
||||
@ -82,13 +82,13 @@ SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const Window& window)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// No matching subview ?
|
||||
if (view == nil) {
|
||||
sf::err() << "Cannot find a valid SFOpenGLView subview." << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
if (nsHandle != 0) {
|
||||
sf::err() << "The system handle is neither a <NSWindow*> nor <NSView*>"
|
||||
@ -99,7 +99,7 @@ SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const Window& window)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -132,15 +132,15 @@ Vector2i InputImpl::getMousePosition()
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
{
|
||||
SFOpenGLView* view = getSFOpenGLViewFromSFMLWindow(relativeTo);
|
||||
|
||||
|
||||
// No view ?
|
||||
if (view == nil) {
|
||||
return Vector2i();
|
||||
}
|
||||
|
||||
|
||||
// Use -cursorPositionFromEvent: with nil.
|
||||
NSPoint pos = [view cursorPositionFromEvent:nil];
|
||||
|
||||
|
||||
return Vector2i(pos.x, pos.y);
|
||||
}
|
||||
|
||||
@ -150,11 +150,11 @@ void InputImpl::setMousePosition(const Vector2i& position)
|
||||
{
|
||||
// Here we don't need to reverse the coordinates.
|
||||
CGPoint pos = CGPointMake(position.x, position.y);
|
||||
|
||||
|
||||
// Place the cursor.
|
||||
CGEventRef event = CGEventCreateMouseEvent(NULL,
|
||||
kCGEventMouseMoved,
|
||||
pos,
|
||||
CGEventRef event = CGEventCreateMouseEvent(NULL,
|
||||
kCGEventMouseMoved,
|
||||
pos,
|
||||
/*we don't care about this : */0);
|
||||
CGEventPost(kCGHIDEventTap, event);
|
||||
CFRelease(event);
|
||||
@ -166,12 +166,12 @@ void InputImpl::setMousePosition(const Vector2i& position)
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
SFOpenGLView* view = getSFOpenGLViewFromSFMLWindow(relativeTo);
|
||||
|
||||
|
||||
// No view ?
|
||||
if (view == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Let SFOpenGLView compute the position in global coordinate
|
||||
NSPoint p = NSMakePoint(position.x, position.y);
|
||||
p = [view computeGlobalPositionOfRelativePoint:p];
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
@ -66,47 +66,47 @@ void JoystickImpl::cleanup()
|
||||
bool JoystickImpl::isConnected(unsigned int index)
|
||||
{
|
||||
bool state = false; // Is the index-th joystick connected ?
|
||||
|
||||
|
||||
// First, let's check if the device was previously detected :
|
||||
|
||||
|
||||
if (m_locationIDs[index] != 0) {
|
||||
state = true;
|
||||
}
|
||||
|
||||
|
||||
// Otherwise, let's check if it is now connected :
|
||||
else { // i.e., m_locationIDs[index] == 0
|
||||
|
||||
|
||||
// if there is more connected joystick to the HID manager than
|
||||
// opened joystick devices then we find the new one.
|
||||
|
||||
|
||||
unsigned int openedCount = 0;
|
||||
for (unsigned int i(0); i < sf::Joystick::Count; ++i) {
|
||||
if (m_locationIDs[i] != 0) openedCount++;
|
||||
}
|
||||
|
||||
|
||||
unsigned int connectedCount = HIDJoystickManager::getInstance().getJoystickCount();
|
||||
|
||||
|
||||
if (connectedCount > openedCount) {
|
||||
|
||||
|
||||
// Get all devices
|
||||
CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks();
|
||||
|
||||
|
||||
if (devices != NULL) {
|
||||
|
||||
|
||||
CFIndex size = CFSetGetCount(devices);
|
||||
|
||||
|
||||
if (size > 0) {
|
||||
|
||||
|
||||
CFTypeRef array[size]; // array of IOHIDDeviceRef
|
||||
CFSetGetValues(devices, array);
|
||||
|
||||
|
||||
// If there exists a device d s.t. there is no j s.t.
|
||||
// m_locationIDs[j] == d's location then we have a new device.
|
||||
|
||||
|
||||
for (CFIndex didx(0); didx < size; ++didx) {
|
||||
IOHIDDeviceRef d = (IOHIDDeviceRef)array[didx];
|
||||
Location dloc = HIDInputManager::getLocationID(d);
|
||||
|
||||
|
||||
bool foundJ = false;
|
||||
for (unsigned int j(0); j < Joystick::Count; ++j) {
|
||||
if (m_locationIDs[j] == dloc) {
|
||||
@ -114,7 +114,7 @@ bool JoystickImpl::isConnected(unsigned int index)
|
||||
break; // no need to loop again
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (foundJ) {
|
||||
// This is a known device
|
||||
// Nothing else to do
|
||||
@ -126,14 +126,14 @@ bool JoystickImpl::isConnected(unsigned int index)
|
||||
break; // We stop looking for a new device
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
CFRelease(devices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -143,18 +143,18 @@ bool JoystickImpl::open(unsigned int index)
|
||||
{
|
||||
m_index = index;
|
||||
Location deviceLoc = m_locationIDs[index]; // The device we need to load
|
||||
|
||||
|
||||
// Get all devices
|
||||
CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks();
|
||||
if (devices == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Get a usable copy of the joysticks devices.
|
||||
CFIndex joysticksCount = CFSetGetCount(devices);
|
||||
CFTypeRef devicesArray[joysticksCount];
|
||||
CFSetGetValues(devices, devicesArray);
|
||||
|
||||
|
||||
// Get the desired joystick.
|
||||
IOHIDDeviceRef self = 0;
|
||||
for (CFIndex i(0); i < joysticksCount; ++i) {
|
||||
@ -164,70 +164,70 @@ bool JoystickImpl::open(unsigned int index)
|
||||
break; // We found it so we stop looping.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (self == 0) {
|
||||
// This shouldn't happen!
|
||||
CFRelease(devices);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Get a list of all elements attached to the device.
|
||||
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(self,
|
||||
NULL,
|
||||
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(self,
|
||||
NULL,
|
||||
kIOHIDOptionsTypeNone);
|
||||
|
||||
|
||||
if (elements == NULL) {
|
||||
CFRelease(devices);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// How many elements are there ?
|
||||
CFIndex elementsCount = CFArrayGetCount(elements);
|
||||
|
||||
|
||||
if (elementsCount == 0) {
|
||||
// What is a joystick with no element ?
|
||||
CFRelease(elements);
|
||||
CFRelease(devices);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Go through all connected elements.
|
||||
for (int i = 0; i < elementsCount; ++i) {
|
||||
IOHIDElementRef element = (IOHIDElementRef) CFArrayGetValueAtIndex(elements, i);
|
||||
|
||||
|
||||
switch (IOHIDElementGetType(element)) {
|
||||
|
||||
|
||||
case kIOHIDElementTypeInput_Misc:
|
||||
switch (IOHIDElementGetUsage(element)) {
|
||||
|
||||
|
||||
case kHIDUsage_GD_X:
|
||||
m_axis[Joystick::X] = element;
|
||||
break;
|
||||
|
||||
|
||||
case kHIDUsage_GD_Y:
|
||||
m_axis[Joystick::Y] = element;
|
||||
break;
|
||||
|
||||
|
||||
case kHIDUsage_GD_Z:
|
||||
m_axis[Joystick::Z] = element;
|
||||
break;
|
||||
|
||||
|
||||
case kHIDUsage_GD_Rx:
|
||||
m_axis[Joystick::U] = element;
|
||||
m_axis[Joystick::U] = element;
|
||||
break;
|
||||
|
||||
|
||||
case kHIDUsage_GD_Ry:
|
||||
m_axis[Joystick::V] = element;
|
||||
m_axis[Joystick::V] = element;
|
||||
break;
|
||||
|
||||
|
||||
case kHIDUsage_GD_Rz:
|
||||
m_axis[Joystick::R] = element;
|
||||
m_axis[Joystick::R] = element;
|
||||
break;
|
||||
|
||||
|
||||
// kHIDUsage_GD_Vx, kHIDUsage_GD_Vy, kHIDUsage_GD_Vz are ignored.
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case kIOHIDElementTypeInput_Button:
|
||||
if (m_buttons.size() < Joystick::ButtonCount) { // If we have free slot...
|
||||
m_buttons.push_back(element); // ...we add this element to the list
|
||||
@ -235,19 +235,19 @@ bool JoystickImpl::open(unsigned int index)
|
||||
// Too many buttons. We ignore this one.
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default: // Make compiler happy
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Ensure that the buttons will be indexed in the same order as their
|
||||
// HID Usage (assigned by manufacturer and/or a driver).
|
||||
std::sort(m_buttons.begin(), m_buttons.end(), JoystickButtonSortPredicate);
|
||||
|
||||
|
||||
// Note : Joy::AxisPovX/Y are not supported (yet).
|
||||
// Maybe kIOHIDElementTypeInput_Axis is the corresponding type but I can't test.
|
||||
|
||||
|
||||
// Retain all these objets for personal use
|
||||
for (ButtonsVector::iterator it(m_buttons.begin()); it != m_buttons.end(); ++it) {
|
||||
CFRetain(*it);
|
||||
@ -255,14 +255,14 @@ bool JoystickImpl::open(unsigned int index)
|
||||
for (AxisMap::iterator it(m_axis.begin()); it != m_axis.end(); ++it) {
|
||||
CFRetain(it->second);
|
||||
}
|
||||
|
||||
|
||||
// Note : we didn't retain element in the switch because we might have multiple
|
||||
// Axis X (for example) and we want to keep only the last one. So to prevent
|
||||
// leaking we retain objects 'only' now.
|
||||
|
||||
|
||||
CFRelease(devices);
|
||||
CFRelease(elements);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -274,12 +274,12 @@ void JoystickImpl::close()
|
||||
CFRelease(*it);
|
||||
}
|
||||
m_buttons.clear();
|
||||
|
||||
|
||||
for (AxisMap::iterator it(m_axis.begin()); it != m_axis.end(); ++it) {
|
||||
CFRelease(it->second);
|
||||
}
|
||||
m_axis.clear();
|
||||
|
||||
|
||||
// And we unregister this joystick
|
||||
m_locationIDs[m_index] = 0;
|
||||
}
|
||||
@ -289,15 +289,15 @@ void JoystickImpl::close()
|
||||
JoystickCaps JoystickImpl::getCapabilities() const
|
||||
{
|
||||
JoystickCaps caps;
|
||||
|
||||
|
||||
// Buttons :
|
||||
caps.buttonCount = m_buttons.size();
|
||||
|
||||
|
||||
// Axis :
|
||||
for (AxisMap::const_iterator it(m_axis.begin()); it != m_axis.end(); ++it) {
|
||||
caps.axes[it->first] = true;
|
||||
}
|
||||
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
@ -308,24 +308,24 @@ JoystickState JoystickImpl::update()
|
||||
static const JoystickState disconnectedState; // return this if joystick was disconnected
|
||||
JoystickState state; // otherwise return that
|
||||
state.connected = true;
|
||||
|
||||
|
||||
// Note : free up is done in close() which is called, if required,
|
||||
// by the joystick manager. So we don't release buttons nor axes here.
|
||||
|
||||
|
||||
// First, let's determine if the joystick is still connected
|
||||
Location selfLoc = m_locationIDs[m_index];
|
||||
|
||||
|
||||
// Get all devices
|
||||
CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks();
|
||||
if (devices == NULL) {
|
||||
return disconnectedState;
|
||||
}
|
||||
|
||||
|
||||
// Get a usable copy of the joysticks devices.
|
||||
CFIndex joysticksCount = CFSetGetCount(devices);
|
||||
CFTypeRef devicesArray[joysticksCount];
|
||||
CFSetGetValues(devices, devicesArray);
|
||||
|
||||
|
||||
// Search for it
|
||||
bool found = false;
|
||||
for (CFIndex i(0); i < joysticksCount; ++i) {
|
||||
@ -335,10 +335,10 @@ JoystickState JoystickImpl::update()
|
||||
break; // Stop looping
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Release unused stuff
|
||||
CFRelease(devices);
|
||||
|
||||
|
||||
// Was it found ?
|
||||
if (found) {
|
||||
// Yes, so we can continue.
|
||||
@ -346,38 +346,38 @@ JoystickState JoystickImpl::update()
|
||||
// No, so we stop here
|
||||
return disconnectedState;
|
||||
}
|
||||
|
||||
|
||||
// Update buttons' state
|
||||
unsigned int i = 0;
|
||||
for (ButtonsVector::iterator it(m_buttons.begin()); it != m_buttons.end(); ++it, ++i) {
|
||||
IOHIDValueRef value = 0;
|
||||
IOHIDDeviceGetValue(IOHIDElementGetDevice(*it), *it, &value);
|
||||
|
||||
|
||||
// Check for plug out.
|
||||
if (!value) {
|
||||
// No value ? Hum... Seems like the joystick is gone
|
||||
return disconnectedState;
|
||||
}
|
||||
|
||||
|
||||
// 1 means pressed, others mean released
|
||||
state.buttons[i] = IOHIDValueGetIntegerValue(value) == 1;
|
||||
}
|
||||
|
||||
|
||||
// Update axes' state
|
||||
for (AxisMap::iterator it = m_axis.begin(); it != m_axis.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
|
||||
return disconnectedState;
|
||||
}
|
||||
|
||||
|
||||
// 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
|
||||
//
|
||||
@ -392,8 +392,8 @@ JoystickState JoystickImpl::update()
|
||||
float scaledValue = ((physicalValue - physicalMin) * (scaledMax - scaledMin) / (physicalMax - physicalMin)) + scaledMin;
|
||||
state.axes[it->first] = scaledValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
@ -108,13 +108,13 @@ private :
|
||||
typedef long Location;
|
||||
typedef std::map<sf::Joystick::Axis, IOHIDElementRef> AxisMap;
|
||||
typedef std::vector<IOHIDElementRef> ButtonsVector;
|
||||
|
||||
|
||||
AxisMap m_axis; ///< Axis (IOHIDElementRef) connected to the joystick
|
||||
ButtonsVector m_buttons; ///< Buttons (IOHIDElementRef) connected to the joystick
|
||||
unsigned int m_index; ///< SFML index
|
||||
|
||||
|
||||
static Location m_locationIDs[sf::Joystick::Count]; ///< Global Joystick register
|
||||
/// For a corresponding SFML index, m_locationIDs is either some usb
|
||||
/// For a corresponding SFML index, m_locationIDs is either some usb
|
||||
/// location or 0 if there isn't currently a connected joystick device
|
||||
};
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -38,7 +38,7 @@
|
||||
{
|
||||
[SFApplication sharedApplication]; // Make sure NSApp exists
|
||||
NSEvent* event = nil;
|
||||
|
||||
|
||||
while ((event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
||||
untilDate:[NSDate distantPast]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
@ -48,7 +48,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sendEvent:(NSEvent *)anEvent
|
||||
-(void)sendEvent:(NSEvent *)anEvent
|
||||
{
|
||||
if ([anEvent type] == NSKeyUp) {
|
||||
[[[self mainWindow] firstResponder] tryToPerform:@selector(keyUp:)
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -72,7 +72,7 @@ public:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFContext(SFContext* shared);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context attached to a window
|
||||
///
|
||||
@ -84,7 +84,7 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
const WindowImpl* owner, unsigned int bitsPerPixel);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context that embeds its own rendering target
|
||||
///
|
||||
@ -94,21 +94,21 @@ public:
|
||||
/// \param height Back buffer height, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
unsigned int width, unsigned int height);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~SFContext();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Display what has been rendered to the context so far
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void display();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable vertical synchronization
|
||||
///
|
||||
@ -121,7 +121,7 @@ public:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setVerticalSyncEnabled(bool enabled);
|
||||
|
||||
|
||||
protected:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate the context as the current target
|
||||
@ -131,7 +131,7 @@ protected:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool makeCurrent();
|
||||
|
||||
|
||||
private:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the context
|
||||
@ -142,10 +142,10 @@ private:
|
||||
/// \param settings Creation parameters
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void createContext(SFContext* shared,
|
||||
unsigned int bitsPerPixel,
|
||||
void createContext(SFContext* shared,
|
||||
unsigned int bitsPerPixel,
|
||||
const ContextSettings& settings);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -153,9 +153,9 @@ private:
|
||||
NSOpenGLViewRef m_view; ///< Only for offscreen context.
|
||||
NSWindowRef m_window; ///< Only for offscreen context.
|
||||
};
|
||||
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#endif // SFML_SFCONTEXT_HPP
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -44,14 +44,14 @@ SFContext::SFContext(SFContext* shared)
|
||||
{
|
||||
// Ask for a pool.
|
||||
retainPool();
|
||||
|
||||
|
||||
// Create the context
|
||||
createContext(shared,
|
||||
VideoMode::getDesktopMode().bitsPerPixel,
|
||||
VideoMode::getDesktopMode().bitsPerPixel,
|
||||
ContextSettings(0, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
const WindowImpl* owner, unsigned int bitsPerPixel)
|
||||
@ -59,10 +59,10 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
{
|
||||
// Ask for a pool.
|
||||
retainPool();
|
||||
|
||||
|
||||
// Create the context.
|
||||
createContext(shared, bitsPerPixel, settings);
|
||||
|
||||
|
||||
// Apply context.
|
||||
WindowImplCocoa const * ownerCocoa = static_cast<WindowImplCocoa const *>(owner);
|
||||
ownerCocoa->applyContext(m_context);
|
||||
@ -70,19 +70,19 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
unsigned int width, unsigned int height)
|
||||
: m_view(0), m_window(0)
|
||||
{
|
||||
// Ensure the process is setup in order to create a valid window.
|
||||
WindowImplCocoa::setUpProcess();
|
||||
|
||||
|
||||
// Ask for a pool.
|
||||
retainPool();
|
||||
|
||||
|
||||
// Create the context.
|
||||
createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, settings);
|
||||
|
||||
|
||||
// Create a dummy window/view pair (hidden) and asign it our context.
|
||||
m_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
|
||||
styleMask:NSBorderlessWindowMask
|
||||
@ -100,10 +100,10 @@ SFContext::~SFContext()
|
||||
{
|
||||
[m_context clearDrawable];
|
||||
[m_context release];
|
||||
|
||||
|
||||
[m_view release]; // Might be nil but we don't care.
|
||||
[m_window release]; // Idem.
|
||||
|
||||
|
||||
releasePool();
|
||||
}
|
||||
|
||||
@ -130,89 +130,89 @@ void SFContext::setVerticalSyncEnabled(bool enabled)
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||
typedef int GLint;
|
||||
#endif
|
||||
|
||||
|
||||
GLint swapInterval = enabled ? 1 : 0;
|
||||
|
||||
|
||||
[m_context setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFContext::createContext(SFContext* shared,
|
||||
unsigned int bitsPerPixel,
|
||||
unsigned int bitsPerPixel,
|
||||
const ContextSettings& settings)
|
||||
{
|
||||
// Choose the attributs of OGL context.
|
||||
std::vector<NSOpenGLPixelFormatAttribute> attrs;
|
||||
attrs.reserve(20); // max attributs (estimation).
|
||||
|
||||
|
||||
// These casts are safe. C++ is much more strict than Obj-C.
|
||||
|
||||
|
||||
attrs.push_back(NSOpenGLPFAClosestPolicy);
|
||||
attrs.push_back(NSOpenGLPFADoubleBuffer);
|
||||
|
||||
|
||||
if (bitsPerPixel > 24) {
|
||||
attrs.push_back(NSOpenGLPFAAlphaSize);
|
||||
attrs.push_back((NSOpenGLPixelFormatAttribute)8);
|
||||
}
|
||||
|
||||
|
||||
attrs.push_back(NSOpenGLPFADepthSize);
|
||||
attrs.push_back((NSOpenGLPixelFormatAttribute)settings.depthBits);
|
||||
|
||||
|
||||
attrs.push_back(NSOpenGLPFAStencilSize);
|
||||
attrs.push_back((NSOpenGLPixelFormatAttribute)settings.stencilBits);
|
||||
|
||||
|
||||
if (settings.antialiasingLevel > 0) {
|
||||
/*
|
||||
* Antialiasing techniques are described in the
|
||||
/*
|
||||
* Antialiasing techniques are described in the
|
||||
* "OpenGL Programming Guide for Mac OS X" document.
|
||||
*
|
||||
* According to this document, the specification currently allows
|
||||
* According to this document, the specification currently allows
|
||||
* only one multisample buffer.
|
||||
*
|
||||
* The document also states that software renderers should be avoided
|
||||
* because antialisaing techniques are very slow with them.
|
||||
*/
|
||||
|
||||
|
||||
// Prefer multisampling over supersampling
|
||||
attrs.push_back(NSOpenGLPFAMultisample);
|
||||
|
||||
|
||||
// Only one buffer is currently available
|
||||
attrs.push_back(NSOpenGLPFASampleBuffers);
|
||||
attrs.push_back((NSOpenGLPixelFormatAttribute)1);
|
||||
|
||||
|
||||
// Antialiasing level
|
||||
attrs.push_back(NSOpenGLPFASamples);
|
||||
attrs.push_back((NSOpenGLPixelFormatAttribute)settings.antialiasingLevel);
|
||||
|
||||
|
||||
// No software renderer - only hardware renderer
|
||||
attrs.push_back(NSOpenGLPFAAccelerated);
|
||||
}
|
||||
|
||||
|
||||
attrs.push_back((NSOpenGLPixelFormatAttribute)0); // end of array
|
||||
|
||||
|
||||
// Create the pixel pormat.
|
||||
NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attrs[0]];
|
||||
|
||||
|
||||
if (pixFmt == nil) {
|
||||
sf::err() << "Error. Unable to find a suitable pixel format." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Use the shared context if one is given.
|
||||
NSOpenGLContext* sharedContext = shared != NULL ? shared->m_context : nil;
|
||||
|
||||
|
||||
// Create the context.
|
||||
m_context = [[NSOpenGLContext alloc] initWithFormat:pixFmt
|
||||
shareContext:sharedContext];
|
||||
|
||||
|
||||
if (m_context == nil) {
|
||||
sf::err() << "Error. Unable to create the context." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
// Free up.
|
||||
[pixFmt release];
|
||||
|
||||
|
||||
// Save the settings. (OpenGL version is updated elsewhere.)
|
||||
m_settings = settings;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -46,7 +46,7 @@ namespace sf {
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set up a SFML key event based on the given modifiers
|
||||
/// flags and key code.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Event::KeyEvent keyEventWithModifiers(NSUInteger modifiers, sf::Keyboard::Key key);
|
||||
|
||||
@ -54,7 +54,7 @@ sf::Event::KeyEvent keyEventWithModifiers(NSUInteger modifiers, sf::Keyboard::Ke
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Handle the state of modifiers keys and send key
|
||||
/// release & pressed events to the requester.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void handleModifiersChanged(NSUInteger modifiers, sf::priv::WindowImplCocoa& requester);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -71,20 +71,20 @@ namespace sf {
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create the SFML opengl view to fit the given area.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(id)initWithFrame:(NSRect)frameRect;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Handle going in and out of fullscreen mode.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)enterFullscreen;
|
||||
-(void)exitFullscreen;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Apply the given resquester to the view.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester;
|
||||
|
||||
@ -93,27 +93,27 @@ namespace sf {
|
||||
/// If not set, or set to its default value NSZeroSize, the view
|
||||
/// won't recompute the mouse coordinates before sending them
|
||||
/// to the requester.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)setRealSize:(NSSize)newSize;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Compute the position in global coordinate
|
||||
/// of the given point in SFML coordinate.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(NSPoint)computeGlobalPositionOfRelativePoint:(NSPoint)point;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Adjust key repeat configuration.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)enableKeyRepeat;
|
||||
-(void)disableKeyRepeat;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Compute the position of the cursor.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(NSPoint)cursorPositionFromEvent:(NSEvent *)eventOrNil;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -53,20 +53,20 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Handle view resized event.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)viewDidEndLiveResize;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Establish if the mouse is inside or outside the OpenGL view.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(BOOL)isMouseInside;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Update the mouse state (in or out) and fire an event
|
||||
/// if its state has changed.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)updateMouseState;
|
||||
|
||||
@ -74,7 +74,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
/// Convert the NSEvent mouse button type to SFML type.
|
||||
///
|
||||
/// Returns ButtonCount if the button is unknown
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(sf::Mouse::Button)mouseButtonFromEvent:(NSEvent *)event;
|
||||
|
||||
@ -101,7 +101,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
[self setRequesterTo:0];
|
||||
[self enableKeyRepeat];
|
||||
m_realSize = NSZeroSize;
|
||||
|
||||
|
||||
// Register for mouse move event
|
||||
m_mouseIsIn = [self isMouseInside];
|
||||
NSUInteger opts = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
|
||||
@ -170,7 +170,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(NSPoint)computeGlobalPositionOfRelativePoint:(NSPoint)point
|
||||
{
|
||||
{
|
||||
// Recompute the mouse pos if required.
|
||||
if (!NSEqualSizes(m_realSize, NSZeroSize)) {
|
||||
point.x = point.x / m_realSize.width * [self frame].size.width;
|
||||
@ -183,17 +183,17 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
//
|
||||
// So we stick with the old one for now.
|
||||
|
||||
|
||||
|
||||
// Flip SFML coordinates to match window coordinates
|
||||
point.y = [self frame].size.height - point.y;
|
||||
|
||||
|
||||
// Get the position of (x, y) in the coordinate system of the window.
|
||||
point = [self convertPoint:point toView:self];
|
||||
point = [self convertPoint:point toView:nil]; // nil means window
|
||||
|
||||
|
||||
// Convert it to screen coordinates
|
||||
point = [[self window] convertBaseToScreen:point];
|
||||
|
||||
|
||||
// Flip screen coodinates to match CGDisplayMoveCursorToPoint referential.
|
||||
float const screenHeight = [[[self window] screen] frame].size.height;
|
||||
point.y = screenHeight - point.y;
|
||||
@ -232,13 +232,13 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
|
||||
// Update mouse internal state.
|
||||
[self updateMouseState];
|
||||
|
||||
|
||||
// Update the OGL view to fit the new size.
|
||||
[self update];
|
||||
|
||||
|
||||
// Send an event
|
||||
if (m_requester == 0) return;
|
||||
|
||||
|
||||
// The new size
|
||||
NSSize newSize = [self frame].size;
|
||||
m_requester->windowResized(newSize.width, newSize.height);
|
||||
@ -250,11 +250,11 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
NSPoint relativeToWindow = [[self window] mouseLocationOutsideOfEventStream];
|
||||
NSPoint relativeToView = [self convertPoint:relativeToWindow fromView:nil];
|
||||
|
||||
|
||||
if (NSPointInRect(relativeToView, [self frame])) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
BOOL mouseWasIn = m_mouseIsIn;
|
||||
m_mouseIsIn = [self isMouseInside];
|
||||
|
||||
|
||||
// Send event if needed.
|
||||
if (mouseWasIn && !m_mouseIsIn) {
|
||||
[self mouseExited:nil];
|
||||
@ -296,8 +296,8 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(BOOL)acceptsFirstResponder
|
||||
{
|
||||
-(BOOL)acceptsFirstResponder
|
||||
{
|
||||
// Accepts key event.
|
||||
return YES;
|
||||
}
|
||||
@ -316,11 +316,11 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)mouseDown:(NSEvent *)theEvent
|
||||
-(void)mouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
// Forward to...
|
||||
[self otherMouseDown:theEvent];
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseDown:theEvent];
|
||||
}
|
||||
@ -331,7 +331,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Forward to...
|
||||
[self otherMouseUp:theEvent];
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseUp:theEvent];
|
||||
}
|
||||
@ -342,7 +342,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Forward to...
|
||||
[self otherMouseDragged:theEvent];
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseMoved:theEvent];
|
||||
}
|
||||
@ -353,10 +353,10 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
if (m_requester != 0) {
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
|
||||
m_requester->mouseWheelScrolledAt([theEvent deltaY], loc.x, loc.y);
|
||||
}
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] scrollWheel:theEvent];
|
||||
}
|
||||
@ -406,7 +406,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Forward to...
|
||||
[self otherMouseDown:theEvent];
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] rightMouseDown:theEvent];
|
||||
}
|
||||
@ -417,7 +417,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Forward to...
|
||||
[self otherMouseUp:theEvent];
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] rightMouseUp:theEvent];
|
||||
}
|
||||
@ -427,15 +427,15 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
-(void)otherMouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
|
||||
|
||||
|
||||
if (m_requester != 0) {
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
|
||||
if (button != sf::Mouse::ButtonCount) {
|
||||
m_requester->mouseDownAt(button, loc.x, loc.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the event is not forwarded by mouseDown or rightMouseDown...
|
||||
if (button != sf::Mouse::Left && button != sf::Mouse::Right) {
|
||||
// ... transmit to non-SFML responder
|
||||
@ -448,15 +448,15 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
-(void)otherMouseUp:(NSEvent *)theEvent
|
||||
{
|
||||
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
|
||||
|
||||
|
||||
if (m_requester != 0) {
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
|
||||
if (button != sf::Mouse::ButtonCount) {
|
||||
m_requester->mouseUpAt(button, loc.x, loc.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the event is not forwarded by mouseUp or rightMouseUp...
|
||||
if (button != sf::Mouse::Left && button != sf::Mouse::Right) {
|
||||
// ... transmit to non-SFML responder
|
||||
@ -470,7 +470,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Forward to...
|
||||
[self otherMouseDragged:theEvent];
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] rightMouseDragged:theEvent];
|
||||
}
|
||||
@ -481,7 +481,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Forward to...
|
||||
[self otherMouseDragged:theEvent];
|
||||
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseDragged:theEvent];
|
||||
}
|
||||
@ -501,7 +501,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
m_requester->mouseMovedAt(loc.x, loc.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the event is not forwarded by mouseDragged or rightMouseDragged...
|
||||
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
|
||||
if (button != sf::Mouse::Left && button != sf::Mouse::Right) {
|
||||
@ -522,17 +522,17 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
} else {
|
||||
loc = [self convertPoint:[eventOrNil locationInWindow] fromView:nil];
|
||||
}
|
||||
|
||||
|
||||
// Don't forget to change to SFML coord system.
|
||||
float h = [self frame].size.height;
|
||||
loc.y = h - loc.y;
|
||||
|
||||
|
||||
// Recompute the mouse pos if required.
|
||||
if (!NSEqualSizes(m_realSize, NSZeroSize)) {
|
||||
loc.x = loc.x * m_realSize.width / [self frame].size.width;
|
||||
loc.y = loc.y * m_realSize.height / [self frame].size.height;
|
||||
}
|
||||
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
@ -560,13 +560,13 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] keyDown:theEvent];
|
||||
|
||||
|
||||
if (m_requester == 0) return;
|
||||
|
||||
|
||||
// Handle key down event
|
||||
if (m_useKeyRepeat || ![theEvent isARepeat]) {
|
||||
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
|
||||
|
||||
|
||||
if (key.code != sf::Keyboard::Unknown) { // The key is recognized.
|
||||
m_requester->keyDown(key);
|
||||
}
|
||||
@ -623,11 +623,11 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] keyUp:theEvent];
|
||||
|
||||
|
||||
if (m_requester == 0) return;
|
||||
|
||||
|
||||
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
|
||||
|
||||
|
||||
if (key.code != sf::Keyboard::Unknown) { // The key is recognized.
|
||||
m_requester->keyUp(key);
|
||||
}
|
||||
@ -639,9 +639,9 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] flagsChanged:theEvent];
|
||||
|
||||
|
||||
if (m_requester == 0) return;
|
||||
|
||||
|
||||
NSUInteger modifiers = [theEvent modifierFlags];
|
||||
handleModifiersChanged(modifiers, *m_requester);
|
||||
}
|
||||
@ -652,20 +652,20 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
{
|
||||
// Key code
|
||||
sf::Keyboard::Key key = sf::Keyboard::Unknown;
|
||||
|
||||
|
||||
// First we look if the key down is from a list of characters
|
||||
// that depend on keyboard localization.
|
||||
NSString* string = [anEvent charactersIgnoringModifiers];
|
||||
if ([string length] > 0) {
|
||||
key = sf::priv::HIDInputManager::localizedKeys([string characterAtIndex:0]);
|
||||
}
|
||||
|
||||
|
||||
// If the key is not a localized one, we try to find a corresponding code
|
||||
// through virtual key code.
|
||||
if (key == sf::Keyboard::Unknown) {
|
||||
key = sf::priv::HIDInputManager::nonLocalizedKeys([anEvent keyCode]);
|
||||
}
|
||||
|
||||
|
||||
//#ifdef SFML_DEBUG // Don't bother the final customers with annoying messages.
|
||||
// if (key.code == sf::Keyboard::Unknown) { // The key is unknown.
|
||||
// sf::err() << "This is an unknow key. Virtual key code is 0x"
|
||||
@ -675,7 +675,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
// << std::endl;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
|
||||
return keyEventWithModifiers([anEvent modifierFlags], key);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -40,41 +40,41 @@
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
m_requester = 0;
|
||||
|
||||
|
||||
// Retain the view for our own use.
|
||||
m_view = [view retain];
|
||||
|
||||
|
||||
if (m_view == nil) {
|
||||
|
||||
sf::err()
|
||||
|
||||
sf::err()
|
||||
<< "No view was given to initWithWindow:."
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// Create the view.
|
||||
NSRect frame = [m_view frame];
|
||||
frame.origin.x = 0;
|
||||
frame.origin.y = 0;
|
||||
m_oglView = [[SFOpenGLView alloc] initWithFrame:frame];
|
||||
|
||||
|
||||
if (m_oglView == nil) {
|
||||
|
||||
|
||||
sf::err()
|
||||
<< "Could not create an instance of NSOpenGLView "
|
||||
<< "in (SFViewController -initWithView:)."
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// Set the (OGL) view to the view as its "content" view.
|
||||
[m_view addSubview:m_oglView];
|
||||
|
||||
|
||||
[m_oglView setAutoresizingMask:[m_view autoresizingMask]];
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -83,10 +83,10 @@
|
||||
-(void)dealloc
|
||||
{
|
||||
[self closeWindow];
|
||||
|
||||
|
||||
[m_view release];
|
||||
[m_oglView release];
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@
|
||||
[m_view frame].origin.y,
|
||||
width,
|
||||
height);
|
||||
|
||||
|
||||
[m_view setFrame:frame];
|
||||
[m_oglView setFrame:frame];
|
||||
}
|
||||
@ -200,7 +200,7 @@
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)setIconTo:(unsigned int)width
|
||||
by:(unsigned int)height
|
||||
by:(unsigned int)height
|
||||
with:(sf::Uint8 const *)pixels
|
||||
{
|
||||
sf::err() << "Cannot set an icon when SFML is integrated in a NSView." << std::endl;
|
||||
@ -219,10 +219,10 @@
|
||||
sf::err()
|
||||
<< "Cannot fetch event from a worker thread. (OS X restriction)"
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// If we don't have a requester we don't fetch event.
|
||||
if (m_requester != 0) {
|
||||
[SFApplication processEvent];
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -42,7 +42,7 @@ namespace sf {
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Implementation of WindowImplDelegateProtocol for window managment.
|
||||
///
|
||||
///
|
||||
/// Key and mouse events are delegated to its view.
|
||||
/// Window events are managed by this class.
|
||||
///
|
||||
@ -66,13 +66,13 @@ namespace sf {
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create the SFML window with an external Cocoa window.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(id)initWithWindow:(NSWindow *)window;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create the SFML window "from scratch" (full SFML handling).
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(id)initWithMode:(sf::VideoMode const &)mode andStyle:(unsigned long)style;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -47,13 +47,13 @@
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Retrieves the screen height.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(float)screenHeight;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Retrives the title bar height.
|
||||
///
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-(float)titlebarHeight;
|
||||
|
||||
@ -70,36 +70,36 @@
|
||||
if ((self = [super init])) {
|
||||
m_requester = 0;
|
||||
m_fullscreenMode = new sf::VideoMode();
|
||||
|
||||
|
||||
// Retain the window for our own use.
|
||||
m_window = [window retain];
|
||||
|
||||
|
||||
if (m_window == nil) {
|
||||
|
||||
sf::err()
|
||||
|
||||
sf::err()
|
||||
<< "No window was given to initWithWindow:."
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// Create the view.
|
||||
m_oglView = [[SFOpenGLView alloc] initWithFrame:[[m_window contentView] frame]];
|
||||
|
||||
|
||||
if (m_oglView == nil) {
|
||||
|
||||
|
||||
sf::err()
|
||||
<< "Could not create an instance of NSOpenGLView "
|
||||
<< "in (SFWindowController -initWithWindow:)."
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// Set the view to the window as its content view.
|
||||
[m_window setContentView:m_oglView];
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -116,100 +116,100 @@
|
||||
sf::err()
|
||||
<< "Cannot create a window from a worker thread. (OS X limitation)"
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
if ((self = [super init])) {
|
||||
m_requester = 0;
|
||||
m_fullscreenMode = new sf::VideoMode();
|
||||
|
||||
|
||||
// Create our window size.
|
||||
NSRect rect = NSZeroRect;
|
||||
if (style & sf::Style::Fullscreen && mode != sf::VideoMode::getDesktopMode()) {
|
||||
// We use desktop mode to size the window
|
||||
// but we set the back buffer size to 'mode' in applyContext method.
|
||||
|
||||
|
||||
*m_fullscreenMode = mode;
|
||||
|
||||
|
||||
sf::VideoMode dm = sf::VideoMode::getDesktopMode();
|
||||
rect = NSMakeRect(0, 0, dm.width, dm.height);
|
||||
|
||||
|
||||
} else { // no fullscreen requested.
|
||||
rect = NSMakeRect(0, 0, mode.width, mode.height);
|
||||
}
|
||||
|
||||
|
||||
// Convert the SFML window style to Cocoa window style.
|
||||
unsigned int nsStyle = NSBorderlessWindowMask;
|
||||
if (!(style & sf::Style::Fullscreen)) { // if fullscrean we keep our NSBorderlessWindowMask.
|
||||
|
||||
|
||||
if (style & sf::Style::Titlebar) nsStyle |= NSTitledWindowMask | NSMiniaturizableWindowMask;
|
||||
|
||||
|
||||
if (style & sf::Style::Resize) nsStyle |= NSResizableWindowMask;
|
||||
|
||||
|
||||
if (style & sf::Style::Close) nsStyle |= NSClosableWindowMask;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create the window.
|
||||
m_window = [[SFWindow alloc] initWithContentRect:rect
|
||||
styleMask:nsStyle
|
||||
backing:NSBackingStoreBuffered
|
||||
styleMask:nsStyle
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO]; // Don't defer it!
|
||||
/*
|
||||
"YES" produces some "invalid drawable".
|
||||
See http://www.cocoabuilder.com/archive/cocoa/152482-nsviews-and-nsopenglcontext-invalid-drawable-error.html
|
||||
|
||||
|
||||
[...]
|
||||
As best as I can figure, this is happening because the NSWindow (and
|
||||
hence my view) are not visible onscreen yet, and the system doesn't like that.
|
||||
[...]
|
||||
*/
|
||||
|
||||
|
||||
if (m_window == nil) {
|
||||
sf::err()
|
||||
sf::err()
|
||||
<< "Could not create an instance of NSWindow "
|
||||
<< "in (SFWindowController -initWithMode:andStyle:)."
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// Apply special feature for fullscreen window.
|
||||
if (style & sf::Style::Fullscreen) {
|
||||
// We place the window above everything else.
|
||||
[m_window setOpaque:YES];
|
||||
[m_window setHidesOnDeactivate:YES];
|
||||
[m_window setLevel:NSMainMenuWindowLevel+1];
|
||||
|
||||
|
||||
// And hide the menu bar
|
||||
[NSMenu setMenuBarVisible:NO];
|
||||
|
||||
|
||||
/* ---------------------------
|
||||
* | Note for future version |
|
||||
* ---------------------------
|
||||
*
|
||||
* starting with OS 10.6 NSView provides
|
||||
* a new method -enterFullScreenMode:withOptions:
|
||||
* a new method -enterFullScreenMode:withOptions:
|
||||
* which could be a good alternative.
|
||||
*/
|
||||
}
|
||||
|
||||
// Center the window to be cool =)
|
||||
[m_window center];
|
||||
|
||||
|
||||
// Create the view.
|
||||
m_oglView = [[SFOpenGLView alloc] initWithFrame:[[m_window contentView] frame]];
|
||||
|
||||
|
||||
if (m_oglView == nil) {
|
||||
sf::err()
|
||||
<< "Could not create an instance of NSOpenGLView "
|
||||
<< "in (SFWindowController -initWithMode:andStyle:)."
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
// If a fullscreen window was requested...
|
||||
if (style & sf::Style::Fullscreen) {
|
||||
/// ... we tell the OpenGL view
|
||||
@ -221,20 +221,20 @@
|
||||
[m_oglView setRealSize:NSMakeSize(m_fullscreenMode->width, m_fullscreenMode->height)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set the view to the window as its content view.
|
||||
[m_window setContentView:m_oglView];
|
||||
|
||||
|
||||
// Register for event.
|
||||
[m_window setDelegate:self];
|
||||
[m_window setAcceptsMouseMovedEvents:YES];
|
||||
[m_window setIgnoresMouseEvents:NO];
|
||||
|
||||
|
||||
// And some other things...
|
||||
[m_window setAutodisplay:YES];
|
||||
[m_window setReleasedWhenClosed:NO];
|
||||
} // if super init ok
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -243,12 +243,12 @@
|
||||
{
|
||||
[self closeWindow];
|
||||
[NSMenu setMenuBarVisible:YES];
|
||||
|
||||
|
||||
[m_window release];
|
||||
[m_oglView release];
|
||||
|
||||
|
||||
delete m_fullscreenMode;
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@ -302,12 +302,12 @@
|
||||
|
||||
// Next, convert it to the screen base system
|
||||
NSPoint const positionInScreen = [[m_oglView window] convertBaseToScreen:positionInWindow];
|
||||
|
||||
|
||||
// Finally, flip for SFML window coordinate system
|
||||
// Don't forget to discard the title bar !
|
||||
NSPoint const positionInSFML = NSMakePoint(positionInScreen.x,
|
||||
([self screenHeight] - [self titlebarHeight]) - positionInScreen.y);
|
||||
|
||||
|
||||
return positionInSFML;
|
||||
}
|
||||
|
||||
@ -316,10 +316,10 @@
|
||||
-(void)setWindowPositionToX:(int)x Y:(int)y
|
||||
{
|
||||
NSPoint point = NSMakePoint(x, y);
|
||||
|
||||
|
||||
// Flip for SFML window coordinate system.
|
||||
point.y = [self screenHeight] - point.y;
|
||||
|
||||
|
||||
// Place the window.
|
||||
[m_window setFrameTopLeftPoint:point];
|
||||
}
|
||||
@ -344,7 +344,7 @@
|
||||
[m_window frame].origin.y,
|
||||
width,
|
||||
height + [self titlebarHeight]);
|
||||
|
||||
|
||||
[m_window setFrame:frame display:YES];
|
||||
}
|
||||
|
||||
@ -395,15 +395,15 @@
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)setIconTo:(unsigned int)width
|
||||
by:(unsigned int)height
|
||||
by:(unsigned int)height
|
||||
with:(sf::Uint8 const *)pixels
|
||||
{
|
||||
// Create an empty image representation.
|
||||
NSBitmapImageRep* bitmap =
|
||||
NSBitmapImageRep* bitmap =
|
||||
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:0 // if 0 : only allocate memory
|
||||
pixelsWide:width
|
||||
pixelsHigh:height
|
||||
bitsPerSample:8 // The number of bits used to specify
|
||||
bitsPerSample:8 // The number of bits used to specify
|
||||
// one pixel in a single component of the data.
|
||||
samplesPerPixel:4 // 3 if no alpha, 4 with it
|
||||
hasAlpha:YES
|
||||
@ -411,12 +411,12 @@
|
||||
colorSpaceName:NSCalibratedRGBColorSpace
|
||||
bytesPerRow:0 // 0 == determine automatically
|
||||
bitsPerPixel:0]; // 0 == determine automatically
|
||||
|
||||
|
||||
// Load data pixels.
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 // We may need to define NSUInteger.
|
||||
#define NSUInteger unsigned int
|
||||
#endif
|
||||
for (unsigned int y = 0; y < height; ++y) {
|
||||
for (unsigned int y = 0; y < height; ++y) {
|
||||
for (unsigned int x = 0; x < width; ++x, pixels+=4) {
|
||||
NSUInteger pixel[4] = { pixels[0], pixels[1], pixels[2], pixels[3] };
|
||||
[bitmap setPixel:pixel
|
||||
@ -424,14 +424,14 @@
|
||||
y:y];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create an image from the representation.
|
||||
NSImage* icon = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
|
||||
[icon addRepresentation:bitmap];
|
||||
|
||||
|
||||
// Set app icon.
|
||||
[[SFApplication sharedApplication] setApplicationIconImage:icon];
|
||||
|
||||
|
||||
// Free up.
|
||||
[icon release];
|
||||
[bitmap release];
|
||||
@ -450,10 +450,10 @@
|
||||
sf::err()
|
||||
<< "Cannot fetch event from a worker thread. (OS X restriction)"
|
||||
<< std::endl;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// If we don't have a requester we don't fetch event.
|
||||
if (m_requester != 0) {
|
||||
[SFApplication processEvent];
|
||||
@ -466,15 +466,15 @@
|
||||
{
|
||||
[m_oglView setOpenGLContext:context];
|
||||
[context setView:m_oglView];
|
||||
|
||||
|
||||
// If fullscreen was requested and the mode used to create the window
|
||||
// was not the desktop mode, we change the back buffer size of the
|
||||
// context.
|
||||
if (*m_fullscreenMode != sf::VideoMode()) {
|
||||
CGLContextObj cgcontext = (CGLContextObj)[context CGLContextObj];
|
||||
|
||||
|
||||
GLint dim[2] = {m_fullscreenMode->width, m_fullscreenMode->height};
|
||||
|
||||
|
||||
CGLSetParameter(cgcontext, kCGLCPSurfaceBackingSize, dim);
|
||||
CGLEnable(cgcontext, kCGLCESurfaceBackingSize);
|
||||
}
|
||||
@ -489,7 +489,7 @@
|
||||
-(BOOL)windowShouldClose:(id)sender
|
||||
{
|
||||
if (m_requester == 0) return YES;
|
||||
|
||||
|
||||
m_requester->windowClosed();
|
||||
return NO;
|
||||
}
|
||||
@ -500,7 +500,7 @@
|
||||
{
|
||||
// Send event.
|
||||
if (m_requester == 0) return;
|
||||
|
||||
|
||||
m_requester->windowGainedFocus();
|
||||
|
||||
if (*m_fullscreenMode != sf::VideoMode()) {
|
||||
@ -514,7 +514,7 @@
|
||||
{
|
||||
// Send event.
|
||||
if (m_requester == 0) return;
|
||||
|
||||
|
||||
m_requester->windowLostFocus();
|
||||
|
||||
if (*m_fullscreenMode != sf::VideoMode()) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -34,9 +34,9 @@
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Note :
|
||||
/// Note :
|
||||
/// Starting with 10.6, CGDisplayModeRef and CGDisplayCopyAllDisplayModes
|
||||
/// should be used instead of CFDictionaryRef and CGDisplayAvailableModes.
|
||||
///
|
||||
@ -44,62 +44,62 @@ namespace priv
|
||||
std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||
|
||||
|
||||
std::vector<VideoMode> modes;
|
||||
|
||||
|
||||
// Retrieve array of dictionaries representing display modes.
|
||||
CFArrayRef displayModes = CGDisplayAvailableModes(CGMainDisplayID());
|
||||
|
||||
|
||||
if (displayModes == NULL) {
|
||||
sf::err() << "Couldn't get VideoMode for main display.";
|
||||
return modes;
|
||||
}
|
||||
|
||||
|
||||
// Loop on each mode and convert it into a sf::VideoMode object.
|
||||
CFIndex const modesCount = CFArrayGetCount(displayModes);
|
||||
for (CFIndex i = 0; i < modesCount; i++) {
|
||||
CFDictionaryRef dictionary = (CFDictionaryRef)CFArrayGetValueAtIndex(displayModes, i);
|
||||
|
||||
|
||||
VideoMode mode = convertCGModeToSFMode(dictionary);
|
||||
|
||||
|
||||
// If not yet listed we add it to our modes array.
|
||||
if (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
|
||||
modes.push_back(mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return modes;
|
||||
|
||||
|
||||
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||
|
||||
|
||||
std::vector<VideoMode> modes;
|
||||
|
||||
|
||||
// Retrieve all modes available for main screen only.
|
||||
CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
|
||||
|
||||
|
||||
if (cgmodes == NULL) {
|
||||
sf::err() << "Couldn't get VideoMode for main display.";
|
||||
return modes;
|
||||
}
|
||||
|
||||
|
||||
// Loop on each mode and convert it into a sf::VideoMode object.
|
||||
CFIndex const modesCount = CFArrayGetCount(cgmodes);
|
||||
for (CFIndex i = 0; i < modesCount; i++) {
|
||||
CGDisplayModeRef cgmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cgmodes, i);
|
||||
|
||||
|
||||
VideoMode mode = convertCGModeToSFMode(cgmode);
|
||||
|
||||
|
||||
// If not yet listed we add it to our modes array.
|
||||
if (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
|
||||
modes.push_back(mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Clean up memory.
|
||||
CFRelease(cgmodes);
|
||||
|
||||
|
||||
return modes;
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -108,8 +108,8 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
|
||||
VideoMode VideoModeImpl::getDesktopMode()
|
||||
{
|
||||
CGDirectDisplayID display = CGMainDisplayID();
|
||||
return VideoMode(CGDisplayPixelsWide(display),
|
||||
CGDisplayPixelsHigh(display),
|
||||
return VideoMode(CGDisplayPixelsWide(display),
|
||||
CGDisplayPixelsHigh(display),
|
||||
displayBitsPerPixel(display));
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -71,7 +71,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplCocoa(WindowHandle handle);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the window implementation
|
||||
///
|
||||
@ -82,13 +82,13 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplCocoa(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~WindowImplCocoa();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Window Closed Event – called by the cocoa window object.
|
||||
///
|
||||
@ -96,7 +96,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void windowClosed(void);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Window Resized Event – called by the cocoa window object.
|
||||
///
|
||||
@ -107,7 +107,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void windowResized(unsigned int width, unsigned int height);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Window Lost Focus Event – called by the cocoa window object.
|
||||
///
|
||||
@ -115,7 +115,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void windowLostFocus(void);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Window Get Focus Event – called by the cocoa window object.
|
||||
///
|
||||
@ -123,7 +123,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void windowGainedFocus(void);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Mouse Down Event – called by the cocoa view object.
|
||||
///
|
||||
@ -135,7 +135,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void mouseDownAt(Mouse::Button button, int x, int y);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Mouse Up Event – called by the cocoa view object.
|
||||
///
|
||||
@ -147,7 +147,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void mouseUpAt(Mouse::Button button, int x, int y);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Mouse Moved Event – called by the cocoa view object.
|
||||
///
|
||||
@ -158,7 +158,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void mouseMovedAt(int x, int y);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Mouse Wheel Scrolled Event – called by the cocoa view object.
|
||||
///
|
||||
@ -170,7 +170,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void mouseWheelScrolledAt(float delta, int x, int y);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Mouse In Event – called by the cocoa view object.
|
||||
///
|
||||
@ -178,7 +178,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void mouseMovedIn(void);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Mouse Out Event – called by the cocoa view object.
|
||||
///
|
||||
@ -186,7 +186,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void mouseMovedOut(void);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Key Down Event – called by the cocoa view object.
|
||||
///
|
||||
@ -196,7 +196,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void keyDown(Event::KeyEvent key);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Key Up Event – called by the cocoa view object.
|
||||
///
|
||||
@ -206,7 +206,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void keyUp(Event::KeyEvent key);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Text Entred Event – called by the cocoa view object.
|
||||
///
|
||||
@ -216,7 +216,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void textEntered(unichar charcode);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Apply the context to the view.
|
||||
///
|
||||
@ -226,16 +226,16 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void applyContext(NSOpenGLContextRef context) const;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the type of the current process to become a full GUI app.
|
||||
/// Also ensure NSApp is constructed.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setUpProcess(void);
|
||||
|
||||
|
||||
public :
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the OS-specific handle of the window
|
||||
///
|
||||
@ -243,7 +243,7 @@ public :
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual WindowHandle getSystemHandle() const;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the window
|
||||
///
|
||||
@ -334,9 +334,9 @@ private :
|
||||
WindowImplDelegateRef m_delegate; ///< Implementation in Obj-C.
|
||||
bool m_showCursor; ///< Is the cursor displayed or hidden ?
|
||||
};
|
||||
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -50,36 +50,36 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle)
|
||||
{
|
||||
// Ask for a pool.
|
||||
retainPool();
|
||||
|
||||
|
||||
// Treat the handle as it real type
|
||||
id nsHandle = (id)handle;
|
||||
if ([nsHandle isKindOfClass:[NSWindow class]]) {
|
||||
|
||||
|
||||
// We have a window.
|
||||
m_delegate = [[SFWindowController alloc] initWithWindow:nsHandle];
|
||||
|
||||
|
||||
} else if ([nsHandle isKindOfClass:[NSView class]]) {
|
||||
|
||||
|
||||
// We have a view.
|
||||
m_delegate = [[SFViewController alloc] initWithView:nsHandle];
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
sf::err()
|
||||
<< "Cannot import this Window Handle because it is neither "
|
||||
<< "a <NSWindow*> nor <NSView*> object "
|
||||
<< "(or any of their subclasses). You gave a <"
|
||||
<< "(or any of their subclasses). You gave a <"
|
||||
<< [[nsHandle className] UTF8String]
|
||||
<< "> object."
|
||||
<< std::endl;
|
||||
return;
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
[m_delegate setRequesterTo:this];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplCocoa::WindowImplCocoa(VideoMode mode,
|
||||
const String& title,
|
||||
@ -89,31 +89,31 @@ WindowImplCocoa::WindowImplCocoa(VideoMode mode,
|
||||
{
|
||||
// Transform the app process.
|
||||
setUpProcess();
|
||||
|
||||
|
||||
// Ask for a pool.
|
||||
retainPool();
|
||||
|
||||
|
||||
m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style];
|
||||
[m_delegate changeTitle:sfStringToNSString(title)];
|
||||
[m_delegate setRequesterTo:this];
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplCocoa::~WindowImplCocoa()
|
||||
{
|
||||
[m_delegate closeWindow];
|
||||
|
||||
|
||||
[m_delegate release];
|
||||
|
||||
|
||||
releasePool();
|
||||
|
||||
|
||||
drainPool(); // Make sure everything was freed
|
||||
// This solve some issue when sf::Window::Create is called for the
|
||||
// second time (nothing was render until the function was called again)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::applyContext(NSOpenGLContextRef context) const
|
||||
{
|
||||
@ -125,18 +125,18 @@ void WindowImplCocoa::applyContext(NSOpenGLContextRef context) const
|
||||
void WindowImplCocoa::setUpProcess(void)
|
||||
{
|
||||
static bool isTheProcessSetAsApplication = false;
|
||||
|
||||
|
||||
if (!isTheProcessSetAsApplication) {
|
||||
// Do it only once !
|
||||
isTheProcessSetAsApplication = true;
|
||||
|
||||
|
||||
// Set the process as a normal application so it can get focus.
|
||||
ProcessSerialNumber psn;
|
||||
if (!GetCurrentProcess(&psn)) {
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
SetFrontProcess(&psn);
|
||||
}
|
||||
|
||||
|
||||
// Tell the application to stop bouncing in the Dock.
|
||||
[[SFApplication sharedApplication] finishLaunching];
|
||||
// NOTE : This last call won't harm anything even if SFML window was
|
||||
@ -147,18 +147,18 @@ void WindowImplCocoa::setUpProcess(void)
|
||||
|
||||
#pragma mark
|
||||
#pragma mark WindowImplCocoa's window-event methods
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::windowClosed(void)
|
||||
{
|
||||
{
|
||||
Event event;
|
||||
event.type = Event::Closed;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::windowResized(unsigned int width, unsigned int height)
|
||||
{
|
||||
@ -166,42 +166,42 @@ void WindowImplCocoa::windowResized(unsigned int width, unsigned int height)
|
||||
event.type = Event::Resized;
|
||||
event.size.width = width;
|
||||
event.size.height = height;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::windowLostFocus(void)
|
||||
{
|
||||
if (!m_showCursor) {
|
||||
[m_delegate showMouseCursor]; // Make sur the cursor is visible
|
||||
}
|
||||
|
||||
|
||||
Event event;
|
||||
event.type = Event::LostFocus;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::windowGainedFocus(void)
|
||||
{
|
||||
if (!m_showCursor) {
|
||||
[m_delegate hideMouseCursor]; // Restore user's setting
|
||||
}
|
||||
|
||||
|
||||
Event event;
|
||||
event.type = Event::GainedFocus;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
#pragma mark
|
||||
#pragma mark WindowImplCocoa's mouse-event methods
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::mouseDownAt(Mouse::Button button, int x, int y)
|
||||
{
|
||||
@ -210,11 +210,11 @@ void WindowImplCocoa::mouseDownAt(Mouse::Button button, int x, int y)
|
||||
event.mouseButton.button = button;
|
||||
event.mouseButton.x = x;
|
||||
event.mouseButton.y = y;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::mouseUpAt(Mouse::Button button, int x, int y)
|
||||
{
|
||||
@ -223,7 +223,7 @@ void WindowImplCocoa::mouseUpAt(Mouse::Button button, int x, int y)
|
||||
event.mouseButton.button = button;
|
||||
event.mouseButton.x = x;
|
||||
event.mouseButton.y = y;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ void WindowImplCocoa::mouseMovedAt(int x, int y)
|
||||
event.type = Event::MouseMoved;
|
||||
event.mouseMove.x = x;
|
||||
event.mouseMove.y = y;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ void WindowImplCocoa::mouseWheelScrolledAt(float delta, int x, int y)
|
||||
event.mouseWheel.delta = delta;
|
||||
event.mouseWheel.x = x;
|
||||
event.mouseWheel.y = y;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
@ -257,49 +257,49 @@ void WindowImplCocoa::mouseMovedIn(void)
|
||||
if (!m_showCursor) {
|
||||
[m_delegate hideMouseCursor]; // Restore user's setting
|
||||
}
|
||||
|
||||
|
||||
Event event;
|
||||
event.type = Event::MouseEntered;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::mouseMovedOut(void)
|
||||
{
|
||||
if (!m_showCursor) {
|
||||
[m_delegate showMouseCursor]; // Make sur the cursor is visible
|
||||
}
|
||||
|
||||
|
||||
Event event;
|
||||
event.type = Event::MouseLeft;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma mark
|
||||
#pragma mark WindowImplCocoa's key-event methods
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::keyDown(Event::KeyEvent key)
|
||||
{
|
||||
Event event;
|
||||
event.type = Event::KeyPressed;
|
||||
event.key = key;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::keyUp(Event::KeyEvent key)
|
||||
{
|
||||
Event event;
|
||||
event.type = Event::KeyReleased;
|
||||
event.key = key;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
@ -310,11 +310,11 @@ void WindowImplCocoa::textEntered(unichar charcode)
|
||||
Event event;
|
||||
event.type = Event::TextEntered;
|
||||
event.text.unicode = charcode;
|
||||
|
||||
|
||||
pushEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark
|
||||
#pragma mark WindowImplCocoa's event-related methods
|
||||
|
||||
@ -323,7 +323,7 @@ void WindowImplCocoa::processEvents()
|
||||
{
|
||||
[m_delegate processEvent];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark
|
||||
#pragma mark WindowImplCocoa's private methods
|
||||
|
||||
@ -333,7 +333,7 @@ WindowHandle WindowImplCocoa::getSystemHandle() const
|
||||
return [m_delegate getSystemHandle];
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i WindowImplCocoa::getPosition() const
|
||||
{
|
||||
@ -356,28 +356,28 @@ Vector2u WindowImplCocoa::getSize() const
|
||||
return Vector2u(size.width, size.height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::setSize(const Vector2u& size)
|
||||
{
|
||||
{
|
||||
[m_delegate resizeTo:size.x by:size.y];
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::setTitle(const String& title)
|
||||
{
|
||||
[m_delegate changeTitle:sfStringToNSString(title)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::setIcon(unsigned int width, unsigned int height, const Uint8* pixels)
|
||||
{
|
||||
[m_delegate setIconTo:width by:height with:pixels];
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::setVisible(bool visible)
|
||||
{
|
||||
@ -388,12 +388,12 @@ void WindowImplCocoa::setVisible(bool visible)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::setMouseCursorVisible(bool visible)
|
||||
{
|
||||
m_showCursor = visible;
|
||||
|
||||
|
||||
if (m_showCursor) {
|
||||
[m_delegate showMouseCursor];
|
||||
} else {
|
||||
@ -401,7 +401,7 @@ void WindowImplCocoa::setMouseCursorVisible(bool visible)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::setKeyRepeatEnabled(bool enabled)
|
||||
{
|
||||
@ -412,7 +412,7 @@ void WindowImplCocoa::setKeyRepeatEnabled(bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -38,7 +38,7 @@ namespace sf {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// This protocol defines the interface of the delegate of
|
||||
/// This protocol defines the interface of the delegate of
|
||||
/// the window implementation.
|
||||
///
|
||||
/// We don't create an interface here because Obj-C doesn't allow
|
||||
@ -47,7 +47,7 @@ namespace sf {
|
||||
/// we have to duplicate some code.
|
||||
///
|
||||
/// Everything is done via a class that implement this protocol.
|
||||
/// There are two of these classes :
|
||||
/// There are two of these classes :
|
||||
///
|
||||
/// SFViewController and SFWindowController
|
||||
///
|
||||
@ -61,7 +61,7 @@ namespace sf {
|
||||
///
|
||||
/// keyDown, keyUp, textEntered
|
||||
///
|
||||
/// Note : Joysticks are not bound to a view or window
|
||||
/// Note : Joysticks are not bound to a view or window
|
||||
/// thus they're not managed by a class implementing this protocol.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -39,26 +39,26 @@ namespace priv
|
||||
size_t modeBitsPerPixel(CGDisplayModeRef mode)
|
||||
{
|
||||
size_t bpp = 0; // no match
|
||||
|
||||
|
||||
// Compare encoding.
|
||||
CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode);
|
||||
if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||
|
||||
|
||||
bpp = 32;
|
||||
|
||||
|
||||
} else if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||
|
||||
|
||||
bpp = 16;
|
||||
|
||||
|
||||
} else if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||
|
||||
|
||||
bpp = 8;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Clean up memory.
|
||||
CFRelease(pixEnc);
|
||||
|
||||
|
||||
return bpp;
|
||||
}
|
||||
#endif
|
||||
@ -69,22 +69,22 @@ size_t modeBitsPerPixel(CGDisplayModeRef mode)
|
||||
size_t displayBitsPerPixel(CGDirectDisplayID displayId)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||
|
||||
|
||||
return CGDisplayBitsPerPixel(displayId);
|
||||
|
||||
|
||||
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||
|
||||
|
||||
// Get the display mode.
|
||||
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
|
||||
|
||||
|
||||
// Get bpp for the mode.
|
||||
size_t const bpp = modeBitsPerPixel(mode);
|
||||
|
||||
|
||||
// Clean up Memory.
|
||||
CGDisplayModeRelease(mode);
|
||||
|
||||
|
||||
return bpp;
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -95,16 +95,16 @@ size_t displayBitsPerPixel(CGDirectDisplayID displayId)
|
||||
VideoMode convertCGModeToSFMode(CFDictionaryRef dictionary)
|
||||
{
|
||||
VideoMode sfmode;
|
||||
|
||||
|
||||
CFNumberRef cfnumber = (CFNumberRef)CFDictionaryGetValue(dictionary, kCGDisplayWidth);
|
||||
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.width));
|
||||
|
||||
|
||||
cfnumber = (CFNumberRef)CFDictionaryGetValue(dictionary, kCGDisplayHeight);
|
||||
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.height));
|
||||
|
||||
|
||||
cfnumber = (CFNumberRef)CFDictionaryGetValue(dictionary, kCGDisplayBitsPerPixel);
|
||||
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.bitsPerPixel));
|
||||
|
||||
|
||||
return sfmode;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ VideoMode convertCGModeToSFMode(CGDisplayModeRef cgmode)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||
|
||||
@ -139,39 +139,39 @@ CGDisplayModeRef convertSFModeToCGMode(VideoMode sfmode)
|
||||
{
|
||||
// Starting with 10.6 we should query the display all the modes and
|
||||
// search for the best one.
|
||||
|
||||
|
||||
// Will return NULL if sfmode is not in VideoMode::GetFullscreenModes.
|
||||
CGDisplayModeRef cgbestMode = NULL;
|
||||
|
||||
|
||||
// Retrieve all modes available for main screen only.
|
||||
CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
|
||||
|
||||
|
||||
if (cgmodes == NULL) { // Should not happen but anyway...
|
||||
sf::err() << "Couldn't get VideoMode for main display.";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Loop on each mode and convert it into a sf::VideoMode object.
|
||||
CFIndex const modesCount = CFArrayGetCount(cgmodes);
|
||||
for (CFIndex i = 0; i < modesCount; i++) {
|
||||
CGDisplayModeRef cgmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cgmodes, i);
|
||||
|
||||
|
||||
VideoMode mode = convertCGModeToSFMode(cgmode);
|
||||
|
||||
|
||||
if (mode == sfmode) {
|
||||
cgbestMode = cgmode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Clean up memory.
|
||||
CFRelease(cgmodes);
|
||||
|
||||
|
||||
if (cgbestMode == NULL) {
|
||||
sf::err()
|
||||
<< "Couldn't convert the given sf:VideoMode into a CGDisplayMode."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
return cgbestMode;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2013 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.
|
||||
@ -38,18 +38,18 @@ namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get bpp of a video mode for OS 10.6 or later.
|
||||
///
|
||||
///
|
||||
/// With OS 10.6 and later, Quartz doesn't use anymore dictionaries
|
||||
/// to represent video mode. Instead it uses a CGDisplayMode opaque type.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||
size_t modeBitsPerPixel(CGDisplayModeRef mode);
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get bpp for all OS X version.
|
||||
///
|
||||
///
|
||||
/// This function use only non-deprecated way to get the
|
||||
/// display bits per pixel information for a given display id.
|
||||
///
|
||||
@ -65,7 +65,7 @@ VideoMode convertCGModeToSFMode(CFDictionaryRef dictionary);
|
||||
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||
VideoMode convertCGModeToSFMode(CGDisplayModeRef cgmode);
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a sf::VideoMode object into a Quartz video mode.
|
||||
///
|
||||
@ -75,7 +75,7 @@ CFDictionaryRef convertSFModeToCGMode(VideoMode sfmode);
|
||||
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||
CGDisplayModeRef convertSFModeToCGMode(VideoMode sfmode);
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace priv
|
||||
} // namespace sf
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
|
@ -1,8 +1,8 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
|
||||
// Laurent Gomila (laurent.gom@gmail.com),
|
||||
// Copyright (C) 2007-2012 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.
|
||||
@ -37,7 +37,7 @@ NSString* stringToNSString(std::string const& string)
|
||||
std::string utf8; utf8.reserve(string.size() + 1);
|
||||
sf::Utf8::fromAnsi(string.begin(), string.end(), std::back_inserter(utf8));
|
||||
NSString* str = [NSString stringWithCString:utf8.c_str() encoding:NSUTF8StringEncoding];
|
||||
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user