Updated Mac OS X code according to commits ff5b69d312 and 14ac411542

This commit is contained in:
Marco Antognini 2012-03-12 09:19:07 +01:00
parent 4119c3bb31
commit 2ef92a2af2
32 changed files with 878 additions and 878 deletions

View File

@ -38,13 +38,13 @@ struct SFMLmainWindow;
@interface CocoaAppDelegate : NSObject <NSApplicationDelegate> {
@private
NSWindow *_window;
NSView *_sfmlView;
NSTextField *_textField;
SFMLmainWindow *_mainWindow;
NSTimer *_renderTimer;
BOOL _visible;
BOOL _initialized;
NSWindow *m_window;
NSView *m_sfmlView;
NSTextField *m_textField;
SFMLmainWindow *m_mainWindow;
NSTimer *m_renderTimer;
BOOL m_visible;
BOOL m_initialized;
}
@property (retain) IBOutlet NSWindow *window;

View File

@ -39,23 +39,23 @@ struct SFMLmainWindow
, background(sf::Color::Blue)
{
std::string resPath = [[[NSBundle mainBundle] resourcePath] tostdstring];
if (!logo.LoadFromFile(resPath + "/logo.png")) {
if (!logo.loadFromFile(resPath + "/logo.png")) {
NSLog(@"Couldn't load the logo image");
}
logo.SetSmooth(true);
logo.setSmooth(true);
sprite.SetTexture(logo, true);
sf::FloatRect rect = sprite.GetLocalBounds();
sf::Vector2f size(rect.Width, rect.Height);
sprite.SetOrigin(size / 2.f);
sprite.Scale(0.3, 0.3);
sprite.setTexture(logo, true);
sf::FloatRect rect = sprite.getLocalBounds();
sf::Vector2f size(rect.width, rect.height);
sprite.setOrigin(size / 2.f);
sprite.scale(0.3, 0.3);
unsigned int ww = renderWindow.GetSize().x;
unsigned int wh = renderWindow.GetSize().y;
sprite.SetPosition(sf::Vector2f(ww, wh) / 2.f);
unsigned int ww = renderWindow.getSize().x;
unsigned int wh = renderWindow.getSize().y;
sprite.setPosition(sf::Vector2f(ww, wh) / 2.f);
text.SetColor(sf::Color::White);
text.setColor(sf::Color::White);
}
sf::RenderWindow renderWindow;
@ -82,15 +82,15 @@ struct SFMLmainWindow
// Finally, the implementation
@implementation CocoaAppDelegate
@synthesize window = _window;
@synthesize sfmlView = _sfmlView;
@synthesize textField = _textField;
@synthesize window = m_window;
@synthesize sfmlView = m_sfmlView;
@synthesize textField = m_textField;
@synthesize mainWindow = _mainWindow;
@synthesize renderTimer = _renderTimer;
@synthesize visible = _visible;
@synthesize mainWindow = m_mainWindow;
@synthesize renderTimer = m_renderTimer;
@synthesize visible = m_visible;
@synthesize initialized = _initialized;
@synthesize initialized = m_initialized;
- (id)init {
self = [super init];
@ -106,7 +106,7 @@ struct SFMLmainWindow
{
// Init the SFML render area.
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;
// Launch the timer to periodically display our stuff into the Cocoa view.
@ -135,7 +135,7 @@ struct SFMLmainWindow
-(void)dealloc
{
[self.renderTimer invalidate];
self.mainWindow->renderWindow.Close();
self.mainWindow->renderWindow.close();
self.window = nil;
self.sfmlView = nil;
@ -152,27 +152,27 @@ struct SFMLmainWindow
{
// Scaling
/* /!\ we do this at 60fps so choose low scaling factor! /!\ */
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
self.mainWindow->sprite.Scale(1.01, 1.01);
self.mainWindow->sprite.scale(1.01f, 1.01f);
}
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Down))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
self.mainWindow->sprite.Scale(0.99, 0.99);
self.mainWindow->sprite.scale(0.99f, 0.99f);
}
// Clear the window, display some stuff and display it into our view.
self.mainWindow->renderWindow.Clear(self.mainWindow->background);
self.mainWindow->renderWindow.clear(self.mainWindow->background);
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();
}
-(IBAction)colorChanged:(NSPopUpButton *)sender
@ -201,7 +201,7 @@ struct SFMLmainWindow
if (self.initialized)
{
float angle = [sender floatValue];
self.mainWindow->sprite.SetRotation(angle);
self.mainWindow->sprite.setRotation(angle);
}
}
@ -214,7 +214,7 @@ struct SFMLmainWindow
-(IBAction)textChanged:(NSTextField *)sender
{
if (self.initialized)
self.mainWindow->text.SetString([[sender stringValue] tostdwstring]);
self.mainWindow->text.setString([[sender stringValue] tostdwstring]);
}
- (IBAction)updateText:(NSButton *)sender

View File

@ -33,7 +33,7 @@
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];

View File

@ -30,7 +30,7 @@
/// See SPECIAL CONSIDERATION in implementation file.
///
////////////////////////////////////////////////////////////
void RetainPool(void);
void retainPool(void);
////////////////////////////////////////////////////////////
/// \brief Release the pool.
@ -39,13 +39,13 @@ void RetainPool(void);
/// See SPECIAL CONSIDERATION in implementation file.
///
////////////////////////////////////////////////////////////
void ReleasePool(void);
void releasePool(void);
////////////////////////////////////////////////////////////
/// \brief Drain the pool.
///
/// ReleasePool must be called at least once before DrainPool.
/// releasePool must be called at least once before drainPool.
///
////////////////////////////////////////////////////////////
void DrainPool();
void drainPool();

View File

