paint: cleanup
This commit is contained in:
parent
aade29ca7c
commit
639cec9329
1 changed files with 40 additions and 18 deletions
|
@ -15,6 +15,7 @@ Image *back;
|
||||||
Image *pal[16]; /* palette */
|
Image *pal[16]; /* palette */
|
||||||
Rectangle palr; /* palette rect on screen */
|
Rectangle palr; /* palette rect on screen */
|
||||||
Rectangle penr; /* pen size rect on screen */
|
Rectangle penr; /* pen size rect on screen */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NBRUSH = 10+1,
|
NBRUSH = 10+1,
|
||||||
};
|
};
|
||||||
|
@ -41,6 +42,29 @@ int c64[] = { /* c64 color palette */
|
||||||
0x959595,
|
0x959595,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get bounding rectnagle for stroke from r.min to r.max with
|
||||||
|
* specified brush (size).
|
||||||
|
*/
|
||||||
|
static Rectangle
|
||||||
|
strokerect(Rectangle r, int brush)
|
||||||
|
{
|
||||||
|
r = canonrect(r);
|
||||||
|
return Rect(r.min.x-brush, r.min.y-brush, r.max.x+brush+1, r.max.y+brush+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* draw stroke from r.min to r.max to dst with color ink and
|
||||||
|
* brush (size).
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
strokedraw(Image *dst, Rectangle r, Image *ink, int brush)
|
||||||
|
{
|
||||||
|
if(!eqpt(r.min, r.max))
|
||||||
|
line(dst, r.min, r.max, Enddisc, Enddisc, brush, ink, ZP);
|
||||||
|
fillellipse(dst, r.max, brush, brush, ink, ZP);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A draw operation that touches only the area contained in bot but not in top.
|
* A draw operation that touches only the area contained in bot but not in top.
|
||||||
* mp and sp get aligned with bot.min.
|
* mp and sp get aligned with bot.min.
|
||||||
|
@ -259,7 +283,7 @@ restore(int n)
|
||||||
if((tmp = undo[x]) == nil)
|
if((tmp = undo[x]) == nil)
|
||||||
return;
|
return;
|
||||||
undo[x] = nil;
|
undo[x] = nil;
|
||||||
if(canvas != nil && canvas->chan != tmp->chan){
|
if(canvas == nil || canvas->chan != tmp->chan){
|
||||||
freeimage(canvas);
|
freeimage(canvas);
|
||||||
canvas = tmp;
|
canvas = tmp;
|
||||||
update(nil);
|
update(nil);
|
||||||
|
@ -456,19 +480,21 @@ drawpal(void)
|
||||||
|
|
||||||
r = penr;
|
r = penr;
|
||||||
draw(screen, r, back, nil, ZP);
|
draw(screen, r, back, nil, ZP);
|
||||||
for(i=0; i<10; i++){
|
for(i=0; i<NBRUSH; i++){
|
||||||
r.max.x = penr.min.x + (i+1)*Dx(penr) / NBRUSH;
|
r.max.x = penr.min.x + (i+1)*Dx(penr) / NBRUSH;
|
||||||
rr = r;
|
rr = r;
|
||||||
if(i == brush)
|
if(i == brush)
|
||||||
rr.min.y += Dy(r)/3;
|
rr.min.y += Dy(r)/3;
|
||||||
fillellipse(screen, addpt(rr.min, divpt(subpt(rr.max, rr.min), 2)), i, i, ink, ZP);
|
if(i == NBRUSH-1){
|
||||||
|
/* last is special brush for fill draw */
|
||||||
|
draw(screen, rr, ink, nil, ZP);
|
||||||
|
} else {
|
||||||
|
rr.min = addpt(rr.min, divpt(subpt(rr.max, rr.min), 2));
|
||||||
|
rr.max = rr.min;
|
||||||
|
strokedraw(screen, rr, ink, i);
|
||||||
|
}
|
||||||
r.min.x = r.max.x;
|
r.min.x = r.max.x;
|
||||||
}
|
}
|
||||||
r.max.x = penr.min.x + (i+1)*Dx(penr) / NBRUSH;
|
|
||||||
rr = r;
|
|
||||||
if(i == brush)
|
|
||||||
rr.min.y += Dy(r)/3;
|
|
||||||
draw(screen, rr, ink, nil, ZP);
|
|
||||||
|
|
||||||
r = palr;
|
r = palr;
|
||||||
for(i=1; i<=nelem(pal); i++){
|
for(i=1; i<=nelem(pal); i++){
|
||||||
|
@ -620,7 +646,7 @@ main(int argc, char *argv[])
|
||||||
/* no break */
|
/* no break */
|
||||||
case 1:
|
case 1:
|
||||||
p = s2c(e.mouse.xy);
|
p = s2c(e.mouse.xy);
|
||||||
if(brush >= 10){
|
if(brush == NBRUSH-1){
|
||||||
/* flood fill brush */
|
/* flood fill brush */
|
||||||
if(canvas == nil || !ptinrect(p, canvas->r)){
|
if(canvas == nil || !ptinrect(p, canvas->r)){
|
||||||
back = img;
|
back = img;
|
||||||
|
@ -638,10 +664,10 @@ main(int argc, char *argv[])
|
||||||
;
|
;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
r = Rect(p.x-brush, p.y-brush, p.x+brush+1, p.y+brush+1);
|
r = strokerect(Rpt(p, p), brush);
|
||||||
expand(r);
|
expand(r);
|
||||||
save(r, 1);
|
save(r, 1);
|
||||||
fillellipse(canvas, p, brush, brush, img, ZP);
|
strokedraw(canvas, Rpt(p, p), img, brush);
|
||||||
update(&r);
|
update(&r);
|
||||||
for(;;){
|
for(;;){
|
||||||
m = e.mouse;
|
m = e.mouse;
|
||||||
|
@ -652,14 +678,10 @@ main(int argc, char *argv[])
|
||||||
d = s2c(e.mouse.xy);
|
d = s2c(e.mouse.xy);
|
||||||
if(eqpt(d, p))
|
if(eqpt(d, p))
|
||||||
continue;
|
continue;
|
||||||
r = canonrect(Rpt(p, d));
|
r = strokerect(Rpt(p, d), brush);
|
||||||
r.min.x -= brush;
|
|
||||||
r.min.y -= brush;
|
|
||||||
r.max.x += brush+1;
|
|
||||||
r.max.y += brush+1;
|
|
||||||
expand(r);
|
expand(r);
|
||||||
save(r, 0);
|
save(r, 0);
|
||||||
line(canvas, p, d, Enddisc, Enddisc, brush, img, ZP);
|
strokedraw(canvas, Rpt(p, d), img, brush);
|
||||||
update(&r);
|
update(&r);
|
||||||
p = d;
|
p = d;
|
||||||
}
|
}
|
||||||
|
@ -702,7 +724,7 @@ main(int argc, char *argv[])
|
||||||
restore(16);
|
restore(16);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
brush = 10;
|
brush = NBRUSH-1;
|
||||||
drawpal();
|
drawpal();
|
||||||
break;
|
break;
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
|
|
Loading…
Reference in a new issue