aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp104
1 files changed, 68 insertions, 36 deletions
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));