Board index FlightGear Development Canvas

Canvas gui button - emulate mod-up

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Canvas gui button - emulate mod-up

Postby Alant » Fri Dec 01, 2017 10:06 pm

Is it possible to emulate the mod-up or one-shot binding with a canvas gui button?

I am setting a property to true when a button is clicked, but wish to set it false when the mouse is released.

Code: Select all
me.Enter_button = canvas.gui.widgets.Button.new(root, canvas.style, {})
         .setText("ENTER")
         .setFixedSize(100, 30)
         .listen("clicked",func {Enter_key()});

buttons1.addItem(me.Enter_button);

var Enter_key = func {
   print("Enter key clicked");
   setprop("systems/navigation/switches/Enter_key",1);
   }


TIA

Alan
Alant
 
Posts: 912
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10

Re: Canvas gui button - emulate mod-up

Postby wlbragg » Sat Dec 02, 2017 6:02 am

If you don't get a direct answer like a mod-up equivalent, could you use a timer to set it back to false?
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4877
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Canvas gui button - emulate mod-up

Postby Alant » Sat Dec 02, 2017 9:57 am

Yes that would work in this case.I could also clear the button-press property once it has been used.

However I have other buttons which have a specific action when released, and yet others which operate for as long as the button is pressed (e.g. slew, key repeat) and would like to simulate them also.
My Gui dialogs are designed to emulate (and work in parallel with) the relevant aircraft panels .

Tanks for the reply.

Alan
Alant
 
Posts: 912
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10

Re: Canvas gui button - emulate mod-up

Postby Hooray » Sat Dec 02, 2017 10:33 am

I guess I would also use timer objects (via maketimer) and then use lower-level canvas events: http://wiki.flightgear.org/Canvas_Event ... vent_types

You'd basically start a timer task and stop/suspend it separately, in your timer, you'd run a while loop doing check to make sure that it's not an infinite loop.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Canvas gui button - emulate mod-up

Postby Alant » Sat Dec 02, 2017 11:05 am

Hooray.

I will give that a go. I would prefer not to use a timer and will try to integrate the events directly with the button widget and my canvas code.

Alan
Alant
 
Posts: 912
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10

Re: Canvas gui button - emulate mod-up

Postby Alant » Sat Dec 02, 2017 11:06 pm

Hooray

I have a working solution - it turned out to be quite simple. :D

In fgdata/Nasal/canvas/gui/Buttons.nas, some code added to setDown. Note that at present it only works if the button is not checkable.

Code: Select all
  setDown: func(down = 1)
  {
    if( me._checkable or me._down == down )
      return me;

    me._down = down;
    me._onStateChange();

   if (!me._down){
      me._trigger("mouse_up", {checked: 0});
     print ("mouse up");
     }
    else{
      me._trigger("mouse_down", {checked: 0});
     print ("mouse down");
     }   
    
    return me;
  },


It is called from my canvas gui
Code: Select all
      me.Enter_button = canvas.gui.widgets.Button.new(root, canvas.style, {})
         .setText("ENTER")
         .setFixedSize(100, 30)
         .listen("mouse_down",func {Enter_key_press()})
         .listen("mouse_up",func {Enter_key_release()});
        buttons1.addItem(me.Enter_button);

var Enter_key_press = func {
   print("Enter key press");
   setprop("systems/navigation/switches/Enter_key",1);
   }
var Enter_key_release = func {
   print("Enter key release");
   setprop("systems/navigation/switches/Enter_key",0);
   }


For many purposes setting a property on mouse down is preferable to waiting for a complete mouse click cycle (click = down followed by release).

I will submit this to the devel list after some more testing, and deciding what is best to do if the button is checkable. If you have any observations please let me know.

Alan
Alant
 
Posts: 912
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10


Return to Canvas

Who is online

Users browsing this forum: No registered users and 28 guests