URI: 
       ttweak: add support for Cursor2 - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit be0a15c47b75dc73a5c389cca125692f0cfdf726
   DIR parent 8581c2b56763d7787604c8c833d2bd78bdc6a466
  HTML Author: Russ Cox <rsc@swtch.com>
       Date:   Thu, 15 Nov 2018 20:24:38 -0500
       
       ttweak: add support for Cursor2
       
       Diffstat:
         M src/cmd/draw/tweak.c                |     108 ++++++++++++++++++++++---------
       
       1 file changed, 78 insertions(+), 30 deletions(-)
       ---
   DIR diff --git a/src/cmd/draw/tweak.c b/src/cmd/draw/tweak.c
       t@@ -30,7 +30,7 @@ enum
                Up                = 1,
                Down        = 0,
                Mag                = 4,
       -        Maxmag        = 10
       +        Maxmag        = 20
        };
        
        enum
       t@@ -161,7 +161,7 @@ Image                *values[256];
        Image                *greyvalues[256];
        uchar                data[8192];
        
       -Thing*        tget(char*);
       +Thing*        tget(char*, int);
        void        mesg(char*, ...);
        void        drawthing(Thing*, int);
        void        xselect(void);
       t@@ -184,6 +184,7 @@ main(volatile int argc, char **volatile argv)
                volatile int i;
                Event e;
                Thing *t;
       +        Thing *nt;
        
                ARGBEGIN{
                case 'W':
       t@@ -209,9 +210,14 @@ main(volatile int argc, char **volatile argv)
                setjmp(err);
                for(; i<argc; i++){
                        file = argv[i];
       -                t = tget(argv[i]);
       -                if(t)
       +                t = tget(argv[i], 1);
       +                if(t) {
       +                        nt = t->next;
       +                        t->next = 0;
                                drawthing(t, 1);
       +                        if(nt)
       +                                drawthing(nt, 1);
       +                }
                        flushimage(display, 1);
                }
                file = 0;
       t@@ -382,6 +388,8 @@ stext(Thing *t, char *l0, char *l1)
                }else if(t->s)
                        sprint(l1, "offset(hex): %ux n:%d  height:%d  ascent:%d",
                                t->off, t->s->n, t->s->height, t->s->ascent);
       +        else if(t->face == CURSOR)
       +                sprint(l0+strlen(l0), " cursor:%d", Dx(t->b->r));
        }
        
        void
       t@@ -569,7 +577,7 @@ tohex(int c)
        }
        
        Thing*
       -tget(char *file)
       +tget(char *file, int extra)
        {
                int i, j, fd, face, x, y, c, chan;
                Image *b;
       t@@ -577,8 +585,9 @@ tget(char *file)
                Thing *t;
                Dir *volatile d;
                jmp_buf oerr;
       -        uchar buf[256];
       +        uchar buf[300];
                char *data;
       +        Rectangle r;
        
                buf[0] = '\0';
                errstr((char*)buf, sizeof buf);        /* flush pending error message */
       t@@ -628,17 +637,15 @@ tget(char *file)
                                close(fd);
                                goto Err;
                        }
       -                b = allocimage(display, Rect(0, 0, 16, 32), GREY1, 0, DNofill);
       -                if(b == 0){
       -                        mesg("image alloc failed file %s: %r", file);
       -                        free(data);
       -                        close(fd);
       -                        goto Err;
       -                }
                        i = 0;
       -                for(x=0;x<64; ){
       -                        if((c=data[i]) == '\0')
       -                                goto ill;
       +                for(x=0;; ){
       +                        if((c=data[i]) == '\0' || x > 256) {
       +                                if(x == 64 || x == 256)
       +                                        goto HaveCursor;
       +                                mesg("ill-formed cursor file %s", file);
       +                                close(fd);
       +                                goto Err;
       +                        }
                                if(c=='0' && data[i+1] == 'x'){
                                        i += 2;
                                        continue;
       t@@ -650,7 +657,19 @@ tget(char *file)
                                }
                                i++;
                        }
       -                loadimage(b, Rect(0, 0, 16, 32), buf, sizeof buf);
       +        HaveCursor:
       +                if(x == 64)
       +                        r = Rect(0, 0, 16, 32);
       +                else
       +                        r = Rect(0, 0, 32, 64);
       +                b = allocimage(display, r, GREY1, 0, DNofill);
       +                if(b == 0){
       +                        mesg("image alloc failed file %s: %r", file);
       +                        free(data);
       +                        close(fd);
       +                        goto Err;
       +                }
       +                loadimage(b, r, buf, sizeof buf);
                        free(data);
                }else if(memcmp(buf, "0x", 2)==0){
                        /*
       t@@ -752,7 +771,7 @@ tget(char *file)
                                s = readsubfonti(display, file, fd, b, 0);
                }
                close(fd);
       -        t = malloc(sizeof(Thing));
       +        t = mallocz(sizeof(Thing), 1);
                if(t == 0){
           nomem:
                        mesg("malloc failed: %r");
       t@@ -775,6 +794,40 @@ tget(char *file)
                t->c = -1;
                t->mag = 1;
                t->off = 0;
       +        if(face == CURSOR && extra && Dx(t->b->r) == 16) {
       +                // Make 32x32 cursor as second image.
       +                Thing *nt;
       +                Cursor c;
       +                Cursor2 c2;
       +
       +                nt = mallocz(sizeof(Thing), 1);
       +                if(nt == 0)
       +                        goto nomem;
       +                nt->name = strdup("");
       +                if(nt->name == 0) {
       +                        free(nt);
       +                        goto nomem;
       +                }
       +                b = allocimage(display, Rect(0, 0, 32, 64), GREY1, 0, DNofill);
       +                if(b == nil) {
       +                        free(nt->name);
       +                        free(nt);
       +                        goto nomem;
       +                }
       +                memmove(c.clr, buf, 64);
       +                scalecursor(&c2, &c);
       +                memmove(buf, c2.clr, 256);
       +                loadimage(b, b->r, buf, sizeof buf);
       +                t->next = nt;
       +                nt->b = b;
       +                nt->s = 0;
       +                nt->face = CURSOR;
       +                nt->mod = 0;
       +                nt->parent = 0;
       +                nt->c = -1;
       +                nt->mag = 1;
       +                nt->off = 0;
       +        }
                memmove(err, oerr, sizeof err);
                return t;
        }
       t@@ -1637,18 +1690,13 @@ twrite(Thing *t)
                                                Bprint(&buf, "%.2x", data[i+j]);
                                        Bprint(&buf, ", ");
                                }
       -                        if(t->face == CURSOR){
       -                                switch(y){
       -                                case 3: case 7: case 11: case 19: case 23: case 27:
       -                                        Bprint(&buf, "\n ");
       -                                        break;
       -                                case 15:
       +                        if(t->face == CURSOR) {
       +                                if(y == Dy(r)/2-1)
                                                Bprint(&buf, "},\n{");
       -                                        break;
       -                                case 31:
       +                                else if(y == Dy(r)-1)
                                                Bprint(&buf, "}\n");
       -                                        break;
       -                                }
       +                                else
       +                                        Bprint(&buf, "\n\t");
                                }else
                                        Bprint(&buf, "\n");
                        }
       t@@ -1759,7 +1807,7 @@ tread(Thing *t)
        
                if(t->parent)
                        t = t->parent;
       -        new = tget(t->name);
       +        new = tget(t->name, 0);
                if(new == 0)
                        return;
                nclosed = 0;
       t@@ -2025,7 +2073,7 @@ menu(void)
                switch(sel){
                case Mopen:
                        if(type(buf, "file")){
       -                        t = tget(buf);
       +                        t = tget(buf, 0);
                                if(t)
                                        drawthing(t, 1);
                        }