Subversion Repositories Kolibri OS

Rev

Rev 8945 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8945 leency 1
format binary as ""
2
 
3
use32
4
org 0x0
5
 
6
db 'MENUET01'
7
dd 0x01, START, I_END, E_END, stacktop, __params, sys_path
8
 
9
;-----------------------------------------------------------------------------
10
 
11
__DEBUG__        = 0
12
__DEBUG_LEVEL__  = 1
13
 
14
LG_TRACE equ 1
15
 
16
include '../../../config.inc'
17
include '../../../proc32.inc'
18
include '../../../macros.inc'
19
include '../../../KOSfuncs.inc'
20
include '../../../dll.inc'
21
include '../../../debug-fdo.inc'
22
include '../../../develop/libraries/libs-dev/libimg/libimg.inc'
23
 
24
 
25
KEY_MOVE_PIXELS   = 50
26
SCROLL_WIDTH_SIZE = 15
27
AR_OFFSET         = 10
28
 
29
MIN_WINDOW_WIDTH  = 50+25*numimages
30
MIN_WINDOW_HEIGHT = 100
31
TOOLBAR_HEIGHT    = 31
32
CANVAS_PADDING    = 5
33
;-----------------------------------------------------------------------------
34
 
35
START:
36
        mcall   SF_SYS_MISC, SSF_HEAP_INIT
37
        mcall   SF_KEYBOARD, SSF_SET_INPUT_MODE, 1  ; set kbd mode to scancodes
38
        mcall   SF_SET_EVENTS_MASK, EVM_REDRAW or EVM_KEY or EVM_BUTTON or \
39
                EVM_MOUSE or EVM_MOUSE_FILTER
40
 
41
        stdcall dll.Load, @IMPORT
42
        or      eax, eax
43
        jnz     exit
44
 
45
        invoke  sort.START, 1
46
 
47
        mov     ecx, 1  ; for 15.4: 1 = tile
48
        cmp     word[__params], '\T'
49
        jz      set_bgr
50
        inc     ecx     ; for 15.4: 2 = stretch
51
        cmp     word[__params], '\S'
52
        jz      set_bgr
53
 
54
        cmp     byte[__params], 0
55
        jz      @f
56
        mov     esi, __params
57
        mov     edi, path
58
        mov     ecx, 4096/4
59
        rep movsd
60
        mov     byte[edi-1], 0
61
@@:
62
; OpenDialog initialisation
63
        push    dword OpenDialog_data
64
        call    [OpenDialog_Init]
65
 
66
; initialize keyboard handling
67
        invoke  ini_get_shortcut, inifilename, aKivSection, aNext, -1, next_mod
68
        mov     [next_key], eax
69
        invoke  ini_get_shortcut, inifilename, aKivSection, aPrev, -1, prev_mod
70
        mov     [prev_key], eax
71
        invoke  ini_get_shortcut, inifilename, aKivSection, aSlide, -1, slide_mod
72
        mov     [slide_key], eax
73
        invoke  ini_get_shortcut, inifilename, aKivSection, aTglbar, -1, tglbar_mod
74
        mov     [tglbar_key], eax
75
 
76
        invoke  ini_get_int, inifilename, aKivSection, aWinX, 100
77
        mov     [window.left], eax
78
        invoke  ini_get_int, inifilename, aKivSection, aWinY, 150
79
        mov     [window.top], eax
80
        invoke  ini_get_int, inifilename, aKivSection, aWinW, 0
81
        mov     [window.width], eax
82
        invoke  ini_get_int, inifilename, aKivSection, aWinH, 0
83
        mov     [window.height], eax
84
 
85
        cmp     byte[__params], 0
86
        jnz     params_given
87
 
88
        mov     [OpenDialog_data.draw_window], draw_window_fake
89
 
90
; OpenDialog Open
91
        push    dword OpenDialog_data
92
        call    [OpenDialog_Start]
93
 
94
        cmp     [OpenDialog_data.status], 1
95
        jnz     exit
96
 
97
        mov     [OpenDialog_data.draw_window], draw_window
98
 
99
        mov     esi, path
100
        mov     edi, __params
101
        mov     ecx, 4096/4
102
        rep movsd
103
        mov     byte[edi-1], 0
104
        jmp     params_given
105
 
106
set_bgr:
107
        mcall   SF_BACKGROUND_SET, SSF_MODE_BG
108
        stdcall load_image, __params+4
109
        jc      exit
110
        call    set_as_bgr
111
        jmp     exit
112
 
113
params_given:
114
        mov     esi, __params
115
        push    esi
116
        call    find_last_name_component
117
        call    load_directory
118
 
119
        pop     eax
120
        stdcall load_image, eax
121
        jc      exit
122
 
123
;-----------------------------------------------------------------------------
124
 
125
redraw_all:
126
        call    draw_window
127
 
128
still:
129
        mov     eax, [orig_image]
130
        test    [eax+Image.Flags], Image.IsAnimated
131
        movi    eax, SF_WAIT_EVENT
132
        jz      .wait_event
133
        mcall   SF_SYSTEM_GET, SSF_TIME_COUNT
134
        mov     edx, [cur_frame]
135
        mov     ebx, [cur_frame_time]
136
        add     ebx, [edx+Image.Delay]
137
        sub     ebx, eax
138
        cmp     ebx, [edx+Image.Delay]
139
        jna     @f
140
        call    red_update_frame
141
        jmp     still
142
@@:
143
        test    ebx, ebx
144
        jnz     @f
145
        call    red_update_frame
146
        jmp     still
147
@@:
148
        movi    eax, SF_WAIT_EVENT_TIMEOUT
149
.wait_event:
150
        mcall
151
        dec     eax
152
        jns     @f
153
        call    red_update_frame
154
        jmp     still
155
@@:
156
        jz      redraw_all
157
        dec     eax
158
        jz      key
159
        dec     eax
160
        jz      button
161
 
162
mouse:
163
        mov     eax, [need_scrollbar_v]
164
        add     eax, [need_scrollbar_h]
165
        test    eax, eax
166
        jz      .done
167
        mov     [pict_moved], 0
168
 
169
        invoke  scrollbar_vert_mouse, scroll_bar_data_vertical
170
        invoke  scrollbar_hort_mouse, scroll_bar_data_horizontal
171
        xor     ecx, ecx
172
        mov     eax, [scroll_bar_data_vertical.position]
173
        cmp     [pict.top], eax
174
        mov     [pict.top], eax
175
        setnz   cl
176
        mov     eax, [scroll_bar_data_horizontal.position]
177
        cmp     [pict.left], eax
178
        mov     [pict.left], eax
179
        setnz   ch
180
        test    ecx, ecx
181
        jz      @f
182
        call    draw_view
183
        call    draw_onimage_decorations
184
@@:
185
 
186
        ; check for scroll
187
        mcall   SF_MOUSE_GET, SSF_SCROLL_DATA
188
        test    eax, eax
189
        jz      .no_scroll
190
        movsx   ecx, ax
191
        shl     ecx, 4
192
        sar     eax, 16
193
        shl     eax, 4
194
        stdcall move_pictport, eax, ecx
195
        mov     [pict_moved], eax
196
        jmp     .mouse_done
197
.no_scroll:
198
 
199
        ; get cursor coordinates in window
200
        mcall   SF_MOUSE_GET, SSF_WINDOW_POSITION
201
        movsx   ebx, ax
202
        cmp     ebx, 0
203
        jge     @f
204
        add     eax, 0x10000
205
@@:
206
        mov     ecx, [mouse_pos]
207
        cmp     eax, ecx
208
        jz      .no_mouse_move
209
        mov     [mouse_pos], eax
210
 
211
        cmp     [pict_drag], 1
212
        jnz     .no_mouse_move
213
        sar     eax, 16
214
        movsx   edx, cx
215
        sar     ecx, 16
216
        sub     eax, ecx
217
        sub     ebx, edx
218
        neg     eax
219
        neg     ebx
220
        stdcall move_pictport, eax, ebx
221
        mov     [pict_moved], eax
222
        jmp     .no_mouse_move
223
.no_mouse_move:
224
 
225
        ; check buttons
226
        mcall   SF_MOUSE_GET, SSF_BUTTON
227
        mov     ecx, eax
228
        xor     ecx, [mouse_buttons]
229
        mov     [mouse_buttons], eax
230
        test    ecx, 0x01
231
        jz      .left_button_handled
232
        test    eax, 0x01
233
        jnz     .left_button_down
234
.left_button_up:
235
        mov     [pict_drag], 0
236
        jmp     .left_button_handled
237
.left_button_down:
238
        mov     ecx, [mouse_pos]
239
        movzx   edx, cx
240
        sar     ecx, 16
241
        mov     ebx, [canvas_abs_top]
242
        add     ebx, [view.top]
243
        cmp     ebx, edx
244
        jg      .left_click_pict_done
245
        add     ebx, [view.height]
246
        cmp     ebx, edx
247
        jl      .left_click_pict_done
248
        mov     ebx, [canvas_abs_left]
249
        add     ebx, [view.left]
250
        cmp     ebx, ecx
251
        jg      .left_click_pict_done
252
        add     ebx, [view.width]
253
        cmp     ebx, ecx
254
        jl      .left_click_pict_done
255
        mov     [pict_drag], 1
256
        jmp     .left_button_handled
257
.left_click_pict_done:
258
 
259
.left_button_handled:
260
.mouse_done:
261
        mov     eax, [pict_moved]
262
        test    eax, eax
263
        jz      .done
264
        stdcall update_scrollbars, eax
265
        call    draw_view
266
        call    draw_onimage_decorations
267
.done:
268
        jmp     still
269
 
270
key:
271
        xor     esi, esi
272
keyloop:
273
        mcall   SF_GET_KEY
274
        test    al, al
275
        jnz     keyloopdone
276
        shr     eax, 8
277
        mov     ecx, eax
278
        mcall   SF_KEYBOARD, SSF_GET_CONTROL_KEYS
279
        mov     edx, next_mod
280
        call    check_shortcut
281
        jz      .next
282
        add     edx, prev_mod-next_mod
283
        call    check_shortcut
284
        jz      .prev
285
        add     edx, slide_mod-prev_mod
286
        call    check_shortcut
287
        jz      .slide
288
        add     edx, tglbar_mod-slide_mod
289
        call    check_shortcut
290
        jz      .tglbar
291
 
292
        mov     edx, scale_none_mod
293
        call    check_shortcut
294
        jz      .set_scale_none
295
        add     edx, scale_fit_min_mod-scale_none_mod
296
        call    check_shortcut
297
        jz      .set_scale_fit_min
298
        add     edx, move_pictport_left_1_mod-scale_fit_min_mod
299
        call    check_shortcut
300
        jz      .move_pictport_left
301
        add     edx, move_pictport_left_2_mod-move_pictport_left_1_mod
302
        call    check_shortcut
303
        jz      .move_pictport_left
304
        add     edx, move_pictport_right_1_mod-move_pictport_left_2_mod
305
        call    check_shortcut
306
        jz      .move_pictport_right
307
        add     edx, move_pictport_right_2_mod-move_pictport_right_1_mod
308
        call    check_shortcut
309
        jz      .move_pictport_right
310
        add     edx, move_pictport_up_1_mod-move_pictport_right_2_mod
311
        call    check_shortcut
312
        jz      .move_pictport_up
313
        add     edx, move_pictport_up_2_mod-move_pictport_up_1_mod
314
        call    check_shortcut
315
        jz      .move_pictport_up
316
        add     edx, move_pictport_down_1_mod-move_pictport_up_2_mod
317
        call    check_shortcut
318
        jz      .move_pictport_down
