Added the iOS port
This commit is contained in:
parent
f2ef524b57
commit
e5ee38fc26
99 changed files with 24297 additions and 156 deletions
|
@ -1,9 +1,9 @@
|
|||
|
||||
# include the SFML specific macros
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/Macros.cmake)
|
||||
|
||||
# let CMake know about our additional libraries paths (on Windows and OS X)
|
||||
if (SFML_OS_WINDOWS)
|
||||
|
||||
# let CMake know about our additional libraries paths
|
||||
if (SFML_OS_WINDOWS)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers")
|
||||
if(SFML_COMPILER_GCC)
|
||||
if(ARCH_32BITS)
|
||||
|
@ -23,6 +23,9 @@ if (SFML_OS_WINDOWS)
|
|||
elseif(SFML_OS_MACOSX)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers")
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-osx/lib/")
|
||||
elseif(IOS)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers")
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-ios/")
|
||||
endif()
|
||||
|
||||
# add the SFML sources path
|
||||
|
@ -38,8 +41,10 @@ set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")
|
|||
add_subdirectory(System)
|
||||
add_subdirectory(Window)
|
||||
add_subdirectory(Network)
|
||||
add_subdirectory(Graphics)
|
||||
add_subdirectory(Audio)
|
||||
if(SFML_OS_WINDOWS)
|
||||
add_subdirectory(Graphics)
|
||||
if(NOT SFML_OS_IOS)
|
||||
add_subdirectory(Audio)
|
||||
endif()
|
||||
if(SFML_OS_WINDOWS)
|
||||
add_subdirectory(Main)
|
||||
endif()
|
||||
|
|
|
@ -13,6 +13,8 @@ set(SRC
|
|||
${INCROOT}/Glyph.hpp
|
||||
${SRCROOT}/GLCheck.cpp
|
||||
${SRCROOT}/GLCheck.hpp
|
||||
${SRCROOT}/GLExtensions.hpp
|
||||
${SRCROOT}/GLExtensions.cpp
|
||||
${SRCROOT}/Image.cpp
|
||||
${INCROOT}/Image.hpp
|
||||
${SRCROOT}/ImageLoader.cpp
|
||||
|
@ -82,38 +84,52 @@ set(STB_SRC
|
|||
${SRCROOT}/stb_image/stb_image_write.h
|
||||
)
|
||||
source_group("stb_image" FILES ${STB_SRC})
|
||||
|
||||
|
||||
# let CMake know about our additional graphics libraries paths (on Windows and OSX)
|
||||
if(SFML_OS_WINDOWS OR SFML_OS_MACOSX)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/jpeg")
|
||||
endif()
|
||||
|
||||
# let CMake know about our additional graphics libraries paths
|
||||
if(SFML_OS_WINDOWS)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/windows")
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/windows/freetype")
|
||||
elseif(SFML_OS_MACOSX)
|
||||
elseif(SFML_OS_MACOSX)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/osx")
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/osx/freetype2")
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-osx/Frameworks")
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-osx/Frameworks")
|
||||
elseif(SFML_OS_IOS)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/jpeg")
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/ios")
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers/libfreetype/ios/freetype2")
|
||||
endif()
|
||||
|
||||
# find external libraries
|
||||
if(NOT IOS)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(Freetype REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(JPEG REQUIRED)
|
||||
if(SFML_OS_LINUX)
|
||||
find_package(X11 REQUIRED)
|
||||
endif()
|
||||
set(GRAPHICS_EXT_INCLUDE_PATHS ${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
|
||||
set(GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY})
|
||||
|
||||
# find external libraries
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(Freetype REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
find_package(JPEG REQUIRED)
|
||||
if(SFML_OS_LINUX)
|
||||
find_package(X11 REQUIRED)
|
||||
# build the list of libraries to link
|
||||
set(GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY} ${OPENGL_gl_LIBRARY})
|
||||
if(SFML_OS_LINUX)
|
||||
set(GRAPHICS_EXT_LIBS ${GRAPHICS_EXT_LIBS} ${X11_LIBRARIES})
|
||||
endif()
|
||||
else()
|
||||
find_host_package(JPEG REQUIRED)
|
||||
find_host_package(Freetype REQUIRED)
|
||||
set(GRAPHICS_EXT_INCLUDE_PATHS ${FREETYPE_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR})
|
||||
set(GRAPHICS_EXT_LIBS -framework OpenGLES ${FREETYPE_LIBRARY} ${JPEG_LIBRARY})
|
||||
endif()
|
||||
|
||||
# add include paths of external libraries
|
||||
include_directories(${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
|
||||
|
||||
# build the list of libraries to link
|
||||
set(GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY} ${OPENGL_gl_LIBRARY})
|
||||
if(SFML_OS_LINUX)
|
||||
set(GRAPHICS_EXT_LIBS ${GRAPHICS_EXT_LIBS} ${X11_LIBRARIES})
|
||||
endif()
|
||||
include_directories(${GRAPHICS_EXT_INCLUDE_PATHS})
|
||||
|
||||
# add preprocessor symbols
|
||||
add_definitions(-DGLEW_STATIC -DSTBI_FAILURE_USERMSG)
|
||||
|
|
|
@ -90,10 +90,10 @@ void glCheckError(const char* file, unsigned int line)
|
|||
break;
|
||||
}
|
||||
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION :
|
||||
{
|
||||
error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT";
|
||||
description = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"";
|
||||
error = "GL_INVALID_FRAMEBUFFER_OPERATION";
|
||||
description = "the object bound to FRAMEBUFFER_BINDING is not \"framebuffer complete\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -107,24 +107,6 @@ void glCheckError(const char* file, unsigned int line)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void ensureGlewInit()
|
||||
{
|
||||
static bool initialized = false;
|
||||
if (!initialized)
|
||||
{
|
||||
GLenum status = glewInit();
|
||||
if (status == GLEW_OK)
|
||||
{
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err() << "Failed to initialize GLEW, " << glewGetErrorString(status) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <GL/glew.h>
|
||||
#include <SFML/Graphics/GLExtensions.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
@ -61,12 +61,6 @@ namespace priv
|
|||
////////////////////////////////////////////////////////////
|
||||
void glCheckError(const char* file, unsigned int line);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Make sure that GLEW is initialized
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void ensureGlewInit();
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
|
57
src/SFML/Graphics/GLExtensions.cpp
Normal file
57
src/SFML/Graphics/GLExtensions.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/Graphics/GLExtensions.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void ensureExtensionsInit()
|
||||
{
|
||||
#ifndef SFML_SYSTEM_IOS
|
||||
static bool initialized = false;
|
||||
if (!initialized)
|
||||
{
|
||||
GLenum status = glewInit();
|
||||
if (status == GLEW_OK)
|
||||
{
|
||||
initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err() << "Failed to initialize GLEW, " << glewGetErrorString(status) << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
104
src/SFML/Graphics/GLExtensions.hpp
Normal file
104
src/SFML/Graphics/GLExtensions.hpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_GLEXTENSIONS_HPP
|
||||
#define SFML_GLEXTENSIONS_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
#define GL_blend_func_separate GL_OES_blend_func_separate
|
||||
#define glBlendFuncSeparate glBlendFuncSeparateOES
|
||||
#define GL_framebuffer_object GL_OES_framebuffer_object
|
||||
#define glGenFramebuffers glGenFramebuffersOES
|
||||
#define glGenRenderbuffers glGenRenderbuffersOES
|
||||
#define glBindFramebuffer glBindFramebufferOES
|
||||
#define glBindRenderbuffer glBindRenderbufferOES
|
||||
#define glDeleteFramebuffers glDeleteFramebuffersOES
|
||||
#define glDeleteRenderbuffers glDeleteRenderbuffersOES
|
||||
#define glRenderbufferStorage glRenderbufferStorageOES
|
||||
#define glFramebufferRenderbuffer glFramebufferRenderbufferOES
|
||||
#define glFramebufferTexture2D glFramebufferTexture2DOES
|
||||
#define glCheckFramebufferStatus glCheckFramebufferStatusOES
|
||||
#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
|
||||
#define GL_RENDERBUFFER GL_RENDERBUFFER_OES
|
||||
#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES
|
||||
#define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES
|
||||
#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES
|
||||
#define GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT16_OES
|
||||
#define GL_INVALID_FRAMEBUFFER_OPERATION GL_INVALID_FRAMEBUFFER_OPERATION_OES
|
||||
#define GL_texture_non_power_of_two false
|
||||
|
||||
#else
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
#define GL_blend_func_separate GLEW_EXT_blend_func_separate
|
||||
#define glBlendFuncSeparate glBlendFuncSeparateEXT
|
||||
#define GL_framebuffer_object GLEW_EXT_framebuffer_object
|
||||
#define glGenFramebuffers glGenFramebuffersEXT
|
||||
#define glGenRenderbuffers glGenRenderbuffersEXT
|
||||
#define glBindFramebuffer glBindFramebufferEXT
|
||||
#define glBindRenderbuffer glBindRenderbufferEXT
|
||||
#define glDeleteFramebuffers glDeleteFramebuffersEXT
|
||||
#define glDeleteRenderbuffers glDeleteRenderbuffersEXT
|
||||
#define glRenderbufferStorage glRenderbufferStorageEXT
|
||||
#define glFramebufferRenderbuffer glRenderbufferStorageEXT
|
||||
#define glFramebufferTexture2D glFramebufferTexture2DEXT
|
||||
#define glCheckFramebufferStatus glCheckFramebufferStatusEXT
|
||||
#define GL_FRAMEBUFFER GL_FRAMEBUFFER_EXT
|
||||
#define GL_RENDERBUFFER GL_RENDERBUFFER_EXT
|
||||
#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT
|
||||
#define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_EXT
|
||||
#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_EXT
|
||||
//#define GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT
|
||||
#define GL_INVALID_FRAMEBUFFER_OPERATION GL_INVALID_FRAMEBUFFER_OPERATION_EXT
|
||||
#define GL_texture_non_power_of_two GLEW_ARB_texture_non_power_of_two
|
||||
|
||||
#endif
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Make sure that extensions are initialized
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void ensureExtensionsInit();
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_GLEXTENSIONS_HPP
|
|
@ -120,12 +120,14 @@ Vector2f RenderTarget::mapPixelToCoords(const Vector2i& point, const View& view)
|
|||
return view.getInverseTransform().transformPoint(normalized);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i RenderTarget::mapCoordsToPixel(const Vector2f& point) const
|
||||
{
|
||||
return mapCoordsToPixel(point, getView());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i RenderTarget::mapCoordsToPixel(const Vector2f& point, const View& view) const
|
||||
{
|
||||
|
@ -141,6 +143,7 @@ Vector2i RenderTarget::mapCoordsToPixel(const Vector2f& point, const View& view)
|
|||
return pixel;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void RenderTarget::draw(const Drawable& drawable, const RenderStates& states)
|
||||
{
|
||||
|
@ -156,6 +159,15 @@ void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount,
|
|||
if (!vertices || (vertexCount == 0))
|
||||
return;
|
||||
|
||||
// GL_QUADS is unavailable on OpenGL ES
|
||||
#ifdef SFML_OPENGL_ES
|
||||
if (type == Quads)
|
||||
{
|
||||
err() << "sf::Quads primitive type is not supported on OpenGL ES platforms, drawing skipped" << std::endl;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (activate(true))
|
||||
{
|
||||
// First set the persistent OpenGL states if it's the very first call
|
||||
|
@ -222,7 +234,7 @@ void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount,
|
|||
|
||||
// Find the OpenGL primitive type
|
||||
static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES,
|
||||
GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS};
|
||||
GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN};
|
||||
GLenum mode = modes[type];
|
||||
|
||||
// Draw the primitives
|
||||
|
@ -243,19 +255,21 @@ void RenderTarget::pushGLStates()
|
|||
{
|
||||
if (activate(true))
|
||||
{
|
||||
#ifdef SFML_DEBUG
|
||||
// make sure that the user didn't leave an unchecked OpenGL error
|
||||
GLenum error = glGetError();
|
||||
if (error != GL_NO_ERROR)
|
||||
{
|
||||
err() << "OpenGL error (" << error << ") detected in user code, "
|
||||
<< "you should check for errors with glGetError()"
|
||||
<< std::endl;
|
||||
}
|
||||
#endif
|
||||
#ifdef SFML_DEBUG
|
||||
// make sure that the user didn't leave an unchecked OpenGL error
|
||||
GLenum error = glGetError();
|
||||
if (error != GL_NO_ERROR)
|
||||
{
|
||||
err() << "OpenGL error (" << error << ") detected in user code, "
|
||||
<< "you should check for errors with glGetError()"
|
||||
<< std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
glCheck(glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS));
|
||||
glCheck(glPushAttrib(GL_ALL_ATTRIB_BITS));
|
||||
#ifndef SFML_OPENGL_ES
|
||||
glCheck(glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS));
|
||||
glCheck(glPushAttrib(GL_ALL_ATTRIB_BITS));
|
||||
#endif
|
||||
glCheck(glMatrixMode(GL_MODELVIEW));
|
||||
glCheck(glPushMatrix());
|
||||
glCheck(glMatrixMode(GL_PROJECTION));
|
||||
|
@ -279,8 +293,10 @@ void RenderTarget::popGLStates()
|
|||
glCheck(glPopMatrix());
|
||||
glCheck(glMatrixMode(GL_TEXTURE));
|
||||
glCheck(glPopMatrix());
|
||||
glCheck(glPopClientAttrib());
|
||||
glCheck(glPopAttrib());
|
||||
#ifndef SFML_OPENGL_ES
|
||||
glCheck(glPopClientAttrib());
|
||||
glCheck(glPopAttrib());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,8 +306,8 @@ void RenderTarget::resetGLStates()
|
|||
{
|
||||
if (activate(true))
|
||||
{
|
||||
// Make sure that GLEW is initialized
|
||||
priv::ensureGlewInit();
|
||||
// Make sure that extensions are initialized
|
||||
priv::ensureExtensionsInit();
|
||||
|
||||
// Define the default OpenGL states
|
||||
glCheck(glDisable(GL_CULL_FACE));
|
||||
|
@ -357,22 +373,22 @@ void RenderTarget::applyBlendMode(BlendMode mode)
|
|||
{
|
||||
switch (mode)
|
||||
{
|
||||
// glBlendFuncSeparateEXT is used when available to avoid an incorrect alpha value when the target
|
||||
// glBlendFuncSeparate is used when available to avoid an incorrect alpha value when the target
|
||||
// is a RenderTexture -- in this case the alpha value must be written directly to the target buffer
|
||||
|
||||
// Alpha blending
|
||||
default :
|
||||
case BlendAlpha :
|
||||
if (GLEW_EXT_blend_func_separate)
|
||||
glCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
if (GL_blend_func_separate)
|
||||
glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
else
|
||||
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
break;
|
||||
|
||||
// Additive blending
|
||||
case BlendAdd :
|
||||
if (GLEW_EXT_blend_func_separate)
|
||||
glCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE));
|
||||
if (GL_blend_func_separate)
|
||||
glCheck(glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE));
|
||||
else
|
||||
glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
|
||||
break;
|
||||
|
|
|
@ -53,14 +53,14 @@ RenderTextureImplFBO::~RenderTextureImplFBO()
|
|||
if (m_depthBuffer)
|
||||
{
|
||||
GLuint depthBuffer = static_cast<GLuint>(m_depthBuffer);
|
||||
glCheck(glDeleteRenderbuffersEXT(1, &depthBuffer));
|
||||
glCheck(glDeleteRenderbuffers(1, &depthBuffer));
|
||||
}
|
||||
|
||||
// Destroy the frame buffer
|
||||
if (m_frameBuffer)
|
||||
{
|
||||
GLuint frameBuffer = static_cast<GLuint>(m_frameBuffer);
|
||||
glCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
|
||||
glCheck(glDeleteFramebuffers(1, &frameBuffer));
|
||||
}
|
||||
|
||||
// Delete the context
|
||||
|
@ -73,10 +73,10 @@ bool RenderTextureImplFBO::isAvailable()
|
|||
{
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that GLEW is initialized
|
||||
priv::ensureGlewInit();
|
||||
// Make sure that extensions are initialized
|
||||
priv::ensureExtensionsInit();
|
||||
|
||||
return GLEW_EXT_framebuffer_object != 0;
|
||||
return GL_framebuffer_object != 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,38 +88,38 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
|
|||
|
||||
// Create the framebuffer object
|
||||
GLuint frameBuffer = 0;
|
||||
glCheck(glGenFramebuffersEXT(1, &frameBuffer));
|
||||
glCheck(glGenFramebuffers(1, &frameBuffer));
|
||||
m_frameBuffer = static_cast<unsigned int>(frameBuffer);
|
||||
if (!m_frameBuffer)
|
||||
{
|
||||
err() << "Impossible to create render texture (failed to create the frame buffer object)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_frameBuffer));
|
||||
glCheck(glBindFramebuffer(GL_FRAMEBUFFER, m_frameBuffer));
|
||||
|
||||
// Create the depth buffer if requested
|
||||
if (depthBuffer)
|
||||
{
|
||||
GLuint depth = 0;
|
||||
glCheck(glGenRenderbuffersEXT(1, &depth));
|
||||
glCheck(glGenRenderbuffers(1, &depth));
|
||||
m_depthBuffer = static_cast<unsigned int>(depth);
|
||||
if (!m_depthBuffer)
|
||||
{
|
||||
err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
glCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer));
|
||||
glCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height));
|
||||
glCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer));
|
||||
glCheck(glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer));
|
||||
glCheck(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height));
|
||||
glCheck(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer));
|
||||
}
|
||||
|
||||
// Link the texture to the frame buffer
|
||||
glCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0));
|
||||
glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0));
|
||||
|
||||
// A final check, just to be sure...
|
||||
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
glCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
|
||||
glCheck(glBindFramebuffer(GL_FRAMEBUFFER, 0));
|
||||
err() << "Impossible to create render texture (failed to link the target texture to the frame buffer)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -35,12 +35,14 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#ifndef SFML_OPENGL_ES
|
||||
|
||||
namespace
|
||||
{
|
||||
// Retrieve the maximum number of texture units available
|
||||
GLint getMaxTextureUnits()
|
||||
{
|
||||
GLint maxUnits;
|
||||
GLint maxUnits = 0;
|
||||
glCheck(glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &maxUnits));
|
||||
return maxUnits;
|
||||
}
|
||||
|
@ -427,8 +429,8 @@ bool Shader::isAvailable()
|
|||
{
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that GLEW is initialized
|
||||
priv::ensureGlewInit();
|
||||
// Make sure that extensions are initialized
|
||||
priv::ensureExtensionsInit();
|
||||
|
||||
return GLEW_ARB_shading_language_100 &&
|
||||
GLEW_ARB_shader_objects &&
|
||||
|
@ -591,3 +593,158 @@ int Shader::getParamLocation(const std::string& name)
|
|||
}
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#else // SFML_OPENGL_ES
|
||||
|
||||
// OpenGL ES 1 does't support GLSL shaders at all, we have to provide an empty implementation
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Shader::CurrentTextureType Shader::CurrentTexture;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Shader::Shader() :
|
||||
m_shaderProgram (0),
|
||||
m_currentTexture(-1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Shader::~Shader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::loadFromFile(const std::string& filename, Type type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::loadFromMemory(const std::string& shader, Type type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::loadFromStream(InputStream& stream, Type type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::loadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, float x)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, float x, float y)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, float x, float y, float z)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, float x, float y, float z, float w)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, const Vector2f& v)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, const Vector3f& v)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, const Color& color)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, const sf::Transform& transform)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, const Texture& texture)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::setParameter(const std::string& name, CurrentTextureType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::bind(const Shader* shader)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::isAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Shader::bindTextures() const
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#endif // SFML_OPENGL_ES
|
||||
|
|
|
@ -140,7 +140,7 @@ void Sprite::draw(RenderTarget& target, RenderStates states) const
|
|||
{
|
||||
states.transform *= getTransform();
|
||||
states.texture = m_texture;
|
||||
target.draw(m_vertices, 4, Quads, states);
|
||||
target.draw(m_vertices, 4, TrianglesStrip, states);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,8 @@ void Sprite::updatePositions()
|
|||
|
||||
m_vertices[0].position = Vector2f(0, 0);
|
||||
m_vertices[1].position = Vector2f(0, bounds.height);
|
||||
m_vertices[2].position = Vector2f(bounds.width, bounds.height);
|
||||
m_vertices[3].position = Vector2f(bounds.width, 0);
|
||||
m_vertices[2].position = Vector2f(bounds.width, 0);
|
||||
m_vertices[3].position = Vector2f(bounds.width, bounds.height);
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,8 +167,8 @@ void Sprite::updateTexCoords()
|
|||
|
||||
m_vertices[0].texCoords = Vector2f(left, top);
|
||||
m_vertices[1].texCoords = Vector2f(left, bottom);
|
||||
m_vertices[2].texCoords = Vector2f(right, bottom);
|
||||
m_vertices[3].texCoords = Vector2f(right, top);
|
||||
m_vertices[2].texCoords = Vector2f(right, top);
|
||||
m_vertices[3].texCoords = Vector2f(right, bottom);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -34,30 +34,30 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Text::Text() :
|
||||
Text::Text() :
|
||||
m_string (),
|
||||
m_font (NULL),
|
||||
m_characterSize (30),
|
||||
m_style (Regular),
|
||||
m_color (255, 255, 255),
|
||||
m_vertices (Quads),
|
||||
m_vertices (Triangles),
|
||||
m_bounds (),
|
||||
m_geometryNeedUpdate(false)
|
||||
m_geometryNeedUpdate(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Text::Text(const String& string, const Font& font, unsigned int characterSize) :
|
||||
Text::Text(const String& string, const Font& font, unsigned int characterSize) :
|
||||
m_string (string),
|
||||
m_font (&font),
|
||||
m_characterSize (characterSize),
|
||||
m_style (Regular),
|
||||
m_color (255, 255, 255),
|
||||
m_vertices (Quads),
|
||||
m_vertices (Triangles),
|
||||
m_bounds (),
|
||||
m_geometryNeedUpdate(true)
|
||||
m_geometryNeedUpdate(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -294,8 +294,10 @@ void Text::ensureGeometryUpdate() const
|
|||
|
||||
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// Handle special characters
|
||||
|
@ -337,8 +339,10 @@ void Text::ensureGeometryUpdate() const
|
|||
// Add a quad for the current character
|
||||
m_vertices.append(Vertex(Vector2f(x + left - italic * top, y + top), m_color, Vector2f(u1, v1)));
|
||||
m_vertices.append(Vertex(Vector2f(x + right - italic * top, y + top), m_color, Vector2f(u2, v1)));
|
||||
m_vertices.append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), m_color, Vector2f(u2, v2)));
|
||||
m_vertices.append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), m_color, Vector2f(u1, v2)));
|
||||
m_vertices.append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), m_color, Vector2f(u1, v2)));
|
||||
m_vertices.append(Vertex(Vector2f(x + right - italic * top, y + top), m_color, Vector2f(u2, v1)));
|
||||
m_vertices.append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), m_color, Vector2f(u2, v2)));
|
||||
|
||||
// Update the current bounds
|
||||
minX = std::min(minX, x + left - italic * bottom);
|
||||
|
@ -358,8 +362,10 @@ void Text::ensureGeometryUpdate() const
|
|||
|
||||
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
|
||||
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
|
||||
}
|
||||
|
||||
// Update the bounding rectangle
|
||||
|
|
|
@ -142,7 +142,7 @@ bool Texture::create(unsigned int width, unsigned int height)
|
|||
|
||||
// Initialize the texture
|
||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||
glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
|
||||
glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : GL_CLAMP_TO_EDGE));
|
||||
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
|
||||
|
@ -266,6 +266,22 @@ Image Texture::copyToImage() const
|
|||
// Create an array of pixels
|
||||
std::vector<Uint8> pixels(m_size.x * m_size.y * 4);
|
||||
|
||||
#ifdef SFML_OPENGL_ES
|
||||
|
||||
// OpenGL ES doesn't have the glGetTexImage function, the only way to read
|
||||
// from a texture is to bind it to a FBO and use glReadPixels
|
||||
GLuint frameBuffer = 0;
|
||||
glCheck(glGenFramebuffers(1, &frameBuffer));
|
||||
if (frameBuffer)
|
||||
{
|
||||
glCheck(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer));
|
||||
glCheck(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0));
|
||||
glCheck(glReadPixels(0, 0, m_size.x, m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]));
|
||||
glCheck(glDeleteFramebuffers(1, &frameBuffer));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if ((m_size == m_actualSize) && !m_pixelsFlipped)
|
||||
{
|
||||
// Texture is not padded nor flipped, we can use a direct copy
|
||||
|
@ -302,6 +318,8 @@ Image Texture::copyToImage() const
|
|||
}
|
||||
}
|
||||
|
||||
#endif // SFML_OPENGL_ES
|
||||
|
||||
// Create the image
|
||||
Image image;
|
||||
image.create(m_size.x, m_size.y, &pixels[0]);
|
||||
|
@ -530,10 +548,10 @@ unsigned int Texture::getValidSize(unsigned int size)
|
|||
{
|
||||
ensureGlContext();
|
||||
|
||||
// Make sure that GLEW is initialized
|
||||
priv::ensureGlewInit();
|
||||
// Make sure that extensions are initialized
|
||||
priv::ensureExtensionsInit();
|
||||
|
||||
if (GLEW_ARB_texture_non_power_of_two)
|
||||
if (GL_texture_non_power_of_two)
|
||||
{
|
||||
// If hardware supports NPOT textures, then just return the unmodified size
|
||||
return size;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Unix/ClockImpl.hpp>
|
||||
#ifdef SFML_SYSTEM_MACOS
|
||||
#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS)
|
||||
#include <mach/mach_time.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
|
@ -40,7 +40,7 @@ namespace priv
|
|||
////////////////////////////////////////////////////////////
|
||||
Time ClockImpl::getCurrentTime()
|
||||
{
|
||||
#ifdef SFML_SYSTEM_MACOS
|
||||
#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS)
|
||||
|
||||
// Mac OS X specific implementation (it doesn't support clock_gettime)
|
||||
static mach_timebase_info_data_t frequency = {0, 0};
|
||||
|
|
|
@ -21,6 +21,7 @@ set(SRC
|
|||
${SRCROOT}/JoystickManager.hpp
|
||||
${INCROOT}/Keyboard.hpp
|
||||
${SRCROOT}/Keyboard.cpp
|
||||
${INCROOT}/Main.hpp
|
||||
${INCROOT}/Mouse.hpp
|
||||
${SRCROOT}/Mouse.cpp
|
||||
${SRCROOT}/VideoMode.cpp
|
||||
|
@ -63,8 +64,7 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
|||
${SRCROOT}/Unix/VideoModeImpl.cpp
|
||||
${SRCROOT}/Unix/WindowImplX11.cpp
|
||||
${SRCROOT}/Unix/WindowImplX11.hpp
|
||||
)
|
||||
if(SFML_OS_LINUX)
|
||||
if(SFML_OS_LINUX)
|
||||
set(PLATFORM_SRC
|
||||
${PLATFORM_SRC}
|
||||
${SRCROOT}/Unix/JoystickImpl.cpp
|
||||
|
@ -76,9 +76,9 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
|||
${SRCROOT}/FreeBSD/JoystickImpl.cpp
|
||||
${SRCROOT}/FreeBSD/JoystickImpl.hpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
source_group("unix" FILES ${PLATFORM_SRC})
|
||||
elseif(SFML_OS_MACOSX)
|
||||
elseif(SFML_OS_MACOSX)
|
||||
set(PLATFORM_SRC
|
||||
${SRCROOT}/OSX/cpp_objc_conversion.h
|
||||
${SRCROOT}/OSX/cpp_objc_conversion.mm
|
||||
|
@ -116,36 +116,63 @@ elseif(SFML_OS_MACOSX)
|
|||
${SRCROOT}/OSX/WindowImplDelegateProtocol.h
|
||||
)
|
||||
source_group("mac" FILES ${PLATFORM_SRC})
|
||||
elseif(IOS)
|
||||
set(PLATFORM_SRC
|
||||
${SRCROOT}/iOS/EaglContext.mm
|
||||
${SRCROOT}/iOS/EaglContext.hpp
|
||||
${SRCROOT}/iOS/InputImpl.mm
|
||||
${SRCROOT}/iOS/InputImpl.hpp
|
||||
${SRCROOT}/iOS/JoystickImpl.mm
|
||||
${SRCROOT}/iOS/JoystickImpl.hpp
|
||||
${SRCROOT}/iOS/VideoModeImpl.mm
|
||||
${SRCROOT}/iOS/WindowImplUIKit.hpp
|
||||
${SRCROOT}/iOS/WindowImplUIKit.mm
|
||||
${SRCROOT}/iOS/Main.mm
|
||||
${SRCROOT}/iOS/ObjCType.hpp
|
||||
${SRCROOT}/iOS/SFAppDelegate.hpp
|
||||
${SRCROOT}/iOS/SFAppDelegate.mm
|
||||
${SRCROOT}/iOS/SFView.hpp
|
||||
${SRCROOT}/iOS/SFView.mm
|
||||
${SRCROOT}/iOS/SFViewController.hpp
|
||||
${SRCROOT}/iOS/SFViewController.mm
|
||||
${SRCROOT}/iOS/SFMain.hpp
|
||||
${SRCROOT}/iOS/SFMain.mm
|
||||
)
|
||||
source_group("ios" FILES ${PLATFORM_SRC})
|
||||
endif()
|
||||
|
||||
# find external libraries
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
if(SFML_OS_LINUX)
|
||||
find_package(X11 REQUIRED)
|
||||
if(NOT X11_Xrandr_FOUND)
|
||||
message(FATAL_ERROR "Xrandr library not found")
|
||||
endif()
|
||||
# find external libraries
|
||||
if(NOT SFML_OS_IOS)
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
if(SFML_OS_LINUX)
|
||||
find_package(X11 REQUIRED)
|
||||
if(NOT X11_Xrandr_FOUND)
|
||||
message(FATAL_ERROR "Xrandr library not found")
|
||||
endif()
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
endif()
|
||||
include_directories(${X11_INCLUDE_DIR})
|
||||
|
||||
find_package(UDev REQUIRED)
|
||||
if(NOT UDEV_FOUND)
|
||||
message(FATAL_ERROR "udev library not found")
|
||||
endif()
|
||||
include_directories(${UDEV_INCLUDE_DIR})
|
||||
include_directories(${UDEV_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# build the list of external libraries to link
|
||||
set(WINDOW_EXT_LIBS ${OPENGL_gl_LIBRARY})
|
||||
# build the list of external libraries to link
|
||||
if(SFML_OS_WINDOWS)
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} winmm gdi32)
|
||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES})
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${OPENGL_gl_LIBRARY} winmm gdi32)
|
||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${OPENGL_gl_LIBRARY} ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES})
|
||||
if(SFML_OS_FREEBSD)
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} usbhid)
|
||||
endif()
|
||||
endif()
|
||||
elseif(SFML_OS_MACOSX)
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} "-framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${OPENGL_gl_LIBRARY} "-framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
||||
elseif(SFML_OS_IOS)
|
||||
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} "-framework OpenGLES -framework Foundation -framework UIKit -framework CoreGraphics")
|
||||
endif()
|
||||
|
||||
# define the sfml-window target
|
||||
|
|
|
@ -30,11 +30,14 @@
|
|||
#include <SFML/System/Mutex.hpp>
|
||||
#include <SFML/System/Lock.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
#include <SFML/Window/glext/glext.h>
|
||||
#include <set>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef SFML_SYSTEM_IOS
|
||||
#include <OpenGLES/ES1/gl.h>
|
||||
#else
|
||||
#include <SFML/Window/glext/glext.h>
|
||||
#endif
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
|
@ -51,6 +54,11 @@
|
|||
#include <SFML/Window/OSX/SFContext.hpp>
|
||||
typedef sf::priv::SFContext ContextType;
|
||||
|
||||
#elif defined(SFML_SYSTEM_IOS)
|
||||
|
||||
#include <SFML/Window/iOS/EaglContext.hpp>
|
||||
typedef sf::priv::EaglContext ContextType;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -272,7 +280,7 @@ void GlContext::initialize()
|
|||
|
||||
// Enable antialiasing if needed
|
||||
if (m_settings.antialiasingLevel > 0)
|
||||
glEnable(GL_MULTISAMPLE_ARB);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include <SFML/Window/Unix/InputImpl.hpp>
|
||||
#elif defined(SFML_SYSTEM_MACOS)
|
||||
#include <SFML/Window/OSX/InputImpl.hpp>
|
||||
#elif defined(SFML_SYSTEM_IOS)
|
||||
#include <SFML/Window/iOS/InputImpl.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -86,6 +86,8 @@ struct JoystickState
|
|||
#include <SFML/Window/FreeBSD/JoystickImpl.hpp>
|
||||
#elif defined(SFML_SYSTEM_MACOS)
|
||||
#include <SFML/Window/OSX/JoystickImpl.hpp>
|
||||
#elif defined(SFML_SYSTEM_IOS)
|
||||
#include <SFML/Window/iOS/JoystickImpl.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -37,4 +37,11 @@ bool Keyboard::isKeyPressed(Key key)
|
|||
return priv::InputImpl::isKeyPressed(key);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Keyboard::setVirtualKeyboardVisible(bool visible)
|
||||
{
|
||||
return priv::InputImpl::setVirtualKeyboardVisible(visible);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -47,6 +47,11 @@
|
|||
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
|
||||
typedef sf::priv::WindowImplCocoa WindowImplType;
|
||||
|
||||
#elif defined(SFML_SYSTEM_IOS)
|
||||
|
||||
#include <SFML/Window/iOS/WindowImplUIKit.hpp>
|
||||
typedef sf::priv::WindowImplUIKit WindowImplType;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
152
src/SFML/Window/iOS/EaglContext.hpp
Normal file
152
src/SFML/Window/iOS/EaglContext.hpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_EAGLCONTEXT_HPP
|
||||
#define SFML_EAGLCONTEXT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/GlContext.hpp>
|
||||
#include <SFML/Window/iOS/ObjCType.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <OpenGLES/ES1/gl.h>
|
||||
|
||||
|
||||
SFML_DECLARE_OBJC_CLASS(EAGLContext);
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
class WindowImplUIKit;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief iOS (EAGL) implementation of OpenGL contexts
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class EaglContext : public GlContext
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context, not associated to a window
|
||||
///
|
||||
/// \param shared Context to share the new one with (can be NULL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
EaglContext(EaglContext* shared);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context attached to a window
|
||||
///
|
||||
/// \param shared Context to share the new one with
|
||||
/// \param settings Creation parameters
|
||||
/// \param owner Pointer to the owner window
|
||||
/// \param bitsPerPixel Pixel depth, in bits per pixel
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
EaglContext(EaglContext* shared, const ContextSettings& settings,
|
||||
const WindowImpl* owner, unsigned int bitsPerPixel);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new context that embeds its own rendering target
|
||||
///
|
||||
/// \param shared Context to share the new one with
|
||||
/// \param settings Creation parameters
|
||||
/// \param width Back buffer width, in pixels
|
||||
/// \param height Back buffer height, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
EaglContext(EaglContext* shared, const ContextSettings& settings,
|
||||
unsigned int width, unsigned int height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~EaglContext();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Display what has been rendered to the context so far
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void display();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable vertical synchronization
|
||||
///
|
||||
/// Activating vertical synchronization will limit the number
|
||||
/// of frames displayed to the refresh rate of the monitor.
|
||||
/// This can avoid some visual artifacts, and limit the framerate
|
||||
/// to a good value (but not constant across different computers).
|
||||
///
|
||||
/// \param enabled : True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setVerticalSyncEnabled(bool enabled);
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate the context as the current target
|
||||
/// for rendering
|
||||
///
|
||||
/// \return True on success, false if any error happened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool makeCurrent();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the context
|
||||
///
|
||||
/// \param shared Context to share the new one with (can be NULL)
|
||||
/// \param window Window to attach the context to (can be NULL)
|
||||
/// \param size Size of the context's drawable
|
||||
/// \param bitsPerPixel Pixel depth, in bits per pixel
|
||||
/// \param settings Creation parameters
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void createContext(EaglContext* shared,
|
||||
const WindowImplUIKit* window,
|
||||
Vector2u size,
|
||||
unsigned int bitsPerPixel,
|
||||
const ContextSettings& settings);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
EAGLContext* m_context; ///< The internal context
|
||||
GLuint m_framebuffer; ///< Frame buffer associated to the context
|
||||
GLuint m_colorbuffer; ///< Color render buffer
|
||||
GLuint m_depthbuffer; ///< Depth render buffer
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#endif // SFML_EAGLCONTEXT_HPP
|
191
src/SFML/Window/iOS/EaglContext.mm
Normal file
191
src/SFML/Window/iOS/EaglContext.mm
Normal file
|
@ -0,0 +1,191 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/EaglContext.hpp>
|
||||
#include <SFML/Window/iOS/WindowImplUIKit.hpp>
|
||||
#include <SFML/Window/iOS/SFView.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <OpenGLES/EAGL.h>
|
||||
#include <OpenGLES/ES1/glext.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
EaglContext::EaglContext(EaglContext* shared) :
|
||||
m_context (nil),
|
||||
m_framebuffer(0),
|
||||
m_colorbuffer(0),
|
||||
m_depthbuffer(0)
|
||||
{
|
||||
// Create the context
|
||||
if (shared)
|
||||
m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:[shared->m_context sharegroup]];
|
||||
else
|
||||
m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
EaglContext::EaglContext(EaglContext* shared, const ContextSettings& settings,
|
||||
const WindowImpl* owner, unsigned int bitsPerPixel) :
|
||||
m_context (nil),
|
||||
m_framebuffer(0),
|
||||
m_colorbuffer(0),
|
||||
m_depthbuffer(0)
|
||||
{
|
||||
const WindowImplUIKit* window = static_cast<const WindowImplUIKit*>(owner);
|
||||
|
||||
createContext(shared, window, window->getSize(), bitsPerPixel, settings);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
EaglContext::EaglContext(EaglContext* shared, const ContextSettings& settings,
|
||||
unsigned int width, unsigned int height) :
|
||||
m_context (nil),
|
||||
m_framebuffer(0),
|
||||
m_colorbuffer(0),
|
||||
m_depthbuffer(0)
|
||||
{
|
||||
// This constructor shoult never be used by implementation
|
||||
err() << "Calling bad EaglContext constructor, please contact your developer :)" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
EaglContext::~EaglContext()
|
||||
{
|
||||
if (m_context)
|
||||
{
|
||||
// Activate the context, so that we can destroy the buffers
|
||||
EAGLContext* previousContext = [EAGLContext currentContext];
|
||||
[EAGLContext setCurrentContext:m_context];
|
||||
|
||||
// Destroy the buffers
|
||||
if (m_framebuffer)
|
||||
glDeleteFramebuffersOES(1, &m_framebuffer);
|
||||
if (m_colorbuffer)
|
||||
glDeleteRenderbuffersOES(1, &m_colorbuffer);
|
||||
if (m_depthbuffer)
|
||||
glDeleteRenderbuffersOES(1, &m_depthbuffer);
|
||||
|
||||
// Restore the previous context
|
||||
[EAGLContext setCurrentContext:previousContext];
|
||||
|
||||
// Release the context
|
||||
[m_context release];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool EaglContext::makeCurrent()
|
||||
{
|
||||
return [EAGLContext setCurrentContext:m_context];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void EaglContext::display()
|
||||
{
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorbuffer);
|
||||
[m_context presentRenderbuffer:GL_RENDERBUFFER_OES];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void EaglContext::setVerticalSyncEnabled(bool enabled)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void EaglContext::createContext(EaglContext* shared,
|
||||
const WindowImplUIKit* window,
|
||||
Vector2u size,
|
||||
unsigned int bitsPerPixel,
|
||||
const ContextSettings& settings)
|
||||
{
|
||||
// Save the settings
|
||||
m_settings = settings;
|
||||
|
||||
// Create the context
|
||||
if (shared)
|
||||
m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:[shared->m_context sharegroup]];
|
||||
else
|
||||
m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
|
||||
|
||||
// Activate it
|
||||
makeCurrent();
|
||||
|
||||
// Create the framebuffer (this is the only allowed drawable on iOS)
|
||||
glGenFramebuffersOES(1, &m_framebuffer);
|
||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_framebuffer);
|
||||
|
||||
// Create the color buffer
|
||||
glGenRenderbuffersOES(1, &m_colorbuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorbuffer);
|
||||
if (window)
|
||||
[m_context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:window->getGlView().layer];
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, m_colorbuffer);
|
||||
|
||||
// Create a depth buffer if requested
|
||||
if (settings.depthBits > 0)
|
||||
{
|
||||
// Find the best internal format
|
||||
GLenum format;
|
||||
if (settings.depthBits > 16)
|
||||
{
|
||||
format = GL_DEPTH_COMPONENT24_OES;
|
||||
m_settings.depthBits = 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
format = GL_DEPTH_COMPONENT16_OES;
|
||||
m_settings.depthBits = 16;
|
||||
}
|
||||
|
||||
// Create the depth buffer
|
||||
glGenRenderbuffersOES(1, &m_depthbuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthbuffer);
|
||||
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, size.x, size.y);
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, m_depthbuffer);
|
||||
}
|
||||
|
||||
// Make sure that everything's ok
|
||||
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE_OES)
|
||||
err() << "Failed to create a valid frame buffer (error code: " << status << ")" << std::endl;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
131
src/SFML/Window/iOS/InputImpl.hpp
Normal file
131
src/SFML/Window/iOS/InputImpl.hpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_INPUTIMPLIOS_HPP
|
||||
#define SFML_INPUTIMPLIOS_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief iOS implementation of inputs (keyboard + mouse)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class InputImpl
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a key is pressed
|
||||
///
|
||||
/// \param key Key to check
|
||||
///
|
||||
/// \return True if the key is pressed, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool isKeyPressed(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the virtual keyboard
|
||||
///
|
||||
/// \param visible True to show, false to hide
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setVirtualKeyboardVisible(bool visible);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a mouse button is pressed
|
||||
///
|
||||
/// \param button Button to check
|
||||
///
|
||||
/// \return True if the button is pressed, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool isMouseButtonPressed(Mouse::Button button);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, in global (desktop) coordinates.
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getMousePosition();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function returns the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it returns desktop coordinates.
|
||||
///
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
/// \return Current position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector2i getMousePosition(const Window& relativeTo);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in desktop coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor in global (desktop) coordinates.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setMousePosition(const Vector2i& position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the current position of the mouse in window coordinates
|
||||
///
|
||||
/// This function sets the current position of the mouse
|
||||
/// cursor, relative to the given window.
|
||||
/// If no window is used, it sets the position in desktop coordinates.
|
||||
///
|
||||
/// \param position New position of the mouse
|
||||
/// \param relativeTo Reference window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void setMousePosition(const Vector2i& position, const Window& relativeTo);
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_INPUTIMPLIOS_HPP
|
99
src/SFML/Window/iOS/InputImpl.mm
Normal file
99
src/SFML/Window/iOS/InputImpl.mm
Normal file
|
@ -0,0 +1,99 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/InputImpl.hpp>
|
||||
#include <SFML/Window/iOS/SFAppDelegate.hpp>
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
bool InputImpl::isKeyPressed(Keyboard::Key key)
|
||||
{
|
||||
// Not applicable
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setVirtualKeyboardVisible(bool visible)
|
||||
{
|
||||
[[SFAppDelegate getInstance] setVirtualKeyboardVisible:visible];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool InputImpl::isMouseButtonPressed(Mouse::Button button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case Mouse::Left:
|
||||
return getMousePosition() != Vector2i(-1, -1);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getMousePosition()
|
||||
{
|
||||
return [[SFAppDelegate getInstance] getTouchPosition];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::getMousePosition(const Window& relativeTo)
|
||||
{
|
||||
(void)relativeTo;
|
||||
|
||||
return getMousePosition();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setMousePosition(const Vector2i& position)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
113
src/SFML/Window/iOS/JoystickImpl.hpp
Normal file
113
src/SFML/Window/iOS/JoystickImpl.hpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_JOYSTICKIMPLIOS_HPP
|
||||
#define SFML_JOYSTICKIMPLIOS_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/JoystickImpl.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief iOS implementation of joysticks
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class JoystickImpl
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Perform the global initialization of the joystick module
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void initialize();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Perform the global cleanup of the joystick module
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void cleanup();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a joystick is currently connected
|
||||
///
|
||||
/// \param index Index of the joystick to check
|
||||
///
|
||||
/// \return True if the joystick is connected, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool isConnected(unsigned int index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open the joystick
|
||||
///
|
||||
/// \param index Index assigned to the joystick
|
||||
///
|
||||
/// \return True on success, false on failure
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool open(unsigned int index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Close the joystick
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void close();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the joystick capabilities
|
||||
///
|
||||
/// \return Joystick capabilities
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
JoystickCaps getCapabilities() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the joystick and get its new state
|
||||
///
|
||||
/// \return Joystick state
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
JoystickState update();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
int m_index; ///< Index of the joystick
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_JOYSTICKIMPLIOS_HPP
|
193
src/SFML/Window/iOS/JoystickImpl.mm
Normal file
193
src/SFML/Window/iOS/JoystickImpl.mm
Normal file
|
@ -0,0 +1,193 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/JoystickImpl.hpp>
|
||||
#include <SFML/Window/iOS/SFAppDelegate.hpp>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
enum
|
||||
{
|
||||
Accelerometer,
|
||||
Gyroscope,
|
||||
Magnetometer,
|
||||
UserAcceleration,
|
||||
AbsoluteOrientation
|
||||
};
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void JoystickImpl::initialize()
|
||||
{
|
||||
static const NSTimeInterval updateInterval = 1. / 60.;
|
||||
|
||||
[SFAppDelegate getInstance].motionManager.accelerometerUpdateInterval = updateInterval;
|
||||
[[SFAppDelegate getInstance].motionManager startAccelerometerUpdates];
|
||||
|
||||
[SFAppDelegate getInstance].motionManager.gyroUpdateInterval = updateInterval;
|
||||
[[SFAppDelegate getInstance].motionManager startGyroUpdates];
|
||||
|
||||
[SFAppDelegate getInstance].motionManager.magnetometerUpdateInterval = updateInterval;
|
||||
[[SFAppDelegate getInstance].motionManager startMagnetometerUpdates];
|
||||
|
||||
[SFAppDelegate getInstance].motionManager.deviceMotionUpdateInterval = updateInterval;
|
||||
[[SFAppDelegate getInstance].motionManager startDeviceMotionUpdates];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void JoystickImpl::cleanup()
|
||||
{
|
||||
if ([SFAppDelegate getInstance].motionManager.accelerometerActive)
|
||||
[[SFAppDelegate getInstance].motionManager stopAccelerometerUpdates];
|
||||
|
||||
if ([SFAppDelegate getInstance].motionManager.gyroActive)
|
||||
[[SFAppDelegate getInstance].motionManager stopGyroUpdates];
|
||||
|
||||
if ([SFAppDelegate getInstance].motionManager.magnetometerActive)
|
||||
[[SFAppDelegate getInstance].motionManager stopMagnetometerUpdates];
|
||||
|
||||
if ([SFAppDelegate getInstance].motionManager.deviceMotionActive)
|
||||
[[SFAppDelegate getInstance].motionManager stopDeviceMotionUpdates];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool JoystickImpl::isConnected(unsigned int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case Accelerometer:
|
||||
return [SFAppDelegate getInstance].motionManager.accelerometerAvailable;
|
||||
|
||||
case Gyroscope:
|
||||
return [SFAppDelegate getInstance].motionManager.gyroAvailable;
|
||||
|
||||
case Magnetometer:
|
||||
return [SFAppDelegate getInstance].motionManager.magnetometerAvailable;
|
||||
|
||||
case UserAcceleration:
|
||||
case AbsoluteOrientation:
|
||||
return [SFAppDelegate getInstance].motionManager.deviceMotionAvailable;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool JoystickImpl::open(unsigned int index)
|
||||
{
|
||||
// Save the index
|
||||
m_index = index;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void JoystickImpl::close()
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
JoystickCaps JoystickImpl::getCapabilities() const
|
||||
{
|
||||
JoystickCaps caps;
|
||||
|
||||
// All the connected joysticks have (X, Y, Z) axes
|
||||
caps.axes[Joystick::X] = true;
|
||||
caps.axes[Joystick::Y] = true;
|
||||
caps.axes[Joystick::Z] = true;
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
JoystickState JoystickImpl::update()
|
||||
{
|
||||
JoystickState state;
|
||||
|
||||
// Always connected
|
||||
state.connected = true;
|
||||
|
||||
switch (m_index)
|
||||
{
|
||||
case Accelerometer:
|
||||
// Acceleration is given in G (reminder: 1G is regular earth gravity, 9.81 m/s^2), in range [-2, 2] (could be more on newer devices?)
|
||||
state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.accelerometerData.acceleration.x;
|
||||
state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.accelerometerData.acceleration.y;
|
||||
state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.accelerometerData.acceleration.z;
|
||||
break;
|
||||
|
||||
case Gyroscope:
|
||||
// Rotation rates are given in rad/s, in range [?, ?]
|
||||
state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.gyroData.rotationRate.x;
|
||||
state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.gyroData.rotationRate.y;
|
||||
state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.gyroData.rotationRate.z;
|
||||
break;
|
||||
|
||||
case Magnetometer:
|
||||
// Magnetic field is given in microteslas, in range [?, ?]
|
||||
state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.magnetometerData.magneticField.x;
|
||||
state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.magnetometerData.magneticField.y;
|
||||
state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.magnetometerData.magneticField.z;
|
||||
break;
|
||||
|
||||
case UserAcceleration:
|
||||
// User acceleration (gravity removed), same unit and range as raw accelerometer values
|
||||
state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.deviceMotion.userAcceleration.x;
|
||||
state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.deviceMotion.userAcceleration.y;
|
||||
state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.deviceMotion.userAcceleration.z;
|
||||
break;
|
||||
|
||||
case AbsoluteOrientation:
|
||||
// Absolute rotation (Euler) angles are given in radians, in range [-PI, PI]
|
||||
state.axes[Joystick::X] = [SFAppDelegate getInstance].motionManager.deviceMotion.attitude.yaw;
|
||||
state.axes[Joystick::Y] = [SFAppDelegate getInstance].motionManager.deviceMotion.attitude.pitch;
|
||||
state.axes[Joystick::Z] = [SFAppDelegate getInstance].motionManager.deviceMotion.attitude.roll;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
38
src/SFML/Window/iOS/Main.mm
Normal file
38
src/SFML/Window/iOS/Main.mm
Normal file
|
@ -0,0 +1,38 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/SFAppDelegate.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
[SFAppDelegate main:argc argv:argv];
|
||||
}
|
||||
}
|
37
src/SFML/Window/iOS/ObjCType.hpp
Normal file
37
src/SFML/Window/iOS/ObjCType.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_OBJCTYPE_HPP
|
||||
#define SFML_OBJCTYPE_HPP
|
||||
|
||||
|
||||
// Forward declare an Objective-C class
|
||||
#ifdef __OBJC__
|
||||
#define SFML_DECLARE_OBJC_CLASS(c) @class c
|
||||
#else
|
||||
#define SFML_DECLARE_OBJC_CLASS(c) typedef struct objc_object c
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SFML_OBJCTYPE_HPP
|
113
src/SFML/Window/iOS/SFAppDelegate.hpp
Normal file
113
src/SFML/Window/iOS/SFAppDelegate.hpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_SFAPPDELEGATE_HPP
|
||||
#define SFML_SFAPPDELEGATE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/iOS/WindowImplUIKit.hpp>
|
||||
#include <UIKit/UIKit.h>
|
||||
#include <CoreMotion/CoreMotion.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Our custom application delegate
|
||||
///
|
||||
/// This class handles global application events.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface SFAppDelegate : NSObject<UIApplicationDelegate>
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Run the application
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
+(int)main:(int)argc argv:(char**)argv;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the instance of the application delegate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
+(SFAppDelegate*)getInstance;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the virtual keyboard
|
||||
///
|
||||
/// \param visible True to show, false to hide
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)setVirtualKeyboardVisible:(bool)visible;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current touch position
|
||||
///
|
||||
/// \return Current touch position, or (-1, -1) if no touch
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (sf::Vector2i)getTouchPosition;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Receive an external touch begin notification
|
||||
///
|
||||
/// \param position Position of the touch
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyTouchBeginAt:(CGPoint)position;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Receive an external touch move notification
|
||||
///
|
||||
/// \param position Position of the touch
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyTouchMoveAt:(CGPoint)position;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Receive an external touch end notification
|
||||
///
|
||||
/// \param position Position of the touch
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyTouchEndAt:(CGPoint)position;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Receive an external character notification
|
||||
///
|
||||
/// \param character The typed character
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyCharacter:(sf::Uint32)character;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
@property (nonatomic) sf::priv::WindowImplUIKit* sfWindow; ///< Main window of the application
|
||||
@property (readonly, nonatomic) CMMotionManager* motionManager; ///< Instance of the motion manager
|
||||
|
||||
@end
|
||||
|
||||
#endif // SFML_SFAPPDELEGATE_HPP
|
||||
|
261
src/SFML/Window/iOS/SFAppDelegate.mm
Normal file
261
src/SFML/Window/iOS/SFAppDelegate.mm
Normal file
|
@ -0,0 +1,261 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/SFAppDelegate.hpp>
|
||||
#include <SFML/Window/iOS/SFMain.hpp>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// Save the main's arguments, to pass them back to the user's main
|
||||
int mainArgc;
|
||||
char** mainArgv;
|
||||
|
||||
// Save the global instance of the delegate
|
||||
SFAppDelegate* delegateInstance = NULL;
|
||||
}
|
||||
|
||||
|
||||
@interface SFAppDelegate()
|
||||
|
||||
@property (nonatomic) CMMotionManager* motionManager;
|
||||
@property (nonatomic) sf::Vector2i touchPosition;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation SFAppDelegate
|
||||
|
||||
@synthesize sfWindow;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
+(int)main:(int)argc argv:(char**)argv
|
||||
{
|
||||
mainArgc = argc;
|
||||
mainArgv = argv;
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([SFAppDelegate class]));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
+(SFAppDelegate*)getInstance
|
||||
{
|
||||
return delegateInstance;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
-(void)runUserMain
|
||||
{
|
||||
sfmlMain(mainArgc, mainArgv);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
// Save the delegate instance
|
||||
delegateInstance = self;
|
||||
|
||||
// Instanciate the motion manager
|
||||
self.motionManager = [[CMMotionManager alloc] init];
|
||||
|
||||
// Initialize the touch position
|
||||
self.touchPosition = sf::Vector2i(-1, -1);
|
||||
|
||||
// Register orientation changes notifications
|
||||
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object: nil];
|
||||
|
||||
// Schedule an indirect call to the user main, so that this call (and the whole
|
||||
// init sequence) can end, and the default splashscreen can be destroyed
|
||||
[self performSelector:@selector(runUserMain) withObject:nil afterDelay:0.0];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)applicationWillResignActive:(UIApplication *)application
|
||||
{
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||
{
|
||||
// Generate a LostFocus event
|
||||
if (self.sfWindow)
|
||||
{
|
||||
sf::Event event;
|
||||
event.type = sf::Event::LostFocus;
|
||||
sfWindow->pushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application
|
||||
{
|
||||
// Generate a GainedFocus event
|
||||
if (self.sfWindow)
|
||||
{
|
||||
sf::Event event;
|
||||
event.type = sf::Event::GainedFocus;
|
||||
sfWindow->pushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application
|
||||
{
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)applicationWillTerminate:(UIApplication *)application
|
||||
{
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)deviceOrientationDidChange:(NSNotification *)notification
|
||||
{
|
||||
if (self.sfWindow)
|
||||
{
|
||||
// Get the new orientation
|
||||
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
|
||||
|
||||
// Filter interesting orientations
|
||||
if ((orientation == UIDeviceOrientationLandscapeLeft) ||
|
||||
(orientation == UIDeviceOrientationLandscapeRight) ||
|
||||
(orientation == UIDeviceOrientationPortrait) ||
|
||||
(orientation == UIDeviceOrientationPortraitUpsideDown))
|
||||
{
|
||||
// Send a Resized event to the current window
|
||||
sf::Event event;
|
||||
event.type = sf::Event::Resized;
|
||||
if (UIDeviceOrientationIsLandscape(orientation))
|
||||
{
|
||||
event.size.width = 480;
|
||||
event.size.height = 320;
|
||||
}
|
||||
else
|
||||
{
|
||||
event.size.width = 320;
|
||||
event.size.height = 480;
|
||||
}
|
||||
sfWindow->pushEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)setVirtualKeyboardVisible:(bool)visible
|
||||
{
|
||||
if (self.sfWindow)
|
||||
self.sfWindow->setVirtualKeyboardVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (sf::Vector2i)getTouchPosition
|
||||
{
|
||||
return self.touchPosition;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyTouchBeginAt:(CGPoint)position
|
||||
{
|
||||
self.touchPosition = sf::Vector2i(static_cast<int>(position.x), static_cast<int>(position.y));
|
||||
|
||||
if (self.sfWindow)
|
||||
{
|
||||
sf::Event event;
|
||||
event.type = sf::Event::MouseButtonPressed;
|
||||
event.mouseButton.x = position.x;
|
||||
event.mouseButton.y = position.y;
|
||||
event.mouseButton.button = sf::Mouse::Left;
|
||||
sfWindow->pushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyTouchMoveAt:(CGPoint)position
|
||||
{
|
||||
self.touchPosition = sf::Vector2i(static_cast<int>(position.x), static_cast<int>(position.y));
|
||||
|
||||
if (self.sfWindow)
|
||||
{
|
||||
sf::Event event;
|
||||
event.type = sf::Event::MouseMoved;
|
||||
event.mouseMove.x = position.x;
|
||||
event.mouseMove.y = position.y;
|
||||
sfWindow->pushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyTouchEndAt:(CGPoint)position
|
||||
{
|
||||
self.touchPosition = sf::Vector2i(-1, -1);
|
||||
|
||||
if (self.sfWindow)
|
||||
{
|
||||
sf::Event event;
|
||||
event.type = sf::Event::MouseButtonReleased;
|
||||
event.mouseButton.x = position.x;
|
||||
event.mouseButton.y = position.y;
|
||||
event.mouseButton.button = sf::Mouse::Left;
|
||||
sfWindow->pushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)notifyCharacter:(sf::Uint32)character
|
||||
{
|
||||
if (self.sfWindow)
|
||||
{
|
||||
sf::Event event;
|
||||
event.type = sf::Event::TextEntered;
|
||||
event.text.unicode = character;
|
||||
sfWindow->pushEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
35
src/SFML/Window/iOS/SFMain.hpp
Normal file
35
src/SFML/Window/iOS/SFMain.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_SFMAIN_HPP
|
||||
#define SFML_SFMAIN_HPP
|
||||
|
||||
|
||||
int sfmlMain(int argc, char** argv);
|
||||
|
||||
int sfmlMain();
|
||||
|
||||
|
||||
#endif // SFML_SFMAIN_HPP
|
||||
|
52
src/SFML/Window/iOS/SFMain.mm
Normal file
52
src/SFML/Window/iOS/SFMain.mm
Normal file
|
@ -0,0 +1,52 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/SFMain.hpp>
|
||||
|
||||
|
||||
// We declare both versions of sfmlMain, but with the 'weak' attribute (GCC extension)
|
||||
// so that the user-declared one will replace SFML's one at linking stage.
|
||||
//
|
||||
// If user defines main(argc, argv) then it will be called directly,
|
||||
// if he defines main() then it will be called by our placeholder.
|
||||
//
|
||||
// The sfmlMain() version is never called, it is just defined to avoid a
|
||||
// linker error if the user directly defines the version with arguments.
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
__attribute__((weak)) int sfmlMain(int, char**)
|
||||
{
|
||||
return sfmlMain();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
__attribute__((weak)) int sfmlMain()
|
||||
{
|
||||
return 0;
|
||||
}
|
43
src/SFML/Window/iOS/SFView.hpp
Normal file
43
src/SFML/Window/iOS/SFView.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_SFVIEW_HPP
|
||||
#define SFML_SFVIEW_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Our custom implementation of the window's view
|
||||
/// (supports OpenGL and reports events)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface SFView : UIView<UIKeyInput>
|
||||
|
||||
@end
|
||||
|
||||
#endif // SFML_SFVIEW_HPP
|
156
src/SFML/Window/iOS/SFView.mm
Normal file
156
src/SFML/Window/iOS/SFView.mm
Normal file
|
@ -0,0 +1,156 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/SFView.hpp>
|
||||
#include <SFML/Window/iOS/SFAppDelegate.hpp>
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <QuartzCore/CAEAGLLayer.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
@implementation SFView
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
-(BOOL)canBecomeFirstResponder
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (BOOL)hasText
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)deleteBackward
|
||||
{
|
||||
[[SFAppDelegate getInstance] notifyCharacter:'\b'];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)insertText:(NSString*)text
|
||||
{
|
||||
// Convert the NSString to UTF-8
|
||||
const char* utf8 = [text UTF8String];
|
||||
|
||||
// Then convert to UTF-32 and notify the application delegate of each new character
|
||||
const char* end = utf8 + std::strlen(utf8);
|
||||
while (utf8 < end)
|
||||
{
|
||||
sf::Uint32 character;
|
||||
utf8 = sf::Utf8::decode(utf8, end, character);
|
||||
[[SFAppDelegate getInstance] notifyCharacter:character];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
|
||||
{
|
||||
UITouch* touch = [touches anyObject];
|
||||
CGPoint position = [touch locationInView:self];
|
||||
|
||||
[[SFAppDelegate getInstance] notifyTouchBeginAt:position];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
|
||||
{
|
||||
UITouch* touch = [touches anyObject];
|
||||
CGPoint position = [touch locationInView:self];
|
||||
|
||||
[[SFAppDelegate getInstance] notifyTouchMoveAt:position];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
|
||||
{
|
||||
UITouch* touch = [touches anyObject];
|
||||
CGPoint position = [touch locationInView:self];
|
||||
|
||||
[[SFAppDelegate getInstance] notifyTouchEndAt:position];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event
|
||||
{
|
||||
// Treat touch cancel events the same way as touch end
|
||||
[self touchesEnded:touches withEvent:event];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
+(Class)layerClass
|
||||
{
|
||||
return [CAEAGLLayer class];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
-(id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self)
|
||||
{
|
||||
if (![self initialize])
|
||||
{
|
||||
[self release];
|
||||
self = nil;
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
-(bool)initialize
|
||||
{
|
||||
// Configure the EAGL layer
|
||||
CAEAGLLayer* eaglLayer = (CAEAGLLayer*)self.layer;
|
||||
eaglLayer.opaque = YES;
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
|
||||
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
|
||||
nil];
|
||||
|
||||
// Enable user interactions on the view (touch events)
|
||||
self.userInteractionEnabled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@end
|
73
src/SFML/Window/iOS/SFViewController.hpp
Normal file
73
src/SFML/Window/iOS/SFViewController.hpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_SFVIEWCONTROLLER_HPP
|
||||
#define SFML_SFVIEWCONTROLLER_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief The view controller handles the view's orientation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
@interface SFViewController : UIViewController
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tells if the controller supports auto-rotation (iOS < 6)
|
||||
///
|
||||
/// \param interfaceOrientation Orientation to check
|
||||
///
|
||||
/// \return True if auto-rotation is supported, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tells if the controller supports auto-rotation (iOS >= 6)
|
||||
///
|
||||
/// \return True if auto-rotation is supported, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (BOOL)shouldAutorotate;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Returns the supported orientations (iOS >= 6)
|
||||
///
|
||||
/// \return A combination of all the supported orientations
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
- (NSUInteger)supportedInterfaceOrientations;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
@property (nonatomic) bool orientationCanChange; ///< Tells whether the controller's view can rotate or not
|
||||
|
||||
@end
|
||||
|
||||
#endif // SFML_SFVIEWCONTROLLER_HPP
|
59
src/SFML/Window/iOS/SFViewController.mm
Normal file
59
src/SFML/Window/iOS/SFViewController.mm
Normal file
|
@ -0,0 +1,59 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/SFViewController.hpp>
|
||||
|
||||
|
||||
@implementation SFViewController
|
||||
|
||||
@synthesize orientationCanChange;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
(void)interfaceOrientation;
|
||||
|
||||
return self.orientationCanChange;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (BOOL)shouldAutorotate
|
||||
{
|
||||
return self.orientationCanChange;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
- (NSUInteger)supportedInterfaceOrientations
|
||||
{
|
||||
return UIInterfaceOrientationMaskAll;
|
||||
}
|
||||
|
||||
|
||||
@end
|
59
src/SFML/Window/iOS/VideoModeImpl.mm
Normal file
59
src/SFML/Window/iOS/VideoModeImpl.mm
Normal file
|
@ -0,0 +1,59 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/VideoModeImpl.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
|
||||
{
|
||||
VideoMode desktop = getDesktopMode();
|
||||
|
||||
// Return both protrait and landscape resolutions
|
||||
std::vector<VideoMode> modes;
|
||||
modes.push_back(desktop);
|
||||
modes.push_back(VideoMode(desktop.height, desktop.width, desktop.bitsPerPixel));
|
||||
return modes;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
VideoMode VideoModeImpl::getDesktopMode()
|
||||
{
|
||||
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||
return VideoMode(bounds.size.width, bounds.size.height);
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
203
src/SFML/Window/iOS/WindowImplUIKit.hpp
Normal file
203
src/SFML/Window/iOS/WindowImplUIKit.hpp
Normal file
|
@ -0,0 +1,203 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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_WINDOWIMPLUIKIT_HPP
|
||||
#define SFML_WINDOWIMPLUIKIT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <SFML/Window/WindowImpl.hpp>
|
||||
#include <SFML/Window/iOS/ObjCType.hpp>
|
||||
|
||||
|
||||
SFML_DECLARE_OBJC_CLASS(UIWindow);
|
||||
SFML_DECLARE_OBJC_CLASS(SFView);
|
||||
SFML_DECLARE_OBJC_CLASS(SFViewController);
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief iOS (UIKit) implementation of WindowImpl
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class WindowImplUIKit : public WindowImpl
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the window implementation from an existing control
|
||||
///
|
||||
/// \param handle Platform-specific handle of the control
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplUIKit(WindowHandle handle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the window implementation
|
||||
///
|
||||
/// \param mode Video mode to use
|
||||
/// \param title Title of the window
|
||||
/// \param style Window style (resizable, fixed, or fullscren)
|
||||
/// \param settings Additional settings for the underlying OpenGL context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplUIKit(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~WindowImplUIKit();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the OS-specific handle of the window
|
||||
///
|
||||
/// \return Handle of the window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual WindowHandle getSystemHandle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the window
|
||||
///
|
||||
/// \return Position of the window, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2i getPosition() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the position of the window on screen
|
||||
///
|
||||
/// \param position New position of the window, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setPosition(const Vector2i& position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the client size of the window
|
||||
///
|
||||
/// \return Size of the window, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2u getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the size of the rendering region of the window
|
||||
///
|
||||
/// \param size New size, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setSize(const Vector2u& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the title of the window
|
||||
///
|
||||
/// \param title New title
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setTitle(const String& title);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the window's icon
|
||||
///
|
||||
/// \param width Icon's width, in pixels
|
||||
/// \param height Icon's height, in pixels
|
||||
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the window
|
||||
///
|
||||
/// \param visible True to show, false to hide
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setVisible(bool visible);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the mouse cursor
|
||||
///
|
||||
/// \param visible True to show, false to hide
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setMouseCursorVisible(bool visible);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable automatic key-repeat
|
||||
///
|
||||
/// \param enabled True to enable, false to disable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void setKeyRepeatEnabled(bool enabled);
|
||||
|
||||
public:
|
||||
|
||||
using WindowImpl::pushEvent;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the window's view
|
||||
///
|
||||
/// \return Pointer to the window's view
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFView* getGlView() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Show or hide the virtual keyboard
|
||||
///
|
||||
/// \param visible True to show, false to hide
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setVirtualKeyboardVisible(bool visible);
|
||||
|
||||
protected :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Process incoming events from the operating system
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void processEvents();
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
UIWindow* m_window; ///< Pointer to the internal UIKit window
|
||||
SFView* m_view; ///< OpenGL view of the window
|
||||
SFViewController* m_viewController; ///< Controller attached to the view
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_WINDOWIMPLUIKIT_HPP
|
192
src/SFML/Window/iOS/WindowImplUIKit.mm
Normal file
192
src/SFML/Window/iOS/WindowImplUIKit.mm
Normal file
|
@ -0,0 +1,192 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2013 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/iOS/WindowImplUIKit.hpp>
|
||||
#include <SFML/Window/iOS/SFView.hpp>
|
||||
#include <SFML/Window/iOS/SFViewController.hpp>
|
||||
#include <SFML/Window/iOS/SFAppDelegate.hpp>
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplUIKit::WindowImplUIKit(WindowHandle handle)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplUIKit::WindowImplUIKit(VideoMode mode,
|
||||
const String& title,
|
||||
unsigned long style,
|
||||
const ContextSettings& /*settings*/)
|
||||
{
|
||||
// Apply the fullscreen flag
|
||||
[UIApplication sharedApplication].statusBarHidden = !(style & Style::Titlebar) || (style & Style::Fullscreen);
|
||||
|
||||
// Set the orientation according to the requested size
|
||||
if (mode.width > mode.height)
|
||||
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
else
|
||||
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
|
||||
|
||||
// Create the window
|
||||
CGRect frame = {{0, 0}, {mode.width, mode.height}}; // @todo keep user mode or force to device resolution?? (-> test)
|
||||
m_window = [[UIWindow alloc] initWithFrame:frame];
|
||||
|
||||
// Assign it to the application delegate
|
||||
[SFAppDelegate getInstance].sfWindow = this;
|
||||
|
||||
// Create the view
|
||||
m_view = [[SFView alloc] initWithFrame:frame];
|
||||
[m_window addSubview:m_view];
|
||||
[m_view resignFirstResponder];
|
||||
|
||||
// Create the view controller
|
||||
m_viewController = [SFViewController alloc];
|
||||
m_viewController.view = m_view;
|
||||
m_viewController.orientationCanChange = style & Style::Resize;
|
||||
m_window.rootViewController = m_viewController;
|
||||
|
||||
// Make it the current window
|
||||
[m_window makeKeyAndVisible];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowImplUIKit::~WindowImplUIKit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::processEvents()
|
||||
{
|
||||
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0001, TRUE) == kCFRunLoopRunHandledSource)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WindowHandle WindowImplUIKit::getSystemHandle() const
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i WindowImplUIKit::getPosition() const
|
||||
{
|
||||
return Vector2i(m_window.frame.origin.x, m_window.frame.origin.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setPosition(const Vector2i& position)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u WindowImplUIKit::getSize() const
|
||||
{
|
||||
return Vector2u(m_window.frame.size.width, m_window.frame.size.height);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setSize(const Vector2u& size)
|
||||
{
|
||||
// @todo ...
|
||||
|
||||
// Set the orientation according to the requested size
|
||||
if (size.x > size.y)
|
||||
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
else
|
||||
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setTitle(const String& title)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setIcon(unsigned int width, unsigned int height, const Uint8* pixels)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setVisible(bool visible)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setMouseCursorVisible(bool visible)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setKeyRepeatEnabled(bool enabled)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SFView* WindowImplUIKit::getGlView() const
|
||||
{
|
||||
return m_view;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void WindowImplUIKit::setVirtualKeyboardVisible(bool visible)
|
||||
{
|
||||
if (visible)
|
||||
[m_view becomeFirstResponder];
|
||||
else
|
||||
[m_view resignFirstResponder];
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
Loading…
Add table
Add a link
Reference in a new issue