Skip to content

Commit

Permalink
一些字体相关的函数
Browse files Browse the repository at this point in the history
  • Loading branch information
WheatBox committed Sep 19, 2023
1 parent 738bc58 commit 557a7a7
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 11 deletions.
107 changes: 107 additions & 0 deletions FxxkGML/FxxkGML/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,111 @@

namespace fgm {

bool font_exists(asset ind) {
__basic(__FuncId::font_exists, ind);
return g_funcres.m_real;
}

std::string font_get_name(asset ind) {
__basic(__FuncId::font_get_name, ind);
return g_funcres.m_string;
}

std::string font_get_fontname(asset ind) {
__basic(__FuncId::font_get_fontname, ind);
return g_funcres.m_string;
}

int font_get_first(asset ind) {
__basic(__FuncId::font_get_first, ind);
return g_funcres.m_real;
}

int font_get_last(asset ind) {
__basic(__FuncId::font_get_last, ind);
return g_funcres.m_real;
}

bool font_get_italic(asset ind) {
__basic(__FuncId::font_get_italic, ind);
return g_funcres.m_real;
}

bool font_get_bold(asset ind) {
__basic(__FuncId::font_get_bold, ind);
return g_funcres.m_real;
}

double font_get_size(asset ind) {
__basic(__FuncId::font_get_size, ind);
return g_funcres.m_real;
}

asset font_add(const std::string & name, double size, bool bold, bool italic, int first, int last) {
__basic(__FuncId::font_add, name, size, bold, italic, first, last);
return g_funcres.m_real;
}

asset font_add_sprite(asset spr, int first, bool prop, int sep) {
__basic(__FuncId::font_add_sprite, spr, first, prop, sep);
return g_funcres.m_real;
}

asset font_add_sprite_ext(asset spr, const std::string & string_map, bool prop, int sep) {
__basic(__FuncId::font_add_sprite_ext, spr, string_map, prop, sep);
return g_funcres.m_real;
}

void font_replace_sprite(asset ind, asset spr, int first, bool prop, int sep) {
__basic(__FuncId::font_replace_sprite, ind, spr, first, prop, sep);
}

void font_replace_sprite_ext(asset ind, asset spr, const std::string & string_map, bool prop, int sep) {
__basic(__FuncId::font_replace_sprite_ext, ind, spr, string_map, prop, sep);
}

void font_delete(asset ind) {
__basic(__FuncId::font_delete, ind);
}

int font_texture_page_size_get() {
__basic(__FuncId::font_texture_page_size_get);
return g_funcres.m_real;
}

void font_texture_page_size_set(int size) {
__basic(__FuncId::font_texture_page_size_set, size);
}

void font_set_cache_size(asset ind, int max) {
__basic(__FuncId::font_set_cache_size, ind, max);
}

void font_add_enable_aa(bool enable) {
__basic(__FuncId::font_add_enable_aa, enable);
}

bool font_add_get_enable_aa() {
__basic(__FuncId::font_add_get_enable_aa);
return g_funcres.m_real;
}

void font_enable_sdf(asset ind, bool enable) {
__basic(__FuncId::font_enable_sdf, ind, enable);
}

bool font_get_sdf_enabled(asset ind) {
__basic(__FuncId::font_get_sdf_enabled, ind);
return g_funcres.m_real;
}

void font_sdf_spread(asset ind, int spread) {
__basic(__FuncId::font_sdf_spread, ind, spread);
}

int font_get_sdf_spread(asset ind) {
__basic(__FuncId::font_get_sdf_spread, ind);
return g_funcres.m_real;
}

}
26 changes: 26 additions & 0 deletions FxxkGML/FxxkGML/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,30 @@

