mum work
This commit is contained in:
parent
2f8827fd78
commit
fb88641883
|
@ -41,6 +41,7 @@ function keycode(name) { return charCodeAt(name); }
|
|||
function keyname_extd(key)
|
||||
{
|
||||
if (typeof key === 'string') return key;
|
||||
|
||||
if (key > 289 && key < 302) {
|
||||
var num = key-289;
|
||||
return `f${num}`;
|
||||
|
|
|
@ -13,16 +13,17 @@ mum.inputs.lm = function()
|
|||
}
|
||||
|
||||
mum.base = {
|
||||
padding:[0,0], /* Each element inset with this padding on all sides */
|
||||
offset:[0,0],
|
||||
pos: null,
|
||||
pos: null, // If set, puts the cursor to this position before drawing the element
|
||||
offset:[0,0], // Move x,y to the right and down before drawing
|
||||
padding:[0,0], // Pad inwards after drawing, to prepare for the next element
|
||||
font: "fonts/c64.ttf",
|
||||
selectable: false,
|
||||
selected: false,
|
||||
font_size: 16,
|
||||
scale: 1,
|
||||
angle: 0,
|
||||
anchor: [0,1], // where to draw the item from, relative to the cursor.
|
||||
inset: null,
|
||||
anchor: [0,1], // where to draw the item from, relative to the cursor. [0,1] is from the top left corner. [1,0] is from the bottom right
|
||||
background_image: null,
|
||||
slice: null,
|
||||
hover: {
|
||||
|
@ -32,13 +33,13 @@ mum.base = {
|
|||
pos: [0,0],
|
||||
color: Color.white,
|
||||
},
|
||||
text_outline: 1, /* outline in pixels */
|
||||
border: 0, // Draw a border around the element. For text, an outline.
|
||||
overflow: "wrap", // how to deal with overflow from parent element
|
||||
wrap: -1,
|
||||
text_align: "left", /* left, center, right */
|
||||
text_shader: null,
|
||||
overflow: "wrap", // clip, wrap, break
|
||||
shader: null, // Use this shader, instead of the engine provided one
|
||||
color: Color.white,
|
||||
margin: [0,0], /* Distance between elements for things like columns */
|
||||
size: null,
|
||||
opacity:1,
|
||||
width:0,
|
||||
height:0,
|
||||
max_width: Infinity,
|
||||
|
@ -57,37 +58,50 @@ mum.debug = false;
|
|||
var post = function() {};
|
||||
var posts = [];
|
||||
|
||||
mum.style = mum.base;
|
||||
|
||||
var context = mum.style;
|
||||
var context = mum.base;
|
||||
var container = undefined;
|
||||
var contexts = [];
|
||||
|
||||
var cursor = [0,0];
|
||||
|
||||
mum._frame = function()
|
||||
{
|
||||
cursor = [0,0];
|
||||
}
|
||||
|
||||
var pre = function(data)
|
||||
{
|
||||
if (data.hide) return true;
|
||||
data.__proto__ = mum.style;
|
||||
data.__proto__ = mum.base;
|
||||
if (context)
|
||||
contexts.push(context);
|
||||
|
||||
context = data;
|
||||
if (context.pos) cursor = context.pos.slice();
|
||||
context.drawpos = cursor.slice().add(context.offset);
|
||||
}
|
||||
|
||||
var end = function()
|
||||
{
|
||||
var old = context;
|
||||
context = contexts.pop();
|
||||
cursor = cursor.add(old.padding);
|
||||
post(old);
|
||||
}
|
||||
|
||||
mum.style = function(fn, data)
|
||||
{
|
||||
var oldbase = mum.base;
|
||||
data.__proto__ = mum.base;
|
||||
mum.base = data;
|
||||
fn();
|
||||
mum.base = oldbase;
|
||||
}
|
||||
|
||||
mum.list = function(fn, data = {})
|
||||
{
|
||||
if (pre(data)) return;
|
||||
var aa = [0,1].sub(context.anchor);
|
||||
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);
|
||||
|
@ -101,8 +115,6 @@ mum.list = function(fn, data = {})
|
|||
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();
|
||||
|
@ -151,11 +163,10 @@ mum.label = function(str, data = {})
|
|||
|
||||
var aa = [0,1].sub(context.anchor);
|
||||
|
||||
var pos = cursor.slice();
|
||||
pos.y -= (context.bb.t-cursor.y);
|
||||
pos = pos.add(context.wh.scale(aa)).add(context.offset);
|
||||
data.drawpos.y -= (context.bb.t-cursor.y);
|
||||
data.drawpos = data.drawpos.add(context.wh.scale(aa)).add(context.offset);
|
||||
|
||||
context.bb = render.text_bb(str, context.scale, -1, pos);
|
||||
context.bb = render.text_bb(str, context.scale, data.wrap, data.drawpos);
|
||||
|
||||
if (context.action && bbox.pointin(context.bb, input.mouse.screenpos())) {
|
||||
if (context.hover) {
|
||||
|
@ -165,7 +176,7 @@ mum.label = function(str, data = {})
|
|||
}
|
||||
}
|
||||
|
||||
context.bb = render.text(str, pos, context.scale, context.color);
|
||||
context.bb = render.text(str, data.drawpos, context.scale, context.color, data.wrap);
|
||||
|
||||
if (show_debug())
|
||||
render.boundingbox(context.bb);
|
||||
|
@ -180,12 +191,18 @@ mum.image = function(path, data = {})
|
|||
var tex = path;
|
||||
if (typeof path === 'string')
|
||||
tex = game.texture(path);
|
||||
|
||||
data.width ??= tex.width;
|
||||
data.height ??= tex.height;
|
||||
|
||||
var aa = [0,0].sub(data.anchor);
|
||||
data.drawpos = data.drawpos.add(aa.scale([data.width,data.height]));
|
||||
|
||||
if (context.slice)
|
||||
render.slice9(tex, cursor, context.slice, context.scale);
|
||||
render.slice9(tex, data.drawpos, context.slice, [data.width,data.height]);
|
||||
else {
|
||||
cursor.y -= tex.height*context.scale;
|
||||
context.bb = render.image(tex, cursor, [context.scale*tex.width, context.scale*tex.height]);
|
||||
context.bb = render.image(tex, data.drawpos, [context.scale*tex.width, context.scale*tex.height]);
|
||||
}
|
||||
|
||||
end();
|
||||
|
@ -220,17 +237,11 @@ mum.button = function(str, data = {padding:[4,4], color:Color.black})
|
|||
|
||||
mum.window = function(fn, data = {})
|
||||
{
|
||||
data = Object.assign({
|
||||
size:[400,400],
|
||||
color: Color.black
|
||||
}, data);
|
||||
|
||||
if (pre(data)) return;
|
||||
|
||||
render.rectangle(cursor, cursor.add(context.size), context.color);
|
||||
cursor.y += context.height;
|
||||
cursor = cursor.add(context.padding);
|
||||
context.pos = cursor.slice();
|
||||
fn();
|
||||
end();
|
||||
}
|
||||
|
|
|
@ -607,6 +607,8 @@ render.image = function(tex, pos, scale = [tex.width, tex.height], rotation = 0,
|
|||
return bb;
|
||||
}
|
||||
|
||||
|
||||
// pos is the lower left corner, scale is the width and height
|
||||
render.slice9 = function(tex, pos, bb, scale = [tex.width,tex.height], color = Color.white)
|
||||
{
|
||||
var t = os.make_transform();
|
||||
|
|
|
@ -58,9 +58,9 @@ void mesh_add_material(primitive *prim, cgltf_material *mat)
|
|||
cgltf_buffer_view *buf = img->buffer_view;
|
||||
pmat->diffuse = texture_fromdata(buf->buffer->data, buf->size);
|
||||
} else {
|
||||
char *path = makepath(dirname(cpath), img->uri);
|
||||
pmat->diffuse = texture_from_file(path);
|
||||
free(path);
|
||||
// char *path = makepath(dirname(cpath), img->uri);
|
||||
// pmat->diffuse = texture_from_file(path);
|
||||
// free(path);
|
||||
}
|
||||
} else
|
||||
pmat->diffuse = texture_from_file("icons/moon.gif");
|
||||
|
|
|
@ -126,17 +126,6 @@ char *dirname(const char *path)
|
|||
return dir;
|
||||
}
|
||||
|
||||
char *makepath(char *dir, char *file)
|
||||
{
|
||||
int d = strlen(dir) + strlen(file) + 2;
|
||||
char *path = malloc(d);
|
||||
path[0] = 0;
|
||||
strncat(path, dir, d);
|
||||
strncat(path, "/", d);
|
||||
strncat(path, file, d);
|
||||
return path;
|
||||
}
|
||||
|
||||
char *seprint(char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
|
|
@ -12,7 +12,6 @@ extern int LOADED_GAME;
|
|||
void resources_init();
|
||||
char *get_filename_from_path(char *path, int extension);
|
||||
char *dirname(const char *path);
|
||||
char *makepath(char *dir, char *file);
|
||||
char *str_replace_ext(const char *s, const char *newext);
|
||||
FILE *res_open(char *path, const char *tag);
|
||||
char **ls(const char *path);
|
||||
|
|
Loading…
Reference in a new issue