1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
26 static const char *keys_help
[] = {
29 "Esc, Enter, Q - quit spiv",
31 "< or KP Minus - zoom out by 1.5",
32 "> or KP Plus - zoom in by 1.5",
33 "R - rotate by 90 degrees clockwise",
34 "Up, Down, Left, Right - move image by 1px",
35 " (by 10 with Shift)",
37 "Space - move to the next image",
38 "BackSpace - move to the prev image",
39 "PgDown - move to the start of directory",
40 "PgUp - move to the end of directory",
41 "Home - move to the first image",
42 "End - move to the last image",
44 "I - toggle show info box",
45 "P - toggle show progress",
47 "] - change to next resampling method",
48 "[ - change to prev resampling method",
49 " (current method is shown in info box)",
50 "L - toggle low pass filter",
51 "D - drop image cache",
54 "F1-F10 - execute action 0 - 9",
56 "1 - resize spiv window to the image size",
57 "1 - resize spiv window to the image size",
58 "2 - resize spiv window to the half of the image size",
59 "3 - resize spiv window to the third of the image size",
61 "9 - resize spiv window to the ninth of the image size",
63 "Shift 2 - resize spiv window twice of the image size",
64 "Shift 3 - resize spiv window three times of the image size",
68 static const int keys_help_len
= sizeof(keys_help
) / sizeof(char*);
74 printf("Usage: spiv [opts] images or dirs with images\n\n");
75 printf(" -I show image info box\n");
76 printf(" -P show loading progress\n");
77 printf(" -f use floyd-steinberg dithering\n");
78 printf(" -s msec slideshow interval in miliseconds\n");
79 printf(" -c turns on bicubic resampling (experimental)\n");
80 printf(" -e pixel_type turns on backend type emulation\n");
81 printf(" for example -e G1 sets 1-bit grayscale\n");
82 printf(" -r angle rotate display 90,180 or 270 degrees\n");
84 printf(" -zf zoom is set and modified by user\n");
85 printf(" -zw zoom is fixed to window size (currently default)\n");
86 printf(" -b pass backend init string to backend init\n");
87 printf(" pass -b help for more info\n");
89 printf("Actions:\n\n");
90 printf(" -0 'cmd' sets first action\n");
91 printf(" -1 'cmd' sets second action\n");
93 printf(" -9 'cmd' sets tenth action\n");
95 printf(" actions are shell commands with following modifiers:\n");
96 printf(" %%f path to current image\n");
97 printf(" %%F shell escaped path to current image\n");
98 printf(" %%n current image filename without extension\n");
99 printf(" %%N shell escaped image filename without extension\n");
100 printf(" %%e current image file extension\n");
103 for (i
= 0; i
< keys_help_len
; i
++)
108 printf("Some cool options to try:\n\n");
109 printf("spiv -0 'cp %%F sorted' [images]\n");
110 printf("\tcopies current image into directory 'sorted/' on F1\n");
111 printf("spiv -e G1 -f [images]\n");
112 printf("\truns spiv in 1-bit bitmap mode and turns on dithering\n\n");
113 printf("spiv -b 'X11:ROOT_WIN' [images]\n");
114 printf("\truns spiv using X root window as backend window\n\n");
115 printf("spiv -b 'X11:CREATE_ROOT' [images]\n");
116 printf("\tSame as abowe but works in KDE\n");
120 static int redraw_help(GP_Backend
*backend
, unsigned int loff
, GP_Coord xoff
)
122 GP_Context
*c
= backend
->context
;
123 GP_Pixel black
= GP_ColorToContextPixel(GP_COL_BLACK
, c
);
124 GP_Pixel white
= GP_ColorToContextPixel(GP_COL_WHITE
, c
);
129 for (i
= loff
; i
< keys_help_len
; i
++) {
130 GP_Coord h
= 2 + (i
- loff
) * 15;
132 if (h
+ 2 >= (GP_Coord
)c
->h
)
135 GP_Print(c
, NULL
, 20 + 10 * xoff
, h
, GP_ALIGN_RIGHT
|GP_VALIGN_BOTTOM
,
136 white
, black
, "%s", keys_help
[i
]);
140 GP_BackendFlip(backend
);
144 static int max_lines(GP_Backend
*backend
)
146 return (backend
->context
->h
- 4) / 15;
149 void draw_help(GP_Backend
*backend
)
151 int loff
= 0, last
, xoff
= 0;
153 last
= redraw_help(backend
, loff
, xoff
);
158 while (GP_BackendWaitEvent(backend
, &ev
)) {
161 if (ev
.code
!= GP_EV_KEY_DOWN
)
164 switch (ev
.val
.key
.key
) {
166 if (last
< keys_help_len
)
167 last
= redraw_help(backend
, ++loff
, xoff
);
171 last
= redraw_help(backend
, --loff
, xoff
);
174 last
= redraw_help(backend
, loff
, --xoff
);
177 last
= redraw_help(backend
, loff
, ++xoff
);
179 case GP_KEY_PAGE_DOWN
:
180 if (last
< keys_help_len
) {
181 if (loff
+ max_lines(backend
) >= keys_help_len
)
184 loff
+= max_lines(backend
);
186 last
= redraw_help(backend
, loff
, xoff
);
191 loff
-= max_lines(backend
);
194 last
= redraw_help(backend
, loff
, xoff
);
203 case GP_EV_SYS_RESIZE
:
204 GP_BackendResizeAck(backend
);
205 last
= redraw_help(backend
, loff
, xoff
);
208 GP_BackendPutEventBack(backend
, &ev
);