Caneta "desenhe [ ] em x y" e tipo do valor no balão de prévia
- Stage.Draw aceita a saída de outro bloco: imagem (desenha centrada),
lista de pontos [[x,y],...] (traço com a caneta atual, deslocado por
x/y) ou texto (nome de uma imagem guardada).
- O balão de resultado mostra o tipo do valor ("lista de pontos",
"imagem", "texto", "número inteiro"...); blocos booleanos mostram
"verdadeiro"/"falso".
- Status longo no menu mostra o fim da mensagem e não cobre mais o
botão "Carregar library=".
- Harness: desenhe (reta) no palco e tipo no balão.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
33705b2903
commit
4df6eb1bbf
4 files changed
+165
-15
No files matched your search
@@ -1144,6 +1144,7 @@ void bubble_clear(Ed* ed) {
|
||||
if (ed->bubble_img) { tb_image_release(ed->bubble_img); ed->bubble_img = NULL; }
|
||||
ed->bubble_bi = -1;
|
||||
ed->bubble_text[0] = 0;
|
||||
ed->bubble_type[0] = 0;
|
||||
}
|
||||
|
||||
/* Um array JSON é "lista de pontos" quando todos os itens são [x, y]? */
|
||||
@@ -1177,10 +1178,40 @@ static bool json_point_at(const TinyBlocks_JsonValue* arr, int i, double* x, dou
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* Nome do tipo do valor, para o balão de resultado */
|
||||
static const char* value_type_name(const TinyBlocks_Value* v) {
|
||||
switch (v->kind) {
|
||||
case TB_VALUE_INTEGER: return "número inteiro";
|
||||
case TB_VALUE_REAL: return "número real";
|
||||
case TB_VALUE_TEXT: return "texto";
|
||||
case TB_VALUE_BLOCK: return "bloco";
|
||||
case TB_VALUE_VECTOR: return "desenho vetorial";
|
||||
case TB_VALUE_IMAGE: return "imagem";
|
||||
case TB_VALUE_JSON:
|
||||
if (!v->as.json) return "JSON";
|
||||
if (json_is_points(v->as.json)) return "lista de pontos";
|
||||
switch (tb_json_kind(v->as.json)) {
|
||||
case TB_JSON_ARRAY: return "lista";
|
||||
case TB_JSON_OBJECT: return "objeto JSON";
|
||||
default: return "JSON";
|
||||
}
|
||||
default: return "nada";
|
||||
}
|
||||
}
|
||||
|
||||
/* Mostra o resultado de um repórter no balão (estilo Scratch) */
|
||||
static void bubble_set(Ed* ed, int root, TinyBlocks_Value* v) {
|
||||
bubble_clear(ed);
|
||||
ed->bubble_bi = root;
|
||||
scopy(ed->bubble_type, sizeof(ed->bubble_type), value_type_name(v));
|
||||
/* bloco booleano (hexagonal): verdadeiro/falso, como no Scratch */
|
||||
if (root >= 0 && shape_of(blk_type(ed, &CT.ws[root])) == SH_BOOL &&
|
||||
(v->kind == TB_VALUE_INTEGER || v->kind == TB_VALUE_REAL)) {
|
||||
bool t = v->kind == TB_VALUE_INTEGER ? v->as.integer != 0 : v->as.real != 0.0;
|
||||
scopy(ed->bubble_type, sizeof(ed->bubble_type), "booleano");
|
||||
scopy(ed->bubble_text, sizeof(ed->bubble_text), t ? "verdadeiro" : "falso");
|
||||
return;
|
||||
}
|
||||
if (v->kind == TB_VALUE_JSON && v->as.json && json_is_points(v->as.json)) {
|
||||
tb_json_retain(v->as.json);
|
||||
ed->bubble_json = v->as.json;
|
||||
@@ -2240,6 +2271,12 @@ static bool hit_export_btn(float mx, float my);
|
||||
static bool hit_libman_btn(float mx, float my);
|
||||
static bool hit_settings_btn(Ed* ed, float mx, float my);
|
||||
|
||||
/* Tipo do valor no topo dos baloes graficos (imagem, lista de pontos) */
|
||||
static void bubble_type_label(Ed* ed, TinyBlocks_RenderableBlock* rb, float bx, float by) {
|
||||
if (!ed->bubble_type[0]) return;
|
||||
rb_text_c(rb, bx + 10, by + 12, ed->bubble_type, COL_TEXT_DIM, 10.f);
|
||||
}
|
||||
|
||||
static void menu_button(TinyBlocks_RenderableBlock* rb, float x, float w, const char* label, bool active) {
|
||||
rb_fill_rrect(rb, x, 7, w, MENU_H - 14, 6, active ? COL_MENU_DARK : COLA(255, 255, 255, 34));
|
||||
rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, MENU_H * 0.5f, label, COL_WHITE, FS_UI);
|
||||
@@ -2276,8 +2313,21 @@ static void render_menu(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
float cw = tw(ed->path_input_buf, FS_UI);
|
||||
rb_fill_rect(rb, bx + 11 + cw, MENU_H*0.5f - 8, 1.5f, 16, COL_TEXT);
|
||||
} else if (ed->hot_status[0]) {
|
||||
float w = tw(ed->hot_status, FS_SM);
|
||||
rb_text_c(rb, CFG_BTN_X - 12 - w, MENU_H*0.5f, ed->hot_status,
|
||||
/* cabe entre "Carregar library=" e "Config"; se nao couber, mostra
|
||||
o fim da mensagem (o fim de um caminho e o que importa) */
|
||||
float avail = CFG_BTN_X - 12 - (LIB_BTN_X + LIB_BTN_W + 10);
|
||||
const char* s = ed->hot_status;
|
||||
char buf[300];
|
||||
if (avail > 20 && tw(s, FS_SM) > avail) {
|
||||
while (*s && tw(s, FS_SM) + tw("...", FS_SM) > avail) {
|
||||
s++;
|
||||
while ((*s & 0xC0) == 0x80) s++;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "...%s", s);
|
||||
s = buf;
|
||||
}
|
||||
float w = tw(s, FS_SM);
|
||||
rb_text_c(rb, CFG_BTN_X - 12 - w, MENU_H*0.5f, s,
|
||||
ed->hot_status_ok ? COL_WHITE : COL_ERR_MENU, FS_SM);
|
||||
}
|
||||
}
|
||||
@@ -2912,27 +2962,29 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
EdBlock* b = &CT.ws[ed->bubble_bi];
|
||||
if (ed->bubble_img) {
|
||||
/* Balão com prévia da imagem (escalada, mantendo proporção) */
|
||||
const float BW = 184, BH = 160, PAD = 10;
|
||||
const float BW = 184, BH = 174, PAD = 10, HEAD = 16;
|
||||
float bx = b->ax + ox + 8, by = b->ay + oy - (BH + 6);
|
||||
rb_fill_rrect(rb, bx, by, BW, BH, 10, COL_BORDER);
|
||||
rb_fill_rrect(rb, bx+1, by+1, BW-2, BH-2, 9, COL_WHITE);
|
||||
rb_bubble_tail(rb, bx + 22, by + BH - 1, COL_WHITE);
|
||||
bubble_type_label(ed, rb, bx, by);
|
||||
int iw = tb_image_width(ed->bubble_img);
|
||||
int ih = tb_image_height(ed->bubble_img);
|
||||
if (iw > 0 && ih > 0) {
|
||||
float aw = BW - 2*PAD, ah = BH - 2*PAD - 12;
|
||||
float aw = BW - 2*PAD, ah = BH - 2*PAD - 12 - HEAD;
|
||||
float sc = aw/iw < ah/ih ? aw/iw : ah/ih;
|
||||
float dw = iw*sc, dh = ih*sc;
|
||||
tb_draw_image(rb, bx + (BW-dw)*0.5f, by + (BH-12-dh)*0.5f, dw, dh, ed->bubble_img);
|
||||
tb_draw_image(rb, bx + (BW-dw)*0.5f, by + HEAD + (BH-HEAD-12-dh)*0.5f, dw, dh, ed->bubble_img);
|
||||
}
|
||||
rb_text_c(rb, bx + 10, by + BH - 4, ed->bubble_text, COL_TEXT_DIM, 11.f);
|
||||
} else if (ed->bubble_json) {
|
||||
/* Balão com prévia gráfica de uma lista de pontos (curva) */
|
||||
const float BW = 180, BH = 140, PAD = 16;
|
||||
const float BW = 180, BH = 154, PAD = 16, HEAD = 14;
|
||||
float bx = b->ax + ox + 8, by = b->ay + oy - (BH + 6);
|
||||
rb_fill_rrect(rb, bx, by, BW, BH, 10, COL_BORDER);
|
||||
rb_fill_rrect(rb, bx+1, by+1, BW-2, BH-2, 9, COL_WHITE);
|
||||
rb_bubble_tail(rb, bx + 22, by + BH - 1, COL_WHITE);
|
||||
bubble_type_label(ed, rb, bx, by);
|
||||
|
||||
int n = (int)tb_json_array_length(ed->bubble_json);
|
||||
double minx = 1e30, maxx = -1e30, miny = 1e30, maxy = -1e30;
|
||||
@@ -2947,10 +2999,10 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
double spanx = maxx - minx, spany = maxy - miny;
|
||||
if (spanx < 1e-9) { spanx = 1; minx -= 0.5; }
|
||||
if (spany < 1e-9) { spany = 1; miny -= 0.5; }
|
||||
float aw = BW - 2*PAD, ah = BH - 2*PAD - 12;
|
||||
float aw = BW - 2*PAD, ah = BH - 2*PAD - 12 - HEAD;
|
||||
float sc = (float)((aw/spanx < ah/spany) ? aw/spanx : ah/spany);
|
||||
float gx = bx + PAD + (aw - (float)spanx*sc)*0.5f;
|
||||
float gy = by + PAD + (ah - (float)spany*sc)*0.5f;
|
||||
float gy = by + HEAD + PAD + (ah - (float)spany*sc)*0.5f;
|
||||
Col cc = COLA(233, 30, 99, 255);
|
||||
float lx = 0, ly = 0, fx = 0, fy = 0, ex = 0, ey = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
@@ -2967,12 +3019,14 @@ static void render_workspace(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
rb_fill_circle(rb, ex, ey, 3.2f, COLA(229,57,53,255)); /* fim */
|
||||
rb_text_c(rb, bx + 10, by + BH - 4, ed->bubble_text, COL_TEXT_DIM, 11.f);
|
||||
} else {
|
||||
float w = tw(ed->bubble_text, FS) + 20;
|
||||
float bx = b->ax + ox + 8, by = b->ay + oy - 32;
|
||||
rb_fill_rrect(rb, bx, by, w, 26, 8, COL_BORDER);
|
||||
rb_fill_rrect(rb, bx+1, by+1, w-2, 24, 7, COL_WHITE);
|
||||
rb_bubble_tail(rb, bx + 16, by + 25, COL_WHITE);
|
||||
rb_text_c(rb, bx + 10, by + 13, ed->bubble_text, COL_TEXT, FS);
|
||||
/* tipo (pequeno, em cima) + valor */
|
||||
float w = fmaxf(tw(ed->bubble_text, FS), tw(ed->bubble_type, 10.f)) + 20;
|
||||
float bx = b->ax + ox + 8, by = b->ay + oy - 44;
|
||||
rb_fill_rrect(rb, bx, by, w, 38, 8, COL_BORDER);
|
||||
rb_fill_rrect(rb, bx+1, by+1, w-2, 36, 7, COL_WHITE);
|
||||
rb_bubble_tail(rb, bx + 16, by + 37, COL_WHITE);
|
||||
rb_text_c(rb, bx + 10, by + 11, ed->bubble_type, COL_TEXT_DIM, 10.f);
|
||||
rb_text_c(rb, bx + 10, by + 26, ed->bubble_text, COL_TEXT, FS);
|
||||
}
|
||||
}
|
||||
clip_clear(ed, rb);
|
||||
|
||||
Reference in new issue
Block a user