namespace fgm {

bool font_exists(asset ind);
std::string font_get_name(asset ind);
std::string font_get_fontname(asset ind);
int font_get_first(asset ind);
int font_get_last(asset ind);
bool font_get_italic(asset ind);
bool font_get_bold(asset ind);
double font_get_size(asset ind);

asset font_add(const std::string & name, double size, bool bold, bool italic, int first, int last);
asset font_add_sprite(asset spr, int first, bool prop, int sep);
asset font_add_sprite_ext(asset spr, const std::string & string_map, bool prop, int sep);
void font_replace_sprite(asset ind, asset spr, int first, bool prop, int sep);
void font_replace_sprite_ext(asset ind, asset spr, const std::string & string_map, bool prop, int sep);
void font_delete(asset ind);

int font_texture_page_size_get();
void font_texture_page_size_set(int size);
void font_set_cache_size(asset ind, int max);
void font_add_enable_aa(bool enable);
bool font_add_get_enable_aa();

void font_enable_sdf(asset ind, bool enable);
bool font_get_sdf_enabled(asset ind);
void font_sdf_spread(asset ind, int spread);
int font_get_sdf_spread(asset ind);
}
21 changes: 11 additions & 10 deletions FxxkGML/FxxkGML/funcid.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ namespace fgm {
font_get_italic = 8006,
font_get_bold = 8007,
font_get_size = 8008,
font_get_info = 8009,
// font_get_info = 8009, // TODO

// Texture
// TODO
Expand All @@ -546,18 +546,19 @@ namespace fgm {

// Configuration

font_texture_page_size = 8019,
font_set_cache_size = 8020,
font_add_enable_aa = 8021,
font_add_get_enable_aa = 8022,
font_texture_page_size_get = 8019,
font_texture_page_size_set = 8020,
font_set_cache_size = 8021,
font_add_enable_aa = 8022,
font_add_get_enable_aa = 8023,

// SDF

font_enable_sdf = 8023,
font_get_sdf_enabled = 8024,
font_sdf_spread = 8025,
font_get_sdf_spread = 8026,
font_enable_effects = 8027,
font_enable_sdf = 8024,
font_get_sdf_enabled = 8025,
font_sdf_spread = 8026,
font_get_sdf_spread = 8027,
// font_enable_effects = 8028, // TODO

};
}
Binary file modified FxxkGML_GM_Project/datafiles/a_nameless_button.dll
Binary file not shown.
Binary file modified FxxkGML_GM_Project/datafiles/game.dll
Binary file not shown.
96 changes: 96 additions & 0 deletions FxxkGML_GM_Project/scripts/FxxkGML_GM_API/FxxkGML_GM_API.gml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,52 @@ enum EFxxkGMLFuncId {
_sprite_flush = 7044,
// _sprite_flush_multi = 7045, // TODO

/* font.h 8000+ */

// Asset Info

_font_exists = 8001,
_font_get_name = 8002,
_font_get_fontname = 8003,
_font_get_first = 8004,
_font_get_last = 8005,
_font_get_italic = 8006,
_font_get_bold = 8007,
_font_get_size = 8008,
// _font_get_info = 8009, // TODO

// Texture
// TODO

// _font_get_texture = 8010,
// _font_get_uvs = 8011,
// _font_cache_glyph = 8012,

// Adding/Removing Fonts

_font_add = 8013,
_font_add_sprite = 8014,
_font_add_sprite_ext = 8015,
_font_replace_sprite = 8016,
_font_replace_sprite_ext = 8017,
_font_delete = 8018,

// Configuration

_font_texture_page_size_get = 8019,
_font_texture_page_size_set = 8020,
_font_set_cache_size = 8021,
_font_add_enable_aa = 8022,
_font_add_get_enable_aa = 8023,

// SDF

_font_enable_sdf = 8024,
_font_get_sdf_enabled = 8025,
_font_sdf_spread = 8026,
_font_get_sdf_spread = 8027,
// _font_enable_effects = 8028, TODO

};

