aboutsummaryrefslogtreecommitdiff
path: root/include/Body.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-17 09:47:45 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-17 09:59:29 +0100
commit453eac7f1f5ef70390ec51087fc1f190811a7507 (patch)
tree21a32ef6de9a3d7c29562484104b56c12518a6f0 /include/Body.hpp
parentfc49d40c0d2f6edbbe9dde1f1b53d6a17e9d9f7d (diff)
Replace sfml with mgl
Diffstat (limited to 'include/Body.hpp')
-rw-r--r--include/Body.hpp91
1 files changed, 47 insertions, 44 deletions
diff --git a/include/Body.hpp b/include/Body.hpp
index d4eb49f..45749ce 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -2,11 +2,12 @@
#include "BodyItem.hpp"
#include "RoundedRectangle.hpp"
-#include <SFML/Graphics/RectangleShape.hpp>
-#include <SFML/Graphics/Sprite.hpp>
+#include <mglpp/graphics/Rectangle.hpp>
+#include <mglpp/graphics/Sprite.hpp>
+#include <functional>
-namespace sf {
- class RenderWindow;
+namespace mgl {
+ class Window;
class Shader;
class Texture;
class Event;
@@ -17,6 +18,8 @@ namespace Json {
}
namespace QuickMedia {
+ void init_body_themes();
+
class ThumbnailData;
using BodyItemRenderCallback = std::function<void(std::shared_ptr<BodyItem> &body_item)>;
// Return true to merge
@@ -41,7 +44,7 @@ namespace QuickMedia {
class Body {
public:
- Body(BodyTheme body_theme, sf::Texture &loading_icon_texture, sf::Shader *rounded_rectangle_shader, sf::Shader *rounded_rectangle_mask_shader);
+ Body(BodyTheme body_theme, mgl::Texture &loading_icon_texture, mgl::Shader *rounded_rectangle_shader, mgl::Shader *rounded_rectangle_mask_shader);
~Body();
// Select previous page, ignoring invisible items. Returns true if the item was changed. This can be used to check if the top was hit when wrap_around is set to false
@@ -102,17 +105,17 @@ namespace QuickMedia {
void clamp_selection();
// Returns true if the event was handled
- bool on_event(const sf::RenderWindow &window, const sf::Event &event, bool keyboard_navigation = true);
+ bool on_event(const mgl::Window &window, const mgl::Event &event, bool keyboard_navigation = true);
// Returns the the body total height
- double draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size);
+ double draw(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size);
// Returns the the body total height
- double draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress);
+ double draw(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, const Json::Value &content_progress);
// |size| is the clip size, another outside this will be cut off.
// Note: this should be called after |draw|, or thumbnails will be messed up. TODO: find a way to solve this issue in a clean way.
// This happens because of |draw| sets thumbnails as unreferenced at the beginning and cleans them up at the end if they are not drawn in the same function call.
// TODO: Right now drawing an item that also exists in the body will cause the text to update geometry every frame if the text is wrapping text and the items are drawn at different sizes,
// because of Text::setMaxWidth
- void draw_item(sf::RenderWindow &window, std::shared_ptr<BodyItem> &item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item = true, bool is_embedded = false);
+ void draw_item(mgl::Window &window, std::shared_ptr<BodyItem> &item, mgl::vec2f pos, mgl::vec2f size, bool include_embedded_item = true, bool is_embedded = false);
float get_item_height(BodyItem *item, float width, bool load_texture = true, bool include_embedded_item = true, bool merge_with_previous = false, int item_index = -1);
@@ -137,11 +140,11 @@ namespace QuickMedia {
bool draw_thumbnails;
// Set to {0, 0} to disable resizing
- sf::Vector2i thumbnail_max_size;
+ mgl::vec2i thumbnail_max_size;
BodyItemRenderCallback body_item_render_callback;
BodyItemMergeHandler body_item_merge_handler;
std::function<void(BodyItem*)> body_item_select_callback;
- sf::Shader *thumbnail_mask_shader;
+ mgl::Shader *thumbnail_mask_shader;
AttachSide attach_side = AttachSide::TOP;
bool title_mark_urls = false;
bool swiping_enabled = false;
@@ -151,18 +154,18 @@ namespace QuickMedia {
std::function<void()> on_top_reached = nullptr;
std::function<void()> on_bottom_reached = nullptr;
private:
- void draw_drop_shadow(sf::RenderWindow &window);
+ void draw_drop_shadow(mgl::Window &window);
void filter_search_fuzzy_item(const std::string &text, BodyItem *body_item);
- void handle_item_render(const sf::Vector2f pos, const float item_width, const float item_height, int item_index);
+ void handle_item_render(const mgl::vec2f pos, const float item_width, const float item_height, int item_index);
// Returns the the body total height
- double draw_list_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress);
+ double draw_list_view(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, const Json::Value &content_progress);
// Returns the the body total height
- double draw_card_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, sf::Vector2u window_size, float scissor_y);
- void draw_item(sf::RenderWindow &window, std::shared_ptr<BodyItem> &item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item = true, bool merge_with_previous = false);
- void draw_card_item(sf::RenderWindow &window, std::shared_ptr<BodyItem> &item, const sf::Vector2f &pos, const sf::Vector2f &pos_offset, const sf::Vector2f &body_size, const sf::Vector2f &window_size, float item_height, float scissor_y, int item_index, ThumbnailData *item_thumbnail);
+ double draw_card_view(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, mgl::vec2i window_size, float scissor_y, bool &switched_to_list_view);
+ void draw_item(mgl::Window &window, std::shared_ptr<BodyItem> &item, const mgl::vec2f &pos, const mgl::vec2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item = true, bool merge_with_previous = false);
+ void draw_card_item(mgl::Window &window, std::shared_ptr<BodyItem> &item, const mgl::vec2f &pos, const mgl::vec2f &pos_offset, const mgl::vec2f &body_size, const mgl::vec2f &window_size, float item_height, float scissor_y, int item_index, ThumbnailData *item_thumbnail);
void update_dirty_state(BodyItem *body_item, float width);
void clear_body_item_cache(BodyItem *body_item);
- sf::Vector2i get_item_thumbnail_size(BodyItem *item) const;
+ mgl::vec2i get_item_thumbnail_size(BodyItem *item) const;
// Returns -1 if not found
int get_previous_visible_item(int start_index);
@@ -189,9 +192,9 @@ namespace QuickMedia {
struct RenderItem {
std::shared_ptr<BodyItem> body_item;
- sf::Vector2f pos;
- sf::Vector2f pos_offset;
- sf::Vector2f size;
+ mgl::vec2f pos;
+ mgl::vec2f pos_offset;
+ mgl::vec2f size;
float item_height;
int item_index;
bool merge_with_previous;
@@ -212,14 +215,14 @@ namespace QuickMedia {
float selected_scrolled = 0.0f;
// TODO: Use a loading gif or something similar instead, to properly indicate the image is loading. Which could also have text that says "failed to load image" when image loading failed.
// TODO: Use rounded rectangle instead
- sf::RectangleShape image_fallback;
- //sf::RectangleShape item_separator;
- sf::Sprite image;
- sf::Sprite loading_icon;
+ mgl::Rectangle image_fallback;
+ //mgl::Rectangle item_separator;
+ mgl::Sprite image;
+ mgl::Sprite loading_icon;
- sf::Text progress_text;
- sf::Text replies_text;
- sf::Text embedded_item_load_text;
+ mgl::Text progress_text;
+ mgl::Text replies_text;
+ mgl::Text embedded_item_load_text;
bool body_size_changed = false;
@@ -228,8 +231,8 @@ namespace QuickMedia {
bool bottom_cut_off;
int first_visible_item = -1;
int last_visible_item = -1;
- sf::Clock draw_timer;
- sf::Clock frame_timer;
+ mgl::Clock draw_timer;
+ mgl::Clock frame_timer;
double elapsed_time_sec = 0.0;
bool selected_line_top_visible = true;
bool selected_line_bottom_visible = true;
@@ -242,15 +245,15 @@ namespace QuickMedia {
int selected_column = 0;
bool card_view_enabled = true;
StuckDirection stuck_direction = StuckDirection::NONE;
- sf::Vector2f mouse_click_pos;
- sf::Vector2f mouse_release_pos;
+ mgl::vec2f mouse_click_pos;
+ mgl::vec2f mouse_release_pos;
double mouse_press_pixels_moved_abs;
- sf::Vector2f mouse_pos;
- sf::Vector2i prev_mouse_pos_raw;
- sf::Vector2i mouse_pos_raw;
- sf::Vector2f mouse_scroll_accel;
- sf::Vector2f body_pos;
- sf::Vector2f body_size;
+ mgl::vec2f mouse_pos;
+ mgl::vec2i prev_mouse_pos_raw;
+ mgl::vec2i mouse_pos_raw;
+ mgl::vec2f mouse_scroll_accel;
+ mgl::vec2f body_pos;
+ mgl::vec2f body_size;
double body_swipe_x = 0.0;
bool body_swipe_move_right = false;
bool grabbed_left_side = false;
@@ -259,15 +262,15 @@ namespace QuickMedia {
RoundedRectangle item_background;
RoundedRectangle reaction_background;
bool render_selected_item_bg = true;
- sf::Vector2f item_background_prev_pos;
- sf::Vector2f item_background_target_pos;
- sf::Vector2f item_background_prev_size;
- sf::Vector2f item_background_target_size;
+ mgl::vec2f item_background_prev_pos;
+ mgl::vec2f item_background_target_pos;
+ mgl::vec2f item_background_prev_size;
+ mgl::vec2f item_background_target_size;
float item_background_target_height = 0.0f;
TargetSetState target_set = TargetSetState::NOT_SET;
std::string current_filter;
bool using_filter = false;
- sf::Shader *rounded_rectangle_shader;
- sf::Shader *rounded_rectangle_mask_shader;
+ mgl::Shader *rounded_rectangle_shader;
+ mgl::Shader *rounded_rectangle_mask_shader;
};
} \ No newline at end of file