add background image and slice

This commit is contained in:
John Alanbrook 2024-07-09 16:43:09 -05:00
parent d36ac1957f
commit 9626da4ff8
2 changed files with 18 additions and 12 deletions

View file

@ -23,6 +23,7 @@ mum.base = {
angle: 0, angle: 0,
anchor: [0,1], anchor: [0,1],
background_image: null, background_image: null,
slice: null,
hovered: {}, hovered: {},
text_shadow: { text_shadow: {
pos: [0,0], pos: [0,0],
@ -76,13 +77,13 @@ var listpost = function()
mum.list = function(fn, data = {}) mum.list = function(fn, data = {})
{ {
if (pre(data)) return; if (pre(data)) return;
cursor = context.pos; cursor = context.pos;
cursor = cursor.add(context.offset); cursor = cursor.add(context.offset);
posts.push(post); posts.push(post);
post = listpost; post = listpost;
fn(); fn();
post = posts.pop(); post = posts.pop();
end(); end();
} }
@ -92,15 +93,14 @@ mum.image = function(path, data = {})
if (pre(data)) return; if (pre(data)) return;
var tex = game.texture(path); var tex = game.texture(path);
context.bb = render.image(tex, cursor, context.size); if (context.slice)
render.slice9(tex, cursor, context.slice, context.size);
else
context.bb = render.image(tex, cursor, context.size);
end(); end();
} }
mum.slice9 = function(path, data = {})
{
}
var btnbb; var btnbb;
var btnpost = function() var btnpost = function()
{ {

View file

@ -527,10 +527,10 @@ render.text = function(str, pos, size = 1, color = Color.white, wrap = -1, ancho
return bb; return bb;
}; };
render.image = function(tex, pos, scale = 1, rotation = 0, color = Color.white, dimensions = [tex.width, tex.height]) { render.image = function(tex, pos, scale = [tex.width, tex.height], rotation = 0, color = Color.white) {
var t = os.make_transform(); var t = os.make_transform();
t.pos = pos; t.pos = pos;
t.scale = [scale,scale,scale]; t.scale = [scale.x/tex.width,scale.y/tex.height,1];
render.setpipeline(render.spriteshader.pipe); render.setpipeline(render.spriteshader.pipe);
render.setunim4(0, render.spriteshader.vs.unimap.model.slot, t); render.setunim4(0, render.spriteshader.vs.unimap.model.slot, t);
render.shader_apply_material(render.spriteshader, { render.shader_apply_material(render.spriteshader, {
@ -549,19 +549,25 @@ render.image = function(tex, pos, scale = 1, rotation = 0, color = Color.white,
return bb; return bb;
} }
render.slice9 = function(tex, pos, bb, scale = 1, color = Color.white) render.slice9 = function(tex, pos, bb, scale = [tex.width,tex.height], color = Color.white)
{ {
var t = os.make_transform(); var t = os.make_transform();
t.pos = pos; t.pos = pos;
t.scale = [scale,scale,scale]; t.scale = [scale.x/tex.width,scale.y/tex.height,1];
var border;
if (typeof bb === 'number')
border = [bb/tex.width,bb/tex.height,bb/tex.width,bb/tex.height];
else
border = [bb.l/tex.width, bb.b/tex.height, bb.r/tex.width, bb.t/tex.height];
render.setpipeline(slice9shader.pipe); render.setpipeline(slice9shader.pipe);
render.setunim4(0, slice9shader.vs.unimap.model.slot, t); render.setunim4(0, slice9shader.vs.unimap.model.slot, t);
render.shader_apply_material(slice9shader, { render.shader_apply_material(slice9shader, {
shade: color, shade: color,
diffuse:tex, diffuse:tex,
rect:[0,0,1,1], rect:[0,0,1,1],
border: [bb.l/tex.width, bb.b/tex.height, bb.r/tex.width, bb.t/tex.height], border: border,
scale: [scale,scale] scale: [scale.x/tex.width,scale.y/tex.height]
}); });
var bind = render.sg_bind(slice9shader, shape.quad, {diffuse:tex}); var bind = render.sg_bind(slice9shader, shape.quad, {diffuse:tex});
bind.inst = 1; bind.inst = 1;