#macro ARG external_call
Expand Down Expand Up @@ -1295,6 +1341,56 @@ function __FxxkGML_RunFunc() {
CASE EFxxkGMLFuncId._sprite_flush:
RET(__RetR, sprite_flush(ARG_R_0to0));
// CASE EFxxkGMLFuncId._sprite_flush_multi: // TODO

CASE EFxxkGMLFuncId._font_exists:
RET(__RetR, font_exists(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_get_name:
RET(__RetS, font_get_name(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_get_fontname:
RET(__RetS, font_get_fontname(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_get_first:
RET(__RetR, font_get_first(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_get_last:
RET(__RetR, font_get_last(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_get_italic:
RET(__RetR, font_get_italic(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_get_bold:
RET(__RetR, font_get_bold(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_get_size:
RET(__RetR, font_get_size(ARG_R_0to0));
// CASE EFxxkGMLFuncId._font_get_info: // TODO

CASE EFxxkGMLFuncId._font_add:
RET(__RetR, font_add(ARG(__S, 0), ARG(__R, 1), ARG(__R, 2), ARG(__R, 3), ARG(__R, 4), ARG(__R, 5)));
CASE EFxxkGMLFuncId._font_add_sprite:
RET(__RetR, font_add_sprite(ARG_R_0to3));
CASE EFxxkGMLFuncId._font_add_sprite_ext:
RET(__RetR, font_add_sprite_ext(ARG(__R, 0), ARG(__S, 1), ARG(__R, 2), ARG(__R, 3)));
CASE EFxxkGMLFuncId._font_replace_sprite:
font_replace_sprite(ARG_R_0to4);
CASE EFxxkGMLFuncId._font_replace_sprite_ext:
font_replace_sprite_ext(ARG(__R, 0), ARG(__R, 1), ARG(__S, 2), ARG(__R, 3), ARG(__R, 4));
CASE EFxxkGMLFuncId._font_delete:
font_delete(ARG_R_0to0);
CASE EFxxkGMLFuncId._font_texture_page_size_get:
RET(__RetR, font_texture_page_size);
CASE EFxxkGMLFuncId._font_texture_page_size_set:
font_texture_page_size = ARG(__R, 0);
CASE EFxxkGMLFuncId._font_set_cache_size:
font_set_cache_size(ARG_R_0to1);
CASE EFxxkGMLFuncId._font_add_enable_aa:
font_add_enable_aa(ARG_R_0to0);
CASE EFxxkGMLFuncId._font_add_get_enable_aa:
RET(__RetR, font_add_get_enable_aa());
CASE EFxxkGMLFuncId._font_enable_sdf:
font_enable_sdf(ARG_R_0to1);
CASE EFxxkGMLFuncId._font_get_sdf_enabled:
RET(__RetR, font_get_sdf_enabled(ARG_R_0to0));
CASE EFxxkGMLFuncId._font_sdf_spread:
font_sdf_spread(ARG_R_0to1);
CASE EFxxkGMLFuncId._font_get_sdf_spread:
RET(__RetR, font_get_sdf_spread(ARG_R_0to0));
// CASE EFxxkGMLFuncId._font_enable_effects: // TODO

}

Expand Down
2 changes: 1 addition & 1 deletion test/a_nameless_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void fgm_main() {
fgm::draw_set_color(fgm::c_black);
fgm::draw_roundrect_ext(button_area, 16, 16, false);
fgm::draw_set_color(fgm::c_white);
fgm::draw_text(button_area.left_top() + fgm::vec2(20, 6), "A Nameless Button");
fgm::draw_text(button_area.left_top() + fgm::vec2(20, 9), "A Nameless Button");

if(button_area.collision(fgm::mouse_pos_get())) {
fgm::draw_set_alpha(0.3);
Expand Down
3 changes: 3 additions & 0 deletions test/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ void fgm_init() {
fgm::randomize();
fgm::show_debug_overlay(true);

fgm::asset fnt_consolas = fgm::font_add("C:/Windows/Fonts/consola.ttf", 12, false, false, 0, 65535);
fgm::draw_set_font(fnt_consolas);

spr_test = fgm::sprite_add("spr_test.png", 1, false, false, 128, 256);
spr_block = fgm::asset_get_index("spr_block");
obj_test = fgm::asset_get_index("obj_test");
Expand Down

0 comments on commit 557a7a7

Please sign in to comment.