aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-22 10:59:04 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-22 10:59:04 +0200
commit31b99befbe173508554cdd808c3947f45cc24ea3 (patch)
tree32c608cfe99e798ac06d35c311ef3066465bced9 /src
parent58f8ddf56649a3342b500b8526f1cee2593b4562 (diff)
Temporary fix for crash when resizing (text is deallocated when hidden), fix text randomly getting glitched out
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp68
-rw-r--r--src/QuickMedia.cpp3
-rw-r--r--src/Text.cpp1
3 files changed, 29 insertions, 43 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 9b6a5d8..78629f3 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -8,7 +8,6 @@
#include "../plugins/Plugin.hpp"
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Window/Event.hpp>
-#include <SFML/OpenGL.hpp>
#include <assert.h>
#include <cmath>
#include <malloc.h>
@@ -20,7 +19,6 @@ static const float padding_x = std::floor(10.0f * QuickMedia::get_ui_scale());
static const float image_padding_x = std::floor(5.0f * QuickMedia::get_ui_scale());
static const float padding_y = std::floor(5.0f * QuickMedia::get_ui_scale());
static const float embedded_item_padding_y = std::floor(0.0f * QuickMedia::get_ui_scale());
-static const double thumbnail_fade_duration_sec = 0.1;
static const float reaction_background_padding_x = std::floor(7.0f * QuickMedia::get_ui_scale());
static const float reaction_background_padding_y = std::floor(3.0f * QuickMedia::get_ui_scale());
@@ -496,8 +494,9 @@ namespace QuickMedia {
items_dirty = DirtyState::FALSE;
}
- sf::Vector2f scissor_pos = pos;
- sf::Vector2f scissor_size = size;
+ const float scissor_y = pos.y;
+ pos.y = 0.0f;
+
const float start_y = pos.y;
float frame_time = frame_timer.restart().asSeconds();
if(frame_time > 2.0f)
@@ -613,16 +612,19 @@ namespace QuickMedia {
if(!mouse_left_pressed) {
const float scroll_deaccel = 1.02f;
double deaccel = scroll_deaccel * (1.0 + frame_time);
- if(deaccel < 0.0001)
- deaccel = 1.0;
-
- mouse_scroll_accel.x /= deaccel;
- if(fabs(mouse_scroll_accel.x) < 0.0001)
+ if(deaccel > 0.0001) {
+ mouse_scroll_accel.x /= deaccel;
+ if(fabs(mouse_scroll_accel.x) < 0.0001)
+ mouse_scroll_accel.x = 0.0;
+
+ mouse_scroll_accel.y /= deaccel;
+ if(fabs(mouse_scroll_accel.y) < 0.0001)
+ mouse_scroll_accel.y = 0.0;
+ } else {
+ deaccel = 0.0;
mouse_scroll_accel.x = 0.0;
-
- mouse_scroll_accel.y /= deaccel;
- if(fabs(mouse_scroll_accel.y) < 0.0001)
mouse_scroll_accel.y = 0.0;
+ }
}
}
@@ -666,7 +668,7 @@ namespace QuickMedia {
selected_line_bottom_visible = true;
int num_items = items.size();
- if(num_items == 0 || size.y <= 0.0f) {
+ if(num_items == 0 || size.y <= 0.001f) {
for(auto &body_item : items) {
clear_body_item_cache(body_item.get());
if(body_item->embedded_item)
@@ -803,6 +805,11 @@ namespace QuickMedia {
sf::Vector2u window_size = window.getSize();
+ sf::View prev_view = window.getView();
+ sf::View new_view(sf::FloatRect(0.0f, 0.0f, window_size.x, window_size.y));
+ new_view.setViewport(sf::FloatRect(0.0f, scissor_y / (float)window_size.y, 1.0f, 1.0f));
+ window.setView(new_view);
+
if(prev_num_visible_items > 0) {
const float item_background_prev_pos_y = item_background.get_position().y;
const float item_background_pos_diff = item_background_target_pos_y - item_background_prev_pos_y;
@@ -814,12 +821,8 @@ namespace QuickMedia {
const float item_background_height_speed = 50.0f;
item_background.set_size(sf::Vector2f(size.x, item_background_prev_height + (item_background_height_diff * std::min(1.0f, frame_time * item_background_height_speed))));
- if(render_selected_item_bg) {
- glEnable(GL_SCISSOR_TEST);
- glScissor(scissor_pos.x, (int)window_size.y - (int)scissor_pos.y - (int)scissor_size.y, scissor_size.x, scissor_size.y);
+ if(render_selected_item_bg)
item_background.draw(window);
- glDisable(GL_SCISSOR_TEST);
- }
}
sf::Vector2f prev_pos = pos;
@@ -850,11 +853,7 @@ namespace QuickMedia {
if(prev_pos.y + item_height_with_merge <= start_y)
break;
- // This is needed here rather than above the loop, since update_dirty_text cant be called inside scissor because it corrupts the text for some reason
- glEnable(GL_SCISSOR_TEST);
- glScissor(scissor_pos.x, (int)window_size.y - (int)scissor_pos.y - (int)scissor_size.y, scissor_size.x, scissor_size.y);
draw_item(window, item.get(), prev_pos, size, item_height, i, content_progress, true, merge_with_previous);
- glDisable(GL_SCISSOR_TEST);
++num_visible_items;
first_visible_item = i;
last_visible_item = i;
@@ -906,11 +905,7 @@ namespace QuickMedia {
item->last_drawn_time = elapsed_time_sec;
- // This is needed here rather than above the loop, since update_dirty_text cant be called inside scissor because it corrupts the text for some reason
- glEnable(GL_SCISSOR_TEST);
- glScissor(scissor_pos.x, (int)window_size.y - (int)scissor_pos.y - (int)scissor_size.y, scissor_size.x, scissor_size.y);
draw_item(window, item.get(), after_pos, size, item_height, i, content_progress, true, after_merge_with_previous);
- glDisable(GL_SCISSOR_TEST);
after_pos.y += item_height;
after_pos.y += spacing_y;
++num_visible_items;
@@ -940,6 +935,8 @@ namespace QuickMedia {
break;
}
+ window.setView(prev_view);
+
if(first_fully_visible_item == -1)
first_fully_visible_item = selected_item;
if(last_fully_visible_item == -1)
@@ -981,7 +978,7 @@ namespace QuickMedia {
else
body_item->title_text = std::make_unique<Text>(std::move(str), false, std::floor(16 * get_ui_scale()), width, title_mark_urls);
body_item->title_text->setFillColor(body_item->get_title_color());
- body_item->title_text->updateGeometry();
+ //body_item->title_text->updateGeometry();
}
if(body_item->dirty_description) {
@@ -992,7 +989,7 @@ namespace QuickMedia {
else
body_item->description_text = std::make_unique<Text>(std::move(str), false, std::floor(14 * get_ui_scale()), width, true);
body_item->description_text->setFillColor(body_item->get_description_color());
- body_item->description_text->updateGeometry();
+ //body_item->description_text->updateGeometry();
}
if(body_item->dirty_author) {
@@ -1003,7 +1000,7 @@ namespace QuickMedia {
else
body_item->author_text = std::make_unique<Text>(std::move(str), true, std::floor(14 * get_ui_scale()), width);
body_item->author_text->setFillColor(body_item->get_author_color());
- body_item->author_text->updateGeometry();
+ //body_item->author_text->updateGeometry();
}
if(body_item->dirty_timestamp) {
@@ -1177,18 +1174,9 @@ namespace QuickMedia {
}
void Body::draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item, bool is_embedded) {
- update_dirty_state(item, size.x);
item->last_drawn_time = draw_timer.getElapsedTime().asMilliseconds();
- sf::Vector2u window_size = window.getSize();
get_item_height(item, size.x, true, false, false, -1);
- if(!is_embedded) {
- glEnable(GL_SCISSOR_TEST);
- glScissor(pos.x, (int)window_size.y - (int)pos.y - (int)size.y, size.x, size.y);
- }
draw_item(window, item, pos, size, size.y + spacing_y, -1, Json::Value::nullSingleton(), include_embedded_item);
- if(!is_embedded) {
- glDisable(GL_SCISSOR_TEST);
- }
}
// TODO: Better message? maybe fallback to the reply message, or message status (such as message redacted)
@@ -1361,7 +1349,7 @@ namespace QuickMedia {
for(int i = 0; i < item->reactions.size(); ++i) {
auto &reaction = item->reactions[i];
reaction.text->setMaxWidth(size.x - text_offset_x - image_padding_x);
- reaction.text->updateGeometry();
+ //reaction.text->updateGeometry();
reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight());
reaction.text->setPosition(std::floor(item_pos.x + text_offset_x + reaction_offset_x + reaction_background_padding_x), std::floor(item_pos.y + padding_y - 4.0f + reaction_background_padding_y));
reaction_background.set_position(sf::Vector2f(std::floor(item_pos.x + text_offset_x + reaction_offset_x), std::floor(item_pos.y + padding_y)));
@@ -1463,7 +1451,7 @@ namespace QuickMedia {
for(int i = 0; i < item->reactions.size(); ++i) {
auto &reaction = item->reactions[i];
reaction.text->setMaxWidth(width - text_offset_x - image_padding_x);
- reaction.text->updateGeometry();
+ //reaction.text->updateGeometry();
reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight());
reaction_offset_x += reaction.text->getWidth() + reaction_background_padding_x * 2.0f + reaction_spacing_x;
if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > width && i < (int)item->reactions.size() - 1) {
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 4d20b24..8de42a8 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -49,7 +49,6 @@
#include <json/writer.h>
#include <X11/keysym.h>
#include <X11/extensions/Xrandr.h>
-#include <SFML/OpenGL.hpp>
#include <GL/glx.h>
static const sf::Color back_color(21, 25, 30);
@@ -4518,7 +4517,7 @@ namespace QuickMedia {
std::string str_to_append = selected_mention_item->get_description();
if(!str_to_append.empty())
str_to_append.erase(0, 1);
- str_to_append += ": ";
+ str_to_append += " ";
chat_input.replace(chat_input.get_caret_index() - mention.filter.getSize(), mention.filter.getSize(), sf::String::fromUtf8(str_to_append.begin(), str_to_append.end()));
mention.hide();
}
diff --git a/src/Text.cpp b/src/Text.cpp
index 3790c85..0834048 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -352,7 +352,6 @@ namespace QuickMedia
} else {
url_ranges.clear();
}
- dirty = true;
}
if(!update_even_if_not_dirty && !dirty)