2025-08-02 20:10:33 +03:00
|
|
|
#pragma once
|
2025-12-26 10:40:58 +03:00
|
|
|
#include "../../../CanvasComponents/TextBoxCanvasComponent.hpp"
|
2025-08-02 20:10:33 +03:00
|
|
|
#include "DrawingProgramEditToolBase.hpp"
|
|
|
|
|
#include <Helpers/SCollision.hpp>
|
|
|
|
|
#include <any>
|
2026-04-04 17:52:43 +03:00
|
|
|
#include "../../../RichTextUserInput.hpp"
|
2025-08-02 20:10:33 +03:00
|
|
|
|
|
|
|
|
class DrawingProgram;
|
|
|
|
|
|
|
|
|
|
class TextBoxEditTool : public DrawingProgramEditToolBase {
|
|
|
|
|
public:
|
2026-04-04 17:52:43 +03:00
|
|
|
TextBoxEditTool(DrawingProgram& initDrawP, CanvasComponentContainer::ObjInfo* initComp);
|
|
|
|
|
|
|
|
|
|
virtual void edit_start(EditTool& editTool, std::any& prevData) override;
|
|
|
|
|
virtual void commit_edit_updates(std::any& prevData) override;
|
|
|
|
|
virtual bool edit_update() override;
|
|
|
|
|
virtual void edit_gui() override;
|
|
|
|
|
virtual void right_click_popup_gui(Vector2f popupPos) override;
|
|
|
|
|
|
2026-04-11 16:36:24 +03:00
|
|
|
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste) override;
|
2026-04-04 17:52:43 +03:00
|
|
|
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
|
|
|
|
virtual void input_text_callback(const InputManager::TextCallbackArgs& text) override;
|
|
|
|
|
virtual void input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button, bool isDraggingPoint) override;
|
|
|
|
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool isDraggingPoint) override;
|
2025-08-02 20:10:33 +03:00
|
|
|
private:
|
2026-04-04 17:52:43 +03:00
|
|
|
std::unique_ptr<RichTextUserInput> userInput;
|
|
|
|
|
std::optional<unsigned> textboxID;
|
|
|
|
|
|
2025-10-25 17:31:55 +03:00
|
|
|
struct TextBoxEditToolAllData {
|
2025-12-15 15:36:42 +03:00
|
|
|
TextBoxCanvasComponent::Data textboxData;
|
2025-11-10 14:45:51 +03:00
|
|
|
RichText::TextData richText;
|
2025-10-25 17:31:55 +03:00
|
|
|
};
|
2025-11-05 18:21:49 +03:00
|
|
|
|
|
|
|
|
uint32_t newFontSize = 15;
|
|
|
|
|
Vector4f newTextColor{1.0f, 1.0f, 1.0f, 1.0f};
|
2025-11-24 17:45:21 +03:00
|
|
|
Vector4f newHighlightColor{1.0f, 1.0f, 1.0f, 0.0f};
|
2025-11-09 16:24:40 +03:00
|
|
|
bool newIsBold = false;
|
|
|
|
|
bool newIsItalic = false;
|
|
|
|
|
bool newIsUnderlined = false;
|
|
|
|
|
bool newIsLinethrough = false;
|
|
|
|
|
bool newIsOverline = false;
|
2025-11-08 20:50:23 +03:00
|
|
|
std::string newFontName;
|
2025-11-27 10:54:56 +03:00
|
|
|
RichText::ParagraphStyleData currentPStyle;
|
2025-11-05 12:29:31 +03:00
|
|
|
|
2025-11-09 16:24:40 +03:00
|
|
|
uint8_t get_new_decoration_value();
|
2025-12-15 15:36:42 +03:00
|
|
|
void set_styles_at_selection(TextBoxCanvasComponent& a);
|
|
|
|
|
void add_undo_if_selecting_area(TextBoxCanvasComponent& a, const std::function<void()>& func);
|
2025-11-12 14:54:46 +03:00
|
|
|
void add_undo(const std::function<void()>& func);
|
|
|
|
|
|
2025-12-15 15:36:42 +03:00
|
|
|
void hold_undo_data(const std::string& undoName, TextBoxCanvasComponent& a);
|
2025-11-12 14:54:46 +03:00
|
|
|
void release_undo_data(const std::string& undoName);
|
|
|
|
|
|
2026-04-04 17:52:43 +03:00
|
|
|
void commit_update_func();
|
|
|
|
|
void commit_update_and_layout_func();
|
|
|
|
|
|
2025-11-12 14:54:46 +03:00
|
|
|
std::unordered_map<std::string, std::pair<RichText::TextBox::Cursor, RichText::TextData>> undoHeldData;
|
|
|
|
|
|
2026-03-07 13:12:11 +03:00
|
|
|
std::shared_ptr<RichText::TextStyleModifier::ModifierMap> currentModsPtr = std::make_shared<RichText::TextStyleModifier::ModifierMap>();
|
2025-11-05 12:29:31 +03:00
|
|
|
|
2025-11-08 20:50:23 +03:00
|
|
|
std::vector<std::string> sortedFontList;
|
|
|
|
|
|
2025-12-15 15:36:42 +03:00
|
|
|
TextBoxEditToolAllData get_all_data(const TextBoxCanvasComponent& a);
|
2025-08-02 20:10:33 +03:00
|
|
|
};
|