font string pulling
This commit is contained in:
parent
14deabf2dd
commit
f1b2984f61
|
@ -139,6 +139,7 @@ json.doc = {
|
||||||
Resources.scripts = ["jsoc", "jsc", "jso", "js"];
|
Resources.scripts = ["jsoc", "jsc", "jso", "js"];
|
||||||
Resources.images = ["qoi", "png", "gif", "jpg", "jpeg"];
|
Resources.images = ["qoi", "png", "gif", "jpg", "jpeg"];
|
||||||
Resources.sounds = ["wav", "flac", "mp3", "qoa"];
|
Resources.sounds = ["wav", "flac", "mp3", "qoa"];
|
||||||
|
Resources.fonts = ["ttf"];
|
||||||
Resources.is_image = function (path) {
|
Resources.is_image = function (path) {
|
||||||
var ext = path.ext();
|
var ext = path.ext();
|
||||||
return Resources.images.some(x => x === ext);
|
return Resources.images.some(x => x === ext);
|
||||||
|
@ -204,6 +205,10 @@ Resources.find_script = function (file, root = "") {
|
||||||
return find_ext(file, Resources.scripts, root);
|
return find_ext(file, Resources.scripts, root);
|
||||||
}.hashify();
|
}.hashify();
|
||||||
|
|
||||||
|
Resources.find_font = function(file, root = "") {
|
||||||
|
return find_ext(file, Resources.fonts, root);
|
||||||
|
}.hashify();
|
||||||
|
|
||||||
console.transcript = "";
|
console.transcript = "";
|
||||||
console.say = function (msg) {
|
console.say = function (msg) {
|
||||||
msg += "\n";
|
msg += "\n";
|
||||||
|
|
|
@ -162,7 +162,6 @@ game.startengine = 0;
|
||||||
|
|
||||||
prosperon.release_mode = function () {
|
prosperon.release_mode = function () {
|
||||||
prosperon.debug = false;
|
prosperon.debug = false;
|
||||||
mum.debug = false;
|
|
||||||
debug.kill();
|
debug.kill();
|
||||||
};
|
};
|
||||||
prosperon.debug = true;
|
prosperon.debug = true;
|
||||||
|
|
|
@ -903,12 +903,23 @@ render.window = function render_window(pos, wh, color) {
|
||||||
};
|
};
|
||||||
|
|
||||||
render.text = function (str, pos, font = cur_font, size = 0, color = Color.white, wrap = -1) {
|
render.text = function (str, pos, font = cur_font, size = 0, color = Color.white, wrap = -1) {
|
||||||
|
if (typeof font === 'string')
|
||||||
|
font = render.get_font(font);
|
||||||
|
|
||||||
if (!font) return;
|
if (!font) return;
|
||||||
gui.text(str, pos, size, color, wrap, font); // this puts text into buffer
|
gui.text(str, pos, size, color, wrap, font); // this puts text into buffer
|
||||||
cur_font = font;
|
cur_font = font;
|
||||||
check_flush(render.flush_text);
|
check_flush(render.flush_text);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var tttsize = render.text_size;
|
||||||
|
render.text_size = function(str, font)
|
||||||
|
{
|
||||||
|
if (typeof font === 'string')
|
||||||
|
font = render.get_font(font);
|
||||||
|
return tttsize(str,font);
|
||||||
|
}
|
||||||
|
|
||||||
var lasttex = undefined;
|
var lasttex = undefined;
|
||||||
var img_cache = [];
|
var img_cache = [];
|
||||||
var img_idx = 0;
|
var img_idx = 0;
|
||||||
|
@ -1108,7 +1119,13 @@ var fontcache = {};
|
||||||
|
|
||||||
render.get_font = function(path,size)
|
render.get_font = function(path,size)
|
||||||
{
|
{
|
||||||
var fontstr = `${path}-${size}`;
|
var parts = path.split('.');
|
||||||
|
if (!isNaN(parts[1])) {
|
||||||
|
path = parts[0];
|
||||||
|
size = Number(parts[1]);
|
||||||
|
}
|
||||||
|
path = Resources.find_font(path);
|
||||||
|
var fontstr = `${path}.${size}`;
|
||||||
if (!fontcache[fontstr]) fontcache[fontstr] = os.make_font(path,size);
|
if (!fontcache[fontstr]) fontcache[fontstr] = os.make_font(path,size);
|
||||||
return fontcache[fontstr];
|
return fontcache[fontstr];
|
||||||
}
|
}
|
||||||
|
@ -1360,7 +1377,8 @@ prosperon.render = function () {
|
||||||
prosperon.postvals.diffuse = prosperon.screencolor;
|
prosperon.postvals.diffuse = prosperon.screencolor;
|
||||||
|
|
||||||
render.use_mat(prosperon.postvals);
|
render.use_mat(prosperon.postvals);
|
||||||
render.draw((os.backend() === "directx" || os.backend() === 'metal') ? shape.flipquad : shape.quad);
|
render.draw(shape.quad);
|
||||||
|
//render.draw((os.backend() === "directx" || os.backend() === 'metal') ? shape.flipquad : shape.quad);
|
||||||
|
|
||||||
profile.endreport("post process");
|
profile.endreport("post process");
|
||||||
|
|
||||||
|
@ -1372,13 +1390,8 @@ prosperon.render = function () {
|
||||||
|
|
||||||
render.set_camera(prosperon.appcam);
|
render.set_camera(prosperon.appcam);
|
||||||
render.viewport(...prosperon.appcam.view());
|
render.viewport(...prosperon.appcam.view());
|
||||||
|
|
||||||
// Call gui functions
|
// Call gui functions
|
||||||
mum.style = mum.dbg_style;
|
|
||||||
if (render.draw_gui) prosperon.gui();
|
if (render.draw_gui) prosperon.gui();
|
||||||
if (mum.drawinput) mum.drawinput();
|
|
||||||
render.flush_text();
|
|
||||||
mum.style = mum.base;
|
|
||||||
|
|
||||||
check_flush();
|
check_flush();
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,6 @@ struct sFont *MakeFont(const char *fontfile, int height) {
|
||||||
newfont->descent = descent*emscale;
|
newfont->descent = descent*emscale;
|
||||||
newfont->linegap = linegap*emscale;
|
newfont->linegap = linegap*emscale;
|
||||||
|
|
||||||
printf("ascent %g descent %g linegap %g\n", newfont->ascent, newfont->descent, newfont->linegap);
|
|
||||||
|
|
||||||
newfont->texture = malloc(sizeof(texture));
|
newfont->texture = malloc(sizeof(texture));
|
||||||
newfont->texture->id = sg_make_image(&(sg_image_desc){
|
newfont->texture->id = sg_make_image(&(sg_image_desc){
|
||||||
.type = SG_IMAGETYPE_2D,
|
.type = SG_IMAGETYPE_2D,
|
||||||
|
|
|
@ -826,6 +826,16 @@ JSC_CCALL(render_camera_screen2world,
|
||||||
return vec42js(HMM_MulM4V4(view, p));
|
return vec42js(HMM_MulM4V4(view, p));
|
||||||
)
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(render_set_projection,
|
||||||
|
globalview.p = camera2projection(argv[0]);
|
||||||
|
globalview.vp = HMM_MulM4(globalview.p, globalview.v);
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(render_set_view,
|
||||||
|
globalview.v = transform2view(js2transform(argv[0]));
|
||||||
|
globalview.vp = HMM_MulM4(globalview.p, globalview.v);
|
||||||
|
)
|
||||||
|
|
||||||
JSC_CCALL(render_set_camera,
|
JSC_CCALL(render_set_camera,
|
||||||
JSValue cam = argv[0];
|
JSValue cam = argv[0];
|
||||||
globalview.p = camera2projection(argv[0]);
|
globalview.p = camera2projection(argv[0]);
|
||||||
|
@ -1271,6 +1281,8 @@ static const JSCFunctionListEntry js_render_funcs[] = {
|
||||||
MIST_FUNC_DEF(render, glue_pass, 0),
|
MIST_FUNC_DEF(render, glue_pass, 0),
|
||||||
MIST_FUNC_DEF(render, text_size, 5),
|
MIST_FUNC_DEF(render, text_size, 5),
|
||||||
MIST_FUNC_DEF(render, set_camera, 1),
|
MIST_FUNC_DEF(render, set_camera, 1),
|
||||||
|
MIST_FUNC_DEF(render, set_projection, 1),
|
||||||
|
MIST_FUNC_DEF(render, set_view, 1),
|
||||||
MIST_FUNC_DEF(render, make_pipeline, 1),
|
MIST_FUNC_DEF(render, make_pipeline, 1),
|
||||||
MIST_FUNC_DEF(render, setuniv3, 2),
|
MIST_FUNC_DEF(render, setuniv3, 2),
|
||||||
MIST_FUNC_DEF(render, setuniv, 2),
|
MIST_FUNC_DEF(render, setuniv, 2),
|
||||||
|
|
Loading…
Reference in a new issue