Subversion Repositories Kolibri OS

Rev

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

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