2017-11-21 02:04:19 +00:00
|
|
|
# A3XX ND Canvas
|
|
|
|
# Joshua Davidson (it0uchpods)
|
|
|
|
# Based on work by artix
|
|
|
|
|
2018-12-20 01:55:02 +00:00
|
|
|
# Copyright (c) 2018 Joshua Davidson (it0uchpods)
|
2017-11-21 02:04:19 +00:00
|
|
|
|
2017-06-19 00:14:41 +00:00
|
|
|
var SymbolPainter = {
|
|
|
|
aircraft_dir: nil,
|
|
|
|
getOpts: func(opts){
|
|
|
|
if(opts == nil) opts = {};
|
|
|
|
var defOpts = {id:nil,color:nil,scale:1,create_group:0,update_center:0};
|
2017-11-20 22:03:07 +00:00
|
|
|
if(contains(opts, "id"))
|
2017-06-19 00:14:41 +00:00
|
|
|
defOpts.id = opts.id;
|
2017-11-20 22:03:07 +00:00
|
|
|
if(contains(opts, "color"))
|
2017-06-19 00:14:41 +00:00
|
|
|
defOpts.color = opts.color;
|
2017-11-20 22:03:07 +00:00
|
|
|
if(contains(opts, "scale"))
|
2017-06-19 00:14:41 +00:00
|
|
|
defOpts.scale = opts.scale;
|
2017-11-20 22:03:07 +00:00
|
|
|
if(contains(opts, "create_group"))
|
2017-06-19 00:14:41 +00:00
|
|
|
defOpts.create_group = opts.create_group;
|
2017-11-20 22:03:07 +00:00
|
|
|
if(contains(opts, "update_center"))
|
2017-06-19 00:14:41 +00:00
|
|
|
defOpts.update_center = opts.update_center;
|
|
|
|
return defOpts;
|
|
|
|
},
|
|
|
|
getAircraftDir: func(){
|
|
|
|
if(me.aircraft_dir == nil)
|
2017-11-20 22:03:07 +00:00
|
|
|
me.aircraft_dir = split("/", getprop("/sim/aircraft-dir"))[-1];
|
2017-06-19 00:14:41 +00:00
|
|
|
return me.aircraft_dir;
|
|
|
|
},
|
|
|
|
svgPath: func(file){
|
|
|
|
return "Aircraft/" ~ me.getAircraftDir() ~ "/Models/Instruments/ND/canvas/res/"~file;
|
|
|
|
},
|
|
|
|
drawFIX : func(grp, opts = nil){
|
|
|
|
var icon_fix = nil;
|
|
|
|
opts = me.getOpts(opts);
|
|
|
|
var sym_id = opts.id;
|
|
|
|
if(sym_id != nil)
|
|
|
|
icon_fix = grp.createChild("path", sym_id);
|
|
|
|
else
|
|
|
|
icon_fix = grp.createChild("path");
|
|
|
|
var color = opts.color;
|
|
|
|
if(color == nil){
|
|
|
|
color = {
|
|
|
|
r: 0.69,
|
|
|
|
g: 0,
|
|
|
|
b: 0.39
|
|
|
|
};
|
|
|
|
}
|
|
|
|
var scale = opts.scale;
|
|
|
|
if(scale == nil) scale = 0.8;
|
|
|
|
icon_fix.moveTo(-10,0)
|
|
|
|
.lineTo(0,-17)
|
|
|
|
.lineTo(10,0)
|
|
|
|
.lineTo(0,17)
|
|
|
|
.close()
|
|
|
|
.setStrokeLineWidth(3)
|
|
|
|
.setColor(color.r,color.g,color.b)
|
|
|
|
.setScale(scale,scale);
|
|
|
|
return icon_fix;
|
|
|
|
},
|
|
|
|
drawVOR: func(grp, opts = nil){
|
|
|
|
opts = me.getOpts(opts);
|
|
|
|
if(opts.create_group){
|
|
|
|
var sym_id = opts.id;
|
|
|
|
if(sym_id != nil)
|
|
|
|
grp = grp.createChild("group", sym_id);
|
|
|
|
else
|
|
|
|
grp = grp.createChild("group");
|
|
|
|
}
|
2017-11-20 22:03:07 +00:00
|
|
|
var svg_path = me.svgPath("airbus_vor.svg");
|
2017-06-19 00:14:41 +00:00
|
|
|
canvas.parsesvg(grp, svg_path);
|
|
|
|
var scale = opts.scale;
|
|
|
|
if(scale == nil) scale = 0.8;
|
|
|
|
grp.setScale(scale,scale);
|
|
|
|
if(opts.update_center)
|
|
|
|
grp.setTranslation(-24 * scale,-24 * scale);
|
2017-11-20 22:03:07 +00:00
|
|
|
if(!contains(grp, "setColor")){
|
2017-06-19 00:14:41 +00:00
|
|
|
grp.setColor = func {
|
2017-11-20 22:03:07 +00:00
|
|
|
var layer1 = grp.getElementById("layer1");
|
2017-06-19 00:14:41 +00:00
|
|
|
if(layer1 == nil) return;
|
|
|
|
var children = layer1.getChildren();
|
|
|
|
foreach(var c; children){
|
|
|
|
if(isa(c, canvas.Path))
|
|
|
|
c.setColor(arg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return grp;
|
|
|
|
},
|
|
|
|
drawNDB: func(grp, opts = nil){
|
|
|
|
var icon_ndb = nil;
|
|
|
|
opts = me.getOpts(opts);
|
|
|
|
var sym_id = opts.id;
|
|
|
|
if(sym_id != nil)
|
|
|
|
icon_ndb = grp.createChild("path", sym_id);
|
|
|
|
else
|
|
|
|
icon_ndb = grp.createChild("path");
|
|
|
|
var color = opts.color;
|
|
|
|
var color = opts.color;
|
|
|
|
if(color == nil){
|
|
|
|
color = {
|
|
|
|
r: 0.69,
|
|
|
|
g: 0,
|
|
|
|
b: 0.39
|
|
|
|
};
|
|
|
|
}
|
|
|
|
var scale = opts.scale;
|
|
|
|
if(scale == nil) scale = 0.8;
|
|
|
|
icon_ndb.moveTo(-15,15)
|
|
|
|
.lineTo(0,-15)
|
|
|
|
.lineTo(15,15)
|
|
|
|
.close()
|
|
|
|
.setStrokeLineWidth(3)
|
|
|
|
.setColor(color.r,color.g,color.b)
|
|
|
|
.setScale(scale,scale);
|
|
|
|
return icon_ndb;
|
|
|
|
},
|
|
|
|
drawAirport: func(grp, opts = nil){
|
|
|
|
opts = me.getOpts(opts);
|
|
|
|
if(opts.create_group){
|
|
|
|
var sym_id = opts.id;
|
|
|
|
if(sym_id != nil)
|
|
|
|
grp = grp.createChild("group", sym_id);
|
|
|
|
else
|
|
|
|
grp = grp.createChild("group");
|
|
|
|
}
|
2017-11-20 22:03:07 +00:00
|
|
|
var svg_path = me.svgPath("airbus_airport.svg");
|
2017-06-19 00:14:41 +00:00
|
|
|
canvas.parsesvg(grp, svg_path);
|
|
|
|
var scale = opts.scale;
|
|
|
|
if(scale == nil) scale = 0.8;
|
|
|
|
grp.setScale(scale,scale);
|
|
|
|
if(opts.update_center)
|
|
|
|
grp.setTranslation(-24 * scale,-24 * scale);
|
|
|
|
return grp;
|
|
|
|
},
|
|
|
|
draw: func(type, grp, opts = nil){
|
2017-11-20 22:03:07 +00:00
|
|
|
if(type == "VOR" or type == "vor")
|
2017-06-19 00:14:41 +00:00
|
|
|
return me.drawVOR(grp, opts);
|
2017-11-20 22:03:07 +00:00
|
|
|
elsif(type == "NDB" or type == "ndb")
|
2017-06-19 00:14:41 +00:00
|
|
|
return me.drawNDB(grp, opts);
|
2017-11-20 22:03:07 +00:00
|
|
|
elsif(type == "ARPT" or type == "arpt")
|
2017-06-19 00:14:41 +00:00
|
|
|
return me.drawAirport(grp, opts);
|
|
|
|
else
|
|
|
|
return me.drawFIX(grp, opts);
|
|
|
|
}
|
|
|
|
};
|