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
|
|
@ -43,7 +43,7 @@ DrawingProgram::DrawingProgram(World& initWorld):
|
|||
if(addToCompCacheOnInsert)
|
||||
compCache.add_component(c);
|
||||
DrawComponentType t = c->obj->get_type();
|
||||
if(t == DRAWCOMPONENT_IMAGE || t == DRAWCOMPONENT_TEXTBOX)
|
||||
if(t == DRAWCOMPONENT_IMAGE)
|
||||
updateableComponents.emplace(c->obj);
|
||||
};
|
||||
components.clientEraseCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ void DrawingProgramSelection::commit_transform_selection() {
|
|||
}
|
||||
DrawComponent::client_send_transform_many(drawP, transformsToSend);
|
||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||
[&, transformsFrom = transformsFrom]() {
|
||||
[isSingleThread, &drawP = drawP, transformsFrom = transformsFrom]() {
|
||||
std::vector<std::pair<ServerClientID, CoordSpaceHelper>> transformsToSend;
|
||||
for(auto& [comp, coords] : transformsFrom) {
|
||||
auto lockObjInfo = comp->obj->collabListInfo.lock();
|
||||
|
|
@ -188,7 +188,6 @@ void DrawingProgramSelection::commit_transform_selection() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool isSingleThread = a.size() < DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD;
|
||||
parallel_loop_container(transformsFrom, [&](auto& p) {
|
||||
auto& [comp, coords] = p;
|
||||
comp->obj->coords = coords;
|
||||
|
|
@ -202,7 +201,7 @@ void DrawingProgramSelection::commit_transform_selection() {
|
|||
|
||||
return true;
|
||||
},
|
||||
[&, transformsTo = transformsTo]() {
|
||||
[isSingleThread, &drawP = drawP, transformsTo = transformsTo]() {
|
||||
std::vector<std::pair<ServerClientID, CoordSpaceHelper>> transformsToSend;
|
||||
for(auto& [comp, coords] : transformsTo) {
|
||||
auto lockObjInfo = comp->obj->collabListInfo.lock();
|
||||
|
|
@ -212,7 +211,6 @@ void DrawingProgramSelection::commit_transform_selection() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool isSingleThread = a.size() < DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD;
|
||||
parallel_loop_container(transformsTo, [&](auto& p) {
|
||||
auto& [comp, coords] = p;
|
||||
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 cData = a->d;
|
||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||
[&, a, pData]() {
|
||||
[&drawP = drawP, a, pData]() {
|
||||
a->d = pData;
|
||||
a->client_send_update(drawP, true);
|
||||
a->commit_update(drawP);
|
||||
return true;
|
||||
},
|
||||
[&, a, cData]() {
|
||||
[&drawP = drawP, a, cData]() {
|
||||
a->d = cData;
|
||||
a->client_send_update(drawP, true);
|
||||
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 cData = a->d;
|
||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||
[&, a, pData]() {
|
||||
[&drawP = drawP, a, pData]() {
|
||||
a->d = pData;
|
||||
a->client_send_update(drawP, true);
|
||||
a->commit_update(drawP);
|
||||
return true;
|
||||
},
|
||||
[&, a, cData]() {
|
||||
[&drawP = drawP, a, cData]() {
|
||||
a->d = cData;
|
||||
a->client_send_update(drawP, true);
|
||||
a->commit_update(drawP);
|
||||
|
|
|
|||
|
|
@ -16,17 +16,20 @@ bool TextBoxEditTool::edit_gui(const std::shared_ptr<DrawComponent>& comp) {
|
|||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool 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.left_to_right_line_layout([&]() {
|
||||
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))
|
||||
t.color_selector_right(&a->d.textColor == t.colorRight ? nullptr : &a->d.textColor);
|
||||
}
|
||||
t.gui.text_label("Text Color");
|
||||
});
|
||||
//t.gui.slider_scalar_field("Text Relative Size", "Text Size", &a->d.textSize, 5.0f, 100.0f);
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// 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))
|
||||
// t.color_selector_right(&a->d.textColor == t.colorRight ? nullptr : &a->d.textColor);
|
||||
// }
|
||||
// t.gui.text_label("Text Color");
|
||||
//});
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
a->d.editing = false;
|
||||
DrawTextBox::Data pData = std::any_cast<DrawTextBox::Data>(prevData);
|
||||
DrawTextBox::Data cData = a->d;
|
||||
auto pData = std::any_cast<TextBoxEditToolAllData>(prevData);
|
||||
TextBoxEditToolAllData cData = get_all_data(a);
|
||||
RichTextBox::RichTextData richText = a->textBox->get_rich_text_data();
|
||||
drawP.world.undo.push(UndoManager::UndoRedoPair{
|
||||
[&, a, pData]() {
|
||||
a->d = pData;
|
||||
a->set_textbox_string(pData.currentText);
|
||||
[&drawP = drawP, a, pData]() {
|
||||
a->d = pData.textboxData;
|
||||
a->textBox->set_rich_text_data(pData.richText);
|
||||
a->d.editing = false;
|
||||
a->client_send_update(drawP, true);
|
||||
a->commit_update(drawP);
|
||||
return true;
|
||||
},
|
||||
[&, a, cData]() {
|
||||
a->d = cData;
|
||||
a->set_textbox_string(cData.currentText);
|
||||
[&drawP = drawP, a, cData]() {
|
||||
a->d = cData.textboxData;
|
||||
a->textBox->set_rich_text_data(cData.richText);
|
||||
a->d.editing = false;
|
||||
a->client_send_update(drawP, true);
|
||||
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) {
|
||||
std::shared_ptr<DrawTextBox> a = std::static_pointer_cast<DrawTextBox>(comp);
|
||||
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>();
|
||||
Vector2f textSelectPos = a->get_mouse_pos(drawP);
|
||||
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->client_send_update(drawP, false);
|
||||
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;
|
||||
}
|
||||
|
||||
// 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_gui(const std::shared_ptr<DrawComponent>& a) override;
|
||||
private:
|
||||
void edit_text(std::function<void()> toRun, const std::shared_ptr<DrawTextBox>& textBox);
|
||||
void update_textbox_network(const std::shared_ptr<DrawTextBox>& textBox);
|
||||
struct TextBoxEditToolAllData {
|
||||
DrawTextBox::Data textboxData;
|
||||
RichTextBox::RichTextData richText;
|
||||
bool operator==(const TextBoxEditToolAllData& o) const = default;
|
||||
bool operator!=(const TextBoxEditToolAllData& o) const = default;
|
||||
};
|
||||
TextBoxEditToolAllData get_all_data(const std::shared_ptr<DrawTextBox>& a);
|
||||
|
||||
std::optional<DrawTextBox::Data> oldData;
|
||||
TextBoxEditToolAllData oldData;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,14 +39,13 @@ void TextBoxTool::tool_update() {
|
|||
controls.endAt = 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.textColor = drawP.controls.foregroundColor;
|
||||
controls.intermediateItem->d.textSize = controls.textRelativeSize;
|
||||
controls.intermediateItem->d.editing = true;
|
||||
controls.intermediateItem->coords = drawP.world.drawData.cam.c;
|
||||
controls.intermediateItem->lastUpdateTime = std::chrono::steady_clock::now();
|
||||
uint64_t placement = drawP.components.client_list().size();
|
||||
auto objAdd = drawP.components.client_insert(placement, controls.intermediateItem);
|
||||
controls.intermediateItem->client_send_place(drawP);
|
||||
controls.intermediateItem->commit_update(drawP);
|
||||
drawP.add_undo_place_component(objAdd);
|
||||
controls.drawStage = 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue