commit cf9336060f7ba63be42921e98556135bb3adde82
parent 396870fd28aa3a8bf756768b8520bf0cdabc8c5c
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sun, 18 Apr 2021 19:49:37 -0700
Add more views and dismiss image offsets in setview
Diffstat:
M | lel.c | | | 39 | ++++++++++++++++++++++++++++++--------- |
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/lel.c b/lel.c
@@ -24,7 +24,7 @@
enum { NONE = 0, LOADED = 1, SCALED = 2, DRAWN = 4 };
/* View mode. */
-enum { ASPECT = 0, FULL_ASPECT, FULL_STRETCH };
+enum { ASPECT, FULL_ASPECT, FULL_STRETCH, FULL_WIDTH, FULL_HEIGHT };
struct img {
int index;
@@ -325,13 +325,20 @@ scaleview(void)
h = winheight;
break;
case FULL_ASPECT:
- if (winwidth * img.height > winheight * img.width) {
- w = img.width * winheight / img.height;
- h = winheight;
- } else {
- w = winwidth;
- h = img.height * winwidth / img.width;
- }
+ if (winwidth * img.height > winheight * img.width)
+ goto width;
+ else
+ goto height;
+ break;
+ case FULL_WIDTH:
+width:
+ w = winwidth;
+ h = img.height * winwidth / img.width;
+ break;
+ case FULL_HEIGHT:
+height:
+ w = img.width * winheight / img.height;
+ h = winheight;
break;
case ASPECT:
default:
@@ -383,6 +390,8 @@ setview(int mode)
if (viewmode == mode)
return;
viewmode = mode;
+ img.view.panyoffset = 0;
+ img.view.panxoffset = 0;
img.state &= ~(DRAWN | SCALED);
}
@@ -511,6 +520,12 @@ keypress(XEvent *ev)
previmg();
img.state &= ~(DRAWN | SCALED);
break;
+ case XK_w:
+ setview(FULL_WIDTH);
+ break;
+ case XK_e:
+ setview(FULL_HEIGHT);
+ break;
}
update();
}
@@ -589,14 +604,20 @@ main(int argc, char *argv[])
{
int c;
- while ((c = getopt(argc, argv, "af")) != -1) {
+ while ((c = getopt(argc, argv, "aefw")) != -1) {
switch (c) {
case 'a':
viewmode = FULL_ASPECT;
break;
+ case 'e':
+ viewmode = FULL_HEIGHT;
+ break;
case 'f':
viewmode = FULL_STRETCH;
break;
+ case 'w':
+ viewmode = FULL_WIDTH;
+ break;
default:
fprintf(stderr, "usage: %s [-afv] [file...]\n",
getprogname());