aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ImageViewer.cpp10
-rw-r--r--src/QuickMedia.cpp121
2 files changed, 39 insertions, 92 deletions
diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp
index 9777611..8ce9b30 100644
--- a/src/ImageViewer.cpp
+++ b/src/ImageViewer.cpp
@@ -117,6 +117,10 @@ namespace QuickMedia {
return true;
}
+ static double sign(double value) {
+ return value >= 0.0 ? 1.0 : -1.0;
+ }
+
ImageViewerAction ImageViewer::draw(sf::RenderWindow &window) {
const double frame_delta = frame_timer.restart().asSeconds();
const double scroll_speed_key_input = 450.0;
@@ -177,7 +181,11 @@ namespace QuickMedia {
if(middle_mouse_scrolling) {
double distance_to_start_y = (double)sf::Mouse::getPosition(window).y - autoscroll_start_y;
- scroll_speed = -distance_to_start_y * scroll_speed_autoscroll * frame_delta;
+ double dist_abs = std::abs(distance_to_start_y);
+ dist_abs -= 20.0;
+ if(dist_abs < 0.0)
+ dist_abs = 0.0;
+ scroll_speed = -(dist_abs * sign(distance_to_start_y)) * scroll_speed_autoscroll * frame_delta;
const double max_speed = 100.0;
if(scroll_speed > max_speed)
scroll_speed = max_speed;
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 99d713e..eefc45a 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -30,6 +30,8 @@
static const sf::Color back_color(30, 32, 34);
static const int DOUBLE_CLICK_TIME = 500;
static const std::string fourchan_google_captcha_api_key = "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc";
+static const float tab_text_size = 18.0f;
+static const float tab_height = tab_text_size + 10.0f;
// Prevent writing to broken pipe from exiting the program
static void sigpipe_handler(int unused) {
@@ -469,6 +471,25 @@ namespace QuickMedia {
fill_history_items_from_json(load_video_history_json(plugin), history_items);
}
+ static void get_body_dimensions(const sf::Vector2f &window_size, SearchBar *search_bar, sf::Vector2f &body_pos, sf::Vector2f &body_size, bool has_tabs = false) {
+ float body_padding_horizontal = 25.0f;
+ float body_padding_vertical = 25.0f;
+ float body_width = window_size.x - body_padding_horizontal * 2.0f;
+ if(body_width <= 480.0f) {
+ body_width = window_size.x;
+ body_padding_horizontal = 0.0f;
+ body_padding_vertical = 10.0f;
+ }
+
+ float tab_h = tab_height;
+ if(!has_tabs)
+ tab_h = 0.0f;
+
+ float search_bottom = search_bar->getBottomWithoutShadow();
+ body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical + tab_h);
+ body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical - tab_h);
+ }
+
void Program::search_suggestion_page() {
std::string update_search_text;
bool search_running = false;
@@ -479,16 +500,14 @@ namespace QuickMedia {
Body history_body(this, font, bold_font);
std::unique_ptr<Body> recommended_body;
- const float tab_text_size = 18.0f;
- const float tab_height = tab_text_size + 10.0f;
sf::Text all_tab_text("All", font, tab_text_size);
sf::Text history_tab_text("History", font, tab_text_size);
sf::Text recommended_tab_text("Recommended", font, tab_text_size);
- //if(current_plugin->name == "youtube") {
+ // if(current_plugin->name == "youtube") {
// recommended_body = std::make_unique<Body>(this, font, bold_font);
// recommended_body->draw_thumbnails = true;
- //}
+ // }
struct Tab {
Body *body;
@@ -636,18 +655,7 @@ namespace QuickMedia {
if(redraw) {
redraw = false;
search_bar->onWindowResize(window_size);
-
- float body_padding_horizontal = 50.0f;
- float body_padding_vertical = tab_spacer_height + tab_height + 50.0f;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- if(body_width < 400) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }
-
- float search_bottom = search_bar->getBottomWithoutShadow();
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical);
+ get_body_dimensions(window_size, search_bar.get(), body_pos, body_size, true);
}
search_bar->update();
@@ -762,18 +770,7 @@ namespace QuickMedia {
if(redraw) {
redraw = false;
search_bar->onWindowResize(window_size);
-
- float body_padding_horizontal = 50.0f;
- float body_padding_vertical = 50.0f;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- if(body_width < 400) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }
-
- float search_bottom = search_bar->getBottom();
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical);
+ get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
}
search_bar->update();
@@ -1161,18 +1158,7 @@ namespace QuickMedia {
if(redraw) {
redraw = false;
search_bar->onWindowResize(window_size);
-
- float body_padding_horizontal = 50.0f;
- float body_padding_vertical = 50.0f;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- if(body_width < 400) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }
-
- float search_bottom = search_bar->getBottom();
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical);
+ get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
}
search_bar->update();
@@ -1594,18 +1580,7 @@ namespace QuickMedia {
if(redraw) {
redraw = false;
search_bar->onWindowResize(window_size);
-
- float body_padding_horizontal = 50.0f;
- float body_padding_vertical = 50.0f;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- if(body_width < 400) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }
-
- float search_bottom = search_bar->getBottom();
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical);
+ get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
}
search_bar->update();
@@ -1650,22 +1625,10 @@ namespace QuickMedia {
redraw = true;
}
- // TODO: This code is duplicated in many places. Handle it in one place.
if(redraw) {
redraw = false;
search_bar->onWindowResize(window_size);
-
- float body_padding_horizontal = 50.0f;
- float body_padding_vertical = 50.0f;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- if(body_width < 400) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }
-
- float search_bottom = search_bar->getBottom();
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical);
+ get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
}
search_bar->update();
@@ -1715,22 +1678,10 @@ namespace QuickMedia {
redraw = true;
}
- // TODO: This code is duplicated in many places. Handle it in one place.
if(redraw) {
redraw = false;
search_bar->onWindowResize(window_size);
-
- float body_padding_horizontal = 50.0f;
- float body_padding_vertical = 50.0f;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- if(body_width < 400) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }
-
- float search_bottom = search_bar->getBottom();
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical);
+ get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
}
search_bar->update();
@@ -2070,22 +2021,10 @@ namespace QuickMedia {
}
}
- // TODO: This code is duplicated in many places. Handle it in one place.
if(redraw) {
redraw = false;
search_bar->onWindowResize(window_size);
-
- float body_padding_horizontal = 50.0f;
- float body_padding_vertical = 50.0f;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- if(body_width < 400) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }
-
- float search_bottom = search_bar->getBottom();
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical);
+ get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
}
//search_bar->update();