VERSIÓ 1.4.6
-[NEW] font.load() -[NEW] font.current() -[NEW] font.spacing() -[NEW] font.DEFAULT -[NEW] surf.SCREEN
This commit is contained in:
40
mini.cpp
40
mini.cpp
@@ -37,6 +37,7 @@ struct char_t {
|
||||
struct font_t {
|
||||
char *name {nullptr};
|
||||
uint8_t surface {0};
|
||||
uint8_t spacing {1};
|
||||
char_t chars[256];
|
||||
};
|
||||
|
||||
@@ -61,6 +62,7 @@ surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
|
||||
font_t fonts[MAX_FONTS];
|
||||
font_t *current_font;
|
||||
FILE *file = NULL;
|
||||
//uint8_t file_mode = 0;
|
||||
bool file_ignore_comma=true;
|
||||
@@ -416,7 +418,7 @@ void shader_init(const char* vshader, const char* fshader)
|
||||
void shader_enable() { shader::enable(); }
|
||||
void shader_disable() { shader::disable(); }
|
||||
|
||||
uint8_t loadfont_from_buffer(const char* buffer, uint8_t index) {
|
||||
uint8_t loadfont_from_buffer(const char* buffer, uint8_t index, const char* name) {
|
||||
if (!buffer) return false;
|
||||
|
||||
const char* ptr = buffer;
|
||||
@@ -435,6 +437,9 @@ uint8_t loadfont_from_buffer(const char* buffer, uint8_t index) {
|
||||
if (strncmp(line, "bitmap=", 7) != 0) return false; // Parse first line
|
||||
|
||||
fonts[index].surface = loadsurf(line + 7);
|
||||
|
||||
fonts[index].name = (char*)malloc(strlen(name)+1);
|
||||
strcpy(fonts[index].name, name);
|
||||
}
|
||||
|
||||
// --- Read character lines ---
|
||||
@@ -472,7 +477,7 @@ uint8_t loadfont(const char *filename) {
|
||||
|
||||
// Agafar la pròxima textura lliure
|
||||
unsigned int i = 0;
|
||||
while (i<MAX_FONTS && surfaces[i].p != NULL) ++i;
|
||||
while (i<MAX_FONTS && fonts[i].name != NULL) ++i;
|
||||
if (i==MAX_FONTS) return 255;
|
||||
|
||||
// Carregar l'arxiu de disc
|
||||
@@ -487,13 +492,30 @@ uint8_t loadfont(const char *filename) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
loadfont_from_buffer(buffer, i);
|
||||
loadfont_from_buffer(buffer, i, filename);
|
||||
free(buffer);
|
||||
|
||||
log_msg(LOG_INFO, "Arxiu '%s' carregat en font: %i.\n", filename, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
uint8_t getfont() {
|
||||
for (unsigned int i=0; i<MAX_FONTS; ++i) if (current_font == &fonts[i]) return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setfont(uint8_t font) {
|
||||
current_font = &fonts[font];
|
||||
}
|
||||
|
||||
uint8_t getfontspacing() {
|
||||
return current_font->spacing;
|
||||
}
|
||||
|
||||
void setfontspacing(uint8_t spacing) {
|
||||
current_font->spacing = spacing;
|
||||
}
|
||||
|
||||
void createDisplay() {
|
||||
if (screen_zoom <= 0) screen_zoom = 1;
|
||||
while (screen_width*screen_zoom > desktop_width || screen_height*screen_zoom > desktop_height) screen_zoom--;
|
||||
@@ -641,7 +663,8 @@ int main(int argc,char*argv[]){
|
||||
initaudio();
|
||||
|
||||
loadsurf(default_font_gif, "default_font");
|
||||
loadfont_from_buffer((const char*)default_font_fnt, 0);
|
||||
loadfont_from_buffer((const char*)default_font_fnt, 0, "default_font");
|
||||
current_font = &fonts[0];
|
||||
|
||||
lua_init(main_lua_file);
|
||||
lua_call_init();
|
||||
@@ -1041,7 +1064,7 @@ void old_print(const char *str, int x, int y, uint8_t color) {
|
||||
}
|
||||
|
||||
const uint8_t printchar(uint8_t c, int x, int y) {
|
||||
char_t &chr = fonts[0].chars[c];
|
||||
char_t &chr = current_font->chars[c];
|
||||
blit(chr.x, chr.y, chr.w, chr.h, x, y-chr.base);
|
||||
return chr.w;
|
||||
}
|
||||
@@ -1053,9 +1076,11 @@ void print(const char* str, int x, int y, uint8_t color) {
|
||||
uint8_t xpos = x;
|
||||
|
||||
uint8_t old_source = getsource();
|
||||
setsource(fonts[0].surface);
|
||||
setsource(current_font->surface);
|
||||
uint8_t old_color = ds::draw_palette[1];
|
||||
ds::draw_palette[1] = color;
|
||||
uint8_t old_trans = ds::trans;
|
||||
ds::trans = 0;
|
||||
while (p[0]!=0) {
|
||||
if (p[0] < 0x80) {
|
||||
cp = p[0];
|
||||
@@ -1064,8 +1089,9 @@ void print(const char* str, int x, int y, uint8_t color) {
|
||||
cp = (p[0] << 6) | (p[1] & 0x3F);
|
||||
p+=2;
|
||||
}
|
||||
xpos += printchar(cp, xpos, y) + 1;
|
||||
xpos += printchar(cp, xpos, y) + current_font->spacing;
|
||||
}
|
||||
ds::trans = old_trans;
|
||||
ds::draw_palette[1] = old_color;
|
||||
setsource(old_source);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user