@@ -27,6 +27,8 @@
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <tb_qr.h>
# include <tb_camera.h>
# include <math.h>
# include <unistd.h>
# include <dlfcn.h>
@@ -470,12 +472,23 @@ void blk_release(Tab* T, int i) {
parametros de uma camada da tinyblocks - tensor . */
static uint64_t s_blk_uid ;
/* Criado por codigo (agente MCP, scratchblocks colado): surge animado, em
cascata na ordem de criacao */
static void blk_mark_appear ( Tab * T , int i ) {
Ed * ed = g_active_ed ;
if ( ! ed | | ! ed - > appear_batch | | ed - > anim_off | | T = = & ed - > fly ) return ;
int k = ed - > appear_k < 24 ? ed - > appear_k : 24 ;
ed - > appear_k + + ;
T - > ws [ i ] . ap_t0 = ( ed - > t_ms ? ed - > t_ms : 1 ) + ( unsigned ) k * 30u ;
}
static int blk_alloc ( Tab * T ) {
if ( T - > free_n > 0 ) {
int i = T - > free_ids [ - - T - > free_n ] ;
blk_slot_clear ( T , i ) ;
T - > ws [ i ] . used = true ;
T - > ws [ i ] . uid = + + s_blk_uid ;
blk_mark_appear ( T , i ) ;
return i ;
}
if ( T - > ws_n > = MAX_WS ) return - 1 ;
@@ -484,6 +497,7 @@ static int blk_alloc(Tab* T) {
blk_slot_clear ( T , i ) ;
T - > ws [ i ] . used = true ;
T - > ws [ i ] . uid = + + s_blk_uid ;
blk_mark_appear ( T , i ) ;
return i ;
}
@@ -647,7 +661,10 @@ void free_tree(Ed* ed, Tab* T, int bi) {
}
/* Apaga só bi (com o que está encaixado nele); os blocos abaixo sobem */
void ghost_capture ( Ed * ed , Tab * T , int bi , bool chain , float wsx , float wsy , bool clip ) ;
void delete_heal ( Ed * ed , Tab * T , int bi ) {
if ( T = = & CT & & AREA ( V_SCRIPTS ) . shown ) ghost_capture ( ed , T , bi , false , WS_X , WS_Y , true ) ;
EdBlock * b = & T - > ws [ bi ] ;
int nx = b - > next , par = b - > parent , rel = b - > prel ;
if ( nx > = 0 ) { b - > next = - 1 ; T - > ws [ nx ] . parent = - 1 ; T - > ws [ nx ] . prel = REL_NONE ; }
@@ -964,12 +981,38 @@ static void place_chain(Tab* T, int head, float x, float y) {
for ( int c = head ; c > = 0 ; c = T - > ws [ c ] . next ) { place ( T , c , x , y ) ; y + = T - > ws [ c ] . h ; }
}
/* Bloco que mudou de lugar dentro da mesma pilha (algo entrou ou saiu
acima dele ) : desliza do lugar antigo em vez de pular . Arrastar a pilha
( a raiz anda ) ou trocar de pilha nao anima . */
static void blk_slide_off ( Ed * ed , const EdBlock * b , float * dx , float * dy ) ;
static void anim_track ( Tab * T ) {
Ed * ed = g_active_ed ;
if ( ! ed | | T = = & ed - > fly ) return ;
for ( int i = 0 ; i < T - > ws_n ; i + + ) {
EdBlock * b = & T - > ws [ i ] ;
if ( ! b - > used ) continue ;
int r = stack_root ( T , i ) ;
float rx = T - > ws [ r ] . x , ry = T - > ws [ r ] . y ;
if ( b - > l_ok & & ! ed - > anim_off & & ! b - > dragging & & r = = b - > l_root & & rx = = b - > l_rx & & ry = = b - > l_ry & &
fabsf ( b - > ay - b - > l_y ) > 0.5f ) {
float ox , oy ;
blk_slide_off ( ed , b , & ox , & oy ) ;
b - > an_dx = b - > l_x + ox - b - > ax ;
b - > an_dy = b - > l_y + oy - b - > ay ;
b - > an_t0 = ed - > t_ms ? ed - > t_ms : 1 ;
}
b - > l_ok = true ; b - > l_root = r ; b - > l_rx = rx ; b - > l_ry = ry ;
b - > l_x = b - > ax ; b - > l_y = b - > ay ;
}
}
void layout_tab ( Tab * T ) {
for ( int i = 0 ; i < T - > top_n ; i + + ) {
int h = T - > top [ i ] ;
measure_chain ( T , h ) ;
place_chain ( T , h , T - > ws [ h ] . x , T - > ws [ h ] . y ) ;
}
anim_track ( T ) ;
}
/* ===
@@ -1262,6 +1305,46 @@ void ed_cull_pane(Ed* ed, bool on, float x, float y, float w, float h) {
ed - > cull_on = on ; ed - > cull_x = x ; ed - > cull_y = y ; ed - > cull_w = w ; ed - > cull_h = h ;
}
/* == Animacao dos blocos (curvas do M3) === */
/* Progresso 0..1 desde t0 (0 = ainda nao comecou: cascata) */
static float anim_k ( Ed * ed , unsigned t0 , unsigned dur ) {
if ( ed - > anim_off | | ! t0 ) return 1.f ;
int dt = ( int ) ( ed - > t_ms - t0 ) ;
if ( dt < = 0 ) return 0.f ;
return ( unsigned ) dt > = dur ? 1.f : ( float ) dt / ( float ) dur ;
}
static void blk_slide_off ( Ed * ed , const EdBlock * b , float * dx , float * dy ) {
* dx = * dy = 0.f ;
if ( ! b - > an_t0 ) return ;
float k = anim_k ( ed , b - > an_t0 , M3_DUR_SLIDE ) ;
if ( k > = 1.f ) return ;
float r = 1.f - M3_EASE_STANDARD ( k ) ;
* dx = b - > an_dx * r ; * dy = b - > an_dy * r ;
}
/* Escala (em torno de cx, cy) e opacidade dos comandos a partir de first */
static void rb_fx_from ( TinyBlocks_RenderableBlock * rb , uint32_t first , float cx , float cy , float s , float a ) {
for ( uint32_t i = first ; i < rb - > count ; i + + ) {
TinyBlocks_DrawCmd * c = & rb - > cmds [ i ] ;
if ( c - > kind = = TB_DRAW_CLEAR | | c - > kind = = TB_DRAW_CLEAR_CLIP | | c - > kind = = TB_DRAW_SET_CLIP ) continue ;
c - > a * = a ;
if ( s = = 1.f ) continue ;
if ( c - > kind = = TB_DRAW_FILL_POLY ) {
float xy [ 2 * TB_POLY_MAX ] ;
int n = tb_draw_poly_get ( c , xy ) ;
for ( int k = 0 ; k < n ; k + + ) { xy [ 2 * k ] = cx + ( xy [ 2 * k ] - cx ) * s ; xy [ 2 * k + 1 ] = cy + ( xy [ 2 * k + 1 ] - cy ) * s ; }
tb_draw_poly_set ( c , xy , n ) ;
continue ;
}
c - > x = cx + ( c - > x - cx ) * s ; c - > y = cy + ( c - > y - cy ) * s ;
if ( c - > kind = = TB_DRAW_STROKE_LINE ) { c - > w = cx + ( c - > w - cx ) * s ; c - > h = cy + ( c - > h - cy ) * s ; }
else { c - > w * = s ; c - > h * = s ; }
if ( c - > kind ! = TB_DRAW_TEXT ) c - > param * = s ;
c - > font_size * = s ;
}
}
static bool culled ( const Ed * ed , const EdBlock * b , float ox , float oy ) {
if ( ! ed - > cull_on ) return false ;
const float M = 80.f ; /* folga: valores encaixados passam do corpo */
@@ -1270,12 +1353,15 @@ static bool culled(const Ed* ed, const EdBlock* b, float ox, float oy) {
y + b - > h < ed - > cull_y - M | | y > ed - > cull_y + ed - > cull_h + M ;
}
static void render_block ( Ed * ed , TinyBlocks_RenderableBlock * rb , Tab * T , int bi , float ox , float oy ) {
static void render_block ( Ed * ed , TinyBlocks_RenderableBlock * rb , Tab * T , int bi , float ox , float oy ) ;
static void render_block_body ( Ed * ed , TinyBlocks_RenderableBlock * rb , Tab * T , int bi , float ox , float oy ) {
EdBlock * b = & T - > ws [ bi ] ;
if ( culled ( ed , b , ox , oy ) ) return ;
Shape sh = shape_of ( b - > type ) ;
Col c , d ; block_cols ( ed , b , & c , & d ) ;
float x = b - > ax + ox , y = b - > ay + oy , w = b - > w , h = b - > h ;
float sdx , sdy ; /* deslize: so o desenho deste bloco */
blk_slide_off ( ed , b , & sdx , & sdy ) ;
float x = b - > ax + ox + sdx , y = b - > ay + oy + sdy , w = b - > w , h = b - > h ;
/* == Corpo: contorno escuro + preenchimento === */
switch ( sh ) {
@@ -1397,6 +1483,18 @@ static void render_block(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int bi,
}
/* Desenha de baixo para cima, para cada encaixe cobrir o bloco seguinte */
/* Bloco surgindo (criado por codigo): cresce e aparece com a curva de
entrada do M3 ; os filhos tem a propria animacao */
static void render_block ( Ed * ed , TinyBlocks_RenderableBlock * rb , Tab * T , int bi , float ox , float oy ) {
EdBlock * b = & T - > ws [ bi ] ;
float k = b - > ap_t0 ? anim_k ( ed , b - > ap_t0 , M3_DUR_APPEAR ) : 1.f ;
if ( k > = 1.f ) { b - > ap_t0 = 0 ; render_block_body ( ed , rb , T , bi , ox , oy ) ; return ; }
uint32_t from = rb - > count ;
render_block_body ( ed , rb , T , bi , ox , oy ) ;
float e = M3_EASE_EMPH_DECEL ( k ) ;
rb_fx_from ( rb , from , b - > ax + ox + b - > w * 0.5f , b - > ay + oy + b - > h * 0.5f , 0.6f + 0.4f * e , e ) ;
}
static void render_chain ( Ed * ed , TinyBlocks_RenderableBlock * rb , Tab * T , int head , float ox , float oy ) {
int * ids = T - > ws_n > 0 ? ( int * ) malloc ( ( size_t ) T - > ws_n * sizeof ( int ) ) : NULL ;
int n = 0 ;
@@ -1405,6 +1503,69 @@ static void render_chain(Ed* ed, TinyBlocks_RenderableBlock* rb, Tab* T, int hea
free ( ids ) ;
}
/* == Blocos apagados saindo de cena ===
* Na hora de apagar , o desenho do bloco ( como esta na tela ) vira um
* " fantasma " que encolhe e some com a curva de saida do M3 . */
static void rb_scale_from ( TinyBlocks_RenderableBlock * rb , uint32_t first , float ox , float oy , float s ) ;
static void ghost_free ( Ed * ed , int i ) {
free ( ed - > ghosts [ i ] . cmds ) ;
memmove ( & ed - > ghosts [ i ] , & ed - > ghosts [ i + 1 ] , ( size_t ) ( ed - > ghost_n - i - 1 ) * sizeof ( Ghost ) ) ;
ed - > ghost_n - - ;
}
void ghost_capture ( Ed * ed , Tab * T , int bi , bool chain , float wsx , float wsy , bool clip ) {
if ( ed - > anim_off | | bi < 0 | | bi > = T - > ws_n | | ! T - > ws [ bi ] . used ) return ;
TinyBlocks_RenderableBlock * rb = tb_renderable_acquire ( ) ;
if ( ! rb ) return ;
bool editing = ed - > editing ;
ed - > editing = false ; /* sem cursor no fantasma */
float ox = wsx - T - > ws_sx , oy = wsy - T - > ws_sy ;
if ( chain ) render_chain ( ed , rb , T , bi , ox , oy ) ;
else render_block ( ed , rb , T , bi , ox , oy ) ;
ed - > editing = editing ;
rb_scale_from ( rb , 0 , wsx , wsy , tab_zoom ( T ) ) ;
if ( ed - > ghost_n = = GHOST_MAX ) ghost_free ( ed , 0 ) ;
Ghost * g = & ed - > ghosts [ ed - > ghost_n ] ;
memset ( g , 0 , sizeof ( * g ) ) ;
g - > cmds = ( TinyBlocks_DrawCmd * ) malloc ( rb - > count * sizeof ( TinyBlocks_DrawCmd ) ) ;
float x0 = 1e9 f , y0 = 1e9 f , x1 = - 1e9 f , y1 = - 1e9 f ;
for ( uint32_t i = 0 ; g - > cmds & & i < rb - > count ; i + + ) {
const TinyBlocks_DrawCmd * c = & rb - > cmds [ i ] ;
/* imagens podem morrer com o bloco; o clip e o da area */
if ( c - > kind = = TB_DRAW_IMAGE | | c - > kind = = TB_DRAW_SET_CLIP | | c - > kind = = TB_DRAW_CLEAR_CLIP | |
c - > kind = = TB_DRAW_CLEAR ) continue ;
g - > cmds [ g - > n + + ] = * c ;
if ( c - > kind = = TB_DRAW_FILL_RECT | | c - > kind = = TB_DRAW_FILL_RRECT | | c - > kind = = TB_DRAW_FILL_POLY ) {
x0 = fminf ( x0 , c - > x ) ; y0 = fminf ( y0 , c - > y ) ;
x1 = fmaxf ( x1 , c - > x + c - > w ) ; y1 = fmaxf ( y1 , c - > y + c - > h ) ;
}
}
tb_renderable_release ( rb ) ;
if ( ! g - > cmds | | ! g - > n ) { free ( g - > cmds ) ; return ; }
g - > cx = ( x0 + x1 ) * 0.5f ; g - > cy = ( y0 + y1 ) * 0.5f ;
g - > t0 = ed - > t_ms ? ed - > t_ms : 1 ;
g - > clip = clip ;
if ( clip ) { g - > clip_r [ 0 ] = WS_X ; g - > clip_r [ 1 ] = WS_Y ; g - > clip_r [ 2 ] = WS_W ; g - > clip_r [ 3 ] = WS_H ; }
ed - > ghost_n + + ;
}
static void ghosts_render ( Ed * ed , TinyBlocks_RenderableBlock * rb ) {
for ( int i = 0 ; i < ed - > ghost_n ; ) {
Ghost * g = & ed - > ghosts [ i ] ;
float k = anim_k ( ed , g - > t0 , M3_DUR_EXIT ) ;
if ( k > = 1.f | | rb - > count + ( uint32_t ) g - > n + 2 > TB_DRAW_CMD_CAP ) { ghost_free ( ed , i ) ; continue ; }
float e = M3_EASE_EMPH_ACCEL ( k ) ;
if ( g - > clip ) tb_draw_set_clip ( rb , g - > clip_r [ 0 ] , g - > clip_r [ 1 ] , g - > clip_r [ 2 ] , g - > clip_r [ 3 ] ) ;
uint32_t from = rb - > count ;
memcpy ( & rb - > cmds [ rb - > count ] , g - > cmds , ( size_t ) g - > n * sizeof ( TinyBlocks_DrawCmd ) ) ;
rb - > count + = ( uint32_t ) g - > n ;
rb_fx_from ( rb , from , g - > cx , g - > cy , 1.f - 0.3f * e , 1.f - e ) ;
if ( g - > clip ) tb_draw_clear_clip ( rb ) ;
i + + ;
}
}
/* ===
* Execução
* = = = */
@@ -2839,18 +3000,6 @@ static int detach_btn_at(Ed* ed, float mx, float my) {
return - 1 ;
}
/* Icone: duas janelas (destacar) ou janela com o canto cheio (recolher) */
static void draw_window_icon ( TinyBlocks_RenderableBlock * rb , float x , float y , float s , bool detached , Col c ) {
float k = s / 32.f ;
if ( detached ) {
rb_stroke_rect ( rb , x + 9 * k , y + 7 * k , 22 * k , 18 * k , 1.5f , c ) ;
rb_fill_rect ( rb , x + 12 * k , y + 15 * k , 10 * k , 7 * k , c ) ;
} else {
rb_stroke_rect ( rb , x + 9 * k , y + 11 * k , 15 * k , 13 * k , 1.5f , c ) ;
rb_stroke_rect ( rb , x + 16 * k , y + 6 * k , 15 * k , 13 * k , 1.5f , c ) ;
}
}
static void draw_detach_btn ( Ed * ed , TinyBlocks_RenderableBlock * rb , int v ) {
if ( v = = V_STAGE | | ! ed - > area [ v ] . shown | | ed - > compact ) return ;
float bx , by ;
@@ -2960,6 +3109,27 @@ static float cat_max_scroll(Ed* ed) {
return m > 0 ? m : 0 ;
}
/* == Rolagem suave (curva standard do M3) ===
* A roda define o alvo ; o valor anda ate ele em M3_DUR_SCROLL . Ticks
* seguidos somam no alvo , sem recomecar do zero . */
static float sa_base ( const ScrollAnim * a , float cur ) { return a - > on ? a - > to : cur ; }
static void sa_to ( Ed * ed , ScrollAnim * a , float * var , float target ) {
if ( ed - > anim_off ) { a - > on = false ; * var = target ; return ; }
a - > from = * var ; a - > to = target ; a - > t0 = ed - > t_ms ? ed - > t_ms : 1 ; a - > on = true ;
}
static void sa_step ( Ed * ed , ScrollAnim * a , float * var ) {
if ( ! a - > on ) return ;
float k = anim_k ( ed , a - > t0 , M3_DUR_SCROLL ) ;
* var = a - > from + ( a - > to - a - > from ) * M3_EASE_STANDARD ( k ) ;
if ( k > = 1.f ) a - > on = false ;
}
static void sa_step_i ( Ed * ed , ScrollAnim * a , int * var ) {
if ( ! a - > on ) return ;
float v = ( float ) * var ;
sa_step ( ed , a , & v ) ;
* var = ( int ) lroundf ( v ) ;
}
static void cat_scroll_by ( Ed * ed , float d ) {
ed - > cat_scroll + = d ;
if ( ed - > cat_scroll > cat_max_scroll ( ed ) ) ed - > cat_scroll = cat_max_scroll ( ed ) ;
@@ -3775,7 +3945,16 @@ static bool sb_import_file(Ed* ed, const char* path) {
}
/* Texto em scratchblocks -> aba nova chamada `name` */
static bool sb_import_text_ ( Ed * ed , const char * text , const char * name ) ;
/* Colado/importado por codigo: os blocos surgem animados */
static bool sb_import_text ( Ed * ed , const char * text , const char * name ) {
bool was = ed - > appear_batch ;
if ( ! was ) { ed - > appear_batch = true ; ed - > appear_k = 0 ; }
bool ok = sb_import_text_ ( ed , text , name ) ;
ed - > appear_batch = was ;
return ok ;
}
static bool sb_import_text_ ( Ed * ed , const char * text , const char * name ) {
TbBpTab * B = calloc ( 1 , sizeof ( TbBpTab ) ) ;
if ( ! B ) return false ;
TbSbLabel * labels = NULL ;
@@ -6229,6 +6408,10 @@ static unsigned ctx_icon(int id) {
case CM_MB_LIBMAN : return MI_LIBRARY_BOOKS ;
case CM_MB_LIB : return MI_UPLOAD_FILE ;
case CM_MB_CFG : return MI_SETTINGS ;
case CM_SOURCE : return MI_SOURCE ;
case CM_SHARE_STACK : return MI_SHARE ;
case CM_SHARE_TAB : return MI_QR_CODE ;
case CM_RECEIVE : return MI_QR_SCANNER ;
default : return 0 ;
}
}
@@ -6255,6 +6438,10 @@ static const char* ctx_label(int id) {
case CM_MB_LIBMAN : return " Bibliotecas " ;
case CM_MB_LIB : return " Carregar library... " ;
case CM_MB_CFG : return " Configurações " ;
case CM_SOURCE : return " Ver código-fonte " ;
case CM_SHARE_STACK : return " Compartilhar pilha (QR) " ;
case CM_SHARE_TAB : return " Compartilhar blueprint (QR) " ;
case CM_RECEIVE : return " Receber blocos (QR) " ;
default : return " " ;
}
}
@@ -7746,6 +7933,9 @@ static void menu_action(Ed* ed, int id) {
}
}
static void qr_share_open ( Ed * ed , const char * title , char * text ) ;
static void qr_recv_open ( Ed * ed , float wx , float wy ) ;
static void ctx_exec ( Ed * ed , int id ) {
Tab * T = & CT ;
int bi = ed - > ctx_menu_bi ;
@@ -7795,6 +7985,16 @@ static void ctx_exec(Ed* ed, int id) {
case CM_MB_LIBMAN : case CM_MB_LIB : case CM_MB_CFG :
menu_action ( ed , id - CM_MB_OPEN ) ;
break ;
case CM_SOURCE : { /* a funcao C do bloco, na aba de codigo */
const TinyBlocks_BlockMeta * m = bi > = 0 ? tb_meta_find ( T - > ws [ bi ] . type_name ) : NULL ;
if ( m & & m - > file ) open_code_at ( ed , m - > file , tb_meta_line ( m ) > 0 ? tb_meta_line ( m ) : 1 ) ;
break ;
}
case CM_SHARE_STACK :
if ( bi > = 0 ) qr_share_open ( ed , " Compartilhar pilha " , ed_scratchblocks_export ( ed , T , stack_root ( T , bi ) ) ) ;
break ;
case CM_SHARE_TAB : qr_share_open ( ed , " Compartilhar blueprint " , ed_scratchblocks_export ( ed , T , - 1 ) ) ; break ;
case CM_RECEIVE : qr_recv_open ( ed , ed - > ctx_wx , ed - > ctx_wy ) ; break ;
default : break ;
}
}
@@ -7814,11 +8014,23 @@ struct ModalClass {
} ;
static bool settings_is_open ( Ed * ed ) { return ed - > settings_open ; }
static void settings_scroll_m ( Ed * ed , float dy ) { settings_scroll_by ( ed , dy ) ; }
/* Rolagem animada de uma lista com clamp proprio: calcula o alvo a partir do
alvo atual e anima ate ele ( arrastar com o dedo vai direto ) */
static void modal_scroll_anim ( Ed * ed , ScrollAnim * a , int * var , void ( * by ) ( Ed * , float ) , float dy ) {
if ( ed - > anim_off | | ed - > modal_drag ) { a - > on = false ; by ( ed , dy ) ; return ; }
int cur = * var ;
* var = ( int ) lroundf ( sa_base ( a , ( float ) cur ) ) ;
by ( ed , dy ) ;
int target = * var ;
* var = cur ;
float v = ( float ) cur ;
sa_to ( ed , a , & v , ( float ) target ) ;
}
static void settings_scroll_m ( Ed * ed , float dy ) { modal_scroll_anim ( ed , & ed - > sa_st , & ed - > settings_scroll , settings_scroll_by , dy ) ; }
static bool libman_is_open ( Ed * ed ) { return ed - > libman_open ; }
static void libman_key_m ( Ed * ed , int sc , bool ctrl ) { ( void ) ctrl ; libman_key ( ed , sc ) ; }
static void libman_scroll_m ( Ed * ed , float dy ) { libman_scroll_by ( ed , dy ) ; }
static void libman_scroll_m ( Ed * ed , float dy ) { modal_scroll_anim ( ed , & ed - > sa_lm , & ed - > libman_scroll , libman_scroll_by , dy ) ; }
/* o explorador vem do modulo do editor (pode faltar) */
static bool files_is_open ( Ed * ed ) { return ed - > fdlg . open ; }
@@ -7839,7 +8051,299 @@ static bool dlg_is_open(Ed* ed) { return ed->comp_dialog_open; }
static void dlg_key_m ( Ed * ed , int sc , bool ctrl ) { ( void ) ctrl ; dlg_key ( ed , sc ) ; }
static void dlg_click_m ( Ed * ed , float mx , float my ) { dlg_click ( ed , mx , my ) ; }
/* ===
* QR : compartilhar e receber blocos entre instancias do editor
* Conteudo = scratchblocks . Cada QR leva " TB1|id|parte|total| " + um pedaco
* de ate QR_CHUNK bytes ; o painel mostra as partes em loop ( 1 s cada ) e o
* receptor junta em qualquer ordem , quantas voltas forem precisas .
* = = = */
# define QR_CHUNK 220
# define QR_PART_MS 1000u
# define QR_GRAY_CAP (1920 * 1088)
/* Fim do pedaco que comeca em pos (sem cortar uma letra UTF-8) */
static int qr_cut ( const char * t , int len , int pos ) {
int end = pos + QR_CHUNK ;
if ( end > = len ) return len ;
while ( end > pos & & ( ( unsigned char ) t [ end ] & 0xC0 ) = = 0x80 ) end - - ;
return end ;
}
static void qr_share_close ( Ed * ed ) {
free ( ed - > qrs_text ) ;
ed - > qrs_text = NULL ;
ed - > qrs_open = false ;
}
static void qr_share_open ( Ed * ed , const char * title , char * text ) {
qr_share_close ( ed ) ;
if ( ! text | | ! text [ 0 ] ) {
free ( text ) ;
snprintf ( ed - > hot_status , sizeof ( ed - > hot_status ) , " Nada para compartilhar " ) ;
ed - > hot_status_ok = false ;
return ;
}
ed - > qrs_text = text ;
int len = ( int ) strlen ( text ) , n = 0 ;
for ( int p = 0 ; p < len ; p = qr_cut ( text , len , p ) ) n + + ;
ed - > qrs_n = n ;
ed - > qrs_t0 = ed - > t_ms ? ed - > t_ms : 1 ;
snprintf ( ed - > qrs_id , sizeof ( ed - > qrs_id ) , " %04x " , ( unsigned ) ( ( now_ms ( ) * 2654435761u ) > > 16 ) & 0xffffu ) ;
scopy ( ed - > qrs_title , sizeof ( ed - > qrs_title ) , title ) ;
ed - > qrs_open = true ;
}
/* Texto do QR da parte i (0..n-1) */
static void qr_part_text ( Ed * ed , int i , char * out , size_t cap ) {
const char * t = ed - > qrs_text ;
int len = ( int ) strlen ( t ) , p = 0 ;
for ( int k = 0 ; k < i & & p < len ; k + + ) p = qr_cut ( t , len , p ) ;
int e = qr_cut ( t , len , p ) ;
snprintf ( out , cap , " TB1|%s|%d|%d|%.*s " , ed - > qrs_id , i + 1 , ed - > qrs_n , e - p , t + p ) ;
}
static bool qrs_is_open ( Ed * ed ) { return ed - > qrs_open ; }
static void qrs_geom ( Ed * ed , float * x , float * y , float * w , float * h ) {
* w = fminf ( 440.f , WIN_W - 32.f ) ;
* h = * w + 128.f ;
if ( * h > WIN_H - 32.f ) { * h = WIN_H - 32.f ; * w = * h - 128.f ; }
* x = ( WIN_W - * w ) * 0.5f ; * y = ( WIN_H - * h ) * 0.5f ;
}
/* Modulos escuros do QR como faixas horizontais (uma por sequencia) */
static void draw_qr ( TinyBlocks_RenderableBlock * rb , const unsigned char * mods , int side , float x , float y , float m ) {
Col ink = COLA ( 20 , 22 , 30 , 255 ) ;
for ( int r = 0 ; r < side ; r + + )
for ( int c = 0 ; c < side ; ) {
if ( ! mods [ r * side + c ] ) { c + + ; continue ; }
int c0 = c ;
while ( c < side & & mods [ r * side + c ] ) c + + ;
/* um pouco maior que o modulo: sem frestas entre as faixas em
nenhuma escala ( a densidade do celular nao e inteira ) */
rb_fill_rect ( rb , x + c0 * m , y + r * m , ( c - c0 ) * m + 0.6f , m + 0.6f , ink ) ;
}
}
static void qrs_render ( Ed * ed , TinyBlocks_RenderableBlock * rb ) {
if ( ! ed - > qrs_open | | ! ed - > qrs_text ) return ;
float x , y , w , h ;
qrs_geom ( ed , & x , & y , & w , & h ) ;
m3_scrim ( rb , WIN_W , WIN_H ) ;
m3_dialog_surface ( rb , x , y , w , h ) ;
tb_a11y_set_states ( ax ( ed ) , ax_push ( ed , TB_A11Y_DIALOG , ed - > qrs_title , x , y , w , h ) , TB_A11Y_MODAL ) ;
rb_icon ( rb , x + 24 + 12 , y + 34 , MI_QR_CODE , 24.f , M3_PRIMARY , false ) ;
rb_text_f ( rb , x + 24 + 24 + 12 , y + 34 , ed - > qrs_title , M3_ON_SURFACE , M3_HEADLINE_S , TB_FONT_REGULAR ) ;
int n = ed - > qrs_n , i = n > 1 ? ( int ) ( ( ( ed - > t_ms - ed - > qrs_t0 ) / QR_PART_MS ) % ( unsigned ) n ) : 0 ;
static char part [ QR_CHUNK + 64 ] ;
static unsigned char mods [ TB_QR_MAX_SIDE * TB_QR_MAX_SIDE ] ;
qr_part_text ( ed , i , part , sizeof ( part ) ) ;
int side = tb_qr_encode ( part , mods , ( int ) sizeof ( mods ) ) ;
float q = w - 48.f , qx = x + 24.f , qy = y + 62.f ;
rb_fill_rrect ( rb , qx , qy , q , q , M3_SHAPE_M , COL_WHITE ) ; /* QR com margem clara */
if ( side > 0 ) {
float m = floorf ( q / ( float ) ( side + 8 ) ) ;
float off = floorf ( ( q - m * side ) * 0.5f ) ;
draw_qr ( rb , mods , side , floorf ( qx ) + off , floorf ( qy ) + off , m ) ;
}
char lab [ 64 ] ;
snprintf ( lab , sizeof ( lab ) , " Parte %d de %d " , i + 1 , n ) ;
float ty = qy + q + 22.f ;
rb_text_f ( rb , x + 24 , ty , lab , M3_ON_SURFACE , M3_TITLE_S , TB_FONT_MEDIUM ) ;
tb_a11y_set_value ( ax ( ed ) , ax_add ( ed , TB_A11Y_LABEL , " Parte " , x + 24 , ty - 10 , 120 , 20 ) , lab ) ;
if ( n > 1 & & n < = 24 ) /* qual parte esta no ar */
for ( int k = 0 ; k < n ; k + + )
rb_fill_circle ( rb , x + w - 24 - ( n - 1 - k ) * 12 , ty , k = = i ? 4.f : 3.f ,
k = = i ? M3_PRIMARY : M3_OUTLINE_VAR ) ;
rb_text_f ( rb , x + 24 , ty + 22 , " No outro TinyBlocks: botão direito na área › Receber blocos " ,
M3_ON_SURFACE_VAR , M3_BODY_S , TB_FONT_REGULAR ) ;
float bx = x + w - 24 - 90 , by = y + h - 48 ;
m3_button ( rb , M3_TEXT , bx , by , 90 , 36 , " Fechar " , 0 , M3_PRIMARY , in_rect ( ed - > mouse_x , ed - > mouse_y , bx , by , 90 , 36 ) , false ) ;
ax_button ( ed , " Fechar " , bx , by , 90 , 36 ) ;
ax_pop ( ed ) ;
}
static void qrs_click ( Ed * ed , float mx , float my ) {
float x , y , w , h ;
qrs_geom ( ed , & x , & y , & w , & h ) ;
if ( ! in_rect ( mx , my , x , y , w , h ) | | in_rect ( mx , my , x + w - 24 - 90 , y + h - 48 , 90 , 36 ) ) qr_share_close ( ed ) ;
}
static void qrs_key ( Ed * ed , int sc , bool ctrl ) {
( void ) ctrl ;
if ( sc = = TB_KEY_ESCAPE | | sc = = TB_KEY_RETURN ) qr_share_close ( ed ) ;
}
/* -- Receber --- */
static void qr_recv_reset ( Ed * ed ) {
for ( int i = 0 ; ed - > qrr_part & & i < ed - > qrr_n ; i + + ) free ( ed - > qrr_part [ i ] ) ;
free ( ed - > qrr_part ) ;
ed - > qrr_part = NULL ;
ed - > qrr_n = ed - > qrr_got = 0 ;
ed - > qrr_id [ 0 ] = 0 ;
}
static void qr_recv_close ( Ed * ed ) {
if ( ed - > qrr_cam ) tb_camera_close ( ) ;
ed - > qrr_cam = false ;
qr_recv_reset ( ed ) ;
tb_qr_reader_free ( ed - > qrr_reader ) ;
ed - > qrr_reader = NULL ;
free ( ed - > qrr_gray ) ;
ed - > qrr_gray = NULL ;
if ( ed - > qrr_img ) tb_image_release ( ed - > qrr_img ) ;
ed - > qrr_img = NULL ;
ed - > qrr_open = false ;
}
static void qr_recv_open ( Ed * ed , float wx , float wy ) {
qr_recv_close ( ed ) ;
if ( ! tab_class ( & CT ) - > blocks ) return ;
ed - > qrr_open = true ;
ed - > qrr_x = wx ; ed - > qrr_y = wy ;
ed - > qrr_reader = tb_qr_reader_new ( ) ;
ed - > qrr_gray = ( unsigned char * ) malloc ( QR_GRAY_CAP ) ;
ed - > qrr_cam = tb_camera_open ( 640 , 480 ) ;
snprintf ( ed - > qrr_msg , sizeof ( ed - > qrr_msg ) , " %s " ,
ed - > qrr_cam ? " Aponte a câmera para o QR do outro TinyBlocks " : tb_camera_error ( ) ) ;
}
/* Um QR lido: guarda a parte; com todas, importa os blocos */
static void qr_recv_text ( Ed * ed , const char * t , int len ) {
char id [ 8 ] ;
int i = 0 , n = 0 , hl = 0 ;
if ( len < 8 | | strncmp ( t , " TB1| " , 4 ) ! = 0 ) return ;
if ( sscanf ( t + 4 , " %7[0-9a-f]|%d|%d|%n " , id , & i , & n , & hl ) < 3 | | hl < = 0 ) return ;
if ( n < 1 | | n > 4096 | | i < 1 | | i > n ) return ;
if ( strcmp ( id , ed - > qrr_id ) ! = 0 | | n ! = ed - > qrr_n ) { /* outro compartilhamento: recomeca */
qr_recv_reset ( ed ) ;
ed - > qrr_part = ( char * * ) calloc ( ( size_t ) n , sizeof ( char * ) ) ;
if ( ! ed - > qrr_part ) return ;
ed - > qrr_n = n ;
scopy ( ed - > qrr_id , sizeof ( ed - > qrr_id ) , id ) ;
}
if ( ed - > qrr_part [ i - 1 ] ) return ;
const char * body = t + 4 + hl ;
int bl = len - ( int ) ( body - t ) ;
char * p = ( char * ) malloc ( ( size_t ) bl + 1 ) ;
if ( ! p ) return ;
memcpy ( p , body , ( size_t ) bl ) ; p [ bl ] = 0 ;
ed - > qrr_part [ i - 1 ] = p ;
ed - > qrr_got + + ;
if ( ed - > qrr_got < ed - > qrr_n ) return ;
size_t total = 1 ;
for ( int k = 0 ; k < n ; k + + ) total + = strlen ( ed - > qrr_part [ k ] ) ;
char * all = ( char * ) malloc ( total ) ;
if ( ! all ) return ;
all [ 0 ] = 0 ;
for ( int k = 0 ; k < n ; k + + ) strcat ( all , ed - > qrr_part [ k ] ) ;
int heads [ 64 ] ;
char warn [ 200 ] = " " ;
ed - > appear_batch = true ; ed - > appear_k = 0 ; /* os blocos surgem animados */
int got = ed_scratchblocks_import ( ed , & CT , all , ed - > qrr_x , ed - > qrr_y , heads , 64 , warn , sizeof ( warn ) ) ;
ed - > appear_batch = false ;
free ( all ) ;
layout_tab ( & CT ) ;
if ( got > 0 ) snprintf ( ed - > hot_status , sizeof ( ed - > hot_status ) , " Recebido: %d pilha(s)%s%s " , got ,
warn [ 0 ] ? " - " : " " , warn ) ;
else snprintf ( ed - > hot_status , sizeof ( ed - > hot_status ) , " O QR não trouxe blocos%s%s " , warn [ 0 ] ? " : " : " " , warn ) ;
ed - > hot_status_ok = got > 0 ;
qr_recv_close ( ed ) ;
}
static void qr_found_cb ( const char * t , int len , void * user ) {
Ed * ed = ( Ed * ) user ;
if ( ed - > qrr_open ) qr_recv_text ( ed , t , len ) ;
}
/* A cada quadro: quadro novo da camera -> previa + leitura */
static void qr_recv_poll ( Ed * ed ) {
if ( ! ed - > qrr_open | | ! ed - > qrr_cam | | ! ed - > qrr_gray ) return ;
int w = 0 , h = 0 ;
if ( ! tb_camera_frame ( ed - > qrr_gray , QR_GRAY_CAP , & w , & h ) ) return ;
if ( ! ed - > qrr_img | | tb_image_width ( ed - > qrr_img ) ! = w | | tb_image_height ( ed - > qrr_img ) ! = h ) {
if ( ed - > qrr_img ) tb_image_release ( ed - > qrr_img ) ;
ed - > qrr_img = tb_image_new ( w , h , 4 ) ;
}
if ( ed - > qrr_img ) {
uint8_t * px = tb_image_data ( ed - > qrr_img ) ;
for ( int k = 0 ; k < w * h ; k + + ) {
uint8_t g = ed - > qrr_gray [ k ] ;
px [ 4 * k ] = px [ 4 * k + 1 ] = px [ 4 * k + 2 ] = g ; px [ 4 * k + 3 ] = 255 ;
}
}
tb_qr_reader_scan ( ed - > qrr_reader , ed - > qrr_gray , w , h , qr_found_cb , ed ) ;
}
TB_API void tb_editor_qr_feed ( TinyBlocks_Block * scene , const char * text ) {
Ed * ed = scene & & scene - > userdata ? * ( Ed * * ) scene - > userdata : NULL ;
if ( ed & & ed - > qrr_open & & text ) qr_recv_text ( ed , text , ( int ) strlen ( text ) ) ;
}
static bool qrr_is_open ( Ed * ed ) { return ed - > qrr_open ; }
static void qrr_render ( Ed * ed , TinyBlocks_RenderableBlock * rb ) {
if ( ! ed - > qrr_open ) return ;
float x , y , w , h ;
qrs_geom ( ed , & x , & y , & w , & h ) ;
m3_scrim ( rb , WIN_W , WIN_H ) ;
m3_dialog_surface ( rb , x , y , w , h ) ;
tb_a11y_set_states ( ax ( ed ) , ax_push ( ed , TB_A11Y_DIALOG , " Receber blocos " , x , y , w , h ) , TB_A11Y_MODAL ) ;
rb_icon ( rb , x + 24 + 12 , y + 34 , MI_QR_SCANNER , 24.f , M3_PRIMARY , false ) ;
rb_text_f ( rb , x + 24 + 24 + 12 , y + 34 , " Receber blocos " , M3_ON_SURFACE , M3_HEADLINE_S , TB_FONT_REGULAR ) ;
float q = w - 48.f , qx = x + 24.f , qy = y + 62.f ;
rb_fill_rrect ( rb , qx , qy , q , q , M3_SHAPE_M , M3_INVERSE_SURFACE ) ;
if ( ed - > qrr_img ) { /* previa da camera, sem deformar */
float iw = ( float ) tb_image_width ( ed - > qrr_img ) , ih = ( float ) tb_image_height ( ed - > qrr_img ) ;
float k = fminf ( q / iw , q / ih ) , dw = iw * k , dh = ih * k ;
tb_draw_image ( rb , qx + ( q - dw ) * 0.5f , qy + ( q - dh ) * 0.5f , dw , dh , ed - > qrr_img ) ;
} else {
rb_icon ( rb , qx + q * 0.5f , qy + q * 0.5f , MI_QR_SCANNER , 64.f , m3_alpha ( COL_WHITE , 0.5f ) , false ) ;
}
{ /* cantos da mira */
float c = q * 0.18f , m0 = q * 0.14f , t = 4.f ;
float l = qx + m0 , r = qx + q - m0 , tp = qy + m0 , bt = qy + q - m0 ;
Col wc = m3_alpha ( COL_WHITE , 0.85f ) ;
rb_fill_rect ( rb , l , tp , c , t , wc ) ; rb_fill_rect ( rb , l , tp , t , c , wc ) ;
rb_fill_rect ( rb , r - c , tp , c , t , wc ) ; rb_fill_rect ( rb , r - t , tp , t , c , wc ) ;
rb_fill_rect ( rb , l , bt - t , c , t , wc ) ; rb_fill_rect ( rb , l , bt - c , t , c , wc ) ;
rb_fill_rect ( rb , r - c , bt - t , c , t , wc ) ; rb_fill_rect ( rb , r - t , bt - c , t , c , wc ) ;
}
float ty = qy + q + 22.f ;
char st [ 96 ] ;
if ( ed - > qrr_n > 0 ) snprintf ( st , sizeof ( st ) , " Recebidas %d de %d partes " , ed - > qrr_got , ed - > qrr_n ) ;
else snprintf ( st , sizeof ( st ) , " %s " , ed - > qrr_cam ? " Procurando QR... " : " Sem câmera " ) ;
rb_text_f ( rb , x + 24 , ty , st , M3_ON_SURFACE , M3_TITLE_S , TB_FONT_MEDIUM ) ;
tb_a11y_set_value ( ax ( ed ) , ax_add ( ed , TB_A11Y_STATUS , " Recebimento " , x + 24 , ty - 10 , w - 48 , 20 ) , st ) ;
if ( ed - > qrr_n > 0 ) { /* indicador de progresso linear do M3 */
float pw = w - 48.f , k = ( float ) ed - > qrr_got / ( float ) ed - > qrr_n ;
rb_fill_rrect ( rb , x + 24 , ty + 14 , pw , 4 , 2 , M3_SECONDARY_CONTAINER ) ;
rb_fill_rrect ( rb , x + 24 , ty + 14 , fmaxf ( 4.f , pw * k ) , 4 , 2 , M3_PRIMARY ) ;
}
rb_text_f ( rb , x + 24 , ty + 34 , ed - > qrr_msg , ed - > qrr_cam ? M3_ON_SURFACE_VAR : COL_ERR_TEXT , M3_BODY_S ,
TB_FONT_REGULAR ) ;
float bx = x + w - 24 - 100 , by = y + h - 48 ;
m3_button ( rb , M3_TEXT , bx , by , 100 , 36 , " Cancelar " , 0 , M3_PRIMARY , in_rect ( ed - > mouse_x , ed - > mouse_y , bx , by , 100 , 36 ) , false ) ;
ax_button ( ed , " Cancelar " , bx , by , 100 , 36 ) ;
ax_pop ( ed ) ;
}
static void qrr_click ( Ed * ed , float mx , float my ) {
float x , y , w , h ;
qrs_geom ( ed , & x , & y , & w , & h ) ;
if ( ! in_rect ( mx , my , x , y , w , h ) | | in_rect ( mx , my , x + w - 24 - 100 , y + h - 48 , 100 , 36 ) ) qr_recv_close ( ed ) ;
}
static void qrr_key ( Ed * ed , int sc , bool ctrl ) {
( void ) ctrl ;
if ( sc = = TB_KEY_ESCAPE ) qr_recv_close ( ed ) ;
}
static const ModalClass s_modals [ ] = { /* do mais alto para o mais baixo */
{ " receber " , qrr_is_open , qrr_render , qrr_click , qrr_key , NULL , NULL } ,
{ " compartilhar " , qrs_is_open , qrs_render , qrs_click , qrs_key , NULL , NULL } ,
{ " configurações " , settings_is_open , settings_render , settings_click , settings_key , settings_text , settings_scroll_m } ,
{ " bibliotecas " , libman_is_open , libman_render , libman_click , libman_key_m , libman_text , libman_scroll_m } ,
{ " explorador " , files_is_open , files_render_m , files_click_m , files_key_m , files_text_m , files_scroll_m } ,
@@ -8039,6 +8543,7 @@ static void on_lmb_down(Ed* ed, float mx, float my) {
return ;
}
ed - > state = ES_PAN ;
ed - > sa_ws_x . on = ed - > sa_ws_y . on = ed - > za . on = false ; /* o dedo manda */
ed - > pan_mx = mx ; ed - > pan_my = my ;
ed - > pan_sx = CT . ws_sx ; ed - > pan_sy = CT . ws_sy ;
return ;
@@ -8160,7 +8665,10 @@ static void on_lmb_up(Ed* ed, float mx, float my) {
if ( ed - > state = = ES_DRAG & & ed - > drag_bi > = 0 ) {
mark_drag ( & CT , ed - > drag_bi , false ) ;
int tgt = ws_ctx_at ( ed , mx , my ) ;
if ( view_at ( ed , mx , my ) = = V_PALETTE ) free_tree ( ed , & CT , ed - > drag_bi ) ; /* solto na paleta = apagar */
if ( view_at ( ed , mx , my ) = = V_PALETTE ) { /* solto na paleta = apagar */
ghost_capture ( ed , & CT , ed - > drag_bi , true , ed - > drag_ws_x , ed - > drag_ws_y , false ) ;
free_tree ( ed , & CT , ed - > drag_bi ) ;
}
else if ( tgt ! = - 2 & & tgt ! = ed - > tabctx ) drag_to_ctx ( ed , tgt ) ;
else apply_snap ( ed ) ;
} else if ( ed - > state = = ES_PRESS ) {
@@ -8201,6 +8709,9 @@ static void on_rmb_down(Ed* ed, float mx, float my) {
ed - > ctx_items [ ed - > ctx_n + + ] = CM_DELETE ;
if ( is_def | | ( t & & strncmp ( t - > type_name , " User. " , 5 ) = = 0 ) ) ed - > ctx_items [ ed - > ctx_n + + ] = CM_EDIT_DEF ;
ed - > ctx_items [ ed - > ctx_n + + ] = CM_GROUP_STACK ;
const TinyBlocks_BlockMeta * m = tb_meta_find ( CT . ws [ bi ] . type_name ) ;
if ( m & & m - > file & & m - > file [ 0 ] ) ed - > ctx_items [ ed - > ctx_n + + ] = CM_SOURCE ;
ed - > ctx_items [ ed - > ctx_n + + ] = CM_SHARE_STACK ;
} else if ( g > = 0 ) {
ed - > ctx_items [ ed - > ctx_n + + ] = CM_GROUP_RENAME ;
ed - > ctx_items [ ed - > ctx_n + + ] = CM_GROUP_COLOR ;
@@ -8210,6 +8721,8 @@ static void on_rmb_down(Ed* ed, float mx, float my) {
ed - > ctx_items [ ed - > ctx_n + + ] = CM_CLEANUP ;
ed - > ctx_items [ ed - > ctx_n + + ] = CM_NEW_COMPOSITE ;
ed - > ctx_items [ ed - > ctx_n + + ] = CM_GROUP_NEW ;
if ( CT . top_n > 0 ) ed - > ctx_items [ ed - > ctx_n + + ] = CM_SHARE_TAB ;
ed - > ctx_items [ ed - > ctx_n + + ] = CM_RECEIVE ;
}
ed - > ctx_menu_open = true ;
ed - > ctx_export = false ;
@@ -8456,7 +8969,7 @@ static void pointer_motion(Ed* ed, float mx, float my, int from) {
if ( ! ed - > fly_pan_cats & & ed - > fly_press_item > = 0 & & fabsf ( dx ) > fabsf ( dy ) * 0.8f ) {
ed - > state = ES_IDLE ;
spawn_from_fly ( ed , ed - > fly_press_item , ed - > press_mx , ed - > press_my ) ;
} else ed - > state = ES_FLYPAN ;
} else { ed - > state = ES_FLYPAN ; ed - > sa_fly . on = ed - > sa_cat . on = false ; }
}
}
if ( ed - > state = = ES_FLYPAN ) {
@@ -8640,7 +9153,9 @@ static void pinch_update(Ed* ed, TinyBlocks_Block* evb, float ox, float oy) {
/* Para conferir o visual sem clicar (com TINYBLOCKS_SHOT): TINYBLOCKS_OPEN
* abre uma tela no inicio - bloco , config , bibliotecas , abrir , menu ,
* nova - aba , exportar , codigo , imagem */
* nova - aba , exportar , codigo , imagem , compartilhar , receber */
static void qr_share_open ( Ed * ed , const char * title , char * text ) ;
static void qr_recv_open ( Ed * ed , float wx , float wy ) ;
static void dev_open ( Ed * ed ) {
const char * w = getenv ( " TINYBLOCKS_OPEN " ) ;
if ( ! w | | ! w [ 0 ] ) return ;
@@ -8667,6 +9182,8 @@ static void dev_open(Ed* ed) {
CT . code_hl_dirty = true ;
}
else if ( ! strcmp ( w , " imagem " ) ) { tab_new_kind ( ed , " Imagem " , false , TK_IMAGE ) ; palette_rebuild ( ed ) ; }
else if ( ! strcmp ( w , " compartilhar " ) ) qr_share_open ( ed , " Compartilhar blueprint " , ed_scratchblocks_export ( ed , & CT , - 1 ) ) ;
else if ( ! strcmp ( w , " receber " ) ) qr_recv_open ( ed , 40 , 40 ) ;
}
static void ed_handle_input ( Ed * ed , TinyBlocks_Block * evb , int from ) {
@@ -8678,7 +9195,24 @@ static void ed_handle_input(Ed* ed, TinyBlocks_Block* evb, int from) {
}
if ( from < 0 ) {
ed - > frame_no + + ;
tb_ed_w . anim_now ( ( double ) now_ms ( ) ) ;
ed - > t_ms = now_ms ( ) ;
if ( ! ed - > t_ms ) ed - > t_ms = 1 ;
tb_ed_w . anim_now ( ( double ) ed - > t_ms ) ;
/* rolagens e zoom animados andam um quadro */
if ( ed - > sa_ws_tab = = ed - > cur_tab ) {
sa_step ( ed , & ed - > sa_ws_x , & CT . ws_sx ) ;
sa_step ( ed , & ed - > sa_ws_y , & CT . ws_sy ) ;
if ( ed - > za . on & & ed - > za . tab = = ed - > cur_tab ) {
float k = anim_k ( ed , ed - > za . t0 , M3_DUR_SCROLL ) ;
ws_zoom_at ( ed , & CT , ed - > za . from + ( ed - > za . to - ed - > za . from ) * M3_EASE_STANDARD ( k ) , ed - > za . ax , ed - > za . ay ) ;
if ( k > = 1.f ) ed - > za . on = false ;
}
}
sa_step ( ed , & ed - > sa_fly , & ed - > fly_scroll ) ;
sa_step ( ed , & ed - > sa_cat , & ed - > cat_scroll ) ;
sa_step_i ( ed , & ed - > sa_lm , & ed - > libman_scroll ) ;
sa_step_i ( ed , & ed - > sa_st , & ed - > settings_scroll ) ;
qr_recv_poll ( ed ) ; /* leitor de QR: camera -> partes */
int ww = ( int ) ev_int ( evb , GFX_IN_WIN_W ) ;
int wh = ( int ) ev_int ( evb , GFX_IN_WIN_H ) ;
if ( ww > 0 ) ed - > win_w = ww ;
@@ -8758,16 +9292,37 @@ static void ed_handle_input(Ed* ed, TinyBlocks_Block* evb, int from) {
} else if ( in_ws ( ed , mx , my ) ) {
/* roda = vertical, Shift+roda = horizontal, Ctrl+roda = zoom no ponteiro */
int mods = ( int ) ev_int ( evb , GFX_IN_MOD_STATE ) ;
if ( ed - > sa_ws_tab ! = ed - > cur_tab ) { /* outra aba: anima do zero */
ed - > sa_ws_x . on = ed - > sa_ws_y . on = ed - > za . on = false ;
ed - > sa_ws_tab = ed - > cur_tab ;
}
if ( mods & TB_MOD_CTRL ) {
if ( sdy ! = 0.0 ) ws_zoom_at ( ed , & CT , tab_zoom ( & CT ) * powf ( 1.1f , ( float ) sdy ) , mx , my ) ;
if ( sdy ! = 0.0 ) {
float z0 = ed - > za . on ? ed - > za . to : tab_zoom ( & CT ) ;
float zt = fminf ( WS_ZOOM_MAX , fmaxf ( WS_ZOOM_MIN , z0 * powf ( 1.1f , ( float ) sdy ) ) ) ;
if ( ed - > anim_off ) ws_zoom_at ( ed , & CT , zt , mx , my ) ;
else {
ed - > sa_ws_x . on = ed - > sa_ws_y . on = false ;
ed - > za . on = true ; ed - > za . from = tab_zoom ( & CT ) ; ed - > za . to = zt ;
ed - > za . ax = mx ; ed - > za . ay = my ; ed - > za . t0 = ed - > t_ms ? ed - > t_ms : 1 ;
ed - > za . tab = ed - > cur_tab ;
}
}
} else {
if ( mods & TB_MOD_SHIFT ) { sdx + = sdy ; sdy = 0.0 ; }
CT . ws_sx - = ( float ) sdx * 40.f / tab_zoom ( & CT ) ;
CT . ws_sy - = ( float ) sdy * 40.f / tab_zoom ( & CT ) ;
float z = tab_zoom ( & CT ) ;
ed - > za . on = false ;
if ( sdx ! = 0.0 ) sa_to ( ed , & ed - > sa_ws_x , & CT . ws_sx , sa_base ( & ed - > sa_ws_x , CT . ws_sx ) - ( float ) sdx * 40.f / z ) ;
if ( sdy ! = 0.0 ) sa_to ( ed , & ed - > sa_ws_y , & CT . ws_sy , sa_base ( & ed - > sa_ws_y , CT . ws_sy ) - ( float ) sdy * 40.f / z ) ;
}
} else if ( view_at ( ed , mx , my ) = = V_PALETTE & & my > = PAL_Y ) {
if ( mx < FLY_X ) cat_scroll_by ( ed , - ( float ) sdy * 48.f ) ;
else fly_scroll_by ( ed , - ( float ) sdy * 48.f ) ;
if ( mx < FLY_X ) {
float t = fminf ( cat_max_scroll ( ed ) , fmaxf ( 0.f , sa_base ( & ed - > sa_cat , ed - > cat_scroll ) - ( float ) sdy * 48.f ) ) ;
sa_to ( ed , & ed - > sa_cat , & ed - > cat_scroll , t ) ;
} else {
float t = fminf ( fly_max_scroll ( ed ) , fmaxf ( 0.f , sa_base ( & ed - > sa_fly , ed - > fly_scroll ) - ( float ) sdy * 48.f ) ) ;
sa_to ( ed , & ed - > sa_fly , & ed - > fly_scroll , t ) ;
}
}
}
@@ -9057,6 +9612,7 @@ static bool editor_on_draw(TinyBlocks_Block* self, TinyBlocks* rt,
/* A pilha arrastada fica por cima de tudo (pode passar sobre a paleta) */
if ( ed - > state = = ES_DRAG & & ed - > drag_bi > = 0 )
render_drag_chain ( ed , rb ) ;
ghosts_render ( ed , rb ) ; /* blocos apagados saindo de cena */
render_areas_overlay ( ed , rb ) ;
render_plus_menu ( ed , rb ) ;
@@ -9121,6 +9677,10 @@ static bool editor_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
ed - > swap_pending [ 0 ] = ed - > swap_pending [ 1 ] = - 1 ;
ed - > mouse_owner = - 1 ;
ed - > te_handle_drag = - 1 ;
{ /* TINYBLOCKS_REDUCE_MOTION=1: sem animacoes (acessibilidade, testes) */
const char * rm = getenv ( " TINYBLOCKS_REDUCE_MOTION " ) ;
ed - > anim_off = rm & & rm [ 0 ] & & strcmp ( rm , " 0 " ) ! = 0 ;
}
ed - > ax_tree = tb_a11y_tree_new ( ) ;
tb_a11y_set_perform ( ed - > ax_tree , ax_perform , ed ) ;
{ /* TINYBLOCKS_A11Y=0 desliga; =log escreve os eventos no stderr (um narrador de texto) */
@@ -9222,6 +9782,8 @@ static void editor_instance_deinit(TinyBlocks_Block* self, TinyBlocks* rt) {
tab_doc_free ( & ed - > fly ) ; /* pool da paleta */
free ( ed - > fly_items ) ;
free ( ed - > fdlg . ents ) ;
qr_share_close ( ed ) ;
qr_recv_close ( ed ) ;
free ( ed - > sbp_text ) ;
free ( ed - > run_blocks ) ;
jit_reset ( ed ) ;