2024-07-09 01:03:39 -05:00
|
|
|
globalThis.mum = {};
|
2024-07-10 09:39:28 -05:00
|
|
|
|
2024-04-18 17:34:56 -05:00
|
|
|
var panel;
|
|
|
|
|
2024-07-09 13:48:15 -05:00
|
|
|
var selected = undefined;
|
|
|
|
|
|
|
|
mum.inputs = {};
|
|
|
|
mum.inputs.lm = function()
|
|
|
|
{
|
|
|
|
if (!selected) return;
|
2024-07-11 14:25:45 -05:00
|
|
|
if (!selected.action) return;
|
2024-07-09 13:48:15 -05:00
|
|
|
selected.action();
|
|
|
|
}
|
|
|
|
|
2024-07-09 01:03:39 -05:00
|
|
|
mum.base = {
|
|
|
|
padding:[0,0], /* Each element inset with this padding on all sides */
|
|
|
|
offset:[0,0],
|
|
|
|
pos: [0,0],
|
|
|
|
font: "fonts/c64.ttf",
|
|
|
|
selectable: false,
|
|
|
|
selected: false,
|
|
|
|
font_size: 16,
|
|
|
|
scale: 1,
|
|
|
|
angle: 0,
|
|
|
|
anchor: [0,1],
|
|
|
|
background_image: null,
|
2024-07-09 16:43:09 -05:00
|
|
|
slice: null,
|
2024-07-09 01:03:39 -05:00
|
|
|
hovered: {},
|
|
|
|
text_shadow: {
|
|
|
|
pos: [0,0],
|
|
|
|
color: Color.white,
|
|
|
|
},
|
|
|
|
text_outline: 1, /* outline in pixels */
|
2024-07-11 14:25:45 -05:00
|
|
|
text_align: "left", /* left, center, right */
|
|
|
|
text_shader: null,
|
2024-07-09 01:03:39 -05:00
|
|
|
color: Color.white,
|
|
|
|
margin: [0,0], /* Distance between elements for things like columns */
|
2024-07-10 09:39:28 -05:00
|
|
|
size: null,
|
2024-07-09 01:03:39 -05:00
|
|
|
max_width: Infinity,
|
|
|
|
max_height: Infinity,
|
|
|
|
image_repeat: false,
|
|
|
|
image_repeat_offset: [0,0],
|
|
|
|
debug: false, /* set to true to draw debug boxes */
|
|
|
|
hide: false,
|
2024-07-09 13:48:15 -05:00
|
|
|
tooltip: null,
|
2024-07-09 01:03:39 -05:00
|
|
|
}
|
|
|
|
|
2024-07-10 09:39:28 -05:00
|
|
|
mum.debug = false;
|
|
|
|
|
2024-07-09 01:03:39 -05:00
|
|
|
var post = function() {};
|
|
|
|
var posts = [];
|
|
|
|
|
|
|
|
var context = mum.base;
|
|
|
|
var contexts = [];
|
|
|
|
|
|
|
|
var cursor = [0,0];
|
|
|
|
|
|
|
|
var pre = function(data)
|
|
|
|
{
|
2024-07-10 09:39:28 -05:00
|
|
|
if (data.hide) return true;
|
|
|
|
data.__proto__ = mum.base;
|
|
|
|
if (context)
|
|
|
|
contexts.push(context);
|
|
|
|
|
2024-07-09 01:03:39 -05:00
|
|
|
context = data;
|
|
|
|
}
|
|
|
|
|
2024-07-10 09:39:28 -05:00
|
|
|
var end = function()
|
2024-07-09 13:48:15 -05:00
|
|
|
{
|
2024-07-10 09:39:28 -05:00
|
|
|
var old = context;
|
|
|
|
context = contexts.pop();
|
|
|
|
post(old);
|
2024-07-09 13:48:15 -05:00
|
|
|
}
|
|
|
|
|
2024-07-09 01:03:39 -05:00
|
|
|
mum.list = function(fn, data = {})
|
|
|
|
{
|
|
|
|
if (pre(data)) return;
|
|
|
|
cursor = context.pos;
|
|
|
|
cursor = cursor.add(context.offset);
|
|
|
|
posts.push(post);
|
2024-07-10 09:39:28 -05:00
|
|
|
post = mum.list.post;
|
2024-07-09 01:03:39 -05:00
|
|
|
|
|
|
|
fn();
|
2024-07-10 09:39:28 -05:00
|
|
|
|
|
|
|
context.bb.l -= context.padding.x;
|
|
|
|
context.bb.r += context.padding.x;
|
|
|
|
context.bb.t += context.padding.y;
|
|
|
|
context.bb.b -= context.padding.y;
|
|
|
|
|
|
|
|
if (mum.debug)
|
|
|
|
render.boundingbox(context.bb);
|
|
|
|
|
2024-07-09 01:03:39 -05:00
|
|
|
post = posts.pop();
|
|
|
|
end();
|
|
|
|
}
|
|
|
|
|
2024-07-10 09:39:28 -05:00
|
|
|
mum.list.post = function(e)
|
|
|
|
{
|
|
|
|
cursor.y -= (e.bb.t - e.bb.b);
|
|
|
|
cursor.y -= e.padding.y;
|
|
|
|
|
|
|
|
if (context.bb)
|
|
|
|
context.bb = bbox.expand(context.bb,e.bb)
|
|
|
|
else
|
|
|
|
context.bb = e.bb;
|
|
|
|
}
|
|
|
|
|
|
|
|
mum.label = function(str, data = {})
|
|
|
|
{
|
|
|
|
if (pre(data)) return;
|
|
|
|
|
|
|
|
render.set_font(context.font, context.font_size);
|
|
|
|
|
|
|
|
context.bb = render.text_bb(str, context.scale, -1, cursor);
|
|
|
|
|
|
|
|
if (mum.debug)
|
|
|
|
render.boundingbox(context.bb);
|
|
|
|
|
|
|
|
if (bbox.pointin(context.bb, input.mouse.screenpos())) {
|
|
|
|
if (context.hover) {
|
|
|
|
context.hover.__proto__ = context;
|
|
|
|
context = context.hover;
|
|
|
|
selected = context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context.bb = render.text(str, cursor, context.scale, context.color);
|
|
|
|
|
|
|
|
end();
|
|
|
|
}
|
|
|
|
|
2024-07-09 01:03:39 -05:00
|
|
|
mum.image = function(path, data = {})
|
|
|
|
{
|
|
|
|
if (pre(data)) return;
|
|
|
|
|
|
|
|
var tex = game.texture(path);
|
2024-07-09 16:43:09 -05:00
|
|
|
if (context.slice)
|
2024-07-10 09:39:28 -05:00
|
|
|
render.slice9(tex, cursor, context.slice, context.scale);
|
2024-07-09 16:43:09 -05:00
|
|
|
else
|
2024-07-10 09:39:28 -05:00
|
|
|
context.bb = render.image(tex, cursor, context.scale);
|
2024-07-09 01:03:39 -05:00
|
|
|
|
|
|
|
end();
|
|
|
|
}
|
|
|
|
|
2024-07-09 13:48:15 -05:00
|
|
|
var btnbb;
|
|
|
|
var btnpost = function()
|
|
|
|
{
|
|
|
|
btnbb = context.bb;
|
|
|
|
}
|
|
|
|
|
|
|
|
mum.button = function(str, data = {padding:[4,4], color:Color.black, hover:{color:Color.red}})
|
2024-04-18 17:34:56 -05:00
|
|
|
{
|
2024-07-09 01:03:39 -05:00
|
|
|
if (pre(data)) return;
|
2024-07-09 13:48:15 -05:00
|
|
|
posts.push(post);
|
|
|
|
post = btnpost;
|
|
|
|
if (typeof str === 'string')
|
2024-07-10 09:39:28 -05:00
|
|
|
render.text(str, cursor.add(context.padding), context.scale, context.color);
|
2024-07-09 13:48:15 -05:00
|
|
|
else
|
|
|
|
str();
|
|
|
|
|
|
|
|
if (data.hover && bbox.pointin(btnbb, input.mouse.screenpos())) {
|
|
|
|
data.hover.__proto__ = data;
|
|
|
|
context = data.hover;
|
|
|
|
}
|
|
|
|
render.rectangle([btnbb.l-context.padding.x, btnbb.b-context.padding.y], [btnbb.r+context.padding.y, btnbb.t+context.padding.y], context.color);
|
|
|
|
context.bb = btnbb;
|
|
|
|
|
|
|
|
post = posts.pop();
|
|
|
|
end();
|
|
|
|
}
|
|
|
|
|
|
|
|
mum.window = function(fn, data = {})
|
|
|
|
{
|
|
|
|
data = Object.assign({
|
2024-07-10 09:39:28 -05:00
|
|
|
size:[400,400],
|
2024-07-09 13:48:15 -05:00
|
|
|
color: Color.black
|
|
|
|
}, data);
|
|
|
|
|
|
|
|
if (pre(data)) return;
|
|
|
|
|
|
|
|
cursor = context.pos;
|
2024-07-10 09:39:28 -05:00
|
|
|
render.rectangle(cursor, cursor.add(context.size), context.color);
|
2024-07-09 13:48:15 -05:00
|
|
|
cursor.y += context.height;
|
|
|
|
cursor = cursor.add(context.padding);
|
|
|
|
context.pos = cursor.slice();
|
|
|
|
fn();
|
2024-07-09 01:03:39 -05:00
|
|
|
end();
|
2024-04-18 17:34:56 -05:00
|
|
|
}
|
|
|
|
|
2024-07-09 13:48:15 -05:00
|
|
|
mum.div = function(fn, data = {})
|
|
|
|
{
|
|
|
|
if (pre(data)) return;
|
|
|
|
fn();
|
|
|
|
end();
|
|
|
|
}
|