Add context menu to node canvas

This commit is contained in:
Lubos Lenco
2021-05-20 16:15:03 +02:00
parent eb347e8a33
commit 064585a6f6
+39
View File
@@ -60,6 +60,7 @@ class UINodes {
Nodes.excludeRemove.push("BrushOutputNode");
Nodes.onLinkDrag = onLinkDrag;
Nodes.onSocketReleased = onSocketReleased;
Nodes.onCanvasReleased = onCanvasReleased;
Nodes.onNodeRemove = onNodeRemove;
Nodes.onCanvasControl = onCanvasControl;
@@ -197,6 +198,37 @@ class UINodes {
}
}
function onCanvasReleased() {
if (ui.inputReleasedR && Math.abs(ui.inputX - ui.inputStartedX) < 2 && Math.abs(ui.inputY - ui.inputStartedY) < 2) {
UIMenu.draw(function(uiMenu: Zui) {
var nodes = getNodes();
uiMenu._y += 1;
uiMenu.enabled = nodes.nodesSelected.length > 0;
if (menuButton(uiMenu, tr("Cut"), "ctrl+x")) {
Zui.isCopy = true;
Zui.isCut = true;
}
if (menuButton(uiMenu, tr("Copy"), "ctrl+c")) {
Zui.isCopy = true;
}
uiMenu.enabled = Nodes.clipboard != "";
if (menuButton(uiMenu, tr("Paste"), "ctrl+v")) {
Zui.isPaste = true;
}
uiMenu.enabled = nodes.nodesSelected.length > 0;
if (menuButton(uiMenu, tr("Delete"), "delete")) {
ui.isDeleteDown = true;
App.notifyOnNextFrame(function() { ui.isDeleteDown = false; });
}
if (menuButton(uiMenu, tr("Duplicate"))) {
Zui.isCopy = true;
Zui.isPaste = true;
}
uiMenu.enabled = true;
}, 5);
}
}
public static function onNodeRemove(node: TNode) {
if (node.type == "GROUP") { // Remove unused groups
var found = false;
@@ -881,4 +913,11 @@ class UINodes {
for (c in canvases) if (c.name == name) return c;
return null;
}
static function menuButton(ui: Zui, text: String, label = ""): Bool {
#if (krom_android || krom_ios)
label = "";
#end
return ui.button(Config.buttonSpacing + text, Config.buttonAlign, label);
}
}