aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp57
-rw-r--r--src/Config.cpp29
-rw-r--r--src/Downloader.cpp8
-rw-r--r--src/QuickMedia.cpp38
4 files changed, 57 insertions, 75 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index d5395fd..3f24e7d 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -110,6 +110,7 @@ namespace QuickMedia {
bottom_cut_off(false),
item_background(sf::Vector2f(1.0f, 1.0f), 10.0f, get_theme().selected_color, rounded_rectangle_shader),
reaction_background(sf::Vector2f(1.0f, 1.0f), 10.0f, get_theme().shade_color, rounded_rectangle_shader),
+ rounded_rectangle_shader(rounded_rectangle_shader),
rounded_rectangle_mask_shader(rounded_rectangle_mask_shader)
{
assert(rounded_rectangle_shader);
@@ -592,13 +593,13 @@ namespace QuickMedia {
window.draw(gradient_points, 4, sf::Quads);
}
- void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size) {
- draw(window, pos, size, Json::Value::nullSingleton());
+ double Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size) {
+ return draw(window, pos, size, Json::Value::nullSingleton());
}
// TODO: Use a render target for the whole body so all images can be put into one.
// TODO: Load thumbnails with more than one thread.
- void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) {
+ double Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) {
const bool rendering_card_view = card_view && card_view_enabled;
body_size_changed = std::abs(size.x - body_size.x) > 0.1f || std::abs(size.y - body_size.y) > 0.1f;
@@ -609,6 +610,7 @@ namespace QuickMedia {
const float scissor_y = pos.y;
pos.y = 0.0f;
+ size.x = std::max(0.0f, size.x - 10.0f);
if(!rendering_card_view) {
pos.x += body_spacing[body_theme].body_padding_horizontal;
size.x = std::max(0.0f, size.x - body_spacing[body_theme].body_padding_horizontal * 2.0f);
@@ -665,7 +667,7 @@ namespace QuickMedia {
clicked_body_item = nullptr;
draw_drop_shadow(window);
- return;
+ return 0.0f;
}
if(is_touch_enabled()) {
@@ -774,9 +776,9 @@ namespace QuickMedia {
}
item_background_prev_pos = item_background_new_pos;
- float body_total_height = 0.0f;
+ double body_total_height = 0.0;
if(rendering_card_view) {
- draw_card_view(window, pos, size, window_size, scissor_y);
+ body_total_height = draw_card_view(window, pos, size, window_size, scissor_y);
} else {
body_total_height = draw_list_view(window, pos, size, content_progress);
}
@@ -784,6 +786,31 @@ namespace QuickMedia {
window.setView(prev_view);
draw_drop_shadow(window);
+ const double scrolling_bar_height_ratio = body_total_height == 0.0 ? 0.0 : (size.y / body_total_height);
+ if(scrolling_bar_height_ratio <= 1.0) {
+ const double scrollbar_max_height = size.y - body_spacing[body_theme].body_padding_vertical * 2.0f;
+ double scrollbar_offset_y = body_total_height == 0.0 ? 0.0 : (std::abs(page_scroll) / body_total_height);
+
+ RoundedRectangle scrollbar(
+ sf::Vector2f(std::floor(5.0f * get_config().scale), std::floor(scrollbar_max_height * scrolling_bar_height_ratio)), std::floor(3.0f * get_config().scale),
+ get_theme().selected_color,
+ rounded_rectangle_shader);
+
+ float scrollbar_offset_x = size.x + 10.0f;
+ if(rendering_card_view)
+ scrollbar_offset_x = std::floor(size.x - scrollbar.get_size().x);
+
+ double scrollbar_y;
+ if(attach_side == AttachSide::TOP)
+ scrollbar_y = std::floor(scissor_y + body_spacing[body_theme].body_padding_vertical + scrollbar_offset_y * scrollbar_max_height);
+ else
+ scrollbar_y = std::floor(scissor_y + body_spacing[body_theme].body_padding_vertical + scrollbar_max_height - scrollbar.get_size().y - scrollbar_offset_y * scrollbar_max_height);
+
+ scrollbar.set_position(
+ sf::Vector2f(pos.x + scrollbar_offset_x, scrollbar_y));
+ scrollbar.draw(window);
+ }
+
// TODO: Move up where scroll is limited? then we wont delay this by 1 frame creating a small scroll overflow only in the opposite direction of attach side.
// Also take |selected_scrolled| into consideration
// Limit scroll in the opposide direction of attach side, since the scroll is already limited for the attach side above (with a simple check)
@@ -792,7 +819,6 @@ namespace QuickMedia {
if(top_cut_off && !bottom_cut_off && body_total_height > (size.y - body_spacing[body_theme].body_padding_vertical))
page_scroll = -(body_total_height - (size.y - body_spacing[body_theme].body_padding_vertical));
} else {
- body_total_height = -body_total_height;
if(bottom_cut_off && !top_cut_off && body_total_height > size.y)
page_scroll = (body_total_height - size.y);
}
@@ -807,7 +833,7 @@ namespace QuickMedia {
}
if(is_touch_enabled())
- return;
+ return body_total_height;
const float item_target_top_diff = item_background_target_pos.y - selected_scrolled - (attach_side == AttachSide::TOP ? body_spacing[body_theme].body_padding_vertical : 0.0f);
const float item_target_bottom_diff = (item_background_target_pos.y - selected_scrolled + item_background_target_size.y + body_spacing[body_theme].spacing_y) - size.y;
@@ -839,6 +865,8 @@ namespace QuickMedia {
else
page_scroll -= item_target_bottom_diff*page_scroll_speed;
}
+
+ return body_total_height;
}
void Body::update_dirty_state(BodyItem *body_item, float width) {
@@ -1007,7 +1035,7 @@ namespace QuickMedia {
return { std::floor(vec.x), std::floor(vec.y) };
}
- float Body::draw_list_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) {
+ double Body::draw_list_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) {
const int num_items = items.size();
const float pos_y_before_scroll = pos.y;
@@ -1183,10 +1211,10 @@ namespace QuickMedia {
}
render_items.clear();
- return pos.y - pos_y_start;
+ return std::abs(pos.y - pos_y_start);
}
- void Body::draw_card_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, sf::Vector2u window_size, float scissor_y) {
+ double Body::draw_card_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, sf::Vector2u window_size, float scissor_y) {
num_columns = size.x / card_width;
int space_left_column = size.x - (num_columns * card_width);
@@ -1205,9 +1233,9 @@ namespace QuickMedia {
if(num_columns <= num_columns_switch_to_list) {
num_columns = 1;
card_view_enabled = false;
- draw(window, body_pos, body_size);
+ const float body_total_height = draw(window, body_pos, body_size);
card_view_enabled = true;
- return;
+ return body_total_height;
}
const int space_left_row_each = space_left_column_each;
@@ -1221,6 +1249,7 @@ namespace QuickMedia {
int num_visible_rows = 1;
int row_max_height = 0;
const int num_items = items.size();
+ const float pos_y_start = page_scroll;
sf::Vector2f pos_offset(space_left_column_each, page_scroll);
while(item_index < num_items) {
@@ -1348,6 +1377,8 @@ namespace QuickMedia {
if(row_has_selected_item)
item_background_target_size = sf::Vector2f(card_width, row_max_height);
+
+ return std::abs(pos_offset.y - pos_y_start);
}
void Body::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, bool merge_with_previous) {
diff --git a/src/Config.cpp b/src/Config.cpp
index c75f120..266c45c 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -15,26 +15,17 @@ namespace QuickMedia {
static int xrdb_get_dpi() {
int xft_dpi = XFT_DPI_DEFAULT;
- FILE *xrdb_query = popen("xrdb -query", "r");
+ FILE *xrdb_query = popen("xrdb -get Xft.dpi", "r");
if(!xrdb_query)
return xft_dpi;
- char line[512];
- while(fgets(line, sizeof(line), xrdb_query)) {
- int line_length = strlen(line);
- if(line_length > 0 && line[line_length - 1] == '\n') {
- line[line_length - 1] = '\0';
- line_length--;
- }
-
- if(line_length > 8 && memcmp(line, "Xft.dpi:", 8) == 0) {
- int xft_dpi_file = atoi(line + 8);
- if(xft_dpi_file > 0) {
- xft_dpi = xft_dpi_file;
- break;
- }
- }
- }
+ char line[32];
+ line[0] = '\0';
+ fread(line, 1, sizeof(line), xrdb_query);
+
+ const int xft_dpi_file = atoi(line);
+ if(xft_dpi_file > 0)
+ xft_dpi = xft_dpi_file;
pclose(xrdb_query);
return xft_dpi;
@@ -44,7 +35,7 @@ namespace QuickMedia {
if(scale_set)
return scale;
- char *gdk_scale = getenv("GDK_SCALE");
+ const char *gdk_scale = getenv("GDK_SCALE");
if(gdk_scale) {
setlocale(LC_ALL, "C"); // Sigh... stupid C
scale = atof(gdk_scale);
@@ -143,8 +134,6 @@ namespace QuickMedia {
const Json::Value &scale_json = json_root["scale"];
if(scale_json.isNumeric())
config->scale = scale_json.asDouble();
- else
- config->scale = get_ui_scale();
const Json::Value &font_scale = json_root["font_scale"];
if(font_scale.isNumeric())
diff --git a/src/Downloader.cpp b/src/Downloader.cpp
index fc16e07..820ca81 100644
--- a/src/Downloader.cpp
+++ b/src/Downloader.cpp
@@ -185,9 +185,9 @@ namespace QuickMedia {
// TODO: Remove this async task and make the fd non blocking instead
youtube_dl_output_reader = AsyncTask<bool>([this]{
char line[128];
- char progress_c[10];
- char content_size_c[20];
- char download_speed_c[20];
+ char progress_c[11];
+ char content_size_c[21];
+ char download_speed_c[21];
while(true) {
if(fgets(line, sizeof(line), read_program_file)) {
@@ -469,4 +469,4 @@ namespace QuickMedia {
min_index = 0;
return downloaders[min_index].get();
}
-} \ No newline at end of file
+}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index bb71c73..9122108 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2054,12 +2054,6 @@ namespace QuickMedia {
}
}
- sf::RectangleShape more_items_above_rect;
- more_items_above_rect.setFillColor(get_theme().more_items_color);
-
- sf::RectangleShape more_items_below_rect;
- more_items_below_rect.setFillColor(get_theme().more_items_color);
-
sf::Event event;
sf::Clock frame_timer;
@@ -2173,12 +2167,6 @@ namespace QuickMedia {
gradient_points[3].position.x = 0.0f;
gradient_points[3].position.y = body_pos.y + gradient_height;
}
-
- more_items_above_rect.setPosition(sf::Vector2f(0.0f, body_pos.y));
- more_items_above_rect.setSize(sf::Vector2f(window_size.x, more_items_height));
-
- more_items_below_rect.setPosition(sf::Vector2f(0.0f, window_size.y - more_items_height));
- more_items_below_rect.setSize(sf::Vector2f(window_size.x, more_items_height));
}
if(tab_associated_data[selected_tab].fetching_next_page_running) {
@@ -2357,12 +2345,6 @@ namespace QuickMedia {
on_reached_end();
else if(tabs[selected_tab].body->attach_side == AttachSide::BOTTOM && !tabs[selected_tab].body->is_top_cut_off())
on_reached_end();
-
- if(tabs[selected_tab].body->is_top_cut_off())
- window.draw(more_items_above_rect);
-
- if(tabs[selected_tab].body->is_bottom_cut_off())
- window.draw(more_items_below_rect);
}
AsyncImageLoader::get_instance().update();
@@ -3975,12 +3957,6 @@ namespace QuickMedia {
const float chat_input_padding_x = std::floor(10.0f * get_config().scale);
const float chat_input_padding_y = std::floor(10.0f * get_config().scale);
- sf::RectangleShape more_items_above_rect;
- more_items_above_rect.setFillColor(get_theme().more_items_color);
-
- sf::RectangleShape more_items_below_rect;
- more_items_below_rect.setFillColor(get_theme().more_items_color);
-
sf::Vector2f body_pos;
sf::Vector2f body_size;
sf::Event event;
@@ -4381,12 +4357,6 @@ namespace QuickMedia {
logo_sprite.setPosition(logo_padding_x, chat_input_padding_y);
file_to_upload_sprite.setPosition(logo_sprite.getPosition() + sf::Vector2f(0.0f, logo_size.y + logo_file_to_upload_spacing));
-
- more_items_above_rect.setPosition(sf::Vector2f(0.0f, body_pos.y));
- more_items_above_rect.setSize(sf::Vector2f(window_size.x, more_items_height));
-
- more_items_below_rect.setPosition(sf::Vector2f(0.0f, window_size.y - more_items_height));
- more_items_below_rect.setSize(sf::Vector2f(window_size.x, more_items_height));
}
//comment_input.update();
@@ -4533,14 +4503,6 @@ namespace QuickMedia {
}
}
- if(navigation_stage == NavigationStage::REPLYING || navigation_stage == NavigationStage::VIEWING_COMMENTS) {
- if(thread_body->is_top_cut_off())
- window.draw(more_items_above_rect);
-
- if(thread_body->is_bottom_cut_off())
- window.draw(more_items_below_rect);
- }
-
AsyncImageLoader::get_instance().update();
window.display();
}