Merge branch 'master' into drawables
Conflicts: include/SFML/Graphics/Sprite.hpp include/SFML/Graphics/Text.hpp src/SFML/Graphics/Sprite.cpp
This commit is contained in:
commit
eeff685255
79 changed files with 747 additions and 892 deletions
|
@ -48,7 +48,7 @@ float Listener::GetGlobalVolume()
|
|||
float volume = 0.f;
|
||||
ALCheck(alGetListenerf(AL_GAIN, &volume));
|
||||
|
||||
return volume;
|
||||
return volume * 100;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -139,7 +139,8 @@ void Music::OnSeek(Uint32 timeOffset)
|
|||
void Music::Initialize()
|
||||
{
|
||||
// Compute the music duration
|
||||
myDuration = static_cast<Uint32>(1000 * myFile->GetSamplesCount() / myFile->GetSampleRate() / myFile->GetChannelsCount());
|
||||
Uint64 samples = myFile->GetSamplesCount();
|
||||
myDuration = static_cast<Uint32>(1000 * samples / myFile->GetSampleRate() / myFile->GetChannelsCount());
|
||||
|
||||
// Resize the internal buffer so that it can contain 1 second of audio samples
|
||||
mySamples.resize(myFile->GetSampleRate() * myFile->GetChannelsCount());
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Sound::Sound()
|
||||
Sound::Sound() :
|
||||
myBuffer(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -50,11 +50,10 @@ myDuration(0)
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundBuffer::SoundBuffer(const SoundBuffer& copy) :
|
||||
Resource<SoundBuffer>(),
|
||||
myBuffer (0),
|
||||
mySamples (copy.mySamples),
|
||||
myDuration (copy.myDuration),
|
||||
mySounds () // don't copy the attached sounds
|
||||
myBuffer (0),
|
||||
mySamples (copy.mySamples),
|
||||
myDuration(copy.myDuration),
|
||||
mySounds () // don't copy the attached sounds
|
||||
{
|
||||
// Create the buffer
|
||||
ALCheck(alGenBuffers(1, &myBuffer));
|
||||
|
|
|
@ -86,7 +86,7 @@ if(MACOSX)
|
|||
endif()
|
||||
|
||||
# add include paths of external libraries
|
||||
include_directories(${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR})
|
||||
include_directories(${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
|
||||
|
||||
# build the list of libraries to link
|
||||
# GL and X11 are only needed for shared build, as they are already linked by sfml-window
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace
|
|||
unsigned long Read(FT_Stream rec, unsigned long offset, unsigned char* buffer, unsigned long count)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(rec->descriptor.pointer);
|
||||
if (stream->Seek(offset) == offset)
|
||||
if (static_cast<unsigned long>(stream->Seek(offset)) == offset)
|
||||
{
|
||||
if (count > 0)
|
||||
return static_cast<unsigned long>(stream->Read(reinterpret_cast<char*>(buffer), count));
|
||||
|
@ -77,7 +77,6 @@ myRefCount (NULL)
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
Font::Font(const Font& copy) :
|
||||
Resource<Font>(),
|
||||
myLibrary (copy.myLibrary),
|
||||
myFace (copy.myFace),
|
||||
myStreamRec (copy.myStreamRec),
|
||||
|
@ -339,7 +338,7 @@ const Font& Font::GetDefaultFont()
|
|||
// Load the default font on first call
|
||||
if (!loaded)
|
||||
{
|
||||
static const char data[] =
|
||||
static const signed char data[] =
|
||||
{
|
||||
#include <SFML/Graphics/Arial.hpp>
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@ RenderWindow::RenderWindow()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderWindow::RenderWindow(VideoMode mode, const std::string& title, unsigned long style, const ContextSettings& settings)
|
||||
RenderWindow::RenderWindow(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings)
|
||||
{
|
||||
// Don't call the base class constructor because it contains virtual function calls
|
||||
Create(mode, title, style, settings);
|
||||
|
|
|
@ -96,6 +96,7 @@ bool Shader::LoadFromFile(const std::string& filename)
|
|||
}
|
||||
|
||||
// Read the shader code from the file
|
||||
myFragmentShader.clear();
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
myFragmentShader += line + "\n";
|
||||
|
|
|
@ -90,7 +90,7 @@ void Text::SetCharacterSize(unsigned int size)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Text::SetStyle(unsigned long style)
|
||||
void Text::SetStyle(Uint32 style)
|
||||
{
|
||||
if (myStyle != style)
|
||||
{
|
||||
|
@ -135,7 +135,7 @@ unsigned int Text::GetCharacterSize() const
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned long Text::GetStyle() const
|
||||
Uint32 Text::GetStyle() const
|
||||
{
|
||||
return myStyle;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ myPixelsFlipped(false)
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture::Texture(const Texture& copy) :
|
||||
Resource<Texture>(),
|
||||
myWidth (0),
|
||||
myHeight (0),
|
||||
myTextureWidth (0),
|
||||
|
@ -63,7 +62,8 @@ myIsSmooth (copy.myIsSmooth),
|
|||
myIsRepeated (copy.myIsRepeated),
|
||||
myPixelsFlipped(false)
|
||||
{
|
||||
LoadFromImage(copy.CopyToImage());
|
||||
if (copy.myTexture)
|
||||
LoadFromImage(copy.CopyToImage());
|
||||
}
|
||||
|
||||
|
||||
|
@ -189,19 +189,19 @@ bool Texture::LoadFromImage(const Image& image, const IntRect& area)
|
|||
IntRect rectangle = area;
|
||||
if (rectangle.Left < 0) rectangle.Left = 0;
|
||||
if (rectangle.Top < 0) rectangle.Top = 0;
|
||||
if (rectangle.Width > width) rectangle.Width = width;
|
||||
if (rectangle.Height > height) rectangle.Height = height;
|
||||
if (rectangle.Left + rectangle.Width > width) rectangle.Width = width - rectangle.Left;
|
||||
if (rectangle.Top + rectangle.Height > height) rectangle.Height = height - rectangle.Top;
|
||||
|
||||
// Create the texture and upload the pixels
|
||||
if (Create(rectangle.Width, rectangle.Height))
|
||||
{
|
||||
// Copy the pixels to the texture, row by row
|
||||
const Uint8* pixels = image.GetPixelsPtr() + rectangle.Left + (width * rectangle.Top);
|
||||
const Uint8* pixels = image.GetPixelsPtr() + 4 * (rectangle.Left + (width * rectangle.Top));
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
|
||||
for (int i = 0; i < rectangle.Height; ++i)
|
||||
{
|
||||
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, myWidth, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
pixels += width;
|
||||
pixels += 4 * width;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -139,13 +139,13 @@ IpAddress IpAddress::GetLocalAddress()
|
|||
return localAddress;
|
||||
|
||||
// Connect the socket to localhost on any port
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(INADDR_LOOPBACK, 0);
|
||||
sockaddr_in address = priv::SocketImpl::CreateAddress(ntohl(INADDR_LOOPBACK), 0);
|
||||
if (connect(sock, reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
|
||||
{
|
||||
priv::SocketImpl::Close(sock);
|
||||
return localAddress;
|
||||
}
|
||||
|
||||
|
||||
// Get the local address of the socket connection
|
||||
priv::SocketImpl::AddrLength size = sizeof(address);
|
||||
if (getsockname(sock, reinterpret_cast<sockaddr*>(&address), &size) == -1)
|
||||
|
|
|
@ -277,7 +277,7 @@ Socket::Status TcpSocket::Send(Packet& packet)
|
|||
const char* data = packet.OnSend(size);
|
||||
|
||||
// First send the packet size
|
||||
Uint32 packetSize = htonl(static_cast<unsigned long>(size));
|
||||
Uint32 packetSize = htonl(static_cast<Uint32>(size));
|
||||
Status status = Send(reinterpret_cast<const char*>(&packetSize), sizeof(packetSize));
|
||||
|
||||
// Make sure that the size was properly sent
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <SFML/Network/Unix/SocketImpl.hpp>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -36,10 +36,10 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
sockaddr_in SocketImpl::CreateAddress(unsigned long address, unsigned short port)
|
||||
sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
|
||||
std::memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
|
||||
addr.sin_addr.s_addr = htonl(address);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
|
|
|
@ -65,7 +65,7 @@ public :
|
|||
/// \return sockaddr_in ready to be used by socket functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static sockaddr_in CreateAddress(unsigned long address, unsigned short port);
|
||||
static sockaddr_in CreateAddress(Uint32 address, unsigned short port);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the value of the invalid socket
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
sockaddr_in SocketImpl::CreateAddress(unsigned long address, unsigned short port)
|
||||
sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port)
|
||||
{
|
||||
sockaddr_in addr;
|
||||
std::memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
|
||||
|
@ -63,7 +63,7 @@ void SocketImpl::Close(SocketHandle sock)
|
|||
////////////////////////////////////////////////////////////
|
||||
void SocketImpl::SetBlocking(SocketHandle sock, bool block)
|
||||
{
|
||||
unsigned long blocking = block ? 0 : 1;
|
||||
u_long blocking = block ? 0 : 1;
|
||||
ioctlsocket(sock, FIONBIO, &blocking);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public :
|
|||
/// \return sockaddr_in ready to be used by socket functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static sockaddr_in CreateAddress(unsigned long address, unsigned short port);
|
||||
static sockaddr_in CreateAddress(Uint32 address, unsigned short port);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the value of the invalid socket
|
||||
|
|
|
@ -14,9 +14,6 @@ set(SRC
|
|||
${INCROOT}/Mutex.hpp
|
||||
${INCROOT}/NonCopyable.hpp
|
||||
${SRCROOT}/Platform.hpp
|
||||
${INCROOT}/Resource.hpp
|
||||
${INCROOT}/Resource.inl
|
||||
${INCROOT}/ResourcePtr.inl
|
||||
${SRCROOT}/Sleep.cpp
|
||||
${INCROOT}/Sleep.hpp
|
||||
${SRCROOT}/String.cpp
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Lucas Soltic (ceylow@gmail.com) and 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/Config.hpp>
|
||||
|
||||
|
||||
#ifdef SFML_SYSTEM_MACOS
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Under Mac OS X, when launching an application from the Finder,
|
||||
/// the default working directory is the user home directory ;
|
||||
/// when launching from Xcode, the default one is the directory
|
||||
/// containing the application. In order to produce a uniform behaviour
|
||||
/// and simplify the use of resources, SFML sets the working directory to
|
||||
/// the Resources folder of the application bundle.
|
||||
/// The "constructor" attribute forces the function to be called
|
||||
/// at library loading time.
|
||||
////////////////////////////////////////////////////////////
|
||||
void InitializeWorkingDirectory(void) __attribute__ ((constructor));
|
||||
void InitializeWorkingDirectory(void)
|
||||
{
|
||||
char PathBuffer[4096];
|
||||
bool Encoded = false;
|
||||
|
||||
// Get the application bundle
|
||||
CFBundleRef MainBundle = CFBundleGetMainBundle();
|
||||
assert(MainBundle != NULL);
|
||||
|
||||
// Get the resource directory URL
|
||||
CFURLRef ResourceDirectory = CFBundleCopyResourcesDirectoryURL(MainBundle);
|
||||
assert(ResourceDirectory != NULL);
|
||||
|
||||
// Convert it as absolute URL
|
||||
CFURLRef AbsoluteURL = CFURLCopyAbsoluteURL(ResourceDirectory);
|
||||
assert(AbsoluteURL != NULL);
|
||||
|
||||
// Get the path as C string
|
||||
Encoded = CFURLGetFileSystemRepresentation(AbsoluteURL, true, (UInt8 *)PathBuffer, 4096);
|
||||
assert(Encoded);
|
||||
|
||||
// Set the working directory
|
||||
chdir(PathBuffer);
|
||||
|
||||
CFRelease(AbsoluteURL);
|
||||
CFRelease(ResourceDirectory);
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SYSTEM_MACOS
|
||||
|
|
@ -66,13 +66,13 @@ else() # MACOSX
|
|||
${SRCROOT}/OSX/cpp_objc_conversion.h
|
||||
${SRCROOT}/OSX/cpp_objc_conversion.mm
|
||||
${SRCROOT}/OSX/cg_sf_conversion.hpp
|
||||
${SRCROOT}/OSX/cg_sf_conversion.cpp
|
||||
${SRCROOT}/OSX/cg_sf_conversion.cpp
|
||||
${SRCROOT}/OSX/InputImpl.mm
|
||||
${SRCROOT}/OSX/InputImpl.hpp
|
||||
${SRCROOT}/OSX/HIDInputManager.hpp
|
||||
${SRCROOT}/OSX/HIDInputManager.mm
|
||||
${SRCROOT}/OSX/HIDJoystickManager.hpp
|
||||
${SRCROOT}/OSX/HIDJoystickManager.cpp
|
||||
${SRCROOT}/OSX/InputImpl.hpp
|
||||
${SRCROOT}/OSX/HIDInputManager.hpp
|
||||
${SRCROOT}/OSX/HIDInputManager.mm
|
||||
${SRCROOT}/OSX/HIDJoystickManager.hpp
|
||||
${SRCROOT}/OSX/HIDJoystickManager.cpp
|
||||
${SRCROOT}/OSX/JoystickImpl.cpp
|
||||
${SRCROOT}/OSX/JoystickImpl.hpp
|
||||
${SRCROOT}/OSX/SFApplication.h
|
||||
|
@ -98,8 +98,13 @@ endif()
|
|||
|
||||
# find external libraries
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
if(LINUX)
|
||||
find_package(X11 REQUIRED)
|
||||
if(NOT X11_Xrandr_FOUND)
|
||||
message(FATAL_ERROR "Xrandr library not found")
|
||||
endif()
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# build the list of external libraries to link
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
namespace
|
||||
{
|
||||
// OpenGL resources counter and its mutex
|
||||
unsigned long count = 0;
|
||||
unsigned int count = 0;
|
||||
sf::Mutex mutex;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,3 +41,11 @@ void RetainPool(void);
|
|||
////////////////////////////////////////////////////////////
|
||||
void ReleasePool(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Drain the pool.
|
||||
///
|
||||
/// ReleasePool must be called at least once before DrainPool.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DrainPool();
|
||||
|
||||
|
|
|
@ -84,6 +84,12 @@ public :
|
|||
////////////////////////////////////////////////////////////
|
||||
void Release();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Drain the pool
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Drain();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -109,12 +115,12 @@ PoolWrapper::~PoolWrapper()
|
|||
#ifdef SFML_DEBUG
|
||||
if (count < 0) {
|
||||
sf::Err() << "~PoolWrapper : count is less than zero! "
|
||||
"You called ReleasePool from a thread too many times."
|
||||
<< std::endl;
|
||||
"You called ReleasePool from a thread too many times."
|
||||
<< std::endl;
|
||||
} else if (count > 0) {
|
||||
sf::Err() << "~PoolWrapper : count is greater than zero! "
|
||||
"You called ReleasePool from a thread to few times."
|
||||
<< std::endl;
|
||||
"You called ReleasePool from a thread to few times."
|
||||
<< std::endl;
|
||||
} else { // count == 0
|
||||
sf::Err() << "~PoolWrapper is HAPPY!" << std::endl;
|
||||
}
|
||||
|
@ -149,8 +155,7 @@ void PoolWrapper::Release()
|
|||
|
||||
// Drain pool if required.
|
||||
if (count == 0) {
|
||||
[pool drain];
|
||||
pool = 0;
|
||||
Drain();
|
||||
}
|
||||
|
||||
#ifdef SFML_DEBUG
|
||||
|
@ -160,6 +165,16 @@ void PoolWrapper::Release()
|
|||
#endif
|
||||
}
|
||||
|
||||
void PoolWrapper::Drain()
|
||||
{
|
||||
[pool drain];
|
||||
pool = 0;
|
||||
|
||||
if (count != 0) {
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
@ -207,3 +222,18 @@ void ReleasePool(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void DrainPool()
|
||||
{
|
||||
if (localPool != NULL) {
|
||||
localPool->Drain();
|
||||
}
|
||||
#ifdef SFML_DEBUG
|
||||
else {
|
||||
sf::Err() << "ReleasePool must be called at least one before DrainPool"
|
||||
<< std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,17 @@
|
|||
#include <SFML/Window/OSX/HIDJoystickManager.hpp>
|
||||
#include <SFML/Window/OSX/HIDInputManager.hpp>
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Private data
|
||||
////////////////////////////////////////////////////////////
|
||||
namespace
|
||||
{
|
||||
// Using a custom run loop mode solve some issues that appears when SFML
|
||||
// is used with Cocoa.
|
||||
CFStringRef const runLoopMode = CFSTR("SFML_RUN_LOOP_MODE");
|
||||
}
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
|
@ -74,7 +85,7 @@ HIDJoystickManager::HIDJoystickManager()
|
|||
|
||||
IOHIDManagerScheduleWithRunLoop(myHIDManager,
|
||||
CFRunLoopGetCurrent(),
|
||||
kCFRunLoopDefaultMode);
|
||||
runLoopMode);
|
||||
|
||||
IOHIDManagerOpen(myHIDManager, kIOHIDOptionsTypeNone);
|
||||
}
|
||||
|
@ -85,7 +96,7 @@ HIDJoystickManager::~HIDJoystickManager()
|
|||
{
|
||||
IOHIDManagerUnscheduleFromRunLoop(myHIDManager,
|
||||
CFRunLoopGetCurrent(),
|
||||
kCFRunLoopDefaultMode);
|
||||
runLoopMode);
|
||||
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(myHIDManager, NULL, 0);
|
||||
IOHIDManagerRegisterDeviceRemovalCallback(myHIDManager, NULL, 0);
|
||||
|
@ -100,7 +111,7 @@ void HIDJoystickManager::Update()
|
|||
SInt32 status = kCFRunLoopRunHandledSource;
|
||||
|
||||
while (status == kCFRunLoopRunHandledSource) {
|
||||
status = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
|
||||
status = CFRunLoopRunInMode(runLoopMode, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,20 +39,22 @@ namespace priv
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
SFContext::SFContext(SFContext* shared)
|
||||
: myView(0), myWindow(0)
|
||||
: myView(0), myWindow(0)
|
||||
{
|
||||
// Ask for a pool.
|
||||
RetainPool();
|
||||
|
||||
// Create the context
|
||||
CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings(0, 0, 0));
|
||||
CreateContext(shared,
|
||||
VideoMode::GetDesktopMode().BitsPerPixel,
|
||||
ContextSettings(0, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
const WindowImpl* owner, unsigned int bitsPerPixel)
|
||||
: myView(0), myWindow(0)
|
||||
: myView(0), myWindow(0)
|
||||
{
|
||||
// Ask for a pool.
|
||||
RetainPool();
|
||||
|
@ -68,7 +70,7 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
|||
|
||||
SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
|
||||
unsigned int width, unsigned int height)
|
||||
: myView(0), myWindow(0)
|
||||
: myView(0), myWindow(0)
|
||||
{
|
||||
// Ensure the process is setup in order to create a valid window.
|
||||
WindowImplCocoa::SetUpProcess();
|
||||
|
|
|
@ -286,6 +286,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
{
|
||||
// Forward to...
|
||||
[self otherMouseDown:theEvent];
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseDown:theEvent];
|
||||
}
|
||||
|
||||
|
||||
|
@ -294,6 +297,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
{
|
||||
// Forward to...
|
||||
[self otherMouseUp:theEvent];
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseUp:theEvent];
|
||||
}
|
||||
|
||||
|
||||
|
@ -302,17 +308,23 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
{
|
||||
// Forward to...
|
||||
[self otherMouseDragged:theEvent];
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseMoved:theEvent];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)scrollWheel:(NSEvent *)theEvent
|
||||
{
|
||||
if (myRequester == 0) return;
|
||||
if (myRequester != 0) {
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
myRequester->MouseWheelScrolledAt([theEvent deltaY], loc.x, loc.y);
|
||||
}
|
||||
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
myRequester->MouseWheelScrolledAt([theEvent deltaY], loc.x, loc.y);
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] scrollWheel:theEvent];
|
||||
}
|
||||
|
||||
|
||||
|
@ -343,6 +355,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
{
|
||||
// Forward to...
|
||||
[self otherMouseDown:theEvent];
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] rightMouseDown:theEvent];
|
||||
}
|
||||
|
||||
|
||||
|
@ -351,46 +366,51 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
{
|
||||
// Forward to...
|
||||
[self otherMouseUp:theEvent];
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] rightMouseUp:theEvent];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)otherMouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
if (myRequester == 0) return;
|
||||
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
|
||||
|
||||
if (button != sf::Mouse::ButtonCount) {
|
||||
myRequester->MouseDownAt(button, loc.x, loc.y);
|
||||
if (myRequester != 0) {
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
if (button != sf::Mouse::ButtonCount) {
|
||||
myRequester->MouseDownAt(button, loc.x, loc.y);
|
||||
}
|
||||
}
|
||||
|
||||
// If the event is not forwarded by mouseDown or rightMouseDown...
|
||||
if (button != sf::Mouse::Left && button != sf::Mouse::Right) {
|
||||
// ... transmit to non-SFML responder
|
||||
[[self nextResponder] otherMouseDown:theEvent];
|
||||
}
|
||||
//#ifdef SFML_DEBUG
|
||||
// else {
|
||||
// sf::Err() << "Unknown mouse button released." << std::endl;
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)otherMouseUp:(NSEvent *)theEvent
|
||||
{
|
||||
if (myRequester == 0) return;
|
||||
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
|
||||
|
||||
if (button != sf::Mouse::ButtonCount) {
|
||||
myRequester->MouseUpAt(button, loc.x, loc.y);
|
||||
if (myRequester != 0) {
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
if (button != sf::Mouse::ButtonCount) {
|
||||
myRequester->MouseUpAt(button, loc.x, loc.y);
|
||||
}
|
||||
}
|
||||
|
||||
// If the event is not forwarded by mouseUp or rightMouseUp...
|
||||
if (button != sf::Mouse::Left && button != sf::Mouse::Right) {
|
||||
// ... transmit to non-SFML responder
|
||||
[[self nextResponder] otherMouseUp:theEvent];
|
||||
}
|
||||
//#ifdef SFML_DEBUG
|
||||
// else {
|
||||
// sf::Err() << "Unknown mouse button released." << std::endl;
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -399,6 +419,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
{
|
||||
// Forward to...
|
||||
[self otherMouseDragged:theEvent];
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] rightMouseDragged:theEvent];
|
||||
}
|
||||
|
||||
|
||||
|
@ -407,20 +430,30 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
{
|
||||
// Forward to...
|
||||
[self otherMouseDragged:theEvent];
|
||||
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] mouseDragged:theEvent];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)otherMouseDragged:(NSEvent *)theEvent
|
||||
{
|
||||
if (myRequester == 0) return;
|
||||
if (myRequester != 0) {
|
||||
// If the event is not useful.
|
||||
if (!myMouseIsIn) return;
|
||||
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
myRequester->MouseMovedAt(loc.x, loc.y);
|
||||
}
|
||||
|
||||
// If the event is not useful.
|
||||
if (!myMouseIsIn) return;
|
||||
|
||||
NSPoint loc = [self cursorPositionFromEvent:theEvent];
|
||||
|
||||
myRequester->MouseMovedAt(loc.x, loc.y);
|
||||
// If the event is not forwarded by mouseDragged or rightMouseDragged...
|
||||
sf::Mouse::Button button = [self mouseButtonFromEvent:theEvent];
|
||||
if (button != sf::Mouse::Left && button != sf::Mouse::Right) {
|
||||
// ... transmit to non-SFML responder
|
||||
[[self nextResponder] otherMouseUp:theEvent];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -471,6 +504,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
////////////////////////////////////////////////////////
|
||||
-(void)keyDown:(NSEvent *)theEvent
|
||||
{
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] keyDown:theEvent];
|
||||
|
||||
if (myRequester == 0) return;
|
||||
|
||||
// Handle key down event
|
||||
|
@ -484,11 +520,13 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
|
||||
|
||||
// Handle text entred event
|
||||
// We create a new event without command modifiers
|
||||
// We create a new event without command/ctrl modifiers
|
||||
// to prevent the OS from sending an alert
|
||||
NSUInteger modifiers = [theEvent modifierFlags] & NSCommandKeyMask
|
||||
? [theEvent modifierFlags] & ~NSCommandKeyMask
|
||||
: [theEvent modifierFlags];
|
||||
NSUInteger modifiers = [theEvent modifierFlags];
|
||||
|
||||
if (modifiers & NSCommandKeyMask) modifiers = modifiers & ~NSCommandKeyMask;
|
||||
if (modifiers & NSControlKeyMask) modifiers = modifiers & ~NSControlKeyMask;
|
||||
|
||||
NSEvent* ev = [NSEvent keyEventWithType:NSKeyDown
|
||||
location:[theEvent locationInWindow]
|
||||
modifierFlags:modifiers
|
||||
|
@ -526,6 +564,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
////////////////////////////////////////////////////////
|
||||
-(void)keyUp:(NSEvent *)theEvent
|
||||
{
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] keyUp:theEvent];
|
||||
|
||||
if (myRequester == 0) return;
|
||||
|
||||
sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent];
|
||||
|
@ -539,6 +580,9 @@ NSUInteger KeepOnlyMaskFromData(NSUInteger data, NSUInteger mask);
|
|||
////////////////////////////////////////////////////////
|
||||
-(void)flagsChanged:(NSEvent *)theEvent
|
||||
{
|
||||
// Transmit to non-SFML responder
|
||||
[[self nextResponder] flagsChanged:theEvent];
|
||||
|
||||
if (myRequester == 0) return;
|
||||
|
||||
NSUInteger modifiers = [theEvent modifierFlags];
|
||||
|
|
|
@ -32,14 +32,28 @@
|
|||
@implementation SFWindow
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(BOOL)acceptsFirstResponder {
|
||||
-(BOOL)acceptsFirstResponder
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(BOOL)canBecomeKeyWindow {
|
||||
-(BOOL)canBecomeKeyWindow
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)keyDown:(NSEvent *)theEvent
|
||||
{
|
||||
// Do nothing except preventing a system alert each time a key is pressed
|
||||
//
|
||||
// Special Consideration :
|
||||
// -----------------------
|
||||
// Consider overriding NSResponder -keyDown: message in a Cocoa view/window
|
||||
// that contains a SFML rendering area. Doing so will prevent a system
|
||||
// alert to be thrown everytime the user presses a key.
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -311,7 +311,8 @@ private:
|
|||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplDelegateRef myDelegate; ///< Implementation in Obj-C.
|
||||
WindowImplDelegateRef myDelegate; ///< Implementation in Obj-C.
|
||||
bool myShowCursor; ///< Is the cursor displayed or hidden ?
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -44,7 +44,8 @@ namespace priv
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplCocoa::WindowImplCocoa(WindowHandle handle)
|
||||
{
|
||||
: myShowCursor(true)
|
||||
{
|
||||
// Ask for a pool.
|
||||
RetainPool();
|
||||
|
||||
|
@ -91,6 +92,7 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle)
|
|||
WindowImplCocoa::WindowImplCocoa(VideoMode mode,
|
||||
const std::string& title,
|
||||
unsigned long style)
|
||||
: myShowCursor(true)
|
||||
{
|
||||
// Transform the app process.
|
||||
SetUpProcess();
|
||||
|
@ -116,6 +118,10 @@ WindowImplCocoa::~WindowImplCocoa()
|
|||
[myDelegate release];
|
||||
|
||||
ReleasePool();
|
||||
|
||||
DrainPool(); // Make sure everything was freed
|
||||
// This solve some issue when sf::Window::Create is called for the
|
||||
// second time (nothing was render until the function was called again)
|
||||
}
|
||||
|
||||
|
||||
|
@ -183,6 +189,10 @@ void WindowImplCocoa::WindowResized(unsigned int width, unsigned int height)
|
|||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::WindowLostFocus(void)
|
||||
{
|
||||
if (!myShowCursor) {
|
||||
[myDelegate showMouseCursor]; // Make sur the cursor is visible
|
||||
}
|
||||
|
||||
Event event;
|
||||
event.Type = Event::LostFocus;
|
||||
|
||||
|
@ -193,6 +203,10 @@ void WindowImplCocoa::WindowLostFocus(void)
|
|||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::WindowGainedFocus(void)
|
||||
{
|
||||
if (!myShowCursor) {
|
||||
[myDelegate hideMouseCursor]; // Restore user's setting
|
||||
}
|
||||
|
||||
Event event;
|
||||
event.Type = Event::GainedFocus;
|
||||
|
||||
|
@ -255,6 +269,10 @@ void WindowImplCocoa::MouseWheelScrolledAt(float delta, int x, int y)
|
|||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::MouseMovedIn(void)
|
||||
{
|
||||
if (!myShowCursor) {
|
||||
[myDelegate hideMouseCursor]; // Restore user's setting
|
||||
}
|
||||
|
||||
Event event;
|
||||
event.Type = Event::MouseEntered;
|
||||
|
||||
|
@ -264,6 +282,10 @@ void WindowImplCocoa::MouseMovedIn(void)
|
|||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::MouseMovedOut(void)
|
||||
{
|
||||
if (!myShowCursor) {
|
||||
[myDelegate showMouseCursor]; // Make sur the cursor is visible
|
||||
}
|
||||
|
||||
Event event;
|
||||
event.Type = Event::MouseLeft;
|
||||
|
||||
|
@ -330,7 +352,9 @@ WindowHandle WindowImplCocoa::GetSystemHandle() const
|
|||
////////////////////////////////////////////////////////////
|
||||
void WindowImplCocoa::ShowMouseCursor(bool show)
|
||||
{
|
||||
if (show) {
|
||||
myShowCursor = show;
|
||||
|
||||
if (myShowCursor) {
|
||||
[myDelegate showMouseCursor];
|
||||
} else {
|
||||
[myDelegate hideMouseCursor];
|
||||
|
|
|
@ -145,7 +145,7 @@ bool InputImpl::IsKeyPressed(Keyboard::Key key)
|
|||
case Keyboard::Pause: vkey = VK_PAUSE; break;
|
||||
}
|
||||
|
||||
return GetAsyncKeyState(vkey) != 0;
|
||||
return (GetAsyncKeyState(vkey) & 0x8000) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -162,7 +162,7 @@ bool InputImpl::IsMouseButtonPressed(Mouse::Button button)
|
|||
case Mouse::XButton2: vkey = VK_XBUTTON2; break;
|
||||
}
|
||||
|
||||
return GetAsyncKeyState(vkey) != 0;
|
||||
return (GetAsyncKeyState(vkey) & 0x8000) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/GlContext.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
|
|
@ -87,7 +87,7 @@ myIsCursorIn (false)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplWin32::WindowImplWin32(VideoMode mode, const std::string& title, unsigned long style) :
|
||||
WindowImplWin32::WindowImplWin32(VideoMode mode, const std::string& title, Uint32 style) :
|
||||
myHandle (NULL),
|
||||
myCallback (0),
|
||||
myCursor (NULL),
|
||||
|
|
|
@ -62,7 +62,7 @@ public :
|
|||
/// \param style Window style
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplWin32(VideoMode mode, const std::string& title, unsigned long style);
|
||||
WindowImplWin32(VideoMode mode, const std::string& title, Uint32 style);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
|
|
|
@ -55,7 +55,7 @@ myFramerateLimit(0)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Window::Window(VideoMode mode, const std::string& title, unsigned long style, const ContextSettings& settings) :
|
||||
Window::Window(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings) :
|
||||
myWindow (NULL),
|
||||
myContext (NULL),
|
||||
myLastFrameTime (0),
|
||||
|
@ -84,7 +84,7 @@ Window::~Window()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Window::Create(VideoMode mode, const std::string& title, unsigned long style, const ContextSettings& settings)
|
||||
void Window::Create(VideoMode mode, const std::string& title, Uint32 style, const ContextSettings& settings)
|
||||
{
|
||||
// Destroy the previous window implementation
|
||||
Close();
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImpl* WindowImpl::New(VideoMode mode, const std::string& title, unsigned long style)
|
||||
WindowImpl* WindowImpl::New(VideoMode mode, const std::string& title, Uint32 style)
|
||||
{
|
||||
return new WindowImplType(mode, title, style);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public :
|
|||
/// \return Pointer to the created window (don't forget to delete it)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static WindowImpl* New(VideoMode mode, const std::string& title, unsigned long style);
|
||||
static WindowImpl* New(VideoMode mode, const std::string& title, Uint32 style);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new window depending on to the current OS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue