Pixel-Composer/scripts/font_sprite_loader/font_sprite_loader.gml

47 lines
1.1 KiB
Text
Raw Normal View History

2023-01-17 08:11:55 +01:00
globalvar FONT_INTERNAL, FONT_SPRITES;
FONT_SPRITES = ds_map_create();
#region font refresh
function loadFontSprite(path) {
if(ds_map_exists(FONT_SPRITES, path)) return;
var f = _font_add(path, 32);
2024-06-25 08:44:08 +02:00
if(!font_exists(f)) return;
2023-01-17 08:11:55 +01:00
draw_set_text(f, fa_left, fa_top, c_white);
var name = "ABCabc123";
2024-06-25 08:44:08 +02:00
var ww = max(1, string_width(name));
var hh = max(1, string_height(name));
2023-01-17 08:11:55 +01:00
var s = surface_create(ww, hh);
surface_set_target(s);
2023-03-19 09:17:39 +01:00
DRAW_CLEAR
2023-01-17 08:11:55 +01:00
draw_text(0, 0, name);
surface_reset_target();
var spr = sprite_create_from_surface(s, 0, 0, ww, hh, false, false, 0, 0);
surface_free(s);
2023-07-05 15:09:52 +02:00
font_delete(f);
2023-01-17 08:11:55 +01:00
FONT_SPRITES[? path] = spr;
}
function refreshFontFolder() {
FONT_INTERNAL = [];
var root = DIRECTORY + "Fonts/*";
var f = file_find_first(root, -1);
var filter = [ ".ttf", ".otf" ];
2023-07-05 15:09:52 +02:00
2023-01-17 08:11:55 +01:00
while(f != "") {
var fullname = DIRECTORY + "Fonts/" + f;
var ext = filename_ext(fullname);
if(array_exists(filter, string_lower(ext))) {
array_push(FONT_INTERNAL, f);
loadFontSprite(fullname);
}
f = file_find_next();
}
2023-07-05 15:09:52 +02:00
2023-01-17 08:11:55 +01:00
file_find_close();
}
#endregion