boxes

Tracer des diagrammes dans un terminal - retour accueil

git clone git://bebou.netlib.re/boxes

Log | Files | Refs | README |

commit f9b903d07daa8d29cd5a6bdf0c09f135e1791dfe
parent cd38384a002af2c601d40eb4a02c49285c21d069
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Fri, 13 Jun 2025 21:45:03 +0200

Facto du décompte des boites quand on suppr une

Diffstat:
Mboxes.c | 14+++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/boxes.c b/boxes.c @@ -32,8 +32,9 @@ struct box createbox(int x, int y, int w, int h) { struct box b; b.x=x; b.y=y; b.w=w; b.h=h; return b; } -void deletebox(struct box* boxes, int index, int boxescount) { +int deletebox(struct box* boxes, int index, int boxescount) { for (int i=index;i<boxescount-1;i++) boxes[i]=boxes[i+1]; + return boxescount-1; } int main(int argc, char **argv) { @@ -46,6 +47,7 @@ int main(int argc, char **argv) { while(1) { tb_clear(); for (int i=0;i<boxescount;i++) drawbox(boxes[i]); + tb_printf(tb_height(),0,TB_DEFAULT,TB_DEFAULT,"count: %d",boxescount); tb_present(); tb_poll_event(&ev); switch(ev.key) { @@ -66,16 +68,14 @@ int main(int argc, char **argv) { boxes[boxescount]=b; boxescount++; break; case 26: /*ctrl+z*/ - deletebox(boxes,boxescount-1,boxescount); - boxescount=max(boxescount-1,0); + boxescount=deletebox(boxes,boxescount-1,boxescount); break; case 65511: /*MouseRight*/ - for(int i=0;i<boxescount;i++) { + for(int i=0;i<boxescount;i++) if(ev.x==boxes[i].x && ev.y==boxes[i].y) { - deletebox(boxes,i,boxescount); - boxescount=max(boxescount-1,0); + boxescount=deletebox(boxes,i,boxescount); + break; } - } break; } }