(Canvi d'ordenador)
- [WIP] Treballant en les fonts
This commit is contained in:
130
default.fnt
Normal file
130
default.fnt
Normal file
@@ -0,0 +1,130 @@
|
||||
bitmap=font.gif
|
||||
32: 0 0 3 5 0 #
|
||||
33: 4 0 3 5 0 # !
|
||||
34: 8 0 3 5 0 # "
|
||||
35: 12 0 3 5 0 # #
|
||||
36: 16 0 3 5 0 # $
|
||||
37: 20 0 3 5 0 # %
|
||||
38: 24 0 3 5 0 # &
|
||||
39: 28 0 3 5 0 # '
|
||||
40: 32 0 3 5 0 # (
|
||||
41: 36 0 3 5 0 # )
|
||||
42: 40 0 3 5 0 # *
|
||||
43: 44 0 3 5 0 # +
|
||||
44: 48 0 3 5 0 # ,
|
||||
45: 52 0 3 5 0 # -
|
||||
46: 56 0 3 5 0 # .
|
||||
47: 60 0 3 5 0 # /
|
||||
|
||||
48: 0 6 3 5 0 # 0
|
||||
49: 4 6 3 5 0 # 1
|
||||
50: 8 6 3 5 0 # 2
|
||||
51: 12 6 3 5 0 # 3
|
||||
52: 16 6 3 5 0 # 4
|
||||
53: 20 6 3 5 0 # 5
|
||||
54: 24 6 3 5 0 # 6
|
||||
55: 28 6 3 5 0 # 7
|
||||
56: 32 6 3 5 0 # 8
|
||||
57: 36 6 3 5 0 # 9
|
||||
58: 40 6 3 5 0 # :
|
||||
59: 44 6 3 5 0 # ;
|
||||
60: 48 6 3 5 0 # <
|
||||
61: 52 6 3 5 0 # =
|
||||
62: 56 6 3 5 0 # >
|
||||
63: 60 6 3 5 0 # ?
|
||||
|
||||
64: 0 12 3 5 0 # @
|
||||
65: 4 12 3 5 0 # A
|
||||
66: 8 12 3 5 0 # B
|
||||
67: 12 12 3 5 0 # C
|
||||
68: 16 12 3 5 0 # D
|
||||
69: 20 12 3 5 0 # E
|
||||
70: 24 12 3 5 0 # F
|
||||
71: 28 12 3 5 0 # G
|
||||
72: 32 12 3 5 0 # H
|
||||
73: 36 12 3 5 0 # I
|
||||
74: 40 12 3 5 0 # J
|
||||
75: 44 12 3 5 0 # K
|
||||
76: 48 12 3 5 0 # L
|
||||
77: 52 12 3 5 0 # M
|
||||
78: 56 12 3 5 0 # N
|
||||
79: 60 12 3 5 0 # O
|
||||
|
||||
80: 0 18 3 5 0 # P
|
||||
81: 4 18 3 5 0 # Q
|
||||
82: 8 18 3 5 0 # R
|
||||
83: 12 18 3 5 0 # S
|
||||
84: 16 18 3 5 0 # T
|
||||
85: 20 18 3 5 0 # U
|
||||
86: 24 18 3 5 0 # V
|
||||
87: 28 18 3 5 0 # W
|
||||
88: 32 18 3 5 0 # X
|
||||
89: 36 18 3 5 0 # Y
|
||||
90: 40 18 3 5 0 # Z
|
||||
91: 44 18 3 5 0 # [
|
||||
92: 48 18 3 5 0 # \
|
||||
93: 52 18 3 5 0 # ]
|
||||
94: 56 18 3 5 0 # ^
|
||||
95: 60 18 3 5 0 # _
|
||||
|
||||
96: 0 24 3 5 0 # `
|
||||
97: 4 24 3 5 0 # a
|
||||
98: 8 24 3 5 0 # b
|
||||
99: 12 24 3 5 0 # c
|
||||
100: 16 24 3 5 0 # d
|
||||
101: 20 24 3 5 0 # e
|
||||
102: 24 24 3 5 0 # f
|
||||
103: 28 24 3 5 0 # g
|
||||
104: 32 24 3 5 0 # h
|
||||
105: 36 24 3 5 0 # i
|
||||
106: 40 24 3 5 0 # j
|
||||
107: 44 24 3 5 0 # k
|
||||
108: 48 24 3 5 0 # l
|
||||
109: 52 24 3 5 0 # m
|
||||
110: 56 24 3 5 0 # n
|
||||
111: 60 24 3 5 0 # o
|
||||
|
||||
112: 0 30 3 5 0 # p
|
||||
113: 4 30 3 5 0 # q
|
||||
114: 8 30 3 5 0 # r
|
||||
115: 12 30 3 5 0 # s
|
||||
116: 16 30 3 5 0 # t
|
||||
117: 20 30 3 5 0 # u
|
||||
118: 24 30 3 5 0 # v
|
||||
119: 28 30 3 5 0 # w
|
||||
120: 32 30 3 5 0 # x
|
||||
121: 36 30 3 5 0 # y
|
||||
122: 40 30 3 5 0 # z
|
||||
123: 44 30 3 5 0 # {
|
||||
124: 48 30 3 5 0 # |
|
||||
125: 52 30 3 5 0 # }
|
||||
126: 56 30 3 5 0 # ~
|
||||
127: 60 30 3 5 0 # ⌂ (DEL placeholder)
|
||||
|
||||
# Extended characters
|
||||
161: 0 36 3 5 0 # ¡
|
||||
191: 4 36 3 5 0 # ¿
|
||||
192: 8 36 3 8 3 # À
|
||||
193: 12 36 3 8 3 # Á
|
||||
200: 16 36 3 8 3 # È
|
||||
201: 20 36 3 8 3 # É
|
||||
204: 24 36 3 8 3 # Ì
|
||||
205: 28 36 3 8 3 # Í
|
||||
210: 32 36 3 8 3 # Ò
|
||||
211: 36 36 3 8 3 # Ó
|
||||
217: 40 36 3 8 3 # Ù
|
||||
218: 44 36 3 8 3 # Ú
|
||||
209: 48 36 3 7 2 # Ñ
|
||||
241: 52 36 3 6 1 # ñ
|
||||
199: 56 36 3 5 0 # Ç
|
||||
231: 60 36 3 5 0 # ç
|
||||
224: 0 45 3 7 2 # à
|
||||
225: 4 45 3 7 2 # á
|
||||
232: 8 45 3 7 2 # è
|
||||
233: 12 45 3 7 2 # é
|
||||
236: 16 45 3 7 2 # ì
|
||||
237: 20 45 3 7 2 # í
|
||||
242: 24 45 3 7 2 # ò
|
||||
243: 28 45 3 7 2 # ó
|
||||
249: 32 45 3 7 2 # ù
|
||||
250: 36 45 3 7 2 # ú
|
||||
107
mini.cpp
107
mini.cpp
@@ -10,6 +10,7 @@
|
||||
#include "log.h"
|
||||
|
||||
#define MAX_SURFACES 100
|
||||
#define MAX_FONTS 5
|
||||
|
||||
#ifdef MACOS_BUNDLE
|
||||
#include <libgen.h>
|
||||
@@ -26,11 +27,14 @@ struct surface_t {
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
struct char_t {
|
||||
uint8_t x,y,w,h,base;
|
||||
};
|
||||
|
||||
struct font_t {
|
||||
struct special_char_t { uint8_t character; SDL_Rect glyph; SDL_Point displacement; };
|
||||
int8_t spacing;
|
||||
SDL_Rect characters[96];
|
||||
special_char_t specials[64];
|
||||
char *name {nullptr};
|
||||
uint8_t surface {0};
|
||||
char_t chars[256];
|
||||
};
|
||||
|
||||
int fps=0;
|
||||
@@ -53,6 +57,7 @@ surface_t *dest_surface = screen_surface;
|
||||
surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
|
||||
font_t fonts[MAX_FONTS];
|
||||
FILE *file = NULL;
|
||||
//uint8_t file_mode = 0;
|
||||
bool file_ignore_comma=true;
|
||||
@@ -274,6 +279,20 @@ uint8_t newsurf(int w, int h) {
|
||||
return i;
|
||||
}
|
||||
|
||||
uint8_t loadsurf(uint8_t* buffer, const char* name) {
|
||||
// Agafar la pròxima textura lliure
|
||||
unsigned int i = 0;
|
||||
while (i<MAX_SURFACES && surfaces[i].p != NULL) ++i;
|
||||
if (i==MAX_SURFACES) return 255;
|
||||
|
||||
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
|
||||
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||
surfaces[i].name = (char*)malloc(strlen(name)+1);
|
||||
strcpy(surfaces[i].name, name);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
uint8_t loadsurf(const char* filename, const bool external) {
|
||||
// Si el gif ja s'ha carregat en una textura, tornem eixa textura
|
||||
for (unsigned int i=0; i<MAX_SURFACES; ++i)
|
||||
@@ -658,6 +677,86 @@ int main(int argc,char*argv[]){
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool loadfont_from_buffer(const char* buffer, font_t& font) {
|
||||
if (!buffer) return false;
|
||||
|
||||
const char* ptr = buffer;
|
||||
char line[256];
|
||||
|
||||
// --- Read first line ---
|
||||
{
|
||||
// Extract line
|
||||
int len = 0;
|
||||
while (ptr[len] && ptr[len] != '\n' && len < 255) len++;
|
||||
|
||||
memcpy(line, ptr, len);
|
||||
line[len] = '\0';
|
||||
ptr += (ptr[len] == '\n') ? len + 1 : len; // Advance pointer
|
||||
|
||||
if (strncmp(line, "bitmap=", 7) != 0) return false; // Parse first line
|
||||
|
||||
font.surface = loadsurf(line + 7);
|
||||
}
|
||||
|
||||
// --- Read character lines ---
|
||||
while (*ptr) {
|
||||
// Extract next line
|
||||
int len = 0;
|
||||
while (ptr[len] && ptr[len] != '\n' && len < 255) len++;
|
||||
|
||||
memcpy(line, ptr, len);
|
||||
line[len] = '\0';
|
||||
ptr += (ptr[len] == '\n') ? len + 1 : len; // Advance pointer
|
||||
|
||||
// Remove comments
|
||||
char* hash = strchr(line, '#');
|
||||
if (hash) *hash = '\0';
|
||||
|
||||
// Parse
|
||||
int code, x, y, w, h, base;
|
||||
if (sscanf(line, "%d: %d %d %d %d %d", &code, &x, &y, &w, &h, &base) == 6) {
|
||||
if (code >= 0 && code < 256) {
|
||||
font.chars[code] = { (uint8_t)x, (uint8_t)y, (uint8_t)w, (uint8_t)h, (uint8_t)base };
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline uint32_t utf8_decode(const char* s, int& advance) {
|
||||
const unsigned char* p = (const unsigned char*)s;
|
||||
uint32_t cp;
|
||||
|
||||
if (p[0] < 0x80) {
|
||||
cp = p[0];
|
||||
advance = 1;
|
||||
}
|
||||
else if ((p[0] & 0xE0) == 0xC0) {
|
||||
cp = ((p[0] & 0x1F) << 6) |
|
||||
(p[1] & 0x3F);
|
||||
advance = 2;
|
||||
}
|
||||
else if ((p[0] & 0xF0) == 0xE0) {
|
||||
cp = ((p[0] & 0x0F) << 12) |
|
||||
((p[1] & 0x3F) << 6) |
|
||||
(p[2] & 0x3F);
|
||||
advance = 3;
|
||||
}
|
||||
else if ((p[0] & 0xF8) == 0xF0) {
|
||||
cp = ((p[0] & 0x07) << 18) |
|
||||
((p[1] & 0x3F) << 12) |
|
||||
((p[2] & 0x3F) << 6) |
|
||||
(p[3] & 0x3F);
|
||||
advance = 4;
|
||||
}
|
||||
else {
|
||||
cp = 0xFFFD; // carácter inválido
|
||||
advance = 1;
|
||||
}
|
||||
|
||||
return cp;
|
||||
}
|
||||
|
||||
void simple_pset(int x, int y, uint8_t color) {
|
||||
x += ds::origin[0]; y += ds::origin[1];
|
||||
if (x < ds::clip[0] || x > ds::clip[2] || y < ds::clip[1] || y > ds::clip[3]) return;
|
||||
|
||||
Reference in New Issue
Block a user