Prevent undo and redo at points when they might break the program
This commit is contained in:
parent
f606fc6fc1
commit
2de5c90006
21 changed files with 79 additions and 2 deletions
|
|
@ -168,6 +168,10 @@ void BrushTool::gui_toolbox() {
|
|||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
bool BrushTool::prevent_undo_or_redo() {
|
||||
return controls.intermediateItem != nullptr;
|
||||
}
|
||||
|
||||
void BrushTool::commit_stroke() {
|
||||
if(controls.intermediateItem && controls.intermediateItem->collabListInfo.lock()) {
|
||||
if(!controls.intermediateItem->d.points.empty()) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class BrushTool {
|
|||
void tool_update();
|
||||
void reset_tool();
|
||||
void draw(SkCanvas* canvas, const DrawData& drawData);
|
||||
bool prevent_undo_or_redo();
|
||||
private:
|
||||
void commit_stroke();
|
||||
bool extensive_point_checking_back(const Vector2f& newPoint);
|
||||
|
|
|
|||
|
|
@ -392,6 +392,32 @@ void DrawingProgram::update() {
|
|||
compCache.test_rebuild(components.client_list());
|
||||
}
|
||||
|
||||
bool DrawingProgram::prevent_undo_or_redo() {
|
||||
switch(controls.selectedTool) {
|
||||
case TOOL_BRUSH:
|
||||
return brushTool.prevent_undo_or_redo();
|
||||
case TOOL_ERASER:
|
||||
return eraserTool.prevent_undo_or_redo();
|
||||
case TOOL_RECTSELECT:
|
||||
return rectSelectTool.prevent_undo_or_redo();
|
||||
case TOOL_RECTANGLE:
|
||||
return rectDrawTool.prevent_undo_or_redo();
|
||||
case TOOL_ELLIPSE:
|
||||
return ellipseDrawTool.prevent_undo_or_redo();
|
||||
case TOOL_TEXTBOX:
|
||||
return textBoxTool.prevent_undo_or_redo();
|
||||
case TOOL_INKDROPPER:
|
||||
return inkDropperTool.prevent_undo_or_redo();
|
||||
case TOOL_SCREENSHOT:
|
||||
return screenshotTool.prevent_undo_or_redo();
|
||||
case TOOL_EDIT:
|
||||
return editTool.prevent_undo_or_redo();
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
void DrawingProgram::force_rebuild_cache() {
|
||||
if(controls.selectedTool == TOOL_ERASER)
|
||||
compCache.test_rebuild_dont_include_set_dont_include_nodes(components.client_list(), eraserTool.erasedComponents, eraserTool.erasedBVHNodes, true);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ class DrawingProgram {
|
|||
void free_collider_memory();
|
||||
void allocate_collider_memory();
|
||||
|
||||
bool prevent_undo_or_redo();
|
||||
|
||||
void add_file_to_canvas_by_path(const std::string& filePath, Vector2f dropPos, bool addInSameThread);
|
||||
void add_file_to_canvas_by_data(const std::string& fileName, std::string_view fileBuffer, Vector2f dropPos);
|
||||
|
||||
|
|
|
|||
|
|
@ -219,6 +219,10 @@ void EditTool::tool_update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool EditTool::prevent_undo_or_redo() {
|
||||
return controls.isEditing;
|
||||
}
|
||||
|
||||
void EditTool::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
if(controls.isEditing) {
|
||||
std::shared_ptr<DrawComponent> a = controls.compToEdit.lock();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class EditTool {
|
|||
void draw(SkCanvas* canvas, const DrawData& drawData);
|
||||
void add_point_handle(const HandleData& handle);
|
||||
void edit_start(const std::shared_ptr<DrawComponent>& comp);
|
||||
bool prevent_undo_or_redo();
|
||||
|
||||
struct EditControls {
|
||||
std::vector<HandleData> pointHandles;
|
||||
|
|
|
|||
|
|
@ -139,6 +139,10 @@ void EllipseDrawTool::tool_update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool EllipseDrawTool::prevent_undo_or_redo() {
|
||||
return controls.intermediateItem != nullptr;
|
||||
}
|
||||
|
||||
void EllipseDrawTool::commit() {
|
||||
if(controls.intermediateItem && controls.intermediateItem->collabListInfo.lock()) {
|
||||
controls.intermediateItem->client_send_update_final(drawP);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class EllipseDrawTool {
|
|||
void commit_edit_updates(const std::shared_ptr<DrawEllipse>& a, std::any& prevData);
|
||||
bool edit_update(const std::shared_ptr<DrawEllipse>& a);
|
||||
bool edit_gui(const std::shared_ptr<DrawEllipse>& a);
|
||||
|
||||
bool prevent_undo_or_redo();
|
||||
private:
|
||||
void commit();
|
||||
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ void EraserTool::tool_update() {
|
|||
reset_tool();
|
||||
}
|
||||
|
||||
bool EraserTool::prevent_undo_or_redo() {
|
||||
return drawP.controls.leftClickHeld;
|
||||
}
|
||||
|
||||
void EraserTool::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
if(!drawData.main->toolbar.io->hoverObstructed) {
|
||||
SkColor4f c = drawP.world.main.canvasTheme.toolFrontColor;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ class EraserTool {
|
|||
void reset_tool();
|
||||
void draw(SkCanvas* canvas, const DrawData& drawData);
|
||||
|
||||
bool prevent_undo_or_redo();
|
||||
|
||||
std::unordered_set<CollabListType::ObjectInfoPtr> erasedComponents;
|
||||
std::unordered_set<std::shared_ptr<DrawingProgramCacheBVHNode>> erasedBVHNodes;
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -73,5 +73,9 @@ void InkDropperTool::tool_update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool InkDropperTool::prevent_undo_or_redo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void InkDropperTool::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class InkDropperTool {
|
|||
void gui_toolbox();
|
||||
void tool_update();
|
||||
void draw(SkCanvas* canvas, const DrawData& drawData);
|
||||
bool prevent_undo_or_redo();
|
||||
private:
|
||||
|
||||
DrawingProgram& drawP;
|
||||
|
|
|
|||
|
|
@ -139,6 +139,10 @@ void RectDrawTool::tool_update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool RectDrawTool::prevent_undo_or_redo() {
|
||||
return controls.intermediateItem != nullptr;
|
||||
}
|
||||
|
||||
void RectDrawTool::commit_rectangle() {
|
||||
if(controls.intermediateItem && controls.intermediateItem->collabListInfo.lock()) {
|
||||
controls.intermediateItem->client_send_update_final(drawP);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class RectDrawTool {
|
|||
void commit_edit_updates(const std::shared_ptr<DrawRectangle>& a, std::any& prevData);
|
||||
bool edit_update(const std::shared_ptr<DrawRectangle>& a);
|
||||
bool edit_gui(const std::shared_ptr<DrawRectangle>& a);
|
||||
|
||||
bool prevent_undo_or_redo();
|
||||
private:
|
||||
void commit_rectangle();
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ void RectSelectTool::tool_update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool RectSelectTool::prevent_undo_or_redo() {
|
||||
return drawP.selection.is_something_selected() || controls.selectionMode == 1;
|
||||
}
|
||||
|
||||
void RectSelectTool::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
if(controls.selectionMode == 1) {
|
||||
canvas->save();
|
||||
|
|
|
|||
|
|
@ -14,11 +14,12 @@ class RectSelectTool {
|
|||
void tool_update();
|
||||
void draw(SkCanvas* canvas, const DrawData& drawData);
|
||||
void reset_tool();
|
||||
|
||||
bool prevent_undo_or_redo();
|
||||
private:
|
||||
struct RectSelectControls {
|
||||
int selectionMode = 0;
|
||||
|
||||
|
||||
CoordSpaceHelper coords;
|
||||
|
||||
Vector2f selectStartAt;
|
||||
|
|
|
|||
|
|
@ -324,6 +324,10 @@ void ScreenshotTool::commit_rect() {
|
|||
controls.circles[7] = {drawP.world.drawData.cam.c.to_space(controls.coords.from_space({controls.rectX2, (controls.rectY1 + controls.rectY2) * 0.5})), DRAG_POINT_RADIUS};
|
||||
}
|
||||
|
||||
bool ScreenshotTool::prevent_undo_or_redo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScreenshotTool::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||
if(controls.selectionMode == 1 || controls.selectionMode == 2) {
|
||||
canvas->save();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class ScreenshotTool {
|
|||
void tool_update();
|
||||
void draw(SkCanvas* canvas, const DrawData& drawData);
|
||||
void reset_tool();
|
||||
bool prevent_undo_or_redo();
|
||||
private:
|
||||
void commit_rect();
|
||||
void take_screenshot(const std::filesystem::path& filePath);
|
||||
|
|
|
|||
|
|
@ -261,6 +261,10 @@ void TextBoxTool::tool_update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool TextBoxTool::prevent_undo_or_redo() {
|
||||
return controls.intermediateItem != nullptr;
|
||||
}
|
||||
|
||||
// Passing a function in, just in case we have to do something before editing the text
|
||||
void TextBoxTool::edit_text(std::function<void()> toRun, const std::shared_ptr<DrawTextBox>& textBox) {
|
||||
toRun();
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class TextBoxTool {
|
|||
void commit_edit_updates(const std::shared_ptr<DrawTextBox>& a, std::any& prevData);
|
||||
bool edit_update(const std::shared_ptr<DrawTextBox>& a);
|
||||
bool edit_gui(const std::shared_ptr<DrawTextBox>& a);
|
||||
|
||||
bool prevent_undo_or_redo();
|
||||
private:
|
||||
void edit_text(std::function<void()> toRun, const std::shared_ptr<DrawTextBox>& textBox);
|
||||
void update_textbox_network(const std::shared_ptr<DrawTextBox>& textBox);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue