Criar um Bloco: ícones desenhados e espaçamentos; parâmetro só com o nome, mais escuro

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-23 07:02:26 -03:00
1 parent fce274f85e
commit 6729ce11fa
2 files changed
+56 -30

No files matched your search

+44 -26
View File
@@ -258,6 +258,8 @@ static UserBlockDef* user_def_find(Ed* ed, const char* name) {
return NULL;
}
#define PARAM_SHADE 0.82f /* parametros (no "defina" e soltos) sao mais escuros */
static void block_cols(Ed* ed, const EdBlock* b, Col* c, Col* d) {
const TinyBlocks_TypeBlock* t = b->type;
if (!t || !t->type_name) { *c = COL_MISSING; *d = col_mul(COL_MISSING, 0.75f); return; }
@@ -270,6 +272,10 @@ static void block_cols(Ed* ed, const EdBlock* b, Col* c, Col* d) {
int k = cat_of(ed, t->type_name);
if (k < 0) { *c = COL_EXT; *d = COL_EXT_DARK; return; }
*c = ed->cats[k].col; *d = ed->cats[k].dark;
if (strcmp(t->type_name, "Port.In") == 0) { /* parametro: tom mais escuro */
*c = col_mul(*c, PARAM_SHADE);
*d = col_mul(*d, PARAM_SHADE);
}
}
/* ===
@@ -565,6 +571,12 @@ static void build_parts(EdBlock* b) {
add_part(b, PART_PROTO, NULL, 0);
return;
}
if (t->type_name && strcmp(t->type_name, "Port.In") == 0) {
/* parametro: so o nome, como o reporter que sai do "defina" */
const char* nm = b->in_text[0][0] ? b->in_text[0] : "parâmetro";
add_part(b, -1, nm, (int)strlen(nm));
return;
}
if (sp) {
const char* p = sp->label; const char* seg = p;
while (*p) {
@@ -925,8 +937,9 @@ static void render_block(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int bi,
for (int k = 0; k < L.n; k++) {
if (L.param[k]) { /* parametro: reporter arrastavel */
float qx = px + L.x[k], qy = cy - PILL_H * 0.5f;
rb_fill_rrect(rb, qx, qy, L.w[k], PILL_H, PILL_H * 0.5f, d);
rb_fill_rrect(rb, qx + 1, qy + 1, L.w[k] - 2, PILL_H - 2, PILL_H * 0.5f - 1, c);
rb_fill_rrect(rb, qx, qy, L.w[k], PILL_H, PILL_H * 0.5f, col_mul(d, PARAM_SHADE));
rb_fill_rrect(rb, qx + 1, qy + 1, L.w[k] - 2, PILL_H - 2, PILL_H * 0.5f - 1,
col_mul(c, PARAM_SHADE));
rb_text_c(rb, qx + 10, cy, L.txt[k], COL_WHITE, FS);
} else {
rb_text_c(rb, px + L.x[k], cy, L.txt[k], COL_WHITE, FS);
@@ -3064,7 +3077,7 @@ static void sb_paste(Ed* ed) {
* Diálogo modal "Criar um Bloco" (estilo Scratch)
* === */
#define DLG_W 580
#define DLG_H 380
#define DLG_H 344
#define DLG_HEAD_H 50
/* Geometria do protótipo: preenche comp_dialog_geom e devolve o retângulo */
@@ -3089,13 +3102,13 @@ static void dlg_geom(Ed* ed, float* bx, float* by, float* bw, float* bh) {
float dx = (WIN_W - DLG_W) * 0.5f, dy = (WIN_H - DLG_H) * 0.5f;
*bw = w; *bh = 40.f;
*bx = dx + (DLG_W - w) * 0.5f;
*by = dy + DLG_HEAD_H + 46.f;
*by = dy + DLG_HEAD_H + 44.f; /* espaço p/ os controles da parte */
}
/* Dimensões de um card "Adicionar=" */
static void dlg_card_rect(float* w, float* h) {
*w = (DLG_W - 56.f - 32.f) / 3.f;
*h = 88.f;
*h = 84.f;
}
void dlg_open(Ed* ed, int def_idx) {
@@ -3268,8 +3281,12 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rect(rb, dx, dy + DLG_HEAD_H - 12, DLG_W, 12, accent);
const char* title = ed->comp_dialog_def >= 0 ? "Editar Bloco" : "Criar um Bloco";
rb_text_c(rb, dx + (DLG_W - tw(title, 18)) * 0.5f, dy + DLG_HEAD_H * 0.5f, title, COL_WHITE, 18);
rb_fill_circle(rb, dx + DLG_W - 26, dy + DLG_HEAD_H * 0.5f, 12, COLA(255, 255, 255, 60));
rb_text_c(rb, dx + DLG_W - 30, dy + DLG_HEAD_H * 0.5f, "=", COL_WHITE, 18);
{ /* fechar: um X desenhado */
float qx = dx + DLG_W - 26, qy = dy + DLG_HEAD_H * 0.5f;
rb_fill_circle(rb, qx, qy, 12, COLA(255, 255, 255, 60));
rb_line(rb, qx - 4.5f, qy - 4.5f, qx + 4.5f, qy + 4.5f, 2.f, COL_WHITE);
rb_line(rb, qx + 4.5f, qy - 4.5f, qx - 4.5f, qy + 4.5f, 2.f, COL_WHITE);
}
/* Protótipo do bloco */
float bx, by, bw, bh;
@@ -3321,8 +3338,11 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
/* Controles - apagar - da parte selecionada */
if (ed->comp_dialog_sel >= 0) {
float ctr = bx + bw * 0.5f, cty = by - 26;
rb_text_c(rb, ctr - 44, cty, "=", COL_TEXT, 22);
rb_text_c(rb, ctr + 40, cty, "=", COL_TEXT, 22);
/* setas: mover a parte para a esquerda/direita */
rb_line(rb, ctr - 38, cty - 6, ctr - 44, cty, 2.f, COL_TEXT);
rb_line(rb, ctr - 44, cty, ctr - 38, cty + 6, 2.f, COL_TEXT);
rb_line(rb, ctr + 38, cty - 6, ctr + 44, cty, 2.f, COL_TEXT);
rb_line(rb, ctr + 44, cty, ctr + 38, cty + 6, 2.f, COL_TEXT);
rb_fill_rect(rb, ctr - 7, cty - 8, 14, 3, COL_TEXT);
rb_fill_rect(rb, ctr - 4, cty - 12, 8, 4, COL_TEXT);
rb_fill_rect(rb, ctr - 6, cty - 4, 12, 12, COL_TEXT);
@@ -3331,36 +3351,34 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
/* Cards de adicionar */
float cw, ch; dlg_card_rect(&cw, &ch);
float cx0 = dx + 28.f;
float cy0 = by + bh + 34.f;
const char* lines[3][3] = {
{"Adicionar uma", "entrada", "numérica ou texto"},
{"Adicionar uma", "entrada", "booleana"},
{"Adicionar um", "rótulo", ""},
float cy0 = by + bh + 30.f;
const char* lines[3][2] = {
{"Entrada", "número ou texto"},
{"Entrada", "booleana"},
{"Rótulo", "texto fixo"},
};
for (int i = 0; i < 3; i++) {
float cx = cx0 + i * (cw + 16.f);
bool hover = in_rect(ed->mouse_x, ed->mouse_y, cx, cy0, cw, ch);
rb_fill_rrect(rb, cx, cy0, cw, ch, 8, hover ? COL_HOVER : COL_PANEL);
rb_stroke_rect(rb, cx + 0.5f, cy0 + 0.5f, cw - 1, ch - 1, 1, hover ? COL_MENU : COL_BORDER);
float iy = cy0 + 16.f;
if (i == 0) {
float iy = cy0 + 14.f;
if (i == 0) { /* um campo vazio, como a entrada no bloco */
rb_fill_rrect(rb, cx + cw * 0.5f - 22, iy, 44, 22, 11, accent);
rb_text_c(rb, cx + cw * 0.5f - 14, iy + 11, "= = =", COL_WHITE, FS);
rb_fill_rrect(rb, cx + cw * 0.5f - 16, iy + 5, 32, 12, 6, COL_WHITE);
} else if (i == 1) {
draw_hex(rb, cx + cw * 0.5f - 20, iy, 40, 22, accent);
} else {
rb_fill_rrect(rb, cx + cw * 0.5f - 22, iy, 44, 22, 4, accent);
rb_text_c(rb, cx + cw * 0.5f - 11, iy + 11, "text", COL_WHITE, FS);
}
float ty = cy0 + 46.f;
for (int l = 0; l < 3 && lines[i][l][0]; l++) {
rb_text_c(rb, cx + (cw - tw(lines[i][l], FS)) * 0.5f, ty, lines[i][l], COL_TEXT, FS);
ty += 16.f;
}
rb_text_c(rb, cx + (cw - tw(lines[i][0], FS)) * 0.5f, cy0 + 50.f, lines[i][0], COL_TEXT, FS);
rb_text_c(rb, cx + (cw - tw(lines[i][1], FS)) * 0.5f, cy0 + 66.f, lines[i][1], COL_TEXT_DIM, FS);
}
/* Cores + Cancelar/OK */
float fy = dy + DLG_H - 40.f;
/* Cores + Cancelar/OK, separados do conteúdo por uma linha */
rb_line(rb, dx + 1, dy + DLG_H - 62.f, dx + DLG_W - 1, dy + DLG_H - 62.f, 1.f, COL_BORDER);
float fy = dy + DLG_H - 42.f;
for (int ci = 0; ci < USER_COLOR_COUNT; ci++) {
float sx = dx + 28.f + ci * 30.f;
if (ed->comp_dialog_color == ci) rb_fill_rrect(rb, sx - 2, fy - 2, 26, 26, 6, COL_TEXT);
@@ -3399,7 +3417,7 @@ bool dlg_click(Ed* ed, float mx, float my) {
}
float cw, ch; dlg_card_rect(&cw, &ch);
float cx0 = dx + 28.f, cy0 = by + bh + 34.f;
float cx0 = dx + 28.f, cy0 = by + bh + 30.f;
for (int i = 0; i < 3; i++) {
float cx = cx0 + i * (cw + 16.f);
if (in_rect(mx, my, cx, cy0, cw, ch)) {
@@ -3408,7 +3426,7 @@ bool dlg_click(Ed* ed, float mx, float my) {
}
}
float fy = dy + DLG_H - 40.f;
float fy = dy + DLG_H - 42.f;
for (int ci = 0; ci < USER_COLOR_COUNT; ci++)
if (in_rect(mx, my, dx + 28.f + ci * 30.f, fy, 22, 22)) { ed->comp_dialog_color = ci; return true; }
float okx = dx + DLG_W - 28.f - 84.f, cax = okx - 96.f;