Skip to content

Commit

Permalink
Edit multiple parts at once. (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
seagetch authored Jan 3, 2023
1 parent dc460b7 commit 8d786a9
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 287 deletions.
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

0 comments on commit 8d786a9

Please sign in to comment.