Rev 8505 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8446 | maxcodehac | 1 | /*==== INCLUDES ====*/ |
2 | |||
4680 | right-hear | 3 | #include "fitz.h" |
4 | #include "mupdf.h" |
||
5 | #include "pdfapp.h" |
||
4696 | right-hear | 6 | #include "icons/allbtns.h" |
8436 | maxcodehac | 7 | #include "kolibri.h" |
4680 | right-hear | 8 | |
9 | |||
5496 | leency | 10 | /*==== DATA ====*/ |
11 | |||
12 | static char Title[1024] = "uPDF"; |
||
13 | static pdfapp_t gapp; |
||
14 | char debugstr[256]; |
||
15 | char do_not_blit=0; |
||
16 | |||
17 | #define TOOLBAR_HEIGHT 34 |
||
8505 | maxcodehac | 18 | struct proc_info Form; |
5496 | leency | 19 | |
20 | #define DOCUMENT_BORDER 0x979797 |
||
21 | #define DOCUMENT_BG 0xABABAB |
||
22 | |||
5508 | leency | 23 | #define SCROLL_H 25 |
5496 | leency | 24 | |
5508 | leency | 25 | short show_area_w = 65; |
26 | short show_area_x; |
||
27 | |||
28 | char key_mode_enter_page_number; |
||
29 | int new_page_number; |
||
30 | |||
31 | static short window_center, draw_h, draw_w; |
||
32 | |||
5496 | leency | 33 | const char *help[] = { |
34 | "Keys:", |
||
35 | " ", |
||
36 | "PageUp - go to previous page", |
||
37 | "PageDown - go to next page", |
||
38 | "Home - go to first page", |
||
39 | "End - go to last page", |
||
40 | "Down arrow - scroll current page down", |
||
41 | "Up arrow - scroll current page up", |
||
42 | "+/- - zoom in/out", |
||
43 | "[ or l - rotate page 90 deg to the left", |
||
44 | "] or r - rotate page 90 deg to the right", |
||
5508 | leency | 45 | "g - grayscale on/off", |
5496 | leency | 46 | " ", |
47 | "Press Escape to hide help", |
||
48 | |||
49 | }; |
||
50 | |||
51 | /*==== CODE ====*/ |
||
8436 | maxcodehac | 52 | // Prototypes // |
53 | void RunApp(char app[], char param[]); |
||
54 | void winblit(pdfapp_t *app); |
||
55 | void DrawPagination(void); |
||
56 | void HandleNewPageNumber(unsigned char key); |
||
57 | void ApplyNewPageNumber(void); |
||
8446 | maxcodehac | 58 | void DrawMainWindow(void); |
5496 | leency | 59 | |
60 | |||
61 | // not implemented yet |
||
62 | void wincursor(pdfapp_t *app, int curs) { } |
||
63 | void winhelp(pdfapp_t *app) { } |
||
64 | void winresize(pdfapp_t *app, int w, int h) { } |
||
65 | void windocopy(pdfapp_t *app) { } |
||
66 | void winopenuri(pdfapp_t *app, char *buf) { } |
||
67 | void winrepaintsearch(pdfapp_t *app) { } |
||
68 | |||
69 | |||
4680 | right-hear | 70 | void winwarn(pdfapp_t *app, char *msg) |
71 | { |
||
72 | fprintf(stderr, "mupdf: %s\n", msg); |
||
73 | } |
||
74 | |||
5496 | leency | 75 | |
4680 | right-hear | 76 | void winerror(pdfapp_t *app, fz_error error) |
77 | { |
||
78 | fz_catch(error, "aborting"); |
||
79 | exit(1); |
||
80 | } |
||
81 | |||
5496 | leency | 82 | |
4680 | right-hear | 83 | char *winpassword(pdfapp_t *app, char *filename) |
84 | { |
||
85 | char *r = ""; |
||
86 | return r; |
||
7533 | leency | 87 | random(); |
4680 | right-hear | 88 | } |
89 | |||
90 | |||
8438 | maxcodehac | 91 | void wintitle(pdfapp_t *app, char *s, char param[]) |
4680 | right-hear | 92 | { |
5496 | leency | 93 | sprintf(Title,"%s - uPDF", strrchr(param, '/') + 1 ); |
4680 | right-hear | 94 | } |
95 | |||
96 | |||
97 | void winreloadfile(pdfapp_t *app) |
||
98 | { |
||
5496 | leency | 99 | //pdfapp_close(app); |
100 | //pdfapp_open(app, filename, 0, 1); |
||
4680 | right-hear | 101 | } |
102 | |||
103 | void winclose(pdfapp_t *app) |
||
104 | { |
||
105 | pdfapp_close(&gapp); |
||
8436 | maxcodehac | 106 | exit(0); |
4680 | right-hear | 107 | } |
108 | |||
8436 | maxcodehac | 109 | void RunOpenApp(char name[]) |
7533 | leency | 110 | { |
8436 | maxcodehac | 111 | char cmd[250] = "*pdf* "; |
112 | strcat(cmd, name); |
||
113 | RunApp("/sys/lod", cmd); |
||
7533 | leency | 114 | } |
5496 | leency | 115 | |
7533 | leency | 116 | |
5496 | leency | 117 | void winrepaint(pdfapp_t *app) |
4680 | right-hear | 118 | { |
5496 | leency | 119 | winblit(&gapp); |
4680 | right-hear | 120 | } |
121 | |||
122 | |||
5496 | leency | 123 | void winblit(pdfapp_t *app) |
4680 | right-hear | 124 | { |
125 | |||
5496 | leency | 126 | if (do_not_blit) return; |
4680 | right-hear | 127 | |
5508 | leency | 128 | if (key_mode_enter_page_number==1) HandleNewPageNumber(0); else DrawPagination(); |
129 | |||
8505 | maxcodehac | 130 | if (Form.cwidth > gapp.image->w) window_center = (Form.cwidth - gapp.image->w) / 2; else window_center = 0; |
4680 | right-hear | 131 | |
5821 | leency | 132 | gapp.panx = 0; |
8461 | maxcodehac | 133 | |
9960 | turbocat | 134 | kos_blit(window_center + Form.cleft, |
135 | Form.ctop + TOOLBAR_HEIGHT, |
||
136 | Form.cwidth, |
||
137 | Form.cheight - TOOLBAR_HEIGHT, |
||
8461 | maxcodehac | 138 | gapp.panx, |
139 | gapp.pany, |
||
140 | gapp.image->w, |
||
141 | gapp.image->h, |
||
142 | gapp.image->w * gapp.image->n, // stride |
||
143 | gapp.image->samples // image |
||
144 | ); |
||
145 | |||
146 | /* |
||
147 | void kos_blit(int dstx, int dsty, int w, int h, int srcx, int srcy, int srcw, int srch, int stride, char *d) |
||
148 | */ |
||
149 | |||
5508 | leency | 150 | } |
151 | |||
152 | |||
153 | void DrawPageSides(void) |
||
7624 | leency | 154 | { |
8505 | maxcodehac | 155 | if (gapp.image->h < Form.cheight - TOOLBAR_HEIGHT) { |
7624 | leency | 156 | draw_h = gapp.image->h - gapp.pany; |
157 | } else { |
||
8505 | maxcodehac | 158 | draw_h = Form.cheight - TOOLBAR_HEIGHT; |
7624 | leency | 159 | } |
160 | |||
8505 | maxcodehac | 161 | if (gapp.image->w < Form.cwidth) { |
162 | window_center = (Form.cwidth - gapp.image->w) / 2; |
||
7624 | leency | 163 | draw_w = gapp.image->w + 2; |
8505 | maxcodehac | 164 | kol_paint_bar(0, TOOLBAR_HEIGHT, window_center-1, Form.cheight - TOOLBAR_HEIGHT, DOCUMENT_BG); |
7475 | leency | 165 | kol_paint_bar(window_center-1, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
166 | kol_paint_bar(window_center + gapp.image->w, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
||
8505 | maxcodehac | 167 | kol_paint_bar(window_center + gapp.image->w+1, TOOLBAR_HEIGHT, Form.cwidth - window_center - gapp.image->w - 1, Form.cheight - TOOLBAR_HEIGHT, DOCUMENT_BG); |
7624 | leency | 168 | } else { |
5508 | leency | 169 | window_center = 1; |
8505 | maxcodehac | 170 | draw_w = Form.cwidth; |
5508 | leency | 171 | } |
7624 | leency | 172 | |
7475 | leency | 173 | kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT, draw_w, 1, DOCUMENT_BORDER); |
9960 | turbocat | 174 | kol_paint_bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT + 1, |
8505 | maxcodehac | 175 | draw_w, Form.cheight - gapp.image->h - TOOLBAR_HEIGHT + gapp.pany - 1, DOCUMENT_BG); |
4680 | right-hear | 176 | } |
177 | |||
178 | |||
5508 | leency | 179 | void GetNewPageNumber(void) |
180 | { |
||
181 | new_page_number = gapp.pageno; |
||
182 | key_mode_enter_page_number = 1; |
||
183 | HandleNewPageNumber(0); |
||
184 | } |
||
5496 | leency | 185 | |
5508 | leency | 186 | void HandleNewPageNumber(unsigned char key) |
5496 | leency | 187 | { |
5508 | leency | 188 | char label_new_page[8]; |
189 | |||
190 | if ((key >= '0') && (key <= '9')) |
||
5496 | leency | 191 | { |
5508 | leency | 192 | new_page_number = new_page_number * 10 + key - '0'; |
5496 | leency | 193 | } |
5508 | leency | 194 | if (key == ASCII_KEY_BS) |
195 | { |
||
196 | new_page_number /= 10; |
||
197 | } |
||
198 | if (key == ASCII_KEY_ENTER) |
||
199 | { |
||
200 | ApplyNewPageNumber(); |
||
201 | return; |
||
202 | } |
||
9960 | turbocat | 203 | if (key==ASCII_KEY_ESC) |
5508 | leency | 204 | { |
205 | key_mode_enter_page_number = 0; |
||
8446 | maxcodehac | 206 | DrawMainWindow(); |
5508 | leency | 207 | return; |
208 | } |
||
209 | |||
210 | itoa(new_page_number, label_new_page, 10); |
||
211 | strcat(label_new_page, "_"); |
||
7475 | leency | 212 | kol_paint_bar(show_area_x, 6, show_area_w, 22, 0xFDF88E); |
8446 | maxcodehac | 213 | kos_text(show_area_x + show_area_w/2 - strlen(label_new_page)*6/2, 14, 0x000000, label_new_page, strlen(label_new_page)); |
5508 | leency | 214 | |
215 | if (new_page_number > gapp.pagecount) ApplyNewPageNumber(); |
||
5496 | leency | 216 | } |
217 | |||
5508 | leency | 218 | void ApplyNewPageNumber(void) |
219 | { |
||
220 | key_mode_enter_page_number = 0; |
||
221 | gapp.pageno = new_page_number -1; |
||
222 | pdfapp_onkey(&gapp, ']'); |
||
223 | } |
||
5496 | leency | 224 | |
225 | void DrawPagination(void) |
||
226 | { |
||
227 | char pages_display[12]; |
||
7475 | leency | 228 | kol_paint_bar(show_area_x, 6, show_area_w, 22, 0xF4F4F4); |
5496 | leency | 229 | sprintf (pages_display, "%d/%d", gapp.pageno, gapp.pagecount); |
8446 | maxcodehac | 230 | kos_text(show_area_x + show_area_w/2 - strlen(pages_display)*6/2, 14, 0x000000, pages_display, strlen(pages_display)); |
5496 | leency | 231 | } |
232 | |||
7624 | leency | 233 | void DrawToolbarButton(int x, char image_id) |
234 | { |
||
8446 | maxcodehac | 235 | kol_btn_define(x, 5, 26-1, 24-1, 10 + image_id + BT_HIDE, 0); |
9960 | turbocat | 236 | kol_paint_image(x, 5, 26, 24, image_id * 24 * 26 * 3 + toolbar_image); |
7624 | leency | 237 | } |
5496 | leency | 238 | |
8446 | maxcodehac | 239 | void DrawMainWindow(void) |
5496 | leency | 240 | { |
8505 | maxcodehac | 241 | kol_paint_bar(0, 0, Form.cwidth, TOOLBAR_HEIGHT - 1, 0xe1e1e1); // bar on the top (buttons holder) |
242 | kol_paint_bar(0, TOOLBAR_HEIGHT - 1, Form.cwidth, 1, 0x7F7F7F); |
||
5508 | leency | 243 | DrawToolbarButton(8,0); //open_folder |
244 | DrawToolbarButton(42,1); //magnify - |
||
245 | DrawToolbarButton(67,2); //magnify + |
||
246 | DrawToolbarButton(101,6); //rotate left |
||
247 | DrawToolbarButton(126,7); //rotate right |
||
8505 | maxcodehac | 248 | DrawToolbarButton(Form.cwidth - 160,3); //show help |
249 | show_area_x = Form.cwidth - show_area_w - 34; |
||
5508 | leency | 250 | DrawToolbarButton(show_area_x - 26,4); //prev page |
251 | DrawToolbarButton(show_area_x + show_area_w,5); //nex page |
||
8446 | maxcodehac | 252 | kol_btn_define(show_area_x-1, 5, show_area_w+1, 23, 20 + BT_HIDE, 0xA4A4A4); |
7475 | leency | 253 | kol_paint_bar(show_area_x, 5, show_area_w, 1, 0xA4A4A4); |
254 | kol_paint_bar(show_area_x, 28, show_area_w, 1, 0xA4A4A4); |
||
5496 | leency | 255 | winblit(&gapp); |
256 | DrawPageSides(); |
||
257 | } |
||
258 | |||
259 | |||
260 | /* Actions */ |
||
261 | |||
262 | void PageScrollDown(void) |
||
263 | { |
||
5497 | leency | 264 | //pdfapp_onkey(&gapp, 'k'); //move down |
8505 | maxcodehac | 265 | if (gapp.image->h - gapp.pany - SCROLL_H < Form.cheight - TOOLBAR_HEIGHT) |
5496 | leency | 266 | { |
267 | pdfapp_onkey(&gapp, '.'); |
||
268 | } |
||
269 | else { |
||
270 | gapp.pany += SCROLL_H; |
||
271 | winblit(&gapp); |
||
272 | } |
||
273 | } |
||
274 | |||
275 | |||
276 | void PageScrollUp(void) |
||
277 | { |
||
5497 | leency | 278 | //pdfapp_onkey(&gapp, 'j'); //move up |
5496 | leency | 279 | if (gapp.pany >= SCROLL_H) { |
280 | gapp.pany -= SCROLL_H; |
||
281 | winblit(&gapp); |
||
282 | } |
||
283 | else { |
||
5497 | leency | 284 | //not very nice way of using do_not_blit, but it simple |
5496 | leency | 285 | if (gapp.pageno == 1) return; |
286 | do_not_blit = 1; |
||
287 | pdfapp_onkey(&gapp, ','); |
||
288 | do_not_blit = 0; |
||
8505 | maxcodehac | 289 | gapp.pany = gapp.image->h - SCROLL_H - Form.cheight + TOOLBAR_HEIGHT; |
5496 | leency | 290 | if (gapp.pany < 0) gapp.pany = 0; |
291 | //sprintf (debugstr, "gapp.pany: %d \n", gapp.pany); |
||
7475 | leency | 292 | //kol_board_puts(debugstr); |
5496 | leency | 293 | winblit(&gapp); |
294 | } |
||
295 | } |
||
296 | |||
7475 | leency | 297 | void RunApp(char app[], char param[]) |
298 | { |
||
299 | kol_struct70 r; |
||
300 | r.p00 = 7; |
||
301 | r.p04 = 0; |
||
302 | r.p08 = param; |
||
303 | r.p12 = 0; |
||
304 | r.p16 = 0; |
||
305 | r.p20 = 0; |
||
306 | r.p21 = app; |
||
307 | kol_file_70(&r); |
||
308 | } |
||
5496 | leency | 309 | |
310 | void PageZoomIn(void) |
||
311 | { |
||
312 | pdfapp_onkey(&gapp, '+'); |
||
313 | DrawPageSides(); |
||
314 | } |
||
315 | |||
316 | |||
317 | void PageZoomOut(void) |
||
318 | { |
||
319 | pdfapp_onkey(&gapp, '-'); |
||
320 | DrawPageSides(); |
||
321 | } |
||
322 | |||
5497 | leency | 323 | void PageRotateLeft(void) |
324 | { |
||
325 | pdfapp_onkey(&gapp, 'L'); |
||
326 | DrawPageSides(); |
||
327 | } |
||
5496 | leency | 328 | |
5497 | leency | 329 | void PageRotateRight(void) |
330 | { |
||
331 | pdfapp_onkey(&gapp, 'R'); |
||
332 | DrawPageSides(); |
||
333 | } |
||
334 | |||
8436 | maxcodehac | 335 | int main (int argc, char* argv[]) |
7624 | leency | 336 | { |
337 | char ii, mouse_wheels_state; |
||
338 | |||
8438 | maxcodehac | 339 | // argv without spaces |
340 | char full_argv[1024]; |
||
341 | for (int i = 1; i |
||
342 | if (i != 1) strcat(full_argv, " "); |
||
343 | strcat(full_argv, argv[i]); |
||
344 | } |
||
345 | |||
8436 | maxcodehac | 346 | if (argc == 1) { |
8461 | maxcodehac | 347 | kol_board_puts("uPDF: no param set, showing OpenDialog...\n"); |
8436 | maxcodehac | 348 | RunOpenApp(argv[0]); |
349 | exit(0); |
||
7624 | leency | 350 | } |
351 | |||
8438 | maxcodehac | 352 | kol_board_puts(full_argv); |
7624 | leency | 353 | kol_board_puts("\n"); |
354 | |||
355 | char buf[128]; |
||
356 | int resolution = 72; |
||
357 | int pageno = 1; |
||
358 | fz_accelerate(); |
||
8461 | maxcodehac | 359 | kol_board_puts("PDF init...\n"); |
7624 | leency | 360 | pdfapp_init(&gapp); |
361 | gapp.scrw = 600; |
||
362 | gapp.scrh = 400; |
||
363 | gapp.resolution = resolution; |
||
364 | gapp.pageno = pageno; |
||
8461 | maxcodehac | 365 | kol_board_puts("PDF Open...\n"); |
8438 | maxcodehac | 366 | pdfapp_open(&gapp, full_argv, 0, 0); |
8461 | maxcodehac | 367 | kol_board_puts("PDF Opened!\n"); |
8438 | maxcodehac | 368 | wintitle(&gapp, 0, full_argv); |
7624 | leency | 369 | |
370 | kol_board_puts("Inital paint\n"); |
||
371 | |||
372 | int butt, key, screen_max_x, screen_max_y; |
||
8446 | maxcodehac | 373 | kos_screen_max(&screen_max_x, &screen_max_y); |
374 | kol_event_mask(EVENT_REDRAW+EVENT_KEY+EVENT_BUTTON+EVENT_MOUSE_CHANGE); |
||
7624 | leency | 375 | |
8436 | maxcodehac | 376 | for(;;) |
7624 | leency | 377 | { |
9960 | turbocat | 378 | switch(kol_event_wait()) |
8436 | maxcodehac | 379 | { |
380 | case evReDraw: |
||
381 | // gapp.shrinkwrap = 2; |
||
9960 | turbocat | 382 | kol_paint_start(); |
8446 | maxcodehac | 383 | kol_wnd_define(screen_max_x / 2 - 350-50+kos_random(50), |
8436 | maxcodehac | 384 | screen_max_y / 2 - 300-50+kos_random(50), |
385 | 700, 600, 0x73000000, 0x800000FF, Title); |
||
9960 | turbocat | 386 | kol_paint_end(); |
387 | kol_process_info(-1, (char*)&Form); |
||
8438 | maxcodehac | 388 | |
9960 | turbocat | 389 | if (Form.window_state & 4) continue; // if Rolled-up |
8438 | maxcodehac | 390 | |
8446 | maxcodehac | 391 | // Minimal size (700x600) |
9960 | turbocat | 392 | if (Form.width < 700) kol_wnd_change(-1, -1, 700, -1); |
393 | if (Form.height < 600) kol_wnd_change(-1, -1, -1, 600); |
||
8446 | maxcodehac | 394 | |
395 | DrawMainWindow(); |
||
8436 | maxcodehac | 396 | break; |
7624 | leency | 397 | |
8436 | maxcodehac | 398 | case evKey: |
8452 | maxcodehac | 399 | key = kos_get_key(); |
8436 | maxcodehac | 400 | if (key_mode_enter_page_number) |
401 | { |
||
402 | HandleNewPageNumber(key); |
||
403 | break; |
||
404 | } |
||
8446 | maxcodehac | 405 | if (key==ASCII_KEY_ESC) DrawMainWindow(); //close help |
8436 | maxcodehac | 406 | if (key==ASCII_KEY_PGDN) pdfapp_onkey(&gapp, ']'); |
407 | if (key==ASCII_KEY_PGUP) pdfapp_onkey(&gapp, '['); |
||
408 | if (key==ASCII_KEY_HOME) pdfapp_onkey(&gapp, 'g'); |
||
409 | if (key==ASCII_KEY_END ) pdfapp_onkey(&gapp, 'G'); |
||
410 | if (key=='g' ) pdfapp_onkey(&gapp, 'c'); |
||
411 | if ((key=='[' ) || (key=='l')) PageRotateLeft(); |
||
412 | if ((key==']' ) || (key=='r')) PageRotateRight(); |
||
413 | if (key==ASCII_KEY_DOWN ) PageScrollDown(); |
||
414 | if (key==ASCII_KEY_UP ) PageScrollUp(); |
||
415 | if (key=='-') PageZoomOut(); |
||
416 | if ((key=='=') || (key=='+')) PageZoomIn(); |
||
7624 | leency | 417 | break; |
418 | |||
8436 | maxcodehac | 419 | case evButton: |
9960 | turbocat | 420 | butt = kol_btn_get(); |
8436 | maxcodehac | 421 | if(butt==1) exit(0); |
422 | if(butt==10) RunOpenApp(argv[0]); |
||
423 | if(butt==11) PageZoomOut(); //magnify - |
||
424 | if(butt==12) PageZoomIn(); //magnify + |
||
425 | if(butt==13) //show help |
||
426 | { |
||
9960 | turbocat | 427 | kol_paint_bar(0, TOOLBAR_HEIGHT, Form.cwidth, Form.cheight - TOOLBAR_HEIGHT, 0xF2F2F2); |
8446 | maxcodehac | 428 | kos_text(20, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
429 | kos_text(21, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
||
8436 | maxcodehac | 430 | for (ii=0; help[ii]!=0; ii++) { |
8446 | maxcodehac | 431 | kos_text(20, TOOLBAR_HEIGHT + 60 + ii * 15, 0x80000000, help[ii], 0); |
8436 | maxcodehac | 432 | } |
7624 | leency | 433 | } |
8436 | maxcodehac | 434 | if(butt==14) pdfapp_onkey(&gapp, '['); //previous page |
435 | if(butt==15) pdfapp_onkey(&gapp, ']'); //next page |
||
436 | if(butt==16) PageRotateLeft(); |
||
437 | if(butt==17) PageRotateRight(); |
||
438 | if(butt==20) GetNewPageNumber(); |
||
439 | break; |
||
7624 | leency | 440 | |
8436 | maxcodehac | 441 | case evMouse: |
442 | if (mouse_wheels_state = kos_get_mouse_wheels()) |
||
443 | { |
||
444 | if (mouse_wheels_state==1) { PageScrollDown(); PageScrollDown(); } |
||
445 | if (mouse_wheels_state==-1) { PageScrollUp(); PageScrollUp(); } |
||
446 | } |
||
447 | //sprintf (debugstr, "mouse_wheels_state: %d \n", mouse_wheels_state); |
||
448 | //kol_board_puts(debugstr); |
||
449 | //pdfapp_onmouse(&gapp, int x, int y, int btn, int modifiers, int state) |
||
450 | break; |
||
451 | } |
||
7624 | leency | 452 | } |
8436 | maxcodehac | 453 | }>>>>=>>> |