319
        add     edx, move_pictport_down_2_mod-move_pictport_down_1_mod
320
        call    check_shortcut
321
        jz      .move_pictport_down
322
 
323
        cmp     cl, 1 ; Esc
324
        jz      .esc
325
        jmp     keyloop
326
.esc:
327
        test    [bSlideShow], 1
328
        jz      keyloop
329
        jmp     .slide
330
.tglbar:
331
        bt      [window_style], 25
332
        jnc     @f
333
        mov     [bToggleToolbar], 1
334
        xor     [bShowToolbar], 1
335
@@:
336
        jmp     keyloop
337
.slide:
338
        call    slide_show
339
        jmp     keyloop
340
.set_scale_none:
341
        mov     eax, LIBIMG_SCALE_NONE
342
        call    set_scale_mode
343
        jz      @f
344
        call    recalc_canvas
345
@@:
346
        jmp     keyloop
347
.set_scale_fit_min:
348
        mov     eax, LIBIMG_SCALE_FIT_MIN
349
        call    set_scale_mode
350
        jz      @f
351
        call    recalc_work
352
@@:
353
        jmp     keyloop
354
.move_pictport_left:
355
        stdcall move_pictport, -KEY_MOVE_PIXELS, 0
356
        stdcall update_scrollbars, eax
357
        call    draw_view
358
        call    draw_onimage_decorations
359
        jmp     keyloop
360
.move_pictport_right:
361
        stdcall move_pictport, KEY_MOVE_PIXELS, 0
362
        stdcall update_scrollbars, eax
363
        call    draw_view
364
        call    draw_onimage_decorations
365
        jmp     keyloop
366
.move_pictport_up:
367
        stdcall move_pictport, 0, -KEY_MOVE_PIXELS
368
        stdcall update_scrollbars, eax
369
        call    draw_view
370
        call    draw_onimage_decorations
371
        jmp     keyloop
372
.move_pictport_down:
373
        stdcall move_pictport, 0, KEY_MOVE_PIXELS
374
        stdcall update_scrollbars, eax
375
        call    draw_view
376
        call    draw_onimage_decorations
377
        jmp     keyloop
378
.prev:
379
        dec     esi
380
        jmp     keyloop
381
.next:
382
        inc     esi
383
        jmp     keyloop
384
keyloopdone:
385
        test    esi, esi
386
        jnz     next_or_prev_handler
387
        test    [bToggleSlideShow], 1
388
        jnz     redraw_all
389
        test    [bToggleToolbar], 1
390
        stdcall recalc_client
391
        jnz     redraw_all
392
        test    [bScaleModeChanged], 1
393
        mov     [bScaleModeChanged], 0
394
        jnz     redraw_all
395
        test    [bNewImage], 1
396
        mov     [bNewImage], 0
397
        jnz     redraw_all
398
        jmp     still
399
next_or_prev_handler:
400
        call    next_or_prev_image
401
        jmp     redraw_all
402
 
403
red_update_frame:
404
        mov     eax, [cur_frame]
405
        mov     eax, [eax+Image.Next]
406
        test    eax, eax
407
        jnz     @f
408
        mov     eax, [cur_image]
409
@@:
410
        mov     [cur_frame], eax
411
        mcall   SF_SYSTEM_GET, SSF_TIME_COUNT
412
        mov     [cur_frame_time], eax
413
        call    draw_view
414
        ret
415
 
416
button:
417
        mcall   SF_GET_BUTTON
418
        shr     eax, 8
419
 
420
        ; flip horizontally
421
        cmp     eax, 'flh'
422
        jnz     .not_flh
423
 
424
        mov     eax, [cur_image]
425
        cmp     eax, [orig_image]
426
        jz      @f
427
        invoke  img.flip, [cur_image], FLIP_HORIZONTAL
428
@@:
429
        invoke  img.flip, [orig_image], FLIP_HORIZONTAL
430
        jmp     redraw_all
431
 
432
        ; flip vertically
433
.not_flh:
434
        cmp     eax, 'flv'
435
        jnz     .not_flv
436
 
437
        mov     eax, [cur_image]
438
        cmp     eax, [orig_image]
439
        jz      @f
440
        invoke  img.flip, [cur_image], FLIP_VERTICAL
441
@@:
442
        invoke  img.flip, [orig_image], FLIP_VERTICAL
443
        jmp     redraw_all
444
 
445
        ; flip both horizontally and vertically
446
.not_flv:
447
        cmp     eax, 'flb'
448
        jnz     .not_flb
449
 
450
        mov     eax, [cur_image]
451
        cmp     eax, [orig_image]
452
        jz      @f
453
        invoke  img.flip, [cur_image], FLIP_BOTH
454
@@:
455
        invoke  img.flip, [orig_image], FLIP_BOTH
456
        jmp     redraw_all
457
 
458
        ; rotate left
459
.not_flb:
460
        cmp     eax, 'rtl'
461
        jnz     .not_rtl
462
 
463
        push    ROTATE_90_CCW
464
.rotate_common:
465
        mov     eax, [cur_image]
466
        cmp     eax, [orig_image]
467
        jz      @f
468
        push    dword[esp]
469
        invoke  img.rotate, [cur_image]
470
@@:
471
        invoke  img.rotate, [orig_image]
472
        mov     [bNewImage], 1
473
        jmp     redraw_all
474
 
475
        ; rotate right
476
.not_rtl:
477
        cmp     eax, 'rtr'
478
        jnz     .not_rtr
479
 
480
        push    ROTATE_90_CW
481
        jmp     .rotate_common
482
 
483
        ; open new file
484
.not_rtr:
485
        cmp     eax, 'opn'
486
        jnz     @f
487
 
488
; OpenDialog Open
489
        push    dword OpenDialog_data
490
        call    [OpenDialog_Start]
491
 
492
        cmp     [OpenDialog_data.status], 1
493
        jnz     still
494
 
495
        mov     esi, path
496
        mov     edi, __params
497
        push    edi
498
        mov     ecx, 4096/4
499
        rep movsd
500
        mov     byte[edi-1], 0
501
 
502
        pop     esi
503
        push    esi
504
        call    find_last_name_component
505
 
506
        pop     eax
507
        push    [cur_image]
508
        stdcall load_image, eax
509
        jc      .restore_old
510
        call    free_directory
511
        jmp     redraw_all
512
 
513
.restore_old:
514
        pop     eax
515
        jmp     still
516
 
517
        ; set background
518
@@:
519
        cmp     eax, 'bgr'
520
        jnz     @f
521
 
522
        mcall   SF_BACKGROUND_SET, SSF_MODE_BG, 2 ; stretch by default
523
        call    set_as_bgr
524
        jmp     still
525
 
526
@@:
527
        cmp     eax, 'sld'
528
        jnz     @f
529
 
530
        call    slide_show
531
        jmp     redraw_all
532
 
533
@@:
534
        cmp     eax, 'scl'
535
        jnz     .not_scl
536
        mov     eax, LIBIMG_SCALE_NONE
537
        cmp     [scale_mode], LIBIMG_SCALE_NONE
538
        jnz     @f
539
        mov     eax, LIBIMG_SCALE_FIT_MIN
540
@@:
541
        call    set_scale_mode
542
        jz      @f
543
        call    recalc_work
544
@@:
545
        jmp     redraw_all
546
.not_scl:
547
        or      esi, -1
548
        cmp     eax, 'bck'
549
        jz      next_or_prev_handler
550
        neg     esi
551
        cmp     eax, 'fwd'
552
        jz      next_or_prev_handler
553
 
554
        cmp     eax, 1
555
        jnz     still
556
 
557
exit:
558
        invoke  ini_set_int, inifilename, aKivSection, aWinX, [window.left]
559
        invoke  ini_set_int, inifilename, aKivSection, aWinY, [window.top]
560
        invoke  ini_set_int, inifilename, aKivSection, aWinW, [window.width]
561
        invoke  ini_set_int, inifilename, aKivSection, aWinH, [window.height]
562
        mcall   -1
563
 
564
 
565
proc load_image _filename
566
        push    ebx esi edi
567
        invoke  img.from_file, [_filename]
568
        test    eax, eax
569
        jz      .error
570
        mov     ebx, eax
571
 
572
        test    [eax+Image.Flags], Image.IsAnimated
573
        jnz     @f
574
        cmp     [eax+Image.Next], 0
575
        jz      @f
576
        stdcall merge_icons_to_single_img, eax
577
        test    eax, eax
578
        jz      .error_destroy
579
@@:
580
        stdcall init_frame, eax
581
        clc
582
        jmp     .exit
583
 
584
.error_destroy:
585
        invoke  img.destroy, ebx
586
        xor     eax, eax
587
.error:
588
        stc
589
.exit:
590
        pop     edi esi ebx
591
        ret
592
endp
593
 
594
 
595
; in:  eax -- pointer to image
596
; out: fill pict structure
597
proc calculate_picture_size
598
        mov     edx, [eax+Image.Width]
599
        test    [eax+Image.Flags], Image.IsAnimated
600
        jnz     .not_in_row
601
        push    eax
602
@@:
603
        cmp     [eax+Image.Next], 0
604
        jz      @f
605
        mov     eax, [eax+Image.Next]
606
        add     edx, [eax+Image.Width]
607
        inc     edx
608
        jmp     @b
609
@@:
610
        pop     eax
611
.not_in_row:
612
        mov     [pict.width], edx
613
        add     edx, 19
614
        cmp     edx, 50+25*numimages
615
        jae     @f
616
        mov     edx, 50+25*numimages
617
@@:
618
        mov     esi, [eax+Image.Height]
619
        test    [eax+Image.Flags], Image.IsAnimated
620
        jnz     .max_equals_first
621
        push    eax
622
@@:
623
        cmp     [eax+Image.Next], 0
624
        jz      @f
625
        mov     eax, [eax+Image.Next]
626
        cmp     esi, [eax+Image.Height]
627
        jae     @b
628
        mov     esi, [eax+Image.Height]
629
        jmp     @b
630
@@:
631
        pop     eax
632
.max_equals_first:
633
        mov     [pict.height], esi
634
        ret
635
endp
636
 
637
 
638
; in:  [orig_image]
639
proc set_as_bgr
640
        mov     esi, [orig_image]
641
        mov     ecx, [esi+Image.Width]
642
        mov     edx, [esi+Image.Height]
643
        mcall   SF_BACKGROUND_SET, SSF_SIZE_BG
644
        mcall   SF_BACKGROUND_SET, SSF_MAP_BG
645
        test    eax, eax
646
        jz      @f
647
 
648
        push    eax
649
        invoke  img.to_rgb2, esi, eax
650
        pop     ecx
651
        mcall   SF_BACKGROUND_SET, SSF_UNMAP_BG
652
 
653
@@:
654
        mcall   SF_BACKGROUND_SET, SSF_REDRAW_BG
655
        ; save to file eskin.ini
656
        xor     al, al
657
        mov     ecx, 1024
658
        mov     edi, sys_path+2
659
        repne scasb
660
        sub     edi, sys_path+3
661
        invoke  ini_set_str, inifileeskin, amain, aprogram, sys_path+2, edi
662
        ; add param '\S__'
663
        cmp     word[__params], '\T'
664
        jz      @f
665
        cmp     word[__params], '\S'
666
        je      @f
667
        mov     esi, __params+4096-8
668
        mov     edi, __params+4096-4
669
        mov     ecx, 4096/4-1
670
        std
671
        rep movsd
672
        cld
673
        mov     dword[__params], '\S__'
674
@@:
675
        xor     al, al
676
        mov     ecx, 4096
677
        mov     edi, __params
678
        repne scasb
679
        sub     edi, __params+1
680
        invoke  ini_set_str, inifileeskin, amain, aparam, __params, edi
