Synchronized with trunk
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1442 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
4e93cc92fa
18 changed files with 1196 additions and 471 deletions
|
@ -380,7 +380,9 @@ Ftp::Response Ftp::Download(const std::string& distantFile, const std::string& d
|
|||
std::ofstream file((path + filename).c_str(), std::ios_base::binary);
|
||||
if (!file)
|
||||
return Response(Response::InvalidFile);
|
||||
file.write(&fileData[0], static_cast<std::streamsize>(fileData.size()));
|
||||
|
||||
if (!fileData.empty())
|
||||
file.write(&fileData[0], static_cast<std::streamsize>(fileData.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -398,11 +400,13 @@ Ftp::Response Ftp::Upload(const std::string& localFile, const std::string& destP
|
|||
std::ifstream file(localFile.c_str(), std::ios_base::binary);
|
||||
if (!file)
|
||||
return Response(Response::InvalidFile);
|
||||
|
||||
file.seekg(0, std::ios::end);
|
||||
std::size_t length = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
std::vector<char> fileData(length);
|
||||
file.read(&fileData[0], static_cast<std::streamsize>(length));
|
||||
if (length > 0)
|
||||
file.read(&fileData[0], static_cast<std::streamsize>(length));
|
||||
|
||||
// Extract the filename from the file path
|
||||
std::string filename = localFile;
|
||||
|
@ -700,7 +704,8 @@ void Ftp::DataChannel::Receive(std::vector<char>& data)
|
|||
void Ftp::DataChannel::Send(const std::vector<char>& data)
|
||||
{
|
||||
// Send data
|
||||
myDataSocket.Send(&data[0], data.size());
|
||||
if (!data.empty())
|
||||
myDataSocket.Send(&data[0], data.size());
|
||||
|
||||
// Close the data socket
|
||||
myDataSocket.Close();
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Http.hpp>
|
||||
#include <ctype.h>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
@ -294,8 +296,7 @@ void Http::Response::FromString(const std::string& data)
|
|||
|
||||
// Finally extract the body
|
||||
myBody.clear();
|
||||
while (std::getline(in, line))
|
||||
myBody += line + "\n";
|
||||
std::copy(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>(), std::back_inserter(myBody));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -344,11 +344,20 @@ Socket::Status SocketTCP::Receive(Packet& packet)
|
|||
std::size_t received = 0;
|
||||
if (myPendingPacketSize < 0)
|
||||
{
|
||||
Socket::Status status = Receive(reinterpret_cast<char*>(&packetSize), sizeof(packetSize), received);
|
||||
if (status != Socket::Done)
|
||||
return status;
|
||||
// Loop until we've received the entire size of the packet
|
||||
// (even a 4 bytes variable may be received in more than one call)
|
||||
while (myPendingHeaderSize < sizeof(myPendingHeader))
|
||||
{
|
||||
char* data = reinterpret_cast<char*>(&myPendingHeader) + myPendingHeaderSize;
|
||||
Socket::Status status = Receive(data, sizeof(myPendingHeader) - myPendingHeaderSize, received);
|
||||
myPendingHeaderSize += received;
|
||||
|
||||
packetSize = ntohl(packetSize);
|
||||
if (status != Socket::Done)
|
||||
return status;
|
||||
}
|
||||
|
||||
packetSize = ntohl(myPendingHeader);
|
||||
myPendingHeaderSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -472,6 +481,7 @@ void SocketTCP::Create(SocketHelper::SocketType descriptor)
|
|||
myIsBlocking = true;
|
||||
|
||||
// Reset the pending packet
|
||||
myPendingHeaderSize = 0;
|
||||
myPendingPacket.clear();
|
||||
myPendingPacketSize = -1;
|
||||
|
||||
|
|
|
@ -249,11 +249,20 @@ Socket::Status SocketUDP::Receive(Packet& packet, IPAddress& address, unsigned s
|
|||
std::size_t received = 0;
|
||||
if (myPendingPacketSize < 0)
|
||||
{
|
||||
Socket::Status status = Receive(reinterpret_cast<char*>(&packetSize), sizeof(packetSize), received, address, port);
|
||||
if (status != Socket::Done)
|
||||
return status;
|
||||
// Loop until we've received the entire size of the packet
|
||||
// (even a 4 bytes variable may be received in more than one call)
|
||||
while (myPendingHeaderSize < sizeof(myPendingHeader))
|
||||
{
|
||||
char* data = reinterpret_cast<char*>(&myPendingHeader) + myPendingHeaderSize;
|
||||
Socket::Status status = Receive(data, sizeof(myPendingHeader) - myPendingHeaderSize, received, address, port);
|
||||
myPendingHeaderSize += received;
|
||||
|
||||
packetSize = ntohl(packetSize);
|
||||
if (status != Socket::Done)
|
||||
return status;
|
||||
}
|
||||
|
||||
packetSize = ntohl(myPendingHeader);
|
||||
myPendingHeaderSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -261,9 +270,6 @@ Socket::Status SocketUDP::Receive(Packet& packet, IPAddress& address, unsigned s
|
|||
packetSize = myPendingPacketSize;
|
||||
}
|
||||
|
||||
// Clear the user packet
|
||||
packet.Clear();
|
||||
|
||||
// Use another address instance for receiving the packet data ;
|
||||
// chunks of data coming from a different sender will be discarded (and lost...)
|
||||
IPAddress sender;
|
||||
|
@ -398,6 +404,7 @@ void SocketUDP::Create(SocketHelper::SocketType descriptor)
|
|||
myPort = 0;
|
||||
|
||||
// Reset the pending packet
|
||||
myPendingHeaderSize = 0;
|
||||
myPendingPacket.clear();
|
||||
myPendingPacketSize = -1;
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Randomizer.hpp>
|
||||
#include <SFML/System/Platform.hpp>
|
||||
#include <cstdlib>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -39,7 +39,7 @@ namespace
|
|||
// in milliseconds, so that it is always different
|
||||
unsigned int InitializeSeed()
|
||||
{
|
||||
unsigned int seed = static_cast<unsigned int>(sf::priv::Platform::GetSystemTime() * 1000);
|
||||
unsigned int seed = static_cast<unsigned int>(time(NULL));
|
||||
srand(seed);
|
||||
return seed;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ Thread::~Thread()
|
|||
////////////////////////////////////////////////////////////
|
||||
void Thread::Launch()
|
||||
{
|
||||
delete myThreadImpl;
|
||||
Wait();
|
||||
myThreadImpl = new priv::ThreadImpl(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ enum {
|
|||
CleanScreen
|
||||
};
|
||||
|
||||
@class WindowWrapper;
|
||||
@interface AppController : NSObject {
|
||||
@class sfPrivWindow;
|
||||
@interface sfPrivAppController : NSObject {
|
||||
BOOL myOwningEventLoop;
|
||||
WindowWrapper *myFullscreenWrapper;
|
||||
sfPrivWindow *myFullscreenWrapper;
|
||||
NSAutoreleasePool *myMainPool;
|
||||
sf::VideoMode myDesktopMode;
|
||||
sf::VideoMode myPrevMode;
|
||||
|
@ -48,7 +48,7 @@ enum {
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Return the shared AppController instance. Make one if needed.
|
||||
////////////////////////////////////////////////////////////
|
||||
+ (AppController *)sharedController;
|
||||
+ (sfPrivAppController *)sharedController;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Returns the primay computer's screen
|
||||
|
@ -76,7 +76,7 @@ enum {
|
|||
/// Set @window as the current fullscreen window
|
||||
/// Change the screen resolution if needed according to @window and @fullscreenMode
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)setFullscreenWindow:(WindowWrapper *)window mode:(sf::VideoMode *)fullscreenMode;
|
||||
- (void)setFullscreenWindow:(sfPrivWindow *)window mode:(sf::VideoMode *)fullscreenMode;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Perform fade operation where 'operation' is one of { FillScreen, CleanScreen}
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
@end
|
||||
|
||||
|
||||
@implementation AppController
|
||||
@implementation sfPrivAppController
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -129,10 +129,10 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Return the shared AppController instance. Make one if needed.
|
||||
////////////////////////////////////////////////////////////
|
||||
+ (AppController *)sharedController
|
||||
+ (sfPrivAppController *)sharedController
|
||||
{
|
||||
// AppController singleton object
|
||||
static AppController *shared = [[AppController alloc] init];
|
||||
static sfPrivAppController *shared = [[sfPrivAppController alloc] init];
|
||||
return shared;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@
|
|||
if (myFullscreenWrapper) {
|
||||
myPrevMode = sf::VideoMode::GetDesktopMode();
|
||||
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([AppController primaryScreen],
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
|
||||
myDesktopMode.BitsPerPixel,
|
||||
myDesktopMode.Width,
|
||||
myDesktopMode.Height,
|
||||
|
@ -202,7 +202,7 @@
|
|||
[[myFullscreenWrapper window] setAlphaValue:0.0f];
|
||||
|
||||
// Switch to the wished display mode
|
||||
CGDisplaySwitchToMode([AppController primaryScreen], displayMode);
|
||||
CGDisplaySwitchToMode([sfPrivAppController primaryScreen], displayMode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@
|
|||
- (void)applicationWillActivate:(NSNotification *)aNotification
|
||||
{
|
||||
if (myFullscreenWrapper) {
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([AppController primaryScreen],
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
|
||||
myPrevMode.BitsPerPixel,
|
||||
myPrevMode.Width,
|
||||
myPrevMode.Height,
|
||||
|
@ -221,7 +221,7 @@
|
|||
[NSMenu setMenuBarVisible:NO];
|
||||
|
||||
// Switch to the wished display mode
|
||||
CGDisplaySwitchToMode([AppController primaryScreen], displayMode);
|
||||
CGDisplaySwitchToMode([sfPrivAppController primaryScreen], displayMode);
|
||||
|
||||
// Show the fullscreen window if existing
|
||||
if (myFullscreenWrapper)
|
||||
|
@ -380,14 +380,14 @@
|
|||
myOwningEventLoop = YES;
|
||||
}
|
||||
|
||||
// Clean the autorelease pool
|
||||
[myMainPool release];
|
||||
myMainPool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSEvent *event = nil;
|
||||
|
||||
if (myOwningEventLoop)
|
||||
{
|
||||
// Clean the autorelease pool
|
||||
[myMainPool release];
|
||||
myMainPool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Minimal event loop
|
||||
while (nil != (event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
||||
untilDate:nil
|
||||
|
@ -404,13 +404,13 @@
|
|||
/// Set @window as the current fullscreen window
|
||||
/// Change the screen resolution if needed according to @window and @fullscreenMode
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)setFullscreenWindow:(WindowWrapper *)aWrapper mode:(sf::VideoMode *)fullscreenMode
|
||||
- (void)setFullscreenWindow:(sfPrivWindow *)aWindow mode:(sf::VideoMode *)fullscreenMode
|
||||
{
|
||||
// If we have a fullscreen window and want to remove it
|
||||
if (aWrapper == nil && myFullscreenWrapper)
|
||||
if (aWindow == nil && myFullscreenWrapper)
|
||||
{
|
||||
// Get the CoreGraphics display mode according to the desktop mode
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([AppController primaryScreen],
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
|
||||
myDesktopMode.BitsPerPixel,
|
||||
myDesktopMode.Width,
|
||||
myDesktopMode.Height,
|
||||
|
@ -422,7 +422,7 @@
|
|||
#endif
|
||||
|
||||
// Switch to the desktop display mode
|
||||
CGDisplaySwitchToMode([AppController primaryScreen], displayMode);
|
||||
CGDisplaySwitchToMode([sfPrivAppController primaryScreen], displayMode);
|
||||
|
||||
// Close the window
|
||||
[[myFullscreenWrapper window] close];
|
||||
|
@ -438,13 +438,13 @@
|
|||
// Release the saved window wrapper
|
||||
myFullscreenWrapper = nil;
|
||||
}
|
||||
else if (aWrapper)
|
||||
else if (aWindow)
|
||||
{
|
||||
// else if we want to SET fullscreen
|
||||
assert(fullscreenMode != NULL);
|
||||
|
||||
// Get the CoreGraphics display mode according to the given sf mode
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([AppController primaryScreen],
|
||||
CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
|
||||
fullscreenMode->BitsPerPixel,
|
||||
fullscreenMode->Width,
|
||||
fullscreenMode->Height,
|
||||
|
@ -465,7 +465,7 @@
|
|||
{
|
||||
// Switch to the wished display mode
|
||||
myPrevMode = *fullscreenMode;
|
||||
CGDisplaySwitchToMode([AppController primaryScreen], displayMode);
|
||||
CGDisplaySwitchToMode([sfPrivAppController primaryScreen], displayMode);
|
||||
}
|
||||
|
||||
if (myFullscreenWrapper)
|
||||
|
@ -474,8 +474,8 @@
|
|||
}
|
||||
|
||||
// Open and center the window
|
||||
[[aWrapper window] makeKeyAndOrderFront:nil];
|
||||
[[aWrapper window] center];
|
||||
[[aWindow window] makeKeyAndOrderFront:nil];
|
||||
[[aWindow window] center];
|
||||
|
||||
#if ENABLE_FADE_OPERATIONS
|
||||
// Fade to normal screen
|
||||
|
@ -483,11 +483,11 @@
|
|||
#endif
|
||||
|
||||
// Save the fullscreen wrapper
|
||||
myFullscreenWrapper = aWrapper;
|
||||
myFullscreenWrapper = aWindow;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Inconcistency error for arguments given to -[AppController setFullscreenWindow:mode:]" << std::endl;
|
||||
std::cerr << "Inconcistency error for arguments given to -[sfPrivAppController setFullscreenWindow:mode:]" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,7 +514,7 @@
|
|||
if (!result) {
|
||||
// Capture display but do not fill the screen with black
|
||||
// so that we can see the fade operation
|
||||
capture = CGDisplayCaptureWithOptions([AppController primaryScreen], kCGCaptureNoFill);
|
||||
capture = CGDisplayCaptureWithOptions([sfPrivAppController primaryScreen], kCGCaptureNoFill);
|
||||
|
||||
if (!capture) {
|
||||
// Do the increasing fade operation
|
||||
|
@ -524,11 +524,11 @@
|
|||
0.0f, 0.0f, 0.0f, sync);
|
||||
|
||||
// Now, release the non black-filling capture
|
||||
CGDisplayRelease([AppController primaryScreen]);
|
||||
CGDisplayRelease([sfPrivAppController primaryScreen]);
|
||||
|
||||
// And capture with filling
|
||||
// so that we don't see the switching in the meantime
|
||||
CGDisplayCaptureWithOptions([AppController primaryScreen], kCGCaptureNoOptions);
|
||||
CGDisplayCaptureWithOptions([sfPrivAppController primaryScreen], kCGCaptureNoOptions);
|
||||
}
|
||||
|
||||
prevToken = token;
|
||||
|
@ -541,10 +541,10 @@
|
|||
if (!result) {
|
||||
if (!capture) {
|
||||
// Release the black-filling capture
|
||||
CGDisplayRelease([AppController primaryScreen]);
|
||||
CGDisplayRelease([sfPrivAppController primaryScreen]);
|
||||
|
||||
// Capture the display but do not fill with black (still for the fade operation)
|
||||
CGDisplayCaptureWithOptions([AppController primaryScreen], kCGCaptureNoFill);
|
||||
CGDisplayCaptureWithOptions([sfPrivAppController primaryScreen], kCGCaptureNoFill);
|
||||
|
||||
// Do the decreasing fading
|
||||
CGDisplayFade(token, time,
|
||||
|
@ -560,7 +560,7 @@
|
|||
}
|
||||
|
||||
// Release the captured display
|
||||
CGDisplayRelease([AppController primaryScreen]);
|
||||
CGDisplayRelease([sfPrivAppController primaryScreen]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Window independant OpenGL context class
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface GLContext : NSOpenGLContext
|
||||
{
|
||||
|
||||
}
|
||||
@interface sfPrivGLContext : NSOpenGLContext
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the shared OpenGL context instance (making one if needed)
|
||||
|
@ -47,7 +44,7 @@
|
|||
/// and the shared context @context
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithAttributes:(sf::WindowSettings&)attribs
|
||||
sharedContext:(GLContext *)context;
|
||||
sharedContext:(sfPrivGLContext *)context;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -55,22 +52,31 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Customized Cocoa OpenGL view
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface GLView : NSOpenGLView
|
||||
@interface sfPrivGLView : NSOpenGLView
|
||||
{
|
||||
sf::priv::WindowImplCocoa *myDelegate;
|
||||
GLContext *myGLContext;
|
||||
sfPrivGLContext *myGLContext;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Make a new view according the the rect @frame,
|
||||
/// the video mode @mode, the window settings @settings
|
||||
/// and the sf window delegate @delegate
|
||||
/// @delegate must not be null
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithFrame:(NSRect)frame
|
||||
mode:(const sf::VideoMode&)mode
|
||||
settings:(sf::WindowSettings&)settings
|
||||
delegate:(sf::priv::WindowImplCocoa *)delegate;
|
||||
settings:(sf::WindowSettings&)settings;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Sets @aDelegate as the view delegate
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)setDelegate:(sf::priv::WindowImplCocoa *)aDelegate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Returns the view delegate
|
||||
////////////////////////////////////////////////////////////
|
||||
- (sf::priv::WindowImplCocoa *)delegate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Finish view setting (after having added it to the window)
|
||||
|
@ -94,53 +100,16 @@
|
|||
|
||||
@end
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// WindowWrapper class : handles both imported and self-built windows
|
||||
/// Parent class for handling general SFML window stuff
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface WindowWrapper : NSObject
|
||||
@interface sfPrivWindow : NSObject
|
||||
{
|
||||
@private
|
||||
NSWindow *myWindow;
|
||||
GLView *myView;
|
||||
sf::VideoMode myFullscreenMode;
|
||||
bool myIsFullscreen;
|
||||
sfPrivGLView *myView;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Make a new window wrapper according to the window settings @attribs,
|
||||
/// the video mode @mode, the window style @style, the window title @title
|
||||
/// and the sf window implementation delegate @delegate
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithSettings:(sf::WindowSettings&)attribs
|
||||
videoMode:(sf::VideoMode&)mode
|
||||
style:(unsigned long)style
|
||||
title:(NSString *)title
|
||||
delegate:(sf::priv::WindowImplCocoa *)delegate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Make a new window wrapper by importing @window and according to
|
||||
/// the window settings @params and the sf window implementation delegate
|
||||
/// @delegate
|
||||
/// @window and @delegate must not be null
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithWindow:(NSWindow *)window
|
||||
settings:(sf::WindowSettings&)params
|
||||
delegate:(sf::priv::WindowImplCocoa *)delegate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Make a new window wrapper by importing @window if it's not null and according to
|
||||
/// the window settings @params and the sf window implementation delegate
|
||||
/// @delegate; or by creating a new window if @window is null. In this case @title
|
||||
/// must therefore not be null and @params must be valid.
|
||||
/// @delegate must never be null
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithWindow:(NSWindow *)window
|
||||
settings:(sf::WindowSettings&)params
|
||||
videoMode:(sf::VideoMode&)mode
|
||||
style:(unsigned long)style
|
||||
title:(NSString *)title
|
||||
delegate:(sf::priv::WindowImplCocoa *)delegate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return a reference to the internal Cocoa window
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -149,7 +118,17 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Return a reference to the internal Cocoa OpenGL view
|
||||
////////////////////////////////////////////////////////////
|
||||
- (GLView *)glView;
|
||||
- (sfPrivGLView *)view;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Sets @aDelegate as the window delegate
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)setDelegate:(sf::priv::WindowImplCocoa *)aDelegate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Returns the window delegate
|
||||
////////////////////////////////////////////////////////////
|
||||
- (sf::priv::WindowImplCocoa *)delegate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Forward call to set the window position on screen
|
||||
|
@ -193,3 +172,61 @@
|
|||
|
||||
@end
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Class for creating new SFML windows from informations
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface sfPrivOwnedWindow : sfPrivWindow
|
||||
{
|
||||
@private
|
||||
sf::VideoMode myFullscreenMode;
|
||||
bool myIsFullscreen;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Creates and returns a new SFML window handler with
|
||||
/// the given parameters
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithVideoMode:(sf::VideoMode&)aMode
|
||||
settings:(sf::WindowSettings&)someSettings
|
||||
style:(unsigned long)aStyle
|
||||
title:(NSString *)aTitle;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Returns the window's fullscreen state
|
||||
////////////////////////////////////////////////////////////
|
||||
- (BOOL)isFullscreen;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Class for creating SFML windows from Cocoa windows
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface sfPrivImportedWindow : sfPrivWindow
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Returns a new SFML window handler with the given window
|
||||
/// and parameters
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithWindow:(NSWindow *)aWindow
|
||||
settings:(sf::WindowSettings&)someSettings;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Class for creating SFML windows from Cocoa views
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface sfPrivImportedView : sfPrivWindow
|
||||
{
|
||||
NSView *parentView;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Returns a new SFML window handler with the given view
|
||||
/// and parameters
|
||||
////////////////////////////////////////////////////////////
|
||||
- (id)initWithView:(NSView *)aView
|
||||
settings:(sf::WindowSettings&)someSettings;
|
||||
|
||||
@end
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -33,10 +33,10 @@
|
|||
#include <string>
|
||||
|
||||
#ifdef __OBJC__
|
||||
@class WindowWrapper;
|
||||
typedef WindowWrapper* WindowWrapperRef;
|
||||
@class sfPrivWindow;
|
||||
typedef sfPrivWindow* sfPrivWindowRef;
|
||||
#else
|
||||
typedef void* WindowWrapperRef;
|
||||
typedef void* sfPrivWindowRef;
|
||||
#endif
|
||||
|
||||
namespace sf
|
||||
|
@ -192,7 +192,7 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowWrapperRef myWrapper;
|
||||
sfPrivWindowRef myWrapper;
|
||||
bool myUseKeyRepeat;
|
||||
bool myMouseIn;
|
||||
float myWheelStatus;
|
||||
|
|
|
@ -67,10 +67,10 @@ myUseKeyRepeat(false),
|
|||
myMouseIn(false),
|
||||
myWheelStatus(0.0f)
|
||||
{
|
||||
[AppController sharedController];
|
||||
[sfPrivAppController sharedController];
|
||||
|
||||
// Create the shared OpenGL context
|
||||
if ([GLContext sharedContext]) {
|
||||
if ([sfPrivGLContext sharedContext]) {
|
||||
// Then we make it the current active OpenGL context
|
||||
SetActive();
|
||||
} else {
|
||||
|
@ -88,22 +88,19 @@ myUseKeyRepeat(false),
|
|||
myMouseIn(false),
|
||||
myWheelStatus(0.0f)
|
||||
{
|
||||
if (Handle)
|
||||
{
|
||||
NSWindow *cocoaWindow = nil;
|
||||
|
||||
if (Handle) {
|
||||
// Classical window import
|
||||
if ([(id)Handle isKindOfClass:[NSWindow class]])
|
||||
{
|
||||
cocoaWindow = (NSWindow *)Handle;
|
||||
if ([(id)Handle isKindOfClass:[NSWindow class]]) {
|
||||
myWrapper = [[sfPrivImportedWindow alloc]
|
||||
initWithWindow:(NSWindow *)Handle
|
||||
settings:params];
|
||||
}
|
||||
// Qt "window" import
|
||||
else if ([(id)Handle isKindOfClass:[NSView class]])
|
||||
{
|
||||
cocoaWindow = [(NSView *)Handle window];
|
||||
}
|
||||
else
|
||||
{
|
||||
else if ([(id)Handle isKindOfClass:[NSView class]]) {
|
||||
myWrapper = [[sfPrivImportedView alloc]
|
||||
initWithView:(NSView *)Handle
|
||||
settings:params];
|
||||
} else {
|
||||
std::cerr
|
||||
<< "Cannot import this Window Handle because it is neither"
|
||||
<< "a <NSWindow *> nor <NSView *> object"
|
||||
|
@ -114,36 +111,23 @@ myWheelStatus(0.0f)
|
|||
|
||||
}
|
||||
|
||||
if (cocoaWindow)
|
||||
{
|
||||
if (myWrapper) {
|
||||
[myWrapper setDelegate:this];
|
||||
|
||||
// We create the window according to the given handle
|
||||
myWrapper = [[WindowWrapper alloc] initWithWindow:cocoaWindow
|
||||
settings:params
|
||||
delegate:this];
|
||||
// initial mouse state
|
||||
myMouseIn = [myWrapper mouseInside];
|
||||
|
||||
if (myWrapper)
|
||||
{
|
||||
// initial mouse state
|
||||
myMouseIn = [myWrapper mouseInside];
|
||||
|
||||
// We set the myWidth and myHeight members to the correct values
|
||||
myWidth = (int) [[myWrapper glView] frame].size.width;
|
||||
myHeight = (int) [[myWrapper glView] frame].size.height;
|
||||
} else {
|
||||
std::cerr << "Failed to make the public window" << std::endl;
|
||||
}
|
||||
// We set the myWidth and myHeight members to the correct values
|
||||
myWidth = (int) [[myWrapper view] frame].size.width;
|
||||
myHeight = (int) [[myWrapper view] frame].size.height;
|
||||
} else {
|
||||
std::cerr << "Failed to make the public window" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr
|
||||
<< "Could not get a valid NSWindow object from the given handle"
|
||||
<< " (%p <"
|
||||
<< [[(id)Handle className] UTF8String]
|
||||
<< ">"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
} else {
|
||||
std::cerr
|
||||
<< "Invalid null handle given to "
|
||||
<< "Window::Window(WindowHandle Handle, const WindowSettings& Params)"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,14 +147,18 @@ myWheelStatus(0.0f)
|
|||
encoding:NSASCIIStringEncoding];
|
||||
|
||||
// We create the window
|
||||
myWrapper = [[WindowWrapper alloc] initWithSettings:params
|
||||
videoMode:Mode
|
||||
style:WindowStyle
|
||||
title:title
|
||||
delegate:this];
|
||||
myWrapper = [[sfPrivOwnedWindow alloc]
|
||||
initWithVideoMode:Mode
|
||||
settings:params
|
||||
style:WindowStyle
|
||||
title:title];
|
||||
|
||||
|
||||
|
||||
if (myWrapper)
|
||||
{
|
||||
[myWrapper setDelegate:this];
|
||||
|
||||
// initial mouse state
|
||||
myMouseIn = [myWrapper mouseInside];
|
||||
|
||||
|
@ -566,7 +554,7 @@ void WindowImplCocoa::Display()
|
|||
void WindowImplCocoa::ProcessEvents()
|
||||
{
|
||||
// Forward event handling call to the application controller
|
||||
[[AppController sharedController] processEvents];
|
||||
[[sfPrivAppController sharedController] processEvents];
|
||||
}
|
||||
|
||||
|
||||
|
@ -581,10 +569,10 @@ void WindowImplCocoa::SetActive(bool Active) const
|
|||
else {
|
||||
// Or directly activate the shared OpenGL context if we're not using a window
|
||||
if (Active) {
|
||||
if ([NSOpenGLContext currentContext] != [GLContext sharedContext])
|
||||
[[GLContext sharedContext] makeCurrentContext];
|
||||
if ([NSOpenGLContext currentContext] != [sfPrivGLContext sharedContext])
|
||||
[[sfPrivGLContext sharedContext] makeCurrentContext];
|
||||
} else {
|
||||
if ([NSOpenGLContext currentContext] == [GLContext sharedContext])
|
||||
if ([NSOpenGLContext currentContext] == [sfPrivGLContext sharedContext])
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
}
|
||||
}
|
||||
|
@ -626,7 +614,7 @@ void WindowImplCocoa::SetCursorPosition(unsigned int Left, unsigned int Top)
|
|||
pos.y = [[myWrapper window] frame].size.height - pos.y;
|
||||
|
||||
// Adjust for view reference instead of window
|
||||
pos.y -= [[myWrapper window] frame].size.height - [[myWrapper glView] frame].size.height;
|
||||
pos.y -= [[myWrapper window] frame].size.height - [[myWrapper view] frame].size.height;
|
||||
|
||||
// Convert to screen coordinates
|
||||
NSPoint absolute = [[myWrapper window] convertBaseToScreen:pos];
|
||||
|
@ -635,7 +623,8 @@ void WindowImplCocoa::SetCursorPosition(unsigned int Left, unsigned int Top)
|
|||
absolute.y = [[NSScreen mainScreen] frame].size.height - absolute.y;
|
||||
|
||||
// Move cursor
|
||||
CGDisplayMoveCursorToPoint([AppController primaryScreen], CGPointMake(absolute.x, absolute.y));
|
||||
CGDisplayMoveCursorToPoint([sfPrivAppController primaryScreen],
|
||||
CGPointMake(absolute.x, absolute.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,6 +224,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co
|
|||
descriptor.cColorBits = static_cast<BYTE>(bitsPerPixel);
|
||||
descriptor.cDepthBits = static_cast<BYTE>(mySettings.DepthBits);
|
||||
descriptor.cStencilBits = static_cast<BYTE>(mySettings.StencilBits);
|
||||
descriptor.cAlphaBits = bitsPerPixel == 32 ? 8 : 0;
|
||||
|
||||
// Get the pixel format that best matches our requirements
|
||||
bestFormat = ChoosePixelFormat(myDeviceContext, &descriptor);
|
||||
|
|
|
@ -367,14 +367,14 @@ void WindowImplWin32::SwitchToFullscreen(const VideoMode& mode)
|
|||
return;
|
||||
}
|
||||
|
||||
// Resize the window so that it fits the entire screen
|
||||
SetWindowPos(myHandle, HWND_TOP, 0, 0, mode.Width, mode.Height, SWP_FRAMECHANGED);
|
||||
ShowWindow(myHandle, SW_SHOW);
|
||||
|
||||
// Make the window flags compatible with fullscreen mode
|
||||
SetWindowLong(myHandle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
|
||||
SetWindowLong(myHandle, GWL_EXSTYLE, WS_EX_APPWINDOW);
|
||||
|
||||
// Resize the window so that it fits the entire screen
|
||||
SetWindowPos(myHandle, HWND_TOP, 0, 0, mode.Width, mode.Height, SWP_FRAMECHANGED);
|
||||
ShowWindow(myHandle, SW_SHOW);
|
||||
|
||||
// Set "this" as the current fullscreen window
|
||||
FullscreenWindow = this;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue