Skinnable canvas window: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
Line 16: Line 16:
sk.addSkin("/foo/osc2.png"));</syntaxhighlight>
sk.addSkin("/foo/osc2.png"));</syntaxhighlight>


=== listen_mouse_clicks: func(object, function) ===
=== listen_mouse_events: func(caller, Hots) ===
: creates the listener and binds the events to ''function(e)''. Also checks the {{key press |ctrl}} key: ''ctrl-click'' outputs the mouse coordinates.
: '''Hots''' as vector of hashes as:  <br />
'''object''' as the calling object.<br />
*  {type:"click",  x:<''x''>, y:<''y''>,  action:<''action''>, tol:<''tol''>, parms:<''parms''> }
'''function''' as the callback function.<br />
*  {type:"wheel", x:<''x''>, y:<''y''>,  action:<''action''>, tol:<''tol''> }
: e.g. <syntaxhighlight lang="nasal">var sk = canvas.skinnable.new([575,290]);
*  {type:"cursor", x:<''x''>, y:<''y''>, style:<''style''>, tol:<''tol''>, tip:<''tipText''> }
sk.addSkin("/foo/osc2.png"));
*  {type:"tip", x:<''x''>, y:<''y''>, text:<''tipText''>, tol:<''tol''> }
sk.listen_mouse_clicks(object:me, function:me.onClick);
: where  ''x'' and ''y'' are the local coords of the hotspot.
</syntaxhighlight>
::: ''action'' (as string) is a function. The event will call the '''''caller['action']''''' method.
::: ''tol'' is the tolerance, the hotspot radious.
::: ''parms'' (as vector, scalar or nil) will be passed to ''caller.action()'' as arguments.
::: ''style'' (as string) is the cursor style to be used over the hotspot.
::: ''tipText'' is the string to be shown over the hotspot. Use an empty string for none.
<br />
: e.g. (borrowed from Oscilloscope) <syntaxhighlight lang="nasal">var wheelHots = [
{type:'wheel', x:417, y:82, action:'set1Gain', tol:12 },
{type:'cursor', x:417, y:82, style:'hand',      tol:12,  tip:'Ch-1 Gain' },
{type:'click',  x:427, y:82, action:'set1Gain', tol:6 ,  parms:1  },
{type:'click',  x:403, y:82, action:'set1Gain', tol:6 ,  parms:-1 },...
        ];
me.sk.listen_mouse_events(caller:me, Hots:Hots);</syntaxhighlight>


== Members ==
== Members ==

Revision as of 16:00, 8 March 2018


skinnable.nas implements the skinnable class. It inherits from canvas.

Constructor

new: func(size, title)

size mandatory as [width, height] vector, the window dimension.
title optional as string , the window title. Empty by default.

e.g.
 var sk = canvas.skinnable.new([575,290]);

Methods

Skinnable objects includes 2 methods:

addSkin: func(filename)

loads the image file and creates Canvas Image element.

filename as the absolute file path. The file must be a .png or a .jpg image.

e.g.
var sk = canvas.skinnable.new([575,290]);
sk.addSkin("/foo/osc2.png"));

listen_mouse_events: func(caller, Hots)

Hots as vector of hashes as:
  • {type:"click", x:<x>, y:<y>, action:<action>, tol:<tol>, parms:<parms> }
  • {type:"wheel", x:<x>, y:<y>, action:<action>, tol:<tol> }
  • {type:"cursor", x:<x>, y:<y>, style:<style>, tol:<tol>, tip:<tipText> }
  • {type:"tip", x:<x>, y:<y>, text:<tipText>, tol:<tol> }
where x and y are the local coords of the hotspot.
action (as string) is a function. The event will call the caller['action'] method.
tol is the tolerance, the hotspot radious.
parms (as vector, scalar or nil) will be passed to caller.action() as arguments.
style (as string) is the cursor style to be used over the hotspot.
tipText is the string to be shown over the hotspot. Use an empty string for none.


e.g. (borrowed from Oscilloscope)
var wheelHots = [
	{type:'wheel', x:417, y:82, action:'set1Gain', tol:12 },
	{type:'cursor', x:417, y:82, style:'hand',      tol:12,  tip:'Ch-1 Gain' },
	{type:'click',  x:427, y:82, action:'set1Gain', tol:6 ,  parms:1  },
	{type:'click',  x:403, y:82, action:'set1Gain', tol:6 ,  parms:-1 },...
        ];
 me.sk.listen_mouse_events(caller:me, Hots:Hots);

Members

skinnable.size

returns the window size as [width, height].

skinnable.window

returns the canvas.Window object.

skinnable.canvas

returns the canvas object.

skinnable.root

returns the root group/layer.


e.g.
 var sk = canvas.skinnable.new([575,290]);
 sk.window.set("title","oscilloscope" ).clearFocus();
 sk.canvas.set("background", '#224422');
 myGroup =  sk.root.createChild("group");