Source code changes.
* Changed newlines to \n. * Removed whitespace before colons. * Fixed several alignments.
This commit is contained in:
parent
b27cbd5036
commit
f24ca9a840
268 changed files with 40227 additions and 40227 deletions
612
CMakeLists.txt
612
CMakeLists.txt
|
@ -1,306 +1,306 @@
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
# define a macro that helps defining an option
|
# define a macro that helps defining an option
|
||||||
macro(sfml_set_option var default type docstring)
|
macro(sfml_set_option var default type docstring)
|
||||||
if(NOT DEFINED ${var})
|
if(NOT DEFINED ${var})
|
||||||
set(${var} ${default})
|
set(${var} ${default})
|
||||||
endif()
|
endif()
|
||||||
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
|
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
# set a default build type if none was provided
|
# set a default build type if none was provided
|
||||||
# this has to be done before the project() instruction!
|
# this has to be done before the project() instruction!
|
||||||
sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
|
sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
|
||||||
|
|
||||||
# project name
|
# project name
|
||||||
project(SFML)
|
project(SFML)
|
||||||
|
|
||||||
# include the configuration file
|
# include the configuration file
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake)
|
||||||
|
|
||||||
# setup version numbers
|
# setup version numbers
|
||||||
set(VERSION_MAJOR 2)
|
set(VERSION_MAJOR 2)
|
||||||
set(VERSION_MINOR 1)
|
set(VERSION_MINOR 1)
|
||||||
set(VERSION_PATCH 0)
|
set(VERSION_PATCH 0)
|
||||||
|
|
||||||
# add the SFML header path
|
# add the SFML header path
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
# add an option for choosing the build type (shared or static)
|
# add an option for choosing the build type (shared or static)
|
||||||
if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID))
|
if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID))
|
||||||
sfml_set_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries")
|
sfml_set_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries")
|
||||||
else()
|
else()
|
||||||
if(SFML_OS_IOS)
|
if(SFML_OS_IOS)
|
||||||
set(BUILD_SHARED_LIBS FALSE)
|
set(BUILD_SHARED_LIBS FALSE)
|
||||||
elseif(SFML_OS_ANDROID)
|
elseif(SFML_OS_ANDROID)
|
||||||
set(BUILD_SHARED_LIBS TRUE)
|
set(BUILD_SHARED_LIBS TRUE)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# add an option for building the examples
|
# add an option for building the examples
|
||||||
if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID))
|
if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID))
|
||||||
sfml_set_option(SFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them")
|
sfml_set_option(SFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them")
|
||||||
else()
|
else()
|
||||||
set(SFML_BUILD_EXAMPLES FALSE)
|
set(SFML_BUILD_EXAMPLES FALSE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# add an option for building the API documentation
|
# add an option for building the API documentation
|
||||||
sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
|
sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
|
||||||
|
|
||||||
# add an option for choosing the OpenGL implementation
|
# add an option for choosing the OpenGL implementation
|
||||||
sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation")
|
sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation")
|
||||||
|
|
||||||
# Mac OS X specific options
|
# Mac OS X specific options
|
||||||
if(SFML_OS_MACOSX)
|
if(SFML_OS_MACOSX)
|
||||||
# add an option to build frameworks instead of dylibs (release only)
|
# add an option to build frameworks instead of dylibs (release only)
|
||||||
sfml_set_option(SFML_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
|
sfml_set_option(SFML_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
|
||||||
|
|
||||||
# add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...)
|
# add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...)
|
||||||
sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory")
|
sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory")
|
||||||
|
|
||||||
# add an option to automatically install Xcode templates
|
# add an option to automatically install Xcode templates
|
||||||
sfml_set_option(SFML_INSTALL_XCODE_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode templates, FALSE to do nothing about it. The templates are compatible with Xcode 4 and 5.")
|
sfml_set_option(SFML_INSTALL_XCODE_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode templates, FALSE to do nothing about it. The templates are compatible with Xcode 4 and 5.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Android options
|
# Android options
|
||||||
if(SFML_OS_ANDROID)
|
if(SFML_OS_ANDROID)
|
||||||
# force usage of the STL port
|
# force usage of the STL port
|
||||||
set(ANDROID_USE_STLPORT TRUE)
|
set(ANDROID_USE_STLPORT TRUE)
|
||||||
|
|
||||||
# make sure there's the android library available
|
# make sure there's the android library available
|
||||||
if (${ANDROID_NATIVE_API_LEVEL} LESS 9)
|
if (${ANDROID_NATIVE_API_LEVEL} LESS 9)
|
||||||
message(FATAL_ERROR "API level must be equal or greater than 9")
|
message(FATAL_ERROR "API level must be equal or greater than 9")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# install everything in $NDK/sources/ because this path is appended by the NDK (convenient)
|
# install everything in $NDK/sources/ because this path is appended by the NDK (convenient)
|
||||||
set(CMAKE_INSTALL_PREFIX ${ANDROID_NDK}/sources/sfml)
|
set(CMAKE_INSTALL_PREFIX ${ANDROID_NDK}/sources/sfml)
|
||||||
|
|
||||||
# we install libs in a subdirectory named after the ABI (lib/mips/*.so)
|
# we install libs in a subdirectory named after the ABI (lib/mips/*.so)
|
||||||
set(LIB_SUFFIX "/${ANDROID_ABI}")
|
set(LIB_SUFFIX "/${ANDROID_ABI}")
|
||||||
|
|
||||||
# this is a workaround to compile sfml-activity without stlport_shared as dependency
|
# this is a workaround to compile sfml-activity without stlport_shared as dependency
|
||||||
# we save the original compilation command line to restore it later in Macro.cmake
|
# we save the original compilation command line to restore it later in Macro.cmake
|
||||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STLPORT ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STLPORT ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
|
||||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STLPORT "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STLPORT "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# define SFML_STATIC if the build type is not set to 'shared'
|
# define SFML_STATIC if the build type is not set to 'shared'
|
||||||
if(NOT BUILD_SHARED_LIBS)
|
if(NOT BUILD_SHARED_LIBS)
|
||||||
add_definitions(-DSFML_STATIC)
|
add_definitions(-DSFML_STATIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# remove SL security warnings with Visual C++
|
# remove SL security warnings with Visual C++
|
||||||
if(SFML_COMPILER_MSVC)
|
if(SFML_COMPILER_MSVC)
|
||||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# define SFML_OPENGL_ES if needed
|
# define SFML_OPENGL_ES if needed
|
||||||
if(SFML_OPENGL_ES)
|
if(SFML_OPENGL_ES)
|
||||||
add_definitions(-DSFML_OPENGL_ES)
|
add_definitions(-DSFML_OPENGL_ES)
|
||||||
add_definitions(-DGL_GLEXT_PROTOTYPES)
|
add_definitions(-DGL_GLEXT_PROTOTYPES)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# define an option for choosing between static and dynamic C runtime (Windows only)
|
# define an option for choosing between static and dynamic C runtime (Windows only)
|
||||||
if(SFML_OS_WINDOWS)
|
if(SFML_OS_WINDOWS)
|
||||||
sfml_set_option(SFML_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
|
sfml_set_option(SFML_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
|
||||||
|
|
||||||
# the following combination of flags is not valid
|
# the following combination of flags is not valid
|
||||||
if (BUILD_SHARED_LIBS AND SFML_USE_STATIC_STD_LIBS)
|
if (BUILD_SHARED_LIBS AND SFML_USE_STATIC_STD_LIBS)
|
||||||
message(FATAL_ERROR "BUILD_SHARED_LIBS and SFML_USE_STATIC_STD_LIBS cannot be used together")
|
message(FATAL_ERROR "BUILD_SHARED_LIBS and SFML_USE_STATIC_STD_LIBS cannot be used together")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# for VC++, we can apply it globally by modifying the compiler flags
|
# for VC++, we can apply it globally by modifying the compiler flags
|
||||||
if(SFML_COMPILER_MSVC AND SFML_USE_STATIC_STD_LIBS)
|
if(SFML_COMPILER_MSVC AND SFML_USE_STATIC_STD_LIBS)
|
||||||
foreach(flag
|
foreach(flag
|
||||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||||
if(${flag} MATCHES "/MD")
|
if(${flag} MATCHES "/MD")
|
||||||
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# setup Mac OS X stuff
|
# setup Mac OS X stuff
|
||||||
if(SFML_OS_MACOSX)
|
if(SFML_OS_MACOSX)
|
||||||
# SFML_BUILD_FRAMEWORKS needs two things :
|
# SFML_BUILD_FRAMEWORKS needs two things:
|
||||||
# first, it's available only for release
|
# first, it's available only for release
|
||||||
# (because cmake currently doesn't allow specifying a custom framework name so XXX-d is not possible)
|
# (because cmake currently doesn't allow specifying a custom framework name so XXX-d is not possible)
|
||||||
# secondly, it works only with BUILD_SHARED_LIBS enabled
|
# secondly, it works only with BUILD_SHARED_LIBS enabled
|
||||||
if(SFML_BUILD_FRAMEWORKS)
|
if(SFML_BUILD_FRAMEWORKS)
|
||||||
# requirement #1
|
# requirement #1
|
||||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
message(FATAL_ERROR "CMAKE_BUILD_TYPE should be \"Release\" when SFML_BUILD_FRAMEWORKS is TRUE")
|
message(FATAL_ERROR "CMAKE_BUILD_TYPE should be \"Release\" when SFML_BUILD_FRAMEWORKS is TRUE")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# requirement #2
|
# requirement #2
|
||||||
if(NOT BUILD_SHARED_LIBS)
|
if(NOT BUILD_SHARED_LIBS)
|
||||||
message(FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when SFML_BUILD_FRAMEWORKS is TRUE")
|
message(FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when SFML_BUILD_FRAMEWORKS is TRUE")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# configure Xcode templates
|
# configure Xcode templates
|
||||||
if(CMAKE_OSX_ARCHITECTURES)
|
if(CMAKE_OSX_ARCHITECTURES)
|
||||||
# maybe multiple arches are present in CMAKE_OSX_ARCHITECTURES
|
# maybe multiple arches are present in CMAKE_OSX_ARCHITECTURES
|
||||||
# we simply need to replace ';' by ' ' (space) and store the result in XCODE_TEMPLATES_ARCH
|
# we simply need to replace ';' by ' ' (space) and store the result in XCODE_TEMPLATES_ARCH
|
||||||
string(REPLACE ";" " " XCODE_TEMPLATES_ARCH "${CMAKE_OSX_ARCHITECTURES}")
|
string(REPLACE ";" " " XCODE_TEMPLATES_ARCH "${CMAKE_OSX_ARCHITECTURES}")
|
||||||
else()
|
else()
|
||||||
# no arch was provided to cmake, so we use the default one
|
# no arch was provided to cmake, so we use the default one
|
||||||
set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)")
|
set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||||
set(PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
|
set(PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
|
||||||
if(SFML_OS_FREEBSD)
|
if(SFML_OS_FREEBSD)
|
||||||
set(PKGCONFIG_DIR libdata/pkgconfig)
|
set(PKGCONFIG_DIR libdata/pkgconfig)
|
||||||
endif()
|
endif()
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
sfml_set_option(SFML_INSTALL_PKGCONFIG_FILES FALSE BOOL "TRUE to automatically install pkg-config files so other projects can find SFML")
|
sfml_set_option(SFML_INSTALL_PKGCONFIG_FILES FALSE BOOL "TRUE to automatically install pkg-config files so other projects can find SFML")
|
||||||
if(SFML_INSTALL_PKGCONFIG_FILES)
|
if(SFML_INSTALL_PKGCONFIG_FILES)
|
||||||
foreach(sfml_module IN ITEMS all system window graphics audio network)
|
foreach(sfml_module IN ITEMS all system window graphics audio network)
|
||||||
CONFIGURE_FILE(
|
CONFIGURE_FILE(
|
||||||
"tools/pkg-config/sfml-${sfml_module}.pc.in"
|
"tools/pkg-config/sfml-${sfml_module}.pc.in"
|
||||||
"tools/pkg-config/sfml-${sfml_module}.pc"
|
"tools/pkg-config/sfml-${sfml_module}.pc"
|
||||||
@ONLY)
|
@ONLY)
|
||||||
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc"
|
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc"
|
||||||
DESTINATION "${CMAKE_INSTALL_PREFIX}/${PKGCONFIG_DIR}")
|
DESTINATION "${CMAKE_INSTALL_PREFIX}/${PKGCONFIG_DIR}")
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
if(SFML_INSTALL_PKGCONFIG_FILES)
|
if(SFML_INSTALL_PKGCONFIG_FILES)
|
||||||
message(WARNING "No pkg-config files are provided for the static SFML libraries (SFML_INSTALL_PKGCONFIG_FILES will be ignored).")
|
message(WARNING "No pkg-config files are provided for the static SFML libraries (SFML_INSTALL_PKGCONFIG_FILES will be ignored).")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# enable project folders
|
# enable project folders
|
||||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
|
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
|
||||||
|
|
||||||
# add the subdirectories
|
# add the subdirectories
|
||||||
add_subdirectory(src/SFML)
|
add_subdirectory(src/SFML)
|
||||||
if(SFML_BUILD_EXAMPLES)
|
if(SFML_BUILD_EXAMPLES)
|
||||||
add_subdirectory(examples)
|
add_subdirectory(examples)
|
||||||
endif()
|
endif()
|
||||||
if(SFML_BUILD_DOC)
|
if(SFML_BUILD_DOC)
|
||||||
add_subdirectory(doc)
|
add_subdirectory(doc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# setup the install rules
|
# setup the install rules
|
||||||
if(NOT SFML_BUILD_FRAMEWORKS)
|
if(NOT SFML_BUILD_FRAMEWORKS)
|
||||||
install(DIRECTORY include
|
install(DIRECTORY include
|
||||||
DESTINATION .
|
DESTINATION .
|
||||||
COMPONENT devel
|
COMPONENT devel
|
||||||
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl")
|
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl")
|
||||||
else()
|
else()
|
||||||
# find only "root" headers
|
# find only "root" headers
|
||||||
file(GLOB SFML_HEADERS RELATIVE ${PROJECT_SOURCE_DIR} "include/SFML/*")
|
file(GLOB SFML_HEADERS RELATIVE ${PROJECT_SOURCE_DIR} "include/SFML/*")
|
||||||
|
|
||||||
# in fact we have to fool cmake to copy all the headers in subdirectories
|
# in fact we have to fool cmake to copy all the headers in subdirectories
|
||||||
# to do that we have to add the "root" headers to the PUBLIC_HEADER
|
# to do that we have to add the "root" headers to the PUBLIC_HEADER
|
||||||
# then we can run a post script to copy the remaining headers
|
# then we can run a post script to copy the remaining headers
|
||||||
|
|
||||||
# we need a dummy file in order to compile the framework
|
# we need a dummy file in order to compile the framework
|
||||||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
|
||||||
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
||||||
|
|
||||||
set(SFML_SOURCES ${SFML_HEADERS})
|
set(SFML_SOURCES ${SFML_HEADERS})
|
||||||
list(APPEND SFML_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
list(APPEND SFML_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
||||||
|
|
||||||
# create SFML.framework
|
# create SFML.framework
|
||||||
add_library(SFML ${SFML_SOURCES})
|
add_library(SFML ${SFML_SOURCES})
|
||||||
|
|
||||||
# edit target properties
|
# edit target properties
|
||||||
set_target_properties(SFML PROPERTIES
|
set_target_properties(SFML PROPERTIES
|
||||||
FRAMEWORK TRUE
|
FRAMEWORK TRUE
|
||||||
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.SFML
|
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.SFML
|
||||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
PUBLIC_HEADER "${SFML_HEADERS}")
|
PUBLIC_HEADER "${SFML_HEADERS}")
|
||||||
|
|
||||||
# add the remaining headers
|
# add the remaining headers
|
||||||
add_custom_command(TARGET SFML
|
add_custom_command(TARGET SFML
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* $<TARGET_FILE_DIR:SFML>/Headers)
|
COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* $<TARGET_FILE_DIR:SFML>/Headers)
|
||||||
|
|
||||||
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
||||||
# NOTE : it's not required to link agains SFML.framework
|
# NOTE: it's not required to link agains SFML.framework
|
||||||
set_target_properties(SFML PROPERTIES
|
set_target_properties(SFML PROPERTIES
|
||||||
BUILD_WITH_INSTALL_RPATH 1
|
BUILD_WITH_INSTALL_RPATH 1
|
||||||
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
||||||
|
|
||||||
# install rule
|
# install rule
|
||||||
install(TARGETS SFML
|
install(TARGETS SFML
|
||||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}
|
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}
|
||||||
COMPONENT devel)
|
COMPONENT devel)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR})
|
install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR})
|
||||||
install(FILES readme.txt DESTINATION ${INSTALL_MISC_DIR})
|
install(FILES readme.txt DESTINATION ${INSTALL_MISC_DIR})
|
||||||
if(NOT SFML_OS_ANDROID)
|
if(NOT SFML_OS_ANDROID)
|
||||||
install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules)
|
install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# install 3rd-party libraries and tools
|
# install 3rd-party libraries and tools
|
||||||
if(SFML_OS_WINDOWS)
|
if(SFML_OS_WINDOWS)
|
||||||
|
|
||||||
# install the binaries of SFML dependencies
|
# install the binaries of SFML dependencies
|
||||||
if(ARCH_32BITS)
|
if(ARCH_32BITS)
|
||||||
install(DIRECTORY extlibs/bin/x86/ DESTINATION bin)
|
install(DIRECTORY extlibs/bin/x86/ DESTINATION bin)
|
||||||
if(SFML_COMPILER_MSVC)
|
if(SFML_COMPILER_MSVC)
|
||||||
install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION lib)
|
install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION lib)
|
||||||
else()
|
else()
|
||||||
install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION lib)
|
install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION lib)
|
||||||
endif()
|
endif()
|
||||||
elseif(ARCH_64BITS)
|
elseif(ARCH_64BITS)
|
||||||
install(DIRECTORY extlibs/bin/x64/ DESTINATION bin)
|
install(DIRECTORY extlibs/bin/x64/ DESTINATION bin)
|
||||||
if(SFML_COMPILER_MSVC)
|
if(SFML_COMPILER_MSVC)
|
||||||
install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION lib)
|
install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION lib)
|
||||||
else()
|
else()
|
||||||
install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION lib)
|
install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION lib)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
elseif(SFML_OS_MACOSX)
|
elseif(SFML_OS_MACOSX)
|
||||||
|
|
||||||
# install the non-standard frameworks SFML depends on
|
# install the non-standard frameworks SFML depends on
|
||||||
install(DIRECTORY extlibs/libs-osx/Frameworks/sndfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
install(DIRECTORY extlibs/libs-osx/Frameworks/sndfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
||||||
install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
||||||
|
|
||||||
# install the Xcode templates if requested
|
# install the Xcode templates if requested
|
||||||
if(SFML_INSTALL_XCODE_TEMPLATES)
|
if(SFML_INSTALL_XCODE_TEMPLATES)
|
||||||
configure_file(
|
configure_file(
|
||||||
"tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist.in"
|
"tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist.in"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist"
|
"${CMAKE_CURRENT_BINARY_DIR}/tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist"
|
||||||
@ONLY)
|
@ONLY)
|
||||||
install(DIRECTORY "tools/xcode/templates/SFML" "${CMAKE_CURRENT_BINARY_DIR}/tools/xcode/templates/SFML"
|
install(DIRECTORY "tools/xcode/templates/SFML" "${CMAKE_CURRENT_BINARY_DIR}/tools/xcode/templates/SFML"
|
||||||
DESTINATION /Library/Developer/Xcode/Templates
|
DESTINATION /Library/Developer/Xcode/Templates
|
||||||
PATTERN "*.in" EXCLUDE)
|
PATTERN "*.in" EXCLUDE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
elseif(SFML_OS_IOS)
|
elseif(SFML_OS_IOS)
|
||||||
|
|
||||||
# fix CMake install rules broken for iOS (see http://public.kitware.com/Bug/view.php?id=12506)
|
# fix CMake install rules broken for iOS (see http://public.kitware.com/Bug/view.php?id=12506)
|
||||||
if(SFML_OS_IOS)
|
if(SFML_OS_IOS)
|
||||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/lib/\$ENV{CONFIGURATION}/" DESTINATION lib${LIB_SUFFIX})
|
install(DIRECTORY "${CMAKE_BINARY_DIR}/lib/\$ENV{CONFIGURATION}/" DESTINATION lib${LIB_SUFFIX})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# since the iOS libraries are built as static, we must install the SFML dependencies
|
# since the iOS libraries are built as static, we must install the SFML dependencies
|
||||||
# too so that the end user can easily link them to its final application
|
# too so that the end user can easily link them to its final application
|
||||||
install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib)
|
install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib)
|
||||||
|
|
||||||
elseif(SFML_OS_ANDROID)
|
elseif(SFML_OS_ANDROID)
|
||||||
|
|
||||||
# install extlibs
|
# install extlibs
|
||||||
install(DIRECTORY extlibs/libs-android/${ANDROID_ABI} DESTINATION extlibs/lib)
|
install(DIRECTORY extlibs/libs-android/${ANDROID_ABI} DESTINATION extlibs/lib)
|
||||||
install(FILES extlibs/Android.mk DESTINATION extlibs)
|
install(FILES extlibs/Android.mk DESTINATION extlibs)
|
||||||
|
|
||||||
# install Android.mk so the NDK knows how to set up SFML
|
# install Android.mk so the NDK knows how to set up SFML
|
||||||
install(FILES src/SFML/Android.mk DESTINATION .)
|
install(FILES src/SFML/Android.mk DESTINATION .)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,117 +1,117 @@
|
||||||
# detect the OS
|
# detect the OS
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
set(SFML_OS_WINDOWS 1)
|
set(SFML_OS_WINDOWS 1)
|
||||||
|
|
||||||
# don't use the OpenGL ES implementation on Windows
|
# don't use the OpenGL ES implementation on Windows
|
||||||
set(OPENGL_ES 0)
|
set(OPENGL_ES 0)
|
||||||
|
|
||||||
# detect the architecture (note: this test won't work for cross-compilation)
|
# detect the architecture (note: this test won't work for cross-compilation)
|
||||||
include(CheckTypeSize)
|
include(CheckTypeSize)
|
||||||
check_type_size(void* SIZEOF_VOID_PTR)
|
check_type_size(void* SIZEOF_VOID_PTR)
|
||||||
if("${SIZEOF_VOID_PTR}" STREQUAL "4")
|
if("${SIZEOF_VOID_PTR}" STREQUAL "4")
|
||||||
set(ARCH_32BITS 1)
|
set(ARCH_32BITS 1)
|
||||||
elseif("${SIZEOF_VOID_PTR}" STREQUAL "8")
|
elseif("${SIZEOF_VOID_PTR}" STREQUAL "8")
|
||||||
set(ARCH_64BITS 1)
|
set(ARCH_64BITS 1)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Unsupported architecture")
|
message(FATAL_ERROR "Unsupported architecture")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
set(SFML_OS_UNIX 1)
|
set(SFML_OS_UNIX 1)
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
set(SFML_OS_ANDROID 1)
|
set(SFML_OS_ANDROID 1)
|
||||||
# use the OpenGL ES implementation on Android
|
# use the OpenGL ES implementation on Android
|
||||||
set(OPENGL_ES 1)
|
set(OPENGL_ES 1)
|
||||||
else()
|
else()
|
||||||
set(SFML_OS_LINUX 1)
|
set(SFML_OS_LINUX 1)
|
||||||
# don't use the OpenGL ES implementation on Linux
|
# don't use the OpenGL ES implementation on Linux
|
||||||
set(OPENGL_ES 0)
|
set(OPENGL_ES 0)
|
||||||
endif()
|
endif()
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||||
set(SFML_OS_FREEBSD 1)
|
set(SFML_OS_FREEBSD 1)
|
||||||
# don't use the OpenGL ES implementation on FreeBSD
|
# don't use the OpenGL ES implementation on FreeBSD
|
||||||
set(OPENGL_ES 0)
|
set(OPENGL_ES 0)
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
if(IOS)
|
if(IOS)
|
||||||
set(SFML_OS_IOS 1)
|
set(SFML_OS_IOS 1)
|
||||||
|
|
||||||
# set the target framework and platforms
|
|
||||||
set(CMAKE_OSX_SYSROOT "iphoneos")
|
|
||||||
set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386")
|
|
||||||
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
|
|
||||||
|
|
||||||
# help the compiler detection script below
|
# set the target framework and platforms
|
||||||
set(CMAKE_COMPILER_IS_GNUCXX 1)
|
set(CMAKE_OSX_SYSROOT "iphoneos")
|
||||||
|
set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386")
|
||||||
# use the OpenGL ES implementation on iOS
|
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
|
||||||
set(OPENGL_ES 1)
|
|
||||||
else()
|
# help the compiler detection script below
|
||||||
set(SFML_OS_MACOSX 1)
|
set(CMAKE_COMPILER_IS_GNUCXX 1)
|
||||||
|
|
||||||
# don't use the OpenGL ES implementation on Mac OS X
|
# use the OpenGL ES implementation on iOS
|
||||||
set(OPENGL_ES 0)
|
set(OPENGL_ES 1)
|
||||||
|
else()
|
||||||
# detect OS X version. (use '/usr/bin/sw_vers -productVersion' to extract V from '10.V.x'.)
|
set(SFML_OS_MACOSX 1)
|
||||||
EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
|
|
||||||
|
# don't use the OpenGL ES implementation on Mac OS X
|
||||||
|
set(OPENGL_ES 0)
|
||||||
|
|
||||||
|
# detect OS X version. (use '/usr/bin/sw_vers -productVersion' to extract V from '10.V.x'.)
|
||||||
|
EXEC_PROGRAM(/usr/bin/sw_vers ARGS -productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
|
||||||
STRING(REGEX REPLACE "10\\.([0-9]+).*" "\\1" MACOSX_VERSION "${MACOSX_VERSION_RAW}")
|
STRING(REGEX REPLACE "10\\.([0-9]+).*" "\\1" MACOSX_VERSION "${MACOSX_VERSION_RAW}")
|
||||||
if(${MACOSX_VERSION} LESS 7)
|
if(${MACOSX_VERSION} LESS 7)
|
||||||
message(FATAL_ERROR "Unsupported version of OS X: ${MACOSX_VERSION_RAW}")
|
message(FATAL_ERROR "Unsupported version of OS X: ${MACOSX_VERSION_RAW}")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||||
set(SFML_OS_ANDROID 1)
|
set(SFML_OS_ANDROID 1)
|
||||||
|
|
||||||
# use the OpenGL ES implementation on Android
|
|
||||||
set(OPENGL_ES 1)
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Unsupported operating system")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# detect the compiler and its version
|
|
||||||
# Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true
|
|
||||||
# even when CLANG is used, therefore the Clang test is done first
|
|
||||||
if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
||||||
# CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change,
|
|
||||||
# but there is no other way to detect CLang at the moment
|
|
||||||
set(SFML_COMPILER_CLANG 1)
|
|
||||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
|
|
||||||
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" SFML_CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
|
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
set(SFML_COMPILER_GCC 1)
|
|
||||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
|
|
||||||
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" SFML_GCC_VERSION "${GCC_VERSION_OUTPUT}")
|
|
||||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE GCC_COMPILER_VERSION)
|
|
||||||
string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" SFML_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}")
|
|
||||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE)
|
|
||||||
string(STRIP "${GCC_MACHINE}" GCC_MACHINE)
|
|
||||||
if(${GCC_MACHINE} MATCHES ".*w64.*")
|
|
||||||
set(SFML_COMPILER_GCC_W64 1)
|
|
||||||
endif()
|
|
||||||
elseif(MSVC)
|
|
||||||
set(SFML_COMPILER_MSVC 1)
|
|
||||||
if(MSVC_VERSION EQUAL 1400)
|
|
||||||
set(SFML_MSVC_VERSION 8)
|
|
||||||
elseif(MSVC_VERSION EQUAL 1500)
|
|
||||||
set(SFML_MSVC_VERSION 9)
|
|
||||||
elseif(MSVC_VERSION EQUAL 1600)
|
|
||||||
set(SFML_MSVC_VERSION 10)
|
|
||||||
elseif(MSVC_VERSION EQUAL 1700)
|
|
||||||
set(SFML_MSVC_VERSION 11)
|
|
||||||
elseif(MSVC_VERSION EQUAL 1800)
|
|
||||||
set(SFML_MSVC_VERSION 12)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Unsupported compiler")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# define the install directory for miscellaneous files
|
# use the OpenGL ES implementation on Android
|
||||||
|
set(OPENGL_ES 1)
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unsupported operating system")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# detect the compiler and its version
|
||||||
|
# Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true
|
||||||
|
# even when CLANG is used, therefore the Clang test is done first
|
||||||
|
if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
|
# CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change,
|
||||||
|
# but there is no other way to detect CLang at the moment
|
||||||
|
set(SFML_COMPILER_CLANG 1)
|
||||||
|
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE CLANG_VERSION_OUTPUT)
|
||||||
|
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" SFML_CLANG_VERSION "${CLANG_VERSION_OUTPUT}")
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
set(SFML_COMPILER_GCC 1)
|
||||||
|
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
|
||||||
|
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" SFML_GCC_VERSION "${GCC_VERSION_OUTPUT}")
|
||||||
|
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE GCC_COMPILER_VERSION)
|
||||||
|
string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" SFML_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}")
|
||||||
|
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpmachine" OUTPUT_VARIABLE GCC_MACHINE)
|
||||||
|
string(STRIP "${GCC_MACHINE}" GCC_MACHINE)
|
||||||
|
if(${GCC_MACHINE} MATCHES ".*w64.*")
|
||||||
|
set(SFML_COMPILER_GCC_W64 1)
|
||||||
|
endif()
|
||||||
|
elseif(MSVC)
|
||||||
|
set(SFML_COMPILER_MSVC 1)
|
||||||
|
if(MSVC_VERSION EQUAL 1400)
|
||||||
|
set(SFML_MSVC_VERSION 8)
|
||||||
|
elseif(MSVC_VERSION EQUAL 1500)
|
||||||
|
set(SFML_MSVC_VERSION 9)
|
||||||
|
elseif(MSVC_VERSION EQUAL 1600)
|
||||||
|
set(SFML_MSVC_VERSION 10)
|
||||||
|
elseif(MSVC_VERSION EQUAL 1700)
|
||||||
|
set(SFML_MSVC_VERSION 11)
|
||||||
|
elseif(MSVC_VERSION EQUAL 1800)
|
||||||
|
set(SFML_MSVC_VERSION 12)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unsupported compiler")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# define the install directory for miscellaneous files
|
||||||
if(SFML_OS_WINDOWS OR SFML_OS_IOS)
|
if(SFML_OS_WINDOWS OR SFML_OS_IOS)
|
||||||
set(INSTALL_MISC_DIR .)
|
set(INSTALL_MISC_DIR .)
|
||||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
|
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
|
||||||
set(INSTALL_MISC_DIR share/SFML)
|
set(INSTALL_MISC_DIR share/SFML)
|
||||||
elseif(SFML_OS_ANDROID)
|
elseif(SFML_OS_ANDROID)
|
||||||
set(INSTALL_MISC_DIR ${ANDROID_NDK}/sources/sfml)
|
set(INSTALL_MISC_DIR ${ANDROID_NDK}/sources/sfml)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,178 +1,178 @@
|
||||||
include(CMakeParseArguments)
|
include(CMakeParseArguments)
|
||||||
|
|
||||||
# add a new target which is a SFML library
|
# add a new target which is a SFML library
|
||||||
# ex: sfml_add_library(sfml-graphics
|
# ex: sfml_add_library(sfml-graphics
|
||||||
# SOURCES sprite.cpp image.cpp ...
|
# SOURCES sprite.cpp image.cpp ...
|
||||||
# DEPENDS sfml-window sfml-system
|
# DEPENDS sfml-window sfml-system
|
||||||
# EXTERNAL_LIBS opengl freetype ...)
|
# EXTERNAL_LIBS opengl freetype ...)
|
||||||
macro(sfml_add_library target)
|
macro(sfml_add_library target)
|
||||||
|
|
||||||
# parse the arguments
|
# parse the arguments
|
||||||
cmake_parse_arguments(THIS "" "" "SOURCES;DEPENDS;EXTERNAL_LIBS" ${ARGN})
|
cmake_parse_arguments(THIS "" "" "SOURCES;DEPENDS;EXTERNAL_LIBS" ${ARGN})
|
||||||
|
|
||||||
|
# create the target
|
||||||
|
add_library(${target} ${THIS_SOURCES})
|
||||||
|
|
||||||
|
# define the export symbol of the module
|
||||||
|
string(REPLACE "-" "_" NAME_UPPER "${target}")
|
||||||
|
string(TOUPPER "${NAME_UPPER}" NAME_UPPER)
|
||||||
|
set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS)
|
||||||
|
|
||||||
|
# adjust the output file prefix/suffix to match our conventions
|
||||||
|
if(BUILD_SHARED_LIBS)
|
||||||
|
if(SFML_OS_WINDOWS)
|
||||||
|
# include the major version number in Windows shared library names (but not import library names)
|
||||||
|
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||||
|
set_target_properties(${target} PROPERTIES SUFFIX "-${VERSION_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||||
|
else()
|
||||||
|
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||||
|
endif()
|
||||||
|
if (SFML_OS_WINDOWS AND SFML_COMPILER_GCC)
|
||||||
|
# on Windows/gcc get rid of "lib" prefix for shared libraries,
|
||||||
|
# and transform the ".dll.a" suffix into ".a" for import libraries
|
||||||
|
set_target_properties(${target} PROPERTIES PREFIX "")
|
||||||
|
set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".a")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -s-d)
|
||||||
|
set_target_properties(${target} PROPERTIES RELEASE_POSTFIX -s)
|
||||||
|
set_target_properties(${target} PROPERTIES MINSIZEREL_POSTFIX -s)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# set the version and soversion of the target (for compatible systems -- mostly Linuxes)
|
||||||
|
# except for Android which strips soversion suffixes
|
||||||
|
if(NOT SFML_OS_ANDROID)
|
||||||
|
set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR})
|
||||||
|
set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||||
|
set_target_properties(${target} PROPERTIES FOLDER "SFML")
|
||||||
|
|
||||||
|
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
||||||
|
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
|
||||||
|
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
|
||||||
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
||||||
|
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
|
||||||
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# if using gcc >= 4.0 or clang >= 3.0 on a non-Windows platform, we must hide public symbols by default
|
||||||
|
# (exported ones are explicitely marked)
|
||||||
|
if(NOT SFML_OS_WINDOWS AND ((SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4") OR (SFML_COMPILER_CLANG AND NOT SFML_CLANG_VERSION VERSION_LESS "3")))
|
||||||
|
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# link the target to its SFML dependencies
|
||||||
|
if(THIS_DEPENDS)
|
||||||
|
target_link_libraries(${target} ${THIS_DEPENDS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# build frameworks or dylibs
|
||||||
|
if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS)
|
||||||
|
if(SFML_BUILD_FRAMEWORKS)
|
||||||
|
# adapt target to build frameworks instead of dylibs
|
||||||
|
set_target_properties(${target} PROPERTIES
|
||||||
|
FRAMEWORK TRUE
|
||||||
|
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
|
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.${target}
|
||||||
|
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
|
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
||||||
|
set_target_properties(${target} PROPERTIES
|
||||||
|
BUILD_WITH_INSTALL_RPATH 1
|
||||||
|
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# enable automatic reference counting on iOS
|
||||||
|
if (SFML_OS_IOS)
|
||||||
|
set_target_properties(${target} PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# sfml-activity library is our bootstrap activity and must not depend on stlport_shared
|
||||||
|
# (otherwise Android will fail to load it)
|
||||||
|
if (SFML_OS_ANDROID)
|
||||||
|
if (${target} MATCHES "sfml-activity")
|
||||||
|
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fpermissive)
|
||||||
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-landroid -llog")
|
||||||
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STLPORT})
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STLPORT})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# link the target to its external dependencies
|
||||||
|
if(THIS_EXTERNAL_LIBS)
|
||||||
|
target_link_libraries(${target} ${THIS_EXTERNAL_LIBS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# add the install rule
|
||||||
|
install(TARGETS ${target}
|
||||||
|
RUNTIME DESTINATION bin COMPONENT bin
|
||||||
|
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
|
||||||
|
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
|
||||||
|
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# add a new target which is a SFML example
|
||||||
|
# ex: sfml_add_example(ftp
|
||||||
|
# SOURCES ftp.cpp ...
|
||||||
|
# DEPENDS sfml-network sfml-system)
|
||||||
|
macro(sfml_add_example target)
|
||||||
|
|
||||||
|
# parse the arguments
|
||||||
|
cmake_parse_arguments(THIS "GUI_APP" "" "SOURCES;DEPENDS" ${ARGN})
|
||||||
|
|
||||||
|
# set a source group for the source files
|
||||||
|
source_group("" FILES ${THIS_SOURCES})
|
||||||
|
|
||||||
# create the target
|
|
||||||
add_library(${target} ${THIS_SOURCES})
|
|
||||||
|
|
||||||
# define the export symbol of the module
|
|
||||||
string(REPLACE "-" "_" NAME_UPPER "${target}")
|
|
||||||
string(TOUPPER "${NAME_UPPER}" NAME_UPPER)
|
|
||||||
set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS)
|
|
||||||
|
|
||||||
# adjust the output file prefix/suffix to match our conventions
|
|
||||||
if(BUILD_SHARED_LIBS)
|
|
||||||
if(SFML_OS_WINDOWS)
|
|
||||||
# include the major version number in Windows shared library names (but not import library names)
|
|
||||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
|
||||||
set_target_properties(${target} PROPERTIES SUFFIX "-${VERSION_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
|
||||||
else()
|
|
||||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
|
||||||
endif()
|
|
||||||
if (SFML_OS_WINDOWS AND SFML_COMPILER_GCC)
|
|
||||||
# on Windows/gcc get rid of "lib" prefix for shared libraries,
|
|
||||||
# and transform the ".dll.a" suffix into ".a" for import libraries
|
|
||||||
set_target_properties(${target} PROPERTIES PREFIX "")
|
|
||||||
set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".a")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -s-d)
|
|
||||||
set_target_properties(${target} PROPERTIES RELEASE_POSTFIX -s)
|
|
||||||
set_target_properties(${target} PROPERTIES MINSIZEREL_POSTFIX -s)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# set the version and soversion of the target (for compatible systems -- mostly Linuxes)
|
|
||||||
# except for Android which strips soversion suffixes
|
|
||||||
if(NOT SFML_OS_ANDROID)
|
|
||||||
set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR})
|
|
||||||
set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
|
||||||
set_target_properties(${target} PROPERTIES FOLDER "SFML")
|
|
||||||
|
|
||||||
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
|
||||||
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
|
|
||||||
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
|
|
||||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
|
||||||
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
|
|
||||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# if using gcc >= 4.0 or clang >= 3.0 on a non-Windows platform, we must hide public symbols by default
|
|
||||||
# (exported ones are explicitely marked)
|
|
||||||
if(NOT SFML_OS_WINDOWS AND ((SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4") OR (SFML_COMPILER_CLANG AND NOT SFML_CLANG_VERSION VERSION_LESS "3")))
|
|
||||||
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# link the target to its SFML dependencies
|
|
||||||
if(THIS_DEPENDS)
|
|
||||||
target_link_libraries(${target} ${THIS_DEPENDS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# build frameworks or dylibs
|
|
||||||
if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS)
|
|
||||||
if(SFML_BUILD_FRAMEWORKS)
|
|
||||||
# adapt target to build frameworks instead of dylibs
|
|
||||||
set_target_properties(${target} PROPERTIES
|
|
||||||
FRAMEWORK TRUE
|
|
||||||
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
|
||||||
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.${target}
|
|
||||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
|
||||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
|
||||||
set_target_properties(${target} PROPERTIES
|
|
||||||
BUILD_WITH_INSTALL_RPATH 1
|
|
||||||
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# enable automatic reference counting on iOS
|
|
||||||
if (SFML_OS_IOS)
|
|
||||||
set_target_properties(${target} PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# sfml-activity library is our bootstrap activity and must not depend on stlport_shared
|
|
||||||
# (otherwise Android will fail to load it)
|
|
||||||
if (SFML_OS_ANDROID)
|
|
||||||
if (${target} MATCHES "sfml-activity")
|
|
||||||
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fpermissive)
|
|
||||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-landroid -llog")
|
|
||||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STLPORT})
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STLPORT})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# link the target to its external dependencies
|
|
||||||
if(THIS_EXTERNAL_LIBS)
|
|
||||||
target_link_libraries(${target} ${THIS_EXTERNAL_LIBS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# add the install rule
|
|
||||||
install(TARGETS ${target}
|
|
||||||
RUNTIME DESTINATION bin COMPONENT bin
|
|
||||||
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
|
|
||||||
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
|
|
||||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin)
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
# add a new target which is a SFML example
|
|
||||||
# ex: sfml_add_example(ftp
|
|
||||||
# SOURCES ftp.cpp ...
|
|
||||||
# DEPENDS sfml-network sfml-system)
|
|
||||||
macro(sfml_add_example target)
|
|
||||||
|
|
||||||
# parse the arguments
|
|
||||||
cmake_parse_arguments(THIS "GUI_APP" "" "SOURCES;DEPENDS" ${ARGN})
|
|
||||||
|
|
||||||
# set a source group for the source files
|
|
||||||
source_group("" FILES ${THIS_SOURCES})
|
|
||||||
|
|
||||||
# create the target
|
# create the target
|
||||||
if(THIS_GUI_APP AND SFML_OS_WINDOWS)
|
if(THIS_GUI_APP AND SFML_OS_WINDOWS)
|
||||||
add_executable(${target} WIN32 ${THIS_SOURCES})
|
add_executable(${target} WIN32 ${THIS_SOURCES})
|
||||||
target_link_libraries(${target} sfml-main)
|
target_link_libraries(${target} sfml-main)
|
||||||
else()
|
else()
|
||||||
add_executable(${target} ${THIS_SOURCES})
|
add_executable(${target} ${THIS_SOURCES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# set the debug suffix
|
# set the debug suffix
|
||||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||||
|
|
||||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||||
set_target_properties(${target} PROPERTIES FOLDER "Examples")
|
set_target_properties(${target} PROPERTIES FOLDER "Examples")
|
||||||
|
|
||||||
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
||||||
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
|
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
|
||||||
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
|
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
|
||||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
||||||
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
|
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
|
||||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# link the target to its SFML dependencies
|
# link the target to its SFML dependencies
|
||||||
if(THIS_DEPENDS)
|
if(THIS_DEPENDS)
|
||||||
target_link_libraries(${target} ${THIS_DEPENDS})
|
target_link_libraries(${target} ${THIS_DEPENDS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# add the install rule
|
# add the install rule
|
||||||
install(TARGETS ${target}
|
install(TARGETS ${target}
|
||||||
RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples
|
RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples
|
||||||
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples)
|
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples)
|
||||||
|
|
||||||
# install the example's source code
|
# install the example's source code
|
||||||
install(FILES ${THIS_SOURCES}
|
install(FILES ${THIS_SOURCES}
|
||||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||||
COMPONENT examples)
|
COMPONENT examples)
|
||||||
|
|
||||||
# install the example's resources as well
|
# install the example's resources as well
|
||||||
set(EXAMPLE_RESOURCES "${CMAKE_SOURCE_DIR}/examples/${target}/resources")
|
set(EXAMPLE_RESOURCES "${CMAKE_SOURCE_DIR}/examples/${target}/resources")
|
||||||
if(EXISTS ${EXAMPLE_RESOURCES})
|
if(EXISTS ${EXAMPLE_RESOURCES})
|
||||||
install(DIRECTORY ${EXAMPLE_RESOURCES}
|
install(DIRECTORY ${EXAMPLE_RESOURCES}
|
||||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||||
COMPONENT examples)
|
COMPONENT examples)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#
|
#
|
||||||
# Try to find EGL library and include path.
|
# Try to find EGL library and include path.
|
||||||
# Once done this will define
|
# Once done this will define
|
||||||
#
|
#
|
||||||
# EGL_FOUND
|
# EGL_FOUND
|
||||||
# EGL_INCLUDE_PATH
|
# EGL_INCLUDE_PATH
|
||||||
# EGL_LIBRARY
|
# EGL_LIBRARY
|
||||||
#
|
#
|
||||||
|
|
||||||
find_path(EGL_INCLUDE_DIR EGL/egl.h)
|
find_path(EGL_INCLUDE_DIR EGL/egl.h)
|
||||||
find_library(EGL_LIBRARY NAMES EGL)
|
find_library(EGL_LIBRARY NAMES EGL)
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR)
|
find_package_handle_standard_args(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR)
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#
|
#
|
||||||
# Try to find GLES library and include path.
|
# Try to find GLES library and include path.
|
||||||
# Once done this will define
|
# Once done this will define
|
||||||
#
|
#
|
||||||
# GLES_FOUND
|
# GLES_FOUND
|
||||||
# GLES_INCLUDE_PATH
|
# GLES_INCLUDE_PATH
|
||||||
# GLES_LIBRARY
|
# GLES_LIBRARY
|
||||||
#
|
#
|
||||||
|
|
||||||
find_path(GLES_INCLUDE_DIR GLES/gl.h)
|
find_path(GLES_INCLUDE_DIR GLES/gl.h)
|
||||||
find_library(GLES_LIBRARY NAMES GLESv1_CM)
|
find_library(GLES_LIBRARY NAMES GLESv1_CM)
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(GLES DEFAULT_MSG GLES_LIBRARY GLES_INCLUDE_DIR)
|
find_package_handle_standard_args(GLES DEFAULT_MSG GLES_LIBRARY GLES_INCLUDE_DIR)
|
||||||
|
|
|
@ -1,65 +1,65 @@
|
||||||
#
|
#
|
||||||
# Try to find GLEW library and include path.
|
# Try to find GLEW library and include path.
|
||||||
# Once done this will define
|
# Once done this will define
|
||||||
#
|
#
|
||||||
# GLEW_FOUND
|
# GLEW_FOUND
|
||||||
# GLEW_INCLUDE_PATH
|
# GLEW_INCLUDE_PATH
|
||||||
# GLEW_LIBRARY
|
# GLEW_LIBRARY
|
||||||
#
|
#
|
||||||
|
|
||||||
IF (WIN32)
|
IF (WIN32)
|
||||||
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
||||||
$ENV{PROGRAMFILES}/GLEW/include
|
$ENV{PROGRAMFILES}/GLEW/include
|
||||||
${GLEW_ROOT_DIR}/include
|
${GLEW_ROOT_DIR}/include
|
||||||
DOC "The directory where GL/glew.h resides")
|
DOC "The directory where GL/glew.h resides")
|
||||||
|
|
||||||
IF (NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
IF (NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||||
FIND_LIBRARY( GLEW_LIBRARY
|
FIND_LIBRARY( GLEW_LIBRARY
|
||||||
NAMES glew64 glew64s
|
NAMES glew64 glew64s
|
||||||
PATHS
|
PATHS
|
||||||
$ENV{PROGRAMFILES}/GLEW/lib
|
$ENV{PROGRAMFILES}/GLEW/lib
|
||||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
||||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
||||||
DOC "The GLEW library (64-bit)"
|
DOC "The GLEW library (64-bit)"
|
||||||
)
|
)
|
||||||
ELSE(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
ELSE(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||||
FIND_LIBRARY( GLEW_LIBRARY
|
FIND_LIBRARY( GLEW_LIBRARY
|
||||||
NAMES glew GLEW glew32 glew32s
|
NAMES glew GLEW glew32 glew32s
|
||||||
PATHS
|
PATHS
|
||||||
$ENV{PROGRAMFILES}/GLEW/lib
|
$ENV{PROGRAMFILES}/GLEW/lib
|
||||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
||||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
||||||
DOC "The GLEW library"
|
DOC "The GLEW library"
|
||||||
)
|
)
|
||||||
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||||
ELSE (WIN32)
|
ELSE (WIN32)
|
||||||
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
||||||
/usr/include
|
/usr/include
|
||||||
/usr/local/include
|
/usr/local/include
|
||||||
/sw/include
|
/sw/include
|
||||||
/opt/local/include
|
/opt/local/include
|
||||||
${GLEW_ROOT_DIR}/include
|
${GLEW_ROOT_DIR}/include
|
||||||
DOC "The directory where GL/glew.h resides")
|
DOC "The directory where GL/glew.h resides")
|
||||||
|
|
||||||
FIND_LIBRARY( GLEW_LIBRARY
|
FIND_LIBRARY( GLEW_LIBRARY
|
||||||
NAMES GLEW glew
|
NAMES GLEW glew
|
||||||
PATHS
|
PATHS
|
||||||
/usr/lib64
|
/usr/lib64
|
||||||
/usr/lib
|
/usr/lib
|
||||||
/usr/local/lib64
|
/usr/local/lib64
|
||||||
/usr/local/lib
|
/usr/local/lib
|
||||||
/sw/lib
|
/sw/lib
|
||||||
/opt/local/lib
|
/opt/local/lib
|
||||||
${GLEW_ROOT_DIR}/lib
|
${GLEW_ROOT_DIR}/lib
|
||||||
DOC "The GLEW library")
|
DOC "The GLEW library")
|
||||||
ENDIF (WIN32)
|
ENDIF (WIN32)
|
||||||
|
|
||||||
SET(GLEW_FOUND "NO")
|
SET(GLEW_FOUND "NO")
|
||||||
IF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
IF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
||||||
SET(GLEW_LIBRARIES ${GLEW_LIBRARY})
|
SET(GLEW_LIBRARIES ${GLEW_LIBRARY})
|
||||||
SET(GLEW_FOUND "YES")
|
SET(GLEW_FOUND "YES")
|
||||||
ENDIF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
ENDIF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
||||||
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_PATH)
|
find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_PATH)
|
||||||
|
|
|
@ -1,354 +1,354 @@
|
||||||
# This script locates the SFML library
|
# This script locates the SFML library
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
#
|
#
|
||||||
# Usage
|
# Usage
|
||||||
# -----
|
# -----
|
||||||
#
|
#
|
||||||
# When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main).
|
# When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main).
|
||||||
# If none is given, the SFML_LIBRARIES variable will be empty and you'll end up linking to nothing.
|
# If none is given, the SFML_LIBRARIES variable will be empty and you'll end up linking to nothing.
|
||||||
# example:
|
# example:
|
||||||
# find_package(SFML COMPONENTS graphics window system) // find the graphics, window and system modules
|
# find_package(SFML COMPONENTS graphics window system) // find the graphics, window and system modules
|
||||||
#
|
#
|
||||||
# You can enforce a specific version, either MAJOR.MINOR or only MAJOR.
|
# You can enforce a specific version, either MAJOR.MINOR or only MAJOR.
|
||||||
# If nothing is specified, the version won't be checked (ie. any version will be accepted).
|
# If nothing is specified, the version won't be checked (ie. any version will be accepted).
|
||||||
# example:
|
# example:
|
||||||
# find_package(SFML COMPONENTS ...) // no specific version required
|
# find_package(SFML COMPONENTS ...) // no specific version required
|
||||||
# find_package(SFML 2 COMPONENTS ...) // any 2.x version
|
# find_package(SFML 2 COMPONENTS ...) // any 2.x version
|
||||||
# find_package(SFML 2.4 COMPONENTS ...) // version 2.4 or greater
|
# find_package(SFML 2.4 COMPONENTS ...) // version 2.4 or greater
|
||||||
#
|
#
|
||||||
# By default, the dynamic libraries of SFML will be found. To find the static ones instead,
|
# By default, the dynamic libraries of SFML will be found. To find the static ones instead,
|
||||||
# you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...).
|
# you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...).
|
||||||
# Since you have to link yourself all the SFML dependencies when you link it statically, the following
|
# Since you have to link yourself all the SFML dependencies when you link it statically, the following
|
||||||
# additional variables are defined: SFML_XXX_DEPENDENCIES and SFML_DEPENDENCIES (see their detailed
|
# additional variables are defined: SFML_XXX_DEPENDENCIES and SFML_DEPENDENCIES (see their detailed
|
||||||
# description below).
|
# description below).
|
||||||
# In case of static linking, the SFML_STATIC macro will also be defined by this script.
|
# In case of static linking, the SFML_STATIC macro will also be defined by this script.
|
||||||
# example:
|
# example:
|
||||||
# set(SFML_STATIC_LIBRARIES TRUE)
|
# set(SFML_STATIC_LIBRARIES TRUE)
|
||||||
# find_package(SFML 2 COMPONENTS network system)
|
# find_package(SFML 2 COMPONENTS network system)
|
||||||
#
|
#
|
||||||
# On Mac OS X if SFML_STATIC_LIBRARIES is not set to TRUE then by default CMake will search for frameworks unless
|
# On Mac OS X if SFML_STATIC_LIBRARIES is not set to TRUE then by default CMake will search for frameworks unless
|
||||||
# CMAKE_FIND_FRAMEWORK is set to "NEVER" for example. Please refer to CMake documentation for more details.
|
# CMAKE_FIND_FRAMEWORK is set to "NEVER" for example. Please refer to CMake documentation for more details.
|
||||||
# Moreover, keep in mind that SFML frameworks are only available as release libraries unlike dylibs which
|
# Moreover, keep in mind that SFML frameworks are only available as release libraries unlike dylibs which
|
||||||
# are available for both release and debug modes.
|
# are available for both release and debug modes.
|
||||||
#
|
#
|
||||||
# If SFML is not installed in a standard path, you can use the SFML_ROOT CMake (or environment) variable
|
# If SFML is not installed in a standard path, you can use the SFML_ROOT CMake (or environment) variable
|
||||||
# to tell CMake where SFML is.
|
# to tell CMake where SFML is.
|
||||||
#
|
#
|
||||||
# Output
|
# Output
|
||||||
# ------
|
# ------
|
||||||
#
|
#
|
||||||
# This script defines the following variables:
|
# This script defines the following variables:
|
||||||
# - For each specified module XXX (system, window, graphics, network, audio, main):
|
# - For each specified module XXX (system, window, graphics, network, audio, main):
|
||||||
# - SFML_XXX_LIBRARY_DEBUG: the name of the debug library of the xxx module (set to SFML_XXX_LIBRARY_RELEASE is no debug version is found)
|
# - SFML_XXX_LIBRARY_DEBUG: the name of the debug library of the xxx module (set to SFML_XXX_LIBRARY_RELEASE is no debug version is found)
|
||||||
# - SFML_XXX_LIBRARY_RELEASE: the name of the release library of the xxx module (set to SFML_XXX_LIBRARY_DEBUG is no release version is found)
|
# - SFML_XXX_LIBRARY_RELEASE: the name of the release library of the xxx module (set to SFML_XXX_LIBRARY_DEBUG is no release version is found)
|
||||||
# - SFML_XXX_LIBRARY: the name of the library to link to for the xxx module (includes both debug and optimized names if necessary)
|
# - SFML_XXX_LIBRARY: the name of the library to link to for the xxx module (includes both debug and optimized names if necessary)
|
||||||
# - SFML_XXX_FOUND: true if either the debug or release library of the xxx module is found
|
# - SFML_XXX_FOUND: true if either the debug or release library of the xxx module is found
|
||||||
# - SFML_XXX_DEPENDENCIES: the list of libraries the module depends on, in case of static linking
|
# - SFML_XXX_DEPENDENCIES: the list of libraries the module depends on, in case of static linking
|
||||||
# - SFML_LIBRARIES: the list of all libraries corresponding to the required modules
|
# - SFML_LIBRARIES: the list of all libraries corresponding to the required modules
|
||||||
# - SFML_FOUND: true if all the required modules are found
|
# - SFML_FOUND: true if all the required modules are found
|
||||||
# - SFML_INCLUDE_DIR: the path where SFML headers are located (the directory containing the SFML/Config.hpp file)
|
# - SFML_INCLUDE_DIR: the path where SFML headers are located (the directory containing the SFML/Config.hpp file)
|
||||||
# - SFML_DEPENDENCIES: the list of libraries SFML depends on, in case of static linking
|
# - SFML_DEPENDENCIES: the list of libraries SFML depends on, in case of static linking
|
||||||
#
|
#
|
||||||
# example:
|
# example:
|
||||||
# find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED)
|
# find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED)
|
||||||
# include_directories(${SFML_INCLUDE_DIR})
|
# include_directories(${SFML_INCLUDE_DIR})
|
||||||
# add_executable(myapp ...)
|
# add_executable(myapp ...)
|
||||||
# target_link_libraries(myapp ${SFML_LIBRARIES})
|
# target_link_libraries(myapp ${SFML_LIBRARIES})
|
||||||
|
|
||||||
# define the SFML_STATIC macro if static build was chosen
|
# define the SFML_STATIC macro if static build was chosen
|
||||||
if(SFML_STATIC_LIBRARIES)
|
if(SFML_STATIC_LIBRARIES)
|
||||||
add_definitions(-DSFML_STATIC)
|
add_definitions(-DSFML_STATIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# define the list of search paths for headers and libraries
|
# define the list of search paths for headers and libraries
|
||||||
set(FIND_SFML_PATHS
|
set(FIND_SFML_PATHS
|
||||||
${SFML_ROOT}
|
${SFML_ROOT}
|
||||||
$ENV{SFML_ROOT}
|
$ENV{SFML_ROOT}
|
||||||
~/Library/Frameworks
|
~/Library/Frameworks
|
||||||
/Library/Frameworks
|
/Library/Frameworks
|
||||||
/usr/local
|
/usr/local
|
||||||
/usr
|
/usr
|
||||||
/sw
|
/sw
|
||||||
/opt/local
|
/opt/local
|
||||||
/opt/csw
|
/opt/csw
|
||||||
/opt)
|
/opt)
|
||||||
|
|
||||||
# find the SFML include directory
|
# find the SFML include directory
|
||||||
find_path(SFML_INCLUDE_DIR SFML/Config.hpp
|
find_path(SFML_INCLUDE_DIR SFML/Config.hpp
|
||||||
PATH_SUFFIXES include
|
PATH_SUFFIXES include
|
||||||
PATHS ${FIND_SFML_PATHS})
|
PATHS ${FIND_SFML_PATHS})
|
||||||
|
|
||||||
# check the version number
|
# check the version number
|
||||||
set(SFML_VERSION_OK TRUE)
|
set(SFML_VERSION_OK TRUE)
|
||||||
if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR)
|
if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR)
|
||||||
# extract the major and minor version numbers from SFML/Config.hpp
|
# extract the major and minor version numbers from SFML/Config.hpp
|
||||||
# we have to handle framework a little bit differently :
|
# we have to handle framework a little bit differently:
|
||||||
if("${SFML_INCLUDE_DIR}" MATCHES "SFML.framework")
|
if("${SFML_INCLUDE_DIR}" MATCHES "SFML.framework")
|
||||||
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/Headers/Config.hpp")
|
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/Headers/Config.hpp")
|
||||||
else()
|
else()
|
||||||
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp")
|
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp")
|
||||||
endif()
|
endif()
|
||||||
FILE(READ "${SFML_CONFIG_HPP_INPUT}" SFML_CONFIG_HPP_CONTENTS)
|
FILE(READ "${SFML_CONFIG_HPP_INPUT}" SFML_CONFIG_HPP_CONTENTS)
|
||||||
STRING(REGEX MATCH ".*#define SFML_VERSION_MAJOR ([0-9]+).*#define SFML_VERSION_MINOR ([0-9]+).*" SFML_CONFIG_HPP_CONTENTS "${SFML_CONFIG_HPP_CONTENTS}")
|
STRING(REGEX MATCH ".*#define SFML_VERSION_MAJOR ([0-9]+).*#define SFML_VERSION_MINOR ([0-9]+).*" SFML_CONFIG_HPP_CONTENTS "${SFML_CONFIG_HPP_CONTENTS}")
|
||||||
STRING(REGEX REPLACE ".*#define SFML_VERSION_MAJOR ([0-9]+).*" "\\1" SFML_VERSION_MAJOR "${SFML_CONFIG_HPP_CONTENTS}")
|
STRING(REGEX REPLACE ".*#define SFML_VERSION_MAJOR ([0-9]+).*" "\\1" SFML_VERSION_MAJOR "${SFML_CONFIG_HPP_CONTENTS}")
|
||||||
STRING(REGEX REPLACE ".*#define SFML_VERSION_MINOR ([0-9]+).*" "\\1" SFML_VERSION_MINOR "${SFML_CONFIG_HPP_CONTENTS}")
|
STRING(REGEX REPLACE ".*#define SFML_VERSION_MINOR ([0-9]+).*" "\\1" SFML_VERSION_MINOR "${SFML_CONFIG_HPP_CONTENTS}")
|
||||||
math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10 + ${SFML_FIND_VERSION_MINOR}")
|
math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10 + ${SFML_FIND_VERSION_MINOR}")
|
||||||
|
|
||||||
# if we could extract them, compare with the requested version number
|
# if we could extract them, compare with the requested version number
|
||||||
if (SFML_VERSION_MAJOR)
|
if (SFML_VERSION_MAJOR)
|
||||||
# transform version numbers to an integer
|
# transform version numbers to an integer
|
||||||
math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10 + ${SFML_VERSION_MINOR}")
|
math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10 + ${SFML_VERSION_MINOR}")
|
||||||
|
|
||||||
# compare them
|
# compare them
|
||||||
if(SFML_VERSION LESS SFML_REQUESTED_VERSION)
|
if(SFML_VERSION LESS SFML_REQUESTED_VERSION)
|
||||||
set(SFML_VERSION_OK FALSE)
|
set(SFML_VERSION_OK FALSE)
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
# SFML version is < 2.0
|
# SFML version is < 2.0
|
||||||
if (SFML_REQUESTED_VERSION GREATER 19)
|
if (SFML_REQUESTED_VERSION GREATER 19)
|
||||||
set(SFML_VERSION_OK FALSE)
|
set(SFML_VERSION_OK FALSE)
|
||||||
set(SFML_VERSION_MAJOR 1)
|
set(SFML_VERSION_MAJOR 1)
|
||||||
set(SFML_VERSION_MINOR x)
|
set(SFML_VERSION_MINOR x)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# find the requested modules
|
# find the requested modules
|
||||||
set(SFML_FOUND TRUE) # will be set to false if one of the required modules is not found
|
set(SFML_FOUND TRUE) # will be set to false if one of the required modules is not found
|
||||||
foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS})
|
foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS})
|
||||||
string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER)
|
string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER)
|
||||||
string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER)
|
string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER)
|
||||||
set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER})
|
set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER})
|
||||||
|
|
||||||
# no suffix for sfml-main, it is always a static library
|
# no suffix for sfml-main, it is always a static library
|
||||||
if(FIND_SFML_COMPONENT_LOWER STREQUAL "main")
|
if(FIND_SFML_COMPONENT_LOWER STREQUAL "main")
|
||||||
# release library
|
# release library
|
||||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
|
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
|
||||||
NAMES ${FIND_SFML_COMPONENT_NAME}
|
NAMES ${FIND_SFML_COMPONENT_NAME}
|
||||||
PATH_SUFFIXES lib64 lib
|
PATH_SUFFIXES lib64 lib
|
||||||
PATHS ${FIND_SFML_PATHS})
|
PATHS ${FIND_SFML_PATHS})
|
||||||
|
|
||||||
# debug library
|
# debug library
|
||||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG
|
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG
|
||||||
NAMES ${FIND_SFML_COMPONENT_NAME}-d
|
NAMES ${FIND_SFML_COMPONENT_NAME}-d
|
||||||
PATH_SUFFIXES lib64 lib
|
PATH_SUFFIXES lib64 lib
|
||||||
PATHS ${FIND_SFML_PATHS})
|
PATHS ${FIND_SFML_PATHS})
|
||||||
else()
|
else()
|
||||||
# static release library
|
# static release library
|
||||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE
|
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE
|
||||||
NAMES ${FIND_SFML_COMPONENT_NAME}-s
|
NAMES ${FIND_SFML_COMPONENT_NAME}-s
|
||||||
PATH_SUFFIXES lib64 lib
|
PATH_SUFFIXES lib64 lib
|
||||||
PATHS ${FIND_SFML_PATHS})
|
PATHS ${FIND_SFML_PATHS})
|
||||||
|
|
||||||
# static debug library
|
# static debug library
|
||||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG
|
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG
|
||||||
NAMES ${FIND_SFML_COMPONENT_NAME}-s-d
|
NAMES ${FIND_SFML_COMPONENT_NAME}-s-d
|
||||||
PATH_SUFFIXES lib64 lib
|
PATH_SUFFIXES lib64 lib
|
||||||
PATHS ${FIND_SFML_PATHS})
|
PATHS ${FIND_SFML_PATHS})
|
||||||
|
|
||||||
# dynamic release library
|
# dynamic release library
|
||||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE
|
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE
|
||||||
NAMES ${FIND_SFML_COMPONENT_NAME}
|
NAMES ${FIND_SFML_COMPONENT_NAME}
|
||||||
PATH_SUFFIXES lib64 lib
|
PATH_SUFFIXES lib64 lib
|
||||||
PATHS ${FIND_SFML_PATHS})
|
PATHS ${FIND_SFML_PATHS})
|
||||||
|
|
||||||
# dynamic debug library
|
# dynamic debug library
|
||||||
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG
|
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG
|
||||||
NAMES ${FIND_SFML_COMPONENT_NAME}-d
|
NAMES ${FIND_SFML_COMPONENT_NAME}-d
|
||||||
PATH_SUFFIXES lib64 lib
|
PATH_SUFFIXES lib64 lib
|
||||||
PATHS ${FIND_SFML_PATHS})
|
PATHS ${FIND_SFML_PATHS})
|
||||||
|
|
||||||
# choose the entries that fit the requested link type
|
# choose the entries that fit the requested link type
|
||||||
if(SFML_STATIC_LIBRARIES)
|
if(SFML_STATIC_LIBRARIES)
|
||||||
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE)
|
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE)
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE})
|
||||||
endif()
|
endif()
|
||||||
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG)
|
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG)
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG})
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE)
|
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE)
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE})
|
||||||
endif()
|
endif()
|
||||||
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG)
|
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG)
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG})
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG OR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG OR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
||||||
# library found
|
# library found
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND TRUE)
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND TRUE)
|
||||||
|
|
||||||
# if both are found, set SFML_XXX_LIBRARY to contain both
|
# if both are found, set SFML_XXX_LIBRARY to contain both
|
||||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY debug ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY debug ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}
|
||||||
optimized ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
optimized ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# if only one debug/release variant is found, set the other to be equal to the found one
|
# if only one debug/release variant is found, set the other to be equal to the found one
|
||||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
|
||||||
# debug and not release
|
# debug and not release
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
|
||||||
endif()
|
endif()
|
||||||
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG)
|
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG)
|
||||||
# release and not debug
|
# release and not debug
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
# library not found
|
# library not found
|
||||||
set(SFML_FOUND FALSE)
|
set(SFML_FOUND FALSE)
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND FALSE)
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND FALSE)
|
||||||
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY "")
|
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY "")
|
||||||
set(FIND_SFML_MISSING "${FIND_SFML_MISSING} SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY")
|
set(FIND_SFML_MISSING "${FIND_SFML_MISSING} SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# mark as advanced
|
# mark as advanced
|
||||||
MARK_AS_ADVANCED(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY
|
MARK_AS_ADVANCED(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY
|
||||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
|
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
|
||||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG
|
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG
|
||||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE
|
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE
|
||||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG
|
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG
|
||||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE
|
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE
|
||||||
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG)
|
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG)
|
||||||
|
|
||||||
# add to the global list of libraries
|
# add to the global list of libraries
|
||||||
set(SFML_LIBRARIES ${SFML_LIBRARIES} "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}")
|
set(SFML_LIBRARIES ${SFML_LIBRARIES} "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# in case of static linking, we must also define the list of all the dependencies of SFML libraries
|
# in case of static linking, we must also define the list of all the dependencies of SFML libraries
|
||||||
if(SFML_STATIC_LIBRARIES)
|
if(SFML_STATIC_LIBRARIES)
|
||||||
|
|
||||||
# detect the OS
|
# detect the OS
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
set(FIND_SFML_OS_WINDOWS 1)
|
set(FIND_SFML_OS_WINDOWS 1)
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
set(FIND_SFML_OS_LINUX 1)
|
set(FIND_SFML_OS_LINUX 1)
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||||
set(FIND_SFML_OS_FREEBSD 1)
|
set(FIND_SFML_OS_FREEBSD 1)
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
set(FIND_SFML_OS_MACOSX 1)
|
set(FIND_SFML_OS_MACOSX 1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# start with an empty list
|
# start with an empty list
|
||||||
set(SFML_DEPENDENCIES)
|
set(SFML_DEPENDENCIES)
|
||||||
set(FIND_SFML_DEPENDENCIES_NOTFOUND)
|
set(FIND_SFML_DEPENDENCIES_NOTFOUND)
|
||||||
|
|
||||||
# macro that searches for a 3rd-party library
|
# macro that searches for a 3rd-party library
|
||||||
macro(find_sfml_dependency output friendlyname)
|
macro(find_sfml_dependency output friendlyname)
|
||||||
find_library(${output} NAMES ${ARGN} PATHS ${FIND_SFML_PATHS} PATH_SUFFIXES lib)
|
find_library(${output} NAMES ${ARGN} PATHS ${FIND_SFML_PATHS} PATH_SUFFIXES lib)
|
||||||
if(${${output}} STREQUAL "${output}-NOTFOUND")
|
if(${${output}} STREQUAL "${output}-NOTFOUND")
|
||||||
unset(output)
|
unset(output)
|
||||||
set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${friendlyname}")
|
set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${friendlyname}")
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
# sfml-system
|
# sfml-system
|
||||||
list(FIND SFML_FIND_COMPONENTS "system" FIND_SFML_SYSTEM_COMPONENT)
|
list(FIND SFML_FIND_COMPONENTS "system" FIND_SFML_SYSTEM_COMPONENT)
|
||||||
if(NOT ${FIND_SFML_SYSTEM_COMPONENT} EQUAL -1)
|
if(NOT ${FIND_SFML_SYSTEM_COMPONENT} EQUAL -1)
|
||||||
|
|
||||||
# update the list -- these are only system libraries, no need to find them
|
# update the list -- these are only system libraries, no need to find them
|
||||||
if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD OR FIND_SFML_OS_MACOSX)
|
if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD OR FIND_SFML_OS_MACOSX)
|
||||||
set(SFML_SYSTEM_DEPENDENCIES "pthread")
|
set(SFML_SYSTEM_DEPENDENCIES "pthread")
|
||||||
endif()
|
endif()
|
||||||
if(FIND_SFML_OS_LINUX)
|
if(FIND_SFML_OS_LINUX)
|
||||||
set(SFML_SYSTEM_DEPENDENCIES "rt")
|
set(SFML_SYSTEM_DEPENDENCIES "rt")
|
||||||
endif()
|
endif()
|
||||||
if(FIND_SFML_OS_WINDOWS)
|
if(FIND_SFML_OS_WINDOWS)
|
||||||
set(SFML_SYSTEM_DEPENDENCIES "winmm")
|
set(SFML_SYSTEM_DEPENDENCIES "winmm")
|
||||||
endif()
|
endif()
|
||||||
set(SFML_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
set(SFML_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# sfml-network
|
# sfml-network
|
||||||
list(FIND SFML_FIND_COMPONENTS "network" FIND_SFML_NETWORK_COMPONENT)
|
list(FIND SFML_FIND_COMPONENTS "network" FIND_SFML_NETWORK_COMPONENT)
|
||||||
if(NOT ${FIND_SFML_NETWORK_COMPONENT} EQUAL -1)
|
if(NOT ${FIND_SFML_NETWORK_COMPONENT} EQUAL -1)
|
||||||
|
|
||||||
# update the list -- these are only system libraries, no need to find them
|
# update the list -- these are only system libraries, no need to find them
|
||||||
if(FIND_SFML_OS_WINDOWS)
|
if(FIND_SFML_OS_WINDOWS)
|
||||||
set(SFML_NETWORK_DEPENDENCIES "ws2_32")
|
set(SFML_NETWORK_DEPENDENCIES "ws2_32")
|
||||||
endif()
|
endif()
|
||||||
set(SFML_DEPENDENCIES ${SFML_NETWORK_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
set(SFML_DEPENDENCIES ${SFML_NETWORK_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# sfml-window
|
# sfml-window
|
||||||
list(FIND SFML_FIND_COMPONENTS "window" FIND_SFML_WINDOW_COMPONENT)
|
list(FIND SFML_FIND_COMPONENTS "window" FIND_SFML_WINDOW_COMPONENT)
|
||||||
if(NOT ${FIND_SFML_WINDOW_COMPONENT} EQUAL -1)
|
if(NOT ${FIND_SFML_WINDOW_COMPONENT} EQUAL -1)
|
||||||
|
|
||||||
# find libraries
|
# find libraries
|
||||||
if(FIND_SFML_OS_LINUX)
|
if(FIND_SFML_OS_LINUX)
|
||||||
find_sfml_dependency(X11_LIBRARY "X11" X11)
|
find_sfml_dependency(X11_LIBRARY "X11" X11)
|
||||||
find_sfml_dependency(XRANDR_LIBRARY "Xrandr" Xrandr)
|
find_sfml_dependency(XRANDR_LIBRARY "Xrandr" Xrandr)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# update the list
|
# update the list
|
||||||
if(FIND_SFML_OS_WINDOWS)
|
if(FIND_SFML_OS_WINDOWS)
|
||||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32")
|
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32")
|
||||||
elseif(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
|
elseif(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
|
||||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${XRANDR_LIBRARY})
|
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${XRANDR_LIBRARY})
|
||||||
if(FIND_SFML_OS_FREEBSD)
|
if(FIND_SFML_OS_FREEBSD)
|
||||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "usbhid")
|
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "usbhid")
|
||||||
endif()
|
endif()
|
||||||
elseif(FIND_SFML_OS_MACOSX)
|
elseif(FIND_SFML_OS_MACOSX)
|
||||||
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon")
|
||||||
endif()
|
endif()
|
||||||
set(SFML_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
set(SFML_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# sfml-graphics
|
# sfml-graphics
|
||||||
list(FIND SFML_FIND_COMPONENTS "graphics" FIND_SFML_GRAPHICS_COMPONENT)
|
list(FIND SFML_FIND_COMPONENTS "graphics" FIND_SFML_GRAPHICS_COMPONENT)
|
||||||
if(NOT ${FIND_SFML_GRAPHICS_COMPONENT} EQUAL -1)
|
if(NOT ${FIND_SFML_GRAPHICS_COMPONENT} EQUAL -1)
|
||||||
|
|
||||||
# find libraries
|
# find libraries
|
||||||
find_sfml_dependency(FREETYPE_LIBRARY "FreeType" freetype)
|
find_sfml_dependency(FREETYPE_LIBRARY "FreeType" freetype)
|
||||||
find_sfml_dependency(GLEW_LIBRARY "GLEW" glew GLEW glew32 glew32s glew64 glew64s)
|
find_sfml_dependency(GLEW_LIBRARY "GLEW" glew GLEW glew32 glew32s glew64 glew64s)
|
||||||
find_sfml_dependency(JPEG_LIBRARY "libjpeg" jpeg)
|
find_sfml_dependency(JPEG_LIBRARY "libjpeg" jpeg)
|
||||||
|
|
||||||
# update the list
|
# update the list
|
||||||
set(SFML_GRAPHICS_DEPENDENCIES ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY})
|
set(SFML_GRAPHICS_DEPENDENCIES ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY})
|
||||||
set(SFML_DEPENDENCIES ${SFML_GRAPHICS_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
set(SFML_DEPENDENCIES ${SFML_GRAPHICS_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# sfml-audio
|
# sfml-audio
|
||||||
list(FIND SFML_FIND_COMPONENTS "audio" FIND_SFML_AUDIO_COMPONENT)
|
list(FIND SFML_FIND_COMPONENTS "audio" FIND_SFML_AUDIO_COMPONENT)
|
||||||
if(NOT ${FIND_SFML_AUDIO_COMPONENT} EQUAL -1)
|
if(NOT ${FIND_SFML_AUDIO_COMPONENT} EQUAL -1)
|
||||||
|
|
||||||
# find libraries
|
# find libraries
|
||||||
find_sfml_dependency(OPENAL_LIBRARY "OpenAL" openal openal32)
|
find_sfml_dependency(OPENAL_LIBRARY "OpenAL" openal openal32)
|
||||||
find_sfml_dependency(SNDFILE_LIBRARY "libsndfile" sndfile)
|
find_sfml_dependency(SNDFILE_LIBRARY "libsndfile" sndfile)
|
||||||
|
|
||||||
# update the list
|
# update the list
|
||||||
set(SFML_AUDIO_DEPENDENCIES ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY})
|
set(SFML_AUDIO_DEPENDENCIES ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY})
|
||||||
set(SFML_DEPENDENCIES ${SFML_AUDIO_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
set(SFML_DEPENDENCIES ${SFML_AUDIO_DEPENDENCIES} ${SFML_DEPENDENCIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# handle errors
|
# handle errors
|
||||||
if(NOT SFML_VERSION_OK)
|
if(NOT SFML_VERSION_OK)
|
||||||
# SFML version not ok
|
# SFML version not ok
|
||||||
set(FIND_SFML_ERROR "SFML found but version too low (requested: ${SFML_FIND_VERSION}, found: ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR})")
|
set(FIND_SFML_ERROR "SFML found but version too low (requested: ${SFML_FIND_VERSION}, found: ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR})")
|
||||||
set(SFML_FOUND FALSE)
|
set(SFML_FOUND FALSE)
|
||||||
elseif(SFML_STATIC_LIBRARIES AND FIND_SFML_DEPENDENCIES_NOTFOUND)
|
elseif(SFML_STATIC_LIBRARIES AND FIND_SFML_DEPENDENCIES_NOTFOUND)
|
||||||
set(FIND_SFML_ERROR "SFML found but some of its dependencies are missing (${FIND_SFML_DEPENDENCIES_NOTFOUND})")
|
set(FIND_SFML_ERROR "SFML found but some of its dependencies are missing (${FIND_SFML_DEPENDENCIES_NOTFOUND})")
|
||||||
set(SFML_FOUND FALSE)
|
set(SFML_FOUND FALSE)
|
||||||
elseif(NOT SFML_FOUND)
|
elseif(NOT SFML_FOUND)
|
||||||
# include directory or library not found
|
# include directory or library not found
|
||||||
set(FIND_SFML_ERROR "Could NOT find SFML (missing: ${FIND_SFML_MISSING})")
|
set(FIND_SFML_ERROR "Could NOT find SFML (missing: ${FIND_SFML_MISSING})")
|
||||||
endif()
|
endif()
|
||||||
if (NOT SFML_FOUND)
|
if (NOT SFML_FOUND)
|
||||||
if(SFML_FIND_REQUIRED)
|
if(SFML_FIND_REQUIRED)
|
||||||
# fatal error
|
# fatal error
|
||||||
message(FATAL_ERROR ${FIND_SFML_ERROR})
|
message(FATAL_ERROR ${FIND_SFML_ERROR})
|
||||||
elseif(NOT SFML_FIND_QUIETLY)
|
elseif(NOT SFML_FIND_QUIETLY)
|
||||||
# error but continue
|
# error but continue
|
||||||
message("${FIND_SFML_ERROR}")
|
message("${FIND_SFML_ERROR}")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# handle success
|
# handle success
|
||||||
if(SFML_FOUND)
|
if(SFML_FOUND)
|
||||||
message(STATUS "Found SFML ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR} in ${SFML_INCLUDE_DIR}")
|
message(STATUS "Found SFML ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR} in ${SFML_INCLUDE_DIR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
# - Find sndfile
|
# - Find sndfile
|
||||||
# Find the native sndfile includes and libraries
|
# Find the native sndfile includes and libraries
|
||||||
#
|
#
|
||||||
# SNDFILE_INCLUDE_DIR - where to find sndfile.h, etc.
|
# SNDFILE_INCLUDE_DIR - where to find sndfile.h, etc.
|
||||||
# SNDFILE_LIBRARIES - List of libraries when using libsndfile.
|
# SNDFILE_LIBRARIES - List of libraries when using libsndfile.
|
||||||
# SNDFILE_FOUND - True if libsndfile found.
|
# SNDFILE_FOUND - True if libsndfile found.
|
||||||
|
|
||||||
if(SNDFILE_INCLUDE_DIR)
|
if(SNDFILE_INCLUDE_DIR)
|
||||||
# Already in cache, be silent
|
# Already in cache, be silent
|
||||||
set(SNDFILE_FIND_QUIETLY TRUE)
|
set(SNDFILE_FIND_QUIETLY TRUE)
|
||||||
endif(SNDFILE_INCLUDE_DIR)
|
endif(SNDFILE_INCLUDE_DIR)
|
||||||
|
|
||||||
find_path(SNDFILE_INCLUDE_DIR sndfile.h)
|
find_path(SNDFILE_INCLUDE_DIR sndfile.h)
|
||||||
|
|
||||||
find_library(SNDFILE_LIBRARY NAMES sndfile sndfile-1)
|
find_library(SNDFILE_LIBRARY NAMES sndfile sndfile-1)
|
||||||
|
|
||||||
# Handle the QUIETLY and REQUIRED arguments and set SNDFILE_FOUND to TRUE if
|
# Handle the QUIETLY and REQUIRED arguments and set SNDFILE_FOUND to TRUE if
|
||||||
# all listed variables are TRUE.
|
# all listed variables are TRUE.
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(SNDFILE DEFAULT_MSG SNDFILE_LIBRARY SNDFILE_INCLUDE_DIR)
|
find_package_handle_standard_args(SNDFILE DEFAULT_MSG SNDFILE_LIBRARY SNDFILE_INCLUDE_DIR)
|
||||||
|
|
||||||
if(SNDFILE_FOUND)
|
if(SNDFILE_FOUND)
|
||||||
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})
|
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})
|
||||||
else(SNDFILE_FOUND)
|
else(SNDFILE_FOUND)
|
||||||
set(SNDFILE_LIBRARIES)
|
set(SNDFILE_LIBRARIES)
|
||||||
endif(SNDFILE_FOUND)
|
endif(SNDFILE_FOUND)
|
||||||
|
|
||||||
mark_as_advanced(SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY)
|
mark_as_advanced(SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="footer-container">
|
<div id="footer-container">
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
Copyright © Laurent Gomila ::
|
Copyright © Laurent Gomila ::
|
||||||
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> ::
|
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> ::
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<title>SFML - Simple and Fast Multimedia Library</title>
|
<title>SFML - Simple and Fast Multimedia Library</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
|
||||||
<!--<link rel='stylesheet' type='text/css' href="http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
<!--<link rel='stylesheet' type='text/css' href="http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
||||||
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="banner-container">
|
<div id="banner-container">
|
||||||
<div id="banner">
|
<div id="banner">
|
||||||
<span id="sfml">SFML</span>
|
<span id="sfml">SFML</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
142
doc/mainpage.hpp
142
doc/mainpage.hpp
|
@ -1,71 +1,71 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \mainpage
|
/// \mainpage
|
||||||
///
|
///
|
||||||
/// \section welcome Welcome
|
/// \section welcome Welcome
|
||||||
/// Welcome to the official SFML documentation. Here you will find a detailed
|
/// Welcome to the official SFML documentation. Here you will find a detailed
|
||||||
/// view of all the SFML <a href="./annotated.php">classes</a> and functions. <br/>
|
/// view of all the SFML <a href="./annotated.php">classes</a> and functions. <br/>
|
||||||
/// If you are looking for tutorials, you can visit the official website
|
/// If you are looking for tutorials, you can visit the official website
|
||||||
/// at <a href="http://www.sfml-dev.org/">www.sfml-dev.org</a>.
|
/// at <a href="http://www.sfml-dev.org/">www.sfml-dev.org</a>.
|
||||||
///
|
///
|
||||||
/// \section example Short example
|
/// \section example Short example
|
||||||
/// Here is a short example, to show you how simple it is to use SFML :
|
/// Here is a short example, to show you how simple it is to use SFML:
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
///
|
///
|
||||||
/// #include <SFML/Audio.hpp>
|
/// #include <SFML/Audio.hpp>
|
||||||
/// #include <SFML/Graphics.hpp>
|
/// #include <SFML/Graphics.hpp>
|
||||||
///
|
///
|
||||||
/// int main()
|
/// int main()
|
||||||
/// {
|
/// {
|
||||||
/// // Create the main window
|
/// // Create the main window
|
||||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
||||||
///
|
///
|
||||||
/// // Load a sprite to display
|
/// // Load a sprite to display
|
||||||
/// sf::Texture texture;
|
/// sf::Texture texture;
|
||||||
/// if (!texture.loadFromFile("cute_image.jpg"))
|
/// if (!texture.loadFromFile("cute_image.jpg"))
|
||||||
/// return EXIT_FAILURE;
|
/// return EXIT_FAILURE;
|
||||||
/// sf::Sprite sprite(texture);
|
/// sf::Sprite sprite(texture);
|
||||||
///
|
///
|
||||||
/// // Create a graphical text to display
|
/// // Create a graphical text to display
|
||||||
/// sf::Font font;
|
/// sf::Font font;
|
||||||
/// if (!font.loadFromFile("arial.ttf"))
|
/// if (!font.loadFromFile("arial.ttf"))
|
||||||
/// return EXIT_FAILURE;
|
/// return EXIT_FAILURE;
|
||||||
/// sf::Text text("Hello SFML", font, 50);
|
/// sf::Text text("Hello SFML", font, 50);
|
||||||
///
|
///
|
||||||
/// // Load a music to play
|
/// // Load a music to play
|
||||||
/// sf::Music music;
|
/// sf::Music music;
|
||||||
/// if (!music.openFromFile("nice_music.ogg"))
|
/// if (!music.openFromFile("nice_music.ogg"))
|
||||||
/// return EXIT_FAILURE;
|
/// return EXIT_FAILURE;
|
||||||
///
|
///
|
||||||
/// // Play the music
|
/// // Play the music
|
||||||
/// music.play();
|
/// music.play();
|
||||||
///
|
///
|
||||||
/// // Start the game loop
|
/// // Start the game loop
|
||||||
/// while (window.isOpen())
|
/// while (window.isOpen())
|
||||||
/// {
|
/// {
|
||||||
/// // Process events
|
/// // Process events
|
||||||
/// sf::Event event;
|
/// sf::Event event;
|
||||||
/// while (window.pollEvent(event))
|
/// while (window.pollEvent(event))
|
||||||
/// {
|
/// {
|
||||||
/// // Close window : exit
|
/// // Close window: exit
|
||||||
/// if (event.type == sf::Event::Closed)
|
/// if (event.type == sf::Event::Closed)
|
||||||
/// window.close();
|
/// window.close();
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Clear screen
|
/// // Clear screen
|
||||||
/// window.clear();
|
/// window.clear();
|
||||||
///
|
///
|
||||||
/// // Draw the sprite
|
/// // Draw the sprite
|
||||||
/// window.draw(sprite);
|
/// window.draw(sprite);
|
||||||
///
|
///
|
||||||
/// // Draw the string
|
/// // Draw the string
|
||||||
/// window.draw(text);
|
/// window.draw(text);
|
||||||
///
|
///
|
||||||
/// // Update the window
|
/// // Update the window
|
||||||
/// window.display();
|
/// window.display();
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// return EXIT_SUCCESS;
|
/// return EXIT_SUCCESS;
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
|
|
||||||
# add the examples subdirectories
|
# add the examples subdirectories
|
||||||
add_subdirectory(ftp)
|
add_subdirectory(ftp)
|
||||||
add_subdirectory(opengl)
|
add_subdirectory(opengl)
|
||||||
add_subdirectory(pong)
|
add_subdirectory(pong)
|
||||||
add_subdirectory(shader)
|
add_subdirectory(shader)
|
||||||
add_subdirectory(sockets)
|
add_subdirectory(sockets)
|
||||||
add_subdirectory(sound)
|
add_subdirectory(sound)
|
||||||
add_subdirectory(sound_capture)
|
add_subdirectory(sound_capture)
|
||||||
add_subdirectory(voip)
|
add_subdirectory(voip)
|
||||||
add_subdirectory(window)
|
add_subdirectory(window)
|
||||||
if(SFML_OS_WINDOWS)
|
if(SFML_OS_WINDOWS)
|
||||||
add_subdirectory(win32)
|
add_subdirectory(win32)
|
||||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
|
||||||
add_subdirectory(X11)
|
add_subdirectory(X11)
|
||||||
elseif(SFML_OS_MACOSX)
|
elseif(SFML_OS_MACOSX)
|
||||||
add_subdirectory(cocoa)
|
add_subdirectory(cocoa)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/X11)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/X11)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/X11.cpp)
|
set(SRC ${SRCROOT}/X11.cpp)
|
||||||
|
|
||||||
# find OpenGL, GLU and X11
|
# find OpenGL, GLU and X11
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
include_directories(${OPENGL_INCLUDE_DIR})
|
include_directories(${OPENGL_INCLUDE_DIR})
|
||||||
find_package(X11 REQUIRED)
|
find_package(X11 REQUIRED)
|
||||||
include_directories(${X11_INCLUDE_DIR})
|
include_directories(${X11_INCLUDE_DIR})
|
||||||
|
|
||||||
# define the X11 target
|
# define the X11 target
|
||||||
sfml_add_example(X11 GUI_APP
|
sfml_add_example(X11 GUI_APP
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-window sfml-system ${OPENGL_LIBRARIES} ${X11_LIBRARIES})
|
DEPENDS sfml-window sfml-system ${OPENGL_LIBRARIES} ${X11_LIBRARIES})
|
||||||
|
|
|
@ -1,199 +1,199 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window.hpp>
|
#include <SFML/Window.hpp>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Initialize OpenGL states into the specified view
|
/// Initialize OpenGL states into the specified view
|
||||||
///
|
///
|
||||||
/// \param Window Target window to initialize
|
/// \param Window Target window to initialize
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void initialize(sf::Window& window)
|
void initialize(sf::Window& window)
|
||||||
{
|
{
|
||||||
// Activate the window
|
// Activate the window
|
||||||
window.setActive();
|
window.setActive();
|
||||||
|
|
||||||
// Setup OpenGL states
|
// Setup OpenGL states
|
||||||
// Set color and depth clear value
|
// Set color and depth clear value
|
||||||
glClearDepth(1.f);
|
glClearDepth(1.f);
|
||||||
glClearColor(0.f, 0.5f, 0.5f, 0.f);
|
glClearColor(0.f, 0.5f, 0.5f, 0.f);
|
||||||
|
|
||||||
// Enable Z-buffer read and write
|
// Enable Z-buffer read and write
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
// Setup a perspective projection
|
// Setup a perspective projection
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(90.f, 1.f, 1.f, 500.f);
|
gluPerspective(90.f, 1.f, 1.f, 500.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Draw the OpenGL scene (a rotating cube) into
|
/// Draw the OpenGL scene (a rotating cube) into
|
||||||
/// the specified view
|
/// the specified view
|
||||||
///
|
///
|
||||||
/// \param window Target window for rendering
|
/// \param window Target window for rendering
|
||||||
/// \param elapsedTime Time elapsed since the last draw
|
/// \param elapsedTime Time elapsed since the last draw
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void draw(sf::Window& window, float elapsedTime)
|
void draw(sf::Window& window, float elapsedTime)
|
||||||
{
|
{
|
||||||
// Activate the window
|
// Activate the window
|
||||||
window.setActive();
|
window.setActive();
|
||||||
|
|
||||||
// Clear color and depth buffers
|
// Clear color and depth buffers
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Apply some transformations
|
// Apply some transformations
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.f, 0.f, -200.f);
|
glTranslatef(0.f, 0.f, -200.f);
|
||||||
glRotatef(elapsedTime * 0.05f, 1.f, 0.f, 0.f);
|
glRotatef(elapsedTime * 0.05f, 1.f, 0.f, 0.f);
|
||||||
glRotatef(elapsedTime * 0.03f, 0.f, 1.f, 0.f);
|
glRotatef(elapsedTime * 0.03f, 0.f, 1.f, 0.f);
|
||||||
glRotatef(elapsedTime * 0.09f, 0.f, 0.f, 1.f);
|
glRotatef(elapsedTime * 0.09f, 0.f, 0.f, 1.f);
|
||||||
|
|
||||||
// Draw a cube
|
// Draw a cube
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
glColor3f(1.f, 1.f, 0.f);
|
glColor3f(1.f, 1.f, 0.f);
|
||||||
glVertex3f(-50.f, -50.f, -50.f);
|
glVertex3f(-50.f, -50.f, -50.f);
|
||||||
glVertex3f(-50.f, 50.f, -50.f);
|
glVertex3f(-50.f, 50.f, -50.f);
|
||||||
glVertex3f( 50.f, 50.f, -50.f);
|
glVertex3f( 50.f, 50.f, -50.f);
|
||||||
glVertex3f( 50.f, -50.f, -50.f);
|
glVertex3f( 50.f, -50.f, -50.f);
|
||||||
|
|
||||||
glColor3f(1.f, 1.f, 0.f);
|
glColor3f(1.f, 1.f, 0.f);
|
||||||
glVertex3f(-50.f, -50.f, 50.f);
|
glVertex3f(-50.f, -50.f, 50.f);
|
||||||
glVertex3f(-50.f, 50.f, 50.f);
|
glVertex3f(-50.f, 50.f, 50.f);
|
||||||
glVertex3f( 50.f, 50.f, 50.f);
|
glVertex3f( 50.f, 50.f, 50.f);
|
||||||
glVertex3f( 50.f, -50.f, 50.f);
|
glVertex3f( 50.f, -50.f, 50.f);
|
||||||
|
|
||||||
glColor3f(0.f, 1.f, 1.f);
|
glColor3f(0.f, 1.f, 1.f);
|
||||||
glVertex3f(-50.f, -50.f, -50.f);
|
glVertex3f(-50.f, -50.f, -50.f);
|
||||||
glVertex3f(-50.f, 50.f, -50.f);
|
glVertex3f(-50.f, 50.f, -50.f);
|
||||||
glVertex3f(-50.f, 50.f, 50.f);
|
glVertex3f(-50.f, 50.f, 50.f);
|
||||||
glVertex3f(-50.f, -50.f, 50.f);
|
glVertex3f(-50.f, -50.f, 50.f);
|
||||||
|
|
||||||
glColor3f(0.f, 1.f, 1.f);
|
glColor3f(0.f, 1.f, 1.f);
|
||||||
glVertex3f(50.f, -50.f, -50.f);
|
glVertex3f(50.f, -50.f, -50.f);
|
||||||
glVertex3f(50.f, 50.f, -50.f);
|
glVertex3f(50.f, 50.f, -50.f);
|
||||||
glVertex3f(50.f, 50.f, 50.f);
|
glVertex3f(50.f, 50.f, 50.f);
|
||||||
glVertex3f(50.f, -50.f, 50.f);
|
glVertex3f(50.f, -50.f, 50.f);
|
||||||
|
|
||||||
glColor3f(1.f, 0.f, 1.f);
|
glColor3f(1.f, 0.f, 1.f);
|
||||||
glVertex3f(-50.f, -50.f, 50.f);
|
glVertex3f(-50.f, -50.f, 50.f);
|
||||||
glVertex3f(-50.f, -50.f, -50.f);
|
glVertex3f(-50.f, -50.f, -50.f);
|
||||||
glVertex3f( 50.f, -50.f, -50.f);
|
glVertex3f( 50.f, -50.f, -50.f);
|
||||||
glVertex3f( 50.f, -50.f, 50.f);
|
glVertex3f( 50.f, -50.f, 50.f);
|
||||||
|
|
||||||
glColor3f(1.f, 0.f, 1.f);
|
glColor3f(1.f, 0.f, 1.f);
|
||||||
glVertex3f(-50.f, 50.f, 50.f);
|
glVertex3f(-50.f, 50.f, 50.f);
|
||||||
glVertex3f(-50.f, 50.f, -50.f);
|
glVertex3f(-50.f, 50.f, -50.f);
|
||||||
glVertex3f( 50.f, 50.f, -50.f);
|
glVertex3f( 50.f, 50.f, -50.f);
|
||||||
glVertex3f( 50.f, 50.f, 50.f);
|
glVertex3f( 50.f, 50.f, 50.f);
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Error code
|
/// \return Error code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Open a connection with the X server
|
// Open a connection with the X server
|
||||||
Display* display = XOpenDisplay(NULL);
|
Display* display = XOpenDisplay(NULL);
|
||||||
if (!display)
|
if (!display)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
// Get the default screen
|
// Get the default screen
|
||||||
int screen = DefaultScreen(display);
|
int screen = DefaultScreen(display);
|
||||||
|
|
||||||
// Let's create the main window
|
// Let's create the main window
|
||||||
XSetWindowAttributes attributes;
|
XSetWindowAttributes attributes;
|
||||||
attributes.background_pixel = BlackPixel(display, screen);
|
attributes.background_pixel = BlackPixel(display, screen);
|
||||||
attributes.event_mask = KeyPressMask;
|
attributes.event_mask = KeyPressMask;
|
||||||
Window window = XCreateWindow(display, RootWindow(display, screen),
|
Window window = XCreateWindow(display, RootWindow(display, screen),
|
||||||
0, 0, 650, 330, 0,
|
0, 0, 650, 330, 0,
|
||||||
DefaultDepth(display, screen),
|
DefaultDepth(display, screen),
|
||||||
InputOutput,
|
InputOutput,
|
||||||
DefaultVisual(display, screen),
|
DefaultVisual(display, screen),
|
||||||
CWBackPixel | CWEventMask, &attributes);
|
CWBackPixel | CWEventMask, &attributes);
|
||||||
if (!window)
|
if (!window)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
// Set the window's name
|
// Set the window's name
|
||||||
XStoreName(display, window , "SFML Window");
|
XStoreName(display, window , "SFML Window");
|
||||||
|
|
||||||
// Let's create the windows which will serve as containers for our SFML views
|
// Let's create the windows which will serve as containers for our SFML views
|
||||||
Window view1 = XCreateWindow(display, window,
|
Window view1 = XCreateWindow(display, window,
|
||||||
10, 10, 310, 310, 0,
|
10, 10, 310, 310, 0,
|
||||||
DefaultDepth(display, screen),
|
DefaultDepth(display, screen),
|
||||||
InputOutput,
|
InputOutput,
|
||||||
DefaultVisual(display, screen),
|
DefaultVisual(display, screen),
|
||||||
0, NULL);
|
0, NULL);
|
||||||
Window view2 = XCreateWindow(display, window,
|
Window view2 = XCreateWindow(display, window,
|
||||||
330, 10, 310, 310, 0,
|
330, 10, 310, 310, 0,
|
||||||
DefaultDepth(display, screen),
|
DefaultDepth(display, screen),
|
||||||
InputOutput,
|
InputOutput,
|
||||||
DefaultVisual(display, screen),
|
DefaultVisual(display, screen),
|
||||||
0, NULL);
|
0, NULL);
|
||||||
|
|
||||||
// Show our windows
|
// Show our windows
|
||||||
XMapWindow(display, window);
|
XMapWindow(display, window);
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
|
|
||||||
// Create our SFML views
|
// Create our SFML views
|
||||||
sf::Window SFMLView1(view1);
|
sf::Window SFMLView1(view1);
|
||||||
sf::Window SFMLView2(view2);
|
sf::Window SFMLView2(view2);
|
||||||
|
|
||||||
// Create a clock for measuring elapsed time
|
// Create a clock for measuring elapsed time
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
|
|
||||||
// Initialize our views
|
// Initialize our views
|
||||||
initialize(SFMLView1);
|
initialize(SFMLView1);
|
||||||
initialize(SFMLView2);
|
initialize(SFMLView2);
|
||||||
|
|
||||||
// Start the event loop
|
// Start the event loop
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
while (XPending(display))
|
while (XPending(display))
|
||||||
{
|
{
|
||||||
// Get the next pending event
|
// Get the next pending event
|
||||||
XEvent event;
|
XEvent event;
|
||||||
XNextEvent(display, &event);
|
XNextEvent(display, &event);
|
||||||
|
|
||||||
// Process it
|
// Process it
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
// Any key is pressed : quit
|
// Any key is pressed: quit
|
||||||
case KeyPress :
|
case KeyPress:
|
||||||
running = false;
|
running = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw something into our views
|
// Draw something into our views
|
||||||
draw(SFMLView1, clock.getElapsedTime().asSeconds());
|
draw(SFMLView1, clock.getElapsedTime().asSeconds());
|
||||||
draw(SFMLView2, clock.getElapsedTime().asSeconds() * 0.3f);
|
draw(SFMLView2, clock.getElapsedTime().asSeconds() * 0.3f);
|
||||||
|
|
||||||
// Display the views on screen
|
// Display the views on screen
|
||||||
SFMLView1.display();
|
SFMLView1.display();
|
||||||
SFMLView2.display();
|
SFMLView2.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the display
|
// Close the display
|
||||||
XCloseDisplay(display);
|
XCloseDisplay(display);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/cocoa)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/cocoa)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/CocoaAppDelegate.h
|
set(SRC ${SRCROOT}/CocoaAppDelegate.h
|
||||||
${SRCROOT}/CocoaAppDelegate.mm
|
${SRCROOT}/CocoaAppDelegate.mm
|
||||||
${SRCROOT}/NSString+stdstring.h
|
${SRCROOT}/NSString+stdstring.h
|
||||||
${SRCROOT}/NSString+stdstring.mm
|
${SRCROOT}/NSString+stdstring.mm
|
||||||
|
@ -28,9 +28,9 @@ set_target_properties(cocoa PROPERTIES
|
||||||
MACOSX_BUNDLE_INFO_PLIST ${SRCROOT}/resources/Cocoa-Info.plist)
|
MACOSX_BUNDLE_INFO_PLIST ${SRCROOT}/resources/Cocoa-Info.plist)
|
||||||
target_link_libraries(cocoa "-framework Cocoa -framework Foundation"
|
target_link_libraries(cocoa "-framework Cocoa -framework Foundation"
|
||||||
sfml-system sfml-window sfml-graphics)
|
sfml-system sfml-window sfml-graphics)
|
||||||
|
|
||||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||||
set_target_properties(cocoa PROPERTIES FOLDER "Examples")
|
set_target_properties(cocoa PROPERTIES FOLDER "Examples")
|
||||||
|
|
||||||
# compile XIB files
|
# compile XIB files
|
||||||
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
|
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
|
||||||
|
@ -48,20 +48,20 @@ foreach(XIB ${XIBS})
|
||||||
--compile ${XIB_OUTPUT_PATH}/${XIB}.nib
|
--compile ${XIB_OUTPUT_PATH}/${XIB}.nib
|
||||||
${XIB_INPUT_PATH}/${XIB}.xib
|
${XIB_INPUT_PATH}/${XIB}.xib
|
||||||
COMMENT "Compiling ${XIB}.xib")
|
COMMENT "Compiling ${XIB}.xib")
|
||||||
# deactivated options : --warnings --notices
|
# deactivated options: --warnings --notices
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# add install rule
|
# add install rule
|
||||||
install(TARGETS cocoa
|
install(TARGETS cocoa
|
||||||
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/cocoa
|
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/cocoa
|
||||||
COMPONENT examples)
|
COMPONENT examples)
|
||||||
|
|
||||||
#
|
#
|
||||||
# define the cocoa target
|
# define the cocoa target
|
||||||
# sfml_add_example is not compatible with application bundles !
|
# sfml_add_example is not compatible with application bundles !
|
||||||
#
|
#
|
||||||
#sfml_add_example(cocoa
|
#sfml_add_example(cocoa
|
||||||
# SOURCES ${SRC}
|
# SOURCES ${SRC}
|
||||||
# DEPENDS sfml-system sfml-window sfml-graphics)
|
# DEPENDS sfml-system sfml-window sfml-graphics)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,11 @@
|
||||||
#import <SFML/Graphics.hpp>
|
#import <SFML/Graphics.hpp>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NB : We need pointers for C++ objects fields in Obj-C interface !
|
* NB: We need pointers for C++ objects fields in Obj-C interface !
|
||||||
* The recommended way is to use PIMP idiom.
|
* The recommended way is to use PIMPL idiom.
|
||||||
*
|
*
|
||||||
* It's elegant. Moreover, we do no constrain
|
* It's elegant. Moreover, we do no constrain
|
||||||
* other file including this one to be Obj-C++.
|
* other file including this one to be Obj-C++.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct SFMLmainWindow;
|
struct SFMLmainWindow;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/ftp)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/ftp)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/Ftp.cpp)
|
set(SRC ${SRCROOT}/Ftp.cpp)
|
||||||
|
|
||||||
# define the ftp target
|
# define the ftp target
|
||||||
sfml_add_example(ftp
|
sfml_add_example(ftp
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-network sfml-system)
|
DEPENDS sfml-network sfml-system)
|
||||||
|
|
|
@ -1,206 +1,206 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network.hpp>
|
#include <SFML/Network.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Print a FTP response into a standard output stream
|
/// Print a FTP response into a standard output stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response)
|
std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response)
|
||||||
{
|
{
|
||||||
return stream << response.getStatus() << response.getMessage();
|
return stream << response.getStatus() << response.getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Choose the server address
|
// Choose the server address
|
||||||
sf::IpAddress address;
|
sf::IpAddress address;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Enter the FTP server address : ";
|
std::cout << "Enter the FTP server address: ";
|
||||||
std::cin >> address;
|
std::cin >> address;
|
||||||
}
|
}
|
||||||
while (address == sf::IpAddress::None);
|
while (address == sf::IpAddress::None);
|
||||||
|
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
sf::Ftp server;
|
sf::Ftp server;
|
||||||
sf::Ftp::Response connectResponse = server.connect(address);
|
sf::Ftp::Response connectResponse = server.connect(address);
|
||||||
std::cout << connectResponse << std::endl;
|
std::cout << connectResponse << std::endl;
|
||||||
if (!connectResponse.isOk())
|
if (!connectResponse.isOk())
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
// Ask for user name and password
|
// Ask for user name and password
|
||||||
std::string user, password;
|
std::string user, password;
|
||||||
std::cout << "User name : ";
|
std::cout << "User name: ";
|
||||||
std::cin >> user;
|
std::cin >> user;
|
||||||
std::cout << "Password : ";
|
std::cout << "Password: ";
|
||||||
std::cin >> password;
|
std::cin >> password;
|
||||||
|
|
||||||
// Login to the server
|
// Login to the server
|
||||||
sf::Ftp::Response loginResponse = server.login(user, password);
|
sf::Ftp::Response loginResponse = server.login(user, password);
|
||||||
std::cout << loginResponse << std::endl;
|
std::cout << loginResponse << std::endl;
|
||||||
if (!loginResponse.isOk())
|
if (!loginResponse.isOk())
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
// Main menu
|
// Main menu
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Main FTP menu
|
// Main FTP menu
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "Choose an action:" << std::endl;
|
std::cout << "Choose an action:" << std::endl;
|
||||||
std::cout << "1. Print working directory" << std::endl;
|
std::cout << "1. Print working directory" << std::endl;
|
||||||
std::cout << "2. Print contents of working directory" << std::endl;
|
std::cout << "2. Print contents of working directory" << std::endl;
|
||||||
std::cout << "3. Change directory" << std::endl;
|
std::cout << "3. Change directory" << std::endl;
|
||||||
std::cout << "4. Create directory" << std::endl;
|
std::cout << "4. Create directory" << std::endl;
|
||||||
std::cout << "5. Delete directory" << std::endl;
|
std::cout << "5. Delete directory" << std::endl;
|
||||||
std::cout << "6. Rename file" << std::endl;
|
std::cout << "6. Rename file" << std::endl;
|
||||||
std::cout << "7. Remove file" << std::endl;
|
std::cout << "7. Remove file" << std::endl;
|
||||||
std::cout << "8. Download file" << std::endl;
|
std::cout << "8. Download file" << std::endl;
|
||||||
std::cout << "9. Upload file" << std::endl;
|
std::cout << "9. Upload file" << std::endl;
|
||||||
std::cout << "0. Disconnect" << std::endl;
|
std::cout << "0. Disconnect" << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
std::cout << "Your choice: ";
|
std::cout << "Your choice: ";
|
||||||
std::cin >> choice;
|
std::cin >> choice;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
switch (choice)
|
switch (choice)
|
||||||
{
|
{
|
||||||
default :
|
default:
|
||||||
{
|
{
|
||||||
// Wrong choice
|
// Wrong choice
|
||||||
std::cout << "Invalid choice!" << std::endl;
|
std::cout << "Invalid choice!" << std::endl;
|
||||||
std::cin.clear();
|
std::cin.clear();
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1 :
|
case 1:
|
||||||
{
|
{
|
||||||
// Print the current server directory
|
// Print the current server directory
|
||||||
sf::Ftp::DirectoryResponse response = server.getWorkingDirectory();
|
sf::Ftp::DirectoryResponse response = server.getWorkingDirectory();
|
||||||
std::cout << response << std::endl;
|
std::cout << response << std::endl;
|
||||||
std::cout << "Current directory is " << response.getDirectory() << std::endl;
|
std::cout << "Current directory is " << response.getDirectory() << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2 :
|
case 2:
|
||||||
{
|
{
|
||||||
// Print the contents of the current server directory
|
// Print the contents of the current server directory
|
||||||
sf::Ftp::ListingResponse response = server.getDirectoryListing();
|
sf::Ftp::ListingResponse response = server.getDirectoryListing();
|
||||||
std::cout << response << std::endl;
|
std::cout << response << std::endl;
|
||||||
const std::vector<std::string>& names = response.getListing();
|
const std::vector<std::string>& names = response.getListing();
|
||||||
for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
|
for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
|
||||||
std::cout << *it << std::endl;
|
std::cout << *it << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 3 :
|
case 3:
|
||||||
{
|
{
|
||||||
// Change the current directory
|
// Change the current directory
|
||||||
std::string directory;
|
std::string directory;
|
||||||
std::cout << "Choose a directory: ";
|
std::cout << "Choose a directory: ";
|
||||||
std::cin >> directory;
|
std::cin >> directory;
|
||||||
std::cout << server.changeDirectory(directory) << std::endl;
|
std::cout << server.changeDirectory(directory) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4 :
|
case 4:
|
||||||
{
|
{
|
||||||
// Create a new directory
|
// Create a new directory
|
||||||
std::string directory;
|
std::string directory;
|
||||||
std::cout << "Name of the directory to create: ";
|
std::cout << "Name of the directory to create: ";
|
||||||
std::cin >> directory;
|
std::cin >> directory;
|
||||||
std::cout << server.createDirectory(directory) << std::endl;
|
std::cout << server.createDirectory(directory) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 5 :
|
case 5:
|
||||||
{
|
{
|
||||||
// Remove an existing directory
|
// Remove an existing directory
|
||||||
std::string directory;
|
std::string directory;
|
||||||
std::cout << "Name of the directory to remove: ";
|
std::cout << "Name of the directory to remove: ";
|
||||||
std::cin >> directory;
|
std::cin >> directory;
|
||||||
std::cout << server.deleteDirectory(directory) << std::endl;
|
std::cout << server.deleteDirectory(directory) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 6 :
|
case 6:
|
||||||
{
|
{
|
||||||
// Rename a file
|
// Rename a file
|
||||||
std::string source, destination;
|
std::string source, destination;
|
||||||
std::cout << "Name of the file to rename: ";
|
std::cout << "Name of the file to rename: ";
|
||||||
std::cin >> source;
|
std::cin >> source;
|
||||||
std::cout << "New name: ";
|
std::cout << "New name: ";
|
||||||
std::cin >> destination;
|
std::cin >> destination;
|
||||||
std::cout << server.renameFile(source, destination) << std::endl;
|
std::cout << server.renameFile(source, destination) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 7 :
|
case 7:
|
||||||
{
|
{
|
||||||
// Remove an existing directory
|
// Remove an existing directory
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::cout << "Name of the file to remove: ";
|
std::cout << "Name of the file to remove: ";
|
||||||
std::cin >> filename;
|
std::cin >> filename;
|
||||||
std::cout << server.deleteFile(filename) << std::endl;
|
std::cout << server.deleteFile(filename) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 8 :
|
case 8:
|
||||||
{
|
{
|
||||||
// Download a file from server
|
// Download a file from server
|
||||||
std::string filename, directory;
|
std::string filename, directory;
|
||||||
std::cout << "Filename of the file to download (relative to current directory): ";
|
std::cout << "Filename of the file to download (relative to current directory): ";
|
||||||
std::cin >> filename;
|
std::cin >> filename;
|
||||||
std::cout << "Directory to download the file to: ";
|
std::cout << "Directory to download the file to: ";
|
||||||
std::cin >> directory;
|
std::cin >> directory;
|
||||||
std::cout << server.download(filename, directory) << std::endl;
|
std::cout << server.download(filename, directory) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 9 :
|
case 9:
|
||||||
{
|
{
|
||||||
// Upload a file to server
|
// Upload a file to server
|
||||||
std::string filename, directory;
|
std::string filename, directory;
|
||||||
std::cout << "Path of the file to upload (absolute or relative to working directory): ";
|
std::cout << "Path of the file to upload (absolute or relative to working directory): ";
|
||||||
std::cin >> filename;
|
std::cin >> filename;
|
||||||
std::cout << "Directory to upload the file to (relative to current directory): ";
|
std::cout << "Directory to upload the file to (relative to current directory): ";
|
||||||
std::cin >> directory;
|
std::cin >> directory;
|
||||||
std::cout << server.upload(filename, directory) << std::endl;
|
std::cout << server.upload(filename, directory) << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0 :
|
case 0:
|
||||||
{
|
{
|
||||||
// Disconnect
|
// Disconnect
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (choice != 0);
|
} while (choice != 0);
|
||||||
|
|
||||||
// Disconnect from the server
|
// Disconnect from the server
|
||||||
std::cout << "Disconnecting from server..." << std::endl;
|
std::cout << "Disconnecting from server..." << std::endl;
|
||||||
std::cout << server.disconnect() << std::endl;
|
std::cout << server.disconnect() << std::endl;
|
||||||
|
|
||||||
// Wait until the user presses 'enter' key
|
// Wait until the user presses 'enter' key
|
||||||
std::cout << "Press enter to exit..." << std::endl;
|
std::cout << "Press enter to exit..." << std::endl;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/opengl)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/opengl)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/OpenGL.cpp)
|
set(SRC ${SRCROOT}/OpenGL.cpp)
|
||||||
|
|
||||||
# find OpenGL and GLU
|
# find OpenGL and GLU
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
include_directories(${OPENGL_INCLUDE_DIR})
|
include_directories(${OPENGL_INCLUDE_DIR})
|
||||||
set(ADDITIONAL_LIBRARIES ${OPENGL_LIBRARIES})
|
set(ADDITIONAL_LIBRARIES ${OPENGL_LIBRARIES})
|
||||||
|
|
||||||
# define the opengl target
|
# define the opengl target
|
||||||
sfml_add_example(opengl GUI_APP
|
sfml_add_example(opengl GUI_APP
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-graphics sfml-window sfml-system ${ADDITIONAL_LIBRARIES})
|
DEPENDS sfml-graphics sfml-window sfml-system ${ADDITIONAL_LIBRARIES})
|
||||||
|
|
|
@ -1,198 +1,198 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <SFML/OpenGL.hpp>
|
#include <SFML/OpenGL.hpp>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Request a 32-bits depth buffer when creating the window
|
// Request a 32-bits depth buffer when creating the window
|
||||||
sf::ContextSettings contextSettings;
|
sf::ContextSettings contextSettings;
|
||||||
contextSettings.depthBits = 32;
|
contextSettings.depthBits = 32;
|
||||||
|
|
||||||
// Create the main window
|
// Create the main window
|
||||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings);
|
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings);
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(true);
|
||||||
|
|
||||||
// Create a sprite for the background
|
// Create a sprite for the background
|
||||||
sf::Texture backgroundTexture;
|
sf::Texture backgroundTexture;
|
||||||
if (!backgroundTexture.loadFromFile("resources/background.jpg"))
|
if (!backgroundTexture.loadFromFile("resources/background.jpg"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
sf::Sprite background(backgroundTexture);
|
sf::Sprite background(backgroundTexture);
|
||||||
|
|
||||||
// Create some text to draw on top of our OpenGL object
|
// Create some text to draw on top of our OpenGL object
|
||||||
sf::Font font;
|
sf::Font font;
|
||||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
sf::Text text("SFML / OpenGL demo", font);
|
sf::Text text("SFML / OpenGL demo", font);
|
||||||
text.setColor(sf::Color(255, 255, 255, 170));
|
text.setColor(sf::Color(255, 255, 255, 170));
|
||||||
text.setPosition(250.f, 450.f);
|
text.setPosition(250.f, 450.f);
|
||||||
|
|
||||||
// Make the window the active target for OpenGL calls
|
// Make the window the active target for OpenGL calls
|
||||||
// Note: If using sf::Texture or sf::Shader with OpenGL,
|
// Note: If using sf::Texture or sf::Shader with OpenGL,
|
||||||
// be sure to call sf::Texture::getMaximumSize() and/or
|
// be sure to call sf::Texture::getMaximumSize() and/or
|
||||||
// sf::Shader::isAvailable() at least once before calling
|
// sf::Shader::isAvailable() at least once before calling
|
||||||
// setActive(), as those functions will cause a context switch
|
// setActive(), as those functions will cause a context switch
|
||||||
window.setActive();
|
window.setActive();
|
||||||
|
|
||||||
// Load an OpenGL texture.
|
// Load an OpenGL texture.
|
||||||
// We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
|
// We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
|
||||||
// but here we want more control on it (generate mipmaps, ...) so we create a new one from an image
|
// but here we want more control on it (generate mipmaps, ...) so we create a new one from an image
|
||||||
GLuint texture = 0;
|
GLuint texture = 0;
|
||||||
{
|
{
|
||||||
sf::Image image;
|
sf::Image image;
|
||||||
if (!image.loadFromFile("resources/texture.jpg"))
|
if (!image.loadFromFile("resources/texture.jpg"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &texture);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
|
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable Z-buffer read and write
|
// Enable Z-buffer read and write
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
glClearDepth(1.f);
|
glClearDepth(1.f);
|
||||||
|
|
||||||
// Disable lighting
|
// Disable lighting
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
// Configure the viewport (the same size as the window)
|
// Configure the viewport (the same size as the window)
|
||||||
glViewport(0, 0, window.getSize().x, window.getSize().y);
|
glViewport(0, 0, window.getSize().x, window.getSize().y);
|
||||||
|
|
||||||
// Setup a perspective projection
|
// Setup a perspective projection
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
||||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||||
|
|
||||||
// Bind the texture
|
// Bind the texture
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
|
||||||
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
||||||
GLfloat cube[] =
|
GLfloat cube[] =
|
||||||
{
|
{
|
||||||
// positions // texture coordinates
|
// positions // texture coordinates
|
||||||
-20, -20, -20, 0, 0,
|
-20, -20, -20, 0, 0,
|
||||||
-20, 20, -20, 1, 0,
|
-20, 20, -20, 1, 0,
|
||||||
-20, -20, 20, 0, 1,
|
-20, -20, 20, 0, 1,
|
||||||
-20, -20, 20, 0, 1,
|
-20, -20, 20, 0, 1,
|
||||||
-20, 20, -20, 1, 0,
|
-20, 20, -20, 1, 0,
|
||||||
-20, 20, 20, 1, 1,
|
-20, 20, 20, 1, 1,
|
||||||
|
|
||||||
20, -20, -20, 0, 0,
|
20, -20, -20, 0, 0,
|
||||||
20, 20, -20, 1, 0,
|
20, 20, -20, 1, 0,
|
||||||
20, -20, 20, 0, 1,
|
20, -20, 20, 0, 1,
|
||||||
20, -20, 20, 0, 1,
|
20, -20, 20, 0, 1,
|
||||||
20, 20, -20, 1, 0,
|
20, 20, -20, 1, 0,
|
||||||
20, 20, 20, 1, 1,
|
20, 20, 20, 1, 1,
|
||||||
|
|
||||||
-20, -20, -20, 0, 0,
|
-20, -20, -20, 0, 0,
|
||||||
20, -20, -20, 1, 0,
|
20, -20, -20, 1, 0,
|
||||||
-20, -20, 20, 0, 1,
|
-20, -20, 20, 0, 1,
|
||||||
-20, -20, 20, 0, 1,
|
-20, -20, 20, 0, 1,
|
||||||
20, -20, -20, 1, 0,
|
20, -20, -20, 1, 0,
|
||||||
20, -20, 20, 1, 1,
|
20, -20, 20, 1, 1,
|
||||||
|
|
||||||
-20, 20, -20, 0, 0,
|
-20, 20, -20, 0, 0,
|
||||||
20, 20, -20, 1, 0,
|
20, 20, -20, 1, 0,
|
||||||
-20, 20, 20, 0, 1,
|
-20, 20, 20, 0, 1,
|
||||||
-20, 20, 20, 0, 1,
|
-20, 20, 20, 0, 1,
|
||||||
20, 20, -20, 1, 0,
|
20, 20, -20, 1, 0,
|
||||||
20, 20, 20, 1, 1,
|
20, 20, 20, 1, 1,
|
||||||
|
|
||||||
-20, -20, -20, 0, 0,
|
-20, -20, -20, 0, 0,
|
||||||
20, -20, -20, 1, 0,
|
20, -20, -20, 1, 0,
|
||||||
-20, 20, -20, 0, 1,
|
-20, 20, -20, 0, 1,
|
||||||
-20, 20, -20, 0, 1,
|
-20, 20, -20, 0, 1,
|
||||||
20, -20, -20, 1, 0,
|
20, -20, -20, 1, 0,
|
||||||
20, 20, -20, 1, 1,
|
20, 20, -20, 1, 1,
|
||||||
|
|
||||||
-20, -20, 20, 0, 0,
|
-20, -20, 20, 0, 0,
|
||||||
20, -20, 20, 1, 0,
|
20, -20, 20, 1, 0,
|
||||||
-20, 20, 20, 0, 1,
|
-20, 20, 20, 0, 1,
|
||||||
-20, 20, 20, 0, 1,
|
-20, 20, 20, 0, 1,
|
||||||
20, -20, 20, 1, 0,
|
20, -20, 20, 1, 0,
|
||||||
20, 20, 20, 1, 1
|
20, 20, 20, 1, 1
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enable position and texture coordinates vertex components
|
// Enable position and texture coordinates vertex components
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), cube);
|
glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), cube);
|
||||||
glTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), cube + 3);
|
glTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), cube + 3);
|
||||||
|
|
||||||
// Disable normal and color vertex components
|
// Disable normal and color vertex components
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
// Create a clock for measuring the time elapsed
|
// Create a clock for measuring the time elapsed
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
|
|
||||||
// Start game loop
|
// Start game loop
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
{
|
{
|
||||||
// Process events
|
// Process events
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
{
|
{
|
||||||
// Close window : exit
|
// Close window: exit
|
||||||
if (event.type == sf::Event::Closed)
|
if (event.type == sf::Event::Closed)
|
||||||
window.close();
|
window.close();
|
||||||
|
|
||||||
// Escape key : exit
|
// Escape key: exit
|
||||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
|
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
|
||||||
window.close();
|
window.close();
|
||||||
|
|
||||||
// Adjust the viewport when the window is resized
|
// Adjust the viewport when the window is resized
|
||||||
if (event.type == sf::Event::Resized)
|
if (event.type == sf::Event::Resized)
|
||||||
glViewport(0, 0, event.size.width, event.size.height);
|
glViewport(0, 0, event.size.width, event.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the background
|
// Draw the background
|
||||||
window.pushGLStates();
|
window.pushGLStates();
|
||||||
window.draw(background);
|
window.draw(background);
|
||||||
window.popGLStates();
|
window.popGLStates();
|
||||||
|
|
||||||
// Clear the depth buffer
|
// Clear the depth buffer
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// We get the position of the mouse cursor, so that we can move the box accordingly
|
// We get the position of the mouse cursor, so that we can move the box accordingly
|
||||||
float x = sf::Mouse::getPosition(window).x * 200.f / window.getSize().x - 100.f;
|
float x = sf::Mouse::getPosition(window).x * 200.f / window.getSize().x - 100.f;
|
||||||
float y = -sf::Mouse::getPosition(window).y * 200.f / window.getSize().y + 100.f;
|
float y = -sf::Mouse::getPosition(window).y * 200.f / window.getSize().y + 100.f;
|
||||||
|
|
||||||
// Apply some transformations
|
// Apply some transformations
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(x, y, -100.f);
|
glTranslatef(x, y, -100.f);
|
||||||
glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
|
glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
|
||||||
glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
|
glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
|
||||||
glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);
|
glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);
|
||||||
|
|
||||||
// Draw the cube
|
// Draw the cube
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
|
||||||
// Draw some text on top of our OpenGL object
|
// Draw some text on top of our OpenGL object
|
||||||
window.pushGLStates();
|
window.pushGLStates();
|
||||||
window.draw(text);
|
window.draw(text);
|
||||||
window.popGLStates();
|
window.popGLStates();
|
||||||
|
|
||||||
// Finally, display the rendered frame on screen
|
// Finally, display the rendered frame on screen
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't forget to destroy our texture
|
// Don't forget to destroy our texture
|
||||||
glDeleteTextures(1, &texture);
|
glDeleteTextures(1, &texture);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/pong)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/pong)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/Pong.cpp)
|
set(SRC ${SRCROOT}/Pong.cpp)
|
||||||
|
|
||||||
# define the pong target
|
# define the pong target
|
||||||
sfml_add_example(pong GUI_APP
|
sfml_add_example(pong GUI_APP
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-audio sfml-graphics sfml-window sfml-system)
|
DEPENDS sfml-audio sfml-graphics sfml-window sfml-system)
|
||||||
|
|
|
@ -1,241 +1,241 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::srand(static_cast<unsigned int>(std::time(NULL)));
|
std::srand(static_cast<unsigned int>(std::time(NULL)));
|
||||||
|
|
||||||
// Define some constants
|
// Define some constants
|
||||||
const float pi = 3.14159f;
|
const float pi = 3.14159f;
|
||||||
const int gameWidth = 800;
|
const int gameWidth = 800;
|
||||||
const int gameHeight = 600;
|
const int gameHeight = 600;
|
||||||
sf::Vector2f paddleSize(25, 100);
|
sf::Vector2f paddleSize(25, 100);
|
||||||
float ballRadius = 10.f;
|
float ballRadius = 10.f;
|
||||||
|
|
||||||
// Create the window of the application
|
// Create the window of the application
|
||||||
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong");
|
sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32), "SFML Pong");
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(true);
|
||||||
|
|
||||||
// Load the sounds used in the game
|
// Load the sounds used in the game
|
||||||
sf::SoundBuffer ballSoundBuffer;
|
sf::SoundBuffer ballSoundBuffer;
|
||||||
if (!ballSoundBuffer.loadFromFile("resources/ball.wav"))
|
if (!ballSoundBuffer.loadFromFile("resources/ball.wav"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
sf::Sound ballSound(ballSoundBuffer);
|
sf::Sound ballSound(ballSoundBuffer);
|
||||||
|
|
||||||
// Create the left paddle
|
// Create the left paddle
|
||||||
sf::RectangleShape leftPaddle;
|
sf::RectangleShape leftPaddle;
|
||||||
leftPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
leftPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
||||||
leftPaddle.setOutlineThickness(3);
|
leftPaddle.setOutlineThickness(3);
|
||||||
leftPaddle.setOutlineColor(sf::Color::Black);
|
leftPaddle.setOutlineColor(sf::Color::Black);
|
||||||
leftPaddle.setFillColor(sf::Color(100, 100, 200));
|
leftPaddle.setFillColor(sf::Color(100, 100, 200));
|
||||||
leftPaddle.setOrigin(paddleSize / 2.f);
|
leftPaddle.setOrigin(paddleSize / 2.f);
|
||||||
|
|
||||||
// Create the right paddle
|
// Create the right paddle
|
||||||
sf::RectangleShape rightPaddle;
|
sf::RectangleShape rightPaddle;
|
||||||
rightPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
rightPaddle.setSize(paddleSize - sf::Vector2f(3, 3));
|
||||||
rightPaddle.setOutlineThickness(3);
|
rightPaddle.setOutlineThickness(3);
|
||||||
rightPaddle.setOutlineColor(sf::Color::Black);
|
rightPaddle.setOutlineColor(sf::Color::Black);
|
||||||
rightPaddle.setFillColor(sf::Color(200, 100, 100));
|
rightPaddle.setFillColor(sf::Color(200, 100, 100));
|
||||||
rightPaddle.setOrigin(paddleSize / 2.f);
|
rightPaddle.setOrigin(paddleSize / 2.f);
|
||||||
|
|
||||||
// Create the ball
|
// Create the ball
|
||||||
sf::CircleShape ball;
|
sf::CircleShape ball;
|
||||||
ball.setRadius(ballRadius - 3);
|
ball.setRadius(ballRadius - 3);
|
||||||
ball.setOutlineThickness(3);
|
ball.setOutlineThickness(3);
|
||||||
ball.setOutlineColor(sf::Color::Black);
|
ball.setOutlineColor(sf::Color::Black);
|
||||||
ball.setFillColor(sf::Color::White);
|
ball.setFillColor(sf::Color::White);
|
||||||
ball.setOrigin(ballRadius / 2, ballRadius / 2);
|
ball.setOrigin(ballRadius / 2, ballRadius / 2);
|
||||||
|
|
||||||
// Load the text font
|
// Load the text font
|
||||||
sf::Font font;
|
sf::Font font;
|
||||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
// Initialize the pause message
|
// Initialize the pause message
|
||||||
sf::Text pauseMessage;
|
sf::Text pauseMessage;
|
||||||
pauseMessage.setFont(font);
|
pauseMessage.setFont(font);
|
||||||
pauseMessage.setCharacterSize(40);
|
pauseMessage.setCharacterSize(40);
|
||||||
pauseMessage.setPosition(170.f, 150.f);
|
pauseMessage.setPosition(170.f, 150.f);
|
||||||
pauseMessage.setColor(sf::Color::White);
|
pauseMessage.setColor(sf::Color::White);
|
||||||
pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game");
|
pauseMessage.setString("Welcome to SFML pong!\nPress space to start the game");
|
||||||
|
|
||||||
// Define the paddles properties
|
// Define the paddles properties
|
||||||
sf::Clock AITimer;
|
sf::Clock AITimer;
|
||||||
const sf::Time AITime = sf::seconds(0.1f);
|
const sf::Time AITime = sf::seconds(0.1f);
|
||||||
const float paddleSpeed = 400.f;
|
const float paddleSpeed = 400.f;
|
||||||
float rightPaddleSpeed = 0.f;
|
float rightPaddleSpeed = 0.f;
|
||||||
const float ballSpeed = 400.f;
|
const float ballSpeed = 400.f;
|
||||||
float ballAngle = 0.f; // to be changed later
|
float ballAngle = 0.f; // to be changed later
|
||||||
|
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
bool isPlaying = false;
|
bool isPlaying = false;
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
{
|
{
|
||||||
// Handle events
|
// Handle events
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
{
|
{
|
||||||
// Window closed or escape key pressed: exit
|
// Window closed or escape key pressed: exit
|
||||||
if ((event.type == sf::Event::Closed) ||
|
if ((event.type == sf::Event::Closed) ||
|
||||||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
|
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
|
||||||
{
|
{
|
||||||
window.close();
|
window.close();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Space key pressed: play
|
// Space key pressed: play
|
||||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
|
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
|
||||||
{
|
{
|
||||||
if (!isPlaying)
|
if (!isPlaying)
|
||||||
{
|
{
|
||||||
// (re)start the game
|
// (re)start the game
|
||||||
isPlaying = true;
|
isPlaying = true;
|
||||||
clock.restart();
|
clock.restart();
|
||||||
|
|
||||||
// Reset the position of the paddles and ball
|
// Reset the position of the paddles and ball
|
||||||
leftPaddle.setPosition(10 + paddleSize.x / 2, gameHeight / 2);
|
leftPaddle.setPosition(10 + paddleSize.x / 2, gameHeight / 2);
|
||||||
rightPaddle.setPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2);
|
rightPaddle.setPosition(gameWidth - 10 - paddleSize.x / 2, gameHeight / 2);
|
||||||
ball.setPosition(gameWidth / 2, gameHeight / 2);
|
ball.setPosition(gameWidth / 2, gameHeight / 2);
|
||||||
|
|
||||||
// Reset the ball angle
|
// Reset the ball angle
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Make sure the ball initial angle is not too much vertical
|
// Make sure the ball initial angle is not too much vertical
|
||||||
ballAngle = (std::rand() % 360) * 2 * pi / 360;
|
ballAngle = (std::rand() % 360) * 2 * pi / 360;
|
||||||
}
|
}
|
||||||
while (std::abs(std::cos(ballAngle)) < 0.7f);
|
while (std::abs(std::cos(ballAngle)) < 0.7f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPlaying)
|
if (isPlaying)
|
||||||
{
|
{
|
||||||
float deltaTime = clock.restart().asSeconds();
|
float deltaTime = clock.restart().asSeconds();
|
||||||
|
|
||||||
// Move the player's paddle
|
// Move the player's paddle
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) &&
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) &&
|
||||||
(leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f))
|
(leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f))
|
||||||
{
|
{
|
||||||
leftPaddle.move(0.f, -paddleSpeed * deltaTime);
|
leftPaddle.move(0.f, -paddleSpeed * deltaTime);
|
||||||
}
|
}
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) &&
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) &&
|
||||||
(leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))
|
(leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f))
|
||||||
{
|
{
|
||||||
leftPaddle.move(0.f, paddleSpeed * deltaTime);
|
leftPaddle.move(0.f, paddleSpeed * deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the computer's paddle
|
// Move the computer's paddle
|
||||||
if (((rightPaddleSpeed < 0.f) && (rightPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) ||
|
if (((rightPaddleSpeed < 0.f) && (rightPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) ||
|
||||||
((rightPaddleSpeed > 0.f) && (rightPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)))
|
((rightPaddleSpeed > 0.f) && (rightPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)))
|
||||||
{
|
{
|
||||||
rightPaddle.move(0.f, rightPaddleSpeed * deltaTime);
|
rightPaddle.move(0.f, rightPaddleSpeed * deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the computer's paddle direction according to the ball position
|
// Update the computer's paddle direction according to the ball position
|
||||||
if (AITimer.getElapsedTime() > AITime)
|
if (AITimer.getElapsedTime() > AITime)
|
||||||
{
|
{
|
||||||
AITimer.restart();
|
AITimer.restart();
|
||||||
if (ball.getPosition().y + ballRadius > rightPaddle.getPosition().y + paddleSize.y / 2)
|
if (ball.getPosition().y + ballRadius > rightPaddle.getPosition().y + paddleSize.y / 2)
|
||||||
rightPaddleSpeed = paddleSpeed;
|
rightPaddleSpeed = paddleSpeed;
|
||||||
else if (ball.getPosition().y - ballRadius < rightPaddle.getPosition().y - paddleSize.y / 2)
|
else if (ball.getPosition().y - ballRadius < rightPaddle.getPosition().y - paddleSize.y / 2)
|
||||||
rightPaddleSpeed = -paddleSpeed;
|
rightPaddleSpeed = -paddleSpeed;
|
||||||
else
|
else
|
||||||
rightPaddleSpeed = 0.f;
|
rightPaddleSpeed = 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the ball
|
// Move the ball
|
||||||
float factor = ballSpeed * deltaTime;
|
float factor = ballSpeed * deltaTime;
|
||||||
ball.move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
|
ball.move(std::cos(ballAngle) * factor, std::sin(ballAngle) * factor);
|
||||||
|
|
||||||
// Check collisions between the ball and the screen
|
// Check collisions between the ball and the screen
|
||||||
if (ball.getPosition().x - ballRadius < 0.f)
|
if (ball.getPosition().x - ballRadius < 0.f)
|
||||||
{
|
{
|
||||||
isPlaying = false;
|
isPlaying = false;
|
||||||
pauseMessage.setString("You lost!\nPress space to restart or\nescape to exit");
|
pauseMessage.setString("You lost!\nPress space to restart or\nescape to exit");
|
||||||
}
|
}
|
||||||
if (ball.getPosition().x + ballRadius > gameWidth)
|
if (ball.getPosition().x + ballRadius > gameWidth)
|
||||||
{
|
{
|
||||||
isPlaying = false;
|
isPlaying = false;
|
||||||
pauseMessage.setString("You won!\nPress space to restart or\nescape to exit");
|
pauseMessage.setString("You won!\nPress space to restart or\nescape to exit");
|
||||||
}
|
}
|
||||||
if (ball.getPosition().y - ballRadius < 0.f)
|
if (ball.getPosition().y - ballRadius < 0.f)
|
||||||
{
|
{
|
||||||
ballSound.play();
|
ballSound.play();
|
||||||
ballAngle = -ballAngle;
|
ballAngle = -ballAngle;
|
||||||
ball.setPosition(ball.getPosition().x, ballRadius + 0.1f);
|
ball.setPosition(ball.getPosition().x, ballRadius + 0.1f);
|
||||||
}
|
}
|
||||||
if (ball.getPosition().y + ballRadius > gameHeight)
|
if (ball.getPosition().y + ballRadius > gameHeight)
|
||||||
{
|
{
|
||||||
ballSound.play();
|
ballSound.play();
|
||||||
ballAngle = -ballAngle;
|
ballAngle = -ballAngle;
|
||||||
ball.setPosition(ball.getPosition().x, gameHeight - ballRadius - 0.1f);
|
ball.setPosition(ball.getPosition().x, gameHeight - ballRadius - 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the collisions between the ball and the paddles
|
// Check the collisions between the ball and the paddles
|
||||||
// Left Paddle
|
// Left Paddle
|
||||||
if (ball.getPosition().x - ballRadius < leftPaddle.getPosition().x + paddleSize.x / 2 &&
|
if (ball.getPosition().x - ballRadius < leftPaddle.getPosition().x + paddleSize.x / 2 &&
|
||||||
ball.getPosition().x - ballRadius > leftPaddle.getPosition().x &&
|
ball.getPosition().x - ballRadius > leftPaddle.getPosition().x &&
|
||||||
ball.getPosition().y + ballRadius >= leftPaddle.getPosition().y - paddleSize.y / 2 &&
|
ball.getPosition().y + ballRadius >= leftPaddle.getPosition().y - paddleSize.y / 2 &&
|
||||||
ball.getPosition().y - ballRadius <= leftPaddle.getPosition().y + paddleSize.y / 2)
|
ball.getPosition().y - ballRadius <= leftPaddle.getPosition().y + paddleSize.y / 2)
|
||||||
{
|
{
|
||||||
if (ball.getPosition().y > leftPaddle.getPosition().y)
|
if (ball.getPosition().y > leftPaddle.getPosition().y)
|
||||||
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
||||||
else
|
else
|
||||||
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
||||||
|
|
||||||
ballSound.play();
|
ballSound.play();
|
||||||
ball.setPosition(leftPaddle.getPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.getPosition().y);
|
ball.setPosition(leftPaddle.getPosition().x + ballRadius + paddleSize.x / 2 + 0.1f, ball.getPosition().y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right Paddle
|
// Right Paddle
|
||||||
if (ball.getPosition().x + ballRadius > rightPaddle.getPosition().x - paddleSize.x / 2 &&
|
if (ball.getPosition().x + ballRadius > rightPaddle.getPosition().x - paddleSize.x / 2 &&
|
||||||
ball.getPosition().x + ballRadius < rightPaddle.getPosition().x &&
|
ball.getPosition().x + ballRadius < rightPaddle.getPosition().x &&
|
||||||
ball.getPosition().y + ballRadius >= rightPaddle.getPosition().y - paddleSize.y / 2 &&
|
ball.getPosition().y + ballRadius >= rightPaddle.getPosition().y - paddleSize.y / 2 &&
|
||||||
ball.getPosition().y - ballRadius <= rightPaddle.getPosition().y + paddleSize.y / 2)
|
ball.getPosition().y - ballRadius <= rightPaddle.getPosition().y + paddleSize.y / 2)
|
||||||
{
|
{
|
||||||
if (ball.getPosition().y > rightPaddle.getPosition().y)
|
if (ball.getPosition().y > rightPaddle.getPosition().y)
|
||||||
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
ballAngle = pi - ballAngle + (std::rand() % 20) * pi / 180;
|
||||||
else
|
else
|
||||||
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
ballAngle = pi - ballAngle - (std::rand() % 20) * pi / 180;
|
||||||
|
|
||||||
ballSound.play();
|
ballSound.play();
|
||||||
ball.setPosition(rightPaddle.getPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.getPosition().y);
|
ball.setPosition(rightPaddle.getPosition().x - ballRadius - paddleSize.x / 2 - 0.1f, ball.getPosition().y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the window
|
// Clear the window
|
||||||
window.clear(sf::Color(50, 200, 50));
|
window.clear(sf::Color(50, 200, 50));
|
||||||
|
|
||||||
if (isPlaying)
|
if (isPlaying)
|
||||||
{
|
{
|
||||||
// Draw the paddles and the ball
|
// Draw the paddles and the ball
|
||||||
window.draw(leftPaddle);
|
window.draw(leftPaddle);
|
||||||
window.draw(rightPaddle);
|
window.draw(rightPaddle);
|
||||||
window.draw(ball);
|
window.draw(ball);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Draw the pause message
|
// Draw the pause message
|
||||||
window.draw(pauseMessage);
|
window.draw(pauseMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display things on screen
|
// Display things on screen
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/shader)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/shader)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC
|
set(SRC
|
||||||
${SRCROOT}/Effect.hpp
|
${SRCROOT}/Effect.hpp
|
||||||
${SRCROOT}/Shader.cpp)
|
${SRCROOT}/Shader.cpp)
|
||||||
|
|
||||||
# define the shader target
|
# define the shader target
|
||||||
sfml_add_example(shader GUI_APP
|
sfml_add_example(shader GUI_APP
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-graphics sfml-window sfml-system)
|
DEPENDS sfml-graphics sfml-window sfml-system)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class Effect : public sf::Drawable
|
class Effect : public sf::Drawable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
virtual ~Effect()
|
virtual ~Effect()
|
||||||
{
|
{
|
||||||
|
@ -56,7 +56,7 @@ public :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
Effect(const std::string& name) :
|
Effect(const std::string& name) :
|
||||||
m_name(name),
|
m_name(name),
|
||||||
|
@ -70,14 +70,14 @@ protected :
|
||||||
return *s_font;
|
return *s_font;
|
||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
// Virtual functions to be implemented in derived effects
|
// Virtual functions to be implemented in derived effects
|
||||||
virtual bool onLoad() = 0;
|
virtual bool onLoad() = 0;
|
||||||
virtual void onUpdate(float time, float x, float y) = 0;
|
virtual void onUpdate(float time, float x, float y) = 0;
|
||||||
virtual void onDraw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
|
virtual void onDraw(sf::RenderTarget& target, sf::RenderStates states) const = 0;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
bool m_isLoaded;
|
bool m_isLoaded;
|
||||||
|
|
|
@ -1,379 +1,379 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include "Effect.hpp"
|
#include "Effect.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
const sf::Font* Effect::s_font = NULL;
|
const sf::Font* Effect::s_font = NULL;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// "Pixelate" fragment shader
|
// "Pixelate" fragment shader
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class Pixelate : public Effect
|
class Pixelate : public Effect
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
Pixelate() :
|
Pixelate() :
|
||||||
Effect("pixelate")
|
Effect("pixelate")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onLoad()
|
bool onLoad()
|
||||||
{
|
{
|
||||||
// Load the texture and initialize the sprite
|
// Load the texture and initialize the sprite
|
||||||
if (!m_texture.loadFromFile("resources/background.jpg"))
|
if (!m_texture.loadFromFile("resources/background.jpg"))
|
||||||
return false;
|
return false;
|
||||||
m_sprite.setTexture(m_texture);
|
m_sprite.setTexture(m_texture);
|
||||||
|
|
||||||
// Load the shader
|
// Load the shader
|
||||||
if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
|
if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Fragment))
|
||||||
return false;
|
return false;
|
||||||
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
|
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate(float, float x, float y)
|
void onUpdate(float, float x, float y)
|
||||||
{
|
{
|
||||||
m_shader.setParameter("pixel_threshold", (x + y) / 30);
|
m_shader.setParameter("pixel_threshold", (x + y) / 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
{
|
{
|
||||||
states.shader = &m_shader;
|
states.shader = &m_shader;
|
||||||
target.draw(m_sprite, states);
|
target.draw(m_sprite, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
sf::Texture m_texture;
|
sf::Texture m_texture;
|
||||||
sf::Sprite m_sprite;
|
sf::Sprite m_sprite;
|
||||||
sf::Shader m_shader;
|
sf::Shader m_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// "Wave" vertex shader + "blur" fragment shader
|
// "Wave" vertex shader + "blur" fragment shader
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class WaveBlur : public Effect
|
class WaveBlur : public Effect
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
WaveBlur() :
|
WaveBlur() :
|
||||||
Effect("wave + blur")
|
Effect("wave + blur")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onLoad()
|
bool onLoad()
|
||||||
{
|
{
|
||||||
// Create the text
|
// Create the text
|
||||||
m_text.setString("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n"
|
m_text.setString("Praesent suscipit augue in velit pulvinar hendrerit varius purus aliquam.\n"
|
||||||
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n"
|
"Mauris mi odio, bibendum quis fringilla a, laoreet vel orci. Proin vitae vulputate tortor.\n"
|
||||||
"Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n"
|
"Praesent cursus ultrices justo, ut feugiat ante vehicula quis.\n"
|
||||||
"Donec fringilla scelerisque mauris et viverra.\n"
|
"Donec fringilla scelerisque mauris et viverra.\n"
|
||||||
"Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n"
|
"Maecenas adipiscing ornare scelerisque. Nullam at libero elit.\n"
|
||||||
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n"
|
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n"
|
||||||
"Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n"
|
"Nullam leo urna, tincidunt id semper eget, ultricies sed mi.\n"
|
||||||
"Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n"
|
"Morbi mauris massa, commodo id dignissim vel, lobortis et elit.\n"
|
||||||
"Fusce vel libero sed neque scelerisque venenatis.\n"
|
"Fusce vel libero sed neque scelerisque venenatis.\n"
|
||||||
"Integer mattis tincidunt quam vitae iaculis.\n"
|
"Integer mattis tincidunt quam vitae iaculis.\n"
|
||||||
"Vivamus fringilla sem non velit venenatis fermentum.\n"
|
"Vivamus fringilla sem non velit venenatis fermentum.\n"
|
||||||
"Vivamus varius tincidunt nisi id vehicula.\n"
|
"Vivamus varius tincidunt nisi id vehicula.\n"
|
||||||
"Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n"
|
"Integer ullamcorper, enim vitae euismod rutrum, massa nisl semper ipsum,\n"
|
||||||
"vestibulum sodales sem ante in massa.\n"
|
"vestibulum sodales sem ante in massa.\n"
|
||||||
"Vestibulum in augue non felis convallis viverra.\n"
|
"Vestibulum in augue non felis convallis viverra.\n"
|
||||||
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n"
|
"Mauris ultricies dolor sed massa convallis sed aliquet augue fringilla.\n"
|
||||||
"Duis erat eros, porta in accumsan in, blandit quis sem.\n"
|
"Duis erat eros, porta in accumsan in, blandit quis sem.\n"
|
||||||
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n");
|
"In hac habitasse platea dictumst. Etiam fringilla est id odio dapibus sit amet semper dui laoreet.\n");
|
||||||
m_text.setFont(getFont());
|
m_text.setFont(getFont());
|
||||||
m_text.setCharacterSize(22);
|
m_text.setCharacterSize(22);
|
||||||
m_text.setPosition(30, 20);
|
m_text.setPosition(30, 20);
|
||||||
|
|
||||||
// Load the shader
|
// Load the shader
|
||||||
if (!m_shader.loadFromFile("resources/wave.vert", "resources/blur.frag"))
|
if (!m_shader.loadFromFile("resources/wave.vert", "resources/blur.frag"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate(float time, float x, float y)
|
void onUpdate(float time, float x, float y)
|
||||||
{
|
{
|
||||||
m_shader.setParameter("wave_phase", time);
|
m_shader.setParameter("wave_phase", time);
|
||||||
m_shader.setParameter("wave_amplitude", x * 40, y * 40);
|
m_shader.setParameter("wave_amplitude", x * 40, y * 40);
|
||||||
m_shader.setParameter("blur_radius", (x + y) * 0.008f);
|
m_shader.setParameter("blur_radius", (x + y) * 0.008f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
{
|
{
|
||||||
states.shader = &m_shader;
|
states.shader = &m_shader;
|
||||||
target.draw(m_text, states);
|
target.draw(m_text, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
sf::Text m_text;
|
sf::Text m_text;
|
||||||
sf::Shader m_shader;
|
sf::Shader m_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// "Storm" vertex shader + "blink" fragment shader
|
// "Storm" vertex shader + "blink" fragment shader
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class StormBlink : public Effect
|
class StormBlink : public Effect
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
StormBlink() :
|
StormBlink() :
|
||||||
Effect("storm + blink")
|
Effect("storm + blink")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onLoad()
|
bool onLoad()
|
||||||
{
|
{
|
||||||
// Create the points
|
// Create the points
|
||||||
m_points.setPrimitiveType(sf::Points);
|
m_points.setPrimitiveType(sf::Points);
|
||||||
for (int i = 0; i < 40000; ++i)
|
for (int i = 0; i < 40000; ++i)
|
||||||
{
|
{
|
||||||
float x = static_cast<float>(std::rand() % 800);
|
float x = static_cast<float>(std::rand() % 800);
|
||||||
float y = static_cast<float>(std::rand() % 600);
|
float y = static_cast<float>(std::rand() % 600);
|
||||||
sf::Uint8 r = std::rand() % 255;
|
sf::Uint8 r = std::rand() % 255;
|
||||||
sf::Uint8 g = std::rand() % 255;
|
sf::Uint8 g = std::rand() % 255;
|
||||||
sf::Uint8 b = std::rand() % 255;
|
sf::Uint8 b = std::rand() % 255;
|
||||||
m_points.append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b)));
|
m_points.append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the shader
|
// Load the shader
|
||||||
if (!m_shader.loadFromFile("resources/storm.vert", "resources/blink.frag"))
|
if (!m_shader.loadFromFile("resources/storm.vert", "resources/blink.frag"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate(float time, float x, float y)
|
void onUpdate(float time, float x, float y)
|
||||||
{
|
{
|
||||||
float radius = 200 + std::cos(time) * 150;
|
float radius = 200 + std::cos(time) * 150;
|
||||||
m_shader.setParameter("storm_position", x * 800, y * 600);
|
m_shader.setParameter("storm_position", x * 800, y * 600);
|
||||||
m_shader.setParameter("storm_inner_radius", radius / 3);
|
m_shader.setParameter("storm_inner_radius", radius / 3);
|
||||||
m_shader.setParameter("storm_total_radius", radius);
|
m_shader.setParameter("storm_total_radius", radius);
|
||||||
m_shader.setParameter("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
|
m_shader.setParameter("blink_alpha", 0.5f + std::cos(time * 3) * 0.25f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
{
|
{
|
||||||
states.shader = &m_shader;
|
states.shader = &m_shader;
|
||||||
target.draw(m_points, states);
|
target.draw(m_points, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
sf::VertexArray m_points;
|
sf::VertexArray m_points;
|
||||||
sf::Shader m_shader;
|
sf::Shader m_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// "Edge" post-effect fragment shader
|
// "Edge" post-effect fragment shader
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class Edge : public Effect
|
class Edge : public Effect
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
Edge() :
|
Edge() :
|
||||||
Effect("edge post-effect")
|
Effect("edge post-effect")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onLoad()
|
bool onLoad()
|
||||||
{
|
{
|
||||||
// Create the off-screen surface
|
// Create the off-screen surface
|
||||||
if (!m_surface.create(800, 600))
|
if (!m_surface.create(800, 600))
|
||||||
return false;
|
return false;
|
||||||
m_surface.setSmooth(true);
|
m_surface.setSmooth(true);
|
||||||
|
|
||||||
// Load the textures
|
// Load the textures
|
||||||
if (!m_backgroundTexture.loadFromFile("resources/sfml.png"))
|
if (!m_backgroundTexture.loadFromFile("resources/sfml.png"))
|
||||||
return false;
|
return false;
|
||||||
m_backgroundTexture.setSmooth(true);
|
m_backgroundTexture.setSmooth(true);
|
||||||
if (!m_entityTexture.loadFromFile("resources/devices.png"))
|
if (!m_entityTexture.loadFromFile("resources/devices.png"))
|
||||||
return false;
|
return false;
|
||||||
m_entityTexture.setSmooth(true);
|
m_entityTexture.setSmooth(true);
|
||||||
|
|
||||||
// Initialize the background sprite
|
// Initialize the background sprite
|
||||||
m_backgroundSprite.setTexture(m_backgroundTexture);
|
m_backgroundSprite.setTexture(m_backgroundTexture);
|
||||||
m_backgroundSprite.setPosition(135, 100);
|
m_backgroundSprite.setPosition(135, 100);
|
||||||
|
|
||||||
// Load the moving entities
|
// Load the moving entities
|
||||||
for (int i = 0; i < 6; ++i)
|
for (int i = 0; i < 6; ++i)
|
||||||
{
|
{
|
||||||
sf::Sprite entity(m_entityTexture, sf::IntRect(96 * i, 0, 96, 96));
|
sf::Sprite entity(m_entityTexture, sf::IntRect(96 * i, 0, 96, 96));
|
||||||
m_entities.push_back(entity);
|
m_entities.push_back(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the shader
|
// Load the shader
|
||||||
if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Fragment))
|
if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Fragment))
|
||||||
return false;
|
return false;
|
||||||
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
|
m_shader.setParameter("texture", sf::Shader::CurrentTexture);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate(float time, float x, float y)
|
void onUpdate(float time, float x, float y)
|
||||||
{
|
{
|
||||||
m_shader.setParameter("edge_threshold", 1 - (x + y) / 2);
|
m_shader.setParameter("edge_threshold", 1 - (x + y) / 2);
|
||||||
|
|
||||||
// Update the position of the moving entities
|
// Update the position of the moving entities
|
||||||
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
||||||
{
|
{
|
||||||
sf::Vector2f position;
|
sf::Vector2f position;
|
||||||
position.x = std::cos(0.25f * (time * i + (m_entities.size() - i))) * 300 + 350;
|
position.x = std::cos(0.25f * (time * i + (m_entities.size() - i))) * 300 + 350;
|
||||||
position.y = std::sin(0.25f * (time * (m_entities.size() - i) + i)) * 200 + 250;
|
position.y = std::sin(0.25f * (time * (m_entities.size() - i) + i)) * 200 + 250;
|
||||||
m_entities[i].setPosition(position);
|
m_entities[i].setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the updated scene to the off-screen surface
|
// Render the updated scene to the off-screen surface
|
||||||
m_surface.clear(sf::Color::White);
|
m_surface.clear(sf::Color::White);
|
||||||
m_surface.draw(m_backgroundSprite);
|
m_surface.draw(m_backgroundSprite);
|
||||||
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
for (std::size_t i = 0; i < m_entities.size(); ++i)
|
||||||
m_surface.draw(m_entities[i]);
|
m_surface.draw(m_entities[i]);
|
||||||
m_surface.display();
|
m_surface.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
void onDraw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
{
|
{
|
||||||
states.shader = &m_shader;
|
states.shader = &m_shader;
|
||||||
target.draw(sf::Sprite(m_surface.getTexture()), states);
|
target.draw(sf::Sprite(m_surface.getTexture()), states);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
sf::RenderTexture m_surface;
|
sf::RenderTexture m_surface;
|
||||||
sf::Texture m_backgroundTexture;
|
sf::Texture m_backgroundTexture;
|
||||||
sf::Texture m_entityTexture;
|
sf::Texture m_entityTexture;
|
||||||
sf::Sprite m_backgroundSprite;
|
sf::Sprite m_backgroundSprite;
|
||||||
std::vector<sf::Sprite> m_entities;
|
std::vector<sf::Sprite> m_entities;
|
||||||
sf::Shader m_shader;
|
sf::Shader m_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Create the main window
|
// Create the main window
|
||||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
|
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(true);
|
||||||
|
|
||||||
// Load the application font and pass it to the Effect class
|
// Load the application font and pass it to the Effect class
|
||||||
sf::Font font;
|
sf::Font font;
|
||||||
if (!font.loadFromFile("resources/sansation.ttf"))
|
if (!font.loadFromFile("resources/sansation.ttf"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
Effect::setFont(font);
|
Effect::setFont(font);
|
||||||
|
|
||||||
// Create the effects
|
// Create the effects
|
||||||
std::vector<Effect*> effects;
|
std::vector<Effect*> effects;
|
||||||
effects.push_back(new Pixelate);
|
effects.push_back(new Pixelate);
|
||||||
effects.push_back(new WaveBlur);
|
effects.push_back(new WaveBlur);
|
||||||
effects.push_back(new StormBlink);
|
effects.push_back(new StormBlink);
|
||||||
effects.push_back(new Edge);
|
effects.push_back(new Edge);
|
||||||
std::size_t current = 0;
|
std::size_t current = 0;
|
||||||
|
|
||||||
// Initialize them
|
// Initialize them
|
||||||
for (std::size_t i = 0; i < effects.size(); ++i)
|
for (std::size_t i = 0; i < effects.size(); ++i)
|
||||||
effects[i]->load();
|
effects[i]->load();
|
||||||
|
|
||||||
// Create the messages background
|
// Create the messages background
|
||||||
sf::Texture textBackgroundTexture;
|
sf::Texture textBackgroundTexture;
|
||||||
if (!textBackgroundTexture.loadFromFile("resources/text-background.png"))
|
if (!textBackgroundTexture.loadFromFile("resources/text-background.png"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
sf::Sprite textBackground(textBackgroundTexture);
|
sf::Sprite textBackground(textBackgroundTexture);
|
||||||
textBackground.setPosition(0, 520);
|
textBackground.setPosition(0, 520);
|
||||||
textBackground.setColor(sf::Color(255, 255, 255, 200));
|
textBackground.setColor(sf::Color(255, 255, 255, 200));
|
||||||
|
|
||||||
// Create the description text
|
// Create the description text
|
||||||
sf::Text description("Current effect: " + effects[current]->getName(), font, 20);
|
sf::Text description("Current effect: " + effects[current]->getName(), font, 20);
|
||||||
description.setPosition(10, 530);
|
description.setPosition(10, 530);
|
||||||
description.setColor(sf::Color(80, 80, 80));
|
description.setColor(sf::Color(80, 80, 80));
|
||||||
|
|
||||||
// Create the instructions text
|
// Create the instructions text
|
||||||
sf::Text instructions("Press left and right arrows to change the current shader", font, 20);
|
sf::Text instructions("Press left and right arrows to change the current shader", font, 20);
|
||||||
instructions.setPosition(280, 555);
|
instructions.setPosition(280, 555);
|
||||||
instructions.setColor(sf::Color(80, 80, 80));
|
instructions.setColor(sf::Color(80, 80, 80));
|
||||||
|
|
||||||
// Start the game loop
|
// Start the game loop
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
{
|
{
|
||||||
// Process events
|
// Process events
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
{
|
{
|
||||||
// Close window: exit
|
// Close window: exit
|
||||||
if (event.type == sf::Event::Closed)
|
if (event.type == sf::Event::Closed)
|
||||||
window.close();
|
window.close();
|
||||||
|
|
||||||
if (event.type == sf::Event::KeyPressed)
|
if (event.type == sf::Event::KeyPressed)
|
||||||
{
|
{
|
||||||
switch (event.key.code)
|
switch (event.key.code)
|
||||||
{
|
{
|
||||||
// Escape key: exit
|
// Escape key: exit
|
||||||
case sf::Keyboard::Escape:
|
case sf::Keyboard::Escape:
|
||||||
window.close();
|
window.close();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Left arrow key: previous shader
|
// Left arrow key: previous shader
|
||||||
case sf::Keyboard::Left:
|
case sf::Keyboard::Left:
|
||||||
if (current == 0)
|
if (current == 0)
|
||||||
current = effects.size() - 1;
|
current = effects.size() - 1;
|
||||||
else
|
else
|
||||||
current--;
|
current--;
|
||||||
description.setString("Current effect: " + effects[current]->getName());
|
description.setString("Current effect: " + effects[current]->getName());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Right arrow key: next shader
|
// Right arrow key: next shader
|
||||||
case sf::Keyboard::Right:
|
case sf::Keyboard::Right:
|
||||||
if (current == effects.size() - 1)
|
if (current == effects.size() - 1)
|
||||||
current = 0;
|
current = 0;
|
||||||
else
|
else
|
||||||
current++;
|
current++;
|
||||||
description.setString("Current effect: " + effects[current]->getName());
|
description.setString("Current effect: " + effects[current]->getName());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the current example
|
// Update the current example
|
||||||
float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
|
float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
|
||||||
float y = static_cast<float>(sf::Mouse::getPosition(window).y) / window.getSize().y;
|
float y = static_cast<float>(sf::Mouse::getPosition(window).y) / window.getSize().y;
|
||||||
effects[current]->update(clock.getElapsedTime().asSeconds(), x, y);
|
effects[current]->update(clock.getElapsedTime().asSeconds(), x, y);
|
||||||
|
|
||||||
// Clear the window
|
// Clear the window
|
||||||
window.clear(sf::Color(255, 128, 0));
|
window.clear(sf::Color(255, 128, 0));
|
||||||
|
|
||||||
// Draw the current example
|
// Draw the current example
|
||||||
window.draw(*effects[current]);
|
window.draw(*effects[current]);
|
||||||
|
|
||||||
// Draw the text
|
// Draw the text
|
||||||
window.draw(textBackground);
|
window.draw(textBackground);
|
||||||
window.draw(instructions);
|
window.draw(instructions);
|
||||||
window.draw(description);
|
window.draw(description);
|
||||||
|
|
||||||
// Finally, display the rendered frame on screen
|
// Finally, display the rendered frame on screen
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the effects
|
// delete the effects
|
||||||
for (std::size_t i = 0; i < effects.size(); ++i)
|
for (std::size_t i = 0; i < effects.size(); ++i)
|
||||||
delete effects[i];
|
delete effects[i];
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
uniform float blur_radius;
|
uniform float blur_radius;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 offx = vec2(blur_radius, 0.0);
|
vec2 offx = vec2(blur_radius, 0.0);
|
||||||
vec2 offy = vec2(0.0, blur_radius);
|
vec2 offy = vec2(0.0, blur_radius);
|
||||||
|
|
||||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
|
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
|
texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
||||||
|
|
||||||
gl_FragColor = gl_Color * (pixel / 16.0);
|
gl_FragColor = gl_Color * (pixel / 16.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
uniform float edge_threshold;
|
uniform float edge_threshold;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
const float offset = 1.0 / 512.0;
|
const float offset = 1.0 / 512.0;
|
||||||
vec2 offx = vec2(offset, 0.0);
|
vec2 offx = vec2(offset, 0.0);
|
||||||
vec2 offy = vec2(0.0, offset);
|
vec2 offy = vec2(0.0, offset);
|
||||||
|
|
||||||
vec4 hEdge = texture2D(texture, gl_TexCoord[0].xy - offy) * -2.0 +
|
vec4 hEdge = texture2D(texture, gl_TexCoord[0].xy - offy) * -2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * -1.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * -1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * -1.0 +
|
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * -1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
||||||
|
|
||||||
vec4 vEdge = texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
vec4 vEdge = texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx) * -2.0 +
|
texture2D(texture, gl_TexCoord[0].xy + offx) * -2.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * -1.0 +
|
texture2D(texture, gl_TexCoord[0].xy - offx + offy) * -1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
||||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * -1.0;
|
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * -1.0;
|
||||||
|
|
||||||
vec3 result = sqrt(hEdge.rgb * hEdge.rgb + vEdge.rgb * vEdge.rgb);
|
vec3 result = sqrt(hEdge.rgb * hEdge.rgb + vEdge.rgb * vEdge.rgb);
|
||||||
float edge = length(result);
|
float edge = length(result);
|
||||||
vec4 pixel = gl_Color * texture2D(texture, gl_TexCoord[0].xy);
|
vec4 pixel = gl_Color * texture2D(texture, gl_TexCoord[0].xy);
|
||||||
if (edge > (edge_threshold * 8.0))
|
if (edge > (edge_threshold * 8.0))
|
||||||
pixel.rgb = vec3(0.0, 0.0, 0.0);
|
pixel.rgb = vec3(0.0, 0.0, 0.0);
|
||||||
else
|
else
|
||||||
pixel.a = edge_threshold;
|
pixel.a = edge_threshold;
|
||||||
gl_FragColor = pixel;
|
gl_FragColor = pixel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
uniform float pixel_threshold;
|
uniform float pixel_threshold;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float factor = 1.0 / (pixel_threshold + 0.001);
|
float factor = 1.0 / (pixel_threshold + 0.001);
|
||||||
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
|
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
|
||||||
gl_FragColor = texture2D(texture, pos) * gl_Color;
|
gl_FragColor = texture2D(texture, pos) * gl_Color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sockets)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sockets)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/Sockets.cpp
|
set(SRC ${SRCROOT}/Sockets.cpp
|
||||||
${SRCROOT}/TCP.cpp
|
${SRCROOT}/TCP.cpp
|
||||||
${SRCROOT}/UDP.cpp)
|
${SRCROOT}/UDP.cpp)
|
||||||
|
|
||||||
# define the sockets target
|
# define the sockets target
|
||||||
sfml_add_example(sockets
|
sfml_add_example(sockets
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-network sfml-system)
|
DEPENDS sfml-network sfml-system)
|
||||||
|
|
|
@ -1,59 +1,59 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
void runTcpServer(unsigned short port);
|
void runTcpServer(unsigned short port);
|
||||||
void runTcpClient(unsigned short port);
|
void runTcpClient(unsigned short port);
|
||||||
void runUdpServer(unsigned short port);
|
void runUdpServer(unsigned short port);
|
||||||
void runUdpClient(unsigned short port);
|
void runUdpClient(unsigned short port);
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Choose an arbitrary port for opening sockets
|
// Choose an arbitrary port for opening sockets
|
||||||
const unsigned short port = 50001;
|
const unsigned short port = 50001;
|
||||||
|
|
||||||
// TCP, UDP or connected UDP ?
|
// TCP, UDP or connected UDP ?
|
||||||
char protocol;
|
char protocol;
|
||||||
std::cout << "Do you want to use TCP (t) or UDP (u) ? ";
|
std::cout << "Do you want to use TCP (t) or UDP (u) ? ";
|
||||||
std::cin >> protocol;
|
std::cin >> protocol;
|
||||||
|
|
||||||
// Client or server ?
|
// Client or server ?
|
||||||
char who;
|
char who;
|
||||||
std::cout << "Do you want to be a server (s) or a client (c) ? ";
|
std::cout << "Do you want to be a server (s) or a client (c) ? ";
|
||||||
std::cin >> who;
|
std::cin >> who;
|
||||||
|
|
||||||
if (protocol == 't')
|
if (protocol == 't')
|
||||||
{
|
{
|
||||||
// Test the TCP protocol
|
// Test the TCP protocol
|
||||||
if (who == 's')
|
if (who == 's')
|
||||||
runTcpServer(port);
|
runTcpServer(port);
|
||||||
else
|
else
|
||||||
runTcpClient(port);
|
runTcpClient(port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Test the unconnected UDP protocol
|
// Test the unconnected UDP protocol
|
||||||
if (who == 's')
|
if (who == 's')
|
||||||
runUdpServer(port);
|
runUdpServer(port);
|
||||||
else
|
else
|
||||||
runUdpClient(port);
|
runUdpClient(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until the user presses 'enter' key
|
// Wait until the user presses 'enter' key
|
||||||
std::cout << "Press enter to exit..." << std::endl;
|
std::cout << "Press enter to exit..." << std::endl;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,81 +1,81 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network.hpp>
|
#include <SFML/Network.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Launch a server, wait for an incoming connection,
|
/// Launch a server, wait for an incoming connection,
|
||||||
/// send a message and wait for the answer.
|
/// send a message and wait for the answer.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void runTcpServer(unsigned short port)
|
void runTcpServer(unsigned short port)
|
||||||
{
|
{
|
||||||
// Create a server socket to accept new connections
|
// Create a server socket to accept new connections
|
||||||
sf::TcpListener listener;
|
sf::TcpListener listener;
|
||||||
|
|
||||||
// Listen to the given port for incoming connections
|
// Listen to the given port for incoming connections
|
||||||
if (listener.listen(port) != sf::Socket::Done)
|
if (listener.listen(port) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||||
|
|
||||||
// Wait for a connection
|
// Wait for a connection
|
||||||
sf::TcpSocket socket;
|
sf::TcpSocket socket;
|
||||||
if (listener.accept(socket) != sf::Socket::Done)
|
if (listener.accept(socket) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Client connected: " << socket.getRemoteAddress() << std::endl;
|
std::cout << "Client connected: " << socket.getRemoteAddress() << std::endl;
|
||||||
|
|
||||||
// Send a message to the connected client
|
// Send a message to the connected client
|
||||||
const char out[] = "Hi, I'm the server";
|
const char out[] = "Hi, I'm the server";
|
||||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||||
|
|
||||||
// Receive a message back from the client
|
// Receive a message back from the client
|
||||||
char in[128];
|
char in[128];
|
||||||
std::size_t received;
|
std::size_t received;
|
||||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Answer received from the client: \"" << in << "\"" << std::endl;
|
std::cout << "Answer received from the client: \"" << in << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Create a client, connect it to a server, display the
|
/// Create a client, connect it to a server, display the
|
||||||
/// welcome message and send an answer.
|
/// welcome message and send an answer.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void runTcpClient(unsigned short port)
|
void runTcpClient(unsigned short port)
|
||||||
{
|
{
|
||||||
// Ask for the server address
|
// Ask for the server address
|
||||||
sf::IpAddress server;
|
sf::IpAddress server;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Type the address or name of the server to connect to: ";
|
std::cout << "Type the address or name of the server to connect to: ";
|
||||||
std::cin >> server;
|
std::cin >> server;
|
||||||
}
|
}
|
||||||
while (server == sf::IpAddress::None);
|
while (server == sf::IpAddress::None);
|
||||||
|
|
||||||
// Create a socket for communicating with the server
|
// Create a socket for communicating with the server
|
||||||
sf::TcpSocket socket;
|
sf::TcpSocket socket;
|
||||||
|
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
if (socket.connect(server, port) != sf::Socket::Done)
|
if (socket.connect(server, port) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Connected to server " << server << std::endl;
|
std::cout << "Connected to server " << server << std::endl;
|
||||||
|
|
||||||
// Receive a message from the server
|
// Receive a message from the server
|
||||||
char in[128];
|
char in[128];
|
||||||
std::size_t received;
|
std::size_t received;
|
||||||
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message received from the server: \"" << in << "\"" << std::endl;
|
std::cout << "Message received from the server: \"" << in << "\"" << std::endl;
|
||||||
|
|
||||||
// Send an answer to the server
|
// Send an answer to the server
|
||||||
const char out[] = "Hi, I'm a client";
|
const char out[] = "Hi, I'm a client";
|
||||||
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,72 +1,72 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network.hpp>
|
#include <SFML/Network.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Launch a server, wait for a message, send an answer.
|
/// Launch a server, wait for a message, send an answer.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void runUdpServer(unsigned short port)
|
void runUdpServer(unsigned short port)
|
||||||
{
|
{
|
||||||
// Create a socket to receive a message from anyone
|
// Create a socket to receive a message from anyone
|
||||||
sf::UdpSocket socket;
|
sf::UdpSocket socket;
|
||||||
|
|
||||||
// Listen to messages on the specified port
|
// Listen to messages on the specified port
|
||||||
if (socket.bind(port) != sf::Socket::Done)
|
if (socket.bind(port) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl;
|
std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl;
|
||||||
|
|
||||||
// Wait for a message
|
// Wait for a message
|
||||||
char in[128];
|
char in[128];
|
||||||
std::size_t received;
|
std::size_t received;
|
||||||
sf::IpAddress sender;
|
sf::IpAddress sender;
|
||||||
unsigned short senderPort;
|
unsigned short senderPort;
|
||||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message received from client " << sender << ": \"" << in << "\"" << std::endl;
|
std::cout << "Message received from client " << sender << ": \"" << in << "\"" << std::endl;
|
||||||
|
|
||||||
// Send an answer to the client
|
// Send an answer to the client
|
||||||
const char out[] = "Hi, I'm the server";
|
const char out[] = "Hi, I'm the server";
|
||||||
if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
|
if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
std::cout << "Message sent to the client: \"" << out << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Send a message to the server, wait for the answer
|
/// Send a message to the server, wait for the answer
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void runUdpClient(unsigned short port)
|
void runUdpClient(unsigned short port)
|
||||||
{
|
{
|
||||||
// Ask for the server address
|
// Ask for the server address
|
||||||
sf::IpAddress server;
|
sf::IpAddress server;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Type the address or name of the server to connect to: ";
|
std::cout << "Type the address or name of the server to connect to: ";
|
||||||
std::cin >> server;
|
std::cin >> server;
|
||||||
}
|
}
|
||||||
while (server == sf::IpAddress::None);
|
while (server == sf::IpAddress::None);
|
||||||
|
|
||||||
// Create a socket for communicating with the server
|
// Create a socket for communicating with the server
|
||||||
sf::UdpSocket socket;
|
sf::UdpSocket socket;
|
||||||
|
|
||||||
// Send a message to the server
|
// Send a message to the server
|
||||||
const char out[] = "Hi, I'm a client";
|
const char out[] = "Hi, I'm a client";
|
||||||
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
|
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
std::cout << "Message sent to the server: \"" << out << "\"" << std::endl;
|
||||||
|
|
||||||
// Receive an answer from anyone (but most likely from the server)
|
// Receive an answer from anyone (but most likely from the server)
|
||||||
char in[128];
|
char in[128];
|
||||||
std::size_t received;
|
std::size_t received;
|
||||||
sf::IpAddress sender;
|
sf::IpAddress sender;
|
||||||
unsigned short senderPort;
|
unsigned short senderPort;
|
||||||
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl;
|
std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sound)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sound)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/Sound.cpp)
|
set(SRC ${SRCROOT}/Sound.cpp)
|
||||||
|
|
||||||
# define the sound target
|
# define the sound target
|
||||||
sfml_add_example(sound
|
sfml_add_example(sound
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-audio sfml-system)
|
DEPENDS sfml-audio sfml-system)
|
||||||
|
|
|
@ -1,98 +1,98 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Play a sound
|
/// Play a sound
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void playSound()
|
void playSound()
|
||||||
{
|
{
|
||||||
// Load a sound buffer from a wav file
|
// Load a sound buffer from a wav file
|
||||||
sf::SoundBuffer buffer;
|
sf::SoundBuffer buffer;
|
||||||
if (!buffer.loadFromFile("resources/canary.wav"))
|
if (!buffer.loadFromFile("resources/canary.wav"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Display sound informations
|
// Display sound informations
|
||||||
std::cout << "canary.wav :" << std::endl;
|
std::cout << "canary.wav:" << std::endl;
|
||||||
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
|
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
|
||||||
std::cout << " " << buffer.getSampleRate() << " samples / sec" << std::endl;
|
std::cout << " " << buffer.getSampleRate() << " samples / sec" << std::endl;
|
||||||
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
|
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
|
||||||
|
|
||||||
// Create a sound instance and play it
|
// Create a sound instance and play it
|
||||||
sf::Sound sound(buffer);
|
sf::Sound sound(buffer);
|
||||||
sound.play();
|
sound.play();
|
||||||
|
|
||||||
// Loop while the sound is playing
|
// Loop while the sound is playing
|
||||||
while (sound.getStatus() == sf::Sound::Playing)
|
while (sound.getStatus() == sf::Sound::Playing)
|
||||||
{
|
{
|
||||||
// Leave some CPU time for other processes
|
// Leave some CPU time for other processes
|
||||||
sf::sleep(sf::milliseconds(100));
|
sf::sleep(sf::milliseconds(100));
|
||||||
|
|
||||||
// Display the playing position
|
// Display the playing position
|
||||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec ";
|
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec ";
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
}
|
}
|
||||||
std::cout << std::endl << std::endl;
|
std::cout << std::endl << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Play a music
|
/// Play a music
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void playMusic()
|
void playMusic()
|
||||||
{
|
{
|
||||||
// Load an ogg music file
|
// Load an ogg music file
|
||||||
sf::Music music;
|
sf::Music music;
|
||||||
if (!music.openFromFile("resources/orchestral.ogg"))
|
if (!music.openFromFile("resources/orchestral.ogg"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Display music informations
|
// Display music informations
|
||||||
std::cout << "orchestral.ogg :" << std::endl;
|
std::cout << "orchestral.ogg:" << std::endl;
|
||||||
std::cout << " " << music.getDuration().asSeconds() << " seconds" << std::endl;
|
std::cout << " " << music.getDuration().asSeconds() << " seconds" << std::endl;
|
||||||
std::cout << " " << music.getSampleRate() << " samples / sec" << std::endl;
|
std::cout << " " << music.getSampleRate() << " samples / sec" << std::endl;
|
||||||
std::cout << " " << music.getChannelCount() << " channels" << std::endl;
|
std::cout << " " << music.getChannelCount() << " channels" << std::endl;
|
||||||
|
|
||||||
// Play it
|
// Play it
|
||||||
music.play();
|
music.play();
|
||||||
|
|
||||||
// Loop while the music is playing
|
// Loop while the music is playing
|
||||||
while (music.getStatus() == sf::Music::Playing)
|
while (music.getStatus() == sf::Music::Playing)
|
||||||
{
|
{
|
||||||
// Leave some CPU time for other processes
|
// Leave some CPU time for other processes
|
||||||
sf::sleep(sf::milliseconds(100));
|
sf::sleep(sf::milliseconds(100));
|
||||||
|
|
||||||
// Display the playing position
|
// Display the playing position
|
||||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.getPlayingOffset().asSeconds() << " sec ";
|
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << music.getPlayingOffset().asSeconds() << " sec ";
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Play a sound
|
// Play a sound
|
||||||
playSound();
|
playSound();
|
||||||
|
|
||||||
// Play a music
|
// Play a music
|
||||||
playMusic();
|
playMusic();
|
||||||
|
|
||||||
// Wait until the user presses 'enter' key
|
// Wait until the user presses 'enter' key
|
||||||
std::cout << "Press enter to exit..." << std::endl;
|
std::cout << "Press enter to exit..." << std::endl;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sound_capture)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/sound_capture)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/SoundCapture.cpp)
|
set(SRC ${SRCROOT}/SoundCapture.cpp)
|
||||||
|
|
||||||
# define the sound-capture target
|
# define the sound-capture target
|
||||||
sfml_add_example(sound-capture
|
sfml_add_example(sound-capture
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-audio sfml-system)
|
DEPENDS sfml-audio sfml-system)
|
||||||
|
|
|
@ -1,95 +1,95 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Check that the device can capture audio
|
// Check that the device can capture audio
|
||||||
if (sf::SoundRecorder::isAvailable() == false)
|
if (sf::SoundRecorder::isAvailable() == false)
|
||||||
{
|
{
|
||||||
std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
|
std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Choose the sample rate
|
// Choose the sample rate
|
||||||
unsigned int sampleRate;
|
unsigned int sampleRate;
|
||||||
std::cout << "Please choose the sample rate for sound capture (44100 is CD quality) : ";
|
std::cout << "Please choose the sample rate for sound capture (44100 is CD quality) : ";
|
||||||
std::cin >> sampleRate;
|
std::cin >> sampleRate;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
// Wait for user input...
|
// Wait for user input...
|
||||||
std::cout << "Press enter to start recording audio";
|
std::cout << "Press enter to start recording audio";
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
// Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
|
// Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
|
||||||
sf::SoundBufferRecorder recorder;
|
sf::SoundBufferRecorder recorder;
|
||||||
|
|
||||||
// Audio capture is done in a separate thread, so we can block the main thread while it is capturing
|
// Audio capture is done in a separate thread, so we can block the main thread while it is capturing
|
||||||
recorder.start(sampleRate);
|
recorder.start(sampleRate);
|
||||||
std::cout << "Recording... press enter to stop";
|
std::cout << "Recording... press enter to stop";
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
recorder.stop();
|
recorder.stop();
|
||||||
|
|
||||||
// Get the buffer containing the captured data
|
// Get the buffer containing the captured data
|
||||||
const sf::SoundBuffer& buffer = recorder.getBuffer();
|
const sf::SoundBuffer& buffer = recorder.getBuffer();
|
||||||
|
|
||||||
// Display captured sound informations
|
// Display captured sound informations
|
||||||
std::cout << "Sound information :" << std::endl;
|
std::cout << "Sound information:" << std::endl;
|
||||||
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
|
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
|
||||||
std::cout << " " << buffer.getSampleRate() << " samples / seconds" << std::endl;
|
std::cout << " " << buffer.getSampleRate() << " samples / seconds" << std::endl;
|
||||||
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
|
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
|
||||||
|
|
||||||
// Choose what to do with the recorded sound data
|
// Choose what to do with the recorded sound data
|
||||||
char choice;
|
char choice;
|
||||||
std::cout << "What do you want to do with captured sound (p = play, s = save) ? ";
|
std::cout << "What do you want to do with captured sound (p = play, s = save) ? ";
|
||||||
std::cin >> choice;
|
std::cin >> choice;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
if (choice == 's')
|
if (choice == 's')
|
||||||
{
|
{
|
||||||
// Choose the filename
|
// Choose the filename
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::cout << "Choose the file to create : ";
|
std::cout << "Choose the file to create: ";
|
||||||
std::getline(std::cin, filename);
|
std::getline(std::cin, filename);
|
||||||
|
|
||||||
// Save the buffer
|
// Save the buffer
|
||||||
buffer.saveToFile(filename);
|
buffer.saveToFile(filename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Create a sound instance and play it
|
// Create a sound instance and play it
|
||||||
sf::Sound sound(buffer);
|
sf::Sound sound(buffer);
|
||||||
sound.play();
|
sound.play();
|
||||||
|
|
||||||
// Wait until finished
|
// Wait until finished
|
||||||
while (sound.getStatus() == sf::Sound::Playing)
|
while (sound.getStatus() == sf::Sound::Playing)
|
||||||
{
|
{
|
||||||
// Display the playing position
|
// Display the playing position
|
||||||
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec";
|
std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << sound.getPlayingOffset().asSeconds() << " sec";
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
|
|
||||||
// Leave some CPU time for other threads
|
// Leave some CPU time for other threads
|
||||||
sf::sleep(sf::milliseconds(100));
|
sf::sleep(sf::milliseconds(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finished!
|
// Finished!
|
||||||
std::cout << std::endl << "Done!" << std::endl;
|
std::cout << std::endl << "Done!" << std::endl;
|
||||||
|
|
||||||
// Wait until the user presses 'enter' key
|
// Wait until the user presses 'enter' key
|
||||||
std::cout << "Press enter to exit..." << std::endl;
|
std::cout << "Press enter to exit..." << std::endl;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/voip)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/voip)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/VoIP.cpp
|
set(SRC ${SRCROOT}/VoIP.cpp
|
||||||
${SRCROOT}/Client.cpp
|
${SRCROOT}/Client.cpp
|
||||||
${SRCROOT}/Server.cpp)
|
${SRCROOT}/Server.cpp)
|
||||||
|
|
||||||
# define the voip target
|
# define the voip target
|
||||||
sfml_add_example(voip
|
sfml_add_example(voip
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-audio sfml-network sfml-system)
|
DEPENDS sfml-audio sfml-network sfml-system)
|
||||||
|
|
|
@ -1,129 +1,129 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <SFML/Network.hpp>
|
#include <SFML/Network.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
const sf::Uint8 audioData = 1;
|
const sf::Uint8 audioData = 1;
|
||||||
const sf::Uint8 endOfStream = 2;
|
const sf::Uint8 endOfStream = 2;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Specialization of audio recorder for sending recorded audio
|
/// Specialization of audio recorder for sending recorded audio
|
||||||
/// data through the network
|
/// data through the network
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class NetworkRecorder : public sf::SoundRecorder
|
class NetworkRecorder : public sf::SoundRecorder
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Constructor
|
/// Constructor
|
||||||
///
|
///
|
||||||
/// \param host Remote host to which send the recording data
|
/// \param host Remote host to which send the recording data
|
||||||
/// \param port Port of the remote host
|
/// \param port Port of the remote host
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
NetworkRecorder(const sf::IpAddress& host, unsigned short port) :
|
NetworkRecorder(const sf::IpAddress& host, unsigned short port) :
|
||||||
m_host(host),
|
m_host(host),
|
||||||
m_port(port)
|
m_port(port)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see SoundRecorder::OnStart
|
/// /see SoundRecorder::OnStart
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onStart()
|
virtual bool onStart()
|
||||||
{
|
{
|
||||||
if (m_socket.connect(m_host, m_port) == sf::Socket::Done)
|
if (m_socket.connect(m_host, m_port) == sf::Socket::Done)
|
||||||
{
|
{
|
||||||
std::cout << "Connected to server " << m_host << std::endl;
|
std::cout << "Connected to server " << m_host << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see SoundRecorder::ProcessSamples
|
/// /see SoundRecorder::ProcessSamples
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
|
virtual bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
|
||||||
{
|
{
|
||||||
// Pack the audio samples into a network packet
|
// Pack the audio samples into a network packet
|
||||||
sf::Packet packet;
|
sf::Packet packet;
|
||||||
packet << audioData;
|
packet << audioData;
|
||||||
packet.append(samples, sampleCount * sizeof(sf::Int16));
|
packet.append(samples, sampleCount * sizeof(sf::Int16));
|
||||||
|
|
||||||
// Send the audio packet to the server
|
// Send the audio packet to the server
|
||||||
return m_socket.send(packet) == sf::Socket::Done;
|
return m_socket.send(packet) == sf::Socket::Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see SoundRecorder::OnStop
|
/// /see SoundRecorder::OnStop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onStop()
|
virtual void onStop()
|
||||||
{
|
{
|
||||||
// Send a "end-of-stream" packet
|
// Send a "end-of-stream" packet
|
||||||
sf::Packet packet;
|
sf::Packet packet;
|
||||||
packet << endOfStream;
|
packet << endOfStream;
|
||||||
m_socket.send(packet);
|
m_socket.send(packet);
|
||||||
|
|
||||||
// Close the socket
|
// Close the socket
|
||||||
m_socket.disconnect();
|
m_socket.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::IpAddress m_host; ///< Address of the remote host
|
sf::IpAddress m_host; ///< Address of the remote host
|
||||||
unsigned short m_port; ///< Remote port
|
unsigned short m_port; ///< Remote port
|
||||||
sf::TcpSocket m_socket; ///< Socket used to communicate with the server
|
sf::TcpSocket m_socket; ///< Socket used to communicate with the server
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Create a client, connect it to a running server and
|
/// Create a client, connect it to a running server and
|
||||||
/// start sending him audio data
|
/// start sending him audio data
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void doClient(unsigned short port)
|
void doClient(unsigned short port)
|
||||||
{
|
{
|
||||||
// Check that the device can capture audio
|
// Check that the device can capture audio
|
||||||
if (sf::SoundRecorder::isAvailable() == false)
|
if (sf::SoundRecorder::isAvailable() == false)
|
||||||
{
|
{
|
||||||
std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
|
std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask for server address
|
// Ask for server address
|
||||||
sf::IpAddress server;
|
sf::IpAddress server;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::cout << "Type address or name of the server to connect to : ";
|
std::cout << "Type address or name of the server to connect to: ";
|
||||||
std::cin >> server;
|
std::cin >> server;
|
||||||
}
|
}
|
||||||
while (server == sf::IpAddress::None);
|
while (server == sf::IpAddress::None);
|
||||||
|
|
||||||
// Create an instance of our custom recorder
|
// Create an instance of our custom recorder
|
||||||
NetworkRecorder recorder(server, port);
|
NetworkRecorder recorder(server, port);
|
||||||
|
|
||||||
// Wait for user input...
|
// Wait for user input...
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
std::cout << "Press enter to start recording audio";
|
std::cout << "Press enter to start recording audio";
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
// Start capturing audio data
|
// Start capturing audio data
|
||||||
recorder.start(44100);
|
recorder.start(44100);
|
||||||
std::cout << "Recording... press enter to stop";
|
std::cout << "Recording... press enter to stop";
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
recorder.stop();
|
recorder.stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,200 +1,200 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <SFML/Network.hpp>
|
#include <SFML/Network.hpp>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
|
||||||
const sf::Uint8 audioData = 1;
|
const sf::Uint8 audioData = 1;
|
||||||
const sf::Uint8 endOfStream = 2;
|
const sf::Uint8 endOfStream = 2;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Customized sound stream for acquiring audio data
|
/// Customized sound stream for acquiring audio data
|
||||||
/// from the network
|
/// from the network
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class NetworkAudioStream : public sf::SoundStream
|
class NetworkAudioStream : public sf::SoundStream
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Default constructor
|
/// Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
NetworkAudioStream() :
|
NetworkAudioStream() :
|
||||||
m_offset (0),
|
m_offset (0),
|
||||||
m_hasFinished(false)
|
m_hasFinished(false)
|
||||||
{
|
{
|
||||||
// Set the sound parameters
|
// Set the sound parameters
|
||||||
initialize(1, 44100);
|
initialize(1, 44100);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Run the server, stream audio data from the client
|
/// Run the server, stream audio data from the client
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void start(unsigned short port)
|
void start(unsigned short port)
|
||||||
{
|
{
|
||||||
if (!m_hasFinished)
|
if (!m_hasFinished)
|
||||||
{
|
{
|
||||||
// Listen to the given port for incoming connections
|
// Listen to the given port for incoming connections
|
||||||
if (m_listener.listen(port) != sf::Socket::Done)
|
if (m_listener.listen(port) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl;
|
||||||
|
|
||||||
// Wait for a connection
|
// Wait for a connection
|
||||||
if (m_listener.accept(m_client) != sf::Socket::Done)
|
if (m_listener.accept(m_client) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
std::cout << "Client connected: " << m_client.getRemoteAddress() << std::endl;
|
std::cout << "Client connected: " << m_client.getRemoteAddress() << std::endl;
|
||||||
|
|
||||||
// Start playback
|
// Start playback
|
||||||
play();
|
play();
|
||||||
|
|
||||||
// Start receiving audio data
|
// Start receiving audio data
|
||||||
receiveLoop();
|
receiveLoop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Start playback
|
// Start playback
|
||||||
play();
|
play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see SoundStream::OnGetData
|
/// /see SoundStream::OnGetData
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onGetData(sf::SoundStream::Chunk& data)
|
virtual bool onGetData(sf::SoundStream::Chunk& data)
|
||||||
{
|
{
|
||||||
// We have reached the end of the buffer and all audio data have been played : we can stop playback
|
// We have reached the end of the buffer and all audio data have been played: we can stop playback
|
||||||
if ((m_offset >= m_samples.size()) && m_hasFinished)
|
if ((m_offset >= m_samples.size()) && m_hasFinished)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// No new data has arrived since last update : wait until we get some
|
// No new data has arrived since last update: wait until we get some
|
||||||
while ((m_offset >= m_samples.size()) && !m_hasFinished)
|
while ((m_offset >= m_samples.size()) && !m_hasFinished)
|
||||||
sf::sleep(sf::milliseconds(10));
|
sf::sleep(sf::milliseconds(10));
|
||||||
|
|
||||||
// Copy samples into a local buffer to avoid synchronization problems
|
// Copy samples into a local buffer to avoid synchronization problems
|
||||||
// (don't forget that we run in two separate threads)
|
// (don't forget that we run in two separate threads)
|
||||||
{
|
{
|
||||||
sf::Lock lock(m_mutex);
|
sf::Lock lock(m_mutex);
|
||||||
m_tempBuffer.assign(m_samples.begin() + m_offset, m_samples.end());
|
m_tempBuffer.assign(m_samples.begin() + m_offset, m_samples.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill audio data to pass to the stream
|
// Fill audio data to pass to the stream
|
||||||
data.samples = &m_tempBuffer[0];
|
data.samples = &m_tempBuffer[0];
|
||||||
data.sampleCount = m_tempBuffer.size();
|
data.sampleCount = m_tempBuffer.size();
|
||||||
|
|
||||||
// Update the playing offset
|
// Update the playing offset
|
||||||
m_offset += m_tempBuffer.size();
|
m_offset += m_tempBuffer.size();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// /see SoundStream::OnSeek
|
/// /see SoundStream::OnSeek
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onSeek(sf::Time timeOffset)
|
virtual void onSeek(sf::Time timeOffset)
|
||||||
{
|
{
|
||||||
m_offset = timeOffset.asMilliseconds() * getSampleRate() * getChannelCount() / 1000;
|
m_offset = timeOffset.asMilliseconds() * getSampleRate() * getChannelCount() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get audio data from the client until playback is stopped
|
/// Get audio data from the client until playback is stopped
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void receiveLoop()
|
void receiveLoop()
|
||||||
{
|
{
|
||||||
while (!m_hasFinished)
|
while (!m_hasFinished)
|
||||||
{
|
{
|
||||||
// Get waiting audio data from the network
|
// Get waiting audio data from the network
|
||||||
sf::Packet packet;
|
sf::Packet packet;
|
||||||
if (m_client.receive(packet) != sf::Socket::Done)
|
if (m_client.receive(packet) != sf::Socket::Done)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Extract the message ID
|
// Extract the message ID
|
||||||
sf::Uint8 id;
|
sf::Uint8 id;
|
||||||
packet >> id;
|
packet >> id;
|
||||||
|
|
||||||
if (id == audioData)
|
if (id == audioData)
|
||||||
{
|
{
|
||||||
// Extract audio samples from the packet, and append it to our samples buffer
|
// Extract audio samples from the packet, and append it to our samples buffer
|
||||||
const sf::Int16* samples = reinterpret_cast<const sf::Int16*>(static_cast<const char*>(packet.getData()) + 1);
|
const sf::Int16* samples = reinterpret_cast<const sf::Int16*>(static_cast<const char*>(packet.getData()) + 1);
|
||||||
std::size_t sampleCount = (packet.getDataSize() - 1) / sizeof(sf::Int16);
|
std::size_t sampleCount = (packet.getDataSize() - 1) / sizeof(sf::Int16);
|
||||||
|
|
||||||
// Don't forget that the other thread can access the sample array at any time
|
// Don't forget that the other thread can access the sample array at any time
|
||||||
// (so we protect any operation on it with the mutex)
|
// (so we protect any operation on it with the mutex)
|
||||||
{
|
{
|
||||||
sf::Lock lock(m_mutex);
|
sf::Lock lock(m_mutex);
|
||||||
std::copy(samples, samples + sampleCount, std::back_inserter(m_samples));
|
std::copy(samples, samples + sampleCount, std::back_inserter(m_samples));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (id == endOfStream)
|
else if (id == endOfStream)
|
||||||
{
|
{
|
||||||
// End of stream reached : we stop receiving audio data
|
// End of stream reached: we stop receiving audio data
|
||||||
std::cout << "Audio data has been 100% received!" << std::endl;
|
std::cout << "Audio data has been 100% received!" << std::endl;
|
||||||
m_hasFinished = true;
|
m_hasFinished = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Something's wrong...
|
// Something's wrong...
|
||||||
std::cout << "Invalid packet received..." << std::endl;
|
std::cout << "Invalid packet received..." << std::endl;
|
||||||
m_hasFinished = true;
|
m_hasFinished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::TcpListener m_listener;
|
sf::TcpListener m_listener;
|
||||||
sf::TcpSocket m_client;
|
sf::TcpSocket m_client;
|
||||||
sf::Mutex m_mutex;
|
sf::Mutex m_mutex;
|
||||||
std::vector<sf::Int16> m_samples;
|
std::vector<sf::Int16> m_samples;
|
||||||
std::vector<sf::Int16> m_tempBuffer;
|
std::vector<sf::Int16> m_tempBuffer;
|
||||||
std::size_t m_offset;
|
std::size_t m_offset;
|
||||||
bool m_hasFinished;
|
bool m_hasFinished;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Launch a server and wait for incoming audio data from
|
/// Launch a server and wait for incoming audio data from
|
||||||
/// a connected client
|
/// a connected client
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void doServer(unsigned short port)
|
void doServer(unsigned short port)
|
||||||
{
|
{
|
||||||
// Build an audio stream to play sound data as it is received through the network
|
// Build an audio stream to play sound data as it is received through the network
|
||||||
NetworkAudioStream audioStream;
|
NetworkAudioStream audioStream;
|
||||||
audioStream.start(port);
|
audioStream.start(port);
|
||||||
|
|
||||||
// Loop until the sound playback is finished
|
// Loop until the sound playback is finished
|
||||||
while (audioStream.getStatus() != sf::SoundStream::Stopped)
|
while (audioStream.getStatus() != sf::SoundStream::Stopped)
|
||||||
{
|
{
|
||||||
// Leave some CPU time for other threads
|
// Leave some CPU time for other threads
|
||||||
sf::sleep(sf::milliseconds(100));
|
sf::sleep(sf::milliseconds(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
// Wait until the user presses 'enter' key
|
// Wait until the user presses 'enter' key
|
||||||
std::cout << "Press enter to replay the sound..." << std::endl;
|
std::cout << "Press enter to replay the sound..." << std::endl;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
// Replay the sound (just to make sure replaying the received data is OK)
|
// Replay the sound (just to make sure replaying the received data is OK)
|
||||||
audioStream.play();
|
audioStream.play();
|
||||||
|
|
||||||
// Loop until the sound playback is finished
|
// Loop until the sound playback is finished
|
||||||
while (audioStream.getStatus() != sf::SoundStream::Stopped)
|
while (audioStream.getStatus() != sf::SoundStream::Stopped)
|
||||||
{
|
{
|
||||||
// Leave some CPU time for other threads
|
// Leave some CPU time for other threads
|
||||||
sf::sleep(sf::milliseconds(100));
|
sf::sleep(sf::milliseconds(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +1,50 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
// (I'm too lazy to put them into separate headers...)
|
// (I'm too lazy to put them into separate headers...)
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void doClient(unsigned short port);
|
void doClient(unsigned short port);
|
||||||
void doServer(unsigned short port);
|
void doServer(unsigned short port);
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Choose a random port for opening sockets (ports < 1024 are reserved)
|
// Choose a random port for opening sockets (ports < 1024 are reserved)
|
||||||
const unsigned short port = 2435;
|
const unsigned short port = 2435;
|
||||||
|
|
||||||
// Client or server ?
|
// Client or server ?
|
||||||
char who;
|
char who;
|
||||||
std::cout << "Do you want to be a server ('s') or a client ('c') ? ";
|
std::cout << "Do you want to be a server ('s') or a client ('c') ? ";
|
||||||
std::cin >> who;
|
std::cin >> who;
|
||||||
|
|
||||||
if (who == 's')
|
if (who == 's')
|
||||||
{
|
{
|
||||||
// Run as a server
|
// Run as a server
|
||||||
doServer(port);
|
doServer(port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Run as a client
|
// Run as a client
|
||||||
doClient(port);
|
doClient(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until the user presses 'enter' key
|
// Wait until the user presses 'enter' key
|
||||||
std::cout << "Press enter to exit..." << std::endl;
|
std::cout << "Press enter to exit..." << std::endl;
|
||||||
std::cin.ignore(10000, '\n');
|
std::cin.ignore(10000, '\n');
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/win32)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/win32)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/Win32.cpp)
|
set(SRC ${SRCROOT}/Win32.cpp)
|
||||||
|
|
||||||
# define the win32 target
|
# define the win32 target
|
||||||
sfml_add_example(win32 GUI_APP
|
sfml_add_example(win32 GUI_APP
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-graphics sfml-window sfml-system)
|
DEPENDS sfml-graphics sfml-window sfml-system)
|
||||||
|
|
|
@ -1,130 +1,130 @@
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
HWND button;
|
HWND button;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Function called whenever one of our windows receives a message
|
/// Function called whenever one of our windows receives a message
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
LRESULT CALLBACK onEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK onEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
// Quit when we close the main window
|
// Quit when we close the main window
|
||||||
case WM_CLOSE :
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit when we click the "quit" button
|
// Quit when we click the "quit" button
|
||||||
case WM_COMMAND :
|
case WM_COMMAND:
|
||||||
{
|
{
|
||||||
if (reinterpret_cast<HWND>(lParam) == button)
|
if (reinterpret_cast<HWND>(lParam) == button)
|
||||||
{
|
{
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefWindowProc(handle, message, wParam, lParam);
|
return DefWindowProc(handle, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \param Instance : Instance of the application
|
/// \param Instance: Instance of the application
|
||||||
///
|
///
|
||||||
/// \return Error code
|
/// \return Error code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
|
INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT)
|
||||||
{
|
{
|
||||||
// Define a class for our main window
|
// Define a class for our main window
|
||||||
WNDCLASS windowClass;
|
WNDCLASS windowClass;
|
||||||
windowClass.style = 0;
|
windowClass.style = 0;
|
||||||
windowClass.lpfnWndProc = &onEvent;
|
windowClass.lpfnWndProc = &onEvent;
|
||||||
windowClass.cbClsExtra = 0;
|
windowClass.cbClsExtra = 0;
|
||||||
windowClass.cbWndExtra = 0;
|
windowClass.cbWndExtra = 0;
|
||||||
windowClass.hInstance = instance;
|
windowClass.hInstance = instance;
|
||||||
windowClass.hIcon = NULL;
|
windowClass.hIcon = NULL;
|
||||||
windowClass.hCursor = 0;
|
windowClass.hCursor = 0;
|
||||||
windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
|
windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
|
||||||
windowClass.lpszMenuName = NULL;
|
windowClass.lpszMenuName = NULL;
|
||||||
windowClass.lpszClassName = TEXT("SFML App");
|
windowClass.lpszClassName = TEXT("SFML App");
|
||||||
RegisterClass(&windowClass);
|
RegisterClass(&windowClass);
|
||||||
|
|
||||||
// Let's create the main window
|
// Let's create the main window
|
||||||
HWND window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, NULL, NULL, instance, NULL);
|
HWND window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, NULL, NULL, instance, NULL);
|
||||||
|
|
||||||
// Add a button for exiting
|
// Add a button for exiting
|
||||||
button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, NULL, instance, NULL);
|
button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, NULL, instance, NULL);
|
||||||
|
|
||||||
// Let's create two SFML views
|
// Let's create two SFML views
|
||||||
HWND view1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, window, NULL, instance, NULL);
|
HWND view1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, window, NULL, instance, NULL);
|
||||||
HWND view2 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, window, NULL, instance, NULL);
|
HWND view2 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, window, NULL, instance, NULL);
|
||||||
sf::RenderWindow SFMLView1(view1);
|
sf::RenderWindow SFMLView1(view1);
|
||||||
sf::RenderWindow SFMLView2(view2);
|
sf::RenderWindow SFMLView2(view2);
|
||||||
|
|
||||||
// Load some textures to display
|
// Load some textures to display
|
||||||
sf::Texture texture1, texture2;
|
sf::Texture texture1, texture2;
|
||||||
if (!texture1.loadFromFile("resources/image1.jpg") || !texture2.loadFromFile("resources/image2.jpg"))
|
if (!texture1.loadFromFile("resources/image1.jpg") || !texture2.loadFromFile("resources/image2.jpg"))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
sf::Sprite sprite1(texture1);
|
sf::Sprite sprite1(texture1);
|
||||||
sf::Sprite sprite2(texture2);
|
sf::Sprite sprite2(texture2);
|
||||||
sprite1.setOrigin(sf::Vector2f(texture1.getSize()) / 2.f);
|
sprite1.setOrigin(sf::Vector2f(texture1.getSize()) / 2.f);
|
||||||
sprite1.setPosition(sprite1.getOrigin());
|
sprite1.setPosition(sprite1.getOrigin());
|
||||||
|
|
||||||
// Create a clock for measuring elapsed time
|
// Create a clock for measuring elapsed time
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
|
|
||||||
// Loop until a WM_QUIT message is received
|
// Loop until a WM_QUIT message is received
|
||||||
MSG message;
|
MSG message;
|
||||||
message.message = static_cast<UINT>(~WM_QUIT);
|
message.message = static_cast<UINT>(~WM_QUIT);
|
||||||
while (message.message != WM_QUIT)
|
while (message.message != WM_QUIT)
|
||||||
{
|
{
|
||||||
if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
|
if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
|
||||||
{
|
{
|
||||||
// If a message was waiting in the message queue, process it
|
// If a message was waiting in the message queue, process it
|
||||||
TranslateMessage(&message);
|
TranslateMessage(&message);
|
||||||
DispatchMessage(&message);
|
DispatchMessage(&message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float time = clock.getElapsedTime().asSeconds();
|
float time = clock.getElapsedTime().asSeconds();
|
||||||
|
|
||||||
// Clear views
|
// Clear views
|
||||||
SFMLView1.clear();
|
SFMLView1.clear();
|
||||||
SFMLView2.clear();
|
SFMLView2.clear();
|
||||||
|
|
||||||
// Draw sprite 1 on view 1
|
// Draw sprite 1 on view 1
|
||||||
sprite1.setRotation(time * 100);
|
sprite1.setRotation(time * 100);
|
||||||
SFMLView1.draw(sprite1);
|
SFMLView1.draw(sprite1);
|
||||||
|
|
||||||
// Draw sprite 2 on view 2
|
// Draw sprite 2 on view 2
|
||||||
sprite2.setPosition(std::cos(time) * 100.f, 0.f);
|
sprite2.setPosition(std::cos(time) * 100.f, 0.f);
|
||||||
SFMLView2.draw(sprite2);
|
SFMLView2.draw(sprite2);
|
||||||
|
|
||||||
// Display each view on screen
|
// Display each view on screen
|
||||||
SFMLView1.display();
|
SFMLView1.display();
|
||||||
SFMLView2.display();
|
SFMLView2.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the main window (all its child controls will be destroyed)
|
// Destroy the main window (all its child controls will be destroyed)
|
||||||
DestroyWindow(window);
|
DestroyWindow(window);
|
||||||
|
|
||||||
// Don't forget to unregister the window class
|
// Don't forget to unregister the window class
|
||||||
UnregisterClass(TEXT("SFML App"), instance);
|
UnregisterClass(TEXT("SFML App"), instance);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
|
|
||||||
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/window)
|
set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/window)
|
||||||
|
|
||||||
# all source files
|
# all source files
|
||||||
set(SRC ${SRCROOT}/Window.cpp)
|
set(SRC ${SRCROOT}/Window.cpp)
|
||||||
|
|
||||||
# find OpenGL and GLU
|
# find OpenGL and GLU
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
include_directories(${OPENGL_INCLUDE_DIR})
|
include_directories(${OPENGL_INCLUDE_DIR})
|
||||||
set(ADDITIONAL_LIBRARIES ${OPENGL_LIBRARIES})
|
set(ADDITIONAL_LIBRARIES ${OPENGL_LIBRARIES})
|
||||||
|
|
||||||
# define the window target
|
# define the window target
|
||||||
sfml_add_example(window GUI_APP
|
sfml_add_example(window GUI_APP
|
||||||
SOURCES ${SRC}
|
SOURCES ${SRC}
|
||||||
DEPENDS sfml-window sfml-system ${ADDITIONAL_LIBRARIES})
|
DEPENDS sfml-window sfml-system ${ADDITIONAL_LIBRARIES})
|
||||||
|
|
|
@ -1,146 +1,146 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window.hpp>
|
#include <SFML/Window.hpp>
|
||||||
#include <SFML/OpenGL.hpp>
|
#include <SFML/OpenGL.hpp>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Entry point of application
|
/// Entry point of application
|
||||||
///
|
///
|
||||||
/// \return Application exit code
|
/// \return Application exit code
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Request a 32-bits depth buffer when creating the window
|
// Request a 32-bits depth buffer when creating the window
|
||||||
sf::ContextSettings contextSettings;
|
sf::ContextSettings contextSettings;
|
||||||
contextSettings.depthBits = 32;
|
contextSettings.depthBits = 32;
|
||||||
|
|
||||||
// Create the main window
|
// Create the main window
|
||||||
sf::Window window(sf::VideoMode(640, 480), "SFML window with OpenGL", sf::Style::Default, contextSettings);
|
sf::Window window(sf::VideoMode(640, 480), "SFML window with OpenGL", sf::Style::Default, contextSettings);
|
||||||
|
|
||||||
// Make it the active window for OpenGL calls
|
// Make it the active window for OpenGL calls
|
||||||
window.setActive();
|
window.setActive();
|
||||||
|
|
||||||
// Set the color and depth clear values
|
// Set the color and depth clear values
|
||||||
glClearDepth(1.f);
|
glClearDepth(1.f);
|
||||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||||
|
|
||||||
// Enable Z-buffer read and write
|
// Enable Z-buffer read and write
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
// Disable lighting and texturing
|
// Disable lighting and texturing
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
// Configure the viewport (the same size as the window)
|
// Configure the viewport (the same size as the window)
|
||||||
glViewport(0, 0, window.getSize().x, window.getSize().y);
|
glViewport(0, 0, window.getSize().x, window.getSize().y);
|
||||||
|
|
||||||
// Setup a perspective projection
|
// Setup a perspective projection
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
|
||||||
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
|
||||||
|
|
||||||
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
// Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
|
||||||
GLfloat cube[] =
|
GLfloat cube[] =
|
||||||
{
|
{
|
||||||
// positions // colors (r, g, b, a)
|
// positions // colors (r, g, b, a)
|
||||||
-50, -50, -50, 0, 0, 1, 1,
|
-50, -50, -50, 0, 0, 1, 1,
|
||||||
-50, 50, -50, 0, 0, 1, 1,
|
-50, 50, -50, 0, 0, 1, 1,
|
||||||
-50, -50, 50, 0, 0, 1, 1,
|
-50, -50, 50, 0, 0, 1, 1,
|
||||||
-50, -50, 50, 0, 0, 1, 1,
|
-50, -50, 50, 0, 0, 1, 1,
|
||||||
-50, 50, -50, 0, 0, 1, 1,
|
-50, 50, -50, 0, 0, 1, 1,
|
||||||
-50, 50, 50, 0, 0, 1, 1,
|
-50, 50, 50, 0, 0, 1, 1,
|
||||||
|
|
||||||
50, -50, -50, 0, 1, 0, 1,
|
50, -50, -50, 0, 1, 0, 1,
|
||||||
50, 50, -50, 0, 1, 0, 1,
|
50, 50, -50, 0, 1, 0, 1,
|
||||||
50, -50, 50, 0, 1, 0, 1,
|
50, -50, 50, 0, 1, 0, 1,
|
||||||
50, -50, 50, 0, 1, 0, 1,
|
50, -50, 50, 0, 1, 0, 1,
|
||||||
50, 50, -50, 0, 1, 0, 1,
|
50, 50, -50, 0, 1, 0, 1,
|
||||||
50, 50, 50, 0, 1, 0, 1,
|
50, 50, 50, 0, 1, 0, 1,
|
||||||
|
|
||||||
-50, -50, -50, 1, 0, 0, 1,
|
-50, -50, -50, 1, 0, 0, 1,
|
||||||
50, -50, -50, 1, 0, 0, 1,
|
50, -50, -50, 1, 0, 0, 1,
|
||||||
-50, -50, 50, 1, 0, 0, 1,
|
-50, -50, 50, 1, 0, 0, 1,
|
||||||
-50, -50, 50, 1, 0, 0, 1,
|
-50, -50, 50, 1, 0, 0, 1,
|
||||||
50, -50, -50, 1, 0, 0, 1,
|
50, -50, -50, 1, 0, 0, 1,
|
||||||
50, -50, 50, 1, 0, 0, 1,
|
50, -50, 50, 1, 0, 0, 1,
|
||||||
|
|
||||||
-50, 50, -50, 0, 1, 1, 1,
|
-50, 50, -50, 0, 1, 1, 1,
|
||||||
50, 50, -50, 0, 1, 1, 1,
|
50, 50, -50, 0, 1, 1, 1,
|
||||||
-50, 50, 50, 0, 1, 1, 1,
|
-50, 50, 50, 0, 1, 1, 1,
|
||||||
-50, 50, 50, 0, 1, 1, 1,
|
-50, 50, 50, 0, 1, 1, 1,
|
||||||
50, 50, -50, 0, 1, 1, 1,
|
50, 50, -50, 0, 1, 1, 1,
|
||||||
50, 50, 50, 0, 1, 1, 1,
|
50, 50, 50, 0, 1, 1, 1,
|
||||||
|
|
||||||
-50, -50, -50, 1, 0, 1, 1,
|
-50, -50, -50, 1, 0, 1, 1,
|
||||||
50, -50, -50, 1, 0, 1, 1,
|
50, -50, -50, 1, 0, 1, 1,
|
||||||
-50, 50, -50, 1, 0, 1, 1,
|
-50, 50, -50, 1, 0, 1, 1,
|
||||||
-50, 50, -50, 1, 0, 1, 1,
|
-50, 50, -50, 1, 0, 1, 1,
|
||||||
50, -50, -50, 1, 0, 1, 1,
|
50, -50, -50, 1, 0, 1, 1,
|
||||||
50, 50, -50, 1, 0, 1, 1,
|
50, 50, -50, 1, 0, 1, 1,
|
||||||
|
|
||||||
-50, -50, 50, 1, 1, 0, 1,
|
-50, -50, 50, 1, 1, 0, 1,
|
||||||
50, -50, 50, 1, 1, 0, 1,
|
50, -50, 50, 1, 1, 0, 1,
|
||||||
-50, 50, 50, 1, 1, 0, 1,
|
-50, 50, 50, 1, 1, 0, 1,
|
||||||
-50, 50, 50, 1, 1, 0, 1,
|
-50, 50, 50, 1, 1, 0, 1,
|
||||||
50, -50, 50, 1, 1, 0, 1,
|
50, -50, 50, 1, 1, 0, 1,
|
||||||
50, 50, 50, 1, 1, 0, 1,
|
50, 50, 50, 1, 1, 0, 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enable position and color vertex components
|
// Enable position and color vertex components
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
glVertexPointer(3, GL_FLOAT, 7 * sizeof(GLfloat), cube);
|
glVertexPointer(3, GL_FLOAT, 7 * sizeof(GLfloat), cube);
|
||||||
glColorPointer(4, GL_FLOAT, 7 * sizeof(GLfloat), cube + 3);
|
glColorPointer(4, GL_FLOAT, 7 * sizeof(GLfloat), cube + 3);
|
||||||
|
|
||||||
// Disable normal and texture coordinates vertex components
|
// Disable normal and texture coordinates vertex components
|
||||||
glDisableClientState(GL_NORMAL_ARRAY);
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
|
||||||
// Create a clock for measuring the time elapsed
|
// Create a clock for measuring the time elapsed
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
|
|
||||||
// Start the game loop
|
// Start the game loop
|
||||||
while (window.isOpen())
|
while (window.isOpen())
|
||||||
{
|
{
|
||||||
// Process events
|
// Process events
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
{
|
{
|
||||||
// Close window: exit
|
// Close window: exit
|
||||||
if (event.type == sf::Event::Closed)
|
if (event.type == sf::Event::Closed)
|
||||||
window.close();
|
window.close();
|
||||||
|
|
||||||
// Escape key: exit
|
// Escape key: exit
|
||||||
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
|
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
|
||||||
window.close();
|
window.close();
|
||||||
|
|
||||||
// Resize event: adjust the viewport
|
// Resize event: adjust the viewport
|
||||||
if (event.type == sf::Event::Resized)
|
if (event.type == sf::Event::Resized)
|
||||||
glViewport(0, 0, event.size.width, event.size.height);
|
glViewport(0, 0, event.size.width, event.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the color and depth buffers
|
// Clear the color and depth buffers
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Apply some transformations to rotate the cube
|
// Apply some transformations to rotate the cube
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.f, 0.f, -200.f);
|
glTranslatef(0.f, 0.f, -200.f);
|
||||||
glRotatef(clock.getElapsedTime().asSeconds() * 50, 1.f, 0.f, 0.f);
|
glRotatef(clock.getElapsedTime().asSeconds() * 50, 1.f, 0.f, 0.f);
|
||||||
glRotatef(clock.getElapsedTime().asSeconds() * 30, 0.f, 1.f, 0.f);
|
glRotatef(clock.getElapsedTime().asSeconds() * 30, 0.f, 1.f, 0.f);
|
||||||
glRotatef(clock.getElapsedTime().asSeconds() * 90, 0.f, 0.f, 1.f);
|
glRotatef(clock.getElapsedTime().asSeconds() * 90, 0.f, 0.f, 1.f);
|
||||||
|
|
||||||
// Draw the cube
|
// Draw the cube
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
|
||||||
// Finally, display the rendered frame on screen
|
// Finally, display the rendered frame on screen
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +1,50 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_AUDIO_HPP
|
#ifndef SFML_AUDIO_HPP
|
||||||
#define SFML_AUDIO_HPP
|
#define SFML_AUDIO_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
#include <SFML/Audio/Listener.hpp>
|
#include <SFML/Audio/Listener.hpp>
|
||||||
#include <SFML/Audio/Music.hpp>
|
#include <SFML/Audio/Music.hpp>
|
||||||
#include <SFML/Audio/Sound.hpp>
|
#include <SFML/Audio/Sound.hpp>
|
||||||
#include <SFML/Audio/SoundBuffer.hpp>
|
#include <SFML/Audio/SoundBuffer.hpp>
|
||||||
#include <SFML/Audio/SoundBufferRecorder.hpp>
|
#include <SFML/Audio/SoundBufferRecorder.hpp>
|
||||||
#include <SFML/Audio/SoundRecorder.hpp>
|
#include <SFML/Audio/SoundRecorder.hpp>
|
||||||
#include <SFML/Audio/SoundStream.hpp>
|
#include <SFML/Audio/SoundStream.hpp>
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_AUDIO_HPP
|
#endif // SFML_AUDIO_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \defgroup audio Audio module
|
/// \defgroup audio Audio module
|
||||||
///
|
///
|
||||||
/// Sounds, streaming (musics or custom sources), recording,
|
/// Sounds, streaming (musics or custom sources), recording,
|
||||||
/// spatialization.
|
/// spatialization.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,234 +1,234 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_LISTENER_HPP
|
#ifndef SFML_LISTENER_HPP
|
||||||
#define SFML_LISTENER_HPP
|
#define SFML_LISTENER_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/System/Vector3.hpp>
|
#include <SFML/System/Vector3.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief The audio listener is the point in the scene
|
/// \brief The audio listener is the point in the scene
|
||||||
/// from where all the sounds are heard
|
/// from where all the sounds are heard
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API Listener
|
class SFML_AUDIO_API Listener
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the global volume of all the sounds and musics
|
/// \brief Change the global volume of all the sounds and musics
|
||||||
///
|
///
|
||||||
/// The volume is a number between 0 and 100; it is combined with
|
/// The volume is a number between 0 and 100; it is combined with
|
||||||
/// the individual volume of each sound / music.
|
/// the individual volume of each sound / music.
|
||||||
/// The default value for the volume is 100 (maximum).
|
/// The default value for the volume is 100 (maximum).
|
||||||
///
|
///
|
||||||
/// \param volume New global volume, in the range [0, 100]
|
/// \param volume New global volume, in the range [0, 100]
|
||||||
///
|
///
|
||||||
/// \see getGlobalVolume
|
/// \see getGlobalVolume
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void setGlobalVolume(float volume);
|
static void setGlobalVolume(float volume);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current value of the global volume
|
/// \brief Get the current value of the global volume
|
||||||
///
|
///
|
||||||
/// \return Current global volume, in the range [0, 100]
|
/// \return Current global volume, in the range [0, 100]
|
||||||
///
|
///
|
||||||
/// \see setGlobalVolume
|
/// \see setGlobalVolume
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static float getGlobalVolume();
|
static float getGlobalVolume();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the position of the listener in the scene
|
/// \brief Set the position of the listener in the scene
|
||||||
///
|
///
|
||||||
/// The default listener's position is (0, 0, 0).
|
/// The default listener's position is (0, 0, 0).
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of the listener's position
|
/// \param x X coordinate of the listener's position
|
||||||
/// \param y Y coordinate of the listener's position
|
/// \param y Y coordinate of the listener's position
|
||||||
/// \param z Z coordinate of the listener's position
|
/// \param z Z coordinate of the listener's position
|
||||||
///
|
///
|
||||||
/// \see getPosition, setDirection
|
/// \see getPosition, setDirection
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void setPosition(float x, float y, float z);
|
static void setPosition(float x, float y, float z);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the position of the listener in the scene
|
/// \brief Set the position of the listener in the scene
|
||||||
///
|
///
|
||||||
/// The default listener's position is (0, 0, 0).
|
/// The default listener's position is (0, 0, 0).
|
||||||
///
|
///
|
||||||
/// \param position New listener's position
|
/// \param position New listener's position
|
||||||
///
|
///
|
||||||
/// \see getPosition, setDirection
|
/// \see getPosition, setDirection
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void setPosition(const Vector3f& position);
|
static void setPosition(const Vector3f& position);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current position of the listener in the scene
|
/// \brief Get the current position of the listener in the scene
|
||||||
///
|
///
|
||||||
/// \return Listener's position
|
/// \return Listener's position
|
||||||
///
|
///
|
||||||
/// \see setPosition
|
/// \see setPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static Vector3f getPosition();
|
static Vector3f getPosition();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the forward vector of the listener in the scene
|
/// \brief Set the forward vector of the listener in the scene
|
||||||
///
|
///
|
||||||
/// The direction (also called "at vector") is the vector
|
/// The direction (also called "at vector") is the vector
|
||||||
/// pointing forward from the listener's perspective. Together
|
/// pointing forward from the listener's perspective. Together
|
||||||
/// with the up vector, it defines the 3D orientation of the
|
/// with the up vector, it defines the 3D orientation of the
|
||||||
/// listener in the scene. The direction vector doesn't
|
/// listener in the scene. The direction vector doesn't
|
||||||
/// have to be normalized.
|
/// have to be normalized.
|
||||||
/// The default listener's direction is (0, 0, -1).
|
/// The default listener's direction is (0, 0, -1).
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of the listener's direction
|
/// \param x X coordinate of the listener's direction
|
||||||
/// \param y Y coordinate of the listener's direction
|
/// \param y Y coordinate of the listener's direction
|
||||||
/// \param z Z coordinate of the listener's direction
|
/// \param z Z coordinate of the listener's direction
|
||||||
///
|
///
|
||||||
/// \see getDirection, setUpVector, setPosition
|
/// \see getDirection, setUpVector, setPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void setDirection(float x, float y, float z);
|
static void setDirection(float x, float y, float z);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the forward vector of the listener in the scene
|
/// \brief Set the forward vector of the listener in the scene
|
||||||
///
|
///
|
||||||
/// The direction (also called "at vector") is the vector
|
/// The direction (also called "at vector") is the vector
|
||||||
/// pointing forward from the listener's perspective. Together
|
/// pointing forward from the listener's perspective. Together
|
||||||
/// with the up vector, it defines the 3D orientation of the
|
/// with the up vector, it defines the 3D orientation of the
|
||||||
/// listener in the scene. The direction vector doesn't
|
/// listener in the scene. The direction vector doesn't
|
||||||
/// have to be normalized.
|
/// have to be normalized.
|
||||||
/// The default listener's direction is (0, 0, -1).
|
/// The default listener's direction is (0, 0, -1).
|
||||||
///
|
///
|
||||||
/// \param direction New listener's direction
|
/// \param direction New listener's direction
|
||||||
///
|
///
|
||||||
/// \see getDirection, setUpVector, setPosition
|
/// \see getDirection, setUpVector, setPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void setDirection(const Vector3f& direction);
|
static void setDirection(const Vector3f& direction);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current forward vector of the listener in the scene
|
/// \brief Get the current forward vector of the listener in the scene
|
||||||
///
|
///
|
||||||
/// \return Listener's forward vector (not normalized)
|
/// \return Listener's forward vector (not normalized)
|
||||||
///
|
///
|
||||||
/// \see setDirection
|
/// \see setDirection
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static Vector3f getDirection();
|
static Vector3f getDirection();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the upward vector of the listener in the scene
|
/// \brief Set the upward vector of the listener in the scene
|
||||||
///
|
///
|
||||||
/// The up vector is the vector that points upward from the
|
/// The up vector is the vector that points upward from the
|
||||||
/// listener's perspective. Together with the direction, it
|
/// listener's perspective. Together with the direction, it
|
||||||
/// defines the 3D orientation of the listener in the scene.
|
/// defines the 3D orientation of the listener in the scene.
|
||||||
/// The up vector doesn't have to be normalized.
|
/// The up vector doesn't have to be normalized.
|
||||||
/// The default listener's up vector is (0, 1, 0). It is usually
|
/// The default listener's up vector is (0, 1, 0). It is usually
|
||||||
/// not necessary to change it, especially in 2D scenarios.
|
/// not necessary to change it, especially in 2D scenarios.
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of the listener's up vector
|
/// \param x X coordinate of the listener's up vector
|
||||||
/// \param y Y coordinate of the listener's up vector
|
/// \param y Y coordinate of the listener's up vector
|
||||||
/// \param z Z coordinate of the listener's up vector
|
/// \param z Z coordinate of the listener's up vector
|
||||||
///
|
///
|
||||||
/// \see getUpVector, setDirection, setPosition
|
/// \see getUpVector, setDirection, setPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void setUpVector(float x, float y, float z);
|
static void setUpVector(float x, float y, float z);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the upward vector of the listener in the scene
|
/// \brief Set the upward vector of the listener in the scene
|
||||||
///
|
///
|
||||||
/// The up vector is the vector that points upward from the
|
/// The up vector is the vector that points upward from the
|
||||||
/// listener's perspective. Together with the direction, it
|
/// listener's perspective. Together with the direction, it
|
||||||
/// defines the 3D orientation of the listener in the scene.
|
/// defines the 3D orientation of the listener in the scene.
|
||||||
/// The up vector doesn't have to be normalized.
|
/// The up vector doesn't have to be normalized.
|
||||||
/// The default listener's up vector is (0, 1, 0). It is usually
|
/// The default listener's up vector is (0, 1, 0). It is usually
|
||||||
/// not necessary to change it, especially in 2D scenarios.
|
/// not necessary to change it, especially in 2D scenarios.
|
||||||
///
|
///
|
||||||
/// \param upVector New listener's up vector
|
/// \param upVector New listener's up vector
|
||||||
///
|
///
|
||||||
/// \see getUpVector, setDirection, setPosition
|
/// \see getUpVector, setDirection, setPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void setUpVector(const Vector3f& upVector);
|
static void setUpVector(const Vector3f& upVector);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current upward vector of the listener in the scene
|
/// \brief Get the current upward vector of the listener in the scene
|
||||||
///
|
///
|
||||||
/// \return Listener's upward vector (not normalized)
|
/// \return Listener's upward vector (not normalized)
|
||||||
///
|
///
|
||||||
/// \see setUpVector
|
/// \see setUpVector
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static Vector3f getUpVector();
|
static Vector3f getUpVector();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_LISTENER_HPP
|
#endif // SFML_LISTENER_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Listener
|
/// \class sf::Listener
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// The audio listener defines the global properties of the
|
/// The audio listener defines the global properties of the
|
||||||
/// audio environment, it defines where and how sounds and musics
|
/// audio environment, it defines where and how sounds and musics
|
||||||
/// are heard. If sf::View is the eyes of the user, then sf::Listener
|
/// are heard. If sf::View is the eyes of the user, then sf::Listener
|
||||||
/// is his ears (by the way, they are often linked together --
|
/// is his ears (by the way, they are often linked together --
|
||||||
/// same position, orientation, etc.).
|
/// same position, orientation, etc.).
|
||||||
///
|
///
|
||||||
/// sf::Listener is a simple interface, which allows to setup the
|
/// sf::Listener is a simple interface, which allows to setup the
|
||||||
/// listener in the 3D audio environment (position, direction and
|
/// listener in the 3D audio environment (position, direction and
|
||||||
/// up vector), and to adjust the global volume.
|
/// up vector), and to adjust the global volume.
|
||||||
///
|
///
|
||||||
/// Because the listener is unique in the scene, sf::Listener only
|
/// Because the listener is unique in the scene, sf::Listener only
|
||||||
/// contains static functions and doesn't have to be instantiated.
|
/// contains static functions and doesn't have to be instantiated.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Move the listener to the position (1, 0, -5)
|
/// // Move the listener to the position (1, 0, -5)
|
||||||
/// sf::Listener::setPosition(1, 0, -5);
|
/// sf::Listener::setPosition(1, 0, -5);
|
||||||
///
|
///
|
||||||
/// // Make it face the right axis (1, 0, 0)
|
/// // Make it face the right axis (1, 0, 0)
|
||||||
/// sf::Listener::setDirection(1, 0, 0);
|
/// sf::Listener::setDirection(1, 0, 0);
|
||||||
///
|
///
|
||||||
/// // Reduce the global volume
|
/// // Reduce the global volume
|
||||||
/// sf::Listener::setGlobalVolume(50);
|
/// sf::Listener::setGlobalVolume(50);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,228 +1,228 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_MUSIC_HPP
|
#ifndef SFML_MUSIC_HPP
|
||||||
#define SFML_MUSIC_HPP
|
#define SFML_MUSIC_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/Audio/SoundStream.hpp>
|
#include <SFML/Audio/SoundStream.hpp>
|
||||||
#include <SFML/System/Mutex.hpp>
|
#include <SFML/System/Mutex.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
class SoundFile;
|
class SoundFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
class InputStream;
|
class InputStream;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Streamed music played from an audio file
|
/// \brief Streamed music played from an audio file
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API Music : public SoundStream
|
class SFML_AUDIO_API Music : public SoundStream
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Music();
|
Music();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~Music();
|
~Music();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Open a music from an audio file
|
/// \brief Open a music from an audio file
|
||||||
///
|
///
|
||||||
/// This function doesn't start playing the music (call play()
|
/// This function doesn't start playing the music (call play()
|
||||||
/// to do so).
|
/// to do so).
|
||||||
/// Here is a complete list of all the supported audio formats:
|
/// Here is a complete list of all the supported audio formats:
|
||||||
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
||||||
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
||||||
///
|
///
|
||||||
/// \param filename Path of the music file to open
|
/// \param filename Path of the music file to open
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see openFromMemory, openFromStream
|
/// \see openFromMemory, openFromStream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool openFromFile(const std::string& filename);
|
bool openFromFile(const std::string& filename);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Open a music from an audio file in memory
|
/// \brief Open a music from an audio file in memory
|
||||||
///
|
///
|
||||||
/// This function doesn't start playing the music (call play()
|
/// This function doesn't start playing the music (call play()
|
||||||
/// to do so).
|
/// to do so).
|
||||||
/// Here is a complete list of all the supported audio formats:
|
/// Here is a complete list of all the supported audio formats:
|
||||||
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
||||||
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
||||||
/// Since the music is not loaded completely but rather streamed
|
/// Since the music is not loaded completely but rather streamed
|
||||||
/// continuously, the \a data must remain available as long as the
|
/// continuously, the \a data must remain available as long as the
|
||||||
/// music is playing (ie. you can't deallocate it right after calling
|
/// music is playing (ie. you can't deallocate it right after calling
|
||||||
/// this function).
|
/// this function).
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the file data in memory
|
/// \param data Pointer to the file data in memory
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
/// \param sizeInBytes Size of the data to load, in bytes
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see openFromFile, openFromStream
|
/// \see openFromFile, openFromStream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool openFromMemory(const void* data, std::size_t sizeInBytes);
|
bool openFromMemory(const void* data, std::size_t sizeInBytes);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Open a music from an audio file in a custom stream
|
/// \brief Open a music from an audio file in a custom stream
|
||||||
///
|
///
|
||||||
/// This function doesn't start playing the music (call play()
|
/// This function doesn't start playing the music (call play()
|
||||||
/// to do so).
|
/// to do so).
|
||||||
/// Here is a complete list of all the supported audio formats:
|
/// Here is a complete list of all the supported audio formats:
|
||||||
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
||||||
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
||||||
/// Since the music is not loaded completely but rather streamed
|
/// Since the music is not loaded completely but rather streamed
|
||||||
/// continuously, the \a stream must remain alive as long as the
|
/// continuously, the \a stream must remain alive as long as the
|
||||||
/// music is playing (ie. you can't destroy it right after calling
|
/// music is playing (ie. you can't destroy it right after calling
|
||||||
/// this function).
|
/// this function).
|
||||||
///
|
///
|
||||||
/// \param stream Source stream to read from
|
/// \param stream Source stream to read from
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see openFromFile, openFromMemory
|
/// \see openFromFile, openFromMemory
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool openFromStream(InputStream& stream);
|
bool openFromStream(InputStream& stream);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the total duration of the music
|
/// \brief Get the total duration of the music
|
||||||
///
|
///
|
||||||
/// \return Music duration
|
/// \return Music duration
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Time getDuration() const;
|
Time getDuration() const;
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Request a new chunk of audio samples from the stream source
|
/// \brief Request a new chunk of audio samples from the stream source
|
||||||
///
|
///
|
||||||
/// This function fills the chunk from the next samples
|
/// This function fills the chunk from the next samples
|
||||||
/// to read from the audio file.
|
/// to read from the audio file.
|
||||||
///
|
///
|
||||||
/// \param data Chunk of data to fill
|
/// \param data Chunk of data to fill
|
||||||
///
|
///
|
||||||
/// \return True to continue playback, false to stop
|
/// \return True to continue playback, false to stop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onGetData(Chunk& data);
|
virtual bool onGetData(Chunk& data);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the current playing position in the stream source
|
/// \brief Change the current playing position in the stream source
|
||||||
///
|
///
|
||||||
/// \param timeOffset New playing position, from the beginning of the music
|
/// \param timeOffset New playing position, from the beginning of the music
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onSeek(Time timeOffset);
|
virtual void onSeek(Time timeOffset);
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Initialize the internal state after loading a new music
|
/// \brief Initialize the internal state after loading a new music
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
priv::SoundFile* m_file; ///< Sound file
|
priv::SoundFile* m_file; ///< Sound file
|
||||||
Time m_duration; ///< Music duration
|
Time m_duration; ///< Music duration
|
||||||
std::vector<Int16> m_samples; ///< Temporary buffer of samples
|
std::vector<Int16> m_samples; ///< Temporary buffer of samples
|
||||||
Mutex m_mutex; ///< Mutex protecting the data
|
Mutex m_mutex; ///< Mutex protecting the data
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_MUSIC_HPP
|
#endif // SFML_MUSIC_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Music
|
/// \class sf::Music
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// Musics are sounds that are streamed rather than completely
|
/// Musics are sounds that are streamed rather than completely
|
||||||
/// loaded in memory. This is especially useful for compressed
|
/// loaded in memory. This is especially useful for compressed
|
||||||
/// musics that usually take hundreds of MB when they are
|
/// musics that usually take hundreds of MB when they are
|
||||||
/// uncompressed: by streaming it instead of loading it entirely,
|
/// uncompressed: by streaming it instead of loading it entirely,
|
||||||
/// you avoid saturating the memory and have almost no loading delay.
|
/// you avoid saturating the memory and have almost no loading delay.
|
||||||
///
|
///
|
||||||
/// Apart from that, a sf::Music has almost the same features as
|
/// Apart from that, a sf::Music has almost the same features as
|
||||||
/// the sf::SoundBuffer / sf::Sound pair: you can play/pause/stop
|
/// the sf::SoundBuffer / sf::Sound pair: you can play/pause/stop
|
||||||
/// it, request its parameters (channels, sample rate), change
|
/// it, request its parameters (channels, sample rate), change
|
||||||
/// the way it is played (pitch, volume, 3D position, ...), etc.
|
/// the way it is played (pitch, volume, 3D position, ...), etc.
|
||||||
///
|
///
|
||||||
/// As a sound stream, a music is played in its own thread in order
|
/// As a sound stream, a music is played in its own thread in order
|
||||||
/// not to block the rest of the program. This means that you can
|
/// not to block the rest of the program. This means that you can
|
||||||
/// leave the music alone after calling play(), it will manage itself
|
/// leave the music alone after calling play(), it will manage itself
|
||||||
/// very well.
|
/// very well.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Declare a new music
|
/// // Declare a new music
|
||||||
/// sf::Music music;
|
/// sf::Music music;
|
||||||
///
|
///
|
||||||
/// // Open it from an audio file
|
/// // Open it from an audio file
|
||||||
/// if (!music.openFromFile("music.ogg"))
|
/// if (!music.openFromFile("music.ogg"))
|
||||||
/// {
|
/// {
|
||||||
/// // error...
|
/// // error...
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Change some parameters
|
/// // Change some parameters
|
||||||
/// music.setPosition(0, 1, 10); // change its 3D position
|
/// music.setPosition(0, 1, 10); // change its 3D position
|
||||||
/// music.setPitch(2); // increase the pitch
|
/// music.setPitch(2); // increase the pitch
|
||||||
/// music.setVolume(50); // reduce the volume
|
/// music.setVolume(50); // reduce the volume
|
||||||
/// music.setLoop(true); // make it loop
|
/// music.setLoop(true); // make it loop
|
||||||
///
|
///
|
||||||
/// // Play it
|
/// // Play it
|
||||||
/// music.play();
|
/// music.play();
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Sound, sf::SoundStream
|
/// \see sf::Sound, sf::SoundStream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,264 +1,264 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOUND_HPP
|
#ifndef SFML_SOUND_HPP
|
||||||
#define SFML_SOUND_HPP
|
#define SFML_SOUND_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/Audio/SoundSource.hpp>
|
#include <SFML/Audio/SoundSource.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class SoundBuffer;
|
class SoundBuffer;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Regular sound that can be played in the audio environment
|
/// \brief Regular sound that can be played in the audio environment
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API Sound : public SoundSource
|
class SFML_AUDIO_API Sound : public SoundSource
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Sound();
|
Sound();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the sound with a buffer
|
/// \brief Construct the sound with a buffer
|
||||||
///
|
///
|
||||||
/// \param buffer Sound buffer containing the audio data to play with the sound
|
/// \param buffer Sound buffer containing the audio data to play with the sound
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
explicit Sound(const SoundBuffer& buffer);
|
explicit Sound(const SoundBuffer& buffer);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy constructor
|
/// \brief Copy constructor
|
||||||
///
|
///
|
||||||
/// \param copy Instance to copy
|
/// \param copy Instance to copy
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Sound(const Sound& copy);
|
Sound(const Sound& copy);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~Sound();
|
~Sound();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Start or resume playing the sound
|
/// \brief Start or resume playing the sound
|
||||||
///
|
///
|
||||||
/// This function starts the stream if it was stopped, resumes
|
/// This function starts the stream if it was stopped, resumes
|
||||||
/// it if it was paused, and restarts it from beginning if it
|
/// it if it was paused, and restarts it from beginning if it
|
||||||
/// was it already playing.
|
/// was it already playing.
|
||||||
/// This function uses its own thread so that it doesn't block
|
/// This function uses its own thread so that it doesn't block
|
||||||
/// the rest of the program while the sound is played.
|
/// the rest of the program while the sound is played.
|
||||||
///
|
///
|
||||||
/// \see pause, stop
|
/// \see pause, stop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void play();
|
void play();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Pause the sound
|
/// \brief Pause the sound
|
||||||
///
|
///
|
||||||
/// This function pauses the sound if it was playing,
|
/// This function pauses the sound if it was playing,
|
||||||
/// otherwise (sound already paused or stopped) it has no effect.
|
/// otherwise (sound already paused or stopped) it has no effect.
|
||||||
///
|
///
|
||||||
/// \see play, stop
|
/// \see play, stop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void pause();
|
void pause();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief stop playing the sound
|
/// \brief stop playing the sound
|
||||||
///
|
///
|
||||||
/// This function stops the sound if it was playing or paused,
|
/// This function stops the sound if it was playing or paused,
|
||||||
/// and does nothing if it was already stopped.
|
/// and does nothing if it was already stopped.
|
||||||
/// It also resets the playing position (unlike pause()).
|
/// It also resets the playing position (unlike pause()).
|
||||||
///
|
///
|
||||||
/// \see play, pause
|
/// \see play, pause
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the source buffer containing the audio data to play
|
/// \brief Set the source buffer containing the audio data to play
|
||||||
///
|
///
|
||||||
/// It is important to note that the sound buffer is not copied,
|
/// It is important to note that the sound buffer is not copied,
|
||||||
/// thus the sf::SoundBuffer instance must remain alive as long
|
/// thus the sf::SoundBuffer instance must remain alive as long
|
||||||
/// as it is attached to the sound.
|
/// as it is attached to the sound.
|
||||||
///
|
///
|
||||||
/// \param buffer Sound buffer to attach to the sound
|
/// \param buffer Sound buffer to attach to the sound
|
||||||
///
|
///
|
||||||
/// \see getBuffer
|
/// \see getBuffer
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setBuffer(const SoundBuffer& buffer);
|
void setBuffer(const SoundBuffer& buffer);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set whether or not the sound should loop after reaching the end
|
/// \brief Set whether or not the sound should loop after reaching the end
|
||||||
///
|
///
|
||||||
/// If set, the sound will restart from beginning after
|
/// If set, the sound will restart from beginning after
|
||||||
/// reaching the end and so on, until it is stopped or
|
/// reaching the end and so on, until it is stopped or
|
||||||
/// setLoop(false) is called.
|
/// setLoop(false) is called.
|
||||||
/// The default looping state for sound is false.
|
/// The default looping state for sound is false.
|
||||||
///
|
///
|
||||||
/// \param loop True to play in loop, false to play once
|
/// \param loop True to play in loop, false to play once
|
||||||
///
|
///
|
||||||
/// \see getLoop
|
/// \see getLoop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setLoop(bool loop);
|
void setLoop(bool loop);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the current playing position of the sound
|
/// \brief Change the current playing position of the sound
|
||||||
///
|
///
|
||||||
/// The playing position can be changed when the sound is
|
/// The playing position can be changed when the sound is
|
||||||
/// either paused or playing. Changing the playing position
|
/// either paused or playing. Changing the playing position
|
||||||
/// when the sound is stopped has no effect, since playing
|
/// when the sound is stopped has no effect, since playing
|
||||||
/// the sound would reset its position.
|
/// the sound would reset its position.
|
||||||
///
|
///
|
||||||
/// \param timeOffset New playing position, from the beginning of the sound
|
/// \param timeOffset New playing position, from the beginning of the sound
|
||||||
///
|
///
|
||||||
/// \see getPlayingOffset
|
/// \see getPlayingOffset
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setPlayingOffset(Time timeOffset);
|
void setPlayingOffset(Time timeOffset);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the audio buffer attached to the sound
|
/// \brief Get the audio buffer attached to the sound
|
||||||
///
|
///
|
||||||
/// \return Sound buffer attached to the sound (can be NULL)
|
/// \return Sound buffer attached to the sound (can be NULL)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const SoundBuffer* getBuffer() const;
|
const SoundBuffer* getBuffer() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether or not the sound is in loop mode
|
/// \brief Tell whether or not the sound is in loop mode
|
||||||
///
|
///
|
||||||
/// \return True if the sound is looping, false otherwise
|
/// \return True if the sound is looping, false otherwise
|
||||||
///
|
///
|
||||||
/// \see setLoop
|
/// \see setLoop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool getLoop() const;
|
bool getLoop() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current playing position of the sound
|
/// \brief Get the current playing position of the sound
|
||||||
///
|
///
|
||||||
/// \return Current playing position, from the beginning of the sound
|
/// \return Current playing position, from the beginning of the sound
|
||||||
///
|
///
|
||||||
/// \see setPlayingOffset
|
/// \see setPlayingOffset
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Time getPlayingOffset() const;
|
Time getPlayingOffset() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current status of the sound (stopped, paused, playing)
|
/// \brief Get the current status of the sound (stopped, paused, playing)
|
||||||
///
|
///
|
||||||
/// \return Current status of the sound
|
/// \return Current status of the sound
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status getStatus() const;
|
Status getStatus() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of assignment operator
|
/// \brief Overload of assignment operator
|
||||||
///
|
///
|
||||||
/// \param right Instance to assign
|
/// \param right Instance to assign
|
||||||
///
|
///
|
||||||
/// \return Reference to self
|
/// \return Reference to self
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Sound& operator =(const Sound& right);
|
Sound& operator =(const Sound& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Reset the internal buffer of the sound
|
/// \brief Reset the internal buffer of the sound
|
||||||
///
|
///
|
||||||
/// This function is for internal use only, you don't have
|
/// This function is for internal use only, you don't have
|
||||||
/// to use it. It is called by the sf::SoundBuffer that
|
/// to use it. It is called by the sf::SoundBuffer that
|
||||||
/// this sound uses, when it is destroyed in order to prevent
|
/// this sound uses, when it is destroyed in order to prevent
|
||||||
/// the sound from using a dead buffer.
|
/// the sound from using a dead buffer.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void resetBuffer();
|
void resetBuffer();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const SoundBuffer* m_buffer; ///< Sound buffer bound to the source
|
const SoundBuffer* m_buffer; ///< Sound buffer bound to the source
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUND_HPP
|
#endif // SFML_SOUND_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Sound
|
/// \class sf::Sound
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// sf::Sound is the class to use to play sounds.
|
/// sf::Sound is the class to use to play sounds.
|
||||||
/// It provides:
|
/// It provides:
|
||||||
/// \li Control (play, pause, stop)
|
/// \li Control (play, pause, stop)
|
||||||
/// \li Ability to modify output parameters in real-time (pitch, volume, ...)
|
/// \li Ability to modify output parameters in real-time (pitch, volume, ...)
|
||||||
/// \li 3D spatial features (position, attenuation, ...).
|
/// \li 3D spatial features (position, attenuation, ...).
|
||||||
///
|
///
|
||||||
/// sf::Sound is perfect for playing short sounds that can
|
/// sf::Sound is perfect for playing short sounds that can
|
||||||
/// fit in memory and require no latency, like foot steps or
|
/// fit in memory and require no latency, like foot steps or
|
||||||
/// gun shots. For longer sounds, like background musics
|
/// gun shots. For longer sounds, like background musics
|
||||||
/// or long speeches, rather see sf::Music (which is based
|
/// or long speeches, rather see sf::Music (which is based
|
||||||
/// on streaming).
|
/// on streaming).
|
||||||
///
|
///
|
||||||
/// In order to work, a sound must be given a buffer of audio
|
/// In order to work, a sound must be given a buffer of audio
|
||||||
/// data to play. Audio data (samples) is stored in sf::SoundBuffer,
|
/// data to play. Audio data (samples) is stored in sf::SoundBuffer,
|
||||||
/// and attached to a sound with the setBuffer() function.
|
/// and attached to a sound with the setBuffer() function.
|
||||||
/// The buffer object attached to a sound must remain alive
|
/// The buffer object attached to a sound must remain alive
|
||||||
/// as long as the sound uses it. Note that multiple sounds
|
/// as long as the sound uses it. Note that multiple sounds
|
||||||
/// can use the same sound buffer at the same time.
|
/// can use the same sound buffer at the same time.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::SoundBuffer buffer;
|
/// sf::SoundBuffer buffer;
|
||||||
/// buffer.loadFromFile("sound.wav");
|
/// buffer.loadFromFile("sound.wav");
|
||||||
///
|
///
|
||||||
/// sf::Sound sound;
|
/// sf::Sound sound;
|
||||||
/// sound.setBuffer(buffer);
|
/// sound.setBuffer(buffer);
|
||||||
/// sound.play();
|
/// sound.play();
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::SoundBuffer, sf::Music
|
/// \see sf::SoundBuffer, sf::Music
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,359 +1,359 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOUNDBUFFER_HPP
|
#ifndef SFML_SOUNDBUFFER_HPP
|
||||||
#define SFML_SOUNDBUFFER_HPP
|
#define SFML_SOUNDBUFFER_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
class SoundFile;
|
class SoundFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sound;
|
class Sound;
|
||||||
class InputStream;
|
class InputStream;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Storage for audio samples defining a sound
|
/// \brief Storage for audio samples defining a sound
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API SoundBuffer
|
class SFML_AUDIO_API SoundBuffer
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundBuffer();
|
SoundBuffer();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy constructor
|
/// \brief Copy constructor
|
||||||
///
|
///
|
||||||
/// \param copy Instance to copy
|
/// \param copy Instance to copy
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundBuffer(const SoundBuffer& copy);
|
SoundBuffer(const SoundBuffer& copy);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~SoundBuffer();
|
~SoundBuffer();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the sound buffer from a file
|
/// \brief Load the sound buffer from a file
|
||||||
///
|
///
|
||||||
/// Here is a complete list of all the supported audio formats:
|
/// Here is a complete list of all the supported audio formats:
|
||||||
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
||||||
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
||||||
///
|
///
|
||||||
/// \param filename Path of the sound file to load
|
/// \param filename Path of the sound file to load
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromMemory, loadFromStream, loadFromSamples, saveToFile
|
/// \see loadFromMemory, loadFromStream, loadFromSamples, saveToFile
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromFile(const std::string& filename);
|
bool loadFromFile(const std::string& filename);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the sound buffer from a file in memory
|
/// \brief Load the sound buffer from a file in memory
|
||||||
///
|
///
|
||||||
/// Here is a complete list of all the supported audio formats:
|
/// Here is a complete list of all the supported audio formats:
|
||||||
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
||||||
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the file data in memory
|
/// \param data Pointer to the file data in memory
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
/// \param sizeInBytes Size of the data to load, in bytes
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromStream, loadFromSamples
|
/// \see loadFromFile, loadFromStream, loadFromSamples
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the sound buffer from a custom stream
|
/// \brief Load the sound buffer from a custom stream
|
||||||
///
|
///
|
||||||
/// Here is a complete list of all the supported audio formats:
|
/// Here is a complete list of all the supported audio formats:
|
||||||
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
||||||
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
||||||
///
|
///
|
||||||
/// \param stream Source stream to read from
|
/// \param stream Source stream to read from
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromMemory, loadFromSamples
|
/// \see loadFromFile, loadFromMemory, loadFromSamples
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromStream(InputStream& stream);
|
bool loadFromStream(InputStream& stream);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the sound buffer from an array of audio samples
|
/// \brief Load the sound buffer from an array of audio samples
|
||||||
///
|
///
|
||||||
/// The assumed format of the audio samples is 16 bits signed integer
|
/// The assumed format of the audio samples is 16 bits signed integer
|
||||||
/// (sf::Int16).
|
/// (sf::Int16).
|
||||||
///
|
///
|
||||||
/// \param samples Pointer to the array of samples in memory
|
/// \param samples Pointer to the array of samples in memory
|
||||||
/// \param sampleCount Number of samples in the array
|
/// \param sampleCount Number of samples in the array
|
||||||
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
|
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
|
||||||
/// \param sampleRate Sample rate (number of samples to play per second)
|
/// \param sampleRate Sample rate (number of samples to play per second)
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromMemory, saveToFile
|
/// \see loadFromFile, loadFromMemory, saveToFile
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromSamples(const Int16* samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate);
|
bool loadFromSamples(const Int16* samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Save the sound buffer to an audio file
|
/// \brief Save the sound buffer to an audio file
|
||||||
///
|
///
|
||||||
/// Here is a complete list of all the supported audio formats:
|
/// Here is a complete list of all the supported audio formats:
|
||||||
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
|
||||||
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
|
||||||
///
|
///
|
||||||
/// \param filename Path of the sound file to write
|
/// \param filename Path of the sound file to write
|
||||||
///
|
///
|
||||||
/// \return True if saving succeeded, false if it failed
|
/// \return True if saving succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromMemory, loadFromSamples
|
/// \see loadFromFile, loadFromMemory, loadFromSamples
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool saveToFile(const std::string& filename) const;
|
bool saveToFile(const std::string& filename) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the array of audio samples stored in the buffer
|
/// \brief Get the array of audio samples stored in the buffer
|
||||||
///
|
///
|
||||||
/// The format of the returned samples is 16 bits signed integer
|
/// The format of the returned samples is 16 bits signed integer
|
||||||
/// (sf::Int16). The total number of samples in this array
|
/// (sf::Int16). The total number of samples in this array
|
||||||
/// is given by the getSampleCount() function.
|
/// is given by the getSampleCount() function.
|
||||||
///
|
///
|
||||||
/// \return Read-only pointer to the array of sound samples
|
/// \return Read-only pointer to the array of sound samples
|
||||||
///
|
///
|
||||||
/// \see getSampleCount
|
/// \see getSampleCount
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Int16* getSamples() const;
|
const Int16* getSamples() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the number of samples stored in the buffer
|
/// \brief Get the number of samples stored in the buffer
|
||||||
///
|
///
|
||||||
/// The array of samples can be accessed with the getSamples()
|
/// The array of samples can be accessed with the getSamples()
|
||||||
/// function.
|
/// function.
|
||||||
///
|
///
|
||||||
/// \return Number of samples
|
/// \return Number of samples
|
||||||
///
|
///
|
||||||
/// \see getSamples
|
/// \see getSamples
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::size_t getSampleCount() const;
|
std::size_t getSampleCount() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the sample rate of the sound
|
/// \brief Get the sample rate of the sound
|
||||||
///
|
///
|
||||||
/// The sample rate is the number of samples played per second.
|
/// The sample rate is the number of samples played per second.
|
||||||
/// The higher, the better the quality (for example, 44100
|
/// The higher, the better the quality (for example, 44100
|
||||||
/// samples/s is CD quality).
|
/// samples/s is CD quality).
|
||||||
///
|
///
|
||||||
/// \return Sample rate (number of samples per second)
|
/// \return Sample rate (number of samples per second)
|
||||||
///
|
///
|
||||||
/// \see getChannelCount, getDuration
|
/// \see getChannelCount, getDuration
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getSampleRate() const;
|
unsigned int getSampleRate() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the number of channels used by the sound
|
/// \brief Get the number of channels used by the sound
|
||||||
///
|
///
|
||||||
/// If the sound is mono then the number of channels will
|
/// If the sound is mono then the number of channels will
|
||||||
/// be 1, 2 for stereo, etc.
|
/// be 1, 2 for stereo, etc.
|
||||||
///
|
///
|
||||||
/// \return Number of channels
|
/// \return Number of channels
|
||||||
///
|
///
|
||||||
/// \see getSampleRate, getDuration
|
/// \see getSampleRate, getDuration
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getChannelCount() const;
|
unsigned int getChannelCount() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the total duration of the sound
|
/// \brief Get the total duration of the sound
|
||||||
///
|
///
|
||||||
/// \return Sound duration
|
/// \return Sound duration
|
||||||
///
|
///
|
||||||
/// \see getSampleRate, getChannelCount
|
/// \see getSampleRate, getChannelCount
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Time getDuration() const;
|
Time getDuration() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of assignment operator
|
/// \brief Overload of assignment operator
|
||||||
///
|
///
|
||||||
/// \param right Instance to assign
|
/// \param right Instance to assign
|
||||||
///
|
///
|
||||||
/// \return Reference to self
|
/// \return Reference to self
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundBuffer& operator =(const SoundBuffer& right);
|
SoundBuffer& operator =(const SoundBuffer& right);
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
friend class Sound;
|
friend class Sound;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Initialize the internal state after loading a new sound
|
/// \brief Initialize the internal state after loading a new sound
|
||||||
///
|
///
|
||||||
/// \param file Sound file providing access to the new loaded sound
|
/// \param file Sound file providing access to the new loaded sound
|
||||||
///
|
///
|
||||||
/// \return True on succesful initialization, false on failure
|
/// \return True on succesful initialization, false on failure
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool initialize(priv::SoundFile& file);
|
bool initialize(priv::SoundFile& file);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the internal buffer with the cached audio samples
|
/// \brief Update the internal buffer with the cached audio samples
|
||||||
///
|
///
|
||||||
/// \param channelCount Number of channels
|
/// \param channelCount Number of channels
|
||||||
/// \param sampleRate Sample rate (number of samples per second)
|
/// \param sampleRate Sample rate (number of samples per second)
|
||||||
///
|
///
|
||||||
/// \return True on success, false if any error happened
|
/// \return True on success, false if any error happened
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool update(unsigned int channelCount, unsigned int sampleRate);
|
bool update(unsigned int channelCount, unsigned int sampleRate);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Add a sound to the list of sounds that use this buffer
|
/// \brief Add a sound to the list of sounds that use this buffer
|
||||||
///
|
///
|
||||||
/// \param sound Sound instance to attach
|
/// \param sound Sound instance to attach
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void attachSound(Sound* sound) const;
|
void attachSound(Sound* sound) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Remove a sound from the list of sounds that use this buffer
|
/// \brief Remove a sound from the list of sounds that use this buffer
|
||||||
///
|
///
|
||||||
/// \param sound Sound instance to detach
|
/// \param sound Sound instance to detach
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void detachSound(Sound* sound) const;
|
void detachSound(Sound* sound) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Types
|
// Types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef std::set<Sound*> SoundList; ///< Set of unique sound instances
|
typedef std::set<Sound*> SoundList; ///< Set of unique sound instances
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int m_buffer; ///< OpenAL buffer identifier
|
unsigned int m_buffer; ///< OpenAL buffer identifier
|
||||||
std::vector<Int16> m_samples; ///< Samples buffer
|
std::vector<Int16> m_samples; ///< Samples buffer
|
||||||
Time m_duration; ///< Sound duration
|
Time m_duration; ///< Sound duration
|
||||||
mutable SoundList m_sounds; ///< List of sounds that are using this buffer
|
mutable SoundList m_sounds; ///< List of sounds that are using this buffer
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDBUFFER_HPP
|
#endif // SFML_SOUNDBUFFER_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::SoundBuffer
|
/// \class sf::SoundBuffer
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// A sound buffer holds the data of a sound, which is
|
/// A sound buffer holds the data of a sound, which is
|
||||||
/// an array of audio samples. A sample is a 16 bits signed integer
|
/// an array of audio samples. A sample is a 16 bits signed integer
|
||||||
/// that defines the amplitude of the sound at a given time.
|
/// that defines the amplitude of the sound at a given time.
|
||||||
/// The sound is then restituted by playing these samples at
|
/// The sound is then restituted by playing these samples at
|
||||||
/// a high rate (for example, 44100 samples per second is the
|
/// a high rate (for example, 44100 samples per second is the
|
||||||
/// standard rate used for playing CDs). In short, audio samples
|
/// standard rate used for playing CDs). In short, audio samples
|
||||||
/// are like texture pixels, and a sf::SoundBuffer is similar to
|
/// are like texture pixels, and a sf::SoundBuffer is similar to
|
||||||
/// a sf::Texture.
|
/// a sf::Texture.
|
||||||
///
|
///
|
||||||
/// A sound buffer can be loaded from a file (see loadFromFile()
|
/// A sound buffer can be loaded from a file (see loadFromFile()
|
||||||
/// for the complete list of supported formats), from memory, from
|
/// for the complete list of supported formats), from memory, from
|
||||||
/// a custom stream (see sf::InputStream) or directly from an array
|
/// a custom stream (see sf::InputStream) or directly from an array
|
||||||
/// of samples. It can also be saved back to a file.
|
/// of samples. It can also be saved back to a file.
|
||||||
///
|
///
|
||||||
/// Sound buffers alone are not very useful: they hold the audio data
|
/// Sound buffers alone are not very useful: they hold the audio data
|
||||||
/// but cannot be played. To do so, you need to use the sf::Sound class,
|
/// but cannot be played. To do so, you need to use the sf::Sound class,
|
||||||
/// which provides functions to play/pause/stop the sound as well as
|
/// which provides functions to play/pause/stop the sound as well as
|
||||||
/// changing the way it is outputted (volume, pitch, 3D position, ...).
|
/// changing the way it is outputted (volume, pitch, 3D position, ...).
|
||||||
/// This separation allows more flexibility and better performances:
|
/// This separation allows more flexibility and better performances:
|
||||||
/// indeed a sf::SoundBuffer is a heavy resource, and any operation on it
|
/// indeed a sf::SoundBuffer is a heavy resource, and any operation on it
|
||||||
/// is slow (often too slow for real-time applications). On the other
|
/// is slow (often too slow for real-time applications). On the other
|
||||||
/// side, a sf::Sound is a lightweight object, which can use the audio data
|
/// side, a sf::Sound is a lightweight object, which can use the audio data
|
||||||
/// of a sound buffer and change the way it is played without actually
|
/// of a sound buffer and change the way it is played without actually
|
||||||
/// modifying that data. Note that it is also possible to bind
|
/// modifying that data. Note that it is also possible to bind
|
||||||
/// several sf::Sound instances to the same sf::SoundBuffer.
|
/// several sf::Sound instances to the same sf::SoundBuffer.
|
||||||
///
|
///
|
||||||
/// It is important to note that the sf::Sound instance doesn't
|
/// It is important to note that the sf::Sound instance doesn't
|
||||||
/// copy the buffer that it uses, it only keeps a reference to it.
|
/// copy the buffer that it uses, it only keeps a reference to it.
|
||||||
/// Thus, a sf::SoundBuffer must not be destructed while it is
|
/// Thus, a sf::SoundBuffer must not be destructed while it is
|
||||||
/// used by a sf::Sound (i.e. never write a function that
|
/// used by a sf::Sound (i.e. never write a function that
|
||||||
/// uses a local sf::SoundBuffer instance for loading a sound).
|
/// uses a local sf::SoundBuffer instance for loading a sound).
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Declare a new sound buffer
|
/// // Declare a new sound buffer
|
||||||
/// sf::SoundBuffer buffer;
|
/// sf::SoundBuffer buffer;
|
||||||
///
|
///
|
||||||
/// // Load it from a file
|
/// // Load it from a file
|
||||||
/// if (!buffer.loadFromFile("sound.wav"))
|
/// if (!buffer.loadFromFile("sound.wav"))
|
||||||
/// {
|
/// {
|
||||||
/// // error...
|
/// // error...
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Create a sound source and bind it to the buffer
|
/// // Create a sound source and bind it to the buffer
|
||||||
/// sf::Sound sound1;
|
/// sf::Sound sound1;
|
||||||
/// sound1.setBuffer(buffer);
|
/// sound1.setBuffer(buffer);
|
||||||
///
|
///
|
||||||
/// // Play the sound
|
/// // Play the sound
|
||||||
/// sound1.play();
|
/// sound1.play();
|
||||||
///
|
///
|
||||||
/// // Create another sound source bound to the same buffer
|
/// // Create another sound source bound to the same buffer
|
||||||
/// sf::Sound sound2;
|
/// sf::Sound sound2;
|
||||||
/// sound2.setBuffer(buffer);
|
/// sound2.setBuffer(buffer);
|
||||||
///
|
///
|
||||||
/// // Play it with a higher pitch -- the first sound remains unchanged
|
/// // Play it with a higher pitch -- the first sound remains unchanged
|
||||||
/// sound2.setPitch(2);
|
/// sound2.setPitch(2);
|
||||||
/// sound2.play();
|
/// sound2.play();
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Sound, sf::SoundBufferRecorder
|
/// \see sf::Sound, sf::SoundBufferRecorder
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,138 +1,138 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOUNDBUFFERRECORDER_HPP
|
#ifndef SFML_SOUNDBUFFERRECORDER_HPP
|
||||||
#define SFML_SOUNDBUFFERRECORDER_HPP
|
#define SFML_SOUNDBUFFERRECORDER_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/Audio/SoundBuffer.hpp>
|
#include <SFML/Audio/SoundBuffer.hpp>
|
||||||
#include <SFML/Audio/SoundRecorder.hpp>
|
#include <SFML/Audio/SoundRecorder.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Specialized SoundRecorder which stores the captured
|
/// \brief Specialized SoundRecorder which stores the captured
|
||||||
/// audio data into a sound buffer
|
/// audio data into a sound buffer
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
|
class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the sound buffer containing the captured audio data
|
/// \brief Get the sound buffer containing the captured audio data
|
||||||
///
|
///
|
||||||
/// The sound buffer is valid only after the capture has ended.
|
/// The sound buffer is valid only after the capture has ended.
|
||||||
/// This function provides a read-only access to the internal
|
/// This function provides a read-only access to the internal
|
||||||
/// sound buffer, but it can be copied if you need to
|
/// sound buffer, but it can be copied if you need to
|
||||||
/// make any modification to it.
|
/// make any modification to it.
|
||||||
///
|
///
|
||||||
/// \return Read-only access to the sound buffer
|
/// \return Read-only access to the sound buffer
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const SoundBuffer& getBuffer() const;
|
const SoundBuffer& getBuffer() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Start capturing audio data
|
/// \brief Start capturing audio data
|
||||||
///
|
///
|
||||||
/// \return True to start the capture, or false to abort it
|
/// \return True to start the capture, or false to abort it
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onStart();
|
virtual bool onStart();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Process a new chunk of recorded samples
|
/// \brief Process a new chunk of recorded samples
|
||||||
///
|
///
|
||||||
/// \param samples Pointer to the new chunk of recorded samples
|
/// \param samples Pointer to the new chunk of recorded samples
|
||||||
/// \param sampleCount Number of samples pointed by \a samples
|
/// \param sampleCount Number of samples pointed by \a samples
|
||||||
///
|
///
|
||||||
/// \return True to continue the capture, or false to stop it
|
/// \return True to continue the capture, or false to stop it
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount);
|
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Stop capturing audio data
|
/// \brief Stop capturing audio data
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onStop();
|
virtual void onStop();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::vector<Int16> m_samples; ///< Temporary sample buffer to hold the recorded data
|
std::vector<Int16> m_samples; ///< Temporary sample buffer to hold the recorded data
|
||||||
SoundBuffer m_buffer; ///< Sound buffer that will contain the recorded data
|
SoundBuffer m_buffer; ///< Sound buffer that will contain the recorded data
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
#endif // SFML_SOUNDBUFFERRECORDER_HPP
|
#endif // SFML_SOUNDBUFFERRECORDER_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::SoundBufferRecorder
|
/// \class sf::SoundBufferRecorder
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// sf::SoundBufferRecorder allows to access a recorded sound
|
/// sf::SoundBufferRecorder allows to access a recorded sound
|
||||||
/// through a sf::SoundBuffer, so that it can be played, saved
|
/// through a sf::SoundBuffer, so that it can be played, saved
|
||||||
/// to a file, etc.
|
/// to a file, etc.
|
||||||
///
|
///
|
||||||
/// It has the same simple interface as its base class (start(), stop())
|
/// It has the same simple interface as its base class (start(), stop())
|
||||||
/// and adds a function to retrieve the recorded sound buffer
|
/// and adds a function to retrieve the recorded sound buffer
|
||||||
/// (getBuffer()).
|
/// (getBuffer()).
|
||||||
///
|
///
|
||||||
/// As usual, don't forget to call the isAvailable() function
|
/// As usual, don't forget to call the isAvailable() function
|
||||||
/// before using this class (see sf::SoundRecorder for more details
|
/// before using this class (see sf::SoundRecorder for more details
|
||||||
/// about this).
|
/// about this).
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// if (sf::SoundBufferRecorder::isAvailable())
|
/// if (sf::SoundBufferRecorder::isAvailable())
|
||||||
/// {
|
/// {
|
||||||
/// // Record some audio data
|
/// // Record some audio data
|
||||||
/// sf::SoundBufferRecorder recorder;
|
/// sf::SoundBufferRecorder recorder;
|
||||||
/// recorder.start();
|
/// recorder.start();
|
||||||
/// ...
|
/// ...
|
||||||
/// recorder.stop();
|
/// recorder.stop();
|
||||||
///
|
///
|
||||||
/// // Get the buffer containing the captured audio data
|
/// // Get the buffer containing the captured audio data
|
||||||
/// const sf::SoundBuffer& buffer = recorder.getBuffer();
|
/// const sf::SoundBuffer& buffer = recorder.getBuffer();
|
||||||
///
|
///
|
||||||
/// // Save it to a file (for example...)
|
/// // Save it to a file (for example...)
|
||||||
/// buffer.saveToFile("my_record.ogg");
|
/// buffer.saveToFile("my_record.ogg");
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::SoundRecorder
|
/// \see sf::SoundRecorder
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,363 +1,363 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOUNDRECORDER_HPP
|
#ifndef SFML_SOUNDRECORDER_HPP
|
||||||
#define SFML_SOUNDRECORDER_HPP
|
#define SFML_SOUNDRECORDER_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/System/Thread.hpp>
|
#include <SFML/System/Thread.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Abstract base class for capturing sound data
|
/// \brief Abstract base class for capturing sound data
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API SoundRecorder
|
class SFML_AUDIO_API SoundRecorder
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief destructor
|
/// \brief destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~SoundRecorder();
|
virtual ~SoundRecorder();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Start the capture
|
/// \brief Start the capture
|
||||||
///
|
///
|
||||||
/// The \a sampleRate parameter defines the number of audio samples
|
/// The \a sampleRate parameter defines the number of audio samples
|
||||||
/// captured per second. The higher, the better the quality
|
/// captured per second. The higher, the better the quality
|
||||||
/// (for example, 44100 samples/sec is CD quality).
|
/// (for example, 44100 samples/sec is CD quality).
|
||||||
/// This function uses its own thread so that it doesn't block
|
/// This function uses its own thread so that it doesn't block
|
||||||
/// the rest of the program while the capture runs.
|
/// the rest of the program while the capture runs.
|
||||||
/// Please note that only one capture can happen at the same time.
|
/// Please note that only one capture can happen at the same time.
|
||||||
/// You can select which capture device will be used, by passing
|
/// You can select which capture device will be used, by passing
|
||||||
/// the name to the setDevice() method. If none was selected
|
/// the name to the setDevice() method. If none was selected
|
||||||
/// before, the default capture device will be used. You can get a
|
/// before, the default capture device will be used. You can get a
|
||||||
/// list of the names of all available capture devices by calling
|
/// list of the names of all available capture devices by calling
|
||||||
/// getAvailableDevices().
|
/// getAvailableDevices().
|
||||||
///
|
///
|
||||||
/// \param sampleRate Desired capture rate, in number of samples per second
|
/// \param sampleRate Desired capture rate, in number of samples per second
|
||||||
///
|
///
|
||||||
/// \return True, if start of capture was successful
|
/// \return True, if start of capture was successful
|
||||||
///
|
///
|
||||||
/// \see stop, getAvailableDevices
|
/// \see stop, getAvailableDevices
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool start(unsigned int sampleRate = 44100);
|
bool start(unsigned int sampleRate = 44100);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Stop the capture
|
/// \brief Stop the capture
|
||||||
///
|
///
|
||||||
/// \see start
|
/// \see start
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the sample rate
|
/// \brief Get the sample rate
|
||||||
///
|
///
|
||||||
/// The sample rate defines the number of audio samples
|
/// The sample rate defines the number of audio samples
|
||||||
/// captured per second. The higher, the better the quality
|
/// captured per second. The higher, the better the quality
|
||||||
/// (for example, 44100 samples/sec is CD quality).
|
/// (for example, 44100 samples/sec is CD quality).
|
||||||
///
|
///
|
||||||
/// \return Sample rate, in samples per second
|
/// \return Sample rate, in samples per second
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getSampleRate() const;
|
unsigned int getSampleRate() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get a list of the names of all availabe audio capture devices
|
/// \brief Get a list of the names of all availabe audio capture devices
|
||||||
///
|
///
|
||||||
/// This function returns a vector of strings, containing
|
/// This function returns a vector of strings, containing
|
||||||
/// the names of all availabe audio capture devices.
|
/// the names of all availabe audio capture devices.
|
||||||
///
|
///
|
||||||
/// \return A vector of strings containing the names
|
/// \return A vector of strings containing the names
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static std::vector<std::string> getAvailableDevices();
|
static std::vector<std::string> getAvailableDevices();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the name of the default audio capture device
|
/// \brief Get the name of the default audio capture device
|
||||||
///
|
///
|
||||||
/// This function returns the name of the default audio
|
/// This function returns the name of the default audio
|
||||||
/// capture device. If none is available, an empty string
|
/// capture device. If none is available, an empty string
|
||||||
/// is returned.
|
/// is returned.
|
||||||
///
|
///
|
||||||
/// \return The name of the default audio capture device
|
/// \return The name of the default audio capture device
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static std::string getDefaultDevice();
|
static std::string getDefaultDevice();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the audio capture device
|
/// \brief Set the audio capture device
|
||||||
///
|
///
|
||||||
/// This function sets the audio capture device to the device
|
/// This function sets the audio capture device to the device
|
||||||
/// with the given \a name. It can be called on the fly (i.e:
|
/// with the given \a name. It can be called on the fly (i.e:
|
||||||
/// while recording). If you do so while recording and
|
/// while recording). If you do so while recording and
|
||||||
/// opening the device fails, it stops the recording.
|
/// opening the device fails, it stops the recording.
|
||||||
///
|
///
|
||||||
/// \param name The name of the audio capture device
|
/// \param name The name of the audio capture device
|
||||||
///
|
///
|
||||||
/// \return True, if it was able to set the requested device
|
/// \return True, if it was able to set the requested device
|
||||||
///
|
///
|
||||||
/// \see getAvailableDevices, getDefaultDevice
|
/// \see getAvailableDevices, getDefaultDevice
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool setDevice(const std::string& name);
|
bool setDevice(const std::string& name);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the name of the current audio capture device
|
/// \brief Get the name of the current audio capture device
|
||||||
///
|
///
|
||||||
/// \return The name of the current audio capture device
|
/// \return The name of the current audio capture device
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const std::string& getDevice() const;
|
const std::string& getDevice() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check if the system supports audio capture
|
/// \brief Check if the system supports audio capture
|
||||||
///
|
///
|
||||||
/// This function should always be called before using
|
/// This function should always be called before using
|
||||||
/// the audio capture features. If it returns false, then
|
/// the audio capture features. If it returns false, then
|
||||||
/// any attempt to use sf::SoundRecorder or one of its derived
|
/// any attempt to use sf::SoundRecorder or one of its derived
|
||||||
/// classes will fail.
|
/// classes will fail.
|
||||||
///
|
///
|
||||||
/// \return True if audio capture is supported, false otherwise
|
/// \return True if audio capture is supported, false otherwise
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static bool isAvailable();
|
static bool isAvailable();
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor is only meant to be called by derived classes.
|
/// This constructor is only meant to be called by derived classes.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundRecorder();
|
SoundRecorder();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the processing interval
|
/// \brief Set the processing interval
|
||||||
///
|
///
|
||||||
/// The processing interval controls the period
|
/// The processing interval controls the period
|
||||||
/// between calls to the onProcessSamples function. You may
|
/// between calls to the onProcessSamples function. You may
|
||||||
/// want to use a small interval if you want to process the
|
/// want to use a small interval if you want to process the
|
||||||
/// recorded data in real time, for example.
|
/// recorded data in real time, for example.
|
||||||
///
|
///
|
||||||
/// Note: this is only a hint, the actual period may vary.
|
/// Note: this is only a hint, the actual period may vary.
|
||||||
/// So don't rely on this parameter to implement precise timing.
|
/// So don't rely on this parameter to implement precise timing.
|
||||||
///
|
///
|
||||||
/// The default processing interval is 100 ms.
|
/// The default processing interval is 100 ms.
|
||||||
///
|
///
|
||||||
/// \param interval Processing interval
|
/// \param interval Processing interval
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setProcessingInterval(sf::Time interval);
|
void setProcessingInterval(sf::Time interval);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Start capturing audio data
|
/// \brief Start capturing audio data
|
||||||
///
|
///
|
||||||
/// This virtual function may be overriden by a derived class
|
/// This virtual function may be overriden by a derived class
|
||||||
/// if something has to be done every time a new capture
|
/// if something has to be done every time a new capture
|
||||||
/// starts. If not, this function can be ignored; the default
|
/// starts. If not, this function can be ignored; the default
|
||||||
/// implementation does nothing.
|
/// implementation does nothing.
|
||||||
///
|
///
|
||||||
/// \return True to start the capture, or false to abort it
|
/// \return True to start the capture, or false to abort it
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onStart();
|
virtual bool onStart();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Process a new chunk of recorded samples
|
/// \brief Process a new chunk of recorded samples
|
||||||
///
|
///
|
||||||
/// This virtual function is called every time a new chunk of
|
/// This virtual function is called every time a new chunk of
|
||||||
/// recorded data is available. The derived class can then do
|
/// recorded data is available. The derived class can then do
|
||||||
/// whatever it wants with it (storing it, playing it, sending
|
/// whatever it wants with it (storing it, playing it, sending
|
||||||
/// it over the network, etc.).
|
/// it over the network, etc.).
|
||||||
///
|
///
|
||||||
/// \param samples Pointer to the new chunk of recorded samples
|
/// \param samples Pointer to the new chunk of recorded samples
|
||||||
/// \param sampleCount Number of samples pointed by \a samples
|
/// \param sampleCount Number of samples pointed by \a samples
|
||||||
///
|
///
|
||||||
/// \return True to continue the capture, or false to stop it
|
/// \return True to continue the capture, or false to stop it
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount) = 0;
|
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount) = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Stop capturing audio data
|
/// \brief Stop capturing audio data
|
||||||
///
|
///
|
||||||
/// This virtual function may be overriden by a derived class
|
/// This virtual function may be overriden by a derived class
|
||||||
/// if something has to be done every time the capture
|
/// if something has to be done every time the capture
|
||||||
/// ends. If not, this function can be ignored; the default
|
/// ends. If not, this function can be ignored; the default
|
||||||
/// implementation does nothing.
|
/// implementation does nothing.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onStop();
|
virtual void onStop();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Function called as the entry point of the thread
|
/// \brief Function called as the entry point of the thread
|
||||||
///
|
///
|
||||||
/// This function starts the recording loop, and returns
|
/// This function starts the recording loop, and returns
|
||||||
/// only when the capture is stopped.
|
/// only when the capture is stopped.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void record();
|
void record();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the new available audio samples and process them
|
/// \brief Get the new available audio samples and process them
|
||||||
///
|
///
|
||||||
/// This function is called continuously during the
|
/// This function is called continuously during the
|
||||||
/// capture loop. It retrieves the captured samples and
|
/// capture loop. It retrieves the captured samples and
|
||||||
/// forwards them to the derived class.
|
/// forwards them to the derived class.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void processCapturedSamples();
|
void processCapturedSamples();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Clean up the recorder's internal resources
|
/// \brief Clean up the recorder's internal resources
|
||||||
///
|
///
|
||||||
/// This function is called when the capture stops.
|
/// This function is called when the capture stops.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Thread m_thread; ///< Thread running the background recording task
|
Thread m_thread; ///< Thread running the background recording task
|
||||||
std::vector<Int16> m_samples; ///< Buffer to store captured samples
|
std::vector<Int16> m_samples; ///< Buffer to store captured samples
|
||||||
unsigned int m_sampleRate; ///< Sample rate
|
unsigned int m_sampleRate; ///< Sample rate
|
||||||
sf::Time m_processingInterval; ///< Time period between calls to onProcessSamples
|
sf::Time m_processingInterval; ///< Time period between calls to onProcessSamples
|
||||||
bool m_isCapturing; ///< Capturing state
|
bool m_isCapturing; ///< Capturing state
|
||||||
std::string m_deviceName; ///< Name of the audio capture device
|
std::string m_deviceName; ///< Name of the audio capture device
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDRECORDER_HPP
|
#endif // SFML_SOUNDRECORDER_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::SoundRecorder
|
/// \class sf::SoundRecorder
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// sf::SoundBuffer provides a simple interface to access
|
/// sf::SoundBuffer provides a simple interface to access
|
||||||
/// the audio recording capabilities of the computer
|
/// the audio recording capabilities of the computer
|
||||||
/// (the microphone). As an abstract base class, it only cares
|
/// (the microphone). As an abstract base class, it only cares
|
||||||
/// about capturing sound samples, the task of making something
|
/// about capturing sound samples, the task of making something
|
||||||
/// useful with them is left to the derived class. Note that
|
/// useful with them is left to the derived class. Note that
|
||||||
/// SFML provides a built-in specialization for saving the
|
/// SFML provides a built-in specialization for saving the
|
||||||
/// captured data to a sound buffer (see sf::SoundBufferRecorder).
|
/// captured data to a sound buffer (see sf::SoundBufferRecorder).
|
||||||
///
|
///
|
||||||
/// A derived class has only one virtual function to override:
|
/// A derived class has only one virtual function to override:
|
||||||
/// \li onProcessSamples provides the new chunks of audio samples while the capture happens
|
/// \li onProcessSamples provides the new chunks of audio samples while the capture happens
|
||||||
///
|
///
|
||||||
/// Moreover, two additionnal virtual functions can be overriden
|
/// Moreover, two additionnal virtual functions can be overriden
|
||||||
/// as well if necessary:
|
/// as well if necessary:
|
||||||
/// \li onStart is called before the capture happens, to perform custom initializations
|
/// \li onStart is called before the capture happens, to perform custom initializations
|
||||||
/// \li onStop is called after the capture ends, to perform custom cleanup
|
/// \li onStop is called after the capture ends, to perform custom cleanup
|
||||||
///
|
///
|
||||||
/// A derived class can also control the frequency of the onProcessSamples
|
/// A derived class can also control the frequency of the onProcessSamples
|
||||||
/// calls, with the setProcessingInterval protected function. The default
|
/// calls, with the setProcessingInterval protected function. The default
|
||||||
/// interval is chosen so that recording thread doesn't consume too much
|
/// interval is chosen so that recording thread doesn't consume too much
|
||||||
/// CPU, but it can be changed to a smaller value if you need to process
|
/// CPU, but it can be changed to a smaller value if you need to process
|
||||||
/// the recorded data in real time, for example.
|
/// the recorded data in real time, for example.
|
||||||
///
|
///
|
||||||
/// The audio capture feature may not be supported or activated
|
/// The audio capture feature may not be supported or activated
|
||||||
/// on every platform, thus it is recommended to check its
|
/// on every platform, thus it is recommended to check its
|
||||||
/// availability with the isAvailable() function. If it returns
|
/// availability with the isAvailable() function. If it returns
|
||||||
/// false, then any attempt to use an audio recorder will fail.
|
/// false, then any attempt to use an audio recorder will fail.
|
||||||
///
|
///
|
||||||
/// If you have multiple sound input devices connected to your
|
/// If you have multiple sound input devices connected to your
|
||||||
/// computer (for example: microphone, external soundcard, webcam mic, ...)
|
/// computer (for example: microphone, external soundcard, webcam mic, ...)
|
||||||
/// you can get a list of all available devices throught the
|
/// you can get a list of all available devices throught the
|
||||||
/// getAvailableDevices() function. You can then select a device
|
/// getAvailableDevices() function. You can then select a device
|
||||||
/// by calling setDevice() with the appropiate device. Otherwise
|
/// by calling setDevice() with the appropiate device. Otherwise
|
||||||
/// the default capturing device will be used.
|
/// the default capturing device will be used.
|
||||||
///
|
///
|
||||||
/// It is important to note that the audio capture happens in a
|
/// It is important to note that the audio capture happens in a
|
||||||
/// separate thread, so that it doesn't block the rest of the
|
/// separate thread, so that it doesn't block the rest of the
|
||||||
/// program. In particular, the onProcessSamples virtual function
|
/// program. In particular, the onProcessSamples virtual function
|
||||||
/// (but not onStart and not onStop) will be called
|
/// (but not onStart and not onStop) will be called
|
||||||
/// from this separate thread. It is important to keep this in
|
/// from this separate thread. It is important to keep this in
|
||||||
/// mind, because you may have to take care of synchronization
|
/// mind, because you may have to take care of synchronization
|
||||||
/// issues if you share data between threads.
|
/// issues if you share data between threads.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// class CustomRecorder : public sf::SoundRecorder
|
/// class CustomRecorder : public sf::SoundRecorder
|
||||||
/// {
|
/// {
|
||||||
/// virtual bool onStart() // optional
|
/// virtual bool onStart() // optional
|
||||||
/// {
|
/// {
|
||||||
/// // Initialize whatever has to be done before the capture starts
|
/// // Initialize whatever has to be done before the capture starts
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
/// // Return true to start playing
|
/// // Return true to start playing
|
||||||
/// return true;
|
/// return true;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount)
|
/// virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount)
|
||||||
/// {
|
/// {
|
||||||
/// // Do something with the new chunk of samples (store them, send them, ...)
|
/// // Do something with the new chunk of samples (store them, send them, ...)
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
/// // Return true to continue playing
|
/// // Return true to continue playing
|
||||||
/// return true;
|
/// return true;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// virtual void onStop() // optional
|
/// virtual void onStop() // optional
|
||||||
/// {
|
/// {
|
||||||
/// // Clean up whatever has to be done after the capture ends
|
/// // Clean up whatever has to be done after the capture ends
|
||||||
/// ...
|
/// ...
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Usage
|
/// // Usage
|
||||||
/// if (CustomRecorder::isAvailable())
|
/// if (CustomRecorder::isAvailable())
|
||||||
/// {
|
/// {
|
||||||
/// CustomRecorder recorder;
|
/// CustomRecorder recorder;
|
||||||
///
|
///
|
||||||
/// if (!recorder.start())
|
/// if (!recorder.start())
|
||||||
/// return -1;
|
/// return -1;
|
||||||
///
|
///
|
||||||
/// ...
|
/// ...
|
||||||
/// recorder.stop();
|
/// recorder.stop();
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::SoundBufferRecorder
|
/// \see sf::SoundBufferRecorder
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,286 +1,286 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOUNDSOURCE_HPP
|
#ifndef SFML_SOUNDSOURCE_HPP
|
||||||
#define SFML_SOUNDSOURCE_HPP
|
#define SFML_SOUNDSOURCE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/System/Vector3.hpp>
|
#include <SFML/System/Vector3.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Base class defining a sound's properties
|
/// \brief Base class defining a sound's properties
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API SoundSource
|
class SFML_AUDIO_API SoundSource
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Enumeration of the sound source states
|
/// \brief Enumeration of the sound source states
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum Status
|
enum Status
|
||||||
{
|
{
|
||||||
Stopped, ///< Sound is not playing
|
Stopped, ///< Sound is not playing
|
||||||
Paused, ///< Sound is paused
|
Paused, ///< Sound is paused
|
||||||
Playing ///< Sound is playing
|
Playing ///< Sound is playing
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy constructor
|
/// \brief Copy constructor
|
||||||
///
|
///
|
||||||
/// \param copy Instance to copy
|
/// \param copy Instance to copy
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundSource(const SoundSource& copy);
|
SoundSource(const SoundSource& copy);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~SoundSource();
|
virtual ~SoundSource();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the pitch of the sound
|
/// \brief Set the pitch of the sound
|
||||||
///
|
///
|
||||||
/// The pitch represents the perceived fundamental frequency
|
/// The pitch represents the perceived fundamental frequency
|
||||||
/// of a sound; thus you can make a sound more acute or grave
|
/// of a sound; thus you can make a sound more acute or grave
|
||||||
/// by changing its pitch. A side effect of changing the pitch
|
/// by changing its pitch. A side effect of changing the pitch
|
||||||
/// is to modify the playing speed of the sound as well.
|
/// is to modify the playing speed of the sound as well.
|
||||||
/// The default value for the pitch is 1.
|
/// The default value for the pitch is 1.
|
||||||
///
|
///
|
||||||
/// \param pitch New pitch to apply to the sound
|
/// \param pitch New pitch to apply to the sound
|
||||||
///
|
///
|
||||||
/// \see getPitch
|
/// \see getPitch
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setPitch(float pitch);
|
void setPitch(float pitch);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the volume of the sound
|
/// \brief Set the volume of the sound
|
||||||
///
|
///
|
||||||
/// The volume is a value between 0 (mute) and 100 (full volume).
|
/// The volume is a value between 0 (mute) and 100 (full volume).
|
||||||
/// The default value for the volume is 100.
|
/// The default value for the volume is 100.
|
||||||
///
|
///
|
||||||
/// \param volume Volume of the sound
|
/// \param volume Volume of the sound
|
||||||
///
|
///
|
||||||
/// \see getVolume
|
/// \see getVolume
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setVolume(float volume);
|
void setVolume(float volume);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the 3D position of the sound in the audio scene
|
/// \brief Set the 3D position of the sound in the audio scene
|
||||||
///
|
///
|
||||||
/// Only sounds with one channel (mono sounds) can be
|
/// Only sounds with one channel (mono sounds) can be
|
||||||
/// spatialized.
|
/// spatialized.
|
||||||
/// The default position of a sound is (0, 0, 0).
|
/// The default position of a sound is (0, 0, 0).
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of the position of the sound in the scene
|
/// \param x X coordinate of the position of the sound in the scene
|
||||||
/// \param y Y coordinate of the position of the sound in the scene
|
/// \param y Y coordinate of the position of the sound in the scene
|
||||||
/// \param z Z coordinate of the position of the sound in the scene
|
/// \param z Z coordinate of the position of the sound in the scene
|
||||||
///
|
///
|
||||||
/// \see getPosition
|
/// \see getPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setPosition(float x, float y, float z);
|
void setPosition(float x, float y, float z);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the 3D position of the sound in the audio scene
|
/// \brief Set the 3D position of the sound in the audio scene
|
||||||
///
|
///
|
||||||
/// Only sounds with one channel (mono sounds) can be
|
/// Only sounds with one channel (mono sounds) can be
|
||||||
/// spatialized.
|
/// spatialized.
|
||||||
/// The default position of a sound is (0, 0, 0).
|
/// The default position of a sound is (0, 0, 0).
|
||||||
///
|
///
|
||||||
/// \param position Position of the sound in the scene
|
/// \param position Position of the sound in the scene
|
||||||
///
|
///
|
||||||
/// \see getPosition
|
/// \see getPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setPosition(const Vector3f& position);
|
void setPosition(const Vector3f& position);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Make the sound's position relative to the listener or absolute
|
/// \brief Make the sound's position relative to the listener or absolute
|
||||||
///
|
///
|
||||||
/// Making a sound relative to the listener will ensure that it will always
|
/// Making a sound relative to the listener will ensure that it will always
|
||||||
/// be played the same way regardless the position of the listener.
|
/// be played the same way regardless the position of the listener.
|
||||||
/// This can be useful for non-spatialized sounds, sounds that are
|
/// This can be useful for non-spatialized sounds, sounds that are
|
||||||
/// produced by the listener, or sounds attached to it.
|
/// produced by the listener, or sounds attached to it.
|
||||||
/// The default value is false (position is absolute).
|
/// The default value is false (position is absolute).
|
||||||
///
|
///
|
||||||
/// \param relative True to set the position relative, false to set it absolute
|
/// \param relative True to set the position relative, false to set it absolute
|
||||||
///
|
///
|
||||||
/// \see isRelativeToListener
|
/// \see isRelativeToListener
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setRelativeToListener(bool relative);
|
void setRelativeToListener(bool relative);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the minimum distance of the sound
|
/// \brief Set the minimum distance of the sound
|
||||||
///
|
///
|
||||||
/// The "minimum distance" of a sound is the maximum
|
/// The "minimum distance" of a sound is the maximum
|
||||||
/// distance at which it is heard at its maximum volume. Further
|
/// distance at which it is heard at its maximum volume. Further
|
||||||
/// than the minimum distance, it will start to fade out according
|
/// than the minimum distance, it will start to fade out according
|
||||||
/// to its attenuation factor. A value of 0 ("inside the head
|
/// to its attenuation factor. A value of 0 ("inside the head
|
||||||
/// of the listener") is an invalid value and is forbidden.
|
/// of the listener") is an invalid value and is forbidden.
|
||||||
/// The default value of the minimum distance is 1.
|
/// The default value of the minimum distance is 1.
|
||||||
///
|
///
|
||||||
/// \param distance New minimum distance of the sound
|
/// \param distance New minimum distance of the sound
|
||||||
///
|
///
|
||||||
/// \see getMinDistance, setAttenuation
|
/// \see getMinDistance, setAttenuation
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setMinDistance(float distance);
|
void setMinDistance(float distance);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the attenuation factor of the sound
|
/// \brief Set the attenuation factor of the sound
|
||||||
///
|
///
|
||||||
/// The attenuation is a multiplicative factor which makes
|
/// The attenuation is a multiplicative factor which makes
|
||||||
/// the sound more or less loud according to its distance
|
/// the sound more or less loud according to its distance
|
||||||
/// from the listener. An attenuation of 0 will produce a
|
/// from the listener. An attenuation of 0 will produce a
|
||||||
/// non-attenuated sound, i.e. its volume will always be the same
|
/// non-attenuated sound, i.e. its volume will always be the same
|
||||||
/// whether it is heard from near or from far. On the other hand,
|
/// whether it is heard from near or from far. On the other hand,
|
||||||
/// an attenuation value such as 100 will make the sound fade out
|
/// an attenuation value such as 100 will make the sound fade out
|
||||||
/// very quickly as it gets further from the listener.
|
/// very quickly as it gets further from the listener.
|
||||||
/// The default value of the attenuation is 1.
|
/// The default value of the attenuation is 1.
|
||||||
///
|
///
|
||||||
/// \param attenuation New attenuation factor of the sound
|
/// \param attenuation New attenuation factor of the sound
|
||||||
///
|
///
|
||||||
/// \see getAttenuation, setMinDistance
|
/// \see getAttenuation, setMinDistance
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setAttenuation(float attenuation);
|
void setAttenuation(float attenuation);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the pitch of the sound
|
/// \brief Get the pitch of the sound
|
||||||
///
|
///
|
||||||
/// \return Pitch of the sound
|
/// \return Pitch of the sound
|
||||||
///
|
///
|
||||||
/// \see setPitch
|
/// \see setPitch
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getPitch() const;
|
float getPitch() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the volume of the sound
|
/// \brief Get the volume of the sound
|
||||||
///
|
///
|
||||||
/// \return Volume of the sound, in the range [0, 100]
|
/// \return Volume of the sound, in the range [0, 100]
|
||||||
///
|
///
|
||||||
/// \see setVolume
|
/// \see setVolume
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getVolume() const;
|
float getVolume() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the 3D position of the sound in the audio scene
|
/// \brief Get the 3D position of the sound in the audio scene
|
||||||
///
|
///
|
||||||
/// \return Position of the sound
|
/// \return Position of the sound
|
||||||
///
|
///
|
||||||
/// \see setPosition
|
/// \see setPosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector3f getPosition() const;
|
Vector3f getPosition() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether the sound's position is relative to the
|
/// \brief Tell whether the sound's position is relative to the
|
||||||
/// listener or is absolute
|
/// listener or is absolute
|
||||||
///
|
///
|
||||||
/// \return True if the position is relative, false if it's absolute
|
/// \return True if the position is relative, false if it's absolute
|
||||||
///
|
///
|
||||||
/// \see setRelativeToListener
|
/// \see setRelativeToListener
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool isRelativeToListener() const;
|
bool isRelativeToListener() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the minimum distance of the sound
|
/// \brief Get the minimum distance of the sound
|
||||||
///
|
///
|
||||||
/// \return Minimum distance of the sound
|
/// \return Minimum distance of the sound
|
||||||
///
|
///
|
||||||
/// \see setMinDistance, getAttenuation
|
/// \see setMinDistance, getAttenuation
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getMinDistance() const;
|
float getMinDistance() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the attenuation factor of the sound
|
/// \brief Get the attenuation factor of the sound
|
||||||
///
|
///
|
||||||
/// \return Attenuation factor of the sound
|
/// \return Attenuation factor of the sound
|
||||||
///
|
///
|
||||||
/// \see setAttenuation, getMinDistance
|
/// \see setAttenuation, getMinDistance
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getAttenuation() const;
|
float getAttenuation() const;
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor is meant ot be called by derived classes only.
|
/// This constructor is meant ot be called by derived classes only.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundSource();
|
SoundSource();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current status of the sound (stopped, paused, playing)
|
/// \brief Get the current status of the sound (stopped, paused, playing)
|
||||||
///
|
///
|
||||||
/// \return Current status of the sound
|
/// \return Current status of the sound
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status getStatus() const;
|
Status getStatus() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int m_source; ///< OpenAL source identifier
|
unsigned int m_source; ///< OpenAL source identifier
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDSOURCE_HPP
|
#endif // SFML_SOUNDSOURCE_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::SoundSource
|
/// \class sf::SoundSource
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// sf::SoundSource is not meant to be used directly, it
|
/// sf::SoundSource is not meant to be used directly, it
|
||||||
/// only serves as a common base for all audio objects
|
/// only serves as a common base for all audio objects
|
||||||
/// that can live in the audio environment.
|
/// that can live in the audio environment.
|
||||||
///
|
///
|
||||||
/// It defines several properties for the sound: pitch,
|
/// It defines several properties for the sound: pitch,
|
||||||
/// volume, position, attenuation, etc. All of them can be
|
/// volume, position, attenuation, etc. All of them can be
|
||||||
/// changed at any time with no impact on performances.
|
/// changed at any time with no impact on performances.
|
||||||
///
|
///
|
||||||
/// \see sf::Sound, sf::SoundStream
|
/// \see sf::Sound, sf::SoundStream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,386 +1,386 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOUNDSTREAM_HPP
|
#ifndef SFML_SOUNDSTREAM_HPP
|
||||||
#define SFML_SOUNDSTREAM_HPP
|
#define SFML_SOUNDSTREAM_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Audio/Export.hpp>
|
#include <SFML/Audio/Export.hpp>
|
||||||
#include <SFML/Audio/SoundSource.hpp>
|
#include <SFML/Audio/SoundSource.hpp>
|
||||||
#include <SFML/System/Thread.hpp>
|
#include <SFML/System/Thread.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <SFML/System/Mutex.hpp>
|
#include <SFML/System/Mutex.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Abstract base class for streamed audio sources
|
/// \brief Abstract base class for streamed audio sources
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_AUDIO_API SoundStream : public SoundSource
|
class SFML_AUDIO_API SoundStream : public SoundSource
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Structure defining a chunk of audio data to stream
|
/// \brief Structure defining a chunk of audio data to stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct Chunk
|
struct Chunk
|
||||||
{
|
{
|
||||||
const Int16* samples; ///< Pointer to the audio samples
|
const Int16* samples; ///< Pointer to the audio samples
|
||||||
std::size_t sampleCount; ///< Number of samples pointed by Samples
|
std::size_t sampleCount; ///< Number of samples pointed by Samples
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~SoundStream();
|
virtual ~SoundStream();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Start or resume playing the audio stream
|
/// \brief Start or resume playing the audio stream
|
||||||
///
|
///
|
||||||
/// This function starts the stream if it was stopped, resumes
|
/// This function starts the stream if it was stopped, resumes
|
||||||
/// it if it was paused, and restarts it from the beginning if
|
/// it if it was paused, and restarts it from the beginning if
|
||||||
/// it was already playing.
|
/// it was already playing.
|
||||||
/// This function uses its own thread so that it doesn't block
|
/// This function uses its own thread so that it doesn't block
|
||||||
/// the rest of the program while the stream is played.
|
/// the rest of the program while the stream is played.
|
||||||
///
|
///
|
||||||
/// \see pause, stop
|
/// \see pause, stop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void play();
|
void play();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Pause the audio stream
|
/// \brief Pause the audio stream
|
||||||
///
|
///
|
||||||
/// This function pauses the stream if it was playing,
|
/// This function pauses the stream if it was playing,
|
||||||
/// otherwise (stream already paused or stopped) it has no effect.
|
/// otherwise (stream already paused or stopped) it has no effect.
|
||||||
///
|
///
|
||||||
/// \see play, stop
|
/// \see play, stop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void pause();
|
void pause();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Stop playing the audio stream
|
/// \brief Stop playing the audio stream
|
||||||
///
|
///
|
||||||
/// This function stops the stream if it was playing or paused,
|
/// This function stops the stream if it was playing or paused,
|
||||||
/// and does nothing if it was already stopped.
|
/// and does nothing if it was already stopped.
|
||||||
/// It also resets the playing position (unlike pause()).
|
/// It also resets the playing position (unlike pause()).
|
||||||
///
|
///
|
||||||
/// \see play, pause
|
/// \see play, pause
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Return the number of channels of the stream
|
/// \brief Return the number of channels of the stream
|
||||||
///
|
///
|
||||||
/// 1 channel means a mono sound, 2 means stereo, etc.
|
/// 1 channel means a mono sound, 2 means stereo, etc.
|
||||||
///
|
///
|
||||||
/// \return Number of channels
|
/// \return Number of channels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getChannelCount() const;
|
unsigned int getChannelCount() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the stream sample rate of the stream
|
/// \brief Get the stream sample rate of the stream
|
||||||
///
|
///
|
||||||
/// The sample rate is the number of audio samples played per
|
/// The sample rate is the number of audio samples played per
|
||||||
/// second. The higher, the better the quality.
|
/// second. The higher, the better the quality.
|
||||||
///
|
///
|
||||||
/// \return Sample rate, in number of samples per second
|
/// \return Sample rate, in number of samples per second
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getSampleRate() const;
|
unsigned int getSampleRate() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current status of the stream (stopped, paused, playing)
|
/// \brief Get the current status of the stream (stopped, paused, playing)
|
||||||
///
|
///
|
||||||
/// \return Current status
|
/// \return Current status
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status getStatus() const;
|
Status getStatus() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the current playing position of the stream
|
/// \brief Change the current playing position of the stream
|
||||||
///
|
///
|
||||||
/// The playing position can be changed when the stream is
|
/// The playing position can be changed when the stream is
|
||||||
/// either paused or playing. Changing the playing position
|
/// either paused or playing. Changing the playing position
|
||||||
/// when the stream is stopped has no effect, since playing
|
/// when the stream is stopped has no effect, since playing
|
||||||
/// the stream would reset its position.
|
/// the stream would reset its position.
|
||||||
///
|
///
|
||||||
/// \param timeOffset New playing position, from the beginning of the stream
|
/// \param timeOffset New playing position, from the beginning of the stream
|
||||||
///
|
///
|
||||||
/// \see getPlayingOffset
|
/// \see getPlayingOffset
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setPlayingOffset(Time timeOffset);
|
void setPlayingOffset(Time timeOffset);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current playing position of the stream
|
/// \brief Get the current playing position of the stream
|
||||||
///
|
///
|
||||||
/// \return Current playing position, from the beginning of the stream
|
/// \return Current playing position, from the beginning of the stream
|
||||||
///
|
///
|
||||||
/// \see setPlayingOffset
|
/// \see setPlayingOffset
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Time getPlayingOffset() const;
|
Time getPlayingOffset() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set whether or not the stream should loop after reaching the end
|
/// \brief Set whether or not the stream should loop after reaching the end
|
||||||
///
|
///
|
||||||
/// If set, the stream will restart from beginning after
|
/// If set, the stream will restart from beginning after
|
||||||
/// reaching the end and so on, until it is stopped or
|
/// reaching the end and so on, until it is stopped or
|
||||||
/// setLoop(false) is called.
|
/// setLoop(false) is called.
|
||||||
/// The default looping state for streams is false.
|
/// The default looping state for streams is false.
|
||||||
///
|
///
|
||||||
/// \param loop True to play in loop, false to play once
|
/// \param loop True to play in loop, false to play once
|
||||||
///
|
///
|
||||||
/// \see getLoop
|
/// \see getLoop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setLoop(bool loop);
|
void setLoop(bool loop);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether or not the stream is in loop mode
|
/// \brief Tell whether or not the stream is in loop mode
|
||||||
///
|
///
|
||||||
/// \return True if the stream is looping, false otherwise
|
/// \return True if the stream is looping, false otherwise
|
||||||
///
|
///
|
||||||
/// \see setLoop
|
/// \see setLoop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool getLoop() const;
|
bool getLoop() const;
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor is only meant to be called by derived classes.
|
/// This constructor is only meant to be called by derived classes.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundStream();
|
SoundStream();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Define the audio stream parameters
|
/// \brief Define the audio stream parameters
|
||||||
///
|
///
|
||||||
/// This function must be called by derived classes as soon
|
/// This function must be called by derived classes as soon
|
||||||
/// as they know the audio settings of the stream to play.
|
/// as they know the audio settings of the stream to play.
|
||||||
/// Any attempt to manipulate the stream (play(), ...) before
|
/// Any attempt to manipulate the stream (play(), ...) before
|
||||||
/// calling this function will fail.
|
/// calling this function will fail.
|
||||||
/// It can be called multiple times if the settings of the
|
/// It can be called multiple times if the settings of the
|
||||||
/// audio stream change, but only when the stream is stopped.
|
/// audio stream change, but only when the stream is stopped.
|
||||||
///
|
///
|
||||||
/// \param channelCount Number of channels of the stream
|
/// \param channelCount Number of channels of the stream
|
||||||
/// \param sampleRate Sample rate, in samples per second
|
/// \param sampleRate Sample rate, in samples per second
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void initialize(unsigned int channelCount, unsigned int sampleRate);
|
void initialize(unsigned int channelCount, unsigned int sampleRate);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Request a new chunk of audio samples from the stream source
|
/// \brief Request a new chunk of audio samples from the stream source
|
||||||
///
|
///
|
||||||
/// This function must be overriden by derived classes to provide
|
/// This function must be overriden by derived classes to provide
|
||||||
/// the audio samples to play. It is called continuously by the
|
/// the audio samples to play. It is called continuously by the
|
||||||
/// streaming loop, in a separate thread.
|
/// streaming loop, in a separate thread.
|
||||||
/// The source can choose to stop the streaming loop at any time, by
|
/// The source can choose to stop the streaming loop at any time, by
|
||||||
/// returning false to the caller.
|
/// returning false to the caller.
|
||||||
/// If you return true (i.e. continue streaming) it is important that
|
/// If you return true (i.e. continue streaming) it is important that
|
||||||
/// the returned array of samples is not empty; this would stop the stream
|
/// the returned array of samples is not empty; this would stop the stream
|
||||||
/// due to an internal limitation.
|
/// due to an internal limitation.
|
||||||
///
|
///
|
||||||
/// \param data Chunk of data to fill
|
/// \param data Chunk of data to fill
|
||||||
///
|
///
|
||||||
/// \return True to continue playback, false to stop
|
/// \return True to continue playback, false to stop
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool onGetData(Chunk& data) = 0;
|
virtual bool onGetData(Chunk& data) = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the current playing position in the stream source
|
/// \brief Change the current playing position in the stream source
|
||||||
///
|
///
|
||||||
/// This function must be overriden by derived classes to
|
/// This function must be overriden by derived classes to
|
||||||
/// allow random seeking into the stream source.
|
/// allow random seeking into the stream source.
|
||||||
///
|
///
|
||||||
/// \param timeOffset New playing position, relative to the beginning of the stream
|
/// \param timeOffset New playing position, relative to the beginning of the stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onSeek(Time timeOffset) = 0;
|
virtual void onSeek(Time timeOffset) = 0;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Function called as the entry point of the thread
|
/// \brief Function called as the entry point of the thread
|
||||||
///
|
///
|
||||||
/// This function starts the streaming loop, and returns
|
/// This function starts the streaming loop, and returns
|
||||||
/// only when the sound is stopped.
|
/// only when the sound is stopped.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void streamData();
|
void streamData();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Fill a new buffer with audio samples, and append
|
/// \brief Fill a new buffer with audio samples, and append
|
||||||
/// it to the playing queue
|
/// it to the playing queue
|
||||||
///
|
///
|
||||||
/// This function is called as soon as a buffer has been fully
|
/// This function is called as soon as a buffer has been fully
|
||||||
/// consumed; it fills it again and inserts it back into the
|
/// consumed; it fills it again and inserts it back into the
|
||||||
/// playing queue.
|
/// playing queue.
|
||||||
///
|
///
|
||||||
/// \param bufferNum Number of the buffer to fill (in [0, BufferCount])
|
/// \param bufferNum Number of the buffer to fill (in [0, BufferCount])
|
||||||
///
|
///
|
||||||
/// \return True if the stream source has requested to stop, false otherwise
|
/// \return True if the stream source has requested to stop, false otherwise
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool fillAndPushBuffer(unsigned int bufferNum);
|
bool fillAndPushBuffer(unsigned int bufferNum);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Fill the audio buffers and put them all into the playing queue
|
/// \brief Fill the audio buffers and put them all into the playing queue
|
||||||
///
|
///
|
||||||
/// This function is called when playing starts and the
|
/// This function is called when playing starts and the
|
||||||
/// playing queue is empty.
|
/// playing queue is empty.
|
||||||
///
|
///
|
||||||
/// \return True if the derived class has requested to stop, false otherwise
|
/// \return True if the derived class has requested to stop, false otherwise
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool fillQueue();
|
bool fillQueue();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Clear all the audio buffers and empty the playing queue
|
/// \brief Clear all the audio buffers and empty the playing queue
|
||||||
///
|
///
|
||||||
/// This function is called when the stream is stopped.
|
/// This function is called when the stream is stopped.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void clearQueue();
|
void clearQueue();
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
BufferCount = 3 ///< Number of audio buffers used by the streaming loop
|
BufferCount = 3 ///< Number of audio buffers used by the streaming loop
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Thread m_thread; ///< Thread running the background tasks
|
Thread m_thread; ///< Thread running the background tasks
|
||||||
mutable Mutex m_threadMutex; ///< Thread mutex
|
mutable Mutex m_threadMutex; ///< Thread mutex
|
||||||
Status m_threadStartState; ///< State the thread starts in (Playing, Paused, Stopped)
|
Status m_threadStartState; ///< State the thread starts in (Playing, Paused, Stopped)
|
||||||
bool m_isStreaming; ///< Streaming state (true = playing, false = stopped)
|
bool m_isStreaming; ///< Streaming state (true = playing, false = stopped)
|
||||||
unsigned int m_buffers[BufferCount]; ///< Sound buffers used to store temporary audio data
|
unsigned int m_buffers[BufferCount]; ///< Sound buffers used to store temporary audio data
|
||||||
unsigned int m_channelCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
|
unsigned int m_channelCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
|
||||||
unsigned int m_sampleRate; ///< Frequency (samples / second)
|
unsigned int m_sampleRate; ///< Frequency (samples / second)
|
||||||
Uint32 m_format; ///< Format of the internal sound buffers
|
Uint32 m_format; ///< Format of the internal sound buffers
|
||||||
bool m_loop; ///< Loop flag (true to loop, false to play once)
|
bool m_loop; ///< Loop flag (true to loop, false to play once)
|
||||||
Uint64 m_samplesProcessed; ///< Number of buffers processed since beginning of the stream
|
Uint64 m_samplesProcessed; ///< Number of buffers processed since beginning of the stream
|
||||||
bool m_endBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation
|
bool m_endBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOUNDSTREAM_HPP
|
#endif // SFML_SOUNDSTREAM_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::SoundStream
|
/// \class sf::SoundStream
|
||||||
/// \ingroup audio
|
/// \ingroup audio
|
||||||
///
|
///
|
||||||
/// Unlike audio buffers (see sf::SoundBuffer), audio streams
|
/// Unlike audio buffers (see sf::SoundBuffer), audio streams
|
||||||
/// are never completely loaded in memory. Instead, the audio
|
/// are never completely loaded in memory. Instead, the audio
|
||||||
/// data is acquired continuously while the stream is playing.
|
/// data is acquired continuously while the stream is playing.
|
||||||
/// This behaviour allows to play a sound with no loading delay,
|
/// This behaviour allows to play a sound with no loading delay,
|
||||||
/// and keeps the memory consumption very low.
|
/// and keeps the memory consumption very low.
|
||||||
///
|
///
|
||||||
/// Sound sources that need to be streamed are usually big files
|
/// Sound sources that need to be streamed are usually big files
|
||||||
/// (compressed audio musics that would eat hundreds of MB in memory)
|
/// (compressed audio musics that would eat hundreds of MB in memory)
|
||||||
/// or files that would take a lot of time to be received
|
/// or files that would take a lot of time to be received
|
||||||
/// (sounds played over the network).
|
/// (sounds played over the network).
|
||||||
///
|
///
|
||||||
/// sf::SoundStream is a base class that doesn't care about the
|
/// sf::SoundStream is a base class that doesn't care about the
|
||||||
/// stream source, which is left to the derived class. SFML provides
|
/// stream source, which is left to the derived class. SFML provides
|
||||||
/// a built-in specialization for big files (see sf::Music).
|
/// a built-in specialization for big files (see sf::Music).
|
||||||
/// No network stream source is provided, but you can write your own
|
/// No network stream source is provided, but you can write your own
|
||||||
/// by combining this class with the network module.
|
/// by combining this class with the network module.
|
||||||
///
|
///
|
||||||
/// A derived class has to override two virtual functions:
|
/// A derived class has to override two virtual functions:
|
||||||
/// \li onGetData fills a new chunk of audio data to be played
|
/// \li onGetData fills a new chunk of audio data to be played
|
||||||
/// \li onSeek changes the current playing position in the source
|
/// \li onSeek changes the current playing position in the source
|
||||||
///
|
///
|
||||||
/// It is important to note that each SoundStream is played in its
|
/// It is important to note that each SoundStream is played in its
|
||||||
/// own separate thread, so that the streaming loop doesn't block the
|
/// own separate thread, so that the streaming loop doesn't block the
|
||||||
/// rest of the program. In particular, the OnGetData and OnSeek
|
/// rest of the program. In particular, the OnGetData and OnSeek
|
||||||
/// virtual functions may sometimes be called from this separate thread.
|
/// virtual functions may sometimes be called from this separate thread.
|
||||||
/// It is important to keep this in mind, because you may have to take
|
/// It is important to keep this in mind, because you may have to take
|
||||||
/// care of synchronization issues if you share data between threads.
|
/// care of synchronization issues if you share data between threads.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// class CustomStream : public sf::SoundStream
|
/// class CustomStream : public sf::SoundStream
|
||||||
/// {
|
/// {
|
||||||
/// public :
|
/// public:
|
||||||
///
|
///
|
||||||
/// bool open(const std::string& location)
|
/// bool open(const std::string& location)
|
||||||
/// {
|
/// {
|
||||||
/// // Open the source and get audio settings
|
/// // Open the source and get audio settings
|
||||||
/// ...
|
/// ...
|
||||||
/// unsigned int channelCount = ...;
|
/// unsigned int channelCount = ...;
|
||||||
/// unsigned int sampleRate = ...;
|
/// unsigned int sampleRate = ...;
|
||||||
///
|
///
|
||||||
/// // Initialize the stream -- important!
|
/// // Initialize the stream -- important!
|
||||||
/// initialize(channelCount, sampleRate);
|
/// initialize(channelCount, sampleRate);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// private :
|
/// private:
|
||||||
///
|
///
|
||||||
/// virtual bool onGetData(Chunk& data)
|
/// virtual bool onGetData(Chunk& data)
|
||||||
/// {
|
/// {
|
||||||
/// // Fill the chunk with audio data from the stream source
|
/// // Fill the chunk with audio data from the stream source
|
||||||
/// // (note: must not be empty if you want to continue playing)
|
/// // (note: must not be empty if you want to continue playing)
|
||||||
/// data.samples = ...;
|
/// data.samples = ...;
|
||||||
/// data.sampleCount = ...;
|
/// data.sampleCount = ...;
|
||||||
///
|
///
|
||||||
/// // Return true to continue playing
|
/// // Return true to continue playing
|
||||||
/// return true;
|
/// return true;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// virtual void onSeek(Uint32 timeOffset)
|
/// virtual void onSeek(Uint32 timeOffset)
|
||||||
/// {
|
/// {
|
||||||
/// // Change the current position in the stream source
|
/// // Change the current position in the stream source
|
||||||
/// ...
|
/// ...
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Usage
|
/// // Usage
|
||||||
/// CustomStream stream;
|
/// CustomStream stream;
|
||||||
/// stream.open("path/to/stream");
|
/// stream.open("path/to/stream");
|
||||||
/// stream.play();
|
/// stream.play();
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Music
|
/// \see sf::Music
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,192 +1,192 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_CONFIG_HPP
|
#ifndef SFML_CONFIG_HPP
|
||||||
#define SFML_CONFIG_HPP
|
#define SFML_CONFIG_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Define the SFML version
|
// Define the SFML version
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#define SFML_VERSION_MAJOR 2
|
#define SFML_VERSION_MAJOR 2
|
||||||
#define SFML_VERSION_MINOR 1
|
#define SFML_VERSION_MINOR 1
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Identify the operating system
|
// Identify the operating system
|
||||||
// see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
|
// see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
// Windows
|
// Windows
|
||||||
#define SFML_SYSTEM_WINDOWS
|
#define SFML_SYSTEM_WINDOWS
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__APPLE__) && defined(__MACH__)
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
|
|
||||||
// Apple platform, see which one it is
|
// Apple platform, see which one it is
|
||||||
#include "TargetConditionals.h"
|
#include "TargetConditionals.h"
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
|
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
|
||||||
|
|
||||||
// iOS
|
// iOS
|
||||||
#define SFML_SYSTEM_IOS
|
#define SFML_SYSTEM_IOS
|
||||||
|
|
||||||
#elif TARGET_OS_MAC
|
#elif TARGET_OS_MAC
|
||||||
|
|
||||||
// MacOS
|
// MacOS
|
||||||
#define SFML_SYSTEM_MACOS
|
#define SFML_SYSTEM_MACOS
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Unsupported Apple system
|
// Unsupported Apple system
|
||||||
#error This Apple operating system is not supported by SFML library
|
#error This Apple operating system is not supported by SFML library
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__unix__)
|
#elif defined(__unix__)
|
||||||
|
|
||||||
// UNIX system, see which one it is
|
// UNIX system, see which one it is
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
|
|
||||||
// Android
|
// Android
|
||||||
#define SFML_SYSTEM_ANDROID
|
#define SFML_SYSTEM_ANDROID
|
||||||
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
|
||||||
// Linux
|
// Linux
|
||||||
#define SFML_SYSTEM_LINUX
|
#define SFML_SYSTEM_LINUX
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
|
|
||||||
// FreeBSD
|
// FreeBSD
|
||||||
#define SFML_SYSTEM_FREEBSD
|
#define SFML_SYSTEM_FREEBSD
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Unsupported UNIX system
|
// Unsupported UNIX system
|
||||||
#error This UNIX operating system is not supported by SFML library
|
#error This UNIX operating system is not supported by SFML library
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Unsupported system
|
// Unsupported system
|
||||||
#error This operating system is not supported by SFML library
|
#error This operating system is not supported by SFML library
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Define a portable debug macro
|
// Define a portable debug macro
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
|
|
||||||
#define SFML_DEBUG
|
#define SFML_DEBUG
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Define helpers to create portable import / export macros for each module
|
// Define helpers to create portable import / export macros for each module
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#if !defined(SFML_STATIC)
|
#if !defined(SFML_STATIC)
|
||||||
|
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
#if defined(SFML_SYSTEM_WINDOWS)
|
||||||
|
|
||||||
// Windows compilers need specific (and different) keywords for export and import
|
// Windows compilers need specific (and different) keywords for export and import
|
||||||
#define SFML_API_EXPORT __declspec(dllexport)
|
#define SFML_API_EXPORT __declspec(dllexport)
|
||||||
#define SFML_API_IMPORT __declspec(dllimport)
|
#define SFML_API_IMPORT __declspec(dllimport)
|
||||||
|
|
||||||
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning
|
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
#pragma warning(disable : 4251)
|
#pragma warning(disable: 4251)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else // Linux, FreeBSD, Mac OS X
|
#else // Linux, FreeBSD, Mac OS X
|
||||||
|
|
||||||
#if __GNUC__ >= 4
|
#if __GNUC__ >= 4
|
||||||
|
|
||||||
// GCC 4 has special keywords for showing/hidding symbols,
|
// GCC 4 has special keywords for showing/hidding symbols,
|
||||||
// the same keyword is used for both importing and exporting
|
// the same keyword is used for both importing and exporting
|
||||||
#define SFML_API_EXPORT __attribute__ ((__visibility__ ("default")))
|
#define SFML_API_EXPORT __attribute__ ((__visibility__ ("default")))
|
||||||
#define SFML_API_IMPORT __attribute__ ((__visibility__ ("default")))
|
#define SFML_API_IMPORT __attribute__ ((__visibility__ ("default")))
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// GCC < 4 has no mechanism to explicitely hide symbols, everything's exported
|
// GCC < 4 has no mechanism to explicitely hide symbols, everything's exported
|
||||||
#define SFML_API_EXPORT
|
#define SFML_API_EXPORT
|
||||||
#define SFML_API_IMPORT
|
#define SFML_API_IMPORT
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Static build doesn't need import/export macros
|
// Static build doesn't need import/export macros
|
||||||
#define SFML_API_EXPORT
|
#define SFML_API_EXPORT
|
||||||
#define SFML_API_IMPORT
|
#define SFML_API_IMPORT
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Define portable fixed-size types
|
// Define portable fixed-size types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
// All "common" platforms use the same size for char, short and int
|
// All "common" platforms use the same size for char, short and int
|
||||||
// (basically there are 3 types for 3 sizes, so no other match is possible),
|
// (basically there are 3 types for 3 sizes, so no other match is possible),
|
||||||
// we can use them without doing any kind of check
|
// we can use them without doing any kind of check
|
||||||
|
|
||||||
// 8 bits integer types
|
// 8 bits integer types
|
||||||
typedef signed char Int8;
|
typedef signed char Int8;
|
||||||
typedef unsigned char Uint8;
|
typedef unsigned char Uint8;
|
||||||
|
|
||||||
// 16 bits integer types
|
// 16 bits integer types
|
||||||
typedef signed short Int16;
|
typedef signed short Int16;
|
||||||
typedef unsigned short Uint16;
|
typedef unsigned short Uint16;
|
||||||
|
|
||||||
// 32 bits integer types
|
// 32 bits integer types
|
||||||
typedef signed int Int32;
|
typedef signed int Int32;
|
||||||
typedef unsigned int Uint32;
|
typedef unsigned int Uint32;
|
||||||
|
|
||||||
// 64 bits integer types
|
// 64 bits integer types
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
typedef signed __int64 Int64;
|
typedef signed __int64 Int64;
|
||||||
typedef unsigned __int64 Uint64;
|
typedef unsigned __int64 Uint64;
|
||||||
#else
|
#else
|
||||||
typedef signed long long Int64;
|
typedef signed long long Int64;
|
||||||
typedef unsigned long long Uint64;
|
typedef unsigned long long Uint64;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_CONFIG_HPP
|
#endif // SFML_CONFIG_HPP
|
||||||
|
|
|
@ -1,62 +1,62 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_GRAPHICS_HPP
|
#ifndef SFML_GRAPHICS_HPP
|
||||||
#define SFML_GRAPHICS_HPP
|
#define SFML_GRAPHICS_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/Window.hpp>
|
#include <SFML/Window.hpp>
|
||||||
#include <SFML/Graphics/BlendMode.hpp>
|
#include <SFML/Graphics/BlendMode.hpp>
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
#include <SFML/Graphics/Font.hpp>
|
#include <SFML/Graphics/Font.hpp>
|
||||||
#include <SFML/Graphics/Glyph.hpp>
|
#include <SFML/Graphics/Glyph.hpp>
|
||||||
#include <SFML/Graphics/Image.hpp>
|
#include <SFML/Graphics/Image.hpp>
|
||||||
#include <SFML/Graphics/RenderStates.hpp>
|
#include <SFML/Graphics/RenderStates.hpp>
|
||||||
#include <SFML/Graphics/RenderTexture.hpp>
|
#include <SFML/Graphics/RenderTexture.hpp>
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
#include <SFML/Graphics/Shader.hpp>
|
#include <SFML/Graphics/Shader.hpp>
|
||||||
#include <SFML/Graphics/Shape.hpp>
|
#include <SFML/Graphics/Shape.hpp>
|
||||||
#include <SFML/Graphics/CircleShape.hpp>
|
#include <SFML/Graphics/CircleShape.hpp>
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
#include <SFML/Graphics/ConvexShape.hpp>
|
#include <SFML/Graphics/ConvexShape.hpp>
|
||||||
#include <SFML/Graphics/Sprite.hpp>
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
#include <SFML/Graphics/Text.hpp>
|
#include <SFML/Graphics/Text.hpp>
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
#include <SFML/Graphics/Transform.hpp>
|
||||||
#include <SFML/Graphics/Vertex.hpp>
|
#include <SFML/Graphics/Vertex.hpp>
|
||||||
#include <SFML/Graphics/VertexArray.hpp>
|
#include <SFML/Graphics/VertexArray.hpp>
|
||||||
#include <SFML/Graphics/View.hpp>
|
#include <SFML/Graphics/View.hpp>
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_GRAPHICS_HPP
|
#endif // SFML_GRAPHICS_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \defgroup graphics Graphics module
|
/// \defgroup graphics Graphics module
|
||||||
///
|
///
|
||||||
/// 2D graphics module: sprites, text, shapes, ...
|
/// 2D graphics module: sprites, text, shapes, ...
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API CircleShape : public Shape
|
class SFML_GRAPHICS_API CircleShape : public Shape
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
@ -106,7 +106,7 @@ public :
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual Vector2f getPoint(unsigned int index) const;
|
virtual Vector2f getPoint(unsigned int index) const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
|
|
|
@ -1,259 +1,259 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_COLOR_HPP
|
#ifndef SFML_COLOR_HPP
|
||||||
#define SFML_COLOR_HPP
|
#define SFML_COLOR_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Utility class for manpulating RGBA colors
|
/// \brief Utility class for manpulating RGBA colors
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Color
|
class SFML_GRAPHICS_API Color
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Constructs an opaque black color. It is equivalent to
|
/// Constructs an opaque black color. It is equivalent to
|
||||||
/// sf::Color(0, 0, 0, 255).
|
/// sf::Color(0, 0, 0, 255).
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Color();
|
Color();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the color from its 4 RGBA components
|
/// \brief Construct the color from its 4 RGBA components
|
||||||
///
|
///
|
||||||
/// \param red Red component (in the range [0, 255])
|
/// \param red Red component (in the range [0, 255])
|
||||||
/// \param green Green component (in the range [0, 255])
|
/// \param green Green component (in the range [0, 255])
|
||||||
/// \param blue Blue component (in the range [0, 255])
|
/// \param blue Blue component (in the range [0, 255])
|
||||||
/// \param alpha Alpha (opacity) component (in the range [0, 255])
|
/// \param alpha Alpha (opacity) component (in the range [0, 255])
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
|
Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Static member data
|
// Static member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static const Color Black; ///< Black predefined color
|
static const Color Black; ///< Black predefined color
|
||||||
static const Color White; ///< White predefined color
|
static const Color White; ///< White predefined color
|
||||||
static const Color Red; ///< Red predefined color
|
static const Color Red; ///< Red predefined color
|
||||||
static const Color Green; ///< Green predefined color
|
static const Color Green; ///< Green predefined color
|
||||||
static const Color Blue; ///< Blue predefined color
|
static const Color Blue; ///< Blue predefined color
|
||||||
static const Color Yellow; ///< Yellow predefined color
|
static const Color Yellow; ///< Yellow predefined color
|
||||||
static const Color Magenta; ///< Magenta predefined color
|
static const Color Magenta; ///< Magenta predefined color
|
||||||
static const Color Cyan; ///< Cyan predefined color
|
static const Color Cyan; ///< Cyan predefined color
|
||||||
static const Color Transparent; ///< Transparent (black) predefined color
|
static const Color Transparent; ///< Transparent (black) predefined color
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Uint8 r; ///< Red component
|
Uint8 r; ///< Red component
|
||||||
Uint8 g; ///< Green component
|
Uint8 g; ///< Green component
|
||||||
Uint8 b; ///< Blue component
|
Uint8 b; ///< Blue component
|
||||||
Uint8 a; ///< Alpha (opacity) component
|
Uint8 a; ///< Alpha (opacity) component
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the == operator
|
/// \brief Overload of the == operator
|
||||||
///
|
///
|
||||||
/// This operator compares two colors and check if they are equal.
|
/// This operator compares two colors and check if they are equal.
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return True if colors are equal, false if they are different
|
/// \return True if colors are equal, false if they are different
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right);
|
SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the != operator
|
/// \brief Overload of the != operator
|
||||||
///
|
///
|
||||||
/// This operator compares two colors and check if they are different.
|
/// This operator compares two colors and check if they are different.
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return True if colors are different, false if they are equal
|
/// \return True if colors are different, false if they are equal
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right);
|
SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the binary + operator
|
/// \brief Overload of the binary + operator
|
||||||
///
|
///
|
||||||
/// This operator returns the component-wise sum of two colors.
|
/// This operator returns the component-wise sum of two colors.
|
||||||
/// Components that exceed 255 are clamped to 255.
|
/// Components that exceed 255 are clamped to 255.
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return Result of \a left + \a right
|
/// \return Result of \a left + \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right);
|
SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the binary - operator
|
/// \brief Overload of the binary - operator
|
||||||
///
|
///
|
||||||
/// This operator returns the component-wise subtraction of two colors.
|
/// This operator returns the component-wise subtraction of two colors.
|
||||||
/// Components below 0 are clamped to 0.
|
/// Components below 0 are clamped to 0.
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return Result of \a left - \a right
|
/// \return Result of \a left - \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API Color operator -(const Color& left, const Color& right);
|
SFML_GRAPHICS_API Color operator -(const Color& left, const Color& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the binary * operator
|
/// \brief Overload of the binary * operator
|
||||||
///
|
///
|
||||||
/// This operator returns the component-wise multiplication
|
/// This operator returns the component-wise multiplication
|
||||||
/// (also called "modulation") of two colors.
|
/// (also called "modulation") of two colors.
|
||||||
/// Components are then divided by 255 so that the result is
|
/// Components are then divided by 255 so that the result is
|
||||||
/// still in the range [0, 255].
|
/// still in the range [0, 255].
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return Result of \a left * \a right
|
/// \return Result of \a left * \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right);
|
SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the binary += operator
|
/// \brief Overload of the binary += operator
|
||||||
///
|
///
|
||||||
/// This operator computes the component-wise sum of two colors,
|
/// This operator computes the component-wise sum of two colors,
|
||||||
/// and assigns the result to the left operand.
|
/// and assigns the result to the left operand.
|
||||||
/// Components that exceed 255 are clamped to 255.
|
/// Components that exceed 255 are clamped to 255.
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return Reference to \a left
|
/// \return Reference to \a left
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right);
|
SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the binary -= operator
|
/// \brief Overload of the binary -= operator
|
||||||
///
|
///
|
||||||
/// This operator computes the component-wise subtraction of two colors,
|
/// This operator computes the component-wise subtraction of two colors,
|
||||||
/// and assigns the result to the left operand.
|
/// and assigns the result to the left operand.
|
||||||
/// Components below 0 are clamped to 0.
|
/// Components below 0 are clamped to 0.
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return Reference to \a left
|
/// \return Reference to \a left
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API Color& operator -=(Color& left, const Color& right);
|
SFML_GRAPHICS_API Color& operator -=(Color& left, const Color& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Color
|
/// \relates Color
|
||||||
/// \brief Overload of the binary *= operator
|
/// \brief Overload of the binary *= operator
|
||||||
///
|
///
|
||||||
/// This operator returns the component-wise multiplication
|
/// This operator returns the component-wise multiplication
|
||||||
/// (also called "modulation") of two colors, and assigns
|
/// (also called "modulation") of two colors, and assigns
|
||||||
/// the result to the left operand.
|
/// the result to the left operand.
|
||||||
/// Components are then divided by 255 so that the result is
|
/// Components are then divided by 255 so that the result is
|
||||||
/// still in the range [0, 255].
|
/// still in the range [0, 255].
|
||||||
///
|
///
|
||||||
/// \param left Left operand
|
/// \param left Left operand
|
||||||
/// \param right Right operand
|
/// \param right Right operand
|
||||||
///
|
///
|
||||||
/// \return Reference to \a left
|
/// \return Reference to \a left
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right);
|
SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right);
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_COLOR_HPP
|
#endif // SFML_COLOR_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Color
|
/// \class sf::Color
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::Color is a simple color class composed of 4 components:
|
/// sf::Color is a simple color class composed of 4 components:
|
||||||
/// \li Red
|
/// \li Red
|
||||||
/// \li Green
|
/// \li Green
|
||||||
/// \li Blue
|
/// \li Blue
|
||||||
/// \li Alpha (opacity)
|
/// \li Alpha (opacity)
|
||||||
///
|
///
|
||||||
/// Each component is a public member, an unsigned integer in
|
/// Each component is a public member, an unsigned integer in
|
||||||
/// the range [0, 255]. Thus, colors can be constructed and
|
/// the range [0, 255]. Thus, colors can be constructed and
|
||||||
/// manipulated very easily:
|
/// manipulated very easily:
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::Color color(255, 0, 0); // red
|
/// sf::Color color(255, 0, 0); // red
|
||||||
/// color.r = 0; // make it black
|
/// color.r = 0; // make it black
|
||||||
/// color.b = 128; // make it dark blue
|
/// color.b = 128; // make it dark blue
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// The fourth component of colors, named "alpha", represents
|
/// The fourth component of colors, named "alpha", represents
|
||||||
/// the opacity of the color. A color with an alpha value of
|
/// the opacity of the color. A color with an alpha value of
|
||||||
/// 255 will be fully opaque, while an alpha value of 0 will
|
/// 255 will be fully opaque, while an alpha value of 0 will
|
||||||
/// make a color fully transparent, whatever the value of the
|
/// make a color fully transparent, whatever the value of the
|
||||||
/// other components is.
|
/// other components is.
|
||||||
///
|
///
|
||||||
/// The most common colors are already defined as static variables:
|
/// The most common colors are already defined as static variables:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::Color black = sf::Color::Black;
|
/// sf::Color black = sf::Color::Black;
|
||||||
/// sf::Color white = sf::Color::White;
|
/// sf::Color white = sf::Color::White;
|
||||||
/// sf::Color red = sf::Color::Red;
|
/// sf::Color red = sf::Color::Red;
|
||||||
/// sf::Color green = sf::Color::Green;
|
/// sf::Color green = sf::Color::Green;
|
||||||
/// sf::Color blue = sf::Color::Blue;
|
/// sf::Color blue = sf::Color::Blue;
|
||||||
/// sf::Color yellow = sf::Color::Yellow;
|
/// sf::Color yellow = sf::Color::Yellow;
|
||||||
/// sf::Color magenta = sf::Color::Magenta;
|
/// sf::Color magenta = sf::Color::Magenta;
|
||||||
/// sf::Color cyan = sf::Color::Cyan;
|
/// sf::Color cyan = sf::Color::Cyan;
|
||||||
/// sf::Color transparent = sf::Color::Transparent;
|
/// sf::Color transparent = sf::Color::Transparent;
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Colors can also be added and modulated (multiplied) using the
|
/// Colors can also be added and modulated (multiplied) using the
|
||||||
/// overloaded operators + and *.
|
/// overloaded operators + and *.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API ConvexShape : public Shape
|
class SFML_GRAPHICS_API ConvexShape : public Shape
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
@ -107,7 +107,7 @@ public :
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual Vector2f getPoint(unsigned int index) const;
|
virtual Vector2f getPoint(unsigned int index) const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
|
|
|
@ -1,126 +1,126 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_DRAWABLE_HPP
|
#ifndef SFML_DRAWABLE_HPP
|
||||||
#define SFML_DRAWABLE_HPP
|
#define SFML_DRAWABLE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/RenderStates.hpp>
|
#include <SFML/Graphics/RenderStates.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class RenderTarget;
|
class RenderTarget;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Abstract base class for objects that can be drawn
|
/// \brief Abstract base class for objects that can be drawn
|
||||||
/// to a render target
|
/// to a render target
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Drawable
|
class SFML_GRAPHICS_API Drawable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Virtual destructor
|
/// \brief Virtual destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~Drawable() {}
|
virtual ~Drawable() {}
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
friend class RenderTarget;
|
friend class RenderTarget;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Draw the object to a render target
|
/// \brief Draw the object to a render target
|
||||||
///
|
///
|
||||||
/// This is a pure virtual function that has to be implemented
|
/// This is a pure virtual function that has to be implemented
|
||||||
/// by the derived class to define how the drawable should be
|
/// by the derived class to define how the drawable should be
|
||||||
/// drawn.
|
/// drawn.
|
||||||
///
|
///
|
||||||
/// \param target Render target to draw to
|
/// \param target Render target to draw to
|
||||||
/// \param states Current render states
|
/// \param states Current render states
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const = 0;
|
virtual void draw(RenderTarget& target, RenderStates states) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_DRAWABLE_HPP
|
#endif // SFML_DRAWABLE_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Drawable
|
/// \class sf::Drawable
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::Drawable is a very simple base class that allows objects
|
/// sf::Drawable is a very simple base class that allows objects
|
||||||
/// of derived classes to be drawn to a sf::RenderTarget.
|
/// of derived classes to be drawn to a sf::RenderTarget.
|
||||||
///
|
///
|
||||||
/// All you have to do in your derived class is to override the
|
/// All you have to do in your derived class is to override the
|
||||||
/// draw virtual function.
|
/// draw virtual function.
|
||||||
///
|
///
|
||||||
/// Note that inheriting from sf::Drawable is not mandatory,
|
/// Note that inheriting from sf::Drawable is not mandatory,
|
||||||
/// but it allows this nice syntax "window.draw(object)" rather
|
/// but it allows this nice syntax "window.draw(object)" rather
|
||||||
/// than "object.draw(window)", which is more consistent with other
|
/// than "object.draw(window)", which is more consistent with other
|
||||||
/// SFML classes.
|
/// SFML classes.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// \code
|
/// \code
|
||||||
/// class MyDrawable : public sf::Drawable
|
/// class MyDrawable : public sf::Drawable
|
||||||
/// {
|
/// {
|
||||||
/// public :
|
/// public:
|
||||||
///
|
///
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
/// private :
|
/// private:
|
||||||
///
|
///
|
||||||
/// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
|
/// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||||
/// {
|
/// {
|
||||||
/// // You can draw other high-level objects
|
/// // You can draw other high-level objects
|
||||||
/// target.draw(m_sprite, states);
|
/// target.draw(m_sprite, states);
|
||||||
///
|
///
|
||||||
/// // ... or use the low-level API
|
/// // ... or use the low-level API
|
||||||
/// states.texture = &m_texture;
|
/// states.texture = &m_texture;
|
||||||
/// target.draw(m_vertices, states);
|
/// target.draw(m_vertices, states);
|
||||||
///
|
///
|
||||||
/// // ... or draw with OpenGL directly
|
/// // ... or draw with OpenGL directly
|
||||||
/// glBegin(GL_QUADS);
|
/// glBegin(GL_QUADS);
|
||||||
/// ...
|
/// ...
|
||||||
/// glEnd();
|
/// glEnd();
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// sf::Sprite m_sprite;
|
/// sf::Sprite m_sprite;
|
||||||
/// sf::Texture m_texture;
|
/// sf::Texture m_texture;
|
||||||
/// sf::VertexArray m_vertices;
|
/// sf::VertexArray m_vertices;
|
||||||
/// };
|
/// };
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::RenderTarget
|
/// \see sf::RenderTarget
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,423 +1,423 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_FONT_HPP
|
#ifndef SFML_FONT_HPP
|
||||||
#define SFML_FONT_HPP
|
#define SFML_FONT_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Glyph.hpp>
|
#include <SFML/Graphics/Glyph.hpp>
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <SFML/System/String.hpp>
|
#include <SFML/System/String.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class InputStream;
|
class InputStream;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Class for loading and manipulating character fonts
|
/// \brief Class for loading and manipulating character fonts
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Font
|
class SFML_GRAPHICS_API Font
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Holds various information about a font
|
/// \brief Holds various information about a font
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct Info
|
struct Info
|
||||||
{
|
{
|
||||||
std::string family; ///< The font family
|
std::string family; ///< The font family
|
||||||
};
|
};
|
||||||
|
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor defines an empty font
|
/// This constructor defines an empty font
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Font();
|
Font();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy constructor
|
/// \brief Copy constructor
|
||||||
///
|
///
|
||||||
/// \param copy Instance to copy
|
/// \param copy Instance to copy
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Font(const Font& copy);
|
Font(const Font& copy);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
/// Cleans up all the internal resources used by the font
|
/// Cleans up all the internal resources used by the font
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the font from a file
|
/// \brief Load the font from a file
|
||||||
///
|
///
|
||||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
/// The supported font formats are: TrueType, Type 1, CFF,
|
||||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
||||||
/// Note that this function know nothing about the standard
|
/// Note that this function know nothing about the standard
|
||||||
/// fonts installed on the user's system, thus you can't
|
/// fonts installed on the user's system, thus you can't
|
||||||
/// load them directly.
|
/// load them directly.
|
||||||
///
|
///
|
||||||
/// \param filename Path of the font file to load
|
/// \param filename Path of the font file to load
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromMemory, loadFromStream
|
/// \see loadFromMemory, loadFromStream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromFile(const std::string& filename);
|
bool loadFromFile(const std::string& filename);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the font from a file in memory
|
/// \brief Load the font from a file in memory
|
||||||
///
|
///
|
||||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
/// The supported font formats are: TrueType, Type 1, CFF,
|
||||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
||||||
/// Warning: SFML cannot preload all the font data in this
|
/// Warning: SFML cannot preload all the font data in this
|
||||||
/// function, so the buffer pointed by \a data has to remain
|
/// function, so the buffer pointed by \a data has to remain
|
||||||
/// valid as long as the font is used.
|
/// valid as long as the font is used.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the file data in memory
|
/// \param data Pointer to the file data in memory
|
||||||
/// \param sizeInBytes Size of the data to load, in bytes
|
/// \param sizeInBytes Size of the data to load, in bytes
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromStream
|
/// \see loadFromFile, loadFromStream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the font from a custom stream
|
/// \brief Load the font from a custom stream
|
||||||
///
|
///
|
||||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
/// The supported font formats are: TrueType, Type 1, CFF,
|
||||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
||||||
/// Warning: SFML cannot preload all the font data in this
|
/// Warning: SFML cannot preload all the font data in this
|
||||||
/// function, so the contents of \a stream have to remain
|
/// function, so the contents of \a stream have to remain
|
||||||
/// valid as long as the font is used.
|
/// valid as long as the font is used.
|
||||||
///
|
///
|
||||||
/// \param stream Source stream to read from
|
/// \param stream Source stream to read from
|
||||||
///
|
///
|
||||||
/// \return True if loading succeeded, false if it failed
|
/// \return True if loading succeeded, false if it failed
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromMemory
|
/// \see loadFromFile, loadFromMemory
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromStream(InputStream& stream);
|
bool loadFromStream(InputStream& stream);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the font information
|
/// \brief Get the font information
|
||||||
///
|
///
|
||||||
/// \return A structure that holds the font information
|
/// \return A structure that holds the font information
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Info& getInfo() const;
|
const Info& getInfo() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Retrieve a glyph of the font
|
/// \brief Retrieve a glyph of the font
|
||||||
///
|
///
|
||||||
/// If the font is a bitmap font, not all character sizes
|
/// If the font is a bitmap font, not all character sizes
|
||||||
/// might be available. If the glyph is not available at the
|
/// might be available. If the glyph is not available at the
|
||||||
/// requested size, an empty glyph is returned.
|
/// requested size, an empty glyph is returned.
|
||||||
///
|
///
|
||||||
/// \param codePoint Unicode code point of the character to get
|
/// \param codePoint Unicode code point of the character to get
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
/// \param bold Retrieve the bold version or the regular one?
|
/// \param bold Retrieve the bold version or the regular one?
|
||||||
///
|
///
|
||||||
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
|
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the kerning offset of two glyphs
|
/// \brief Get the kerning offset of two glyphs
|
||||||
///
|
///
|
||||||
/// The kerning is an extra offset (negative) to apply between two
|
/// The kerning is an extra offset (negative) to apply between two
|
||||||
/// glyphs when rendering them, to make the pair look more "natural".
|
/// glyphs when rendering them, to make the pair look more "natural".
|
||||||
/// For example, the pair "AV" have a special kerning to make them
|
/// For example, the pair "AV" have a special kerning to make them
|
||||||
/// closer than other characters. Most of the glyphs pairs have a
|
/// closer than other characters. Most of the glyphs pairs have a
|
||||||
/// kerning offset of zero, though.
|
/// kerning offset of zero, though.
|
||||||
///
|
///
|
||||||
/// \param first Unicode code point of the first character
|
/// \param first Unicode code point of the first character
|
||||||
/// \param second Unicode code point of the second character
|
/// \param second Unicode code point of the second character
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
///
|
///
|
||||||
/// \return Kerning value for \a first and \a second, in pixels
|
/// \return Kerning value for \a first and \a second, in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
|
float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the line spacing
|
/// \brief Get the line spacing
|
||||||
///
|
///
|
||||||
/// Line spacing is the vertical offset to apply between two
|
/// Line spacing is the vertical offset to apply between two
|
||||||
/// consecutive lines of text.
|
/// consecutive lines of text.
|
||||||
///
|
///
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
///
|
///
|
||||||
/// \return Line spacing, in pixels
|
/// \return Line spacing, in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getLineSpacing(unsigned int characterSize) const;
|
float getLineSpacing(unsigned int characterSize) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the position of the underline
|
/// \brief Get the position of the underline
|
||||||
///
|
///
|
||||||
/// Underline position is the vertical offset to apply between the
|
/// Underline position is the vertical offset to apply between the
|
||||||
/// baseline and the underline.
|
/// baseline and the underline.
|
||||||
///
|
///
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
///
|
///
|
||||||
/// \return Underline position, in pixels
|
/// \return Underline position, in pixels
|
||||||
///
|
///
|
||||||
/// \see getUnderlineThickness
|
/// \see getUnderlineThickness
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getUnderlinePosition(unsigned int characterSize) const;
|
float getUnderlinePosition(unsigned int characterSize) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the thickness of the underline
|
/// \brief Get the thickness of the underline
|
||||||
///
|
///
|
||||||
/// Underline thickness is the vertical size of the underline.
|
/// Underline thickness is the vertical size of the underline.
|
||||||
///
|
///
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
///
|
///
|
||||||
/// \return Underline thickness, in pixels
|
/// \return Underline thickness, in pixels
|
||||||
///
|
///
|
||||||
/// \see getUnderlinePosition
|
/// \see getUnderlinePosition
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getUnderlineThickness(unsigned int characterSize) const;
|
float getUnderlineThickness(unsigned int characterSize) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Retrieve the texture containing the loaded glyphs of a certain size
|
/// \brief Retrieve the texture containing the loaded glyphs of a certain size
|
||||||
///
|
///
|
||||||
/// The contents of the returned texture changes as more glyphs
|
/// The contents of the returned texture changes as more glyphs
|
||||||
/// are requested, thus it is not very relevant. It is mainly
|
/// are requested, thus it is not very relevant. It is mainly
|
||||||
/// used internally by sf::Text.
|
/// used internally by sf::Text.
|
||||||
///
|
///
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
///
|
///
|
||||||
/// \return Texture containing the glyphs of the requested size
|
/// \return Texture containing the glyphs of the requested size
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Texture& getTexture(unsigned int characterSize) const;
|
const Texture& getTexture(unsigned int characterSize) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of assignment operator
|
/// \brief Overload of assignment operator
|
||||||
///
|
///
|
||||||
/// \param right Instance to assign
|
/// \param right Instance to assign
|
||||||
///
|
///
|
||||||
/// \return Reference to self
|
/// \return Reference to self
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Font& operator =(const Font& right);
|
Font& operator =(const Font& right);
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Structure defining a row of glyphs
|
/// \brief Structure defining a row of glyphs
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct Row
|
struct Row
|
||||||
{
|
{
|
||||||
Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
|
Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
|
||||||
|
|
||||||
unsigned int width; ///< Current width of the row
|
unsigned int width; ///< Current width of the row
|
||||||
unsigned int top; ///< Y position of the row into the texture
|
unsigned int top; ///< Y position of the row into the texture
|
||||||
unsigned int height; ///< Height of the row
|
unsigned int height; ///< Height of the row
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Types
|
// Types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef std::map<Uint32, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
|
typedef std::map<Uint32, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Structure defining a page of glyphs
|
/// \brief Structure defining a page of glyphs
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct Page
|
struct Page
|
||||||
{
|
{
|
||||||
Page();
|
Page();
|
||||||
|
|
||||||
GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph
|
GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph
|
||||||
sf::Texture texture; ///< Texture containing the pixels of the glyphs
|
sf::Texture texture; ///< Texture containing the pixels of the glyphs
|
||||||
unsigned int nextRow; ///< Y position of the next new row in the texture
|
unsigned int nextRow; ///< Y position of the next new row in the texture
|
||||||
std::vector<Row> rows; ///< List containing the position of all the existing rows
|
std::vector<Row> rows; ///< List containing the position of all the existing rows
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Free all the internal resources
|
/// \brief Free all the internal resources
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load a new glyph and store it in the cache
|
/// \brief Load a new glyph and store it in the cache
|
||||||
///
|
///
|
||||||
/// \param codePoint Unicode code point of the character to load
|
/// \param codePoint Unicode code point of the character to load
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
/// \param bold Retrieve the bold version or the regular one?
|
/// \param bold Retrieve the bold version or the regular one?
|
||||||
///
|
///
|
||||||
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
|
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Find a suitable rectangle within the texture for a glyph
|
/// \brief Find a suitable rectangle within the texture for a glyph
|
||||||
///
|
///
|
||||||
/// \param page Page of glyphs to search in
|
/// \param page Page of glyphs to search in
|
||||||
/// \param width Width of the rectangle
|
/// \param width Width of the rectangle
|
||||||
/// \param height Height of the rectangle
|
/// \param height Height of the rectangle
|
||||||
///
|
///
|
||||||
/// \return Found rectangle within the texture
|
/// \return Found rectangle within the texture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
|
IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Make sure that the given size is the current one
|
/// \brief Make sure that the given size is the current one
|
||||||
///
|
///
|
||||||
/// \param characterSize Reference character size
|
/// \param characterSize Reference character size
|
||||||
///
|
///
|
||||||
/// \return True on success, false if any error happened
|
/// \return True on success, false if any error happened
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool setCurrentSize(unsigned int characterSize) const;
|
bool setCurrentSize(unsigned int characterSize) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Types
|
// Types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef std::map<unsigned int, Page> PageTable; ///< Table mapping a character size to its page (texture)
|
typedef std::map<unsigned int, Page> PageTable; ///< Table mapping a character size to its page (texture)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details)
|
void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details)
|
||||||
void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details)
|
void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details)
|
||||||
void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details)
|
void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details)
|
||||||
int* m_refCount; ///< Reference counter used by implicit sharing
|
int* m_refCount; ///< Reference counter used by implicit sharing
|
||||||
Info m_info; ///< Information about the font
|
Info m_info; ///< Information about the font
|
||||||
mutable PageTable m_pages; ///< Table containing the glyphs pages by character size
|
mutable PageTable m_pages; ///< Table containing the glyphs pages by character size
|
||||||
mutable std::vector<Uint8> m_pixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
|
mutable std::vector<Uint8> m_pixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
|
||||||
#ifdef SFML_SYSTEM_ANDROID
|
#ifdef SFML_SYSTEM_ANDROID
|
||||||
void* m_stream; ///< Asset file streamer (if loaded from file)
|
void* m_stream; ///< Asset file streamer (if loaded from file)
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_FONT_HPP
|
#endif // SFML_FONT_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Font
|
/// \class sf::Font
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// Fonts can be loaded from a file, from memory or from a custom
|
/// Fonts can be loaded from a file, from memory or from a custom
|
||||||
/// stream, and supports the most common types of fonts. See
|
/// stream, and supports the most common types of fonts. See
|
||||||
/// the loadFromFile function for the complete list of supported formats.
|
/// the loadFromFile function for the complete list of supported formats.
|
||||||
///
|
///
|
||||||
/// Once it is loaded, a sf::Font instance provides three
|
/// Once it is loaded, a sf::Font instance provides three
|
||||||
/// types of information about the font:
|
/// types of information about the font:
|
||||||
/// \li Global metrics, such as the line spacing
|
/// \li Global metrics, such as the line spacing
|
||||||
/// \li Per-glyph metrics, such as bounding box or kerning
|
/// \li Per-glyph metrics, such as bounding box or kerning
|
||||||
/// \li Pixel representation of glyphs
|
/// \li Pixel representation of glyphs
|
||||||
///
|
///
|
||||||
/// Fonts alone are not very useful: they hold the font data
|
/// Fonts alone are not very useful: they hold the font data
|
||||||
/// but cannot make anything useful of it. To do so you need to
|
/// but cannot make anything useful of it. To do so you need to
|
||||||
/// use the sf::Text class, which is able to properly output text
|
/// use the sf::Text class, which is able to properly output text
|
||||||
/// with several options such as character size, style, color,
|
/// with several options such as character size, style, color,
|
||||||
/// position, rotation, etc.
|
/// position, rotation, etc.
|
||||||
/// This separation allows more flexibility and better performances:
|
/// This separation allows more flexibility and better performances:
|
||||||
/// indeed a sf::Font is a heavy resource, and any operation on it
|
/// indeed a sf::Font is a heavy resource, and any operation on it
|
||||||
/// is slow (often too slow for real-time applications). On the other
|
/// is slow (often too slow for real-time applications). On the other
|
||||||
/// side, a sf::Text is a lightweight object which can combine the
|
/// side, a sf::Text is a lightweight object which can combine the
|
||||||
/// glyphs data and metrics of a sf::Font to display any text on a
|
/// glyphs data and metrics of a sf::Font to display any text on a
|
||||||
/// render target.
|
/// render target.
|
||||||
/// Note that it is also possible to bind several sf::Text instances
|
/// Note that it is also possible to bind several sf::Text instances
|
||||||
/// to the same sf::Font.
|
/// to the same sf::Font.
|
||||||
///
|
///
|
||||||
/// It is important to note that the sf::Text instance doesn't
|
/// It is important to note that the sf::Text instance doesn't
|
||||||
/// copy the font that it uses, it only keeps a reference to it.
|
/// copy the font that it uses, it only keeps a reference to it.
|
||||||
/// Thus, a sf::Font must not be destructed while it is
|
/// Thus, a sf::Font must not be destructed while it is
|
||||||
/// used by a sf::Text (i.e. never write a function that
|
/// used by a sf::Text (i.e. never write a function that
|
||||||
/// uses a local sf::Font instance for creating a text).
|
/// uses a local sf::Font instance for creating a text).
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Declare a new font
|
/// // Declare a new font
|
||||||
/// sf::Font font;
|
/// sf::Font font;
|
||||||
///
|
///
|
||||||
/// // Load it from a file
|
/// // Load it from a file
|
||||||
/// if (!font.loadFromFile("arial.ttf"))
|
/// if (!font.loadFromFile("arial.ttf"))
|
||||||
/// {
|
/// {
|
||||||
/// // error...
|
/// // error...
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Create a text which uses our font
|
/// // Create a text which uses our font
|
||||||
/// sf::Text text1;
|
/// sf::Text text1;
|
||||||
/// text1.setFont(font);
|
/// text1.setFont(font);
|
||||||
/// text1.setCharacterSize(30);
|
/// text1.setCharacterSize(30);
|
||||||
/// text1.setStyle(sf::Text::Regular);
|
/// text1.setStyle(sf::Text::Regular);
|
||||||
///
|
///
|
||||||
/// // Create another text using the same font, but with different parameters
|
/// // Create another text using the same font, but with different parameters
|
||||||
/// sf::Text text2;
|
/// sf::Text text2;
|
||||||
/// text2.setFont(font);
|
/// text2.setFont(font);
|
||||||
/// text2.setCharacterSize(50);
|
/// text2.setCharacterSize(50);
|
||||||
/// text1.setStyle(sf::Text::Italic);
|
/// text1.setStyle(sf::Text::Italic);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Apart from loading font files, and passing them to instances
|
/// Apart from loading font files, and passing them to instances
|
||||||
/// of sf::Text, you should normally not have to deal directly
|
/// of sf::Text, you should normally not have to deal directly
|
||||||
/// with this class. However, it may be useful to access the
|
/// with this class. However, it may be useful to access the
|
||||||
/// font metrics or rasterized glyphs for advanced usage.
|
/// font metrics or rasterized glyphs for advanced usage.
|
||||||
///
|
///
|
||||||
/// Note that if the font is a bitmap font, it is not scalable,
|
/// Note that if the font is a bitmap font, it is not scalable,
|
||||||
/// thus not all requested sizes will be available to use. This
|
/// thus not all requested sizes will be available to use. This
|
||||||
/// needs to be taken into consideration when using sf::Text.
|
/// needs to be taken into consideration when using sf::Text.
|
||||||
/// If you need to display text of a certain size, make sure the
|
/// If you need to display text of a certain size, make sure the
|
||||||
/// corresponding bitmap font that supports that size is used.
|
/// corresponding bitmap font that supports that size is used.
|
||||||
///
|
///
|
||||||
/// \see sf::Text
|
/// \see sf::Text
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,79 +1,79 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_GLYPH_HPP
|
#ifndef SFML_GLYPH_HPP
|
||||||
#define SFML_GLYPH_HPP
|
#define SFML_GLYPH_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Structure describing a glyph
|
/// \brief Structure describing a glyph
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Glyph
|
class SFML_GRAPHICS_API Glyph
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Glyph() : advance(0) {}
|
Glyph() : advance(0) {}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float advance; ///< Offset to move horizontically to the next character
|
float advance; ///< Offset to move horizontically to the next character
|
||||||
FloatRect bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline
|
FloatRect bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline
|
||||||
IntRect textureRect; ///< Texture coordinates of the glyph inside the font's texture
|
IntRect textureRect; ///< Texture coordinates of the glyph inside the font's texture
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_GLYPH_HPP
|
#endif // SFML_GLYPH_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Glyph
|
/// \class sf::Glyph
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// A glyph is the visual representation of a character.
|
/// A glyph is the visual representation of a character.
|
||||||
///
|
///
|
||||||
/// The sf::Glyph structure provides the information needed
|
/// The sf::Glyph structure provides the information needed
|
||||||
/// to handle the glyph:
|
/// to handle the glyph:
|
||||||
/// \li its coordinates in the font's texture
|
/// \li its coordinates in the font's texture
|
||||||
/// \li its bounding rectangle
|
/// \li its bounding rectangle
|
||||||
/// \li the offset to apply to get the starting position of the next glyph
|
/// \li the offset to apply to get the starting position of the next glyph
|
||||||
///
|
///
|
||||||
/// \see sf::Font
|
/// \see sf::Font
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,327 +1,327 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_IMAGE_HPP
|
#ifndef SFML_IMAGE_HPP
|
||||||
#define SFML_IMAGE_HPP
|
#define SFML_IMAGE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class InputStream;
|
class InputStream;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Class for loading, manipulating and saving images
|
/// \brief Class for loading, manipulating and saving images
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Image
|
class SFML_GRAPHICS_API Image
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Creates an empty image.
|
/// Creates an empty image.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Image();
|
Image();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~Image();
|
~Image();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create the image and fill it with a unique color
|
/// \brief Create the image and fill it with a unique color
|
||||||
///
|
///
|
||||||
/// \param width Width of the image
|
/// \param width Width of the image
|
||||||
/// \param height Height of the image
|
/// \param height Height of the image
|
||||||
/// \param color Fill color
|
/// \param color Fill color
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0));
|
void create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0));
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create the image from an array of pixels
|
/// \brief Create the image from an array of pixels
|
||||||
///
|
///
|
||||||
/// The \a pixel array is assumed to contain 32-bits RGBA pixels,
|
/// The \a pixel array is assumed to contain 32-bits RGBA pixels,
|
||||||
/// and have the given \a width and \a height. If not, this is
|
/// and have the given \a width and \a height. If not, this is
|
||||||
/// an undefined behaviour.
|
/// an undefined behaviour.
|
||||||
/// If \a pixels is null, an empty image is created.
|
/// If \a pixels is null, an empty image is created.
|
||||||
///
|
///
|
||||||
/// \param width Width of the image
|
/// \param width Width of the image
|
||||||
/// \param height Height of the image
|
/// \param height Height of the image
|
||||||
/// \param pixels Array of pixels to copy to the image
|
/// \param pixels Array of pixels to copy to the image
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void create(unsigned int width, unsigned int height, const Uint8* pixels);
|
void create(unsigned int width, unsigned int height, const Uint8* pixels);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the image from a file on disk
|
/// \brief Load the image from a file on disk
|
||||||
///
|
///
|
||||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||||
/// psd, hdr and pic. Some format options are not supported,
|
/// psd, hdr and pic. Some format options are not supported,
|
||||||
/// like progressive jpeg.
|
/// like progressive jpeg.
|
||||||
/// If this function fails, the image is left unchanged.
|
/// If this function fails, the image is left unchanged.
|
||||||
///
|
///
|
||||||
/// \param filename Path of the image file to load
|
/// \param filename Path of the image file to load
|
||||||
///
|
///
|
||||||
/// \return True if loading was successful
|
/// \return True if loading was successful
|
||||||
///
|
///
|
||||||
/// \see loadFromMemory, loadFromStream, saveToFile
|
/// \see loadFromMemory, loadFromStream, saveToFile
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromFile(const std::string& filename);
|
bool loadFromFile(const std::string& filename);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the image from a file in memory
|
/// \brief Load the image from a file in memory
|
||||||
///
|
///
|
||||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||||
/// psd, hdr and pic. Some format options are not supported,
|
/// psd, hdr and pic. Some format options are not supported,
|
||||||
/// like progressive jpeg.
|
/// like progressive jpeg.
|
||||||
/// If this function fails, the image is left unchanged.
|
/// If this function fails, the image is left unchanged.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the file data in memory
|
/// \param data Pointer to the file data in memory
|
||||||
/// \param size Size of the data to load, in bytes
|
/// \param size Size of the data to load, in bytes
|
||||||
///
|
///
|
||||||
/// \return True if loading was successful
|
/// \return True if loading was successful
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromStream
|
/// \see loadFromFile, loadFromStream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromMemory(const void* data, std::size_t size);
|
bool loadFromMemory(const void* data, std::size_t size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load the image from a custom stream
|
/// \brief Load the image from a custom stream
|
||||||
///
|
///
|
||||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||||
/// psd, hdr and pic. Some format options are not supported,
|
/// psd, hdr and pic. Some format options are not supported,
|
||||||
/// like progressive jpeg.
|
/// like progressive jpeg.
|
||||||
/// If this function fails, the image is left unchanged.
|
/// If this function fails, the image is left unchanged.
|
||||||
///
|
///
|
||||||
/// \param stream Source stream to read from
|
/// \param stream Source stream to read from
|
||||||
///
|
///
|
||||||
/// \return True if loading was successful
|
/// \return True if loading was successful
|
||||||
///
|
///
|
||||||
/// \see loadFromFile, loadFromMemory
|
/// \see loadFromFile, loadFromMemory
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool loadFromStream(InputStream& stream);
|
bool loadFromStream(InputStream& stream);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Save the image to a file on disk
|
/// \brief Save the image to a file on disk
|
||||||
///
|
///
|
||||||
/// The format of the image is automatically deduced from
|
/// The format of the image is automatically deduced from
|
||||||
/// the extension. The supported image formats are bmp, png,
|
/// the extension. The supported image formats are bmp, png,
|
||||||
/// tga and jpg. The destination file is overwritten
|
/// tga and jpg. The destination file is overwritten
|
||||||
/// if it already exists. This function fails if the image is empty.
|
/// if it already exists. This function fails if the image is empty.
|
||||||
///
|
///
|
||||||
/// \param filename Path of the file to save
|
/// \param filename Path of the file to save
|
||||||
///
|
///
|
||||||
/// \return True if saving was successful
|
/// \return True if saving was successful
|
||||||
///
|
///
|
||||||
/// \see create, loadFromFile, loadFromMemory
|
/// \see create, loadFromFile, loadFromMemory
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool saveToFile(const std::string& filename) const;
|
bool saveToFile(const std::string& filename) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Return the size (width and height) of the image
|
/// \brief Return the size (width and height) of the image
|
||||||
///
|
///
|
||||||
/// \return Size of the image, in pixels
|
/// \return Size of the image, in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2u getSize() const;
|
Vector2u getSize() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create a transparency mask from a specified color-key
|
/// \brief Create a transparency mask from a specified color-key
|
||||||
///
|
///
|
||||||
/// This function sets the alpha value of every pixel matching
|
/// This function sets the alpha value of every pixel matching
|
||||||
/// the given color to \a alpha (0 by default), so that they
|
/// the given color to \a alpha (0 by default), so that they
|
||||||
/// become transparent.
|
/// become transparent.
|
||||||
///
|
///
|
||||||
/// \param color Color to make transparent
|
/// \param color Color to make transparent
|
||||||
/// \param alpha Alpha value to assign to transparent pixels
|
/// \param alpha Alpha value to assign to transparent pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void createMaskFromColor(const Color& color, Uint8 alpha = 0);
|
void createMaskFromColor(const Color& color, Uint8 alpha = 0);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy pixels from another image onto this one
|
/// \brief Copy pixels from another image onto this one
|
||||||
///
|
///
|
||||||
/// This function does a slow pixel copy and should not be
|
/// This function does a slow pixel copy and should not be
|
||||||
/// used intensively. It can be used to prepare a complex
|
/// used intensively. It can be used to prepare a complex
|
||||||
/// static image from several others, but if you need this
|
/// static image from several others, but if you need this
|
||||||
/// kind of feature in real-time you'd better use sf::RenderTexture.
|
/// kind of feature in real-time you'd better use sf::RenderTexture.
|
||||||
///
|
///
|
||||||
/// If \a sourceRect is empty, the whole image is copied.
|
/// If \a sourceRect is empty, the whole image is copied.
|
||||||
/// If \a applyAlpha is set to true, the transparency of
|
/// If \a applyAlpha is set to true, the transparency of
|
||||||
/// source pixels is applied. If it is false, the pixels are
|
/// source pixels is applied. If it is false, the pixels are
|
||||||
/// copied unchanged with their alpha value.
|
/// copied unchanged with their alpha value.
|
||||||
///
|
///
|
||||||
/// \param source Source image to copy
|
/// \param source Source image to copy
|
||||||
/// \param destX X coordinate of the destination position
|
/// \param destX X coordinate of the destination position
|
||||||
/// \param destY Y coordinate of the destination position
|
/// \param destY Y coordinate of the destination position
|
||||||
/// \param sourceRect Sub-rectangle of the source image to copy
|
/// \param sourceRect Sub-rectangle of the source image to copy
|
||||||
/// \param applyAlpha Should the copy take in account the source transparency?
|
/// \param applyAlpha Should the copy take in account the source transparency?
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false);
|
void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the color of a pixel
|
/// \brief Change the color of a pixel
|
||||||
///
|
///
|
||||||
/// This function doesn't check the validity of the pixel
|
/// This function doesn't check the validity of the pixel
|
||||||
/// coordinates, using out-of-range values will result in
|
/// coordinates, using out-of-range values will result in
|
||||||
/// an undefined behaviour.
|
/// an undefined behaviour.
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of pixel to change
|
/// \param x X coordinate of pixel to change
|
||||||
/// \param y Y coordinate of pixel to change
|
/// \param y Y coordinate of pixel to change
|
||||||
/// \param color New color of the pixel
|
/// \param color New color of the pixel
|
||||||
///
|
///
|
||||||
/// \see getPixel
|
/// \see getPixel
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setPixel(unsigned int x, unsigned int y, const Color& color);
|
void setPixel(unsigned int x, unsigned int y, const Color& color);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the color of a pixel
|
/// \brief Get the color of a pixel
|
||||||
///
|
///
|
||||||
/// This function doesn't check the validity of the pixel
|
/// This function doesn't check the validity of the pixel
|
||||||
/// coordinates, using out-of-range values will result in
|
/// coordinates, using out-of-range values will result in
|
||||||
/// an undefined behaviour.
|
/// an undefined behaviour.
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of pixel to get
|
/// \param x X coordinate of pixel to get
|
||||||
/// \param y Y coordinate of pixel to get
|
/// \param y Y coordinate of pixel to get
|
||||||
///
|
///
|
||||||
/// \return Color of the pixel at coordinates (x, y)
|
/// \return Color of the pixel at coordinates (x, y)
|
||||||
///
|
///
|
||||||
/// \see setPixel
|
/// \see setPixel
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Color getPixel(unsigned int x, unsigned int y) const;
|
Color getPixel(unsigned int x, unsigned int y) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get a read-only pointer to the array of pixels
|
/// \brief Get a read-only pointer to the array of pixels
|
||||||
///
|
///
|
||||||
/// The returned value points to an array of RGBA pixels made of
|
/// The returned value points to an array of RGBA pixels made of
|
||||||
/// 8 bits integers components. The size of the array is
|
/// 8 bits integers components. The size of the array is
|
||||||
/// width * height * 4 (getSize().x * getSize().y * 4).
|
/// width * height * 4 (getSize().x * getSize().y * 4).
|
||||||
/// Warning: the returned pointer may become invalid if you
|
/// Warning: the returned pointer may become invalid if you
|
||||||
/// modify the image, so you should never store it for too long.
|
/// modify the image, so you should never store it for too long.
|
||||||
/// If the image is empty, a null pointer is returned.
|
/// If the image is empty, a null pointer is returned.
|
||||||
///
|
///
|
||||||
/// \return Read-only pointer to the array of pixels
|
/// \return Read-only pointer to the array of pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Uint8* getPixelsPtr() const;
|
const Uint8* getPixelsPtr() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Flip the image horizontally (left <-> right)
|
/// \brief Flip the image horizontally (left <-> right)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void flipHorizontally();
|
void flipHorizontally();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Flip the image vertically (top <-> bottom)
|
/// \brief Flip the image vertically (top <-> bottom)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void flipVertically();
|
void flipVertically();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2u m_size; ///< Image size
|
Vector2u m_size; ///< Image size
|
||||||
std::vector<Uint8> m_pixels; ///< Pixels of the image
|
std::vector<Uint8> m_pixels; ///< Pixels of the image
|
||||||
#ifdef SFML_SYSTEM_ANDROID
|
#ifdef SFML_SYSTEM_ANDROID
|
||||||
void* m_stream; ///< Asset file streamer (if loaded from file)
|
void* m_stream; ///< Asset file streamer (if loaded from file)
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_IMAGE_HPP
|
#endif // SFML_IMAGE_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Image
|
/// \class sf::Image
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::Image is an abstraction to manipulate images
|
/// sf::Image is an abstraction to manipulate images
|
||||||
/// as bidimensional arrays of pixels. The class provides
|
/// as bidimensional arrays of pixels. The class provides
|
||||||
/// functions to load, read, write and save pixels, as well
|
/// functions to load, read, write and save pixels, as well
|
||||||
/// as many other useful functions.
|
/// as many other useful functions.
|
||||||
///
|
///
|
||||||
/// sf::Image can handle a unique internal representation of
|
/// sf::Image can handle a unique internal representation of
|
||||||
/// pixels, which is RGBA 32 bits. This means that a pixel
|
/// pixels, which is RGBA 32 bits. This means that a pixel
|
||||||
/// must be composed of 8 bits red, green, blue and alpha
|
/// must be composed of 8 bits red, green, blue and alpha
|
||||||
/// channels -- just like a sf::Color.
|
/// channels -- just like a sf::Color.
|
||||||
/// All the functions that return an array of pixels follow
|
/// All the functions that return an array of pixels follow
|
||||||
/// this rule, and all parameters that you pass to sf::Image
|
/// this rule, and all parameters that you pass to sf::Image
|
||||||
/// functions (such as loadFromMemory) must use this
|
/// functions (such as loadFromMemory) must use this
|
||||||
/// representation as well.
|
/// representation as well.
|
||||||
///
|
///
|
||||||
/// A sf::Image can be copied, but it is a heavy resource and
|
/// A sf::Image can be copied, but it is a heavy resource and
|
||||||
/// if possible you should always use [const] references to
|
/// if possible you should always use [const] references to
|
||||||
/// pass or return them to avoid useless copies.
|
/// pass or return them to avoid useless copies.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Load an image file from a file
|
/// // Load an image file from a file
|
||||||
/// sf::Image background;
|
/// sf::Image background;
|
||||||
/// if (!background.loadFromFile("background.jpg"))
|
/// if (!background.loadFromFile("background.jpg"))
|
||||||
/// return -1;
|
/// return -1;
|
||||||
///
|
///
|
||||||
/// // Create a 20x20 image filled with black color
|
/// // Create a 20x20 image filled with black color
|
||||||
/// sf::Image image;
|
/// sf::Image image;
|
||||||
/// image.create(20, 20, sf::Color::Black);
|
/// image.create(20, 20, sf::Color::Black);
|
||||||
///
|
///
|
||||||
/// // Copy image1 on image2 at position (10, 10)
|
/// // Copy image1 on image2 at position (10, 10)
|
||||||
/// image.copy(background, 10, 10);
|
/// image.copy(background, 10, 10);
|
||||||
///
|
///
|
||||||
/// // Make the top-left pixel transparent
|
/// // Make the top-left pixel transparent
|
||||||
/// sf::Color color = image.getPixel(0, 0);
|
/// sf::Color color = image.getPixel(0, 0);
|
||||||
/// color.a = 0;
|
/// color.a = 0;
|
||||||
/// image.setPixel(0, 0, color);
|
/// image.setPixel(0, 0, color);
|
||||||
///
|
///
|
||||||
/// // Save the image to a file
|
/// // Save the image to a file
|
||||||
/// if (!image.saveToFile("result.png"))
|
/// if (!image.saveToFile("result.png"))
|
||||||
/// return -1;
|
/// return -1;
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Texture
|
/// \see sf::Texture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,248 +1,248 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_RECT_HPP
|
#ifndef SFML_RECT_HPP
|
||||||
#define SFML_RECT_HPP
|
#define SFML_RECT_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Utility class for manipulating 2D axis aligned rectangles
|
/// \brief Utility class for manipulating 2D axis aligned rectangles
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Rect
|
class Rect
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Creates an empty rectangle (it is equivalent to calling
|
/// Creates an empty rectangle (it is equivalent to calling
|
||||||
/// Rect(0, 0, 0, 0)).
|
/// Rect(0, 0, 0, 0)).
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Rect();
|
Rect();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the rectangle from its coordinates
|
/// \brief Construct the rectangle from its coordinates
|
||||||
///
|
///
|
||||||
/// Be careful, the last two parameters are the width
|
/// Be careful, the last two parameters are the width
|
||||||
/// and height, not the right and bottom coordinates!
|
/// and height, not the right and bottom coordinates!
|
||||||
///
|
///
|
||||||
/// \param rectLeft Left coordinate of the rectangle
|
/// \param rectLeft Left coordinate of the rectangle
|
||||||
/// \param rectTop Top coordinate of the rectangle
|
/// \param rectTop Top coordinate of the rectangle
|
||||||
/// \param rectWidth Width of the rectangle
|
/// \param rectWidth Width of the rectangle
|
||||||
/// \param rectHeight Height of the rectangle
|
/// \param rectHeight Height of the rectangle
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight);
|
Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the rectangle from position and size
|
/// \brief Construct the rectangle from position and size
|
||||||
///
|
///
|
||||||
/// Be careful, the last parameter is the size,
|
/// Be careful, the last parameter is the size,
|
||||||
/// not the bottom-right corner!
|
/// not the bottom-right corner!
|
||||||
///
|
///
|
||||||
/// \param position Position of the top-left corner of the rectangle
|
/// \param position Position of the top-left corner of the rectangle
|
||||||
/// \param size Size of the rectangle
|
/// \param size Size of the rectangle
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Rect(const Vector2<T>& position, const Vector2<T>& size);
|
Rect(const Vector2<T>& position, const Vector2<T>& size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the rectangle from another type of rectangle
|
/// \brief Construct the rectangle from another type of rectangle
|
||||||
///
|
///
|
||||||
/// This constructor doesn't replace the copy constructor,
|
/// This constructor doesn't replace the copy constructor,
|
||||||
/// it's called only when U != T.
|
/// it's called only when U != T.
|
||||||
/// A call to this constructor will fail to compile if U
|
/// A call to this constructor will fail to compile if U
|
||||||
/// is not convertible to T.
|
/// is not convertible to T.
|
||||||
///
|
///
|
||||||
/// \param rectangle Rectangle to convert
|
/// \param rectangle Rectangle to convert
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename U>
|
template <typename U>
|
||||||
explicit Rect(const Rect<U>& rectangle);
|
explicit Rect(const Rect<U>& rectangle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check if a point is inside the rectangle's area
|
/// \brief Check if a point is inside the rectangle's area
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of the point to test
|
/// \param x X coordinate of the point to test
|
||||||
/// \param y Y coordinate of the point to test
|
/// \param y Y coordinate of the point to test
|
||||||
///
|
///
|
||||||
/// \return True if the point is inside, false otherwise
|
/// \return True if the point is inside, false otherwise
|
||||||
///
|
///
|
||||||
/// \see intersects
|
/// \see intersects
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool contains(T x, T y) const;
|
bool contains(T x, T y) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check if a point is inside the rectangle's area
|
/// \brief Check if a point is inside the rectangle's area
|
||||||
///
|
///
|
||||||
/// \param point Point to test
|
/// \param point Point to test
|
||||||
///
|
///
|
||||||
/// \return True if the point is inside, false otherwise
|
/// \return True if the point is inside, false otherwise
|
||||||
///
|
///
|
||||||
/// \see intersects
|
/// \see intersects
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool contains(const Vector2<T>& point) const;
|
bool contains(const Vector2<T>& point) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check the intersection between two rectangles
|
/// \brief Check the intersection between two rectangles
|
||||||
///
|
///
|
||||||
/// \param rectangle Rectangle to test
|
/// \param rectangle Rectangle to test
|
||||||
///
|
///
|
||||||
/// \return True if rectangles overlap, false otherwise
|
/// \return True if rectangles overlap, false otherwise
|
||||||
///
|
///
|
||||||
/// \see contains
|
/// \see contains
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool intersects(const Rect<T>& rectangle) const;
|
bool intersects(const Rect<T>& rectangle) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check the intersection between two rectangles
|
/// \brief Check the intersection between two rectangles
|
||||||
///
|
///
|
||||||
/// This overload returns the overlapped rectangle in the
|
/// This overload returns the overlapped rectangle in the
|
||||||
/// \a intersection parameter.
|
/// \a intersection parameter.
|
||||||
///
|
///
|
||||||
/// \param rectangle Rectangle to test
|
/// \param rectangle Rectangle to test
|
||||||
/// \param intersection Rectangle to be filled with the intersection
|
/// \param intersection Rectangle to be filled with the intersection
|
||||||
///
|
///
|
||||||
/// \return True if rectangles overlap, false otherwise
|
/// \return True if rectangles overlap, false otherwise
|
||||||
///
|
///
|
||||||
/// \see contains
|
/// \see contains
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool intersects(const Rect<T>& rectangle, Rect<T>& intersection) const;
|
bool intersects(const Rect<T>& rectangle, Rect<T>& intersection) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
T left; ///< Left coordinate of the rectangle
|
T left; ///< Left coordinate of the rectangle
|
||||||
T top; ///< Top coordinate of the rectangle
|
T top; ///< Top coordinate of the rectangle
|
||||||
T width; ///< Width of the rectangle
|
T width; ///< Width of the rectangle
|
||||||
T height; ///< Height of the rectangle
|
T height; ///< Height of the rectangle
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Rect
|
/// \relates Rect
|
||||||
/// \brief Overload of binary operator ==
|
/// \brief Overload of binary operator ==
|
||||||
///
|
///
|
||||||
/// This operator compares strict equality between two rectangles.
|
/// This operator compares strict equality between two rectangles.
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a rectangle)
|
/// \param left Left operand (a rectangle)
|
||||||
/// \param right Right operand (a rectangle)
|
/// \param right Right operand (a rectangle)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is equal to \a right
|
/// \return True if \a left is equal to \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator ==(const Rect<T>& left, const Rect<T>& right);
|
bool operator ==(const Rect<T>& left, const Rect<T>& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \relates Rect
|
/// \relates Rect
|
||||||
/// \brief Overload of binary operator !=
|
/// \brief Overload of binary operator !=
|
||||||
///
|
///
|
||||||
/// This operator compares strict difference between two rectangles.
|
/// This operator compares strict difference between two rectangles.
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a rectangle)
|
/// \param left Left operand (a rectangle)
|
||||||
/// \param right Right operand (a rectangle)
|
/// \param right Right operand (a rectangle)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is not equal to \a right
|
/// \return True if \a left is not equal to \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator !=(const Rect<T>& left, const Rect<T>& right);
|
bool operator !=(const Rect<T>& left, const Rect<T>& right);
|
||||||
|
|
||||||
#include <SFML/Graphics/Rect.inl>
|
#include <SFML/Graphics/Rect.inl>
|
||||||
|
|
||||||
// Create typedefs for the most common types
|
// Create typedefs for the most common types
|
||||||
typedef Rect<int> IntRect;
|
typedef Rect<int> IntRect;
|
||||||
typedef Rect<float> FloatRect;
|
typedef Rect<float> FloatRect;
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RECT_HPP
|
#endif // SFML_RECT_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Rect
|
/// \class sf::Rect
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// A rectangle is defined by its top-left corner and its size.
|
/// A rectangle is defined by its top-left corner and its size.
|
||||||
/// It is a very simple class defined for convenience, so
|
/// It is a very simple class defined for convenience, so
|
||||||
/// its member variables (left, top, width and height) are public
|
/// its member variables (left, top, width and height) are public
|
||||||
/// and can be accessed directly, just like the vector classes
|
/// and can be accessed directly, just like the vector classes
|
||||||
/// (Vector2 and Vector3).
|
/// (Vector2 and Vector3).
|
||||||
///
|
///
|
||||||
/// To keep things simple, sf::Rect doesn't define
|
/// To keep things simple, sf::Rect doesn't define
|
||||||
/// functions to emulate the properties that are not directly
|
/// functions to emulate the properties that are not directly
|
||||||
/// members (such as right, bottom, center, etc.), it rather
|
/// members (such as right, bottom, center, etc.), it rather
|
||||||
/// only provides intersection functions.
|
/// only provides intersection functions.
|
||||||
///
|
///
|
||||||
/// sf::Rect uses the usual rules for its boundaries:
|
/// sf::Rect uses the usual rules for its boundaries:
|
||||||
/// \li The left and top edges are included in the rectangle's area
|
/// \li The left and top edges are included in the rectangle's area
|
||||||
/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area
|
/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area
|
||||||
///
|
///
|
||||||
/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1)
|
/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1)
|
||||||
/// don't intersect.
|
/// don't intersect.
|
||||||
///
|
///
|
||||||
/// sf::Rect is a template and may be used with any numeric type, but
|
/// sf::Rect is a template and may be used with any numeric type, but
|
||||||
/// for simplicity the instanciations used by SFML are typedefed:
|
/// for simplicity the instanciations used by SFML are typedefed:
|
||||||
/// \li sf::Rect<int> is sf::IntRect
|
/// \li sf::Rect<int> is sf::IntRect
|
||||||
/// \li sf::Rect<float> is sf::FloatRect
|
/// \li sf::Rect<float> is sf::FloatRect
|
||||||
///
|
///
|
||||||
/// So that you don't have to care about the template syntax.
|
/// So that you don't have to care about the template syntax.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Define a rectangle, located at (0, 0) with a size of 20x5
|
/// // Define a rectangle, located at (0, 0) with a size of 20x5
|
||||||
/// sf::IntRect r1(0, 0, 20, 5);
|
/// sf::IntRect r1(0, 0, 20, 5);
|
||||||
///
|
///
|
||||||
/// // Define another rectangle, located at (4, 2) with a size of 18x10
|
/// // Define another rectangle, located at (4, 2) with a size of 18x10
|
||||||
/// sf::Vector2i position(4, 2);
|
/// sf::Vector2i position(4, 2);
|
||||||
/// sf::Vector2i size(18, 10);
|
/// sf::Vector2i size(18, 10);
|
||||||
/// sf::IntRect r2(position, size);
|
/// sf::IntRect r2(position, size);
|
||||||
///
|
///
|
||||||
/// // Test intersections with the point (3, 1)
|
/// // Test intersections with the point (3, 1)
|
||||||
/// bool b1 = r1.contains(3, 1); // true
|
/// bool b1 = r1.contains(3, 1); // true
|
||||||
/// bool b2 = r2.contains(3, 1); // false
|
/// bool b2 = r2.contains(3, 1); // false
|
||||||
///
|
///
|
||||||
/// // Test the intersection between r1 and r2
|
/// // Test the intersection between r1 and r2
|
||||||
/// sf::IntRect result;
|
/// sf::IntRect result;
|
||||||
/// bool b3 = r1.intersects(r2, result); // true
|
/// bool b3 = r1.intersects(r2, result); // true
|
||||||
/// // result == (4, 2, 16, 3)
|
/// // result == (4, 2, 16, 3)
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,159 +1,159 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Rect<T>::Rect() :
|
Rect<T>::Rect() :
|
||||||
left (0),
|
left (0),
|
||||||
top (0),
|
top (0),
|
||||||
width (0),
|
width (0),
|
||||||
height(0)
|
height(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Rect<T>::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) :
|
Rect<T>::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) :
|
||||||
left (rectLeft),
|
left (rectLeft),
|
||||||
top (rectTop),
|
top (rectTop),
|
||||||
width (rectWidth),
|
width (rectWidth),
|
||||||
height(rectHeight)
|
height(rectHeight)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) :
|
Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) :
|
||||||
left (position.x),
|
left (position.x),
|
||||||
top (position.y),
|
top (position.y),
|
||||||
width (size.x),
|
width (size.x),
|
||||||
height(size.y)
|
height(size.y)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
template <typename U>
|
template <typename U>
|
||||||
Rect<T>::Rect(const Rect<U>& rectangle) :
|
Rect<T>::Rect(const Rect<U>& rectangle) :
|
||||||
left (static_cast<T>(rectangle.left)),
|
left (static_cast<T>(rectangle.left)),
|
||||||
top (static_cast<T>(rectangle.top)),
|
top (static_cast<T>(rectangle.top)),
|
||||||
width (static_cast<T>(rectangle.width)),
|
width (static_cast<T>(rectangle.width)),
|
||||||
height(static_cast<T>(rectangle.height))
|
height(static_cast<T>(rectangle.height))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool Rect<T>::contains(T x, T y) const
|
bool Rect<T>::contains(T x, T y) const
|
||||||
{
|
{
|
||||||
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
||||||
|
|
||||||
// Compute the real min and max of the rectangle on both axes
|
// Compute the real min and max of the rectangle on both axes
|
||||||
T minX = std::min(left, static_cast<T>(left + width));
|
T minX = std::min(left, static_cast<T>(left + width));
|
||||||
T maxX = std::max(left, static_cast<T>(left + width));
|
T maxX = std::max(left, static_cast<T>(left + width));
|
||||||
T minY = std::min(top, static_cast<T>(top + height));
|
T minY = std::min(top, static_cast<T>(top + height));
|
||||||
T maxY = std::max(top, static_cast<T>(top + height));
|
T maxY = std::max(top, static_cast<T>(top + height));
|
||||||
|
|
||||||
return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY);
|
return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool Rect<T>::contains(const Vector2<T>& point) const
|
bool Rect<T>::contains(const Vector2<T>& point) const
|
||||||
{
|
{
|
||||||
return contains(point.x, point.y);
|
return contains(point.x, point.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool Rect<T>::intersects(const Rect<T>& rectangle) const
|
bool Rect<T>::intersects(const Rect<T>& rectangle) const
|
||||||
{
|
{
|
||||||
Rect<T> intersection;
|
Rect<T> intersection;
|
||||||
return intersects(rectangle, intersection);
|
return intersects(rectangle, intersection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool Rect<T>::intersects(const Rect<T>& rectangle, Rect<T>& intersection) const
|
bool Rect<T>::intersects(const Rect<T>& rectangle, Rect<T>& intersection) const
|
||||||
{
|
{
|
||||||
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
||||||
|
|
||||||
// Compute the min and max of the first rectangle on both axes
|
// Compute the min and max of the first rectangle on both axes
|
||||||
T r1MinX = std::min(left, static_cast<T>(left + width));
|
T r1MinX = std::min(left, static_cast<T>(left + width));
|
||||||
T r1MaxX = std::max(left, static_cast<T>(left + width));
|
T r1MaxX = std::max(left, static_cast<T>(left + width));
|
||||||
T r1MinY = std::min(top, static_cast<T>(top + height));
|
T r1MinY = std::min(top, static_cast<T>(top + height));
|
||||||
T r1MaxY = std::max(top, static_cast<T>(top + height));
|
T r1MaxY = std::max(top, static_cast<T>(top + height));
|
||||||
|
|
||||||
// Compute the min and max of the second rectangle on both axes
|
// Compute the min and max of the second rectangle on both axes
|
||||||
T r2MinX = std::min(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
T r2MinX = std::min(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
||||||
T r2MaxX = std::max(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
T r2MaxX = std::max(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
||||||
T r2MinY = std::min(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
T r2MinY = std::min(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
||||||
T r2MaxY = std::max(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
T r2MaxY = std::max(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
||||||
|
|
||||||
// Compute the intersection boundaries
|
// Compute the intersection boundaries
|
||||||
T interLeft = std::max(r1MinX, r2MinX);
|
T interLeft = std::max(r1MinX, r2MinX);
|
||||||
T interTop = std::max(r1MinY, r2MinY);
|
T interTop = std::max(r1MinY, r2MinY);
|
||||||
T interRight = std::min(r1MaxX, r2MaxX);
|
T interRight = std::min(r1MaxX, r2MaxX);
|
||||||
T interBottom = std::min(r1MaxY, r2MaxY);
|
T interBottom = std::min(r1MaxY, r2MaxY);
|
||||||
|
|
||||||
// If the intersection is valid (positive non zero area), then there is an intersection
|
// If the intersection is valid (positive non zero area), then there is an intersection
|
||||||
if ((interLeft < interRight) && (interTop < interBottom))
|
if ((interLeft < interRight) && (interTop < interBottom))
|
||||||
{
|
{
|
||||||
intersection = Rect<T>(interLeft, interTop, interRight - interLeft, interBottom - interTop);
|
intersection = Rect<T>(interLeft, interTop, interRight - interLeft, interBottom - interTop);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
intersection = Rect<T>(0, 0, 0, 0);
|
intersection = Rect<T>(0, 0, 0, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator ==(const Rect<T>& left, const Rect<T>& right)
|
inline bool operator ==(const Rect<T>& left, const Rect<T>& right)
|
||||||
{
|
{
|
||||||
return (left.left == right.left) && (left.width == right.width) &&
|
return (left.left == right.left) && (left.width == right.width) &&
|
||||||
(left.top == right.top) && (left.height == right.height);
|
(left.top == right.top) && (left.height == right.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator !=(const Rect<T>& left, const Rect<T>& right)
|
inline bool operator !=(const Rect<T>& left, const Rect<T>& right)
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API RectangleShape : public Shape
|
class SFML_GRAPHICS_API RectangleShape : public Shape
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
@ -94,7 +94,7 @@ public :
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual Vector2f getPoint(unsigned int index) const;
|
virtual Vector2f getPoint(unsigned int index) const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Texture;
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API RenderStates
|
class SFML_GRAPHICS_API RenderStates
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
|
|
@ -1,451 +1,451 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_RENDERTARGET_HPP
|
#ifndef SFML_RENDERTARGET_HPP
|
||||||
#define SFML_RENDERTARGET_HPP
|
#define SFML_RENDERTARGET_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
#include <SFML/Graphics/View.hpp>
|
#include <SFML/Graphics/View.hpp>
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
#include <SFML/Graphics/Transform.hpp>
|
||||||
#include <SFML/Graphics/BlendMode.hpp>
|
#include <SFML/Graphics/BlendMode.hpp>
|
||||||
#include <SFML/Graphics/RenderStates.hpp>
|
#include <SFML/Graphics/RenderStates.hpp>
|
||||||
#include <SFML/Graphics/PrimitiveType.hpp>
|
#include <SFML/Graphics/PrimitiveType.hpp>
|
||||||
#include <SFML/Graphics/Vertex.hpp>
|
#include <SFML/Graphics/Vertex.hpp>
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class Drawable;
|
class Drawable;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Base class for all render targets (window, texture, ...)
|
/// \brief Base class for all render targets (window, texture, ...)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API RenderTarget : NonCopyable
|
class SFML_GRAPHICS_API RenderTarget : NonCopyable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~RenderTarget();
|
virtual ~RenderTarget();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Clear the entire target with a single color
|
/// \brief Clear the entire target with a single color
|
||||||
///
|
///
|
||||||
/// This function is usually called once every frame,
|
/// This function is usually called once every frame,
|
||||||
/// to clear the previous contents of the target.
|
/// to clear the previous contents of the target.
|
||||||
///
|
///
|
||||||
/// \param color Fill color to use to clear the render target
|
/// \param color Fill color to use to clear the render target
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void clear(const Color& color = Color(0, 0, 0, 255));
|
void clear(const Color& color = Color(0, 0, 0, 255));
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the current active view
|
/// \brief Change the current active view
|
||||||
///
|
///
|
||||||
/// The view is like a 2D camera, it controls which part of
|
/// The view is like a 2D camera, it controls which part of
|
||||||
/// the 2D scene is visible, and how it is viewed in the
|
/// the 2D scene is visible, and how it is viewed in the
|
||||||
/// render-target.
|
/// render-target.
|
||||||
/// The new view will affect everything that is drawn, until
|
/// The new view will affect everything that is drawn, until
|
||||||
/// another view is set.
|
/// another view is set.
|
||||||
/// The render target keeps its own copy of the view object,
|
/// The render target keeps its own copy of the view object,
|
||||||
/// so it is not necessary to keep the original one alive
|
/// so it is not necessary to keep the original one alive
|
||||||
/// after calling this function.
|
/// after calling this function.
|
||||||
/// To restore the original view of the target, you can pass
|
/// To restore the original view of the target, you can pass
|
||||||
/// the result of getDefaultView() to this function.
|
/// the result of getDefaultView() to this function.
|
||||||
///
|
///
|
||||||
/// \param view New view to use
|
/// \param view New view to use
|
||||||
///
|
///
|
||||||
/// \see getView, getDefaultView
|
/// \see getView, getDefaultView
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setView(const View& view);
|
void setView(const View& view);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the view currently in use in the render target
|
/// \brief Get the view currently in use in the render target
|
||||||
///
|
///
|
||||||
/// \return The view object that is currently used
|
/// \return The view object that is currently used
|
||||||
///
|
///
|
||||||
/// \see setView, getDefaultView
|
/// \see setView, getDefaultView
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const View& getView() const;
|
const View& getView() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the default view of the render target
|
/// \brief Get the default view of the render target
|
||||||
///
|
///
|
||||||
/// The default view has the initial size of the render target,
|
/// The default view has the initial size of the render target,
|
||||||
/// and never changes after the target has been created.
|
/// and never changes after the target has been created.
|
||||||
///
|
///
|
||||||
/// \return The default view of the render target
|
/// \return The default view of the render target
|
||||||
///
|
///
|
||||||
/// \see setView, getView
|
/// \see setView, getView
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const View& getDefaultView() const;
|
const View& getDefaultView() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the viewport of a view, applied to this render target
|
/// \brief Get the viewport of a view, applied to this render target
|
||||||
///
|
///
|
||||||
/// The viewport is defined in the view as a ratio, this function
|
/// The viewport is defined in the view as a ratio, this function
|
||||||
/// simply applies this ratio to the current dimensions of the
|
/// simply applies this ratio to the current dimensions of the
|
||||||
/// render target to calculate the pixels rectangle that the viewport
|
/// render target to calculate the pixels rectangle that the viewport
|
||||||
/// actually covers in the target.
|
/// actually covers in the target.
|
||||||
///
|
///
|
||||||
/// \param view The view for which we want to compute the viewport
|
/// \param view The view for which we want to compute the viewport
|
||||||
///
|
///
|
||||||
/// \return Viewport rectangle, expressed in pixels
|
/// \return Viewport rectangle, expressed in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IntRect getViewport(const View& view) const;
|
IntRect getViewport(const View& view) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert a point from target coordinates to world
|
/// \brief Convert a point from target coordinates to world
|
||||||
/// coordinates, using the current view
|
/// coordinates, using the current view
|
||||||
///
|
///
|
||||||
/// This function is an overload of the mapPixelToCoords
|
/// This function is an overload of the mapPixelToCoords
|
||||||
/// function that implicitely uses the current view.
|
/// function that implicitely uses the current view.
|
||||||
/// It is equivalent to:
|
/// It is equivalent to:
|
||||||
/// \code
|
/// \code
|
||||||
/// target.mapPixelToCoords(point, target.getView());
|
/// target.mapPixelToCoords(point, target.getView());
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \param point Pixel to convert
|
/// \param point Pixel to convert
|
||||||
///
|
///
|
||||||
/// \return The converted point, in "world" coordinates
|
/// \return The converted point, in "world" coordinates
|
||||||
///
|
///
|
||||||
/// \see mapCoordsToPixel
|
/// \see mapCoordsToPixel
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2f mapPixelToCoords(const Vector2i& point) const;
|
Vector2f mapPixelToCoords(const Vector2i& point) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert a point from target coordinates to world coordinates
|
/// \brief Convert a point from target coordinates to world coordinates
|
||||||
///
|
///
|
||||||
/// This function finds the 2D position that matches the
|
/// This function finds the 2D position that matches the
|
||||||
/// given pixel of the render-target. In other words, it does
|
/// given pixel of the render-target. In other words, it does
|
||||||
/// the inverse of what the graphics card does, to find the
|
/// the inverse of what the graphics card does, to find the
|
||||||
/// initial position of a rendered pixel.
|
/// initial position of a rendered pixel.
|
||||||
///
|
///
|
||||||
/// Initially, both coordinate systems (world units and target pixels)
|
/// Initially, both coordinate systems (world units and target pixels)
|
||||||
/// match perfectly. But if you define a custom view or resize your
|
/// match perfectly. But if you define a custom view or resize your
|
||||||
/// render-target, this assertion is not true anymore, ie. a point
|
/// render-target, this assertion is not true anymore, ie. a point
|
||||||
/// located at (10, 50) in your render-target may map to the point
|
/// located at (10, 50) in your render-target may map to the point
|
||||||
/// (150, 75) in your 2D world -- if the view is translated by (140, 25).
|
/// (150, 75) in your 2D world -- if the view is translated by (140, 25).
|
||||||
///
|
///
|
||||||
/// For render-windows, this function is typically used to find
|
/// For render-windows, this function is typically used to find
|
||||||
/// which point (or object) is located below the mouse cursor.
|
/// which point (or object) is located below the mouse cursor.
|
||||||
///
|
///
|
||||||
/// This version uses a custom view for calculations, see the other
|
/// This version uses a custom view for calculations, see the other
|
||||||
/// overload of the function if you want to use the current view of the
|
/// overload of the function if you want to use the current view of the
|
||||||
/// render-target.
|
/// render-target.
|
||||||
///
|
///
|
||||||
/// \param point Pixel to convert
|
/// \param point Pixel to convert
|
||||||
/// \param view The view to use for converting the point
|
/// \param view The view to use for converting the point
|
||||||
///
|
///
|
||||||
/// \return The converted point, in "world" units
|
/// \return The converted point, in "world" units
|
||||||
///
|
///
|
||||||
/// \see mapCoordsToPixel
|
/// \see mapCoordsToPixel
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
|
Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert a point from world coordinates to target
|
/// \brief Convert a point from world coordinates to target
|
||||||
/// coordinates, using the current view
|
/// coordinates, using the current view
|
||||||
///
|
///
|
||||||
/// This function is an overload of the mapCoordsToPixel
|
/// This function is an overload of the mapCoordsToPixel
|
||||||
/// function that implicitely uses the current view.
|
/// function that implicitely uses the current view.
|
||||||
/// It is equivalent to:
|
/// It is equivalent to:
|
||||||
/// \code
|
/// \code
|
||||||
/// target.mapCoordsToPixel(point, target.getView());
|
/// target.mapCoordsToPixel(point, target.getView());
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \param point Point to convert
|
/// \param point Point to convert
|
||||||
///
|
///
|
||||||
/// \return The converted point, in target coordinates (pixels)
|
/// \return The converted point, in target coordinates (pixels)
|
||||||
///
|
///
|
||||||
/// \see mapPixelToCoords
|
/// \see mapPixelToCoords
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2i mapCoordsToPixel(const Vector2f& point) const;
|
Vector2i mapCoordsToPixel(const Vector2f& point) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert a point from world coordinates to target coordinates
|
/// \brief Convert a point from world coordinates to target coordinates
|
||||||
///
|
///
|
||||||
/// This function finds the pixel of the render-target that matches
|
/// This function finds the pixel of the render-target that matches
|
||||||
/// the given 2D point. In other words, it goes through the same process
|
/// the given 2D point. In other words, it goes through the same process
|
||||||
/// as the graphics card, to compute the final position of a rendered point.
|
/// as the graphics card, to compute the final position of a rendered point.
|
||||||
///
|
///
|
||||||
/// Initially, both coordinate systems (world units and target pixels)
|
/// Initially, both coordinate systems (world units and target pixels)
|
||||||
/// match perfectly. But if you define a custom view or resize your
|
/// match perfectly. But if you define a custom view or resize your
|
||||||
/// render-target, this assertion is not true anymore, ie. a point
|
/// render-target, this assertion is not true anymore, ie. a point
|
||||||
/// located at (150, 75) in your 2D world may map to the pixel
|
/// located at (150, 75) in your 2D world may map to the pixel
|
||||||
/// (10, 50) of your render-target -- if the view is translated by (140, 25).
|
/// (10, 50) of your render-target -- if the view is translated by (140, 25).
|
||||||
///
|
///
|
||||||
/// This version uses a custom view for calculations, see the other
|
/// This version uses a custom view for calculations, see the other
|
||||||
/// overload of the function if you want to use the current view of the
|
/// overload of the function if you want to use the current view of the
|
||||||
/// render-target.
|
/// render-target.
|
||||||
///
|
///
|
||||||
/// \param point Point to convert
|
/// \param point Point to convert
|
||||||
/// \param view The view to use for converting the point
|
/// \param view The view to use for converting the point
|
||||||
///
|
///
|
||||||
/// \return The converted point, in target coordinates (pixels)
|
/// \return The converted point, in target coordinates (pixels)
|
||||||
///
|
///
|
||||||
/// \see mapPixelToCoords
|
/// \see mapPixelToCoords
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
|
Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Draw a drawable object to the render-target
|
/// \brief Draw a drawable object to the render-target
|
||||||
///
|
///
|
||||||
/// \param drawable Object to draw
|
/// \param drawable Object to draw
|
||||||
/// \param states Render states to use for drawing
|
/// \param states Render states to use for drawing
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
|
void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Draw primitives defined by an array of vertices
|
/// \brief Draw primitives defined by an array of vertices
|
||||||
///
|
///
|
||||||
/// \param vertices Pointer to the vertices
|
/// \param vertices Pointer to the vertices
|
||||||
/// \param vertexCount Number of vertices in the array
|
/// \param vertexCount Number of vertices in the array
|
||||||
/// \param type Type of primitives to draw
|
/// \param type Type of primitives to draw
|
||||||
/// \param states Render states to use for drawing
|
/// \param states Render states to use for drawing
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void draw(const Vertex* vertices, unsigned int vertexCount,
|
void draw(const Vertex* vertices, unsigned int vertexCount,
|
||||||
PrimitiveType type, const RenderStates& states = RenderStates::Default);
|
PrimitiveType type, const RenderStates& states = RenderStates::Default);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Return the size of the rendering region of the target
|
/// \brief Return the size of the rendering region of the target
|
||||||
///
|
///
|
||||||
/// \return Size in pixels
|
/// \return Size in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual Vector2u getSize() const = 0;
|
virtual Vector2u getSize() const = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Save the current OpenGL render states and matrices
|
/// \brief Save the current OpenGL render states and matrices
|
||||||
///
|
///
|
||||||
/// This function can be used when you mix SFML drawing
|
/// This function can be used when you mix SFML drawing
|
||||||
/// and direct OpenGL rendering. Combined with PopGLStates,
|
/// and direct OpenGL rendering. Combined with PopGLStates,
|
||||||
/// it ensures that:
|
/// it ensures that:
|
||||||
/// \li SFML's internal states are not messed up by your OpenGL code
|
/// \li SFML's internal states are not messed up by your OpenGL code
|
||||||
/// \li your OpenGL states are not modified by a call to a SFML function
|
/// \li your OpenGL states are not modified by a call to a SFML function
|
||||||
///
|
///
|
||||||
/// More specifically, it must be used around code that
|
/// More specifically, it must be used around code that
|
||||||
/// calls Draw functions. Example:
|
/// calls Draw functions. Example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // OpenGL code here...
|
/// // OpenGL code here...
|
||||||
/// window.pushGLStates();
|
/// window.pushGLStates();
|
||||||
/// window.draw(...);
|
/// window.draw(...);
|
||||||
/// window.draw(...);
|
/// window.draw(...);
|
||||||
/// window.popGLStates();
|
/// window.popGLStates();
|
||||||
/// // OpenGL code here...
|
/// // OpenGL code here...
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Note that this function is quite expensive: it saves all the
|
/// Note that this function is quite expensive: it saves all the
|
||||||
/// possible OpenGL states and matrices, even the ones you
|
/// possible OpenGL states and matrices, even the ones you
|
||||||
/// don't care about. Therefore it should be used wisely.
|
/// don't care about. Therefore it should be used wisely.
|
||||||
/// It is provided for convenience, but the best results will
|
/// It is provided for convenience, but the best results will
|
||||||
/// be achieved if you handle OpenGL states yourself (because
|
/// be achieved if you handle OpenGL states yourself (because
|
||||||
/// you know which states have really changed, and need to be
|
/// you know which states have really changed, and need to be
|
||||||
/// saved and restored). Take a look at the ResetGLStates
|
/// saved and restored). Take a look at the ResetGLStates
|
||||||
/// function if you do so.
|
/// function if you do so.
|
||||||
///
|
///
|
||||||
/// \see popGLStates
|
/// \see popGLStates
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void pushGLStates();
|
void pushGLStates();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Restore the previously saved OpenGL render states and matrices
|
/// \brief Restore the previously saved OpenGL render states and matrices
|
||||||
///
|
///
|
||||||
/// See the description of pushGLStates to get a detailed
|
/// See the description of pushGLStates to get a detailed
|
||||||
/// description of these functions.
|
/// description of these functions.
|
||||||
///
|
///
|
||||||
/// \see pushGLStates
|
/// \see pushGLStates
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void popGLStates();
|
void popGLStates();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Reset the internal OpenGL states so that the target is ready for drawing
|
/// \brief Reset the internal OpenGL states so that the target is ready for drawing
|
||||||
///
|
///
|
||||||
/// This function can be used when you mix SFML drawing
|
/// This function can be used when you mix SFML drawing
|
||||||
/// and direct OpenGL rendering, if you choose not to use
|
/// and direct OpenGL rendering, if you choose not to use
|
||||||
/// pushGLStates/popGLStates. It makes sure that all OpenGL
|
/// pushGLStates/popGLStates. It makes sure that all OpenGL
|
||||||
/// states needed by SFML are set, so that subsequent draw()
|
/// states needed by SFML are set, so that subsequent draw()
|
||||||
/// calls will work as expected.
|
/// calls will work as expected.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // OpenGL code here...
|
/// // OpenGL code here...
|
||||||
/// glPushAttrib(...);
|
/// glPushAttrib(...);
|
||||||
/// window.resetGLStates();
|
/// window.resetGLStates();
|
||||||
/// window.draw(...);
|
/// window.draw(...);
|
||||||
/// window.draw(...);
|
/// window.draw(...);
|
||||||
/// glPopAttrib(...);
|
/// glPopAttrib(...);
|
||||||
/// // OpenGL code here...
|
/// // OpenGL code here...
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void resetGLStates();
|
void resetGLStates();
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
RenderTarget();
|
RenderTarget();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Performs the common initialization step after creation
|
/// \brief Performs the common initialization step after creation
|
||||||
///
|
///
|
||||||
/// The derived classes must call this function after the
|
/// The derived classes must call this function after the
|
||||||
/// target is created and ready for drawing.
|
/// target is created and ready for drawing.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Apply the current view
|
/// \brief Apply the current view
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void applyCurrentView();
|
void applyCurrentView();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Apply a new blending mode
|
/// \brief Apply a new blending mode
|
||||||
///
|
///
|
||||||
/// \param mode Blending mode to apply
|
/// \param mode Blending mode to apply
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void applyBlendMode(const BlendMode& mode);
|
void applyBlendMode(const BlendMode& mode);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Apply a new transform
|
/// \brief Apply a new transform
|
||||||
///
|
///
|
||||||
/// \param transform Transform to apply
|
/// \param transform Transform to apply
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void applyTransform(const Transform& transform);
|
void applyTransform(const Transform& transform);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Apply a new texture
|
/// \brief Apply a new texture
|
||||||
///
|
///
|
||||||
/// \param texture Texture to apply
|
/// \param texture Texture to apply
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void applyTexture(const Texture* texture);
|
void applyTexture(const Texture* texture);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Apply a new shader
|
/// \brief Apply a new shader
|
||||||
///
|
///
|
||||||
/// \param shader Shader to apply
|
/// \param shader Shader to apply
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void applyShader(const Shader* shader);
|
void applyShader(const Shader* shader);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Activate the target for rendering
|
/// \brief Activate the target for rendering
|
||||||
///
|
///
|
||||||
/// This function must be implemented by derived classes to make
|
/// This function must be implemented by derived classes to make
|
||||||
/// their OpenGL context current; it is called by the base class
|
/// their OpenGL context current; it is called by the base class
|
||||||
/// everytime it's going to use OpenGL calls.
|
/// everytime it's going to use OpenGL calls.
|
||||||
///
|
///
|
||||||
/// \param active True to make the target active, false to deactivate it
|
/// \param active True to make the target active, false to deactivate it
|
||||||
///
|
///
|
||||||
/// \return True if the function succeeded
|
/// \return True if the function succeeded
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool activate(bool active) = 0;
|
virtual bool activate(bool active) = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Render states cache
|
/// \brief Render states cache
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct StatesCache
|
struct StatesCache
|
||||||
{
|
{
|
||||||
enum {VertexCacheSize = 4};
|
enum {VertexCacheSize = 4};
|
||||||
|
|
||||||
bool glStatesSet; ///< Are our internal GL states set yet?
|
bool glStatesSet; ///< Are our internal GL states set yet?
|
||||||
bool viewChanged; ///< Has the current view changed since last draw?
|
bool viewChanged; ///< Has the current view changed since last draw?
|
||||||
BlendMode lastBlendMode; ///< Cached blending mode
|
BlendMode lastBlendMode; ///< Cached blending mode
|
||||||
Uint64 lastTextureId; ///< Cached texture
|
Uint64 lastTextureId; ///< Cached texture
|
||||||
bool useVertexCache; ///< Did we previously use the vertex cache?
|
bool useVertexCache; ///< Did we previously use the vertex cache?
|
||||||
Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache
|
Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
View m_defaultView; ///< Default view
|
View m_defaultView; ///< Default view
|
||||||
View m_view; ///< Current view
|
View m_view; ///< Current view
|
||||||
StatesCache m_cache; ///< Render states cache
|
StatesCache m_cache; ///< Render states cache
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RENDERTARGET_HPP
|
#endif // SFML_RENDERTARGET_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::RenderTarget
|
/// \class sf::RenderTarget
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::RenderTarget defines the common behaviour of all the
|
/// sf::RenderTarget defines the common behaviour of all the
|
||||||
/// 2D render targets usable in the graphics module. It makes
|
/// 2D render targets usable in the graphics module. It makes
|
||||||
/// it possible to draw 2D entities like sprites, shapes, text
|
/// it possible to draw 2D entities like sprites, shapes, text
|
||||||
/// without using any OpenGL command directly.
|
/// without using any OpenGL command directly.
|
||||||
///
|
///
|
||||||
/// A sf::RenderTarget is also able to use views (sf::View),
|
/// A sf::RenderTarget is also able to use views (sf::View),
|
||||||
/// which are a kind of 2D cameras. With views you can globally
|
/// which are a kind of 2D cameras. With views you can globally
|
||||||
/// scroll, rotate or zoom everything that is drawn,
|
/// scroll, rotate or zoom everything that is drawn,
|
||||||
/// without having to transform every single entity. See the
|
/// without having to transform every single entity. See the
|
||||||
/// documentation of sf::View for more details and sample pieces of
|
/// documentation of sf::View for more details and sample pieces of
|
||||||
/// code about this class.
|
/// code about this class.
|
||||||
///
|
///
|
||||||
/// On top of that, render targets are still able to render direct
|
/// On top of that, render targets are still able to render direct
|
||||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
||||||
/// and regular SFML drawing commands. When doing so, make sure that
|
/// and regular SFML drawing commands. When doing so, make sure that
|
||||||
/// OpenGL states are not messed up by calling the
|
/// OpenGL states are not messed up by calling the
|
||||||
/// pushGLStates/popGLStates functions.
|
/// pushGLStates/popGLStates functions.
|
||||||
///
|
///
|
||||||
/// \see sf::RenderWindow, sf::RenderTexture, sf::View
|
/// \see sf::RenderWindow, sf::RenderTexture, sf::View
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,280 +1,280 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_RENDERTEXTURE_HPP
|
#ifndef SFML_RENDERTEXTURE_HPP
|
||||||
#define SFML_RENDERTEXTURE_HPP
|
#define SFML_RENDERTEXTURE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
#include <SFML/Graphics/RenderTarget.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
class RenderTextureImpl;
|
class RenderTextureImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Target for off-screen 2D rendering into a texture
|
/// \brief Target for off-screen 2D rendering into a texture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API RenderTexture : public RenderTarget
|
class SFML_GRAPHICS_API RenderTexture : public RenderTarget
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Constructs an empty, invalid render-texture. You must
|
/// Constructs an empty, invalid render-texture. You must
|
||||||
/// call create to have a valid render-texture.
|
/// call create to have a valid render-texture.
|
||||||
///
|
///
|
||||||
/// \see create
|
/// \see create
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
RenderTexture();
|
RenderTexture();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~RenderTexture();
|
virtual ~RenderTexture();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create the render-texture
|
/// \brief Create the render-texture
|
||||||
///
|
///
|
||||||
/// Before calling this function, the render-texture is in
|
/// Before calling this function, the render-texture is in
|
||||||
/// an invalid state, thus it is mandatory to call it before
|
/// an invalid state, thus it is mandatory to call it before
|
||||||
/// doing anything with the render-texture.
|
/// doing anything with the render-texture.
|
||||||
/// The last parameter, \a depthBuffer, is useful if you want
|
/// The last parameter, \a depthBuffer, is useful if you want
|
||||||
/// to use the render-texture for 3D OpenGL rendering that requires
|
/// to use the render-texture for 3D OpenGL rendering that requires
|
||||||
/// a depth-buffer. Otherwise it is unnecessary, and you should
|
/// a depth-buffer. Otherwise it is unnecessary, and you should
|
||||||
/// leave this parameter to false (which is its default value).
|
/// leave this parameter to false (which is its default value).
|
||||||
///
|
///
|
||||||
/// \param width Width of the render-texture
|
/// \param width Width of the render-texture
|
||||||
/// \param height Height of the render-texture
|
/// \param height Height of the render-texture
|
||||||
/// \param depthBuffer Do you want this render-texture to have a depth buffer?
|
/// \param depthBuffer Do you want this render-texture to have a depth buffer?
|
||||||
///
|
///
|
||||||
/// \return True if creation has been successful
|
/// \return True if creation has been successful
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool create(unsigned int width, unsigned int height, bool depthBuffer = false);
|
bool create(unsigned int width, unsigned int height, bool depthBuffer = false);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Enable or disable texture smoothing
|
/// \brief Enable or disable texture smoothing
|
||||||
///
|
///
|
||||||
/// This function is similar to Texture::setSmooth.
|
/// This function is similar to Texture::setSmooth.
|
||||||
/// This parameter is disabled by default.
|
/// This parameter is disabled by default.
|
||||||
///
|
///
|
||||||
/// \param smooth True to enable smoothing, false to disable it
|
/// \param smooth True to enable smoothing, false to disable it
|
||||||
///
|
///
|
||||||
/// \see isSmooth
|
/// \see isSmooth
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setSmooth(bool smooth);
|
void setSmooth(bool smooth);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether the smooth filtering is enabled or not
|
/// \brief Tell whether the smooth filtering is enabled or not
|
||||||
///
|
///
|
||||||
/// \return True if texture smoothing is enabled
|
/// \return True if texture smoothing is enabled
|
||||||
///
|
///
|
||||||
/// \see setSmooth
|
/// \see setSmooth
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool isSmooth() const;
|
bool isSmooth() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Enable or disable texture repeating
|
/// \brief Enable or disable texture repeating
|
||||||
///
|
///
|
||||||
/// This function is similar to Texture::setRepeated.
|
/// This function is similar to Texture::setRepeated.
|
||||||
/// This parameter is disabled by default.
|
/// This parameter is disabled by default.
|
||||||
///
|
///
|
||||||
/// \param repeated True to enable repeating, false to disable it
|
/// \param repeated True to enable repeating, false to disable it
|
||||||
///
|
///
|
||||||
/// \see isRepeated
|
/// \see isRepeated
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setRepeated(bool repeated);
|
void setRepeated(bool repeated);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether the texture is repeated or not
|
/// \brief Tell whether the texture is repeated or not
|
||||||
///
|
///
|
||||||
/// \return True if texture is repeated
|
/// \return True if texture is repeated
|
||||||
///
|
///
|
||||||
/// \see setRepeated
|
/// \see setRepeated
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool isRepeated() const;
|
bool isRepeated() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Activate of deactivate the render-texture for rendering
|
/// \brief Activate of deactivate the render-texture for rendering
|
||||||
///
|
///
|
||||||
/// This function makes the render-texture's context current for
|
/// This function makes the render-texture's context current for
|
||||||
/// future OpenGL rendering operations (so you shouldn't care
|
/// future OpenGL rendering operations (so you shouldn't care
|
||||||
/// about it if you're not doing direct OpenGL stuff).
|
/// about it if you're not doing direct OpenGL stuff).
|
||||||
/// Only one context can be current in a thread, so if you
|
/// Only one context can be current in a thread, so if you
|
||||||
/// want to draw OpenGL geometry to another render target
|
/// want to draw OpenGL geometry to another render target
|
||||||
/// (like a RenderWindow) don't forget to activate it again.
|
/// (like a RenderWindow) don't forget to activate it again.
|
||||||
///
|
///
|
||||||
/// \param active True to activate, false to deactivate
|
/// \param active True to activate, false to deactivate
|
||||||
///
|
///
|
||||||
/// \return True if operation was successful, false otherwise
|
/// \return True if operation was successful, false otherwise
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool setActive(bool active = true);
|
bool setActive(bool active = true);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the contents of the target texture
|
/// \brief Update the contents of the target texture
|
||||||
///
|
///
|
||||||
/// This function updates the target texture with what
|
/// This function updates the target texture with what
|
||||||
/// has been drawn so far. Like for windows, calling this
|
/// has been drawn so far. Like for windows, calling this
|
||||||
/// function is mandatory at the end of rendering. Not calling
|
/// function is mandatory at the end of rendering. Not calling
|
||||||
/// it may leave the texture in an undefined state.
|
/// it may leave the texture in an undefined state.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void display();
|
void display();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Return the size of the rendering region of the texture
|
/// \brief Return the size of the rendering region of the texture
|
||||||
///
|
///
|
||||||
/// The returned value is the size that you passed to
|
/// The returned value is the size that you passed to
|
||||||
/// the create function.
|
/// the create function.
|
||||||
///
|
///
|
||||||
/// \return Size in pixels
|
/// \return Size in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual Vector2u getSize() const;
|
virtual Vector2u getSize() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get a read-only reference to the target texture
|
/// \brief Get a read-only reference to the target texture
|
||||||
///
|
///
|
||||||
/// After drawing to the render-texture and calling Display,
|
/// After drawing to the render-texture and calling Display,
|
||||||
/// you can retrieve the updated texture using this function,
|
/// you can retrieve the updated texture using this function,
|
||||||
/// and draw it using a sprite (for example).
|
/// and draw it using a sprite (for example).
|
||||||
/// The internal sf::Texture of a render-texture is always the
|
/// The internal sf::Texture of a render-texture is always the
|
||||||
/// same instance, so that it is possible to call this function
|
/// same instance, so that it is possible to call this function
|
||||||
/// once and keep a reference to the texture even after it is
|
/// once and keep a reference to the texture even after it is
|
||||||
/// modified.
|
/// modified.
|
||||||
///
|
///
|
||||||
/// \return Const reference to the texture
|
/// \return Const reference to the texture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Texture& getTexture() const;
|
const Texture& getTexture() const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Activate the target for rendering
|
/// \brief Activate the target for rendering
|
||||||
///
|
///
|
||||||
/// This function is called by the base class
|
/// This function is called by the base class
|
||||||
/// everytime it's going to use OpenGL calls.
|
/// everytime it's going to use OpenGL calls.
|
||||||
///
|
///
|
||||||
/// \param active True to make the target active, false to deactivate it
|
/// \param active True to make the target active, false to deactivate it
|
||||||
///
|
///
|
||||||
/// \return True if the function succeeded
|
/// \return True if the function succeeded
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool activate(bool active);
|
virtual bool activate(bool active);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation
|
priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation
|
||||||
Texture m_texture; ///< Target texture to draw on
|
Texture m_texture; ///< Target texture to draw on
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RENDERTEXTURE_HPP
|
#endif // SFML_RENDERTEXTURE_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::RenderTexture
|
/// \class sf::RenderTexture
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::RenderTexture is the little brother of sf::RenderWindow.
|
/// sf::RenderTexture is the little brother of sf::RenderWindow.
|
||||||
/// It implements the same 2D drawing and OpenGL-related functions
|
/// It implements the same 2D drawing and OpenGL-related functions
|
||||||
/// (see their base class sf::RenderTarget for more details),
|
/// (see their base class sf::RenderTarget for more details),
|
||||||
/// the difference is that the result is stored in an off-screen
|
/// the difference is that the result is stored in an off-screen
|
||||||
/// texture rather than being show in a window.
|
/// texture rather than being show in a window.
|
||||||
///
|
///
|
||||||
/// Rendering to a texture can be useful in a variety of situations:
|
/// Rendering to a texture can be useful in a variety of situations:
|
||||||
/// \li precomputing a complex static texture (like a level's background from multiple tiles)
|
/// \li precomputing a complex static texture (like a level's background from multiple tiles)
|
||||||
/// \li applying post-effects to the whole scene with shaders
|
/// \li applying post-effects to the whole scene with shaders
|
||||||
/// \li creating a sprite from a 3D object rendered with OpenGL
|
/// \li creating a sprite from a 3D object rendered with OpenGL
|
||||||
/// \li etc.
|
/// \li etc.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// // Create a new render-window
|
/// // Create a new render-window
|
||||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
||||||
///
|
///
|
||||||
/// // Create a new render-texture
|
/// // Create a new render-texture
|
||||||
/// sf::RenderTexture texture;
|
/// sf::RenderTexture texture;
|
||||||
/// if (!texture.create(500, 500))
|
/// if (!texture.create(500, 500))
|
||||||
/// return -1;
|
/// return -1;
|
||||||
///
|
///
|
||||||
/// // The main loop
|
/// // The main loop
|
||||||
/// while (window.isOpen())
|
/// while (window.isOpen())
|
||||||
/// {
|
/// {
|
||||||
/// // Event processing
|
/// // Event processing
|
||||||
/// // ...
|
/// // ...
|
||||||
///
|
///
|
||||||
/// // Clear the whole texture with red color
|
/// // Clear the whole texture with red color
|
||||||
/// texture.clear(sf::Color::Red);
|
/// texture.clear(sf::Color::Red);
|
||||||
///
|
///
|
||||||
/// // Draw stuff to the texture
|
/// // Draw stuff to the texture
|
||||||
/// texture.draw(sprite); // sprite is a sf::Sprite
|
/// texture.draw(sprite); // sprite is a sf::Sprite
|
||||||
/// texture.draw(shape); // shape is a sf::Shape
|
/// texture.draw(shape); // shape is a sf::Shape
|
||||||
/// texture.draw(text); // text is a sf::Text
|
/// texture.draw(text); // text is a sf::Text
|
||||||
///
|
///
|
||||||
/// // We're done drawing to the texture
|
/// // We're done drawing to the texture
|
||||||
/// texture.display();
|
/// texture.display();
|
||||||
///
|
///
|
||||||
/// // Now we start rendering to the window, clear it first
|
/// // Now we start rendering to the window, clear it first
|
||||||
/// window.clear();
|
/// window.clear();
|
||||||
///
|
///
|
||||||
/// // Draw the texture
|
/// // Draw the texture
|
||||||
/// sf::Sprite sprite(texture.getTexture());
|
/// sf::Sprite sprite(texture.getTexture());
|
||||||
/// window.draw(sprite);
|
/// window.draw(sprite);
|
||||||
///
|
///
|
||||||
/// // End the current frame and display its contents on screen
|
/// // End the current frame and display its contents on screen
|
||||||
/// window.display();
|
/// window.display();
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Like sf::RenderWindow, sf::RenderTexture is still able to render direct
|
/// Like sf::RenderWindow, sf::RenderTexture is still able to render direct
|
||||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
||||||
/// and regular SFML drawing commands. If you need a depth buffer for
|
/// and regular SFML drawing commands. If you need a depth buffer for
|
||||||
/// 3D rendering, don't forget to request it when calling RenderTexture::create.
|
/// 3D rendering, don't forget to request it when calling RenderTexture::create.
|
||||||
///
|
///
|
||||||
/// \see sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
|
/// \see sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,267 +1,267 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_RENDERWINDOW_HPP
|
#ifndef SFML_RENDERWINDOW_HPP
|
||||||
#define SFML_RENDERWINDOW_HPP
|
#define SFML_RENDERWINDOW_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
#include <SFML/Graphics/RenderTarget.hpp>
|
||||||
#include <SFML/Graphics/Image.hpp>
|
#include <SFML/Graphics/Image.hpp>
|
||||||
#include <SFML/Window/Window.hpp>
|
#include <SFML/Window/Window.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Window that can serve as a target for 2D drawing
|
/// \brief Window that can serve as a target for 2D drawing
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
|
class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor doesn't actually create the window,
|
/// This constructor doesn't actually create the window,
|
||||||
/// use the other constructors or call create() to do so.
|
/// use the other constructors or call create() to do so.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
RenderWindow();
|
RenderWindow();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct a new window
|
/// \brief Construct a new window
|
||||||
///
|
///
|
||||||
/// This constructor creates the window with the size and pixel
|
/// This constructor creates the window with the size and pixel
|
||||||
/// depth defined in \a mode. An optional style can be passed to
|
/// depth defined in \a mode. An optional style can be passed to
|
||||||
/// customize the look and behaviour of the window (borders,
|
/// customize the look and behaviour of the window (borders,
|
||||||
/// title bar, resizable, closable, ...).
|
/// title bar, resizable, closable, ...).
|
||||||
///
|
///
|
||||||
/// The fourth parameter is an optional structure specifying
|
/// The fourth parameter is an optional structure specifying
|
||||||
/// advanced OpenGL context settings such as antialiasing,
|
/// advanced OpenGL context settings such as antialiasing,
|
||||||
/// depth-buffer bits, etc. You shouldn't care about these
|
/// depth-buffer bits, etc. You shouldn't care about these
|
||||||
/// parameters for a regular usage of the graphics module.
|
/// parameters for a regular usage of the graphics module.
|
||||||
///
|
///
|
||||||
/// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
|
/// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
|
||||||
/// \param title Title of the window
|
/// \param title Title of the window
|
||||||
/// \param style %Window style, a bitwise OR combination of sf::Style enumerators
|
/// \param style %Window style, a bitwise OR combination of sf::Style enumerators
|
||||||
/// \param settings Additional settings for the underlying OpenGL context
|
/// \param settings Additional settings for the underlying OpenGL context
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
|
RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the window from an existing control
|
/// \brief Construct the window from an existing control
|
||||||
///
|
///
|
||||||
/// Use this constructor if you want to create an SFML
|
/// Use this constructor if you want to create an SFML
|
||||||
/// rendering area into an already existing control.
|
/// rendering area into an already existing control.
|
||||||
///
|
///
|
||||||
/// The second parameter is an optional structure specifying
|
/// The second parameter is an optional structure specifying
|
||||||
/// advanced OpenGL context settings such as antialiasing,
|
/// advanced OpenGL context settings such as antialiasing,
|
||||||
/// depth-buffer bits, etc. You shouldn't care about these
|
/// depth-buffer bits, etc. You shouldn't care about these
|
||||||
/// parameters for a regular usage of the graphics module.
|
/// parameters for a regular usage of the graphics module.
|
||||||
///
|
///
|
||||||
/// \param handle Platform-specific handle of the control (\a HWND on
|
/// \param handle Platform-specific handle of the control (\a HWND on
|
||||||
/// Windows, \a %Window on Linux/FreeBSD, \a NSWindow on OS X)
|
/// Windows, \a %Window on Linux/FreeBSD, \a NSWindow on OS X)
|
||||||
/// \param settings Additional settings for the underlying OpenGL context
|
/// \param settings Additional settings for the underlying OpenGL context
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings());
|
explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
/// Closes the window and frees all the resources attached to it.
|
/// Closes the window and frees all the resources attached to it.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~RenderWindow();
|
virtual ~RenderWindow();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the size of the rendering region of the window
|
/// \brief Get the size of the rendering region of the window
|
||||||
///
|
///
|
||||||
/// The size doesn't include the titlebar and borders
|
/// The size doesn't include the titlebar and borders
|
||||||
/// of the window.
|
/// of the window.
|
||||||
///
|
///
|
||||||
/// \return Size in pixels
|
/// \return Size in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual Vector2u getSize() const;
|
virtual Vector2u getSize() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy the current contents of the window to an image
|
/// \brief Copy the current contents of the window to an image
|
||||||
///
|
///
|
||||||
/// This is a slow operation, whose main purpose is to make
|
/// This is a slow operation, whose main purpose is to make
|
||||||
/// screenshots of the application. If you want to update an
|
/// screenshots of the application. If you want to update an
|
||||||
/// image with the contents of the window and then use it for
|
/// image with the contents of the window and then use it for
|
||||||
/// drawing, you should rather use a sf::Texture and its
|
/// drawing, you should rather use a sf::Texture and its
|
||||||
/// update(Window&) function.
|
/// update(Window&) function.
|
||||||
/// You can also draw things directly to a texture with the
|
/// You can also draw things directly to a texture with the
|
||||||
/// sf::RenderTexture class.
|
/// sf::RenderTexture class.
|
||||||
///
|
///
|
||||||
/// \return Image containing the captured contents
|
/// \return Image containing the captured contents
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Image capture() const;
|
Image capture() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Function called after the window has been created
|
/// \brief Function called after the window has been created
|
||||||
///
|
///
|
||||||
/// This function is called so that derived classes can
|
/// This function is called so that derived classes can
|
||||||
/// perform their own specific initialization as soon as
|
/// perform their own specific initialization as soon as
|
||||||
/// the window is created.
|
/// the window is created.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onCreate();
|
virtual void onCreate();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Function called after the window has been resized
|
/// \brief Function called after the window has been resized
|
||||||
///
|
///
|
||||||
/// This function is called so that derived classes can
|
/// This function is called so that derived classes can
|
||||||
/// perform custom actions when the size of the window changes.
|
/// perform custom actions when the size of the window changes.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onResize();
|
virtual void onResize();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Activate the target for rendering
|
/// \brief Activate the target for rendering
|
||||||
///
|
///
|
||||||
/// \param active True to make the target active, false to deactivate it
|
/// \param active True to make the target active, false to deactivate it
|
||||||
///
|
///
|
||||||
/// \return True if the function succeeded
|
/// \return True if the function succeeded
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual bool activate(bool active);
|
virtual bool activate(bool active);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_RENDERWINDOW_HPP
|
#endif // SFML_RENDERWINDOW_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::RenderWindow
|
/// \class sf::RenderWindow
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::RenderWindow is the main class of the Graphics module.
|
/// sf::RenderWindow is the main class of the Graphics module.
|
||||||
/// It defines an OS window that can be painted using the other
|
/// It defines an OS window that can be painted using the other
|
||||||
/// classes of the graphics module.
|
/// classes of the graphics module.
|
||||||
///
|
///
|
||||||
/// sf::RenderWindow is derived from sf::Window, thus it inherits
|
/// sf::RenderWindow is derived from sf::Window, thus it inherits
|
||||||
/// all its features: events, window management, OpenGL rendering,
|
/// all its features: events, window management, OpenGL rendering,
|
||||||
/// etc. See the documentation of sf::Window for a more complete
|
/// etc. See the documentation of sf::Window for a more complete
|
||||||
/// description of all these features, as well as code examples.
|
/// description of all these features, as well as code examples.
|
||||||
///
|
///
|
||||||
/// On top of that, sf::RenderWindow adds more features related to
|
/// On top of that, sf::RenderWindow adds more features related to
|
||||||
/// 2D drawing with the graphics module (see its base class
|
/// 2D drawing with the graphics module (see its base class
|
||||||
/// sf::RenderTarget for more details).
|
/// sf::RenderTarget for more details).
|
||||||
/// Here is a typical rendering and event loop with a sf::RenderWindow:
|
/// Here is a typical rendering and event loop with a sf::RenderWindow:
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// // Declare and create a new render-window
|
/// // Declare and create a new render-window
|
||||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
||||||
///
|
///
|
||||||
/// // Limit the framerate to 60 frames per second (this step is optional)
|
/// // Limit the framerate to 60 frames per second (this step is optional)
|
||||||
/// window.setFramerateLimit(60);
|
/// window.setFramerateLimit(60);
|
||||||
///
|
///
|
||||||
/// // The main loop - ends as soon as the window is closed
|
/// // The main loop - ends as soon as the window is closed
|
||||||
/// while (window.isOpen())
|
/// while (window.isOpen())
|
||||||
/// {
|
/// {
|
||||||
/// // Event processing
|
/// // Event processing
|
||||||
/// sf::Event event;
|
/// sf::Event event;
|
||||||
/// while (window.pollEvent(event))
|
/// while (window.pollEvent(event))
|
||||||
/// {
|
/// {
|
||||||
/// // Request for closing the window
|
/// // Request for closing the window
|
||||||
/// if (event.type == sf::Event::Closed)
|
/// if (event.type == sf::Event::Closed)
|
||||||
/// window.close();
|
/// window.close();
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Clear the whole window before rendering a new frame
|
/// // Clear the whole window before rendering a new frame
|
||||||
/// window.clear();
|
/// window.clear();
|
||||||
///
|
///
|
||||||
/// // Draw some graphical entities
|
/// // Draw some graphical entities
|
||||||
/// window.draw(sprite);
|
/// window.draw(sprite);
|
||||||
/// window.draw(circle);
|
/// window.draw(circle);
|
||||||
/// window.draw(text);
|
/// window.draw(text);
|
||||||
///
|
///
|
||||||
/// // End the current frame and display its contents on screen
|
/// // End the current frame and display its contents on screen
|
||||||
/// window.display();
|
/// window.display();
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Like sf::Window, sf::RenderWindow is still able to render direct
|
/// Like sf::Window, sf::RenderWindow is still able to render direct
|
||||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
||||||
/// and regular SFML drawing commands.
|
/// and regular SFML drawing commands.
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// // Create the render window
|
/// // Create the render window
|
||||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
|
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
|
||||||
///
|
///
|
||||||
/// // Create a sprite and a text to display
|
/// // Create a sprite and a text to display
|
||||||
/// sf::Sprite sprite;
|
/// sf::Sprite sprite;
|
||||||
/// sf::Text text;
|
/// sf::Text text;
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
/// // Perform OpenGL initializations
|
/// // Perform OpenGL initializations
|
||||||
/// glMatrixMode(GL_PROJECTION);
|
/// glMatrixMode(GL_PROJECTION);
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
/// // Start the rendering loop
|
/// // Start the rendering loop
|
||||||
/// while (window.isOpen())
|
/// while (window.isOpen())
|
||||||
/// {
|
/// {
|
||||||
/// // Process events
|
/// // Process events
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
/// // Draw a background sprite
|
/// // Draw a background sprite
|
||||||
/// window.pushGLStates();
|
/// window.pushGLStates();
|
||||||
/// window.draw(sprite);
|
/// window.draw(sprite);
|
||||||
/// window.popGLStates();
|
/// window.popGLStates();
|
||||||
///
|
///
|
||||||
/// // Draw a 3D object using OpenGL
|
/// // Draw a 3D object using OpenGL
|
||||||
/// glBegin(GL_QUADS);
|
/// glBegin(GL_QUADS);
|
||||||
/// glVertex3f(...);
|
/// glVertex3f(...);
|
||||||
/// ...
|
/// ...
|
||||||
/// glEnd();
|
/// glEnd();
|
||||||
///
|
///
|
||||||
/// // Draw text on top of the 3D object
|
/// // Draw text on top of the 3D object
|
||||||
/// window.pushGLStates();
|
/// window.pushGLStates();
|
||||||
/// window.draw(text);
|
/// window.draw(text);
|
||||||
/// window.popGLStates();
|
/// window.popGLStates();
|
||||||
///
|
///
|
||||||
/// // Finally, display the rendered frame on screen
|
/// // Finally, display the rendered frame on screen
|
||||||
/// window.display();
|
/// window.display();
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View
|
/// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,348 +1,348 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SHAPE_HPP
|
#ifndef SFML_SHAPE_HPP
|
||||||
#define SFML_SHAPE_HPP
|
#define SFML_SHAPE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
#include <SFML/Graphics/Drawable.hpp>
|
||||||
#include <SFML/Graphics/Transformable.hpp>
|
#include <SFML/Graphics/Transformable.hpp>
|
||||||
#include <SFML/Graphics/VertexArray.hpp>
|
#include <SFML/Graphics/VertexArray.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Base class for textured shapes with outline
|
/// \brief Base class for textured shapes with outline
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
|
class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Virtual destructor
|
/// \brief Virtual destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~Shape();
|
virtual ~Shape();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the source texture of the shape
|
/// \brief Change the source texture of the shape
|
||||||
///
|
///
|
||||||
/// The \a texture argument refers to a texture that must
|
/// The \a texture argument refers to a texture that must
|
||||||
/// exist as long as the shape uses it. Indeed, the shape
|
/// exist as long as the shape uses it. Indeed, the shape
|
||||||
/// doesn't store its own copy of the texture, but rather keeps
|
/// doesn't store its own copy of the texture, but rather keeps
|
||||||
/// a pointer to the one that you passed to this function.
|
/// a pointer to the one that you passed to this function.
|
||||||
/// If the source texture is destroyed and the shape tries to
|
/// If the source texture is destroyed and the shape tries to
|
||||||
/// use it, the behaviour is undefined.
|
/// use it, the behaviour is undefined.
|
||||||
/// \a texture can be NULL to disable texturing.
|
/// \a texture can be NULL to disable texturing.
|
||||||
/// If \a resetRect is true, the TextureRect property of
|
/// If \a resetRect is true, the TextureRect property of
|
||||||
/// the shape is automatically adjusted to the size of the new
|
/// the shape is automatically adjusted to the size of the new
|
||||||
/// texture. If it is false, the texture rect is left unchanged.
|
/// texture. If it is false, the texture rect is left unchanged.
|
||||||
///
|
///
|
||||||
/// \param texture New texture
|
/// \param texture New texture
|
||||||
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
||||||
///
|
///
|
||||||
/// \see getTexture, setTextureRect
|
/// \see getTexture, setTextureRect
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setTexture(const Texture* texture, bool resetRect = false);
|
void setTexture(const Texture* texture, bool resetRect = false);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the sub-rectangle of the texture that the shape will display
|
/// \brief Set the sub-rectangle of the texture that the shape will display
|
||||||
///
|
///
|
||||||
/// The texture rect is useful when you don't want to display
|
/// The texture rect is useful when you don't want to display
|
||||||
/// the whole texture, but rather a part of it.
|
/// the whole texture, but rather a part of it.
|
||||||
/// By default, the texture rect covers the entire texture.
|
/// By default, the texture rect covers the entire texture.
|
||||||
///
|
///
|
||||||
/// \param rect Rectangle defining the region of the texture to display
|
/// \param rect Rectangle defining the region of the texture to display
|
||||||
///
|
///
|
||||||
/// \see getTextureRect, setTexture
|
/// \see getTextureRect, setTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setTextureRect(const IntRect& rect);
|
void setTextureRect(const IntRect& rect);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the fill color of the shape
|
/// \brief Set the fill color of the shape
|
||||||
///
|
///
|
||||||
/// This color is modulated (multiplied) with the shape's
|
/// This color is modulated (multiplied) with the shape's
|
||||||
/// texture if any. It can be used to colorize the shape,
|
/// texture if any. It can be used to colorize the shape,
|
||||||
/// or change its global opacity.
|
/// or change its global opacity.
|
||||||
/// You can use sf::Color::Transparent to make the inside of
|
/// You can use sf::Color::Transparent to make the inside of
|
||||||
/// the shape transparent, and have the outline alone.
|
/// the shape transparent, and have the outline alone.
|
||||||
/// By default, the shape's fill color is opaque white.
|
/// By default, the shape's fill color is opaque white.
|
||||||
///
|
///
|
||||||
/// \param color New color of the shape
|
/// \param color New color of the shape
|
||||||
///
|
///
|
||||||
/// \see getFillColor, setOutlineColor
|
/// \see getFillColor, setOutlineColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setFillColor(const Color& color);
|
void setFillColor(const Color& color);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the outline color of the shape
|
/// \brief Set the outline color of the shape
|
||||||
///
|
///
|
||||||
/// By default, the shape's outline color is opaque white.
|
/// By default, the shape's outline color is opaque white.
|
||||||
///
|
///
|
||||||
/// \param color New outline color of the shape
|
/// \param color New outline color of the shape
|
||||||
///
|
///
|
||||||
/// \see getOutlineColor, setFillColor
|
/// \see getOutlineColor, setFillColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setOutlineColor(const Color& color);
|
void setOutlineColor(const Color& color);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the thickness of the shape's outline
|
/// \brief Set the thickness of the shape's outline
|
||||||
///
|
///
|
||||||
/// Note that negative values are allowed (so that the outline
|
/// Note that negative values are allowed (so that the outline
|
||||||
/// expands towards the center of the shape), and using zero
|
/// expands towards the center of the shape), and using zero
|
||||||
/// disables the outline.
|
/// disables the outline.
|
||||||
/// By default, the outline thickness is 0.
|
/// By default, the outline thickness is 0.
|
||||||
///
|
///
|
||||||
/// \param thickness New outline thickness
|
/// \param thickness New outline thickness
|
||||||
///
|
///
|
||||||
/// \see getOutlineThickness
|
/// \see getOutlineThickness
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setOutlineThickness(float thickness);
|
void setOutlineThickness(float thickness);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the source texture of the shape
|
/// \brief Get the source texture of the shape
|
||||||
///
|
///
|
||||||
/// If the shape has no source texture, a NULL pointer is returned.
|
/// If the shape has no source texture, a NULL pointer is returned.
|
||||||
/// The returned pointer is const, which means that you can't
|
/// The returned pointer is const, which means that you can't
|
||||||
/// modify the texture when you retrieve it with this function.
|
/// modify the texture when you retrieve it with this function.
|
||||||
///
|
///
|
||||||
/// \return Pointer to the shape's texture
|
/// \return Pointer to the shape's texture
|
||||||
///
|
///
|
||||||
/// \see setTexture
|
/// \see setTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Texture* getTexture() const;
|
const Texture* getTexture() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the sub-rectangle of the texture displayed by the shape
|
/// \brief Get the sub-rectangle of the texture displayed by the shape
|
||||||
///
|
///
|
||||||
/// \return Texture rectangle of the shape
|
/// \return Texture rectangle of the shape
|
||||||
///
|
///
|
||||||
/// \see setTextureRect
|
/// \see setTextureRect
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const IntRect& getTextureRect() const;
|
const IntRect& getTextureRect() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the fill color of the shape
|
/// \brief Get the fill color of the shape
|
||||||
///
|
///
|
||||||
/// \return Fill color of the shape
|
/// \return Fill color of the shape
|
||||||
///
|
///
|
||||||
/// \see setFillColor
|
/// \see setFillColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Color& getFillColor() const;
|
const Color& getFillColor() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the outline color of the shape
|
/// \brief Get the outline color of the shape
|
||||||
///
|
///
|
||||||
/// \return Outline color of the shape
|
/// \return Outline color of the shape
|
||||||
///
|
///
|
||||||
/// \see setOutlineColor
|
/// \see setOutlineColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Color& getOutlineColor() const;
|
const Color& getOutlineColor() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the outline thickness of the shape
|
/// \brief Get the outline thickness of the shape
|
||||||
///
|
///
|
||||||
/// \return Outline thickness of the shape
|
/// \return Outline thickness of the shape
|
||||||
///
|
///
|
||||||
/// \see setOutlineThickness
|
/// \see setOutlineThickness
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getOutlineThickness() const;
|
float getOutlineThickness() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the total number of points of the shape
|
/// \brief Get the total number of points of the shape
|
||||||
///
|
///
|
||||||
/// \return Number of points of the shape
|
/// \return Number of points of the shape
|
||||||
///
|
///
|
||||||
/// \see getPoint
|
/// \see getPoint
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual unsigned int getPointCount() const = 0;
|
virtual unsigned int getPointCount() const = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get a point of the shape
|
/// \brief Get a point of the shape
|
||||||
///
|
///
|
||||||
/// The returned point is in local coordinates, that is,
|
/// The returned point is in local coordinates, that is,
|
||||||
/// the shape's transforms (position, rotation, scale) are
|
/// the shape's transforms (position, rotation, scale) are
|
||||||
/// not taken into account.
|
/// not taken into account.
|
||||||
/// The result is undefined if \a index is out of the valid range.
|
/// The result is undefined if \a index is out of the valid range.
|
||||||
///
|
///
|
||||||
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
||||||
///
|
///
|
||||||
/// \return index-th point of the shape
|
/// \return index-th point of the shape
|
||||||
///
|
///
|
||||||
/// \see getPointCount
|
/// \see getPointCount
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual Vector2f getPoint(unsigned int index) const = 0;
|
virtual Vector2f getPoint(unsigned int index) const = 0;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the local bounding rectangle of the entity
|
/// \brief Get the local bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
/// The returned rectangle is in local coordinates, which means
|
/// The returned rectangle is in local coordinates, which means
|
||||||
/// that it ignores the transformations (translation, rotation,
|
/// that it ignores the transformations (translation, rotation,
|
||||||
/// scale, ...) that are applied to the entity.
|
/// scale, ...) that are applied to the entity.
|
||||||
/// In other words, this function returns the bounds of the
|
/// In other words, this function returns the bounds of the
|
||||||
/// entity in the entity's coordinate system.
|
/// entity in the entity's coordinate system.
|
||||||
///
|
///
|
||||||
/// \return Local bounding rectangle of the entity
|
/// \return Local bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FloatRect getLocalBounds() const;
|
FloatRect getLocalBounds() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the global bounding rectangle of the entity
|
/// \brief Get the global bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
/// The returned rectangle is in global coordinates, which means
|
/// The returned rectangle is in global coordinates, which means
|
||||||
/// that it takes in account the transformations (translation,
|
/// that it takes in account the transformations (translation,
|
||||||
/// rotation, scale, ...) that are applied to the entity.
|
/// rotation, scale, ...) that are applied to the entity.
|
||||||
/// In other words, this function returns the bounds of the
|
/// In other words, this function returns the bounds of the
|
||||||
/// sprite in the global 2D world's coordinate system.
|
/// sprite in the global 2D world's coordinate system.
|
||||||
///
|
///
|
||||||
/// \return Global bounding rectangle of the entity
|
/// \return Global bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FloatRect getGlobalBounds() const;
|
FloatRect getGlobalBounds() const;
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Shape();
|
Shape();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Recompute the internal geometry of the shape
|
/// \brief Recompute the internal geometry of the shape
|
||||||
///
|
///
|
||||||
/// This function must be called by the derived class everytime
|
/// This function must be called by the derived class everytime
|
||||||
/// the shape's points change (ie. the result of either
|
/// the shape's points change (ie. the result of either
|
||||||
/// getPointCount or getPoint is different).
|
/// getPointCount or getPoint is different).
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Draw the shape to a render target
|
/// \brief Draw the shape to a render target
|
||||||
///
|
///
|
||||||
/// \param target Render target to draw to
|
/// \param target Render target to draw to
|
||||||
/// \param states Current render states
|
/// \param states Current render states
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
virtual void draw(RenderTarget& target, RenderStates states) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the fill vertices' color
|
/// \brief Update the fill vertices' color
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void updateFillColors();
|
void updateFillColors();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the fill vertices' texture coordinates
|
/// \brief Update the fill vertices' texture coordinates
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void updateTexCoords();
|
void updateTexCoords();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the outline vertices' position
|
/// \brief Update the outline vertices' position
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void updateOutline();
|
void updateOutline();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the outline vertices' color
|
/// \brief Update the outline vertices' color
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void updateOutlineColors();
|
void updateOutlineColors();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Texture* m_texture; ///< Texture of the shape
|
const Texture* m_texture; ///< Texture of the shape
|
||||||
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
||||||
Color m_fillColor; ///< Fill color
|
Color m_fillColor; ///< Fill color
|
||||||
Color m_outlineColor; ///< Outline color
|
Color m_outlineColor; ///< Outline color
|
||||||
float m_outlineThickness; ///< Thickness of the shape's outline
|
float m_outlineThickness; ///< Thickness of the shape's outline
|
||||||
VertexArray m_vertices; ///< Vertex array containing the fill geometry
|
VertexArray m_vertices; ///< Vertex array containing the fill geometry
|
||||||
VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
|
VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
|
||||||
FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill)
|
FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill)
|
||||||
FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill)
|
FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SHAPE_HPP
|
#endif // SFML_SHAPE_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Shape
|
/// \class sf::Shape
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::Shape is a drawable class that allows to define and
|
/// sf::Shape is a drawable class that allows to define and
|
||||||
/// display a custom convex shape on a render target.
|
/// display a custom convex shape on a render target.
|
||||||
/// It's only an abstract base, it needs to be specialized for
|
/// It's only an abstract base, it needs to be specialized for
|
||||||
/// concrete types of shapes (circle, rectangle, convex polygon,
|
/// concrete types of shapes (circle, rectangle, convex polygon,
|
||||||
/// star, ...).
|
/// star, ...).
|
||||||
///
|
///
|
||||||
/// In addition to the attributes provided by the specialized
|
/// In addition to the attributes provided by the specialized
|
||||||
/// shape classes, a shape always has the following attributes:
|
/// shape classes, a shape always has the following attributes:
|
||||||
/// \li a texture
|
/// \li a texture
|
||||||
/// \li a texture rectangle
|
/// \li a texture rectangle
|
||||||
/// \li a fill color
|
/// \li a fill color
|
||||||
/// \li an outline color
|
/// \li an outline color
|
||||||
/// \li an outline thickness
|
/// \li an outline thickness
|
||||||
///
|
///
|
||||||
/// Each feature is optional, and can be disabled easily:
|
/// Each feature is optional, and can be disabled easily:
|
||||||
/// \li the texture can be null
|
/// \li the texture can be null
|
||||||
/// \li the fill/outline colors can be sf::Color::Transparent
|
/// \li the fill/outline colors can be sf::Color::Transparent
|
||||||
/// \li the outline thickness can be zero
|
/// \li the outline thickness can be zero
|
||||||
///
|
///
|
||||||
/// You can write your own derived shape class, there are only
|
/// You can write your own derived shape class, there are only
|
||||||
/// two virtual functions to override:
|
/// two virtual functions to override:
|
||||||
/// \li getPointCount must return the number of points of the shape
|
/// \li getPointCount must return the number of points of the shape
|
||||||
/// \li getPoint must return the points of the shape
|
/// \li getPoint must return the points of the shape
|
||||||
///
|
///
|
||||||
/// \see sf::RectangleShape, sf::CircleShape, sf::ConvexShape, sf::Transformable
|
/// \see sf::RectangleShape, sf::CircleShape, sf::ConvexShape, sf::Transformable
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,279 +1,279 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SPRITE_HPP
|
#ifndef SFML_SPRITE_HPP
|
||||||
#define SFML_SPRITE_HPP
|
#define SFML_SPRITE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
#include <SFML/Graphics/Drawable.hpp>
|
||||||
#include <SFML/Graphics/Transformable.hpp>
|
#include <SFML/Graphics/Transformable.hpp>
|
||||||
#include <SFML/Graphics/Vertex.hpp>
|
#include <SFML/Graphics/Vertex.hpp>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Drawable representation of a texture, with its
|
/// \brief Drawable representation of a texture, with its
|
||||||
/// own transformations, color, etc.
|
/// own transformations, color, etc.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
|
class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Creates an empty sprite with no source texture.
|
/// Creates an empty sprite with no source texture.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Sprite();
|
Sprite();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the sprite from a source texture
|
/// \brief Construct the sprite from a source texture
|
||||||
///
|
///
|
||||||
/// \param texture Source texture
|
/// \param texture Source texture
|
||||||
///
|
///
|
||||||
/// \see setTexture
|
/// \see setTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
explicit Sprite(const Texture& texture);
|
explicit Sprite(const Texture& texture);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the sprite from a sub-rectangle of a source texture
|
/// \brief Construct the sprite from a sub-rectangle of a source texture
|
||||||
///
|
///
|
||||||
/// \param texture Source texture
|
/// \param texture Source texture
|
||||||
/// \param rectangle Sub-rectangle of the texture to assign to the sprite
|
/// \param rectangle Sub-rectangle of the texture to assign to the sprite
|
||||||
///
|
///
|
||||||
/// \see setTexture, setTextureRect
|
/// \see setTexture, setTextureRect
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Sprite(const Texture& texture, const IntRect& rectangle);
|
Sprite(const Texture& texture, const IntRect& rectangle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Change the source texture of the sprite
|
/// \brief Change the source texture of the sprite
|
||||||
///
|
///
|
||||||
/// The \a texture argument refers to a texture that must
|
/// The \a texture argument refers to a texture that must
|
||||||
/// exist as long as the sprite uses it. Indeed, the sprite
|
/// exist as long as the sprite uses it. Indeed, the sprite
|
||||||
/// doesn't store its own copy of the texture, but rather keeps
|
/// doesn't store its own copy of the texture, but rather keeps
|
||||||
/// a pointer to the one that you passed to this function.
|
/// a pointer to the one that you passed to this function.
|
||||||
/// If the source texture is destroyed and the sprite tries to
|
/// If the source texture is destroyed and the sprite tries to
|
||||||
/// use it, the behaviour is undefined.
|
/// use it, the behaviour is undefined.
|
||||||
/// If \a resetRect is true, the TextureRect property of
|
/// If \a resetRect is true, the TextureRect property of
|
||||||
/// the sprite is automatically adjusted to the size of the new
|
/// the sprite is automatically adjusted to the size of the new
|
||||||
/// texture. If it is false, the texture rect is left unchanged.
|
/// texture. If it is false, the texture rect is left unchanged.
|
||||||
///
|
///
|
||||||
/// \param texture New texture
|
/// \param texture New texture
|
||||||
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
||||||
///
|
///
|
||||||
/// \see getTexture, setTextureRect
|
/// \see getTexture, setTextureRect
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setTexture(const Texture& texture, bool resetRect = false);
|
void setTexture(const Texture& texture, bool resetRect = false);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the sub-rectangle of the texture that the sprite will display
|
/// \brief Set the sub-rectangle of the texture that the sprite will display
|
||||||
///
|
///
|
||||||
/// The texture rect is useful when you don't want to display
|
/// The texture rect is useful when you don't want to display
|
||||||
/// the whole texture, but rather a part of it.
|
/// the whole texture, but rather a part of it.
|
||||||
/// By default, the texture rect covers the entire texture.
|
/// By default, the texture rect covers the entire texture.
|
||||||
///
|
///
|
||||||
/// \param rectangle Rectangle defining the region of the texture to display
|
/// \param rectangle Rectangle defining the region of the texture to display
|
||||||
///
|
///
|
||||||
/// \see getTextureRect, setTexture
|
/// \see getTextureRect, setTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setTextureRect(const IntRect& rectangle);
|
void setTextureRect(const IntRect& rectangle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the global color of the sprite
|
/// \brief Set the global color of the sprite
|
||||||
///
|
///
|
||||||
/// This color is modulated (multiplied) with the sprite's
|
/// This color is modulated (multiplied) with the sprite's
|
||||||
/// texture. It can be used to colorize the sprite, or change
|
/// texture. It can be used to colorize the sprite, or change
|
||||||
/// its global opacity.
|
/// its global opacity.
|
||||||
/// By default, the sprite's color is opaque white.
|
/// By default, the sprite's color is opaque white.
|
||||||
///
|
///
|
||||||
/// \param color New color of the sprite
|
/// \param color New color of the sprite
|
||||||
///
|
///
|
||||||
/// \see getColor
|
/// \see getColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setColor(const Color& color);
|
void setColor(const Color& color);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the source texture of the sprite
|
/// \brief Get the source texture of the sprite
|
||||||
///
|
///
|
||||||
/// If the sprite has no source texture, a NULL pointer is returned.
|
/// If the sprite has no source texture, a NULL pointer is returned.
|
||||||
/// The returned pointer is const, which means that you can't
|
/// The returned pointer is const, which means that you can't
|
||||||
/// modify the texture when you retrieve it with this function.
|
/// modify the texture when you retrieve it with this function.
|
||||||
///
|
///
|
||||||
/// \return Pointer to the sprite's texture
|
/// \return Pointer to the sprite's texture
|
||||||
///
|
///
|
||||||
/// \see setTexture
|
/// \see setTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Texture* getTexture() const;
|
const Texture* getTexture() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the sub-rectangle of the texture displayed by the sprite
|
/// \brief Get the sub-rectangle of the texture displayed by the sprite
|
||||||
///
|
///
|
||||||
/// \return Texture rectangle of the sprite
|
/// \return Texture rectangle of the sprite
|
||||||
///
|
///
|
||||||
/// \see setTextureRect
|
/// \see setTextureRect
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const IntRect& getTextureRect() const;
|
const IntRect& getTextureRect() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the global color of the sprite
|
/// \brief Get the global color of the sprite
|
||||||
///
|
///
|
||||||
/// \return Global color of the sprite
|
/// \return Global color of the sprite
|
||||||
///
|
///
|
||||||
/// \see setColor
|
/// \see setColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Color& getColor() const;
|
const Color& getColor() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the local bounding rectangle of the entity
|
/// \brief Get the local bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
/// The returned rectangle is in local coordinates, which means
|
/// The returned rectangle is in local coordinates, which means
|
||||||
/// that it ignores the transformations (translation, rotation,
|
/// that it ignores the transformations (translation, rotation,
|
||||||
/// scale, ...) that are applied to the entity.
|
/// scale, ...) that are applied to the entity.
|
||||||
/// In other words, this function returns the bounds of the
|
/// In other words, this function returns the bounds of the
|
||||||
/// entity in the entity's coordinate system.
|
/// entity in the entity's coordinate system.
|
||||||
///
|
///
|
||||||
/// \return Local bounding rectangle of the entity
|
/// \return Local bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FloatRect getLocalBounds() const;
|
FloatRect getLocalBounds() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the global bounding rectangle of the entity
|
/// \brief Get the global bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
/// The returned rectangle is in global coordinates, which means
|
/// The returned rectangle is in global coordinates, which means
|
||||||
/// that it takes in account the transformations (translation,
|
/// that it takes in account the transformations (translation,
|
||||||
/// rotation, scale, ...) that are applied to the entity.
|
/// rotation, scale, ...) that are applied to the entity.
|
||||||
/// In other words, this function returns the bounds of the
|
/// In other words, this function returns the bounds of the
|
||||||
/// sprite in the global 2D world's coordinate system.
|
/// sprite in the global 2D world's coordinate system.
|
||||||
///
|
///
|
||||||
/// \return Global bounding rectangle of the entity
|
/// \return Global bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FloatRect getGlobalBounds() const;
|
FloatRect getGlobalBounds() const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Draw the sprite to a render target
|
/// \brief Draw the sprite to a render target
|
||||||
///
|
///
|
||||||
/// \param target Render target to draw to
|
/// \param target Render target to draw to
|
||||||
/// \param states Current render states
|
/// \param states Current render states
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
virtual void draw(RenderTarget& target, RenderStates states) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the vertices' positions
|
/// \brief Update the vertices' positions
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void updatePositions();
|
void updatePositions();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Update the vertices' texture coordinates
|
/// \brief Update the vertices' texture coordinates
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void updateTexCoords();
|
void updateTexCoords();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry
|
Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry
|
||||||
const Texture* m_texture; ///< Texture of the sprite
|
const Texture* m_texture; ///< Texture of the sprite
|
||||||
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SPRITE_HPP
|
#endif // SFML_SPRITE_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Sprite
|
/// \class sf::Sprite
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::Sprite is a drawable class that allows to easily display
|
/// sf::Sprite is a drawable class that allows to easily display
|
||||||
/// a texture (or a part of it) on a render target.
|
/// a texture (or a part of it) on a render target.
|
||||||
///
|
///
|
||||||
/// It inherits all the functions from sf::Transformable:
|
/// It inherits all the functions from sf::Transformable:
|
||||||
/// position, rotation, scale, origin. It also adds sprite-specific
|
/// position, rotation, scale, origin. It also adds sprite-specific
|
||||||
/// properties such as the texture to use, the part of it to display,
|
/// properties such as the texture to use, the part of it to display,
|
||||||
/// and some convenience functions to change the overall color of the
|
/// and some convenience functions to change the overall color of the
|
||||||
/// sprite, or to get its bounding rectangle.
|
/// sprite, or to get its bounding rectangle.
|
||||||
///
|
///
|
||||||
/// sf::Sprite works in combination with the sf::Texture class, which
|
/// sf::Sprite works in combination with the sf::Texture class, which
|
||||||
/// loads and provides the pixel data of a given texture.
|
/// loads and provides the pixel data of a given texture.
|
||||||
///
|
///
|
||||||
/// The separation of sf::Sprite and sf::Texture allows more flexibility
|
/// The separation of sf::Sprite and sf::Texture allows more flexibility
|
||||||
/// and better performances: indeed a sf::Texture is a heavy resource,
|
/// and better performances: indeed a sf::Texture is a heavy resource,
|
||||||
/// and any operation on it is slow (often too slow for real-time
|
/// and any operation on it is slow (often too slow for real-time
|
||||||
/// applications). On the other side, a sf::Sprite is a lightweight
|
/// applications). On the other side, a sf::Sprite is a lightweight
|
||||||
/// object which can use the pixel data of a sf::Texture and draw
|
/// object which can use the pixel data of a sf::Texture and draw
|
||||||
/// it with its own transformation/color/blending attributes.
|
/// it with its own transformation/color/blending attributes.
|
||||||
///
|
///
|
||||||
/// It is important to note that the sf::Sprite instance doesn't
|
/// It is important to note that the sf::Sprite instance doesn't
|
||||||
/// copy the texture that it uses, it only keeps a reference to it.
|
/// copy the texture that it uses, it only keeps a reference to it.
|
||||||
/// Thus, a sf::Texture must not be destroyed while it is
|
/// Thus, a sf::Texture must not be destroyed while it is
|
||||||
/// used by a sf::Sprite (i.e. never write a function that
|
/// used by a sf::Sprite (i.e. never write a function that
|
||||||
/// uses a local sf::Texture instance for creating a sprite).
|
/// uses a local sf::Texture instance for creating a sprite).
|
||||||
///
|
///
|
||||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Declare and load a texture
|
/// // Declare and load a texture
|
||||||
/// sf::Texture texture;
|
/// sf::Texture texture;
|
||||||
/// texture.loadFromFile("texture.png");
|
/// texture.loadFromFile("texture.png");
|
||||||
///
|
///
|
||||||
/// // Create a sprite
|
/// // Create a sprite
|
||||||
/// sf::Sprite sprite;
|
/// sf::Sprite sprite;
|
||||||
/// sprite.setTexture(texture);
|
/// sprite.setTexture(texture);
|
||||||
/// sprite.setTextureRect(sf::IntRect(10, 10, 50, 30));
|
/// sprite.setTextureRect(sf::IntRect(10, 10, 50, 30));
|
||||||
/// sprite.setColor(sf::Color(255, 255, 255, 200));
|
/// sprite.setColor(sf::Color(255, 255, 255, 200));
|
||||||
/// sprite.setPosition(100, 25);
|
/// sprite.setPosition(100, 25);
|
||||||
///
|
///
|
||||||
/// // Draw it
|
/// // Draw it
|
||||||
/// window.draw(sprite);
|
/// window.draw(sprite);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Texture, sf::Transformable
|
/// \see sf::Texture, sf::Transformable
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,372 +1,372 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_TEXT_HPP
|
#ifndef SFML_TEXT_HPP
|
||||||
#define SFML_TEXT_HPP
|
#define SFML_TEXT_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
#include <SFML/Graphics/Drawable.hpp>
|
||||||
#include <SFML/Graphics/Transformable.hpp>
|
#include <SFML/Graphics/Transformable.hpp>
|
||||||
#include <SFML/Graphics/Font.hpp>
|
#include <SFML/Graphics/Font.hpp>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
#include <SFML/Graphics/VertexArray.hpp>
|
#include <SFML/Graphics/VertexArray.hpp>
|
||||||
#include <SFML/System/String.hpp>
|
#include <SFML/System/String.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Graphical text that can be drawn to a render target
|
/// \brief Graphical text that can be drawn to a render target
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Text : public Drawable, public Transformable
|
class SFML_GRAPHICS_API Text : public Drawable, public Transformable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Enumeration of the string drawing styles
|
/// \brief Enumeration of the string drawing styles
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum Style
|
enum Style
|
||||||
{
|
{
|
||||||
Regular = 0, ///< Regular characters, no style
|
Regular = 0, ///< Regular characters, no style
|
||||||
Bold = 1 << 0, ///< Bold characters
|
Bold = 1 << 0, ///< Bold characters
|
||||||
Italic = 1 << 1, ///< Italic characters
|
Italic = 1 << 1, ///< Italic characters
|
||||||
Underlined = 1 << 2, ///< Underlined characters
|
Underlined = 1 << 2, ///< Underlined characters
|
||||||
StrikeThrough = 1 << 3 ///< Strike through characters
|
StrikeThrough = 1 << 3 ///< Strike through characters
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Creates an empty text.
|
/// Creates an empty text.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Text();
|
Text();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the text from a string, font and size
|
/// \brief Construct the text from a string, font and size
|
||||||
///
|
///
|
||||||
/// Note that if the used font is a bitmap font, it is not
|
/// Note that if the used font is a bitmap font, it is not
|
||||||
/// scalable, thus not all requested sizes will be available
|
/// scalable, thus not all requested sizes will be available
|
||||||
/// to use. This needs to be taken into consideration when
|
/// to use. This needs to be taken into consideration when
|
||||||
/// setting the character size. If you need to display text
|
/// setting the character size. If you need to display text
|
||||||
/// of a certain size, make sure the corresponding bitmap
|
/// of a certain size, make sure the corresponding bitmap
|
||||||
/// font that supports that size is used.
|
/// font that supports that size is used.
|
||||||
///
|
///
|
||||||
/// \param string Text assigned to the string
|
/// \param string Text assigned to the string
|
||||||
/// \param font Font used to draw the string
|
/// \param font Font used to draw the string
|
||||||
/// \param characterSize Base size of characters, in pixels
|
/// \param characterSize Base size of characters, in pixels
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Text(const String& string, const Font& font, unsigned int characterSize = 30);
|
Text(const String& string, const Font& font, unsigned int characterSize = 30);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the text's string
|
/// \brief Set the text's string
|
||||||
///
|
///
|
||||||
/// The \a string argument is a sf::String, which can
|
/// The \a string argument is a sf::String, which can
|
||||||
/// automatically be constructed from standard string types.
|
/// automatically be constructed from standard string types.
|
||||||
/// So, the following calls are all valid:
|
/// So, the following calls are all valid:
|
||||||
/// \code
|
/// \code
|
||||||
/// text.setString("hello");
|
/// text.setString("hello");
|
||||||
/// text.setString(L"hello");
|
/// text.setString(L"hello");
|
||||||
/// text.setString(std::string("hello"));
|
/// text.setString(std::string("hello"));
|
||||||
/// text.setString(std::wstring(L"hello"));
|
/// text.setString(std::wstring(L"hello"));
|
||||||
/// \endcode
|
/// \endcode
|
||||||
/// A text's string is empty by default.
|
/// A text's string is empty by default.
|
||||||
///
|
///
|
||||||
/// \param string New string
|
/// \param string New string
|
||||||
///
|
///
|
||||||
/// \see getString
|
/// \see getString
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setString(const String& string);
|
void setString(const String& string);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the text's font
|
/// \brief Set the text's font
|
||||||
///
|
///
|
||||||
/// The \a font argument refers to a font that must
|
/// The \a font argument refers to a font that must
|
||||||
/// exist as long as the text uses it. Indeed, the text
|
/// exist as long as the text uses it. Indeed, the text
|
||||||
/// doesn't store its own copy of the font, but rather keeps
|
/// doesn't store its own copy of the font, but rather keeps
|
||||||
/// a pointer to the one that you passed to this function.
|
/// a pointer to the one that you passed to this function.
|
||||||
/// If the font is destroyed and the text tries to
|
/// If the font is destroyed and the text tries to
|
||||||
/// use it, the behaviour is undefined.
|
/// use it, the behaviour is undefined.
|
||||||
///
|
///
|
||||||
/// \param font New font
|
/// \param font New font
|
||||||
///
|
///
|
||||||
/// \see getFont
|
/// \see getFont
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setFont(const Font& font);
|
void setFont(const Font& font);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the character size
|
/// \brief Set the character size
|
||||||
///
|
///
|
||||||
/// The default size is 30.
|
/// The default size is 30.
|
||||||
///
|
///
|
||||||
/// Note that if the used font is a bitmap font, it is not
|
/// Note that if the used font is a bitmap font, it is not
|
||||||
/// scalable, thus not all requested sizes will be available
|
/// scalable, thus not all requested sizes will be available
|
||||||
/// to use. This needs to be taken into consideration when
|
/// to use. This needs to be taken into consideration when
|
||||||
/// setting the character size. If you need to display text
|
/// setting the character size. If you need to display text
|
||||||
/// of a certain size, make sure the corresponding bitmap
|
/// of a certain size, make sure the corresponding bitmap
|
||||||
/// font that supports that size is used.
|
/// font that supports that size is used.
|
||||||
///
|
///
|
||||||
/// \param size New character size, in pixels
|
/// \param size New character size, in pixels
|
||||||
///
|
///
|
||||||
/// \see getCharacterSize
|
/// \see getCharacterSize
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setCharacterSize(unsigned int size);
|
void setCharacterSize(unsigned int size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the text's style
|
/// \brief Set the text's style
|
||||||
///
|
///
|
||||||
/// You can pass a combination of one or more styles, for
|
/// You can pass a combination of one or more styles, for
|
||||||
/// example sf::Text::Bold | sf::Text::Italic.
|
/// example sf::Text::Bold | sf::Text::Italic.
|
||||||
/// The default style is sf::Text::Regular.
|
/// The default style is sf::Text::Regular.
|
||||||
///
|
///
|
||||||
/// \param style New style
|
/// \param style New style
|
||||||
///
|
///
|
||||||
/// \see getStyle
|
/// \see getStyle
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setStyle(Uint32 style);
|
void setStyle(Uint32 style);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the global color of the text
|
/// \brief Set the global color of the text
|
||||||
///
|
///
|
||||||
/// By default, the text's color is opaque white.
|
/// By default, the text's color is opaque white.
|
||||||
///
|
///
|
||||||
/// \param color New color of the text
|
/// \param color New color of the text
|
||||||
///
|
///
|
||||||
/// \see getColor
|
/// \see getColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setColor(const Color& color);
|
void setColor(const Color& color);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the text's string
|
/// \brief Get the text's string
|
||||||
///
|
///
|
||||||
/// The returned string is a sf::String, which can automatically
|
/// The returned string is a sf::String, which can automatically
|
||||||
/// be converted to standard string types. So, the following
|
/// be converted to standard string types. So, the following
|
||||||
/// lines of code are all valid:
|
/// lines of code are all valid:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::String s1 = text.getString();
|
/// sf::String s1 = text.getString();
|
||||||
/// std::string s2 = text.getString();
|
/// std::string s2 = text.getString();
|
||||||
/// std::wstring s3 = text.getString();
|
/// std::wstring s3 = text.getString();
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \return Text's string
|
/// \return Text's string
|
||||||
///
|
///
|
||||||
/// \see setString
|
/// \see setString
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const String& getString() const;
|
const String& getString() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the text's font
|
/// \brief Get the text's font
|
||||||
///
|
///
|
||||||
/// If the text has no font attached, a NULL pointer is returned.
|
/// If the text has no font attached, a NULL pointer is returned.
|
||||||
/// The returned reference is const, which means that you
|
/// The returned reference is const, which means that you
|
||||||
/// cannot modify the font when you get it from this function.
|
/// cannot modify the font when you get it from this function.
|
||||||
///
|
///
|
||||||
/// \return Pointer to the text's font
|
/// \return Pointer to the text's font
|
||||||
///
|
///
|
||||||
/// \see setFont
|
/// \see setFont
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Font* getFont() const;
|
const Font* getFont() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the character size
|
/// \brief Get the character size
|
||||||
///
|
///
|
||||||
/// \return Size of the characters, in pixels
|
/// \return Size of the characters, in pixels
|
||||||
///
|
///
|
||||||
/// \see setCharacterSize
|
/// \see setCharacterSize
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getCharacterSize() const;
|
unsigned int getCharacterSize() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the text's style
|
/// \brief Get the text's style
|
||||||
///
|
///
|
||||||
/// \return Text's style
|
/// \return Text's style
|
||||||
///
|
///
|
||||||
/// \see setStyle
|
/// \see setStyle
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Uint32 getStyle() const;
|
Uint32 getStyle() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the global color of the text
|
/// \brief Get the global color of the text
|
||||||
///
|
///
|
||||||
/// \return Global color of the text
|
/// \return Global color of the text
|
||||||
///
|
///
|
||||||
/// \see setColor
|
/// \see setColor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Color& getColor() const;
|
const Color& getColor() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Return the position of the \a index-th character
|
/// \brief Return the position of the \a index-th character
|
||||||
///
|
///
|
||||||
/// This function computes the visual position of a character
|
/// This function computes the visual position of a character
|
||||||
/// from its index in the string. The returned position is
|
/// from its index in the string. The returned position is
|
||||||
/// in global coordinates (translation, rotation, scale and
|
/// in global coordinates (translation, rotation, scale and
|
||||||
/// origin are applied).
|
/// origin are applied).
|
||||||
/// If \a index is out of range, the position of the end of
|
/// If \a index is out of range, the position of the end of
|
||||||
/// the string is returned.
|
/// the string is returned.
|
||||||
///
|
///
|
||||||
/// \param index Index of the character
|
/// \param index Index of the character
|
||||||
///
|
///
|
||||||
/// \return Position of the character
|
/// \return Position of the character
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2f findCharacterPos(std::size_t index) const;
|
Vector2f findCharacterPos(std::size_t index) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the local bounding rectangle of the entity
|
/// \brief Get the local bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
/// The returned rectangle is in local coordinates, which means
|
/// The returned rectangle is in local coordinates, which means
|
||||||
/// that it ignores the transformations (translation, rotation,
|
/// that it ignores the transformations (translation, rotation,
|
||||||
/// scale, ...) that are applied to the entity.
|
/// scale, ...) that are applied to the entity.
|
||||||
/// In other words, this function returns the bounds of the
|
/// In other words, this function returns the bounds of the
|
||||||
/// entity in the entity's coordinate system.
|
/// entity in the entity's coordinate system.
|
||||||
///
|
///
|
||||||
/// \return Local bounding rectangle of the entity
|
/// \return Local bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FloatRect getLocalBounds() const;
|
FloatRect getLocalBounds() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the global bounding rectangle of the entity
|
/// \brief Get the global bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
/// The returned rectangle is in global coordinates, which means
|
/// The returned rectangle is in global coordinates, which means
|
||||||
/// that it takes in account the transformations (translation,
|
/// that it takes in account the transformations (translation,
|
||||||
/// rotation, scale, ...) that are applied to the entity.
|
/// rotation, scale, ...) that are applied to the entity.
|
||||||
/// In other words, this function returns the bounds of the
|
/// In other words, this function returns the bounds of the
|
||||||
/// sprite in the global 2D world's coordinate system.
|
/// sprite in the global 2D world's coordinate system.
|
||||||
///
|
///
|
||||||
/// \return Global bounding rectangle of the entity
|
/// \return Global bounding rectangle of the entity
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FloatRect getGlobalBounds() const;
|
FloatRect getGlobalBounds() const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Draw the text to a render target
|
/// \brief Draw the text to a render target
|
||||||
///
|
///
|
||||||
/// \param target Render target to draw to
|
/// \param target Render target to draw to
|
||||||
/// \param states Current render states
|
/// \param states Current render states
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
virtual void draw(RenderTarget& target, RenderStates states) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Make sure the text's geometry is updated
|
/// \brief Make sure the text's geometry is updated
|
||||||
///
|
///
|
||||||
/// All the attributes related to rendering are cached, such
|
/// All the attributes related to rendering are cached, such
|
||||||
/// that the geometry is only updated when necessary.
|
/// that the geometry is only updated when necessary.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void ensureGeometryUpdate() const;
|
void ensureGeometryUpdate() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
String m_string; ///< String to display
|
String m_string; ///< String to display
|
||||||
const Font* m_font; ///< Font used to display the string
|
const Font* m_font; ///< Font used to display the string
|
||||||
unsigned int m_characterSize; ///< Base size of characters, in pixels
|
unsigned int m_characterSize; ///< Base size of characters, in pixels
|
||||||
Uint32 m_style; ///< Text style (see Style enum)
|
Uint32 m_style; ///< Text style (see Style enum)
|
||||||
Color m_color; ///< Text color
|
Color m_color; ///< Text color
|
||||||
mutable VertexArray m_vertices; ///< Vertex array containing the text's geometry
|
mutable VertexArray m_vertices; ///< Vertex array containing the text's geometry
|
||||||
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
|
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
|
||||||
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
|
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TEXT_HPP
|
#endif // SFML_TEXT_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Text
|
/// \class sf::Text
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::Text is a drawable class that allows to easily display
|
/// sf::Text is a drawable class that allows to easily display
|
||||||
/// some text with custom style and color on a render target.
|
/// some text with custom style and color on a render target.
|
||||||
///
|
///
|
||||||
/// It inherits all the functions from sf::Transformable:
|
/// It inherits all the functions from sf::Transformable:
|
||||||
/// position, rotation, scale, origin. It also adds text-specific
|
/// position, rotation, scale, origin. It also adds text-specific
|
||||||
/// properties such as the font to use, the character size,
|
/// properties such as the font to use, the character size,
|
||||||
/// the font style (bold, italic, underlined, strike through), the
|
/// the font style (bold, italic, underlined, strike through), the
|
||||||
/// global color and the text to display of course.
|
/// global color and the text to display of course.
|
||||||
/// It also provides convenience functions to calculate the
|
/// It also provides convenience functions to calculate the
|
||||||
/// graphical size of the text, or to get the global position
|
/// graphical size of the text, or to get the global position
|
||||||
/// of a given character.
|
/// of a given character.
|
||||||
///
|
///
|
||||||
/// sf::Text works in combination with the sf::Font class, which
|
/// sf::Text works in combination with the sf::Font class, which
|
||||||
/// loads and provides the glyphs (visual characters) of a given font.
|
/// loads and provides the glyphs (visual characters) of a given font.
|
||||||
///
|
///
|
||||||
/// The separation of sf::Font and sf::Text allows more flexibility
|
/// The separation of sf::Font and sf::Text allows more flexibility
|
||||||
/// and better performances: indeed a sf::Font is a heavy resource,
|
/// and better performances: indeed a sf::Font is a heavy resource,
|
||||||
/// and any operation on it is slow (often too slow for real-time
|
/// and any operation on it is slow (often too slow for real-time
|
||||||
/// applications). On the other side, a sf::Text is a lightweight
|
/// applications). On the other side, a sf::Text is a lightweight
|
||||||
/// object which can combine the glyphs data and metrics of a sf::Font
|
/// object which can combine the glyphs data and metrics of a sf::Font
|
||||||
/// to display any text on a render target.
|
/// to display any text on a render target.
|
||||||
///
|
///
|
||||||
/// It is important to note that the sf::Text instance doesn't
|
/// It is important to note that the sf::Text instance doesn't
|
||||||
/// copy the font that it uses, it only keeps a reference to it.
|
/// copy the font that it uses, it only keeps a reference to it.
|
||||||
/// Thus, a sf::Font must not be destructed while it is
|
/// Thus, a sf::Font must not be destructed while it is
|
||||||
/// used by a sf::Text (i.e. never write a function that
|
/// used by a sf::Text (i.e. never write a function that
|
||||||
/// uses a local sf::Font instance for creating a text).
|
/// uses a local sf::Font instance for creating a text).
|
||||||
///
|
///
|
||||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Declare and load a font
|
/// // Declare and load a font
|
||||||
/// sf::Font font;
|
/// sf::Font font;
|
||||||
/// font.loadFromFile("arial.ttf");
|
/// font.loadFromFile("arial.ttf");
|
||||||
///
|
///
|
||||||
/// // Create a text
|
/// // Create a text
|
||||||
/// sf::Text text("hello", font);
|
/// sf::Text text("hello", font);
|
||||||
/// text.setCharacterSize(30);
|
/// text.setCharacterSize(30);
|
||||||
/// text.setStyle(sf::Text::Bold);
|
/// text.setStyle(sf::Text::Bold);
|
||||||
/// text.setColor(sf::Color::Red);
|
/// text.setColor(sf::Color::Red);
|
||||||
///
|
///
|
||||||
/// // Draw it
|
/// // Draw it
|
||||||
/// window.draw(text);
|
/// window.draw(text);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Font, sf::Transformable
|
/// \see sf::Font, sf::Transformable
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -46,7 +46,7 @@ class InputStream;
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Texture : GlResource
|
class SFML_GRAPHICS_API Texture : GlResource
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Types of texture coordinates that can be used for rendering
|
/// \brief Types of texture coordinates that can be used for rendering
|
||||||
|
@ -58,7 +58,7 @@ public :
|
||||||
Pixels ///< Texture coordinates in range [0 .. size]
|
Pixels ///< Texture coordinates in range [0 .. size]
|
||||||
};
|
};
|
||||||
|
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
@ -468,7 +468,7 @@ public :
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static unsigned int getMaximumSize();
|
static unsigned int getMaximumSize();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
friend class RenderTexture;
|
friend class RenderTexture;
|
||||||
friend class RenderTarget;
|
friend class RenderTarget;
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Transform
|
class SFML_GRAPHICS_API Transform
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Transformable
|
class SFML_GRAPHICS_API Transformable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
@ -311,7 +311,7 @@ public :
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Transform& getInverseTransform() const;
|
const Transform& getInverseTransform() const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
|
@ -396,7 +396,7 @@ private :
|
||||||
/// \code
|
/// \code
|
||||||
/// class MyEntity
|
/// class MyEntity
|
||||||
/// {
|
/// {
|
||||||
/// public :
|
/// public:
|
||||||
/// void SetPosition(const MyVector& v)
|
/// void SetPosition(const MyVector& v)
|
||||||
/// {
|
/// {
|
||||||
/// myTransform.setPosition(v.x(), v.y());
|
/// myTransform.setPosition(v.x(), v.y());
|
||||||
|
@ -407,7 +407,7 @@ private :
|
||||||
/// target.draw(..., myTransform.getTransform());
|
/// target.draw(..., myTransform.getTransform());
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// private :
|
/// private:
|
||||||
/// sf::Transformable myTransform;
|
/// sf::Transformable myTransform;
|
||||||
/// };
|
/// };
|
||||||
/// \endcode
|
/// \endcode
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API Vertex
|
class SFML_GRAPHICS_API Vertex
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API VertexArray : public Drawable
|
class SFML_GRAPHICS_API VertexArray : public Drawable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
|
@ -171,7 +171,7 @@ public :
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FloatRect getBounds() const;
|
FloatRect getBounds() const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Draw the vertex array to a render target
|
/// \brief Draw the vertex array to a render target
|
||||||
|
|
|
@ -1,343 +1,343 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_VIEW_HPP
|
#ifndef SFML_VIEW_HPP
|
||||||
#define SFML_VIEW_HPP
|
#define SFML_VIEW_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/Export.hpp>
|
#include <SFML/Graphics/Export.hpp>
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
#include <SFML/Graphics/Transform.hpp>
|
#include <SFML/Graphics/Transform.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief 2D camera that defines what region is shown on screen
|
/// \brief 2D camera that defines what region is shown on screen
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_GRAPHICS_API View
|
class SFML_GRAPHICS_API View
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor creates a default view of (0, 0, 1000, 1000)
|
/// This constructor creates a default view of (0, 0, 1000, 1000)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
View();
|
View();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the view from a rectangle
|
/// \brief Construct the view from a rectangle
|
||||||
///
|
///
|
||||||
/// \param rectangle Rectangle defining the zone to display
|
/// \param rectangle Rectangle defining the zone to display
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
explicit View(const FloatRect& rectangle);
|
explicit View(const FloatRect& rectangle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the view from its center and size
|
/// \brief Construct the view from its center and size
|
||||||
///
|
///
|
||||||
/// \param center Center of the zone to display
|
/// \param center Center of the zone to display
|
||||||
/// \param size Size of zone to display
|
/// \param size Size of zone to display
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
View(const Vector2f& center, const Vector2f& size);
|
View(const Vector2f& center, const Vector2f& size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the center of the view
|
/// \brief Set the center of the view
|
||||||
///
|
///
|
||||||
/// \param x X coordinate of the new center
|
/// \param x X coordinate of the new center
|
||||||
/// \param y Y coordinate of the new center
|
/// \param y Y coordinate of the new center
|
||||||
///
|
///
|
||||||
/// \see setSize, getCenter
|
/// \see setSize, getCenter
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setCenter(float x, float y);
|
void setCenter(float x, float y);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the center of the view
|
/// \brief Set the center of the view
|
||||||
///
|
///
|
||||||
/// \param center New center
|
/// \param center New center
|
||||||
///
|
///
|
||||||
/// \see setSize, getCenter
|
/// \see setSize, getCenter
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setCenter(const Vector2f& center);
|
void setCenter(const Vector2f& center);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the size of the view
|
/// \brief Set the size of the view
|
||||||
///
|
///
|
||||||
/// \param width New width of the view
|
/// \param width New width of the view
|
||||||
/// \param height New height of the view
|
/// \param height New height of the view
|
||||||
///
|
///
|
||||||
/// \see setCenter, getCenter
|
/// \see setCenter, getCenter
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setSize(float width, float height);
|
void setSize(float width, float height);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the size of the view
|
/// \brief Set the size of the view
|
||||||
///
|
///
|
||||||
/// \param size New size
|
/// \param size New size
|
||||||
///
|
///
|
||||||
/// \see setCenter, getCenter
|
/// \see setCenter, getCenter
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setSize(const Vector2f& size);
|
void setSize(const Vector2f& size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the orientation of the view
|
/// \brief Set the orientation of the view
|
||||||
///
|
///
|
||||||
/// The default rotation of a view is 0 degree.
|
/// The default rotation of a view is 0 degree.
|
||||||
///
|
///
|
||||||
/// \param angle New angle, in degrees
|
/// \param angle New angle, in degrees
|
||||||
///
|
///
|
||||||
/// \see getRotation
|
/// \see getRotation
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setRotation(float angle);
|
void setRotation(float angle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the target viewport
|
/// \brief Set the target viewport
|
||||||
///
|
///
|
||||||
/// The viewport is the rectangle into which the contents of the
|
/// The viewport is the rectangle into which the contents of the
|
||||||
/// view are displayed, expressed as a factor (between 0 and 1)
|
/// view are displayed, expressed as a factor (between 0 and 1)
|
||||||
/// of the size of the RenderTarget to which the view is applied.
|
/// of the size of the RenderTarget to which the view is applied.
|
||||||
/// For example, a view which takes the left side of the target would
|
/// For example, a view which takes the left side of the target would
|
||||||
/// be defined with View.setViewport(sf::FloatRect(0, 0, 0.5, 1)).
|
/// be defined with View.setViewport(sf::FloatRect(0, 0, 0.5, 1)).
|
||||||
/// By default, a view has a viewport which covers the entire target.
|
/// By default, a view has a viewport which covers the entire target.
|
||||||
///
|
///
|
||||||
/// \param viewport New viewport rectangle
|
/// \param viewport New viewport rectangle
|
||||||
///
|
///
|
||||||
/// \see getViewport
|
/// \see getViewport
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setViewport(const FloatRect& viewport);
|
void setViewport(const FloatRect& viewport);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Reset the view to the given rectangle
|
/// \brief Reset the view to the given rectangle
|
||||||
///
|
///
|
||||||
/// Note that this function resets the rotation angle to 0.
|
/// Note that this function resets the rotation angle to 0.
|
||||||
///
|
///
|
||||||
/// \param rectangle Rectangle defining the zone to display
|
/// \param rectangle Rectangle defining the zone to display
|
||||||
///
|
///
|
||||||
/// \see setCenter, setSize, setRotation
|
/// \see setCenter, setSize, setRotation
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void reset(const FloatRect& rectangle);
|
void reset(const FloatRect& rectangle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the center of the view
|
/// \brief Get the center of the view
|
||||||
///
|
///
|
||||||
/// \return Center of the view
|
/// \return Center of the view
|
||||||
///
|
///
|
||||||
/// \see getSize, setCenter
|
/// \see getSize, setCenter
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Vector2f& getCenter() const;
|
const Vector2f& getCenter() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the size of the view
|
/// \brief Get the size of the view
|
||||||
///
|
///
|
||||||
/// \return Size of the view
|
/// \return Size of the view
|
||||||
///
|
///
|
||||||
/// \see getCenter, setSize
|
/// \see getCenter, setSize
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Vector2f& getSize() const;
|
const Vector2f& getSize() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the current orientation of the view
|
/// \brief Get the current orientation of the view
|
||||||
///
|
///
|
||||||
/// \return Rotation angle of the view, in degrees
|
/// \return Rotation angle of the view, in degrees
|
||||||
///
|
///
|
||||||
/// \see setRotation
|
/// \see setRotation
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getRotation() const;
|
float getRotation() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the target viewport rectangle of the view
|
/// \brief Get the target viewport rectangle of the view
|
||||||
///
|
///
|
||||||
/// \return Viewport rectangle, expressed as a factor of the target size
|
/// \return Viewport rectangle, expressed as a factor of the target size
|
||||||
///
|
///
|
||||||
/// \see setViewport
|
/// \see setViewport
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const FloatRect& getViewport() const;
|
const FloatRect& getViewport() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Move the view relatively to its current position
|
/// \brief Move the view relatively to its current position
|
||||||
///
|
///
|
||||||
/// \param offsetX X coordinate of the move offset
|
/// \param offsetX X coordinate of the move offset
|
||||||
/// \param offsetY Y coordinate of the move offset
|
/// \param offsetY Y coordinate of the move offset
|
||||||
///
|
///
|
||||||
/// \see setCenter, rotate, zoom
|
/// \see setCenter, rotate, zoom
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void move(float offsetX, float offsetY);
|
void move(float offsetX, float offsetY);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Move the view relatively to its current position
|
/// \brief Move the view relatively to its current position
|
||||||
///
|
///
|
||||||
/// \param offset Move offset
|
/// \param offset Move offset
|
||||||
///
|
///
|
||||||
/// \see setCenter, rotate, zoom
|
/// \see setCenter, rotate, zoom
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void move(const Vector2f& offset);
|
void move(const Vector2f& offset);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Rotate the view relatively to its current orientation
|
/// \brief Rotate the view relatively to its current orientation
|
||||||
///
|
///
|
||||||
/// \param angle Angle to rotate, in degrees
|
/// \param angle Angle to rotate, in degrees
|
||||||
///
|
///
|
||||||
/// \see setRotation, move, zoom
|
/// \see setRotation, move, zoom
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void rotate(float angle);
|
void rotate(float angle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Resize the view rectangle relatively to its current size
|
/// \brief Resize the view rectangle relatively to its current size
|
||||||
///
|
///
|
||||||
/// Resizing the view simulates a zoom, as the zone displayed on
|
/// Resizing the view simulates a zoom, as the zone displayed on
|
||||||
/// screen grows or shrinks.
|
/// screen grows or shrinks.
|
||||||
/// \a factor is a multiplier:
|
/// \a factor is a multiplier:
|
||||||
/// \li 1 keeps the size unchanged
|
/// \li 1 keeps the size unchanged
|
||||||
/// \li > 1 makes the view bigger (objects appear smaller)
|
/// \li > 1 makes the view bigger (objects appear smaller)
|
||||||
/// \li < 1 makes the view smaller (objects appear bigger)
|
/// \li < 1 makes the view smaller (objects appear bigger)
|
||||||
///
|
///
|
||||||
/// \param factor Zoom factor to apply
|
/// \param factor Zoom factor to apply
|
||||||
///
|
///
|
||||||
/// \see setSize, move, rotate
|
/// \see setSize, move, rotate
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void zoom(float factor);
|
void zoom(float factor);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the projection transform of the view
|
/// \brief Get the projection transform of the view
|
||||||
///
|
///
|
||||||
/// This function is meant for internal use only.
|
/// This function is meant for internal use only.
|
||||||
///
|
///
|
||||||
/// \return Projection transform defining the view
|
/// \return Projection transform defining the view
|
||||||
///
|
///
|
||||||
/// \see getInverseTransform
|
/// \see getInverseTransform
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Transform& getTransform() const;
|
const Transform& getTransform() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the inverse projection transform of the view
|
/// \brief Get the inverse projection transform of the view
|
||||||
///
|
///
|
||||||
/// This function is meant for internal use only.
|
/// This function is meant for internal use only.
|
||||||
///
|
///
|
||||||
/// \return Inverse of the projection transform defining the view
|
/// \return Inverse of the projection transform defining the view
|
||||||
///
|
///
|
||||||
/// \see getTransform
|
/// \see getTransform
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Transform& getInverseTransform() const;
|
const Transform& getInverseTransform() const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Vector2f m_center; ///< Center of the view, in scene coordinates
|
Vector2f m_center; ///< Center of the view, in scene coordinates
|
||||||
Vector2f m_size; ///< Size of the view, in scene coordinates
|
Vector2f m_size; ///< Size of the view, in scene coordinates
|
||||||
float m_rotation; ///< Angle of rotation of the view rectangle, in degrees
|
float m_rotation; ///< Angle of rotation of the view rectangle, in degrees
|
||||||
FloatRect m_viewport; ///< Viewport rectangle, expressed as a factor of the render-target's size
|
FloatRect m_viewport; ///< Viewport rectangle, expressed as a factor of the render-target's size
|
||||||
mutable Transform m_transform; ///< Precomputed projection transform corresponding to the view
|
mutable Transform m_transform; ///< Precomputed projection transform corresponding to the view
|
||||||
mutable Transform m_inverseTransform; ///< Precomputed inverse projection transform corresponding to the view
|
mutable Transform m_inverseTransform; ///< Precomputed inverse projection transform corresponding to the view
|
||||||
mutable bool m_transformUpdated; ///< Internal state telling if the transform needs to be updated
|
mutable bool m_transformUpdated; ///< Internal state telling if the transform needs to be updated
|
||||||
mutable bool m_invTransformUpdated; ///< Internal state telling if the inverse transform needs to be updated
|
mutable bool m_invTransformUpdated; ///< Internal state telling if the inverse transform needs to be updated
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_VIEW_HPP
|
#endif // SFML_VIEW_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::View
|
/// \class sf::View
|
||||||
/// \ingroup graphics
|
/// \ingroup graphics
|
||||||
///
|
///
|
||||||
/// sf::View defines a camera in the 2D scene. This is a
|
/// sf::View defines a camera in the 2D scene. This is a
|
||||||
/// very powerful concept: you can scroll, rotate or zoom
|
/// very powerful concept: you can scroll, rotate or zoom
|
||||||
/// the entire scene without altering the way that your
|
/// the entire scene without altering the way that your
|
||||||
/// drawable objects are drawn.
|
/// drawable objects are drawn.
|
||||||
///
|
///
|
||||||
/// A view is composed of a source rectangle, which defines
|
/// A view is composed of a source rectangle, which defines
|
||||||
/// what part of the 2D scene is shown, and a target viewport,
|
/// what part of the 2D scene is shown, and a target viewport,
|
||||||
/// which defines where the contents of the source rectangle
|
/// which defines where the contents of the source rectangle
|
||||||
/// will be displayed on the render target (window or texture).
|
/// will be displayed on the render target (window or texture).
|
||||||
///
|
///
|
||||||
/// The viewport allows to map the scene to a custom part
|
/// The viewport allows to map the scene to a custom part
|
||||||
/// of the render target, and can be used for split-screen
|
/// of the render target, and can be used for split-screen
|
||||||
/// or for displaying a minimap, for example. If the source
|
/// or for displaying a minimap, for example. If the source
|
||||||
/// rectangle has not the same size as the viewport, its
|
/// rectangle has not the same size as the viewport, its
|
||||||
/// contents will be stretched to fit in.
|
/// contents will be stretched to fit in.
|
||||||
///
|
///
|
||||||
/// To apply a view, you have to assign it to the render target.
|
/// To apply a view, you have to assign it to the render target.
|
||||||
/// Then, every objects drawn in this render target will be
|
/// Then, every objects drawn in this render target will be
|
||||||
/// affected by the view until you use another view.
|
/// affected by the view until you use another view.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::RenderWindow window;
|
/// sf::RenderWindow window;
|
||||||
/// sf::View view;
|
/// sf::View view;
|
||||||
///
|
///
|
||||||
/// // Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
|
/// // Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
|
||||||
/// view.reset(sf::FloatRect(100, 100, 400, 200));
|
/// view.reset(sf::FloatRect(100, 100, 400, 200));
|
||||||
///
|
///
|
||||||
/// // Rotate it by 45 degrees
|
/// // Rotate it by 45 degrees
|
||||||
/// view.rotate(45);
|
/// view.rotate(45);
|
||||||
///
|
///
|
||||||
/// // Set its target viewport to be half of the window
|
/// // Set its target viewport to be half of the window
|
||||||
/// view.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));
|
/// view.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));
|
||||||
///
|
///
|
||||||
/// // Apply it
|
/// // Apply it
|
||||||
/// window.setView(view);
|
/// window.setView(view);
|
||||||
///
|
///
|
||||||
/// // Render stuff
|
/// // Render stuff
|
||||||
/// window.draw(someSprite);
|
/// window.draw(someSprite);
|
||||||
///
|
///
|
||||||
/// // Set the default view back
|
/// // Set the default view back
|
||||||
/// window.setView(window.getDefaultView());
|
/// window.setView(window.getDefaultView());
|
||||||
///
|
///
|
||||||
/// // Render stuff not affected by the view
|
/// // Render stuff not affected by the view
|
||||||
/// window.draw(someText);
|
/// window.draw(someText);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
||||||
///
|
///
|
||||||
/// \see sf::RenderWindow, sf::RenderTexture
|
/// \see sf::RenderWindow, sf::RenderTexture
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,51 +1,51 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_NETWORK_HPP
|
#ifndef SFML_NETWORK_HPP
|
||||||
#define SFML_NETWORK_HPP
|
#define SFML_NETWORK_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
#include <SFML/Network/Ftp.hpp>
|
#include <SFML/Network/Ftp.hpp>
|
||||||
#include <SFML/Network/Http.hpp>
|
#include <SFML/Network/Http.hpp>
|
||||||
#include <SFML/Network/IpAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Network/Packet.hpp>
|
#include <SFML/Network/Packet.hpp>
|
||||||
#include <SFML/Network/SocketSelector.hpp>
|
#include <SFML/Network/SocketSelector.hpp>
|
||||||
#include <SFML/Network/TcpListener.hpp>
|
#include <SFML/Network/TcpListener.hpp>
|
||||||
#include <SFML/Network/TcpSocket.hpp>
|
#include <SFML/Network/TcpSocket.hpp>
|
||||||
#include <SFML/Network/UdpSocket.hpp>
|
#include <SFML/Network/UdpSocket.hpp>
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_NETWORK_HPP
|
#endif // SFML_NETWORK_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \defgroup network Network module
|
/// \defgroup network Network module
|
||||||
///
|
///
|
||||||
/// Socket-based communication, utilities and higher-level
|
/// Socket-based communication, utilities and higher-level
|
||||||
/// network protocols (HTTP, FTP).
|
/// network protocols (HTTP, FTP).
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,482 +1,482 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_HTTP_HPP
|
#ifndef SFML_HTTP_HPP
|
||||||
#define SFML_HTTP_HPP
|
#define SFML_HTTP_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <SFML/Network/IpAddress.hpp>
|
#include <SFML/Network/IpAddress.hpp>
|
||||||
#include <SFML/Network/TcpSocket.hpp>
|
#include <SFML/Network/TcpSocket.hpp>
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief A HTTP client
|
/// \brief A HTTP client
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API Http : NonCopyable
|
class SFML_NETWORK_API Http : NonCopyable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Define a HTTP request
|
/// \brief Define a HTTP request
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API Request
|
class SFML_NETWORK_API Request
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Enumerate the available HTTP methods for a request
|
/// \brief Enumerate the available HTTP methods for a request
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum Method
|
enum Method
|
||||||
{
|
{
|
||||||
Get, ///< Request in get mode, standard method to retrieve a page
|
Get, ///< Request in get mode, standard method to retrieve a page
|
||||||
Post, ///< Request in post mode, usually to send data to a page
|
Post, ///< Request in post mode, usually to send data to a page
|
||||||
Head, ///< Request a page's header only
|
Head, ///< Request a page's header only
|
||||||
Put, ///< Request in put mode, useful for a REST API
|
Put, ///< Request in put mode, useful for a REST API
|
||||||
Delete ///< Request in delete mode, useful for a REST API
|
Delete ///< Request in delete mode, useful for a REST API
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor creates a GET request, with the root
|
/// This constructor creates a GET request, with the root
|
||||||
/// URI ("/") and an empty body.
|
/// URI ("/") and an empty body.
|
||||||
///
|
///
|
||||||
/// \param uri Target URI
|
/// \param uri Target URI
|
||||||
/// \param method Method to use for the request
|
/// \param method Method to use for the request
|
||||||
/// \param body Content of the request's body
|
/// \param body Content of the request's body
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Request(const std::string& uri = "/", Method method = Get, const std::string& body = "");
|
Request(const std::string& uri = "/", Method method = Get, const std::string& body = "");
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the value of a field
|
/// \brief Set the value of a field
|
||||||
///
|
///
|
||||||
/// The field is created if it doesn't exist. The name of
|
/// The field is created if it doesn't exist. The name of
|
||||||
/// the field is case insensitive.
|
/// the field is case insensitive.
|
||||||
/// By default, a request doesn't contain any field (but the
|
/// By default, a request doesn't contain any field (but the
|
||||||
/// mandatory fields are added later by the HTTP client when
|
/// mandatory fields are added later by the HTTP client when
|
||||||
/// sending the request).
|
/// sending the request).
|
||||||
///
|
///
|
||||||
/// \param field Name of the field to set
|
/// \param field Name of the field to set
|
||||||
/// \param value Value of the field
|
/// \param value Value of the field
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setField(const std::string& field, const std::string& value);
|
void setField(const std::string& field, const std::string& value);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the request method
|
/// \brief Set the request method
|
||||||
///
|
///
|
||||||
/// See the Method enumeration for a complete list of all
|
/// See the Method enumeration for a complete list of all
|
||||||
/// the availale methods.
|
/// the availale methods.
|
||||||
/// The method is Http::Request::Get by default.
|
/// The method is Http::Request::Get by default.
|
||||||
///
|
///
|
||||||
/// \param method Method to use for the request
|
/// \param method Method to use for the request
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setMethod(Method method);
|
void setMethod(Method method);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the requested URI
|
/// \brief Set the requested URI
|
||||||
///
|
///
|
||||||
/// The URI is the resource (usually a web page or a file)
|
/// The URI is the resource (usually a web page or a file)
|
||||||
/// that you want to get or post.
|
/// that you want to get or post.
|
||||||
/// The URI is "/" (the root page) by default.
|
/// The URI is "/" (the root page) by default.
|
||||||
///
|
///
|
||||||
/// \param uri URI to request, relative to the host
|
/// \param uri URI to request, relative to the host
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setUri(const std::string& uri);
|
void setUri(const std::string& uri);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the HTTP version for the request
|
/// \brief Set the HTTP version for the request
|
||||||
///
|
///
|
||||||
/// The HTTP version is 1.0 by default.
|
/// The HTTP version is 1.0 by default.
|
||||||
///
|
///
|
||||||
/// \param major Major HTTP version number
|
/// \param major Major HTTP version number
|
||||||
/// \param minor Minor HTTP version number
|
/// \param minor Minor HTTP version number
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setHttpVersion(unsigned int major, unsigned int minor);
|
void setHttpVersion(unsigned int major, unsigned int minor);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the body of the request
|
/// \brief Set the body of the request
|
||||||
///
|
///
|
||||||
/// The body of a request is optional and only makes sense
|
/// The body of a request is optional and only makes sense
|
||||||
/// for POST requests. It is ignored for all other methods.
|
/// for POST requests. It is ignored for all other methods.
|
||||||
/// The body is empty by default.
|
/// The body is empty by default.
|
||||||
///
|
///
|
||||||
/// \param body Content of the body
|
/// \param body Content of the body
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setBody(const std::string& body);
|
void setBody(const std::string& body);
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
friend class Http;
|
friend class Http;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Prepare the final request to send to the server
|
/// \brief Prepare the final request to send to the server
|
||||||
///
|
///
|
||||||
/// This is used internally by Http before sending the
|
/// This is used internally by Http before sending the
|
||||||
/// request to the web server.
|
/// request to the web server.
|
||||||
///
|
///
|
||||||
/// \return String containing the request, ready to be sent
|
/// \return String containing the request, ready to be sent
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::string prepare() const;
|
std::string prepare() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check if the request defines a field
|
/// \brief Check if the request defines a field
|
||||||
///
|
///
|
||||||
/// This function uses case-insensitive comparisons.
|
/// This function uses case-insensitive comparisons.
|
||||||
///
|
///
|
||||||
/// \param field Name of the field to test
|
/// \param field Name of the field to test
|
||||||
///
|
///
|
||||||
/// \return True if the field exists, false otherwise
|
/// \return True if the field exists, false otherwise
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool hasField(const std::string& field) const;
|
bool hasField(const std::string& field) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Types
|
// Types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef std::map<std::string, std::string> FieldTable;
|
typedef std::map<std::string, std::string> FieldTable;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FieldTable m_fields; ///< Fields of the header associated to their value
|
FieldTable m_fields; ///< Fields of the header associated to their value
|
||||||
Method m_method; ///< Method to use for the request
|
Method m_method; ///< Method to use for the request
|
||||||
std::string m_uri; ///< Target URI of the request
|
std::string m_uri; ///< Target URI of the request
|
||||||
unsigned int m_majorVersion; ///< Major HTTP version
|
unsigned int m_majorVersion; ///< Major HTTP version
|
||||||
unsigned int m_minorVersion; ///< Minor HTTP version
|
unsigned int m_minorVersion; ///< Minor HTTP version
|
||||||
std::string m_body; ///< Body of the request
|
std::string m_body; ///< Body of the request
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Define a HTTP response
|
/// \brief Define a HTTP response
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API Response
|
class SFML_NETWORK_API Response
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Enumerate all the valid status codes for a response
|
/// \brief Enumerate all the valid status codes for a response
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum Status
|
enum Status
|
||||||
{
|
{
|
||||||
// 2xx: success
|
// 2xx: success
|
||||||
Ok = 200, ///< Most common code returned when operation was successful
|
Ok = 200, ///< Most common code returned when operation was successful
|
||||||
Created = 201, ///< The resource has successfully been created
|
Created = 201, ///< The resource has successfully been created
|
||||||
Accepted = 202, ///< The request has been accepted, but will be processed later by the server
|
Accepted = 202, ///< The request has been accepted, but will be processed later by the server
|
||||||
NoContent = 204, ///< The server didn't send any data in return
|
NoContent = 204, ///< The server didn't send any data in return
|
||||||
ResetContent = 205, ///< The server informs the client that it should clear the view (form) that caused the request to be sent
|
ResetContent = 205, ///< The server informs the client that it should clear the view (form) that caused the request to be sent
|
||||||
PartialContent = 206, ///< The server has sent a part of the resource, as a response to a partial GET request
|
PartialContent = 206, ///< The server has sent a part of the resource, as a response to a partial GET request
|
||||||
|
|
||||||
// 3xx: redirection
|
// 3xx: redirection
|
||||||
MultipleChoices = 300, ///< The requested page can be accessed from several locations
|
MultipleChoices = 300, ///< The requested page can be accessed from several locations
|
||||||
MovedPermanently = 301, ///< The requested page has permanently moved to a new location
|
MovedPermanently = 301, ///< The requested page has permanently moved to a new location
|
||||||
MovedTemporarily = 302, ///< The requested page has temporarily moved to a new location
|
MovedTemporarily = 302, ///< The requested page has temporarily moved to a new location
|
||||||
NotModified = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed
|
NotModified = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed
|
||||||
|
|
||||||
// 4xx: client error
|
// 4xx: client error
|
||||||
BadRequest = 400, ///< The server couldn't understand the request (syntax error)
|
BadRequest = 400, ///< The server couldn't understand the request (syntax error)
|
||||||
Unauthorized = 401, ///< The requested page needs an authentification to be accessed
|
Unauthorized = 401, ///< The requested page needs an authentification to be accessed
|
||||||
Forbidden = 403, ///< The requested page cannot be accessed at all, even with authentification
|
Forbidden = 403, ///< The requested page cannot be accessed at all, even with authentification
|
||||||
NotFound = 404, ///< The requested page doesn't exist
|
NotFound = 404, ///< The requested page doesn't exist
|
||||||
RangeNotSatisfiable = 407, ///< The server can't satisfy the partial GET request (with a "Range" header field)
|
RangeNotSatisfiable = 407, ///< The server can't satisfy the partial GET request (with a "Range" header field)
|
||||||
|
|
||||||
// 5xx: server error
|
// 5xx: server error
|
||||||
InternalServerError = 500, ///< The server encountered an unexpected error
|
InternalServerError = 500, ///< The server encountered an unexpected error
|
||||||
NotImplemented = 501, ///< The server doesn't implement a requested feature
|
NotImplemented = 501, ///< The server doesn't implement a requested feature
|
||||||
BadGateway = 502, ///< The gateway server has received an error from the source server
|
BadGateway = 502, ///< The gateway server has received an error from the source server
|
||||||
ServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
|
ServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
|
||||||
GatewayTimeout = 504, ///< The gateway server couldn't receive a response from the source server
|
GatewayTimeout = 504, ///< The gateway server couldn't receive a response from the source server
|
||||||
VersionNotSupported = 505, ///< The server doesn't support the requested HTTP version
|
VersionNotSupported = 505, ///< The server doesn't support the requested HTTP version
|
||||||
|
|
||||||
// 10xx: SFML custom codes
|
// 10xx: SFML custom codes
|
||||||
InvalidResponse = 1000, ///< Response is not a valid HTTP one
|
InvalidResponse = 1000, ///< Response is not a valid HTTP one
|
||||||
ConnectionFailed = 1001 ///< Connection with server failed
|
ConnectionFailed = 1001 ///< Connection with server failed
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Constructs an empty response.
|
/// Constructs an empty response.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Response();
|
Response();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the value of a field
|
/// \brief Get the value of a field
|
||||||
///
|
///
|
||||||
/// If the field \a field is not found in the response header,
|
/// If the field \a field is not found in the response header,
|
||||||
/// the empty string is returned. This function uses
|
/// the empty string is returned. This function uses
|
||||||
/// case-insensitive comparisons.
|
/// case-insensitive comparisons.
|
||||||
///
|
///
|
||||||
/// \param field Name of the field to get
|
/// \param field Name of the field to get
|
||||||
///
|
///
|
||||||
/// \return Value of the field, or empty string if not found
|
/// \return Value of the field, or empty string if not found
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const std::string& getField(const std::string& field) const;
|
const std::string& getField(const std::string& field) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the response status code
|
/// \brief Get the response status code
|
||||||
///
|
///
|
||||||
/// The status code should be the first thing to be checked
|
/// The status code should be the first thing to be checked
|
||||||
/// after receiving a response, it defines whether it is a
|
/// after receiving a response, it defines whether it is a
|
||||||
/// success, a failure or anything else (see the Status
|
/// success, a failure or anything else (see the Status
|
||||||
/// enumeration).
|
/// enumeration).
|
||||||
///
|
///
|
||||||
/// \return Status code of the response
|
/// \return Status code of the response
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status getStatus() const;
|
Status getStatus() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the major HTTP version number of the response
|
/// \brief Get the major HTTP version number of the response
|
||||||
///
|
///
|
||||||
/// \return Major HTTP version number
|
/// \return Major HTTP version number
|
||||||
///
|
///
|
||||||
/// \see getMinorHttpVersion
|
/// \see getMinorHttpVersion
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getMajorHttpVersion() const;
|
unsigned int getMajorHttpVersion() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the minor HTTP version number of the response
|
/// \brief Get the minor HTTP version number of the response
|
||||||
///
|
///
|
||||||
/// \return Minor HTTP version number
|
/// \return Minor HTTP version number
|
||||||
///
|
///
|
||||||
/// \see getMajorHttpVersion
|
/// \see getMajorHttpVersion
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int getMinorHttpVersion() const;
|
unsigned int getMinorHttpVersion() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the body of the response
|
/// \brief Get the body of the response
|
||||||
///
|
///
|
||||||
/// The body of a response may contain:
|
/// The body of a response may contain:
|
||||||
/// \li the requested page (for GET requests)
|
/// \li the requested page (for GET requests)
|
||||||
/// \li a response from the server (for POST requests)
|
/// \li a response from the server (for POST requests)
|
||||||
/// \li nothing (for HEAD requests)
|
/// \li nothing (for HEAD requests)
|
||||||
/// \li an error message (in case of an error)
|
/// \li an error message (in case of an error)
|
||||||
///
|
///
|
||||||
/// \return The response body
|
/// \return The response body
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const std::string& getBody() const;
|
const std::string& getBody() const;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
friend class Http;
|
friend class Http;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the header from a response string
|
/// \brief Construct the header from a response string
|
||||||
///
|
///
|
||||||
/// This function is used by Http to build the response
|
/// This function is used by Http to build the response
|
||||||
/// of a request.
|
/// of a request.
|
||||||
///
|
///
|
||||||
/// \param data Content of the response to parse
|
/// \param data Content of the response to parse
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void parse(const std::string& data);
|
void parse(const std::string& data);
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Read values passed in the answer header
|
/// \brief Read values passed in the answer header
|
||||||
///
|
///
|
||||||
/// This function is used by Http to extract values passed
|
/// This function is used by Http to extract values passed
|
||||||
/// in the response.
|
/// in the response.
|
||||||
///
|
///
|
||||||
/// \param in String stream containing the header values
|
/// \param in String stream containing the header values
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void parseFields(std::istream &in);
|
void parseFields(std::istream &in);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Types
|
// Types
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
typedef std::map<std::string, std::string> FieldTable;
|
typedef std::map<std::string, std::string> FieldTable;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
FieldTable m_fields; ///< Fields of the header
|
FieldTable m_fields; ///< Fields of the header
|
||||||
Status m_status; ///< Status code
|
Status m_status; ///< Status code
|
||||||
unsigned int m_majorVersion; ///< Major HTTP version
|
unsigned int m_majorVersion; ///< Major HTTP version
|
||||||
unsigned int m_minorVersion; ///< Minor HTTP version
|
unsigned int m_minorVersion; ///< Minor HTTP version
|
||||||
std::string m_body; ///< Body of the response
|
std::string m_body; ///< Body of the response
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Http();
|
Http();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the HTTP client with the target host
|
/// \brief Construct the HTTP client with the target host
|
||||||
///
|
///
|
||||||
/// This is equivalent to calling setHost(host, port).
|
/// This is equivalent to calling setHost(host, port).
|
||||||
/// The port has a default value of 0, which means that the
|
/// The port has a default value of 0, which means that the
|
||||||
/// HTTP client will use the right port according to the
|
/// HTTP client will use the right port according to the
|
||||||
/// protocol used (80 for HTTP). You should leave it like
|
/// protocol used (80 for HTTP). You should leave it like
|
||||||
/// this unless you really need a port other than the
|
/// this unless you really need a port other than the
|
||||||
/// standard one, or use an unknown protocol.
|
/// standard one, or use an unknown protocol.
|
||||||
///
|
///
|
||||||
/// \param host Web server to connect to
|
/// \param host Web server to connect to
|
||||||
/// \param port Port to use for connection
|
/// \param port Port to use for connection
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Http(const std::string& host, unsigned short port = 0);
|
Http(const std::string& host, unsigned short port = 0);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the target host
|
/// \brief Set the target host
|
||||||
///
|
///
|
||||||
/// This function just stores the host address and port, it
|
/// This function just stores the host address and port, it
|
||||||
/// doesn't actually connect to it until you send a request.
|
/// doesn't actually connect to it until you send a request.
|
||||||
/// The port has a default value of 0, which means that the
|
/// The port has a default value of 0, which means that the
|
||||||
/// HTTP client will use the right port according to the
|
/// HTTP client will use the right port according to the
|
||||||
/// protocol used (80 for HTTP). You should leave it like
|
/// protocol used (80 for HTTP). You should leave it like
|
||||||
/// this unless you really need a port other than the
|
/// this unless you really need a port other than the
|
||||||
/// standard one, or use an unknown protocol.
|
/// standard one, or use an unknown protocol.
|
||||||
///
|
///
|
||||||
/// \param host Web server to connect to
|
/// \param host Web server to connect to
|
||||||
/// \param port Port to use for connection
|
/// \param port Port to use for connection
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setHost(const std::string& host, unsigned short port = 0);
|
void setHost(const std::string& host, unsigned short port = 0);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Send a HTTP request and return the server's response.
|
/// \brief Send a HTTP request and return the server's response.
|
||||||
///
|
///
|
||||||
/// You must have a valid host before sending a request (see setHost).
|
/// You must have a valid host before sending a request (see setHost).
|
||||||
/// Any missing mandatory header field in the request will be added
|
/// Any missing mandatory header field in the request will be added
|
||||||
/// with an appropriate value.
|
/// with an appropriate value.
|
||||||
/// Warning: this function waits for the server's response and may
|
/// Warning: this function waits for the server's response and may
|
||||||
/// not return instantly; use a thread if you don't want to block your
|
/// not return instantly; use a thread if you don't want to block your
|
||||||
/// application, or use a timeout to limit the time to wait. A value
|
/// application, or use a timeout to limit the time to wait. A value
|
||||||
/// of Time::Zero means that the client will use the system defaut timeout
|
/// of Time::Zero means that the client will use the system defaut timeout
|
||||||
/// (which is usually pretty long).
|
/// (which is usually pretty long).
|
||||||
///
|
///
|
||||||
/// \param request Request to send
|
/// \param request Request to send
|
||||||
/// \param timeout Maximum time to wait
|
/// \param timeout Maximum time to wait
|
||||||
///
|
///
|
||||||
/// \return Server's response
|
/// \return Server's response
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Response sendRequest(const Request& request, Time timeout = Time::Zero);
|
Response sendRequest(const Request& request, Time timeout = Time::Zero);
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
TcpSocket m_connection; ///< Connection to the host
|
TcpSocket m_connection; ///< Connection to the host
|
||||||
IpAddress m_host; ///< Web host address
|
IpAddress m_host; ///< Web host address
|
||||||
std::string m_hostName; ///< Web host name
|
std::string m_hostName; ///< Web host name
|
||||||
unsigned short m_port; ///< Port used for connection with host
|
unsigned short m_port; ///< Port used for connection with host
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_HTTP_HPP
|
#endif // SFML_HTTP_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Http
|
/// \class sf::Http
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// sf::Http is a very simple HTTP client that allows you
|
/// sf::Http is a very simple HTTP client that allows you
|
||||||
/// to communicate with a web server. You can retrieve
|
/// to communicate with a web server. You can retrieve
|
||||||
/// web pages, send data to an interactive resource,
|
/// web pages, send data to an interactive resource,
|
||||||
/// download a remote file, etc. The HTTPS protocol is
|
/// download a remote file, etc. The HTTPS protocol is
|
||||||
/// not supported.
|
/// not supported.
|
||||||
///
|
///
|
||||||
/// The HTTP client is split into 3 classes:
|
/// The HTTP client is split into 3 classes:
|
||||||
/// \li sf::Http::Request
|
/// \li sf::Http::Request
|
||||||
/// \li sf::Http::Response
|
/// \li sf::Http::Response
|
||||||
/// \li sf::Http
|
/// \li sf::Http
|
||||||
///
|
///
|
||||||
/// sf::Http::Request builds the request that will be
|
/// sf::Http::Request builds the request that will be
|
||||||
/// sent to the server. A request is made of:
|
/// sent to the server. A request is made of:
|
||||||
/// \li a method (what you want to do)
|
/// \li a method (what you want to do)
|
||||||
/// \li a target URI (usually the name of the web page or file)
|
/// \li a target URI (usually the name of the web page or file)
|
||||||
/// \li one or more header fields (options that you can pass to the server)
|
/// \li one or more header fields (options that you can pass to the server)
|
||||||
/// \li an optional body (for POST requests)
|
/// \li an optional body (for POST requests)
|
||||||
///
|
///
|
||||||
/// sf::Http::Response parse the response from the web server
|
/// sf::Http::Response parse the response from the web server
|
||||||
/// and provides getters to read them. The response contains:
|
/// and provides getters to read them. The response contains:
|
||||||
/// \li a status code
|
/// \li a status code
|
||||||
/// \li header fields (that may be answers to the ones that you requested)
|
/// \li header fields (that may be answers to the ones that you requested)
|
||||||
/// \li a body, which contains the contents of the requested resource
|
/// \li a body, which contains the contents of the requested resource
|
||||||
///
|
///
|
||||||
/// sf::Http provides a simple function, SendRequest, to send a
|
/// sf::Http provides a simple function, SendRequest, to send a
|
||||||
/// sf::Http::Request and return the corresponding sf::Http::Response
|
/// sf::Http::Request and return the corresponding sf::Http::Response
|
||||||
/// from the server.
|
/// from the server.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Create a new HTTP client
|
/// // Create a new HTTP client
|
||||||
/// sf::Http http;
|
/// sf::Http http;
|
||||||
///
|
///
|
||||||
/// // We'll work on http://www.sfml-dev.org
|
/// // We'll work on http://www.sfml-dev.org
|
||||||
/// http.setHost("http://www.sfml-dev.org");
|
/// http.setHost("http://www.sfml-dev.org");
|
||||||
///
|
///
|
||||||
/// // Prepare a request to get the 'features.php' page
|
/// // Prepare a request to get the 'features.php' page
|
||||||
/// sf::Http::Request request("features.php");
|
/// sf::Http::Request request("features.php");
|
||||||
///
|
///
|
||||||
/// // Send the request
|
/// // Send the request
|
||||||
/// sf::Http::Response response = http.sendRequest(request);
|
/// sf::Http::Response response = http.sendRequest(request);
|
||||||
///
|
///
|
||||||
/// // Check the status code and display the result
|
/// // Check the status code and display the result
|
||||||
/// sf::Http::Response::Status status = response.getStatus();
|
/// sf::Http::Response::Status status = response.getStatus();
|
||||||
/// if (status == sf::Http::Response::Ok)
|
/// if (status == sf::Http::Response::Ok)
|
||||||
/// {
|
/// {
|
||||||
/// std::cout << response.getBody() << std::endl;
|
/// std::cout << response.getBody() << std::endl;
|
||||||
/// }
|
/// }
|
||||||
/// else
|
/// else
|
||||||
/// {
|
/// {
|
||||||
/// std::cout << "Error " << status << std::endl;
|
/// std::cout << "Error " << status << std::endl;
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,316 +1,316 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_IPADDRESS_HPP
|
#ifndef SFML_IPADDRESS_HPP
|
||||||
#define SFML_IPADDRESS_HPP
|
#define SFML_IPADDRESS_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Encapsulate an IPv4 network address
|
/// \brief Encapsulate an IPv4 network address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API IpAddress
|
class SFML_NETWORK_API IpAddress
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor creates an empty (invalid) address
|
/// This constructor creates an empty (invalid) address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IpAddress();
|
IpAddress();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the address from a string
|
/// \brief Construct the address from a string
|
||||||
///
|
///
|
||||||
/// Here \a address can be either a decimal address
|
/// Here \a address can be either a decimal address
|
||||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||||
///
|
///
|
||||||
/// \param address IP address or network name
|
/// \param address IP address or network name
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IpAddress(const std::string& address);
|
IpAddress(const std::string& address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the address from a string
|
/// \brief Construct the address from a string
|
||||||
///
|
///
|
||||||
/// Here \a address can be either a decimal address
|
/// Here \a address can be either a decimal address
|
||||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||||
/// This is equivalent to the constructor taking a std::string
|
/// This is equivalent to the constructor taking a std::string
|
||||||
/// parameter, it is defined for convenience so that the
|
/// parameter, it is defined for convenience so that the
|
||||||
/// implicit conversions from literal strings to IpAddress work.
|
/// implicit conversions from literal strings to IpAddress work.
|
||||||
///
|
///
|
||||||
/// \param address IP address or network name
|
/// \param address IP address or network name
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IpAddress(const char* address);
|
IpAddress(const char* address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the address from 4 bytes
|
/// \brief Construct the address from 4 bytes
|
||||||
///
|
///
|
||||||
/// Calling IpAddress(a, b, c, d) is equivalent to calling
|
/// Calling IpAddress(a, b, c, d) is equivalent to calling
|
||||||
/// IpAddress("a.b.c.d"), but safer as it doesn't have to
|
/// IpAddress("a.b.c.d"), but safer as it doesn't have to
|
||||||
/// parse a string to get the address components.
|
/// parse a string to get the address components.
|
||||||
///
|
///
|
||||||
/// \param byte0 First byte of the address
|
/// \param byte0 First byte of the address
|
||||||
/// \param byte1 Second byte of the address
|
/// \param byte1 Second byte of the address
|
||||||
/// \param byte2 Third byte of the address
|
/// \param byte2 Third byte of the address
|
||||||
/// \param byte3 Fourth byte of the address
|
/// \param byte3 Fourth byte of the address
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
|
IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the address from a 32-bits integer
|
/// \brief Construct the address from a 32-bits integer
|
||||||
///
|
///
|
||||||
/// This constructor uses the internal representation of
|
/// This constructor uses the internal representation of
|
||||||
/// the address directly. It should be used for optimization
|
/// the address directly. It should be used for optimization
|
||||||
/// purposes, and only if you got that representation from
|
/// purposes, and only if you got that representation from
|
||||||
/// IpAddress::ToInteger().
|
/// IpAddress::ToInteger().
|
||||||
///
|
///
|
||||||
/// \param address 4 bytes of the address packed into a 32-bits integer
|
/// \param address 4 bytes of the address packed into a 32-bits integer
|
||||||
///
|
///
|
||||||
/// \see toInteger
|
/// \see toInteger
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
explicit IpAddress(Uint32 address);
|
explicit IpAddress(Uint32 address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get a string representation of the address
|
/// \brief Get a string representation of the address
|
||||||
///
|
///
|
||||||
/// The returned string is the decimal representation of the
|
/// The returned string is the decimal representation of the
|
||||||
/// IP address (like "192.168.1.56"), even if it was constructed
|
/// IP address (like "192.168.1.56"), even if it was constructed
|
||||||
/// from a host name.
|
/// from a host name.
|
||||||
///
|
///
|
||||||
/// \return String representation of the address
|
/// \return String representation of the address
|
||||||
///
|
///
|
||||||
/// \see toInteger
|
/// \see toInteger
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get an integer representation of the address
|
/// \brief Get an integer representation of the address
|
||||||
///
|
///
|
||||||
/// The returned number is the internal representation of the
|
/// The returned number is the internal representation of the
|
||||||
/// address, and should be used for optimization purposes only
|
/// address, and should be used for optimization purposes only
|
||||||
/// (like sending the address through a socket).
|
/// (like sending the address through a socket).
|
||||||
/// The integer produced by this function can then be converted
|
/// The integer produced by this function can then be converted
|
||||||
/// back to a sf::IpAddress with the proper constructor.
|
/// back to a sf::IpAddress with the proper constructor.
|
||||||
///
|
///
|
||||||
/// \return 32-bits unsigned integer representation of the address
|
/// \return 32-bits unsigned integer representation of the address
|
||||||
///
|
///
|
||||||
/// \see toString
|
/// \see toString
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Uint32 toInteger() const;
|
Uint32 toInteger() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the computer's local address
|
/// \brief Get the computer's local address
|
||||||
///
|
///
|
||||||
/// The local address is the address of the computer from the
|
/// The local address is the address of the computer from the
|
||||||
/// LAN point of view, i.e. something like 192.168.1.56. It is
|
/// LAN point of view, i.e. something like 192.168.1.56. It is
|
||||||
/// meaningful only for communications over the local network.
|
/// meaningful only for communications over the local network.
|
||||||
/// Unlike getPublicAddress, this function is fast and may be
|
/// Unlike getPublicAddress, this function is fast and may be
|
||||||
/// used safely anywhere.
|
/// used safely anywhere.
|
||||||
///
|
///
|
||||||
/// \return Local IP address of the computer
|
/// \return Local IP address of the computer
|
||||||
///
|
///
|
||||||
/// \see getPublicAddress
|
/// \see getPublicAddress
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static IpAddress getLocalAddress();
|
static IpAddress getLocalAddress();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the computer's public address
|
/// \brief Get the computer's public address
|
||||||
///
|
///
|
||||||
/// The public address is the address of the computer from the
|
/// The public address is the address of the computer from the
|
||||||
/// internet point of view, i.e. something like 89.54.1.169.
|
/// internet point of view, i.e. something like 89.54.1.169.
|
||||||
/// It is necessary for communications over the world wide web.
|
/// It is necessary for communications over the world wide web.
|
||||||
/// The only way to get a public address is to ask it to a
|
/// The only way to get a public address is to ask it to a
|
||||||
/// distant website; as a consequence, this function depends on
|
/// distant website; as a consequence, this function depends on
|
||||||
/// both your network connection and the server, and may be
|
/// both your network connection and the server, and may be
|
||||||
/// very slow. You should use it as few as possible. Because
|
/// very slow. You should use it as few as possible. Because
|
||||||
/// this function depends on the network connection and on a distant
|
/// this function depends on the network connection and on a distant
|
||||||
/// server, you may use a time limit if you don't want your program
|
/// server, you may use a time limit if you don't want your program
|
||||||
/// to be possibly stuck waiting in case there is a problem; this
|
/// to be possibly stuck waiting in case there is a problem; this
|
||||||
/// limit is deactivated by default.
|
/// limit is deactivated by default.
|
||||||
///
|
///
|
||||||
/// \param timeout Maximum time to wait
|
/// \param timeout Maximum time to wait
|
||||||
///
|
///
|
||||||
/// \return Public IP address of the computer
|
/// \return Public IP address of the computer
|
||||||
///
|
///
|
||||||
/// \see getLocalAddress
|
/// \see getLocalAddress
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static IpAddress getPublicAddress(Time timeout = Time::Zero);
|
static IpAddress getPublicAddress(Time timeout = Time::Zero);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Static member data
|
// Static member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static const IpAddress None; ///< Value representing an empty/invalid address
|
static const IpAddress None; ///< Value representing an empty/invalid address
|
||||||
static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally)
|
static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally)
|
||||||
static const IpAddress Broadcast; ///< The "broadcast" address (for sending UDP messages to everyone on a local network)
|
static const IpAddress Broadcast; ///< The "broadcast" address (for sending UDP messages to everyone on a local network)
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Uint32 m_address; ///< Address stored as an unsigned 32 bits integer
|
Uint32 m_address; ///< Address stored as an unsigned 32 bits integer
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of == operator to compare two IP addresses
|
/// \brief Overload of == operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a IP address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a IP address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if both addresses are equal
|
/// \return True if both addresses are equal
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API bool operator ==(const IpAddress& left, const IpAddress& right);
|
SFML_NETWORK_API bool operator ==(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of != operator to compare two IP addresses
|
/// \brief Overload of != operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a IP address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a IP address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if both addresses are different
|
/// \return True if both addresses are different
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API bool operator !=(const IpAddress& left, const IpAddress& right);
|
SFML_NETWORK_API bool operator !=(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of < operator to compare two IP addresses
|
/// \brief Overload of < operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a IP address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a IP address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is lesser than \a right
|
/// \return True if \a left is lesser than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
|
SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of > operator to compare two IP addresses
|
/// \brief Overload of > operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a IP address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a IP address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is greater than \a right
|
/// \return True if \a left is greater than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API bool operator >(const IpAddress& left, const IpAddress& right);
|
SFML_NETWORK_API bool operator >(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of <= operator to compare two IP addresses
|
/// \brief Overload of <= operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a IP address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a IP address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is lesser or equal than \a right
|
/// \return True if \a left is lesser or equal than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API bool operator <=(const IpAddress& left, const IpAddress& right);
|
SFML_NETWORK_API bool operator <=(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of >= operator to compare two IP addresses
|
/// \brief Overload of >= operator to compare two IP addresses
|
||||||
///
|
///
|
||||||
/// \param left Left operand (a IP address)
|
/// \param left Left operand (a IP address)
|
||||||
/// \param right Right operand (a IP address)
|
/// \param right Right operand (a IP address)
|
||||||
///
|
///
|
||||||
/// \return True if \a left is greater or equal than \a right
|
/// \return True if \a left is greater or equal than \a right
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API bool operator >=(const IpAddress& left, const IpAddress& right);
|
SFML_NETWORK_API bool operator >=(const IpAddress& left, const IpAddress& right);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of >> operator to extract an IP address from an input stream
|
/// \brief Overload of >> operator to extract an IP address from an input stream
|
||||||
///
|
///
|
||||||
/// \param stream Input stream
|
/// \param stream Input stream
|
||||||
/// \param address IP address to extract
|
/// \param address IP address to extract
|
||||||
///
|
///
|
||||||
/// \return Reference to the input stream
|
/// \return Reference to the input stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API std::istream& operator >>(std::istream& stream, IpAddress& address);
|
SFML_NETWORK_API std::istream& operator >>(std::istream& stream, IpAddress& address);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of << operator to print an IP address to an output stream
|
/// \brief Overload of << operator to print an IP address to an output stream
|
||||||
///
|
///
|
||||||
/// \param stream Output stream
|
/// \param stream Output stream
|
||||||
/// \param address IP address to print
|
/// \param address IP address to print
|
||||||
///
|
///
|
||||||
/// \return Reference to the output stream
|
/// \return Reference to the output stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_NETWORK_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address);
|
SFML_NETWORK_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address);
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_IPADDRESS_HPP
|
#endif // SFML_IPADDRESS_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::IpAddress
|
/// \class sf::IpAddress
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// sf::IpAddress is a utility class for manipulating network
|
/// sf::IpAddress is a utility class for manipulating network
|
||||||
/// addresses. It provides a set a implicit constructors and
|
/// addresses. It provides a set a implicit constructors and
|
||||||
/// conversion functions to easily build or transform an IP
|
/// conversion functions to easily build or transform an IP
|
||||||
/// address from/to various representations.
|
/// address from/to various representations.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::IpAddress a0; // an invalid address
|
/// sf::IpAddress a0; // an invalid address
|
||||||
/// sf::IpAddress a1 = sf::IpAddress::None; // an invalid address (same as a0)
|
/// sf::IpAddress a1 = sf::IpAddress::None; // an invalid address (same as a0)
|
||||||
/// sf::IpAddress a2("127.0.0.1"); // the local host address
|
/// sf::IpAddress a2("127.0.0.1"); // the local host address
|
||||||
/// sf::IpAddress a3 = sf::IpAddress::Broadcast; // the broadcast address
|
/// sf::IpAddress a3 = sf::IpAddress::Broadcast; // the broadcast address
|
||||||
/// sf::IpAddress a4(192, 168, 1, 56); // a local address
|
/// sf::IpAddress a4(192, 168, 1, 56); // a local address
|
||||||
/// sf::IpAddress a5("my_computer"); // a local address created from a network name
|
/// sf::IpAddress a5("my_computer"); // a local address created from a network name
|
||||||
/// sf::IpAddress a6("89.54.1.169"); // a distant address
|
/// sf::IpAddress a6("89.54.1.169"); // a distant address
|
||||||
/// sf::IpAddress a7("www.google.com"); // a distant address created from a network name
|
/// sf::IpAddress a7("www.google.com"); // a distant address created from a network name
|
||||||
/// sf::IpAddress a8 = sf::IpAddress::getLocalAddress(); // my address on the local network
|
/// sf::IpAddress a8 = sf::IpAddress::getLocalAddress(); // my address on the local network
|
||||||
/// sf::IpAddress a9 = sf::IpAddress::getPublicAddress(); // my address on the internet
|
/// sf::IpAddress a9 = sf::IpAddress::getPublicAddress(); // my address on the internet
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Note that sf::IpAddress currently doesn't support IPv6
|
/// Note that sf::IpAddress currently doesn't support IPv6
|
||||||
/// nor other types of network addresses.
|
/// nor other types of network addresses.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,407 +1,407 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_PACKET_HPP
|
#ifndef SFML_PACKET_HPP
|
||||||
#define SFML_PACKET_HPP
|
#define SFML_PACKET_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class String;
|
class String;
|
||||||
class TcpSocket;
|
class TcpSocket;
|
||||||
class UdpSocket;
|
class UdpSocket;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Utility class to build blocks of data to transfer
|
/// \brief Utility class to build blocks of data to transfer
|
||||||
/// over the network
|
/// over the network
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API Packet
|
class SFML_NETWORK_API Packet
|
||||||
{
|
{
|
||||||
// A bool-like type that cannot be converted to integer or pointer types
|
// A bool-like type that cannot be converted to integer or pointer types
|
||||||
typedef bool (Packet::*BoolType)(std::size_t);
|
typedef bool (Packet::*BoolType)(std::size_t);
|
||||||
|
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Creates an empty packet.
|
/// Creates an empty packet.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet();
|
Packet();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Virtual destructor
|
/// \brief Virtual destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~Packet();
|
virtual ~Packet();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Append data to the end of the packet
|
/// \brief Append data to the end of the packet
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the sequence of bytes to append
|
/// \param data Pointer to the sequence of bytes to append
|
||||||
/// \param sizeInBytes Number of bytes to append
|
/// \param sizeInBytes Number of bytes to append
|
||||||
///
|
///
|
||||||
/// \see clear
|
/// \see clear
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void append(const void* data, std::size_t sizeInBytes);
|
void append(const void* data, std::size_t sizeInBytes);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Clear the packet
|
/// \brief Clear the packet
|
||||||
///
|
///
|
||||||
/// After calling Clear, the packet is empty.
|
/// After calling Clear, the packet is empty.
|
||||||
///
|
///
|
||||||
/// \see append
|
/// \see append
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get a pointer to the data contained in the packet
|
/// \brief Get a pointer to the data contained in the packet
|
||||||
///
|
///
|
||||||
/// Warning: the returned pointer may become invalid after
|
/// Warning: the returned pointer may become invalid after
|
||||||
/// you append data to the packet, therefore it should never
|
/// you append data to the packet, therefore it should never
|
||||||
/// be stored.
|
/// be stored.
|
||||||
/// The return pointer is NULL if the packet is empty.
|
/// The return pointer is NULL if the packet is empty.
|
||||||
///
|
///
|
||||||
/// \return Pointer to the data
|
/// \return Pointer to the data
|
||||||
///
|
///
|
||||||
/// \see getDataSize
|
/// \see getDataSize
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const void* getData() const;
|
const void* getData() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the size of the data contained in the packet
|
/// \brief Get the size of the data contained in the packet
|
||||||
///
|
///
|
||||||
/// This function returns the number of bytes pointed to by
|
/// This function returns the number of bytes pointed to by
|
||||||
/// what getData returns.
|
/// what getData returns.
|
||||||
///
|
///
|
||||||
/// \return Data size, in bytes
|
/// \return Data size, in bytes
|
||||||
///
|
///
|
||||||
/// \see getData
|
/// \see getData
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::size_t getDataSize() const;
|
std::size_t getDataSize() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell if the reading position has reached the
|
/// \brief Tell if the reading position has reached the
|
||||||
/// end of the packet
|
/// end of the packet
|
||||||
///
|
///
|
||||||
/// This function is useful to know if there is some data
|
/// This function is useful to know if there is some data
|
||||||
/// left to be read, without actually reading it.
|
/// left to be read, without actually reading it.
|
||||||
///
|
///
|
||||||
/// \return True if all data was read, false otherwise
|
/// \return True if all data was read, false otherwise
|
||||||
///
|
///
|
||||||
/// \see operator bool
|
/// \see operator bool
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool endOfPacket() const;
|
bool endOfPacket() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Test the validity of the packet, for reading
|
/// \brief Test the validity of the packet, for reading
|
||||||
///
|
///
|
||||||
/// This operator allows to test the packet as a boolean
|
/// This operator allows to test the packet as a boolean
|
||||||
/// variable, to check if a reading operation was successful.
|
/// variable, to check if a reading operation was successful.
|
||||||
///
|
///
|
||||||
/// A packet will be in an invalid state if it has no more
|
/// A packet will be in an invalid state if it has no more
|
||||||
/// data to read.
|
/// data to read.
|
||||||
///
|
///
|
||||||
/// This behaviour is the same as standard C++ streams.
|
/// This behaviour is the same as standard C++ streams.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// float x;
|
/// float x;
|
||||||
/// packet >> x;
|
/// packet >> x;
|
||||||
/// if (packet)
|
/// if (packet)
|
||||||
/// {
|
/// {
|
||||||
/// // ok, x was extracted successfully
|
/// // ok, x was extracted successfully
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // -- or --
|
/// // -- or --
|
||||||
///
|
///
|
||||||
/// float x;
|
/// float x;
|
||||||
/// if (packet >> x)
|
/// if (packet >> x)
|
||||||
/// {
|
/// {
|
||||||
/// // ok, x was extracted successfully
|
/// // ok, x was extracted successfully
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Don't focus on the return type, it's equivalent to bool but
|
/// Don't focus on the return type, it's equivalent to bool but
|
||||||
/// it disallows unwanted implicit conversions to integer or
|
/// it disallows unwanted implicit conversions to integer or
|
||||||
/// pointer types.
|
/// pointer types.
|
||||||
///
|
///
|
||||||
/// \return True if last data extraction from packet was successful
|
/// \return True if last data extraction from packet was successful
|
||||||
///
|
///
|
||||||
/// \see endOfPacket
|
/// \see endOfPacket
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
operator BoolType() const;
|
operator BoolType() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Overloads of operator >> to read data from the packet
|
/// Overloads of operator >> to read data from the packet
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& operator >>(bool& data);
|
Packet& operator >>(bool& data);
|
||||||
Packet& operator >>(Int8& data);
|
Packet& operator >>(Int8& data);
|
||||||
Packet& operator >>(Uint8& data);
|
Packet& operator >>(Uint8& data);
|
||||||
Packet& operator >>(Int16& data);
|
Packet& operator >>(Int16& data);
|
||||||
Packet& operator >>(Uint16& data);
|
Packet& operator >>(Uint16& data);
|
||||||
Packet& operator >>(Int32& data);
|
Packet& operator >>(Int32& data);
|
||||||
Packet& operator >>(Uint32& data);
|
Packet& operator >>(Uint32& data);
|
||||||
Packet& operator >>(float& data);
|
Packet& operator >>(float& data);
|
||||||
Packet& operator >>(double& data);
|
Packet& operator >>(double& data);
|
||||||
Packet& operator >>(char* data);
|
Packet& operator >>(char* data);
|
||||||
Packet& operator >>(std::string& data);
|
Packet& operator >>(std::string& data);
|
||||||
Packet& operator >>(wchar_t* data);
|
Packet& operator >>(wchar_t* data);
|
||||||
Packet& operator >>(std::wstring& data);
|
Packet& operator >>(std::wstring& data);
|
||||||
Packet& operator >>(String& data);
|
Packet& operator >>(String& data);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Overloads of operator << to write data into the packet
|
/// Overloads of operator << to write data into the packet
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& operator <<(bool data);
|
Packet& operator <<(bool data);
|
||||||
Packet& operator <<(Int8 data);
|
Packet& operator <<(Int8 data);
|
||||||
Packet& operator <<(Uint8 data);
|
Packet& operator <<(Uint8 data);
|
||||||
Packet& operator <<(Int16 data);
|
Packet& operator <<(Int16 data);
|
||||||
Packet& operator <<(Uint16 data);
|
Packet& operator <<(Uint16 data);
|
||||||
Packet& operator <<(Int32 data);
|
Packet& operator <<(Int32 data);
|
||||||
Packet& operator <<(Uint32 data);
|
Packet& operator <<(Uint32 data);
|
||||||
Packet& operator <<(float data);
|
Packet& operator <<(float data);
|
||||||
Packet& operator <<(double data);
|
Packet& operator <<(double data);
|
||||||
Packet& operator <<(const char* data);
|
Packet& operator <<(const char* data);
|
||||||
Packet& operator <<(const std::string& data);
|
Packet& operator <<(const std::string& data);
|
||||||
Packet& operator <<(const wchar_t* data);
|
Packet& operator <<(const wchar_t* data);
|
||||||
Packet& operator <<(const std::wstring& data);
|
Packet& operator <<(const std::wstring& data);
|
||||||
Packet& operator <<(const String& data);
|
Packet& operator <<(const String& data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
friend class TcpSocket;
|
friend class TcpSocket;
|
||||||
friend class UdpSocket;
|
friend class UdpSocket;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Called before the packet is sent over the network
|
/// \brief Called before the packet is sent over the network
|
||||||
///
|
///
|
||||||
/// This function can be defined by derived classes to
|
/// This function can be defined by derived classes to
|
||||||
/// transform the data before it is sent; this can be
|
/// transform the data before it is sent; this can be
|
||||||
/// used for compression, encryption, etc.
|
/// used for compression, encryption, etc.
|
||||||
/// The function must return a pointer to the modified data,
|
/// The function must return a pointer to the modified data,
|
||||||
/// as well as the number of bytes pointed.
|
/// as well as the number of bytes pointed.
|
||||||
/// The default implementation provides the packet's data
|
/// The default implementation provides the packet's data
|
||||||
/// without transforming it.
|
/// without transforming it.
|
||||||
///
|
///
|
||||||
/// \param size Variable to fill with the size of data to send
|
/// \param size Variable to fill with the size of data to send
|
||||||
///
|
///
|
||||||
/// \return Pointer to the array of bytes to send
|
/// \return Pointer to the array of bytes to send
|
||||||
///
|
///
|
||||||
/// \see onReceive
|
/// \see onReceive
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual const void* onSend(std::size_t& size);
|
virtual const void* onSend(std::size_t& size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Called after the packet is received over the network
|
/// \brief Called after the packet is received over the network
|
||||||
///
|
///
|
||||||
/// This function can be defined by derived classes to
|
/// This function can be defined by derived classes to
|
||||||
/// transform the data after it is received; this can be
|
/// transform the data after it is received; this can be
|
||||||
/// used for uncompression, decryption, etc.
|
/// used for uncompression, decryption, etc.
|
||||||
/// The function receives a pointer to the received data,
|
/// The function receives a pointer to the received data,
|
||||||
/// and must fill the packet with the transformed bytes.
|
/// and must fill the packet with the transformed bytes.
|
||||||
/// The default implementation fills the packet directly
|
/// The default implementation fills the packet directly
|
||||||
/// without transforming the data.
|
/// without transforming the data.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the received bytes
|
/// \param data Pointer to the received bytes
|
||||||
/// \param size Number of bytes
|
/// \param size Number of bytes
|
||||||
///
|
///
|
||||||
/// \see onSend
|
/// \see onSend
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual void onReceive(const void* data, std::size_t size);
|
virtual void onReceive(const void* data, std::size_t size);
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Disallow comparisons between packets
|
/// Disallow comparisons between packets
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator ==(const Packet& right) const;
|
bool operator ==(const Packet& right) const;
|
||||||
bool operator !=(const Packet& right) const;
|
bool operator !=(const Packet& right) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check if the packet can extract a given number of bytes
|
/// \brief Check if the packet can extract a given number of bytes
|
||||||
///
|
///
|
||||||
/// This function updates accordingly the state of the packet.
|
/// This function updates accordingly the state of the packet.
|
||||||
///
|
///
|
||||||
/// \param size Size to check
|
/// \param size Size to check
|
||||||
///
|
///
|
||||||
/// \return True if \a size bytes can be read from the packet
|
/// \return True if \a size bytes can be read from the packet
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool checkSize(std::size_t size);
|
bool checkSize(std::size_t size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::vector<char> m_data; ///< Data stored in the packet
|
std::vector<char> m_data; ///< Data stored in the packet
|
||||||
std::size_t m_readPos; ///< Current reading position in the packet
|
std::size_t m_readPos; ///< Current reading position in the packet
|
||||||
bool m_isValid; ///< Reading state of the packet
|
bool m_isValid; ///< Reading state of the packet
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_PACKET_HPP
|
#endif // SFML_PACKET_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Packet
|
/// \class sf::Packet
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// Packets provide a safe and easy way to serialize data,
|
/// Packets provide a safe and easy way to serialize data,
|
||||||
/// in order to send it over the network using sockets
|
/// in order to send it over the network using sockets
|
||||||
/// (sf::TcpSocket, sf::UdpSocket).
|
/// (sf::TcpSocket, sf::UdpSocket).
|
||||||
///
|
///
|
||||||
/// Packets solve 2 fundamental problems that arise when
|
/// Packets solve 2 fundamental problems that arise when
|
||||||
/// transfering data over the network:
|
/// transfering data over the network:
|
||||||
/// \li data is interpreted correctly according to the endianness
|
/// \li data is interpreted correctly according to the endianness
|
||||||
/// \li the bounds of the packet are preserved (one send == one receive)
|
/// \li the bounds of the packet are preserved (one send == one receive)
|
||||||
///
|
///
|
||||||
/// The sf::Packet class provides both input and output modes.
|
/// The sf::Packet class provides both input and output modes.
|
||||||
/// It is designed to follow the behaviour of standard C++ streams,
|
/// It is designed to follow the behaviour of standard C++ streams,
|
||||||
/// using operators >> and << to extract and insert data.
|
/// using operators >> and << to extract and insert data.
|
||||||
///
|
///
|
||||||
/// It is recommended to use only fixed-size types (like sf::Int32, etc.),
|
/// It is recommended to use only fixed-size types (like sf::Int32, etc.),
|
||||||
/// to avoid possible differences between the sender and the receiver.
|
/// to avoid possible differences between the sender and the receiver.
|
||||||
/// Indeed, the native C++ types may have different sizes on two platforms
|
/// Indeed, the native C++ types may have different sizes on two platforms
|
||||||
/// and your data may be corrupted if that happens.
|
/// and your data may be corrupted if that happens.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::Uint32 x = 24;
|
/// sf::Uint32 x = 24;
|
||||||
/// std::string s = "hello";
|
/// std::string s = "hello";
|
||||||
/// double d = 5.89;
|
/// double d = 5.89;
|
||||||
///
|
///
|
||||||
/// // Group the variables to send into a packet
|
/// // Group the variables to send into a packet
|
||||||
/// sf::Packet packet;
|
/// sf::Packet packet;
|
||||||
/// packet << x << s << d;
|
/// packet << x << s << d;
|
||||||
///
|
///
|
||||||
/// // Send it over the network (socket is a valid sf::TcpSocket)
|
/// // Send it over the network (socket is a valid sf::TcpSocket)
|
||||||
/// socket.send(packet);
|
/// socket.send(packet);
|
||||||
///
|
///
|
||||||
/// -----------------------------------------------------------------
|
/// -----------------------------------------------------------------
|
||||||
///
|
///
|
||||||
/// // Receive the packet at the other end
|
/// // Receive the packet at the other end
|
||||||
/// sf::Packet packet;
|
/// sf::Packet packet;
|
||||||
/// socket.receive(packet);
|
/// socket.receive(packet);
|
||||||
///
|
///
|
||||||
/// // Extract the variables contained in the packet
|
/// // Extract the variables contained in the packet
|
||||||
/// sf::Uint32 x;
|
/// sf::Uint32 x;
|
||||||
/// std::string s;
|
/// std::string s;
|
||||||
/// double d;
|
/// double d;
|
||||||
/// if (packet >> x >> s >> d)
|
/// if (packet >> x >> s >> d)
|
||||||
/// {
|
/// {
|
||||||
/// // Data extracted successfully...
|
/// // Data extracted successfully...
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Packets have built-in operator >> and << overloads for
|
/// Packets have built-in operator >> and << overloads for
|
||||||
/// standard types:
|
/// standard types:
|
||||||
/// \li bool
|
/// \li bool
|
||||||
/// \li fixed-size integer types (sf::Int8/16/32, sf::Uint8/16/32)
|
/// \li fixed-size integer types (sf::Int8/16/32, sf::Uint8/16/32)
|
||||||
/// \li floating point numbers (float, double)
|
/// \li floating point numbers (float, double)
|
||||||
/// \li string types (char*, wchar_t*, std::string, std::wstring, sf::String)
|
/// \li string types (char*, wchar_t*, std::string, std::wstring, sf::String)
|
||||||
///
|
///
|
||||||
/// Like standard streams, it is also possible to define your own
|
/// Like standard streams, it is also possible to define your own
|
||||||
/// overloads of operators >> and << in order to handle your
|
/// overloads of operators >> and << in order to handle your
|
||||||
/// custom types.
|
/// custom types.
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// struct MyStruct
|
/// struct MyStruct
|
||||||
/// {
|
/// {
|
||||||
/// float number;
|
/// float number;
|
||||||
/// sf::Int8 integer;
|
/// sf::Int8 integer;
|
||||||
/// std::string str;
|
/// std::string str;
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// sf::Packet& operator <<(sf::Packet& packet, const MyStruct& m)
|
/// sf::Packet& operator <<(sf::Packet& packet, const MyStruct& m)
|
||||||
/// {
|
/// {
|
||||||
/// return packet << m.number << m.integer << m.str;
|
/// return packet << m.number << m.integer << m.str;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// sf::Packet& operator >>(sf::Packet& packet, MyStruct& m)
|
/// sf::Packet& operator >>(sf::Packet& packet, MyStruct& m)
|
||||||
/// {
|
/// {
|
||||||
/// return packet >> m.number >> m.integer >> m.str;
|
/// return packet >> m.number >> m.integer >> m.str;
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Packets also provide an extra feature that allows to apply
|
/// Packets also provide an extra feature that allows to apply
|
||||||
/// custom transformations to the data before it is sent,
|
/// custom transformations to the data before it is sent,
|
||||||
/// and after it is received. This is typically used to
|
/// and after it is received. This is typically used to
|
||||||
/// handle automatic compression or encryption of the data.
|
/// handle automatic compression or encryption of the data.
|
||||||
/// This is achieved by inheriting from sf::Packet, and overriding
|
/// This is achieved by inheriting from sf::Packet, and overriding
|
||||||
/// the onSend and onReceive functions.
|
/// the onSend and onReceive functions.
|
||||||
///
|
///
|
||||||
/// Here is an example:
|
/// Here is an example:
|
||||||
/// \code
|
/// \code
|
||||||
/// class ZipPacket : public sf::Packet
|
/// class ZipPacket : public sf::Packet
|
||||||
/// {
|
/// {
|
||||||
/// virtual const void* onSend(std::size_t& size)
|
/// virtual const void* onSend(std::size_t& size)
|
||||||
/// {
|
/// {
|
||||||
/// const void* srcData = getData();
|
/// const void* srcData = getData();
|
||||||
/// std::size_t srcSize = getDataSize();
|
/// std::size_t srcSize = getDataSize();
|
||||||
///
|
///
|
||||||
/// return MySuperZipFunction(srcData, srcSize, &size);
|
/// return MySuperZipFunction(srcData, srcSize, &size);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// virtual void onReceive(const void* data, std::size_t size)
|
/// virtual void onReceive(const void* data, std::size_t size)
|
||||||
/// {
|
/// {
|
||||||
/// std::size_t dstSize;
|
/// std::size_t dstSize;
|
||||||
/// const void* dstData = MySuperUnzipFunction(data, size, &dstSize);
|
/// const void* dstData = MySuperUnzipFunction(data, size, &dstSize);
|
||||||
///
|
///
|
||||||
/// append(dstData, dstSize);
|
/// append(dstData, dstSize);
|
||||||
/// }
|
/// }
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// // Use like regular packets:
|
/// // Use like regular packets:
|
||||||
/// ZipPacket packet;
|
/// ZipPacket packet;
|
||||||
/// packet << x << s << d;
|
/// packet << x << s << d;
|
||||||
/// ...
|
/// ...
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::TcpSocket, sf::UdpSocket
|
/// \see sf::TcpSocket, sf::UdpSocket
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,218 +1,218 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOCKET_HPP
|
#ifndef SFML_SOCKET_HPP
|
||||||
#define SFML_SOCKET_HPP
|
#define SFML_SOCKET_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <SFML/Network/SocketHandle.hpp>
|
#include <SFML/Network/SocketHandle.hpp>
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class SocketSelector;
|
class SocketSelector;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Base class for all the socket types
|
/// \brief Base class for all the socket types
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API Socket : NonCopyable
|
class SFML_NETWORK_API Socket : NonCopyable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Status codes that may be returned by socket functions
|
/// \brief Status codes that may be returned by socket functions
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum Status
|
enum Status
|
||||||
{
|
{
|
||||||
Done, ///< The socket has sent / received the data
|
Done, ///< The socket has sent / received the data
|
||||||
NotReady, ///< The socket is not ready to send / receive data yet
|
NotReady, ///< The socket is not ready to send / receive data yet
|
||||||
Disconnected, ///< The TCP socket has been disconnected
|
Disconnected, ///< The TCP socket has been disconnected
|
||||||
Error ///< An unexpected error happened
|
Error ///< An unexpected error happened
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Some special values used by sockets
|
/// \brief Some special values used by sockets
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
AnyPort = 0 ///< Special value that tells the system to pick any available port
|
AnyPort = 0 ///< Special value that tells the system to pick any available port
|
||||||
};
|
};
|
||||||
|
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
virtual ~Socket();
|
virtual ~Socket();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the blocking state of the socket
|
/// \brief Set the blocking state of the socket
|
||||||
///
|
///
|
||||||
/// In blocking mode, calls will not return until they have
|
/// In blocking mode, calls will not return until they have
|
||||||
/// completed their task. For example, a call to Receive in
|
/// completed their task. For example, a call to Receive in
|
||||||
/// blocking mode won't return until some data was actually
|
/// blocking mode won't return until some data was actually
|
||||||
/// received.
|
/// received.
|
||||||
/// In non-blocking mode, calls will always return immediately,
|
/// In non-blocking mode, calls will always return immediately,
|
||||||
/// using the return code to signal whether there was data
|
/// using the return code to signal whether there was data
|
||||||
/// available or not.
|
/// available or not.
|
||||||
/// By default, all sockets are blocking.
|
/// By default, all sockets are blocking.
|
||||||
///
|
///
|
||||||
/// \param blocking True to set the socket as blocking, false for non-blocking
|
/// \param blocking True to set the socket as blocking, false for non-blocking
|
||||||
///
|
///
|
||||||
/// \see isBlocking
|
/// \see isBlocking
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setBlocking(bool blocking);
|
void setBlocking(bool blocking);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether the socket is in blocking or non-blocking mode
|
/// \brief Tell whether the socket is in blocking or non-blocking mode
|
||||||
///
|
///
|
||||||
/// \return True if the socket is blocking, false otherwise
|
/// \return True if the socket is blocking, false otherwise
|
||||||
///
|
///
|
||||||
/// \see setBlocking
|
/// \see setBlocking
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool isBlocking() const;
|
bool isBlocking() const;
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Types of protocols that the socket can use
|
/// \brief Types of protocols that the socket can use
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
Tcp, ///< TCP protocol
|
Tcp, ///< TCP protocol
|
||||||
Udp ///< UDP protocol
|
Udp ///< UDP protocol
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// This constructor can only be accessed by derived classes.
|
/// This constructor can only be accessed by derived classes.
|
||||||
///
|
///
|
||||||
/// \param type Type of the socket (TCP or UDP)
|
/// \param type Type of the socket (TCP or UDP)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Socket(Type type);
|
Socket(Type type);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Return the internal handle of the socket
|
/// \brief Return the internal handle of the socket
|
||||||
///
|
///
|
||||||
/// The returned handle may be invalid if the socket
|
/// The returned handle may be invalid if the socket
|
||||||
/// was not created yet (or already destroyed).
|
/// was not created yet (or already destroyed).
|
||||||
/// This function can only be accessed by derived classes.
|
/// This function can only be accessed by derived classes.
|
||||||
///
|
///
|
||||||
/// \return The internal (OS-specific) handle of the socket
|
/// \return The internal (OS-specific) handle of the socket
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketHandle getHandle() const;
|
SocketHandle getHandle() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create the internal representation of the socket
|
/// \brief Create the internal representation of the socket
|
||||||
///
|
///
|
||||||
/// This function can only be accessed by derived classes.
|
/// This function can only be accessed by derived classes.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void create();
|
void create();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Create the internal representation of the socket
|
/// \brief Create the internal representation of the socket
|
||||||
/// from a socket handle
|
/// from a socket handle
|
||||||
///
|
///
|
||||||
/// This function can only be accessed by derived classes.
|
/// This function can only be accessed by derived classes.
|
||||||
///
|
///
|
||||||
/// \param handle OS-specific handle of the socket to wrap
|
/// \param handle OS-specific handle of the socket to wrap
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void create(SocketHandle handle);
|
void create(SocketHandle handle);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Close the socket gracefully
|
/// \brief Close the socket gracefully
|
||||||
///
|
///
|
||||||
/// This function can only be accessed by derived classes.
|
/// This function can only be accessed by derived classes.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
friend class SocketSelector;
|
friend class SocketSelector;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Type m_type; ///< Type of the socket (TCP or UDP)
|
Type m_type; ///< Type of the socket (TCP or UDP)
|
||||||
SocketHandle m_socket; ///< Socket descriptor
|
SocketHandle m_socket; ///< Socket descriptor
|
||||||
bool m_isBlocking; ///< Current blocking mode of the socket
|
bool m_isBlocking; ///< Current blocking mode of the socket
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOCKET_HPP
|
#endif // SFML_SOCKET_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Socket
|
/// \class sf::Socket
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// This class mainly defines internal stuff to be used by
|
/// This class mainly defines internal stuff to be used by
|
||||||
/// derived classes.
|
/// derived classes.
|
||||||
///
|
///
|
||||||
/// The only public features that it defines, and which
|
/// The only public features that it defines, and which
|
||||||
/// is therefore common to all the socket classes, is the
|
/// is therefore common to all the socket classes, is the
|
||||||
/// blocking state. All sockets can be set as blocking or
|
/// blocking state. All sockets can be set as blocking or
|
||||||
/// non-blocking.
|
/// non-blocking.
|
||||||
///
|
///
|
||||||
/// In blocking mode, socket functions will hang until
|
/// In blocking mode, socket functions will hang until
|
||||||
/// the operation completes, which means that the entire
|
/// the operation completes, which means that the entire
|
||||||
/// program (well, in fact the current thread if you use
|
/// program (well, in fact the current thread if you use
|
||||||
/// multiple ones) will be stuck waiting for your socket
|
/// multiple ones) will be stuck waiting for your socket
|
||||||
/// operation to complete.
|
/// operation to complete.
|
||||||
///
|
///
|
||||||
/// In non-blocking mode, all the socket functions will
|
/// In non-blocking mode, all the socket functions will
|
||||||
/// return immediately. If the socket is not ready to complete
|
/// return immediately. If the socket is not ready to complete
|
||||||
/// the requested operation, the function simply returns
|
/// the requested operation, the function simply returns
|
||||||
/// the proper status code (Socket::NotReady).
|
/// the proper status code (Socket::NotReady).
|
||||||
///
|
///
|
||||||
/// The default mode, which is blocking, is the one that is
|
/// The default mode, which is blocking, is the one that is
|
||||||
/// generally used, in combination with threads or selectors.
|
/// generally used, in combination with threads or selectors.
|
||||||
/// The non-blocking mode is rather used in real-time
|
/// The non-blocking mode is rather used in real-time
|
||||||
/// applications that run an endless loop that can poll
|
/// applications that run an endless loop that can poll
|
||||||
/// the socket often enough, and cannot afford blocking
|
/// the socket often enough, and cannot afford blocking
|
||||||
/// this loop.
|
/// this loop.
|
||||||
///
|
///
|
||||||
/// \see sf::TcpListener, sf::TcpSocket, sf::UdpSocket
|
/// \see sf::TcpListener, sf::TcpSocket, sf::UdpSocket
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,57 +1,57 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOCKETHANDLE_HPP
|
#ifndef SFML_SOCKETHANDLE_HPP
|
||||||
#define SFML_SOCKETHANDLE_HPP
|
#define SFML_SOCKETHANDLE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Config.hpp>
|
#include <SFML/Config.hpp>
|
||||||
|
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
#if defined(SFML_SYSTEM_WINDOWS)
|
||||||
#include <basetsd.h>
|
#include <basetsd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Define the low-level socket handle type, specific to
|
// Define the low-level socket handle type, specific to
|
||||||
// each platform
|
// each platform
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
#if defined(SFML_SYSTEM_WINDOWS)
|
||||||
|
|
||||||
typedef UINT_PTR SocketHandle;
|
typedef UINT_PTR SocketHandle;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
typedef int SocketHandle;
|
typedef int SocketHandle;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOCKETHANDLE_HPP
|
#endif // SFML_SOCKETHANDLE_HPP
|
||||||
|
|
|
@ -1,263 +1,263 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SOCKETSELECTOR_HPP
|
#ifndef SFML_SOCKETSELECTOR_HPP
|
||||||
#define SFML_SOCKETSELECTOR_HPP
|
#define SFML_SOCKETSELECTOR_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class Socket;
|
class Socket;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Multiplexer that allows to read from multiple sockets
|
/// \brief Multiplexer that allows to read from multiple sockets
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API SocketSelector
|
class SFML_NETWORK_API SocketSelector
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketSelector();
|
SocketSelector();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy constructor
|
/// \brief Copy constructor
|
||||||
///
|
///
|
||||||
/// \param copy Instance to copy
|
/// \param copy Instance to copy
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketSelector(const SocketSelector& copy);
|
SocketSelector(const SocketSelector& copy);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~SocketSelector();
|
~SocketSelector();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Add a new socket to the selector
|
/// \brief Add a new socket to the selector
|
||||||
///
|
///
|
||||||
/// This function keeps a weak reference to the socket,
|
/// This function keeps a weak reference to the socket,
|
||||||
/// so you have to make sure that the socket is not destroyed
|
/// so you have to make sure that the socket is not destroyed
|
||||||
/// while it is stored in the selector.
|
/// while it is stored in the selector.
|
||||||
/// This function does nothing if the socket is not valid.
|
/// This function does nothing if the socket is not valid.
|
||||||
///
|
///
|
||||||
/// \param socket Reference to the socket to add
|
/// \param socket Reference to the socket to add
|
||||||
///
|
///
|
||||||
/// \see remove, clear
|
/// \see remove, clear
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void add(Socket& socket);
|
void add(Socket& socket);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Remove a socket from the selector
|
/// \brief Remove a socket from the selector
|
||||||
///
|
///
|
||||||
/// This function doesn't destroy the socket, it simply
|
/// This function doesn't destroy the socket, it simply
|
||||||
/// removes the reference that the selector has to it.
|
/// removes the reference that the selector has to it.
|
||||||
///
|
///
|
||||||
/// \param socket Reference to the socket to remove
|
/// \param socket Reference to the socket to remove
|
||||||
///
|
///
|
||||||
/// \see add, clear
|
/// \see add, clear
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void remove(Socket& socket);
|
void remove(Socket& socket);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Remove all the sockets stored in the selector
|
/// \brief Remove all the sockets stored in the selector
|
||||||
///
|
///
|
||||||
/// This function doesn't destroy any instance, it simply
|
/// This function doesn't destroy any instance, it simply
|
||||||
/// removes all the references that the selector has to
|
/// removes all the references that the selector has to
|
||||||
/// external sockets.
|
/// external sockets.
|
||||||
///
|
///
|
||||||
/// \see add, remove
|
/// \see add, remove
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Wait until one or more sockets are ready to receive
|
/// \brief Wait until one or more sockets are ready to receive
|
||||||
///
|
///
|
||||||
/// This function returns as soon as at least one socket has
|
/// This function returns as soon as at least one socket has
|
||||||
/// some data available to be received. To know which sockets are
|
/// some data available to be received. To know which sockets are
|
||||||
/// ready, use the isReady function.
|
/// ready, use the isReady function.
|
||||||
/// If you use a timeout and no socket is ready before the timeout
|
/// If you use a timeout and no socket is ready before the timeout
|
||||||
/// is over, the function returns false.
|
/// is over, the function returns false.
|
||||||
///
|
///
|
||||||
/// \param timeout Maximum time to wait, (use Time::Zero for infinity)
|
/// \param timeout Maximum time to wait, (use Time::Zero for infinity)
|
||||||
///
|
///
|
||||||
/// \return True if there are sockets ready, false otherwise
|
/// \return True if there are sockets ready, false otherwise
|
||||||
///
|
///
|
||||||
/// \see isReady
|
/// \see isReady
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool wait(Time timeout = Time::Zero);
|
bool wait(Time timeout = Time::Zero);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Test a socket to know if it is ready to receive data
|
/// \brief Test a socket to know if it is ready to receive data
|
||||||
///
|
///
|
||||||
/// This function must be used after a call to Wait, to know
|
/// This function must be used after a call to Wait, to know
|
||||||
/// which sockets are ready to receive data. If a socket is
|
/// which sockets are ready to receive data. If a socket is
|
||||||
/// ready, a call to receive will never block because we know
|
/// ready, a call to receive will never block because we know
|
||||||
/// that there is data available to read.
|
/// that there is data available to read.
|
||||||
/// Note that if this function returns true for a TcpListener,
|
/// Note that if this function returns true for a TcpListener,
|
||||||
/// this means that it is ready to accept a new connection.
|
/// this means that it is ready to accept a new connection.
|
||||||
///
|
///
|
||||||
/// \param socket Socket to test
|
/// \param socket Socket to test
|
||||||
///
|
///
|
||||||
/// \return True if the socket is ready to read, false otherwise
|
/// \return True if the socket is ready to read, false otherwise
|
||||||
///
|
///
|
||||||
/// \see isReady
|
/// \see isReady
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool isReady(Socket& socket) const;
|
bool isReady(Socket& socket) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Overload of assignment operator
|
/// \brief Overload of assignment operator
|
||||||
///
|
///
|
||||||
/// \param right Instance to assign
|
/// \param right Instance to assign
|
||||||
///
|
///
|
||||||
/// \return Reference to self
|
/// \return Reference to self
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketSelector& operator =(const SocketSelector& right);
|
SocketSelector& operator =(const SocketSelector& right);
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
struct SocketSelectorImpl;
|
struct SocketSelectorImpl;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SocketSelectorImpl* m_impl; ///< Opaque pointer to the implementation (which requires OS-specific types)
|
SocketSelectorImpl* m_impl; ///< Opaque pointer to the implementation (which requires OS-specific types)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SOCKETSELECTOR_HPP
|
#endif // SFML_SOCKETSELECTOR_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::SocketSelector
|
/// \class sf::SocketSelector
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// Socket selectors provide a way to wait until some data is
|
/// Socket selectors provide a way to wait until some data is
|
||||||
/// available on a set of sockets, instead of just one. This
|
/// available on a set of sockets, instead of just one. This
|
||||||
/// is convenient when you have multiple sockets that may
|
/// is convenient when you have multiple sockets that may
|
||||||
/// possibly receive data, but you don't know which one will
|
/// possibly receive data, but you don't know which one will
|
||||||
/// be ready first. In particular, it avoids to use a thread
|
/// be ready first. In particular, it avoids to use a thread
|
||||||
/// for each socket; with selectors, a single thread can handle
|
/// for each socket; with selectors, a single thread can handle
|
||||||
/// all the sockets.
|
/// all the sockets.
|
||||||
///
|
///
|
||||||
/// All types of sockets can be used in a selector:
|
/// All types of sockets can be used in a selector:
|
||||||
/// \li sf::TcpListener
|
/// \li sf::TcpListener
|
||||||
/// \li sf::TcpSocket
|
/// \li sf::TcpSocket
|
||||||
/// \li sf::UdpSocket
|
/// \li sf::UdpSocket
|
||||||
///
|
///
|
||||||
/// A selector doesn't store its own copies of the sockets
|
/// A selector doesn't store its own copies of the sockets
|
||||||
/// (socket classes are not copyable anyway), it simply keeps
|
/// (socket classes are not copyable anyway), it simply keeps
|
||||||
/// a reference to the original sockets that you pass to the
|
/// a reference to the original sockets that you pass to the
|
||||||
/// "add" function. Therefore, you can't use the selector as a
|
/// "add" function. Therefore, you can't use the selector as a
|
||||||
/// socket container, you must store them oustide and make sure
|
/// socket container, you must store them oustide and make sure
|
||||||
/// that they are alive as long as they are used in the selector.
|
/// that they are alive as long as they are used in the selector.
|
||||||
///
|
///
|
||||||
/// Using a selector is simple:
|
/// Using a selector is simple:
|
||||||
/// \li populate the selector with all the sockets that you want to observe
|
/// \li populate the selector with all the sockets that you want to observe
|
||||||
/// \li make it wait until there is data available on any of the sockets
|
/// \li make it wait until there is data available on any of the sockets
|
||||||
/// \li test each socket to find out which ones are ready
|
/// \li test each socket to find out which ones are ready
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Create a socket to listen to new connections
|
/// // Create a socket to listen to new connections
|
||||||
/// sf::TcpListener listener;
|
/// sf::TcpListener listener;
|
||||||
/// listener.listen(55001);
|
/// listener.listen(55001);
|
||||||
///
|
///
|
||||||
/// // Create a list to store the future clients
|
/// // Create a list to store the future clients
|
||||||
/// std::list<sf::TcpSocket*> clients;
|
/// std::list<sf::TcpSocket*> clients;
|
||||||
///
|
///
|
||||||
/// // Create a selector
|
/// // Create a selector
|
||||||
/// sf::SocketSelector selector;
|
/// sf::SocketSelector selector;
|
||||||
///
|
///
|
||||||
/// // Add the listener to the selector
|
/// // Add the listener to the selector
|
||||||
/// selector.add(listener);
|
/// selector.add(listener);
|
||||||
///
|
///
|
||||||
/// // Endless loop that waits for new connections
|
/// // Endless loop that waits for new connections
|
||||||
/// while (running)
|
/// while (running)
|
||||||
/// {
|
/// {
|
||||||
/// // Make the selector wait for data on any socket
|
/// // Make the selector wait for data on any socket
|
||||||
/// if (selector.wait())
|
/// if (selector.wait())
|
||||||
/// {
|
/// {
|
||||||
/// // Test the listener
|
/// // Test the listener
|
||||||
/// if (selector.isReady(listener))
|
/// if (selector.isReady(listener))
|
||||||
/// {
|
/// {
|
||||||
/// // The listener is ready: there is a pending connection
|
/// // The listener is ready: there is a pending connection
|
||||||
/// sf::TcpSocket* client = new sf::TcpSocket;
|
/// sf::TcpSocket* client = new sf::TcpSocket;
|
||||||
/// if (listener.accept(*client) == sf::Socket::Done)
|
/// if (listener.accept(*client) == sf::Socket::Done)
|
||||||
/// {
|
/// {
|
||||||
/// // Add the new client to the clients list
|
/// // Add the new client to the clients list
|
||||||
/// clients.push_back(client);
|
/// clients.push_back(client);
|
||||||
///
|
///
|
||||||
/// // Add the new client to the selector so that we will
|
/// // Add the new client to the selector so that we will
|
||||||
/// // be notified when he sends something
|
/// // be notified when he sends something
|
||||||
/// selector.add(*client);
|
/// selector.add(*client);
|
||||||
/// }
|
/// }
|
||||||
/// else
|
/// else
|
||||||
/// {
|
/// {
|
||||||
/// // Error, we won't get a new connection, delete the socket
|
/// // Error, we won't get a new connection, delete the socket
|
||||||
/// delete client;
|
/// delete client;
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// else
|
/// else
|
||||||
/// {
|
/// {
|
||||||
/// // The listener socket is not ready, test all other sockets (the clients)
|
/// // The listener socket is not ready, test all other sockets (the clients)
|
||||||
/// for (std::list<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
|
/// for (std::list<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
|
||||||
/// {
|
/// {
|
||||||
/// sf::TcpSocket& client = **it;
|
/// sf::TcpSocket& client = **it;
|
||||||
/// if (selector.isReady(client))
|
/// if (selector.isReady(client))
|
||||||
/// {
|
/// {
|
||||||
/// // The client has sent some data, we can receive it
|
/// // The client has sent some data, we can receive it
|
||||||
/// sf::Packet packet;
|
/// sf::Packet packet;
|
||||||
/// if (client.receive(packet) == sf::Socket::Done)
|
/// if (client.receive(packet) == sf::Socket::Done)
|
||||||
/// {
|
/// {
|
||||||
/// ...
|
/// ...
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Socket
|
/// \see sf::Socket
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,162 +1,162 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_TCPLISTENER_HPP
|
#ifndef SFML_TCPLISTENER_HPP
|
||||||
#define SFML_TCPLISTENER_HPP
|
#define SFML_TCPLISTENER_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <SFML/Network/Socket.hpp>
|
#include <SFML/Network/Socket.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class TcpSocket;
|
class TcpSocket;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Socket that listens to new TCP connections
|
/// \brief Socket that listens to new TCP connections
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API TcpListener : public Socket
|
class SFML_NETWORK_API TcpListener : public Socket
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
TcpListener();
|
TcpListener();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the port to which the socket is bound locally
|
/// \brief Get the port to which the socket is bound locally
|
||||||
///
|
///
|
||||||
/// If the socket is not listening to a port, this function
|
/// If the socket is not listening to a port, this function
|
||||||
/// returns 0.
|
/// returns 0.
|
||||||
///
|
///
|
||||||
/// \return Port to which the socket is bound
|
/// \return Port to which the socket is bound
|
||||||
///
|
///
|
||||||
/// \see listen
|
/// \see listen
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned short getLocalPort() const;
|
unsigned short getLocalPort() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Start listening for connections
|
/// \brief Start listening for connections
|
||||||
///
|
///
|
||||||
/// This functions makes the socket listen to the specified
|
/// This functions makes the socket listen to the specified
|
||||||
/// port, waiting for new connections.
|
/// port, waiting for new connections.
|
||||||
/// If the socket was previously listening to another port,
|
/// If the socket was previously listening to another port,
|
||||||
/// it will be stopped first and bound to the new port.
|
/// it will be stopped first and bound to the new port.
|
||||||
///
|
///
|
||||||
/// \param port Port to listen for new connections
|
/// \param port Port to listen for new connections
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see accept, close
|
/// \see accept, close
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status listen(unsigned short port);
|
Status listen(unsigned short port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Stop listening and close the socket
|
/// \brief Stop listening and close the socket
|
||||||
///
|
///
|
||||||
/// This function gracefully stops the listener. If the
|
/// This function gracefully stops the listener. If the
|
||||||
/// socket is not listening, this function has no effect.
|
/// socket is not listening, this function has no effect.
|
||||||
///
|
///
|
||||||
/// \see listen
|
/// \see listen
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Accept a new connection
|
/// \brief Accept a new connection
|
||||||
///
|
///
|
||||||
/// If the socket is in blocking mode, this function will
|
/// If the socket is in blocking mode, this function will
|
||||||
/// not return until a connection is actually received.
|
/// not return until a connection is actually received.
|
||||||
///
|
///
|
||||||
/// \param socket Socket that will hold the new connection
|
/// \param socket Socket that will hold the new connection
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see listen
|
/// \see listen
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status accept(TcpSocket& socket);
|
Status accept(TcpSocket& socket);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TCPLISTENER_HPP
|
#endif // SFML_TCPLISTENER_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::TcpListener
|
/// \class sf::TcpListener
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// A listener socket is a special type of socket that listens to
|
/// A listener socket is a special type of socket that listens to
|
||||||
/// a given port and waits for connections on that port.
|
/// a given port and waits for connections on that port.
|
||||||
/// This is all it can do.
|
/// This is all it can do.
|
||||||
///
|
///
|
||||||
/// When a new connection is received, you must call accept and
|
/// When a new connection is received, you must call accept and
|
||||||
/// the listener returns a new instance of sf::TcpSocket that
|
/// the listener returns a new instance of sf::TcpSocket that
|
||||||
/// is properly initialized and can be used to communicate with
|
/// is properly initialized and can be used to communicate with
|
||||||
/// the new client.
|
/// the new client.
|
||||||
///
|
///
|
||||||
/// Listener sockets are specific to the TCP protocol,
|
/// Listener sockets are specific to the TCP protocol,
|
||||||
/// UDP sockets are connectionless and can therefore communicate
|
/// UDP sockets are connectionless and can therefore communicate
|
||||||
/// directly. As a consequence, a listener socket will always
|
/// directly. As a consequence, a listener socket will always
|
||||||
/// return the new connections as sf::TcpSocket instances.
|
/// return the new connections as sf::TcpSocket instances.
|
||||||
///
|
///
|
||||||
/// A listener is automatically closed on destruction, like all
|
/// A listener is automatically closed on destruction, like all
|
||||||
/// other types of socket. However if you want to stop listening
|
/// other types of socket. However if you want to stop listening
|
||||||
/// before the socket is destroyed, you can call its close()
|
/// before the socket is destroyed, you can call its close()
|
||||||
/// function.
|
/// function.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Create a listener socket and make it wait for new
|
/// // Create a listener socket and make it wait for new
|
||||||
/// // connections on port 55001
|
/// // connections on port 55001
|
||||||
/// sf::TcpListener listener;
|
/// sf::TcpListener listener;
|
||||||
/// listener.listen(55001);
|
/// listener.listen(55001);
|
||||||
///
|
///
|
||||||
/// // Endless loop that waits for new connections
|
/// // Endless loop that waits for new connections
|
||||||
/// while (running)
|
/// while (running)
|
||||||
/// {
|
/// {
|
||||||
/// sf::TcpSocket client;
|
/// sf::TcpSocket client;
|
||||||
/// if (listener.accept(client) == sf::Socket::Done)
|
/// if (listener.accept(client) == sf::Socket::Done)
|
||||||
/// {
|
/// {
|
||||||
/// // A new client just connected!
|
/// // A new client just connected!
|
||||||
/// std::cout << "New connection received from " << client.getRemoteAddress() << std::endl;
|
/// std::cout << "New connection received from " << client.getRemoteAddress() << std::endl;
|
||||||
/// doSomethingWith(client);
|
/// doSomethingWith(client);
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::TcpSocket, sf::Socket
|
/// \see sf::TcpSocket, sf::Socket
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,292 +1,292 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_TCPSOCKET_HPP
|
#ifndef SFML_TCPSOCKET_HPP
|
||||||
#define SFML_TCPSOCKET_HPP
|
#define SFML_TCPSOCKET_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <SFML/Network/Socket.hpp>
|
#include <SFML/Network/Socket.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class TcpListener;
|
class TcpListener;
|
||||||
class IpAddress;
|
class IpAddress;
|
||||||
class Packet;
|
class Packet;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Specialized socket using the TCP protocol
|
/// \brief Specialized socket using the TCP protocol
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API TcpSocket : public Socket
|
class SFML_NETWORK_API TcpSocket : public Socket
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
TcpSocket();
|
TcpSocket();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the port to which the socket is bound locally
|
/// \brief Get the port to which the socket is bound locally
|
||||||
///
|
///
|
||||||
/// If the socket is not connected, this function returns 0.
|
/// If the socket is not connected, this function returns 0.
|
||||||
///
|
///
|
||||||
/// \return Port to which the socket is bound
|
/// \return Port to which the socket is bound
|
||||||
///
|
///
|
||||||
/// \see connect, getRemotePort
|
/// \see connect, getRemotePort
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned short getLocalPort() const;
|
unsigned short getLocalPort() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the address of the connected peer
|
/// \brief Get the address of the connected peer
|
||||||
///
|
///
|
||||||
/// It the socket is not connected, this function returns
|
/// It the socket is not connected, this function returns
|
||||||
/// sf::IpAddress::None.
|
/// sf::IpAddress::None.
|
||||||
///
|
///
|
||||||
/// \return Address of the remote peer
|
/// \return Address of the remote peer
|
||||||
///
|
///
|
||||||
/// \see getRemotePort
|
/// \see getRemotePort
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IpAddress getRemoteAddress() const;
|
IpAddress getRemoteAddress() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the port of the connected peer to which
|
/// \brief Get the port of the connected peer to which
|
||||||
/// the socket is connected
|
/// the socket is connected
|
||||||
///
|
///
|
||||||
/// If the socket is not connected, this function returns 0.
|
/// If the socket is not connected, this function returns 0.
|
||||||
///
|
///
|
||||||
/// \return Remote port to which the socket is connected
|
/// \return Remote port to which the socket is connected
|
||||||
///
|
///
|
||||||
/// \see getRemoteAddress
|
/// \see getRemoteAddress
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned short getRemotePort() const;
|
unsigned short getRemotePort() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Connect the socket to a remote peer
|
/// \brief Connect the socket to a remote peer
|
||||||
///
|
///
|
||||||
/// In blocking mode, this function may take a while, especially
|
/// In blocking mode, this function may take a while, especially
|
||||||
/// if the remote peer is not reachable. The last parameter allows
|
/// if the remote peer is not reachable. The last parameter allows
|
||||||
/// you to stop trying to connect after a given timeout.
|
/// you to stop trying to connect after a given timeout.
|
||||||
/// If the socket was previously connected, it is first disconnected.
|
/// If the socket was previously connected, it is first disconnected.
|
||||||
///
|
///
|
||||||
/// \param remoteAddress Address of the remote peer
|
/// \param remoteAddress Address of the remote peer
|
||||||
/// \param remotePort Port of the remote peer
|
/// \param remotePort Port of the remote peer
|
||||||
/// \param timeout Optional maximum time to wait
|
/// \param timeout Optional maximum time to wait
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see disconnect
|
/// \see disconnect
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
|
Status connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Disconnect the socket from its remote peer
|
/// \brief Disconnect the socket from its remote peer
|
||||||
///
|
///
|
||||||
/// This function gracefully closes the connection. If the
|
/// This function gracefully closes the connection. If the
|
||||||
/// socket is not connected, this function has no effect.
|
/// socket is not connected, this function has no effect.
|
||||||
///
|
///
|
||||||
/// \see connect
|
/// \see connect
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Send raw data to the remote peer
|
/// \brief Send raw data to the remote peer
|
||||||
///
|
///
|
||||||
/// This function will fail if the socket is not connected.
|
/// This function will fail if the socket is not connected.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the sequence of bytes to send
|
/// \param data Pointer to the sequence of bytes to send
|
||||||
/// \param size Number of bytes to send
|
/// \param size Number of bytes to send
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see receive
|
/// \see receive
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status send(const void* data, std::size_t size);
|
Status send(const void* data, std::size_t size);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Receive raw data from the remote peer
|
/// \brief Receive raw data from the remote peer
|
||||||
///
|
///
|
||||||
/// In blocking mode, this function will wait until some
|
/// In blocking mode, this function will wait until some
|
||||||
/// bytes are actually received.
|
/// bytes are actually received.
|
||||||
/// This function will fail if the socket is not connected.
|
/// This function will fail if the socket is not connected.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the array to fill with the received bytes
|
/// \param data Pointer to the array to fill with the received bytes
|
||||||
/// \param size Maximum number of bytes that can be received
|
/// \param size Maximum number of bytes that can be received
|
||||||
/// \param received This variable is filled with the actual number of bytes received
|
/// \param received This variable is filled with the actual number of bytes received
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see send
|
/// \see send
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status receive(void* data, std::size_t size, std::size_t& received);
|
Status receive(void* data, std::size_t size, std::size_t& received);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Send a formatted packet of data to the remote peer
|
/// \brief Send a formatted packet of data to the remote peer
|
||||||
///
|
///
|
||||||
/// This function will fail if the socket is not connected.
|
/// This function will fail if the socket is not connected.
|
||||||
///
|
///
|
||||||
/// \param packet Packet to send
|
/// \param packet Packet to send
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see receive
|
/// \see receive
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status send(Packet& packet);
|
Status send(Packet& packet);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Receive a formatted packet of data from the remote peer
|
/// \brief Receive a formatted packet of data from the remote peer
|
||||||
///
|
///
|
||||||
/// In blocking mode, this function will wait until the whole packet
|
/// In blocking mode, this function will wait until the whole packet
|
||||||
/// has been received.
|
/// has been received.
|
||||||
/// This function will fail if the socket is not connected.
|
/// This function will fail if the socket is not connected.
|
||||||
///
|
///
|
||||||
/// \param packet Packet to fill with the received data
|
/// \param packet Packet to fill with the received data
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see send
|
/// \see send
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status receive(Packet& packet);
|
Status receive(Packet& packet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend class TcpListener;
|
friend class TcpListener;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Structure holding the data of a pending packet
|
/// \brief Structure holding the data of a pending packet
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct PendingPacket
|
struct PendingPacket
|
||||||
{
|
{
|
||||||
PendingPacket();
|
PendingPacket();
|
||||||
|
|
||||||
Uint32 Size; ///< Data of packet size
|
Uint32 Size; ///< Data of packet size
|
||||||
std::size_t SizeReceived; ///< Number of size bytes received so far
|
std::size_t SizeReceived; ///< Number of size bytes received so far
|
||||||
std::vector<char> Data; ///< Data of the packet
|
std::vector<char> Data; ///< Data of the packet
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
PendingPacket m_pendingPacket; ///< Temporary data of the packet currently being received
|
PendingPacket m_pendingPacket; ///< Temporary data of the packet currently being received
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_TCPSOCKET_HPP
|
#endif // SFML_TCPSOCKET_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::TcpSocket
|
/// \class sf::TcpSocket
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// TCP is a connected protocol, which means that a TCP
|
/// TCP is a connected protocol, which means that a TCP
|
||||||
/// socket can only communicate with the host it is connected
|
/// socket can only communicate with the host it is connected
|
||||||
/// to. It can't send or receive anything if it is not connected.
|
/// to. It can't send or receive anything if it is not connected.
|
||||||
///
|
///
|
||||||
/// The TCP protocol is reliable but adds a slight overhead.
|
/// The TCP protocol is reliable but adds a slight overhead.
|
||||||
/// It ensures that your data will always be received in order
|
/// It ensures that your data will always be received in order
|
||||||
/// and without errors (no data corrupted, lost or duplicated).
|
/// and without errors (no data corrupted, lost or duplicated).
|
||||||
///
|
///
|
||||||
/// When a socket is connected to a remote host, you can
|
/// When a socket is connected to a remote host, you can
|
||||||
/// retrieve informations about this host with the
|
/// retrieve informations about this host with the
|
||||||
/// getRemoteAddress and getRemotePort functions. You can
|
/// getRemoteAddress and getRemotePort functions. You can
|
||||||
/// also get the local port to which the socket is bound
|
/// also get the local port to which the socket is bound
|
||||||
/// (which is automatically chosen when the socket is connected),
|
/// (which is automatically chosen when the socket is connected),
|
||||||
/// with the getLocalPort function.
|
/// with the getLocalPort function.
|
||||||
///
|
///
|
||||||
/// Sending and receiving data can use either the low-level
|
/// Sending and receiving data can use either the low-level
|
||||||
/// or the high-level functions. The low-level functions
|
/// or the high-level functions. The low-level functions
|
||||||
/// process a raw sequence of bytes, and cannot ensure that
|
/// process a raw sequence of bytes, and cannot ensure that
|
||||||
/// one call to Send will exactly match one call to Receive
|
/// one call to Send will exactly match one call to Receive
|
||||||
/// at the other end of the socket.
|
/// at the other end of the socket.
|
||||||
///
|
///
|
||||||
/// The high-level interface uses packets (see sf::Packet),
|
/// The high-level interface uses packets (see sf::Packet),
|
||||||
/// which are easier to use and provide more safety regarding
|
/// which are easier to use and provide more safety regarding
|
||||||
/// the data that is exchanged. You can look at the sf::Packet
|
/// the data that is exchanged. You can look at the sf::Packet
|
||||||
/// class to get more details about how they work.
|
/// class to get more details about how they work.
|
||||||
///
|
///
|
||||||
/// The socket is automatically disconnected when it is destroyed,
|
/// The socket is automatically disconnected when it is destroyed,
|
||||||
/// but if you want to explicitely close the connection while
|
/// but if you want to explicitely close the connection while
|
||||||
/// the socket instance is still alive, you can call disconnect.
|
/// the socket instance is still alive, you can call disconnect.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // ----- The client -----
|
/// // ----- The client -----
|
||||||
///
|
///
|
||||||
/// // Create a socket and connect it to 192.168.1.50 on port 55001
|
/// // Create a socket and connect it to 192.168.1.50 on port 55001
|
||||||
/// sf::TcpSocket socket;
|
/// sf::TcpSocket socket;
|
||||||
/// socket.connect("192.168.1.50", 55001);
|
/// socket.connect("192.168.1.50", 55001);
|
||||||
///
|
///
|
||||||
/// // Send a message to the connected host
|
/// // Send a message to the connected host
|
||||||
/// std::string message = "Hi, I am a client";
|
/// std::string message = "Hi, I am a client";
|
||||||
/// socket.send(message.c_str(), message.size() + 1);
|
/// socket.send(message.c_str(), message.size() + 1);
|
||||||
///
|
///
|
||||||
/// // Receive an answer from the server
|
/// // Receive an answer from the server
|
||||||
/// char buffer[1024];
|
/// char buffer[1024];
|
||||||
/// std::size_t received = 0;
|
/// std::size_t received = 0;
|
||||||
/// socket.receive(buffer, sizeof(buffer), received);
|
/// socket.receive(buffer, sizeof(buffer), received);
|
||||||
/// std::cout << "The server said: " << buffer << std::endl;
|
/// std::cout << "The server said: " << buffer << std::endl;
|
||||||
///
|
///
|
||||||
/// // ----- The server -----
|
/// // ----- The server -----
|
||||||
///
|
///
|
||||||
/// // Create a listener to wait for incoming connections on port 55001
|
/// // Create a listener to wait for incoming connections on port 55001
|
||||||
/// sf::TcpListener listener;
|
/// sf::TcpListener listener;
|
||||||
/// listener.listen(55001);
|
/// listener.listen(55001);
|
||||||
///
|
///
|
||||||
/// // Wait for a connection
|
/// // Wait for a connection
|
||||||
/// sf::TcpSocket socket;
|
/// sf::TcpSocket socket;
|
||||||
/// listener.accept(socket);
|
/// listener.accept(socket);
|
||||||
/// std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
|
/// std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
|
||||||
///
|
///
|
||||||
/// // Receive a message from the client
|
/// // Receive a message from the client
|
||||||
/// char buffer[1024];
|
/// char buffer[1024];
|
||||||
/// std::size_t received = 0;
|
/// std::size_t received = 0;
|
||||||
/// socket.receive(buffer, sizeof(buffer), received);
|
/// socket.receive(buffer, sizeof(buffer), received);
|
||||||
/// std::cout << "The client said: " << buffer << std::endl;
|
/// std::cout << "The client said: " << buffer << std::endl;
|
||||||
///
|
///
|
||||||
/// // Send an answer
|
/// // Send an answer
|
||||||
/// std::string message = "Welcome, client";
|
/// std::string message = "Welcome, client";
|
||||||
/// socket.send(message.c_str(), message.size() + 1);
|
/// socket.send(message.c_str(), message.size() + 1);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Socket, sf::UdpSocket, sf::Packet
|
/// \see sf::Socket, sf::UdpSocket, sf::Packet
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,283 +1,283 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_UDPSOCKET_HPP
|
#ifndef SFML_UDPSOCKET_HPP
|
||||||
#define SFML_UDPSOCKET_HPP
|
#define SFML_UDPSOCKET_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Network/Export.hpp>
|
#include <SFML/Network/Export.hpp>
|
||||||
#include <SFML/Network/Socket.hpp>
|
#include <SFML/Network/Socket.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class IpAddress;
|
class IpAddress;
|
||||||
class Packet;
|
class Packet;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Specialized socket using the UDP protocol
|
/// \brief Specialized socket using the UDP protocol
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_NETWORK_API UdpSocket : public Socket
|
class SFML_NETWORK_API UdpSocket : public Socket
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Constants
|
// Constants
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
MaxDatagramSize = 65507 ///< The maximum number of bytes that can be sent in a single UDP datagram
|
MaxDatagramSize = 65507 ///< The maximum number of bytes that can be sent in a single UDP datagram
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
UdpSocket();
|
UdpSocket();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the port to which the socket is bound locally
|
/// \brief Get the port to which the socket is bound locally
|
||||||
///
|
///
|
||||||
/// If the socket is not bound to a port, this function
|
/// If the socket is not bound to a port, this function
|
||||||
/// returns 0.
|
/// returns 0.
|
||||||
///
|
///
|
||||||
/// \return Port to which the socket is bound
|
/// \return Port to which the socket is bound
|
||||||
///
|
///
|
||||||
/// \see bind
|
/// \see bind
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned short getLocalPort() const;
|
unsigned short getLocalPort() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Bind the socket to a specific port
|
/// \brief Bind the socket to a specific port
|
||||||
///
|
///
|
||||||
/// Binding the socket to a port is necessary for being
|
/// Binding the socket to a port is necessary for being
|
||||||
/// able to receive data on that port.
|
/// able to receive data on that port.
|
||||||
/// You can use the special value Socket::AnyPort to tell the
|
/// You can use the special value Socket::AnyPort to tell the
|
||||||
/// system to automatically pick an available port, and then
|
/// system to automatically pick an available port, and then
|
||||||
/// call getLocalPort to retrieve the chosen port.
|
/// call getLocalPort to retrieve the chosen port.
|
||||||
///
|
///
|
||||||
/// \param port Port to bind the socket to
|
/// \param port Port to bind the socket to
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see unbind, getLocalPort
|
/// \see unbind, getLocalPort
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status bind(unsigned short port);
|
Status bind(unsigned short port);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Unbind the socket from the local port to which it is bound
|
/// \brief Unbind the socket from the local port to which it is bound
|
||||||
///
|
///
|
||||||
/// The port that the socket was previously using is immediately
|
/// The port that the socket was previously using is immediately
|
||||||
/// available after this function is called. If the
|
/// available after this function is called. If the
|
||||||
/// socket is not bound to a port, this function has no effect.
|
/// socket is not bound to a port, this function has no effect.
|
||||||
///
|
///
|
||||||
/// \see bind
|
/// \see bind
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void unbind();
|
void unbind();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Send raw data to a remote peer
|
/// \brief Send raw data to a remote peer
|
||||||
///
|
///
|
||||||
/// Make sure that \a size is not greater than
|
/// Make sure that \a size is not greater than
|
||||||
/// UdpSocket::MaxDatagramSize, otherwise this function will
|
/// UdpSocket::MaxDatagramSize, otherwise this function will
|
||||||
/// fail and no data will be sent.
|
/// fail and no data will be sent.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the sequence of bytes to send
|
/// \param data Pointer to the sequence of bytes to send
|
||||||
/// \param size Number of bytes to send
|
/// \param size Number of bytes to send
|
||||||
/// \param remoteAddress Address of the receiver
|
/// \param remoteAddress Address of the receiver
|
||||||
/// \param remotePort Port of the receiver to send the data to
|
/// \param remotePort Port of the receiver to send the data to
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see receive
|
/// \see receive
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort);
|
Status send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Receive raw data from a remote peer
|
/// \brief Receive raw data from a remote peer
|
||||||
///
|
///
|
||||||
/// In blocking mode, this function will wait until some
|
/// In blocking mode, this function will wait until some
|
||||||
/// bytes are actually received.
|
/// bytes are actually received.
|
||||||
/// Be careful to use a buffer which is large enough for
|
/// Be careful to use a buffer which is large enough for
|
||||||
/// the data that you intend to receive, if it is too small
|
/// the data that you intend to receive, if it is too small
|
||||||
/// then an error will be returned and *all* the data will
|
/// then an error will be returned and *all* the data will
|
||||||
/// be lost.
|
/// be lost.
|
||||||
///
|
///
|
||||||
/// \param data Pointer to the array to fill with the received bytes
|
/// \param data Pointer to the array to fill with the received bytes
|
||||||
/// \param size Maximum number of bytes that can be received
|
/// \param size Maximum number of bytes that can be received
|
||||||
/// \param received This variable is filled with the actual number of bytes received
|
/// \param received This variable is filled with the actual number of bytes received
|
||||||
/// \param remoteAddress Address of the peer that sent the data
|
/// \param remoteAddress Address of the peer that sent the data
|
||||||
/// \param remotePort Port of the peer that sent the data
|
/// \param remotePort Port of the peer that sent the data
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see send
|
/// \see send
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status receive(void* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort);
|
Status receive(void* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Send a formatted packet of data to a remote peer
|
/// \brief Send a formatted packet of data to a remote peer
|
||||||
///
|
///
|
||||||
/// Make sure that the packet size is not greater than
|
/// Make sure that the packet size is not greater than
|
||||||
/// UdpSocket::MaxDatagramSize, otherwise this function will
|
/// UdpSocket::MaxDatagramSize, otherwise this function will
|
||||||
/// fail and no data will be sent.
|
/// fail and no data will be sent.
|
||||||
///
|
///
|
||||||
/// \param packet Packet to send
|
/// \param packet Packet to send
|
||||||
/// \param remoteAddress Address of the receiver
|
/// \param remoteAddress Address of the receiver
|
||||||
/// \param remotePort Port of the receiver to send the data to
|
/// \param remotePort Port of the receiver to send the data to
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see receive
|
/// \see receive
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort);
|
Status send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Receive a formatted packet of data from a remote peer
|
/// \brief Receive a formatted packet of data from a remote peer
|
||||||
///
|
///
|
||||||
/// In blocking mode, this function will wait until the whole packet
|
/// In blocking mode, this function will wait until the whole packet
|
||||||
/// has been received.
|
/// has been received.
|
||||||
///
|
///
|
||||||
/// \param packet Packet to fill with the received data
|
/// \param packet Packet to fill with the received data
|
||||||
/// \param remoteAddress Address of the peer that sent the data
|
/// \param remoteAddress Address of the peer that sent the data
|
||||||
/// \param remotePort Port of the peer that sent the data
|
/// \param remotePort Port of the peer that sent the data
|
||||||
///
|
///
|
||||||
/// \return Status code
|
/// \return Status code
|
||||||
///
|
///
|
||||||
/// \see send
|
/// \see send
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Status receive(Packet& packet, IpAddress& remoteAddress, unsigned short& remotePort);
|
Status receive(Packet& packet, IpAddress& remoteAddress, unsigned short& remotePort);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
std::vector<char> m_buffer; ///< Temporary buffer holding the received data in Receive(Packet)
|
std::vector<char> m_buffer; ///< Temporary buffer holding the received data in Receive(Packet)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_UDPSOCKET_HPP
|
#endif // SFML_UDPSOCKET_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::UdpSocket
|
/// \class sf::UdpSocket
|
||||||
/// \ingroup network
|
/// \ingroup network
|
||||||
///
|
///
|
||||||
/// A UDP socket is a connectionless socket. Instead of
|
/// A UDP socket is a connectionless socket. Instead of
|
||||||
/// connecting once to a remote host, like TCP sockets,
|
/// connecting once to a remote host, like TCP sockets,
|
||||||
/// it can send to and receive from any host at any time.
|
/// it can send to and receive from any host at any time.
|
||||||
///
|
///
|
||||||
/// It is a datagram protocol: bounded blocks of data (datagrams)
|
/// It is a datagram protocol: bounded blocks of data (datagrams)
|
||||||
/// are transfered over the network rather than a continuous
|
/// are transfered over the network rather than a continuous
|
||||||
/// stream of data (TCP). Therefore, one call to send will always
|
/// stream of data (TCP). Therefore, one call to send will always
|
||||||
/// match one call to receive (if the datagram is not lost),
|
/// match one call to receive (if the datagram is not lost),
|
||||||
/// with the same data that was sent.
|
/// with the same data that was sent.
|
||||||
///
|
///
|
||||||
/// The UDP protocol is lightweight but unreliable. Unreliable
|
/// The UDP protocol is lightweight but unreliable. Unreliable
|
||||||
/// means that datagrams may be duplicated, be lost or
|
/// means that datagrams may be duplicated, be lost or
|
||||||
/// arrive reordered. However, if a datagram arrives, its
|
/// arrive reordered. However, if a datagram arrives, its
|
||||||
/// data is guaranteed to be valid.
|
/// data is guaranteed to be valid.
|
||||||
///
|
///
|
||||||
/// UDP is generally used for real-time communication
|
/// UDP is generally used for real-time communication
|
||||||
/// (audio or video streaming, real-time games, etc.) where
|
/// (audio or video streaming, real-time games, etc.) where
|
||||||
/// speed is crucial and lost data doesn't matter much.
|
/// speed is crucial and lost data doesn't matter much.
|
||||||
///
|
///
|
||||||
/// Sending and receiving data can use either the low-level
|
/// Sending and receiving data can use either the low-level
|
||||||
/// or the high-level functions. The low-level functions
|
/// or the high-level functions. The low-level functions
|
||||||
/// process a raw sequence of bytes, whereas the high-level
|
/// process a raw sequence of bytes, whereas the high-level
|
||||||
/// interface uses packets (see sf::Packet), which are easier
|
/// interface uses packets (see sf::Packet), which are easier
|
||||||
/// to use and provide more safety regarding the data that is
|
/// to use and provide more safety regarding the data that is
|
||||||
/// exchanged. You can look at the sf::Packet class to get
|
/// exchanged. You can look at the sf::Packet class to get
|
||||||
/// more details about how they work.
|
/// more details about how they work.
|
||||||
///
|
///
|
||||||
/// It is important to note that UdpSocket is unable to send
|
/// It is important to note that UdpSocket is unable to send
|
||||||
/// datagrams bigger than MaxDatagramSize. In this case, it
|
/// datagrams bigger than MaxDatagramSize. In this case, it
|
||||||
/// returns an error and doesn't send anything. This applies
|
/// returns an error and doesn't send anything. This applies
|
||||||
/// to both raw data and packets. Indeed, even packets are
|
/// to both raw data and packets. Indeed, even packets are
|
||||||
/// unable to split and recompose data, due to the unreliability
|
/// unable to split and recompose data, due to the unreliability
|
||||||
/// of the protocol (dropped, mixed or duplicated datagrams may
|
/// of the protocol (dropped, mixed or duplicated datagrams may
|
||||||
/// lead to a big mess when trying to recompose a packet).
|
/// lead to a big mess when trying to recompose a packet).
|
||||||
///
|
///
|
||||||
/// If the socket is bound to a port, it is automatically
|
/// If the socket is bound to a port, it is automatically
|
||||||
/// unbound from it when the socket is destroyed. However,
|
/// unbound from it when the socket is destroyed. However,
|
||||||
/// you can unbind the socket explicitely with the Unbind
|
/// you can unbind the socket explicitely with the Unbind
|
||||||
/// function if necessary, to stop receiving messages or
|
/// function if necessary, to stop receiving messages or
|
||||||
/// make the port available for other sockets.
|
/// make the port available for other sockets.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // ----- The client -----
|
/// // ----- The client -----
|
||||||
///
|
///
|
||||||
/// // Create a socket and bind it to the port 55001
|
/// // Create a socket and bind it to the port 55001
|
||||||
/// sf::UdpSocket socket;
|
/// sf::UdpSocket socket;
|
||||||
/// socket.bind(55001);
|
/// socket.bind(55001);
|
||||||
///
|
///
|
||||||
/// // Send a message to 192.168.1.50 on port 55002
|
/// // Send a message to 192.168.1.50 on port 55002
|
||||||
/// std::string message = "Hi, I am " + sf::IpAddress::getLocalAddress().toString();
|
/// std::string message = "Hi, I am " + sf::IpAddress::getLocalAddress().toString();
|
||||||
/// socket.send(message.c_str(), message.size() + 1, "192.168.1.50", 55002);
|
/// socket.send(message.c_str(), message.size() + 1, "192.168.1.50", 55002);
|
||||||
///
|
///
|
||||||
/// // Receive an answer (most likely from 192.168.1.50, but could be anyone else)
|
/// // Receive an answer (most likely from 192.168.1.50, but could be anyone else)
|
||||||
/// char buffer[1024];
|
/// char buffer[1024];
|
||||||
/// std::size_t received = 0;
|
/// std::size_t received = 0;
|
||||||
/// sf::IpAddress sender;
|
/// sf::IpAddress sender;
|
||||||
/// unsigned short port;
|
/// unsigned short port;
|
||||||
/// socket.receive(buffer, sizeof(buffer), received, sender, port);
|
/// socket.receive(buffer, sizeof(buffer), received, sender, port);
|
||||||
/// std::cout << sender.ToString() << " said: " << buffer << std::endl;
|
/// std::cout << sender.ToString() << " said: " << buffer << std::endl;
|
||||||
///
|
///
|
||||||
/// // ----- The server -----
|
/// // ----- The server -----
|
||||||
///
|
///
|
||||||
/// // Create a socket and bind it to the port 55002
|
/// // Create a socket and bind it to the port 55002
|
||||||
/// sf::UdpSocket socket;
|
/// sf::UdpSocket socket;
|
||||||
/// socket.bind(55002);
|
/// socket.bind(55002);
|
||||||
///
|
///
|
||||||
/// // Receive a message from anyone
|
/// // Receive a message from anyone
|
||||||
/// char buffer[1024];
|
/// char buffer[1024];
|
||||||
/// std::size_t received = 0;
|
/// std::size_t received = 0;
|
||||||
/// sf::IpAddress sender;
|
/// sf::IpAddress sender;
|
||||||
/// unsigned short port;
|
/// unsigned short port;
|
||||||
/// socket.receive(buffer, sizeof(buffer), received, sender, port);
|
/// socket.receive(buffer, sizeof(buffer), received, sender, port);
|
||||||
/// std::cout << sender.ToString() << " said: " << buffer << std::endl;
|
/// std::cout << sender.ToString() << " said: " << buffer << std::endl;
|
||||||
///
|
///
|
||||||
/// // Send an answer
|
/// // Send an answer
|
||||||
/// std::string message = "Welcome " + sender.toString();
|
/// std::string message = "Welcome " + sender.toString();
|
||||||
/// socket.send(message.c_str(), message.size() + 1, sender, port);
|
/// socket.send(message.c_str(), message.size() + 1, sender, port);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \see sf::Socket, sf::TcpSocket, sf::Packet
|
/// \see sf::Socket, sf::TcpSocket, sf::Packet
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,77 +1,77 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_OPENGL_HPP
|
#ifndef SFML_OPENGL_HPP
|
||||||
#define SFML_OPENGL_HPP
|
#define SFML_OPENGL_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Headers
|
/// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Config.hpp>
|
#include <SFML/Config.hpp>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// This file just includes the OpenGL (GL and GLU) headers,
|
/// This file just includes the OpenGL (GL and GLU) headers,
|
||||||
/// which have actually different paths on each system
|
/// which have actually different paths on each system
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#if defined(SFML_SYSTEM_WINDOWS)
|
#if defined(SFML_SYSTEM_WINDOWS)
|
||||||
|
|
||||||
// The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
|
// The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
||||||
|
|
||||||
#if defined(SFML_OPENGL_ES)
|
#if defined(SFML_OPENGL_ES)
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
#else
|
#else
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(SFML_SYSTEM_MACOS)
|
#elif defined(SFML_SYSTEM_MACOS)
|
||||||
|
|
||||||
#include <OpenGL/gl.h>
|
#include <OpenGL/gl.h>
|
||||||
#include <OpenGL/glu.h>
|
#include <OpenGL/glu.h>
|
||||||
|
|
||||||
#elif defined (SFML_SYSTEM_IOS)
|
#elif defined (SFML_SYSTEM_IOS)
|
||||||
|
|
||||||
#include <OpenGLES/ES1/gl.h>
|
#include <OpenGLES/ES1/gl.h>
|
||||||
#include <OpenGLES/ES1/glext.h>
|
#include <OpenGLES/ES1/glext.h>
|
||||||
|
|
||||||
#elif defined (SFML_SYSTEM_ANDROID)
|
#elif defined (SFML_SYSTEM_ANDROID)
|
||||||
|
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_OPENGL_HPP
|
#endif // SFML_OPENGL_HPP
|
||||||
|
|
|
@ -1,56 +1,56 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SYSTEM_HPP
|
#ifndef SFML_SYSTEM_HPP
|
||||||
#define SFML_SYSTEM_HPP
|
#define SFML_SYSTEM_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/Config.hpp>
|
#include <SFML/Config.hpp>
|
||||||
#include <SFML/System/Clock.hpp>
|
#include <SFML/System/Clock.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
#include <SFML/System/InputStream.hpp>
|
#include <SFML/System/InputStream.hpp>
|
||||||
#include <SFML/System/Lock.hpp>
|
#include <SFML/System/Lock.hpp>
|
||||||
#include <SFML/System/Mutex.hpp>
|
#include <SFML/System/Mutex.hpp>
|
||||||
#include <SFML/System/Sleep.hpp>
|
#include <SFML/System/Sleep.hpp>
|
||||||
#include <SFML/System/String.hpp>
|
#include <SFML/System/String.hpp>
|
||||||
#include <SFML/System/Thread.hpp>
|
#include <SFML/System/Thread.hpp>
|
||||||
#include <SFML/System/ThreadLocal.hpp>
|
#include <SFML/System/ThreadLocal.hpp>
|
||||||
#include <SFML/System/ThreadLocalPtr.hpp>
|
#include <SFML/System/ThreadLocalPtr.hpp>
|
||||||
#include <SFML/System/Utf.hpp>
|
#include <SFML/System/Utf.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <SFML/System/Vector3.hpp>
|
#include <SFML/System/Vector3.hpp>
|
||||||
|
|
||||||
#endif // SFML_SYSTEM_HPP
|
#endif // SFML_SYSTEM_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \defgroup system System module
|
/// \defgroup system System module
|
||||||
///
|
///
|
||||||
/// Base module of SFML, defining various utilities. It provides
|
/// Base module of SFML, defining various utilities. It provides
|
||||||
/// vector classes, unicode strings and conversion functions,
|
/// vector classes, unicode strings and conversion functions,
|
||||||
/// threads and mutexes, timing classes.
|
/// threads and mutexes, timing classes.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,117 +1,117 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_CLOCK_HPP
|
#ifndef SFML_CLOCK_HPP
|
||||||
#define SFML_CLOCK_HPP
|
#define SFML_CLOCK_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Export.hpp>
|
#include <SFML/System/Export.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Utility class that measures the elapsed time
|
/// \brief Utility class that measures the elapsed time
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_SYSTEM_API Clock
|
class SFML_SYSTEM_API Clock
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// The clock starts automatically after being constructed.
|
/// The clock starts automatically after being constructed.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Clock();
|
Clock();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the elapsed time
|
/// \brief Get the elapsed time
|
||||||
///
|
///
|
||||||
/// This function returns the time elapsed since the last call
|
/// This function returns the time elapsed since the last call
|
||||||
/// to restart() (or the construction of the instance if restart()
|
/// to restart() (or the construction of the instance if restart()
|
||||||
/// has not been called).
|
/// has not been called).
|
||||||
///
|
///
|
||||||
/// \return Time elapsed
|
/// \return Time elapsed
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Time getElapsedTime() const;
|
Time getElapsedTime() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Restart the clock
|
/// \brief Restart the clock
|
||||||
///
|
///
|
||||||
/// This function puts the time counter back to zero.
|
/// This function puts the time counter back to zero.
|
||||||
/// It also returns the time elapsed since the clock was started.
|
/// It also returns the time elapsed since the clock was started.
|
||||||
///
|
///
|
||||||
/// \return Time elapsed
|
/// \return Time elapsed
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Time restart();
|
Time restart();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Time m_startTime; ///< Time of last reset, in microseconds
|
Time m_startTime; ///< Time of last reset, in microseconds
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_CLOCK_HPP
|
#endif // SFML_CLOCK_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Clock
|
/// \class sf::Clock
|
||||||
/// \ingroup system
|
/// \ingroup system
|
||||||
///
|
///
|
||||||
/// sf::Clock is a lightweight class for measuring time.
|
/// sf::Clock is a lightweight class for measuring time.
|
||||||
///
|
///
|
||||||
/// Its provides the most precise time that the underlying
|
/// Its provides the most precise time that the underlying
|
||||||
/// OS can achieve (generally microseconds or nanoseconds).
|
/// OS can achieve (generally microseconds or nanoseconds).
|
||||||
/// It also ensures monotonicity, which means that the returned
|
/// It also ensures monotonicity, which means that the returned
|
||||||
/// time can never go backward, even if the system time is
|
/// time can never go backward, even if the system time is
|
||||||
/// changed.
|
/// changed.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::Clock clock;
|
/// sf::Clock clock;
|
||||||
/// ...
|
/// ...
|
||||||
/// Time time1 = clock.getElapsedTime();
|
/// Time time1 = clock.getElapsedTime();
|
||||||
/// ...
|
/// ...
|
||||||
/// Time time2 = clock.restart();
|
/// Time time2 = clock.restart();
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// The sf::Time value returned by the clock can then be
|
/// The sf::Time value returned by the clock can then be
|
||||||
/// converted to a number of seconds, milliseconds or even
|
/// converted to a number of seconds, milliseconds or even
|
||||||
/// microseconds.
|
/// microseconds.
|
||||||
///
|
///
|
||||||
/// \see sf::Time
|
/// \see sf::Time
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,80 +1,80 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_ERR_HPP
|
#ifndef SFML_ERR_HPP
|
||||||
#define SFML_ERR_HPP
|
#define SFML_ERR_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Export.hpp>
|
#include <SFML/System/Export.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Standard stream used by SFML to output warnings and errors
|
/// \brief Standard stream used by SFML to output warnings and errors
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_SYSTEM_API std::ostream& err();
|
SFML_SYSTEM_API std::ostream& err();
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_ERR_HPP
|
#endif // SFML_ERR_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \fn sf::err
|
/// \fn sf::err
|
||||||
/// \ingroup system
|
/// \ingroup system
|
||||||
///
|
///
|
||||||
/// By default, sf::err() outputs to the same location as std::cerr,
|
/// By default, sf::err() outputs to the same location as std::cerr,
|
||||||
/// (-> the stderr descriptor) which is the console if there's
|
/// (-> the stderr descriptor) which is the console if there's
|
||||||
/// one available.
|
/// one available.
|
||||||
///
|
///
|
||||||
/// It is a standard std::ostream instance, so it supports all the
|
/// It is a standard std::ostream instance, so it supports all the
|
||||||
/// insertion operations defined by the STL
|
/// insertion operations defined by the STL
|
||||||
/// (operator <<, manipulators, etc.).
|
/// (operator <<, manipulators, etc.).
|
||||||
///
|
///
|
||||||
/// sf::err() can be redirected to write to another output, independently
|
/// sf::err() can be redirected to write to another output, independently
|
||||||
/// of std::cerr, by using the rdbuf() function provided by the
|
/// of std::cerr, by using the rdbuf() function provided by the
|
||||||
/// std::ostream class.
|
/// std::ostream class.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Redirect to a file
|
/// // Redirect to a file
|
||||||
/// std::ofstream file("sfml-log.txt");
|
/// std::ofstream file("sfml-log.txt");
|
||||||
/// std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
|
/// std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
|
||||||
///
|
///
|
||||||
/// // Redirect to nothing
|
/// // Redirect to nothing
|
||||||
/// sf::err().rdbuf(NULL);
|
/// sf::err().rdbuf(NULL);
|
||||||
///
|
///
|
||||||
/// // Restore the original output
|
/// // Restore the original output
|
||||||
/// sf::err().rdbuf(previous);
|
/// sf::err().rdbuf(previous);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// \return Reference to std::ostream representing the SFML error stream
|
/// \return Reference to std::ostream representing the SFML error stream
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace sf
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class InputStream
|
class InputStream
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Virtual destructor
|
/// \brief Virtual destructor
|
||||||
|
@ -114,7 +114,7 @@ public :
|
||||||
/// // custom stream class that reads from inside a zip file
|
/// // custom stream class that reads from inside a zip file
|
||||||
/// class ZipStream : public sf::InputStream
|
/// class ZipStream : public sf::InputStream
|
||||||
/// {
|
/// {
|
||||||
/// public :
|
/// public:
|
||||||
///
|
///
|
||||||
/// ZipStream(std::string archive);
|
/// ZipStream(std::string archive);
|
||||||
///
|
///
|
||||||
|
@ -128,7 +128,7 @@ public :
|
||||||
///
|
///
|
||||||
/// Int64 getSize();
|
/// Int64 getSize();
|
||||||
///
|
///
|
||||||
/// private :
|
/// private:
|
||||||
///
|
///
|
||||||
/// ...
|
/// ...
|
||||||
/// };
|
/// };
|
||||||
|
|
|
@ -1,139 +1,139 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_LOCK_HPP
|
#ifndef SFML_LOCK_HPP
|
||||||
#define SFML_LOCK_HPP
|
#define SFML_LOCK_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Export.hpp>
|
#include <SFML/System/Export.hpp>
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
class Mutex;
|
class Mutex;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Automatic wrapper for locking and unlocking mutexes
|
/// \brief Automatic wrapper for locking and unlocking mutexes
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_SYSTEM_API Lock : NonCopyable
|
class SFML_SYSTEM_API Lock : NonCopyable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the lock with a target mutex
|
/// \brief Construct the lock with a target mutex
|
||||||
///
|
///
|
||||||
/// The mutex passed to sf::Lock is automatically locked.
|
/// The mutex passed to sf::Lock is automatically locked.
|
||||||
///
|
///
|
||||||
/// \param mutex Mutex to lock
|
/// \param mutex Mutex to lock
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
explicit Lock(Mutex& mutex);
|
explicit Lock(Mutex& mutex);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
/// The destructor of sf::Lock automatically unlocks its mutex.
|
/// The destructor of sf::Lock automatically unlocks its mutex.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~Lock();
|
~Lock();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Mutex& m_mutex; ///< Mutex to lock / unlock
|
Mutex& m_mutex; ///< Mutex to lock / unlock
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_LOCK_HPP
|
#endif // SFML_LOCK_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Lock
|
/// \class sf::Lock
|
||||||
/// \ingroup system
|
/// \ingroup system
|
||||||
///
|
///
|
||||||
/// sf::Lock is a RAII wrapper for sf::Mutex. By unlocking
|
/// sf::Lock is a RAII wrapper for sf::Mutex. By unlocking
|
||||||
/// it in its destructor, it ensures that the mutex will
|
/// it in its destructor, it ensures that the mutex will
|
||||||
/// always be released when the current scope (most likely
|
/// always be released when the current scope (most likely
|
||||||
/// a function) ends.
|
/// a function) ends.
|
||||||
/// This is even more important when an exception or an early
|
/// This is even more important when an exception or an early
|
||||||
/// return statement can interrupt the execution flow of the
|
/// return statement can interrupt the execution flow of the
|
||||||
/// function.
|
/// function.
|
||||||
///
|
///
|
||||||
/// For maximum robustness, sf::Lock should always be used
|
/// For maximum robustness, sf::Lock should always be used
|
||||||
/// to lock/unlock a mutex.
|
/// to lock/unlock a mutex.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::Mutex mutex;
|
/// sf::Mutex mutex;
|
||||||
///
|
///
|
||||||
/// void function()
|
/// void function()
|
||||||
/// {
|
/// {
|
||||||
/// sf::Lock lock(mutex); // mutex is now locked
|
/// sf::Lock lock(mutex); // mutex is now locked
|
||||||
///
|
///
|
||||||
/// functionThatMayThrowAnException(); // mutex is unlocked if this function throws
|
/// functionThatMayThrowAnException(); // mutex is unlocked if this function throws
|
||||||
///
|
///
|
||||||
/// if (someCondition)
|
/// if (someCondition)
|
||||||
/// return; // mutex is unlocked
|
/// return; // mutex is unlocked
|
||||||
///
|
///
|
||||||
/// } // mutex is unlocked
|
/// } // mutex is unlocked
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Because the mutex is not explicitely unlocked in the code,
|
/// Because the mutex is not explicitely unlocked in the code,
|
||||||
/// it may remain locked longer than needed. If the region
|
/// it may remain locked longer than needed. If the region
|
||||||
/// of the code that needs to be protected by the mutex is
|
/// of the code that needs to be protected by the mutex is
|
||||||
/// not the entire function, a good practice is to create a
|
/// not the entire function, a good practice is to create a
|
||||||
/// smaller, inner scope so that the lock is limited to this
|
/// smaller, inner scope so that the lock is limited to this
|
||||||
/// part of the code.
|
/// part of the code.
|
||||||
///
|
///
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::Mutex mutex;
|
/// sf::Mutex mutex;
|
||||||
///
|
///
|
||||||
/// void function()
|
/// void function()
|
||||||
/// {
|
/// {
|
||||||
/// {
|
/// {
|
||||||
/// sf::Lock lock(mutex);
|
/// sf::Lock lock(mutex);
|
||||||
/// codeThatRequiresProtection();
|
/// codeThatRequiresProtection();
|
||||||
///
|
///
|
||||||
/// } // mutex is unlocked here
|
/// } // mutex is unlocked here
|
||||||
///
|
///
|
||||||
/// codeThatDoesntCareAboutTheMutex();
|
/// codeThatDoesntCareAboutTheMutex();
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Having a mutex locked longer than required is a bad practice
|
/// Having a mutex locked longer than required is a bad practice
|
||||||
/// which can lead to bad performances. Don't forget that when
|
/// which can lead to bad performances. Don't forget that when
|
||||||
/// a mutex is locked, other threads may be waiting doing nothing
|
/// a mutex is locked, other threads may be waiting doing nothing
|
||||||
/// until it is released.
|
/// until it is released.
|
||||||
///
|
///
|
||||||
/// \see sf::Mutex
|
/// \see sf::Mutex
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,148 +1,148 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_MUTEX_HPP
|
#ifndef SFML_MUTEX_HPP
|
||||||
#define SFML_MUTEX_HPP
|
#define SFML_MUTEX_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Export.hpp>
|
#include <SFML/System/Export.hpp>
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
class MutexImpl;
|
class MutexImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Blocks concurrent access to shared resources
|
/// \brief Blocks concurrent access to shared resources
|
||||||
/// from multiple threads
|
/// from multiple threads
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_SYSTEM_API Mutex : NonCopyable
|
class SFML_SYSTEM_API Mutex : NonCopyable
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Mutex();
|
Mutex();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~Mutex();
|
~Mutex();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Lock the mutex
|
/// \brief Lock the mutex
|
||||||
///
|
///
|
||||||
/// If the mutex is already locked in another thread,
|
/// If the mutex is already locked in another thread,
|
||||||
/// this call will block the execution until the mutex
|
/// this call will block the execution until the mutex
|
||||||
/// is released.
|
/// is released.
|
||||||
///
|
///
|
||||||
/// \see unlock
|
/// \see unlock
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void lock();
|
void lock();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Unlock the mutex
|
/// \brief Unlock the mutex
|
||||||
///
|
///
|
||||||
/// \see lock
|
/// \see lock
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
priv::MutexImpl* m_mutexImpl; ///< OS-specific implementation
|
priv::MutexImpl* m_mutexImpl; ///< OS-specific implementation
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_MUTEX_HPP
|
#endif // SFML_MUTEX_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::Mutex
|
/// \class sf::Mutex
|
||||||
/// \ingroup system
|
/// \ingroup system
|
||||||
///
|
///
|
||||||
/// Mutex stands for "MUTual EXclusion". A mutex is a
|
/// Mutex stands for "MUTual EXclusion". A mutex is a
|
||||||
/// synchronization object, used when multiple threads are involved.
|
/// synchronization object, used when multiple threads are involved.
|
||||||
///
|
///
|
||||||
/// When you want to protect a part of the code from being accessed
|
/// When you want to protect a part of the code from being accessed
|
||||||
/// simultaneously by multiple threads, you typically use a
|
/// simultaneously by multiple threads, you typically use a
|
||||||
/// mutex. When a thread is locked by a mutex, any other thread
|
/// mutex. When a thread is locked by a mutex, any other thread
|
||||||
/// trying to lock it will be blocked until the mutex is released
|
/// trying to lock it will be blocked until the mutex is released
|
||||||
/// by the thread that locked it. This way, you can allow only
|
/// by the thread that locked it. This way, you can allow only
|
||||||
/// one thread at a time to access a critical region of your code.
|
/// one thread at a time to access a critical region of your code.
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// Database database; // this is a critical resource that needs some protection
|
/// Database database; // this is a critical resource that needs some protection
|
||||||
/// sf::Mutex mutex;
|
/// sf::Mutex mutex;
|
||||||
///
|
///
|
||||||
/// void thread1()
|
/// void thread1()
|
||||||
/// {
|
/// {
|
||||||
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread2
|
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread2
|
||||||
/// database.write(...);
|
/// database.write(...);
|
||||||
/// mutex.unlock(); // if thread2 was waiting, it will now be unblocked
|
/// mutex.unlock(); // if thread2 was waiting, it will now be unblocked
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// void thread2()
|
/// void thread2()
|
||||||
/// {
|
/// {
|
||||||
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread1
|
/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread1
|
||||||
/// database.write(...);
|
/// database.write(...);
|
||||||
/// mutex.unlock(); // if thread1 was waiting, it will now be unblocked
|
/// mutex.unlock(); // if thread1 was waiting, it will now be unblocked
|
||||||
/// }
|
/// }
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Be very careful with mutexes. A bad usage can lead to bad problems,
|
/// Be very careful with mutexes. A bad usage can lead to bad problems,
|
||||||
/// like deadlocks (two threads are waiting for each other and the
|
/// like deadlocks (two threads are waiting for each other and the
|
||||||
/// application is globally stuck).
|
/// application is globally stuck).
|
||||||
///
|
///
|
||||||
/// To make the usage of mutexes more robust, particularly in
|
/// To make the usage of mutexes more robust, particularly in
|
||||||
/// environments where exceptions can be thrown, you should
|
/// environments where exceptions can be thrown, you should
|
||||||
/// use the helper class sf::Lock to lock/unlock mutexes.
|
/// use the helper class sf::Lock to lock/unlock mutexes.
|
||||||
///
|
///
|
||||||
/// SFML mutexes are recursive, which means that you can lock
|
/// SFML mutexes are recursive, which means that you can lock
|
||||||
/// a mutex multiple times in the same thread without creating
|
/// a mutex multiple times in the same thread without creating
|
||||||
/// a deadlock. In this case, the first call to lock() behaves
|
/// a deadlock. In this case, the first call to lock() behaves
|
||||||
/// as usual, and the following ones have no effect.
|
/// as usual, and the following ones have no effect.
|
||||||
/// However, you must call unlock() exactly as many times as you
|
/// However, you must call unlock() exactly as many times as you
|
||||||
/// called lock(). If you don't, the mutex won't be released.
|
/// called lock(). If you don't, the mutex won't be released.
|
||||||
///
|
///
|
||||||
/// \see sf::Lock
|
/// \see sf::Lock
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,119 +1,119 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_NONCOPYABLE_HPP
|
#ifndef SFML_NONCOPYABLE_HPP
|
||||||
#define SFML_NONCOPYABLE_HPP
|
#define SFML_NONCOPYABLE_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Export.hpp>
|
#include <SFML/System/Export.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Utility class that makes any derived
|
/// \brief Utility class that makes any derived
|
||||||
/// class non-copyable
|
/// class non-copyable
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class SFML_SYSTEM_API NonCopyable
|
class SFML_SYSTEM_API NonCopyable
|
||||||
{
|
{
|
||||||
protected :
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
///
|
///
|
||||||
/// Because this class has a copy constructor, the compiler
|
/// Because this class has a copy constructor, the compiler
|
||||||
/// will not automatically generate the default constructor.
|
/// will not automatically generate the default constructor.
|
||||||
/// That's why we must define it explicitely.
|
/// That's why we must define it explicitely.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
NonCopyable() {}
|
NonCopyable() {}
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Disabled copy constructor
|
/// \brief Disabled copy constructor
|
||||||
///
|
///
|
||||||
/// By making the copy constructor private, the compiler will
|
/// By making the copy constructor private, the compiler will
|
||||||
/// trigger an error if anyone outside tries to use it.
|
/// trigger an error if anyone outside tries to use it.
|
||||||
/// To prevent NonCopyable or friend classes from using it,
|
/// To prevent NonCopyable or friend classes from using it,
|
||||||
/// we also give no definition, so that the linker will
|
/// we also give no definition, so that the linker will
|
||||||
/// produce an error if the first protection was inefficient.
|
/// produce an error if the first protection was inefficient.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
NonCopyable(const NonCopyable&);
|
NonCopyable(const NonCopyable&);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Disabled assignment operator
|
/// \brief Disabled assignment operator
|
||||||
///
|
///
|
||||||
/// By making the assignment operator private, the compiler will
|
/// By making the assignment operator private, the compiler will
|
||||||
/// trigger an error if anyone outside tries to use it.
|
/// trigger an error if anyone outside tries to use it.
|
||||||
/// To prevent NonCopyable or friend classes from using it,
|
/// To prevent NonCopyable or friend classes from using it,
|
||||||
/// we also give no definition, so that the linker will
|
/// we also give no definition, so that the linker will
|
||||||
/// produce an error if the first protection was inefficient.
|
/// produce an error if the first protection was inefficient.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
NonCopyable& operator =(const NonCopyable&);
|
NonCopyable& operator =(const NonCopyable&);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_NONCOPYABLE_HPP
|
#endif // SFML_NONCOPYABLE_HPP
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \class sf::NonCopyable
|
/// \class sf::NonCopyable
|
||||||
/// \ingroup system
|
/// \ingroup system
|
||||||
///
|
///
|
||||||
/// This class makes its instances non-copyable, by explicitely
|
/// This class makes its instances non-copyable, by explicitely
|
||||||
/// disabling its copy constructor and its assignment operator.
|
/// disabling its copy constructor and its assignment operator.
|
||||||
///
|
///
|
||||||
/// To create a non-copyable class, simply inherit from
|
/// To create a non-copyable class, simply inherit from
|
||||||
/// sf::NonCopyable.
|
/// sf::NonCopyable.
|
||||||
///
|
///
|
||||||
/// The type of inheritance (public or private) doesn't matter,
|
/// The type of inheritance (public or private) doesn't matter,
|
||||||
/// the copy constructor and assignment operator are declared private
|
/// the copy constructor and assignment operator are declared private
|
||||||
/// in sf::NonCopyable so they will end up being inaccessible in both
|
/// in sf::NonCopyable so they will end up being inaccessible in both
|
||||||
/// cases. Thus you can use a shorter syntax for inheriting from it
|
/// cases. Thus you can use a shorter syntax for inheriting from it
|
||||||
/// (see below).
|
/// (see below).
|
||||||
///
|
///
|
||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// class MyNonCopyableClass : sf::NonCopyable
|
/// class MyNonCopyableClass : sf::NonCopyable
|
||||||
/// {
|
/// {
|
||||||
/// ...
|
/// ...
|
||||||
/// };
|
/// };
|
||||||
/// \endcode
|
/// \endcode
|
||||||
///
|
///
|
||||||
/// Deciding whether the instances of a class can be copied
|
/// Deciding whether the instances of a class can be copied
|
||||||
/// or not is a very important design choice. You are strongly
|
/// or not is a very important design choice. You are strongly
|
||||||
/// encouraged to think about it before writing a class,
|
/// encouraged to think about it before writing a class,
|
||||||
/// and to use sf::NonCopyable when necessary to prevent
|
/// and to use sf::NonCopyable when necessary to prevent
|
||||||
/// many potential future errors when using it. This is also
|
/// many potential future errors when using it. This is also
|
||||||
/// a very important indication to users of your class.
|
/// a very important indication to users of your class.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,52 +1,52 @@
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SFML - Simple and Fast Multimedia Library
|
// SFML - Simple and Fast Multimedia Library
|
||||||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
// 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,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
// subject to the following restrictions:
|
// subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented;
|
// 1. The origin of this software must not be misrepresented;
|
||||||
// you must not claim that you wrote the original software.
|
// you must not claim that you wrote the original software.
|
||||||
// If you use this software in a product, an acknowledgment
|
// If you use this software in a product, an acknowledgment
|
||||||
// in the product documentation would be appreciated but is not required.
|
// in the product documentation would be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
// and must not be misrepresented as being the original software.
|
// and must not be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_SLEEP_HPP
|
#ifndef SFML_SLEEP_HPP
|
||||||
#define SFML_SLEEP_HPP
|
#define SFML_SLEEP_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/System/Export.hpp>
|
#include <SFML/System/Export.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \ingroup system
|
/// \ingroup system
|
||||||
/// \brief Make the current thread sleep for a given duration
|
/// \brief Make the current thread sleep for a given duration
|
||||||
///
|
///
|
||||||
/// sf::sleep is the best way to block a program or one of its
|
/// sf::sleep is the best way to block a program or one of its
|
||||||
/// threads, as it doesn't consume any CPU power.
|
/// threads, as it doesn't consume any CPU power.
|
||||||
///
|
///
|
||||||
/// \param duration Time to sleep
|
/// \param duration Time to sleep
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void SFML_SYSTEM_API sleep(Time duration);
|
void SFML_SYSTEM_API sleep(Time duration);
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_SLEEP_HPP
|
#endif // SFML_SLEEP_HPP
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue