From 7be2111d61e0557c4a913e563a5b23631e6a167f Mon Sep 17 00:00:00 2001 From: Jonny Paton Date: Tue, 27 Feb 2018 12:17:08 -0800 Subject: [PATCH] Add iOS demo --- CMakeLists.txt | 2 +- cmake/Macros.cmake | 3 ++ examples/CMakeLists.txt | 62 +++++++++++++++++++---------------- examples/iOS/CMakeLists.txt | 26 +++++++++++++++ examples/iOS/main.cpp | 65 +++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 examples/iOS/CMakeLists.txt create mode 100644 examples/iOS/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a26a9c9e..8daaac8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,7 @@ else() endif() # add an option for building the examples -if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID)) +if(NOT SFML_OS_ANDROID) sfml_set_option(SFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them") else() set(SFML_BUILD_EXAMPLES FALSE) diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 0221b4d1..02dc145e 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -201,6 +201,9 @@ macro(sfml_add_example target) if(THIS_GUI_APP AND SFML_OS_WINDOWS AND NOT DEFINED CMAKE_CONFIGURATION_TYPES AND ${CMAKE_BUILD_TYPE} STREQUAL "Release") add_executable(${target} WIN32 ${target_input}) target_link_libraries(${target} PRIVATE sfml-main) + elseif(THIS_GUI_APP AND SFML_OS_IOS) + add_executable(${target} MACOSX_BUNDLE ${target_input}) + target_link_libraries(${target} PRIVATE sfml-main) else() add_executable(${target} ${target_input}) endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 872c77d9..cc23fbaa 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,30 +1,36 @@ -# add the examples subdirectories -if(SFML_BUILD_NETWORK) - add_subdirectory(ftp) - add_subdirectory(sockets) -endif() -if(SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO) - add_subdirectory(voip) -endif() -if(SFML_BUILD_AUDIO) - add_subdirectory(sound) - add_subdirectory(sound_capture) -endif() -if(SFML_BUILD_WINDOW) - add_subdirectory(window) -endif() -if(SFML_BUILD_GRAPHICS) - add_subdirectory(opengl) - add_subdirectory(shader) - if(SFML_OS_WINDOWS) - add_subdirectory(win32) - elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) - add_subdirectory(X11) - elseif(SFML_OS_MACOSX) - add_subdirectory(cocoa) +# iOS Demo +if(SFML_OS_IOS) + add_subdirectory(iOS) +else(SFML_OS_IOS) + + # add the examples subdirectories + if(SFML_BUILD_NETWORK) + add_subdirectory(ftp) + add_subdirectory(sockets) endif() -endif() -if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO) - add_subdirectory(pong) -endif() + if(SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO) + add_subdirectory(voip) + endif() + if(SFML_BUILD_AUDIO) + add_subdirectory(sound) + add_subdirectory(sound_capture) + endif() + if(SFML_BUILD_WINDOW) + add_subdirectory(window) + endif() + if(SFML_BUILD_GRAPHICS) + add_subdirectory(opengl) + add_subdirectory(shader) + if(SFML_OS_WINDOWS) + add_subdirectory(win32) + elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) + add_subdirectory(X11) + elseif(SFML_OS_MACOSX) + add_subdirectory(cocoa) + endif() + endif() + if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO) + add_subdirectory(pong) + endif() +endif(SFML_OS_IOS) \ No newline at end of file diff --git a/examples/iOS/CMakeLists.txt b/examples/iOS/CMakeLists.txt new file mode 100644 index 00000000..3aaea884 --- /dev/null +++ b/examples/iOS/CMakeLists.txt @@ -0,0 +1,26 @@ + +set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/ios) +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) + +# All source files +set(SRC ${SRCROOT}/main.cpp) + +# Use the resources from the android example +set(RESOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/../android/assets/canary.wav + ${CMAKE_CURRENT_SOURCE_DIR}/../android/assets/image.png + ${CMAKE_CURRENT_SOURCE_DIR}/../android/assets/orchestral.ogg + ${CMAKE_CURRENT_SOURCE_DIR}/../android/assets/sansation.ttf) + +set_source_files_properties( ${RESOURCES} PROPERTIES + MACOSX_PACKAGE_LOCATION Resources ) + +# Define the window target +sfml_add_example(ios_demo GUI_APP + SOURCES ${SRC} ${RESOURCES} + DEPENDS sfml-window sfml-system sfml-graphics sfml-audio + "-framework OpenGLES") + +# The app needs an identifier and signing to work correctly +SET_XCODE_PROPERTY(ios_demo CODE_SIGN_IDENTITY "iPhone Developer") +set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.sfml.ios_demo") diff --git a/examples/iOS/main.cpp b/examples/iOS/main.cpp new file mode 100644 index 00000000..473b2b91 --- /dev/null +++ b/examples/iOS/main.cpp @@ -0,0 +1,65 @@ +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +//////////////////////////////////////////////////////////// +/// Entry point of application +/// +/// \return Application exit code +/// +//////////////////////////////////////////////////////////// +int main() +{ + sf::RenderWindow window(sf::VideoMode::getDesktopMode(), ""); + + sf::Texture texture; + if(!texture.loadFromFile("image.png")) + return EXIT_FAILURE; + + sf::Sprite image(texture); + image.setPosition(0, 0); + image.setOrigin(texture.getSize().x/2, texture.getSize().y/2); + + sf::Music music; + if(!music.openFromFile("canary.wav")) + return EXIT_FAILURE; + + music.play(); + + sf::View view = window.getDefaultView(); + + while (window.isOpen()) + { + sf::Event event; + + while (window.pollEvent(event)) + { + switch (event.type) + { + case sf::Event::Closed: + window.close(); + break; + case sf::Event::Resized: + view.setSize(event.size.width, event.size.height); + view.setCenter(event.size.width/2, event.size.height/2); + window.setView(view); + break; + case sf::Event::TouchBegan: + if (event.touch.finger == 0) + { + image.setPosition(event.touch.x, event.touch.y); + } + break; + } + } + + window.clear(sf::Color::White); + window.draw(image); + window.display(); + } +} +