Classes


Last modified: 2013-2-27

Class jsui

Extends jsthis.

The following section describes properties and methods that are specific to jsui.

Jsui in Cycling '74 Reference

Class Summary
Constructor Attributes Constructor Name and Description
 
jsui()
The following section describes properties and methods that are specific to jsui.
Field Summary
Field Attributes Field Name and Description
Boolean get/set 
The inspector property, if set to 1, causes Max to look for an inspector patch specific to your script rather than the default jsui-insp.pat file.
MGraphics get 
An instance of MGraphics.
Sketch get 
An instance of Sketch which may be drawn into.
Fields borrowed from class jsthis:
autowatch, box, editfontsize, inlet, inlets, jsarguments, max, messagename, outlets
Fields borrowed from class Maxobj:
background, canhilite, colorindex, fontface, fontname, fontsize, hidden, hint, ignoreclick, js, maxclass, nextobject, patcher, rect, selected, valid, varname
Method Summary
Method Attributes Method Name and Description
void 
copies the contents of this.sketch to the screen.
Methods borrowed from class jsthis:
anything, arrayfromargs, assist, bang, declareattribute, embedmessage, getvalueof, list, loadbang, msg_float, msg_int, notifyclients, notifydeleted, outlet, save, setinletassist, setoutletassist, setvalueof, your_function_name_here
Methods borrowed from class Maxobj:
annotation, color, help, message, notify, subpatcher, understands
Event Summary
Event Attributes Event Name and Description
abstract void 
onclick(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all initial click events.
abstract void 
ondblclick(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all double click events.
abstract void 
ondrag(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all dragging events.
abstract void 
onidle(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all idle mouse events while the mouse is over the rectangle occupied by jsui object.
abstract void 
onidleout(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive the first idle mouse event as the mouse leaves the rectangle occupied by the jsui object.
abstract void 
onresize(width, height)
If defined, will receive any resize events with the new width and height.
Class Detail

jsui

()
The following section describes properties and methods that are specific to jsui.

jsui Event Handler methods

Since the jsui 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 jsui 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
function on (x, y, button, modifier1, shift, capslock, option, modifier2){
	// do something
}
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. (width, height) as right bottom corners of the jsui 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,
Example:
function onclick (x, y)
{
	sketch.moveto(sketch.screentoworld(x,y));
	sketch.framecircle(0.1);
	refresh();
}
Field Detail
{Boolean get/set}

inspector

The inspector property, if set to 1, causes Max to look for an inspector patch specific to your script rather than the default jsui-insp.pat file. The name used will be the name of your script (without the .js extension) plus –insp.pat. For example, if your script is called foo.js, your inspector file should be named foo-insp.pat. Inspector patches can be placed anywhere in the Max search path.

{MGraphics get}

mgraphics

An instance of MGraphics.

In order for you to use the mgraphics system within the jsui object, you need to have the following lines of code somewhere within the global section of your code:
Example:
// mgraphics is available after these lines
mgraphics.init();
mgraphics.relative_coords = 1;
mgraphics.autofill = 0;

{Sketch get}

sketch

An instance of Sketch which may be drawn into. A simple example is below. See the Sketch Object for a complete description of the properties and methods of the Sketch object.
Example:
sketch.default2d();

function bang()
{
	sketch.glclear();
	sketch.glcolor(0.5,0.7,0.3);
	sketch.moveto(0.25,-0.25);
	sketch.circle(0.3);
	refresh();
}
Method Detail
{void}

refresh

()
copies the contents of this.sketch to the screen.
Example:
function bang()
{
	draw();
	refresh();
	outlet(0,val);
}

function draw(){
	//... somthing happens here
}
Event Detail
{abstract void}

onclick

(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all initial click events. The button argument will always be on.
Example:
function onclick(x,y,button,cmd,shift,capslock,option,ctrl){
	// cache mouse position for tracking delta movements
	last_x = x;
	last_y = y;
}
//private. could be left public to permit "synthetic" events
onclick.local = 1;
Parameters:
{Integer} x
{Integer} y
{Integer} button
{Integer} cmd
{Integer} shift
{Integer} capslock
{Integer} option
{Integer} ctrl
 

{abstract void}

ondblclick

(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all double click events. The button argument will always be on.
Parameters:
{Integer} x
{Integer} y
{Integer} button
{Integer} cmd
{Integer} shift
{Integer} capslock
{Integer} option
{Integer} ctrl
 

{abstract void}

ondrag

(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all dragging events. The button argument will be on while dragging, and off when the dragging has stopped.
Parameters:
{Integer} x
{Integer} y
{Integer} button
{Integer} cmd
{Integer} shift
{Integer} capslock
{Integer} option
{Integer} ctrl
 

{abstract void}

onidle

(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive all idle mouse events while the mouse is over the rectangle occupied by jsui object. The button argument will always be off.
Example:
var mouseover = 0;

function bang()
{
	draw();
	refresh();
}

function onidle(x, y, button, cmd, shift, capslock, option, ctrl){

	if(mouseover == 0){
		mouseover = 1;
		post("mouse over\n");
		backgroundColor = [.8,.8,.8,1.];
		bang();
	}
}
onidle.local=1;

function onidleout(x, y, button, cmd, shift, capslock, option, ctrl){

	mouseover = 0;
	post("mouse out\n");

	backgroundColor = [1.,1.,1.,1.];
	bang();
}
onidleout.local=1;
Parameters:
{Integer} x
{Integer} y
{Integer} button
{Integer} cmd
{Integer} shift
{Integer} capslock
{Integer} option
{Integer} ctrl
 

{abstract void}

onidleout

(x, y, button, cmd, shift, capslock, option, ctrl)
If defined, will receive the first idle mouse event as the mouse leaves the rectangle occupied by the jsui object. The button argument will always be off.
Example:

var mouseover = 0;

function bang()
{
	draw();
	refresh();
}

function onidle(x, y, button, cmd, shift, capslock, option, ctrl){

	if(mouseover == 0){
		mouseover = 1;
		post("mouse over\n");
		backgroundColor = [.8,.8,.8,1.];
		bang();
	}
}
onidle.local=1;

function onidleout(x, y, button, cmd, shift, capslock, option, ctrl){

	mouseover = 0;
	post("mouse out\n");

	backgroundColor = [1.,1.,1.,1.];
	bang();
}
onidleout.local=1;
Parameters:
{Integer} x
{Integer} y
{Integer} button
{Integer} cmd
{Integer} shift
{Integer} capslock
{Integer} option
{Integer} ctrl
 

{abstract void}

onresize

(width, height)
If defined, will receive any resize events with the new width and height.
Example:

function onresize(w,h)
{
	if (w!=h) { // keep equal length
		h = w;
		box.size(w,h);
	}
	draw();
	refresh();
}
onresize.local = 1; //private
Parameters:
{Integer} width
{Integer} height
 

©2012-2013
Max MSP Documentation copied to JsDoc by Tim Schenk SEO Frelancer Berlin. Some examples are by him. Some descriptions of classes, interfaces, properties, methods or events are by him. Until now, most of it is a copy. Published with permission of Cycling '74. This document might be wrong or incomplete. All informations without any warranty. All trademarks are the property of their respective owners. Documentation generated by JsDoc Toolkit on 2013-2-27