aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/QuickMedia.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 2e1eac3..819e298 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2793,10 +2793,12 @@ 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.
- search_bar->onTextUpdateCallback = nullptr;
- search_bar->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.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 {
if(text.empty())
return false;
@@ -2828,7 +2830,7 @@ namespace QuickMedia {
while (current_page == Page::IMAGE_BOARD_THREAD) {
while (window.pollEvent(event)) {
- search_bar->on_event(event);
+ comment_input.on_event(event);
if (event.type == sf::Event::Closed) {
current_page = Page::EXIT;
@@ -2850,7 +2852,6 @@ namespace QuickMedia {
current_page = Page::IMAGE_BOARD_THREAD_LIST;
body->clear_items();
body->reset_selected();
- search_bar->clear();
} else if(event.key.code == sf::Keyboard::P) {
BodyItem *selected_item = body->get_selected();
if(selected_item && !selected_item->attached_content_url.empty()) {
@@ -2929,21 +2930,27 @@ namespace QuickMedia {
navigation_stage = NavigationStage::REPLYING;
} else if(event.key.code == sf::Keyboard::R && selected_item) {
std::string text_to_add = ">>" + selected_item->post_number;
- if(search_bar->is_cursor_at_start_of_line())
+ if(comment_input.is_cursor_at_start_of_line())
text_to_add += '\n';
- search_bar->append_text(text_to_add);
+ comment_input.append_text(text_to_add);
}
} else if(event.type == sf::Event::TextEntered && navigation_stage == NavigationStage::REPLYING) {
- search_bar->onTextEntered(event.text.unicode);
+ comment_input.onTextEntered(event.text.unicode);
}
if(event.type == sf::Event::KeyPressed && navigation_stage == NavigationStage::REPLYING) {
if(event.key.code == sf::Keyboard::Escape) {
- //search_bar->clear();
+ //comment_input.clear();
navigation_stage = NavigationStage::VIEWING_COMMENTS;
}
}
+ 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) {
@@ -3000,11 +3007,11 @@ namespace QuickMedia {
if(redraw) {
redraw = false;
- search_bar->onWindowResize(window_size);
+ comment_input.onWindowResize(window_size);
get_body_dimensions(window_size, search_bar.get(), body_pos, body_size);
}
- //search_bar->update();
+ //comment_input.update();
window.clear(back_color);
if(navigation_stage == NavigationStage::SOLVING_POST_CAPTCHA) {
@@ -3067,10 +3074,10 @@ namespace QuickMedia {
window.draw(rect);
}
} else if(navigation_stage == NavigationStage::REPLYING) {
- search_bar->draw(window);
+ comment_input.draw(window);
body->draw(window, body_pos, body_size);
} else if(navigation_stage == NavigationStage::VIEWING_COMMENTS) {
- search_bar->draw(window);
+ comment_input.draw(window);
body->draw(window, body_pos, body_size);
}
window.display();
@@ -3090,7 +3097,6 @@ namespace QuickMedia {
// 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.
- search_bar->clear();
}
// TODO: Provide a way to logout
@@ -3264,6 +3270,7 @@ namespace QuickMedia {
// get_all_room_messages is not needed here because its done in the loop, where the initial timeout is 0ms
{
+ assert(plugin_logo.getNativeHandle() == 0); // Only load once
std::string plugin_logo_path = resources_root + "images/matrix_logo.png";
if(!plugin_logo.loadFromFile(plugin_logo_path)) {
show_notification("QuickMedia", "Failed to load plugin logo, path: " + plugin_logo_path, Urgency::CRITICAL);