URI: 
       refactor box management -- towards trapezium - gramscii - A simple editor for ASCII box-and-arrow charts
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit e8c98a65cd161a5d2c0a76d41e39b352e083a9ab
   DIR parent ce2bfb4d3a49a27bde7c8bbc6c6b1ef6f80054aa
  HTML Author: KatolaZ <katolaz@freaknet.org>
       Date:   Sat, 17 Aug 2019 07:43:03 +0100
       
       refactor box management -- towards trapezium
       
       Diffstat:
         M draw.c                              |      88 +++++++++++++++++++++++--------
         M gramscii.h                          |      14 ++++++++++++--
       
       2 files changed, 77 insertions(+), 25 deletions(-)
       ---
   DIR diff --git a/draw.c b/draw.c
       @@ -161,7 +161,7 @@ void draw_parallelogram(int x1, int y1, char st, char fix){
                }
                else
                        f = draw_xy;
       -        if (st & BOX_PARR){
       +        if (st == BOX_PARR){
                        minoff = dy;
                        maxoff = 0;
                        lean = '/';
       @@ -195,47 +195,89 @@ void draw_parallelogram(int x1, int y1, char st, char fix){
        
        }
        
       -char flip_lean(char st){
       -        if (st & BOX_PARR)
       +char flip_par_lean(char st){
       +        if (st == BOX_PARR)
                        return BOX_PARL;
       -        else if (st & BOX_PARL)
       +        else if (st == BOX_PARL)
                        return BOX_PARR;
                return st;
        }
        
       +void draw_trapezium(int x1, int y1, char st, char fix){
       +
       +}
       +
       +/* 
       + * draw the current box, being it an actual box, a parallelogram, or a 
       + *  trapezium
       + */
       +void update_box(int x1, int y1, char st, char fix){
       +
       +        if (st == BOX_RECT)
       +                draw_box(x1, y1, fix);
       +        else if (st & BOX_PAR)
       +                draw_parallelogram(x1, y1, st, fix);
       +        else if (st & BOX_TRAP)
       +                draw_trapezium(x1, y1, st, fix);
       +        status_bar();
       +        show_cursor();
       +}
       +
       +char toggle_trap_type(char st){
       +        return st;
       +}
       +
       +int box_end(char c, char st){
       +        if (c == '\n' || 
       +            c == 27   ||
       +            ((st == BOX_RECT) &&  c == 'b') ||
       +            ((st & BOX_PAR)   &&  c == 'z') ||
       +            ((st & BOX_TRAP)  &&  c == 't'))
       +                return 1;
       +        return 0; 
       +}
       +
       +/* draw boxes, parallelograms, and trapezia */
        void get_box(FILE *fc, char st){
                char c;
                int orig_x=x, orig_y=y;
                redraw();
                step = 1;
       +#ifdef DEBUG
       +        fprintf(stderr, "box style: %d\n", st);
       +#endif
                draw_box(x,y,NOFIX);
       -        while((c=fgetc(fc))!=EOF && c != 27 && c!= 'b' && c != '\n'){
       -                if (c == 'Z'){
       -                        st = flip_lean(st);
       +        while((c=fgetc(fc))!=EOF && !box_end(c, st)){
       +                if (c == 'Z' && (st & BOX_PAR)){
       +                        st = flip_par_lean(st);
                                redraw();
       -                        goto update_box;
       +#ifdef DEBUG
       +        fprintf(stderr, "new parallelogram style: %d\n", st);
       +#endif
       +                        update_box(orig_x, orig_y, st, NOFIX);
       +                        continue;
       +                }
       +                else if (c == 'T' && (st & BOX_TRAP)){
       +                        st = toggle_trap_type(st);
       +                        redraw();
       +                        update_box(orig_x, orig_y, st, NOFIX);
       +                        continue;
       +                }
       +                if (change_style(c)){
       +                        update_box(orig_x, orig_y, st, NOFIX);
       +                        continue;
                        }
       -                if (change_style(c))
       -                        goto update_box;
                        if (!move_around(c, fc, 1)) 
                                continue;
                        check_bound(&x, &y);
                        redraw();
                        step = 1;
       -update_box:
       -                if (st == BOX_RECT)
       -                        draw_box(orig_x, orig_y, NOFIX);
       -                else
       -                        draw_parallelogram(orig_x, orig_y, st, NOFIX);
       -                status_bar();
       -                show_cursor();
       -        }
       -        if (st == BOX_RECT && (c == 'b' || c == '\n')){
       -                draw_box(orig_x, orig_y, FIX);
       -                modified = 1;
       +                update_box(orig_x, orig_y, st, NOFIX);
                }
       -        else if ((st & (BOX_PARR | BOX_PARL)) &&  (c == 'z' || c == '\n')){
       -                draw_parallelogram(orig_x, orig_y, st, FIX);
       +        if (((st == BOX_RECT ) && (c == 'b' || c == '\n')) ||
       +           ( (st &  BOX_PAR  ) && (c == 'z' || c == '\n')) ||
       +           ( (st &  BOX_TRAP ) && (c == 't' || c == '\n'))){
       +                update_box(orig_x, orig_y, st, FIX);
                        modified = 1;
                }
                redraw();
   DIR diff --git a/gramscii.h b/gramscii.h
       @@ -36,10 +36,20 @@
        /** box style **/
        /* rectangular box */
        #define BOX_RECT 0x00
       +/* parallelograms */
       +#define BOX_PAR  0x04
        /* parallelogram (leaning right) */
       -#define BOX_PARR 0x01
       +#define BOX_PARR 0x05
        /* parallelogram (leaning left) */
       -#define BOX_PARL 0x02
       +#define BOX_PARL 0x06
       +/* trapezium */
       +#define BOX_TRAP    0x10
       +#define BOX_TRAP_UR 0x11
       +#define BOX_TRAP_UC 0x12
       +#define BOX_TRAP_UL 0x13
       +#define BOX_TRAP_DL 0x14
       +#define BOX_TRAP_DC 0x15
       +#define BOX_TRAP_DR 0x16
        /**/
        
        #define NOFIX 0x0