Add nodes to get/set global canvas scale

This commit is contained in:
Moritz Brückner 2021-09-26 22:31:56 +02:00
parent 8604e670c3
commit 962f8a79a5
5 changed files with 82 additions and 4 deletions

View file

@ -0,0 +1,22 @@
package armory.logicnode;
import iron.Scene;
import armory.trait.internal.CanvasScript;
class GetGlobalCanvasScaleNode extends LogicNode {
var canvas: CanvasScript;
public function new(tree: LogicTree) {
super(tree);
}
#if arm_ui
override function get(from: Int): Dynamic {
canvas = Scene.active.getTrait(CanvasScript);
if (canvas == null) canvas = Scene.active.camera.getTrait(CanvasScript);
return canvas.getUiScale();
}
#end
}

View file

@ -0,0 +1,25 @@
package armory.logicnode;
import iron.Scene;
import armory.trait.internal.CanvasScript;
class SetGlobalCanvasScaleNode extends LogicNode {
var canvas: CanvasScript;
var factor: Float;
public function new(tree: LogicTree) {
super(tree);
}
#if arm_ui
override function run(from: Int) {
factor = inputs[1].get();
canvas = Scene.active.getTrait(CanvasScript);
if (canvas == null) canvas = Scene.active.camera.getTrait(CanvasScript);
canvas.setUiScale(factor);
runOutput(0);
}
#end
}

View file

@ -114,13 +114,19 @@ class CanvasScript extends Trait {
}
/**
* Set UI scale factor.
* @param factor Scale factor.
*/
public function setUiScale(factor:Float) {
Set the UI scale factor.
**/
public inline function setUiScale(factor: Float) {
cui.setScale(factor);
}
/**
Get the UI scale factor.
**/
public inline function getUiScale(): Float {
return cui.ops.scaleFactor;
}
/**
* Set visibility of canvas
* @param visible Whether canvas should be visible or not

View file

@ -0,0 +1,11 @@
from arm.logicnode.arm_nodes import *
class GetGlobalCanvasScaleNode(ArmLogicTreeNode):
"""Returns the scale of the entire UI Canvas."""
bl_idname = 'LNGetGlobalCanvasScaleNode'
bl_label = 'Get Global Canvas Scale'
arm_version = 1
def arm_init(self, context):
self.add_output('ArmFloatSocket', 'Scale')

View file

@ -0,0 +1,14 @@
from arm.logicnode.arm_nodes import *
class SetGlobalCanvasScaleNode(ArmLogicTreeNode):
"""Sets the scale of the entire UI Canvas."""
bl_idname = 'LNSetGlobalCanvasScaleNode'
bl_label = 'Set Global Canvas Scale'
arm_version = 1
def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmFloatSocket', 'Scale', default_value=1.0)
self.add_output('ArmNodeSocketAction', 'Out')