Add iOS demo
This commit is contained in:
parent
fc655f52b9
commit
7be2111d61
@ -67,7 +67,7 @@ else()
|
|||||||
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_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)
|
||||||
|
@ -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")
|
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})
|
add_executable(${target} WIN32 ${target_input})
|
||||||
target_link_libraries(${target} PRIVATE sfml-main)
|
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()
|
else()
|
||||||
add_executable(${target} ${target_input})
|
add_executable(${target} ${target_input})
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
|
|
||||||
|
# iOS Demo
|
||||||
|
if(SFML_OS_IOS)
|
||||||
|
add_subdirectory(iOS)
|
||||||
|
else(SFML_OS_IOS)
|
||||||
|
|
||||||
# add the examples subdirectories
|
# add the examples subdirectories
|
||||||
if(SFML_BUILD_NETWORK)
|
if(SFML_BUILD_NETWORK)
|
||||||
add_subdirectory(ftp)
|
add_subdirectory(ftp)
|
||||||
@ -28,3 +33,4 @@ endif()
|
|||||||
if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO)
|
if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO)
|
||||||
add_subdirectory(pong)
|
add_subdirectory(pong)
|
||||||
endif()
|
endif()
|
||||||
|
endif(SFML_OS_IOS)
|
26
examples/iOS/CMakeLists.txt
Normal file
26
examples/iOS/CMakeLists.txt
Normal 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
65
examples/iOS/main.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user