681
        ret
682
endp
683
 
684
proc slide_show
685
        push    ebx esi edi
686
        mov     [bToggleSlideShow], 1
687
        btc     [window_style], 25
688
        xor     [bSlideShow], 1
689
        jnz     .to_fullscreen
690
        ; back from fullscreen
691
        movzx   eax, [bShowToolbarSave]
692
        mov     [bShowToolbar], al
693
        mov     [canvas_padding], CANVAS_PADDING
694
        mov     [bg_color], 0x00ffffff
695
        mcall   SF_CHANGE_WINDOW, [window_save.left], [window_save.top], [window_save.width], [window_save.height]
696
        jmp     .done
697
.to_fullscreen:
698
        stdcall copy_box, window, window_save
699
        movzx   eax, [bShowToolbar]
700
        mov     [bShowToolbarSave], al
701
        mov     [bShowToolbar], 0
702
        mov     [canvas_padding], 0
703
        mov     [bg_color], 0x00000000
704
        mcall   SF_GET_SCREEN_SIZE
705
        mov     edx, eax
706
        shr     edx, 16
707
        movzx   eax, ax
708
        mov     esi, eax
709
        mcall   SF_CHANGE_WINDOW, 0, 0, ,
710
        mov     eax, LIBIMG_SCALE_FIT_MIN
711
        call    set_scale_mode
712
 
713
.done:
714
        pop     edi esi ebx
715
        ret
716
endp
717
 
718
 
719
; seek to ESI image files
720
; esi>0 means next file, esi<0-prev file
721
proc next_or_prev_image
722
locals
723
        files_cnt       dd ?
724
        file_idx        dd ?
725
endl
726
        push    ebx esi edi
727
        push    esi
728
        call    load_directory
729
        pop     esi
730
        mov     eax, [directory_ptr]
731
        mov     eax, [eax+4]
732
        mov     [files_cnt], eax
733
        cmp     [directory_ptr], 0
734
        jz      .ret
735
        cmp     [files_cnt], 0 ; number of files
736
        jz      .ret
737
        mov     eax, [cur_file_idx]
738
        cmp     eax, -1
739
        jnz     @f
740
        test    esi, esi
741
        jns     @f
742
        mov     eax, [files_cnt]
743
@@:
744
        add     eax, esi
745
@@:
746
        test    eax, eax
747
        jns     @f
748
        add     eax, [files_cnt]
749
        jmp     @b
750
@@:
751
        cmp     eax, [files_cnt]
752
        jb      @f
753
        sub     eax, [files_cnt]
754
        jmp     @b
755
@@:
756
        mov     [file_idx], eax
757
.scanloop:
758
        push    eax esi
759
        imul    esi, eax, 304
760
        add     esi, [directory_ptr]
761
        add     esi, 32+40
762
        mov     edi, curdir
763
@@:
764
        inc     edi
765
        cmp     byte[edi-1], 0
766
        jnz     @b
767
        mov     byte[edi-1], '/'
768
@@:
769
        lodsb
770
        stosb
771
        test    al, al
772
        jnz     @b
773
        mov     esi, curdir
774
        push    esi
775
        mov     edi, __params
776
        mov     ecx, 4096/4
777
        rep movsd
778
        mov     byte[edi-1], 0
779
        pop     esi
780
        stdcall load_image, curdir
781
        pushfd
782
@@:
783
        lodsb
784
        test    al, al
785
        jnz     @b
786
@@:
787
        dec     esi
788
        cmp     byte[esi], '/'
789
        jnz     @b
790
        mov     byte[esi], 0
791
        popfd
792
        pop     esi eax
793
        jnc     .loadedok
794
        test    esi, esi
795
        js      .try_prev
796
.try_next:
797
        inc     eax
798
        cmp     eax, [files_cnt]
799
        jb      @f
800
        xor     eax, eax
801
@@:
802
.try_common:
803
        cmp     eax, [file_idx]
804
        jz      .notfound
805
        jmp     .scanloop
806
.try_prev:
807
        dec     eax
808
        jns     @f
809
        mov     eax, [files_cnt]
810
        dec     eax
811
@@:
812
        jmp     .try_common
813
.loadedok:
814
        mov     [cur_file_idx], eax
815
.ret:
816
        pop     edi esi ebx
817
        ret
818
.notfound:
819
        pop     edi esi ebx
820
        ret
821
endp
822
 
823
 
824
load_directory:
825
        cmp     [directory_ptr], 0
826
        jnz     .ret
827
        mov     esi, __params
828
        mov     edi, curdir
829
        mov     ecx, [last_name_component]
830
        sub     ecx, esi
831
        dec     ecx
832
        js      @f
833
        rep movsb
834
@@:
835
        mov     byte[edi], 0
836
        mcall   68, 12, 0x1000
837
        test    eax, eax
838
        jz      .ret
839
        mov     ebx, readdir_fileinfo
840
        mov     dword[ebx+12], (0x1000-32) / 304      ; blocks to read
841
        mov     dword[ebx+16], eax      ; where to store
842
        mcall   70
843
        cmp     eax, 6  ; read ok, but there are more files
844
        jz      .dirok
845
        test    eax, eax
846
        jnz     free_directory
847
        mov     edx, [directory_ptr]
848
        mov     ecx, [edx+8]            ; total number of files
849
        mov     [readblocks], ecx
850
        imul    ecx, 304        ; try to read entire dir, FIXME
851
        add     ecx, 32         ; plus header
852
        mcall   68, 20          ; realloc
853
        test    eax, eax
854
        jz      free_directory
855
        mov     [directory_ptr], eax
856
        mcall   70, readdir_fileinfo
857
.dirok:
858
        cmp     ebx, 0
859
        jle     free_directory
860
        mov     eax, [directory_ptr]
861
        mov     edi, [eax+8]  ; total number of files
862
        mov     [files_num], edi
863
        add     eax, 32         ; skip header
864
        mov     edi, eax
865
        push    0
866
.dirskip:
867
        push    eax
868
        test    byte[eax], 0x18 ; volume label or folder
869
        jnz     .nocopy
870
        lea     esi, [eax+40]   ; name
871
        mov     ecx, esi
872
@@:
873
        lodsb
874
        test    al, al
875
        jnz     @b
876
@@:
877
        dec     esi
878
        cmp     esi, ecx
879
        jb      .noext
880
        cmp     byte[esi], '.'
881
        jnz     @b
882
        inc     esi
883
        mov     ecx, [esi]
884
        cmp     byte[esi+3], 0
885
        jnz     .not_3
886
        or      ecx, 0x202020
887
        cmp     ecx, 'jpg'
888
        jz      .copy
889
        cmp     ecx, 'bmp'
890
        jz      .copy
891
        cmp     ecx, 'gif'
892
        jz      .copy
893
        cmp     ecx, 'png'
894
        jz      .copy
895
        cmp     ecx, 'jpe'
896
        jz      .copy
897
        cmp     ecx, 'ico'
898
        jz      .copy
899
        cmp     ecx, 'cur'
900
        jz      .copy
901
        cmp     ecx, 'tga'
902
        jz      .copy
903
        cmp     ecx, 'pcx'
904
        jz      .copy
905
        cmp     ecx, 'xcf'
906
        jz      .copy
907
        cmp     ecx, 'pbm'
908
        jz      .copy
909
        cmp     ecx, 'pgm'
910
        jz      .copy
911
        cmp     ecx, 'pnm'
912
        jz      .copy
913
        cmp     ecx, 'ppm'
914
        jz      .copy
915
        cmp     ecx, 'tif'
916
        jz      .copy
917
        cmp     ecx, 'xbm'
918
        jz      .copy
919
.not_3:
920
        cmp     byte[esi+4], 0
921
        jnz     .nocopy
922
        or      ecx, 0x20202020
923
        cmp     ecx, 'tiff'
924
        jz      @f
925
        cmp     ecx, 'wbmp'
926
        jz      @f
927
        cmp     ecx, 'webp'
928
        jz      @f
929
        cmp     ecx, 'jpeg'
930
        jnz     .nocopy
931
@@:
932
        cmp     byte[esi+4], 0
933
        jnz     .nocopy
934
.copy:
935
        mov     esi, [esp]
936
        mov     ecx, 304 / 4
937
        rep movsd
938
        inc     dword[esp+4]
939
.nocopy:
940
.noext:
941
        pop     eax
942
        add     eax, 304
943
        dec     ebx
944
        jnz     .dirskip
945
        mov     eax, [directory_ptr]
946
        pop     ebx
947
        mov     [eax+4], ebx
948
        test    ebx, ebx
949
        jz      free_directory
950
        push    0   ; sort mode
951
        push    ebx
952
        add     eax, 32
953
        push    eax
954
        call    [SortDir]
955
        xor     eax, eax
956
        mov     edi, [directory_ptr]
957
        add     edi, 32+40    ; name
958
.scan:
959
        mov     esi, [last_name_component]
960
        push    edi
961
        invoke  strcmpi
962
        pop     edi
963
        jz      .found
964
        inc     eax
965
        add     edi, 304
966
        dec     ebx
967
        jnz     .scan
968
        or      eax, -1
969
.found:
970
        mov     [cur_file_idx], eax
971
.ret:
972
        ret
973
 
974
free_directory:
975
        mcall   68, 13, [directory_ptr]
976
        and     [directory_ptr], 0
977
        ret
978
 
979
 
980
; in: esi->full name (e.g. /path/to/file.png)
981
; out: [last_name_component]->last component (e.g. file.png)
982
proc find_last_name_component
983
        mov     ecx, esi
984
@@:
985
        lodsb
986
        test    al, al
987
        jnz     @b
988
@@:
989
        dec     esi
990
        cmp     esi, ecx
991
        jb      @f
992
        cmp     byte[esi], '/'
993
        jnz     @b
994
@@:
995
        inc     esi
996
        mov     [last_name_component], esi
997
        ret
998
endp
999
 
1000
 
1001
proc init_frame uses ebx edx, _img
1002
        mov     eax, [orig_image]
1003
        cmp     eax, [_img]
1004
        jz      .exit
1005
        test    eax, eax
1006
        jz      .freed
1007
        cmp     eax, [cur_image]
1008
        jz      @f
1009
        invoke  img.destroy, [orig_image]
1010
@@:
1011
        invoke  img.destroy, [cur_image]
1012
.freed:
1013
 
1014
        mov     [bNewImage], 1
1015
        mov     eax, [_img]
1016
        mov     [orig_image], eax
1017
        mov     [cur_image], eax
1018
        mov     [cur_frame], eax
1019
        test    byte[eax+Image.Flags], Image.IsAnimated
1020
        jz      @f
1021
        push    ebx
1022
        mcall   SF_SYSTEM_GET, SSF_TIME_COUNT
1023
        pop     ebx
1024
        mov     [cur_frame_time], eax
1025
@@:
1026
        mov     [pict.top], 0
1027
        mov     [pict.left], 0
1028
.exit:
1029
        ret
1030
endp
1031
 
1032
 
1033
proc draw_window
1034
        test    [bFirstWinDraw], 1
1035
        jnz     .min_size_ok
1036
 
1037
        mcall   SF_THREAD_INFO, procinfo, -1
1038
        xor     eax, eax
1039
        mov     edx, -1
1040
        mov     esi, -1
1041
        cmp     [procinfo.wnd_state], 0x04
1042
        je      .min_size_ok
1043
        cmp     [procinfo.box.width], MIN_WINDOW_WIDTH
1044
        ja      @f
1045
        mov     edx, MIN_WINDOW_WIDTH
1046
        inc     eax
1047
@@:
1048
        cmp     [procinfo.box.height], MIN_WINDOW_HEIGHT
