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