aboutsummaryrefslogtreecommitdiff
path: root/src/VideoPlayer.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-08 04:58:17 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-08 04:58:20 +0200
commit0943801f321216dabe9f45593f608a222c0d4310 (patch)
treeb74f2980628a19ae6bbe8e74b41b6cd665453cc9 /src/VideoPlayer.cpp
parent3c9ca2c97ae7a2b39bfe5c5e8a9d7941f9fb1525 (diff)
Add video controls
Diffstat (limited to 'src/VideoPlayer.cpp')
-rw-r--r--src/VideoPlayer.cpp36
1 files changed, 33 insertions, 3 deletions
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) {