commit - 8581c2b56763d7787604c8c833d2bd78bdc6a466
commit + be0a15c47b75dc73a5c389cca125692f0cfdf726
blob - 9d7cd60197e60807186f745a37a1b6f98d934736
blob + 89fdef32a1b84e2532a3142148ba6befa1de921d
--- src/cmd/draw/tweak.c
+++ src/cmd/draw/tweak.c
Up = 1,
Down = 0,
Mag = 4,
- Maxmag = 10
+ Maxmag = 20
};
enum
Image *greyvalues[256];
uchar data[8192];
-Thing* tget(char*);
+Thing* tget(char*, int);
void mesg(char*, ...);
void drawthing(Thing*, int);
void xselect(void);
volatile int i;
Event e;
Thing *t;
+ Thing *nt;
ARGBEGIN{
case 'W':
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;
}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
}
Thing*
-tget(char *file)
+tget(char *file, int extra)
{
int i, j, fd, face, x, y, c, chan;
Image *b;
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 */
data[d->length] = 0;
if(read(fd, data, d->length) != d->length){
mesg("can't read cursor file %s: %r", 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;
}
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){
/*
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->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;
}
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:
- Bprint(&buf, "},\n{");
- break;
- case 31:
+ if(t->face == CURSOR) {
+ if(y == Dy(r)/2-1)
+ Bprint(&buf, "},\n{");
+ else if(y == Dy(r)-1)
Bprint(&buf, "}\n");
- break;
- }
+ else
+ Bprint(&buf, "\n\t");
}else
Bprint(&buf, "\n");
}
if(t->parent)
t = t->parent;
- new = tget(t->name);
+ new = tget(t->name, 0);
if(new == 0)
return;
nclosed = 0;
switch(sel){
case Mopen:
if(type(buf, "file")){
- t = tget(buf);
+ t = tget(buf, 0);
if(t)
drawthing(t, 1);
}