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:
mguinhosandClaude Opus 5.5 committed 2026-10-28 21:34:04 -03:00
1 parent f180eaf75a
commit 0cb2019704
22 files changed
+1451 -516

No files matched your search

+1
View File
@@ -358,6 +358,7 @@ appdir: editor ## Monta o AppDir (build/TinyBlocks.AppDir) para o AppImage
cp $(PKG_DIR)/tinyblocks.desktop $(APPDIR)/usr/share/applications/tinyblocks.desktop cp $(PKG_DIR)/tinyblocks.desktop $(APPDIR)/usr/share/applications/tinyblocks.desktop
cp $(PKG_DIR)/AppRun $(APPDIR)/AppRun cp $(PKG_DIR)/AppRun $(APPDIR)/AppRun
chmod +x $(APPDIR)/AppRun chmod +x $(APPDIR)/AppRun
cp -r assets/fonts $(APPDIR)/fonts # Roboto + Material Symbols (TINYBLOCKS_APPDIR/fonts)
@echo "Empacotando bibliotecas (exceto as do sistema)..." @echo "Empacotando bibliotecas (exceto as do sistema)..."
@ldd $(BUILD)/editor | awk '/=> \//{print $$1, $$3}' | while read name path; do \ @ldd $(BUILD)/editor | awk '/=> \//{print $$1, $$3}' | while read name path; do \
skip=0; \ skip=0; \
+202
View File
@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+15 -1
View File
@@ -41,7 +41,8 @@ typedef struct {
TinyBlocks_DrawCmdKind kind; TinyBlocks_DrawCmdKind kind;
float x, y, w, h; /* geometria (significado varia por kind) */ float x, y, w, h; /* geometria (significado varia por kind) */
float r, g, b, a; /* cor RGBA [0..1] */ float r, g, b, a; /* cor RGBA [0..1] */
float param; /* radius (rrect/circle), espessura (linha/stroke) */ float param; /* radius (rrect/circle), espessura (linha/stroke); *
* no TB_DRAW_TEXT, a fonte (TB_FONT_*) */
float font_size; /* tamanho da fonte em pixels (TB_DRAW_TEXT) */ float font_size; /* tamanho da fonte em pixels (TB_DRAW_TEXT) */
char text[128]; /* conteúdo do texto (TB_DRAW_TEXT) */ char text[128]; /* conteúdo do texto (TB_DRAW_TEXT) */
const TinyBlocks_Image* image; /* pixels (TB_DRAW_IMAGE, não-owning) */ const TinyBlocks_Image* image; /* pixels (TB_DRAW_IMAGE, não-owning) */
@@ -105,6 +106,19 @@ TB_API void tb_draw_text (TinyBlocks_RenderableBlock* rb,
float x, float y, const char* text, float font_size, float x, float y, const char* text, float font_size,
float r, float g, float b, float a); float r, float g, float b, float a);
/* Fontes do texto (param do TB_DRAW_TEXT). Os icones sao glifos do Material
* Symbols (codepoints da area privada, ex.: U+E8B8 = "settings"); o backend
* sem a fonte de icones nao desenha nada. */
#define TB_FONT_REGULAR 0 /* Roboto Regular */
#define TB_FONT_MEDIUM 1 /* Roboto Medium (rotulos, titulos) */
#define TB_FONT_ICON 2 /* Material Symbols Outlined */
#define TB_FONT_ICON_FILLED 3 /* Material Symbols (preenchido) */
#define TB_FONT_COUNT 4
TB_API void tb_draw_text_font (TinyBlocks_RenderableBlock* rb,
float x, float y, const char* text, float font_size, int font,
float r, float g, float b, float a);
/* Desenha a imagem escalada para o retângulo (x,y,w,h). A imagem é /* Desenha a imagem escalada para o retângulo (x,y,w,h). A imagem é
* ref-counted; o comando apenas guarda um ponteiro não-owning, portanto a * ref-counted; o comando apenas guarda um ponteiro não-owning, portanto a
* imagem precisa continuar viva até o backend renderizar o frame. */ * imagem precisa continuar viva até o backend renderizar o frame. */
@@ -57,15 +57,16 @@ typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
* === */ * === */
#define WIN_W_DEFAULT 1280 #define WIN_W_DEFAULT 1280
#define WIN_H_DEFAULT 720 #define WIN_H_DEFAULT 720
#define MENU_H 44 #define MENU_H 56 /* top app bar do M3 (densidade -2) */
#define TAB_H 36 #define TAB_H 40 /* cabecalho das areas / abas (M3, densidade -2) */
#define CAT_W 68 #define CAT_W 68
#define FLY_W 250 #define FLY_W 250
#define FLY_PAD 12 #define FLY_PAD 12
#define FLY_BTN_W 150 #define FLY_BTN_W 150
#define PALETTE_W (CAT_W + FLY_W) /* largura padrao da paleta */ #define PALETTE_W (CAT_W + FLY_W) /* largura padrao da paleta */
#define STAGE_W 360 /* largura padrao da coluna do palco */ #define STAGE_W 360 /* largura padrao da coluna do palco */
#define STAGE_BAR_H 44 #define STAGE_BAR_H TAB_H
#define STAGE_TOP (STAGE_BAR_H + 4) /* onde a vista do palco comeca */
#define WIN_W (ed->win_w) #define WIN_W (ed->win_w)
#define WIN_H (ed->win_h) #define WIN_H (ed->win_h)
@@ -88,8 +89,8 @@ typedef struct TinyBlocks_A11yTree TinyBlocks_A11yTree;
#define PLUS_W 28 #define PLUS_W 28
/* Menu do botao "+" (nova aba) */ /* Menu do botao "+" (nova aba) */
#define PLUS_MENU_W 208 #define PLUS_MENU_W 260
#define PLUS_MENU_ITEM_H 36 #define PLUS_MENU_ITEM_H 52 /* item de duas linhas (M3) */
#define PLUS_MENU_N 4 #define PLUS_MENU_N 4
/* Editor de codigo (aba de codigo) */ /* Editor de codigo (aba de codigo) */
@@ -143,8 +144,8 @@ enum { IT_SEL = 0, IT_BRUSH, IT_LINE, IT_RECT, IT_ELLIPSE,
(menu_layout em tb_editor.c): o que nao cabe vai para o menu "☰". */ (menu_layout em tb_editor.c): o que nao cabe vai para o menu "☰". */
enum { MB_OPEN, MB_SAVE, MB_EXPORT, MB_LIBMAN, MB_LIB, MB_CFG, MB_COUNT }; enum { MB_OPEN, MB_SAVE, MB_EXPORT, MB_LIBMAN, MB_LIB, MB_CFG, MB_COUNT };
typedef struct { float x, w; bool shown; } MenuBtn; typedef struct { float x, w; bool shown; } MenuBtn;
#define MENU_BTN_Y 7 #define MENU_BTN_H 36
#define MENU_BTN_H (MENU_H - 14) #define MENU_BTN_Y ((MENU_H - MENU_BTN_H) / 2)
#define MENU_MORE_W 40 #define MENU_MORE_W 40
/* Modo compacto (janela estreita / celular): uma area de cada vez. /* Modo compacto (janela estreita / celular): uma area de cada vez.
@@ -245,6 +246,9 @@ typedef struct {
#define rb_text_c tb_ed_w.text_c #define rb_text_c tb_ed_w.text_c
#define tw tb_ed_w.text_width #define tw tb_ed_w.text_width
#define in_rect tb_ed_w.in_rect #define in_rect tb_ed_w.in_rect
#define rb_text_f tb_ed_w.text_f
#define rb_icon tb_ed_w.icon
#define rb_shadow tb_ed_w.shadow
static const Col COL_MENU TB_EW_UNUSED = C( 76,151,255); /* #4C97FF */ static const Col COL_MENU TB_EW_UNUSED = C( 76,151,255); /* #4C97FF */
static const Col COL_MENU_DARK TB_EW_UNUSED = C( 61,121,204); static const Col COL_MENU_DARK TB_EW_UNUSED = C( 61,121,204);
@@ -296,6 +300,8 @@ static const Col s_user_colors[USER_COLOR_COUNT] TB_EW_UNUSED = {
C(255,191, 0), C(255,171, 25), C( 89,192, 89), C( 15,189,140), C(255,191, 0), C(255,171, 25), C( 89,192, 89), C( 15,189,140),
}; };
#include "tb_editor_m3.h" /* Material 3 sobre a paleta acima */
/* == Rótulos dos blocos (%N - campo de entrada N) === */ /* == Rótulos dos blocos (%N - campo de entrada N) === */
typedef struct { typedef struct {
const char* type; const char* type;
@@ -0,0 +1,287 @@
/*
* TinyBlocks - tb_editor_m3.h
*
* Linguagem visual do editor: Material 3 (m3.material.io) com as cores que o
* editor ja usava. Papeis de cor do M3 apontam para a paleta do TinyBlocks;
* formas, tipografia (Roboto), icones (Material Symbols), camadas de estado
* e elevacao seguem o M3. Densidade -2 do M3 (desktop): alturas 4 px menores.
*
* Incluido por tb_editor_internal.h (usa Col, C(), COLA() e rb_*).
*/
#ifndef TB_EDITOR_M3_H
#define TB_EDITOR_M3_H
/* == Papeis de cor (M3) -> paleta do editor === */
#define M3_PRIMARY COL_MENU /* #4C97FF */
#define M3_ON_PRIMARY COL_WHITE
#define M3_PRIMARY_DARK COL_MENU_DARK
#define M3_PRIMARY_CONTAINER COL_HOVER /* #D6E4F8 */
#define M3_SECONDARY_CONTAINER COL_TAB_OFF /* #D9E3F2 */
#define M3_SURFACE COL_PANEL /* branco */
#define M3_SURFACE_LOW COL_FLY /* #F9F9F9 */
#define M3_SURFACE_CONTAINER COL_UI_BG /* #E5F0FF */
#define M3_ON_SURFACE COL_TEXT /* #575E75 */
#define M3_ON_SURFACE_VAR COL_TEXT_DIM
#define M3_OUTLINE COL_TEXT_DIM
#define M3_OUTLINE_VAR COL_BORDER
#define M3_INVERSE_SURFACE COL_TIP_BG
#define M3_INVERSE_ON_SURFACE COL_CODE_TEXT
#define M3_INVERSE_PRIMARY COL_TIP_LINK
#define M3_ERROR COL_STOP
/* == Formas (raio dos cantos) === */
#define M3_SHAPE_XS 4.f
#define M3_SHAPE_S 8.f
#define M3_SHAPE_M 12.f
#define M3_SHAPE_L 16.f
#define M3_SHAPE_XL 28.f
/* == Tipografia (tamanho em px; titulos e rotulos em Roboto Medium) === */
#define M3_HEADLINE_S 24.f
#define M3_TITLE_L 22.f
#define M3_TITLE_M 16.f
#define M3_TITLE_S 14.f
#define M3_LABEL_L 14.f
#define M3_LABEL_M 12.f
#define M3_LABEL_S 11.f
#define M3_BODY_L 16.f
#define M3_BODY_M 14.f
#define M3_BODY_S 12.f
/* == Camadas de estado (opacidade da cor do conteudo) === */
#define M3_HOVER 0.08f
#define M3_PRESSED 0.10f
#define M3_DRAGGED 0.16f
/* == Componentes: alturas (densidade -2) === */
#define M3_BUTTON_H 36.f /* botoes comuns (40 no M3 padrao) */
#define M3_ICON_BTN 36.f /* icon button: alvo (40 no padrao) */
#define M3_ICON 20.f /* icone dentro de botoes */
#define M3_MENU_ITEM 40.f /* item de menu (48 no padrao) */
/* == Icones (Material Symbols, codepoints) === */
#define MI_ADD 0xe145
#define MI_ARROW_BACK 0xe5c4
#define MI_ARROW_FORWARD 0xe5c8
#define MI_ARROW_UPWARD 0xe5d8
#define MI_ARROW_RIGHT 0xe5df
#define MI_BRUSH 0xe3ae
#define MI_CANCEL 0xe888
#define MI_CHECK 0xe668
#define MI_CHECK_CIRCLE 0xf0be
#define MI_CHEVRON_LEFT 0xe5cb
#define MI_CHEVRON_RIGHT 0xe5cc
#define MI_CIRCLE 0xef4a
#define MI_CLOSE 0xe5cd
#define MI_CODE 0xe86f
#define MI_COLORIZE 0xe3b8
#define MI_CONTENT_COPY 0xe14d
#define MI_CONTENT_CUT 0xe14e
#define MI_CONTENT_PASTE 0xe14f
#define MI_CREATE_FOLDER 0xe2cc
#define MI_DELETE 0xe92e
#define MI_DESCRIPTION 0xe873
#define MI_DRAFT 0xe66d
#define MI_DRAG_INDICATOR 0xe945
#define MI_EDIT 0xf097
#define MI_ERROR 0xf8b6
#define MI_EXPAND_MORE 0xe5cf
#define MI_EXTENSION 0xe87b
#define MI_FILL 0xe23a
#define MI_FLAG 0xf0c6
#define MI_FOLDER 0xe2c7
#define MI_GRID_VIEW 0xe9b0
#define MI_DATA_OBJECT 0xead3
#define MI_TABLE 0xf191
#define MI_ACCOUNT_TREE 0xe97a
#define MI_SELECT_ALL 0xe162
#define MI_ADD_BOX 0xe146
#define MI_FOLDER_OPEN 0xe2c8
#define MI_HOME 0xe9b2
#define MI_IMAGE 0xe3f4
#define MI_INFO 0xe88e
#define MI_ERASER 0xe6d0
#define MI_IOS_SHARE 0xe6b8
#define MI_LIBRARY_ADD 0xe03c
#define MI_LIBRARY_BOOKS 0xe02f
#define MI_MENU 0xe5d2
#define MI_MORE_VERT 0xe5d4
#define MI_OPEN_IN_NEW 0xe89e
#define MI_CLOSE_FULLSCR 0xf1cf
#define MI_PALETTE 0xe40a
#define MI_PAN_TOOL 0xe925
#define MI_PLAY_ARROW 0xe037
#define MI_RECTANGLE 0xeb54
#define MI_REDO 0xe15a
#define MI_REFRESH 0xe5d5
#define MI_SAVE 0xe161
#define MI_SEARCH 0xef7a
#define MI_SELECT 0xf74d
#define MI_SETTINGS 0xe8b8
#define MI_STOP 0xe047
#define MI_STOP_CIRCLE 0xef71
#define MI_SWAP_HORIZ 0xe8d4
#define MI_TERMINAL 0xeb8e
#define MI_TEXT_FIELDS 0xe262
#define MI_UNDO 0xe166
#define MI_UPLOAD_FILE 0xe9fc
#define MI_WARNING 0xf083
#define MI_WIDGETS 0xe1bd
#define MI_ZOOM_IN 0xe8ff
#define MI_ZOOM_OUT 0xe900
/* == Utilitarios === */
static inline Col m3_alpha(Col c, float a) { c.a = a; return c; }
/* c sobre o fundo bg com opacidade a (cor solida resultante) */
static inline Col m3_mix(Col bg, Col c, float a) {
Col r = { bg.r + (c.r - bg.r) * a, bg.g + (c.g - bg.g) * a, bg.b + (c.b - bg.b) * a, 1.f };
return r;
}
/* Largura de um rotulo em Roboto Medium (a medicao do backend e da Regular) */
static inline float m3_tw_m(const char* s, float fs) { return tw(s, fs) * 1.04f; }
/* Camada de estado: a cor do conteudo, translucida, sobre o componente */
static inline void m3_state(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad,
Col on, bool hover, bool pressed) {
float a = pressed ? M3_PRESSED : hover ? M3_HOVER : 0.f;
if (a > 0.f) rb_fill_rrect(rb, x, y, w, h, rad, m3_alpha(on, a));
}
/* == Botoes (pilula): filled, tonal, outlined, text === */
enum { M3_FILLED, M3_TONAL, M3_OUTLINED, M3_TEXT };
static inline float m3_button_w(const char* label, unsigned icon) {
return m3_tw_m(label, M3_LABEL_L) + (icon ? 16.f + 18.f + 8.f + 24.f : 48.f);
}
/* accent = cor do papel "primary" deste botao (a do editor ou a do dialogo) */
static inline void m3_button(TinyBlocks_RenderableBlock* rb, int kind, float x, float y, float w, float h,
const char* label, unsigned icon, Col accent, bool hover, bool pressed) {
float r = h * 0.5f;
Col on = accent;
if (kind == M3_FILLED) {
rb_fill_rrect(rb, x, y, w, h, r, accent);
on = M3_ON_PRIMARY;
} else if (kind == M3_TONAL) {
rb_fill_rrect(rb, x, y, w, h, r, m3_mix(M3_SURFACE, accent, 0.16f));
on = col_mul(accent, 0.8f);
} else if (kind == M3_OUTLINED) {
rb_fill_rrect(rb, x, y, w, h, r, M3_OUTLINE_VAR);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, r - 1, M3_SURFACE);
}
m3_state(rb, x, y, w, h, r, on, hover, pressed);
float lw = m3_tw_m(label, M3_LABEL_L);
float cx = x + w * 0.5f, cy = y + h * 0.5f;
if (icon) {
float total = 18.f + 8.f + lw;
float ix = cx - total * 0.5f;
rb_icon(rb, ix + 9.f, cy, icon, 18.f, on, false);
rb_text_f(rb, ix + 26.f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
} else {
rb_text_f(rb, cx - lw * 0.5f, cy, label, on, M3_LABEL_L, TB_FONT_MEDIUM);
}
}
/* Icon button (padrao): so o icone; o circulo aparece no hover/pressionado.
selected = toggle ligado (container tonal) */
static inline void m3_icon_button(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned icon, Col c,
bool hover, bool selected) {
float s = M3_ICON_BTN;
if (selected) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, 0.16f));
if (hover) rb_fill_circle(rb, cx, cy, s * 0.5f, m3_alpha(c, M3_HOVER));
rb_icon(rb, cx, cy, icon, M3_ICON, c, selected);
}
/* == Superficies === */
/* Menu: canto XS, elevacao 2 */
static inline void m3_menu_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 2);
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_SURFACE);
}
/* Item de menu: icone opcional a esquerda, rotulo Label Large */
static inline void m3_menu_item(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
const char* label, unsigned icon, bool hover, Col fg) {
m3_state(rb, x, y, w, h, 0, M3_ON_SURFACE, hover, false);
float tx = x + 12.f;
if (icon) { rb_icon(rb, tx + 10.f, y + h * 0.5f, icon, M3_ICON, M3_ON_SURFACE_VAR, false); tx += 20.f + 12.f; }
rb_text_f(rb, tx, y + h * 0.5f, label, fg, M3_LABEL_L, TB_FONT_REGULAR);
}
/* Dialogo: canto XL, elevacao 3 */
static inline void m3_dialog_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
rb_shadow(rb, x, y, w, h, M3_SHAPE_XL, 3);
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XL, M3_SURFACE);
}
/* Scrim atras de dialogos modais */
static inline void m3_scrim(TinyBlocks_RenderableBlock* rb, float w, float h) {
rb_fill_rect(rb, 0, 0, w, h, COLA(0, 0, 0, 82));
}
/* Campo de texto "outlined": canto XS, contorno 1 px (2 px na cor
primaria quando em foco) */
static inline void m3_field(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
bool focused, Col accent) {
if (focused) {
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, accent);
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, M3_SHAPE_XS - 1, M3_SURFACE);
} else {
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_OUTLINE);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_XS - 0.5f, M3_SURFACE);
}
}
/* Barra de busca: pilula, icone de lupa a esquerda */
static inline void m3_search_bar(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
bool focused, Col accent) {
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_SURFACE_CONTAINER);
if (focused) {
rb_fill_rrect(rb, x - 1, y - 1, w + 2, h + 2, h * 0.5f + 1, accent);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, h * 0.5f - 1, M3_SURFACE_CONTAINER);
}
rb_icon(rb, x + 16.f + 12.f, y + h * 0.5f, MI_SEARCH, 24.f, M3_ON_SURFACE_VAR, false);
}
/* Indicador da aba ativa (aba primaria): 3 px com cantos de cima redondos */
static inline void m3_tab_indicator(TinyBlocks_RenderableBlock* rb, float x, float y_bottom, float w, Col c) {
rb_fill_rrect(rb, x, y_bottom - 3.f, w, 6.f, 3.f, c);
}
/* Chip (assist/filter): canto S, 32 px */
static inline void m3_chip(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, const char* label,
unsigned icon, bool selected, bool hover) {
if (selected) rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_SECONDARY_CONTAINER);
else {
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_S, M3_OUTLINE_VAR);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, M3_SHAPE_S - 1, M3_SURFACE);
}
m3_state(rb, x, y, w, h, M3_SHAPE_S, M3_ON_SURFACE, hover, false);
float tx = x + 12.f;
if (icon) { rb_icon(rb, x + 8.f + 9.f, y + h * 0.5f, icon, 18.f, M3_PRIMARY, false); tx = x + 8.f + 18.f + 8.f; }
rb_text_f(rb, tx, y + h * 0.5f, label, M3_ON_SURFACE, M3_LABEL_L, TB_FONT_MEDIUM);
}
/* Snackbar: superficie inversa, canto XS, elevacao 3 */
static inline void m3_snackbar_surface(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h) {
rb_shadow(rb, x, y, w, h, M3_SHAPE_XS, 3);
rb_fill_rrect(rb, x, y, w, h, M3_SHAPE_XS, M3_INVERSE_SURFACE);
}
/* Interruptor (switch) do M3: trilho 52x32, alca 16 (24 ligado) */
static inline void m3_switch(TinyBlocks_RenderableBlock* rb, float x, float y, bool on, Col accent) {
const float w = 52.f, h = 32.f;
if (on) {
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, accent);
rb_fill_circle(rb, x + w - 16.f, y + h * 0.5f, 12.f, M3_ON_PRIMARY);
rb_icon(rb, x + w - 16.f, y + h * 0.5f, MI_CHECK, 16.f, accent, false);
} else {
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, M3_OUTLINE);
rb_fill_rrect(rb, x + 2, y + 2, w - 4, h - 4, h * 0.5f - 2, M3_SURFACE_CONTAINER);
rb_fill_circle(rb, x + 16.f, y + h * 0.5f, 8.f, M3_OUTLINE);
}
}
#endif /* TB_EDITOR_M3_H */
@@ -48,6 +48,9 @@ typedef struct {
void (*text_c) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float); void (*text_c) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float);
float (*text_width) (const char*, float); float (*text_width) (const char*, float);
bool (*in_rect) (float, float, float, float, float, float); bool (*in_rect) (float, float, float, float, float, float);
void (*text_f) (TinyBlocks_RenderableBlock*, float, float, const char*, TbEwColor, float, int);
void (*icon) (TinyBlocks_RenderableBlock*, float, float, unsigned, float, TbEwColor, bool);
void (*shadow) (TinyBlocks_RenderableBlock*, float, float, float, float, float, int);
} TbEdWidgetsApi; } TbEdWidgetsApi;
/* API da library privada tinyblocks-editor-image */ /* API da library privada tinyblocks-editor-image */
@@ -21,15 +21,15 @@
#include "tb_editor_files.h" #include "tb_editor_files.h"
/* -- Geometria --- */ /* -- Geometria --- */
#define FD_HEAD_H 46 #define FD_HEAD_H 60
#define FD_BAR_H 44 #define FD_BAR_H 44
#define FD_SIDE_W 196 #define FD_SIDE_W 196
#define FD_COLH_H 26 #define FD_COLH_H 26
#define FD_ROW_H 26 #define FD_ROW_H 32
#define FD_FOOT_H 100 #define FD_FOOT_H 100
#define FD_PAD 14 #define FD_PAD 14
#define FD_BTN_W 104 #define FD_BTN_W 104
#define FD_BTN_H 32 #define FD_BTN_H 36
static const Col COL_FD_FOLDER = C(255,191, 38); static const Col COL_FD_FOLDER = C(255,191, 38);
static const Col COL_FD_FOLDER_DARK = C(222,150, 10); static const Col COL_FD_FOLDER_DARK = C(222,150, 10);
@@ -66,8 +66,8 @@ static void fd_layout(Ed* ed, FdL* L) {
L->w = w; L->h = h; L->w = w; L->h = h;
L->x = (WIN_W - w) * 0.5f; L->x = (WIN_W - w) * 0.5f;
L->y = (WIN_H - h) * 0.5f; L->y = (WIN_H - h) * 0.5f;
L->close_cx = L->x + w - 26.f; L->close_cx = L->x + w - 32.f;
L->close_cy = L->y + FD_HEAD_H * 0.5f; L->close_cy = L->y + FD_HEAD_H * 0.5f + 2.f;
L->bar_y = L->y + FD_HEAD_H + 7.f; L->bar_y = L->y + FD_HEAD_H + 7.f;
L->up_x = L->x + FD_PAD; L->up_x = L->x + FD_PAD;
L->crumb_x = L->up_x + 40.f; L->crumb_x = L->up_x + 40.f;
@@ -565,11 +565,11 @@ void tb_editor_files_open(Ed* ed, int mode, const char* def) {
/* -- Desenho --- */ /* -- Desenho --- */
/* Icones do Material Symbols (x, y = canto do quadrado de 20 px) */
static void fd_icon_folder(TinyBlocks_RenderableBlock* rb, float x, float y, bool dim) { static void fd_icon_folder(TinyBlocks_RenderableBlock* rb, float x, float y, bool dim) {
Col c = COL_FD_FOLDER, d = COL_FD_FOLDER_DARK; Col c = COL_FD_FOLDER;
if (dim) { c.a = 0.55f; d.a = 0.55f; } if (dim) c.a = 0.55f;
rb_fill_rrect(rb, x, y + 1, 9, 6, 2, d); rb_icon(rb, x + 10, y + 9, dim ? MI_ARROW_UPWARD : MI_FOLDER, 20.f, dim ? M3_ON_SURFACE_VAR : c, !dim);
rb_fill_rrect(rb, x, y + 4, 19, 13, 2, c);
} }
static Col fd_type_col(const char* name) { static Col fd_type_col(const char* name) {
@@ -583,37 +583,38 @@ static Col fd_type_col(const char* name) {
return COL_TEXT_DIM; return COL_TEXT_DIM;
} }
static void fd_icon_file(TinyBlocks_RenderableBlock* rb, float x, float y, Col band) { static unsigned fd_type_icon(const char* name) {
rb_fill_rrect(rb, x + 2, y, 15, 18, 2, COL_BORDER); const char* e = fd_ext(name);
rb_fill_rrect(rb, x + 3, y + 1, 13, 16, 1.5f, COL_WHITE); if (!strcasecmp(e, ".json") || !strcasecmp(e, ".xml") || !strcasecmp(e, ".csv")) return MI_DATA_OBJECT;
rb_fill_rect(rb, x + 3, y + 11, 13, 5, band); if (!strcasecmp(e, ".png") || !strcasecmp(e, ".jpg") || !strcasecmp(e, ".jpeg") ||
rb_line(rb, x + 6, y + 5, x + 13, y + 5, 1, COL_BORDER); !strcasecmp(e, ".bmp") || !strcasecmp(e, ".ppm") || !strcasecmp(e, ".svg")) return MI_IMAGE;
rb_line(rb, x + 6, y + 8, x + 13, y + 8, 1, COL_BORDER); if (!strcasecmp(e, ".so")) return MI_EXTENSION;
if (!strcasecmp(e, ".c") || !strcasecmp(e, ".h") || !strcasecmp(e, ".py") ||
!strcasecmp(e, ".md") || !strcasecmp(e, ".toml")) return MI_CODE;
return MI_DRAFT;
} }
static void fd_icon_file(TinyBlocks_RenderableBlock* rb, float x, float y, Col band, const char* name) {
rb_icon(rb, x + 10, y + 9, fd_type_icon(name), 20.f, band, false);
}
/* Caixa de selecao do M3 (16 px aqui, canto 2) com o rotulo */
static void fd_checkbox(TinyBlocks_RenderableBlock* rb, float x, float cy, bool on, const char* label) { static void fd_checkbox(TinyBlocks_RenderableBlock* rb, float x, float cy, bool on, const char* label) {
float s = 16; float s = 18;
if (on) { if (on) {
rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 3, COL_MENU); rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 2, M3_PRIMARY);
rb_line(rb, x + 4, cy, x + 7, cy + 4, 2, COL_WHITE); rb_icon(rb, x + s * 0.5f, cy, MI_CHECK, 16.f, M3_ON_PRIMARY, false);
rb_line(rb, x + 7, cy + 4, x + 12, cy - 4, 2, COL_WHITE);
} else { } else {
rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 3, COL_BORDER); rb_fill_rrect(rb, x, cy - s * 0.5f, s, s, 2, M3_ON_SURFACE_VAR);
rb_fill_rrect(rb, x + 1.5f, cy - s * 0.5f + 1.5f, s - 3, s - 3, 2, COL_WHITE); rb_fill_rrect(rb, x + 2, cy - s * 0.5f + 2, s - 4, s - 4, 1, M3_SURFACE);
} }
rb_text_c(rb, x + s + 8, cy, label, COL_TEXT, FS_UI); rb_text_f(rb, x + s + 10, cy, label, M3_ON_SURFACE, M3_BODY_M, TB_FONT_REGULAR);
} }
/* Acoes do dialogo: a principal e "filled", a outra e botao de texto */
static void fd_button(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, static void fd_button(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h,
const char* label, bool primary, bool hov, Col accent) { const char* label, bool primary, bool hov, Col accent) {
if (primary) { m3_button(rb, primary ? M3_FILLED : M3_TEXT, x, y, w, h, label, 0, accent, hov, false);
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, hov ? col_mul(accent, 0.86f) : accent);
rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + h * 0.5f, label, COL_WHITE, FS_UI);
} else {
rb_fill_rrect(rb, x, y, w, h, h * 0.5f, COL_BORDER);
rb_fill_rrect(rb, x + 1, y + 1, w - 2, h - 2, h * 0.5f - 1, hov ? COL_HOVER : COL_WHITE);
rb_text_c(rb, x + (w - tw(label, FS_UI)) * 0.5f, y + h * 0.5f, label, COL_TEXT, FS_UI);
}
} }
/* Caixa de confirmacao "substituir?" (geometria compartilhada com o clique) */ /* Caixa de confirmacao "substituir?" (geometria compartilhada com o clique) */
@@ -712,34 +713,26 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
bool modal_free = !F->confirm; bool modal_free = !F->confirm;
char buf[512]; char buf[512];
rb_fill_rect(rb, 0, 0, WIN_W, WIN_H, COLA(0, 0, 0, 120)); m3_scrim(rb, WIN_W, WIN_H);
rb_fill_rrect(rb, L.x + 3, L.y + 4, L.w, L.h, 12, COLA(0, 0, 0, 70)); m3_dialog_surface(rb, L.x, L.y, L.w, L.h);
rb_fill_rrect(rb, L.x, L.y, L.w, L.h, 12, COL_PANEL);
/* Cabecalho */ /* Cabecalho: icone + titulo (headline) a esquerda, fechar a direita */
rb_fill_rrect(rb, L.x, L.y, L.w, FD_HEAD_H, 12, COL_MENU); rb_icon(rb, L.x + 24 + 12, L.y + FD_HEAD_H * 0.5f + 2, F->save ? MI_SAVE : MI_FOLDER_OPEN, 24.f, M3_PRIMARY, false);
rb_fill_rect(rb, L.x, L.y + FD_HEAD_H - 12, L.w, 12, COL_MENU); rb_text_f(rb, L.x + 24 + 24 + 12, L.y + FD_HEAD_H * 0.5f + 2, F->title, M3_ON_SURFACE, M3_HEADLINE_S,
rb_text_c(rb, L.x + (L.w - tw(F->title, 18)) * 0.5f, L.y + FD_HEAD_H * 0.5f, F->title, COL_WHITE, 18); TB_FONT_REGULAR);
{ m3_icon_button(rb, L.close_cx, L.close_cy, MI_CLOSE, M3_ON_SURFACE_VAR,
bool hov = modal_free && hypotf(mx - L.close_cx, my - L.close_cy) < 14.f; modal_free && hypotf(mx - L.close_cx, my - L.close_cy) < 16.f, false);
rb_fill_circle(rb, L.close_cx, L.close_cy, 13, COLA(255, 255, 255, hov ? 110 : 60));
rb_line(rb, L.close_cx - 5, L.close_cy - 5, L.close_cx + 5, L.close_cy + 5, 2, COL_WHITE);
rb_line(rb, L.close_cx + 5, L.close_cy - 5, L.close_cx - 5, L.close_cy + 5, 2, COL_WHITE);
}
/* Barra: pasta acima + trilha */ /* Barra: pasta acima + trilha */
{ {
float by = L.bar_y, bh = 30; float by = L.bar_y, bh = 30;
bool hov = modal_free && in_rect(mx, my, L.up_x, by, 32, bh); bool hov = modal_free && in_rect(mx, my, L.up_x, by, 32, bh);
bool can_up = strcmp(F->dir, "/") != 0; bool can_up = strcmp(F->dir, "/") != 0;
rb_fill_rrect(rb, L.up_x, by, 32, bh, 6, hov && can_up ? COL_HOVER : COL_UI_BG);
Col ac = can_up ? COL_TEXT : COL_TEXT_DIM;
float cx = L.up_x + 16, cy = by + bh * 0.5f; float cx = L.up_x + 16, cy = by + bh * 0.5f;
rb_line(rb, cx, cy + 7, cx, cy - 7, 2, ac); m3_icon_button(rb, cx, cy, MI_ARROW_UPWARD, can_up ? M3_ON_SURFACE_VAR : m3_alpha(M3_ON_SURFACE, 0.38f),
rb_line(rb, cx - 6, cy - 1, cx, cy - 7, 2, ac); hov && can_up, false);
rb_line(rb, cx + 6, cy - 1, cx, cy - 7, 2, ac);
rb_fill_rrect(rb, L.crumb_x, by, L.crumb_w, bh, 6, COL_UI_BG); rb_fill_rrect(rb, L.crumb_x, by, L.crumb_w, bh, bh * 0.5f, M3_SURFACE_CONTAINER);
FdCrumbs K; FdCrumbs K;
fd_crumbs(ed, &L, &K); fd_crumbs(ed, &L, &K);
if (K.ellipsis) if (K.ellipsis)
@@ -750,37 +743,39 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
fd_fit(fit, sizeof(fit), lb, FS_UI, K.w[k] - 16.f); fd_fit(fit, sizeof(fit), lb, FS_UI, K.w[k] - 16.f);
bool last = k == K.n - 1; bool last = k == K.n - 1;
bool h = modal_free && !last && in_rect(mx, my, K.x[k], by + 3, K.w[k], bh - 6); bool h = modal_free && !last && in_rect(mx, my, K.x[k], by + 3, K.w[k], bh - 6);
if (last) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, 5, COL_WHITE); if (last) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, (bh - 6) * 0.5f, M3_SECONDARY_CONTAINER);
else if (h) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, 5, COL_HOVER); else if (h) rb_fill_rrect(rb, K.x[k], by + 3, K.w[k], bh - 6, (bh - 6) * 0.5f,
rb_text_c(rb, K.x[k] + 8, cy, fit, last ? COL_TEXT : COL_MENU_DARK, FS_UI); m3_alpha(M3_ON_SURFACE, M3_HOVER));
if (!last && k > 0) rb_text_c(rb, K.x[k] + K.w[k] + 3, cy, "/", COL_TEXT_DIM, FS_UI); rb_text_f(rb, K.x[k] + 8, cy, fit, last ? M3_ON_SURFACE : M3_PRIMARY_DARK, M3_LABEL_L, TB_FONT_MEDIUM);
if (!last && k > 0) rb_icon(rb, K.x[k] + K.w[k] + 7, cy, MI_CHEVRON_RIGHT, 16.f, M3_ON_SURFACE_VAR, false);
} }
} }
/* Barra lateral: locais */ /* Barra lateral: locais */
rb_line(rb, L.x, L.side_y, L.x + L.w, L.side_y, 1, COL_BORDER); rb_line(rb, L.x, L.side_y, L.x + L.w, L.side_y, 1, M3_OUTLINE_VAR);
if (L.side_w > 0) { if (L.side_w > 0) {
rb_fill_rect(rb, L.side_x, L.side_y, L.side_w, L.side_h, COL_FD_SIDE); rb_line(rb, L.side_x + L.side_w, L.side_y, L.side_x + L.side_w, L.side_y + L.side_h, 1, M3_OUTLINE_VAR);
rb_line(rb, L.side_x + L.side_w, L.side_y, L.side_x + L.side_w, L.side_y + L.side_h, 1, COL_BORDER); rb_text_f(rb, L.side_x + FD_PAD + 4, L.side_y + 16, "Locais", M3_ON_SURFACE_VAR, M3_TITLE_S, TB_FONT_MEDIUM);
rb_text_c(rb, L.side_x + FD_PAD, L.side_y + 16, "Locais", COL_TEXT_DIM, FS_SM);
} }
for (int i = 0; L.side_w > 0 && i < F->place_n; i++) { for (int i = 0; L.side_w > 0 && i < F->place_n; i++) { /* itens da gaveta de navegacao */
float iy = L.side_y + 30 + i * 32; float iy = L.side_y + 30 + i * 32;
bool cur = strcmp(F->dir, F->place_path[i]) == 0; bool cur = strcmp(F->dir, F->place_path[i]) == 0;
bool h = modal_free && in_rect(mx, my, L.side_x + 6, iy, L.side_w - 12, 30); bool h = modal_free && in_rect(mx, my, L.side_x + 6, iy, L.side_w - 12, 30);
if (cur || h) rb_fill_rrect(rb, L.side_x + 6, iy, L.side_w - 12, 30, 6, cur ? COL_HOVER : COLA(214, 228, 248, 140)); if (cur) rb_fill_rrect(rb, L.side_x + 6, iy, L.side_w - 12, 30, 15, M3_SECONDARY_CONTAINER);
if (cur) rb_fill_rrect(rb, L.side_x + 6, iy + 6, 3, 18, 1.5f, COL_MENU); m3_state(rb, L.side_x + 6, iy, L.side_w - 12, 30, 15, M3_ON_SURFACE, h, false);
fd_icon_folder(rb, L.side_x + 16, iy + 6, false); rb_icon(rb, L.side_x + 16 + 10, iy + 15, MI_FOLDER, 20.f, cur ? M3_ON_SURFACE : M3_ON_SURFACE_VAR, cur);
fd_fit(buf, sizeof(buf), F->place_label[i], FS_UI, L.side_w - 60); fd_fit(buf, sizeof(buf), F->place_label[i], FS_UI, L.side_w - 60);
rb_text_c(rb, L.side_x + 42, iy + 15, buf, cur ? COL_MENU_DARK : COL_TEXT, FS_UI); rb_text_f(rb, L.side_x + 44, iy + 15, buf, M3_ON_SURFACE, M3_LABEL_L, cur ? TB_FONT_MEDIUM : TB_FONT_REGULAR);
} }
/* Cabecalho das colunas */ /* Cabecalho das colunas */
float col_size = L.col_size, col_time = L.col_time; float col_size = L.col_size, col_time = L.col_time;
rb_text_c(rb, L.list_x + 44, L.colh_y + FD_COLH_H * 0.5f, "Nome", COL_TEXT_DIM, FS_SM); rb_text_f(rb, L.list_x + 44, L.colh_y + FD_COLH_H * 0.5f, "Nome", M3_ON_SURFACE_VAR, M3_LABEL_M, TB_FONT_MEDIUM);
if (col_size) rb_text_c(rb, col_size, L.colh_y + FD_COLH_H * 0.5f, "Tamanho", COL_TEXT_DIM, FS_SM); if (col_size) rb_text_f(rb, col_size, L.colh_y + FD_COLH_H * 0.5f, "Tamanho", M3_ON_SURFACE_VAR, M3_LABEL_M,
if (col_time) rb_text_c(rb, col_time, L.colh_y + FD_COLH_H * 0.5f, "Modificado", COL_TEXT_DIM, FS_SM); TB_FONT_MEDIUM);
rb_line(rb, L.list_x, L.list_y, L.list_x + L.list_w, L.list_y, 1, COL_BORDER); if (col_time) rb_text_f(rb, col_time, L.colh_y + FD_COLH_H * 0.5f, "Modificado", M3_ON_SURFACE_VAR, M3_LABEL_M,
TB_FONT_MEDIUM);
rb_line(rb, L.list_x, L.list_y, L.list_x + L.list_w, L.list_y, 1, M3_OUTLINE_VAR);
/* Linhas */ /* Linhas */
int end = F->scroll + L.rows; int end = F->scroll + L.rows;
@@ -790,12 +785,14 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float ry = L.list_y + (float)(i - F->scroll) * FD_ROW_H; float ry = L.list_y + (float)(i - F->scroll) * FD_ROW_H;
bool sel = i == F->sel; bool sel = i == F->sel;
bool h = modal_free && in_rect(mx, my, L.list_x, ry, L.list_w - 12, FD_ROW_H); bool h = modal_free && in_rect(mx, my, L.list_x, ry, L.list_w - 12, FD_ROW_H);
if (sel) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, 5, COL_MENU); if (sel) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, M3_SHAPE_S,
else if (h) rb_fill_rrect(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, 5, COL_HOVER); M3_SECONDARY_CONTAINER);
Col tc = sel ? COL_WHITE : COL_TEXT; m3_state(rb, L.list_x + 4, ry + 1, L.list_w - 18, FD_ROW_H - 2, M3_SHAPE_S, M3_ON_SURFACE, h, false);
Col dc = sel ? COLA(255, 255, 255, 210) : COL_TEXT_DIM; Col tc = M3_ON_SURFACE;
if (e->is_dir) fd_icon_folder(rb, L.list_x + 14, ry + 4, e->is_dir == 2); Col dc = M3_ON_SURFACE_VAR;
else fd_icon_file(rb, L.list_x + 14, ry + 4, fd_type_col(e->name)); float iy = ry + (FD_ROW_H - 18) * 0.5f;
if (e->is_dir) fd_icon_folder(rb, L.list_x + 14, iy, e->is_dir == 2);
else fd_icon_file(rb, L.list_x + 14, iy, fd_type_col(e->name), e->name);
fd_fit(buf, sizeof(buf), e->is_dir == 2 ? ".. (pasta acima)" : e->name, FS_UI, fd_fit(buf, sizeof(buf), e->is_dir == 2 ? ".. (pasta acima)" : e->name, FS_UI,
L.name_end - (L.list_x + 44) - 16); L.name_end - (L.list_x + 44) - 16);
rb_text_c(rb, L.list_x + 44, ry + FD_ROW_H * 0.5f, buf, tc, FS_UI); rb_text_c(rb, L.list_x + 44, ry + FD_ROW_H * 0.5f, buf, tc, FS_UI);
@@ -821,8 +818,7 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float kh = th * (float)L.rows / (float)F->n; float kh = th * (float)L.rows / (float)F->n;
if (kh < 24) kh = 24; if (kh < 24) kh = 24;
float ky = L.list_y + 4 + (th - kh) * (float)F->scroll / (float)(F->n - L.rows); float ky = L.list_y + 4 + (th - kh) * (float)F->scroll / (float)(F->n - L.rows);
rb_fill_rrect(rb, tx, L.list_y + 4, 6, th, 3, COL_UI_BG); rb_fill_rrect(rb, tx + 1, ky, 4, kh, 2, m3_alpha(M3_ON_SURFACE, 0.38f));
rb_fill_rrect(rb, tx, ky, 6, kh, 3, COL_TEXT_DIM);
} }
if (F->err[0]) { if (F->err[0]) {
float ey = L.list_y + L.list_h - 30; float ey = L.list_y + L.list_h - 30;
@@ -833,10 +829,9 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
/* Rodape: nome + opcoes + botoes */ /* Rodape: nome + opcoes + botoes */
float foot = L.name_y - 14.f; float foot = L.name_y - 14.f;
rb_line(rb, L.x, foot, L.x + L.w, foot, 1, COL_BORDER); rb_line(rb, L.x, foot, L.x + L.w, foot, 1, M3_OUTLINE_VAR);
rb_text_c(rb, L.x + FD_PAD, L.name_y + 15, "Nome:", COL_TEXT, FS_UI); rb_text_f(rb, L.x + FD_PAD + 4, L.name_y + 15, "Nome:", M3_ON_SURFACE, M3_BODY_M, TB_FONT_MEDIUM);
rb_fill_rrect(rb, L.name_x, L.name_y, L.name_w, 30, 6, COL_MENU); m3_field(rb, L.name_x, L.name_y - 3, L.name_w, 36, true, M3_PRIMARY);
rb_fill_rrect(rb, L.name_x + 1.5f, L.name_y + 1.5f, L.name_w - 3, 27, 5, COL_WHITE);
{ {
float maxw = L.name_w - 24; float maxw = L.name_w - 24;
const char* s = F->name; const char* s = F->name;
@@ -860,7 +855,7 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
char f2[120]; char f2[120];
snprintf(f2, sizeof(f2), "(%s)", F->filter); snprintf(f2, sizeof(f2), "(%s)", F->filter);
fd_fit(buf, sizeof(buf), f2, FS_SM, L.chk_hid_x - L.chk_all_x - 160); fd_fit(buf, sizeof(buf), f2, FS_SM, L.chk_hid_x - L.chk_all_x - 160);
rb_text_c(rb, L.chk_all_x + 24 + tw("Todos os arquivos", FS_UI) + 8, r2, buf, COL_TEXT_DIM, FS_SM); rb_text_f(rb, L.chk_all_x + 28 + tw("Todos os arquivos", M3_BODY_M) + 10, r2, buf, M3_ON_SURFACE_VAR, M3_BODY_S, TB_FONT_REGULAR);
} }
} }
fd_checkbox(rb, L.chk_hid_x, r2, F->show_hidden, "Mostrar ocultos"); fd_checkbox(rb, L.chk_hid_x, r2, F->show_hidden, "Mostrar ocultos");
@@ -871,18 +866,17 @@ void tb_editor_files_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
/* Confirmacao de substituicao */ /* Confirmacao de substituicao */
if (F->confirm) { if (F->confirm) {
rb_fill_rrect(rb, L.x, L.y, L.w, L.h, 12, COLA(0, 0, 0, 60)); rb_fill_rrect(rb, L.x, L.y, L.w, L.h, M3_SHAPE_XL, COLA(0, 0, 0, 60));
float bx, by, bw, bh; float bx, by, bw, bh;
fd_confirm_geom(&L, &bx, &by, &bw, &bh); fd_confirm_geom(&L, &bx, &by, &bw, &bh);
rb_fill_rrect(rb, bx + 2, by + 3, bw, bh, 10, COLA(0, 0, 0, 60)); m3_dialog_surface(rb, bx, by, bw, bh);
rb_fill_rrect(rb, bx, by, bw, bh, 10, COL_PANEL);
const char* b = strrchr(F->name, '/'); const char* b = strrchr(F->name, '/');
b = b ? b + 1 : F->name; b = b ? b + 1 : F->name;
char q[400]; char q[400];
snprintf(q, sizeof(q), "\"%s\" já existe.", b); snprintf(q, sizeof(q), "\"%s\" já existe.", b);
fd_fit(buf, sizeof(buf), q, 15, bw - 40); fd_fit(buf, sizeof(buf), q, 15, bw - 40);
rb_text_c(rb, bx + 20, by + 34, buf, COL_TEXT, 15); rb_text_f(rb, bx + 24, by + 36, buf, M3_ON_SURFACE, M3_TITLE_L - 2, TB_FONT_REGULAR);
rb_text_c(rb, bx + 20, by + 60, "Deseja substituir o arquivo?", COL_TEXT_DIM, FS_UI); rb_text_f(rb, bx + 24, by + 64, "Deseja substituir o arquivo?", M3_ON_SURFACE_VAR, M3_BODY_M, TB_FONT_REGULAR);
float yb = by + bh - FD_BTN_H - 16; float yb = by + bh - FD_BTN_H - 16;
float xo = bx + bw - 20 - FD_BTN_W, xc = xo - 10 - FD_BTN_W; float xo = bx + bw - 20 - FD_BTN_W, xc = xo - 10 - FD_BTN_W;
fd_button(rb, xc, yb, FD_BTN_W, FD_BTN_H, "Cancelar", false, fd_button(rb, xc, yb, FD_BTN_W, FD_BTN_H, "Cancelar", false,
@@ -180,10 +180,10 @@ static float img_pal_y(Ed* ed) {
static void img_zoom_slider(Ed* ed, float* x, float* y, float* w, float* h) { static void img_zoom_slider(Ed* ed, float* x, float* y, float* w, float* h) {
float ax, ay, aw, ah; float ax, ay, aw, ah;
img_area(ed, &ax, &ay, &aw, &ah); img_area(ed, &ax, &ay, &aw, &ah);
*x = ax + 176; *x = ax + 8 + 112 + 4 + 96 + 20; /* depois de Desfazer e Limpar */
*w = aw - 176 - 14; *w = aw - (8 + 112 + 4 + 96 + 20) - 28;
*h = IMG_SLIDER_H; *h = IMG_SLIDER_H;
*y = img_foot_y(ed) + 22.f; *y = img_foot_y(ed) + (IMG_FOOT_H - IMG_SLIDER_H) * 0.5f + 4.f;
(void)h; (void)ah; (void)h; (void)ah;
*h = IMG_SLIDER_H; *h = IMG_SLIDER_H;
} }
@@ -214,10 +214,10 @@ static void img_foot_btn(Ed* ed, int which, float* x, float* y, float* w, float*
float ax, ay, aw, ah, fy; float ax, ay, aw, ah, fy;
img_area(ed, &ax, &ay, &aw, &ah); img_area(ed, &ax, &ay, &aw, &ah);
fy = img_foot_y(ed); fy = img_foot_y(ed);
*y = fy + 5; *h = 24; *y = fy + 3; *h = 28;
switch (which) { switch (which) {
case 0: *w = 78; *x = ax + 10; break; /* Desfazer */ case 0: *w = 112; *x = ax + 8; break; /* Desfazer */
case 1: *w = 68; *x = ax + 96; break; /* Limpar */ case 1: *w = 96; *x = ax + 8 + 112 + 4; break; /* Limpar */
default: *w = 30; *x = ax + aw - 40; break; default: *w = 30; *x = ax + aw - 40; break;
} }
@@ -644,40 +644,14 @@ static void img_undo_do(Tab* T) {
T->img_rev++; T->img_rev++;
} }
/* Icones das ferramentas --- */ /* Icones das ferramentas (Material Symbols) --- */
static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c) { static const unsigned IMG_TOOL_ICON[IT_N] = {
switch (tool) { [IT_SEL] = 0xf82f /* arrow_selector_tool */, [IT_BRUSH] = MI_BRUSH, [IT_LINE] = 0xf41e /* diagonal_line */,
case IT_SEL: [IT_RECT] = MI_RECTANGLE, [IT_ELLIPSE] = MI_CIRCLE, [IT_FILL] = MI_FILL,
rb_line(rb, cx - 6, cy - 8, cx - 6, cy + 7, 2.f, c); [IT_ERASER] = MI_ERASER, [IT_PICK] = MI_COLORIZE,
rb_line(rb, cx - 6, cy - 8, cx + 5, cy + 1, 2.f, c); };
rb_line(rb, cx - 6, cy - 1, cx + 3, cy + 7, 2.f, c); static void img_draw_icon(TinyBlocks_RenderableBlock* rb, int tool, float cx, float cy, Col c, bool on) {
break; rb_icon(rb, cx, cy, IMG_TOOL_ICON[tool], 24.f, c, on);
case IT_BRUSH:
rb_line(rb, cx - 8, cy + 8, cx + 3, cy - 3, 5.f, c);
rb_fill_circle(rb, cx + 6, cy - 6, 3.4f, c);
break;
case IT_LINE:
rb_line(rb, cx - 8, cy + 8, cx + 8, cy - 8, 2.f, c);
break;
case IT_RECT:
rb_stroke_rect(rb, cx - 8, cy - 6, 16, 12, 2.f, c);
break;
case IT_ELLIPSE:
rb_stroke_circle(rb, cx, cy, 8, 2.f, c);
break;
case IT_FILL:
rb_fill_rrect(rb, cx - 8, cy - 8, 13, 13, 3, c);
rb_fill_circle(rb, cx + 4, cy + 5, 4, c);
break;
case IT_ERASER:
rb_fill_rrect(rb, cx - 8, cy - 3, 16, 9, 2, c);
rb_line(rb, cx - 8, cy + 6, cx + 8, cy + 6, 2.f, col_mul(c, 0.6f));
break;
case IT_PICK:
rb_line(rb, cx + 7, cy - 7, cx + 2, cy - 2, 3.f, c);
rb_fill_circle(rb, cx - 2, cy + 2, 4.4f, c);
break;
}
} }
/* Render --- */ /* Render --- */
@@ -810,32 +784,33 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_fill_rect(rb, WS_X, WS_Y, WS_W, WS_H, COL_PAINT_BG); rb_fill_rect(rb, WS_X, WS_Y, WS_W, WS_H, COL_PAINT_BG);
/* --- coluna esquerda: ferramentas --- */ /* --- coluna esquerda: ferramentas --- */
rb_fill_rect(rb, WS_X, WS_Y, IMG_TOOL_W, WS_H, COL_PANEL); rb_fill_rect(rb, WS_X, WS_Y, IMG_TOOL_W, WS_H, M3_SURFACE);
rb_line(rb, WS_X + IMG_TOOL_W - 1, WS_Y, WS_X + IMG_TOOL_W - 1, WS_Y + WS_H, 1.f, COL_PAINT_LINE); rb_line(rb, WS_X + IMG_TOOL_W - 1, WS_Y, WS_X + IMG_TOOL_W - 1, WS_Y + WS_H, 1.f, M3_OUTLINE_VAR);
for (int i = 0; i < IT_N; i++) { for (int i = 0; i < IT_N; i++) { /* icon buttons de alternar (M3) */
float bx, by; float bx, by;
img_tool_rect(ed, i, &bx, &by); img_tool_rect(ed, i, &bx, &by);
bool sel = T->img_tool == i; bool sel = T->img_tool == i;
bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, IMG_TH, IMG_TH); bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, IMG_TH, IMG_TH);
Col bg = sel ? COL_MENU : (hov ? COL_HOVER : COL_PAINT_BTN); if (sel) rb_fill_rrect(rb, bx, by, IMG_TH, IMG_TH, M3_SHAPE_M, M3_PRIMARY);
rb_fill_rrect(rb, bx, by, IMG_TH, IMG_TH, 8, bg); m3_state(rb, bx, by, IMG_TH, IMG_TH, M3_SHAPE_M, sel ? M3_ON_PRIMARY : M3_ON_SURFACE, hov, false);
if (!sel) rb_stroke_rect(rb, bx, by, IMG_TH, IMG_TH, 1.f, COL_PAINT_LINE); img_draw_icon(rb, i, bx + IMG_TH * 0.5f, by + IMG_TH * 0.5f, sel ? M3_ON_PRIMARY : M3_ON_SURFACE_VAR, sel);
img_draw_icon(rb, i, bx + IMG_TH * 0.5f, by + IMG_TH * 0.5f, sel ? COL_WHITE : COL_TEXT); if (hov && !sel) { /* tooltip simples do M3 */
if (hov && !sel) const char* tip = img_tool_tip(i);
rb_text_c(rb, bx + IMG_TH + 6, by + IMG_TH * 0.5f, img_tool_tip(i), COL_TEXT_DIM, 10.f); float tw_ = tw(tip, M3_BODY_S) + 16, ty = by + IMG_TH * 0.5f - 12;
rb_fill_rrect(rb, bx + IMG_TH + 6, ty, tw_, 24, M3_SHAPE_XS, M3_INVERSE_SURFACE);
rb_text_f(rb, bx + IMG_TH + 14, ty + 12, tip, M3_INVERSE_ON_SURFACE, M3_BODY_S, TB_FONT_REGULAR);
}
} }
/* --- barra superior (arquivo) --- */ /* --- barra superior (arquivo) --- */
rb_fill_rect(rb, WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H, COL_PANEL); rb_fill_rect(rb, WS_X + IMG_TOOL_W, WS_Y, WS_W - IMG_TOOL_W, IMG_BAR_H, M3_SURFACE);
rb_line(rb, WS_X + IMG_TOOL_W, WS_Y + IMG_BAR_H - 1, rb_line(rb, WS_X + IMG_TOOL_W, WS_Y + IMG_BAR_H - 1,
WS_X + WS_W, WS_Y + IMG_BAR_H - 1, 1.f, COL_PAINT_LINE); WS_X + WS_W, WS_Y + IMG_BAR_H - 1, 1.f, M3_OUTLINE_VAR);
{ {
float bx = WS_X + IMG_TOOL_W + 10; float bx = WS_X + IMG_TOOL_W + 10, mx = ed->mouse_x, my = ed->mouse_y;
rb_fill_rrect(rb, bx, WS_Y + 5, 62, 24, 6, COL_MENU); m3_button(rb, M3_TONAL, bx, WS_Y + 4, 62, 26, "Abrir", 0, M3_PRIMARY, in_rect(mx, my, bx, WS_Y + 4, 62, 26), false);
rb_text_c(rb, bx + (62 - tw("Abrir", FS_UI-1)) * 0.5f, WS_Y + 17, "Abrir", COL_WHITE, FS_UI-1);
bx += 70; bx += 70;
rb_fill_rrect(rb, bx, WS_Y + 5, 62, 24, 6, COL_MENU_DARK); m3_button(rb, M3_FILLED, bx, WS_Y + 4, 62, 26, "Salvar", 0, M3_PRIMARY, in_rect(mx, my, bx, WS_Y + 4, 62, 26), false);
rb_text_c(rb, bx + (62 - tw("Salvar", FS_UI-1)) * 0.5f, WS_Y + 17, "Salvar", COL_WHITE, FS_UI-1);
bx += 74; bx += 74;
char pbuf[40]; char pbuf[40];
snprintf(pbuf, sizeof(pbuf), "%.30s", T->img_path[0] ? T->img_path : "sem arquivo"); snprintf(pbuf, sizeof(pbuf), "%.30s", T->img_path[0] ? T->img_path : "sem arquivo");
@@ -848,8 +823,8 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
(int)(T->img_zoom * 100.f + 0.5f), T->img_w, T->img_h); (int)(T->img_zoom * 100.f + 0.5f), T->img_w, T->img_h);
if (img_narrow(ed)) { /* sem espaco para o resumo: botao da coluna */ if (img_narrow(ed)) { /* sem espaco para o resumo: botao da coluna */
float cx = WS_X + WS_W - IMG_PANEL_BTN_W - 8; float cx = WS_X + WS_W - IMG_PANEL_BTN_W - 8;
rb_fill_rrect(rb, cx, WS_Y + 5, IMG_PANEL_BTN_W, 24, 6, ed->img_panel_open ? COL_MENU_DARK : COL_MENU); m3_button(rb, ed->img_panel_open ? M3_FILLED : M3_TONAL, cx, WS_Y + 4, IMG_PANEL_BTN_W, 26, "Cores", 0,
rb_text_c(rb, cx + (IMG_PANEL_BTN_W - tw("Cores", FS_UI-1)) * 0.5f, WS_Y + 17, "Cores", COL_WHITE, FS_UI-1); M3_PRIMARY, in_rect(ed->mouse_x, ed->mouse_y, cx, WS_Y + 4, IMG_PANEL_BTN_W, 26), false);
} else } else
rb_text_c(rb, WS_X + WS_W - 12 - tw(info, FS_UI-1), WS_Y + 17, info, COL_TEXT_DIM, FS_UI-1); rb_text_c(rb, WS_X + WS_W - 12 - tw(info, FS_UI-1), WS_Y + 17, info, COL_TEXT_DIM, FS_UI-1);
} }
@@ -926,18 +901,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float ax, ay, aw, ah, fy; float ax, ay, aw, ah, fy;
img_area(ed, &ax, &ay, &aw, &ah); img_area(ed, &ax, &ay, &aw, &ah);
fy = img_foot_y(ed); fy = img_foot_y(ed);
rb_fill_rect(rb, ax, fy, aw, IMG_FOOT_H, COL_PANEL); rb_fill_rect(rb, ax, fy, aw, IMG_FOOT_H, M3_SURFACE);
rb_line(rb, ax, fy, WS_X + WS_W, fy, 1.f, COL_PAINT_LINE); rb_line(rb, ax, fy, WS_X + WS_W, fy, 1.f, M3_OUTLINE_VAR);
const char* labels[2] = { "Desfazer", "Limpar" }; const char* labels[2] = { "Desfazer", "Limpar" };
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) { /* botoes de texto com icone */
float bx, by, bw, bh; float bx, by, bw, bh;
img_foot_btn(ed, i, &bx, &by, &bw, &bh); img_foot_btn(ed, i, &bx, &by, &bw, &bh);
bool enabled = !(i == 0 && T->img_undo_n == 0); bool enabled = !(i == 0 && T->img_undo_n == 0);
bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, bw, bh); bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx, by, bw, bh);
rb_fill_rrect(rb, bx, by, bw, bh, 6, hov && enabled ? COL_HOVER : COL_PAINT_BTN); m3_button(rb, M3_TEXT, bx, by, bw, bh, labels[i], i == 0 ? MI_UNDO : MI_DELETE,
rb_stroke_rect(rb, bx, by, bw, bh, 1.f, COL_PAINT_LINE); enabled ? M3_PRIMARY : m3_alpha(M3_ON_SURFACE, 0.38f), hov && enabled, false);
rb_text_c(rb, bx + (bw - tw(labels[i], FS_UI-1)) * 0.5f, by + bh * 0.5f,
labels[i], enabled ? COL_TEXT : COL_TEXT_DIM, FS_UI - 1);
} }
/* --- widget novo: slider de zoom --- */ /* --- widget novo: slider de zoom --- */
@@ -947,19 +920,17 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
float t = img_zoom_t(T->img_zoom); float t = img_zoom_t(T->img_zoom);
float kx = sx + t * (sw - 14.f) + 7.f; float kx = sx + t * (sw - 14.f) + 7.f;
bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx - 6, sy - 10, sw + 12, sh + 20); bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx - 6, sy - 10, sw + 12, sh + 20);
/* trilha */ /* slider do M3: trilha ativa (primaria) e inativa (container) */
rb_fill_rrect(rb, sx, sy, sw, sh, 3, COL_PAINT_BTN); float tcy = sy + sh * 0.5f;
/* parte preenchida ate o botao */ rb_fill_rrect(rb, sx, tcy - 2, sw, 4, 2, M3_SECONDARY_CONTAINER);
rb_fill_rrect(rb, sx, sy, kx - sx, sh, 3, hov ? COL_MENU : COLA(0, 122, 216, 255)); rb_fill_rrect(rb, sx, tcy - 2, kx - sx, 4, 2, M3_PRIMARY);
rb_stroke_rect(rb, sx, sy, sw, sh, 1.f, COL_PAINT_LINE); { /* marca de 100% */
/* marcas de 100% */
{
float mxr = sx + img_zoom_t(1.f) * (sw - 14.f) + 7.f; float mxr = sx + img_zoom_t(1.f) * (sw - 14.f) + 7.f;
rb_fill_rect(rb, mxr - 0.5f, sy - 3, 1.f, sh + 6, COL_TEXT_DIM); rb_fill_circle(rb, mxr, tcy, 1.5f, kx > mxr ? M3_ON_PRIMARY : M3_PRIMARY);
} }
/* botao */ /* alca */
rb_fill_circle(rb, kx, sy + sh * 0.5f, 7.f, COL_WHITE); if (hov) rb_fill_circle(rb, kx, tcy, 14.f, m3_alpha(M3_PRIMARY, M3_HOVER));
rb_stroke_circle(rb, kx, sy + sh * 0.5f, 7.f, 2.f, hov ? COL_MENU : COLA(0, 122, 216, 255)); rb_fill_circle(rb, kx, tcy, 8.f, M3_PRIMARY);
/* porcentagem acima do botao */ /* porcentagem acima do botao */
{ {
char z[16]; char z[16];
@@ -976,16 +947,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
if (img_panel_shown(ed)) { if (img_panel_shown(ed)) {
float px = img_color_x(ed); float px = img_color_x(ed);
float cx_, cy_, ro, ri; float cx_, cy_, ro, ri;
rb_fill_rect(rb, px, WS_Y, IMG_RIGHT_W, WS_H, COL_PANEL); rb_fill_rect(rb, px, WS_Y, IMG_RIGHT_W, WS_H, M3_SURFACE);
rb_line(rb, px - 1, WS_Y, px - 1, WS_Y + WS_H, 1.f, COL_PAINT_LINE); rb_line(rb, px - 1, WS_Y, px - 1, WS_Y + WS_H, 1.f, M3_OUTLINE_VAR);
rb_text_c(rb, px + 12, WS_Y + 16, "Cores", COL_TEXT_DIM, 11.f); rb_text_f(rb, px + 12, WS_Y + 18, "Cores", M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM);
/* amostra da cor atual */ /* amostra da cor atual */
{ {
Col cc = COLA(T->img_rgb[0], T->img_rgb[1], T->img_rgb[2], 255); Col cc = COLA(T->img_rgb[0], T->img_rgb[1], T->img_rgb[2], 255);
float sw = 30.f, sx = px + IMG_RIGHT_W - 14 - sw; float sw = 30.f, sx = px + IMG_RIGHT_W - 14 - sw;
rb_fill_rrect(rb, sx, WS_Y + 5, sw, sw, 5, COL_PAINT_LINE); rb_fill_circle(rb, sx + sw * 0.5f, WS_Y + 5 + sw * 0.5f, sw * 0.5f, M3_OUTLINE_VAR);
rb_fill_rrect(rb, sx + 2, WS_Y + 7, sw - 4, sw - 4, 4, cc); rb_fill_circle(rb, sx + sw * 0.5f, WS_Y + 5 + sw * 0.5f, sw * 0.5f - 2, cc);
} }
/* roda de matiz: linhas radiais coloridas */ /* roda de matiz: linhas radiais coloridas */
@@ -1025,15 +996,15 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
rb_stroke_circle(rb, mx_, my_, 5.f, 1.2f, COL_TEXT); rb_stroke_circle(rb, mx_, my_, 5.f, 1.2f, COL_TEXT);
} }
/* paleta rapida (3 x 4) */ /* paleta rapida (3 x 4) */
rb_text_c(rb, px + 12, img_pal_y(ed) - 14, "Paleta", COL_TEXT_DIM, 10.f); rb_text_f(rb, px + 12, img_pal_y(ed) - 14, "Paleta", M3_ON_SURFACE_VAR, M3_LABEL_M, TB_FONT_MEDIUM);
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
float sx, sy; float sx, sy;
img_swatch_rect(ed, i, &sx, &sy); img_swatch_rect(ed, i, &sx, &sy);
bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx, sy, 34, 22); bool hov = in_rect(ed->mouse_x, ed->mouse_y, sx, sy, 34, 22);
rb_fill_rrect(rb, sx, sy, 34, 22, 4, COL_PAINT_LINE); bool on = i == T->img_swatch;
rb_fill_rrect(rb, sx + 2, sy + 2, 30, 18, 3, IMG_PALETTE[i]); if (on || hov) rb_fill_rrect(rb, sx - 2, sy - 2, 38, 26, M3_SHAPE_S, on ? M3_PRIMARY : M3_OUTLINE);
if (i == T->img_swatch) rb_stroke_rect(rb, sx - 1, sy - 1, 36, 24, 2.f, COL_MENU); rb_fill_rrect(rb, sx, sy, 34, 22, M3_SHAPE_S - 2, on || hov ? M3_SURFACE : M3_OUTLINE_VAR);
else if (hov) rb_stroke_rect(rb, sx - 1, sy - 1, 36, 24, 1.4f, COL_TEXT_DIM); rb_fill_rrect(rb, sx + 2, sy + 2, 30, 18, M3_SHAPE_S - 3, IMG_PALETTE[i]);
} }
/* informacao da cor escolhida */ /* informacao da cor escolhida */
{ {
@@ -1044,19 +1015,21 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
/* --- camadas: embaixo da roda de cores (como no Krita) --- */ /* --- camadas: embaixo da roda de cores (como no Krita) --- */
rb_line(rb, px + IMG_PAD, img_layers_title_y(ed) - 14, rb_line(rb, px + IMG_PAD, img_layers_title_y(ed) - 14,
px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, COL_PAINT_LINE); px + IMG_RIGHT_W - IMG_PAD, img_layers_title_y(ed) - 14, 1.f, M3_OUTLINE_VAR);
rb_text_c(rb, px + IMG_PAD, img_layers_title_y(ed), "Camadas", COL_TEXT_DIM, 11.f); rb_icon(rb, px + IMG_PAD + 9, img_layers_title_y(ed), 0xe53b /* layers */, 18.f, M3_ON_SURFACE_VAR, false);
rb_text_f(rb, px + IMG_PAD + 24, img_layers_title_y(ed), "Camadas", M3_ON_SURFACE, M3_TITLE_S, TB_FONT_MEDIUM);
for (int i = 0; i < T->img_layer_n; i++) { for (int i = 0; i < T->img_layer_n; i++) {
float rx, ry, rw, rh; float rx, ry, rw, rh;
img_layer_row(ed, i, &rx, &ry, &rw, &rh); img_layer_row(ed, i, &rx, &ry, &rw, &rh);
bool sel = (i == T->img_layer_cur); bool sel = (i == T->img_layer_cur);
bool hov = in_rect(ed->mouse_x, ed->mouse_y, rx, ry, rw, rh); bool hov = in_rect(ed->mouse_x, ed->mouse_y, rx, ry, rw, rh);
rb_fill_rrect(rb, rx, ry, rw, rh, 6, sel ? COL_MENU : (hov ? COL_HOVER : COL_PAINT_BTN)); /* item de lista do M3; selecionado = container */
rb_stroke_rect(rb, rx, ry, rw, rh, 1.f, sel ? COL_MENU_DARK : COL_PAINT_LINE); if (sel) rb_fill_rrect(rb, rx, ry, rw, rh, M3_SHAPE_S, M3_SECONDARY_CONTAINER);
Col tc = sel ? COL_WHITE : COL_TEXT; m3_state(rb, rx, ry, rw, rh, M3_SHAPE_S, M3_ON_SURFACE, hov, false);
Col tc = M3_ON_SURFACE;
/* olho (visibilidade) */ /* olho (visibilidade) */
if (T->img_layers[i].visible) rb_fill_circle(rb, rx + 11, ry + rh * 0.5f, 4.5f, tc); rb_icon(rb, rx + 11, ry + rh * 0.5f, T->img_layers[i].visible ? 0xe8f4 : 0xe8f5, 16.f,
else rb_stroke_circle(rb, rx + 11, ry + rh * 0.5f, 4.5f, 1.4f, tc); M3_ON_SURFACE_VAR, false);
/* miniatura (como uma fantasia do Scratch) */ /* miniatura (como uma fantasia do Scratch) */
{ {
float tx = rx + 20, ty = ry + 4, tw_ = rw - 26, th_ = rh - 8; float tx = rx + 20, ty = ry + 4, tw_ = rw - 26, th_ = rh - 8;
@@ -1076,17 +1049,16 @@ void tb_editor_image_view(Ed* ed, TinyBlocks_RenderableBlock* rb) {
} }
/* botoes: excluir / nova raster / nova vetor */ /* botoes: excluir / nova raster / nova vetor */
{ {
const char* labels[3] = { "- Camada", "+ Raster", "+ Vetor" }; const char* labels[3] = { "Camada", "Raster", "Vetor" };
Col bgs[3] = { {236/255.f,120/255.f,110/255.f,1.f}, COL_MENU, COL_L_VECTOR }; static const unsigned icons[3] = { 0xe15b /* remove */, MI_ADD, MI_ADD };
Col bgs[3] = { COL_STOP, M3_PRIMARY, COL_L_VECTOR };
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
float bx2, by2, bw2, bh2; float bx2, by2, bw2, bh2;
img_side_btn(ed, i, &bx2, &by2, &bw2, &bh2); img_side_btn(ed, i, &bx2, &by2, &bw2, &bh2);
bool enabled = !(i == 0 && T->img_layer_n <= 1); bool enabled = !(i == 0 && T->img_layer_n <= 1);
bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx2, by2, bw2, bh2); bool hov = in_rect(ed->mouse_x, ed->mouse_y, bx2, by2, bw2, bh2);
Col bg = enabled ? (hov ? col_mul(bgs[i], 0.85f) : bgs[i]) : COL_PAINT_SHAD; m3_button(rb, i == 0 ? M3_OUTLINED : M3_TONAL, bx2, by2, bw2, bh2, labels[i], icons[i],
rb_fill_rrect(rb, bx2, by2, bw2, bh2, 6, bg); enabled ? bgs[i] : m3_alpha(M3_ON_SURFACE, 0.38f), hov && enabled, false);
rb_text_c(rb, bx2 + (bw2 - tw(labels[i], FS_UI-1)) * 0.5f, by2 + bh2 * 0.5f,
labels[i], COL_WHITE, FS_UI - 1);
} }
} }
} }
@@ -36,6 +36,15 @@ void tb_ew_line (TinyBlocks_RenderableBlock* rb, float x0, float y0, float
void tb_ew_text_c (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs); void tb_ew_text_c (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs);
/* Largura real do texto, medida pelo backend grafico */ /* Largura real do texto, medida pelo backend grafico */
float tb_ew_text_width(const char* s, float fs); float tb_ew_text_width(const char* s, float fs);
/* Texto numa fonte (TB_FONT_REGULAR / TB_FONT_MEDIUM), centrado em cy */
void tb_ew_text_f (TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs,
int font);
/* Icone do Material Symbols (codepoint, ex.: 0xE8B8 = settings) centrado em
* (cx, cy); size = lado do icone (24 no Material 3) */
void tb_ew_icon (TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned cp, float size, TbEwColor c,
bool filled);
/* Sombra de elevacao do Material 3 (level 1..5) atras de (x, y, w, h) */
void tb_ew_shadow (TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, int level);
bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h); bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h);
@@ -40,5 +40,39 @@ float tb_ew_text_width(const char* s, float fs) {
return tb_graphics_measure_text(s, fs); return tb_graphics_measure_text(s, fs);
} }
void tb_ew_text_f(TinyBlocks_RenderableBlock* rb, float x, float cy, const char* s, TbEwColor c, float fs,
int font) {
if (!s || !s[0]) return;
tb_draw_text_font(rb, x, cy + fs * 0.36f, s, fs, font, c.r, c.g, c.b, c.a);
}
void tb_ew_icon(TinyBlocks_RenderableBlock* rb, float cx, float cy, unsigned cp, float size, TbEwColor c,
bool filled) {
char u[5] = {0}; /* UTF-8 do codepoint (area privada: 3 bytes) */
if (cp < 0x800) { u[0] = (char)(0xC0 | (cp >> 6)); u[1] = (char)(0x80 | (cp & 0x3F)); }
else if (cp < 0x10000) {
u[0] = (char)(0xE0 | (cp >> 12)); u[1] = (char)(0x80 | ((cp >> 6) & 0x3F));
u[2] = (char)(0x80 | (cp & 0x3F));
} else {
u[0] = (char)(0xF0 | (cp >> 18)); u[1] = (char)(0x80 | ((cp >> 12) & 0x3F));
u[2] = (char)(0x80 | ((cp >> 6) & 0x3F)); u[3] = (char)(0x80 | (cp & 0x3F));
}
/* o glifo ocupa 1 em acima da linha de base, avanco = 1 em */
tb_draw_text_font(rb, cx - size * 0.5f, cy + size * 0.5f, u, size,
filled ? TB_FONT_ICON_FILLED : TB_FONT_ICON, c.r, c.g, c.b, c.a);
}
void tb_ew_shadow(TinyBlocks_RenderableBlock* rb, float x, float y, float w, float h, float rad, int level) {
if (level <= 0) return;
/* camadas cada vez maiores e mais fracas, puxadas para baixo (luz de cima) */
float dy = 0.5f + level * 0.75f;
int n = 2 + level;
for (int i = n; i >= 1; i--) {
float g = (float)i;
float a = 0.10f / (float)n * (float)(n - i + 1) * (0.6f + 0.1f * level);
tb_draw_fill_rrect(rb, x - g * 0.5f, y - g * 0.5f + dy, w + g, h + g, rad + g * 0.5f, 0, 0, 0, a);
}
}
bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h) bool tb_ew_in_rect(float mx, float my, float x, float y, float w, float h)
{ return mx >= x && mx < x + w && my >= y && my < y + h; } { return mx >= x && mx < x + w && my >= y && my < y + h; }
File diff suppressed because it is too large. Load diff
@@ -124,8 +124,12 @@ static bool resolve_widgets(void) {
sym_fn(&w.text_c, "tinyblocks-editor-widgets", "tb_ew_text_c"); sym_fn(&w.text_c, "tinyblocks-editor-widgets", "tb_ew_text_c");
sym_fn(&w.text_width, "tinyblocks-editor-widgets", "tb_ew_text_width"); sym_fn(&w.text_width, "tinyblocks-editor-widgets", "tb_ew_text_width");
sym_fn(&w.in_rect, "tinyblocks-editor-widgets", "tb_ew_in_rect"); sym_fn(&w.in_rect, "tinyblocks-editor-widgets", "tb_ew_in_rect");
sym_fn(&w.text_f, "tinyblocks-editor-widgets", "tb_ew_text_f");
sym_fn(&w.icon, "tinyblocks-editor-widgets", "tb_ew_icon");
sym_fn(&w.shadow, "tinyblocks-editor-widgets", "tb_ew_shadow");
bool ok = w.col_mul && w.fill_rect && w.fill_rrect && w.fill_circle && w.stroke_rect && bool ok = w.col_mul && w.fill_rect && w.fill_rrect && w.fill_circle && w.stroke_rect &&
w.stroke_circle && w.line && w.text_c && w.text_width && w.in_rect; w.stroke_circle && w.line && w.text_c && w.text_width && w.in_rect &&
w.text_f && w.icon && w.shadow;
if (ok) tb_ed_w = w; if (ok) tb_ed_w = w;
return ok; return ok;
} }
@@ -174,7 +178,8 @@ bool tb_ed_modules_load(Ed* ed) {
.col_mul = tb_ew_col_mul, .fill_rect = tb_ew_fill_rect, .fill_rrect = tb_ew_fill_rrect, .col_mul = tb_ew_col_mul, .fill_rect = tb_ew_fill_rect, .fill_rrect = tb_ew_fill_rrect,
.fill_circle = tb_ew_fill_circle, .stroke_rect = tb_ew_stroke_rect, .fill_circle = tb_ew_fill_circle, .stroke_rect = tb_ew_stroke_rect,
.stroke_circle = tb_ew_stroke_circle, .line = tb_ew_line, .text_c = tb_ew_text_c, .stroke_circle = tb_ew_stroke_circle, .line = tb_ew_line, .text_c = tb_ew_text_c,
.text_width = tb_ew_text_width, .in_rect = tb_ew_in_rect }; .text_width = tb_ew_text_width, .in_rect = tb_ew_in_rect,
.text_f = tb_ew_text_f, .icon = tb_ew_icon, .shadow = tb_ew_shadow };
tb_ed_img = (TbEdImageApi){ tb_ed_img = (TbEdImageApi){
.view = tb_editor_image_view, .click = tb_editor_image_click, .drag = tb_editor_image_drag, .view = tb_editor_image_view, .click = tb_editor_image_click, .drag = tb_editor_image_drag,
.release = tb_editor_image_release, .load_file = tb_editor_image_load_file, .release = tb_editor_image_release, .load_file = tb_editor_image_load_file,
+75 -12
View File
@@ -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_CACHE_CAP 64 /* o zoom da area de scripts pede muitos tamanhos */
#define FONT_SEARCH_COUNT 9 #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 FontEntry s_font_cache[FONT_CACHE_CAP];
static int s_font_cache_n = 0; 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", "C:/Windows/Fonts/arial.ttf",
}; };
/* A fonte que vai junto do programa (pacote Windows, AppImage): /* Fontes que vao junto do programa (TB_FONT_*): Roboto e Material Symbols.
<pasta do executavel>/fonts/DejaVuSans.ttf */ 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) { static TTF_Font* bundled_font(int size) {
char path[1024]; char path[1024];
const char* dir = getenv("TINYBLOCKS_APPDIR"); const char* dir = getenv("TINYBLOCKS_APPDIR");
@@ -113,16 +142,24 @@ static TTF_Font* bundled_font(int size) {
return TTF_OpenFont(path, 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; static unsigned tick = 0;
tick++; tick++;
if (family < 0 || family >= TB_FONT_COUNT) family = TB_FONT_REGULAR;
for (int i = 0; i < s_font_cache_n; i++) 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); TTF_Font* f = family_font(family, size);
for (int i = 0; i < FONT_SEARCH_COUNT && !f; i++) if (!f && family == TB_FONT_MEDIUM) f = family_font(TB_FONT_REGULAR, size);
f = TTF_OpenFont(s_font_paths[i], size); if (!f && family <= TB_FONT_MEDIUM) { /* sem Roboto: DejaVu */
if (!f) return NULL; 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) */ /* cheio: fecha o usado ha mais tempo (antes vazava uma fonte por chamada) */
int slot = s_font_cache_n; int slot = s_font_cache_n;
@@ -133,6 +170,7 @@ static TTF_Font* get_font(int size) {
TTF_CloseFont(s_font_cache[slot].font); TTF_CloseFont(s_font_cache[slot].font);
} else s_font_cache_n++; } else s_font_cache_n++;
s_font_cache[slot].size = size; s_font_cache[slot].size = size;
s_font_cache[slot].family = family;
s_font_cache[slot].font = f; s_font_cache[slot].font = f;
s_font_cache[slot].used = tick; s_font_cache[slot].used = tick;
return f; return f;
@@ -330,7 +368,8 @@ static void sdl2_execute(SDL_Renderer* ren,
scaled = *cmd; scaled = *cmd;
scaled.x *= s_ui_scale; scaled.y *= s_ui_scale; scaled.x *= s_ui_scale; scaled.y *= s_ui_scale;
scaled.w *= s_ui_scale; scaled.h *= 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; cmd = &scaled;
} }
switch (cmd->kind) { switch (cmd->kind) {
@@ -429,7 +468,7 @@ static void sdl2_execute(SDL_Renderer* ren,
case TB_DRAW_TEXT: case TB_DRAW_TEXT:
if (cmd->text[0]) { 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) { if (font) {
SDL_Color col = { SDL_Color col = {
(Uint8)(cmd->r*255.f), (Uint8)(cmd->g*255.f), (Uint8)(cmd->r*255.f), (Uint8)(cmd->g*255.f),
@@ -866,18 +905,42 @@ static char* be_clipboard_get(void) {
return r; 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) { static void be_window_present(void* handle, const TinyBlocks_RenderableBlock* rb) {
SdlWin* w = (SdlWin*)handle; SdlWin* w = (SdlWin*)handle;
SDL_SetRenderDrawColor(w->ren, 0, 0, 0, 255); SDL_SetRenderDrawColor(w->ren, 0, 0, 0, 255);
SDL_RenderClear(w->ren); SDL_RenderClear(w->ren);
if (rb) sdl2_execute(w->ren, rb); if (rb) sdl2_execute(w->ren, rb);
shot_check(w);
SDL_RenderPresent(w->ren); SDL_RenderPresent(w->ren);
} }
static float be_measure_text(const char* text, float font_size) { static float be_measure_text(const char* text, float font_size) {
if (!be_init()) return 0.f; if (!be_init()) return 0.f;
const float S = s_ui_scale > 0.f ? s_ui_scale : 1.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; int w = 0, h = 0;
if (!font || TTF_SizeUTF8(font, text, &w, &h) != 0) return 0.f; if (!font || TTF_SizeUTF8(font, text, &w, &h) != 0) return 0.f;
return (float)w / S; /* largura em unidades logicas */ return (float)w / S; /* largura em unidades logicas */
+11 -1
View File
@@ -6,7 +6,7 @@
* 2. exporta TINYBLOCKS_APPDIR, que as libraries usam para achar a fonte * 2. exporta TINYBLOCKS_APPDIR, que as libraries usam para achar a fonte
* e os certificados (no Android nao existe /proc/self/exe do app nem * e os certificados (no Android nao existe /proc/self/exe do app nem
* SDL_GetBasePath); * SDL_GetBasePath);
* 3. copia dos assets para essa pasta a DejaVu e o ca-bundle.crt (o * 3. copia dos assets para essa pasta as fontes e o ca-bundle.crt (o
* SDL2_ttf e o OpenSSL precisam de caminho no sistema de arquivos). * SDL2_ttf e o OpenSSL precisam de caminho no sistema de arquivos).
* *
* Chamado do inicio do main() do editor, antes de qualquer library rodar. * Chamado do inicio do main() do editor, antes de qualquer library rodar.
@@ -68,6 +68,16 @@ void tb_android_boot(void) {
copy_asset(am, "fonts/DejaVuSans.ttf", dst); copy_asset(am, "fonts/DejaVuSans.ttf", dst);
snprintf(dst, sizeof(dst), "%s/fonts/DejaVuSansMono.ttf", dir); snprintf(dst, sizeof(dst), "%s/fonts/DejaVuSansMono.ttf", dir);
copy_asset(am, "fonts/DejaVuSansMono.ttf", dst); copy_asset(am, "fonts/DejaVuSansMono.ttf", dst);
static const char* const m3[] = { /* Roboto + Material Symbols (interface M3) */
"Roboto-Regular.ttf", "Roboto-Medium.ttf",
"MaterialSymbolsOutlined.ttf", "MaterialSymbolsFilled.ttf",
};
for (size_t i = 0; i < sizeof(m3) / sizeof(m3[0]); i++) {
char src[96];
snprintf(src, sizeof(src), "fonts/%s", m3[i]);
snprintf(dst, sizeof(dst), "%s/fonts/%s", dir, m3[i]);
copy_asset(am, src, dst);
}
snprintf(dst, sizeof(dst), "%s/certs/ca-bundle.crt", dir); snprintf(dst, sizeof(dst), "%s/certs/ca-bundle.crt", dir);
copy_asset(am, "certs/ca-bundle.crt", dst); copy_asset(am, "certs/ca-bundle.crt", dst);
} }
+1
View File
@@ -229,6 +229,7 @@ mipmaps() {
done done
cp /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf "$AND/assets/fonts/" cp /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf "$AND/assets/fonts/"
cp /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf "$AND/assets/fonts/" cp /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf "$AND/assets/fonts/"
cp "$ROOT"/assets/fonts/*.ttf "$ROOT"/assets/fonts/LICENSE-*.txt "$AND/assets/fonts/" # Roboto + Material Symbols
cp /etc/ssl/certs/ca-certificates.crt "$AND/assets/certs/ca-bundle.crt" cp /etc/ssl/certs/ca-certificates.crt "$AND/assets/certs/ca-bundle.crt"
} }
+2 -1
View File
@@ -117,10 +117,11 @@ win-pkg: $(WIN_EXE)
else cp $(WIN_DEPS)/share/pki/ca-trust-source/ca-bundle.trust.crt $(WIN_PKG)/certs/ca-bundle.crt; fi else cp $(WIN_DEPS)/share/pki/ca-trust-source/ca-bundle.trust.crt $(WIN_PKG)/certs/ca-bundle.crt; fi
@cp $(WIN_FONTS) $(WIN_PKG)/fonts/ || { echo "Falta a fonte DejaVu (pacote fonts-dejavu-core)"; exit 1; } @cp $(WIN_FONTS) $(WIN_PKG)/fonts/ || { echo "Falta a fonte DejaVu (pacote fonts-dejavu-core)"; exit 1; }
@cp $(WIN_FONT_LICENSE) $(WIN_PKG)/fonts/LICENSE.txt 2>/dev/null || true @cp $(WIN_FONT_LICENSE) $(WIN_PKG)/fonts/LICENSE.txt 2>/dev/null || true
@cp assets/fonts/*.ttf assets/fonts/LICENSE-*.txt $(WIN_PKG)/fonts/ # Roboto + Material Symbols
@cp -r examples/gan-animais $(WIN_PKG)/exemplos-gan-animais 2>/dev/null || true @cp -r examples/gan-animais $(WIN_PKG)/exemplos-gan-animais 2>/dev/null || true
@printf '%s\r\n' "TinyBlocks $(APP_VER) para Windows ($(WIN_ARCH))" "" \ @printf '%s\r\n' "TinyBlocks $(APP_VER) para Windows ($(WIN_ARCH))" "" \
"Abra TinyBlocks.exe. As DLLs desta pasta precisam ficar junto dele." \ "Abra TinyBlocks.exe. As DLLs desta pasta precisam ficar junto dele." \
"Fonte: DejaVu Sans (licenca livre, ver fonts/LICENSE.txt)." > $(WIN_PKG)/LEIA-ME.txt "Fontes: Roboto e Material Symbols (Apache 2.0) e DejaVu Sans (ver fonts/)." > $(WIN_PKG)/LEIA-ME.txt
exe: win-pkg ## Gera o TinyBlocks.exe para Windows (build/win-x86_64/TinyBlocks e o .zip) exe: win-pkg ## Gera o TinyBlocks.exe para Windows (build/win-x86_64/TinyBlocks e o .zip)
@rm -f $(WIN_ZIP) @rm -f $(WIN_ZIP)
+8
View File
@@ -125,6 +125,14 @@ void tb_draw_text(TinyBlocks_RenderableBlock* rb,
strncpy(c->text, text, sizeof(c->text) - 1); strncpy(c->text, text, sizeof(c->text) - 1);
} }
void tb_draw_text_font(TinyBlocks_RenderableBlock* rb,
float x, float y, const char* text, float font_size, int font,
float r, float g, float b, float a) {
uint32_t n = rb ? rb->count : 0;
tb_draw_text(rb, x, y, text, font_size, r, g, b, a);
if (rb && rb->count > n) rb->cmds[n].param = (float)font;
}
void tb_draw_image(TinyBlocks_RenderableBlock* rb, void tb_draw_image(TinyBlocks_RenderableBlock* rb,
float x, float y, float w, float h, float x, float y, float w, float h,
const TinyBlocks_Image* image) { const TinyBlocks_Image* image) {