| 1 |
# See: http://wiki.flightgear.org/MapStructure |
| 2 |
# Class things: |
| 3 |
var name = 'VOR_FG1000'; |
| 4 |
var parents = [DotSym]; |
| 5 |
var __self__ = caller(0)[0]; |
| 6 |
DotSym.makeinstance( name, __self__ ); |
| 7 |
|
| 8 |
SymbolLayer.get(name).df_style = { |
| 9 |
line_width: 3, |
| 10 |
scale_factor: 1, |
| 11 |
font: "LiberationFonts/LiberationSans-Regular.ttf", |
| 12 |
font_color: [0,0,0], |
| 13 |
font_size: 28, |
| 14 |
icon_color: [0.5, 0, 0.5], |
| 15 |
circle_color: [0.2,0.2,1.0], |
| 16 |
circle_radius: 64, |
| 17 |
show_labels: 1, |
| 18 |
}; |
| 19 |
|
| 20 |
|
| 21 |
var element_type = "group"; # we want a group, becomes "me.element" |
| 22 |
|
| 23 |
## |
| 24 |
# used during initialization to populate the symbol cache with a VOR symbol |
| 25 |
# |
| 26 |
var drawVOR = func(group) { |
| 27 |
|
| 28 |
# Circle around the edge |
| 29 |
var circle = group.createChild("path") |
| 30 |
.moveTo(0 -circle_radius,0) |
| 31 |
.arcSmallCW(circle_radius, circle_radius, 0, 2 * circle_radius,0) |
| 32 |
.arcSmallCW(circle_radius, circle_radius, 0,-2 * circle_radius,0) |
| 33 |
.close() |
| 34 |
.setStrokeLineWidth(line_width) |
| 35 |
.setColor(circle_color) |
| 36 |
.set("z-index",-2); |
| 37 |
|
| 38 |
# Magnetic North marking. Will be rotated later |
| 39 |
circle.moveTo(0, 0); |
| 40 |
circle.lineTo(0, -circle_radius); |
| 41 |
|
| 42 |
# 10-degree markings |
| 43 |
for (var i = 0; i < 36; i = i + 1) { |
| 44 |
theta = D2R * (i * 10.0); |
| 45 |
# Start at 90% of the circle radius |
| 46 |
var start_x = 0.9 * circle_radius * math.sin(theta); |
| 47 |
var start_y = -0.9 * circle_radius * math.cos(theta); |
| 48 |
var end_x = circle_radius * math.sin(theta); |
| 49 |
var end_y = -circle_radius * math.cos(theta); |
| 50 |
|
| 51 |
circle.moveTo(start_x, start_y); |
| 52 |
circle.lineTo(end_x, end_y); |
| 53 |
} |
| 54 |
|
| 55 |
# 5 - degree markings - 5% of radius |
| 56 |
for (var i = 0; i < 36; i = i + 1) { |
| 57 |
theta = D2R * (i * 10.0 + 5.0); |
| 58 |
# Start at 95% of the circle radius |
| 59 |
var start_x = 0.95 * circle_radius * math.sin(theta); |
| 60 |
var start_y = -0.95 * circle_radius * math.cos(theta); |
| 61 |
var end_x = circle_radius * math.sin(theta); |
| 62 |
var end_y = -circle_radius * math.cos(theta); |
| 63 |
|
| 64 |
circle.moveTo(start_x, start_y); |
| 65 |
circle.lineTo(end_x, end_y); |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
var _name = name; |
| 70 |
|
| 71 |
var init = func { |
| 72 |
# initialize the cached fix symbol |
| 73 |
var draw_fn = me.getOption('draw_function'); |
| 74 |
if(typeof(draw_fn) != 'func') |
| 75 |
draw_fn = drawVOR; |
| 76 |
|
| 77 |
var cache = StyleableCacheable.new( |
| 78 |
name:_name, |
| 79 |
draw_func: draw_fn, |
| 80 |
cache: SymbolCache256x256, |
| 81 |
draw_mode: SymbolCache.DRAW_CENTERED, |
| 82 |
relevant_keys: ["line_width", "icon_color", "circle_color", "circle_radius"], |
| 83 |
); |
| 84 |
cache.render(me.element, me.style).setScale(me.style.scale_factor); |
| 85 |
|
| 86 |
# Rotate the symbol to take into account the magnetic variation for the VOR. |
| 87 |
me.element.setRotation(me.model.magvar * D2R); |
| 88 |
|
| 89 |
# Center icon |
| 90 |
me.element.createChild("path") |
| 91 |
.setRotation(- me.model.magvar * D2R) |
| 92 |
.moveTo(-15,0) |
| 93 |
.lineTo(-7.5,12.5) |
| 94 |
.lineTo(7.5,12.5) |
| 95 |
.lineTo(15,0) |
| 96 |
.lineTo(7.5,-12.5) |
| 97 |
.lineTo(-7.5,-12.5) |
| 98 |
.close() |
| 99 |
.setStrokeLineWidth(me.getStyle('line_width', 1)) |
| 100 |
.setColor(me.getStyle('icon_color', [0,0.6,0.85])) |
| 101 |
.set("z-index",-2); |
| 102 |
|
| 103 |
|
| 104 |
# non-cached stuff: Symbol in use and labels. |
| 105 |
if (me.style.show_labels){ |
| 106 |
var txt_offset = me.getStyle('text_offset', [3, 0]); |
| 107 |
var txt_alignment = me.getStyle('text_alignment', 'center-bottom'); |
| 108 |
var txt_color = me.getStyle('text_color', [0,0.6,0.85]); |
| 109 |
var txt_bgcolor = me.getStyle('text_bgcolor', [0,0,0,0]); |
| 110 |
var txt_mode = me.getStyle('text_mode', canvas.Text.TEXT); |
| 111 |
var txt_padding = me.getStyle('text_padding', 0); |
| 112 |
var txt_size = me.getStyle('font_size', 14); |
| 113 |
|
| 114 |
me.text_fix = me.newText(me.model.id). |
| 115 |
setScale(me.style.scale_factor). |
| 116 |
setTranslation(txt_offset). |
| 117 |
setRotation(- me.model.magvar * D2R). |
| 118 |
setFontSize(txt_size). |
| 119 |
setAlignment(txt_alignment). |
| 120 |
setPadding(txt_padding). |
| 121 |
setDrawMode(txt_mode). |
| 122 |
setColor(txt_color). |
| 123 |
setColorFill(txt_bgcolor); |
| 124 |
} |
| 125 |
} |
| 126 |
var draw = func {me.callback('draw');}; |