Fixed more RichTextBox issues, fixed segfault from zooming in/out too fast, fixed segfault from undoing an edit
This commit is contained in:
parent
4db5838a64
commit
011f8ba0b4
12 changed files with 113 additions and 88 deletions
|
|
@ -124,6 +124,9 @@ void DrawCamera::update_main(World& w) {
|
||||||
isAccurateZooming = newIsAccurateZooming;
|
isAccurateZooming = newIsAccurateZooming;
|
||||||
if(isAccurateZooming && startZoomVal != WorldScalar(0)) {
|
if(isAccurateZooming && startZoomVal != WorldScalar(0)) {
|
||||||
WorldScalar zoomFactor(std::pow(1.0 + w.main.toolbar.dragZoomSpeed, w.main.toolbar.flipZoomToolDirection ? w.main.input.mouse.move.y() : -w.main.input.mouse.move.y()));
|
WorldScalar zoomFactor(std::pow(1.0 + w.main.toolbar.dragZoomSpeed, w.main.toolbar.flipZoomToolDirection ? w.main.input.mouse.move.y() : -w.main.input.mouse.move.y()));
|
||||||
|
if(zoomFactor < WorldScalar(0.000001))
|
||||||
|
zoomFactor = WorldScalar(0.000001);
|
||||||
|
|
||||||
c.scale(zoomFactor);
|
c.scale(zoomFactor);
|
||||||
if(c.inverseScale < WorldScalar(0.0001))
|
if(c.inverseScale < WorldScalar(0.0001))
|
||||||
c.inverseScale = WorldScalar(0.0001);
|
c.inverseScale = WorldScalar(0.0001);
|
||||||
|
|
@ -139,6 +142,10 @@ void DrawCamera::update_main(World& w) {
|
||||||
// Ignore the value of scrollAmount, since that leads to problems on macOS
|
// Ignore the value of scrollAmount, since that leads to problems on macOS
|
||||||
|
|
||||||
WorldScalar zoomFactor(1.0 + w.main.toolbar.scrollZoomSpeed);
|
WorldScalar zoomFactor(1.0 + w.main.toolbar.scrollZoomSpeed);
|
||||||
|
|
||||||
|
if(zoomFactor < WorldScalar(0.000001))
|
||||||
|
zoomFactor = WorldScalar(0.000001);
|
||||||
|
|
||||||
if(zoomFactor != WorldScalar(0)) {
|
if(zoomFactor != WorldScalar(0)) {
|
||||||
if(w.main.input.mouse.scrollAmount.y() < 0.0)
|
if(w.main.input.mouse.scrollAmount.y() < 0.0)
|
||||||
zoomFactor = WorldScalar(1) / zoomFactor;
|
zoomFactor = WorldScalar(1) / zoomFactor;
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,13 @@ DrawComponentType DrawTextBox::get_type() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTextBox::save(cereal::PortableBinaryOutputArchive& a) const {
|
void DrawTextBox::save(cereal::PortableBinaryOutputArchive& a) const {
|
||||||
a(d.editing, d.p1, d.p2, d.textColor, d.textSize, *cursor, d.currentText);
|
a(d.editing, d.p1, d.p2, textBox->get_rich_text_data(), *cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTextBox::load(cereal::PortableBinaryInputArchive& a) {
|
void DrawTextBox::load(cereal::PortableBinaryInputArchive& a) {
|
||||||
a(d.editing, d.p1, d.p2, d.textColor, d.textSize, *cursor, d.currentText);
|
RichTextBox::RichTextData richText;
|
||||||
#ifndef IS_SERVER
|
a(d.editing, d.p1, d.p2, richText, *cursor);
|
||||||
textboxUpdate = true;
|
textBox->set_rich_text_data(richText);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef IS_SERVER
|
#ifndef IS_SERVER
|
||||||
|
|
@ -34,7 +33,7 @@ std::shared_ptr<DrawComponent> DrawTextBox::copy() const {
|
||||||
auto a = std::make_shared<DrawTextBox>();
|
auto a = std::make_shared<DrawTextBox>();
|
||||||
a->d = d;
|
a->d = d;
|
||||||
a->coords = coords;
|
a->coords = coords;
|
||||||
a->textboxUpdate = true;
|
a->textBox->set_rich_text_data(textBox->get_rich_text_data());
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +41,7 @@ std::shared_ptr<DrawComponent> DrawTextBox::deep_copy() const {
|
||||||
auto a = std::make_shared<DrawTextBox>();
|
auto a = std::make_shared<DrawTextBox>();
|
||||||
a->d = d;
|
a->d = d;
|
||||||
a->coords = coords;
|
a->coords = coords;
|
||||||
a->textboxUpdate = false;
|
a->textBox->set_rich_text_data(textBox->get_rich_text_data());
|
||||||
a->collisionTree = collisionTree;
|
a->collisionTree = collisionTree;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
@ -50,13 +49,11 @@ std::shared_ptr<DrawComponent> DrawTextBox::deep_copy() const {
|
||||||
void DrawTextBox::update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& delayedUpdatePtr) {
|
void DrawTextBox::update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& delayedUpdatePtr) {
|
||||||
std::shared_ptr<DrawTextBox> newPtr = std::static_pointer_cast<DrawTextBox>(delayedUpdatePtr);
|
std::shared_ptr<DrawTextBox> newPtr = std::static_pointer_cast<DrawTextBox>(delayedUpdatePtr);
|
||||||
d = newPtr->d;
|
d = newPtr->d;
|
||||||
textboxUpdate = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTextBox::init_text_box(DrawingProgram& drawP) {
|
void DrawTextBox::init_text_box(DrawingProgram& drawP) {
|
||||||
textBox->set_font_collection(drawP.world.main.fonts.collection);
|
textBox->set_font_collection(drawP.world.main.fonts.collection); // Getting a segfault relating to the paragraph cache means that the font collection hasn't been set yet
|
||||||
textBox->set_width(d.p2.x() - d.p1.x());
|
textBox->set_width(d.p2.x() - d.p1.x());
|
||||||
textBox->insert({0, 0}, d.currentText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTextBox::draw(SkCanvas* canvas, const DrawData& drawData) {
|
void DrawTextBox::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||||
|
|
@ -85,19 +82,6 @@ void DrawTextBox::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawTextBox::update(DrawingProgram& drawP) {
|
void DrawTextBox::update(DrawingProgram& drawP) {
|
||||||
if(textboxUpdate)
|
|
||||||
set_textbox_string(d.currentText);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawTextBox::set_textbox_string(const std::string& str) {
|
|
||||||
d.currentText = str;
|
|
||||||
textBox->remove({0, 0}, textBox->move(RichTextBox::Movement::END, {0, 0}));
|
|
||||||
textBox->insert({0, 0}, d.currentText);
|
|
||||||
textboxUpdate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawTextBox::update_contained_string(DrawingProgram& drawP) {
|
|
||||||
d.currentText = textBox->get_string();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2f DrawTextBox::get_mouse_pos(DrawingProgram& drawP) {
|
Vector2f DrawTextBox::get_mouse_pos(DrawingProgram& drawP) {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,9 @@ class DrawTextBox : public DrawComponent {
|
||||||
|
|
||||||
// User input data
|
// User input data
|
||||||
struct Data {
|
struct Data {
|
||||||
Vector4f textColor;
|
|
||||||
float textSize = -100000.0f;
|
|
||||||
Vector2f p1;
|
Vector2f p1;
|
||||||
Vector2f p2;
|
Vector2f p2;
|
||||||
std::string currentText;
|
bool editing = false; // Should probably move this out of the Data struct
|
||||||
bool editing = false;
|
|
||||||
bool operator==(const Data& o) const = default;
|
bool operator==(const Data& o) const = default;
|
||||||
bool operator!=(const Data& o) const = default;
|
bool operator!=(const Data& o) const = default;
|
||||||
} d;
|
} d;
|
||||||
|
|
@ -38,13 +35,10 @@ class DrawTextBox : public DrawComponent {
|
||||||
void create_collider();
|
void create_collider();
|
||||||
virtual void update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& delayedUpdatePtr) override;
|
virtual void update_from_delayed_ptr(const std::shared_ptr<DrawComponent>& delayedUpdatePtr) override;
|
||||||
void init_text_box(DrawingProgram& drawP);
|
void init_text_box(DrawingProgram& drawP);
|
||||||
void update_contained_string(DrawingProgram& drawP);
|
|
||||||
void set_textbox_string(const std::string& str);
|
|
||||||
Vector2f get_mouse_pos(DrawingProgram& drawP);
|
Vector2f get_mouse_pos(DrawingProgram& drawP);
|
||||||
|
|
||||||
virtual SCollision::AABB<float> get_obj_coord_bounds() const override;
|
virtual SCollision::AABB<float> get_obj_coord_bounds() const override;
|
||||||
|
|
||||||
bool textboxUpdate = false;
|
|
||||||
std::shared_ptr<RichTextBox> textBox;
|
std::shared_ptr<RichTextBox> textBox;
|
||||||
std::shared_ptr<RichTextBox::Cursor> cursor;
|
std::shared_ptr<RichTextBox::Cursor> cursor;
|
||||||
SCollision::BVHContainer<float> collisionTree;
|
SCollision::BVHContainer<float> collisionTree;
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ DrawingProgram::DrawingProgram(World& initWorld):
|
||||||
if(addToCompCacheOnInsert)
|
if(addToCompCacheOnInsert)
|
||||||
compCache.add_component(c);
|
compCache.add_component(c);
|
||||||
DrawComponentType t = c->obj->get_type();
|
DrawComponentType t = c->obj->get_type();
|
||||||
if(t == DRAWCOMPONENT_IMAGE || t == DRAWCOMPONENT_TEXTBOX)
|
if(t == DRAWCOMPONENT_IMAGE)
|
||||||
updateableComponents.emplace(c->obj);
|
updateableComponents.emplace(c->obj);
|
||||||
};
|
};
|
||||||
components.clientEraseCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
components.clientEraseCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ void DrawingProgramSelection::commit_transform_selection() {
|
||||||
}
|
}
|
||||||
DrawComponent::client_send_transform_many(drawP, transformsToSend);
|
DrawComponent::client_send_transform_many(drawP, transformsToSend);
|
||||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||||
[&, transformsFrom = transformsFrom]() {
|
[isSingleThread, &drawP = drawP, transformsFrom = transformsFrom]() {
|
||||||
std::vector<std::pair<ServerClientID, CoordSpaceHelper>> transformsToSend;
|
std::vector<std::pair<ServerClientID, CoordSpaceHelper>> transformsToSend;
|
||||||
for(auto& [comp, coords] : transformsFrom) {
|
for(auto& [comp, coords] : transformsFrom) {
|
||||||
auto lockObjInfo = comp->obj->collabListInfo.lock();
|
auto lockObjInfo = comp->obj->collabListInfo.lock();
|
||||||
|
|
@ -188,7 +188,6 @@ void DrawingProgramSelection::commit_transform_selection() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSingleThread = a.size() < DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD;
|
|
||||||
parallel_loop_container(transformsFrom, [&](auto& p) {
|
parallel_loop_container(transformsFrom, [&](auto& p) {
|
||||||
auto& [comp, coords] = p;
|
auto& [comp, coords] = p;
|
||||||
comp->obj->coords = coords;
|
comp->obj->coords = coords;
|
||||||
|
|
@ -202,7 +201,7 @@ void DrawingProgramSelection::commit_transform_selection() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&, transformsTo = transformsTo]() {
|
[isSingleThread, &drawP = drawP, transformsTo = transformsTo]() {
|
||||||
std::vector<std::pair<ServerClientID, CoordSpaceHelper>> transformsToSend;
|
std::vector<std::pair<ServerClientID, CoordSpaceHelper>> transformsToSend;
|
||||||
for(auto& [comp, coords] : transformsTo) {
|
for(auto& [comp, coords] : transformsTo) {
|
||||||
auto lockObjInfo = comp->obj->collabListInfo.lock();
|
auto lockObjInfo = comp->obj->collabListInfo.lock();
|
||||||
|
|
@ -212,7 +211,6 @@ void DrawingProgramSelection::commit_transform_selection() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSingleThread = a.size() < DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD;
|
|
||||||
parallel_loop_container(transformsTo, [&](auto& p) {
|
parallel_loop_container(transformsTo, [&](auto& p) {
|
||||||
auto& [comp, coords] = p;
|
auto& [comp, coords] = p;
|
||||||
comp->obj->coords = coords;
|
comp->obj->coords = coords;
|
||||||
|
|
|
||||||
|
|
@ -60,13 +60,13 @@ void EllipseDrawEditTool::commit_edit_updates(const std::shared_ptr<DrawComponen
|
||||||
DrawEllipse::Data pData = std::any_cast<DrawEllipse::Data>(prevData);
|
DrawEllipse::Data pData = std::any_cast<DrawEllipse::Data>(prevData);
|
||||||
DrawEllipse::Data cData = a->d;
|
DrawEllipse::Data cData = a->d;
|
||||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||||
[&, a, pData]() {
|
[&drawP = drawP, a, pData]() {
|
||||||
a->d = pData;
|
a->d = pData;
|
||||||
a->client_send_update(drawP, true);
|
a->client_send_update(drawP, true);
|
||||||
a->commit_update(drawP);
|
a->commit_update(drawP);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&, a, cData]() {
|
[&drawP = drawP, a, cData]() {
|
||||||
a->d = cData;
|
a->d = cData;
|
||||||
a->client_send_update(drawP, true);
|
a->client_send_update(drawP, true);
|
||||||
a->commit_update(drawP);
|
a->commit_update(drawP);
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,13 @@ void RectDrawEditTool::commit_edit_updates(const std::shared_ptr<DrawComponent>&
|
||||||
DrawRectangle::Data pData = std::any_cast<DrawRectangle::Data>(prevData);
|
DrawRectangle::Data pData = std::any_cast<DrawRectangle::Data>(prevData);
|
||||||
DrawRectangle::Data cData = a->d;
|
DrawRectangle::Data cData = a->d;
|
||||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||||
[&, a, pData]() {
|
[&drawP = drawP, a, pData]() {
|
||||||
a->d = pData;
|
a->d = pData;
|
||||||
a->client_send_update(drawP, true);
|
a->client_send_update(drawP, true);
|
||||||
a->commit_update(drawP);
|
a->commit_update(drawP);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&, a, cData]() {
|
[&drawP = drawP, a, cData]() {
|
||||||
a->d = cData;
|
a->d = cData;
|
||||||
a->client_send_update(drawP, true);
|
a->client_send_update(drawP, true);
|
||||||
a->commit_update(drawP);
|
a->commit_update(drawP);
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,20 @@ bool TextBoxEditTool::edit_gui(const std::shared_ptr<DrawComponent>& comp) {
|
||||||
Toolbar& t = drawP.world.main.toolbar;
|
Toolbar& t = drawP.world.main.toolbar;
|
||||||
t.gui.push_id("edit tool text");
|
t.gui.push_id("edit tool text");
|
||||||
t.gui.text_label_centered("Edit Text");
|
t.gui.text_label_centered("Edit Text");
|
||||||
t.gui.slider_scalar_field("Text Relative Size", "Text Size", &a->d.textSize, 5.0f, 100.0f);
|
//t.gui.slider_scalar_field("Text Relative Size", "Text Size", &a->d.textSize, 5.0f, 100.0f);
|
||||||
t.gui.left_to_right_line_layout([&]() {
|
//t.gui.left_to_right_line_layout([&]() {
|
||||||
CLAY({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(40), .height = CLAY_SIZING_FIXED(40)}}}) {
|
// CLAY({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(40), .height = CLAY_SIZING_FIXED(40)}}}) {
|
||||||
if(t.gui.color_button("Text Color", &a->d.textColor, &a->d.textColor == t.colorRight))
|
// if(t.gui.color_button("Text Color", &a->d.textColor, &a->d.textColor == t.colorRight))
|
||||||
t.color_selector_right(&a->d.textColor == t.colorRight ? nullptr : &a->d.textColor);
|
// t.color_selector_right(&a->d.textColor == t.colorRight ? nullptr : &a->d.textColor);
|
||||||
}
|
// }
|
||||||
t.gui.text_label("Text Color");
|
// t.gui.text_label("Text Color");
|
||||||
});
|
//});
|
||||||
t.gui.pop_id();
|
t.gui.pop_id();
|
||||||
bool editHappened = (!oldData.has_value()) || (a->d != oldData);
|
|
||||||
oldData = a->d;
|
TextBoxEditToolAllData newData = get_all_data(a);
|
||||||
|
bool editHappened = newData != oldData;
|
||||||
|
if(editHappened)
|
||||||
|
oldData = newData;
|
||||||
return editHappened;
|
return editHappened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,20 +37,21 @@ void TextBoxEditTool::commit_edit_updates(const std::shared_ptr<DrawComponent>&
|
||||||
std::shared_ptr<DrawTextBox> a = std::static_pointer_cast<DrawTextBox>(comp);
|
std::shared_ptr<DrawTextBox> a = std::static_pointer_cast<DrawTextBox>(comp);
|
||||||
|
|
||||||
a->d.editing = false;
|
a->d.editing = false;
|
||||||
DrawTextBox::Data pData = std::any_cast<DrawTextBox::Data>(prevData);
|
auto pData = std::any_cast<TextBoxEditToolAllData>(prevData);
|
||||||
DrawTextBox::Data cData = a->d;
|
TextBoxEditToolAllData cData = get_all_data(a);
|
||||||
|
RichTextBox::RichTextData richText = a->textBox->get_rich_text_data();
|
||||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||||
[&, a, pData]() {
|
[&drawP = drawP, a, pData]() {
|
||||||
a->d = pData;
|
a->d = pData.textboxData;
|
||||||
a->set_textbox_string(pData.currentText);
|
a->textBox->set_rich_text_data(pData.richText);
|
||||||
a->d.editing = false;
|
a->d.editing = false;
|
||||||
a->client_send_update(drawP, true);
|
a->client_send_update(drawP, true);
|
||||||
a->commit_update(drawP);
|
a->commit_update(drawP);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&, a, cData]() {
|
[&drawP = drawP, a, cData]() {
|
||||||
a->d = cData;
|
a->d = cData.textboxData;
|
||||||
a->set_textbox_string(cData.currentText);
|
a->textBox->set_rich_text_data(cData.richText);
|
||||||
a->d.editing = false;
|
a->d.editing = false;
|
||||||
a->client_send_update(drawP, true);
|
a->client_send_update(drawP, true);
|
||||||
a->commit_update(drawP);
|
a->commit_update(drawP);
|
||||||
|
|
@ -56,6 +60,13 @@ void TextBoxEditTool::commit_edit_updates(const std::shared_ptr<DrawComponent>&
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextBoxEditTool::TextBoxEditToolAllData TextBoxEditTool::get_all_data(const std::shared_ptr<DrawTextBox>& a) {
|
||||||
|
return {
|
||||||
|
.textboxData = a->d,
|
||||||
|
.richText = a->textBox->get_rich_text_data()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void TextBoxEditTool::edit_start(EditTool& editTool, const std::shared_ptr<DrawComponent>& comp, std::any& prevData) {
|
void TextBoxEditTool::edit_start(EditTool& editTool, const std::shared_ptr<DrawComponent>& comp, std::any& prevData) {
|
||||||
std::shared_ptr<DrawTextBox> a = std::static_pointer_cast<DrawTextBox>(comp);
|
std::shared_ptr<DrawTextBox> a = std::static_pointer_cast<DrawTextBox>(comp);
|
||||||
auto& cur = a->cursor;
|
auto& cur = a->cursor;
|
||||||
|
|
@ -63,7 +74,8 @@ void TextBoxEditTool::edit_start(EditTool& editTool, const std::shared_ptr<DrawC
|
||||||
cur = std::make_shared<RichTextBox::Cursor>();
|
cur = std::make_shared<RichTextBox::Cursor>();
|
||||||
Vector2f textSelectPos = a->get_mouse_pos(drawP);
|
Vector2f textSelectPos = a->get_mouse_pos(drawP);
|
||||||
textbox->process_mouse_left_button(*cur, textSelectPos, true, false, false);
|
textbox->process_mouse_left_button(*cur, textSelectPos, true, false, false);
|
||||||
prevData = a->d;
|
oldData = get_all_data(a);
|
||||||
|
prevData = oldData;
|
||||||
a->d.editing = true;
|
a->d.editing = true;
|
||||||
a->client_send_update(drawP, false);
|
a->client_send_update(drawP, false);
|
||||||
editTool.add_point_handle({&a->d.p1, nullptr, &a->d.p2});
|
editTool.add_point_handle({&a->d.p1, nullptr, &a->d.p2});
|
||||||
|
|
@ -88,15 +100,3 @@ bool TextBoxEditTool::edit_update(const std::shared_ptr<DrawComponent>& comp) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passing a function in, just in case we have to do something before editing the text
|
|
||||||
void TextBoxEditTool::edit_text(std::function<void()> toRun, const std::shared_ptr<DrawTextBox>& textBox) {
|
|
||||||
toRun();
|
|
||||||
textBox->update_contained_string(drawP);
|
|
||||||
update_textbox_network(textBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBoxEditTool::update_textbox_network(const std::shared_ptr<DrawTextBox>& textBox) {
|
|
||||||
textBox->client_send_update(drawP, false);
|
|
||||||
textBox->commit_update(drawP);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,13 @@ class TextBoxEditTool : public DrawingProgramEditToolBase {
|
||||||
virtual bool edit_update(const std::shared_ptr<DrawComponent>& a) override;
|
virtual bool edit_update(const std::shared_ptr<DrawComponent>& a) override;
|
||||||
virtual bool edit_gui(const std::shared_ptr<DrawComponent>& a) override;
|
virtual bool edit_gui(const std::shared_ptr<DrawComponent>& a) override;
|
||||||
private:
|
private:
|
||||||
void edit_text(std::function<void()> toRun, const std::shared_ptr<DrawTextBox>& textBox);
|
struct TextBoxEditToolAllData {
|
||||||
void update_textbox_network(const std::shared_ptr<DrawTextBox>& textBox);
|
DrawTextBox::Data textboxData;
|
||||||
|
RichTextBox::RichTextData richText;
|
||||||
std::optional<DrawTextBox::Data> oldData;
|
bool operator==(const TextBoxEditToolAllData& o) const = default;
|
||||||
|
bool operator!=(const TextBoxEditToolAllData& o) const = default;
|
||||||
|
};
|
||||||
|
TextBoxEditToolAllData get_all_data(const std::shared_ptr<DrawTextBox>& a);
|
||||||
|
|
||||||
|
TextBoxEditToolAllData oldData;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,13 @@ void TextBoxTool::tool_update() {
|
||||||
controls.endAt = controls.startAt;
|
controls.endAt = controls.startAt;
|
||||||
controls.intermediateItem->d.p1 = controls.intermediateItem->d.p2 = controls.startAt;
|
controls.intermediateItem->d.p1 = controls.intermediateItem->d.p2 = controls.startAt;
|
||||||
controls.intermediateItem->d.p2 = ensure_points_have_distance(controls.intermediateItem->d.p1, controls.intermediateItem->d.p2, MINIMUM_DISTANCE_BETWEEN_BOUNDS);
|
controls.intermediateItem->d.p2 = ensure_points_have_distance(controls.intermediateItem->d.p1, controls.intermediateItem->d.p2, MINIMUM_DISTANCE_BETWEEN_BOUNDS);
|
||||||
controls.intermediateItem->d.textColor = drawP.controls.foregroundColor;
|
|
||||||
controls.intermediateItem->d.textSize = controls.textRelativeSize;
|
|
||||||
controls.intermediateItem->d.editing = true;
|
controls.intermediateItem->d.editing = true;
|
||||||
controls.intermediateItem->coords = drawP.world.drawData.cam.c;
|
controls.intermediateItem->coords = drawP.world.drawData.cam.c;
|
||||||
controls.intermediateItem->lastUpdateTime = std::chrono::steady_clock::now();
|
controls.intermediateItem->lastUpdateTime = std::chrono::steady_clock::now();
|
||||||
uint64_t placement = drawP.components.client_list().size();
|
uint64_t placement = drawP.components.client_list().size();
|
||||||
auto objAdd = drawP.components.client_insert(placement, controls.intermediateItem);
|
auto objAdd = drawP.components.client_insert(placement, controls.intermediateItem);
|
||||||
controls.intermediateItem->client_send_place(drawP);
|
controls.intermediateItem->client_send_place(drawP);
|
||||||
|
controls.intermediateItem->commit_update(drawP);
|
||||||
drawP.add_undo_place_component(objAdd);
|
drawP.add_undo_place_component(objAdd);
|
||||||
controls.drawStage = 1;
|
controls.drawStage = 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,24 @@ RichTextBox::TextPosition RichTextBox::get_text_pos_closest_to_point(Vector2f po
|
||||||
return TextPosition{0, pIndex};
|
return TextPosition{0, pIndex};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RichTextBox::RichTextData RichTextBox::get_rich_text_data() {
|
||||||
|
return {get_string()};
|
||||||
|
}
|
||||||
|
|
||||||
|
void RichTextBox::clear_text() {
|
||||||
|
paragraphs.clear();
|
||||||
|
paragraphs.emplace_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RichTextBox::set_string(const std::string& str) {
|
||||||
|
clear_text();
|
||||||
|
insert({0, 0}, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RichTextBox::set_rich_text_data(const RichTextData& richText) {
|
||||||
|
set_string(richText.text);
|
||||||
|
}
|
||||||
|
|
||||||
std::string RichTextBox::get_string() {
|
std::string RichTextBox::get_string() {
|
||||||
return get_text_between({0, 0}, move(RichTextBox::Movement::END, {0, 0}));
|
return get_text_between({0, 0}, move(RichTextBox::Movement::END, {0, 0}));
|
||||||
}
|
}
|
||||||
|
|
@ -244,8 +262,6 @@ std::string RichTextBox::get_text_between(TextPosition p1, TextPosition p2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
RichTextBox::TextPosition RichTextBox::move(Movement movement, TextPosition pos, std::optional<float>* previousX, bool flipDependingOnTextDirection) {
|
RichTextBox::TextPosition RichTextBox::move(Movement movement, TextPosition pos, std::optional<float>* previousX, bool flipDependingOnTextDirection) {
|
||||||
rebuild();
|
|
||||||
|
|
||||||
if(pos.fParagraphIndex >= paragraphs.size()) {
|
if(pos.fParagraphIndex >= paragraphs.size()) {
|
||||||
pos.fParagraphIndex = paragraphs.size() - 1;
|
pos.fParagraphIndex = paragraphs.size() - 1;
|
||||||
pos.fTextByteIndex = paragraphs[pos.fParagraphIndex].text.size();
|
pos.fTextByteIndex = paragraphs[pos.fParagraphIndex].text.size();
|
||||||
|
|
@ -254,6 +270,8 @@ RichTextBox::TextPosition RichTextBox::move(Movement movement, TextPosition pos,
|
||||||
if(pos.fTextByteIndex >= paragraphs[pos.fParagraphIndex].text.size())
|
if(pos.fTextByteIndex >= paragraphs[pos.fParagraphIndex].text.size())
|
||||||
pos.fTextByteIndex = paragraphs[pos.fParagraphIndex].text.size();
|
pos.fTextByteIndex = paragraphs[pos.fParagraphIndex].text.size();
|
||||||
|
|
||||||
|
if(movement != Movement::NOWHERE && movement != Movement::HOME && movement != Movement::END) {
|
||||||
|
rebuild();
|
||||||
if(flipDependingOnTextDirection && paragraphs[pos.fParagraphIndex].pStyle.getTextDirection() == skia::textlayout::TextDirection::kRtl) {
|
if(flipDependingOnTextDirection && paragraphs[pos.fParagraphIndex].pStyle.getTextDirection() == skia::textlayout::TextDirection::kRtl) {
|
||||||
if(movement == Movement::LEFT)
|
if(movement == Movement::LEFT)
|
||||||
movement = Movement::RIGHT;
|
movement = Movement::RIGHT;
|
||||||
|
|
@ -264,6 +282,7 @@ RichTextBox::TextPosition RichTextBox::move(Movement movement, TextPosition pos,
|
||||||
else if(movement == Movement::RIGHT_WORD)
|
else if(movement == Movement::RIGHT_WORD)
|
||||||
movement = Movement::LEFT_WORD;
|
movement = Movement::LEFT_WORD;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (movement) {
|
switch (movement) {
|
||||||
case Movement::NOWHERE:
|
case Movement::NOWHERE:
|
||||||
|
|
@ -430,9 +449,11 @@ void RichTextBox::set_allow_newlines(bool allow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichTextBox::set_font_collection(const sk_sp<skia::textlayout::FontCollection>& fC) {
|
void RichTextBox::set_font_collection(const sk_sp<skia::textlayout::FontCollection>& fC) {
|
||||||
|
if(fontCollection != fC) {
|
||||||
fontCollection = fC;
|
fontCollection = fC;
|
||||||
needsRebuild = true;
|
needsRebuild = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RichTextBox::rebuild() {
|
void RichTextBox::rebuild() {
|
||||||
if(needsRebuild) {
|
if(needsRebuild) {
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,18 @@ class RichTextBox {
|
||||||
std::optional<Cursor> cursor;
|
std::optional<Cursor> cursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RichTextData {
|
||||||
|
std::string text;
|
||||||
|
bool operator==(const RichTextData& o) const = default;
|
||||||
|
bool operator!=(const RichTextData& o) const = default;
|
||||||
|
template <typename Archive> void save(Archive& a) const {
|
||||||
|
a(text);
|
||||||
|
}
|
||||||
|
template <typename Archive> void load(Archive& a) {
|
||||||
|
a(text);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TextPosition move(Movement movement, TextPosition pos, std::optional<float>* previousX = nullptr, bool flipDependingOnTextDirection = false);
|
TextPosition move(Movement movement, TextPosition pos, std::optional<float>* previousX = nullptr, bool flipDependingOnTextDirection = false);
|
||||||
void set_width(float newWidth);
|
void set_width(float newWidth);
|
||||||
TextPosition insert(TextPosition pos, std::string_view textToInsert);
|
TextPosition insert(TextPosition pos, std::string_view textToInsert);
|
||||||
|
|
@ -69,6 +81,11 @@ class RichTextBox {
|
||||||
SELECT_ALL
|
SELECT_ALL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RichTextData get_rich_text_data();
|
||||||
|
void set_rich_text_data(const RichTextData& richText);
|
||||||
|
void clear_text();
|
||||||
|
void set_string(const std::string& str);
|
||||||
|
|
||||||
void process_mouse_left_button(Cursor& cur, const Vector2f& pos, bool clicked, bool held, bool shift);
|
void process_mouse_left_button(Cursor& cur, const Vector2f& pos, bool clicked, bool held, bool shift);
|
||||||
void process_key_input(Cursor& cur, InputKey in, bool ctrl, bool shift);
|
void process_key_input(Cursor& cur, InputKey in, bool ctrl, bool shift);
|
||||||
std::string process_copy(Cursor& cur);
|
std::string process_copy(Cursor& cur);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue