diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-04 02:28:33 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-08-04 02:28:36 +0200 |
commit | 4b24638802385816fb5f90c95f175b30ae2398a8 (patch) | |
tree | ab6c7cbfd7d20c2065e160f6e8f20be02e4cc1b5 /include | |
parent | d9fb89269fd30fa44d2b3728b9ae3c7b896a77d3 (diff) |
Add youtube video playing, page navigation
Diffstat (limited to 'include')
-rw-r--r-- | include/Page.hpp | 10 | ||||
-rw-r--r-- | include/QuickMedia.hpp | 36 | ||||
-rw-r--r-- | include/SearchBar.hpp | 33 | ||||
-rw-r--r-- | include/VideoPlayer.hpp | 46 |
4 files changed, 125 insertions, 0 deletions
diff --git a/include/Page.hpp b/include/Page.hpp new file mode 100644 index 0000000..ce20971 --- /dev/null +++ b/include/Page.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace QuickMedia { + enum class Page { + EXIT, + SEARCH_SUGGESTION, + SEARCH_RESULT, + VIDEO_CONTENT + }; +}
\ No newline at end of file diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp new file mode 100644 index 0000000..291afff --- /dev/null +++ b/include/QuickMedia.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "SearchBar.hpp" +#include "Page.hpp" +#include <vector> +#include <stack> +#include <memory> +#include <SFML/Graphics/Font.hpp> +#include <SFML/Graphics/RenderWindow.hpp> + +namespace QuickMedia { + class Body; + class Plugin; + + class Program { + public: + Program(); + ~Program(); + void run(); + private: + void base_event_handler(sf::Event &event); + void search_suggestion_page(); + void search_result_page(); + void video_content_page(); + private: + sf::RenderWindow window; + sf::Vector2f window_size; + sf::Font font; + Body *body; + Plugin *current_plugin; + std::unique_ptr<SearchBar> search_bar; + Page current_page; + std::string video_url; + std::stack<Page> page_view_stack; + }; +}
\ No newline at end of file diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp new file mode 100644 index 0000000..c9f75f0 --- /dev/null +++ b/include/SearchBar.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include <SFML/Graphics/RenderWindow.hpp> +#include <SFML/Graphics/Font.hpp> +#include <SFML/Graphics/Text.hpp> +#include <SFML/Graphics/RectangleShape.hpp> +#include <functional> + +namespace QuickMedia { + using TextUpdateCallback = std::function<void(const sf::String &text)>; + using TextSubmitCallback = std::function<void(const sf::String &text)>; + + class SearchBar { + public: + SearchBar(sf::Font &font); + void draw(sf::RenderWindow &window); + void update(); + void onWindowResize(const sf::Vector2f &window_size); + void onTextEntered(sf::Uint32 codepoint); + void clear(); + + float getBottom() const; + + TextUpdateCallback onTextUpdateCallback; + TextSubmitCallback onTextSubmitCallback; + private: + sf::Text text; + sf::RectangleShape background; + bool show_placeholder; + bool updated_search; + sf::Clock time_since_search_update; + }; +}
\ No newline at end of file diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp new file mode 100644 index 0000000..e98221e --- /dev/null +++ b/include/VideoPlayer.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include <SFML/Graphics/RenderWindow.hpp> +#include <SFML/Graphics/Texture.hpp> +#include <SFML/Graphics/Sprite.hpp> +#include <SFML/Window/Context.hpp> +#include <thread> +#include <mutex> +#include <atomic> +#include <stdexcept> + +class mpv_handle; +class mpv_opengl_cb_context; + +namespace QuickMedia { + class VideoInitializationException : public std::runtime_error { + public: + VideoInitializationException(const std::string &errMsg) : std::runtime_error(errMsg) {} + }; + + class VideoPlayer { + public: + // Throws VideoInitializationException on error + VideoPlayer(unsigned int width, unsigned int height, const char *file, bool loop = false); + ~VideoPlayer(); + + void setPosition(float x, float y); + bool resize(const sf::Vector2i &size); + void draw(sf::RenderWindow &window); + + // This counter is incremented when mpv wants to redraw content + std::atomic_int redrawCounter; + private: + sf::Context context; + mpv_handle *mpv; + mpv_opengl_cb_context *mpvGl; + std::thread renderThread; + std::mutex renderMutex; + sf::Sprite sprite; + sf::Texture texture; + sf::Uint8 *textureBuffer; + bool alive; + sf::Vector2i video_size; + sf::Vector2i desired_size; + }; +} |