@ -44,8 +44,8 @@
///
/// SPECIAL CONSIDERATION :
/// =======================
/// This implies that if RetainPool is called X times in a thread Y then
/// ReleasePool must be called X times too in the same thread Y.
/// This implies that if retainPool is called X times in a thread Y then
/// releasePool must be called X times too in the same thread Y.
///
////////////////////////////////////////////////////////////
@ -76,13 +76,13 @@ public :
/// \brief Increment retain count and allocate memory if needed
///
////////////////////////////////////////////////////////////
void Retain();
void retain();
////////////////////////////////////////////////////////////
/// \brief Decrement retain count and releasing memory if needed
///
////////////////////////////////////////////////////////////
void Release();
void release();
////////////////////////////////////////////////////////////
/// \brief Drain the pool
@ -95,15 +95,15 @@ private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
int count; ///< How many times was the pool retained ?
NSAutoreleasePool* pool; ///< Our dedicated pool
int m_count; ///< How many times was the pool retained ?
NSAutoreleasePool* m_pool; ///< Our dedicated pool
};
////////////////////////////////////////////////////////////
PoolWrapper::PoolWrapper()
: count(0)
, pool(0)
: m_count(0)
, m_pool(0)
{
/* Nothing else */
}
@ -113,65 +113,65 @@ PoolWrapper::PoolWrapper()
PoolWrapper::~PoolWrapper()
{
#ifdef SFML_DEBUG
if (count < 0) {
sf::Err() << "~PoolWrapper : count is less than zero! "
"You called ReleasePool from a thread too many times."
if (m_count < 0) {
sf::err() << "~PoolWrapper : m_count is less than zero! "
"You called releasePool from a thread too many times."
<< std::endl;
} else if (count > 0) {
sf::Err() << "~PoolWrapper : count is greater than zero! "
"You called ReleasePool from a thread to few times."
} else if (m_count > 0) {
sf::err() << "~PoolWrapper : m_count is greater than zero! "
"You called releasePool from a thread to few times."
<< std::endl;
} else { // count == 0
sf::Err() << "~PoolWrapper is HAPPY!" << std::endl;
} else { // m_count == 0
sf::err() << "~PoolWrapper is HAPPY!" << std::endl;
}
#endif
}
////////////////////////////////////////////////////////////
void PoolWrapper::Retain()
void PoolWrapper::retain()
{
// Increase counter.
++count;
++m_count;
// Allocate pool if required.
if (pool == 0) {
pool = [[NSAutoreleasePool alloc] init];
if (m_pool == 0) {
m_pool = [[NSAutoreleasePool alloc] init];
}
#ifdef SFML_DEBUG
if (count <= 0) {
sf::Err() << "PoolWrapper::Retain : count <= 0! " << std::endl;
if (m_count <= 0) {
sf::err() << "PoolWrapper::retain : m_count <= 0! " << std::endl;
}
#endif
}
////////////////////////////////////////////////////////////
void PoolWrapper::Release()
void PoolWrapper::release()
{
// Decrease counter.
--count;
--m_count;
// Drain pool if required.
if (count == 0) {
if (m_count == 0) {
Drain();
}
#ifdef SFML_DEBUG
if (count < 0) {
sf::Err() << "PoolWrapper::Release : count < 0! " << std::endl;
if (m_count < 0) {
sf::err() << "PoolWrapper::release : m_count < 0! " << std::endl;
}
#endif
}
void PoolWrapper::Drain()
{
[pool drain];
pool = 0;
[m_pool drain];
m_pool = 0;
if (count != 0) {
pool = [[NSAutoreleasePool alloc] init];
if (m_count != 0) {
m_pool = [[NSAutoreleasePool alloc] init];
}
}
@ -191,7 +191,7 @@ namespace
////////////////////////////////////////////////////////////
void RetainPool(void)
void retainPool(void)
{
// First, Check that we have a valid PoolWrapper object in our local pool.
if (localPool == NULL) {
@ -199,23 +199,23 @@ void RetainPool(void)
}
// Then retains!
localPool->Retain();
localPool->retain();
}
////////////////////////////////////////////////////////////
void ReleasePool(void)
void releasePool(void)
{
#ifdef SFML_DEBUG
if (localPool == NULL) {
sf::Err() << "ReleasePool : You must call RetainPool at least once "
"in this thread before calling ReleasePool."
sf::err() << "releasePool : You must call retainPool at least once "
"in this thread before calling releasePool."
<< std::endl;
} else {
#endif
// Releases, that's all.
localPool->Release();
localPool->release();
#ifdef SFML_DEBUG
}
@ -224,14 +224,14 @@ void ReleasePool(void)
////////////////////////////////////////////////////////////
void DrainPool()
void drainPool()
{
if (localPool != NULL) {
localPool->Drain();
}
#ifdef SFML_DEBUG
else {
sf::Err() << "ReleasePool must be called at least one before DrainPool"
sf::err() << "releasePool must be called at least one before drainPool"
<< std::endl;
}
#endif

View File

@ -60,7 +60,7 @@ public :
/// \return Reference to the HIDInputManager instance
///
////////////////////////////////////////////////////////////
static HIDInputManager& GetInstance();
static HIDInputManager& getInstance();
////////////////////////////////////////////////////////////
/// \brief Check if a key is pressed
@ -70,7 +70,7 @@ public :
/// \return True if the key is pressed, false otherwise
///
////////////////////////////////////////////////////////////
bool IsKeyPressed(Keyboard::Key key);
bool isKeyPressed(Keyboard::Key key);
////////////////////////////////////////////////////////////
/// \brief Check if a mouse button is pressed
@ -80,7 +80,7 @@ public :
/// \return True if the button is pressed, false otherwise
///
////////////////////////////////////////////////////////////
bool IsMouseButtonPressed(Mouse::Button button);
bool isMouseButtonPressed(Mouse::Button button);
public :
@ -93,7 +93,7 @@ public :
/// \return the device's location ID or 0 if something went wrong
///
////////////////////////////////////////////////////////////
static long GetLocationID(IOHIDDeviceRef device);
static long getLocationID(IOHIDDeviceRef device);
////////////////////////////////////////////////////////////
/// \brief Create a mask (dictionary) for an IOHIDManager
@ -103,7 +103,7 @@ public :
/// \return a retained CFDictionaryRef
///
////////////////////////////////////////////////////////////
static CFDictionaryRef CopyDevicesMask(UInt32 page, UInt32 usage);
static CFDictionaryRef copyDevicesMask(UInt32 page, UInt32 usage);
////////////////////////////////////////////////////////////
/// Try to convert a character into a SFML key code.
@ -116,7 +116,7 @@ public :
/// US keyboard layouts.)
///
////////////////////////////////////////////////////////////
static Keyboard::Key LocalizedKeys(UniChar ch);
static Keyboard::Key localizedKeys(UniChar ch);
////////////////////////////////////////////////////////////
/// Try to convert a virtual keycode into a SFML key code.
@ -124,7 +124,7 @@ public :
/// Return sf::Keyboard::KeyCount if the keycode is unknown.
///
////////////////////////////////////////////////////////////
static Keyboard::Key NonLocalizedKeys(UniChar virtualKeycode);
static Keyboard::Key nonLocalizedKeys(UniChar virtualKeycode);
private :
@ -143,81 +143,81 @@ private :
////////////////////////////////////////////////////////////
/// \brief Initialize the keyboard part of this class
///
/// If something went wrong FreeUp is called
/// If something went wrong freeUp is called
///
////////////////////////////////////////////////////////////
void InitializeKeyboard();
void initializeKeyboard();
////////////////////////////////////////////////////////////
/// \brief Initialize the mouse part of this class
///
/// If something went wrong FreeUp is called
/// If something went wrong freeUp is called
///
////////////////////////////////////////////////////////////
void InitializeMouse();
void initializeMouse();
////////////////////////////////////////////////////////////
/// \brief Load the given keyboard into myKeys
/// \brief Load the given keyboard into m_keys
///
/// If the given keyboard has no key this function simply
/// returns. FreeUp is _not_ called because this is not fatal.
/// returns. freeUp is _not_ called because this is not fatal.
///
/// \param keyboard Keyboard to load
///
////////////////////////////////////////////////////////////
void LoadKeyboard(IOHIDDeviceRef keyboard);
void loadKeyboard(IOHIDDeviceRef keyboard);
////////////////////////////////////////////////////////////
/// \brief Load the given mouse into myButtons
/// \brief Load the given mouse into m_buttons
///
/// If the given mouse has no button this function simply
/// returns. FreeUp is _not_ called because this is not fatal.
/// returns. freeUp is _not_ called because this is not fatal.
///
/// \param mouse Mouse to load
///
////////////////////////////////////////////////////////////
void LoadMouse(IOHIDDeviceRef mouse);
void loadMouse(IOHIDDeviceRef mouse);
////////////////////////////////////////////////////////////
/// \brief Load the given key into myKeys
/// \brief Load the given key into m_keys
///
/// FreeUp is _not_ called by this function.
/// freeUp is _not_ called by this function.
///
/// \param key Key to load
///
////////////////////////////////////////////////////////////
void LoadKey(IOHIDElementRef key);
void loadKey(IOHIDElementRef key);
////////////////////////////////////////////////////////////
/// \brief Load the given button into myButtons
/// \brief Load the given button into m_buttons
///
/// FreeUp is _not_ called by this function.
/// freeUp is _not_ called by this function.
///
/// \param button Button to load
///
////////////////////////////////////////////////////////////
void LoadButton(IOHIDElementRef button);
void loadButton(IOHIDElementRef button);
////////////////////////////////////////////////////////////
/// \brief Release all resources
///
/// Close all connections to any devices, if required
/// Set amIValid to false
/// Set m_isValid to false
///
////////////////////////////////////////////////////////////
void FreeUp();
void freeUp();
////////////////////////////////////////////////////////////
/// \brief Filter the devices and return them.
///
/// FreeUp is _not_ called by this function.
/// freeUp is _not_ called by this function.
///
/// \param page HID page like kHIDPage_GenericDesktop
/// \param usage HID usage page like kHIDUsage_GD_Keyboard or kHIDUsage_GD_Mouse
/// \return a retained CFSetRef of IOHIDDeviceRef or NULL
///
////////////////////////////////////////////////////////////
CFSetRef CopyDevices(UInt32 page, UInt32 usage);
CFSetRef copyDevices(UInt32 page, UInt32 usage);
////////////////////////////////////////////////////////////
/// \brief Converte a HID key usage to its corresponding virtual code
@ -229,30 +229,30 @@ private :
/// or 0xff if it is associate with no virtual code
///
////////////////////////////////////////////////////////////
static UInt8 UsageToVirtualCode(UInt32 usage);
static UInt8 usageToVirtualCode(UInt32 usage);
private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
bool amIValid; ///< If any error occurs this variable is false
CFDataRef myLayoutData; ///< CFData containing the layout
UCKeyboardLayout* myLayout; ///< Current Keyboard Layout
IOHIDManagerRef myManager; ///< HID Manager
bool m_isValid; ///< If any error occurs this variable is false
CFDataRef m_layoutData; ///< CFData containing the layout
UCKeyboardLayout* m_layout; ///< Current Keyboard Layout
IOHIDManagerRef m_manager; ///< HID Manager
typedef std::vector<IOHIDElementRef> IOHIDElements;
IOHIDElements myKeys[Keyboard::KeyCount]; ///< All the keys on any connected keyboard
IOHIDElements myButtons[Mouse::ButtonCount];///< All the buttons on any connected mouse
IOHIDElements m_keys[Keyboard::KeyCount]; ///< All the keys on any connected keyboard
IOHIDElements m_buttons[Mouse::ButtonCount];///< All the buttons on any connected mouse
////////////////////////////////////////////////////////////
/// myKeys' index corresponds to sf::Keyboard::Key enum.
/// if no key is assigned with key XYZ then myKeys[XYZ].size() == 0.
/// m_keys' index corresponds to sf::Keyboard::Key enum.
/// if no key is assigned with key XYZ then m_keys[XYZ].size() == 0.
/// if there are several keyboards connected and several HID keys associate
/// with the same sf::Keyboard::Key then myKeys[XYZ] contains all these
/// with the same sf::Keyboard::Key then m_keys[XYZ] contains all these
/// HID keys.
///
/// myButtons works the same way.
/// m_buttons works the same way.
///
////////////////////////////////////////////////////////////
};
@ -261,4 +261,4 @@ private :
} // namespace sf
#endif
#endif

View File

@ -35,7 +35,7 @@ namespace sf
namespace priv
{
////////////////////////////////////////////////////////////
HIDInputManager& HIDInputManager::GetInstance()
HIDInputManager& HIDInputManager::getInstance()
{
static HIDInputManager instance;
return instance;
@ -43,17 +43,17 @@ HIDInputManager& HIDInputManager::GetInstance()
////////////////////////////////////////////////////////////
bool HIDInputManager::IsKeyPressed(Keyboard::Key key)
bool HIDInputManager::isKeyPressed(Keyboard::Key key)
{
if (!amIValid) {
sf::Err() << "HIDInputManager is invalid." << std::endl;
if (!m_isValid) {
sf::err() << "HIDInputManager is invalid." << std::endl;
return false;
}
// state = true if at least one corresponding HID key is pressed
bool state = false;
for (IOHIDElements::iterator it = myKeys[key].begin(); it != myKeys[key].end(); ++it) {
for (IOHIDElements::iterator it = m_keys[key].begin(); it != m_keys[key].end(); ++it) {
IOHIDValueRef value = 0;
@ -66,7 +66,7 @@ bool HIDInputManager::IsKeyPressed(Keyboard::Key key)
// element from our keys
CFRelease(*it);
it = myKeys[key].erase(it);
it = m_keys[key].erase(it);
} else if (IOHIDValueGetIntegerValue(value) == 1) {
@ -85,17 +85,17 @@ bool HIDInputManager::IsKeyPressed(Keyboard::Key key)
}
////////////////////////////////////////////////////////////
bool HIDInputManager::IsMouseButtonPressed(Mouse::Button button)
bool HIDInputManager::isMouseButtonPressed(Mouse::Button button)
{
if (!amIValid) {
sf::Err() << "HIDInputManager is invalid." << std::endl;
if (!m_isValid) {
sf::err() << "HIDInputManager is invalid." << std::endl;
return false;
}
// state = true if at least one corresponding HID button is pressed
bool state = false;
for (IOHIDElements::iterator it = myButtons[button].begin(); it != myButtons[button].end(); ++it) {
for (IOHIDElements::iterator it = m_buttons[button].begin(); it != m_buttons[button].end(); ++it) {
IOHIDValueRef value = 0;
@ -108,7 +108,7 @@ bool HIDInputManager::IsMouseButtonPressed(Mouse::Button button)
// element from our buttons
CFRelease(*it);
it = myButtons[button].erase(it);
it = m_buttons[button].erase(it);
} else if (IOHIDValueGetIntegerValue(value) == 1) {
@ -128,7 +128,7 @@ bool HIDInputManager::IsMouseButtonPressed(Mouse::Button button)
////////////////////////////////////////////////////////////
long HIDInputManager::GetLocationID(IOHIDDeviceRef device)
long HIDInputManager::getLocationID(IOHIDDeviceRef device)
{
long loc = 0;
@ -150,7 +150,7 @@ long HIDInputManager::GetLocationID(IOHIDDeviceRef device)
////////////////////////////////////////////////////////////
CFDictionaryRef HIDInputManager::CopyDevicesMask(UInt32 page, UInt32 usage)
CFDictionaryRef HIDInputManager::copyDevicesMask(UInt32 page, UInt32 usage)
{
// Create the dictionary.
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
@ -173,53 +173,53 @@ CFDictionaryRef HIDInputManager::CopyDevicesMask(UInt32 page, UInt32 usage)
////////////////////////////////////////////////////////////
HIDInputManager::HIDInputManager()
: amIValid(true)
, myLayoutData(0)
, myLayout(0)
, myManager(0)
: m_isValid(true)
, m_layoutData(0)
, m_layout(0)
, m_manager(0)
{
// Get the current keyboard layout
TISInputSourceRef tis = TISCopyCurrentKeyboardLayoutInputSource();
myLayoutData = (CFDataRef)TISGetInputSourceProperty(tis,
m_layoutData = (CFDataRef)TISGetInputSourceProperty(tis,
kTISPropertyUnicodeKeyLayoutData);
if (myLayoutData == 0) {
sf::Err() << "Cannot get the keyboard layout" << std::endl;
FreeUp();
if (m_layoutData == 0) {
sf::err() << "Cannot get the keyboard layout" << std::endl;
freeUp();
return;
}
// Keep a reference for ourself
CFRetain(myLayoutData);
myLayout = (UCKeyboardLayout *)CFDataGetBytePtr(myLayoutData);
CFRetain(m_layoutData);
m_layout = (UCKeyboardLayout *)CFDataGetBytePtr(m_layoutData);
// The TIS is no more needed
CFRelease(tis);
// Create an HID Manager reference
myManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
// Open the HID Manager reference
IOReturn openStatus = IOHIDManagerOpen(myManager, kIOHIDOptionsTypeNone);
IOReturn openStatus = IOHIDManagerOpen(m_manager, kIOHIDOptionsTypeNone);
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;
}
// Initialize the keyboard
InitializeKeyboard();
initializeKeyboard();
if (!amIValid) {
if (!m_isValid) {
return; // Something went wrong
}
// Initialize the mouse
InitializeMouse();
initializeMouse();
if (!amIValid) {
if (!m_isValid) {
return; // Something went wrong
}
}
@ -228,24 +228,24 @@ HIDInputManager::HIDInputManager()
////////////////////////////////////////////////////////////
HIDInputManager::~HIDInputManager()
{
FreeUp();
freeUp();
}
void HIDInputManager::InitializeKeyboard()
void HIDInputManager::initializeKeyboard()
{
////////////////////////////////////////////////////////////
// The purpose of this function is to initalize myKeys 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.
// Get only keyboards
CFSetRef keyboards = CopyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
CFSetRef keyboards = copyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
if (keyboards == NULL) {
FreeUp();
freeUp();
return;
}
CFIndex keyboardCount = CFSetGetCount(keyboards); // >= 1 (asserted by CopyDevices)
CFIndex keyboardCount = CFSetGetCount(keyboards); // >= 1 (asserted by copyDevices)
// Get an iterable array
CFTypeRef devicesArray[keyboardCount];
@ -255,32 +255,32 @@ void HIDInputManager::InitializeKeyboard()
IOHIDDeviceRef keyboard = (IOHIDDeviceRef)devicesArray[i];
LoadKeyboard(keyboard);
loadKeyboard(keyboard);
}
// Release unused stuff
CFRelease(keyboards);
////////////////////////////////////////////////////////////
// At this point myKeys is filled with as many IOHIDElementRef as possible
// At this point m_keys is filled with as many IOHIDElementRef as possible
}
////////////////////////////////////////////////////////////
void HIDInputManager::InitializeMouse()
void HIDInputManager::initializeMouse()
{
////////////////////////////////////////////////////////////
// The purpose of this function is to initalize myButtons 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.
// Get only mouses
CFSetRef mouses = CopyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse);
CFSetRef mouses = copyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse);
if (mouses == NULL) {
FreeUp();
freeUp();
return;
}
CFIndex mouseCount = CFSetGetCount(mouses); // >= 1 (asserted by CopyDevices)
CFIndex mouseCount = CFSetGetCount(mouses); // >= 1 (asserted by copyDevices)
// Get an iterable array
CFTypeRef devicesArray[mouseCount];
@ -290,25 +290,25 @@ void HIDInputManager::InitializeMouse()
IOHIDDeviceRef mouse = (IOHIDDeviceRef)devicesArray[i];
LoadMouse(mouse);
loadMouse(mouse);
}
// Release unused stuff
CFRelease(mouses);
////////////////////////////////////////////////////////////
// At this point myButtons 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,
NULL,
kIOHIDOptionsTypeNone);
if (keys == NULL) {
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;
}
@ -316,7 +316,7 @@ void HIDInputManager::LoadKeyboard(IOHIDDeviceRef keyboard)
CFIndex keysCount = CFArrayGetCount(keys);
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);
return;
}
@ -331,7 +331,7 @@ void HIDInputManager::LoadKeyboard(IOHIDDeviceRef keyboard)
continue;
}
LoadKey(aKey);
loadKey(aKey);
}
@ -341,13 +341,13 @@ void HIDInputManager::LoadKeyboard(IOHIDDeviceRef keyboard)
////////////////////////////////////////////////////////////
void HIDInputManager::LoadMouse(IOHIDDeviceRef mouse)
void HIDInputManager::loadMouse(IOHIDDeviceRef mouse)
{
CFArrayRef buttons = IOHIDDeviceCopyMatchingElements(mouse,
NULL,
kIOHIDOptionsTypeNone);
if (buttons == NULL) {
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;
}
@ -355,7 +355,7 @@ void HIDInputManager::LoadMouse(IOHIDDeviceRef mouse)
CFIndex buttonCount = CFArrayGetCount(buttons);
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);
return;
}
@ -370,7 +370,7 @@ void HIDInputManager::LoadMouse(IOHIDDeviceRef mouse)
continue;
}
LoadButton(aButton);
loadButton(aButton);
}
// Release unused stuff
@ -379,11 +379,11 @@ void HIDInputManager::LoadMouse(IOHIDDeviceRef mouse)
////////////////////////////////////////////////////////////
void HIDInputManager::LoadKey(IOHIDElementRef key)
void HIDInputManager::loadKey(IOHIDElementRef key)
{
// Get its virtual code
UInt32 usageCode = IOHIDElementGetUsage(key);
UInt8 virtualCode = UsageToVirtualCode(usageCode);
UInt8 virtualCode = usageToVirtualCode(usageCode);
if (virtualCode == 0xff) {
return; // no corresponding virtual code -> skip
@ -393,14 +393,14 @@ void HIDInputManager::LoadKey(IOHIDElementRef key)
// the current keyboard layout
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 actualStringLength = 0;
UniChar unicodeString[maxStringLength];
OSStatus error;
error = UCKeyTranslate(myLayout, // current layout
error = UCKeyTranslate(m_layout, // current layout
virtualCode, // our key
kUCKeyActionDown, // or kUCKeyActionUp ?
0x100, // no modifiers
@ -420,13 +420,13 @@ void HIDInputManager::LoadKey(IOHIDElementRef key)
// First we look if the key down is from a list of characters
// that depend on keyboard localization
if (actualStringLength > 0) {
code = LocalizedKeys(unicodeString[0]);
code = localizedKeys(unicodeString[0]);
}
// The key is not a localized one so we try to find a
// corresponding code through virtual key code
if (code == Keyboard::KeyCount) {
code = NonLocalizedKeys(virtualCode);
code = nonLocalizedKeys(virtualCode);
}
// A code was found, wonderful!
@ -435,10 +435,10 @@ void HIDInputManager::LoadKey(IOHIDElementRef key)
// Ok, everything went fine. Now we have a unique
// corresponding sf::Keyboard::Key to one IOHIDElementRef
myKeys[code].push_back(key);
m_keys[code].push_back(key);
// And don't forget to keep the reference alive for our usage
CFRetain(myKeys[code].back());
CFRetain(m_keys[code].back());
}
@ -456,7 +456,7 @@ void HIDInputManager::LoadKey(IOHIDElementRef key)
// 0x4c | 0x77 | Select
//if (code == Keyboard::KeyCount) { // 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
// << (UInt32)virtualCode
// << " and HID usage code is 0x"
@ -469,7 +469,7 @@ void HIDInputManager::LoadKey(IOHIDElementRef key)
} /* if (error == noErr) */
else {
sf::Err() << "Cannot translate the virtual key code, error : "
sf::err() << "Cannot translate the virtual key code, error : "
<< error
<< std::endl;
}
@ -477,7 +477,7 @@ void HIDInputManager::LoadKey(IOHIDElementRef key)
////////////////////////////////////////////////////////////
void HIDInputManager::LoadButton(IOHIDElementRef button)
void HIDInputManager::loadButton(IOHIDElementRef button)
{
// Identify the button
UInt32 usage = IOHIDElementGetUsage(button);
@ -498,51 +498,51 @@ void HIDInputManager::LoadButton(IOHIDElementRef button)
if (dest != Mouse::ButtonCount) {
// We know what kind of button it is!
myButtons[dest].push_back(button);
m_buttons[dest].push_back(button);
// And don't forget to keep the reference alive for our usage
CFRetain(myButtons[dest].back());
CFRetain(m_buttons[dest].back());
}
}
////////////////////////////////////////////////////////////
void HIDInputManager::FreeUp()
void HIDInputManager::freeUp()
{
amIValid = false;
m_isValid = false;
if (myLayoutData != 0) CFRelease(myLayoutData);
// Do not release myLayout ! It is owned by myLayoutData.
if (myManager != 0) CFRelease(myManager);
if (m_layoutData != 0) CFRelease(m_layoutData);
// Do not release m_layout ! It is owned by m_layoutData.
if (m_manager != 0) CFRelease(m_manager);
for (unsigned int i = 0; i < Keyboard::KeyCount; ++i) {
for (IOHIDElements::iterator it = myKeys[i].begin(); it != myKeys[i].end(); ++it) {
for (IOHIDElements::iterator it = m_keys[i].begin(); it != m_keys[i].end(); ++it) {
CFRelease(*it);
}
myKeys[i].clear();
m_keys[i].clear();
}
for (unsigned int i = 0; i < Mouse::ButtonCount; ++i) {
for (IOHIDElements::iterator it = myButtons[i].begin(); it != myButtons[i].end(); ++it) {
for (IOHIDElements::iterator it = m_buttons[i].begin(); it != m_buttons[i].end(); ++it) {
CFRelease(*it);
}
myButtons[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
CFDictionaryRef mask = CopyDevicesMask(page, usage);
CFDictionaryRef mask = copyDevicesMask(page, usage);
IOHIDManagerSetDeviceMatching(myManager, mask);
IOHIDManagerSetDeviceMatching(m_manager, mask);
CFRelease(mask);
mask = 0;
CFSetRef devices = IOHIDManagerCopyDevices(myManager);
CFSetRef devices = IOHIDManagerCopyDevices(m_manager);
if (devices == NULL) {
return NULL;
}
@ -559,7 +559,7 @@ CFSetRef HIDInputManager::CopyDevices(UInt32 page, UInt32 usage)
////////////////////////////////////////////////////////////
UInt8 HIDInputManager::UsageToVirtualCode(UInt32 usage)
UInt8 HIDInputManager::usageToVirtualCode(UInt32 usage)
{
// Some usage key doesn't have any corresponding virtual
// code or it was not found (return 0xff).
@ -765,7 +765,7 @@ UInt8 HIDInputManager::UsageToVirtualCode(UInt32 usage)
////////////////////////////////////////////////////////
Keyboard::Key HIDInputManager::LocalizedKeys(UniChar ch)
Keyboard::Key HIDInputManager::localizedKeys(UniChar ch)
{
switch (ch) {
case 'a':
@ -853,7 +853,7 @@ Keyboard::Key HIDInputManager::LocalizedKeys(UniChar ch)
////////////////////////////////////////////////////////
Keyboard::Key HIDInputManager::NonLocalizedKeys(UniChar virtualKeycode)
Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode)
{
// (Some) 0x code based on http://forums.macrumors.com/showthread.php?t=780577
// Some sf::Keyboard::Key are present twice.

View File

@ -36,7 +36,7 @@ namespace
{
// Using a custom run loop mode solve some issues that appears when SFML
// is used with Cocoa.
CFStringRef const runLoopMode = CFSTR("SFML_RUN_LOOP_MODE");
CFStringRef const RunLoopMode = CFSTR("SFML_RUN_LOOP_MODE");
}
@ -45,7 +45,7 @@ namespace sf
namespace priv
{
////////////////////////////////////////////////////////////
HIDJoystickManager& HIDJoystickManager::GetInstance()
HIDJoystickManager& HIDJoystickManager::getInstance()
{
static HIDJoystickManager manager;
return manager;
@ -53,32 +53,32 @@ HIDJoystickManager& HIDJoystickManager::GetInstance()
////////////////////////////////////////////////////////////
unsigned int HIDJoystickManager::GetJoystickCount()
unsigned int HIDJoystickManager::getJoystickCount()
{
Update();
return myJoystickCount;
update();
return m_joystickCount;
}
////////////////////////////////////////////////////////////
CFSetRef HIDJoystickManager::CopyJoysticks()
CFSetRef HIDJoystickManager::copyJoysticks()
{
CFSetRef devices = IOHIDManagerCopyDevices(myHIDManager);
CFSetRef devices = IOHIDManagerCopyDevices(m_manager);
return devices;
}
////////////////////////////////////////////////////////////
HIDJoystickManager::HIDJoystickManager()
: myHIDManager(0)
, myJoystickCount(0)
: m_manager(0)
, m_joystickCount(0)
{
myHIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
CFDictionaryRef mask0 = HIDInputManager::CopyDevicesMask(kHIDPage_GenericDesktop,
CFDictionaryRef mask0 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop,
kHIDUsage_GD_Joystick);
CFDictionaryRef mask1 = HIDInputManager::CopyDevicesMask(kHIDPage_GenericDesktop,
CFDictionaryRef mask1 = HIDInputManager::copyDevicesMask(kHIDPage_GenericDesktop,
kHIDUsage_GD_GamePad);
CFDictionaryRef maskArray[2];
@ -87,44 +87,44 @@ HIDJoystickManager::HIDJoystickManager()
CFArrayRef mask = CFArrayCreate(NULL, (const void**)maskArray, 2, NULL);
IOHIDManagerSetDeviceMatchingMultiple(myHIDManager, mask);
IOHIDManagerSetDeviceMatchingMultiple(m_manager, mask);
CFRelease(mask);
CFRelease(mask1);
CFRelease(mask0);
IOHIDManagerRegisterDeviceMatchingCallback(myHIDManager, pluggedIn, this);
IOHIDManagerRegisterDeviceRemovalCallback(myHIDManager, pluggedOut, this);
IOHIDManagerRegisterDeviceMatchingCallback(m_manager, pluggedIn, this);
IOHIDManagerRegisterDeviceRemovalCallback(m_manager, pluggedOut, this);
IOHIDManagerScheduleWithRunLoop(myHIDManager,
IOHIDManagerScheduleWithRunLoop(m_manager,
CFRunLoopGetCurrent(),
runLoopMode);
RunLoopMode);
IOHIDManagerOpen(myHIDManager, kIOHIDOptionsTypeNone);
IOHIDManagerOpen(m_manager, kIOHIDOptionsTypeNone);
}
////////////////////////////////////////////////////////////
HIDJoystickManager::~HIDJoystickManager()
{
IOHIDManagerUnscheduleFromRunLoop(myHIDManager,
IOHIDManagerUnscheduleFromRunLoop(m_manager,
CFRunLoopGetCurrent(),
runLoopMode);
RunLoopMode);
IOHIDManagerRegisterDeviceMatchingCallback(myHIDManager, NULL, 0);
IOHIDManagerRegisterDeviceRemovalCallback(myHIDManager, NULL, 0);
IOHIDManagerRegisterDeviceMatchingCallback(m_manager, NULL, 0);
IOHIDManagerRegisterDeviceRemovalCallback(m_manager, NULL, 0);
IOHIDManagerClose(myHIDManager, kIOHIDOptionsTypeNone);
IOHIDManagerClose(m_manager, kIOHIDOptionsTypeNone);
}
////////////////////////////////////////////////////////////
void HIDJoystickManager::Update()
void HIDJoystickManager::update()
{
SInt32 status = kCFRunLoopRunHandledSource;
while (status == kCFRunLoopRunHandledSource) {
status = CFRunLoopRunInMode(runLoopMode, 0, true);
status = CFRunLoopRunInMode(RunLoopMode, 0, true);
}
}
@ -133,7 +133,7 @@ void HIDJoystickManager::Update()
void HIDJoystickManager::pluggedIn(void * context, IOReturn, void *, IOHIDDeviceRef)
{
HIDJoystickManager* manager = (HIDJoystickManager*)context;
manager->myJoystickCount++;
manager->m_joystickCount++;
}
@ -141,7 +141,7 @@ void HIDJoystickManager::pluggedIn(void * context, IOReturn, void *, IOHIDDevice
void HIDJoystickManager::pluggedOut(void * context, IOReturn, void *, IOHIDDeviceRef)
{
HIDJoystickManager* manager = (HIDJoystickManager*)context;
manager->myJoystickCount--;
manager->m_joystickCount--;
}

View File

@ -55,7 +55,7 @@ public:
/// \return Reference to the HIDJoystickManager instance
///
////////////////////////////////////////////////////////////
static HIDJoystickManager& GetInstance();
static HIDJoystickManager& getInstance();
public:
@ -63,7 +63,7 @@ public:
/// \brief Get the number of currently connected joystick
///
////////////////////////////////////////////////////////////
unsigned int GetJoystickCount();
unsigned int getJoystickCount();
////////////////////////////////////////////////////////////
/// \brief Copy the devices assosiated with this HID manager
@ -71,7 +71,7 @@ public:
/// \return a retained CFSetRef of IOHIDDeviceRef or NULL
///
////////////////////////////////////////////////////////////
CFSetRef CopyJoysticks();
CFSetRef copyJoysticks();
private:
@ -91,7 +91,7 @@ private:
/// \brief Make sur all event have been processed in the run loop
///
////////////////////////////////////////////////////////////
void Update();
void update();
private:
@ -116,8 +116,8 @@ private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
IOHIDManagerRef myHIDManager; ///< HID Manager
unsigned int myJoystickCount;///< Number of joysticks currently connected
IOHIDManagerRef m_manager; ///< HID Manager
unsigned int m_joystickCount;///< Number of joysticks currently connected
};
@ -125,4 +125,4 @@ private:
} // namespace sf
#endif
#endif

View File

@ -53,7 +53,7 @@ public :
/// \return True if the key is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool IsKeyPressed(Keyboard::Key key);
static bool isKeyPressed(Keyboard::Key key);
////////////////////////////////////////////////////////////
/// \brief Check if a mouse button is pressed
@ -63,7 +63,7 @@ public :
/// \return True if the button is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool IsMouseButtonPressed(Mouse::Button button);
static bool isMouseButtonPressed(Mouse::Button button);
////////////////////////////////////////////////////////////
/// \brief Get the current position of the mouse in desktop coordinates
@ -74,7 +74,7 @@ public :
/// \return Current position of the mouse
///
////////////////////////////////////////////////////////////
static Vector2i GetMousePosition();
static Vector2i getMousePosition();
////////////////////////////////////////////////////////////
/// \brief Get the current position of the mouse in window coordinates
@ -88,7 +88,7 @@ public :
/// \return Current position of the mouse
///
////////////////////////////////////////////////////////////
static Vector2i GetMousePosition(const Window& relativeTo);
static Vector2i getMousePosition(const Window& relativeTo);
////////////////////////////////////////////////////////////
/// \brief Set the current position of the mouse in desktop coordinates
@ -100,7 +100,7 @@ public :
/// \param position New position of the mouse
///
////////////////////////////////////////////////////////////
static void SetMousePosition(const Vector2i& position);
static void setMousePosition(const Vector2i& position);
////////////////////////////////////////////////////////////
/// \brief Set the current position of the mouse in window coordinates
@ -113,7 +113,7 @@ public :
/// \param relativeTo Reference window
///
////////////////////////////////////////////////////////////
static void SetMousePosition(const Vector2i& position, const Window& relativeTo);
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
};
} // namespace priv

View File

@ -55,9 +55,9 @@ namespace priv
/// \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 ...
SFOpenGLView* view = nil;
@ -68,7 +68,7 @@ SFOpenGLView* GetSFOpenGLViewFromSFMLWindow(const Window& window)
// Subview doesn't match ?
if (![view isKindOfClass:[SFOpenGLView class]]) {
sf::Err() << "The content view is not a valid SFOpenGLView"
sf::err() << "The content view is not a valid SFOpenGLView"
<< std::endl;
view = nil;
}
@ -85,13 +85,13 @@ SFOpenGLView* GetSFOpenGLViewFromSFMLWindow(const Window& window)
// No matching subview ?
if (view == nil) {
sf::Err() << "Cannot find a valid SFOpenGLView subview." << std::endl;
sf::err() << "Cannot find a valid SFOpenGLView subview." << std::endl;
}
} else {
if (nsHandle != 0) {
sf::Err() << "The system handle is neither a <NSWindow*> nor <NSView*>"
sf::err() << "The system handle is neither a <NSWindow*> nor <NSView*>"
<< "object. This shouldn't happen."
<< std::endl;
} else {
@ -104,34 +104,34 @@ SFOpenGLView* GetSFOpenGLViewFromSFMLWindow(const Window& window)
}
////////////////////////////////////////////////////////////
bool InputImpl::IsKeyPressed(Keyboard::Key key)
bool InputImpl::isKeyPressed(Keyboard::Key key)
{
return HIDInputManager::GetInstance().IsKeyPressed(key);
return HIDInputManager::getInstance().isKeyPressed(key);
}
////////////////////////////////////////////////////////////
bool InputImpl::IsMouseButtonPressed(Mouse::Button button)
bool InputImpl::isMouseButtonPressed(Mouse::Button button)
{
return HIDInputManager::GetInstance().IsMouseButtonPressed(button);
return HIDInputManager::getInstance().isMouseButtonPressed(button);
}
////////////////////////////////////////////////////////////
Vector2i InputImpl::GetMousePosition()
Vector2i InputImpl::getMousePosition()
{
// Reverse Y axis to match SFML coord.
NSPoint pos = [NSEvent mouseLocation];
pos.y = sf::VideoMode::GetDesktopMode().Height - pos.y;
pos.y = sf::VideoMode::getDesktopMode().height - pos.y;
return Vector2i(pos.x, pos.y);
}
////////////////////////////////////////////////////////////
Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
{
SFOpenGLView* view = GetSFOpenGLViewFromSFMLWindow(relativeTo);
SFOpenGLView* view = getSFOpenGLViewFromSFMLWindow(relativeTo);
// No view ?
if (view == nil) {
@ -146,7 +146,7 @@ Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
////////////////////////////////////////////////////////////
void InputImpl::SetMousePosition(const Vector2i& position)
void InputImpl::setMousePosition(const Vector2i& position)
{
// Here we don't need to reverse the coordinates.
CGPoint pos = CGPointMake(position.x, position.y);
@ -163,9 +163,9 @@ 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 ?
if (view == nil) {

View File

@ -36,37 +36,37 @@ namespace sf
namespace priv
{
////////////////////////////////////////////////////////////
JoystickImpl::Location JoystickImpl::myLocationIDs[sf::Joystick::Count] = { 0 };
JoystickImpl::Location JoystickImpl::m_locationIDs[sf::Joystick::Count] = { 0 };
////////////////////////////////////////////////////////////
bool JoystickImpl::IsConnected(unsigned int index)
bool JoystickImpl::isConnected(unsigned int index)
{
bool state = false; // Is the index-th joystick connected ?
// First, let's check if the device was previously detected :
if (myLocationIDs[index] != 0) {
if (m_locationIDs[index] != 0) {
state = true;
}
// Otherwise, let's check if it is now connected :
else { // i.e., myLocationIDs[index] == 0
else { // i.e., m_locationIDs[index] == 0
// if there is more connected joystick to the HID manager than
// opened joystick devices then we find the new one.
unsigned int openedCount = 0;
for (unsigned int i(0); i < sf::Joystick::Count; ++i) {
if (myLocationIDs[i] != 0) openedCount++;
if (m_locationIDs[i] != 0) openedCount++;
}
unsigned int connectedCount = HIDJoystickManager::GetInstance().GetJoystickCount();
unsigned int connectedCount = HIDJoystickManager::getInstance().getJoystickCount();
if (connectedCount > openedCount) {
// Get all devices
CFSetRef devices = HIDJoystickManager::GetInstance().CopyJoysticks();
CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks();
if (devices != NULL) {
@ -78,15 +78,15 @@ bool JoystickImpl::IsConnected(unsigned int index)
CFSetGetValues(devices, array);
// If there exists a device d s.t. there is no j s.t.
// myLocationIDs[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) {
IOHIDDeviceRef d = (IOHIDDeviceRef)array[didx];
Location dloc = HIDInputManager::GetLocationID(d);
Location dloc = HIDInputManager::getLocationID(d);
bool foundJ = false;
for (unsigned int j(0); j < Joystick::Count; ++j) {
if (myLocationIDs[j] == dloc) {
if (m_locationIDs[j] == dloc) {
foundJ = true;
break; // no need to loop again
}
@ -98,7 +98,7 @@ bool JoystickImpl::IsConnected(unsigned int index)
} else {
// This is a new device
// We set it up for Open(..)
myLocationIDs[index] = dloc;
m_locationIDs[index] = dloc;
state = true;
break; // We stop looking for a new device
}
@ -116,13 +116,13 @@ bool JoystickImpl::IsConnected(unsigned int index)
////////////////////////////////////////////////////////////
bool JoystickImpl::Open(unsigned int index)
bool JoystickImpl::open(unsigned int index)
{
myIndex = index;
Location deviceLoc = myLocationIDs[index]; // The device we need to load
m_index = index;
Location deviceLoc = m_locationIDs[index]; // The device we need to load
// Get all devices
CFSetRef devices = HIDJoystickManager::GetInstance().CopyJoysticks();
CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks();
if (devices == NULL) {
return false;
}
@ -136,7 +136,7 @@ bool JoystickImpl::Open(unsigned int index)
IOHIDDeviceRef self = 0;
for (CFIndex i(0); i < joysticksCount; ++i) {
IOHIDDeviceRef d = (IOHIDDeviceRef)devicesArray[i];
if (deviceLoc == HIDInputManager::GetLocationID(d)) {
if (deviceLoc == HIDInputManager::getLocationID(d)) {
self = d;
break; // We found it so we stop looping.
}
@ -178,27 +178,27 @@ bool JoystickImpl::Open(unsigned int index)
switch (IOHIDElementGetUsage(element)) {
case kHIDUsage_GD_X:
myAxis[Joystick::X] = element;
m_axis[Joystick::X] = element;
break;
case kHIDUsage_GD_Y:
myAxis[Joystick::Y] = element;
m_axis[Joystick::Y] = element;
break;
case kHIDUsage_GD_Z:
myAxis[Joystick::Z] = element;
m_axis[Joystick::Z] = element;
break;
case kHIDUsage_GD_Rx:
myAxis[Joystick::U] = element;
m_axis[Joystick::U] = element;
break;
case kHIDUsage_GD_Ry:
myAxis[Joystick::V] = element;
m_axis[Joystick::V] = element;
break;
case kHIDUsage_GD_Rz:
myAxis[Joystick::R] = element;
m_axis[Joystick::R] = element;
break;
// kHIDUsage_GD_Vx, kHIDUsage_GD_Vy, kHIDUsage_GD_Vz are ignored.
@ -206,8 +206,8 @@ bool JoystickImpl::Open(unsigned int index)
break;
case kIOHIDElementTypeInput_Button:
if (myButtons.size() < Joystick::ButtonCount) { // If we have free slot...
myButtons.push_back(element); // ...we add this element to the list
if (m_buttons.size() < Joystick::ButtonCount) { // If we have free slot...
m_buttons.push_back(element); // ...we add this element to the list
} else {
// Too many buttons. We ignore this one.
}
@ -222,10 +222,10 @@ bool JoystickImpl::Open(unsigned int index)
// Maybe kIOHIDElementTypeInput_Axis is the corresponding type but I can't test.
// Retain all these objets for personal use
for (ButtonsVector::iterator it(myButtons.begin()); it != myButtons.end(); ++it) {
for (ButtonsVector::iterator it(m_buttons.begin()); it != m_buttons.end(); ++it) {
CFRetain(*it);
}
for (AxisMap::iterator it(myAxis.begin()); it != myAxis.end(); ++it) {
for (AxisMap::iterator it(m_axis.begin()); it != m_axis.end(); ++it) {
CFRetain(it->second);
}
@ -241,34 +241,34 @@ bool JoystickImpl::Open(unsigned int index)
////////////////////////////////////////////////////////////
void JoystickImpl::Close()
void JoystickImpl::close()
{
for (ButtonsVector::iterator it(myButtons.begin()); it != myButtons.end(); ++it) {
for (ButtonsVector::iterator it(m_buttons.begin()); it != m_buttons.end(); ++it) {
CFRelease(*it);
}
myButtons.clear();
m_buttons.clear();
for (AxisMap::iterator it(myAxis.begin()); it != myAxis.end(); ++it) {
for (AxisMap::iterator it(m_axis.begin()); it != m_axis.end(); ++it) {
CFRelease(it->second);
}
myAxis.clear();
m_axis.clear();
// And we unregister this joystick
myLocationIDs[myIndex] = 0;
m_locationIDs[m_index] = 0;
}
////////////////////////////////////////////////////////////
JoystickCaps JoystickImpl::GetCapabilities() const
JoystickCaps JoystickImpl::getCapabilities() const
{
JoystickCaps caps;
// Buttons :
caps.ButtonCount = myButtons.size();
caps.buttonCount = m_buttons.size();
// Axis :
for (AxisMap::const_iterator it(myAxis.begin()); it != myAxis.end(); ++it) {
caps.Axes[it->first] = true;
for (AxisMap::const_iterator it(m_axis.begin()); it != m_axis.end(); ++it) {
caps.axes[it->first] = true;
}
return caps;
@ -276,20 +276,20 @@ JoystickCaps JoystickImpl::GetCapabilities() const
////////////////////////////////////////////////////////////
JoystickState JoystickImpl::Update()
JoystickState JoystickImpl::update()
{
static const JoystickState disconnectedState; // return this if joystick was disconnected
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.
// First, let's determine if the joystick is still connected
Location selfLoc = myLocationIDs[myIndex];
Location selfLoc = m_locationIDs[m_index];
// Get all devices
CFSetRef devices = HIDJoystickManager::GetInstance().CopyJoysticks();
CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks();
if (devices == NULL) {
return disconnectedState;
}
@ -303,7 +303,7 @@ JoystickState JoystickImpl::Update()
bool found = false;
for (CFIndex i(0); i < joysticksCount; ++i) {
IOHIDDeviceRef d = (IOHIDDeviceRef)devicesArray[i];
if (selfLoc == HIDInputManager::GetLocationID(d)) {
if (selfLoc == HIDInputManager::getLocationID(d)) {
found = true;
break; // Stop looping
}
@ -322,7 +322,7 @@ JoystickState JoystickImpl::Update()
// Update buttons' state
unsigned int i = 0;
for (ButtonsVector::iterator it(myButtons.begin()); it != myButtons.end(); ++it, ++i) {
for (ButtonsVector::iterator it(m_buttons.begin()); it != m_buttons.end(); ++it, ++i) {
IOHIDValueRef value = 0;
IOHIDDeviceGetValue(IOHIDElementGetDevice(*it), *it, &value);
@ -333,11 +333,11 @@ JoystickState JoystickImpl::Update()
}
// 1 means pressed, others mean released
state.Buttons[i] = IOHIDValueGetIntegerValue(value) == 1;
state.buttons[i] = IOHIDValueGetIntegerValue(value) == 1;
}
// Update axes' state
for (AxisMap::iterator it = myAxis.begin(); it != myAxis.end(); ++it) {
for (AxisMap::iterator it = m_axis.begin(); it != m_axis.end(); ++it) {
IOHIDValueRef value = 0;
IOHIDDeviceGetValue(IOHIDElementGetDevice(it->second), it->second, &value);
@ -363,7 +363,7 @@ JoystickState JoystickImpl::Update()
double scaledMax = 100;
double physicalValue = IOHIDValueGetScaledValue(value, kIOHIDValueScaleTypePhysical);
float scaledValue = ((physicalValue - physicalMin) * (scaledMax - scaledMin) / (physicalMax - physicalMin)) + scaledMin;
state.Axes[it->first] = scaledValue;
state.axes[it->first] = scaledValue;
}

View File

@ -54,7 +54,7 @@ public :
/// \return True if the joystick is connected, false otherwise
///
////////////////////////////////////////////////////////////
static bool IsConnected(unsigned int index);
static bool isConnected(unsigned int index);
////////////////////////////////////////////////////////////
/// \brief Open the joystick
@ -64,13 +64,13 @@ public :
/// \return True on success, false on failure
///
////////////////////////////////////////////////////////////
bool Open(unsigned int index);
bool open(unsigned int index);
////////////////////////////////////////////////////////////
/// \brief Close the joystick
///
////////////////////////////////////////////////////////////
void Close();
void close();
////////////////////////////////////////////////////////////
/// \brief Get the joystick capabilities
@ -78,7 +78,7 @@ public :
/// \return Joystick capabilities
///
////////////////////////////////////////////////////////////
JoystickCaps GetCapabilities() const;
JoystickCaps getCapabilities() const;
////////////////////////////////////////////////////////////
/// \brief Update the joystick and get its new state
@ -86,7 +86,7 @@ public :
/// \return Joystick state
///
////////////////////////////////////////////////////////////
JoystickState Update();
JoystickState update();
private :
@ -97,12 +97,12 @@ private :
typedef std::map<sf::Joystick::Axis, IOHIDElementRef> AxisMap;
typedef std::vector<IOHIDElementRef> ButtonsVector;
AxisMap myAxis; ///< Axis (IOHIDElementRef) connected to the joystick
ButtonsVector myButtons; ///< Buttons (IOHIDElementRef) connected to the joystick
unsigned int myIndex; ///< SFML index
AxisMap m_axis; ///< Axis (IOHIDElementRef) connected to the joystick
ButtonsVector m_buttons; ///< Buttons (IOHIDElementRef) connected to the joystick
unsigned int m_index; ///< SFML index
static Location myLocationIDs[sf::Joystick::Count]; ///< Global Joystick register
/// For a corresponding SFML index, myLocationIDs is either some usb
static Location m_locationIDs[sf::Joystick::Count]; ///< Global Joystick register
/// For a corresponding SFML index, m_locationIDs is either some usb
/// location or 0 if there isn't currently a connected joystick device
};

View File

@ -107,7 +107,7 @@ public:
/// \brief Display what has been rendered to the context so far
///
////////////////////////////////////////////////////////////
virtual void Display();
virtual void display();
////////////////////////////////////////////////////////////
/// \brief Enable or disable vertical synchronization
@ -120,7 +120,7 @@ public:
/// \param enabled : True to enable v-sync, false to deactivate
///
////////////////////////////////////////////////////////////
virtual void SetVerticalSyncEnabled(bool enabled);
virtual void setVerticalSyncEnabled(bool enabled);
protected:
////////////////////////////////////////////////////////////
@ -130,7 +130,7 @@ protected:
/// \return True on success, false if any error happened
///
////////////////////////////////////////////////////////////
virtual bool MakeCurrent();
virtual bool makeCurrent();
private:
////////////////////////////////////////////////////////////
@ -142,16 +142,16 @@ private:
/// \param settings Creation parameters
///
////////////////////////////////////////////////////////////
void CreateContext(SFContext* shared,
void createContext(SFContext* shared,
unsigned int bitsPerPixel,
const ContextSettings& settings);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
NSOpenGLContextRef myContext; ///< OpenGL context.
NSOpenGLViewRef myView; ///< Only for offscreen context.
NSWindowRef myWindow; ///< Only for offscreen context.
NSOpenGLContextRef m_context; ///< OpenGL context.
NSOpenGLViewRef m_view; ///< Only for offscreen context.
NSWindowRef m_window; ///< Only for offscreen context.
};
} // namespace priv

View File

@ -40,14 +40,14 @@ namespace priv
////////////////////////////////////////////////////////////
SFContext::SFContext(SFContext* shared)
: myView(0), myWindow(0)
: m_view(0), m_window(0)
{
// Ask for a pool.
RetainPool();
retainPool();
// Create the context
CreateContext(shared,
VideoMode::GetDesktopMode().BitsPerPixel,
createContext(shared,
VideoMode::getDesktopMode().bitsPerPixel,
ContextSettings(0, 0, 0));
}
@ -55,76 +55,76 @@ SFContext::SFContext(SFContext* shared)
////////////////////////////////////////////////////////////
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
const WindowImpl* owner, unsigned int bitsPerPixel)
: myView(0), myWindow(0)
: m_view(0), m_window(0)
{
// Ask for a pool.
RetainPool();
retainPool();
// Create the context.
CreateContext(shared, bitsPerPixel, settings);
createContext(shared, bitsPerPixel, settings);
// Apply context.
WindowImplCocoa const * ownerCocoa = static_cast<WindowImplCocoa const *>(owner);
ownerCocoa->ApplyContext(myContext);
ownerCocoa->applyContext(m_context);
}
////////////////////////////////////////////////////////////
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
unsigned int width, unsigned int height)
: myView(0), myWindow(0)
: m_view(0), m_window(0)
{
// Ensure the process is setup in order to create a valid window.
WindowImplCocoa::SetUpProcess();
WindowImplCocoa::setUpProcess();
// Ask for a pool.
RetainPool();
retainPool();
// 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.
myWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
m_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]; // Don't defer it!
myView = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, width, height)];
[myWindow setContentView:myView];
[myView setOpenGLContext:myContext];
[myContext setView:myView];
m_view = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, width, height)];
[m_window setContentView:m_view];
[m_view setOpenGLContext:m_context];
[m_context setView:m_view];
}
////////////////////////////////////////////////////////////
SFContext::~SFContext()
{
[myContext clearDrawable];
[myContext release];
[m_context clearDrawable];
[m_context release];
[myView release]; // Might be nil but we don't care.
[myWindow release]; // Idem.
[m_view release]; // Might be nil but we don't care.
[m_window release]; // Idem.
ReleasePool();
releasePool();
}
////////////////////////////////////////////////////////////
bool SFContext::MakeCurrent()
bool SFContext::makeCurrent()
{
[myContext makeCurrentContext];
return myContext == [NSOpenGLContext currentContext]; // Should be true.
[m_context makeCurrentContext];
return m_context == [NSOpenGLContext currentContext]; // Should be true.
}
////////////////////////////////////////////////////////////
void SFContext::Display()
void SFContext::display()
{
[myContext flushBuffer];
[m_context flushBuffer];
}
////////////////////////////////////////////////////////////
void SFContext::SetVerticalSyncEnabled(bool enabled)
void SFContext::setVerticalSyncEnabled(bool enabled)
{
// Make compiler happy
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
@ -133,12 +133,12 @@ void SFContext::SetVerticalSyncEnabled(bool enabled)
GLint swapInterval = enabled ? 1 : 0;
[myContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
[m_context setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
}
////////////////////////////////////////////////////////////
void SFContext::CreateContext(SFContext* shared,
void SFContext::createContext(SFContext* shared,
unsigned int bitsPerPixel,
const ContextSettings& settings)
{
@ -157,12 +157,12 @@ void SFContext::CreateContext(SFContext* shared,
}
attrs.push_back(NSOpenGLPFADepthSize);
attrs.push_back((NSOpenGLPixelFormatAttribute)settings.DepthBits);
attrs.push_back((NSOpenGLPixelFormatAttribute)settings.depthBits);
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
* "OpenGL Programming Guide for Mac OS X" document.
@ -183,7 +183,7 @@ void SFContext::CreateContext(SFContext* shared,
// Antialiasing level
attrs.push_back(NSOpenGLPFASamples);
attrs.push_back((NSOpenGLPixelFormatAttribute)settings.AntialiasingLevel);
attrs.push_back((NSOpenGLPixelFormatAttribute)settings.antialiasingLevel);
// No software renderer - only hardware renderer
attrs.push_back(NSOpenGLPFAAccelerated);
@ -195,26 +195,26 @@ void SFContext::CreateContext(SFContext* shared,
NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attrs[0]];
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;
}
// Use the shared context if one is given.
NSOpenGLContext* sharedContext = shared != NULL ? shared->myContext : nil;
NSOpenGLContext* sharedContext = shared != NULL ? shared->m_context : nil;
// Create the context.
myContext = [[NSOpenGLContext alloc] initWithFormat:pixFmt
m_context = [[NSOpenGLContext alloc] initWithFormat:pixFmt
shareContext:sharedContext];
if (myContext == nil) {
sf::Err() << "Error. Unable to create the context." << std::endl;
if (m_context == nil) {
sf::err() << "Error. Unable to create the context." << std::endl;
}
// Free up.
[pixFmt release];
// Save the settings. (OpenGL version is updated elsewhere.)
mySettings = settings;
m_settings = settings;
}
} // namespace priv

View File

@ -40,8 +40,8 @@ namespace sf {
/// Handle event and send them back to the requester.
///
/// In order to send correct mouse coordonate to the requester when
/// the window is in fullscreen we use myRealSize to represent the
/// back buffer size (see SFWindowController). If 'myRealSize' is
/// the window is in fullscreen we use m_realSize to represent the
/// back buffer size (see SFWindowController). If 'm_realSize' is
/// bound to its default value we don't recompute the mouse position
/// and assume it's correct.
///
@ -50,20 +50,20 @@ namespace sf {
///
////////////////////////////////////////////////////////////
@interface SFOpenGLView : NSOpenGLView {
sf::priv::WindowImplCocoa* myRequester;
BOOL myUseKeyRepeat;
NSTrackingRectTag myTrackingTag;
BOOL myMouseIsIn;
NSSize myRealSize;
sf::priv::WindowImplCocoa* m_requester;
BOOL m_useKeyRepeat;
NSTrackingRectTag m_trackingTag;
BOOL m_mouseIsIn;
NSSize m_realSize;
/// 'modifiers' state
BOOL myRightShiftWasDown;
BOOL myLeftShiftWasDown;
BOOL myRightCommandWasDown;
BOOL myLeftCommandWasDown;
BOOL myRightAlternateWasDown;
BOOL myLeftAlternateWasDown;
BOOL myControlWasDown;
BOOL m_rightShiftWasDown;
BOOL m_leftShiftWasDown;
BOOL m_rightCommandWasDown;
BOOL m_leftCommandWasDown;
BOOL m_rightAlternateWasDown;
BOOL m_leftAlternateWasDown;
BOOL m_controlWasDown;
}
////////////////////////////////////////////////////////////

View File

@ -27,7 +27,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
#include <SFML/Window/OSX/HIDInputManager.hpp> // For LocalizedKeys and NonLocalizedKeys
#include <SFML/Window/OSX/HIDInputManager.hpp> // For localizedKeys and nonLocalizedKeys
#include <SFML/System/Err.hpp>
#import <SFML/Window/OSX/SFOpenGLView.h>
@ -53,13 +53,13 @@
/// Erase (replace with 0) the given bits mask from the given data bits.
///
////////////////////////////////////////////////////////////
NSUInteger EraseMaskFromData(NSUInteger data, NSUInteger mask);
NSUInteger eraseMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////////
/// Erase (replace with 0) everything execept the given bits mask from the given data bits.
///
////////////////////////////////////////////////////////////
NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
NSUInteger keepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////////
/// SFOpenGLView class : Privates Methods Declaration
@ -95,7 +95,7 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////////
/// Convert a key down/up NSEvent into an SFML key event.
/// Based on LocalizedKeys and NonLocalizedKeys function.
/// Based on localizedKeys and nonLocalizedKeys function.
///
/// Return sf::Keyboard::KeyCount as Code if the key is unknown.
///
@ -115,15 +115,15 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
if ((self = [super initWithFrame:frameRect])) {
[self setRequesterTo:0];
[self enableKeyRepeat];
myRealSize = NSZeroSize;
m_realSize = NSZeroSize;
[self initModifiersState];
// Register for mouse-move event
myMouseIsIn = [self isMouseInside];
myTrackingTag = [self addTrackingRect:[self frame]
m_mouseIsIn = [self isMouseInside];
m_trackingTag = [self addTrackingRect:[self frame]
owner:self
userData:nil
assumeInside:myMouseIsIn];
assumeInside:m_mouseIsIn];
// Register for resize event
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
@ -140,14 +140,14 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
{
myRequester = requester;
m_requester = requester;
}
////////////////////////////////////////////////////////
-(void)setRealSize:(NSSize)newSize
{
myRealSize = newSize;
m_realSize = newSize;
}
@ -168,9 +168,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
screenCoord.y = screenHeight - screenCoord.y;
// Recompute the mouse pos if required.
if (!NSEqualSizes(myRealSize, NSZeroSize)) {
screenCoord.x = screenCoord.x / myRealSize.width * [self frame].size.width;
screenCoord.y = screenCoord.y / myRealSize.height * [self frame].size.height;
if (!NSEqualSizes(m_realSize, NSZeroSize)) {
screenCoord.x = screenCoord.x / m_realSize.width * [self frame].size.width;
screenCoord.y = screenCoord.y / m_realSize.height * [self frame].size.height;
}
// Place the cursor.
@ -188,14 +188,14 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////
-(void)enableKeyRepeat
{
myUseKeyRepeat = YES;
m_useKeyRepeat = YES;
}
////////////////////////////////////////////////////////
-(void)disableKeyRepeat
{
myUseKeyRepeat = NO;
m_useKeyRepeat = NO;
}
@ -203,32 +203,32 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
-(void)frameDidChange:(NSNotification *)notification
{
// Update mouse internal state.
BOOL mouseWasIn = myMouseIsIn;
myMouseIsIn = [self isMouseInside];
BOOL mouseWasIn = m_mouseIsIn;
m_mouseIsIn = [self isMouseInside];
// Send event if needed.
if (mouseWasIn && !myMouseIsIn) {
if (mouseWasIn && !m_mouseIsIn) {
[self mouseExited:nil];
} else if (!mouseWasIn && myMouseIsIn) {
} else if (!mouseWasIn && m_mouseIsIn) {
[self mouseEntered:nil];
}
// Adapt tracking area for mouse mouse event.
[self removeTrackingRect:myTrackingTag];
myTrackingTag = [self addTrackingRect:[self frame]
[self removeTrackingRect:m_trackingTag];
m_trackingTag = [self addTrackingRect:[self frame]
owner:self
userData:nil
assumeInside:myMouseIsIn];
assumeInside:m_mouseIsIn];
// Update the OGL view to fit the new size.
[self update];
// Send an event
if (myRequester == 0) return;
if (m_requester == 0) return;
// The new size
NSSize newSize = [self frame].size;
myRequester->WindowResized(newSize.width, newSize.height);
m_requester->windowResized(newSize.width, newSize.height);
}
@ -255,7 +255,7 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
{
// Unregister
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self removeTrackingRect:myTrackingTag];
[self removeTrackingRect:m_trackingTag];
[super dealloc];
}
@ -317,10 +317,10 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////
-(void)scrollWheel:(NSEvent *)theEvent
{
if (myRequester != 0) {
if (m_requester != 0) {
NSPoint loc = [self cursorPositionFromEvent:theEvent];
myRequester->MouseWheelScrolledAt([theEvent deltaY], loc.x, loc.y);
m_requester->mouseWheelScrolledAt([theEvent deltaY], loc.x, loc.y);
}
// Transmit to non-SFML responder
@ -331,22 +331,22 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////
-(void)mouseEntered:(NSEvent *)theEvent
{
myMouseIsIn = YES;
m_mouseIsIn = YES;
if (myRequester == 0) return;
if (m_requester == 0) return;
myRequester->MouseMovedIn();
m_requester->mouseMovedIn();
}
////////////////////////////////////////////////////////
-(void)mouseExited:(NSEvent *)theEvent
{
myMouseIsIn = NO;
m_mouseIsIn = NO;
if (myRequester == 0) return;
if (m_requester == 0) return;
myRequester->MouseMovedOut();
m_requester->mouseMovedOut();
}
@ -377,11 +377,11 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
{
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
if (myRequester != 0) {
if (m_requester != 0) {
NSPoint loc = [self cursorPositionFromEvent:theEvent];
if (button != sf::Mouse::ButtonCount) {
myRequester->MouseDownAt(button, loc.x, loc.y);
m_requester->mouseDownAt(button, loc.x, loc.y);
}
}
@ -398,11 +398,11 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
{
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
if (myRequester != 0) {
if (m_requester != 0) {
NSPoint loc = [self cursorPositionFromEvent:theEvent];
if (button != sf::Mouse::ButtonCount) {
myRequester->MouseUpAt(button, loc.x, loc.y);
m_requester->mouseUpAt(button, loc.x, loc.y);
}
}
@ -439,13 +439,13 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////
-(void)otherMouseDragged:(NSEvent *)theEvent
{
if (myRequester != 0) {
if (m_requester != 0) {
// If the event is not useful.
if (!myMouseIsIn) return;
if (!m_mouseIsIn) return;
NSPoint loc = [self cursorPositionFromEvent:theEvent];
myRequester->MouseMovedAt(loc.x, loc.y);
m_requester->mouseMovedAt(loc.x, loc.y);
}
// If the event is not forwarded by mouseDragged or rightMouseDragged...
@ -474,9 +474,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
loc.y = h - loc.y;
// Recompute the mouse pos if required.
if (!NSEqualSizes(myRealSize, NSZeroSize)) {
loc.x = loc.x * myRealSize.width / [self frame].size.width;
loc.y = loc.y * myRealSize.height / [self frame].size.height;
if (!NSEqualSizes(m_realSize, NSZeroSize)) {
loc.x = loc.x * m_realSize.width / [self frame].size.width;
loc.y = loc.y * m_realSize.height / [self frame].size.height;
}
return loc;
@ -507,14 +507,14 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
// Transmit to non-SFML responder
[[self nextResponder] keyDown:theEvent];
if (myRequester == 0) return;
if (m_requester == 0) return;
// Handle key down event
if (myUseKeyRepeat || ![theEvent isARepeat]) {
if (m_useKeyRepeat || ![theEvent isARepeat]) {
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
if (key.Code != sf::Keyboard::KeyCount) { // The key is recognized.
myRequester->KeyDown(key);
if (key.code != sf::Keyboard::KeyCount) { // The key is recognized.
m_requester->keyDown(key);
}
}
@ -538,7 +538,7 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
isARepeat:[theEvent isARepeat]
keyCode:[theEvent keyCode]];
if ((myUseKeyRepeat || ![ev isARepeat]) && [[ev characters] length] > 0) {
if ((m_useKeyRepeat || ![ev isARepeat]) && [[ev characters] length] > 0) {
// Ignore escape key and non text keycode. (See NSEvent.h)
// They produce a sound alert.
@ -552,7 +552,7 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
NSString* string = [text string];
if ([string length] > 0) {
// It's a valid TextEntered event.
myRequester->TextEntered([string characterAtIndex:0]);
m_requester->textEntered([string characterAtIndex:0]);
[text setString:@""];
}
@ -567,12 +567,12 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
// Transmit to non-SFML responder
[[self nextResponder] keyUp:theEvent];
if (myRequester == 0) return;
if (m_requester == 0) return;
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
if (key.Code != sf::Keyboard::KeyCount) { // The key is recognized.
myRequester->KeyUp(key);
if (key.code != sf::Keyboard::KeyCount) { // The key is recognized.
m_requester->keyUp(key);
}
}
@ -583,17 +583,17 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
// Transmit to non-SFML responder
[[self nextResponder] flagsChanged:theEvent];
if (myRequester == 0) return;
if (m_requester == 0) return;
NSUInteger modifiers = [theEvent modifierFlags];
// Setup a potential event key.
sf::Event::KeyEvent key;
key.Code = sf::Keyboard::KeyCount;
key.Alt = modifiers & NSAlternateKeyMask;
key.Control = modifiers & NSControlKeyMask;
key.Shift = modifiers & NSShiftKeyMask;
key.System = modifiers & NSCommandKeyMask;
key.code = sf::Keyboard::KeyCount;
key.alt = modifiers & NSAlternateKeyMask;
key.control = modifiers & NSControlKeyMask;
key.shift = modifiers & NSShiftKeyMask;
key.system = modifiers & NSCommandKeyMask;
// State
BOOL rightShiftIsDown = NO;
@ -607,26 +607,26 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
// Shift keys.
if (modifiers & NSShiftKeyMask) { // At least one shift key is down.
// Clean up modifiers to keep only 'shift' bits.
NSUInteger shift = KeepOnlyMaskFromData(modifiers, NSRightShiftKeyMask | NSLeftShiftKeyMask);
NSUInteger shift = keepOnlyMaskFromData(modifiers, NSRightShiftKeyMask | NSLeftShiftKeyMask);
// Only right shift is down ?
if (shift == NSRightShiftKeyMask) {
rightShiftIsDown = YES;
if (myLeftShiftWasDown) {
if (m_leftShiftWasDown) {
// left shift released
leftShiftIsDown = NO;
key.Code = sf::Keyboard::LShift;
myRequester->KeyUp(key);
key.code = sf::Keyboard::LShift;
m_requester->keyUp(key);
}
if (!myRightShiftWasDown) {
if (!m_rightShiftWasDown) {
// right shift pressed
key.Code = sf::Keyboard::RShift;
myRequester->KeyDown(key);
key.code = sf::Keyboard::RShift;
m_requester->keyDown(key);
}
}
@ -635,19 +635,19 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
leftShiftIsDown = YES;
if (myRightShiftWasDown) {
if (m_rightShiftWasDown) {
// right shift released
rightShiftIsDown = NO;
key.Code = sf::Keyboard::RShift;
myRequester->KeyUp(key);
key.code = sf::Keyboard::RShift;
m_requester->keyUp(key);
}
if (!myLeftShiftWasDown) {
if (!m_leftShiftWasDown) {
// left shift pressed
key.Code = sf::Keyboard::LShift;
myRequester->KeyDown(key);
key.code = sf::Keyboard::LShift;
m_requester->keyDown(key);
}
}
@ -657,18 +657,18 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
rightShiftIsDown = YES;
leftShiftIsDown = YES;
if (!myRightShiftWasDown) {
if (!m_rightShiftWasDown) {
// right shift pressed
key.Code = sf::Keyboard::RShift;
myRequester->KeyDown(key);
key.code = sf::Keyboard::RShift;
m_requester->keyDown(key);
}
if (!myLeftShiftWasDown) {
if (!m_leftShiftWasDown) {
// left shift pressed
key.Code = sf::Keyboard::LShift;
myRequester->KeyDown(key);
key.code = sf::Keyboard::LShift;
m_requester->keyDown(key);
}
}
} else { // No shift key down.
@ -676,44 +676,44 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
rightShiftIsDown = NO;
leftShiftIsDown = NO;
if (myRightShiftWasDown) {
if (m_rightShiftWasDown) {
// right shift released
key.Code = sf::Keyboard::RShift;
myRequester->KeyUp(key);
key.code = sf::Keyboard::RShift;
m_requester->keyUp(key);
}
if (myLeftShiftWasDown) {
if (m_leftShiftWasDown) {
// left shift released
key.Code = sf::Keyboard::LShift;
myRequester->KeyUp(key);
key.code = sf::Keyboard::LShift;
m_requester->keyUp(key);
}
}
// Command keys.
if (modifiers & NSCommandKeyMask) { // At least one command key is down.
// Clean up modifiers to keep only 'Command' bits.
NSUInteger command = KeepOnlyMaskFromData(modifiers, NSRightCommandKeyMask | NSLeftCommandKeyMask);
NSUInteger command = keepOnlyMaskFromData(modifiers, NSRightCommandKeyMask | NSLeftCommandKeyMask);
// Only right Command is down ?
if (command == NSRightCommandKeyMask) {
rightCommandIsDown = YES;
if (myLeftCommandWasDown) {
if (m_leftCommandWasDown) {
// left command released
leftCommandIsDown = NO;
key.Code = sf::Keyboard::LSystem;
myRequester->KeyUp(key);
key.code = sf::Keyboard::LSystem;
m_requester->keyUp(key);
}
if (!myRightCommandWasDown) {
if (!m_rightCommandWasDown) {
// right command pressed
key.Code = sf::Keyboard::RSystem;
myRequester->KeyDown(key);
key.code = sf::Keyboard::RSystem;
m_requester->keyDown(key);
}
}
@ -722,19 +722,19 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
leftCommandIsDown = YES;
if (myRightCommandWasDown) {
if (m_rightCommandWasDown) {
// right command released
rightCommandIsDown = NO;
key.Code = sf::Keyboard::RSystem;
myRequester->KeyUp(key);
key.code = sf::Keyboard::RSystem;
m_requester->keyUp(key);
}
if (!myLeftCommandWasDown) {
if (!m_leftCommandWasDown) {
// left command pressed
key.Code = sf::Keyboard::LSystem;
myRequester->KeyDown(key);
key.code = sf::Keyboard::LSystem;
m_requester->keyDown(key);
}
}
@ -744,18 +744,18 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
rightCommandIsDown = YES;
leftCommandIsDown = YES;
if (!myRightCommandWasDown) {
if (!m_rightCommandWasDown) {
// right command pressed
key.Code = sf::Keyboard::RSystem;
myRequester->KeyDown(key);
key.code = sf::Keyboard::RSystem;
m_requester->keyDown(key);
}
if (!myLeftCommandWasDown) {
if (!m_leftCommandWasDown) {
// left command pressed
key.Code = sf::Keyboard::LSystem;
myRequester->KeyDown(key);
key.code = sf::Keyboard::LSystem;
m_requester->keyDown(key);
}
}
} else { // No Command key down.
@ -763,44 +763,44 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
rightCommandIsDown = NO;
leftCommandIsDown = NO;
if (myRightCommandWasDown) {
if (m_rightCommandWasDown) {
// right command released
key.Code = sf::Keyboard::RSystem;
myRequester->KeyUp(key);
key.code = sf::Keyboard::RSystem;
m_requester->keyUp(key);
}
if (myLeftCommandWasDown) {
if (m_leftCommandWasDown) {
// left command released
key.Code = sf::Keyboard::LSystem;
myRequester->KeyUp(key);
key.code = sf::Keyboard::LSystem;
m_requester->keyUp(key);
}
}
// Alternate keys.
if (modifiers & NSAlternateKeyMask) { // At least one alternate key is down.
// Clean up modifiers to keep only 'Alternate' bits.
NSUInteger alternate = KeepOnlyMaskFromData(modifiers, NSRightAlternateKeyMask | NSLeftAlternateKeyMask);
NSUInteger alternate = keepOnlyMaskFromData(modifiers, NSRightAlternateKeyMask | NSLeftAlternateKeyMask);
// Only right Alternate is down ?
if (alternate == NSRightAlternateKeyMask) {
rightAlternateIsDown = YES;
if (myLeftAlternateWasDown) {
if (m_leftAlternateWasDown) {
// left alt released
leftAlternateIsDown = NO;
key.Code = sf::Keyboard::LAlt;
myRequester->KeyUp(key);
key.code = sf::Keyboard::LAlt;
m_requester->keyUp(key);
}
if (!myRightAlternateWasDown) {
if (!m_rightAlternateWasDown) {
// right alt pressed
key.Code = sf::Keyboard::RAlt;
myRequester->KeyDown(key);
key.code = sf::Keyboard::RAlt;
m_requester->keyDown(key);
}
}
@ -809,19 +809,19 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
leftAlternateIsDown = YES;
if (myRightAlternateWasDown) {
if (m_rightAlternateWasDown) {
// right alt released
rightAlternateIsDown = NO;
key.Code = sf::Keyboard::RAlt;
myRequester->KeyUp(key);
key.code = sf::Keyboard::RAlt;
m_requester->keyUp(key);
}
if (!myLeftAlternateWasDown) {
if (!m_leftAlternateWasDown) {
// left alt pressed
key.Code = sf::Keyboard::LAlt;
myRequester->KeyDown(key);
key.code = sf::Keyboard::LAlt;
m_requester->keyDown(key);
}
}
@ -831,18 +831,18 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
rightAlternateIsDown = YES;
leftAlternateIsDown = YES;
if (!myRightAlternateWasDown) {
if (!m_rightAlternateWasDown) {
// right alt pressed
key.Code = sf::Keyboard::RAlt;
myRequester->KeyDown(key);
key.code = sf::Keyboard::RAlt;
m_requester->keyDown(key);
}
if (!myLeftAlternateWasDown) {
if (!m_leftAlternateWasDown) {
// left alt pressed
key.Code = sf::Keyboard::LAlt;
myRequester->KeyDown(key);
key.code = sf::Keyboard::LAlt;
m_requester->keyDown(key);
}
}
} else { // No Alternate key down.
@ -850,18 +850,18 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
rightAlternateIsDown = NO;
leftAlternateIsDown = NO;
if (myRightAlternateWasDown) {
if (m_rightAlternateWasDown) {
// right alt released
key.Code = sf::Keyboard::RAlt;
myRequester->KeyUp(key);
key.code = sf::Keyboard::RAlt;
m_requester->keyUp(key);
}
if (myLeftAlternateWasDown) {
if (m_leftAlternateWasDown) {
// left alt released
key.Code = sf::Keyboard::LAlt;
myRequester->KeyUp(key);
key.code = sf::Keyboard::LAlt;
m_requester->keyUp(key);
}
}
@ -871,31 +871,31 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
controlIsDown = YES;
if (!myControlWasDown) {
if (!m_controlWasDown) {
// ctrl pressed
key.Code = sf::Keyboard::LControl;
myRequester->KeyDown(key);
key.code = sf::Keyboard::LControl;
m_requester->keyDown(key);
}
} else { // No control key down.
controlIsDown = NO;
if (myControlWasDown) {
if (m_controlWasDown) {
// ctrl released
key.Code = sf::Keyboard::LControl;
myRequester->KeyUp(key);
key.code = sf::Keyboard::LControl;
m_requester->keyUp(key);
}
}
// Update the state
myRightShiftWasDown = rightShiftIsDown;
myLeftShiftWasDown = leftShiftIsDown;
myRightCommandWasDown = rightCommandIsDown;
myLeftCommandWasDown = leftCommandIsDown;
myRightAlternateWasDown = rightAlternateIsDown;
myLeftAlternateWasDown = leftAlternateIsDown;
myControlWasDown = controlIsDown;
m_rightShiftWasDown = rightShiftIsDown;
m_leftShiftWasDown = leftShiftIsDown;
m_rightCommandWasDown = rightCommandIsDown;
m_leftCommandWasDown = leftCommandIsDown;
m_rightAlternateWasDown = rightAlternateIsDown;
m_leftAlternateWasDown = leftAlternateIsDown;
m_controlWasDown = controlIsDown;
}
@ -903,89 +903,89 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
-(void)initModifiersState
{
// Set default value to NO.
myRightShiftWasDown = NO;
myLeftShiftWasDown = NO;
myRightCommandWasDown = NO;
myLeftCommandWasDown = NO;
myRightAlternateWasDown = NO;
myLeftAlternateWasDown = NO;
myControlWasDown = NO;
m_rightShiftWasDown = NO;
m_leftShiftWasDown = NO;
m_rightCommandWasDown = NO;
m_leftCommandWasDown = NO;
m_rightAlternateWasDown = NO;
m_leftAlternateWasDown = NO;
m_controlWasDown = NO;
NSUInteger modifiers = [[NSApp currentEvent] modifierFlags];
modifiers = EraseMaskFromData(modifiers, 0x100); // We erase something useless that might be present.
modifiers = eraseMaskFromData(modifiers, 0x100); // We erase something useless that might be present.
// Shift keys.
if (modifiers & NSShiftKeyMask) { // At least one shift key is down.
// Clean up modifiers to keep only 'shift' bits.
NSUInteger shift = KeepOnlyMaskFromData(modifiers, NSRightShiftKeyMask | NSLeftShiftKeyMask);
NSUInteger shift = keepOnlyMaskFromData(modifiers, NSRightShiftKeyMask | NSLeftShiftKeyMask);
// Only right shift is down ?
if (shift == NSRightShiftKeyMask) {
myRightShiftWasDown = YES;
m_rightShiftWasDown = YES;
}
// Only left shift is down ?
if (shift == NSLeftShiftKeyMask) {
myLeftShiftWasDown = YES;
m_leftShiftWasDown = YES;
}
// Or are they both down ?
if (shift == (NSRightShiftKeyMask | NSLeftShiftKeyMask)) {
myRightShiftWasDown = YES;
myLeftShiftWasDown = YES;
m_rightShiftWasDown = YES;
m_leftShiftWasDown = YES;
}
}
// Command keys.
if (modifiers & NSCommandKeyMask) { // At least one command key is down.
// Clean up modifiers to keep only 'Command' bits.
NSUInteger command = KeepOnlyMaskFromData(modifiers, NSRightCommandKeyMask | NSLeftCommandKeyMask);
NSUInteger command = keepOnlyMaskFromData(modifiers, NSRightCommandKeyMask | NSLeftCommandKeyMask);
// Only right Command is down ?
if (command == NSRightCommandKeyMask) {
myRightCommandWasDown = YES;
m_rightCommandWasDown = YES;
}
// Only left Command is down ?
if (command == NSLeftCommandKeyMask) {
myLeftCommandWasDown = YES;
m_leftCommandWasDown = YES;
}
// Or are they both down ?
if (command == (NSRightCommandKeyMask | NSLeftCommandKeyMask)) {
myRightCommandWasDown = YES;
myLeftCommandWasDown = YES;
m_rightCommandWasDown = YES;
m_leftCommandWasDown = YES;
}
}
// Alternate keys.
if (modifiers & NSAlternateKeyMask) { // At least one alternate key is down.
// Clean up modifiers to keep only 'Alternate' bits.
NSUInteger alternate = KeepOnlyMaskFromData(modifiers, NSRightAlternateKeyMask | NSLeftAlternateKeyMask);
NSUInteger alternate = keepOnlyMaskFromData(modifiers, NSRightAlternateKeyMask | NSLeftAlternateKeyMask);
// Only right Alternate is down ?
if (alternate == NSRightAlternateKeyMask) {
myRightAlternateWasDown = YES;
m_rightAlternateWasDown = YES;
}
// Only left Alternate is down ?
if (alternate == NSLeftAlternateKeyMask) {
myLeftAlternateWasDown = YES;
m_leftAlternateWasDown = YES;
}
// Or are they both down ?
if (alternate == (NSRightAlternateKeyMask | NSLeftAlternateKeyMask)) {
myRightAlternateWasDown = YES;
myLeftAlternateWasDown = YES;
m_rightAlternateWasDown = YES;
m_leftAlternateWasDown = YES;
}
}
@ -994,7 +994,7 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
if (modifiers & NSControlKeyMask) {
// Currently only the left control key will be used in SFML (see note above).
myControlWasDown = YES;
m_controlWasDown = YES;
}
}
@ -1006,30 +1006,30 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
// Modifiers.
NSUInteger modifierFlags = [anEvent modifierFlags];
key.Alt = modifierFlags & NSAlternateKeyMask;
key.Control = modifierFlags & NSControlKeyMask;
key.Shift = modifierFlags & NSShiftKeyMask;
key.System = modifierFlags & NSCommandKeyMask;
key.alt = modifierFlags & NSAlternateKeyMask;
key.control = modifierFlags & NSControlKeyMask;
key.shift = modifierFlags & NSShiftKeyMask;
key.system = modifierFlags & NSCommandKeyMask;
// Key code.
key.Code = sf::Keyboard::KeyCount;
key.code = sf::Keyboard::KeyCount;
// First we look if the key down is from a list of caracter
// that depend on keyboard localization.
NSString* string = [anEvent charactersIgnoringModifiers];
if ([string length] > 0) {
key.Code = sf::priv::HIDInputManager::LocalizedKeys([string characterAtIndex:0]);
key.code = sf::priv::HIDInputManager::localizedKeys([string characterAtIndex:0]);
}
// The key is not a localized one, so we try to find a corresponding code
// through virtual key code.
if (key.Code == sf::Keyboard::KeyCount) {
key.Code = sf::priv::HIDInputManager::NonLocalizedKeys([anEvent keyCode]);
if (key.code == sf::Keyboard::KeyCount) {
key.code = sf::priv::HIDInputManager::nonLocalizedKeys([anEvent keyCode]);
}
//#ifdef SFML_DEBUG // Don't bother the final customers with annoying messages.
// if (key.Code == sf::Keyboard::KeyCount) { // The key is unknown.
// sf::Err() << "This is an unknow key. Virtual key code is 0x"
// if (key.code == sf::Keyboard::KeyCount) { // The key is unknown.
// sf::err() << "This is an unknow key. Virtual key code is 0x"
// << std::hex
// << [anEvent keyCode]
// << "."
@ -1047,17 +1047,17 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
////////////////////////////////////////////////////////
NSUInteger EraseMaskFromData(NSUInteger data, NSUInteger mask)
NSUInteger eraseMaskFromData(NSUInteger data, NSUInteger mask)
{
return (data | mask) ^ mask;
}
////////////////////////////////////////////////////////
NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask)
NSUInteger keepOnlyMaskFromData(NSUInteger data, NSUInteger mask)
{
NSUInteger negative = NSUIntegerMax ^ mask;
return EraseMaskFromData(data, negative);
return eraseMaskFromData(data, negative);
}

View File

@ -39,9 +39,9 @@
////////////////////////////////////////////////////////////
@interface SFViewController : NSObject <WindowImplDelegateProtocol> {
NSView* myView;
SFOpenGLView* myOGLView;
sf::priv::WindowImplCocoa* myRequester;
NSView* m_view;
SFOpenGLView* m_oglView;
sf::priv::WindowImplCocoa* m_requester;
}
-(id)initWithView:(NSView *)view;

View File

@ -38,14 +38,14 @@
-(id)initWithView:(NSView *)view
{
if ((self = [super init])) {
myRequester = 0;
m_requester = 0;
// Retain the view for our own use.
myView = [view retain];
m_view = [view retain];
if (myView == nil) {
if (m_view == nil) {
sf::Err()
sf::err()
<< "No view was given to initWithWindow:."
<< std::endl;
@ -53,14 +53,14 @@
}
// Create the view.
NSRect frame = [myView frame];
NSRect frame = [m_view frame];
frame.origin.x = 0;
frame.origin.y = 0;
myOGLView = [[SFOpenGLView alloc] initWithFrame:frame];
m_oglView = [[SFOpenGLView alloc] initWithFrame:frame];
if (myOGLView == nil) {
if (m_oglView == nil) {
sf::Err()
sf::err()
<< "Could not create an instance of NSOpenGLView "
<< "in (SFViewController -initWithView:)."
<< std::endl;
@ -69,7 +69,7 @@
}
// Set the (OGL) view to the view as its "content" view.
[myView addSubview:myOGLView];
[m_view addSubview:m_oglView];
}
return self;
@ -81,8 +81,8 @@
{
[self closeWindow];
[myView release];
[myOGLView release];
[m_view release];
[m_oglView release];
[super dealloc];
}
@ -92,36 +92,36 @@
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
{
// Forward to the view.
[myOGLView setRequesterTo:requester];
myRequester = requester;
[m_oglView setRequesterTo:requester];
m_requester = requester;
}
////////////////////////////////////////////////////////
-(sf::WindowHandle)getSystemHandle
{
return myView;
return m_view;
}
////////////////////////////////////////////////////////
-(void)changeTitle:(NSString *)title
{
sf::Err() << "Cannot change the title of the view." << std::endl;
sf::err() << "Cannot change the title of the view." << std::endl;
}
////////////////////////////////////////////////////////
-(void)enableKeyRepeat
{
[myOGLView enableKeyRepeat];
[m_oglView enableKeyRepeat];
}
////////////////////////////////////////////////////////
-(void)disableKeyRepeat
{
[myOGLView disableKeyRepeat];
[m_oglView disableKeyRepeat];
}
@ -142,21 +142,21 @@
////////////////////////////////////////////////////////
-(void)hideWindow
{
[myView setHidden:YES];
[m_view setHidden:YES];
}
////////////////////////////////////////////////////////
-(void)showWindow
{
[myView setHidden:NO];
[m_view setHidden:NO];
}
////////////////////////////////////////////////////////
-(void)closeWindow
{
sf::Err() << "Cannot close the view." << std::endl;
sf::err() << "Cannot close the view." << std::endl;
[self setRequesterTo:0];
}
@ -164,25 +164,25 @@
////////////////////////////////////////////////////////
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
{
if (myRequester == 0) return;
if (m_requester == 0) return;
// Create a SFML event.
myRequester->MouseMovedAt(x, y);
m_requester->mouseMovedAt(x, y);
// Flip for SFML window coordinate system
y = NSHeight([[myView window] frame]) - y;
y = NSHeight([[m_view window] frame]) - y;
// Adjust for view reference instead of window
y -= NSHeight([[myView window] frame]) - NSHeight([myOGLView frame]);
y -= NSHeight([[m_view window] frame]) - NSHeight([m_oglView frame]);
// Convert to screen coordinates
NSPoint screenCoord = [[myView window] convertBaseToScreen:NSMakePoint(x, y)];
NSPoint screenCoord = [[m_view window] convertBaseToScreen:NSMakePoint(x, y)];
// Flip screen coodinates
float const screenHeight = NSHeight([[[myView window] screen] frame]);
float const screenHeight = NSHeight([[[m_view window] screen] frame]);
screenCoord.y = screenHeight - screenCoord.y;
CGDirectDisplayID screenNumber = (CGDirectDisplayID)[[[[[myView window] screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue];
CGDirectDisplayID screenNumber = (CGDirectDisplayID)[[[[[m_view window] screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue];
// Place the cursor.
CGDisplayMoveCursorToPoint(screenNumber, CGPointMake(screenCoord.x, screenCoord.y));
@ -198,10 +198,10 @@
////////////////////////////////////////////////////////////
-(NSPoint)position
{
NSPoint pos = [myView frame].origin;
NSPoint pos = [m_view frame].origin;
// Flip screen coodinates
float const screenHeight = NSHeight([[[myView window] screen] frame]);
float const screenHeight = NSHeight([[[m_view window] screen] frame]);
pos.y = screenHeight - pos.y;
return pos;
@ -210,25 +210,25 @@
////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y
{
sf::Err() << "Cannot move the view." << std::endl;
sf::err() << "Cannot move the view." << std::endl;
}
////////////////////////////////////////////////////////////
-(NSSize)size
{
return [myView frame].size;
return [m_view frame].size;
}
////////////////////////////////////////////////////////
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
{
NSRect frame = NSMakeRect([myView frame].origin.x,
[myView frame].origin.y,
NSRect frame = NSMakeRect([m_view frame].origin.x,
[m_view frame].origin.y,
width,
height);
[myView setFrame:frame];
[m_view setFrame:frame];
}
@ -237,22 +237,22 @@
by:(unsigned int)height
with:(sf::Uint8 const *)pixels
{
sf::Err() << "Cannot set an icon to the view." << std::endl;
sf::err() << "Cannot set an icon to the view." << std::endl;
}
////////////////////////////////////////////////////////
-(void)processEvent
{
sf::Err() << "Cannot process event from the view." << std::endl;
sf::err() << "Cannot process event from the view." << std::endl;
}
////////////////////////////////////////////////////////
-(void)applyContext:(NSOpenGLContext *)context
{
[myOGLView setOpenGLContext:context];
[context setView:myOGLView];
[m_oglView setOpenGLContext:context];
[context setView:m_oglView];
}

View File

@ -49,7 +49,7 @@ namespace sf {
/// Used when SFML handle everything and when a NSWindow* is given
/// as handle to WindowImpl.
///
/// myFullscreenMode is bind to default video mode if we don't need to change screen size.
/// m_fullscreenMode is bind to default video mode if we don't need to change screen size.
///
////////////////////////////////////////////////////////////
@ -58,10 +58,10 @@ namespace sf {
#else
@interface SFWindowController : NSResponder <WindowImplDelegateProtocol, NSWindowDelegate> {
#endif
NSWindow* myWindow;
SFOpenGLView* myOGLView;
sf::priv::WindowImplCocoa* myRequester;
sf::VideoMode* myFullscreenMode; // Note : C++ ctor/dtor are not called for Obj-C fields.
NSWindow* m_window;
SFOpenGLView* m_oglView;
sf::priv::WindowImplCocoa* m_requester;
sf::VideoMode* m_fullscreenMode; // Note : C++ ctor/dtor are not called for Obj-C fields.
}
////////////////////////////////////////////////////////////

View File

@ -68,15 +68,15 @@
-(id)initWithWindow:(NSWindow *)window
{
if ((self = [super init])) {
myRequester = 0;
myFullscreenMode = new sf::VideoMode();
m_requester = 0;
m_fullscreenMode = new sf::VideoMode();
// Retain the window for our own use.
myWindow = [window retain];
m_window = [window retain];
if (myWindow == nil) {
if (m_window == nil) {
sf::Err()
sf::err()
<< "No window was given to initWithWindow:."
<< std::endl;
@ -84,11 +84,11 @@
}
// Create the view.
myOGLView = [[SFOpenGLView alloc] initWithFrame:[[myWindow contentView] frame]];
m_oglView = [[SFOpenGLView alloc] initWithFrame:[[m_window contentView] frame]];
if (myOGLView == nil) {
if (m_oglView == nil) {
sf::Err()
sf::err()
<< "Could not create an instance of NSOpenGLView "
<< "in (SFWindowController -initWithWindow:)."
<< std::endl;
@ -97,7 +97,7 @@
}
// Set the view to the window as its content view.
[myWindow setContentView:myOGLView];
[m_window setContentView:m_oglView];
}
return self;
@ -113,7 +113,7 @@
* See http://lists.apple.com/archives/cocoa-dev/2011/Feb/msg00460.html
* for more information.
*/
sf::Err()
sf::err()
<< "Cannot create a window from a worker thread. (OS X limitation)"
<< std::endl;
@ -121,22 +121,22 @@
}
if ((self = [super init])) {
myRequester = 0;
myFullscreenMode = new sf::VideoMode();
m_requester = 0;
m_fullscreenMode = new sf::VideoMode();
// Create our window size.
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
// but we set the back buffer size to 'mode' in applyContext method.
*myFullscreenMode = mode;
*m_fullscreenMode = mode;
sf::VideoMode dm = sf::VideoMode::GetDesktopMode();
rect = NSMakeRect(0, 0, dm.Width, dm.Height);
sf::VideoMode dm = sf::VideoMode::getDesktopMode();
rect = NSMakeRect(0, 0, dm.width, dm.height);
} else { // no fullscreen requested.
rect = NSMakeRect(0, 0, mode.Width, mode.Height);
rect = NSMakeRect(0, 0, mode.width, mode.height);
}
// Convert the SFML window style to Cocoa window style.
@ -152,7 +152,7 @@
}
// Create the window.
myWindow = [[SFWindow alloc] initWithContentRect:rect
m_window = [[SFWindow alloc] initWithContentRect:rect
styleMask:nsStyle
backing:NSBackingStoreBuffered
defer:NO]; // Don't defer it!
@ -166,8 +166,8 @@
[...]
*/
if (myWindow == nil) {
sf::Err()
if (m_window == nil) {
sf::err()
<< "Could not create an instance of NSWindow "
<< "in (SFWindowController -initWithMode:andStyle:)."
<< std::endl;
@ -178,9 +178,9 @@
// Apply special feature for fullscreen window.
if (style & sf::Style::Fullscreen) {
// We place the window above everything else.
[myWindow setOpaque:YES];
[myWindow setHidesOnDeactivate:YES];
[myWindow setLevel:NSMainMenuWindowLevel+1];
[m_window setOpaque:YES];
[m_window setHidesOnDeactivate:YES];
[m_window setLevel:NSMainMenuWindowLevel+1];
// And hide the menu bar
[NSMenu setMenuBarVisible:NO];
@ -196,13 +196,13 @@
}
// Center the window to be cool =)
[myWindow center];
[m_window center];
// Create the view.
myOGLView = [[SFOpenGLView alloc] initWithFrame:[[myWindow contentView] frame]];
m_oglView = [[SFOpenGLView alloc] initWithFrame:[[m_window contentView] frame]];
if (myOGLView == nil) {
sf::Err()
if (m_oglView == nil) {
sf::err()
<< "Could not create an instance of NSOpenGLView "
<< "in (SFWindowController -initWithMode:andStyle:)."
<< std::endl;
@ -211,22 +211,22 @@
}
// If a fullscreen window was requested...
if (style & sf::Style::Fullscreen && mode != sf::VideoMode::GetDesktopMode()) {
if (style & sf::Style::Fullscreen && mode != sf::VideoMode::getDesktopMode()) {
/// ... we set the "read size" of the view (that is the back buffer size).
[myOGLView setRealSize:NSMakeSize(myFullscreenMode->Width, myFullscreenMode->Height)];
[m_oglView setRealSize:NSMakeSize(m_fullscreenMode->width, m_fullscreenMode->height)];
}
// Set the view to the window as its content view.
[myWindow setContentView:myOGLView];
[m_window setContentView:m_oglView];
// Register for event.
[myWindow setDelegate:self];
[myWindow setAcceptsMouseMovedEvents:YES];
[myWindow setIgnoresMouseEvents:NO];
[m_window setDelegate:self];
[m_window setAcceptsMouseMovedEvents:YES];
[m_window setIgnoresMouseEvents:NO];
// And some other things...
[myWindow setAutodisplay:YES];
[myWindow setReleasedWhenClosed:NO];
[m_window setAutodisplay:YES];
[m_window setReleasedWhenClosed:NO];
} // if super init ok
return self;
@ -238,10 +238,10 @@
[self closeWindow];
[NSMenu setMenuBarVisible:YES];
[myWindow release];
[myOGLView release];
[m_window release];
[m_oglView release];
delete myFullscreenMode;
delete m_fullscreenMode;
[super dealloc];
}
@ -255,15 +255,15 @@
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
{
// Forward to the view.
[myOGLView setRequesterTo:requester];
myRequester = requester;
[m_oglView setRequesterTo:requester];
m_requester = requester;
}
////////////////////////////////////////////////////////
-(sf::WindowHandle)getSystemHandle
{
return myWindow;
return m_window;
}
@ -285,14 +285,14 @@
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
{
// Forward to...
[myOGLView setCursorPositionToX:x Y:y];
[m_oglView setCursorPositionToX:x Y:y];
}
////////////////////////////////////////////////////////////
-(NSPoint)position
{
NSPoint pos = [myOGLView frame].origin;
NSPoint pos = [m_oglView frame].origin;
// Flip for SFML window coordinate system.
pos.y = [self screenHeight] - pos.y;
@ -310,14 +310,14 @@
point.y = [self screenHeight] - point.y;
// Place the window.
[myWindow setFrameTopLeftPoint:point];
[m_window setFrameTopLeftPoint:point];
}
////////////////////////////////////////////////////////
-(NSSize)size
{
return [myOGLView frame].size;
return [m_oglView frame].size;
}
@ -325,41 +325,41 @@
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
{
// Add titlebar height.
NSRect frame = NSMakeRect([myWindow frame].origin.x,
[myWindow frame].origin.y,
NSRect frame = NSMakeRect([m_window frame].origin.x,
[m_window frame].origin.y,
width,
height + [self titlebarHeight]);
[myWindow setFrame:frame display:YES];
[m_window setFrame:frame display:YES];
}
////////////////////////////////////////////////////////
-(void)changeTitle:(NSString *)title
{
[myWindow setTitle:title];
[m_window setTitle:title];
}
////////////////////////////////////////////////////////
-(void)hideWindow
{
[myWindow orderOut:nil];
[m_window orderOut:nil];
}
////////////////////////////////////////////////////////
-(void)showWindow
{
[myWindow makeKeyAndOrderFront:nil];
[m_window makeKeyAndOrderFront:nil];
}
////////////////////////////////////////////////////////
-(void)closeWindow
{
[myWindow close];
[myWindow setDelegate:nil];
[m_window close];
[m_window setDelegate:nil];
[self setRequesterTo:0];
}
@ -367,14 +367,14 @@
////////////////////////////////////////////////////////
-(void)enableKeyRepeat
{
[myOGLView enableKeyRepeat];
[m_oglView enableKeyRepeat];
}
////////////////////////////////////////////////////////
-(void)disableKeyRepeat
{
[myOGLView disableKeyRepeat];
[m_oglView disableKeyRepeat];
}
@ -432,7 +432,7 @@
* See http://lists.apple.com/archives/cocoa-dev/2011/Feb/msg00460.html
* for more information.
*/
sf::Err()
sf::err()
<< "Cannot fetch event from a worker thread. (OS X restriction)"
<< std::endl;
@ -440,7 +440,7 @@
}
// If we don't have a requester we don't fetch event.
if (myRequester != 0) {
if (m_requester != 0) {
[SFApplication processEvent];
}
}
@ -449,16 +449,16 @@
////////////////////////////////////////////////////////
-(void)applyContext:(NSOpenGLContext *)context
{
[myOGLView setOpenGLContext:context];
[context setView:myOGLView];
[m_oglView setOpenGLContext:context];
[context setView:m_oglView];
// If fullscreen was requested and the mode used to create the window
// was not the desktop mode, we change the back buffer size of the
// context.
if (*myFullscreenMode != sf::VideoMode()) {
if (*m_fullscreenMode != sf::VideoMode()) {
CGLContextObj cgcontext = (CGLContextObj)[context CGLContextObj];
GLint dim[2] = {myFullscreenMode->Width, myFullscreenMode->Height};
GLint dim[2] = {m_fullscreenMode->width, m_fullscreenMode->height};
CGLSetParameter(cgcontext, kCGLCPSurfaceBackingSize, dim);
CGLEnable(cgcontext, kCGLCESurfaceBackingSize);
@ -473,9 +473,9 @@
////////////////////////////////////////////////////////
-(BOOL)windowShouldClose:(id)sender
{
if (myRequester == 0) return YES;
if (m_requester == 0) return YES;
myRequester->WindowClosed();
m_requester->windowClosed();
return NO;
}
@ -484,9 +484,9 @@
-(void)windowDidBecomeKey:(NSNotification *)notification
{
// Send event.
if (myRequester == 0) return;
if (m_requester == 0) return;
myRequester->WindowGainedFocus();
m_requester->windowGainedFocus();
}
@ -494,9 +494,9 @@
-(void)windowDidResignKey:(NSNotification *)notification
{
// Send event.
if (myRequester == 0) return;
if (m_requester == 0) return;
myRequester->WindowLostFocus();
m_requester->windowLostFocus();
}
@ -506,7 +506,7 @@
////////////////////////////////////////////////////////
-(float)screenHeight
{
NSDictionary *deviceDescription = [[myWindow screen] deviceDescription];
NSDictionary *deviceDescription = [[m_window screen] deviceDescription];
NSNumber *screenNumber = [deviceDescription valueForKey:@"NSScreenNumber"];
CGDirectDisplayID screenID = (CGDirectDisplayID)[screenNumber intValue];
CGFloat height = CGDisplayPixelsHigh(screenID);
@ -517,7 +517,7 @@
////////////////////////////////////////////////////////
-(float)titlebarHeight
{
return NSHeight([myWindow frame]) - NSHeight([[myWindow contentView] frame]);
return NSHeight([m_window frame]) - NSHeight([[m_window contentView] frame]);
}
@end

View File

@ -41,7 +41,7 @@ namespace priv
/// should be used instead of CFDictionaryRef and CGDisplayAvailableModes.
///
////////////////////////////////////////////////////////////
std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
{
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
@ -51,7 +51,7 @@ std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
CFArrayRef displayModes = CGDisplayAvailableModes(CGMainDisplayID());
if (displayModes == NULL) {
sf::Err() << "Couldn't get VideoMode for main display.";
sf::err() << "Couldn't get VideoMode for main display.";
return modes;
}
@ -60,7 +60,7 @@ std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
for (CFIndex i = 0; i < modesCount; 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 (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
@ -78,7 +78,7 @@ std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
if (cgmodes == NULL) {
sf::Err() << "Couldn't get VideoMode for main display.";
sf::err() << "Couldn't get VideoMode for main display.";
return modes;
}
@ -87,7 +87,7 @@ std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
for (CFIndex i = 0; i < modesCount; 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 (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
@ -105,12 +105,12 @@ std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
////////////////////////////////////////////////////////////
VideoMode VideoModeImpl::GetDesktopMode()
VideoMode VideoModeImpl::getDesktopMode()
{
CGDirectDisplayID display = CGMainDisplayID();
return VideoMode(CGDisplayPixelsWide(display),
CGDisplayPixelsHigh(display),
DisplayBitsPerPixel(display));
displayBitsPerPixel(display));
}
} // namespace priv

View File

@ -93,7 +93,7 @@ public:
/// Send the event to SFML WindowImpl class.
///
////////////////////////////////////////////////////////////
void WindowClosed(void);
void windowClosed(void);
////////////////////////////////////////////////////////////
/// \brief Window Resized Event called by the cocoa window object.
@ -104,7 +104,7 @@ public:
/// \param height
///
////////////////////////////////////////////////////////////
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.
@ -112,7 +112,7 @@ public:
/// Send the event to SFML WindowImpl class.
///
////////////////////////////////////////////////////////////
void WindowLostFocus(void);
void windowLostFocus(void);
////////////////////////////////////////////////////////////
/// \brief Window Get Focus Event called by the cocoa window object.
@ -120,7 +120,7 @@ public:
/// Send the event to SFML WindowImpl class.
///
////////////////////////////////////////////////////////////
void WindowGainedFocus(void);
void windowGainedFocus(void);
////////////////////////////////////////////////////////////
/// \brief Mouse Down Event called by the cocoa view object.
@ -132,7 +132,7 @@ public:
/// \param y
///
////////////////////////////////////////////////////////////
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.
@ -144,7 +144,7 @@ public:
/// \param y
///
////////////////////////////////////////////////////////////
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.
@ -155,7 +155,7 @@ public:
/// \param y
///
////////////////////////////////////////////////////////////
void MouseMovedAt(int x, int y);
void mouseMovedAt(int x, int y);
////////////////////////////////////////////////////////////
/// \brief Mouse Wheel Scrolled Event called by the cocoa view object.
@ -167,7 +167,7 @@ public:
/// \param y
///
////////////////////////////////////////////////////////////
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.
@ -175,7 +175,7 @@ public:
/// Send the event to SFML WindowImpl class.
///
////////////////////////////////////////////////////////////
void MouseMovedIn(void);
void mouseMovedIn(void);
////////////////////////////////////////////////////////////
/// \brief Mouse Out Event called by the cocoa view object.
@ -183,7 +183,7 @@ public:
/// Send the event to SFML WindowImpl class.
///
////////////////////////////////////////////////////////////
void MouseMovedOut(void);
void mouseMovedOut(void);
////////////////////////////////////////////////////////////
/// \brief Key Down Event called by the cocoa view object.
@ -193,7 +193,7 @@ public:
/// \param key
///
////////////////////////////////////////////////////////////
void KeyDown(Event::KeyEvent key);
void keyDown(Event::KeyEvent key);
////////////////////////////////////////////////////////////
/// \brief Key Up Event called by the cocoa view object.
@ -203,7 +203,7 @@ public:
/// \param key
///
////////////////////////////////////////////////////////////
void KeyUp(Event::KeyEvent key);
void keyUp(Event::KeyEvent key);
////////////////////////////////////////////////////////////
/// \brief Text Entred Event called by the cocoa view object.
@ -213,7 +213,7 @@ public:
/// \param charcode Input unicode
///
////////////////////////////////////////////////////////////
void TextEntered(unichar charcode);
void textEntered(unichar charcode);
////////////////////////////////////////////////////////////
/// \brief Apply the context to the view.
@ -223,14 +223,14 @@ public:
/// \param context The context to bind to the window
///
////////////////////////////////////////////////////////////
void ApplyContext(NSOpenGLContextRef context) const;
void applyContext(NSOpenGLContextRef context) const;
////////////////////////////////////////////////////////////
/// \brief Change the type of the current process to become a full GUI app.
/// Also ensure NSApp is constructed.
///
////////////////////////////////////////////////////////////
static void SetUpProcess(void);
static void setUpProcess(void);
private:
@ -238,7 +238,7 @@ private:
/// \brief Process incoming events from the operating system
///
////////////////////////////////////////////////////////////
virtual void ProcessEvents();
virtual void processEvents();
////////////////////////////////////////////////////////////
/// \brief Get the OS-specific handle of the window
@ -246,7 +246,7 @@ private:
/// \return Handle of the window
///
////////////////////////////////////////////////////////////
virtual WindowHandle GetSystemHandle() const;
virtual WindowHandle getSystemHandle() const;
////////////////////////////////////////////////////////////
/// \brief Get the position of the window
@ -254,7 +254,7 @@ private:
/// \return Position of the window, in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2i GetPosition() const;
virtual Vector2i getPosition() const;
////////////////////////////////////////////////////////////
/// \brief Change the position of the window on screen
@ -262,7 +262,7 @@ private:
/// \param position New position of the window, in pixels
///
////////////////////////////////////////////////////////////
virtual void SetPosition(const Vector2i& position);
virtual void setPosition(const Vector2i& position);
////////////////////////////////////////////////////////////
/// \brief Get the client size of the window
@ -270,7 +270,7 @@ private:
/// \return Size of the window, in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u GetSize() const;
virtual Vector2u getSize() const;
////////////////////////////////////////////////////////////
/// \brief Change the size of the rendering region of the window
@ -278,7 +278,7 @@ private:
/// \param size New size, in pixels
///
////////////////////////////////////////////////////////////
virtual void SetSize(const Vector2u& size);
virtual void setSize(const Vector2u& size);
////////////////////////////////////////////////////////////
/// \brief Change the title of the window
@ -286,7 +286,7 @@ private:
/// \param title New title
///
////////////////////////////////////////////////////////////
virtual void SetTitle(const std::string& title);
virtual void setTitle(const std::string& title);
////////////////////////////////////////////////////////////
/// \brief Change the window's icon
@ -296,7 +296,7 @@ private:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window
@ -304,7 +304,7 @@ private:
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetVisible(bool visible);
virtual void setVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Show or hide the mouse cursor
@ -312,7 +312,7 @@ private:
/// \param visible True to show, false to hide
///
////////////////////////////////////////////////////////////
virtual void SetMouseCursorVisible(bool visible);
virtual void setMouseCursorVisible(bool visible);
////////////////////////////////////////////////////////////
/// \brief Enable or disable automatic key-repeat
@ -320,15 +320,15 @@ private:
/// \param enabled True to enable, false to disable
///
////////////////////////////////////////////////////////////
virtual void SetKeyRepeatEnabled(bool enabled);
virtual void setKeyRepeatEnabled(bool enabled);
private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
WindowImplDelegateRef myDelegate; ///< Implementation in Obj-C.
bool myShowCursor; ///< Is the cursor displayed or hidden ?
WindowImplDelegateRef m_delegate; ///< Implementation in Obj-C.
bool m_showCursor; ///< Is the cursor displayed or hidden ?
};
} // namespace priv

View File

@ -44,26 +44,26 @@ namespace priv
////////////////////////////////////////////////////////////
WindowImplCocoa::WindowImplCocoa(WindowHandle handle)
: myShowCursor(true)
: m_showCursor(true)
{
// Ask for a pool.
RetainPool();
retainPool();
// Treat the handle as it real type
id nsHandle = (id)handle;
if ([nsHandle isKindOfClass:[NSWindow class]]) {
// We have a window.
myDelegate = [[SFWindowController alloc] initWithWindow:nsHandle];
m_delegate = [[SFWindowController alloc] initWithWindow:nsHandle];
} else if ([nsHandle isKindOfClass:[NSView class]]) {
// We have a view.
myDelegate = [[SFViewController alloc] initWithView:nsHandle];
m_delegate = [[SFViewController alloc] initWithView:nsHandle];
} else {
sf::Err()
sf::err()
<< "Cannot import this Window Handle because it is neither "
<< "a <NSWindow*> nor <NSView*> object "
<< "(or any of their subclasses). You gave a <"
@ -75,7 +75,7 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle)
}
// NO :
// [myDelegate setRequesterTo:this];
// [m_delegate setRequesterTo:this];
// because we don't handle event.
}
@ -84,44 +84,44 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle)
WindowImplCocoa::WindowImplCocoa(VideoMode mode,
const std::string& title,
unsigned long style)
: myShowCursor(true)
: m_showCursor(true)
{
// Transform the app process.
SetUpProcess();
setUpProcess();
// Ask for a pool.
RetainPool();
retainPool();
myDelegate = [[SFWindowController alloc] initWithMode:mode andStyle:style];
[myDelegate changeTitle:stringToNSString(title)];
[myDelegate setRequesterTo:this];
m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style];
[m_delegate changeTitle:stringToNSString(title)];
[m_delegate setRequesterTo:this];
}
////////////////////////////////////////////////////////////
WindowImplCocoa::~WindowImplCocoa()
{
[myDelegate closeWindow];
[m_delegate closeWindow];
[myDelegate 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
// second time (nothing was render until the function was called again)
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::ApplyContext(NSOpenGLContextRef context) const
void WindowImplCocoa::applyContext(NSOpenGLContextRef context) const
{
[myDelegate applyContext:context];
[m_delegate applyContext:context];
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetUpProcess(void)
void WindowImplCocoa::setUpProcess(void)
{
static bool isTheProcessSetAsApplication = false;
@ -149,52 +149,52 @@ void WindowImplCocoa::SetUpProcess(void)
////////////////////////////////////////////////////////////
void WindowImplCocoa::WindowClosed(void)
void WindowImplCocoa::windowClosed(void)
{
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)
{
Event event;
event.Type = Event::Resized;
event.Size.Width = width;
event.Size.Height = height;
event.type = Event::Resized;
event.size.width = width;
event.size.height = height;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::WindowLostFocus(void)
void WindowImplCocoa::windowLostFocus(void)
{
if (!myShowCursor) {
[myDelegate showMouseCursor]; // Make sur the cursor is visible
if (!m_showCursor) {
[m_delegate showMouseCursor]; // Make sur the cursor is visible
}
Event event;
event.Type = Event::LostFocus;
event.type = Event::LostFocus;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::WindowGainedFocus(void)
void WindowImplCocoa::windowGainedFocus(void)
{
if (!myShowCursor) {
[myDelegate hideMouseCursor]; // Restore user's setting
if (!m_showCursor) {
[m_delegate hideMouseCursor]; // Restore user's setting
}
Event event;
event.Type = Event::GainedFocus;
event.type = Event::GainedFocus;
PushEvent(event);
pushEvent(event);
}
#pragma mark
@ -202,78 +202,78 @@ void WindowImplCocoa::WindowGainedFocus(void)
////////////////////////////////////////////////////////////
void WindowImplCocoa::MouseDownAt(Mouse::Button button, int x, int y)
void WindowImplCocoa::mouseDownAt(Mouse::Button button, int x, int y)
{
Event event;
event.Type = Event::MouseButtonPressed;
event.MouseButton.Button = button;
event.MouseButton.X = x;
event.MouseButton.Y = y;
event.type = Event::MouseButtonPressed;
event.mouseButton.button = button;
event.mouseButton.x = x;
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)
{
Event event;
event.Type = Event::MouseButtonReleased;
event.MouseButton.Button = button;
event.MouseButton.X = x;
event.MouseButton.Y = y;
event.type = Event::MouseButtonReleased;
event.mouseButton.button = button;
event.mouseButton.x = x;
event.mouseButton.y = y;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::MouseMovedAt(int x, int y)
void WindowImplCocoa::mouseMovedAt(int x, int y)
{
Event event;
event.Type = Event::MouseMoved;
event.MouseMove.X = x;
event.MouseMove.Y = y;
event.type = Event::MouseMoved;
event.mouseMove.x = x;
event.mouseMove.y = y;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::MouseWheelScrolledAt(float delta, int x, int y)
void WindowImplCocoa::mouseWheelScrolledAt(float delta, int x, int y)
{
Event event;
event.Type = Event::MouseWheelMoved;
event.MouseWheel.Delta = delta;
event.MouseWheel.X = x;
event.MouseWheel.Y = y;
event.type = Event::MouseWheelMoved;
event.mouseWheel.delta = delta;
event.mouseWheel.x = x;
event.mouseWheel.y = y;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::MouseMovedIn(void)
void WindowImplCocoa::mouseMovedIn(void)
{
if (!myShowCursor) {
[myDelegate hideMouseCursor]; // Restore user's setting
if (!m_showCursor) {
[m_delegate hideMouseCursor]; // Restore user's setting
}
Event event;
event.Type = Event::MouseEntered;
event.type = Event::MouseEntered;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::MouseMovedOut(void)
void WindowImplCocoa::mouseMovedOut(void)
{
if (!myShowCursor) {
[myDelegate showMouseCursor]; // Make sur the cursor is visible
if (!m_showCursor) {
[m_delegate showMouseCursor]; // Make sur the cursor is visible
}
Event event;
event.Type = Event::MouseLeft;
event.type = Event::MouseLeft;
PushEvent(event);
pushEvent(event);
}
@ -282,35 +282,35 @@ void WindowImplCocoa::MouseMovedOut(void)
////////////////////////////////////////////////////////////
void WindowImplCocoa::KeyDown(Event::KeyEvent key)
void WindowImplCocoa::keyDown(Event::KeyEvent key)
{
Event event;
event.Type = Event::KeyPressed;
event.Key = key;
event.type = Event::KeyPressed;
event.key = key;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::KeyUp(Event::KeyEvent key)
void WindowImplCocoa::keyUp(Event::KeyEvent key)
{
Event event;
event.Type = Event::KeyReleased;
event.Key = key;
event.type = Event::KeyReleased;
event.key = key;
PushEvent(event);
pushEvent(event);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::TextEntered(unichar charcode)
void WindowImplCocoa::textEntered(unichar charcode)
{
Event event;
event.Type = Event::TextEntered;
event.Text.Unicode = charcode;
event.type = Event::TextEntered;
event.text.unicode = charcode;
PushEvent(event);
pushEvent(event);
}
@ -318,96 +318,96 @@ void WindowImplCocoa::TextEntered(unichar charcode)
#pragma mark WindowImplCocoa's event-related methods
////////////////////////////////////////////////////////////
void WindowImplCocoa::ProcessEvents()
void WindowImplCocoa::processEvents()
{
[myDelegate processEvent];
[m_delegate processEvent];
}
#pragma mark
#pragma mark WindowImplCocoa's private methods
////////////////////////////////////////////////////////////
WindowHandle WindowImplCocoa::GetSystemHandle() const
WindowHandle WindowImplCocoa::getSystemHandle() const
{
return [myDelegate getSystemHandle];
return [m_delegate getSystemHandle];
}
////////////////////////////////////////////////////////////
Vector2i WindowImplCocoa::GetPosition() const
Vector2i WindowImplCocoa::getPosition() const
{
NSPoint pos = [myDelegate position];
NSPoint pos = [m_delegate position];
return Vector2i(pos.x, pos.y);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetPosition(const Vector2i& position)
void WindowImplCocoa::setPosition(const Vector2i& position)
{
[myDelegate setWindowPositionToX:position.x Y:position.y];
[m_delegate setWindowPositionToX:position.x Y:position.y];
}
////////////////////////////////////////////////////////////
Vector2u WindowImplCocoa::GetSize() const
Vector2u WindowImplCocoa::getSize() const
{
NSSize size = [myDelegate size];
NSSize size = [m_delegate size];
return Vector2u(size.width, size.height);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetSize(const Vector2u& size)
void WindowImplCocoa::setSize(const Vector2u& size)
{
[myDelegate resizeTo:size.x by:size.y];
[m_delegate resizeTo:size.x by:size.y];
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetTitle(const std::string& title)
void WindowImplCocoa::setTitle(const std::string& title)
{
[myDelegate changeTitle:stringToNSString(title)];
[m_delegate changeTitle:stringToNSString(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)
{
[myDelegate setIconTo:width by:height with:pixels];
[m_delegate setIconTo:width by:height with:pixels];
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetVisible(bool visible)
void WindowImplCocoa::setVisible(bool visible)
{
if (visible) {
[myDelegate showWindow];
[m_delegate showWindow];
} else {
[myDelegate hideWindow];
[m_delegate hideWindow];
}
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetMouseCursorVisible(bool visible)
void WindowImplCocoa::setMouseCursorVisible(bool visible)
{
myShowCursor = visible;
m_showCursor = visible;
if (myShowCursor) {
[myDelegate showMouseCursor];
if (m_showCursor) {
[m_delegate showMouseCursor];
} else {
[myDelegate hideMouseCursor];
[m_delegate hideMouseCursor];
}
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetKeyRepeatEnabled(bool enabled)
void WindowImplCocoa::setKeyRepeatEnabled(bool enabled)
{
if (enabled) {
[myDelegate enableKeyRepeat];
[m_delegate enableKeyRepeat];
} else {
[myDelegate disableKeyRepeat];
[m_delegate disableKeyRepeat];
}
}

View File

@ -49,12 +49,12 @@ namespace sf {
/// The requester is a WindowImplCocoa. It's used to send back
/// event via these functions :
///
/// WindowClosed, WindowResized, WindowLostFocus, WindowGainedFocus
/// windowClosed, windowResized, windowLostFocus, windowGainedFocus
///
/// MouseDownAt, MouseUpAt, MouseMovedAt, MouseWheelScrolledAt,
/// MouseMovedIn, MouseMovedOut
/// mouseDownAt, mouseUpAt, mouseMovedAt, mouseWheelScrolledAt,
/// mouseMovedIn, mouseMovedOut
///
/// KeyDown, KeyUp, TextEntered
/// keyDown, keyUp, textEntered
///
/// Note : Joystick are not bound to a view or window
/// thus they're not managed by a class implementing this protocol.

View File

@ -36,7 +36,7 @@ namespace priv
////////////////////////////////////////////////////////////
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
size_t ModeBitsPerPixel(CGDisplayModeRef mode)
size_t modeBitsPerPixel(CGDisplayModeRef mode)
{
size_t bpp = 0; // no match
@ -66,7 +66,7 @@ size_t ModeBitsPerPixel(CGDisplayModeRef mode)
////////////////////////////////////////////////////////////
size_t DisplayBitsPerPixel(CGDirectDisplayID displayId)
size_t displayBitsPerPixel(CGDirectDisplayID displayId)
{
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
@ -78,7 +78,7 @@ size_t DisplayBitsPerPixel(CGDirectDisplayID displayId)
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
// Get bpp for the mode.
size_t const bpp = ModeBitsPerPixel(mode);
size_t const bpp = modeBitsPerPixel(mode);
// Clean up Memory.
CGDisplayModeRelease(mode);
@ -92,15 +92,15 @@ size_t DisplayBitsPerPixel(CGDirectDisplayID displayId)
////////////////////////////////////////////////////////////
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
VideoMode ConvertCGModeToSFMode(CFDictionaryRef dictionary)
VideoMode convertCGModeToSFMode(CFDictionaryRef dictionary)
{
VideoMode sfmode;
CFNumberRef cfnumber = (CFNumberRef)CFDictionaryGetValue(dictionary, kCGDisplayWidth);
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.Width));
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.width));
cfnumber = (CFNumberRef)CFDictionaryGetValue(dictionary, kCGDisplayHeight);
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.Height));
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.height));
cfnumber = (CFNumberRef)CFDictionaryGetValue(dictionary, kCGDisplayBitsPerPixel);
CFNumberGetValue(cfnumber, kCFNumberIntType, &(sfmode.BitsPerPixel));
@ -110,11 +110,11 @@ VideoMode ConvertCGModeToSFMode(CFDictionaryRef dictionary)
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
VideoMode ConvertCGModeToSFMode(CGDisplayModeRef cgmode)
VideoMode convertCGModeToSFMode(CGDisplayModeRef cgmode)
{
return VideoMode(CGDisplayModeGetWidth(cgmode),
CGDisplayModeGetHeight(cgmode),
ModeBitsPerPixel(cgmode));
modeBitsPerPixel(cgmode));
}
#endif
@ -122,20 +122,20 @@ VideoMode ConvertCGModeToSFMode(CGDisplayModeRef cgmode)
////////////////////////////////////////////////////////////
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
CFDictionaryRef ConvertSFModeToCGMode(VideoMode sfmode)
CFDictionaryRef convertSFModeToCGMode(VideoMode sfmode)
{
// If sfmode is in VideoMode::GetFullscreenModes
// then this should be an exact match (see NULL parameter doc).
return CGDisplayBestModeForParameters(CGMainDisplayID(),
sfmode.BitsPerPixel,
sfmode.Width,
sfmode.Height,
sfmode.width,
sfmode.height,
NULL);
}
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
CGDisplayModeRef ConvertSFModeToCGMode(VideoMode sfmode)
CGDisplayModeRef convertSFModeToCGMode(VideoMode sfmode)
{
// Starting with 10.6 we should query the display all the modes and
// search for the best one.
@ -147,7 +147,7 @@ CGDisplayModeRef ConvertSFModeToCGMode(VideoMode sfmode)
CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
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;
}
@ -156,7 +156,7 @@ CGDisplayModeRef ConvertSFModeToCGMode(VideoMode sfmode)
for (CFIndex i = 0; i < modesCount; i++) {
CGDisplayModeRef cgmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cgmodes, i);
VideoMode mode = ConvertCGModeToSFMode(cgmode);
VideoMode mode = convertCGModeToSFMode(cgmode);
if (mode == sfmode) {
cgbestMode = cgmode;
@ -167,7 +167,7 @@ CGDisplayModeRef ConvertSFModeToCGMode(VideoMode sfmode)
CFRelease(cgmodes);
if (cgbestMode == NULL) {
sf::Err()
sf::err()
<< "Couldn't convert the given sf:VideoMode into a CGDisplayMode."
<< std::endl;
}

View File

@ -44,7 +44,7 @@ namespace priv
///
////////////////////////////////////////////////////////////
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
size_t ModeBitsPerPixel(CGDisplayModeRef mode);
size_t modeBitsPerPixel(CGDisplayModeRef mode);
#endif
////////////////////////////////////////////////////////////
@ -54,16 +54,16 @@ size_t ModeBitsPerPixel(CGDisplayModeRef mode);
/// display bits per pixel information for a given display id.
///
////////////////////////////////////////////////////////////
size_t DisplayBitsPerPixel(CGDirectDisplayID displayId);
size_t displayBitsPerPixel(CGDirectDisplayID displayId);
////////////////////////////////////////////////////////////
/// \brief Convert a Quartz video mode into a sf::VideoMode object.
///
////////////////////////////////////////////////////////////
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
VideoMode ConvertCGModeToSFMode(CFDictionaryRef dictionary);
VideoMode convertCGModeToSFMode(CFDictionaryRef dictionary);
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
VideoMode ConvertCGModeToSFMode(CGDisplayModeRef cgmode);
VideoMode convertCGModeToSFMode(CGDisplayModeRef cgmode);
#endif
////////////////////////////////////////////////////////////
@ -71,9 +71,9 @@ VideoMode ConvertCGModeToSFMode(CGDisplayModeRef cgmode);
///
////////////////////////////////////////////////////////////
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
CFDictionaryRef ConvertSFModeToCGMode(VideoMode sfmode);
CFDictionaryRef convertSFModeToCGMode(VideoMode sfmode);
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
CGDisplayModeRef ConvertSFModeToCGMode(VideoMode sfmode);
CGDisplayModeRef convertSFModeToCGMode(VideoMode sfmode);
#endif
} // namespace priv

View File

@ -34,7 +34,7 @@
NSString* stringToNSString(std::string const& string)
{
std::string utf8; utf8.reserve(string.size() + 1);
sf::Utf8::FromAnsi(string.begin(), string.end(), std::back_inserter(utf8));
sf::Utf8::fromAnsi(string.begin(), string.end(), std::back_inserter(utf8));
NSString* str = [NSString stringWithCString:utf8.c_str() encoding:NSUTF8StringEncoding];
return str;

View File

@ -38,6 +38,6 @@
/// with the main bundle or an empty string is there is no bundle.
///
////////////////////////////////////////////////////////////
std::string ResourcePath(void);
std::string resourcePath(void);
#endif

View File

@ -30,7 +30,7 @@
#import <Foundation/Foundation.h>
////////////////////////////////////////////////////////////
std::string ResourcePath(void)
std::string resourcePath(void)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

View File

@ -237,7 +237,7 @@ sf::Sprite sprite(texture);
</string>
<key>main.cpp:main:image_load</key>
<string>if (!texture.LoadFromFile(ResourcePath() + "cute_image.jpg"))</string>
<string>if (!texture.loadFromFile(resourcePath() + "cute_image.jpg"))</string>
<key>main.cpp:main:text_init</key>
<string>
@ -248,22 +248,22 @@ sf::Font font;
<key>main.cpp:main:text_finalize</key>
<string> return EXIT_FAILURE;
sf::Text text("Hello SFML", font, 50);
text.SetColor(sf::Color::Black);
text.setColor(sf::Color::Black);
</string>
<key>main.cpp:main:text_load</key>
<string>if (!font.LoadFromFile(ResourcePath() + "sansation.ttf"))</string>
<string>if (!font.loadFromFile(resourcePath() + "sansation.ttf"))</string>
<key>main.cpp:main:graphics_display</key>
<string>
// Clear screen
window.Clear();
window.clear();
// Draw the sprite
window.Draw(sprite);
window.draw(sprite);
// Draw the string
window.Draw(text);
window.draw(text);
</string>
<!-- erase window module content -->
@ -368,11 +368,11 @@ text.SetColor(sf::Color::Black);
<string>
// Load a music to play
sf::Music music;
if (!music.OpenFromFile(ResourcePath() + "nice_music.ogg"))
if (!music.openFromFile(resourcePath() + "nice_music.ogg"))
return EXIT_FAILURE;
// Play the music
music.Play();
music.play();
</string>
<key>nice_music.ogg</key>
<dict>
@ -548,26 +548,26 @@ int main (int argc, const char * argv[])
<key>main.cpp:main:event_loop</key>
<string>
// Start the game loop
while (window.IsOpen())
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
while (window.pollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
if (event.type == sf::Event::Closed)
window.close();
// Escape pressed : exit
if (event.Type == sf::Event::KeyPressed &amp;&amp; event.Key.Code == sf::Keyboard::Escape)
window.Close();
if (event.type == sf::Event::KeyPressed &amp;&amp; event.key.code == sf::Keyboard::Escape)
window.close();
}
</string>
<key>main.cpp:main:display</key>
<string>
// Update the window
window.Display();
window.display();
}
</string>
@ -575,7 +575,7 @@ while (window.IsOpen())
<string>#include "ResourcePath.hpp"</string>
<key>main.cpp:main:audio_loop</key>
<string>while (music.GetStatus() == sf::Music::Playing) {
<string>while (music.getStatus() == sf::Music::Playing) {
sf::Sleep(100);
}</string>
</dict>

View File

@ -237,7 +237,7 @@ sf::Sprite sprite(texture);
</string>
<key>main.cpp:main:image_load</key>
<string>if (!texture.LoadFromFile("cute_image.jpg"))</string>
<string>if (!texture.loadFromFile("cute_image.jpg"))</string>
<key>main.cpp:main:text_init</key>
<string>
@ -248,22 +248,22 @@ sf::Font font;
<key>main.cpp:main:text_finalize</key>
<string> return EXIT_FAILURE;
sf::Text text("Hello SFML", font, 50);
text.SetColor(sf::Color::Black);
text.setColor(sf::Color::Black);
</string>
<key>main.cpp:main:text_load</key>
<string>if (!font.LoadFromFile("sansation.ttf"))</string>
<string>if (!font.loadFromFile("sansation.ttf"))</string>
<key>main.cpp:main:graphics_display</key>
<string>
// Clear screen
window.Clear();
window.clear();
// Draw the sprite
window.Draw(sprite);
window.draw(sprite);
// Draw the string
window.Draw(text);
window.draw(text);
</string>
<!-- erase window module content -->
@ -368,11 +368,11 @@ text.SetColor(sf::Color::Black);
<string>
// Load a music to play
sf::Music music;
if (!music.OpenFromFile("nice_music.ogg"))
if (!music.openFromFile("nice_music.ogg"))
return EXIT_FAILURE;
// Play the music
music.Play();
music.play();
</string>
<key>nice_music.ogg</key>
<dict>
@ -529,26 +529,26 @@ int main (int argc, const char * argv[])
<key>main.cpp:main:event_loop</key>
<string>
// Start the game loop
while (window.IsOpen())
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
while (window.pollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
if (event.type == sf::Event::Closed)
window.close();
// Escape pressed : exit
if (event.Type == sf::Event::KeyPressed &amp;&amp; event.Key.Code == sf::Keyboard::Escape)
window.Close();
if (event.type == sf::Event::KeyPressed &amp;&amp; event.key.code == sf::Keyboard::Escape)
window.close();
}
</string>
<key>main.cpp:main:display</key>
<string>
// Update the window
window.Display();
window.display();
}
</string>
@ -569,7 +569,7 @@ while (window.IsOpen())
</string>
<key>main.cpp:main:audio_loop</key>
<string>while (music.GetStatus() == sf::Music::Playing) {
<string>while (music.getStatus() == sf::Music::Playing) {
sf::Sleep(100);
}</string>
</dict>