aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--include/Entry.hpp2
-rw-r--r--include/Text.hpp4
-rw-r--r--src/Entry.cpp8
-rw-r--r--src/QuickMedia.cpp104
-rw-r--r--src/Text.cpp17
6 files changed, 88 insertions, 48 deletions
diff --git a/TODO b/TODO
index 969ce1b..9a0593e 100644
--- a/TODO
+++ b/TODO
@@ -49,7 +49,6 @@ Sanitize check: do not allow pasting more than 2gb of text.
Add search bar for matrix rooms.
Put rooms with recent messages at the top and the ones that mention us further at the top (matrix), and also add a tab for favorited rooms? or tag them, whatever.
Allow setting matrix room priority (if it should always be at top).
-Use Entry instead of SearchBar for 4chan commenting as well.
Only add related videos to recommendations if its the first time we watch the video. This is to prevent rewatching a video multiple times from messing up recommendations.
Fix incorrect body visible rows count (draws incorrect number of items and incorrect counted, also messed up pg(up/down)).
Replace messages on matrix instead of appending edits (messages that begin with " * "). This also fixes edit of already edited messages.
diff --git a/include/Entry.hpp b/include/Entry.hpp
index 18a860c..2ef6b04 100644
--- a/include/Entry.hpp
+++ b/include/Entry.hpp
@@ -26,10 +26,12 @@ namespace QuickMedia {
void set_position(const sf::Vector2f &pos);
void set_max_width(float width);
void move_caret_to_end();
+ void append_text(std::string str);
float get_height();
OnEntrySubmit on_submit_callback;
+ bool draw_background;
private:
Text text;
float width;
diff --git a/include/Text.hpp b/include/Text.hpp
index 59693a2..6a4ed9c 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -58,10 +58,11 @@ namespace QuickMedia
{
public:
Text(const sf::Font *font, const sf::Font *cjk_font);
- Text(sf::String str, const sf::Font *font, const sf::Font *cjk_font, unsigned int characterSize, float maxWidth, bool plainText = true);
+ Text(sf::String str, const sf::Font *font, const sf::Font *cjk_font, unsigned int characterSize, float maxWidth);
void setString(sf::String str);
const sf::String& getString() const;
+ void appendText(sf::String str);
void setPosition(float x, float y);
void setPosition(const sf::Vector2f &position);
@@ -137,7 +138,6 @@ namespace QuickMedia
bool dirty;
bool dirtyText;
bool dirtyCaret;
- bool plainText;
bool editable;
bool visible;
CaretMoveDirection caretMoveDirection;
diff --git a/src/Entry.cpp b/src/Entry.cpp
index f9897ba..c57d6cb 100644
--- a/src/Entry.cpp
+++ b/src/Entry.cpp
@@ -11,6 +11,7 @@ const float background_margin_vertical = 0.0f;
namespace QuickMedia {
Entry::Entry(const std::string &placeholder_text, sf::Font *font, sf::Font *cjk_font) :
on_submit_callback(nullptr),
+ draw_background(true),
text("", font, cjk_font, 16, 0.0f),
width(0.0f),
background(sf::Vector2f(1.0f, 1.0f), 7.0f, 10),
@@ -36,7 +37,8 @@ namespace QuickMedia {
// (and also split text into lines to not draw them at all once they are not inside the scissor box)
void Entry::draw(sf::RenderWindow &window) {
background.setSize(sf::Vector2f(width, get_height()));
- //window.draw(background);
+ if(draw_background)
+ window.draw(background);
if(text.getString().isEmpty() && !text.isEditable()) {
window.draw(placeholder);
//sf::Vector2f placeholder_pos = placeholder.getPosition();
@@ -63,6 +65,10 @@ namespace QuickMedia {
text.moveCaretToEnd();
}
+ void Entry::append_text(std::string str) {
+ text.appendText(std::move(str));
+ }
+
void Entry::set_position(const sf::Vector2f &pos) {
background.setPosition(pos);
text.setPosition(pos + sf::Vector2f(background_margin_horizontal, background_margin_vertical - 3.0f));
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c68ad0b..782506d 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2444,7 +2444,6 @@ namespace QuickMedia {
return;
}
- // TODO: Have an option for the search bar to be multi-line.
search_bar->onTextUpdateCallback = nullptr;
search_bar->onTextSubmitCallback = [this](const std::string&) -> bool {
@@ -2506,7 +2505,6 @@ namespace QuickMedia {
show_notification("QuickMedia", "File manager failed to get files in directory: " + file_manager->get_current_dir().string(), Urgency::CRITICAL);
}
- // TODO: Have an option for the search bar to be multi-line.
search_bar->onTextUpdateCallback = [this](const sf::String &text) {
body->filter_search_fuzzy(text);
body->reset_selected();
@@ -2737,7 +2735,12 @@ namespace QuickMedia {
}, current_plugin->use_tor);
};
- auto post_comment = [this, &navigation_stage, &image_board, &board, &thread, &captcha_post_id, &comment_to_post, &request_new_google_captcha_challenge]() {
+ Entry comment_input("Press ctrl+m to begin writing a comment...", font.get(), cjk_font.get());
+ comment_input.draw_background = false;
+ comment_input.set_editable(false);
+
+ auto post_comment = [this, &comment_input, &navigation_stage, &image_board, &board, &thread, &captcha_post_id, &comment_to_post, &request_new_google_captcha_challenge]() {
+ comment_input.set_editable(false);
navigation_stage = NavigationStage::POSTING_COMMENT;
PostResult post_result = image_board->post_comment(board, thread, captcha_post_id, comment_to_post);
if(post_result == PostResult::OK) {
@@ -2762,12 +2765,7 @@ namespace QuickMedia {
}
};
- SearchBar comment_input(*font, &plugin_logo, "Write a comment...");
-
- // Instead of using search bar to searching, use it for commenting.
- // TODO: Have an option for the search bar to be multi-line.
- comment_input.onTextUpdateCallback = nullptr;
- comment_input.onTextSubmitCallback = [&post_comment_future, &navigation_stage, &request_new_google_captcha_challenge, &comment_to_post, &captcha_post_id, &captcha_solved_time, &post_comment, &image_board](const std::string &text) -> bool {
+ comment_input.on_submit_callback = [&post_comment_future, &navigation_stage, &request_new_google_captcha_challenge, &comment_to_post, &captcha_post_id, &captcha_solved_time, &post_comment, &image_board](const std::string &text) -> bool {
if(text.empty())
return false;
@@ -2789,6 +2787,17 @@ namespace QuickMedia {
return true;
};
+ sf::RectangleShape comment_input_shade;
+ comment_input_shade.setFillColor(sf::Color(33, 38, 44));
+
+ sf::Sprite logo_sprite(plugin_logo);
+
+ float prev_chat_height = comment_input.get_height();
+ float chat_input_height_full = 0.0f;
+ const float logo_padding_x = 15.0f;
+ const float chat_input_padding_x = 15.0f;
+ const float chat_input_padding_y = 15.0f;
+
sf::Vector2f body_pos;
sf::Vector2f body_size;
bool redraw = true;
@@ -2799,7 +2808,17 @@ namespace QuickMedia {
while (current_page == Page::IMAGE_BOARD_THREAD) {
while (window.pollEvent(event)) {
- comment_input.on_event(event);
+ if(navigation_stage == NavigationStage::REPLYING) {
+ comment_input.process_event(event);
+ // To prevent pressing enter in comment_input text submit from also immediately sending captcha solution.. is there no better solution?
+ if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Enter)
+ break;
+ if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
+ comment_input.set_editable(false);
+ navigation_stage = NavigationStage::VIEWING_COMMENTS;
+ break;
+ }
+ }
if (event.type == sf::Event::Closed) {
current_page = Page::EXIT;
@@ -2901,29 +2920,15 @@ namespace QuickMedia {
body->set_page_scroll(previous_page_scroll);
} else if(event.key.code == sf::Keyboard::M && event.key.control && selected_item) {
navigation_stage = NavigationStage::REPLYING;
+ comment_input.set_editable(true);
+ comment_input.move_caret_to_end();
} else if(event.key.code == sf::Keyboard::R && selected_item) {
- std::string text_to_add = ">>" + selected_item->post_number;
- if(comment_input.is_cursor_at_start_of_line())
- text_to_add += '\n';
- comment_input.append_text(text_to_add);
- }
- } else if(event.type == sf::Event::TextEntered && navigation_stage == NavigationStage::REPLYING) {
- comment_input.onTextEntered(event.text.unicode);
- }
-
- if(event.type == sf::Event::KeyPressed && navigation_stage == NavigationStage::REPLYING) {
- if(event.key.code == sf::Keyboard::Escape) {
- //comment_input.clear();
- navigation_stage = NavigationStage::VIEWING_COMMENTS;
+ std::string text_to_add = ">>" + selected_item->post_number + "\n";
+ comment_input.append_text(std::move(text_to_add));
+ comment_input.move_caret_to_end();
}
}
- if(navigation_stage == NavigationStage::REPLYING) {
- comment_input.caret_visible = true;
- } else {
- comment_input.caret_visible = false;
- }
-
if(event.type == sf::Event::KeyPressed && navigation_stage == NavigationStage::SOLVING_POST_CAPTCHA) {
int num = -1;
if(event.key.code >= sf::Keyboard::Num1 && event.key.code <= sf::Keyboard::Num9) {
@@ -2978,10 +2983,36 @@ namespace QuickMedia {
}
}
+ chat_input_height_full = comment_input.get_height() + chat_input_padding_y * 2.0f;
+
+ const float chat_height = comment_input.get_height();
+ if(std::abs(chat_height - prev_chat_height) > 1.0f) {
+ prev_chat_height = chat_height;
+ redraw = true;
+ }
+
if(redraw) {
redraw = false;
- comment_input.onWindowResize(window_size);
- get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
+ comment_input.set_max_width(window_size.x);
+
+ comment_input.set_max_width(window_size.x - (logo_padding_x + plugin_logo.getSize().x + chat_input_padding_x * 2.0f));
+ comment_input.set_position(sf::Vector2f(logo_padding_x + plugin_logo.getSize().x + chat_input_padding_x, window_size.y - chat_height - chat_input_padding_y));
+
+ float body_padding_horizontal = 25.0f;
+ float body_padding_vertical = 5.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;
+ }
+
+ comment_input_shade.setSize(sf::Vector2f(window_size.x, chat_input_height_full));
+ comment_input_shade.setPosition(0.0f, window_size.y - comment_input_shade.getSize().y);
+
+ body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical);
+ body_size = sf::Vector2f(body_width, window_size.y - comment_input_shade.getSize().y - body_padding_vertical);
+
+ logo_sprite.setPosition(logo_padding_x, window_size.y - comment_input_shade.getSize().y * 0.5f - plugin_logo.getSize().y * 0.5f);
}
//comment_input.update();
@@ -3065,9 +3096,13 @@ namespace QuickMedia {
window.draw(rect);
}
} else if(navigation_stage == NavigationStage::REPLYING) {
+ window.draw(comment_input_shade);
+ window.draw(logo_sprite);
comment_input.draw(window);
body->draw(window, body_pos, body_size);
} else if(navigation_stage == NavigationStage::VIEWING_COMMENTS) {
+ window.draw(comment_input_shade);
+ window.draw(logo_sprite);
comment_input.draw(window);
body->draw(window, body_pos, body_size);
}
@@ -3085,7 +3120,6 @@ namespace QuickMedia {
load_image_future.get();
// Clear post that is still being written.
- // TODO: A multiline text edit widget should be cleared instead of the search bar.
// TODO: This post should be saved for the thread. Each thread should have its own text edit widget,
// so you dont have to retype a post that was in the middle of being posted when returning.
}
@@ -3321,7 +3355,9 @@ namespace QuickMedia {
sf::Sprite logo_sprite(plugin_logo);
Entry chat_input("Press ctrl+m to begin writing a message...", font.get(), cjk_font.get());
+ chat_input.draw_background = false;
chat_input.set_editable(false);
+
chat_input.on_submit_callback = [matrix, &chat_input, &tabs, &selected_tab, &current_room_id, &new_page, &chat_state, &currently_operating_on_item](const sf::String &text) mutable {
if(tabs[selected_tab].type == ChatTabType::MESSAGES) {
if(text.isEmpty())
@@ -3873,12 +3909,9 @@ namespace QuickMedia {
}
if(redraw) {
- //chat_height += 10.0f;
redraw = false;
chat_input.set_max_width(window_size.x - (logo_padding_x + plugin_logo.getSize().x + chat_input_padding_x * 2.0f));
chat_input.set_position(sf::Vector2f(logo_padding_x + plugin_logo.getSize().x + chat_input_padding_x, window_size.y - chat_height - chat_input_padding_y));
- //chat_input.onWindowResize(window_size);
- //chat_input.set_vertical_position(window_size.y - chat_input.getBottomWithoutShadow());
float body_padding_horizontal = 25.0f;
float body_padding_vertical = 5.0f;
@@ -3893,7 +3926,6 @@ namespace QuickMedia {
body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical + tab_shade_height);
body_size = sf::Vector2f(body_width, window_size.y - chat_input_shade.getSize().y - body_padding_vertical - tab_shade_height);
- //get_body_dimensions(window_size, &chat_input, body_pos, body_size, true);
more_messages_below_rect.setSize(sf::Vector2f(window_size.x, gradient_height));
more_messages_below_rect.setPosition(0.0f, std::floor(window_size.y - chat_input_shade.getSize().y - gradient_height));
diff --git a/src/Text.cpp b/src/Text.cpp
index fb1373c..2165037 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -24,9 +24,9 @@ namespace QuickMedia
return -1;
}
- Text::Text(const sf::Font *_font, const sf::Font *_cjk_font) : Text("", _font, _cjk_font, 0, 0.0f, false) {}
+ Text::Text(const sf::Font *_font, const sf::Font *_cjk_font) : Text("", _font, _cjk_font, 0, 0.0f) {}
- Text::Text(sf::String _str, const sf::Font *_font, const sf::Font *_cjk_font, unsigned int _characterSize, float _maxWidth, bool _plainText) :
+ Text::Text(sf::String _str, const sf::Font *_font, const sf::Font *_cjk_font, unsigned int _characterSize, float _maxWidth) :
font(_font),
cjk_font(_cjk_font),
characterSize(_characterSize),
@@ -36,7 +36,6 @@ namespace QuickMedia
dirty(true),
dirtyText(false),
dirtyCaret(false),
- plainText(_plainText),
editable(false),
visible(true),
caretMoveDirection(CaretMoveDirection::NONE),
@@ -69,6 +68,12 @@ namespace QuickMedia
{
return str;
}
+
+ void Text::appendText(sf::String str) {
+ this->str += std::move(str);
+ dirty = true;
+ dirtyText = true;
+ }
void Text::setPosition(float x, float y)
{
@@ -86,6 +91,7 @@ namespace QuickMedia
return position;
}
+ // TODO: Instead of setting text to dirty, iterate vertices and change their positions
void Text::setMaxWidth(float maxWidth)
{
if(std::abs(maxWidth - this->maxWidth) > 1.0f)
@@ -151,11 +157,6 @@ namespace QuickMedia
if(editable != this->editable)
{
this->editable = editable;
- if(!plainText)
- {
- dirty = true;
- dirtyText = true;
- }
dirtyCaret = true;
}
}