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

Fix bug #177, #178, and #180 #182

Merged
merged 7 commits into from
Feb 14, 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
4 changes: 3 additions & 1 deletion source/creator/viewport/common/mesheditor/operations/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ public:
abstract void forceResetAction();


abstract bool update(ImGuiIO* io, Camera camera);
abstract int peek(ImGuiIO* io, Camera camera);
abstract int unify(int[] actions);
abstract bool update(ImGuiIO* io, Camera camera, int actions);
abstract void draw(Camera camera);

// getPath / setPath is remained for compatibility. should be migrated to implementation of PathDeformTool
Expand Down
18 changes: 16 additions & 2 deletions source/creator/viewport/common/mesheditor/operations/impl.d
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,25 @@ public:
pathTool.path = path;
}

override int peek(ImGuiIO* io, Camera camera) {
if (toolMode in tools) {
return tools[toolMode].peek(io, this);
}
assert(0);
}

override int unify(int[] actions) {
if (toolMode in tools) {
return tools[toolMode].unify(actions);
}
assert(0);
}

override
bool update(ImGuiIO* io, Camera camera) {
bool update(ImGuiIO* io, Camera camera, int actions) {
bool changed = false;
if (toolMode in tools) {
tools[toolMode].update(io, this, changed);
tools[toolMode].update(io, this, actions, changed);
} else {
assert(0);
}
Expand Down
11 changes: 9 additions & 2 deletions source/creator/viewport/common/mesheditor/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ public:
bool update(ImGuiIO* io, Camera camera) {
bool result = false;
incActionPushGroup();
int[] actions;
foreach (drawing, editor; editors) {
result = editor.update(io, camera) || result;
actions ~= editor.peek(io, camera);
}
int action = 0;
if (editors.keys().length > 0)
action = editors[editors.keys()[0]].unify(actions);
foreach (drawing, editor; editors) {
result = editor.update(io, camera, action) || result;
}
incActionPopGroup();
return result;
Expand Down Expand Up @@ -198,7 +205,7 @@ public:
void setMirrorVert(bool mirrorVert) {
this.mirrorVert = mirrorVert;
foreach (e; editors) {
e.mirrorHoriz = mirrorVert;
e.mirrorVert = mirrorVert;
}
}

Expand Down
4 changes: 3 additions & 1 deletion source/creator/viewport/common/mesheditor/tools/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import std.stdio;


interface Tool {
bool update(ImGuiIO* io, IncMeshEditorOne impl, out bool changed);
int peek(ImGuiIO* io, IncMeshEditorOne impl);
int unify(int[] actions);
bool update(ImGuiIO* io, IncMeshEditorOne impl, int action, out bool changed);
void setToolMode(VertexToolMode toolMode, IncMeshEditorOne impl);
void draw(Camera camera, IncMeshEditorOne impl);
}
Expand Down
11 changes: 9 additions & 2 deletions source/creator/viewport/common/mesheditor/tools/connect.d
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ class ConnectTool : NodeSelect {
return true;
}

override bool update(ImGuiIO* io, IncMeshEditorOne impl, out bool changed) {
super.update(io, impl, changed);
override bool update(ImGuiIO* io, IncMeshEditorOne impl, int action, out bool changed) {
super.update(io, impl, action, changed);

if (incInputIsMouseReleased(ImGuiMouseButton.Left)) {
onDragEnd(impl.mousePos, impl);
}

if (igIsMouseClicked(ImGuiMouseButton.Left)) impl.maybeSelectOne = null;

if (!impl.deformOnly)
updateMeshEdit(io, impl, changed);
return changed;
Expand Down
11 changes: 9 additions & 2 deletions source/creator/viewport/common/mesheditor/tools/pathdeform.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ class PathDeformTool : NodeSelect {
super.setToolMode(toolMode, impl);
}

override bool update(ImGuiIO* io, IncMeshEditorOne impl, out bool changed) {
super.update(io, impl, changed);
override bool update(ImGuiIO* io, IncMeshEditorOne impl, int action, out bool changed) {
super.update(io, impl, action, changed);

if (incInputIsMouseReleased(ImGuiMouseButton.Left)) {
onDragEnd(impl.mousePos, impl);
}

if (igIsMouseClicked(ImGuiMouseButton.Left)) impl.maybeSelectOne = null;

if (impl.deforming) {
incStatusTooltip(_("Deform"), _("Left Mouse"));
incStatusTooltip(_("Switch Mode"), _("TAB"));
Expand Down
145 changes: 123 additions & 22 deletions source/creator/viewport/common/mesheditor/tools/point.d
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ class PointTool : NodeSelect {
}
}

enum PointActionID {
Add = cast(int)(SelectActionID.End),
Remove,
Translate,
TranslateUp,
TranslateDown,
TranslateLeft,
TranslateRight,
End
}


bool updateMeshEdit(ImGuiIO* io, IncMeshEditorOne impl, out bool changed) {
incStatusTooltip(_("Select"), _("Left Mouse"));
Expand Down Expand Up @@ -230,7 +241,55 @@ class PointTool : NodeSelect {
}


bool updateDeformEdit(ImGuiIO* io, IncMeshEditorOne impl, out bool changed) {
int peekDeformEdit(ImGuiIO* io, IncMeshEditorOne impl) {

if (incInputIsMouseReleased(ImGuiMouseButton.Left)) {
onDragEnd(impl.mousePos, impl);
}

if (igIsMouseClicked(ImGuiMouseButton.Left)) impl.maybeSelectOne = null;

if (incInputIsKeyPressed(ImGuiKey.LeftArrow)) {
return PointActionID.TranslateLeft;
} else if (incInputIsKeyPressed(ImGuiKey.RightArrow)) {
return PointActionID.TranslateRight;
} else if (incInputIsKeyPressed(ImGuiKey.DownArrow)) {
return PointActionID.TranslateDown;
} else if (incInputIsKeyPressed(ImGuiKey.UpArrow)) {
return PointActionID.TranslateUp;
}

// Left click selection
if (igIsMouseClicked(ImGuiMouseButton.Left)) {
if (impl.isPointOver(impl.mousePos)) {
if (io.KeyShift) return SelectActionID.ToggleSelect;
else if (!impl.isSelected(impl.vtxAtMouse)) return SelectActionID.SelectOne;
else return SelectActionID.MaybeSelectOne;
} else {
return SelectActionID.SelectArea;
}
}
if (!isDragging && !impl.isSelecting &&
incInputIsMouseReleased(ImGuiMouseButton.Left) && impl.maybeSelectOne !is null) {
return SelectActionID.SelectMaybeSelectOne;
}


if (isDragging) {
return PointActionID.Translate;
}

// Dragging
if (incDragStartedInViewport(ImGuiMouseButton.Left) && igIsMouseDown(ImGuiMouseButton.Left) && incInputIsDragRequested(ImGuiMouseButton.Left)) {
if (!impl.isSelecting) {
return SelectActionID.StartDrag;
}
}

return SelectActionID.None;
}

bool updateDeformEdit(ImGuiIO* io, IncMeshEditorOne impl, int action, out bool changed) {

incStatusTooltip(_("Select"), _("Left Mouse"));

Expand All @@ -256,49 +315,91 @@ class PointTool : NodeSelect {
changed = true;
}

if (incInputIsKeyPressed(ImGuiKey.LeftArrow)) {
if (action == PointActionID.TranslateLeft) {
shiftSelection(vec2(-1, 0));
} else if (incInputIsKeyPressed(ImGuiKey.RightArrow)) {
} else if (action == PointActionID.TranslateRight) {
shiftSelection(vec2(1, 0));
} else if (incInputIsKeyPressed(ImGuiKey.DownArrow)) {
} else if (action == PointActionID.TranslateDown) {
shiftSelection(vec2(0, 1));
} else if (incInputIsKeyPressed(ImGuiKey.UpArrow)) {
} else if (action == PointActionID.TranslateUp) {
shiftSelection(vec2(0, -1));
}
if (keyboardMoved)
impl.pushDeformAction();

// Left click selection
if (igIsMouseClicked(ImGuiMouseButton.Left)) {
if (impl.isPointOver(impl.mousePos)) {
if (io.KeyShift) impl.toggleSelect(impl.vtxAtMouse);
else if (!impl.isSelected(impl.vtxAtMouse)) impl.selectOne(impl.vtxAtMouse);
else impl.maybeSelectOne = impl.vtxAtMouse;
} else {
impl.selectOrigin = impl.mousePos;
impl.isSelecting = true;
}
if (action == SelectActionID.ToggleSelect) {
if (impl.vtxAtMouse)
impl.toggleSelect(impl.vtxAtMouse);
} else if (action == SelectActionID.SelectOne) {
if (impl.vtxAtMouse)
impl.selectOne(impl.vtxAtMouse);
else
impl.deselectAll();
} else if (action == SelectActionID.MaybeSelectOne) {
if (impl.vtxAtMouse)
impl.maybeSelectOne = impl.vtxAtMouse;
} else if (action == SelectActionID.SelectArea) {
impl.selectOrigin = impl.mousePos;
impl.isSelecting = true;
}
if (!isDragging && !impl.isSelecting &&
incInputIsMouseReleased(ImGuiMouseButton.Left) && impl.maybeSelectOne !is null) {
impl.selectOne(impl.maybeSelectOne);

if (action == SelectActionID.SelectMaybeSelectOne) {
if (impl.maybeSelectOne !is null)
impl.selectOne(impl.maybeSelectOne);
}

// Dragging
if (incDragStartedInViewport(ImGuiMouseButton.Left) && igIsMouseDown(ImGuiMouseButton.Left) && incInputIsDragRequested(ImGuiMouseButton.Left)) {
if (action == SelectActionID.StartDrag) {
onDragStart(impl.mousePos, impl);
}

changed = onDragUpdate(impl.mousePos, impl) || changed;
if (action == PointActionID.Translate)
changed = onDragUpdate(impl.mousePos, impl) || changed;
return true;
}

override int peek(ImGuiIO* io, IncMeshEditorOne impl) {
super.peek(io, impl);
if (impl.deformOnly)
return peekDeformEdit(io, impl);
else
return 0;
}

override bool update(ImGuiIO* io, IncMeshEditorOne impl, out bool changed) {
super.update(io, impl, changed);
override int unify(int[] actions) {
int[int] priorities;
priorities[PointActionID.Add] = 2;
priorities[PointActionID.Remove] = 2;
priorities[PointActionID.Translate] = 1;
priorities[PointActionID.TranslateUp] = 0;
priorities[PointActionID.TranslateDown] = 0;
priorities[PointActionID.TranslateLeft] = 0;
priorities[PointActionID.TranslateRight] = 0;
priorities[SelectActionID.None] = 10;
priorities[SelectActionID.SelectArea] = 5;
priorities[SelectActionID.ToggleSelect] = 2;
priorities[SelectActionID.SelectOne] = 2;
priorities[SelectActionID.MaybeSelectOne] = 2;
priorities[SelectActionID.StartDrag] = 2;
priorities[SelectActionID.SelectMaybeSelectOne] = 2;

int action = SelectActionID.None;
int curPriority = priorities[action];
foreach (a; actions) {
auto newPriority = priorities[a];
if (newPriority < curPriority) {
curPriority = newPriority;
action = a;
}
}
return action;
}

override bool update(ImGuiIO* io, IncMeshEditorOne impl, int action, out bool changed) {
super.update(io, impl, action, changed);
if (impl.deformOnly)
updateDeformEdit(io, impl, changed);
updateDeformEdit(io, impl, action, changed);
else
updateMeshEdit(io, impl, changed);
return changed;
Expand Down
25 changes: 19 additions & 6 deletions source/creator/viewport/common/mesheditor/tools/select.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ import std.stdio;
class NodeSelect : Tool, Draggable {
bool isDragging = false;

enum SelectActionID {
None = 0,
SelectArea = 1,
ToggleSelect,
SelectOne,
MaybeSelectOne,
SelectMaybeSelectOne,
StartDrag,
End
}

override
void setToolMode(VertexToolMode toolMode, IncMeshEditorOne impl) {
assert(!impl.deformOnly || toolMode != VertexToolMode.Connect);
Expand All @@ -32,8 +43,7 @@ class NodeSelect : Tool, Draggable {
impl.deselectAll();
}


override bool update(ImGuiIO* io, IncMeshEditorOne impl, out bool changed) {
override int peek(ImGuiIO* io, IncMeshEditorOne impl) {
impl.lastMousePos = impl.mousePos;

impl.mousePos = incInputGetMousePosition();
Expand All @@ -48,11 +58,14 @@ class NodeSelect : Tool, Draggable {

impl.vtxAtMouse = impl.getVertexFromPoint(impl.mousePos);

if (incInputIsMouseReleased(ImGuiMouseButton.Left)) {
onDragEnd(impl.mousePos, impl);
}
return 0;
}

override int unify(int[] actions) {
return 0;
}

if (igIsMouseClicked(ImGuiMouseButton.Left)) impl.maybeSelectOne = null;
override bool update(ImGuiIO* io, IncMeshEditorOne impl, int action, out bool changed) {
return false;
}

Expand Down