1049
        ja      @f
1050
        mov     esi, MIN_WINDOW_HEIGHT
1051
        inc     eax
1052
@@:
1053
        test    eax, eax
1054
        jz      @f
1055
        mcall   SF_CHANGE_WINDOW, -1, -1, ,
1056
@@:
1057
 
1058
.min_size_ok:
1059
        test    [bNewImage], 1
1060
        jz      @f
1061
        call    generate_window_header
1062
@@:
1063
        cmp     [window.width], 0
1064
        jne     @f
1065
        mcall   SF_GET_SCREEN_SIZE
1066
        mov     ebx, eax
1067
        shr     ebx, 16         ; ebx = width
1068
        movzx   esi, ax         ; esi = height
1069
 
1070
        mov     eax, ebx
1071
        xor     edx, edx
1072
        mov     ebx, 3
1073
        div     ebx
1074
        imul    eax, 2
1075
        mov     [window.width], eax
1076
 
1077
        xor     edx, edx
1078
        mov     ebx, 4
1079
        div     ebx
1080
        mov     [window.left], eax
1081
 
1082
        mov     eax, esi
1083
        xor     edx, edx
1084
        mov     ebx, 3
1085
        div     ebx
1086
        imul    eax, 2
1087
        mov     [window.height], eax
1088
 
1089
        xor     edx, edx
1090
        mov     ebx, 4
1091
        div     ebx
1092
        mov     [window.top], eax
1093
@@:
1094
 
1095
        mcall   SF_REDRAW, SSF_BEGIN_DRAW
1096
        mov     ecx, [window.top]
1097
        shl     ecx, 16
1098
        mov     cx, word[window.height]
1099
        mov     ebx, [window.left]
1100
        shl     ebx, 16
1101
        mov     bx, word[window.width]
1102
        mcall   0, , , [window_style], 0, window_header
1103
 
1104
        mcall   SF_THREAD_INFO, procinfo, -1
1105
        test    [procinfo.wnd_state], 0x04
1106
        jnz     .nodraw
1107
 
1108
        stdcall copy_box, window, window_prev
1109
        stdcall copy_box, procinfo.box, window
1110
        test    [bFirstWinDraw], 1
1111
        jnz     .recalc
1112
        test    [bToggleSlideShow], 1
1113
        jnz     .recalc
1114
        mov     eax, [window.width]
1115
        cmp     eax, [window_prev.width]
1116
        jnz     .recalc
1117
        mov     eax, [window.height]
1118
        cmp     eax, [window_prev.height]
1119
        jnz     .recalc
1120
        test    [bNewImage], 1
1121
        jnz     .recalc
1122
        test    [bToggleToolbar], 1
1123
        jnz     .recalc
1124
        jmp     .recalc_done
1125
 
1126
.recalc:
1127
        stdcall recalc_window
1128
.recalc_done:
1129
 
1130
        stdcall draw_client
1131
.nodraw:
1132
        mcall   SF_REDRAW, SSF_END_DRAW
1133
        mov     [bFirstWinDraw], 0
1134
        mov     [bNewImage], 0
1135
        mov     [bToggleToolbar], 0
1136
        mov     [bToggleSlideShow], 0
1137
 
1138
        ret
1139
endp
1140
 
1141
 
1142
proc draw_view uses ebx esi edi
1143
        cmp     [scale_mode], LIBIMG_SCALE_FIT_MIN
1144
        jnz     .scale_none
1145
        mov     ecx, [cur_frame]
1146
        mov     eax, [ecx+Image.Width]
1147
        cmp     eax, [view.width]
1148
        jnz     .scale
1149
        mov     eax, [ecx+Image.Height]
1150
        cmp     eax, [view.height]
1151
        jnz     .scale
1152
        jmp     .draw
1153
.scale:
1154
        mov     eax, [orig_image]
1155
        cmp     eax, [cur_image]
1156
        jz      @f
1157
        invoke  img.destroy, [cur_image]
1158
        mov     eax, [orig_image]
1159
@@:
1160
        invoke  img.scale, eax, 0, 0, [eax+Image.Width], [eax+Image.Height], 0, LIBIMG_SCALE_STRETCH, LIBIMG_INTER_DEFAULT, [view.width], [view.height]
1161
        test    eax, eax
1162
;FIXME
1163
        mov     [cur_image], eax
1164
        mov     [cur_frame], eax        ; FIXME index
1165
        jmp     .draw
1166
 
1167
.scale_none:
1168
 
1169
.draw:
1170
        push    [pict.top]
1171
        push    [pict.left]
1172
        push    [view.height]
1173
        push    [view.width]
1174
        push    [view_abs_top]  ; ypos
1175
        push    [view_abs_left] ; xpos
1176
        invoke  img.draw, [cur_frame]
1177
.done:
1178
        ret
1179
endp
1180
 
1181
proc draw_scale_button
1182
        pushad
1183
        mcall   65, buttons+scalebtn*20, <20,20>, [scale_button_xy], 8, palette
1184
        mov     ebx, [scale_button_xy]
1185
        add     ebx, 0x00050006
1186
        ; print letter(s) corresponding to the current scaling mode
1187
        mov     edi, 2
1188
        mov     [scale_button_letter], 'x1'
1189
        cmp     [scale_mode], LIBIMG_SCALE_NONE
1190
        jz      @f
1191
        add     ebx, 0x00020001
1192
        mov     edi, 1
1193
        mov     [scale_button_letter], 'W'
1194
;        cmp     [scale_mode], LIBIMG_SCALE_FIT_MIN
1195
@@:
1196
        mcall   4, , 0x800000ff, scale_button_letter
1197
        popad
1198
        ret
1199
endp
1200
 
1201
proc draw_toolbar uses ebx esi edi
1202
        cmp     [toolbar.height], 0
1203
        jz      .quit
1204
        mov     ebx, [toolbar_abs_left]
1205
        shl     ebx, 16
1206
        add     ebx, [toolbar.width]
1207
        inc     ebx
1208
        mov     ecx, [toolbar_abs_top]
1209
        shl     ecx, 16
1210
        add     ecx, [toolbar.height]
1211
        mcall   13, , , [bg_color]
1212
        mov     ebx, [toolbar_abs_left]
1213
        shl     ebx, 16
1214
        add     ebx, [toolbar_abs_left]
1215
        add     ebx, [toolbar.width]
1216
        mov     ecx, [toolbar_abs_top]
1217
        shl     ecx, 16
1218
        add     ecx, [toolbar_abs_top]
1219
        add     ecx, (30 SHL 16)+30
1220
        mcall   38, , , 0x007F7F7F
1221
        mov     ebx, [toolbar_abs_left]
1222
        shl     ebx, 16
1223
        add     ebx, [toolbar_abs_left]
1224
        add     ebx, ((5+25*1) SHL 16)+(5+25*1)
1225
        mov     ecx, [toolbar_abs_top]
1226
        shl     ecx, 16
1227
        add     ecx, [toolbar_abs_top]
1228
        add     ecx, [toolbar.height]
1229
        mcall
1230
        add     ebx, ((5+25*2) SHL 16)+(5+25*2)
1231
        mcall
1232
        add     ebx, ((5+25*2) SHL 16)+(5+25*2)
1233
        mcall
1234
        add     ebx, ((5+25*1) SHL 16)+(5+25*1)
1235
        mcall
1236
        mov     ebx, [toolbar_abs_left]
1237
        add     ebx, [toolbar.width]
9035 leency 1238
        sub     ebx, 25*4+10
8945 leency 1239
        shl     ebx, 16
1240
        add     ebx, [toolbar_abs_left]
1241
        add     ebx, [toolbar.width]
9035 leency 1242
        sub     ebx, 25*4+10
8945 leency 1243
        mcall
1244
 
1245
        mov     ebx, [toolbar_abs_left]
1246
        shl     ebx, 16
1247
        add     ebx, ((4+25*0) SHL 16)+21
1248
        mov     ecx, [toolbar_abs_top]
1249
        shl     ecx, 16
1250
        add     ecx, (4 SHL 16)+21
1251
        mcall   SF_DEFINE_BUTTON, , , 'opn'+40000000h
1252
        add     ebx, (5+25*1) SHL 16
1253
        mcall    , , , 'bck'+40000000h
1254
        add     ebx, (0+25*1) SHL 16
1255
        mcall    , , , 'fwd'+40000000h
1256
        add     ebx, (5+25*1) SHL 16
1257
        mcall    , , , 'bgr'+40000000h
1258
        add     ebx, (0+25*1) SHL 16
1259
        mcall    , , , 'sld'+40000000h
1260
        add     ebx, (5+25*1) SHL 16
1261
        mcall    , , , 'scl'+40000000h
1262
        mov     ebx, [toolbar_abs_left]
1263
        add     ebx, [toolbar.width]
9035 leency 1264
        sub     ebx, 25*4+10
8945 leency 1265
        add     ebx, 5
1266
        shl     ebx, 16
1267
        mov     bl, 21
1268
        mcall   , , , 'flh'+40000000h
1269
        add     ebx, 25 SHL 16
1270
        mcall   , , , 'flv'+40000000h
1271
        add     ebx, 30 SHL 16
1272
        mcall   , , , 'rtr'+40000000h
1273
        add     ebx, 25 SHL 16
1274
        mcall   , , , 'rtl'+40000000h
1275
        add     ebx, 25 SHL 16
1276
        mcall   , , , 'flb'+40000000h
1277
 
1278
        mov     ebp, (numimages-1)*20
1279
 
1280
        mov     edx, [toolbar_abs_left]
1281
        shl     edx, 16
1282
        add     edx, [toolbar_abs_top]
1283
        add     edx, ((5+25*0) SHL 16)+5
1284
        mcall   65, buttons+openbtn   *20, <20, 20>, , 8, palette
1285
        add     edx, ((5+25*1) SHL 16)+0
1286
        mcall     , buttons+backbtn   *20
1287
        add     edx, ((0+25*1) SHL 16)+0
1288
        mcall     , buttons+forwardbtn*20
1289
        add     edx, ((5+25*1) SHL 16)+0
1290
        mcall     , buttons+bgrbtn    *20
1291
        add     edx, ((0+25*1) SHL 16)+0
1292
        mcall     , buttons+slidebtn  *20
1293
        add     edx, ((5+25*1) SHL 16)+0
1294
;        mcall     , buttons+scalebtn  *20
1295
        mov     [scale_button_xy], edx
1296
        call    draw_scale_button
1297
        mov     edx, [client_abs_left]
1298
        add     edx, [client.width]
9035 leency 1299
        sub     edx, 25*4+4
8945 leency 1300
        shl     edx, 16
1301
        add     edx, [client_abs_top]
1302
        add     edx, 5
1303
        mcall   , buttons+fliphorzbtn*20
1304
        add     edx, 25*65536
1305
        mcall   , buttons+flipvertbtn*20
1306
        add     edx, 30*65536
1307
        mcall   , buttons+rotccwbtn*20
1308
        add     edx, 25*65536
9035 leency 1309
        mcall   , buttons+rotcwbtn*20
8945 leency 1310
 
1311
.quit:
1312
        ret
1313
endp
1314
 
1315
 
1316
proc draw_canvas
1317
        push    ebx esi edi
1318
 
1319
        mov     ebx, [canvas_abs_left]
1320
        shl     ebx, 16
1321
        add     ebx, [canvas.width]
1322
        mov     ecx, [canvas_abs_top]
1323
        shl     ecx, 16
1324
        add     ecx, [view.top]
1325
;mov edx, 0xff0000
1326
        mcall   13, , , [bg_color]
1327
        mcall   13
1328
        mov     ecx, [view_abs_top]
