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:
1 parent
fce274f85e
commit
6729ce11fa
2 files changed
+56
-30
No files matched your search
@@ -258,6 +258,8 @@ static UserBlockDef* user_def_find(Ed* ed, const char* name) {
|
|||||||
return NULL;
|
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) {
|
static void block_cols(Ed* ed, const EdBlock* b, Col* c, Col* d) {
|
||||||
const TinyBlocks_TypeBlock* t = b->type;
|
const TinyBlocks_TypeBlock* t = b->type;
|
||||||
if (!t || !t->type_name) { *c = COL_MISSING; *d = col_mul(COL_MISSING, 0.75f); return; }
|
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);
|
int k = cat_of(ed, t->type_name);
|
||||||
if (k < 0) { *c = COL_EXT; *d = COL_EXT_DARK; return; }
|
if (k < 0) { *c = COL_EXT; *d = COL_EXT_DARK; return; }
|
||||||
*c = ed->cats[k].col; *d = ed->cats[k].dark;
|
*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);
|
add_part(b, PART_PROTO, NULL, 0);
|
||||||
return;
|
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) {
|
if (sp) {
|
||||||
const char* p = sp->label; const char* seg = p;
|
const char* p = sp->label; const char* seg = p;
|
||||||
while (*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++) {
|
for (int k = 0; k < L.n; k++) {
|
||||||
if (L.param[k]) { /* parametro: reporter arrastavel */
|
if (L.param[k]) { /* parametro: reporter arrastavel */
|
||||||
float qx = px + L.x[k], qy = cy - PILL_H * 0.5f;
|
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, 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, c);
|
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);
|
rb_text_c(rb, qx + 10, cy, L.txt[k], COL_WHITE, FS);
|
||||||
} else {
|
} else {
|
||||||
rb_text_c(rb, px + L.x[k], cy, L.txt[k], COL_WHITE, FS);
|
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)
|
* Diálogo modal "Criar um Bloco" (estilo Scratch)
|
||||||
* === */
|
* === */
|
||||||
#define DLG_W 580
|
#define DLG_W 580
|
||||||
#define DLG_H 380
|
#define DLG_H 344
|
||||||
#define DLG_HEAD_H 50
|
#define DLG_HEAD_H 50
|
||||||
|
|
||||||
/* Geometria do protótipo: preenche comp_dialog_geom e devolve o retângulo */
|
/* 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;
|
float dx = (WIN_W - DLG_W) * 0.5f, dy = (WIN_H - DLG_H) * 0.5f;
|
||||||
*bw = w; *bh = 40.f;
|
*bw = w; *bh = 40.f;
|
||||||
*bx = dx + (DLG_W - w) * 0.5f;
|
*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=" */
|
/* Dimensões de um card "Adicionar=" */
|
||||||
static void dlg_card_rect(float* w, float* h) {
|
static void dlg_card_rect(float* w, float* h) {
|
||||||
*w = (DLG_W - 56.f - 32.f) / 3.f;
|
*w = (DLG_W - 56.f - 32.f) / 3.f;
|
||||||
*h = 88.f;
|
*h = 84.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dlg_open(Ed* ed, int def_idx) {
|
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);
|
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";
|
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_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));
|
{ /* fechar: um X desenhado */
|
||||||
rb_text_c(rb, dx + DLG_W - 30, dy + DLG_HEAD_H * 0.5f, "=", COL_WHITE, 18);
|
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 */
|
/* Protótipo do bloco */
|
||||||
float bx, by, bw, bh;
|
float bx, by, bw, bh;
|
||||||
@@ -3321,8 +3338,11 @@ void dlg_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
|||||||
/* Controles - apagar - da parte selecionada */
|
/* Controles - apagar - da parte selecionada */
|
||||||
if (ed->comp_dialog_sel >= 0) {
|
if (ed->comp_dialog_sel >= 0) {
|
||||||
float ctr = bx + bw * 0.5f, cty = by - 26;
|
float ctr = bx + bw * 0.5f, cty = by - 26;
|
||||||
rb_text_c(rb, ctr - 44, cty, "=", COL_TEXT, 22);
|
/* setas: mover a parte para a esquerda/direita */
|
||||||
rb_text_c(rb, ctr + 40, cty, "=", COL_TEXT, 22);
|
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 - 7, cty - 8, 14, 3, COL_TEXT);
|
||||||
rb_fill_rect(rb, ctr - 4, cty - 12, 8, 4, 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);
|
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 */
|
/* Cards de adicionar */
|
||||||
float cw, ch; dlg_card_rect(&cw, &ch);
|
float cw, ch; dlg_card_rect(&cw, &ch);
|
||||||
float cx0 = dx + 28.f;
|
float cx0 = dx + 28.f;
|
||||||
float cy0 = by + bh + 34.f;
|
float cy0 = by + bh + 30.f;
|
||||||
const char* lines[3][3] = {
|
const char* lines[3][2] = {
|
||||||
{"Adicionar uma", "entrada", "numérica ou texto"},
|
{"Entrada", "número ou texto"},
|
||||||
{"Adicionar uma", "entrada", "booleana"},
|
{"Entrada", "booleana"},
|
||||||
{"Adicionar um", "rótulo", ""},
|
{"Rótulo", "texto fixo"},
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
float cx = cx0 + i * (cw + 16.f);
|
float cx = cx0 + i * (cw + 16.f);
|
||||||
bool hover = in_rect(ed->mouse_x, ed->mouse_y, cx, cy0, cw, ch);
|
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_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);
|
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;
|
float iy = cy0 + 14.f;
|
||||||
if (i == 0) {
|
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_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) {
|
} else if (i == 1) {
|
||||||
draw_hex(rb, cx + cw * 0.5f - 20, iy, 40, 22, accent);
|
draw_hex(rb, cx + cw * 0.5f - 20, iy, 40, 22, accent);
|
||||||
} else {
|
} else {
|
||||||
rb_fill_rrect(rb, cx + cw * 0.5f - 22, iy, 44, 22, 4, accent);
|
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);
|
rb_text_c(rb, cx + cw * 0.5f - 11, iy + 11, "text", COL_WHITE, FS);
|
||||||
}
|
}
|
||||||
float ty = cy0 + 46.f;
|
rb_text_c(rb, cx + (cw - tw(lines[i][0], FS)) * 0.5f, cy0 + 50.f, lines[i][0], COL_TEXT, FS);
|
||||||
for (int l = 0; l < 3 && lines[i][l][0]; l++) {
|
rb_text_c(rb, cx + (cw - tw(lines[i][1], FS)) * 0.5f, cy0 + 66.f, lines[i][1], COL_TEXT_DIM, FS);
|
||||||
rb_text_c(rb, cx + (cw - tw(lines[i][l], FS)) * 0.5f, ty, lines[i][l], COL_TEXT, FS);
|
|
||||||
ty += 16.f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cores + Cancelar/OK */
|
/* Cores + Cancelar/OK, separados do conteúdo por uma linha */
|
||||||
float fy = dy + DLG_H - 40.f;
|
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++) {
|
for (int ci = 0; ci < USER_COLOR_COUNT; ci++) {
|
||||||
float sx = dx + 28.f + ci * 30.f;
|
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);
|
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 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++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
float cx = cx0 + i * (cw + 16.f);
|
float cx = cx0 + i * (cw + 16.f);
|
||||||
if (in_rect(mx, my, cx, cy0, cw, ch)) {
|
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++)
|
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; }
|
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;
|
float okx = dx + DLG_W - 28.f - 84.f, cax = okx - 96.f;
|
||||||
|
|||||||
+12
-4
@@ -122,6 +122,12 @@ static bool ws_has(const char* s) {
|
|||||||
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS) && strcmp(cmds[i].text, s) == 0) return true;
|
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS) && strcmp(cmds[i].text, s) == 0) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
static int ws_count(const char* s) {
|
||||||
|
int n = 0;
|
||||||
|
for (uint32_t i = 0; i < ncmd; i++)
|
||||||
|
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS) && strcmp(cmds[i].text, s) == 0) n++;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
static bool find_tabbar(const char* s, float* x, float* y) {
|
static bool find_tabbar(const char* s, float* x, float* y) {
|
||||||
for (uint32_t i = 0; i < ncmd; i++) {
|
for (uint32_t i = 0; i < ncmd; i++) {
|
||||||
TinyBlocks_DrawCmd* c = &cmds[i];
|
TinyBlocks_DrawCmd* c = &cmds[i];
|
||||||
@@ -313,11 +319,11 @@ int main(void) {
|
|||||||
if (need("Criar um Bloco", R_FLY, 0, &x, &y)) click(x, y);
|
if (need("Criar um Bloco", R_FLY, 0, &x, &y)) click(x, y);
|
||||||
if (need("nome do bloco", R_WS, 0, &x, &y)) click(x, y);
|
if (need("nome do bloco", R_WS, 0, &x, &y)) click(x, y);
|
||||||
type("dobro");
|
type("dobro");
|
||||||
if (need("numérica ou texto", R_WS, 0, &x, &y)) click(x, y);
|
if (need("número ou texto", R_WS, 0, &x, &y)) click(x, y);
|
||||||
type("n");
|
type("n");
|
||||||
key(TB_KEY_RETURN, 0, 0); /* OK no diálogo */
|
key(TB_KEY_RETURN, 0, 0); /* OK no diálogo */
|
||||||
/* como no Scratch: o "defina" aparece na própria aba, com o parâmetro ao lado */
|
/* como no Scratch: o "defina" aparece na própria aba, com o parâmetro ao lado */
|
||||||
CHECK(ws_has("defina") && !ws_has("parâmetro"), "Criar um Bloco põe \"defina dobro\" na mesma aba (sem parâmetros soltos)");
|
CHECK(ws_has("defina") && ws_count("n") == 1, "Criar um Bloco põe \"defina dobro\" na mesma aba (sem parâmetros soltos)");
|
||||||
CHECK(ws_has("quando a bandeira for clicado"), "sem abrir aba nova: os scripts continuam ali");
|
CHECK(ws_has("quando a bandeira for clicado"), "sem abrir aba nova: os scripts continuam ali");
|
||||||
hx = 0; hy = 0;
|
hx = 0; hy = 0;
|
||||||
need("defina", R_WS, 0, &hx, &hy);
|
need("defina", R_WS, 0, &hx, &hy);
|
||||||
@@ -341,7 +347,7 @@ int main(void) {
|
|||||||
if (!got) { printf("FAIL slot esquerdo do + (+ em %.0f,%.0f)\n", x, y); fails++; }
|
if (!got) { printf("FAIL slot esquerdo do + (+ em %.0f,%.0f)\n", x, y); fails++; }
|
||||||
else drag(px, py, zx - 3, zy);
|
else drag(px, py, zx - 3, zy);
|
||||||
}
|
}
|
||||||
CHECK(ws_has("parâmetro"), "arrastar o parâmetro do defina cria \"parâmetro n\"");
|
CHECK(ws_count("n") == 2, "arrastar o parâmetro do defina cria o reporter \"n\"");
|
||||||
}
|
}
|
||||||
/* digita 1 no slot direito do "+" */
|
/* digita 1 no slot direito do "+" */
|
||||||
if (block_plus(&x, &y, hy + 20)) {
|
if (block_plus(&x, &y, hy + 20)) {
|
||||||
@@ -353,7 +359,9 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
if (block_plus(&x, &y, hy + 20) && need("=", R_WS, 0, &x2, &y2)) {
|
if (block_plus(&x, &y, hy + 20) && need("=", R_WS, 0, &x2, &y2)) {
|
||||||
float rep_left = x - 3 - 10;
|
float rep_left = x - 3 - 10;
|
||||||
{ float px, py; if (find("parâmetro", R_WS, 0, &px, &py)) rep_left = px - 3 - 10 - 10; }
|
/* o reporter "n" (o outro "n" esta no defina) */
|
||||||
|
{ float px, py; for (int k = 0; find("n", R_WS, k, &px, &py); k++)
|
||||||
|
if (py > hy + 10) { rep_left = px - 3 - 10; break; } }
|
||||||
drag(x, y, x + ((x2 + 12) - rep_left), y + (y2 - y));
|
drag(x, y, x + ((x2 + 12) - rep_left), y + (y2 - y));
|
||||||
}
|
}
|
||||||
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
||||||
|
|||||||
Reference in new issue
Block a user