diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-08 04:58:17 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-08-08 04:58:20 +0200 |
commit | 0943801f321216dabe9f45593f608a222c0d4310 (patch) | |
tree | b74f2980628a19ae6bbe8e74b41b6cd665453cc9 /src | |
parent | 3c9ca2c97ae7a2b39bfe5c5e8a9d7941f9fb1525 (diff) |
Add video controls
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 4 | ||||
-rw-r--r-- | src/VideoPlayer.cpp | 36 |
2 files changed, 35 insertions, 5 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 856fc73..4fa5f35 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -323,7 +323,7 @@ namespace QuickMedia { std::unique_ptr<VideoPlayer> video_player = nullptr; try { printf("Play video: %s\n", content_url.c_str()); - video_player.reset(new VideoPlayer(window, window_size.x, window_size.y, content_url.c_str())); + video_player.reset(new VideoPlayer(&window, window_size.x, window_size.y, content_url.c_str())); } catch(VideoInitializationException &e) { show_notification("Video player", "Failed to create video player", Urgency::CRITICAL); video_player = nullptr; @@ -365,7 +365,7 @@ namespace QuickMedia { if(video_player) { if(event.type == sf::Event::Resized) video_player->resize(window_size); - video_player->handleEvent(event); + video_player->handle_event(event); } } diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 505f74b..62fc7d2 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -8,6 +8,8 @@ #include <cmath> const int UI_VISIBLE_TIMEOUT_MS = 2500; +const int DOUBLE_CLICK_TIME = 500; +const auto pause_key = sf::Keyboard::Space; namespace QuickMedia { static void* getProcAddressMpv(void *funcContext, const char *name) { @@ -51,7 +53,7 @@ namespace QuickMedia { sf::Context *context; }; - VideoPlayer::VideoPlayer(sf::RenderWindow &window, unsigned int width, unsigned int height, const char *file, bool loop) : + VideoPlayer::VideoPlayer(sf::RenderWindow *_window, unsigned int width, unsigned int height, const char *file, bool loop) : redraw(false), event_update(false), onPlaybackEndedCallback(nullptr), @@ -59,7 +61,10 @@ namespace QuickMedia { mpvGl(nullptr), context(nullptr), textureBuffer(nullptr), - desired_size(width, height) + desired_size(width, height), + left_click_counter(0), + window(_window), + video_is_fullscreen(false) { //ContextScope context_scope(context.get()); texture.setSmooth(true); @@ -133,12 +138,37 @@ namespace QuickMedia { //mpv_detach_destroy(mpv); mpv_terminate_destroy(mpv); } + + if(video_is_fullscreen) + window->create(sf::VideoMode::getDesktopMode(), "QuickMedia", sf::Style::Default); } - void VideoPlayer::handleEvent(sf::Event &event) { + void VideoPlayer::handle_event(sf::Event &event) { if(event.type == sf::Event::MouseMoved) { cursor_last_active_timer.restart(); + } else if(event.type == sf::Event::KeyPressed) { + if(event.key.code == pause_key) { + mpv_command_string(mpv, "cycle pause"); + } + } else if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) { + if(time_since_last_left_click.restart().asMilliseconds() <= DOUBLE_CLICK_TIME) { + if(++left_click_counter == 2) { + on_doubleclick(); + left_click_counter = 0; + } + } else { + left_click_counter = 1; + } + } + } + + void VideoPlayer::on_doubleclick() { + if(video_is_fullscreen) { + window->create(sf::VideoMode::getDesktopMode(), "QuickMedia", sf::Style::Default); + } else { + window->create(sf::VideoMode::getDesktopMode(), "QuickMedia", sf::Style::Fullscreen); } + video_is_fullscreen = !video_is_fullscreen; } void VideoPlayer::setPosition(float x, float y) { |