@ -82,6 +82,7 @@ var bg_width, bg_height = 0;
var mg = new MGraphics ( ui _width , ui _height ) ;
var mg = new MGraphics ( ui _width , ui _height ) ;
var base _drawing ;
var base _drawing ;
var is _painting _base = 0 ;
var half _slot _size , half _margin , half _spacing ;
var half _slot _size , half _margin , half _spacing ;
var last _x , last _y , last _hovered = - 1 ;
var last _x , last _y , last _hovered = - 1 ;
@ -167,21 +168,16 @@ function draw_slot(id, scale, cont) {
var offset = slot _size * ( 1 - scale ) ;
var offset = slot _size * ( 1 - scale ) ;
if ( is _painting _base ) {
draw _slot _bubble ( slots [ id ] [ 0 ] * scale , slots [ id ] [ 1 ] * scale , slot _size * scale , slot _size * scale , cont ) ;
} else {
draw _slot _bubble ( slots [ id ] [ 0 ] + offset , slots [ id ] [ 1 ] + offset , slot _size * scale , slot _size * scale , cont ) ;
draw _slot _bubble ( slots [ id ] [ 0 ] + offset , slots [ id ] [ 1 ] + offset , slot _size * scale , slot _size * scale , cont ) ;
}
cont . fill ( ) ;
cont . fill ( ) ;
if ( layout == 1 ) {
if ( layout == 1 ) {
// // Slot number
// var nb = i.toString();
// var nb_dim = text_measure(nb);
// 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 ;
// set_source_rgba(text_color);
// move_to(nb_pos_x, nb_pos_y);
// show_text(nb);
// slot text background
// slot text background
var bg _txt _pos _x = margin + slot _size + spacing ;
var bg _txt _pos _x = margin + slot _size + spacing ;
var bg _txt _pos _y = slots [ id ] [ 1 ] ;
var bg _txt _pos _y = slots [ id ] [ 1 ] ;
@ -193,36 +189,17 @@ 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);
// slot name
// slot name
cont . set _font _size ( font _size * scale ) ;
var text = format _slot _name ( id ) ;
var text = format _slot _name ( id ) ;
draw _text _bubble ( bg _txt _pos _x , bg _txt _pos _y , bg _txt _dim _w , bg _txt _dim _h , text , cont ) ;
if ( is _painting _base ) {
// cont.fill();
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 ) ;
// // 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());
} 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 ) ;
}
}
}
}
}
@ -243,23 +220,13 @@ draw_slot_bubble.local = 1;
function draw _text _bubble ( x , y , w , h , text , cont ) {
function draw _text _bubble ( x , y , w , h , text , cont ) {
cont = typeof cont !== 'undefined' ? cont : mgraphics ;
cont = typeof cont !== 'undefined' ? cont : mgraphics ;
// slot text background
// 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 . rectangle _rounded ( x , y , w , h , 4 , 4 ) ;
cont . fill ( ) ;
cont . fill ( ) ;
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 = x + spacing ;
var txt _pos _y = y + ( h - spacing + text _dim [ 1 ] ) / 2 ;
var txt _pos _y = y + ( text _dim [ 1 ] + h ) / 2 - text _dim [ 1 ] * 0.18 ;
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 ) ;
@ -283,14 +250,15 @@ format_slot_name.local = 1;
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
is _painting _base = 1 ;
// Background
// Background
bg _width = layout == 0 ? columns * ( slot _size + spacing ) - spacing + 2 * margin : ui _width ;
bg _width = layout == 0 ? columns * ( slot _size + spacing ) - spacing + 2 * margin : ui _width ;
bg _height = rows * ( slot _size + spacing ) - spacing + 2 * margin ;
bg _height = rows * ( slot _size + spacing ) - spacing + 2 * margin ;
mg = new MGraphics ( ui _width , bg _height ) ;
mg = new MGraphics ( ui _width * 2 , bg _height * 2 ) ;
with ( mg ) {
with ( mg ) {
set _source _rgba ( background _color ) ;
set _source _rgba ( background _color ) ;
rectangle ( 0 , 0 , bg _width , bg _height ) ;
rectangle ( 0 , 0 , bg _width * 2 , bg _height * 2 ) ;
fill ( ) ;
fill ( ) ;
select _font _face ( font _name ) ;
select _font _face ( font _name ) ;
@ -304,10 +272,11 @@ function paint_base() {
} else {
} else {
set _source _rgba ( empty _slot _color ) ;
set _source _rgba ( empty _slot _color ) ;
}
}
draw _slot ( i , 1 , mg ) ;
draw _slot ( i , 2 , mg ) ;
}
}
}
}
}
}
is _painting _base = 0 ;
update _umenu ( ) ;
update _umenu ( ) ;
base _drawing = new Image ( mg ) ;
base _drawing = new Image ( mg ) ;
mgraphics . redraw ( ) ;
mgraphics . redraw ( ) ;
@ -318,9 +287,15 @@ function paint()
{
{
// post("redraw\n");
// post("redraw\n");
with ( mgraphics ) {
with ( mgraphics ) {
select _font _face ( font _name ) ;
set _font _size ( font _size ) ;
translate ( 0 , y _offset ) ;
translate ( 0 , y _offset ) ;
// Draw the base, which includes empty and filled slots
// 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 ) ;
image _surface _draw ( base _drawing ) ;
scale ( 2 , 2 ) ;
set _line _width ( 1 ) ;
set _line _width ( 1 ) ;
@ -376,8 +351,6 @@ function paint()
if ( layout == 0 ) {
if ( layout == 0 ) {
//Text (slot number and name)
//Text (slot number and name)
var text = format _slot _name ( last _hovered ) ;
var text = format _slot _name ( last _hovered ) ;
select _font _face ( font _name ) ;
set _font _size ( font _size ) ;
var text _dim = text _measure ( text ) ;
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.
// 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.
// Otherwise, it gets displayed on the hovered slot.
@ -414,9 +387,8 @@ function paint()
translate ( last _x , last _y ) ;
translate ( last _x , last _y ) ;
rotate ( 0.15 ) ;
rotate ( 0.15 ) ;
scale ( 1.1 , 1.1 ) ;
scale ( 1.1 , 1.1 ) ;
// scale(3, 3);
// Shadow
// Slot s hadow
set _source _rgba ( 0 , 0 , 0 , 0.15 ) ;
set _source _rgba ( 0 , 0 , 0 , 0.15 ) ;
for ( var i = 0 ; i < 4 ; i ++ ) {
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 ) ;
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 ) ;
@ -424,6 +396,8 @@ function paint()
}
}
draw _slot _bubble ( 2 - slot _size / 2 , 2 - slot _size / 2 , slot _size , slot _size ) ;
draw _slot _bubble ( 2 - slot _size / 2 , 2 - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
fill ( ) ;
//Flying slot
set _source _rgba ( active _slot _color ) ;
set _source _rgba ( active _slot _color ) ;
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
fill ( ) ;
@ -435,15 +409,7 @@ function paint()
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
draw _slot _bubble ( - slot _size / 2 , - slot _size / 2 , slot _size , slot _size ) ;
fill ( ) ;
fill ( ) ;
// slot name
// slot name
var text = drag _slot ;
var text = format _slot _name ( 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 _x = slot _size / 2 + spacing ;
var bg _txt _pos _y = - slot _size / 2 ;
var bg _txt _pos _y = - slot _size / 2 ;
var bg _txt _dim _w = ui _width - ( 2 * margin + slot _size + spacing ) ;
var bg _txt _dim _w = ui _width - ( 2 * margin + slot _size + spacing ) ;