Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit multiple parts at once. #155

Merged
merged 5 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions source/creator/actions/mesheditor.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class MeshEditorDeformationAction : LazyBoundAction {
bool bindingAdded;
bool undoable = true;

this(string name, void delegate() update = null) {
this(string name, Drawable target, void delegate() update = null) {
this.name = name;
this.target = target;
this.bindingAdded = false;
this.clear();

Expand All @@ -46,7 +47,8 @@ class MeshEditorDeformationAction : LazyBoundAction {
}

auto self() {
return incViewportModelDeformGetEditor();
IncMeshEditor editor = incViewportModelDeformGetEditor();
return editor? editor.getEditorFor(target): null;
}

void addVertex(MeshVertex* vertex) {
Expand All @@ -73,7 +75,7 @@ class MeshEditorDeformationAction : LazyBoundAction {
vertices = null;
isSet = false;
} else {
target = self.getTarget();
// target = self.getTarget();
param = incArmedParameter();
keypoint = param.findClosestKeypoint();
vertices = self.getOffsets();
Expand Down Expand Up @@ -207,8 +209,8 @@ public:
return null;
}

this(string name, void delegate() update = null) {
super(name, update);
this(string name, Drawable target, void delegate() update = null) {
super(name, target, update);
if (path !is null)
oldPathPoints = path.points.dup;
else
Expand Down
2 changes: 2 additions & 0 deletions source/creator/actions/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ public:

bool merge(Action other) { return false; }
bool canMerge(Action other) { return false; }

bool empty() { return actions.length == 0; }
}
51 changes: 38 additions & 13 deletions source/creator/core/actionstack.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import inochi2d;

private {
Action[] actions;
GroupAction currentGroup = null;
size_t actionPointer;
size_t actionIndex;
size_t maxUndoHistory;
Expand All @@ -27,21 +28,26 @@ void incActionInit() {
Pushes a new action to the stack
*/
void incActionPush(Action action) {

// Chop away entries outside undo history
if (actionPointer+1 > incActionGetUndoHistoryLength()) {
size_t toChop = (actionPointer+1)-incActionGetUndoHistoryLength();
actions = actions[toChop..$];
actionPointer -= toChop;
}

if (incActionTop() !is null && incActionTop().canMerge(action)) {
incActionTop().merge(action);
incActionNotifyTopChanged();
if (currentGroup !is null) {
currentGroup.addAction(action);
} else {
// Add to the history
actions = actions[0..actionPointer]~action;
actionPointer++;

// Chop away entries outside undo history
if (actionPointer+1 > incActionGetUndoHistoryLength()) {
size_t toChop = (actionPointer+1)-incActionGetUndoHistoryLength();
actions = actions[toChop..$];
actionPointer -= toChop;
}

if (incActionTop() !is null && incActionTop().canMerge(action)) {
incActionTop().merge(action);
incActionNotifyTopChanged();
} else {
// Add to the history
actions = actions[0..actionPointer]~action;
actionPointer++;
}
}
}

Expand Down Expand Up @@ -155,4 +161,23 @@ void incActionSetIndex(size_t index) {
void incActionClearHistory() {
actions.length = 0;
actionPointer = 0;
}

/**
Push GroupAction to action stack.
Subsequent Action is added to GroupAction.
GroupAction is added to action stack when incActionPopGroup is called.
*/
void incActionPushGroup() {
if (!currentGroup)
currentGroup = new GroupAction();
}

void incActionPopGroup() {
if (currentGroup) {
auto group = currentGroup;
currentGroup = null;
if (group !is null && !group.empty())
incActionPush(group);
}
}
6 changes: 5 additions & 1 deletion source/creator/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import creator.core.colorbleed;
import std.file;
import std.format;
import i18n;
import std.algorithm.searching;

/**
A project
Expand Down Expand Up @@ -415,8 +416,10 @@ void incSelectNode(Node n = null) {
Adds node to selection
*/
void incAddSelectNode(Node n) {
if (incArmedParameter()) return;
if (selectedNodes.canFind(n))
return;
selectedNodes ~= n;
incViewportModelNodeSelectionChanged();
}

/**
Expand All @@ -427,6 +430,7 @@ void incRemoveSelectNode(Node n) {
if (n.uuid == nn.uuid) {
import std.algorithm.mutation : remove;
selectedNodes = selectedNodes.remove(i);
incViewportModelNodeSelectionChanged();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/creator/panels/parameters.d
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private {
auto target = cast(Drawable)binding.getTarget().node;
if (target) {
editor.setTarget(target);
auto newDeform = editor.getMesh().deformByDeformationBinding(deformBinding, cParamPoint, true);
auto newDeform = editor.getEditorFor(target).getMesh().deformByDeformationBinding(deformBinding, cParamPoint, true);
if (newDeform)
deformBinding.setValue(cParamPoint, *newDeform);
}
Expand Down
Loading