<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet href="_c74_vig.xsl" type="text/xsl"?>
<vignette name="The jsui Object" package="Max">
<h1>
The jsui Object
</h1>
<p>
The following section describes properties and methods that are specific to <o>jsui</o>.
See
<link type="vignette" module="js" name="jsmaxobject">the Max Object</link>
section on the <o>js</o> Object
for properties and methods that are common to both the <o>js</o> and <o>jsui</o> object.
</p>

	<jsproperty_list name="jsui Specific">
		<jsproperty name="Sketch" get="1" set="0" type="Object">
			<description>
				An instance of Sketch which may be drawn into. A simple example is below. See <link type="vignette" module="js" name="jssketchobject">the Sketch Object</link> for a complete description of the properties and methods of the Sketch object.
				<code language="javascript">
  function bang()
  {
    sketch.glclear();
    sketch.glcolor(0.5,0.7,0.3);
    sketch.moveto(0.25,-0.25);
    sketch.circle(0.3);
    refresh();
  }
				</code>
        	</description>
    	</jsproperty>
    </jsproperty_list>

	<jsmethod_list name="jsui Specific Methods">
  		<jsmethod name="refresh">
		    <arglist>
		    	<arg name="" type=""/>
		    </arglist>
		    <description>
		    	copies the contents of this.sketch to the screen.
		    </description>
  		</jsmethod>
  	</jsmethod_list>
<h2>
jsui Event Handler Methods Overview
</h2>
<p>
Since the <o>jsui</o> object is a user interface object, it can receive and process user interface events. Currently the only user interface events which are supported are related to mouse activity and resizing off the <o>jsui</o> object. If the following methods are defined by your Javascript code, they will be called to handle these user interface events. All mouse events handlers should be defined with have a standard form of
</p>
<code language="javascript">
  function on&lt;eventname&gt; (x, y, button, modifier1, shift, capslock, option, modifier2)
  {
    // do something
  }
</code>
<p>
The modifier1 argument is the command key state on Macintosh, and the control key state on PC, and the modifier2 argument is the control key state on Macintosh, and the right button state on PC. Modifier state is 1 if down/held, or 0 if not. If your event handler is not concerned with any trailing arguments, they can be omitted.
</p>
<p>
One potentially confusing thing is that mouse events are in absolute screen coordinates, with (0,0) as left top, and (width, height) as right bottom corners of the <o>jsui</o> object,  while Sketch's drawing coordinates are in relative world coordinates, with (0,0) as the center, +1 top, -1 bottom,  and x coordinates using a uniform scale based on the y coordinates. To convert between screen and world coordinates, use sketch.screentoworld(x,y) and sketch.worldtoscreen(x,y,z). For example,
</p>
<code language="javascript">
  function onclick (x, y)
  {
    sketch.moveto(sketch.screentoworld(x,y));
    sketch.framecircle(0.1);
    refresh();
  }
</code>

	<jsmethod_list name="jsui Event Handler">

		<jsmethod name="onclick">
		    <arglist>
		    	<arg name="x"/>
				<arg name="y"/>
				<arg name="button"/>
				<arg name="mod1"/>
				<arg name="shift"/>
				<arg name="caps"/>
				<arg name="opt"/>
				<arg name="mod2"/>
		    </arglist>
		    <description>
		    	If defined, will receive all initial click events. The button argument will always be on.
		    </description>
  		</jsmethod>

  		<jsmethod name="ondblclick">
		    <arglist>
		    	<arg name="x"/>
				<arg name="y"/>
				<arg name="button"/>
				<arg name="mod1"/>
				<arg name="shift"/>
				<arg name="caps"/>
				<arg name="opt"/>
				<arg name="mod2"/>
		    </arglist>
		    <description>
		    	If defined, will receive all double click events. The button argument will always be on.
		    </description>
  		</jsmethod>
  		<jsmethod name="ondrag">
		    <arglist>
		    	<arg name="x"/>
				<arg name="y"/>
				<arg name="button"/>
				<arg name="mod1"/>
				<arg name="shift"/>
				<arg name="caps"/>
				<arg name="opt"/>
				<arg name="mod2"/>
		    </arglist>
		    <description>
		    	If defined, will receive all dragging events. The button argument will be on while dragging, and off when the dragging has stopped.
		    </description>
  		</jsmethod>
  		<jsmethod name="onidle">
		    <arglist>
		    	<arg name="x"/>
				<arg name="y"/>
				<arg name="button"/>
				<arg name="mod1"/>
				<arg name="shift"/>
				<arg name="caps"/>
				<arg name="opt"/>
				<arg name="mod2"/>
		    </arglist>
		    <description>
		    	If defined, will receive all idle mouse events while the mouse is over the rectangle occupied by <o>jsui</o> object. The button argument will always be off.
		    </description>
  		</jsmethod>
  		<jsmethod name="onidleout">
		    <arglist>
		    	<arg name="x"/>
				<arg name="y"/>
				<arg name="button"/>
				<arg name="mod1"/>
				<arg name="shift"/>
				<arg name="caps"/>
				<arg name="opt"/>
				<arg name="mod2"/>
		    </arglist>
		    <description>
		    	If defined, will receive the first idle mouse event as the mouse leaves the rectangle occupied by the <o>jsui</o> object. The button argument will always be off.
		    </description>
  		</jsmethod>
  		<jsmethod name="onresize">
		    <arglist>
		    	<arg name="width"/>
		    	<arg name="height"/>
		    </arglist>
		    <description>
		    	If defined, will receive any resize events with the new width and height.
		    </description>
  		</jsmethod>
	</jsmethod_list>
</vignette>
