page: properly draw images with alpha channel, cleanup
This commit is contained in:
parent
4ad59914e8
commit
00f9b5d7f1
1 changed files with 32 additions and 28 deletions
|
@ -35,7 +35,8 @@ Point resize, pos;
|
||||||
Page *root, *current;
|
Page *root, *current;
|
||||||
QLock pagelock;
|
QLock pagelock;
|
||||||
int nullfd;
|
int nullfd;
|
||||||
Image *background;
|
|
||||||
|
Image *frame, *paper, *ground;
|
||||||
|
|
||||||
char pagespool[] = "/tmp/pagespool.";
|
char pagespool[] = "/tmp/pagespool.";
|
||||||
|
|
||||||
|
@ -929,6 +930,7 @@ zoomdraw(Image *d, Rectangle r, Rectangle top, Image *s, Point sp, int f)
|
||||||
Point a;
|
Point a;
|
||||||
|
|
||||||
if(f <= 1){
|
if(f <= 1){
|
||||||
|
gendrawdiff(d, r, top, paper, sp, nil, ZP, SoverD);
|
||||||
gendrawdiff(d, r, top, s, sp, nil, ZP, SoverD);
|
gendrawdiff(d, r, top, s, sp, nil, ZP, SoverD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -947,7 +949,7 @@ zoomdraw(Image *d, Rectangle r, Rectangle top, Image *s, Point sp, int f)
|
||||||
w = s->r.max.x - sp.x;
|
w = s->r.max.x - sp.x;
|
||||||
if(w > Dx(r))
|
if(w > Dx(r))
|
||||||
w = Dx(r);
|
w = Dx(r);
|
||||||
t = allocimage(display, Rect(r.min.x, r.min.y, r.min.x+w, r.max.y), s->chan, 0, DNofill);
|
t = allocimage(display, Rect(r.min.x, r.min.y, r.min.x+w, r.max.y), s->chan, 0, 0);
|
||||||
if(t == nil)
|
if(t == nil)
|
||||||
return;
|
return;
|
||||||
for(y=r.min.y; y<r.max.y; y++){
|
for(y=r.min.y; y<r.max.y; y++){
|
||||||
|
@ -957,16 +959,15 @@ zoomdraw(Image *d, Rectangle r, Rectangle top, Image *s, Point sp, int f)
|
||||||
sp.y++;
|
sp.y++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
x=r.min.x;
|
x=r.min.x;
|
||||||
for(sp=r.min; x<r.max.x; sp.x++){
|
for(sp=r.min; x<r.max.x; sp.x++){
|
||||||
|
gendrawdiff(d, Rect(x, r.min.y, x+1, r.max.y), top, paper, sp, nil, ZP, SoverD);
|
||||||
gendrawdiff(d, Rect(x, r.min.y, x+1, r.max.y), top, t, sp, nil, ZP, SoverD);
|
gendrawdiff(d, Rect(x, r.min.y, x+1, r.max.y), top, t, sp, nil, ZP, SoverD);
|
||||||
for(x++; ++a.x<f && x<r.max.x; x++)
|
for(x++; ++a.x<f && x<r.max.x; x++)
|
||||||
gendrawdiff(d, Rect(x, r.min.y, x+1, r.max.y), top, d,
|
gendrawdiff(d, Rect(x, r.min.y, x+1, r.max.y), top, d,
|
||||||
Pt(x-1, r.min.y), nil, ZP, SoverD);
|
Pt(x-1, r.min.y), nil, ZP, SoverD);
|
||||||
a.x = 0;
|
a.x = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeimage(t);
|
freeimage(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,47 +977,49 @@ pagesize(Page *p)
|
||||||
return p->image ? mulpt(subpt(p->image->r.max, p->image->r.min), zoom) : ZP;
|
return p->image ? mulpt(subpt(p->image->r.max, p->image->r.min), zoom) : ZP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
drawframe(Rectangle r)
|
||||||
|
{
|
||||||
|
border(screen, r, -Borderwidth, frame, ZP);
|
||||||
|
gendrawdiff(screen, screen->r, insetrect(r, -Borderwidth), ground, ZP, nil, ZP, SoverD);
|
||||||
|
flushimage(display, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawpage(Page *p)
|
drawpage(Page *p)
|
||||||
{
|
{
|
||||||
Rectangle r;
|
Rectangle r;
|
||||||
Image *i;
|
Image *i;
|
||||||
|
|
||||||
if((i = p->image) == nil){
|
if(i = p->image){
|
||||||
r.min = ZP;
|
|
||||||
r.max = stringsize(font, p->label);
|
|
||||||
r = rectaddpt(r, addpt(subpt(divpt(subpt(screen->r.max, screen->r.min), 2), divpt(r.max, 2)),
|
|
||||||
screen->r.min));
|
|
||||||
draw(screen, r, display->white, nil, ZP);
|
|
||||||
string(screen, r.min, display->black, ZP, font, p->label);
|
|
||||||
} else {
|
|
||||||
r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
|
r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
|
||||||
zoomdraw(screen, r, ZR, i, i->r.min, zoom);
|
zoomdraw(screen, r, ZR, i, i->r.min, zoom);
|
||||||
|
} else {
|
||||||
|
r = Rpt(ZP, stringsize(font, p->label));
|
||||||
|
r = rectaddpt(r, addpt(subpt(divpt(subpt(screen->r.max, screen->r.min), 2),
|
||||||
|
divpt(r.max, 2)), screen->r.min));
|
||||||
|
draw(screen, r, paper, nil, ZP);
|
||||||
|
string(screen, r.min, display->black, ZP, font, p->label);
|
||||||
}
|
}
|
||||||
gendrawdiff(screen, screen->r, r, background, ZP, nil, ZP, SoverD);
|
drawframe(r);
|
||||||
border(screen, r, -Borderwidth, display->black, ZP);
|
|
||||||
flushimage(display, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
translate(Page *p, Point d)
|
translate(Page *p, Point d)
|
||||||
{
|
{
|
||||||
Rectangle r, or, nr;
|
Rectangle r, nr;
|
||||||
Image *i;
|
Image *i;
|
||||||
|
|
||||||
i = p->image;
|
i = p->image;
|
||||||
if((i==0) || (d.x==0 && d.y==0))
|
if(i==0 || d.x==0 && d.y==0)
|
||||||
return;
|
return;
|
||||||
r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
|
r = rectaddpt(Rpt(ZP, pagesize(p)), addpt(pos, screen->r.min));
|
||||||
pos = addpt(pos, d);
|
pos = addpt(pos, d);
|
||||||
nr = rectaddpt(r, d);
|
nr = rectaddpt(r, d);
|
||||||
or = r;
|
rectclip(&r, screen->r);
|
||||||
rectclip(&or, screen->r);
|
draw(screen, rectaddpt(r, d), screen, nil, r.min);
|
||||||
draw(screen, rectaddpt(or, d), screen, nil, or.min);
|
zoomdraw(screen, nr, rectaddpt(r, d), i, i->r.min, zoom);
|
||||||
zoomdraw(screen, nr, rectaddpt(or, d), i, i->r.min, zoom);
|
drawframe(nr);
|
||||||
gendrawdiff(screen, screen->r, nr, background, ZP, nil, ZP, SoverD);
|
|
||||||
border(screen, nr, -Borderwidth, display->black, ZP);
|
|
||||||
flushimage(display, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Page*
|
Page*
|
||||||
|
@ -1229,14 +1232,15 @@ main(int argc, char *argv[])
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
initdraw(drawerr, nil, argv0);
|
initdraw(drawerr, nil, argv0);
|
||||||
background = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
|
paper = display->white;
|
||||||
draw(screen, screen->r, background, nil, ZP);
|
frame = display->black;
|
||||||
flushimage(display, 1);
|
ground = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x777777FF);
|
||||||
display->locking = 1;
|
display->locking = 1;
|
||||||
unlockdisplay(display);
|
unlockdisplay(display);
|
||||||
einit(Ekeyboard|Emouse);
|
einit(Ekeyboard|Emouse);
|
||||||
eplumb(Eplumb, "image");
|
eplumb(Eplumb, "image");
|
||||||
nullfd = open("/dev/null", ORDWR);
|
if((nullfd = open("/dev/null", ORDWR)) < 0)
|
||||||
|
sysfatal("open: %r");
|
||||||
current = root = addpage(nil, "root", nil, nil, -1);
|
current = root = addpage(nil, "root", nil, nil, -1);
|
||||||
|
|
||||||
if(*argv == nil && !imode)
|
if(*argv == nil && !imode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue