tweak: add support for Cursor2
This commit is contained in:
parent
8581c2b567
commit
be0a15c47b
1 changed files with 78 additions and 30 deletions
|
|
@ -30,7 +30,7 @@ enum
|
||||||
Up = 1,
|
Up = 1,
|
||||||
Down = 0,
|
Down = 0,
|
||||||
Mag = 4,
|
Mag = 4,
|
||||||
Maxmag = 10
|
Maxmag = 20
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
@ -161,7 +161,7 @@ Image *values[256];
|
||||||
Image *greyvalues[256];
|
Image *greyvalues[256];
|
||||||
uchar data[8192];
|
uchar data[8192];
|
||||||
|
|
||||||
Thing* tget(char*);
|
Thing* tget(char*, int);
|
||||||
void mesg(char*, ...);
|
void mesg(char*, ...);
|
||||||
void drawthing(Thing*, int);
|
void drawthing(Thing*, int);
|
||||||
void xselect(void);
|
void xselect(void);
|
||||||
|
|
@ -184,6 +184,7 @@ main(volatile int argc, char **volatile argv)
|
||||||
volatile int i;
|
volatile int i;
|
||||||
Event e;
|
Event e;
|
||||||
Thing *t;
|
Thing *t;
|
||||||
|
Thing *nt;
|
||||||
|
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'W':
|
case 'W':
|
||||||
|
|
@ -209,9 +210,14 @@ main(volatile int argc, char **volatile argv)
|
||||||
setjmp(err);
|
setjmp(err);
|
||||||
for(; i<argc; i++){
|
for(; i<argc; i++){
|
||||||
file = argv[i];
|
file = argv[i];
|
||||||
t = tget(argv[i]);
|
t = tget(argv[i], 1);
|
||||||
if(t)
|
if(t) {
|
||||||
|
nt = t->next;
|
||||||
|
t->next = 0;
|
||||||
drawthing(t, 1);
|
drawthing(t, 1);
|
||||||
|
if(nt)
|
||||||
|
drawthing(nt, 1);
|
||||||
|
}
|
||||||
flushimage(display, 1);
|
flushimage(display, 1);
|
||||||
}
|
}
|
||||||
file = 0;
|
file = 0;
|
||||||
|
|
@ -382,6 +388,8 @@ stext(Thing *t, char *l0, char *l1)
|
||||||
}else if(t->s)
|
}else if(t->s)
|
||||||
sprint(l1, "offset(hex): %ux n:%d height:%d ascent:%d",
|
sprint(l1, "offset(hex): %ux n:%d height:%d ascent:%d",
|
||||||
t->off, t->s->n, t->s->height, t->s->ascent);
|
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
|
void
|
||||||
|
|
@ -569,7 +577,7 @@ tohex(int c)
|
||||||
}
|
}
|
||||||
|
|
||||||
Thing*
|
Thing*
|
||||||
tget(char *file)
|
tget(char *file, int extra)
|
||||||
{
|
{
|
||||||
int i, j, fd, face, x, y, c, chan;
|
int i, j, fd, face, x, y, c, chan;
|
||||||
Image *b;
|
Image *b;
|
||||||
|
|
@ -577,8 +585,9 @@ tget(char *file)
|
||||||
Thing *t;
|
Thing *t;
|
||||||
Dir *volatile d;
|
Dir *volatile d;
|
||||||
jmp_buf oerr;
|
jmp_buf oerr;
|
||||||
uchar buf[256];
|
uchar buf[300];
|
||||||
char *data;
|
char *data;
|
||||||
|
Rectangle r;
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
errstr((char*)buf, sizeof buf); /* flush pending error message */
|
errstr((char*)buf, sizeof buf); /* flush pending error message */
|
||||||
|
|
@ -628,17 +637,15 @@ tget(char *file)
|
||||||
close(fd);
|
close(fd);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
b = allocimage(display, Rect(0, 0, 16, 32), GREY1, 0, DNofill);
|
i = 0;
|
||||||
if(b == 0){
|
for(x=0;; ){
|
||||||
mesg("image alloc failed file %s: %r", file);
|
if((c=data[i]) == '\0' || x > 256) {
|
||||||
free(data);
|
if(x == 64 || x == 256)
|
||||||
|
goto HaveCursor;
|
||||||
|
mesg("ill-formed cursor file %s", file);
|
||||||
close(fd);
|
close(fd);
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
i = 0;
|
|
||||||
for(x=0;x<64; ){
|
|
||||||
if((c=data[i]) == '\0')
|
|
||||||
goto ill;
|
|
||||||
if(c=='0' && data[i+1] == 'x'){
|
if(c=='0' && data[i+1] == 'x'){
|
||||||
i += 2;
|
i += 2;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -650,7 +657,19 @@ tget(char *file)
|
||||||
}
|
}
|
||||||
i++;
|
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);
|
free(data);
|
||||||
}else if(memcmp(buf, "0x", 2)==0){
|
}else if(memcmp(buf, "0x", 2)==0){
|
||||||
/*
|
/*
|
||||||
|
|
@ -752,7 +771,7 @@ tget(char *file)
|
||||||
s = readsubfonti(display, file, fd, b, 0);
|
s = readsubfonti(display, file, fd, b, 0);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
t = malloc(sizeof(Thing));
|
t = mallocz(sizeof(Thing), 1);
|
||||||
if(t == 0){
|
if(t == 0){
|
||||||
nomem:
|
nomem:
|
||||||
mesg("malloc failed: %r");
|
mesg("malloc failed: %r");
|
||||||
|
|
@ -775,6 +794,40 @@ tget(char *file)
|
||||||
t->c = -1;
|
t->c = -1;
|
||||||
t->mag = 1;
|
t->mag = 1;
|
||||||
t->off = 0;
|
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);
|
memmove(err, oerr, sizeof err);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
@ -1637,18 +1690,13 @@ twrite(Thing *t)
|
||||||
Bprint(&buf, "%.2x", data[i+j]);
|
Bprint(&buf, "%.2x", data[i+j]);
|
||||||
Bprint(&buf, ", ");
|
Bprint(&buf, ", ");
|
||||||
}
|
}
|
||||||
if(t->face == CURSOR){
|
if(t->face == CURSOR) {
|
||||||
switch(y){
|
if(y == Dy(r)/2-1)
|
||||||
case 3: case 7: case 11: case 19: case 23: case 27:
|
|
||||||
Bprint(&buf, "\n ");
|
|
||||||
break;
|
|
||||||
case 15:
|
|
||||||
Bprint(&buf, "},\n{");
|
Bprint(&buf, "},\n{");
|
||||||
break;
|
else if(y == Dy(r)-1)
|
||||||
case 31:
|
|
||||||
Bprint(&buf, "}\n");
|
Bprint(&buf, "}\n");
|
||||||
break;
|
else
|
||||||
}
|
Bprint(&buf, "\n\t");
|
||||||
}else
|
}else
|
||||||
Bprint(&buf, "\n");
|
Bprint(&buf, "\n");
|
||||||
}
|
}
|
||||||
|
|
@ -1759,7 +1807,7 @@ tread(Thing *t)
|
||||||
|
|
||||||
if(t->parent)
|
if(t->parent)
|
||||||
t = t->parent;
|
t = t->parent;
|
||||||
new = tget(t->name);
|
new = tget(t->name, 0);
|
||||||
if(new == 0)
|
if(new == 0)
|
||||||
return;
|
return;
|
||||||
nclosed = 0;
|
nclosed = 0;
|
||||||
|
|
@ -2025,7 +2073,7 @@ menu(void)
|
||||||
switch(sel){
|
switch(sel){
|
||||||
case Mopen:
|
case Mopen:
|
||||||
if(type(buf, "file")){
|
if(type(buf, "file")){
|
||||||
t = tget(buf);
|
t = tget(buf, 0);
|
||||||
if(t)
|
if(t)
|
||||||
drawthing(t, 1);
|
drawthing(t, 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue