@ -193,41 +193,50 @@ function draw_slot(id, scale, cont) {
} else {
} else {
cont . set _source _rgba ( empty _slot _color ) ;
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 ) ;
// cont.rectangle_rounded(bg_txt_pos_x, bg_txt_pos_y, bg_txt_dim_w, bg_txt_dim_h, 4, 4);
cont . fill ( ) ;
// 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 ] ;
}
// slot name
draw _text _bubble ( bg _txt _pos _x , bg _txt _pos _y , bg _txt _dim _w , bg _txt _dim _h , text , cont ) ;
if ( 1 ) {
// cont.fill();
// // 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) {
// if (slots[id][4] != null) {
var text = id ;
// text += ': ' + slots[id][4];
// 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 ( ) ;
// text = text.toString();
var text _dim = cont . text _measure ( text ) ;
// var text_dim = cont.text_measure(text);
var txt _pos _x = margin + slot _size + 2 * spacing ;
// 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 ;
// var txt_pos_y = bg_txt_pos_y + (bg_txt_dim_h - spacing + text_dim[1]) / 2 ;
cont . set _source _rgba ( text _color ) ;
// cont.set_source_rgba(text_color);
cont . move _to ( txt _pos _x , txt _pos _y ) ;
// cont.move_to(txt_pos_x, txt_pos_y);
cont . show _text ( text . toString ( ) ) ;
// cont.show_text(text.toString());
}
}
}
}
}
draw _slot . local = 1 ;
draw _slot . local = 1 ;
function draw _slot _bubble ( x , y , w , h , cont ) {
function draw _slot _bubble ( x , y , w , h , cont ) {
cont = typeof cont !== 'undefined' ? cont : mgraphics ;
cont = typeof cont !== 'undefined' ? cont : mgraphics ;
// I assume rectange is faster to draw than rectangle_rounded. Btw rectangle_rounded is wacky when showing interpolation. Maybe *interp on the first slot_round could solve this?
// I assume rectange is faster to draw than rectangle_rounded. Btw rectangle_rounded is wacky when showing interpolation. Maybe *interp on the first slot_round could solve this?
@ -239,6 +248,33 @@ function draw_slot_bubble (x, y, w, h, cont) {
}
}
draw _slot _bubble . local = 1 ;
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 = 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 paint _base ( ) {
function paint _base ( ) {
// We draw all slots (empty and stored ones) so we don't have to for every redraw
// We draw all slots (empty and stored ones) so we don't have to for every redraw
@ -256,13 +292,15 @@ function paint_base() {
// All slots
// All slots
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
if ( slots [ i ] [ 4 ] != null ) {
if ( i != drag _slot ) { //We mask the slot that is currently dragged as it is drawn at the mouse position already
set _source _rgba ( stored _slot _color ) ;
if ( slots [ i ] [ 4 ] != null ) {
} else {
set _source _rgba ( stored _slot _color ) ;
set _source _rgba ( empty _slot _color ) ;
} else {
set _source _rgba ( empty _slot _color ) ;
}
draw _slot ( i , 1 , mg ) ;
// fill();
}
}
draw _slot ( i , 1 , mg ) ;
// fill();
}
}
// if (layout == 0) {
// if (layout == 0) {
@ -307,7 +345,7 @@ function paint()
set _line _width ( 1 ) ;
set _line _width ( 1 ) ;
// Active slot
// Active slot
if ( 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 ) ;
set _source _rgba ( active _slot _color ) ;
draw _slot _bubble ( slots [ active _slot ] [ 0 ] , slots [ active _slot ] [ 1 ] , slot _size , slot _size ) ;
draw _slot _bubble ( slots [ active _slot ] [ 0 ] , slots [ active _slot ] [ 1 ] , slot _size , slot _size ) ;
fill ( ) ;
fill ( ) ;
@ -340,11 +378,13 @@ function paint()
if ( shift _hold ) {
if ( shift _hold ) {
if ( option _hold ) {
if ( option _hold ) {
// About to delete
// 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 ) ;
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 ) ;
draw _slot _bubble ( slots [ last _hovered ] [ 0 ] + 1 , slots [ last _hovered ] [ 1 ] + 1 , slot _size - 2 , slot _size - 2 ) ;
fill ( ) ;
fill ( ) ;
} else {
} else {
// About to store
// 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 ) ;
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 ) ;
draw _slot _bubble ( slots [ last _hovered ] [ 0 ] + 1 , slots [ last _hovered ] [ 1 ] + 1 , slot _size - 2 , slot _size - 2 ) ;
fill ( ) ;
fill ( ) ;
@ -400,22 +440,49 @@ function paint()
// Drag slot
// Drag slot
if ( is _dragging ) {
if ( is _dragging ) {
translate ( last _x , last _y ) ;
if ( layout == 0 ) {
rotate ( 0.15 ) ;
translate ( last _x , last _y ) ;
scale ( 1.1 , 1.1 ) ;
rotate ( 0.15 ) ;
// scale(3, 3);
scale ( 1.1 , 1.1 ) ;
// scale(3, 3);
// Shadow
set _source _rgba ( 0 , 0 , 0 , 0.15 ) ;
// Shadow
for ( var i = 0 ; i < 4 ; i ++ ) {
set _source _rgba ( 0 , 0 , 0 , 0.15 ) ;
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 ) ;
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 ) ;
fill ( ) ;
}
draw _slot _bubble ( 2 - slot _size / 2 , 2 - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
fill ( ) ;
set _source _rgba ( active _slot _color ) ;
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
} else {
translate ( last _x , last _y ) ;
// rotate(0.15);
set _source _rgba ( active _slot _color ) ;
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
// slot name
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 ) ;
var bg _txt _dim _h = slot _size ;
set _source _rgba ( stored _slot _color ) ;
draw _text _bubble ( bg _txt _pos _x , bg _txt _pos _y , bg _txt _dim _w , bg _txt _dim _h , text ) ;
}
}
draw _slot _bubble ( 2 - slot _size / 2 , 2 - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
set _source _rgba ( stored _slot _color ) ;
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
}
}
}
}
@ -792,8 +859,8 @@ function onidle(x,y,but,cmd,shift,capslock,option,ctrl)
var cur = get _slot _index ( x , y - y _offset ) ;
var cur = get _slot _index ( x , y - y _offset ) ;
if ( cur != last _hovered ) {
if ( cur != last _hovered ) {
last _hovered = cur ;
last _hovered = cur ;
mgraphics . redraw ( ) ;
}
}
mgraphics . redraw ( ) ;
}
}
}
}
onidle . local = 1 ;
onidle . local = 1 ;
@ -838,6 +905,7 @@ function ondrag(x,y,but,cmd,shift,capslock,option,ctrl)
if ( dist _from _start > 10 ) {
if ( dist _from _start > 10 ) {
is _dragging = 1 ;
is _dragging = 1 ;
drag _slot = last _hovered ;
drag _slot = last _hovered ;
paint _base ( ) ;
}
}
} else if ( is _dragging == 1 ) {
} else if ( is _dragging == 1 ) {
@ -873,16 +941,19 @@ function ondrag(x,y,but,cmd,shift,capslock,option,ctrl)
if ( drag _slot _lock ) {
if ( drag _slot _lock ) {
lock ( last _hovered , 1 ) ;
lock ( last _hovered , 1 ) ;
}
}
is _dragging = 0 ;
drag _slot = - 1 ;
paint _base ( ) ;
paint _base ( ) ;
outlet ( 0 , "drag" , drag _slot , last _hovered , offset ) ;
outlet ( 0 , "drag" , drag _slot , last _hovered , offset ) ;
set _active _slot ( last _hovered ) ;
set _active _slot ( last _hovered ) ;
is _dragging = 0 ;
trigger _writeagain ( ) ;
trigger _writeagain ( ) ;
} else {
} else { // Drag released but not somewhere we can throw a slot in
is _dragging = 0 ;
is _dragging = 0 ;
mgraphics . redraw ( ) ;
drag _slot = - 1 ;
paint _base ( ) ;
// mgraphics.redraw();
}
}
} else {
} else {