Rev 5497 | Rev 5821 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5497 | Rev 5508 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #define _WIN32 |
2 | #define _WIN32 |
3 | #include "fitz.h" |
3 | #include "fitz.h" |
4 | #include "mupdf.h" |
4 | #include "mupdf.h" |
5 | #include "muxps.h" |
5 | #include "muxps.h" |
6 | #include "pdfapp.h" |
6 | #include "pdfapp.h" |
7 | #include "icons/allbtns.h" |
7 | #include "icons/allbtns.h" |
8 | 8 | ||
9 | // need to be a part of menuet/os.h |
9 | // need to be a part of menuet/os.h |
10 | #define BT_DEL 0x80000000 |
10 | #define BT_DEL 0x80000000 |
11 | #define BT_HIDE 0x40000000 |
11 | #define BT_HIDE 0x40000000 |
12 | #define BT_NOFRAME 0x20000000 |
12 | #define BT_NOFRAME 0x20000000 |
13 | 13 | ||
14 | #define evReDraw 1 |
14 | #define evReDraw 1 |
15 | #define evKey 2 |
15 | #define evKey 2 |
16 | #define evButton 3 |
16 | #define evButton 3 |
17 | #define evMouse 6 |
17 | #define evMouse 6 |
18 | #define evNetwork 8 |
18 | #define evNetwork 8 |
19 | 19 | ||
20 | #define ASCII_KEY_LEFT 176 |
20 | #define ASCII_KEY_LEFT 176 |
21 | #define ASCII_KEY_RIGHT 179 |
21 | #define ASCII_KEY_RIGHT 179 |
22 | #define ASCII_KEY_DOWN 177 |
22 | #define ASCII_KEY_DOWN 177 |
23 | #define ASCII_KEY_UP 178 |
23 | #define ASCII_KEY_UP 178 |
24 | #define ASCII_KEY_HOME 180 |
24 | #define ASCII_KEY_HOME 180 |
25 | #define ASCII_KEY_END 181 |
25 | #define ASCII_KEY_END 181 |
26 | #define ASCII_KEY_PGDN 183 |
26 | #define ASCII_KEY_PGDN 183 |
27 | #define ASCII_KEY_PGUP 184 |
27 | #define ASCII_KEY_PGUP 184 |
28 | 28 | ||
29 | #define ASCII_KEY_BS 8 |
29 | #define ASCII_KEY_BS 8 |
30 | #define ASCII_KEY_TAB 9 |
30 | #define ASCII_KEY_TAB 9 |
31 | #define ASCII_KEY_ENTER 13 |
31 | #define ASCII_KEY_ENTER 13 |
32 | #define ASCII_KEY_ESC 27 |
32 | #define ASCII_KEY_ESC 27 |
33 | #define ASCII_KEY_DEL 182 |
33 | #define ASCII_KEY_DEL 182 |
34 | #define ASCII_KEY_INS 185 |
34 | #define ASCII_KEY_INS 185 |
35 | #define ASCII_KEY_SPACE 032 |
35 | #define ASCII_KEY_SPACE 032 |
36 | 36 | ||
37 | struct blit_call |
37 | struct blit_call |
38 | { |
38 | { |
39 | int dstx; |
39 | int dstx; |
40 | int dsty; |
40 | int dsty; |
41 | int w; |
41 | int w; |
42 | int h; |
42 | int h; |
43 | 43 | ||
44 | int srcx; |
44 | int srcx; |
45 | int srcy; |
45 | int srcy; |
46 | int srcw; |
46 | int srcw; |
47 | int srch; |
47 | int srch; |
48 | 48 | ||
49 | unsigned char *d; |
49 | unsigned char *d; |
50 | int stride; |
50 | int stride; |
51 | }; |
51 | }; |
52 | 52 | ||
53 | void blit(int dstx, int dsty, int w, int h, int srcx, int srcy,int srcw, int srch, int stride, char *d) //Вызов сисфункции Blitter |
53 | void blit(int dstx, int dsty, int w, int h, int srcx, int srcy,int srcw, int srch, int stride, char *d) //Вызов сисфункции Blitter |
54 | { |
54 | { |
55 | struct blit_call image; |
55 | struct blit_call image; |
56 | image.dstx=dstx; |
56 | image.dstx=dstx; |
57 | image.dsty=dsty; |
57 | image.dsty=dsty; |
58 | image.w=w; |
58 | image.w=w; |
59 | image.h=h; |
59 | image.h=h; |
60 | image.srcx=srcx; |
60 | image.srcx=srcx; |
61 | image.srcy=srcy; |
61 | image.srcy=srcy; |
62 | image.srcw=srcw; |
62 | image.srcw=srcw; |
63 | image.srch=srch; |
63 | image.srch=srch; |
64 | image.stride=stride; |
64 | image.stride=stride; |
65 | image.d=d; |
65 | image.d=d; |
66 | asm ("int $0x40"::"a"(73),"b"(0),"c"(&image)); |
66 | asm ("int $0x40"::"a"(73),"b"(0),"c"(&image)); |
67 | } |
67 | } |
68 | 68 | ||
69 | 69 | ||
70 | int __menuet__get_mouse_wheels(void) |
70 | int __menuet__get_mouse_wheels(void) |
71 | { |
71 | { |
72 | int val; |
72 | int val; |
73 | asm ("int $0x40":"=a"(val):"a"(37),"b"(7)); |
73 | asm ("int $0x40":"=a"(val):"a"(37),"b"(7)); |
74 | return val; |
74 | return val; |
75 | }; |
75 | }; |
76 | 76 | ||
77 | /*==== DATA ====*/ |
77 | /*==== DATA ====*/ |
78 | 78 | ||
79 | static char Title[1024] = "uPDF"; |
79 | static char Title[1024] = "uPDF"; |
80 | static char * filename = "/hd0/1/yand.pdf"; |
80 | static char * filename = "/hd0/1/yand.pdf"; |
81 | static pdfapp_t gapp; |
81 | static pdfapp_t gapp; |
82 | char debugstr[256]; |
82 | char debugstr[256]; |
83 | char do_not_blit=0; |
83 | char do_not_blit=0; |
84 | 84 | ||
85 | #define TOOLBAR_HEIGHT 34 |
85 | #define TOOLBAR_HEIGHT 34 |
86 | struct process_table_entry Form; |
86 | struct process_table_entry Form; |
87 | 87 | ||
88 | #define DOCUMENT_BORDER 0x979797 |
88 | #define DOCUMENT_BORDER 0x979797 |
89 | #define DOCUMENT_BG 0xABABAB |
89 | #define DOCUMENT_BG 0xABABAB |
90 | 90 | ||
- | 91 | #define SCROLL_H 25 |
|
- | 92 | ||
- | 93 | short show_area_w = 65; |
|
- | 94 | short show_area_x; |
|
- | 95 | ||
- | 96 | char key_mode_enter_page_number; |
|
- | 97 | int new_page_number; |
|
- | 98 | ||
91 | #define SCROLL_H 17 |
99 | static short window_center, draw_h, draw_w; |
92 | 100 | ||
93 | const char *help[] = { |
101 | const char *help[] = { |
94 | "Keys:", |
102 | "Keys:", |
95 | " ", |
103 | " ", |
96 | "PageUp - go to previous page", |
104 | "PageUp - go to previous page", |
97 | "PageDown - go to next page", |
105 | "PageDown - go to next page", |
98 | "Home - go to first page", |
106 | "Home - go to first page", |
99 | "End - go to last page", |
107 | "End - go to last page", |
100 | "Down arrow - scroll current page down", |
108 | "Down arrow - scroll current page down", |
101 | "Up arrow - scroll current page up", |
109 | "Up arrow - scroll current page up", |
102 | "+/- - zoom in/out", |
110 | "+/- - zoom in/out", |
103 | "[ or l - rotate page 90 deg to the left", |
111 | "[ or l - rotate page 90 deg to the left", |
104 | "] or r - rotate page 90 deg to the right", |
112 | "] or r - rotate page 90 deg to the right", |
105 | "g - greyscale on/off", |
113 | "g - grayscale on/off", |
106 | " ", |
114 | " ", |
107 | "Press Escape to hide help", |
115 | "Press Escape to hide help", |
108 | 0 |
116 | 0 |
109 | }; |
117 | }; |
110 | 118 | ||
111 | /*==== CODE ====*/ |
119 | /*==== CODE ====*/ |
112 | 120 | ||
113 | 121 | ||
114 | // not implemented yet |
122 | // not implemented yet |
115 | void wincursor(pdfapp_t *app, int curs) { } |
123 | void wincursor(pdfapp_t *app, int curs) { } |
116 | void winhelp(pdfapp_t *app) { } |
124 | void winhelp(pdfapp_t *app) { } |
117 | void winresize(pdfapp_t *app, int w, int h) { } |
125 | void winresize(pdfapp_t *app, int w, int h) { } |
118 | void windocopy(pdfapp_t *app) { } |
126 | void windocopy(pdfapp_t *app) { } |
119 | void winopenuri(pdfapp_t *app, char *buf) { } |
127 | void winopenuri(pdfapp_t *app, char *buf) { } |
120 | void winrepaintsearch(pdfapp_t *app) { } |
128 | void winrepaintsearch(pdfapp_t *app) { } |
121 | 129 | ||
122 | 130 | ||
123 | void winwarn(pdfapp_t *app, char *msg) |
131 | void winwarn(pdfapp_t *app, char *msg) |
124 | { |
132 | { |
125 | fprintf(stderr, "mupdf: %s\n", msg); |
133 | fprintf(stderr, "mupdf: %s\n", msg); |
126 | } |
134 | } |
127 | 135 | ||
128 | 136 | ||
129 | void winerror(pdfapp_t *app, fz_error error) |
137 | void winerror(pdfapp_t *app, fz_error error) |
130 | { |
138 | { |
131 | fz_catch(error, "aborting"); |
139 | fz_catch(error, "aborting"); |
132 | exit(1); |
140 | exit(1); |
133 | } |
141 | } |
134 | 142 | ||
135 | 143 | ||
136 | char *winpassword(pdfapp_t *app, char *filename) |
144 | char *winpassword(pdfapp_t *app, char *filename) |
137 | { |
145 | { |
138 | char *r = ""; |
146 | char *r = ""; |
139 | return r; |
147 | return r; |
140 | } |
148 | } |
141 | 149 | ||
142 | 150 | ||
143 | void wintitle(pdfapp_t *app, char *s) |
151 | void wintitle(pdfapp_t *app, char *s) |
144 | { |
152 | { |
145 | char* param = *(char**)0x1C; |
153 | char* param = *(char**)0x1C; |
146 | sprintf(Title,"%s - uPDF", strrchr(param, '/') + 1 ); |
154 | sprintf(Title,"%s - uPDF", strrchr(param, '/') + 1 ); |
147 | } |
155 | } |
148 | 156 | ||
149 | 157 | ||
150 | void winreloadfile(pdfapp_t *app) |
158 | void winreloadfile(pdfapp_t *app) |
151 | { |
159 | { |
152 | //pdfapp_close(app); |
160 | //pdfapp_close(app); |
153 | //pdfapp_open(app, filename, 0, 1); |
161 | //pdfapp_open(app, filename, 0, 1); |
154 | } |
162 | } |
155 | 163 | ||
156 | void winclose(pdfapp_t *app) |
164 | void winclose(pdfapp_t *app) |
157 | { |
165 | { |
158 | pdfapp_close(&gapp); |
166 | pdfapp_close(&gapp); |
159 | __menuet__sys_exit(); |
167 | __menuet__sys_exit(); |
160 | } |
168 | } |
161 | 169 | ||
162 | 170 | ||
163 | void winrepaint(pdfapp_t *app) |
171 | void winrepaint(pdfapp_t *app) |
164 | { |
172 | { |
165 | winblit(&gapp); |
173 | winblit(&gapp); |
166 | } |
174 | } |
167 | 175 | ||
168 | 176 | ||
169 | void winblit(pdfapp_t *app) |
177 | void winblit(pdfapp_t *app) |
170 | { |
178 | { |
171 | signed short window_center, draw_w; |
- | |
172 | 179 | ||
173 | if (do_not_blit) return; |
180 | if (do_not_blit) return; |
- | 181 | ||
- | 182 | if (key_mode_enter_page_number==1) HandleNewPageNumber(0); else DrawPagination(); |
|
174 | 183 | ||
175 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
184 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
176 | 185 | ||
177 | if (gapp.image->n == 4) |
186 | if (gapp.image->n == 4) |
178 | blit(window_center + Form.client_left, |
187 | blit(window_center + Form.client_left, |
179 | Form.client_top + TOOLBAR_HEIGHT, |
188 | Form.client_top + TOOLBAR_HEIGHT, |
180 | Form.client_width, |
189 | Form.client_width, |
181 | Form.client_height - TOOLBAR_HEIGHT, |
190 | Form.client_height - TOOLBAR_HEIGHT, |
182 | gapp.panx, |
191 | gapp.panx, |
183 | gapp.pany, |
192 | gapp.pany, |
184 | gapp.image->w, |
193 | gapp.image->w, |
185 | gapp.image->h, |
194 | gapp.image->h, |
186 | gapp.image->w * gapp.image->n, |
195 | gapp.image->w * gapp.image->n, |
187 | gapp.image->samples |
196 | gapp.image->samples |
188 | ); |
197 | ); |
189 | else if (gapp.image->n == 2) |
198 | else if (gapp.image->n == 2) |
190 | { |
199 | { |
191 | int i = gapp.image->w*gapp.image->h; |
200 | int i = gapp.image->w*gapp.image->h; |
192 | unsigned char *color = malloc(i*4); |
201 | unsigned char *color = malloc(i*4); |
193 | if (color != NULL) |
202 | if (color != NULL) |
194 | { |
203 | { |
195 | unsigned char *s = gapp.image->samples; |
204 | unsigned char *s = gapp.image->samples; |
196 | unsigned char *d = color; |
205 | unsigned char *d = color; |
197 | for (; i > 0 ; i--) |
206 | for (; i > 0 ; i--) |
198 | { |
207 | { |
199 | d[2] = d[1] = d[0] = *s++; |
208 | d[2] = d[1] = d[0] = *s++; |
200 | d[3] = *s++; |
209 | d[3] = *s++; |
201 | d += 4; |
210 | d += 4; |
202 | } |
211 | } |
203 | blit(window_center + Form.client_left, |
212 | blit(window_center + Form.client_left, |
204 | Form.client_top + TOOLBAR_HEIGHT, |
213 | Form.client_top + TOOLBAR_HEIGHT, |
205 | Form.client_width, |
214 | Form.client_width, |
206 | Form.client_height - TOOLBAR_HEIGHT, |
215 | Form.client_height - TOOLBAR_HEIGHT, |
207 | gapp.panx, |
216 | gapp.panx, |
208 | gapp.pany, |
217 | gapp.pany, |
209 | gapp.image->w, |
218 | gapp.image->w, |
210 | gapp.image->h, |
219 | gapp.image->h, |
211 | gapp.image->w * 4, |
220 | gapp.image->w * 4, |
212 | color |
221 | color |
213 | ); |
222 | ); |
214 | free(color); |
223 | free(color); |
215 | } |
224 | } |
216 | } |
225 | } |
- | 226 | } |
|
- | 227 | ||
- | 228 | ||
- | 229 | void DrawPageSides(void) |
|
- | 230 | { |
|
- | 231 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
|
- | 232 | if (gapp.image->h < Form.client_height - TOOLBAR_HEIGHT) draw_h = gapp.image->h - gapp.pany; else draw_h = Form.client_height - TOOLBAR_HEIGHT; |
|
217 | if (gapp.image->h - gapp.pany < Form.client_height - TOOLBAR_HEIGHT) |
233 | if (gapp.image->w < Form.client_width) |
- | 234 | { |
|
- | 235 | __menuet__bar(0, TOOLBAR_HEIGHT, window_center-1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
|
- | 236 | __menuet__bar(window_center-1, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
|
- | 237 | __menuet__bar(window_center + gapp.image->w, TOOLBAR_HEIGHT, 1, draw_h, DOCUMENT_BORDER); |
|
- | 238 | __menuet__bar(window_center + gapp.image->w+1, TOOLBAR_HEIGHT, Form.client_width - window_center - gapp.image->w - 1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
|
- | 239 | } |
|
- | 240 | if (gapp.image->w < Form.client_width) |
|
- | 241 | { |
|
- | 242 | draw_w = gapp.image->w + 2; |
|
- | 243 | } |
|
- | 244 | else |
|
218 | { |
245 | { |
- | 246 | window_center = 1; |
|
219 | if (gapp.image->w < Form.client_width) draw_w = gapp.image->w; else draw_w = Form.client_width; |
247 | draw_w = Form.client_width; |
220 | __menuet__bar(window_center, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT, draw_w, 1, DOCUMENT_BORDER); |
- | |
221 | __menuet__bar(window_center, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT + 1, draw_w, Form.client_height - gapp.image->h - TOOLBAR_HEIGHT + gapp.pany - 1, DOCUMENT_BG); |
- | |
222 | } |
248 | } |
223 | DrawPagination(); |
249 | __menuet__bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT, draw_w, 1, DOCUMENT_BORDER); |
- | 250 | __menuet__bar(window_center - 1, gapp.image->h - gapp.pany + TOOLBAR_HEIGHT + 1, draw_w, Form.client_height - gapp.image->h - TOOLBAR_HEIGHT + gapp.pany - 1, DOCUMENT_BG); |
|
224 | } |
251 | } |
225 | 252 | ||
- | 253 | ||
226 | 254 | ||
227 | int main (void) |
255 | int main (void) |
228 | { |
256 | { |
229 | char ii, mouse_wheels_state; |
257 | char ii, mouse_wheels_state; |
230 | char* original_command_line = *(char**)0x1C; |
258 | char* original_command_line = *(char**)0x1C; |
231 | __menuet__debug_out(original_command_line); |
259 | __menuet__debug_out(original_command_line); |
232 | 260 | ||
233 | char buf[128]; |
261 | char buf[128]; |
234 | int resolution = 72; |
262 | int resolution = 72; |
235 | int pageno = 1; |
263 | int pageno = 1; |
236 | fz_accelerate(); |
264 | fz_accelerate(); |
237 | __menuet__debug_out("PDF init\n"); |
265 | __menuet__debug_out("PDF init\n"); |
238 | pdfapp_init(&gapp); |
266 | pdfapp_init(&gapp); |
239 | gapp.scrw = 600; |
267 | gapp.scrw = 600; |
240 | gapp.scrh = 400; |
268 | gapp.scrh = 400; |
241 | gapp.resolution = resolution; |
269 | gapp.resolution = resolution; |
242 | gapp.pageno = pageno; |
270 | gapp.pageno = pageno; |
243 | __menuet__debug_out("PDF Open\n"); |
271 | __menuet__debug_out("PDF Open\n"); |
244 | pdfapp_open(&gapp, original_command_line, 0, 0); |
272 | pdfapp_open(&gapp, original_command_line, 0, 0); |
245 | __menuet__debug_out("PDF Opened\n"); |
273 | __menuet__debug_out("PDF Opened\n"); |
- | 274 | wintitle(&gapp, 0); |
|
246 | 275 | ||
247 | 276 | ||
248 | __menuet__debug_out("Inital paint\n"); |
277 | __menuet__debug_out("Inital paint\n"); |
249 | //if (gapp.image) gapp.shrinkwrap = 0; |
- | |
250 | 278 | ||
251 | int butt, key, screen_max_x, screen_max_y; |
279 | int butt, key, screen_max_x, screen_max_y; |
252 | __menuet__get_screen_max(&screen_max_x, &screen_max_y); |
280 | __menuet__get_screen_max(&screen_max_x, &screen_max_y); |
253 | __menuet__set_bitfield_for_wanted_events(EVENT_REDRAW+EVENT_KEY+EVENT_BUTTON+EVENT_MOUSE_CHANGE); |
281 | __menuet__set_bitfield_for_wanted_events(EVENT_REDRAW+EVENT_KEY+EVENT_BUTTON+EVENT_MOUSE_CHANGE); |
254 | 282 | ||
255 | for(;;) |
283 | for(;;) |
256 | { |
284 | { |
257 | 285 | ||
258 | switch(__menuet__wait_for_event()) |
286 | switch(__menuet__wait_for_event()) |
259 | { |
287 | { |
260 | case evReDraw: |
288 | case evReDraw: |
- | 289 | // gapp.shrinkwrap = 2; |
|
261 | __menuet__window_redraw(1); |
290 | __menuet__window_redraw(1); |
262 | __menuet__define_window(screen_max_x / 2 - 350, screen_max_y / 2 - 300, 700, 600, 0x73000000, 0x800000FF, Title); |
291 | __menuet__define_window(screen_max_x / 2 - 350, screen_max_y / 2 - 300, 700, 600, 0x73000000, 0x800000FF, Title); |
263 | __menuet__window_redraw(2); |
292 | __menuet__window_redraw(2); |
264 | __menuet__get_process_table(&Form, PID_WHOAMI); |
293 | __menuet__get_process_table(&Form, PID_WHOAMI); |
265 | if (Form.window_state > 2) continue; //fix rolled up |
294 | if (Form.window_state > 2) continue; //fix rolled up |
266 | Form.client_width++; //fix for Menuet kernel bug |
295 | Form.client_width++; //fix for Menuet kernel bug |
267 | Form.client_height++; //fix for Menuet kernel bug |
296 | Form.client_height++; //fix for Menuet kernel bug |
268 | DrawWindow(); |
297 | DrawWindow(); |
269 | break; |
298 | break; |
270 | 299 | ||
271 | case evKey: |
300 | case evKey: |
272 | key = __menuet__getkey(); |
301 | key = __menuet__getkey(); |
- | 302 | if (key_mode_enter_page_number) |
|
- | 303 | { |
|
- | 304 | HandleNewPageNumber(key); |
|
- | 305 | break; |
|
- | 306 | } |
|
273 | if (key==ASCII_KEY_ESC) DrawWindow(); //close help |
307 | if (key==ASCII_KEY_ESC) DrawWindow(); //close help |
274 | if (key==ASCII_KEY_PGDN) pdfapp_onkey(&gapp, ']'); |
308 | if (key==ASCII_KEY_PGDN) pdfapp_onkey(&gapp, ']'); |
275 | if (key==ASCII_KEY_PGUP) pdfapp_onkey(&gapp, '['); |
309 | if (key==ASCII_KEY_PGUP) pdfapp_onkey(&gapp, '['); |
276 | if (key==ASCII_KEY_HOME) pdfapp_onkey(&gapp, 'g'); |
310 | if (key==ASCII_KEY_HOME) pdfapp_onkey(&gapp, 'g'); |
277 | if (key==ASCII_KEY_END ) pdfapp_onkey(&gapp, 'G'); |
311 | if (key==ASCII_KEY_END ) pdfapp_onkey(&gapp, 'G'); |
278 | if (key=='g' ) pdfapp_onkey(&gapp, 'c'); |
312 | if (key=='g' ) pdfapp_onkey(&gapp, 'c'); |
279 | if ((key=='[' ) || (key=='l')) PageRotateLeft(); |
313 | if ((key=='[' ) || (key=='l')) PageRotateLeft(); |
280 | if ((key==']' ) || (key=='r')) PageRotateRight(); |
314 | if ((key==']' ) || (key=='r')) PageRotateRight(); |
281 | if (key==ASCII_KEY_DOWN ) PageScrollDown(); |
315 | if (key==ASCII_KEY_DOWN ) PageScrollDown(); |
282 | if (key==ASCII_KEY_UP ) PageScrollUp(); |
316 | if (key==ASCII_KEY_UP ) PageScrollUp(); |
283 | if (key=='-') PageZoomOut(); |
317 | if (key=='-') PageZoomOut(); |
284 | if ((key=='=') || (key=='+')) PageZoomIn(); |
318 | if ((key=='=') || (key=='+')) PageZoomIn(); |
285 | break; |
319 | break; |
286 | 320 | ||
287 | case evButton: |
321 | case evButton: |
288 | butt = __menuet__get_button_id(); |
322 | butt = __menuet__get_button_id(); |
289 | if(butt==1) __menuet__sys_exit(); |
323 | if(butt==1) __menuet__sys_exit(); |
290 | if(butt==10) ;//mag open file |
324 | if(butt==10) ;//mag open file |
291 | if(butt==11) PageZoomOut(); //magnify - |
325 | if(butt==11) PageZoomOut(); //magnify - |
292 | if(butt==12) PageZoomIn(); //magnify + |
326 | if(butt==12) PageZoomIn(); //magnify + |
293 | if(butt==13) //show help |
327 | if(butt==13) //show help |
294 | { |
328 | { |
295 | __menuet__bar(0, TOOLBAR_HEIGHT, Form.client_width, Form.client_height - TOOLBAR_HEIGHT, 0xF2F2F2); |
329 | __menuet__bar(0, TOOLBAR_HEIGHT, Form.client_width, Form.client_height - TOOLBAR_HEIGHT, 0xF2F2F2); |
296 | __menuet__write_text(20, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.01", 0); |
330 | __menuet__write_text(20, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
297 | __menuet__write_text(21, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.01", 0); |
331 | __menuet__write_text(21, TOOLBAR_HEIGHT + 20 , 0x90000000, "uPDF for KolibriOS v1.2", 0); |
298 | for (ii=0; help[ii]!=0; ii++) { |
332 | for (ii=0; help[ii]!=0; ii++) { |
299 | __menuet__write_text(20, TOOLBAR_HEIGHT + 60 + ii * 15, 0x80000000, help[ii], 0); |
333 | __menuet__write_text(20, TOOLBAR_HEIGHT + 60 + ii * 15, 0x80000000, help[ii], 0); |
300 | } |
334 | } |
301 | } |
335 | } |
302 | if(butt==14) pdfapp_onkey(&gapp, '['); //previous page |
336 | if(butt==14) pdfapp_onkey(&gapp, '['); //previous page |
303 | if(butt==15) pdfapp_onkey(&gapp, ']'); //next page |
337 | if(butt==15) pdfapp_onkey(&gapp, ']'); //next page |
- | 338 | if(butt==16) PageRotateLeft(); |
|
- | 339 | if(butt==17) PageRotateRight(); |
|
- | 340 | if(butt==20) GetNewPageNumber(); |
|
304 | break; |
341 | break; |
305 | 342 | ||
306 | case evMouse: |
343 | case evMouse: |
307 | if (mouse_wheels_state = __menuet__get_mouse_wheels()) |
344 | if (mouse_wheels_state = __menuet__get_mouse_wheels()) |
308 | { |
345 | { |
309 | if (mouse_wheels_state==1) { PageScrollDown(); PageScrollDown(); } |
346 | if (mouse_wheels_state==1) { PageScrollDown(); PageScrollDown(); } |
310 | if (mouse_wheels_state==-1) { PageScrollUp(); PageScrollUp(); } |
347 | if (mouse_wheels_state==-1) { PageScrollUp(); PageScrollUp(); } |
311 | } |
348 | } |
312 | //sprintf (debugstr, "mouse_wheels_state: %d \n", mouse_wheels_state); |
349 | //sprintf (debugstr, "mouse_wheels_state: %d \n", mouse_wheels_state); |
313 | //__menuet__debug_out(debugstr); |
350 | //__menuet__debug_out(debugstr); |
314 | //pdfapp_onmouse(&gapp, int x, int y, int btn, int modifiers, int state) |
351 | //pdfapp_onmouse(&gapp, int x, int y, int btn, int modifiers, int state) |
315 | break; |
352 | break; |
316 | } |
353 | } |
317 | } |
354 | } |
318 | } |
355 | } |
319 | 356 | ||
- | 357 | ||
- | 358 | void GetNewPageNumber(void) |
|
- | 359 | { |
|
- | 360 | new_page_number = gapp.pageno; |
|
- | 361 | key_mode_enter_page_number = 1; |
|
- | 362 | HandleNewPageNumber(0); |
|
320 | 363 | } |
|
321 | 364 | ||
322 | void DrawPageSides(void) |
365 | void HandleNewPageNumber(unsigned char key) |
323 | { |
- | |
- | 366 | { |
|
324 | short window_center; |
367 | char label_new_page[8]; |
325 | if (Form.client_width > gapp.image->w) window_center = (Form.client_width - gapp.image->w) / 2; else window_center = 0; |
368 | |
326 | if (gapp.image->w < Form.client_width) |
369 | if ((key >= '0') && (key <= '9')) |
- | 370 | { |
|
327 | { |
371 | new_page_number = new_page_number * 10 + key - '0'; |
- | 372 | } |
|
328 | __menuet__bar(0, TOOLBAR_HEIGHT, window_center-1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
373 | if (key == ASCII_KEY_BS) |
329 | __menuet__bar(window_center-1, TOOLBAR_HEIGHT, 1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BORDER); |
- | |
330 | __menuet__bar(window_center + gapp.image->w, TOOLBAR_HEIGHT, 1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BORDER); |
374 | { |
- | 375 | new_page_number /= 10; |
|
- | 376 | } |
|
- | 377 | if (key == ASCII_KEY_ENTER) |
|
- | 378 | { |
|
- | 379 | ApplyNewPageNumber(); |
|
- | 380 | return; |
|
- | 381 | } |
|
- | 382 | if (key==ASCII_KEY_ESC) |
|
- | 383 | { |
|
- | 384 | key_mode_enter_page_number = 0; |
|
- | 385 | DrawWindow(); |
|
- | 386 | return; |
|
- | 387 | } |
|
- | 388 | ||
- | 389 | itoa(new_page_number, label_new_page, 10); |
|
- | 390 | strcat(label_new_page, "_"); |
|
- | 391 | __menuet__bar(show_area_x, 6, show_area_w, 22, 0xFDF88E); |
|
- | 392 | __menuet__write_text(show_area_x + show_area_w/2 - strlen(label_new_page)*6/2, 14, 0x000000, label_new_page, strlen(label_new_page)); |
|
331 | __menuet__bar(window_center + gapp.image->w+1, TOOLBAR_HEIGHT, Form.client_width - window_center - gapp.image->w - 1, Form.client_height - TOOLBAR_HEIGHT, DOCUMENT_BG); |
393 | |
- | 394 | if (new_page_number > gapp.pagecount) ApplyNewPageNumber(); |
|
- | 395 | } |
|
- | 396 | ||
- | 397 | void ApplyNewPageNumber(void) |
|
- | 398 | { |
|
- | 399 | key_mode_enter_page_number = 0; |
|
332 | } |
400 | gapp.pageno = new_page_number -1; |
333 | } |
401 | pdfapp_onkey(&gapp, ']'); |
334 | 402 | } |
|
335 | 403 | ||
336 | void DrawPagination(void) |
404 | void DrawPagination(void) |
337 | { |
405 | { |
338 | char pages_display[12]; |
406 | char pages_display[12]; |
339 | short show_area_w = 65; |
- | |
340 | short show_area_x = Form.client_width - show_area_w - 34; |
- | |
341 | - | ||
342 | DrawToolbarButton(show_area_x - 26,5,26,24,4); //prev page |
- | |
343 | DrawToolbarButton(show_area_x + show_area_w,5,26,24,5); //nex page |
- | |
344 | __menuet__bar(show_area_x, 5, show_area_w, 1, 0xA4A4A4); |
- | |
345 | __menuet__bar(show_area_x, 6, show_area_w, 22, 0xF4F4F4); |
407 | __menuet__bar(show_area_x, 6, show_area_w, 22, 0xF4F4F4); |
346 | __menuet__bar(show_area_x, 28, show_area_w, 1, 0xA4A4A4); |
- | |
347 | sprintf (pages_display, "%d/%d", gapp.pageno, gapp.pagecount); |
408 | sprintf (pages_display, "%d/%d", gapp.pageno, gapp.pagecount); |
348 | __menuet__write_text(show_area_x + show_area_w/2 - strlen(pages_display)*6/2, 14, 0x000000, pages_display, strlen(pages_display)); |
409 | __menuet__write_text(show_area_x + show_area_w/2 - strlen(pages_display)*6/2, 14, 0x000000, pages_display, strlen(pages_display)); |
349 | } |
410 | } |
350 | 411 | ||
- | 412 | ||
- | 413 | ||
351 | 414 | ||
352 | void DrawWindow(void) |
415 | void DrawWindow(void) |
353 | { |
416 | { |
354 | __menuet__bar(0, 0, Form.client_width, TOOLBAR_HEIGHT - 1, 0xe1e1e1); // bar on the top (buttons holder) |
417 | __menuet__bar(0, 0, Form.client_width, TOOLBAR_HEIGHT - 1, 0xe1e1e1); // bar on the top (buttons holder) |
355 | __menuet__bar(0, TOOLBAR_HEIGHT - 1, Form.client_width, 1, 0x7F7F7F); |
418 | __menuet__bar(0, TOOLBAR_HEIGHT - 1, Form.client_width, 1, 0x7F7F7F); |
356 | DrawToolbarButton(8,5,26,24,0); //open_folder |
419 | DrawToolbarButton(8,0); //open_folder |
357 | DrawToolbarButton(42,5,26,24,1); //magnify - |
420 | DrawToolbarButton(42,1); //magnify - |
358 | DrawToolbarButton(67,5,26,24,2); //magnify + |
421 | DrawToolbarButton(67,2); //magnify + |
- | 422 | DrawToolbarButton(101,6); //rotate left |
|
- | 423 | DrawToolbarButton(126,7); //rotate right |
|
359 | DrawToolbarButton(Form.client_width - 160,5,26,24,3); //show help |
424 | DrawToolbarButton(Form.client_width - 160,3); //show help |
- | 425 | show_area_x = Form.client_width - show_area_w - 34; |
|
- | 426 | DrawToolbarButton(show_area_x - 26,4); //prev page |
|
- | 427 | DrawToolbarButton(show_area_x + show_area_w,5); //nex page |
|
- | 428 | __menuet__make_button(show_area_x-1, 5, show_area_w+1, 23, 20 + BT_HIDE, 0xA4A4A4); |
|
- | 429 | __menuet__bar(show_area_x, 5, show_area_w, 1, 0xA4A4A4); |
|
- | 430 | __menuet__bar(show_area_x, 28, show_area_w, 1, 0xA4A4A4); |
|
360 | winblit(&gapp); |
431 | winblit(&gapp); |
361 | DrawPageSides(); |
432 | DrawPageSides(); |
362 | } |
433 | } |
363 | - | ||
364 | 434 | ||
365 | void DrawToolbarButton(int x, int y, int w, int h, char image_id) |
435 | void DrawToolbarButton(int x, char image_id) |
366 | { |
436 | { |
367 | __menuet__make_button(x, y, w-1, h-1, 10 + image_id + BT_HIDE, 0); |
437 | __menuet__make_button(x, 5, 26-1, 24-1, 10 + image_id + BT_HIDE, 0); |
368 | __menuet__putimage(x, y, w, h, image_id * 24 * 26 * 3 + toolbar_image); |
438 | __menuet__putimage(x, 5, 26, 24, image_id * 24 * 26 * 3 + toolbar_image); |
369 | } |
- | |
370 | 439 | } |
|
371 | 440 | ||
372 | 441 | ||
373 | /* Actions */ |
442 | /* Actions */ |
374 | 443 | ||
375 | void PageScrollDown(void) |
444 | void PageScrollDown(void) |
376 | { |
445 | { |
377 | //pdfapp_onkey(&gapp, 'k'); //move down |
446 | //pdfapp_onkey(&gapp, 'k'); //move down |
378 | if (gapp.image->h - gapp.pany - SCROLL_H < Form.client_height - TOOLBAR_HEIGHT) |
447 | if (gapp.image->h - gapp.pany - SCROLL_H < Form.client_height - TOOLBAR_HEIGHT) |
379 | { |
448 | { |
380 | pdfapp_onkey(&gapp, '.'); |
449 | pdfapp_onkey(&gapp, '.'); |
381 | } |
450 | } |
382 | else { |
451 | else { |
383 | gapp.pany += SCROLL_H; |
452 | gapp.pany += SCROLL_H; |
384 | winblit(&gapp); |
453 | winblit(&gapp); |
385 | } |
454 | } |
386 | } |
455 | } |
387 | 456 | ||
388 | 457 | ||
389 | void PageScrollUp(void) |
458 | void PageScrollUp(void) |
390 | { |
459 | { |
391 | //pdfapp_onkey(&gapp, 'j'); //move up |
460 | //pdfapp_onkey(&gapp, 'j'); //move up |
392 | if (gapp.pany >= SCROLL_H) { |
461 | if (gapp.pany >= SCROLL_H) { |
393 | gapp.pany -= SCROLL_H; |
462 | gapp.pany -= SCROLL_H; |
394 | winblit(&gapp); |
463 | winblit(&gapp); |
395 | } |
464 | } |
396 | else { |
465 | else { |
397 | //not very nice way of using do_not_blit, but it simple |
466 | //not very nice way of using do_not_blit, but it simple |
398 | if (gapp.pageno == 1) return; |
467 | if (gapp.pageno == 1) return; |
399 | do_not_blit = 1; |
468 | do_not_blit = 1; |
400 | pdfapp_onkey(&gapp, ','); |
469 | pdfapp_onkey(&gapp, ','); |
401 | do_not_blit = 0; |
470 | do_not_blit = 0; |
402 | gapp.pany = gapp.image->h - SCROLL_H - Form.client_height + TOOLBAR_HEIGHT; |
471 | gapp.pany = gapp.image->h - SCROLL_H - Form.client_height + TOOLBAR_HEIGHT; |
403 | if (gapp.pany < 0) gapp.pany = 0; |
472 | if (gapp.pany < 0) gapp.pany = 0; |
404 | //sprintf (debugstr, "gapp.pany: %d \n", gapp.pany); |
473 | //sprintf (debugstr, "gapp.pany: %d \n", gapp.pany); |
405 | //__menuet__debug_out(debugstr); |
474 | //__menuet__debug_out(debugstr); |
406 | winblit(&gapp); |
475 | winblit(&gapp); |
407 | } |
476 | } |
408 | } |
477 | } |
409 | 478 | ||
410 | 479 | ||
411 | void PageZoomIn(void) |
480 | void PageZoomIn(void) |
412 | { |
481 | { |
413 | pdfapp_onkey(&gapp, '+'); |
482 | pdfapp_onkey(&gapp, '+'); |
414 | DrawPageSides(); |
483 | DrawPageSides(); |
415 | } |
484 | } |
416 | 485 | ||
417 | 486 | ||
418 | void PageZoomOut(void) |
487 | void PageZoomOut(void) |
419 | { |
488 | { |
420 | pdfapp_onkey(&gapp, '-'); |
489 | pdfapp_onkey(&gapp, '-'); |
421 | DrawPageSides(); |
490 | DrawPageSides(); |
422 | } |
491 | } |
423 | 492 | ||
424 | void PageRotateLeft(void) |
493 | void PageRotateLeft(void) |
425 | { |
494 | { |
426 | pdfapp_onkey(&gapp, 'L'); |
495 | pdfapp_onkey(&gapp, 'L'); |
427 | DrawPageSides(); |
496 | DrawPageSides(); |
428 | } |
497 | } |
429 | 498 | ||
430 | void PageRotateRight(void) |
499 | void PageRotateRight(void) |
431 | { |
500 | { |
432 | pdfapp_onkey(&gapp, 'R'); |
501 | pdfapp_onkey(&gapp, 'R'); |
433 | DrawPageSides(); |
502 | DrawPageSides(); |
434 | }>>>>> |
503 | }>>=>>>> |