aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/draw
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2018-11-15 20:24:38 -0500
committerRuss Cox <rsc@swtch.com>2018-11-15 20:39:35 -0500
commitbe0a15c47b75dc73a5c389cca125692f0cfdf726 (patch)
tree657433241298b2400e59d9bf897ab96571c26c40 /src/cmd/draw
parent8581c2b56763d7787604c8c833d2bd78bdc6a466 (diff)
downloadplan9port-be0a15c47b75dc73a5c389cca125692f0cfdf726.tar.gz
plan9port-be0a15c47b75dc73a5c389cca125692f0cfdf726.tar.bz2
plan9port-be0a15c47b75dc73a5c389cca125692f0cfdf726.zip
tweak: add support for Cursor2
Diffstat (limited to 'src/cmd/draw')
-rw-r--r--src/cmd/draw/tweak.c108
1 files changed, 78 insertions, 30 deletions
diff --git a/src/cmd/draw/tweak.c b/src/cmd/draw/tweak.c
index 9d7cd601..89fdef32 100644
--- a/src/cmd/draw/tweak.c
+++ b/src/cmd/draw/tweak.c
@@ -30,7 +30,7 @@ enum
Up = 1,
Down = 0,
Mag = 4,
- Maxmag = 10
+ Maxmag = 20
};
enum
@@ -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);
@@ -184,6 +184,7 @@ main(volatile int argc, char **volatile argv)
volatile int i;
Event e;
Thing *t;
+ Thing *nt;
ARGBEGIN{
case 'W':
@@ -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;
@@ -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
@@ -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;
@@ -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 */
@@ -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;
@@ -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){
/*
@@ -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");
@@ -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;
}
@@ -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");
}
@@ -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;
@@ -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);
}