1329
        add     ecx, [view.height]
1330
        shl     ecx, 16
1331
        add     ecx, [canvas.height]
1332
        sub     ecx, [view.top]
1333
        sub     ecx, [view.height]
1334
;mov edx, 0x00ff00
1335
        mcall   13, , , [bg_color]
1336
        mcall   13
1337
        mov     ebx, [canvas_abs_left]
1338
        shl     ebx, 16
1339
        add     ebx, [view.left]
1340
        mov     ecx, [canvas_abs_top]
1341
        shl     ecx, 16
1342
        add     ecx, [canvas.height]
1343
;mov edx, 0x0000ff
1344
;bg_color
1345
        mcall
1346
        mov     ebx, [view_abs_left]
1347
        add     ebx, [view.width]
1348
        shl     ebx, 16
1349
        mov     eax, [canvas.width]
1350
        sub     eax, [view.left]
1351
        sub     ebx, [view.width]
1352
        add     ebx, eax
1353
;mov edx, 0xffff00
1354
;bg_color
1355
        mcall   13
1356
@@:
1357
 
1358
        call    draw_view
1359
 
1360
        pop     edi esi ebx
1361
        ret
1362
endp
1363
 
1364
 
1365
proc draw_client
1366
        push    ebx esi edi
1367
 
1368
        test    [bShowToolbar], 1
1369
        jz      .toolbar_done
1370
        call    draw_toolbar
1371
.toolbar_done:
1372
        call    draw_work
1373
 
1374
        pop     edi esi ebx
1375
        ret
1376
endp
1377
 
1378
 
1379
proc draw_work
1380
        push    ebx esi edi
1381
 
1382
        mov     ebx, [work_abs_left]
1383
        shl     ebx, 16
1384
        add     ebx, [work.width]
1385
        inc     ebx
1386
        mov     ecx, [work_abs_top]
1387
        shl     ecx, 16
1388
        add     ecx, [canvas.top]
1389
;        mcall   13, , , 0xff0000
1390
        mcall   13, , , [bg_color]
1391
        mov     eax, [canvas.height]
1392
        ror     ecx, 16
1393
        add     ecx, eax
1394
        add     ecx, [canvas_padding]
1395
        ror     ecx, 16
1396
;        mcall   13, , , 0x00ff00
1397
        mcall   13, , , [bg_color]
1398
;        mcall   13
1399
 
1400
        mov     ebx, [work_abs_left]
1401
        shl     ebx, 16
1402
        add     ebx, [canvas.left]
1403
        mov     ecx, [work_abs_top]
1404
        add     ecx, [canvas_padding]
1405
        shl     ecx, 16
1406
        add     ecx, [canvas.height]
1407
;        mcall   13, , , 0x0000ff
1408
        mcall   13, , , [bg_color]
1409
;        mcall
1410
        mov     eax, [canvas.width]
1411
        ror     ebx, 16
1412
        add     ebx, eax
1413
        add     ebx, [canvas_padding]
1414
        ror     ebx, 16
1415
;        mcall   13, , , 0xffff00
1416
        mcall   13, , , [bg_color]
1417
;        mcall   13
1418
 
1419
        call    draw_canvas
1420
        call    draw_onimage_decorations
1421
 
1422
        mov     eax, 13
1423
        cmp     [need_scrollbar_v], 1
1424
        jnz     @f
1425
        cmp     [need_scrollbar_h], 1
1426
        jnz     @f
1427
        mov     ebx, [work_abs_left]
1428
        add     ebx, [work.width]
1429
        sub     ebx, SCROLL_WIDTH_SIZE
1430
        shl     ebx, 16
1431
        add     ebx, SCROLL_WIDTH_SIZE
1432
        inc     ebx
1433
        mov     ecx, [work_abs_top]
1434
        add     ecx, [work.height]
1435
        sub     ecx, SCROLL_WIDTH_SIZE
1436
        shl     ecx, 16
1437
        add     ecx, SCROLL_WIDTH_SIZE
1438
        inc     ecx
1439
        mov     edx, [bg_color]
1440
;        mov     edx, 0x00ffff
1441
        mcall
1442
@@:
1443
 
1444
        cmp     [need_scrollbar_v], 0
1445
        jz      .v_scrollbar_done
1446
        mov     eax, [client.left]
1447
        add     eax, [client.width]
1448
        sub     eax, SCROLL_WIDTH_SIZE
1449
        mov     [scroll_bar_data_vertical.start_x], ax
1450
        mov     eax, [toolbar.height]
1451
        add     eax, [client.top]
1452
        mov     [scroll_bar_data_vertical.start_y], ax
1453
        mov     eax, [canvas.height]
1454
        add     eax, [canvas_padding]
1455
        add     eax, [canvas_padding]
1456
        mov     [scroll_bar_data_vertical.size_y], ax
1457
        mov     [scroll_bar_data_vertical.all_redraw], 1
1458
        invoke  scrollbar_vert_draw, scroll_bar_data_vertical
1459
.v_scrollbar_done:
1460
 
1461
        cmp     [need_scrollbar_h], 0
1462
        jz      .h_scrollbar_done
1463
        mov     eax, [client.left]
1464
        mov     [scroll_bar_data_horizontal.start_x], ax
1465
        mov     eax, [client.top]
1466
        add     eax, [client.height]
1467
        sub     eax, SCROLL_WIDTH_SIZE
1468
        mov     [scroll_bar_data_horizontal.start_y], ax
1469
        mov     eax, [canvas.width]
1470
        add     eax, [canvas_padding]
1471
        add     eax, [canvas_padding]
1472
        mov     [scroll_bar_data_horizontal.size_x], ax
1473
        mov     [scroll_bar_data_horizontal.all_redraw], 1
1474
        invoke  scrollbar_hort_draw, scroll_bar_data_horizontal
1475
.h_scrollbar_done:
1476
 
1477
        pop     edi esi ebx
1478
        ret
1479
endp
1480
 
1481
 
1482
proc draw_onimage_decorations
1483
        bt      [window_style], 25
1484
        jc      @f
1485
        ; draw fullscreen decorations on image
1486
        call    draw_filename
1487
        call    draw_fullscreen_controls
1488
@@:
1489
        ret
1490
endp
1491
 
1492
 
1493
proc draw_filename
1494
        push    esi
1495
        mcall   4, <100, 65>, 0x40ffffff, window_header, [window_header_len], 0x008800
1496
        pop     esi
1497
        ret
1498
endp
1499
 
1500
 
1501
proc draw_fullscreen_controls
1502
        push    esi
1503
        mov     ebx, [canvas.width]
1504
        shr     ebx, 1
1505
        add     ebx, [canvas.left]
1506
        sub     ebx, 22
1507
        shl     ebx, 16
1508
        add     ebx, 20
1509
        mov     ecx, [canvas.height]
1510
        shr     ecx, 3
1511
        neg     ecx
1512
        add     ecx, [canvas.height]
1513
        add     ecx, [canvas.top]
1514
        shl     ecx, 16
1515
        add     ecx, 20
1516
        mcall   8, , , 'bck'+40000000h
1517
        add     ebx, 25 SHL 16
1518
        mcall   8, , , 'fwd'+40000000h
1519
        mov     edx, [canvas.width]
1520
        shr     edx, 1
1521
        add     edx, [canvas.left]
1522
        sub     edx, 22
1523
        shl     edx, 16
1524
        add     edx, [canvas.height]
1525
        shr     dx, 3
1526
        neg     dx
1527
        add     dx, word[canvas.height]
1528
        add     edx, [canvas.top]
1529
        mcall   65, buttons+backbtn*20, <20, 20>, , 8, palette
1530
        add     edx, 25 SHL 16
1531
        mcall   65, buttons+forwardbtn*20,      , , 8,
1532
        pop     esi
1533
        ret
1534
endp
1535
 
1536
 
1537
proc check_shortcut
1538
; in:   cl = scancode (from sysfn 2),
1539
;   eax = state of modifiers (from sysfn 66.3),
1540
;   edx -> shortcut descriptor
1541
; out:  ZF set <=> fail
1542
        cmp     cl, [edx+4]
1543
        jnz     .not
1544
        push    eax
1545
        mov     esi, [edx]
1546
        and     esi, 0xf
1547
        and     al, 3
1548
        call    dword[check_modifier_table+esi*4]
1549
        test    al, al
1550
        pop     eax
1551
        jnz     .not
1552
        push    eax
1553
        mov     esi, [edx]
1554
        shr     esi, 4
1555
        and     esi, 0xf
1556
        shr     al, 2
1557
        and     al, 3
1558
        call    dword[check_modifier_table+esi*4]
1559
        test    al, al
1560
        pop     eax
1561
        jnz     .not
1562
        push    eax
1563
        mov     esi, [edx]
1564
        shr     esi, 8
1565
        and     esi, 0xf
1566
        shr     al, 4
1567
        and     al, 3
1568
        call    dword[check_modifier_table+esi*4]
1569
        test    al, al
1570
        pop     eax
1571
;       jnz     .not
1572
.not:
1573
        ret
1574
endp
1575
 
1576
 
1577
check_modifier_0:
1578
        setnz   al
1579
        ret
1580
check_modifier_1:
1581
        setp    al
1582
        ret
1583
check_modifier_2:
1584
        cmp     al, 3
1585
        setnz   al
1586
        ret
1587
check_modifier_3:
1588
        cmp     al, 1
1589
        setnz   al
1590
        ret
1591
check_modifier_4:
1592
        cmp     al, 2
1593
        setnz   al
1594
        ret
1595
 
1596
; >edi = destination string
1597
; >eax = number
1598
proc bin2dec
1599
        push    ebx ecx edx esi
1600
 
1601
        mov     ebx, 10
1602
        xor     ecx, ecx
1603
@@:
1604
        xor     edx, edx
1605
        div     ebx
1606
        push    edx
1607
        inc     ecx
1608
        test    eax, eax
1609
        jnz     @b
1610
 
1611
@@:
1612
        pop     eax
1613
        add     eax, '0'
1614
        stosb
1615
        inc     [window_header_len]
1616
        dec     ecx
1617
        jnz     @b
1618
 
1619
        pop     esi edx ecx ebx
1620
        ret
1621
endp
1622
 
1623
 
1624
; fills window_header with window title
9035 leency 1625
; window title is generated as '[k/n]  (WxH) - Kolibri Image Viewer'
8945 leency 1626
; n = total files in dir
1627
; k = current file index
9035 leency 1628
; W = current image width
1629
; H = current image height
8945 leency 1630
proc generate_window_header
1631
        push    eax ebx esi edi
1632
        mov     esi, [last_name_component]
1633
        mov     edi, window_header
1634
        mov     [window_header_len], 4    ; [,/,],
1635
 
1636
        mov     byte[edi], '['
1637
        inc     edi
1638
        mov     eax, [cur_file_idx]
1639
        inc     eax
1640
        call    bin2dec
1641
        mov     byte[edi], '/'
1642
        inc     edi
1643
        mov     eax, [directory_ptr]
1644
        mov     eax, [eax+4]
1645
        call    bin2dec
1646
        mov     word[edi], '] '
1647
        add     edi, 2
1648
 
1649
        ; add filename
1650
.next_symbol:
1651
        lodsb
1652
        test    al, al
1653
        jz      @f
1654
        stosb
1655
        inc     [window_header_len]
1656
        cmp     edi, window_header+256
1657
        jb      .next_symbol
1658
.overflow:
1659
        mov     dword[edi-4], '...'
1660
.ret:
1661
        pop     edi esi ebx eax
1662
        ret
1663
@@:
9035 leency 1664
        ; add size
1665
        mov     word[edi], ' ('
