Add iOS demo

This commit is contained in:
Jonny Paton 2018-02-27 12:17:08 -08:00
parent fc655f52b9
commit 7be2111d61
5 changed files with 129 additions and 29 deletions

View File

@ -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)

View File

@ -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()

View File

@ -1,20 +1,25 @@
# add the examples subdirectories
if(SFML_BUILD_NETWORK)
# 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()
if(SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO)
endif()
if(SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO)
add_subdirectory(voip)
endif()
if(SFML_BUILD_AUDIO)
endif()
if(SFML_BUILD_AUDIO)
add_subdirectory(sound)
add_subdirectory(sound_capture)
endif()
if(SFML_BUILD_WINDOW)
endif()
if(SFML_BUILD_WINDOW)
add_subdirectory(window)
endif()
if(SFML_BUILD_GRAPHICS)
endif()
if(SFML_BUILD_GRAPHICS)
add_subdirectory(opengl)
add_subdirectory(shader)
if(SFML_OS_WINDOWS)
@ -24,7 +29,8 @@ if(SFML_BUILD_GRAPHICS)
elseif(SFML_OS_MACOSX)
add_subdirectory(cocoa)
endif()
endif()
if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO)
endif()
if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO)
add_subdirectory(pong)
endif()
endif()
endif(SFML_OS_IOS)

View File

@ -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")

65
examples/iOS/main.cpp Normal file
View File

@ -0,0 +1,65 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Main.hpp>
////////////////////////////////////////////////////////////
/// 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();
}
}