From c8072e5e2c5fdbe515762317fb3fc570fa04f769 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sun, 4 Feb 2018 22:40:48 +0000 Subject: [PATCH] Fix badly flashing UI elements due to timers --- .../Nasal/DirectTo/DirectToController.nas | 1 + Nasal/canvas/PFD/DataEntryElement.nas | 58 ++++++++++++------- Nasal/canvas/PFD/HighlightElement.nas | 22 ++++--- Nasal/canvas/PFD/PointerElement.nas | 22 ++++--- Nasal/canvas/PFD/RotatingElement.nas | 22 ++++--- Nasal/canvas/PFD/ScrollElement.nas | 35 ++++++----- Nasal/canvas/PFD/TextElement.nas | 27 ++++++--- 7 files changed, 123 insertions(+), 64 deletions(-) diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/DirectTo/DirectToController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/DirectTo/DirectToController.nas index 7378bdbbd..876df453a 100644 --- a/Aircraft/Instruments-3d/FG1000/Nasal/DirectTo/DirectToController.nas +++ b/Aircraft/Instruments-3d/FG1000/Nasal/DirectTo/DirectToController.nas @@ -228,6 +228,7 @@ var DirectToController = # We're in the Waypoint Submenu, in which case the outer FMS knob # selects between the different waypoints in the Waypoint Submenu. me.page.WaypointSubmenuSelect.unhighlightElement(); + me.page.WaypointSubmenuScroll.showCRSR(); me.page.WaypointSubmenuScroll.incrLarge(value); } else if (me._cursorElements[me._selectedElement].isInEdit()) { # If we're editing an element, then get on with it! diff --git a/Nasal/canvas/PFD/DataEntryElement.nas b/Nasal/canvas/PFD/DataEntryElement.nas index 0db0cabff..ff9193b00 100644 --- a/Nasal/canvas/PFD/DataEntryElement.nas +++ b/Nasal/canvas/PFD/DataEntryElement.nas @@ -35,8 +35,11 @@ var DataEntryElement = # State and timer for flashing highlighting of elements obj._highlighted = 0; - obj._highlightedChar = 0; + obj._highlightEnabled = 0; obj._flashTimer = nil; + + obj._highlightChar = 0; + obj._highlightCharEnabled = 0; obj._flashCharTimer = nil; return obj; @@ -54,19 +57,28 @@ var DataEntryElement = for (var i = 0; i < me._size; i = i + 1) me._dataEntrySymbol[i].setVisible(0); } }, + _flashElement : func() { - if (me._highlighted == 0) { - me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); - me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR); - me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR); - me._highlighted = 1; - } else { + if (me._highlightEnabled == 0) { me._symbol.setDrawMode(canvas.Text.TEXT); me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); me._highlighted = 0; + } else { + if (me._highlighted == 0) { + me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); + me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR); + me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR); + me._highlighted = 1; + } else { + me._symbol.setDrawMode(canvas.Text.TEXT); + me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); + me._highlighted = 0; + } } }, highlightElement : func() { + me._highlightEnabled = 1; + me._highlighted = 0; me._flashElement(); me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); me._flashTimer.start(); @@ -74,25 +86,32 @@ var DataEntryElement = unhighlightElement : func() { if (me._flashTimer != nil) me._flashTimer.stop(); me._flashTimer = nil; - - # Reset the highlight to a non-highlighted state. - me._highlighted = 1; + me._highlightEnabled = 0; + me._highlighted = 0; me._flashElement(); }, _flashCharElement : func() { - if (me._highlighted == 0) { - me._dataEntrySymbol[me._dataEntryPos].setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); - me._dataEntrySymbol[me._dataEntryPos].setColorFill(me._style.HIGHLIGHT_COLOR); - me._dataEntrySymbol[me._dataEntryPos].setColor(me._style.HIGHLIGHT_TEXT_COLOR); - me._highlightedChar = 1; - } else { + if (me._highlightCharEnabled == 0) { me._dataEntrySymbol[me._dataEntryPos].setDrawMode(canvas.Text.TEXT); me._dataEntrySymbol[me._dataEntryPos].setColor(me._style.NORMAL_TEXT_COLOR); - me._highlightedChar = 0; + me._highlightChar = 0; + } else { + if (me._highlightChar == 0) { + me._dataEntrySymbol[me._dataEntryPos].setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); + me._dataEntrySymbol[me._dataEntryPos].setColorFill(me._style.HIGHLIGHT_COLOR); + me._dataEntrySymbol[me._dataEntryPos].setColor(me._style.HIGHLIGHT_TEXT_COLOR); + me._highlightChar = 1; + } else { + me._dataEntrySymbol[me._dataEntryPos].setDrawMode(canvas.Text.TEXT); + me._dataEntrySymbol[me._dataEntryPos].setColor(me._style.NORMAL_TEXT_COLOR); + me._highlightChar = 0; + } } }, highlightCharElement : func() { + me._highlightCharEnabled = 1; + me._highlightChar = 0; me._flashCharElement(); me._flashCharTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashCharElement); me._flashCharTimer.start(); @@ -100,9 +119,8 @@ var DataEntryElement = unhighlightCharElement : func() { if (me._flashCharTimer != nil) me._flashCharTimer.stop(); me._flashCharTimer = nil; - - # Reset the highlight to a non-highlighted state. - me._highlightedChar = 1; + me._highlightCharEnabled = 0; + me._highlightChar = 0; me._flashCharElement(); }, isEditable : func () { return 1; }, diff --git a/Nasal/canvas/PFD/HighlightElement.nas b/Nasal/canvas/PFD/HighlightElement.nas index 281e6fb2b..7bd278f67 100644 --- a/Nasal/canvas/PFD/HighlightElement.nas +++ b/Nasal/canvas/PFD/HighlightElement.nas @@ -17,6 +17,8 @@ var HighlightElement = assert(obj._symbol != nil, "Unable to find element " ~ obj._name); # State and timer for flashing highlighting of elements + # We need a separate Enabled flag as the timers are in a separate thread. + obj._highlightEnabled = 0; obj._highlighted = 0; obj._flashTimer = nil; @@ -31,15 +33,22 @@ var HighlightElement = setVisible : func(vis) { me._symbol.setVisible(vis); }, _flashElement : func() { - if (me._highlighted == 0) { - me._symbol.setVisible(1); - me._highlighted = 1; - } else { + if (me._highlightEnabled == 0) { me._symbol.setVisible(0); me._highlighted = 0; + } else { + if (me._highlighted == 0) { + me._symbol.setVisible(1); + me._highlighted = 1; + } else { + me._symbol.setVisible(0); + me._highlighted = 0; + } } }, highlightElement : func() { + me._highlightEnabled = 1; + me._highlighted = 0; me._flashElement(); me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); me._flashTimer.start(); @@ -47,10 +56,9 @@ var HighlightElement = unhighlightElement : func() { if (me._flashTimer != nil) me._flashTimer.stop(); me._flashTimer = nil; - - # Reset the highlight to a non-highlighted state. - me._symbol.setVisible(0); + me._highlightEnabled = 0; me._highlighted = 0; + me._flashElement(); }, isEditable : func () { return 0; }, isInEdit : func() { return 0; }, diff --git a/Nasal/canvas/PFD/PointerElement.nas b/Nasal/canvas/PFD/PointerElement.nas index be9e0bb2e..9991f964d 100644 --- a/Nasal/canvas/PFD/PointerElement.nas +++ b/Nasal/canvas/PFD/PointerElement.nas @@ -22,6 +22,8 @@ var PointerElement = obj.setValue(value); # State and timer for flashing highlighting of elements + # We need a separate Enabled flag as the timers are in a separate thread. + obj._highlightEnabled = 0; obj._highlighted = 0; obj._flashTimer = nil; @@ -59,15 +61,22 @@ var PointerElement = setVisible : func(vis) { me._symbol.setVisible(vis); }, _flashElement : func() { - if (me._highlighted == 0) { - me._symbol.setVisible(1); - me._highlighted = 1; - } else { + if (me._highlightEnabled == 0) { me._symbol.setVisible(0); me._highlighted = 0; + } else { + if (me._highlighted == 0) { + me._symbol.setVisible(1); + me._highlighted = 1; + } else { + me._symbol.setVisible(0); + me._highlighted = 0; + } } }, highlightElement : func() { + me._highlightEnabled = 1; + me._highlighted = 0; me._flashElement(); me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); me._flashTimer.start(); @@ -75,9 +84,8 @@ var PointerElement = unhighlightElement : func() { if (me._flashTimer != nil) me._flashTimer.stop(); me._flashTimer = nil; - - # Reset the highlight to a non-highlighted state. - me._highlighted = 1; + me._highlightEnabled = 0; + me._highlighted = 0; me._flashElement(); }, isEditable : func () { return 0; }, diff --git a/Nasal/canvas/PFD/RotatingElement.nas b/Nasal/canvas/PFD/RotatingElement.nas index 20a874c2d..2e9f0947c 100644 --- a/Nasal/canvas/PFD/RotatingElement.nas +++ b/Nasal/canvas/PFD/RotatingElement.nas @@ -27,6 +27,8 @@ var RotatingElement = obj.setValue(value); # State and timer for flashing highlighting of elements + # We need a separate Enabled flag as the timers are in a separate thread. + obj._highlightEnabled = 0; obj._highlighted = 0; obj._flashTimer = nil; @@ -51,15 +53,22 @@ var RotatingElement = setVisible : func(vis) { me._symbol.setVisible(vis); }, _flashElement : func() { - if (me._highlighted == 0) { - me._symbol.setVisible(1); - me._highlighted = 1; - } else { + if (me._highlightEnabled == 0) { me._symbol.setVisible(0); me._highlighted = 0; + } else { + if (me._highlighted == 0) { + me._symbol.setVisible(1); + me._highlighted = 1; + } else { + me._symbol.setVisible(0); + me._highlighted = 0; + } } }, highlightElement : func() { + me._highlightEnabled = 1; + me._highlighted = 0; me._flashElement(); me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); me._flashTimer.start(); @@ -67,9 +76,8 @@ var RotatingElement = unhighlightElement : func() { if (me._flashTimer != nil) me._flashTimer.stop(); me._flashTimer = nil; - - # Reset the highlight to a non-highlighted state. - me._highlighted = 1; + me._highlightEnabled = 0; + me._highlighted = 0; me._flashElement(); }, isEditable : func () { return 0; }, diff --git a/Nasal/canvas/PFD/ScrollElement.nas b/Nasal/canvas/PFD/ScrollElement.nas index 5074cee2e..5fbd7b2e5 100644 --- a/Nasal/canvas/PFD/ScrollElement.nas +++ b/Nasal/canvas/PFD/ScrollElement.nas @@ -29,6 +29,8 @@ var ScrollElement = assert(initialIndex < size(values) , "Initial index " ~ initialIndex ~ " extends past end of value array"); # State and timer for flashing highlighting of elements + # We need a separate Enabled flag as the timers are in a separate thread. + obj._highlightEnabled = 0; obj._highlighted = 0; obj._flashTimer = nil; @@ -77,30 +79,35 @@ var ScrollElement = me._rightsymbol.setVisible(vis); }, _flashElement : func() { - if (me._highlighted == 0) { - me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); - me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR); - me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR); - me._highlighted = 1; - } else { + if (me._highlightEnabled == 0) { me._symbol.setDrawMode(canvas.Text.TEXT); me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); me._highlighted = 0; + } else { + if (me._highlighted == 0) { + me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); + me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR); + me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR); + me._highlighted = 1; + } else { + me._symbol.setDrawMode(canvas.Text.TEXT); + me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); + me._highlighted = 0; + } } }, highlightElement : func() { - if (me._flashTimer == nil) { - me._flashElement(); - me._flashTimer = maketimer(0.5, me, me._flashElement); - me._flashTimer.start(); - } + me._highlightEnabled = 1; + me._highlighted = 0; + me._flashElement(); + me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); + me._flashTimer.start(); }, unhighlightElement : func() { if (me._flashTimer != nil) me._flashTimer.stop(); me._flashTimer = nil; - - # Reset the highlight to a non-highlighted state. - me._highlighted = 1; + me._highlightEnabled = 0; + me._highlighted = 0; me._flashElement(); }, isEditable : func () { return 0; }, diff --git a/Nasal/canvas/PFD/TextElement.nas b/Nasal/canvas/PFD/TextElement.nas index 503523625..37ec05243 100644 --- a/Nasal/canvas/PFD/TextElement.nas +++ b/Nasal/canvas/PFD/TextElement.nas @@ -17,6 +17,8 @@ var TextElement = obj.setValue(value); # State and timer for flashing highlighting of elements + # We need a separate Enabled flag as the timers are in a separate thread. + obj._highlightEnabled = 0; obj._highlighted = 0; obj._flashTimer = nil; @@ -28,18 +30,26 @@ var TextElement = setValue : func(value) { me._symbol.setText(value); }, setVisible : func(vis) { me._symbol.setVisible(vis); }, _flashElement : func() { - if (me._highlighted == 0) { - me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); - me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR); - me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR); - me._highlighted = 1; - } else { + if (me._highlightEnabled == 0) { me._symbol.setDrawMode(canvas.Text.TEXT); me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); me._highlighted = 0; + } else { + if (me._highlighted == 0) { + me._symbol.setDrawMode(canvas.Text.TEXT + canvas.Text.FILLEDBOUNDINGBOX); + me._symbol.setColorFill(me._style.HIGHLIGHT_COLOR); + me._symbol.setColor(me._style.HIGHLIGHT_TEXT_COLOR); + me._highlighted = 1; + } else { + me._symbol.setDrawMode(canvas.Text.TEXT); + me._symbol.setColor(me._style.NORMAL_TEXT_COLOR); + me._highlighted = 0; + } } }, highlightElement : func() { + me._highlightEnabled = 1; + me._highlighted = 0; me._flashElement(); me._flashTimer = maketimer(me._style.CURSOR_BLINK_PERIOD, me, me._flashElement); me._flashTimer.start(); @@ -47,9 +57,8 @@ var TextElement = unhighlightElement : func() { if (me._flashTimer != nil) me._flashTimer.stop(); me._flashTimer = nil; - - # Reset the highlight to a non-highlighted state. - me._highlighted = 1; + me._highlightEnabled = 0; + me._highlighted = 0; me._flashElement(); }, isEditable : func () { return 0; },