aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-07 23:46:24 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-07 23:46:27 +0200
commite745c2239b8bcd30e75af27de5067dbcb1707ac1 (patch)
treeaa15d0452b8d26fd255880defb056c4bb13add52 /include
parent852c6bc48b7044c54923b722ab5d9363a27ceb6c (diff)
Correctly scale images and video to window size
Diffstat (limited to 'include')
-rw-r--r--include/Scale.hpp9
-rw-r--r--include/VideoPlayer.hpp11
2 files changed, 16 insertions, 4 deletions
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 <SFML/System/Vector2.hpp>
+
+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 <SFML/Graphics/RenderWindow.hpp>
+#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
@@ -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;
};
}