1666
        add     edi, 2
1667
 
1668
        mov     ebx, [orig_image]
1669
        mov     eax, [ebx+Image.Width]
1670
        call    bin2dec
1671
 
1672
        mov     byte[edi], 'x'
1673
        inc     edi
1674
 
1675
        mov     eax, [ebx+Image.Height]
1676
        call    bin2dec
1677
 
1678
        mov     byte[edi], ')'
1679
        inc     edi
1680
 
8945 leency 1681
        mov     esi, s_header
1682
@@:
1683
        lodsb
1684
        stosb
1685
        test    al, al
1686
        jz      .ret
1687
        cmp     edi, window_header+256
1688
        jb      @b
1689
        jmp     .overflow
1690
endp
1691
 
1692
 
1693
proc scale_none_calc
1694
        push    ebx
1695
 
1696
        mov     [scale_mode], LIBIMG_SCALE_NONE
1697
 
1698
        mov     eax, [cur_image]
1699
        cmp     eax, [orig_image]
1700
        jz      @f
1701
        invoke  img.destroy, eax
1702
@@:
1703
        mov     eax, [orig_image]
1704
        mov     [cur_image], eax
1705
        mov     [cur_frame], eax
1706
        mov     ebx, eax
1707
 
1708
        mov     [need_scrollbar_v], 0
1709
        mov     [need_scrollbar_h], 0
1710
 
1711
        mov     eax, [ebx+Image.Width]
1712
        cmp     eax, [canvas.width]
1713
        jbe     @f
1714
        sub     [canvas.height], SCROLL_WIDTH_SIZE+1
1715
        mov     [need_scrollbar_h], 1
1716
@@:
1717
        mov     eax, [ebx+Image.Height]
1718
        cmp     eax, [canvas.height]
1719
        jbe     @f
1720
        sub     [canvas.width], SCROLL_WIDTH_SIZE+1
1721
        mov     [need_scrollbar_v], 1
1722
@@:
1723
        cmp     [need_scrollbar_h], 1
1724
        jz      @f
1725
        mov     eax, [ebx+Image.Width]
1726
        cmp     eax, [canvas.width]
1727
        jbe     @f
1728
        sub     [canvas.height], SCROLL_WIDTH_SIZE+1
1729
        mov     [need_scrollbar_h], 1
1730
@@:
1731
 
1732
 
1733
        mov     eax, [ebx+Image.Width]
1734
        cmp     eax, [canvas.width]
1735
        jbe     @f
1736
        mov     eax, [canvas.width]
1737
@@:
1738
        mov     [view.width], eax
1739
        mov     [pict.width], eax
1740
 
1741
        mov     eax, [ebx+Image.Height]
1742
        cmp     eax, [canvas.height]
1743
        jbe     @f
1744
        mov     eax, [canvas.height]
1745
@@:
1746
        mov     [view.height], eax
1747
        mov     [pict.height], eax
1748
 
1749
        mov     eax, [canvas.width]
1750
        sub     eax, [view.width]
1751
        sar     eax, 1
1752
        mov     [view.left], eax
1753
        mov     eax, [canvas.height]
1754
        sub     eax, [view.height]
1755
        sar     eax, 1
1756
        mov     [view.top], eax
1757
 
1758
        mov     eax, [ebx+Image.Width]
1759
        sub     eax, [pict.width]
1760
        sar     eax, 1
1761
        mov     [pict.left], eax
1762
        mov     eax, [ebx+Image.Height]
1763
        sub     eax, [pict.height]
1764
        sar     eax, 1
1765
        mov     [pict.top], eax
1766
 
1767
 
1768
        mov     eax, [ebx+Image.Height]
1769
        mov     [scroll_bar_data_vertical.max_area], eax
1770
        mov     eax, [pict.height]
1771
        mov     [scroll_bar_data_vertical.cur_area], eax
1772
        mov     eax, [pict.top]
1773
        mov     [scroll_bar_data_vertical.position], eax
1774
 
1775
        mov     eax, [ebx+Image.Width]
1776
        mov     [scroll_bar_data_horizontal.max_area], eax
1777
        mov     eax, [pict.width]
1778
        mov     [scroll_bar_data_horizontal.cur_area], eax
1779
        mov     eax, [pict.left]
1780
        mov     [scroll_bar_data_horizontal.position], eax
1781
 
1782
        pop     ebx
1783
        ret
1784
endp
1785
 
1786
 
1787
proc scale_fit_min_calc
1788
        push    ebx
1789
 
1790
        mov     [need_scrollbar_v], 0
1791
        mov     [need_scrollbar_h], 0
1792
        mov     [scroll_bar_data_vertical.position], 0
1793
        mov     [scroll_bar_data_horizontal.position], 0
1794
 
1795
        mov     eax, [orig_image]
1796
        cmp     [eax+Image.Type], Image.bpp24
1797
        jz      @f
1798
        cmp     [eax+Image.Type], Image.bpp32
1799
        jz      @f
1800
        cmp     [eax+Image.Type], Image.bpp8g
1801
        jz      @f
1802
        invoke  img.convert, eax, 0, Image.bpp24, 0, 0
1803
        test    eax, eax
1804
;       jz      .error
1805
        push    eax
1806
        invoke  img.destroy, [orig_image]
1807
        pop     eax
1808
        mov     [orig_image], eax
1809
        mov     [cur_image], eax
1810
        mov     [cur_frame], eax
1811
@@:
1812
 
1813
        mov     eax, [orig_image]
1814
        mov     ecx, [eax+Image.Height]
1815
        mov     eax, [eax+Image.Width]
1816
        cmp     eax, [canvas.width]
1817
        ja      .get_size
1818
        cmp     ecx, [canvas.height]
1819
        ja      .get_size
1820
        jmp     .got_size
1821
.get_size:
1822
        invoke  img.get_scaled_size, eax, ecx, LIBIMG_SCALE_FIT_MIN, [canvas.width], [canvas.height]
1823
.got_size:
1824
 
1825
        mov     [pict.top], 0
1826
        mov     [pict.left], 0
1827
 
1828
        cmp     eax, [canvas.width]
1829
        jbe     @f
1830
        mov     eax, [canvas.width]
1831
@@:
1832
        mov     [view.width], eax
1833
        mov     [pict.width], eax
1834
        neg     eax
1835
        add     eax, [canvas.width]
1836
        shr     eax, 1
1837
        mov     [view.left], eax
1838
 
1839
        mov     eax, ecx
1840
        cmp     eax, [canvas.height]
1841
        jbe     @f
1842
        mov     eax, [canvas.height]
1843
@@:
1844
        mov     [view.height], eax
1845
        mov     [pict.height], eax
1846
        neg     eax
1847
        add     eax, [canvas.height]
1848
        shr     eax, 1
1849
        mov     [view.top], eax
1850
 
1851
 
1852
        pop     ebx
1853
        ret
1854
endp
1855
 
1856
 
1857
; eax: new scaling mode
1858
; z/Z - not/changed
1859
proc set_scale_mode
1860
        cmp     eax, [scale_mode]
1861
        mov     [scale_mode], eax
1862
        setnz   [bScaleModeChanged]
1863
        ret
1864
endp
1865
 
1866
proc move_pictport _dx, _dy
1867
locals
1868
        new_left dd ?
1869
        new_top  dd ?
1870
endl
1871
        push    ebx ecx
1872
 
1873
        mov     ebx, [cur_image]
1874
.x:
1875
        mov     eax, [pict.left]
1876
        add     eax, [_dx]
1877
        cmp     eax, 0
1878
        jge     @f
1879
        mov     [new_left], 0
1880
        jmp     .xdone
1881
@@:
1882
        mov     ecx, eax
1883
        add     eax, [pict.width]
1884
        cmp     eax, [ebx+Image.Width]
1885
        ja      @f
1886
        mov     [new_left], ecx
1887
        jmp     .xdone
1888
@@:
1889
        mov     eax, [ebx+Image.Width]
1890
        sub     eax, [pict.width]
1891
        mov     [new_left], eax
1892
        jmp     .xdone
1893
.xdone:
1894
 
1895
.y:
1896
        mov     eax, [pict.top]
1897
        add     eax, [_dy]
1898
        cmp     eax, 0
1899
        jge     @f
1900
        mov     [new_top], 0
1901
        jmp     .ydone
1902
@@:
1903
        mov     ecx, eax
1904
        add     eax, [pict.height]
1905
        cmp     eax, [ebx+Image.Height]
1906
        ja      @f
1907
        mov     [new_top], ecx
1908
        jmp     .ydone
1909
@@:
1910
        mov     eax, [ebx+Image.Height]
1911
        sub     eax, [pict.height]
1912
        mov     [new_top], eax
1913
        jmp     .ydone
1914
.ydone:
1915
 
1916
        xor     eax, eax
1917
        mov     ecx, [new_left]
1918
        mov     edx, [new_top]
1919
 
1920
        cmp     ecx, [pict.left]
1921
        setnz   al
1922
        shl     eax, 8
1923
 
1924
        cmp     edx, [pict.top]
1925
        setnz   al
1926
 
1927
        mov     [pict.left], ecx
1928
        mov     [pict.top], edx
1929
 
1930
        pop     ecx ebx
1931
        ret
1932
endp
1933
 
1934
 
1935
proc update_scrollbars _xxhv
1936
        mov     eax, [_xxhv]
1937
 
1938
        test    ah, ah
1939
        jz      .no_h_scroll
1940
        push    eax
1941
        mov     [scroll_bar_data_horizontal.all_redraw], 0
1942
        mov     eax, [pict.left]
1943
        mov     [scroll_bar_data_horizontal.position], eax
1944
        invoke  scrollbar_hort_draw, scroll_bar_data_horizontal
1945
        pop     eax
1946
.no_h_scroll:
1947
        test    al, al
1948
        jz      .no_v_scroll
1949
        push    eax
1950
        mov     [scroll_bar_data_vertical.all_redraw], 0
1951
        mov     eax, [pict.top]
1952
        mov     [scroll_bar_data_vertical.position], eax
1953
        invoke  scrollbar_vert_draw, scroll_bar_data_vertical
1954
        pop     eax
1955
.no_v_scroll:
1956
 
1957
        ret
1958
endp
1959
 
1960
 
1961
proc merge_icons_to_single_img _img
1962
        push    ebx esi edi
1963
 
1964
        mov     edx, [_img]
1965
        mov     eax, [edx+Image.Width]
1966
        mov     ecx, [edx+Image.Height]
1967
.next:
1968
        cmp     [edx+Image.Next], 0
1969
        jz      .got_sizes
1970
        inc     eax
1971
        mov     edx, [edx+Image.Next]
1972
        add     eax, [edx+Image.Width]
1973
        cmp     ecx, [edx+Image.Height]
1974
        jae     @f
1975
        mov     ecx, [edx+Image.Height]
1976
@@:
1977
        jmp     .next
1978
 
1979
.got_sizes:
1980
        invoke  img.create, eax, ecx, Image.bpp32
1981
        test    eax, eax
1982
        jz      .error
1983
        mov     ebx, eax
1984
 
1985
        mov     eax, [bg_color]
1986
        mov     edi, [ebx+Image.Data]
1987
        mov     ecx, [ebx+Image.Width]
1988
        imul    ecx, [ebx+Image.Height]
1989
        rep stosd
1990
 
1991
        mov     eax, [_img]
1992
        cmp     [eax+Image.Type], Image.bpp32
1993
        jz      @f
1994
        invoke  img.convert, eax, 0, Image.bpp32, 0, 0
1995
        test    eax, eax
1996
        jz      .error
1997
        push    eax
1998
        invoke  img.destroy, [_img]
1999
        pop     eax
