JS Painter file create border Max 7
Hey Guys,
I'd like to create a plain black border around several different objects using a JS Painter file. Could any body help me with the code or point me in the right direction? I tried entering someone's suggestion i found online but it did not work correctly.
Below is the example JavaScript code I used and an attached picture of the result.
Here is an example of drawing a toggle object in JS:
function paint()
{
var val = box.getvalueof()[0]; // this is an array of size 1
var viewsize = mgraphics.size;
var valrange = box.getattr("size");
var width = viewsize[0];
var height = viewsize[1];
var start;
mgraphics.set_source_rgba(box.getattr("bgcolor"));
mgraphics.rectangle(0, 0, width, height);
mgraphics.fill();
if (val) {
mgraphics.set_source_rgba(box.getattr("color"));
} else {
mgraphics.set_source_rgba(box.getattr("elementcolor"));
}
mgraphics.set_line_width((2./12.)*box.getattr("thickness")*0.01* width);
mgraphics.set_line_cap("square");
start = (7./24.) * width;
mgraphics.move_to(start, start);
mgraphics.line_to(width - start, height - start);
mgraphics.stroke();
mgraphics.move_to(width - start, start);
mgraphics.line_to(start, height - start);
mgraphics.stroke();
}
JSPAINTER-EXAMPLE-UI7-20140916.ZIP
Save it as jsp.border.js
in inspector, use it for jspainterfile
it adds a border drawing routine for whatever ui object.
It will eventually get the roundness of the max object and use it.
if not, default to 6
color border is fixed, you can change it in the js.
function paint()
{
var viewsize = mgraphics.size;
var valrange = box.getattr("size");
var width = viewsize[0];
var height = viewsize[1];
var border = 1;
var bordercolor = [ 0.375, 0.375, 0.375,1 ];
var rounded = 6;
if (box.getattr("rounded")) rounded = box.getattr("rounded");
// call original object paint method
mgraphics.parentpaint();
mgraphics.set_source_rgba(bordercolor);
mgraphics.rectangle_rounded(border/2, border/2, width-border, height-border, rounded, rounded);
mgraphics.set_line_width(border);
mgraphics.stroke();
}