From e745c2239b8bcd30e75af27de5067dbcb1707ac1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 7 Aug 2019 23:46:24 +0200 Subject: Correctly scale images and video to window size --- include/Scale.hpp | 9 +++++++++ include/VideoPlayer.hpp | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 include/Scale.hpp (limited to 'include') diff --git a/include/Scale.hpp b/include/Scale.hpp new file mode 100644 index 0000000..4ab2882 --- /dev/null +++ b/include/Scale.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace QuickMedia { + sf::Vector2f wrap_to_size(const sf::Vector2f &size, const sf::Vector2f &clamp_size); + sf::Vector2f clamp_to_size(const sf::Vector2f &size, const sf::Vector2f &clamp_size); + sf::Vector2f get_ratio(const sf::Vector2f &original_size, const sf::Vector2f &new_size); +} \ No newline at end of file diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp index 6bd8f4f..0ae05b0 100644 --- a/include/VideoPlayer.hpp +++ b/include/VideoPlayer.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -25,11 +26,12 @@ namespace QuickMedia { class VideoPlayer { public: // Throws VideoInitializationException on error - VideoPlayer(unsigned int width, unsigned int height, sf::WindowHandle window_handle, const char *file, bool loop = false); + VideoPlayer(sf::RenderWindow &window, unsigned int width, unsigned int height, const char *file, bool loop = false); ~VideoPlayer(); + void handleEvent(sf::Event &event); void setPosition(float x, float y); - void resize(const sf::Vector2i &size); + void resize(const sf::Vector2f &size); void draw(sf::RenderWindow &window); // @path can also be an url if youtube-dl is installed @@ -40,7 +42,7 @@ namespace QuickMedia { std::atomic_bool event_update; PlaybackEndedCallback onPlaybackEndedCallback; private: - void handle_events(); + void handle_mpv_events(); private: mpv_handle *mpv; mpv_render_context *mpvGl; @@ -49,8 +51,9 @@ namespace QuickMedia { sf::Texture texture; sf::Uint8 *textureBuffer; sf::Vector2i video_size; - sf::Vector2i desired_size; + sf::Vector2f desired_size; sf::RectangleShape seekbar; sf::RectangleShape seekbar_background; + sf::Clock cursor_last_active_timer; }; } -- cgit v1.2.3