Fix GetFullscreenModes : no more returns only desktop mode.
Fix fullscreen window by setting up a desktop-wide window and resizing the context's backbuffer. Fix mouse coordinate for fullscreen window. Fix window sending 5 event when resized. Better fix for TextEntered event – no more relies on documentation but on current implementation of the system. Update some obj-classes structures. (Mostly improved the code structure.) Update © date and some comments. git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1792 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
8affa29f54
commit
f664148e27
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
@ -52,6 +52,8 @@ else() # MACOSX
|
|||||||
${SRC}
|
${SRC}
|
||||||
${SRCROOT}/OSX/cpp_objc_conversion.h
|
${SRCROOT}/OSX/cpp_objc_conversion.h
|
||||||
${SRCROOT}/OSX/cpp_objc_conversion.mm
|
${SRCROOT}/OSX/cpp_objc_conversion.mm
|
||||||
|
${SRCROOT}/OSX/cg_sf_conversion.hpp
|
||||||
|
${SRCROOT}/OSX/cg_sf_conversion.cpp
|
||||||
${SRCROOT}/OSX/Joystick.cpp
|
${SRCROOT}/OSX/Joystick.cpp
|
||||||
${SRCROOT}/OSX/Joystick.hpp
|
${SRCROOT}/OSX/Joystick.hpp
|
||||||
${SRCROOT}/OSX/SFApplication.h
|
${SRCROOT}/OSX/SFApplication.h
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Event processing
|
/// \brief Event processing
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@interface SFApplication : NSObject
|
@interface SFApplication : NSObject
|
||||||
|
|
||||||
@ -38,6 +39,7 @@
|
|||||||
/// \brief Event processing
|
/// \brief Event processing
|
||||||
///
|
///
|
||||||
/// \param block blocking mode means at least one event is proccessed.
|
/// \param block blocking mode means at least one event is proccessed.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
+(void)processEventWithBlockingMode:(BOOL)block;
|
+(void)processEventWithBlockingMode:(BOOL)block;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -122,13 +122,13 @@ private:
|
|||||||
/// \note Must only be called from Ctor.
|
/// \note Must only be called from Ctor.
|
||||||
///
|
///
|
||||||
/// \param shared Context to share the new one with (can be NULL)
|
/// \param shared Context to share the new one with (can be NULL)
|
||||||
/// \param settings Creation parameters
|
|
||||||
/// \param bitsPerPixel bpp
|
/// \param bitsPerPixel bpp
|
||||||
|
/// \param settings Creation parameters
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void CreateContext(SFContext* shared,
|
void CreateContext(SFContext* shared,
|
||||||
const ContextSettings& settings,
|
unsigned int bitsPerPixel,
|
||||||
unsigned int bitsPerPixel);
|
const ContextSettings& settings);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -56,7 +56,7 @@ SFContext::SFContext(SFContext* shared)
|
|||||||
myPool = [[NSAutoreleasePool alloc] init];
|
myPool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
CreateContext(shared, ContextSettings(0, 0, 0), 0);
|
CreateContext(shared, 0, ContextSettings(0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ SFContext::SFContext(SFContext* shared, const WindowImpl* owner,
|
|||||||
myPool = [[NSAutoreleasePool alloc] init];
|
myPool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
// Create the context.
|
// Create the context.
|
||||||
CreateContext(shared, settings, bitsPerPixel);
|
CreateContext(shared, bitsPerPixel, settings);
|
||||||
|
|
||||||
// Apply context.
|
// Apply context.
|
||||||
WindowImplCocoa const * ownerCocoa = static_cast<WindowImplCocoa const *>(owner);
|
WindowImplCocoa const * ownerCocoa = static_cast<WindowImplCocoa const *>(owner);
|
||||||
@ -82,7 +82,7 @@ SFContext::~SFContext()
|
|||||||
[myPool drain]; // [A]
|
[myPool drain]; // [A]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[A] : Produce sometimes "*** attempt to pop an unknown autorelease pool"
|
* [A] : Produce sometimes "*** attempt to pop an unknown autorelease pool"
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,15 +118,14 @@ void SFContext::EnableVerticalSync(bool enabled)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void SFContext::CreateContext(SFContext* shared,
|
void SFContext::CreateContext(SFContext* shared,
|
||||||
const ContextSettings& settings,
|
unsigned int bitsPerPixel,
|
||||||
unsigned int bitsPerPixel)
|
const ContextSettings& settings)
|
||||||
{
|
{
|
||||||
// Choose the attributs of OGL context.
|
// Choose the attributs of OGL context.
|
||||||
std::vector<NSOpenGLPixelFormatAttribute> attrs;
|
std::vector<NSOpenGLPixelFormatAttribute> attrs;
|
||||||
attrs.reserve(20); // max attributs (estimation).
|
attrs.reserve(20); // max attributs (estimation).
|
||||||
|
|
||||||
// These casts are safe. C++ is much more stric than Obj-C.
|
// These casts are safe. C++ is much more strict than Obj-C.
|
||||||
|
|
||||||
attrs.push_back(NSOpenGLPFAClosestPolicy);
|
attrs.push_back(NSOpenGLPFAClosestPolicy);
|
||||||
|
|
||||||
attrs.push_back(NSOpenGLPFADoubleBuffer);
|
attrs.push_back(NSOpenGLPFADoubleBuffer);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -38,23 +38,48 @@ namespace sf {
|
|||||||
/// \brief Spesialized NSOpenGLView
|
/// \brief Spesialized NSOpenGLView
|
||||||
///
|
///
|
||||||
/// Handle event and send them back to the requester.
|
/// 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
|
||||||
|
/// bound to its default value we don't recompute the mouse position
|
||||||
|
/// and assume it's correct.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@interface SFOpenGLView : NSOpenGLView {
|
@interface SFOpenGLView : NSOpenGLView {
|
||||||
sf::priv::WindowImplCocoa* myRequester;
|
sf::priv::WindowImplCocoa* myRequester;
|
||||||
BOOL myUseKeyRepeat;
|
BOOL myUseKeyRepeat;
|
||||||
NSTrackingRectTag myTrackingTag;
|
NSTrackingRectTag myTrackingTag;
|
||||||
BOOL myMouseIsIn;
|
BOOL myMouseIsIn;
|
||||||
|
NSSize myRealSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Create the SFML opengl view to fit the given area.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(id)initWithFrame:(NSRect)frameRect;
|
-(id)initWithFrame:(NSRect)frameRect;
|
||||||
-(void)setRequesterTo:(sf::priv::WindowImplCocoa*)requester;
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Apply the given resquester to the view.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Set the real size of view (it should be the back buffer size).
|
||||||
|
/// If not set, or set to its default value NSZeroSize, the view
|
||||||
|
/// won't recompute the mouse coordinates before sending them
|
||||||
|
/// to the requester.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(void)setRealSize:(NSSize)newSize;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Adjust key repeat configuration.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)enableKeyRepeat;
|
-(void)enableKeyRepeat;
|
||||||
-(void)disableKeyRepeat;
|
-(void)disableKeyRepeat;
|
||||||
|
|
||||||
-(void)frameDidChange:(NSNotification*)notification;
|
|
||||||
|
|
||||||
-(BOOL)isMouseInside;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -30,6 +30,26 @@
|
|||||||
|
|
||||||
#import <SFML/Window/OSX/SFOpenGLView.h>
|
#import <SFML/Window/OSX/SFOpenGLView.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// SFOpenGLView class : Privates Methods Declaration
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
@interface SFOpenGLView ()
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Handle view resized event.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(void)frameDidChange:(NSNotification *)notification;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Establish if the mouse is inside or outside the OpenGL view.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(BOOL)isMouseInside;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation SFOpenGLView
|
@implementation SFOpenGLView
|
||||||
|
|
||||||
#pragma mark
|
#pragma mark
|
||||||
@ -42,6 +62,8 @@
|
|||||||
[self setRequesterTo:0];
|
[self setRequesterTo:0];
|
||||||
[self enableKeyRepeat];
|
[self enableKeyRepeat];
|
||||||
|
|
||||||
|
myRealSize = NSZeroSize;
|
||||||
|
|
||||||
// Register for mouse-move event
|
// Register for mouse-move event
|
||||||
myMouseIsIn = [self isMouseInside];
|
myMouseIsIn = [self isMouseInside];
|
||||||
myTrackingTag = [self addTrackingRect:[self frame]
|
myTrackingTag = [self addTrackingRect:[self frame]
|
||||||
@ -54,7 +76,7 @@
|
|||||||
[center addObserver:self
|
[center addObserver:self
|
||||||
selector:@selector(frameDidChange:)
|
selector:@selector(frameDidChange:)
|
||||||
name:NSViewFrameDidChangeNotification
|
name:NSViewFrameDidChangeNotification
|
||||||
object:nil];
|
object:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@ -62,12 +84,19 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)setRequesterTo:(sf::priv::WindowImplCocoa*)requester
|
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
|
||||||
{
|
{
|
||||||
myRequester = requester;
|
myRequester = requester;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
-(void)setRealSize:(NSSize)newSize
|
||||||
|
{
|
||||||
|
myRealSize = newSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)enableKeyRepeat
|
-(void)enableKeyRepeat
|
||||||
{
|
{
|
||||||
@ -83,7 +112,7 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)frameDidChange:(NSNotification*)notification
|
-(void)frameDidChange:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
// Adapt tracking area for mouse mouse event.
|
// Adapt tracking area for mouse mouse event.
|
||||||
[self removeTrackingRect:myTrackingTag];
|
[self removeTrackingRect:myTrackingTag];
|
||||||
@ -154,11 +183,12 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)mouseDown:(NSEvent*)theEvent
|
-(void)mouseDown:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseDownAt(sf::Mouse::Left, loc.x, h - loc.y);
|
myRequester->MouseDownAt(sf::Mouse::Left, loc.x, h - loc.y);
|
||||||
@ -166,19 +196,28 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)mouseUp:(NSEvent*)theEvent
|
-(void)mouseUp:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseUpAt(sf::Mouse::Left, loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseUpAt(sf::Mouse::Left, loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)mouseMoved:(NSEvent*)theEvent
|
-(void)mouseMoved:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
@ -186,26 +225,44 @@
|
|||||||
if (!myMouseIsIn) return;
|
if (!myMouseIsIn) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseMovedAt(loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseMovedAt(loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)scrollWheel:(NSEvent*)theEvent
|
-(void)scrollWheel:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseWheelScrolledAt([theEvent deltaY], loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseWheelScrolledAt([theEvent deltaY], loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)mouseEntered:(NSEvent*)theEvent
|
-(void)mouseEntered:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
myMouseIsIn = YES;
|
myMouseIsIn = YES;
|
||||||
|
|
||||||
@ -216,7 +273,7 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)mouseExited:(NSEvent*)theEvent
|
-(void)mouseExited:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
myMouseIsIn = NO;
|
myMouseIsIn = NO;
|
||||||
|
|
||||||
@ -227,35 +284,54 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)rightMouseDown:(NSEvent*)theEvent
|
-(void)rightMouseDown:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseDownAt(sf::Mouse::Right, loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseDownAt(sf::Mouse::Right, loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)rightMouseUp:(NSEvent*)theEvent
|
-(void)rightMouseUp:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseUpAt(sf::Mouse::Right, loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseUpAt(sf::Mouse::Right, loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)otherMouseDown:(NSEvent*)theEvent
|
-(void)otherMouseDown:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
sf::Mouse::Button button;
|
sf::Mouse::Button button;
|
||||||
switch ([theEvent buttonNumber]) {
|
switch ([theEvent buttonNumber]) {
|
||||||
case 2:
|
case 2:
|
||||||
@ -270,18 +346,28 @@
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseDownAt(button, loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseDownAt(button, loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)otherMouseUp:(NSEvent*)theEvent
|
-(void)otherMouseUp:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
sf::Mouse::Button button;
|
sf::Mouse::Button button;
|
||||||
switch ([theEvent buttonNumber]) {
|
switch ([theEvent buttonNumber]) {
|
||||||
case 2:
|
case 2:
|
||||||
@ -296,14 +382,23 @@
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseUpAt(button, loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseUpAt(button, loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)rightMouseDragged:(NSEvent*)theEvent
|
-(void)rightMouseDragged:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
@ -311,14 +406,23 @@
|
|||||||
if (!myMouseIsIn) return;
|
if (!myMouseIsIn) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseMovedAt(loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseMovedAt(loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)mouseDragged:(NSEvent*)theEvent
|
-(void)mouseDragged:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
@ -326,14 +430,23 @@
|
|||||||
if (!myMouseIsIn) return;
|
if (!myMouseIsIn) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseMovedAt(loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseMovedAt(loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)otherMouseDragged:(NSEvent*)theEvent
|
-(void)otherMouseDragged:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
@ -341,9 +454,18 @@
|
|||||||
if (!myMouseIsIn) return;
|
if (!myMouseIsIn) return;
|
||||||
|
|
||||||
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
// Don't forget to change to SFML coord system.
|
// Don't forget to change to SFML coord system.
|
||||||
float h = [self frame].size.height;
|
float h = [self frame].size.height;
|
||||||
myRequester->MouseMovedAt(loc.x, h - loc.y);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
myRequester->MouseMovedAt(loc.x, loc.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -352,36 +474,42 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)keyDown:(NSEvent*)theEvent
|
-(void)keyDown:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
if (myUseKeyRepeat || ![theEvent isARepeat])
|
if (myUseKeyRepeat || ![theEvent isARepeat])
|
||||||
myRequester->KeyDown([theEvent keyCode], [theEvent modifierFlags]);
|
myRequester->KeyDown([theEvent keyCode], [theEvent modifierFlags]);
|
||||||
|
|
||||||
if ((myUseKeyRepeat || ![theEvent isARepeat]) && [[theEvent characters] length] > 0) {
|
if (myUseKeyRepeat || ![theEvent isARepeat]) {
|
||||||
/// From NSEvent.h :
|
// Let's see if its a valid text.
|
||||||
/*
|
// -interpretKeyEvents: will call -insertText: if theEvent is a valid caracter.
|
||||||
* Unicodes we reserve for function keys on the keyboard,
|
[self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
|
||||||
* OpenStep reserves the range 0xF700-0xF8FF for this purpose.
|
|
||||||
* The availability of various keys will be system dependent.
|
|
||||||
*/
|
|
||||||
/// And 0x35 is the Escape key.
|
|
||||||
unichar ch = [[theEvent characters] characterAtIndex:0];
|
|
||||||
if ([theEvent keyCode] != 0x35 &&
|
|
||||||
(ch < 0xf700 || ch > 0xf8ff)) {
|
|
||||||
myRequester->TextEntered(ch);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)keyUp:(NSEvent*)theEvent
|
-(void)keyUp:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
myRequester->KeyUp([theEvent keyCode], [theEvent modifierFlags]);
|
myRequester->KeyUp([theEvent keyCode], [theEvent modifierFlags]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
-(void)insertText:(id)aString
|
||||||
|
{
|
||||||
|
// aString can be either a NSString or a NSAttributedString.
|
||||||
|
if ([aString isKindOfClass:[NSAttributedString class]]) {
|
||||||
|
aString = [aString string]; // We want a NSString.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myRequester == 0 || [aString length] == 0) return;
|
||||||
|
|
||||||
|
// It's a valid TextEntered event.
|
||||||
|
myRequester->TextEntered([aString characterAtIndex:0]);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -29,17 +29,19 @@
|
|||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Here we redefine some methods to allow grabing fullscreen events.
|
/// \brief Here we redefine some methods to allow grabing fullscreen events.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@interface SFWindow : NSWindow {
|
@interface SFWindow : NSWindow {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
////////////////////////////////////////////////////////////
|
||||||
These two methods must return YES to grab fullscreen events.
|
/// These two methods must return YES to grab fullscreen events.
|
||||||
See http://stackoverflow.com/questions/999464/fullscreen-key-down-actions
|
/// See http://stackoverflow.com/questions/999464/fullscreen-key-down-actions
|
||||||
for more informations
|
/// for more informations
|
||||||
*/
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(BOOL)acceptsFirstResponder;
|
-(BOOL)acceptsFirstResponder;
|
||||||
-(BOOL)canBecomeKeyWindow;
|
-(BOOL)canBecomeKeyWindow;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -27,7 +27,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#import <SFML/Window/OSX/WindowImplDelegateProtocol.h>
|
#import <SFML/Window/OSX/WindowImplDelegateProtocol.h>
|
||||||
|
#include <SFML/Window/VideoMode.hpp>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Predefine some classes
|
/// Predefine some classes
|
||||||
@ -36,7 +36,6 @@ namespace sf {
|
|||||||
namespace priv {
|
namespace priv {
|
||||||
class WindowImplCocoa;
|
class WindowImplCocoa;
|
||||||
}
|
}
|
||||||
class VideoMode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@class SFOpenGLView;
|
@class SFOpenGLView;
|
||||||
@ -49,6 +48,9 @@ namespace sf {
|
|||||||
///
|
///
|
||||||
/// Used when SFML handle everything and when a NSWindow* is given
|
/// Used when SFML handle everything and when a NSWindow* is given
|
||||||
/// as handle to WindowImpl.
|
/// as handle to WindowImpl.
|
||||||
|
///
|
||||||
|
/// myFullscreenMode is bind to default video mode if we don't need to change screen size.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 // NSWindowDelegate is only define since 10.6
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 // NSWindowDelegate is only define since 10.6
|
||||||
@ -59,13 +61,19 @@ namespace sf {
|
|||||||
NSWindow* myWindow;
|
NSWindow* myWindow;
|
||||||
SFOpenGLView* myOGLView;
|
SFOpenGLView* myOGLView;
|
||||||
sf::priv::WindowImplCocoa* myRequester;
|
sf::priv::WindowImplCocoa* myRequester;
|
||||||
|
sf::VideoMode myFullscreenMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithWindow:(NSWindow*)window;
|
////////////////////////////////////////////////////////////
|
||||||
-(id)initWithMode:(sf::VideoMode const*)mode andStyle:(unsigned long)style;
|
/// Create the SFML window with an external Cocoa window.
|
||||||
-(void)dealloc;
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(id)initWithWindow:(NSWindow *)window;
|
||||||
|
|
||||||
-(float)screenHeight;
|
////////////////////////////////////////////////////////////
|
||||||
-(float)titlebarHeight;
|
/// Create the SFML window "from scratch" (full SFML handling).
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(id)initWithMode:(sf::VideoMode const &)mode andStyle:(unsigned long)style;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -31,20 +31,40 @@
|
|||||||
#include <SFML/Window/WindowHandle.hpp>
|
#include <SFML/Window/WindowHandle.hpp>
|
||||||
#include <SFML/Window/WindowStyle.hpp>
|
#include <SFML/Window/WindowStyle.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
|
||||||
#import <SFML/Window/OSX/SFWindowController.h>
|
#import <SFML/Window/OSX/SFWindowController.h>
|
||||||
#import <SFML/Window/OSX/SFApplication.h>
|
#import <SFML/Window/OSX/SFApplication.h>
|
||||||
#import <SFML/Window/OSX/SFOpenGLView.h>
|
#import <SFML/Window/OSX/SFOpenGLView.h>
|
||||||
#import <SFML/Window/OSX/SFWindow.h>
|
#import <SFML/Window/OSX/SFWindow.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// SFWindowController class : Privates Methods Declaration
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
@interface SFWindowController ()
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Retrieves the screen height.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(float)screenHeight;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Retrives the title bar height.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(float)titlebarHeight;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation SFWindowController
|
@implementation SFWindowController
|
||||||
|
|
||||||
#pragma mark
|
#pragma mark
|
||||||
#pragma mark SFWindowController's methods
|
#pragma mark SFWindowController's methods
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(id)initWithWindow:(NSWindow*)window
|
-(id)initWithWindow:(NSWindow *)window
|
||||||
{
|
{
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
myRequester = 0;
|
myRequester = 0;
|
||||||
@ -83,13 +103,25 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(id)initWithMode:(sf::VideoMode const*)mode andStyle:(unsigned long)style
|
-(id)initWithMode:(sf::VideoMode const &)mode andStyle:(unsigned long)style
|
||||||
{
|
{
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
myRequester = 0;
|
myRequester = 0;
|
||||||
|
|
||||||
// Create our window size.
|
// Create our window size.
|
||||||
NSRect rect = NSMakeRect(0, 0, mode->Width, mode->Height);
|
NSRect rect = NSZeroRect;
|
||||||
|
if (style & sf::Style::Fullscreen && mode != sf::VideoMode::GetDesktopMode()) {
|
||||||
|
// We use desktop mode to size the window
|
||||||
|
// but we set the back buffer size to 'mode' in applyContext method.
|
||||||
|
|
||||||
|
myFullscreenMode = mode;
|
||||||
|
|
||||||
|
sf::VideoMode dm = sf::VideoMode::GetDesktopMode();
|
||||||
|
rect = NSMakeRect(0, 0, dm.Width, dm.Height);
|
||||||
|
|
||||||
|
} else { // no fullscreen requested.
|
||||||
|
rect = NSMakeRect(0, 0, mode.Width, mode.Height);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the SFML window style to Cocoa window style.
|
// Convert the SFML window style to Cocoa window style.
|
||||||
unsigned int nsStyle = NSBorderlessWindowMask;
|
unsigned int nsStyle = NSBorderlessWindowMask;
|
||||||
@ -119,7 +151,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (myWindow == nil) {
|
if (myWindow == nil) {
|
||||||
|
|
||||||
sf::Err()
|
sf::Err()
|
||||||
<< "Could not create an instance of NSWindow "
|
<< "Could not create an instance of NSWindow "
|
||||||
<< "in (SFWindowController -initWithMode:andStyle:)."
|
<< "in (SFWindowController -initWithMode:andStyle:)."
|
||||||
@ -131,9 +162,12 @@
|
|||||||
// Apply special feature for fullscreen window.
|
// Apply special feature for fullscreen window.
|
||||||
if (style & sf::Style::Fullscreen) {
|
if (style & sf::Style::Fullscreen) {
|
||||||
// We place the window above everything else.
|
// We place the window above everything else.
|
||||||
[myWindow setLevel:NSMainMenuWindowLevel+1];
|
|
||||||
[myWindow setOpaque:YES];
|
[myWindow setOpaque:YES];
|
||||||
[myWindow setHidesOnDeactivate:YES];
|
[myWindow setHidesOnDeactivate:YES];
|
||||||
|
[myWindow setLevel:NSMainMenuWindowLevel+1];
|
||||||
|
|
||||||
|
// And hide the menu bar
|
||||||
|
[NSMenu setMenuBarVisible:NO];
|
||||||
|
|
||||||
/* ---------------------------
|
/* ---------------------------
|
||||||
* | Note for future version |
|
* | Note for future version |
|
||||||
@ -143,16 +177,15 @@
|
|||||||
* a new method -enterFullScreenMode:withOptions:
|
* a new method -enterFullScreenMode:withOptions:
|
||||||
* which could be a good alternative.
|
* which could be a good alternative.
|
||||||
*/
|
*/
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Center the window to be cool =)
|
// Center the window to be cool =)
|
||||||
[myWindow center];
|
[myWindow center];
|
||||||
}
|
|
||||||
|
|
||||||
// Create the view.
|
// Create the view.
|
||||||
myOGLView = [[SFOpenGLView alloc] initWithFrame:[[myWindow contentView] frame]];
|
myOGLView = [[SFOpenGLView alloc] initWithFrame:[[myWindow contentView] frame]];
|
||||||
|
|
||||||
if (myOGLView == nil) {
|
if (myOGLView == nil) {
|
||||||
|
|
||||||
sf::Err()
|
sf::Err()
|
||||||
<< "Could not create an instance of NSOpenGLView "
|
<< "Could not create an instance of NSOpenGLView "
|
||||||
<< "in (SFWindowController -initWithMode:andStyle:)."
|
<< "in (SFWindowController -initWithMode:andStyle:)."
|
||||||
@ -161,6 +194,12 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a fullscreen window was requested...
|
||||||
|
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)];
|
||||||
|
}
|
||||||
|
|
||||||
// Set the view to the window as its content view.
|
// Set the view to the window as its content view.
|
||||||
[myWindow setContentView:myOGLView];
|
[myWindow setContentView:myOGLView];
|
||||||
|
|
||||||
@ -194,7 +233,7 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)setRequesterTo:(sf::priv::WindowImplCocoa*)requester
|
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
|
||||||
{
|
{
|
||||||
// Forward to the view.
|
// Forward to the view.
|
||||||
[myOGLView setRequesterTo:requester];
|
[myOGLView setRequesterTo:requester];
|
||||||
@ -226,9 +265,9 @@
|
|||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
|
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y
|
||||||
{
|
{
|
||||||
// Create a SFML event.
|
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
|
// Create a SFML event.
|
||||||
myRequester->MouseMovedAt(x, y);
|
myRequester->MouseMovedAt(x, y);
|
||||||
|
|
||||||
// Flip for SFML window coordinate system
|
// Flip for SFML window coordinate system
|
||||||
@ -284,7 +323,7 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)changeTitle:(NSString*)title
|
-(void)changeTitle:(NSString *)title
|
||||||
{
|
{
|
||||||
[myWindow setTitle:title];
|
[myWindow setTitle:title];
|
||||||
}
|
}
|
||||||
@ -330,7 +369,7 @@
|
|||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)setIconTo:(unsigned int)width
|
-(void)setIconTo:(unsigned int)width
|
||||||
by:(unsigned int)height
|
by:(unsigned int)height
|
||||||
with:(sf::Uint8 const*)pixels
|
with:(sf::Uint8 const *)pixels
|
||||||
{
|
{
|
||||||
// Create an empty image representation.
|
// Create an empty image representation.
|
||||||
NSBitmapImageRep* bitmap =
|
NSBitmapImageRep* bitmap =
|
||||||
@ -383,10 +422,22 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)applyContext:(NSOpenGLContext*)context
|
-(void)applyContext:(NSOpenGLContext *)context
|
||||||
{
|
{
|
||||||
[myOGLView setOpenGLContext:context];
|
[myOGLView setOpenGLContext:context];
|
||||||
[context setView:myOGLView];
|
[context setView:myOGLView];
|
||||||
|
|
||||||
|
// 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()) {
|
||||||
|
CGLContextObj cgcontext = (CGLContextObj)[context CGLContextObj];
|
||||||
|
|
||||||
|
GLint dim[2] = {myFullscreenMode.Width, myFullscreenMode.Height};
|
||||||
|
|
||||||
|
CGLSetParameter(cgcontext, kCGLCPSurfaceBackingSize, dim);
|
||||||
|
CGLEnable(cgcontext, kCGLCESurfaceBackingSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -405,7 +456,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)windowDidBecomeKey:(NSNotification*)notification {
|
-(void)windowDidBecomeKey:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
// Send event.
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
myRequester->WindowGainedFocus();
|
myRequester->WindowGainedFocus();
|
||||||
@ -413,7 +466,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(void)windowDidResignKey:(NSNotification*)notification {
|
-(void)windowDidResignKey:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
// Send event.
|
||||||
if (myRequester == 0) return;
|
if (myRequester == 0) return;
|
||||||
|
|
||||||
myRequester->WindowLostFocus();
|
myRequester->WindowLostFocus();
|
||||||
@ -424,7 +479,8 @@
|
|||||||
#pragma mark Other methods
|
#pragma mark Other methods
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(float)screenHeight {
|
-(float)screenHeight
|
||||||
|
{
|
||||||
// With Mac OS X 10.4 and 10.5, there is a shift upwards
|
// With Mac OS X 10.4 and 10.5, there is a shift upwards
|
||||||
// (about 22px – that is the apple menu bar height). With 10.6 and later
|
// (about 22px – that is the apple menu bar height). With 10.6 and later
|
||||||
// we have a workaround : we hide the dock and get the visibleFrame of the
|
// we have a workaround : we hide the dock and get the visibleFrame of the
|
||||||
@ -460,8 +516,10 @@
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
-(float)titlebarHeight {
|
-(float)titlebarHeight
|
||||||
|
{
|
||||||
return NSHeight([myWindow frame]) - NSHeight([[myWindow contentView] frame]);
|
return NSHeight([myWindow frame]) - NSHeight([[myWindow contentView] frame]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -27,79 +27,80 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/VideoModeImpl.hpp>
|
#include <SFML/Window/VideoModeImpl.hpp>
|
||||||
|
#include <SFML/Window/OSX/cg_sf_conversion.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#import <ApplicationServices/ApplicationServices.h>
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get bpp for all OS X version
|
/// Note :
|
||||||
|
/// Starting with 10.6, CGDisplayModeRef and CGDisplayCopyAllDisplayModes
|
||||||
|
/// should be used instead of CFDictionaryRef and CGDisplayAvailableModes.
|
||||||
///
|
///
|
||||||
/// This function use only non-deprecated way to get the
|
|
||||||
/// display bits per pixel information.
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
size_t DisplayBitsPerPixel(CGDirectDisplayID displayId)
|
|
||||||
{
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
|
||||||
|
|
||||||
return CGDisplayBitsPerPixel(displayId);
|
|
||||||
|
|
||||||
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
|
||||||
|
|
||||||
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
|
|
||||||
|
|
||||||
CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode);
|
|
||||||
if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
|
||||||
return 32;
|
|
||||||
else if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
|
||||||
return 16;
|
|
||||||
else if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
|
||||||
return 8;
|
|
||||||
|
|
||||||
return 0; // no match
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
|
std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
|
||||||
{
|
{
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||||
|
|
||||||
std::vector<VideoMode> modes;
|
std::vector<VideoMode> modes;
|
||||||
|
|
||||||
CGDisplayCount count = 0;
|
// Retrieve array of dictionaries representing display modes.
|
||||||
int err = CGGetActiveDisplayList(0, NULL, &count);
|
CFArrayRef displayModes = CGDisplayAvailableModes(CGMainDisplayID());
|
||||||
|
|
||||||
if (err != 0) {
|
if (displayModes == NULL) {
|
||||||
sf::Err() << "Error when retrieving displays count";
|
sf::Err() << "Couldn't get VideoMode for main display.";
|
||||||
return modes;
|
return modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGDirectDisplayID* displays = new CGDirectDisplayID[count];
|
// Loop on each mode and convert it into a sf::VideoMode object.
|
||||||
err = CGGetActiveDisplayList(count, displays, &count);
|
CFIndex const modesCount = CFArrayGetCount(displayModes);
|
||||||
|
for (CFIndex i = 0; i < modesCount; i++) {
|
||||||
|
CFDictionaryRef dictionary = (CFDictionaryRef)CFArrayGetValueAtIndex(displayModes, i);
|
||||||
|
|
||||||
if (err != 0) {
|
VideoMode mode = ConvertCGModeToSFMode(dictionary);
|
||||||
sf::Err() << "Error when retrieving displays array";
|
|
||||||
return modes;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < count; ++i) {
|
// If not yet listed we add it to our modes array.
|
||||||
VideoMode mode(CGDisplayPixelsWide(displays[i]),
|
if (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
|
||||||
CGDisplayPixelsHigh(displays[i]),
|
|
||||||
DisplayBitsPerPixel(displays[i]));
|
|
||||||
|
|
||||||
// Add it only if it isn't already in the array.
|
|
||||||
if (std::find(modes.begin(), modes.end(), mode) == modes.end())
|
|
||||||
modes.push_back(mode);
|
modes.push_back(mode);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
delete[] displays;
|
|
||||||
|
|
||||||
return modes;
|
return modes;
|
||||||
|
|
||||||
|
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
|
||||||
|
std::vector<VideoMode> modes;
|
||||||
|
|
||||||
|
// Retrieve all modes available for main screen only.
|
||||||
|
CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
|
||||||
|
|
||||||
|
if (cgmodes == NULL) {
|
||||||
|
sf::Err() << "Couldn't get VideoMode for main display.";
|
||||||
|
return modes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop on each mode and convert it into a sf::VideoMode object.
|
||||||
|
CFIndex const modesCount = CFArrayGetCount(cgmodes);
|
||||||
|
for (CFIndex i = 0; i < modesCount; i++) {
|
||||||
|
CGDisplayModeRef cgmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cgmodes, i);
|
||||||
|
|
||||||
|
VideoMode mode = ConvertCGModeToSFMode(cgmode);
|
||||||
|
|
||||||
|
// If not yet listed we add it to our modes array.
|
||||||
|
if (std::find(modes.begin(), modes.end(), mode) == modes.end()) {
|
||||||
|
modes.push_back(mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up memory.
|
||||||
|
CFRelease(cgmodes);
|
||||||
|
|
||||||
|
return modes;
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -48,6 +48,8 @@ typedef NSOpenGLContext* NSOpenGLContextRef;
|
|||||||
|
|
||||||
#else // If C++
|
#else // If C++
|
||||||
|
|
||||||
|
typedef unsigned short unichar; // See NSString.h
|
||||||
|
|
||||||
typedef void* WindowImplDelegateRef;
|
typedef void* WindowImplDelegateRef;
|
||||||
typedef void* NSAutoreleasePoolRef;
|
typedef void* NSAutoreleasePoolRef;
|
||||||
typedef void* NSOpenGLContextRef;
|
typedef void* NSOpenGLContextRef;
|
||||||
@ -89,29 +91,155 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~WindowImplCocoa();
|
~WindowImplCocoa();
|
||||||
|
|
||||||
/// Events
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Window Closed Event – called by the cocoa window object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
void WindowClosed(void);
|
void WindowClosed(void);
|
||||||
void WindowResized(unsigned int width, unsigned int height);
|
|
||||||
void WindowLostFocus(void);
|
|
||||||
void WindowGainedFocus(void);
|
|
||||||
void MouseDownAt(Mouse::Button button, int x, int y);
|
|
||||||
void MouseUpAt(Mouse::Button button, int x, int y);
|
|
||||||
void MouseMovedAt(int x, int y);
|
|
||||||
void MouseWheelScrolledAt(float delta, int x, int y);
|
|
||||||
void MouseMovedIn(void);
|
|
||||||
void MouseMovedOut(void);
|
|
||||||
void KeyDown(unsigned short keycode, unsigned int modifierFlags);
|
|
||||||
void KeyUp(unsigned short keycode, unsigned int modifierFlags);
|
|
||||||
void TextEntered(Uint32 charcode);
|
|
||||||
|
|
||||||
static Key::Code NSKeyCodeToSFMLKeyCode(unsigned short rawchar);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Window Resized Event – called by the cocoa window object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param width
|
||||||
|
/// \param height
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void WindowResized(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Window Lost Focus Event – called by the cocoa window object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void WindowLostFocus(void);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Window Get Focus Event – called by the cocoa window object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void WindowGainedFocus(void);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Mouse Down Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param button
|
||||||
|
/// \param x
|
||||||
|
/// \param y
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void MouseDownAt(Mouse::Button button, int x, int y);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Mouse Up Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param button
|
||||||
|
/// \param x
|
||||||
|
/// \param y
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void MouseUpAt(Mouse::Button button, int x, int y);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Mouse Moved Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param x
|
||||||
|
/// \param y
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void MouseMovedAt(int x, int y);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Mouse Wheel Scrolled Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param delta
|
||||||
|
/// \param x
|
||||||
|
/// \param y
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void MouseWheelScrolledAt(float delta, int x, int y);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Mouse In Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void MouseMovedIn(void);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Mouse Out Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void MouseMovedOut(void);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Key Down Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param keycode
|
||||||
|
/// \param modifierFlags
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void KeyDown(unsigned short keycode, unsigned int modifierFlags);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Key Up Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param keycode
|
||||||
|
/// \param modifierFlags
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void KeyUp(unsigned short keycode, unsigned int modifierFlags);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Text Entred Event – called by the cocoa view object.
|
||||||
|
///
|
||||||
|
/// Send the event to SFML WindowImpl class.
|
||||||
|
///
|
||||||
|
/// \param charcode Input unicode
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
void TextEntered(unichar charcode);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Apply the context to the view.
|
||||||
|
///
|
||||||
|
/// Called by the SFML context object to finalize its creation.
|
||||||
|
///
|
||||||
|
/// \param context The context to bind to the window
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void ApplyContext(NSOpenGLContextRef context) const;
|
void ApplyContext(NSOpenGLContextRef context) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Convert Cocoa keycode to SFML keycode.
|
||||||
|
///
|
||||||
|
/// \param rawchar Cocoa keycode to convert
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
static Key::Code NSKeyCodeToSFMLKeyCode(unichar rawchar);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Process incoming events from the operating system
|
/// \brief Process incoming events from the operating system
|
||||||
///
|
///
|
||||||
@ -199,11 +327,13 @@ private:
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the pool after ensuring NSApp is valid.
|
/// \brief Construct the pool after ensuring NSApp is valid.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void SetUpPoolAndApplication(void);
|
void SetUpPoolAndApplication(void);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the type of the current process to become a full GUI app.
|
/// \brief Change the type of the current process to become a full GUI app.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void SetUpProcessAsApplication(void);
|
static void SetUpProcessAsApplication(void);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -92,7 +92,7 @@ WindowImplCocoa::WindowImplCocoa(VideoMode mode,
|
|||||||
myWidth = mode.Width;
|
myWidth = mode.Width;
|
||||||
myHeight = mode.Height;
|
myHeight = mode.Height;
|
||||||
|
|
||||||
myDelegate = [[SFWindowController alloc] initWithMode:&mode andStyle:style];
|
myDelegate = [[SFWindowController alloc] initWithMode:mode andStyle:style];
|
||||||
[myDelegate changeTitle:stringToNSString(title)];
|
[myDelegate changeTitle:stringToNSString(title)];
|
||||||
[myDelegate setRequesterTo:this];
|
[myDelegate setRequesterTo:this];
|
||||||
}
|
}
|
||||||
@ -281,7 +281,7 @@ void WindowImplCocoa::KeyUp(unsigned short keycode, unsigned int modifierFlags)
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void WindowImplCocoa::TextEntered(Uint32 charcode)
|
void WindowImplCocoa::TextEntered(unichar charcode)
|
||||||
{
|
{
|
||||||
Event event;
|
Event event;
|
||||||
event.Type = Event::TextEntered;
|
event.Type = Event::TextEntered;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -58,51 +58,91 @@ namespace sf {
|
|||||||
///
|
///
|
||||||
/// Note : Joystick are not bound to a view or window
|
/// Note : Joystick are not bound to a view or window
|
||||||
/// thus they're not managed by a class implementing this protocol.
|
/// thus they're not managed by a class implementing this protocol.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@protocol WindowImplDelegateProtocol
|
@protocol WindowImplDelegateProtocol
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Set the WindowImpl who requested this delegate
|
/// Set the WindowImpl who requested this delegate
|
||||||
/// (This would be a ctor in C++ or Java where we can prohibit the
|
/// (This would be a ctor in C++ or Java where we can prohibit the
|
||||||
/// construction of an object.)
|
/// construction of an object.)
|
||||||
-(void)setRequesterTo:(sf::priv::WindowImplCocoa*)requester;
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Return the main view or window.
|
/// Return the main view or window.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(sf::WindowHandle)getSystemHandle;
|
-(sf::WindowHandle)getSystemHandle;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Hide or show the mouse cursor.
|
/// Hide or show the mouse cursor.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)hideMouseCursor;
|
-(void)hideMouseCursor;
|
||||||
-(void)showMouseCursor;
|
-(void)showMouseCursor;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Move the mouse cursor to (x,y) (SFML Coordinates).
|
/// Move the mouse cursor to (x,y) (SFML Coordinates).
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y;
|
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Move the window (not the view if we handle not a window) (SFML Coordinates).
|
/// Move the window (not the view if we handle not a window) (SFML Coordinates).
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y;
|
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Resize the window/view.
|
/// Resize the window/view.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)resizeTo:(unsigned int)width by:(unsigned int)height;
|
-(void)resizeTo:(unsigned int)width by:(unsigned int)height;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Set the title (does nothing if we manage a view).
|
/// Set the title (does nothing if we manage a view).
|
||||||
-(void)changeTitle:(NSString*)title;
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(void)changeTitle:(NSString *)title;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Hide or show the window (does nothing if we manage a view).
|
/// Hide or show the window (does nothing if we manage a view).
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)hideWindow;
|
-(void)hideWindow;
|
||||||
-(void)showWindow;
|
-(void)showWindow;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Close the window (does nothing if we manage a view).
|
/// Close the window (does nothing if we manage a view).
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)closeWindow;
|
-(void)closeWindow;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Enable or disable key repeat.
|
/// Enable or disable key repeat.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)enableKeyRepeat;
|
-(void)enableKeyRepeat;
|
||||||
-(void)disableKeyRepeat;
|
-(void)disableKeyRepeat;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Set an icon to the application.
|
/// Set an icon to the application.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)setIconTo:(unsigned int)width by:(unsigned int)height with:(sf::Uint8 const*)pixels;
|
-(void)setIconTo:(unsigned int)width by:(unsigned int)height with:(sf::Uint8 const*)pixels;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Fetch new event
|
/// Fetch new event
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
-(void)processEventWithBlockingMode:(BOOL)block;
|
-(void)processEventWithBlockingMode:(BOOL)block;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
/// Apply a given context to an OpenGL view.
|
/// Apply a given context to an OpenGL view.
|
||||||
-(void)applyContext:(NSOpenGLContext*)context;
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
-(void)applyContext:(NSOpenGLContext *)context;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
181
src/SFML/Window/OSX/cg_sf_conversion.cpp
Normal file
181
src/SFML/Window/OSX/cg_sf_conversion.cpp
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SFML - Simple and Fast Multimedia Library
|
||||||
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
|
//
|
||||||
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
//
|
||||||
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
|
// subject to the following restrictions:
|
||||||
|
//
|
||||||
|
// 1. The origin of this software must not be misrepresented;
|
||||||
|
// you must not claim that you wrote the original software.
|
||||||
|
// If you use this software in a product, an acknowledgment
|
||||||
|
// in the product documentation would be appreciated but is not required.
|
||||||
|
//
|
||||||
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
|
// and must not be misrepresented as being the original software.
|
||||||
|
//
|
||||||
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Headers
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
#include <SFML/Window/OSX/cg_sf_conversion.hpp>
|
||||||
|
#include <SFML/System/Err.hpp>
|
||||||
|
|
||||||
|
namespace sf
|
||||||
|
{
|
||||||
|
namespace priv
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
size_t ModeBitsPerPixel(CGDisplayModeRef mode)
|
||||||
|
{
|
||||||
|
size_t bpp = 0; // no match
|
||||||
|
|
||||||
|
// Compare encoding.
|
||||||
|
CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode);
|
||||||
|
if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||||
|
|
||||||
|
bpp = 32;
|
||||||
|
|
||||||
|
} else if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||||
|
|
||||||
|
bpp = 16;
|
||||||
|
|
||||||
|
} else if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
||||||
|
|
||||||
|
bpp = 8;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up memory.
|
||||||
|
CFRelease(pixEnc);
|
||||||
|
|
||||||
|
return bpp;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
size_t DisplayBitsPerPixel(CGDirectDisplayID displayId)
|
||||||
|
{
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||||
|
|
||||||
|
return CGDisplayBitsPerPixel(displayId);
|
||||||
|
|
||||||
|
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
|
||||||
|
// Get the display mode.
|
||||||
|
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
|
||||||
|
|
||||||
|
// Get bpp for the mode.
|
||||||
|
size_t const bpp = ModeBitsPerPixel(mode);
|
||||||
|
|
||||||
|
// Clean up Memory.
|
||||||
|
CGDisplayModeRelease(mode);
|
||||||
|
|
||||||
|
return bpp;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||||
|
|
||||||
|
VideoMode ConvertCGModeToSFMode(CFDictionaryRef dictionary)
|
||||||
|
{
|
||||||
|
VideoMode sfmode;
|
||||||
|
|
||||||
|
CFNumberRef cfnumber = (CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayWidth);
|
||||||
|
CFNumberGetValue(cfnumber, kCFNumberIntType, &(mode.Width));
|
||||||
|
|
||||||
|
cfnumber = (CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayHeight);
|
||||||
|
CFNumberGetValue(cfnumber, kCFNumberIntType, &(mode.Height));
|
||||||
|
|
||||||
|
cfnumber = (CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayBitsPerPixel);
|
||||||
|
CFNumberGetValue(cfnumber, kCFNumberIntType, &(mode.BitsPerPixel));
|
||||||
|
|
||||||
|
return sfmode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
|
||||||
|
VideoMode ConvertCGModeToSFMode(CGDisplayModeRef cgmode)
|
||||||
|
{
|
||||||
|
return VideoMode(CGDisplayModeGetWidth(cgmode),
|
||||||
|
CGDisplayModeGetHeight(cgmode),
|
||||||
|
ModeBitsPerPixel(cgmode));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||||
|
|
||||||
|
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
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
|
||||||
|
CGDisplayModeRef ConvertSFModeToCGMode(VideoMode sfmode)
|
||||||
|
{
|
||||||
|
// Starting with 10.6 we should query the display all the modes and
|
||||||
|
// search for the best one.
|
||||||
|
|
||||||
|
// Will return NULL if sfmode is not in VideoMode::GetFullscreenModes.
|
||||||
|
CGDisplayModeRef cgbestMode = NULL;
|
||||||
|
|
||||||
|
// Retrieve all modes available for main screen only.
|
||||||
|
CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL);
|
||||||
|
|
||||||
|
if (cgmodes == NULL) { // Should not happen but anyway...
|
||||||
|
sf::Err() << "Couldn't get VideoMode for main display.";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop on each mode and convert it into a sf::VideoMode object.
|
||||||
|
CFIndex const modesCount = CFArrayGetCount(cgmodes);
|
||||||
|
for (CFIndex i = 0; i < modesCount; i++) {
|
||||||
|
CGDisplayModeRef cgmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cgmodes, i);
|
||||||
|
|
||||||
|
VideoMode mode = ConvertCGModeToSFMode(cgmode);
|
||||||
|
|
||||||
|
if (mode == sfmode) {
|
||||||
|
cgbestMode = cgmode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up memory.
|
||||||
|
CFRelease(cgmodes);
|
||||||
|
|
||||||
|
if (cgbestMode == NULL) {
|
||||||
|
sf::Err()
|
||||||
|
<< "Couldn't convert the given sf:VideoMode into a CGDisplayMode."
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cgbestMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace priv
|
||||||
|
} // namespace sf
|
82
src/SFML/Window/OSX/cg_sf_conversion.hpp
Normal file
82
src/SFML/Window/OSX/cg_sf_conversion.hpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SFML - Simple and Fast Multimedia Library
|
||||||
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
|
//
|
||||||
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
//
|
||||||
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
|
// subject to the following restrictions:
|
||||||
|
//
|
||||||
|
// 1. The origin of this software must not be misrepresented;
|
||||||
|
// you must not claim that you wrote the original software.
|
||||||
|
// If you use this software in a product, an acknowledgment
|
||||||
|
// in the product documentation would be appreciated but is not required.
|
||||||
|
//
|
||||||
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
|
// and must not be misrepresented as being the original software.
|
||||||
|
//
|
||||||
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef SFML_CG_SF_CONVERSION_HPP
|
||||||
|
#define SFML_CG_SF_CONVERSION_HPP
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Headers
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
#include <SFML/Window/VideoMode.hpp>
|
||||||
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
|
|
||||||
|
namespace sf
|
||||||
|
{
|
||||||
|
namespace priv
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get bpp of a video mode for OS 10.6 or later.
|
||||||
|
///
|
||||||
|
/// With OS 10.6 and later, Quartz doesn't use anymore dictionaries
|
||||||
|
/// to represent video mode. Instead it uses a CGDisplayMode opaque type.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
size_t ModeBitsPerPixel(CGDisplayModeRef mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get bpp for all OS X version.
|
||||||
|
///
|
||||||
|
/// This function use only non-deprecated way to get the
|
||||||
|
/// display bits per pixel information for a given display id.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
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);
|
||||||
|
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
VideoMode ConvertCGModeToSFMode(CGDisplayModeRef cgmode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Convert a sf::VideoMode object into a Quartz video mode.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
|
||||||
|
CFDictionaryRef ConvertSFModeToCGMode(VideoMode sfmode);
|
||||||
|
#else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
|
||||||
|
CGDisplayModeRef ConvertSFModeToCGMode(VideoMode sfmode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace priv
|
||||||
|
} // namespace sf
|
||||||
|
|
||||||
|
#endif
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Returns a NSString construct with +stringWithCString:encoding:.
|
/// \brief Returns a NSString construct with +stringWithCString:encoding:.
|
||||||
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
NSString* stringToNSString(std::string const& string);
|
NSString* stringToNSString(std::string const& string);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com),
|
// Copyright (C) 2007-2011 Marco Antognini (antognini.marco@gmail.com),
|
||||||
// Laurent Gomila (laurent.gom@gmail.com),
|
// Laurent Gomila (laurent.gom@gmail.com),
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
Loading…
Reference in New Issue
Block a user