From 0943801f321216dabe9f45593f608a222c0d4310 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 8 Aug 2019 04:58:17 +0200 Subject: Add video controls --- src/VideoPlayer.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/VideoPlayer.cpp') 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 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) { -- cgit v1.2.3