@ -82,7 +82,6 @@ var bg_width, bg_height = 0;
var mg = new MGraphics ( ui _width , ui _height ) ;
var base _drawing ;
var is _painting _base = 0 ;
var half _slot _size , half _margin , half _spacing ;
var last _x , last _y , last _hovered = - 1 ;
@ -167,17 +166,22 @@ function draw_slot(id, scale, cont) {
cont = typeof cont !== 'undefined' ? cont : mgraphics ; // Sets drawing context to mgraphics by default if not passed as argument
var offset = slot _size * ( 1 - scale ) ;
draw _slot _bubble ( slots [ id ] [ 0 ] + offset , slots [ id ] [ 1 ] + offset , slot _size * scale , slot _size * scale , cont ) ;
cont . fill ( ) ;
if ( layout == 1 ) {
// // Slot number
// var nb = i.toString();
// var nb_dim = text_measure(nb);
if ( is _painting _base ) {
draw _slot _bubble ( slots [ id ] [ 0 ] * scale , slots [ id ] [ 1 ] * scale , slot _size * scale , slot _size * scale , cont ) ;
// var nb_pos_x = slots[i][0] + (slot_size - nb_dim[0]) / 2;
// var nb_pos_y = slots[i][1] + (slot_size - spacing + nb_dim[1]) / 2 ;
} else {
draw _slot _bubble ( slots [ id ] [ 0 ] + offset , slots [ id ] [ 1 ] + offset , slot _size * scale , slot _size * scale , cont ) ;
}
cont . fill ( ) ;
// set_source_rgba(text_color);
// move_to(nb_pos_x, nb_pos_y);
// show_text(nb);
if ( layout == 1 ) {
// slot text background
var bg _txt _pos _x = margin + slot _size + spacing ;
var bg _txt _pos _y = slots [ id ] [ 1 ] ;
@ -189,17 +193,44 @@ function draw_slot(id, scale, cont) {
} else {
cont . set _source _rgba ( empty _slot _color ) ;
}
// cont.rectangle_rounded(bg_txt_pos_x, bg_txt_pos_y, bg_txt_dim_w, bg_txt_dim_h, 4, 4);
// slot name
cont . set _font _size ( font _size * scale ) ;
var text = format _slot _name ( id ) ;
var text = id ;
// If slot is locked, add brackets around its number
if ( slots [ id ] [ 5 ] == 1 ) {
text = '[' + text + ']' ;
}
// If slot has a name, append it to the preset name
if ( slots [ id ] [ 4 ] != null ) {
text += ': ' + slots [ id ] [ 4 ] ;
}
if ( is _painting _base ) {
draw _text _bubble ( bg _txt _pos _x * scale , bg _txt _pos _y * scale , bg _txt _dim _w * scale , bg _txt _dim _h * scale , text , cont ) ;
draw _text _bubble ( bg _txt _pos _x , bg _txt _pos _y , bg _txt _dim _w , bg _txt _dim _h , text , cont ) ;
// cont.fill();
} else {
draw _text _bubble ( bg _txt _pos _x + offset , bg _txt _pos _y + offset , bg _txt _dim _w * scale , bg _txt _dim _h * scale , text , cont ) ;
}
// // slot name
// var text = id;
// // If slot is locked, add brackets around its number
// if (slots[id][5] == 1) {
// text = '[' + text + ']';
// }
// // If slot has a name, append it to the preset name
// if (slots[id][4] != null) {
// text += ': ' + slots[id][4];
// }
// text = text.toString();
// var text_dim = cont.text_measure(text);
// var txt_pos_x = margin + slot_size + 2 * spacing;
// var txt_pos_y = bg_txt_pos_y + (bg_txt_dim_h - spacing + text_dim[1]) / 2 ;
// cont.set_source_rgba(text_color);
// cont.move_to(txt_pos_x, txt_pos_y);
// cont.show_text(text.toString());
}
}
@ -220,45 +251,40 @@ draw_slot_bubble.local = 1;
function draw _text _bubble ( x , y , w , h , text , cont ) {
cont = typeof cont !== 'undefined' ? cont : mgraphics ;
// slot text background
// var bg_txt_pos_x = margin + slot_size + spacing;
// var bg_txt_pos_y = slots[id][1];
// var bg_txt_dim_w = ui_width - (2*margin + slot_size + spacing);
// var bg_txt_dim_h = slot_size;
// if (slots[id][4] != null) {
// cont.set_source_rgba(stored_slot_color);
// } else {
// cont.set_source_rgba(empty_slot_color);
// }
cont . rectangle _rounded ( x , y , w , h , 4 , 4 ) ;
cont . fill ( ) ;
text = text . toString ( ) ;
var text _dim = cont . text _measure ( text ) ;
var txt _pos _x = x + spacing ;
var txt _pos _y = y + ( text _dim [ 1 ] + h ) / 2 - text _dim [ 1 ] * 0.18 ;
var txt _pos _x = margin + slot _size + 2 * spacing ;
var txt _pos _y = y + ( h - spacing + text _dim [ 1 ] ) / 2 ;
cont . set _source _rgba ( text _color ) ;
cont . move _to ( txt _pos _x , txt _pos _y ) ;
cont . show _text ( text . toString ( ) ) ;
}
function format _slot _name ( id ) {
var text = id ;
// If slot is locked, add brackets around its number
if ( slots [ id ] [ 5 ] == 1 ) {
text = '[' + text + ']' ;
}
// If slot has a name, append it to the preset name
if ( slots [ id ] [ 4 ] != null ) {
text += ': ' + slots [ id ] [ 4 ] ;
}
text = text . toString ( ) ;
return text ;
}
format _slot _name . local = 1 ;
function paint _base ( ) {
// We draw all slots (empty and stored ones) so we don't have to for every redraw
is _painting _base = 1 ;
// Background
bg _width = layout == 0 ? columns * ( slot _size + spacing ) - spacing + 2 * margin : ui _width ;
bg _height = rows * ( slot _size + spacing ) - spacing + 2 * margin ;
mg = new MGraphics ( ui _width * 2 , bg _height * 2 ) ;
mg = new MGraphics ( ui _width , bg _height ) ;
with ( mg ) {
set _source _rgba ( background _color ) ;
rectangle ( 0 , 0 , bg _width * 2 , bg _height * 2 ) ;
rectangle ( 0 , 0 , bg _width , bg _height ) ;
fill ( ) ;
select _font _face ( font _name ) ;
@ -272,11 +298,36 @@ function paint_base() {
} else {
set _source _rgba ( empty _slot _color ) ;
}
draw _slot ( i , 2 , mg ) ;
draw _slot ( i , 1 , mg ) ;
// fill();
}
}
// if (layout == 0) {
// for (var i = 1; i <= slots_count_display; i++) {
// if (slots[i][4] != null) {
// set_source_rgba(stored_slot_color);
// } else {
// set_source_rgba(empty_slot_color);
// }
// draw_slot_bubble(i, 1, mg);
// fill();
// }
// } else {
// for (var i = 1; i <= slots_count_display; i++) {
// if (slots[i][4] != null) {
// set_source_rgba(stored_slot_color);
// } else {
// set_source_rgba(empty_slot_color);
// }
// draw_slot(i, 1, mg);
// // fill();
// }
// }
}
is _painting _base = 0 ;
update _umenu ( ) ;
base _drawing = new Image ( mg ) ;
mgraphics . redraw ( ) ;
@ -287,34 +338,28 @@ function paint()
{
// post("redraw\n");
with ( mgraphics ) {
select _font _face ( font _name ) ;
set _font _size ( font _size ) ;
translate ( 0 , y _offset ) ;
// Draw the base, which includes empty and filled slots
// It is first rendered at twice the size in order to make texts look nice and cripsy on hidpi discplays
// So we need to scale it down here
scale ( 0.5 , 0.5 ) ;
image _surface _draw ( base _drawing ) ;
scale ( 2 , 2 ) ;
set _line _width ( 1 ) ;
// Active slot
if ( is _dragging == 0 && active _slot > 0 && active _slot <= slots _count _display ) {
if ( active _slot > 0 && active _slot <= slots _count _display && is _dragging == 0 ) {
set _source _rgba ( active _slot _color ) ;
draw _slot _bubble ( slots [ active _slot ] [ 0 ] , slots [ active _slot ] [ 1 ] , slot _size , slot _size ) ;
fill ( ) ;
}
// Previous active slot
if ( is _dragging == 0 && previous _active _slot > 0 && previous _active _slot <= slots _count _display ) {
if ( previous _active _slot > 0 && previous _active _slot <= slots _count _display ) {
set _source _rgba ( active _slot _color ) ;
draw _slot _bubble ( slots [ previous _active _slot ] [ 0 ] , slots [ previous _active _slot ] [ 1 ] , slot _size , slot _size ) ;
stroke ( ) ;
}
// Interpolated slots
if ( is _dragging == 0 && display _interp && is _interpolating ) {
if ( display _interp && is _interpolating ) {
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
var interp = slots [ i ] [ 6 ] ;
@ -333,11 +378,13 @@ function paint()
if ( shift _hold ) {
if ( option _hold ) {
// About to delete
post ( "about to delete\n" ) ;
set _source _rgba ( empty _slot _color [ 0 ] , empty _slot _color [ 1 ] , empty _slot _color [ 2 ] , 0.8 ) ;
draw _slot _bubble ( slots [ last _hovered ] [ 0 ] + 1 , slots [ last _hovered ] [ 1 ] + 1 , slot _size - 2 , slot _size - 2 ) ;
fill ( ) ;
} else {
// About to store
post ( "about to stàre\n" ) ;
set _source _rgba ( active _slot _color [ 0 ] , active _slot _color [ 1 ] , active _slot _color [ 2 ] , 0.7 ) ;
draw _slot _bubble ( slots [ last _hovered ] [ 0 ] + 1 , slots [ last _hovered ] [ 1 ] + 1 , slot _size - 2 , slot _size - 2 ) ;
fill ( ) ;
@ -350,7 +397,17 @@ function paint()
if ( layout == 0 ) {
//Text (slot number and name)
var text = format _slot _name ( last _hovered ) ;
var text = last _hovered ;
if ( slots [ last _hovered ] [ 5 ] == 1 ) {
text = '[' + text + ']' ;
}
if ( slots [ last _hovered ] [ 4 ] != null ) {
text += ': ' + slots [ last _hovered ] [ 4 ] ;
}
text = text . toString ( ) ;
select _font _face ( font _name ) ;
set _font _size ( font _size ) ;
var text _dim = text _measure ( text ) ;
// If the text is too big or a slot is being dragged, display the text on top of the next slot.
// Otherwise, it gets displayed on the hovered slot.
@ -387,8 +444,9 @@ function paint()
translate ( last _x , last _y ) ;
rotate ( 0.15 ) ;
scale ( 1.1 , 1.1 ) ;
// scale(3, 3);
// Slot s hadow
// Shadow
set _source _rgba ( 0 , 0 , 0 , 0.15 ) ;
for ( var i = 0 ; i < 4 ; i ++ ) {
draw _slot _bubble ( i * 0.4 + 1 - slot _size / 2 , i * 0.4 + 1 - slot _size / 2 , slot _size + i * 0.8 , slot _size + i * 0.8 ) ;
@ -396,8 +454,6 @@ function paint()
}
draw _slot _bubble ( 2 - slot _size / 2 , 2 - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
//Flying slot
set _source _rgba ( active _slot _color ) ;
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
@ -409,7 +465,15 @@ function paint()
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
// slot name
var text = format _slot _name ( drag _slot ) ;
var text = drag _slot ;
// If slot is locked, add brackets around its number
if ( slots [ drag _slot ] [ 5 ] == 1 ) {
text = '[' + text + ']' ;
}
// If slot has a name, append it to the preset name
if ( slots [ drag _slot ] [ 4 ] != null ) {
text += ': ' + slots [ drag _slot ] [ 4 ] ;
}
var bg _txt _pos _x = slot _size / 2 + spacing ;
var bg _txt _pos _y = - slot _size / 2 ;
var bg _txt _dim _w = ui _width - ( 2 * margin + slot _size + spacing ) ;
@ -428,7 +492,7 @@ paint.local = 1;
function anything ( ) {
// Here just to avoid error messages in case pattrstorage sends unhandled message, like when using getstoredvalue, getsubscriptionlist, getalias, etc.
// Handle the "delete" messages here because we can't declare a "function delete" ( it is a reserv ed word in js and cannot be used as a function name.
// Handle the "delete" messages here because it is a reserev d word in js and cannot be used as a function name.
if ( messagename == "delete" ) {
var v = arrayfromargs ( arguments ) [ 0 ] ;
v = Math . floor ( v ) ;
@ -701,8 +765,7 @@ function find_pattrstorage(name) {
pattrstorage _obj = this . patcher . getnamed ( name ) ;
if ( pattrstorage _obj !== null ) {
pattrstorage _name = name ;
slots _clear ( ) ;
// this.patcher.hiddenconnect(pattrstorage_obj, 0, this.box, 0);
// slots_clear();
to _pattrstorage ( "getslotlist" ) ;
to _pattrstorage ( "getlockedslots" ) ;
} else {