summaryrefslogtreecommitdiff
path: root/src/SFML/Window/OSX/SFViewController.mm
diff options
context:
space:
mode:
authorJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
committerJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
commitfa21c65d0c764705cfc377bf0d0de08fac26874e (patch)
treedbc9e87bbd8684d15e79fc0c8b7a8985389c3b35 /src/SFML/Window/OSX/SFViewController.mm
parentdd835931261c340acd5f0409341d13fa2670423e (diff)
Imported Upstream version 2.2.0+dfsg
Diffstat (limited to 'src/SFML/Window/OSX/SFViewController.mm')
-rw-r--r--src/SFML/Window/OSX/SFViewController.mm128
1 files changed, 76 insertions, 52 deletions
diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm
index d9cc4c7..ba2e8a0 100644
--- a/src/SFML/Window/OSX/SFViewController.mm
+++ b/src/SFML/Window/OSX/SFViewController.mm
@@ -1,8 +1,8 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
-// Laurent Gomila (laurent.gom@gmail.com),
+// Copyright (C) 2007-2014 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.
@@ -26,55 +26,55 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
-#import <SFML/Window/OSX/SFViewController.h>
-#import <SFML/Window/OSX/SFOpenGLView.h>
-#import <SFML/Window/OSX/SFApplication.h>
#include <SFML/System/Err.hpp>
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
+#import <SFML/Window/OSX/SFApplication.h>
+#import <SFML/Window/OSX/SFOpenGLView.h>
+#import <SFML/Window/OSX/SFViewController.h>
+
@implementation SFViewController
////////////////////////////////////////////////////////
-(id)initWithView:(NSView *)view
{
- if ((self = [super init])) {
+ if ((self = [super init]))
+ {
m_requester = 0;
-
+
// Retain the view for our own use.
m_view = [view retain];
-
- if (m_view == nil) {
-
- sf::err()
- << "No view was given to initWithWindow:."
- << std::endl;
-
+
+ if (m_view == nil)
+ {
+ sf::err() << "No view was given to initWithWindow:." << std::endl;
return self;
}
-
+
// Create the view.
NSRect frame = [m_view frame];
frame.origin.x = 0;
frame.origin.y = 0;
m_oglView = [[SFOpenGLView alloc] initWithFrame:frame];
-
- if (m_oglView == nil) {
-
- sf::err()
- << "Could not create an instance of NSOpenGLView "
- << "in (SFViewController -initWithView:)."
- << std::endl;
-
+
+ if (m_oglView == nil)
+ {
+ sf::err() << "Could not create an instance of NSOpenGLView "
+ << "in (SFViewController -initWithView:)."
+ << std::endl;
+
return self;
}
-
+
// Set the (OGL) view to the view as its "content" view.
[m_view addSubview:m_oglView];
-
+
[m_oglView setAutoresizingMask:[m_view autoresizingMask]];
+
+ [m_oglView finishInit];
}
-
+
return self;
}
@@ -83,41 +83,41 @@
-(void)dealloc
{
[self closeWindow];
-
+
[m_view release];
[m_oglView release];
-
+
[super dealloc];
}
////////////////////////////////////////////////////////
--(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
+-(CGFloat)displayScaleFactor
{
- // Forward to the view.
- [m_oglView setRequesterTo:requester];
- m_requester = requester;
+ return [m_oglView displayScaleFactor];
}
////////////////////////////////////////////////////////
--(sf::WindowHandle)getSystemHandle
+-(void)setRequesterTo:(sf::priv::WindowImplCocoa*)requester
{
- return m_view;
+ // Forward to the view.
+ [m_oglView setRequesterTo:requester];
+ m_requester = requester;
}
////////////////////////////////////////////////////////
--(void)hideMouseCursor
+-(sf::WindowHandle)getSystemHandle
{
- [NSCursor hide];
+ return m_view;
}
////////////////////////////////////////////////////////
--(void)showMouseCursor
+-(BOOL)isMouseInside
{
- [NSCursor unhide];
+ return [m_oglView isMouseInside];
}
@@ -132,7 +132,9 @@
////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(int)x Y:(int)y
{
- sf::err() << "Cannot move SFML area when SFML is integrated in a NSView. Use the view hanlder directly instead." << std::endl;
+ (void)x;
+ (void)y;
+ sf::err() << "Cannot move SFML area when SFML is integrated in a NSView. Use the view handler directly instead." << std::endl;
}
@@ -150,15 +152,16 @@
[m_view frame].origin.y,
width,
height);
-
+
[m_view setFrame:frame];
[m_oglView setFrame:frame];
}
////////////////////////////////////////////////////////
--(void)changeTitle:(NSString *)title
+-(void)changeTitle:(NSString*)title
{
+ (void)title;
sf::err() << "Cannot change the title of the SFML area when SFML is integrated in a NSView." << std::endl;
}
@@ -185,6 +188,26 @@
////////////////////////////////////////////////////////
+-(void)requestFocus
+{
+ // Note: this doesn't imply that the view will get any event.
+ // The user has to make sure events are forwarded to the view
+ // with the usual responder chain.
+ [[m_view window] makeKeyAndOrderFront:nil];
+
+ // In case the app is not active, make its dock icon bounce for one sec
+ [NSApp requestUserAttention:NSInformationalRequest];
+}
+
+
+////////////////////////////////////////////////////////////
+-(BOOL)hasFocus
+{
+ return [NSApp keyWindow] == [m_view window];
+}
+
+
+////////////////////////////////////////////////////////
-(void)enableKeyRepeat
{
[m_oglView enableKeyRepeat];
@@ -200,9 +223,12 @@
////////////////////////////////////////////////////////
-(void)setIconTo:(unsigned int)width
- by:(unsigned int)height
- with:(sf::Uint8 const *)pixels
+ by:(unsigned int)height
+ with:(const sf::Uint8*)pixels
{
+ (void)width;
+ (void)height;
+ (void)pixels;
sf::err() << "Cannot set an icon when SFML is integrated in a NSView." << std::endl;
}
@@ -211,27 +237,25 @@
-(void)processEvent
{
// If we are not on the main thread we stop here and advice the user.
- if ([NSThread currentThread] != [NSThread mainThread]) {
+ if ([NSThread currentThread] != [NSThread mainThread])
+ {
/*
* See http://lists.apple.com/archives/cocoa-dev/2011/Feb/msg00460.html
* for more information.
*/
- sf::err()
- << "Cannot fetch event from a worker thread. (OS X restriction)"
- << std::endl;
-
+ sf::err() << "Cannot fetch event from a worker thread. (OS X restriction)" << std::endl;
+
return;
}
-
+
// If we don't have a requester we don't fetch event.
- if (m_requester != 0) {
+ if (m_requester != 0)
[SFApplication processEvent];
- }
}
////////////////////////////////////////////////////////
--(void)applyContext:(NSOpenGLContext *)context
+-(void)applyContext:(NSOpenGLContext*)context
{
[m_oglView setOpenGLContext:context];
[context setView:m_oglView];