devdraw: add Cursor2 support on macOS 10.14 Mojave

This replaces the pixel-art scaling algorithm used for upscaling before.
The results were not crisp enough to serve as everyday cursors.
This commit is contained in:
Russ Cox 2018-11-15 20:28:56 -05:00
parent be0a15c47b
commit 7d43dde539
8 changed files with 113 additions and 45 deletions

View file

@ -11,3 +11,73 @@ Cursor bigarrow = {
0x61, 0xF0, 0x60, 0xE0, 0x40, 0x40, 0x00, 0x00,
},
};
Cursor2 bigarrow2 = {
{ -2, -2 },
{ 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xC0, 0x00, 0x00, 0x03,
0xC0, 0x00, 0x00, 0x07,
0xC0, 0x00, 0x00, 0x1E,
0xC0, 0x00, 0x00, 0x3C,
0xC0, 0x00, 0x00, 0xF0,
0xC0, 0x00, 0x03, 0xE0,
0xC0, 0x00, 0x0F, 0x80,
0xC0, 0x00, 0x0E, 0x00,
0xC0, 0x00, 0x07, 0x00,
0xC0, 0x00, 0x03, 0x80,
0xC0, 0x00, 0x01, 0xC0,
0xC0, 0x00, 0x00, 0xE0,
0xC0, 0x00, 0x00, 0x70,
0xC0, 0x00, 0x00, 0x38,
0xC0, 0x00, 0x00, 0x1C,
0xC0, 0x00, 0x00, 0x0E,
0xC0, 0x00, 0x00, 0x07,
0xC0, 0x00, 0x00, 0x03,
0xC0, 0xC0, 0x00, 0x07,
0xC0, 0xE0, 0x00, 0x0E,
0xC1, 0xF0, 0x00, 0x1C,
0xC1, 0xB8, 0x00, 0x38,
0xC3, 0x9C, 0x00, 0x70,
0xC3, 0x0E, 0x00, 0xE0,
0xC7, 0x07, 0x01, 0xC0,
0xCE, 0x03, 0x83, 0x80,
0xCC, 0x01, 0xC7, 0x00,
0xDC, 0x00, 0xEE, 0x00,
0xF8, 0x00, 0x7C, 0x00,
0xF0, 0x00, 0x38, 0x00,
},
{ 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0xFF, 0xFF, 0xF8,
0x3F, 0xFF, 0xFF, 0xE0,
0x3F, 0xFF, 0xFF, 0xC0,
0x3F, 0xFF, 0xFF, 0x00,
0x3F, 0xFF, 0xFC, 0x00,
0x3F, 0xFF, 0xF0, 0x00,
0x3F, 0xFF, 0xF0, 0x00,
0x3F, 0xFF, 0xF8, 0x00,
0x3F, 0xFF, 0xFC, 0x00,
0x3F, 0xFF, 0xFE, 0x00,
0x3F, 0xFF, 0xFF, 0x00,
0x3F, 0xFF, 0xFF, 0x80,
0x3F, 0xFF, 0xFF, 0xC0,
0x3F, 0xFF, 0xFF, 0xE0,
0x3F, 0xFF, 0xFF, 0xF0,
0x3F, 0xFF, 0xFF, 0xF8,
0x3F, 0xFF, 0xFF, 0xFC,
0x3F, 0x3F, 0xFF, 0xF8,
0x3F, 0x1F, 0xFF, 0xF0,
0x3E, 0x0F, 0xFF, 0xE0,
0x3E, 0x07, 0xFF, 0xC0,
0x3C, 0x03, 0xFF, 0x80,
0x3C, 0x01, 0xFF, 0x00,
0x38, 0x00, 0xFE, 0x00,
0x30, 0x00, 0x7C, 0x00,
0x30, 0x00, 0x38, 0x00,
0x20, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}
};

View file

