Imagens no palco por nome/número, paleta recarregável e slider de zoom
- Core: armazém de imagens nomeadas (tb_image_store_*) e tb_stage_image* para desenhar imagens no palco pelo nome ou pelo número. - Caneta: blocos "desenhe imagem nome/número". - tinyblocks-api: tb_api_load_named/tb_api_find_library e mtime em ns; o editor carrega as libraries de categoria como .so quando existem, para a paleta recarregar ao vivo. - Aba de imagem: slider de zoom no rodapé no lugar dos botões -/+. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b6bc65062
commit
adf5d2cd12
11 files changed
+378
-32
No files matched your search
@@ -2,6 +2,7 @@
|
||||
* TinyBlocks - tb_image.c
|
||||
* TinyBlocks_Image: buffer de pixels ref-counted com 1, 3 ou 4 canais.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
@@ -152,6 +153,85 @@ bool tb_image_save(const TinyBlocks_Image* img, const char* path) {
|
||||
return (f && f->enc) ? f->enc(img, path) : false;
|
||||
}
|
||||
|
||||
/* == Armazem de imagens nomeadas ========================================
|
||||
* Cada imagem carregada ganha um NOME (nome do arquivo, com e sem extensao)
|
||||
* e um NUMERO (ordem de entrada). Os blocos "desenhe imagem nome/numero"
|
||||
* usam isto para achar a imagem depois. */
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
TinyBlocks_Image* img;
|
||||
} TbStoredImage;
|
||||
|
||||
static TbStoredImage s_store[TB_IMAGE_STORE_MAX];
|
||||
static int s_store_n = 0;
|
||||
|
||||
static const char* store_base(const char* p) {
|
||||
const char* b = strrchr(p, '/');
|
||||
return b ? b + 1 : p;
|
||||
}
|
||||
|
||||
int tb_image_store_put(const char* name, TinyBlocks_Image* img) {
|
||||
if (!img) return 0;
|
||||
const char* nm = (name && name[0]) ? name : "imagem";
|
||||
for (int i = 0; i < s_store_n; i++) {
|
||||
if (strcmp(s_store[i].name, nm) == 0) {
|
||||
tb_image_release(s_store[i].img);
|
||||
tb_image_retain(img);
|
||||
s_store[i].img = img;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
if (s_store_n >= TB_IMAGE_STORE_MAX) return 0;
|
||||
TbStoredImage* e = &s_store[s_store_n];
|
||||
memset(e, 0, sizeof(*e));
|
||||
snprintf(e->name, sizeof(e->name), "%s", nm);
|
||||
tb_image_retain(img);
|
||||
e->img = img;
|
||||
s_store_n++;
|
||||
return s_store_n;
|
||||
}
|
||||
|
||||
TinyBlocks_Image* tb_image_store_get(const char* name) {
|
||||
if (!name || !name[0]) return NULL;
|
||||
for (int i = 0; i < s_store_n; i++)
|
||||
if (strcmp(s_store[i].name, name) == 0) return s_store[i].img;
|
||||
/* aceita com/sem extensao e com caminho */
|
||||
const char* base = store_base(name);
|
||||
char stem[64];
|
||||
snprintf(stem, sizeof(stem), "%s", base);
|
||||
char* dot = strrchr(stem, '.');
|
||||
if (dot && dot != stem) *dot = 0;
|
||||
for (int i = 0; i < s_store_n; i++) {
|
||||
char s2[64];
|
||||
snprintf(s2, sizeof(s2), "%s", s_store[i].name);
|
||||
char* d2 = strrchr(s2, '.');
|
||||
if (d2 && d2 != s2) *d2 = 0;
|
||||
if (strcmp(s_store[i].name, base) == 0 || strcmp(s2, base) == 0 ||
|
||||
strcmp(s_store[i].name, stem) == 0 || strcmp(s2, stem) == 0)
|
||||
return s_store[i].img;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TinyBlocks_Image* tb_image_store_at(int number) {
|
||||
if (number < 1 || number > s_store_n) return NULL;
|
||||
return s_store[number - 1].img;
|
||||
}
|
||||
|
||||
int tb_image_store_count(void) { return s_store_n; }
|
||||
|
||||
const char* tb_image_store_name(int number) {
|
||||
if (number < 1 || number > s_store_n) return "";
|
||||
return s_store[number - 1].name;
|
||||
}
|
||||
|
||||
void tb_image_store_clear(void) {
|
||||
for (int i = 0; i < s_store_n; i++) tb_image_release(s_store[i].img);
|
||||
memset(s_store, 0, sizeof(s_store));
|
||||
s_store_n = 0;
|
||||
}
|
||||
|
||||
TinyBlocks_Value tb_value_image(TinyBlocks_Image* img) {
|
||||
TinyBlocks_Value v = { .kind = TB_VALUE_IMAGE, .as.image = img };
|
||||
if (img) tb_image_retain(img);
|
||||
|
||||
Reference in new issue
Block a user