Skip to content

Commit

Permalink
Merge branch 'feature/SampleProgram'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceylo committed May 29, 2015
2 parents dab8ee9 + 2ee097d commit d3b3ff9
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ if (SFEMOVIE_BUILD_UNIT_TESTS)
add_subdirectory(tests)
endif()

# Sample building
add_subdirectory(sample)
# Examples building
add_subdirectory(examples)

# add an option for building the documentation
set(SFEMOVIE_BUILD_DOC FALSE CACHE BOOL "Set to true to build the documentation, requires Doxygen")
Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

add_subdirectory(Demo)
add_subdirectory(MinimalistDemo)
18 changes: 9 additions & 9 deletions sample/CMakeLists.txt → examples/Demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(SFEMOVIE_SAMPLE "sfeMovieSample")
set(SFEMOVIE_DEMO "sfeMovieDemo")

set(SFEMOVIE_SAMPLE_SRC
set(SFEMOVIE_DEMO_SRC
main.cpp
MediaInfo.cpp
MediaInfo.hpp
Expand All @@ -9,40 +9,40 @@ set(SFEMOVIE_SAMPLE_SRC
UserInterface.cpp
UserInterface.hpp
)
source_group("Sources" FILES ${SFEMOVIE_DEMO_SRC})

add_executable(
${SFEMOVIE_SAMPLE}
${SFEMOVIE_SAMPLE_SRC}
${SFEMOVIE_DEMO}
${SFEMOVIE_DEMO_SRC}
)
source_group("Sources" FILES ${SFEMOVIE_SAMPLE_SRC})

if (SFEMOVIE_BUILD_STATIC)
set (SFML_STATIC_LIBRARIES TRUE)
find_package (SFML 2 COMPONENTS graphics window system audio REQUIRED)
message(STATUS "SFML libraries: ${SFML_LIBRARIES}")
message(STATUS "Additional dependencies: ${SFML_DEPENDENCIES}")

set_target_properties(${SFEMOVIE_SAMPLE} PROPERTIES
set_target_properties(${SFEMOVIE_DEMO} PROPERTIES
COMPILE_DEFINITIONS SFML_STATIC
COMPILE_DEFINITIONS SFEMOVIE_STATIC)
target_link_libraries(
${SFEMOVIE_SAMPLE}
${SFEMOVIE_DEMO}
${SFEMOVIE_LIB}
${FFMPEG_LIBRARIES}
${OTHER_LIBRARIES}
${SFML_LIBRARIES}
${SFML_DEPENDENCIES})
else()
target_link_libraries(
${SFEMOVIE_SAMPLE}
${SFEMOVIE_DEMO}
${SFEMOVIE_LIB}
${SFML_LIBRARIES}
${SFML_DEPENDENCIES}
)
endif()

if (MACOSX)
set_target_properties(${SFEMOVIE_SAMPLE} PROPERTIES
set_target_properties(${SFEMOVIE_DEMO} PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
INSTALL_RPATH "@executable_path/")
endif()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions sample/main.cpp → examples/Demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ int main(int argc, const char *argv[])
float width = std::min(static_cast<float>(desktopMode.width), movie.getSize().x);
float height = std::min(static_cast<float>(desktopMode.height), movie.getSize().y);

// For audio files, there is no frame size, set a minimum:
if (width * height < 1.f)
{
width = std::max(width, 250.f);
height = std::max(height, 40.f);
}

// Create window
sf::RenderWindow window(sf::VideoMode(width, height), "sfeMovie Player",
sf::Style::Close | sf::Style::Resize);
Expand Down
42 changes: 42 additions & 0 deletions examples/MinimalistDemo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
set(SFEMOVIE_MINIMALIST_DEMO "sfeMovieMinimalistDemo")

set(SFEMOVIE_MINIMALIST_DEMO_SRC
main.cpp
)
source_group("Sources" FILES ${SFEMOVIE_MINIMALIST_DEMO_SRC})

add_executable(
${SFEMOVIE_MINIMALIST_DEMO}
${SFEMOVIE_MINIMALIST_DEMO_SRC}
)

if (SFEMOVIE_BUILD_STATIC)
set (SFML_STATIC_LIBRARIES TRUE)
find_package (SFML 2 COMPONENTS graphics window system audio REQUIRED)
message(STATUS "SFML libraries: ${SFML_LIBRARIES}")
message(STATUS "Additional dependencies: ${SFML_DEPENDENCIES}")

set_target_properties(${SFEMOVIE_MINIMALIST_DEMO} PROPERTIES
COMPILE_DEFINITIONS SFML_STATIC
COMPILE_DEFINITIONS SFEMOVIE_STATIC)
target_link_libraries(
${SFEMOVIE_MINIMALIST_DEMO}
${SFEMOVIE_LIB}
${FFMPEG_LIBRARIES}
${OTHER_LIBRARIES}
${SFML_LIBRARIES}
${SFML_DEPENDENCIES})
else()
target_link_libraries(
${SFEMOVIE_MINIMALIST_DEMO}
${SFEMOVIE_LIB}
${SFML_LIBRARIES}
${SFML_DEPENDENCIES}
)
endif()

if (MACOSX)
set_target_properties(${SFEMOVIE_MINIMALIST_DEMO} PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
INSTALL_RPATH "@executable_path/")
endif()
133 changes: 133 additions & 0 deletions examples/MinimalistDemo/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

/*
* main.cpp
* sfeMovie project
*
* Copyright (C) 2010-2015 Lucas Soltic
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/


#include <SFML/Config.hpp>
#include <SFML/Graphics.hpp>
#include <sfeMovie/Movie.hpp>
#include <iostream>
#include <algorithm>


/*
* Here is a little use sample for sfeMovie.
* It'll open and display the movie specified by MOVIE_FILE above.
*
* This sample implements basic controls as follow:
* - Escape key to exit
* - Space key to play/pause the movie playback
*/

void my_pause()
{
#ifdef SFML_SYSTEM_WINDOWS
system("PAUSE");
#endif
}

int main(int argc, const char *argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << std::string(argv[0]) << " movie_path" << std::endl;
my_pause();
return 1;
}

std::string mediaFile = std::string(argv[1]);
std::cout << "Going to open movie file \"" << mediaFile << "\"" << std::endl;

sfe::Movie movie;
if (!movie.openFromFile(mediaFile))
{
my_pause();
return 1;
}

sf::VideoMode desktopMode = sf::VideoMode::getDesktopMode();
float width = std::min(static_cast<float>(desktopMode.width), movie.getSize().x);
float height = std::min(static_cast<float>(desktopMode.height), movie.getSize().y);

// For audio files, there is no frame size, set a minimum:
if (width * height < 1.f)
{
width = std::max(width, 250.f);
height = std::max(height, 40.f);
}

// Create window
sf::RenderWindow window(sf::VideoMode(width, height), "sfeMovie Player",
sf::Style::Close | sf::Style::Resize);

// Scale movie to the window drawing area and enable VSync
window.setFramerateLimit(60);
window.setVerticalSyncEnabled(true);

movie.fit(0, 0, width, height);
movie.play();

while (window.isOpen())
{
sf::Event ev;
while (window.pollEvent(ev))
{
// Window closure
if (ev.type == sf::Event::Closed ||
(ev.type == sf::Event::KeyPressed &&
ev.key.code == sf::Keyboard::Escape))
{
window.close();
}

if (ev.type == sf::Event::KeyPressed)
{
switch (ev.key.code)
{
case sf::Keyboard::Space:
if (movie.getStatus() == sfe::Playing)
movie.pause();
else
movie.play();
break;
default:
break;
}
}
else if (ev.type == sf::Event::Resized)
{
movie.fit(0, 0, window.getSize().x, window.getSize().y);
window.setView(sf::View(sf::FloatRect(0, 0, (float)window.getSize().x, (float)window.getSize().y)));
}
}

movie.update();

// Render movie
window.clear();
window.draw(movie);
window.display();
}

return 0;
}

0 comments on commit d3b3ff9

Please sign in to comment.