2000
@@:
2001
        mov     esi, eax
2002
        xor     edi, edi
2003
.next_img:
2004
        stdcall put_img_on_img, ebx, esi, edi, 0
2005
        add     edi, [esi+Image.Width]
2006
        inc     edi
2007
        cmp     [esi+Image.Next], 0
2008
        jz      @f
2009
        mov     esi, [esi+Image.Next]
2010
        jmp     .next_img
2011
@@:
2012
        invoke  img.destroy, esi
2013
        mov     eax, ebx
2014
        jmp     .quit
2015
 
2016
.error:
2017
        xor     eax, eax
2018
.quit:
2019
        pop     edi esi ebx
2020
        ret
2021
endp
2022
 
2023
 
2024
proc put_img_on_img _bottom, _top, _x, _y
2025
locals
2026
        img_height dd ?
2027
endl
2028
        push    ebx esi edi
2029
 
2030
        mov     ebx, [_bottom]
2031
        mov     edx, [_top]
2032
        mov     eax, [edx+Image.Height]
2033
        mov     [img_height], eax
2034
        mov     esi, [edx+Image.Data]
2035
        mov     edi, [ebx+Image.Data]
2036
        mov     eax, [_y]
2037
        imul    eax, [ebx+Image.Width]
2038
        add     eax, [_x]
2039
        shl     eax, 2
2040
        add     edi, eax
2041
.next_line:
2042
        mov     ecx, [edx+Image.Width]
2043
        rep movsd
2044
        mov     eax, [ebx+Image.Width]
2045
        sub     eax, [edx+Image.Width]
2046
        shl     eax, 2
2047
        add     edi, eax
2048
        dec     [img_height]
2049
        jnz     .next_line
2050
 
2051
        pop     edi esi ebx
2052
        ret
2053
endp
2054
 
2055
 
2056
proc copy_box _src, _dst
2057
        pushad
2058
 
2059
        mov     esi, [_src]
2060
        mov     edi, [_dst]
2061
        mov     ecx, 4
2062
        rep movsd
2063
 
2064
        popad
2065
        ret
2066
endp
2067
 
2068
 
2069
proc cmp_box _a, _b
2070
        pushad
2071
 
2072
        mov     esi, [_a]
2073
        mov     edi, [_b]
2074
        mov     ecx, 4
2075
        rep cmpsd
2076
 
2077
        popad
2078
        ret
2079
endp
2080
 
2081
 
2082
proc recalc_client
2083
        stdcall copy_box, toolbar, toolbar_prev
2084
        mov     [toolbar.left], 0
2085
        mov     [toolbar.top], 0
2086
        mov     eax, [client.width]
2087
        mov     [toolbar.width], eax
2088
        mov     [toolbar.height], 0
2089
        cmp     [bShowToolbar], 1
2090
        jnz     @f
2091
        mov     [toolbar.height], TOOLBAR_HEIGHT
2092
@@:
2093
 
2094
        mov     eax, [toolbar.top]
2095
        add     eax, [client_abs_top]
2096
        mov     [toolbar_abs_top], eax
2097
        mov     eax, [toolbar.left]
2098
        add     eax, [client_abs_left]
2099
        mov     [toolbar_abs_left], eax
2100
 
2101
        test    [bFirstWinDraw], 1
2102
        jnz     .recalc_toolbar
2103
        stdcall cmp_box, toolbar, toolbar_prev
2104
        jnz     .recalc_toolbar
2105
        test    [bNewImage], 1
2106
        jnz     .recalc_toolbar
2107
        jmp     .recalc_toolbar_done
2108
.recalc_toolbar:
2109
        stdcall recalc_toolbar
2110
.recalc_toolbar_done:
2111
 
2112
        stdcall copy_box, work, work_prev
2113
        xor     ecx, ecx
2114
        test    [bShowToolbar], 1
2115
        jz      @f
2116
        mov     ecx, [toolbar.height]
2117
@@:
2118
        mov     eax, ecx
2119
        mov     [work.top], eax
2120
        mov     eax, [client.height]
2121
        sub     eax, ecx
2122
        mov     [work.height], eax
2123
        mov     [work.left], 0
2124
        mov     eax, [client.width]
2125
        mov     [work.width], eax
2126
 
2127
        mov     eax, [work.top]
2128
        add     eax, [client_abs_top]
2129
        mov     [work_abs_top], eax
2130
        mov     eax, [work.left]
2131
        add     eax, [client_abs_left]
2132
        mov     [work_abs_left], eax
2133
 
2134
        test    [bFirstWinDraw], 1
2135
        jnz     .recalc_work
2136
        test    [bNewImage], 1
2137
        jnz     .recalc_work
2138
        stdcall cmp_box, work, work_prev
2139
        jnz     .recalc_work
2140
        jmp     .recalc_work_done
2141
.recalc_work:
2142
        stdcall recalc_work
2143
.recalc_work_done:
2144
 
2145
        ret
2146
endp
2147
 
2148
 
2149
proc recalc_toolbar
2150
 
2151
        ret
2152
endp
2153
 
2154
 
2155
proc recalc_window
2156
        stdcall copy_box, client, client_prev
2157
        test    [bSlideShow], 1
2158
        jz      .no_slide_show
2159
.slide_show:
2160
        mov     [client.left], 0
2161
        mov     [client.top], 0
2162
        mov     eax, [procinfo.box.width]
2163
        mov     [client.width], eax
2164
        mov     eax, [procinfo.box.height]
2165
        mov     [client.height], eax
2166
        jmp     .calc_abs
2167
.no_slide_show:
2168
        mcall   SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
2169
        mov     [client.top], eax
2170
        neg     eax
2171
        add     eax, [procinfo.box.height]
2172
        sub     eax, 5
2173
        mov     [client.height], eax
2174
        mov     [client.left], 5
2175
        mov     eax, [procinfo.box.width]
2176
        sub     eax, 10
2177
        mov     [client.width], eax
2178
 
2179
.calc_abs:
2180
        mov     eax, [client.top]
2181
        mov     [client_abs_top], eax
2182
        mov     eax, [client.left]
2183
        mov     [client_abs_left], eax
2184
 
2185
        stdcall cmp_box, client, client_prev
2186
        jnz     .recalc_client
2187
        test    [bNewImage], 1
2188
        jnz     .recalc_client
2189
        test    [bToggleToolbar], 1
2190
        jnz     .recalc_client
2191
        jmp     .recalc_client_done
2192
.recalc_client:
2193
        stdcall recalc_client
2194
.recalc_client_done:
2195
 
2196
        ret
2197
endp
2198
 
2199
 
2200
proc recalc_work
2201
        stdcall copy_box, canvas, canvas_prev
2202
        mov     eax, [work.left]
2203
        add     eax, [canvas_padding]
2204
        mov     [canvas.left], eax
2205
        mov     eax, [work.width]
2206
        sub     eax, [canvas_padding]
2207
        sub     eax, [canvas_padding]
2208
        inc     eax
2209
        mov     [canvas.width], eax
2210
        mov     eax, [canvas_padding]
2211
        mov     [canvas.top], eax
2212
        mov     eax, [work.height]
2213
        sub     eax, [canvas_padding]
2214
        sub     eax, [canvas_padding]
2215
        inc     eax
2216
        mov     [canvas.height], eax
2217
 
2218
        mov     eax, [canvas.top]
2219
        add     eax, [work_abs_top]
2220
        mov     [canvas_abs_top], eax
2221
        mov     eax, [canvas.left]
2222
        add     eax, [work_abs_left]
2223
        mov     [canvas_abs_left], eax
2224
 
2225
        test    [bFirstWinDraw], 1
2226
        jnz     .recalc_canvas
2227
        test    [bNewImage], 1
2228
        jnz     .recalc_canvas
2229
        stdcall cmp_box, canvas, canvas_prev
2230
        jnz     .recalc_canvas
2231
        cmp     [bScaleModeChanged], 0
2232
        jnz     .recalc_canvas
2233
        jmp     .recalc_canvas_done
2234
.recalc_canvas:
2235
        stdcall recalc_canvas
2236
.recalc_canvas_done:
2237
        ret
2238
endp
2239
 
2240
 
2241
proc recalc_canvas
2242
        stdcall copy_box, view, view_prev
2243
        mov     eax, [scale_mode]
2244
        call    [scale_mode_calc+eax*4]
2245
 
2246
        mov     eax, [view.top]
2247
        add     eax, [canvas_abs_top]
2248
        mov     [view_abs_top], eax
2249
        mov     eax, [view.left]
2250
        add     eax, [canvas_abs_left]
2251
        mov     [view_abs_left], eax
2252
 
2253
        ret
2254
endp
2255
 
2256
;-----------------------------------------------------------------------------
2257
DATA
2258
 
2259
s_header        db ' - Kolibri Image Viewer',0
2260
window_style    dd 0x53FFFFFF
2261
window          BOX 100, 150, 0, 0  ; left top width height
2262
window_prev     BOX 0, 0, 0, 0
2263
window_save     BOX 0, 0, 0, 0  ; restore after slide show
2264
client          BOX 0, 0, 0, 0
2265
client_prev     BOX 0, 0, 0, 0
2266
client_abs_top  dd ?
2267
client_abs_left dd ?
2268
toolbar         BOX 0, 0, 0, 0
2269
toolbar_prev    BOX 0, 0, 0, 0
2270
toolbar_abs_top dd ?
2271
toolbar_abs_left dd ?
2272
work            BOX 0, 0, 0, 0
2273
work_prev       BOX 0, 0, 0, 0
2274
work_abs_top    dd ?
2275
work_abs_left   dd ?
2276
canvas          BOX 0, 0, 0, 0
2277
canvas_prev     BOX 0, 0, 0, 0
2278
canvas_abs_top  dd ?
2279
canvas_abs_left dd ?
2280
view            BOX -1, -1, 0, 0
2281
view_prev       BOX -1, -1, 0, 0
2282
view_abs_top    dd ?
2283
view_abs_left   dd ?
2284
pict            BOX 0, 0, 0, 0
2285
canvas_padding  dd 5
2286
bg_color        dd 0x00ffffff
2287
scale_mode      dd LIBIMG_SCALE_FIT_MIN
2288
pict_drag       dd 0
2289
scroll_v_drag   dd 0
2290
scroll_h_drag   dd 0
2291
 
2292
mouse_buttons    dd 0
2293
mouse_pos        dd 0
2294
need_scrollbar_v dd 0
2295
need_scrollbar_h dd 0
2296
 
2297
pict_moved      dd 0
2298
 
