input: timers: Implement remove + docs.
[gfxprim/pasky.git] / demos / spiv / spiv_help.c
blob4a80fd2ca6861977dd64653b3bdcd56e3da7b823
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
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. *
8 * *
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. *
13 * *
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 *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <stdio.h>
24 #include <GP.h>
26 static const char *keys_help[] = {
27 "Keyboard control:",
28 "",
29 "Esc, Enter, Q - quit spiv",
30 "",
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)",
36 "",
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",
43 "",
44 "I - toggle show info box",
45 "P - toggle show progress",
46 "",
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",
52 "H - toggle help",
53 "",
54 "F1-F10 - execute action 0 - 9",
55 "",
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",
60 "...",
61 "9 - resize spiv window to the ninth of the image size",
62 "",
63 "Shift 2 - resize spiv window twice of the image size",
64 "Shift 3 - resize spiv window three times of the image size",
65 "...",
68 static const int keys_help_len = sizeof(keys_help) / sizeof(char*);
70 void print_help(void)
72 int i;
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");
83 printf(" -z mode\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");
88 puts("\n");
89 printf("Actions:\n\n");
90 printf(" -0 'cmd' sets first action\n");
91 printf(" -1 'cmd' sets second action\n");
92 printf(" ...\n");
93 printf(" -9 'cmd' sets tenth action\n");
94 puts("");
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");
101 puts("\n");
103 for (i = 0; i < keys_help_len; i++)
104 puts(keys_help[i]);
106 puts("");
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);
125 int i;
127 GP_Fill(c, black);
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)
133 goto out;
135 GP_Print(c, NULL, 20 + 10 * xoff, h, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
136 white, black, "%s", keys_help[i]);
139 out:
140 GP_BackendFlip(backend);
141 return i;
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);
155 for (;;) {
156 GP_Event ev;
158 while (GP_BackendWaitEvent(backend, &ev)) {
159 switch (ev.type) {
160 case GP_EV_KEY:
161 if (ev.code != GP_EV_KEY_DOWN)
162 continue;
164 switch (ev.val.key.key) {
165 case GP_KEY_DOWN:
166 if (last < keys_help_len)
167 last = redraw_help(backend, ++loff, xoff);
168 break;
169 case GP_KEY_UP:
170 if (loff > 0)
171 last = redraw_help(backend, --loff, xoff);
172 break;
173 case GP_KEY_LEFT:
174 last = redraw_help(backend, loff, --xoff);
175 break;
176 case GP_KEY_RIGHT:
177 last = redraw_help(backend, loff, ++xoff);
178 break;
179 case GP_KEY_PAGE_DOWN:
180 if (last < keys_help_len) {
181 if (loff + max_lines(backend) >= keys_help_len)
182 break;
184 loff += max_lines(backend);
186 last = redraw_help(backend, loff, xoff);
188 break;
189 case GP_KEY_PAGE_UP:
190 if (loff > 0) {
191 loff -= max_lines(backend);
192 if (loff < 0)
193 loff = 0;
194 last = redraw_help(backend, loff, xoff);
196 break;
197 default:
198 return;
200 break;
201 case GP_EV_SYS:
202 switch (ev.code) {
203 case GP_EV_SYS_RESIZE:
204 GP_BackendResizeAck(backend);
205 last = redraw_help(backend, loff, xoff);
206 break;
207 case GP_EV_SYS_QUIT:
208 GP_BackendPutEventBack(backend, &ev);
209 return;