jpg: center image in screen

when using the jpg(1) programs interactively, draw the
image in the center of it. this avoids wasting space
with always on borders on small windows and looks better
when used in fullscreen.
This commit is contained in:
cinap_lenrek 2014-02-08 02:33:29 +01:00
parent b3df8945bd
commit 7af85b9e74
9 changed files with 93 additions and 29 deletions

View file

@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readbmp(int fd, int colorspace);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(image->r);
r.max.y = r.min.y+Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);

View file

@ -26,14 +26,14 @@ char *show(int, char*);
Rectangle
imager(void)
{
Rectangle r;
Point p1, p2;
if(allims==nil || allims[0]==nil)
return screen->r;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(allims[0]->r);
r.max.y = r.min.y+Dy(allims[0]->r);
return r;
p1 = addpt(divpt(subpt(allims[0]->r.max, allims[0]->r.min), 2), allims[0]->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(allims[0]->r, subpt(p2, p1));
}
void

View file

@ -26,6 +26,16 @@ enum{
char *show(int, char*, int);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -37,9 +47,7 @@ eresized(int new)
}
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(image->r);
r.max.y = r.min.y+Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);

View file

@ -23,6 +23,16 @@ enum{
char *show(int, char*, int);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -34,9 +44,7 @@ eresized(int new)
}
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(image->r);
r.max.y = r.min.y+Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
draw(screen, r, image, nil, image->r.min);
flushimage(display, 1);

View file

@ -22,6 +22,16 @@ enum{
char *show(int, char*);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -33,9 +43,7 @@ eresized(int new)
}
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(image->r);
r.max.y = r.min.y+Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);

View file

@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readtga(int fd);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(image->r);
r.max.y = r.min.y+Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);

View file

@ -22,6 +22,16 @@ enum {
int init(void);
char *show(int, char *, int);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -31,9 +41,7 @@ eresized(int new)
sysfatal("getwindow: %r");
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x + Dx(image->r);
r.max.y = r.min.y + Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);

View file

@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readV210(int fd, int colorspace);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(image->r);
r.max.y = r.min.y+Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);

View file

@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readyuv(int fd, int colorspace);
Rectangle
imager(Image *i)
{
Point p1, p2;
p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
return rectaddpt(i->r, subpt(p2, p1));
}
void
eresized(int new)
{
@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
r = insetrect(screen->clipr, Edge+Border);
r.max.x = r.min.x+Dx(image->r);
r.max.y = r.min.y+Dy(image->r);
r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);