2299
;-----------------------------------------------------------------------------
2300
align   4
2301
scroll_bar_data_vertical:
2302
.x:
2303
.size_x         dw SCROLL_WIDTH_SIZE
2304
.start_x        dw 1
2305
.y:
2306
.size_y         dw 100
2307
.start_y        dw 0
2308
.btn_high       dd SCROLL_WIDTH_SIZE
2309
.type           dd 0    ;+12
2310
.max_area       dd 100  ;+16
2311
.cur_area       dd 10   ;+20
2312
.position       dd 0    ;+24
2313
.bckg_col       dd 0xAAAAAA     ;+28
2314
.frnt_col       dd 0xCCCCCC     ;+32
2315
.line_col       dd 0    ;+36
2316
.redraw         dd 0    ;+40
2317
.delta          dw 0    ;+44
2318
.delta2         dw 0    ;+46
2319
.run_x:
2320
.r_size_x       dw 0    ;+48
2321
.r_start_x      dw 0    ;+50
2322
.run_y:
2323
.r_size_y       dw 0    ;+52
2324
.r_start_y      dw 0    ;+54
2325
.m_pos          dd 0    ;+56
2326
.m_pos_2        dd 0    ;+60
2327
.m_keys         dd 0    ;+64
2328
.run_size       dd 0    ;+68
2329
.position2      dd 0    ;+72
2330
.work_size      dd 0    ;+76
2331
.all_redraw     dd 0    ;+80
2332
.ar_offset      dd KEY_MOVE_PIXELS   ;+84
2333
;-----------------------------------------------------------------------------
2334
align   4
2335
scroll_bar_data_horizontal:
2336
.x:
2337
.size_x         dw 0    ;+0
2338
.start_x        dw 0    ;+2
2339
.y:
2340
.size_y         dw SCROLL_WIDTH_SIZE    ;+4
2341
.start_y        dw 0    ;+6
2342
.btn_high       dd SCROLL_WIDTH_SIZE    ;+8
2343
.type           dd 0    ;+12
2344
.max_area       dd 50   ;+16
2345
.cur_area       dd 50   ;+20
2346
.position       dd 0    ;+24
2347
.bckg_col       dd 0xAAAAAA     ;+28
2348
.frnt_col       dd 0xCCCCCC     ;+32
2349
.line_col       dd 0    ;+36
2350
.redraw         dd 0    ;+40
2351
.delta          dw 0    ;+44
2352
.delta2         dw 0    ;+46
2353
.run_x:
2354
.r_size_x       dw 0    ;+48
2355
.r_start_x      dw 0    ;+50
2356
.run_y:
2357
.r_size_y       dw 0    ;+52
2358
.r_start_y      dw 0    ;+54
2359
.m_pos          dd 0    ;+56
2360
.m_pos_2        dd 0    ;+60
2361
.m_keys         dd 0    ;+64
2362
.run_size       dd 0    ;+68
2363
.position2      dd 0    ;+72
2364
.work_size      dd 0    ;+76
2365
.all_redraw     dd 0    ;+80
2366
.ar_offset      dd KEY_MOVE_PIXELS      ;+84
2367
;-----------------------------------------------------------------------------
2368
align 4
2369
@IMPORT:
2370
 
2371
library                           \
2372
        libgfx  , 'libgfx.obj'  , \
2373
        libimg  , 'libimg.obj'  , \
2374
        libini  , 'libini.obj'  , \
2375
        sort    , 'sort.obj'    , \
2376
        proc_lib, 'proc_lib.obj', \
2377
        box_lib , 'box_lib.obj'
2378
 
2379
 
2380
import libgfx                         , \
2381
        libgfx.init  , 'lib_init'     , \
2382
        gfx.open     , 'gfx_open'     , \
2383
        gfx.close    , 'gfx_close'    , \
2384
        gfx.pen.color, 'gfx_pen_color', \
2385
        gfx.line     , 'gfx_line'
2386
 
2387
import libimg                                     , \
2388
        libimg.init        , 'lib_init'           , \
2389
        img.from_file      , 'img_from_file'      , \
2390
        img.to_rgb2        , 'img_to_rgb2'        , \
2391
        img.create         , 'img_create'         , \
2392
        img.flip           , 'img_flip'           , \
2393
        img.rotate         , 'img_rotate'         , \
2394
        img.destroy        , 'img_destroy'        , \
2395
        img.scale          , 'img_scale'          , \
2396
        img.get_scaled_size, 'img_get_scaled_size', \
2397
        img.convert        , 'img_convert'        , \
2398
        img.draw           , 'img_draw'
2399
 
2400
import libini                               , \
2401
        ini_get_shortcut, 'ini_get_shortcut', \
2402
        ini_get_int,      'ini_get_int',\
2403
        ini_set_int,      'ini_set_int',\
2404
        ini_set_str,      'ini_set_str'
2405
 
2406
import sort                  ,\
2407
        sort.START, 'START'  ,\
2408
        SortDir   , 'SortDir',\
2409
        strcmpi   , 'strcmpi'
2410
 
2411
import proc_lib                             ,\
2412
        OpenDialog_Init , 'OpenDialog_init' ,\
2413
        OpenDialog_Start, 'OpenDialog_start'
2414
 
2415
import box_lib                                   ,\
2416
        scrollbar_vert_draw , 'scrollbar_v_draw' ,\
2417
        scrollbar_vert_mouse, 'scrollbar_v_mouse',\
2418
        scrollbar_hort_draw , 'scrollbar_h_draw' ,\
2419
        scrollbar_hort_mouse, 'scrollbar_h_mouse'
2420
 
2421
bFirstWinDraw     db 1
2422
bSlideShow        db 0
2423
bToggleSlideShow  db 0
2424
bShowToolbar      db 1
2425
bShowToolbarSave  db 0  ; to restore state when return from slide show
2426
bToggleToolbar    db 0
2427
bScaleModeChanged db 0
2428
bNewImage         db 0
2429
;-----------------------------------------------------------------------------
2430
 
2431
virtual at 0
2432
file 'kivicons.bmp':0xA,4
2433
load offbits dword from 0
2434
end virtual
2435
numimages = 11
2436
openbtn = 0
2437
backbtn = 1
2438
forwardbtn = 2
2439
bgrbtn = 3
2440
fliphorzbtn = 4
2441
flipvertbtn = 5
2442
rotcwbtn = 6
2443
rotccwbtn = 7
2444
rot180btn = 8
2445
slidebtn = 9
2446
scalebtn = 10
2447
 
2448
palette:
2449
    file 'kivicons.bmp':0x36,offbits-0x36
2450
buttons:
2451
    file 'kivicons.bmp':offbits
2452
repeat 10
2453
y = %-1
2454
z = 20-%
2455
repeat numimages*5
2456
load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
2457
load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
2458
store  dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
2459
store  dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
2460
end repeat
2461
end repeat
2462
 
2463
inifilename db  '/sys/settings/app.ini',0
2464
aKivSection  db  'Kiv',0
2465
aNext       db  'Next',0
2466
aPrev       db  'Prev',0
2467
aSlide      db  'SlideShow',0
2468
aTglbar     db  'ToggleBar',0
2469
aWinX       db  'WinX',0
2470
aWinY       db  'WinY',0
2471
aWinW       db  'WinW',0
2472
aWinH       db  'WinH',0
2473
 
2474
inifileeskin db '/sys/settings/system.ini',0
2475
amain       db 'style',0
2476
aprogram    db 'bg_program',0
2477
aparam      db 'bg_param',0
2478
 
2479
align 4
2480
check_modifier_table:
2481
    dd  check_modifier_0
2482
    dd  check_modifier_1
2483
    dd  check_modifier_2
2484
    dd  check_modifier_3
2485
    dd  check_modifier_4
2486
 
2487
;---------------------------------------------------------------------
2488
align 4
2489
OpenDialog_data:
2490
.type                   dd 0
2491
.procinfo               dd procinfo                             ; +4
2492
.com_area_name          dd communication_area_name              ; +8
2493
.com_area               dd 0                                    ; +12
2494
.opendir_path           dd temp_dir_path                        ; +16
2495
.dir_default_path       dd communication_area_default_path      ; +20
2496
.start_path             dd open_dialog_path                     ; +24
2497
.draw_window            dd draw_window                          ; +28
2498
.status                 dd 0                                    ; +32
2499
.openfile_path          dd path                                 ; openfile_path ; +36
2500
.filename_area          dd 0                                    ; +40
2501
.filter_area            dd Filter
2502
.x:
2503
.x_size                 dw 420                                  ; +48 ; Window X size
2504
.x_start                dw 10                                   ; +50 ; Window X position
2505
.y:
2506
.y_size                 dw 320                                  ; +52 ; Window y size
2507
.y_start                dw 10                                   ; +54 ; Window Y position
2508
 
2509
communication_area_name:
2510
    db 'FFFFFFFF_open_dialog',0
2511
 
2512
open_dialog_path:
2513
if __nightbuild eq yes
2514
    db '/sys/MANAGERS/opendial',0
2515
else
2516
    db '/sys/File Managers/opendial',0
2517
end if
2518
communication_area_default_path:
2519
    db '/rd/1',0
2520
 
2521
Filter:
2522
dd Filter.end-Filter
2523
.1:
2524
db 'BMP',0
2525
db 'GIF',0
2526
db 'JPG',0
2527
db 'JPEG',0
2528
db 'JPE',0
2529
db 'PNG',0
2530
db 'ICO',0
2531
db 'CUR',0
2532
db 'TGA',0
2533
db 'PCX',0
2534
db 'XCF',0
2535
db 'PBM',0
2536
db 'PGM',0
2537
db 'PNM',0
2538
db 'PPM',0
2539
db 'TIF',0
2540
db 'TIFF',0
2541
db 'WBMP',0
2542
db 'WEBP',0
2543
db 'XBM',0
2544
.end:
2545
db 0
2546
 
2547
draw_window_fake:
2548
        ret
2549
;------------------------------------------------------------------------------
2550
scale_mode_calc dd scale_none_calc, 0, 0, 0, scale_fit_min_calc
2551
 
2552
scale_none_mod    dd 0
2553
scale_none_key    dd 13 ; '='
2554
scale_fit_min_mod dd 0
2555
scale_fit_min_key dd 17 ; 'w'
2556
 
2557
move_pictport_left_1_mod dd 0
2558
move_pictport_left_1_key dd 35 ; 'h'
2559
move_pictport_left_2_mod dd 0
2560
move_pictport_left_2_key dd 75 ; arrow left
2561
 
2562
move_pictport_right_1_mod dd 0
2563
move_pictport_right_1_key dd 38 ; 'l'
2564
move_pictport_right_2_mod dd 0
2565
move_pictport_right_2_key dd 77 ; arrow right
2566
 
2567
move_pictport_up_1_mod dd 0
2568
move_pictport_up_1_key dd 37 ; 'k'
2569
move_pictport_up_2_mod dd 0
2570
move_pictport_up_2_key dd 72 ; arrow up
2571
 
2572
move_pictport_down_1_mod dd 0
2573
move_pictport_down_1_key dd 36 ; 'j'
2574
move_pictport_down_2_mod dd 0
2575
move_pictport_down_2_key dd 80 ; arrow down
2576
 
2577
;shift_left_down_mod
2578
 
2579
;include_debug_strings
2580
 
2581
readdir_fileinfo:
2582
    dd  1
2583
    dd  0
2584
    dd  0
2585
readblocks dd   0
2586
directory_ptr   dd 0
2587
curdir          rb 1024
2588
;------------------------------------------------------------------------------
2589
 
2590
I_END:
2591
align 4
2592
img_data_len    rd 1
2593
fh              rd 1
2594
orig_image      rd 1
2595
cur_image       rd 1
2596
files_num       rd 1
2597
cur_file_idx    rd 1
2598
cur_frame_time  rd 1
2599
cur_frame       rd 1
2600
 
2601
next_mod          rd 1
2602
next_key          rd 1
2603
prev_mod          rd 1
2604
prev_key          rd 1
2605
slide_mod         rd 1
2606
slide_key         rd 1
2607
tglbar_mod        rd 1
2608
tglbar_key        rd 1
2609
 
2610
 
2611
last_name_component rd 1
2612
toolbar.height_old  rd 1
2613
 
2614
procinfo        process_information
2615
scale_button_xy dd ?
2616
scale_button_letter dd ?        ; i.e. 'x1',0
2617
align 16
2618
path            rb 4096
2619
window_header   rb 256
2620
window_header_len rd 1
2621
__params        rb 4096
2622
;---------------------------------------------------------------------
2623
sys_path rb 1024
2624
temp_dir_path:
2625
        rb 4096
2626
;---------------------------------------------------------------------
2627
    rb 4096
2628
stacktop:
2629
;---------------------------------------------------------------------
2630
E_END: