CaptainJohnThomas wrote in Wed Feb 19, 2014 8:31 pm:I was just thinking a little widget that could be toggled on and off for like gliders and such
var CanvasApplication = {
##
# constructor
new: func(x=300,y=200) {
var m = { parents: [CanvasApplication] };
m.dlg = canvas.Window.new([x,y],"dialog");
m.canvas = m.dlg.createCanvas().setColorBackground(1,1,1,0.5);
m.root = m.canvas.createGroup();
m.timer = maketimer(0.1, func m.update() );
m.init();
return m;
},
del: func me.timer.stop(),
update: func() {
var hdg=getprop("/orientation/heading-deg");
me.compass.setRotation(-hdg*D2R);
},
init: func() {
var filename = "/Aircraft/Instruments/gyro.xml";
var temp= io.read_properties(getprop("/sim/fg-root") ~ filename);
var layers = temp.getValues().layers.layer;
var z=100;
foreach(var layer; layers ) {
print("new layer:", layer.name);
# if it's not a texture, skip
if (!contains(layer, "texture")) continue;
# get a handle to the texture of the layer
var texture = layer.texture;
# create an image child for the texture
var child=me.root.createChild("image")
.setFile( texture.path )
.setSourceRect( texture.x1, texture.x2, texture.y1, texture.y2 )
.setSize(layer.w,layer.h)
.setTranslation(20,20)
.set("z-index", z +=1 )
.setScale(2.5);
if (layer.w != nil and layer.h!=nil)
child.setCenter(layer.w/2, layer.h/2);
if (layer.name=="compass rose") {
print("Found compass layer");
# child.setCenter(55,55);
me.compass = child;
}
} # foreach
me.timer.start();
},
}; # end of CanvasApplication
var InstrumentWidget = {
new: func(x,y) {
var m = CanvasApplication.new(x:x,y:y);
},
};
var compass = InstrumentWidget.new(x:300, y:300);
print("Compass Loaded...!");
Users browsing this forum: franck and 1 guest