@ -252,21 +252,30 @@ threadmain(int argc, char **argv)
[myContent enlargeLastInputRect:r];
}
typedef struct Cursors Cursors;
struct Cursors {
Cursor *c;
Cursor2 *c2;
};
+ (void)callsetcursor:(NSValue *)v
{
Cursors *cs;
Cursor *c;
Cursor2 *c2;
NSBitmapImageRep *r, *r2;
NSImage *i;
NSPoint p;
uint b, x, y, a;
uchar *plane[5], *plane2[5];
uchar pu, pb, pl, pr, pc; // upper, bottom, left, right, center
uchar pul, pur, pbl, pbr;
uchar ful, fur, fbl, fbr;
int b;
c = [v pointerValue];
cs = [v pointerValue];
c = cs->c;
if(!c)
c = &bigarrow;
c2 = cs->c2;
if(!c2)
c2 = &bigarrow2;
r = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil
@ -280,7 +289,7 @@ threadmain(int argc, char **argv)
bytesPerRow:2
bitsPerPixel:0];
[r getBitmapDataPlanes:plane];
for(b=0; b<2*16; b++){
for(b=0; b<nelem(c->set); b++){
plane[0][b] = ~c->set[b] & c->clr[b];
plane[1][b] = c->set[b] | c->clr[b];
}
@ -297,33 +306,9 @@ threadmain(int argc, char **argv)
bytesPerRow:4
bitsPerPixel:0];
[r2 getBitmapDataPlanes:plane2];
// https://en.wikipedia.org/wiki/Pixel-art_scaling_algorithms#EPX/Scale2×/AdvMAME2×
for(a=0; a<2; a++){
for(y=0; y<16; y++){
for(x=0; x<2; x++){
pc = plane[a][x+2*y];
pu = y==0 ? pc : plane[a][x+2*(y-1)];
pb = y==15 ? pc : plane[a][x+2*(y+1)];
pl = (pc>>1) | (x==0 ? pc&0x80 : (plane[a][x-1+2*y]&1)<<7);
pr = (pc<<1) | (x==1 ? pc&1 : (plane[a][x+1+2*y]&0x80)>>7);
ful = ~(pl^pu) & (pl^pb) & (pu^pr);
pul = (ful & pu) | (~ful & pc);
fur = ~(pu^pr) & (pu^pl) & (pr^pb);
pur = (fur & pr) | (~fur & pc);
fbl = ~(pb^pl) & (pb^pr) & (pl^pu);
pbl = (fbl & pl) | (~fbl & pc);
fbr = ~(pr^pb) & (pr^pu) & (pb^pl);
pbr = (fbr & pb) | (~fbr & pc);
plane2[a][2*x+4*2*y] = (pul&0x80) | ((pul&0x40)>>1) | ((pul&0x20)>>2) | ((pul&0x10)>>3)
| ((pur&0x80)>>1) | ((pur&0x40)>>2) | ((pur&0x20)>>3) | ((pur&0x10)>>4);
plane2[a][2*x+1+4*2*y] = ((pul&0x8)<<4) | ((pul&0x4)<<3) | ((pul&0x2)<<2) | ((pul&0x1)<<1)
| ((pur&0x8)<<3) | ((pur&0x4)<<2) | ((pur&0x2)<<1) | (pur&0x1);
plane2[a][2*x+4*(2*y+1)] = (pbl&0x80) | ((pbl&0x40)>>1) | ((pbl&0x20)>>2) | ((pbl&0x10)>>3)
| ((pbr&0x80)>>1) | ((pbr&0x40)>>2) | ((pbr&0x20)>>3) | ((pbr&0x10)>>4);
plane2[a][2*x+1+4*(2*y+1)] = ((pbl&0x8)<<4) | ((pbl&0x4)<<3) | ((pbl&0x2)<<2) | ((pbl&0x1)<<1)
| ((pbr&0x8)<<3) | ((pbr&0x4)<<2) | ((pbr&0x2)<<1) | (pbr&0x1);
}
}
for(b=0; b<nelem(c2->set); b++){
plane2[0][b] = ~c2->set[b] & c2->clr[b];
plane2[1][b] = c2->set[b] | c2->clr[b];
}
// For checking out the cursor bitmap image
@ -943,7 +928,7 @@ attachscreen(char *label, char *winsize)
withObject:[NSValue valueWithPointer:winsize]
waitUntilDone:YES];
kicklabel(label);
setcursor(nil);
setcursor(nil, nil);
mouseresized = 0;
return initimg();
}
@ -1099,11 +1084,16 @@ kicklabel(char *label)
}
void
setcursor(Cursor *c)
setcursor(Cursor *c, Cursor2 *c2)
{
Cursors cs;
cs.c = c;
cs.c2 = c2;
[AppDelegate
performSelectorOnMainThread:@selector(callsetcursor:)
withObject:[NSValue valueWithPointer:c]
withObject:[NSValue valueWithPointer:&cs]
waitUntilDone:YES];
}

View file

@ -2,7 +2,7 @@
Memimage *attachscreen(char*, char*);
void setmouse(Point);
void setcursor(Cursor*);
void setcursor(Cursor*, Cursor2*);
void setlabel(char*);
char* getsnarf(void);
void putsnarf(char*);

View file

@ -1410,8 +1410,10 @@ kicklabel0(char *label) {
}
void
setcursor(Cursor *c)
setcursor(Cursor *c, Cursor2 *c2)
{
USED(c2);
/*
* No cursor change unless in main thread.
*/
@ -1658,3 +1660,9 @@ setprocname(const char *s)
if(err != noErr)
fprint(2, "Call to set process name failed\n");
}
void
resizewindow(Rectangle r)
{
USED(r);
}

View file

@ -163,9 +163,9 @@ runmsg(Wsysmsg *m)
case Tcursor:
if(m->arrowcursor)
setcursor(nil);
setcursor(nil, nil);
else
setcursor(&m->cursor);
setcursor(&m->cursor, &m->cursor2);
replymsg(m);
break;
@ -221,9 +221,7 @@ runmsg(Wsysmsg *m)
break;
case Tresize:
#if OSX_VERSION >= 101400
resizewindow(m->rect);
#endif
replymsg(m);
break;
}

View file

@ -3,6 +3,8 @@
TARG=devdraw
SHORTLIB=draw memdraw
WSYSOFILES=\
devdraw.$O\
latin1.$O\

View file

@ -5,7 +5,7 @@ void zunlock(void);
Memimage *attachscreen(char*, char*);
void setmouse(Point);
void setcursor(Cursor*);
void setcursor(Cursor*, Cursor2*);
void setlabel(char*);
char* getsnarf(void);
void putsnarf(char*);

View file

@ -230,9 +230,9 @@ runmsg(Wsysmsg *m)
case Tcursor:
if(m->arrowcursor)
setcursor(nil);
setcursor(nil, nil);
else
setcursor(&m->cursor);
setcursor(&m->cursor, &m->cursor2);
replymsg(m);
break;