This commit is contained in:
John Alanbrook 2024-07-14 16:09:50 -05:00
parent 805c9298e6
commit 2f8827fd78
4 changed files with 79 additions and 13 deletions

View file

@ -1447,6 +1447,15 @@ bbox.pointin = function(bb, p)
return true; return true;
} }
bbox.zero = function(bb) {
var newbb = Object.assign({},bb);
newbb.r -= newbb.l;
newbb.t -= newbb.b;
newbb.b = 0;
newbb.l = 0;
return newbb;
}
bbox.move = function(bb, pos) { bbox.move = function(bb, pos) {
var newbb = Object.assign({}, bb); var newbb = Object.assign({}, bb);
newbb.t += pos.y; newbb.t += pos.y;
@ -1456,6 +1465,11 @@ bbox.move = function(bb, pos) {
return newbb; return newbb;
}; };
bbox.moveto = function(bb, pos) {
bb = bbox.zero(bb);
return bbox.move(bb, pos);
}
bbox.expand = function(oldbb, x) { bbox.expand = function(oldbb, x) {
if (!oldbb || !x) return; if (!oldbb || !x) return;
var bb = {}; var bb = {};

View file

@ -52,10 +52,8 @@ debug.draw = function() {
function assert(op, str = `assertion failed [value '${op}']`) function assert(op, str = `assertion failed [value '${op}']`)
{ {
if (!op) { if (!op)
console.error(str); console.panic(str);
os.quit();
}
} }
var Gizmos = { var Gizmos = {

View file

@ -22,7 +22,7 @@ mum.base = {
font_size: 16, font_size: 16,
scale: 1, scale: 1,
angle: 0, angle: 0,
anchor: [0,1], // where to draw the item from. anchor: [0,1], // where to draw the item from, relative to the cursor.
background_image: null, background_image: null,
slice: null, slice: null,
hover: { hover: {
@ -35,9 +35,12 @@ mum.base = {
text_outline: 1, /* outline in pixels */ text_outline: 1, /* outline in pixels */
text_align: "left", /* left, center, right */ text_align: "left", /* left, center, right */
text_shader: null, text_shader: null,
overflow: "wrap", // clip, wrap, break
color: Color.white, color: Color.white,
margin: [0,0], /* Distance between elements for things like columns */ margin: [0,0], /* Distance between elements for things like columns */
size: null, size: null,
width:0,
height:0,
max_width: Infinity, max_width: Infinity,
max_height: Infinity, max_height: Infinity,
image_repeat: false, image_repeat: false,
@ -57,6 +60,7 @@ var posts = [];
mum.style = mum.base; mum.style = mum.base;
var context = mum.style; var context = mum.style;
var container = undefined;
var contexts = []; var contexts = [];
var cursor = [0,0]; var cursor = [0,0];
@ -82,11 +86,35 @@ var end = function()
mum.list = function(fn, data = {}) mum.list = function(fn, data = {})
{ {
if (pre(data)) return; if (pre(data)) return;
cursor = context.pos; var aa = [0,1].sub(context.anchor);
cursor = cursor.add(context.offset); if (context.pos) cursor = context.pos.slice();
cursor = cursor.add([context.width,context.height].scale(aa)).add(context.offset).add(context.padding);
posts.push(post); posts.push(post);
post = mum.list.post; post = mum.list.post;
if (show_debug())
render.boundingbox({
t:cursor.y,
b:cursor.y-context.height,
l:cursor.x,
r:cursor.x+context.width
});
cursor.x += context.width/2;
//if (context.background_image) mum.image(null, Object.create(context))
if (context.background_image) {
var imgpos = context.pos.slice();
imgpos.y -= context.height/2;
imgpos.x -= context.width/2;
var imgscale = [context.width,context.height];
if (context.slice)
render.slice9(game.texture(context.background_image), imgpos, context.slice, imgscale);
else
render.image(game.texture(context.background_image), imgpos, [context.width,context.height]);
}
fn(); fn();
context.bb.l -= context.padding.x; context.bb.l -= context.padding.x;
@ -119,9 +147,15 @@ mum.label = function(str, data = {})
render.set_font(context.font, context.font_size); render.set_font(context.font, context.font_size);
context.bb = render.text_bb(str, context.scale, -1, cursor); context.bb = render.text_bb(str, context.scale, -1, cursor);
context.wh = bbox.towh(context.bb);
if (show_debug()) var aa = [0,1].sub(context.anchor);
render.boundingbox(context.bb);
var pos = cursor.slice();
pos.y -= (context.bb.t-cursor.y);
pos = pos.add(context.wh.scale(aa)).add(context.offset);
context.bb = render.text_bb(str, context.scale, -1, pos);
if (context.action && bbox.pointin(context.bb, input.mouse.screenpos())) { if (context.action && bbox.pointin(context.bb, input.mouse.screenpos())) {
if (context.hover) { if (context.hover) {
@ -131,7 +165,10 @@ mum.label = function(str, data = {})
} }
} }
context.bb = render.text(str, cursor, context.scale, context.color); context.bb = render.text(str, pos, context.scale, context.color);
if (show_debug())
render.boundingbox(context.bb);
end(); end();
} }
@ -139,6 +176,7 @@ mum.label = function(str, data = {})
mum.image = function(path, data = {}) mum.image = function(path, data = {})
{ {
if (pre(data)) return; if (pre(data)) return;
path ??= context.background_image;
var tex = path; var tex = path;
if (typeof path === 'string') if (typeof path === 'string')
tex = game.texture(path); tex = game.texture(path);
@ -196,3 +234,11 @@ mum.window = function(fn, data = {})
fn(); fn();
end(); end();
} }
mum.ex_hud = function()
{
mum.label("TOP LEFT", {pos:[0,game.size.y], anchor:[0,1]});
mum.label("BOTTOM LEFT", {pos:[0,0], anchor:[0,0]});
mum.label("TOP RIGHT", {pos:game.size, anchor:[1,1]});
mum.label("BOTTOM RIGHT", {pos:[game.size.x, 0], anchor:[1,0]});
}

View file

@ -156,6 +156,13 @@ function global_uni(uni, stage)
return false; return false;
} }
var setcam = render.set_camera;
render.set_camera = function(cam)
{
delete cur.shader;
setcam(cam);
}
render.make_shader = function(shader) render.make_shader = function(shader)
{ {
var file = shader; var file = shader;
@ -586,7 +593,8 @@ render.image = function(tex, pos, scale = [tex.width, tex.height], rotation = 0,
render.set_model(t); render.set_model(t);
render.use_mat({ render.use_mat({
shade: color, shade: color,
diffuse: tex diffuse: tex,
rect:[0,0,1,1]
}); });
render.draw(shape.quad); render.draw(shape.quad);