| 1 |
# PFD UI Element - Scrolling UI Text Element. |
| 2 |
# Has a set of values and arrows left & right to indicate whether there are |
| 3 |
# further data items to scroll through. |
| 4 |
var ScrollElement = |
| 5 |
{ |
| 6 |
|
| 7 |
new : func (pageName, svg, name, values, initialIndex=0, style=nil) |
| 8 |
{ |
| 9 |
var obj = { |
| 10 |
parents : [ ScrollElement, PFD.UIElement ], |
| 11 |
_name : pageName ~ name, |
| 12 |
_values : values, |
| 13 |
_index : 0, |
| 14 |
_style : style, |
| 15 |
}; |
| 16 |
|
| 17 |
if (style == nil) obj._style = PFD.DefaultStyle; |
| 18 |
|
| 19 |
obj._symbol = svg.getElementById(obj._name); |
| 20 |
assert(obj._symbol != nil, "Unable to find element " ~ obj._name); |
| 21 |
|
| 22 |
obj._leftsymbol = svg.getElementById(obj._name ~ "Left"); |
| 23 |
assert(obj._leftsymbol != nil, "Unable to find element " ~ obj._name ~ "Left"); |
| 24 |
|
| 25 |
obj._rightsymbol = svg.getElementById(obj._name ~ "Right"); |
| 26 |
assert(obj._rightsymbol != nil, "Unable to find element " ~ obj._name ~ "Right"); |
| 27 |
|
| 28 |
obj._index = initialIndex; |
| 29 |
assert(initialIndex < size(values) , "Initial index " ~ initialIndex ~ " extends past end of value array"); |
| 30 |
|
| 31 |
# State and timer for flashing highlighting of elements |
| 32 |
# We need a separate Enabled flag as the timers are in a separate thread. |
| 33 |
obj._highlightEnabled = 0; |
| 34 |
obj._highlighted = 0; |
| 35 |
obj._flashTimer = nil; |
| 36 |
|
| 37 |
obj.updateValues(); |
| 38 |
|
| 39 |
return obj; |
| 40 |
}, |
| 41 |
|
| 42 |
updateValues : func() { |
| 43 |
if (me._index == 0 ) { |
| 44 |
me._leftsymbol.setColorFill(me._style.SCROLL_UNAVAILABLE); |
| 45 |
me._leftsymbol.setColor(me._style.SCROLL_UNAVAILABLE); |
| 46 |
} else { |
| 47 |
me._leftsymbol.setColorFill(me._style.SCROLL_AVAILABLE); |
| 48 |
me._leftsymbol.setColor(me._style.SCROLL_AVAILABLE); |
| 49 |
} |
| 50 |
|
| 51 |
if ((size(me._values) > 0) and (me._index < (size(me._values) -1))) { |
| 52 |
me._rightsymbol.setColorFill(me._style.SCROLL_AVAILABLE); |
| 53 |
me._rightsymbol.setColor(me._style.SCROLL_AVAILABLE); |
| 54 |
} else { |
| 55 |
me._rightsymbol.setColorFill(me._style.SCROLL_UNAVAILABLE); |
| 56 |
me._rightsymbol.setColor(me._style.SCROLL_UNAVAILABLE); |
| 57 |
} |
| 58 |
|
| 59 |
me._symbol.setText(me._values[me._index]); |
| 60 |
}, |
| 61 |
|
| 62 |
getName : func() { return me._name; }, |
| 63 |
getValue : func() { return me._symbol.getText(); }, |
| 64 |
setValue : func(value) { |
| 65 |
var idx = find(value, me._values); |
| 66 |
if (idx != -1) { |
| 67 |
me._index = idx; |
| 68 |
me._symbol.setText(value); |
| 69 |
} |
| 70 |
}, |
| 71 |
setValues : func(values) { |
| 72 |
me._values = values; |
| 73 |
me._index = 0; |
| 74 |
me.updateValues(); |
| 75 |
}, |
| 76 |
setVisible : func(vis) { |
| 77 |
me._symbol.setVisible(vis); |
| 78 |
me._leftsymbol.setVisible(vis); |
| 79 |
me._rightsymbol.setVisible(vis); |
| 80 |
}, |
| 81 |
_flashElement : func() { |
| 82 |
if (me._highlightEnabled == 0) { |
| 83 |
me._symbol.setDrawMode(canvas.Text.TEXT); |
| 84 |
me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); |
| 85 |
me._highlighted = 0; |
| 86 |
} else { |
| 87 |
if (me._highlighted == 0) { |
| 88 |
me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); |
| 89 |
me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR); |
| 90 |
me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR); |
| 91 |
me._highlighted = 1; |
| 92 |
} else { |
| 93 |
me._symbol.setDrawMode(canvas.Text.TEXT); |
| 94 |
me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); |
| 95 |
me._highlighted = 0; |
| 96 |
} |
| 97 |
} |
| 98 |
}, |
| 99 |
highlightElement : func() { |
| 100 |
me._highlightEnabled = 1; |
| 101 |
me._highlighted = 0; |
| 102 |
me._flashElement(); |
| 103 |
me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); |
| 104 |
me._flashTimer.start(); |
| 105 |
}, |
| 106 |
unhighlightElement : func() { |
| 107 |
if (me._flashTimer != nil) me._flashTimer.stop(); |
| 108 |
me._flashTimer = nil; |
| 109 |
me._highlightEnabled = 0; |
| 110 |
me._highlighted = 0; |
| 111 |
me._flashElement(); |
| 112 |
}, |
| 113 |
isEditable : func () { return 0; }, |
| 114 |
isInEdit : func() { return 0; }, |
| 115 |
enterElement : func() { return me.getValue(); }, |
| 116 |
clearElement : func() { }, |
| 117 |
editElement : func() { }, |
| 118 |
incrSmall : func(value) { |
| 119 |
# Increment the scroll value; |
| 120 |
var incr_or_decr = (value > 0) ? 1 : -1; |
| 121 |
if ((me._index + incr_or_decr) < 0) return; |
| 122 |
if ((me._index + incr_or_decr) > (size(me._values) -1)) return; |
| 123 |
me._index = me._index + incr_or_decr; |
| 124 |
me.updateValues(); |
| 125 |
}, |
| 126 |
incrLarge : func(value) { }, |
| 127 |
}; |