Skip to content

Commit bfc941a

Browse files
committed
value node
1 parent b8ee70b commit bfc941a

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

src/EditorNodes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FillStyle, Theme } from "./colors/Theme";
22
import { UVNode } from "./nodes/attribute/UVNode";
3+
import { ValueNode } from "./nodes/input/ValueNode";
34
import { MathNode } from "./nodes/operators/MathNode";
45
import { MeshStandardNode } from "./nodes/shader/MeshStandardNode";
56
import { ImageTextureNode } from "./nodes/texture/ImageTextureNode";
@@ -16,6 +17,13 @@ export type NodeGroupType = {
1617
}
1718

1819
export const NodeTypes : NodeGroupType[] = [
20+
{
21+
group:"Input",
22+
color:Theme.config.groupInput as string,
23+
nodes: [
24+
{ TypeClass:ValueNode, name:"Value", id:"input-value"}
25+
]
26+
},
1927
{
2028
group:"Attribute",
2129
color:Theme.config.groupAttribute as string,

src/components/DraggableNumber.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { DraggableValue } from "./DraggableValue";
2+
3+
export class DraggableNumber extends DraggableValue {
4+
constructor( name:string ="" ) {
5+
super(name, false, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, 1 );
6+
}
7+
}

src/components/DraggableValue.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,18 @@ export class DraggableValue extends InteractiveLayoutElement {
6464

6565
ctx.translate(5, 0);
6666
maxWidth-= 10;
67+
68+
if( this.name=="" )
69+
{
70+
this.writeText( ctx, this.stringValue, this.fontSize, maxWidth/2, this.rowHeight, Theme.config.barTextColor, "center");
71+
}
72+
else
73+
{
74+
this.writeText( ctx, this.name, this.fontSize, this.xPadding, this.rowHeight, Theme.config.barTextColor, "left");
75+
this.writeText( ctx, this.stringValue, this.fontSize, maxWidth-this.xPadding, this.rowHeight, Theme.config.barTextColor, "right");
76+
}
6777

68-
this.writeText( ctx, this.name, this.fontSize, this.xPadding, this.rowHeight, Theme.config.barTextColor, "left");
69-
this.writeText( ctx, this.stringValue, this.fontSize, maxWidth-this.xPadding, this.rowHeight, Theme.config.barTextColor, "right");
78+
7079

7180
}
7281

@@ -104,9 +113,7 @@ export class DraggableValue extends InteractiveLayoutElement {
104113
}
105114

106115
override onMouseWheel(deltaY: number): void {
107-
108-
const inc = this.step;
109-
110-
this.value = clamp( this.value-inc*(deltaY>0?1:-1), 0, 1 );
116+
117+
this.value = this.value-this.step*(deltaY>0?1:-1);
111118
}
112119
}

src/nodes/input/InputBaseNode.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Theme } from "../../colors/Theme";
2+
import { LayoutElement } from "../../layout/LayoutElement";
3+
import { WinNode } from "../WinNode";
4+
5+
export class InputBaseNode extends WinNode {
6+
constructor( title:string, childs:LayoutElement[]) {
7+
super(title, Theme.config.groupInput, childs)
8+
}
9+
}

src/nodes/input/ValueNode.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { DraggableNumber } from "../../components/DraggableNumber";
2+
import { DraggableValue } from "../../components/DraggableValue";
3+
import { Output } from "../../properties/Output";
4+
import { InputBaseNode } from "./InputBaseNode";
5+
6+
export class ValueNode extends InputBaseNode {
7+
constructor() {
8+
9+
super("Value", [
10+
new Output("Value", 1),
11+
new DraggableNumber()
12+
]);
13+
}
14+
}

0 commit comments

Comments
 (0)