Editor: redesign visual no Material 3 (Roboto, Material Symbols, cores de sempre)
- Fontes em assets/fonts (Roboto Regular/Medium, Material Symbols contorno e preenchido; Apache 2.0). TB_DRAW_TEXT escolhe a fonte pelo param (tb_draw_text_font, TB_FONT_*); backend SDL2 com cache por familia e DejaVu de reserva. Pacotes AppImage/Android/Windows levam as fontes. - tb_editor_m3.h: papeis de cor do M3 sobre a paleta do editor, formas, tipografia, camadas de estado, elevacao, icones e componentes (botoes, icon button, menu, campo, dialogo, chip, snackbar, switch). - Top app bar, abas primarias, navigation rail das categorias, FAB de extensoes, palco, saida, menus, snackbars, dialogos, explorador, Bibliotecas, Configuracoes, previa scratchblocks, editores de codigo e de imagem no estilo M3. - Widgets: icon, text_f e shadow. Backend: TINYBLOCKS_SHOT salva a janela (conferir o visual); editor: TINYBLOCKS_OPEN abre uma tela no inicio. - Console: linhas roladas continuam na arvore acessivel (OFFSCREEN). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f180eaf75a
commit
0cb2019704
22 files changed
+1451
-516
No files matched your search
@@ -79,7 +79,7 @@ static void eval_handle_noop(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
#define FONT_CACHE_CAP 64 /* o zoom da area de scripts pede muitos tamanhos */
|
||||
#define FONT_SEARCH_COUNT 9
|
||||
|
||||
typedef struct { int size; TTF_Font* font; unsigned used; } FontEntry;
|
||||
typedef struct { int size, family; TTF_Font* font; unsigned used; } FontEntry;
|
||||
|
||||
static FontEntry s_font_cache[FONT_CACHE_CAP];
|
||||
static int s_font_cache_n = 0;
|
||||
@@ -96,8 +96,37 @@ static const char* s_font_paths[FONT_SEARCH_COUNT] = {
|
||||
"C:/Windows/Fonts/arial.ttf",
|
||||
};
|
||||
|
||||
/* A fonte que vai junto do programa (pacote Windows, AppImage):
|
||||
<pasta do executavel>/fonts/DejaVuSans.ttf */
|
||||
/* Fontes que vao junto do programa (TB_FONT_*): Roboto e Material Symbols.
|
||||
Procura em $TINYBLOCKS_APPDIR/fonts (AppImage, Android), <pasta do
|
||||
executavel>/fonts (pacote Windows) e <pasta do executavel>/../assets/fonts
|
||||
(rodando da arvore: build/editor). DejaVu fica de reserva para o texto. */
|
||||
static const char* s_family_files[TB_FONT_COUNT] = {
|
||||
"Roboto-Regular.ttf", "Roboto-Medium.ttf",
|
||||
"MaterialSymbolsOutlined.ttf", "MaterialSymbolsFilled.ttf",
|
||||
};
|
||||
|
||||
static TTF_Font* open_in(const char* dir, const char* sub, const char* file, int size) {
|
||||
char path[1200];
|
||||
snprintf(path, sizeof(path), "%s%s%s", dir, sub, file);
|
||||
return TTF_OpenFont(path, size);
|
||||
}
|
||||
|
||||
static TTF_Font* family_font(int family, int size) {
|
||||
const char* file = s_family_files[family];
|
||||
TTF_Font* f = NULL;
|
||||
const char* dir = getenv("TINYBLOCKS_APPDIR");
|
||||
if (dir && dir[0]) f = open_in(dir, "/fonts/", file, size);
|
||||
char* base = f ? NULL : SDL_GetBasePath();
|
||||
if (base) {
|
||||
f = open_in(base, "fonts/", file, size);
|
||||
if (!f) f = open_in(base, "../assets/fonts/", file, size);
|
||||
SDL_free(base);
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
if (!f) f = open_in("", "fonts/", file, size); /* assets do APK */
|
||||
#endif
|
||||
return f;
|
||||
}
|
||||
static TTF_Font* bundled_font(int size) {
|
||||
char path[1024];
|
||||
const char* dir = getenv("TINYBLOCKS_APPDIR");
|
||||
@@ -113,16 +142,24 @@ static TTF_Font* bundled_font(int size) {
|
||||
return TTF_OpenFont(path, size);
|
||||
}
|
||||
|
||||
static TTF_Font* get_font(int size) {
|
||||
static TTF_Font* get_font(int size, int family) {
|
||||
static unsigned tick = 0;
|
||||
tick++;
|
||||
if (family < 0 || family >= TB_FONT_COUNT) family = TB_FONT_REGULAR;
|
||||
for (int i = 0; i < s_font_cache_n; i++)
|
||||
if (s_font_cache[i].size == size) { s_font_cache[i].used = tick; return s_font_cache[i].font; }
|
||||
if (s_font_cache[i].size == size && s_font_cache[i].family == family) {
|
||||
s_font_cache[i].used = tick;
|
||||
return s_font_cache[i].font;
|
||||
}
|
||||
|
||||
TTF_Font* f = bundled_font(size);
|
||||
for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++)
|
||||
f = TTF_OpenFont(s_font_paths[i], size);
|
||||
if (!f) return NULL;
|
||||
TTF_Font* f = family_font(family, size);
|
||||
if (!f && family == TB_FONT_MEDIUM) f = family_font(TB_FONT_REGULAR, size);
|
||||
if (!f && family <= TB_FONT_MEDIUM) { /* sem Roboto: DejaVu */
|
||||
f = bundled_font(size);
|
||||
for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++)
|
||||
f = TTF_OpenFont(s_font_paths[i], size);
|
||||
}
|
||||
if (!f) return NULL; /* sem icones: nada */
|
||||
|
||||
/* cheio: fecha o usado ha mais tempo (antes vazava uma fonte por chamada) */
|
||||
int slot = s_font_cache_n;
|
||||
@@ -133,6 +170,7 @@ static TTF_Font* get_font(int size) {
|
||||
TTF_CloseFont(s_font_cache[slot].font);
|
||||
} else s_font_cache_n++;
|
||||
s_font_cache[slot].size = size;
|
||||
s_font_cache[slot].family = family;
|
||||
s_font_cache[slot].font = f;
|
||||
s_font_cache[slot].used = tick;
|
||||
return f;
|
||||
@@ -330,7 +368,8 @@ static void sdl2_execute(SDL_Renderer* ren,
|
||||
scaled = *cmd;
|
||||
scaled.x *= s_ui_scale; scaled.y *= s_ui_scale;
|
||||
scaled.w *= s_ui_scale; scaled.h *= s_ui_scale;
|
||||
scaled.param *= s_ui_scale; scaled.font_size *= s_ui_scale;
|
||||
if (cmd->kind != TB_DRAW_TEXT) scaled.param *= s_ui_scale; /* no texto e a fonte */
|
||||
scaled.font_size *= s_ui_scale;
|
||||
cmd = &scaled;
|
||||
}
|
||||
switch (cmd->kind) {
|
||||
@@ -429,7 +468,7 @@ static void sdl2_execute(SDL_Renderer* ren,
|
||||
|
||||
case TB_DRAW_TEXT:
|
||||
if (cmd->text[0]) {
|
||||
TTF_Font* font = get_font((int)(cmd->font_size + 0.5f));
|
||||
TTF_Font* font = get_font((int)(cmd->font_size + 0.5f), (int)cmd->param);
|
||||
if (font) {
|
||||
SDL_Color col = {
|
||||
(Uint8)(cmd->r*255.f), (Uint8)(cmd->g*255.f),
|
||||
@@ -866,18 +905,42 @@ static char* be_clipboard_get(void) {
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Captura para conferir o visual sem olhar a tela de ninguem:
|
||||
TINYBLOCKS_SHOT=arquivo.bmp salva a 1a janela depois de
|
||||
TINYBLOCKS_SHOT_FRAMES quadros (padrao 30) e sai. */
|
||||
static void shot_check(SdlWin* w) {
|
||||
static int frames = 0;
|
||||
static bool done = false;
|
||||
const char* path = getenv("TINYBLOCKS_SHOT");
|
||||
if (done || !path || !path[0]) return;
|
||||
SdlWin* first = s_wins;
|
||||
while (first && first->next) first = first->next; /* a lista e LIFO */
|
||||
if (w != first) return;
|
||||
const char* fe = getenv("TINYBLOCKS_SHOT_FRAMES");
|
||||
if (++frames < (fe && atoi(fe) > 0 ? atoi(fe) : 30)) return;
|
||||
done = true;
|
||||
int pw = 0, ph = 0;
|
||||
SDL_GetRendererOutputSize(w->ren, &pw, &ph);
|
||||
SDL_Surface* s = SDL_CreateRGBSurfaceWithFormat(0, pw, ph, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
if (s && SDL_RenderReadPixels(w->ren, NULL, SDL_PIXELFORMAT_ARGB8888, s->pixels, s->pitch) == 0)
|
||||
SDL_SaveBMP(s, path);
|
||||
if (s) SDL_FreeSurface(s);
|
||||
exit(0); /* so para conferir: sai em seguida */
|
||||
}
|
||||
|
||||
static void be_window_present(void* handle, const TinyBlocks_RenderableBlock* rb) {
|
||||
SdlWin* w = (SdlWin*)handle;
|
||||
SDL_SetRenderDrawColor(w->ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(w->ren);
|
||||
if (rb) sdl2_execute(w->ren, rb);
|
||||
shot_check(w);
|
||||
SDL_RenderPresent(w->ren);
|
||||
}
|
||||
|
||||
static float be_measure_text(const char* text, float font_size) {
|
||||
if (!be_init()) return 0.f;
|
||||
const float S = s_ui_scale > 0.f ? s_ui_scale : 1.f;
|
||||
TTF_Font* font = get_font((int)(font_size * S + 0.5f));
|
||||
TTF_Font* font = get_font((int)(font_size * S + 0.5f), TB_FONT_REGULAR);
|
||||
int w = 0, h = 0;
|
||||
if (!font || TTF_SizeUTF8(font, text, &w, &h) != 0) return 0.f;
|
||||
return (float)w / S; /* largura em unidades logicas */
|
||||
|
||||
Reference in new issue
Block a user