update
This commit is contained in:
BIN
ui_canvas/Assets/crate.png
Normal file
BIN
ui_canvas/Assets/crate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 93 KiB |
2
ui_canvas/Assets/license.txt
Normal file
2
ui_canvas/Assets/license.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Crate by Cpt_flash - CC0
|
||||
https://opengameart.org/content/2d-wooden-box
|
||||
1
ui_canvas/Bundled/canvas/MyCanvas.files
Normal file
1
ui_canvas/Bundled/canvas/MyCanvas.files
Normal file
@ -0,0 +1 @@
|
||||
../../Assets/crate.png
|
||||
1
ui_canvas/Bundled/canvas/MyCanvas.json
Normal file
1
ui_canvas/Bundled/canvas/MyCanvas.json
Normal file
@ -0,0 +1 @@
|
||||
{"name":"untitled","x":0,"y":0,"width":960,"height":540,"elements":[{"id":0,"type":0,"name":"MyText","event":"","x":0,"y":0,"width":364,"height":48,"text":"Text","asset":"crate.png","color":-1,"anchor":3,"children":[],"visible":true,"rotation":0,"color_text":-1},{"id":1,"type":1,"name":"MyImage","event":"","x":352,"y":120,"width":256,"height":256,"text":"Image","asset":"crate.png","color":-1,"anchor":0,"children":[],"visible":true,"rotation":0,"color_text":-1,"color_hover":-1},{"id":2,"type":2,"name":"MyButton","event":"buttonEvent","x":5,"y":60,"width":150,"height":34,"text":"0","asset":"crate.png","color":-1,"anchor":0,"children":[],"visible":true,"rotation":0,"color_text":-13290187,"color_hover":-5066062,"color_press":-10921639},{"id":3,"type":9,"name":"Shape","event":"","x":742,"y":66,"width":190,"height":145,"rotation":0,"text":"My Shape","asset":"","color":16777215,"anchor":0,"parent":null,"children":[7,8,10],"visible":true},{"id":4,"type":2,"name":"MenuButton","event":"toggleMenu","x":779,"y":7,"width":150,"height":44,"rotation":0,"text":"Menu","asset":"","color":-1,"anchor":0,"parent":null,"children":[],"visible":true,"color_text":-12763843,"color_hover":-5066062,"color_press":-8421505},{"id":7,"type":8,"name":"Combo","event":"","x":0,"y":4,"width":190,"height":44,"rotation":0,"text":"Combo 1;Combo 2","asset":"","color":-1,"anchor":0,"parent":3,"children":[],"visible":true,"color_text":-1,"color_hover":-5066062},{"id":8,"type":7,"name":"Radio","event":"","x":0,"y":49,"width":190,"height":44,"rotation":0,"text":"Radio 1;Radio 2","asset":"","color":-1,"anchor":0,"parent":3,"children":[],"visible":true,"color_text":-1,"color_hover":-5066062},{"id":9,"type":6,"name":"Check","event":"","x":5,"y":112,"width":150,"height":44,"rotation":0,"text":"Rotate","asset":"","color":-1,"anchor":0,"parent":null,"children":[],"visible":true,"color_text":-1,"color_hover":-5066062},{"id":10,"type":9,"name":"Slider","event":"","x":2,"y":98,"width":187,"height":48,"rotation":0,"text":"My Slider","asset":"","color":-1,"color_text":-8226182,"color_hover":-1,"color_press":-15000805,"anchor":0,"parent":3,"children":[],"visible":true}],"assets":[{"name":"crate.png","file":"../../Assets/crate.png","id":0}]}
|
||||
1
ui_canvas/README.md
Normal file
1
ui_canvas/README.md
Normal file
@ -0,0 +1 @@
|
||||
https://github.com/leenkx3d/leenkx/wiki/ui_editor
|
||||
54
ui_canvas/Sources/lnx/CanvasTrait.hx
Normal file
54
ui_canvas/Sources/lnx/CanvasTrait.hx
Normal file
@ -0,0 +1,54 @@
|
||||
package lnx;
|
||||
|
||||
import iron.Scene;
|
||||
import iron.App;
|
||||
import iron.system.Time;
|
||||
import leenkx.system.Event;
|
||||
import leenkx.trait.internal.CanvasScript;
|
||||
|
||||
class CanvasTrait extends iron.Trait {
|
||||
|
||||
var canvas:CanvasScript;
|
||||
var clicks = 0;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnInit(function() {
|
||||
// Get canvas attached to scene
|
||||
canvas = Scene.active.getTrait(CanvasScript);
|
||||
|
||||
// Notify on button click
|
||||
Event.add("buttonEvent", onEvent);
|
||||
Event.add("toggleMenu", onToggleMenu);
|
||||
|
||||
canvas.notifyOnReady(function() {
|
||||
notifyOnUpdate(update);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onEvent() {
|
||||
// Set butotn text
|
||||
canvas.getElement("MyButton").text = Std.string(++clicks);
|
||||
}
|
||||
|
||||
function onToggleMenu() {
|
||||
var shape = canvas.getElement("Shape");
|
||||
shape.visible = !shape.visible;
|
||||
}
|
||||
|
||||
function update() {
|
||||
// Canvas may be still being loaded
|
||||
if (!canvas.ready) return;
|
||||
|
||||
// Set text
|
||||
canvas.getElement("MyText").text = "Hello world";
|
||||
|
||||
// Move image
|
||||
var img = canvas.getElement("MyImage");
|
||||
var center = App.w() / 2 - img.width / 2;
|
||||
img.x = center + Math.sin(Time.time()) * 100;
|
||||
img.rotation = canvas.getHandle("Check").selected ? Math.PI / 4 : 0;
|
||||
}
|
||||
}
|
||||
BIN
ui_canvas/ui_canvas.blend
Normal file
BIN
ui_canvas/ui_canvas.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user