| 1 |
# PFD UI Element - Rotating UI Element. Displays value by rotating an element around a center-point |
| 2 |
var RotatingElement = |
| 3 |
{ |
| 4 |
new : func (pagename, svg, name, minVal, maxVal, rangeDeg, centerOffset, value=0, style=nil) |
| 5 |
{ |
| 6 |
var obj = { |
| 7 |
parents : [ RotatingElement, PFD.UIElement ], |
| 8 |
_name : pagename ~ name, |
| 9 |
_edit : 0, |
| 10 |
_min : minVal, |
| 11 |
_max : maxVal, |
| 12 |
_rangeDeg : rangeDeg, |
| 13 |
_style : style, |
| 14 |
}; |
| 15 |
|
| 16 |
if (style == nil) obj._style = PFD.DefaultStyle; |
| 17 |
|
| 18 |
obj._symbol = svg.getElementById(obj._name); |
| 19 |
assert(obj._symbol != nil, "Unable to find element " ~ obj._name); |
| 20 |
obj._baseTranslation = obj._symbol.getTranslation(); |
| 21 |
|
| 22 |
# Set the center for rotation purposes. |
| 23 |
assert(size(centerOffset) == 2, "centerOffset must be an array of two elements [x,y]"); |
| 24 |
obj._symbol.set("center-offset-x", centerOffset[0]); |
| 25 |
obj._symbol.set("center-offset-y", centerOffset[1]); |
| 26 |
|
| 27 |
obj.setValue(value); |
| 28 |
|
| 29 |
# State and timer for flashing highlighting of elements |
| 30 |
# We need a separate Enabled flag as the timers are in a separate thread. |
| 31 |
obj._highlightEnabled = 0; |
| 32 |
obj._highlighted = 0; |
| 33 |
obj._flashTimer = nil; |
| 34 |
|
| 35 |
return obj; |
| 36 |
}, |
| 37 |
|
| 38 |
getName : func() { return me._name; }, |
| 39 |
getValue : func() { return me._value; }, |
| 40 |
setValue : func(value) { |
| 41 |
if (value == nil) value = 0.0; |
| 42 |
|
| 43 |
# Bound value to the minimum and maximum values. |
| 44 |
value = math.max(me._min, value); |
| 45 |
value = math.min(me._max, value); |
| 46 |
|
| 47 |
# Convert to normalized value |
| 48 |
value = (value - me._min) / (me._max - me._min); |
| 49 |
|
| 50 |
# Rotate, scales appropriately |
| 51 |
me._symbol.setRotation(value * me._rangeDeg * D2R, [0.0, 0.0]); |
| 52 |
}, |
| 53 |
|
| 54 |
setVisible : func(vis) { me._symbol.setVisible(vis); }, |
| 55 |
_flashElement : func() { |
| 56 |
if (me._highlightEnabled == 0) { |
| 57 |
me._symbol.setVisible(0); |
| 58 |
me._highlighted = 0; |
| 59 |
} else { |
| 60 |
if (me._highlighted == 0) { |
| 61 |
me._symbol.setVisible(1); |
| 62 |
me._highlighted = 1; |
| 63 |
} else { |
| 64 |
me._symbol.setVisible(0); |
| 65 |
me._highlighted = 0; |
| 66 |
} |
| 67 |
} |
| 68 |
}, |
| 69 |
highlightElement : func() { |
| 70 |
me._highlightEnabled = 1; |
| 71 |
me._highlighted = 0; |
| 72 |
me._flashElement(); |
| 73 |
me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); |
| 74 |
me._flashTimer.start(); |
| 75 |
}, |
| 76 |
unhighlightElement : func() { |
| 77 |
if (me._flashTimer != nil) me._flashTimer.stop(); |
| 78 |
me._flashTimer = nil; |
| 79 |
me._highlightEnabled = 0; |
| 80 |
me._highlighted = 0; |
| 81 |
me._flashElement(); |
| 82 |
}, |
| 83 |
isEditable : func () { return 0; }, |
| 84 |
isInEdit : func() { return 0; }, |
| 85 |
enterElement : func() { return me.getValue(); }, |
| 86 |
clearElement : func() { }, |
| 87 |
editElement : func() { }, |
| 88 |
incrSmall : func(value) { }, |
| 89 |
incrLarge : func(value) { }, |
| 90 |
}; |