aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/devdraw
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2018-11-15 20:28:56 -0500
committerRuss Cox <rsc@swtch.com>2018-11-15 20:39:35 -0500
commit7d43dde539378fb5730df6ce961f7916f495746e (patch)
treedf3db29164e5ed9d556db391b2ed56145883d682 /src/cmd/devdraw
parentbe0a15c47b75dc73a5c389cca125692f0cfdf726 (diff)
downloadplan9port-7d43dde539378fb5730df6ce961f7916f495746e.tar.gz
plan9port-7d43dde539378fb5730df6ce961f7916f495746e.tar.bz2
plan9port-7d43dde539378fb5730df6ce961f7916f495746e.zip
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.
Diffstat (limited to 'src/cmd/devdraw')
-rw-r--r--src/cmd/devdraw/bigarrow.h70
-rw-r--r--src/cmd/devdraw/cocoa-screen-metal.m62
-rw-r--r--src/cmd/devdraw/cocoa-screen.h2
-rw-r--r--src/cmd/devdraw/cocoa-screen.m10
-rw-r--r--src/cmd/devdraw/cocoa-srv.c6
-rw-r--r--src/cmd/devdraw/mkfile2
-rw-r--r--src/cmd/devdraw/osx-screen.h2
-rw-r--r--src/cmd/devdraw/osx-srv.c4
8 files changed, 113 insertions, 45 deletions
diff --git a/src/cmd/devdraw/bigarrow.h b/src/cmd/devdraw/bigarrow.h
index 3b66c954..1221ec8c 100644
--- a/src/cmd/devdraw/bigarrow.h
+++ b/src/cmd/devdraw/bigarrow.h
@@ -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,
+ 0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FF, 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,
+ }
+};
diff --git a/src/cmd/devdraw/cocoa-screen-metal.m b/src/cmd/devdraw/cocoa-screen-metal.m
index c82ce0bc..049d1c5c 100644
--- a/src/cmd/devdraw/cocoa-screen-metal.m
+++ b/src/cmd/devdraw/cocoa-screen-metal.m
@@ -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];
}
diff --git a/src/cmd/devdraw/cocoa-screen.h b/src/cmd/devdraw/cocoa-screen.h
index 7b41c34b..b5e3c701 100644
--- a/src/cmd/devdraw/cocoa-screen.h
+++ b/src/cmd/devdraw/cocoa-screen.h
@@ -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*);
diff --git a/src/cmd/devdraw/cocoa-screen.m b/src/cmd/devdraw/cocoa-screen.m
index 16053eaa..c2489a6c 100644
--- a/src/cmd/devdraw/cocoa-screen.m
+++ b/src/cmd/devdraw/cocoa-screen.m
@@ -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);
+}
diff --git a/src/cmd/devdraw/cocoa-srv.c b/src/cmd/devdraw/cocoa-srv.c
index 6f9449ad..329dd71f 100644
--- a/src/cmd/devdraw/cocoa-srv.c
+++ b/src/cmd/devdraw/cocoa-srv.c
@@ -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;
}
diff --git a/src/cmd/devdraw/mkfile b/src/cmd/devdraw/mkfile
index 2e40087e..7f0c2a20 100644
--- a/src/cmd/devdraw/mkfile
+++ b/src/cmd/devdraw/mkfile
@@ -3,6 +3,8 @@
TARG=devdraw
+SHORTLIB=draw memdraw
+
WSYSOFILES=\
devdraw.$O\
latin1.$O\
diff --git a/src/cmd/devdraw/osx-screen.h b/src/cmd/devdraw/osx-screen.h
index f50d8dfe..d5ba3dd2 100644
--- a/src/cmd/devdraw/osx-screen.h
+++ b/src/cmd/devdraw/osx-screen.h
@@ -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*);
diff --git a/src/cmd/devdraw/osx-srv.c b/src/cmd/devdraw/osx-srv.c
index 6cbb5235..d0a1c2d3 100644
--- a/src/cmd/devdraw/osx-srv.c
+++ b/src/cmd/devdraw/osx-srv.c
@@ -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;