From 4b806a36c2899fbe9773723b3ea4825667faf31d Mon Sep 17 00:00:00 2001 From: "Nikolai V. Chr" Date: Tue, 16 Dec 2014 07:26:09 +0100 Subject: [PATCH] Added possibility to specify position to gui.popupTip --- Nasal/canvas/tooltip.nas | 24 +++++++++++++++++++----- Nasal/gui.nas | 9 +++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Nasal/canvas/tooltip.nas b/Nasal/canvas/tooltip.nas index cc92f0170..d1c4f0453 100644 --- a/Nasal/canvas/tooltip.nas +++ b/Nasal/canvas/tooltip.nas @@ -229,11 +229,19 @@ var Tooltip = { } }, - showMessage: func(timeout = nil) + showMessage: func(timeout = nil, node = nil) { - me.setInt("y", getprop('/sim/startup/ysize') * 0.2); - var screenW = getprop('/sim/startup/xsize'); - me.setInt("x", (screenW - me._width) * 0.5); + if(var y = me._haveNode(node, 'y') != nil ) { + me.setInt("y", y); + } else { + me.setInt("y", getprop('/sim/startup/ysize') * 0.2); + } + if(var x = me._haveNode(node, 'x') != nil) { + me.setInt("x", x); + } else { + var screenW = getprop('/sim/startup/xsize'); + me.setInt("x", (screenW - me._width) * 0.5); + } me.show(); # https://code.google.com/p/flightgear-bugs/issues/detail?id=1273 # when tooltip is shown for some other reason, ensure it stays for @@ -243,6 +251,12 @@ var Tooltip = { me._hideTimer.restart(timeout or me.DELAY); }, + _haveNode: func(node, key) { + if(node == nil ) return nil; + var value = num(node.getValue(key) ); + return value; + }, + hide: func() { # this gets run repeatedly during mouse-moves @@ -365,7 +379,7 @@ var showMessage = func(node) innerSetTooltip(node); var timeout = node.getNode("delay"); - tooltip.showMessage( timeout != nil ? timeout.getValue() : nil ); + tooltip.showMessage( timeout != nil ? timeout.getValue() : nil, node); } var clearMessage = func(node) diff --git a/Nasal/gui.nas b/Nasal/gui.nas index 0aa5210f4..0b780753a 100644 --- a/Nasal/gui.nas +++ b/Nasal/gui.nas @@ -6,11 +6,12 @@ # comes along and wants to pop a tip up before your delay is finished, # you lose. :) # -var popupTip = func(label, delay = nil, override = nil) +var popupTip = func(label, delay = nil, override = nil, position = nil) { - fgcommand("show-message", props.Node.new({ "label": label, "delay":delay })); - - + if (position == nil) { + position = {}; + } + fgcommand("show-message", props.Node.new({ "label": label, "delay":delay, "x": position['x'], "y": position['y'] })); } var showDialog = func(name) {