Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1004 diamond 1
use32
2
org 0x0
3
 
4
db 'MENUET01'
1470 mario79 5
dd 0x01, START, I_END, F_END, stacktop, @PARAMS, 0x0
1004 diamond 6
 
7
;-----------------------------------------------------------------------------
8
 
3116 dunkaist 9
include '../../../config.inc'
1080 diamond 10
include '../../../proc32.inc'
11
include '../../../macros.inc'
3116 dunkaist 12
include '../../../dll.inc'
13
;include '../../../debug.inc'
1004 diamond 14
 
15
include '../../../develop/libraries/libs-dev/libio/libio.inc'
16
include '../../../develop/libraries/libs-dev/libimg/libimg.inc'
17
 
1511 mario79 18
;include '../../../develop/libraries/box_lib/asm/trunk/opendial.mac'
19
;use_OpenDialog
1004 diamond 20
;-----------------------------------------------------------------------------
21
 
22
START:
1570 dunkaist 23
    mcall   68, 11
1004 diamond 24
 
1570 dunkaist 25
    stdcall dll.Load, @IMPORT
26
    or  eax, eax
27
    jnz exit
1004 diamond 28
 
1570 dunkaist 29
    invoke  sort.START, 1
1016 diamond 30
 
1570 dunkaist 31
    mov ecx, 1  ; for 15.4: 1 = tile
32
    cmp word [@PARAMS], '\T'
33
    jz  set_bgr
34
    inc ecx ; for 15.4: 2 = stretch
35
    cmp word [@PARAMS], '\S'
36
    jz  set_bgr
1004 diamond 37
 
1594 mario79 38
    cmp byte [@PARAMS], 0
39
    jz @f
40
    mov esi, @PARAMS
41
    mov edi, path
42
    mov ecx, 4096/4
43
    rep movsd
44
    mov byte [edi-1], 0
45
@@:
46
; OpenDialog initialisation
47
    push    dword OpenDialog_data
48
    call    [OpenDialog_Init]
49
 
1427 diamond 50
; initialize keyboard handling
1570 dunkaist 51
    invoke  ini_get_shortcut, inifilename, aShortcuts, aNext, -1, next_mod
52
    mov [next_key], eax
53
    invoke  ini_get_shortcut, inifilename, aShortcuts, aPrev, -1, prev_mod
54
    mov [prev_key], eax
3116 dunkaist 55
    invoke  ini_get_shortcut, inifilename, aShortcuts, aSlide, -1, slide_mod
56
    mov [slide_key], eax
57
    invoke  ini_get_shortcut, inifilename, aShortcuts, aTglbar, -1, tglbar_mod
58
    mov [tglbar_key], eax
1570 dunkaist 59
    mcall   66, 1, 1    ; set kbd mode to scancodes
1427 diamond 60
 
1570 dunkaist 61
    cmp byte [@PARAMS], 0
62
    jnz params_given
1004 diamond 63
 
1570 dunkaist 64
    mov [OpenDialog_data.draw_window],draw_window_fake
65
 
1511 mario79 66
; OpenDialog Open
1570 dunkaist 67
    push    dword OpenDialog_data
68
    call    [OpenDialog_Start]
1470 mario79 69
 
1570 dunkaist 70
    cmp [OpenDialog_data.status],1
71
    jne exit
1470 mario79 72
 
1570 dunkaist 73
    mov [OpenDialog_data.draw_window],draw_window
1470 mario79 74
 
1570 dunkaist 75
    mov esi, path
76
    mov edi, @PARAMS
77
    mov ecx, 4096/4
78
    rep movsd
79
    mov byte [edi-1], 0
80
    jmp params_given
1004 diamond 81
 
82
set_bgr:
1570 dunkaist 83
    mcall   15, 4
84
    mov eax, @PARAMS + 4
85
    call    load_image
86
    jc  exit
1004 diamond 87
 
1570 dunkaist 88
    call    set_as_bgr
89
    jmp exit
1004 diamond 90
 
91
params_given:
92
 
1570 dunkaist 93
    mov esi, @PARAMS
94
    push    esi
95
    call    find_last_name_component
1427 diamond 96
 
1570 dunkaist 97
    pop eax
98
    call    load_image
99
    jc  exit
100
    call    generate_header
1004 diamond 101
 
102
;-----------------------------------------------------------------------------
103
 
104
red:
1570 dunkaist 105
    call    draw_window
1004 diamond 106
 
107
still:
1570 dunkaist 108
    mov eax, [image]
109
    test    byte [eax + Image.Flags], Image.IsAnimated
110
    push    10
111
    pop eax
112
    jz  @f
113
    mcall   26, 9
114
    mov edx, [cur_frame]
115
    mov ebx, [cur_frame_time]
116
    add ebx, [edx + Image.Delay]
117
    sub ebx, eax
118
    cmp ebx, [edx + Image.Delay]
119
    ja  red_update_frame
120
    test    ebx, ebx
121
    jz  red_update_frame
122
    push    23
123
    pop eax
1080 diamond 124
  @@:
1570 dunkaist 125
    mcall
126
    dec eax
127
    js  red_update_frame
128
    jz  red
129
    dec eax
130
    jnz button
1004 diamond 131
 
1080 diamond 132
key:
1570 dunkaist 133
    xor esi, esi
1427 diamond 134
keyloop:
1570 dunkaist 135
    mcall   2
136
    test    al, al
137
    jnz keyloopdone
138
    shr eax, 8
139
    mov ecx, eax
140
    mcall   66, 3
141
    mov edx, next_mod
142
    call    check_shortcut
143
    jz  .next
144
    add edx, prev_mod - next_mod
145
    call    check_shortcut
3116 dunkaist 146
    jz  .prev
147
    add edx, slide_mod - prev_mod
148
    call    check_shortcut
149
    jz  .slide
150
    add edx, tglbar_mod - slide_mod
151
    call    check_shortcut
152
    jz  .tglbar
153
    cmp cl, 1 ; Esc
154
    jz  .esc
155
    jmp keyloop
156
.esc:
157
    test byte [bSlideShow], 1
158
    jnz .slide
159
    jmp keyloop
160
.tglbar:
161
    mov byte [bTglbar], 1
162
    test byte[bSlideShow], 1
163
    jnz @f
164
    xor [toolbar_height], 31
165
@@:
166
    jmp keyloop
167
.slide:
168
    call slide_show
169
    jmp keyloop
1427 diamond 170
.prev:
1570 dunkaist 171
    dec esi
172
    jmp keyloop
1427 diamond 173
.next:
1570 dunkaist 174
    inc esi
175
    jmp keyloop
1427 diamond 176
keyloopdone:
3116 dunkaist 177
    test esi, esi
178
    jnz next_or_prev_handler
179
    test byte [bSlideShow], 2
180
    jnz red
181
    test byte [bTglbar], 1
182
    jnz red
183
    jmp still
1427 diamond 184
next_or_prev_handler:
1570 dunkaist 185
    call    next_or_prev_image
186
    jmp red
1004 diamond 187
 
1080 diamond 188
red_update_frame:
1570 dunkaist 189
    mov eax, [cur_frame]
190
    mov eax, [eax + Image.Next]
191
    test    eax, eax
192
    jnz @f
193
    mov eax, [image]
1080 diamond 194
  @@:
1570 dunkaist 195
    mov [cur_frame], eax
196
    mcall   26, 9
197
    mov [cur_frame_time], eax
198
    mcall   9, procinfo, -1
199
    call    draw_cur_frame
200
    jmp still
1080 diamond 201
 
202
button:
1570 dunkaist 203
    mcall   17
204
    shr eax, 8
1004 diamond 205
 
1570 dunkaist 206
    ; flip horizontally
207
    cmp eax, 'flh'
208
    jne @f
1004 diamond 209
 
1570 dunkaist 210
    invoke  img.flip, [image], FLIP_HORIZONTAL
211
    jmp redraw_image
1004 diamond 212
 
1570 dunkaist 213
    ; flip vertically
214
    @@: cmp eax, 'flv'
215
    jne @f
1004 diamond 216
 
1570 dunkaist 217
    invoke  img.flip, [image], FLIP_VERTICAL
218
    jmp redraw_image
1004 diamond 219
 
1570 dunkaist 220
    ; flip both horizontally and vertically
221
    @@: cmp eax, 'flb'
222
    jne @f
1004 diamond 223
 
1570 dunkaist 224
    invoke  img.flip, [image], FLIP_BOTH
225
    jmp redraw_image
1004 diamond 226
 
1570 dunkaist 227
    ; rotate left
228
    @@: cmp eax, 'rtl'
229
    jne @f
1004 diamond 230
 
1570 dunkaist 231
    push    ROTATE_90_CCW
1004 diamond 232
.rotate_common:
1570 dunkaist 233
    invoke  img.rotate, [image]
234
    mov eax, [image]
235
    test    eax, eax    ; clear ZF flag
236
    call    update_image_sizes
237
    jmp redraw_image
1004 diamond 238
 
1570 dunkaist 239
    ; rotate right
240
    @@: cmp eax, 'rtr'
241
    jne @f
1004 diamond 242
 
1570 dunkaist 243
    push    ROTATE_90_CW
244
    jmp .rotate_common
1004 diamond 245
 
1570 dunkaist 246
    ; open new file
247
    @@: cmp eax, 'opn'
248
    jne @f
249
 
1511 mario79 250
; OpenDialog Open
1570 dunkaist 251
    push    dword OpenDialog_data
252
    call    [OpenDialog_Start]
253
 
254
    cmp [OpenDialog_data.status],1
255
    jne still
256
 
257
    mov esi, path
258
    mov edi, @PARAMS
259
    push    edi
260
    mov ecx, 4096/4
261
    rep movsd
262
    mov byte [edi-1], 0
263
 
264
    pop esi
265
    push    esi
266
    call    find_last_name_component
1475 diamond 267
 
1570 dunkaist 268
    pop eax
269
    push    [image]
270
    call    load_image
271
    jc  .restore_old
272
    call    generate_header
273
 
274
    invoke  img.destroy
275
    call    free_directory
276
    jmp red
277
 
1004 diamond 278
    .restore_old:
1570 dunkaist 279
    pop [image]
280
    call    init_frame
281
    jmp still
1004 diamond 282
 
1570 dunkaist 283
    ; set background
1016 diamond 284
    @@:
1570 dunkaist 285
    cmp eax, 'bgr'
286
    jne @f
1016 diamond 287
 
1570 dunkaist 288
    call    set_as_bgr
289
    jmp still
1016 diamond 290
 
291
    @@:
3116 dunkaist 292
    cmp eax, 'sld'
293
    jne @f
1016 diamond 294
 
3116 dunkaist 295
    call    slide_show
296
    jmp red
297
 
298
    @@:
299
 
1570 dunkaist 300
    or  esi, -1
301
    cmp eax, 'bck'
302
    jz  next_or_prev_handler
303
    neg esi
304
    cmp eax, 'fwd'
305
    jz  next_or_prev_handler
1016 diamond 306
 
1570 dunkaist 307
    cmp eax, 1
308
    jne still
1004 diamond 309
 
310
  exit:
1570 dunkaist 311
    mcall   -1
1004 diamond 312
 
313
  redraw_image = red
314
 
315
load_image:
1570 dunkaist 316
    and [img_data], 0
317
    push    eax
318
    invoke  file.open, eax, O_READ
319
    or  eax, eax
320
    jz  .error_pop
321
    mov [fh], eax
322
    invoke  file.size
323
    mov [img_data_len], ebx
324
    stdcall mem.Alloc, ebx
325
    test    eax, eax
326
    jz  .error_close
327
    mov [img_data], eax
328
    invoke  file.read, [fh], eax, [img_data_len]
329
    cmp eax, -1
330
    jz  .error_close
331
    cmp eax, [img_data_len]
332
    jnz .error_close
333
    invoke  file.close, [fh]
334
    inc eax
335
    jz  .error
1004 diamond 336
 
1570 dunkaist 337
    invoke  img.decode, [img_data], [img_data_len], 0
338
    or  eax, eax
339
    jz  .error
340
    cmp [image], 0
341
    pushf
342
    mov [image], eax
343
    call    init_frame
344
    popf
345
    call    update_image_sizes
346
    call    free_img_data
347
    clc
348
    ret
1004 diamond 349
 
350
.error_free:
1570 dunkaist 351
    invoke  img.destroy, [image]
352
    jmp .error
1004 diamond 353
 
354
.error_pop:
1570 dunkaist 355
    pop eax
356
    jmp .error
1004 diamond 357
.error_close:
1570 dunkaist 358
    invoke  file.close, [fh]
1004 diamond 359
.error:
1570 dunkaist 360
    call    free_img_data
361
    stc
362
    ret
1004 diamond 363
 
364
free_img_data:
1570 dunkaist 365
    mov eax, [img_data]
366
    test    eax, eax
367
    jz  @f
368
    stdcall mem.Free, eax
1004 diamond 369
@@:
1570 dunkaist 370
    ret
1004 diamond 371
 
372
update_image_sizes:
1570 dunkaist 373
    pushf
374
    mov edx, [eax + Image.Width]
2036 dunkaist 375
    test    [eax + Image.Flags], Image.IsAnimated
376
    jnz .not_in_row
377
    push eax
378
@@: cmp [eax + Image.Next], 0
379
    jz  @f
380
    mov eax, [eax + Image.Next]
381
    add edx, [eax + Image.Width]
382
    inc edx
383
    jmp @b
384
@@: pop eax
385
.not_in_row:
1570 dunkaist 386
    mov [draw_width], edx
387
    add edx, 19
3116 dunkaist 388
    cmp edx, 50 + 25*numimages
1570 dunkaist 389
    jae @f
3116 dunkaist 390
    mov edx, 50 + 25*numimages
1004 diamond 391
@@:
3116 dunkaist 392
;    dec edx
1570 dunkaist 393
    mov [wnd_width], edx
394
    mov esi, [eax + Image.Height]
2036 dunkaist 395
    test    [eax + Image.Flags], Image.IsAnimated
396
    jnz .max_equals_first
397
    push eax
398
@@: cmp [eax + Image.Next], 0
399
    jz  @f
400
    mov eax, [eax + Image.Next]
401
    cmp esi, [eax + Image.Height]
402
    jae @b
403
    mov esi, [eax + Image.Height]
404
    jmp @b
405
@@: pop eax
406
.max_equals_first:
1570 dunkaist 407
    mov [draw_height], esi
3116 dunkaist 408
    add esi, [toolbar_height]
409
    add esi, [image_padding]
410
    add esi, [image_padding]
411
    add esi, 5  ; window bottom frame height
412
    dec esi
1570 dunkaist 413
    mov [wnd_height], esi
414
    popf
415
    jz  .no_resize
3116 dunkaist 416
    test [wnd_style], 1 SHL 25
417
    jz .no_resize
1570 dunkaist 418
    mcall   48, 4
419
    add esi, eax
420
    mcall   67,-1,-1
1004 diamond 421
.no_resize:
1570 dunkaist 422
    ret
1004 diamond 423
 
1016 diamond 424
set_as_bgr:
1570 dunkaist 425
    mov esi, [image]
426
    mov ecx, [esi + Image.Width]
427
    mov edx, [esi + Image.Height]
428
    mcall   15, 1
1016 diamond 429
 
1570 dunkaist 430
    mcall   15, 6
431
    test    eax, eax
432
    jz  @f
1016 diamond 433
 
1570 dunkaist 434
    push    eax
435
    invoke  img.to_rgb2, esi, eax
436
    pop ecx
437
    mcall   15, 7
1016 diamond 438
 
439
@@:
1570 dunkaist 440
    mcall   15, 3
441
    ret
1016 diamond 442
 
3116 dunkaist 443
slide_show:
444
    or  byte [bSlideShow], 2
445
    xor byte [bSlideShow], 1
446
    btc dword [wnd_style], 25
447
    jc  @f
448
    mov eax, [toolbar_height_old]
449
    mov [toolbar_height], eax
450
    mov [image_padding], 5
451
    jmp .toolbar_height_done
452
@@:
453
    mov eax, [toolbar_height]
454
    mov [toolbar_height_old], eax
455
    mov [toolbar_height], 0
456
    mov [image_padding], 0
457
.toolbar_height_done:
458
    ret
459
 
1427 diamond 460
; seek to ESI image files
461
; esi>0 means next file, esi<0 - prev file
462
next_or_prev_image:
1570 dunkaist 463
    push    esi
464
    call    load_directory
465
    pop esi
466
    mov ebx, [directory_ptr]
467
    test    ebx, ebx
468
    jz  .ret
469
    cmp dword[ebx+4], 0
470
    jz  .ret
471
    mov eax, [cur_file_idx]
472
    cmp eax, -1
473
    jnz @f
474
    test    esi, esi
475
    jns @f
476
    mov eax, [ebx+4]
1016 diamond 477
@@:
1570 dunkaist 478
    push    [image]
479
    add eax, esi
1427 diamond 480
@@:
1570 dunkaist 481
    test    eax, eax
482
    jns @f
483
    add eax, [ebx+4]
484
    jmp @b
1016 diamond 485
@@:
1570 dunkaist 486
    cmp eax, [ebx+4]
487
    jb  @f
488
    sub eax, [ebx+4]
489
    jmp @b
1427 diamond 490
@@:
1570 dunkaist 491
    push    eax
1427 diamond 492
.scanloop:
1570 dunkaist 493
    push    eax ebx esi
494
    imul    esi, eax, 304
495
    add esi, [directory_ptr]
496
    add esi, 32 + 40
497
    mov edi, curdir
1016 diamond 498
@@:
1570 dunkaist 499
    inc edi
500
    cmp byte [edi-1], 0
501
    jnz @b
502
    mov byte [edi-1], '/'
1016 diamond 503
@@:
1570 dunkaist 504
    lodsb
505
    stosb
506
    test    al, al
507
    jnz @b
508
    mov eax, curdir
509
    call    load_image
510
    pushf
511
    mov esi, curdir
512
    push    esi
513
    mov edi, @PARAMS
514
    mov ecx, 4096/4
515
    rep movsd
516
    mov byte [edi-1], 0
517
    pop esi
1040 diamond 518
@@:
1570 dunkaist 519
    lodsb
520
    test    al, al
521
    jnz @b
1040 diamond 522
@@:
1570 dunkaist 523
    dec esi
524
    cmp byte [esi], '/'
525
    jnz @b
526
    mov byte [esi], 0
527
    popf
528
    pop esi ebx eax
529
    jnc .loadedok
530
    test    esi, esi
531
    js  .try_prev
1427 diamond 532
.try_next:
1570 dunkaist 533
    inc eax
534
    cmp eax, [ebx+4]
535
    jb  @f
536
    xor eax, eax
1016 diamond 537
@@:
1427 diamond 538
.try_common:
1570 dunkaist 539
    cmp eax, [esp]
540
    jz  .notfound
541
    jmp .scanloop
1427 diamond 542
.try_prev:
1570 dunkaist 543
    dec eax
544
    jns @f
545
    mov eax, [ebx+4]
546
    dec eax
1016 diamond 547
@@:
1570 dunkaist 548
    jmp .try_common
1427 diamond 549
.loadedok:
1570 dunkaist 550
    mov [cur_file_idx], eax
551
    pop eax
552
    invoke  img.destroy
553
    call    generate_header
1016 diamond 554
.ret:
1570 dunkaist 555
    ret
1016 diamond 556
.notfound:
1570 dunkaist 557
    pop eax
558
    pop [image]
559
    call    init_frame
560
    ret
1016 diamond 561
 
562
load_directory:
1570 dunkaist 563
    cmp [directory_ptr], 0
564
    jnz .ret
565
    mov esi, @PARAMS
566
    mov edi, curdir
567
    mov ecx, [last_name_component]
568
    sub ecx, esi
569
    dec ecx
570
    js  @f
571
    rep movsb
1427 diamond 572
@@:
1570 dunkaist 573
    mov byte [edi], 0
574
    mcall   68, 12, 0x1000
575
    test    eax, eax
576
    jz  .ret
577
    mov ebx, readdir_fileinfo
578
    mov dword [ebx+12], (0x1000 - 32) / 304
579
    mov dword [ebx+16], eax
580
    mcall   70
581
    cmp eax, 6
582
    jz  .dirok
583
    test    eax, eax
584
    jnz free_directory
585
    mov edx, [directory_ptr]
586
    mov ecx, [edx+8]
587
    mov [readblocks], ecx
588
    imul    ecx, 304
589
    add ecx, 32
590
    mcall   68, 20
591
    test    eax, eax
592
    jz  free_directory
593
    mov [directory_ptr], eax
594
    mcall   70, readdir_fileinfo
1016 diamond 595
.dirok:
1570 dunkaist 596
    cmp ebx, 0
597
    jle free_directory
598
    mov eax, [directory_ptr]
599
    add eax, 32
600
    mov edi, eax
601
    push    0
1016 diamond 602
.dirskip:
1570 dunkaist 603
    push    eax
604
    test    byte [eax], 18h
605
    jnz .nocopy
606
    lea esi, [eax+40]
607
    mov ecx, esi
1016 diamond 608
@@:
1570 dunkaist 609
    lodsb
610
    test    al, al
611
    jnz @b
1016 diamond 612
@@:
1570 dunkaist 613
    dec esi
614
    cmp esi, ecx
615
    jb  .noext
616
    cmp byte [esi], '.'
617
    jnz @b
618
    inc esi
619
    mov ecx, [esi]
620
    or  ecx, 0x202020
621
    cmp ecx, 'jpg'
622
    jz  .copy
623
    cmp ecx, 'bmp'
624
    jz  .copy
625
    cmp ecx, 'gif'
626
    jz  .copy
627
    cmp ecx, 'png'
628
    jz  .copy
629
    cmp ecx, 'jpe'
630
    jz  .copy
631
    cmp ecx, 'ico'
632
    jz  .copy
633
    cmp ecx, 'cur'
634
    jz  .copy
3116 dunkaist 635
    cmp ecx, 'tga'
636
    jz  .copy
1575 dunkaist 637
    cmp ecx, 'pcx'
638
    jz  .copy
1922 dunkaist 639
    cmp ecx, 'xcf'
640
    jz  .copy
2389 dunkaist 641
    cmp ecx, 'pbm'
642
    jz  .copy
643
    cmp ecx, 'pgm'
644
    jz  .copy
645
    cmp ecx, 'pnm'
646
    jz  .copy
647
    cmp ecx, 'tif'
648
    jz  .copy
649
    cmp ecx, 'tiff'
650
    jz  @f
2394 dunkaist 651
    cmp ecx, 'wbmp'
652
    jz  @f
1570 dunkaist 653
    cmp ecx, 'jpeg'
654
    jz  @f
655
    cmp ecx, 'jpeG'
656
    jnz .nocopy
1016 diamond 657
@@:
1570 dunkaist 658
    cmp byte [esi+4], 0
659
    jnz .nocopy
1016 diamond 660
.copy:
1570 dunkaist 661
    mov esi, [esp]
662
    mov ecx, 304 / 4
663
    rep movsd
664
    inc dword [esp+4]
1016 diamond 665
.nocopy:
666
.noext:
1570 dunkaist 667
    pop eax
668
    add eax, 304
669
    dec ebx
670
    jnz .dirskip
671
    mov eax, [directory_ptr]
672
    pop ebx
673
    mov [eax+4], ebx
674
    test    ebx, ebx
675
    jz  free_directory
676
    push    0   ; sort mode
677
    push    ebx
678
    add eax, 32
679
    push    eax
680
    call    [SortDir]
681
    xor eax, eax
682
    mov edi, [directory_ptr]
683
    add edi, 32 + 40
1016 diamond 684
.scan:
1570 dunkaist 685
    mov esi, [last_name_component]
686
    push    edi
687
    invoke  strcmpi
688
    pop edi
689
    jz  .found
690
    inc eax
691
    add edi, 304
692
    dec ebx
693
    jnz .scan
694
    or  eax, -1
1016 diamond 695
.found:
1570 dunkaist 696
    mov [cur_file_idx], eax
1016 diamond 697
.ret:
1570 dunkaist 698
    ret
1016 diamond 699
 
700
free_directory:
1570 dunkaist 701
    mcall   68, 13, [directory_ptr]
702
    and [directory_ptr], 0
703
    ret
1016 diamond 704
 
1427 diamond 705
; in: esi->full name (e.g. /path/to/file.png)
706
; out: [last_name_component]->last component (e.g. file.png)
707
find_last_name_component:
1570 dunkaist 708
    mov ecx, esi
1427 diamond 709
@@:
1570 dunkaist 710
    lodsb
711
    test    al, al
712
    jnz @b
1427 diamond 713
@@:
1570 dunkaist 714
    dec esi
715
    cmp esi, ecx
716
    jb  @f
717
    cmp byte [esi], '/'
718
    jnz @b
1427 diamond 719
@@:
1570 dunkaist 720
    inc esi
721
    mov [last_name_component], esi
722
    ret
1427 diamond 723
 
1080 diamond 724
init_frame:
1570 dunkaist 725
    push    eax
726
    mov eax, [image]
727
    mov [cur_frame], eax
728
    test    byte [eax + Image.Flags], Image.IsAnimated
729
    jz  @f
730
    push    ebx
731
    mcall   26, 9
732
    pop ebx
733
    mov [cur_frame_time], eax
1080 diamond 734
@@:
1570 dunkaist 735
    pop eax
736
    ret
1080 diamond 737
 
1004 diamond 738
draw_window:
3116 dunkaist 739
    btr  word [bSlideShow], 1  ; mode changed
740
    jc .mode_changed
741
    test byte [bTglbar], 1
742
    jz .mode_not_changed
743
.mode_changed:
744
    test [wnd_style], 1 SHL 25
745
    jz .mode_slide
746
    mov [bg_color], 0x00ffffff
747
    mov eax, [image]
748
    cmp eax, eax
749
    call update_image_sizes
750
    mcall 48, 4
751
    mov esi, [wnd_height]
752
    add esi, eax
753
    test byte [bTglbar], 1
754
    jz @f
755
    mcall 67, -1, -1, [wnd_width],
756
    jmp .mode_not_changed
757
@@:
758
    mcall 67, [wnd_x], [wnd_y], [wnd_width],
759
    jmp .mode_not_changed
760
.mode_slide:
761
    mov [bg_color], 0x00000000
762
    mov eax, [procinfo.box.left]
763
    mov [wnd_x], eax
764
    mov eax, [procinfo.box.top]
765
    mov [wnd_y], eax
766
    mcall 14
767
    mov edx, eax
768
    shr edx, 16
769
    movzx eax, ax
770
    mov esi, eax
771
    mcall 67, 0, 0, ,
772
    jmp .posok.slide_show
773
 
774
.mode_not_changed:
1570 dunkaist 775
    cmp [bFirstDraw], 0
776
    jz  .posok
777
    or  ecx, -1
778
    mcall   9, procinfo
1040 diamond 779
 
3116 dunkaist 780
    test byte [procinfo.wnd_state], 0x04
781
    jnz .posok
1040 diamond 782
 
1570 dunkaist 783
    mov edx, ecx
784
    mov esi, ecx
3116 dunkaist 785
    cmp dword [procinfo.box.width], 50 + 25 * numimages
1570 dunkaist 786
    jae @f
3116 dunkaist 787
    mov edx, 50 + 25 * numimages
1040 diamond 788
@@:
3116 dunkaist 789
    cmp dword [procinfo.box.height], 70
1570 dunkaist 790
    jae @f
791
    mov esi, 70
1040 diamond 792
@@:
1570 dunkaist 793
    mov eax, edx
794
    and eax, esi
795
    cmp eax, -1
796
    jz  @f
797
    mov ebx, ecx
798
    mcall   67
1040 diamond 799
@@:
800
 
801
.posok:
3116 dunkaist 802
    test [wnd_style], 1 SHL 25
803
    jz .posok.slide_show
1570 dunkaist 804
    mcall   12, 1
805
    mcall   48, 4
806
    mov ebp, eax    ; save skin height
807
    add eax, [wnd_height]
3116 dunkaist 808
    mov ebx, [wnd_x]
809
    shl ebx, 16
1570 dunkaist 810
    add ebx, [wnd_width]
3116 dunkaist 811
    mov ecx, [wnd_y]
812
    shl ecx, 16
813
    add ecx, eax
814
    mcall   0, , , [wnd_style], 0, real_header
815
    jmp .posok.common
816
.posok.slide_show:
817
    mcall   12, 1
818
    mcall 14
819
    mov ebx, eax
820
    shr ebx, 16
821
    movzx eax, ax
822
    mov ecx, eax
823
    mcall   0, , , [wnd_style], 0, real_header
824
.posok.common:
1570 dunkaist 825
    mcall   9, procinfo, -1
3116 dunkaist 826
    mov eax, [procinfo.client_box.width]
827
    sub eax, [image_padding]
828
    sub eax, [image_padding]
829
    sub eax, [draw_width]
830
    sar eax, 1
831
    test eax, eax
832
    jns @f
833
    mov eax, 0
834
@@:
835
    add eax, [image_padding]
836
    mov [draw_x], eax
837
    mov eax, [procinfo.client_box.height]
838
    sub eax, [toolbar_height]
839
    sub eax, [image_padding]
840
    sub eax, [image_padding]
841
    sub eax, [draw_height]
842
    sar eax, 1
843
    test eax, eax
844
    jns @f
845
    mov eax, 0
846
@@:
847
    add eax, [toolbar_height]
848
    add eax, [image_padding]
849
    mov [draw_y], eax
1570 dunkaist 850
    mov [bFirstDraw], 1
3116 dunkaist 851
    cmp dword [procinfo.client_box.height], 0
1570 dunkaist 852
    jle .nodraw
3116 dunkaist 853
    mov ebx, [procinfo.client_box.width]
1570 dunkaist 854
    inc ebx
3116 dunkaist 855
    mov ecx, [draw_y]
856
    mcall   13, , , [bg_color]
857
    mov ecx, [procinfo.client_box.height]
1570 dunkaist 858
    inc ecx
3116 dunkaist 859
    mov esi, [cur_frame]
860
    mov esi, [esi + Image.Height]
861
    add esi, [draw_y]
1570 dunkaist 862
    sub ecx, esi
863
    jbe @f
864
    push    esi
865
    shl esi, 16
866
    add ecx, esi
867
    pop esi
868
    mcall
869
    xor ecx, ecx
1040 diamond 870
@@:
1570 dunkaist 871
    add ecx, esi
3116 dunkaist 872
    mov ebx, [draw_y]
873
    sub ecx, ebx
874
    shl ebx, 16
875
    add ecx, ebx
876
    mov ebx, [draw_x]
1570 dunkaist 877
    mcall
3116 dunkaist 878
    mov esi, [cur_frame]
879
    mov esi, [esi + Image.Width]
1570 dunkaist 880
    add esi, ebx
3116 dunkaist 881
    mov ebx, [procinfo.client_box.width]
1570 dunkaist 882
    inc ebx
883
    sub ebx, esi
884
    jbe @f
885
    shl esi, 16
886
    add ebx, esi
887
    mcall
1040 diamond 888
@@:
1004 diamond 889
 
3116 dunkaist 890
    test [wnd_style], 1 SHL 25
891
    jz .slide_show_mode
892
    mov byte [bTglbar], 0
893
    cmp byte [toolbar_height], 0
894
    je .decorations_done
895
    mov ebx, [procinfo.client_box.width]
1570 dunkaist 896
    push    ebx
897
    mcall   38, , <30, 30>, 0x007F7F7F
898
    mcall   , <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
899
    mcall   , <10 + 25 * 3, 10 + 25 * 3>
3116 dunkaist 900
    mcall   , <15 + 25 * 5, 15 + 25 * 5>
1570 dunkaist 901
    pop ebx
3116 dunkaist 902
    sub ebx, 25 * 5 + 10
1570 dunkaist 903
    push    ebx
904
    imul    ebx, 10001h
905
    mcall
1004 diamond 906
 
1570 dunkaist 907
    mcall   8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
908
    mcall   , <10 + 25 * 1, 20>, , 'bck'+40000000h
909
    mcall   , <10 + 25 * 2, 20>, , 'fwd'+40000000h
910
    mcall   , <15 + 25 * 3, 20>, , 'bgr'+40000000h
3116 dunkaist 911
    mcall   , <15 + 25 * 4, 20>, , 'sld'+40000000h
1570 dunkaist 912
    pop ebx
913
    add ebx, 5
914
    shl ebx, 16
915
    mov bl, 20
916
    mcall   , , , 'flh'+40000000h
917
    add ebx, 25 * 65536
918
    mcall   , , , 'flv'+40000000h
919
    add ebx, 30 * 65536
920
    mcall   , , , 'rtr'+40000000h
921
    add ebx, 25 * 65536
922
    mcall   , , , 'rtl'+40000000h
923
    add ebx, 25 * 65536
924
    mcall   , , , 'flb'+40000000h
1004 diamond 925
 
1570 dunkaist 926
    mov ebp, (numimages-1)*20
1004 diamond 927
 
1570 dunkaist 928
    mcall   65, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
3116 dunkaist 929
    mcall   , buttons+backbtn*20,    , <10 + 25 * 1, 5>
1570 dunkaist 930
    mcall   , buttons+forwardbtn*20, , <10 + 25 * 2, 5>
3116 dunkaist 931
    mcall   , buttons+bgrbtn*20,     , <15 + 25 * 3, 5>
932
    mcall   , buttons+slidebtn*20,   , <15 + 25 * 4, 5>
933
    mov edx, [procinfo.client_box.width]
1570 dunkaist 934
    sub edx, 25 * 5 + 4
935
    shl edx, 16
936
    mov dl, 5
937
    mcall   , buttons+fliphorzbtn*20
938
    add edx, 25 * 65536
939
    mcall   , buttons+flipvertbtn*20
940
    add edx, 30 * 65536
941
    mcall   , buttons+rotcwbtn*20
942
    add edx, 25 * 65536
943
    mcall   , buttons+rotccwbtn*20
944
    add edx, 25 * 65536
945
    mcall   , buttons+rot180btn*20
3116 dunkaist 946
    jmp .decorations_done
1004 diamond 947
 
3116 dunkaist 948
.slide_show_mode:
949
 
950
.decorations_done:
1570 dunkaist 951
    call    draw_cur_frame
1004 diamond 952
 
1087 diamond 953
.nodraw:
1570 dunkaist 954
    mcall   12, 2
1040 diamond 955
 
1570 dunkaist 956
    ret
1004 diamond 957
 
1080 diamond 958
draw_cur_frame:
1570 dunkaist 959
    push    0   ; ypos
960
    push    0   ; xpos
3116 dunkaist 961
    mov eax, [procinfo.client_box.height]
962
    sub eax, [toolbar_height]
963
    sub eax, [image_padding]
964
    inc eax
1570 dunkaist 965
    push    eax ; max height
3116 dunkaist 966
    mov eax, [procinfo.client_box.width]
967
    sub eax, [image_padding]
968
    inc eax
1570 dunkaist 969
    push    eax ; max width
3116 dunkaist 970
    push [draw_y]
971
    push [draw_x]
1570 dunkaist 972
    push    [cur_frame]
973
    call    [img.draw]
974
    mov eax, [image]
975
    test    [eax + Image.Flags], Image.IsAnimated
976
    jnz .done
977
    cmp [eax + Image.Next], 0
978
    jnz .additional_frames
1102 diamond 979
.done:
1570 dunkaist 980
    ret
1102 diamond 981
.additional_frames:
3116 dunkaist 982
    mov ebx, [procinfo.client_box.width]
983
    sub ebx, [image_padding]
984
    inc ebx
1570 dunkaist 985
    jbe .done
3116 dunkaist 986
    mov esi, [draw_x]
1102 diamond 987
.afloop:
1570 dunkaist 988
    sub ebx, [eax + Image.Width]
989
    jbe .done
990
    dec ebx
991
    jz  .done
992
    add esi, [eax + Image.Width]
993
    mov eax, [eax + Image.Next]
994
    push    eax
995
    inc esi
996
    push    0   ; ypos
997
    push    0   ; xpos
3116 dunkaist 998
    mov ecx, [procinfo.client_box.height]
999
    sub ecx, [toolbar_height]
1000
    sub ecx, [image_padding]
1001
    inc ecx
1002
;    inc ebx
1570 dunkaist 1003
    push    ecx ; max height
1004
    push    ebx ; max width
3116 dunkaist 1005
    push    [draw_y]  ; y
1570 dunkaist 1006
    push    esi ; x
1007
    push    eax ; image
1008
    call    [img.draw]
1009
    pop eax
1010
    cmp [eax + Image.Next], 0
1011
    jnz .afloop
1012
    ret
1080 diamond 1013
 
1004 diamond 1014
 
1427 diamond 1015
check_shortcut:
1570 dunkaist 1016
; in:   cl = scancode (from sysfn 2),
1017
;   eax = state of modifiers (from sysfn 66.3),
1018
;   edx -> shortcut descriptor
1019
; out:  ZF set <=> fail
1020
    cmp cl, [edx+4]
1021
    jnz .not
1022
    push    eax
1023
    mov esi, [edx]
1024
    and esi, 0xF
1025
    and al, 3
1026
    call    dword [check_modifier_table+esi*4]
1027
    test    al, al
1028
    pop eax
1029
    jnz .not
1030
    push    eax
1031
    mov esi, [edx]
1032
    shr esi, 4
1033
    and esi, 0xF
1034
    shr al, 2
1035
    and al, 3
1036
    call    dword [check_modifier_table+esi*4]
1037
    test    al, al
1038
    pop eax
1039
    jnz .not
1040
    push    eax
1041
    mov esi, [edx]
1042
    shr esi, 8
1043
    and esi, 0xF
1044
    shr al, 4
1045
    and al, 3
1046
    call    dword [check_modifier_table+esi*4]
1047
    test    al, al
1048
    pop eax
1049
;   jnz .not
1427 diamond 1050
.not:
1570 dunkaist 1051
    ret
1427 diamond 1052
 
1053
check_modifier_0:
1570 dunkaist 1054
    setnz   al
1055
    ret
1427 diamond 1056
check_modifier_1:
1570 dunkaist 1057
    setp    al
1058
    ret
1427 diamond 1059
check_modifier_2:
1570 dunkaist 1060
    cmp al, 3
1061
    setnz   al
1062
    ret
1427 diamond 1063
check_modifier_3:
1570 dunkaist 1064
    cmp al, 1
1065
    setnz   al
1066
    ret
1427 diamond 1067
check_modifier_4:
1570 dunkaist 1068
    cmp al, 2
1069
    setnz   al
1070
    ret
1427 diamond 1071
 
1072
; fills real_header with window title
1073
; window title is generated as ' - Kolibri Image Viewer'
1074
generate_header:
1570 dunkaist 1075
    push    eax
1076
    mov esi, [last_name_component]
1077
    mov edi, real_header
1427 diamond 1078
@@:
1570 dunkaist 1079
    lodsb
1080
    test    al, al
1081
    jz  @f
1082
    stosb
1083
    cmp edi, real_header+256
1084
    jb  @b
1427 diamond 1085
.overflow:
1570 dunkaist 1086
    mov dword [edi-4], '...'
1427 diamond 1087
.ret:
1570 dunkaist 1088
    pop eax
1089
    ret
1427 diamond 1090
@@:
1570 dunkaist 1091
    mov esi, s_header
1427 diamond 1092
@@:
1570 dunkaist 1093
    lodsb
1094
    stosb
1095
    test    al, al
1096
    jz  .ret
1097
    cmp edi, real_header+256
1098
    jb  @b
1099
    jmp .overflow
1004 diamond 1100
;-----------------------------------------------------------------------------
1101
 
1427 diamond 1102
s_header db ' - Kolibri Image Viewer', 0
3116 dunkaist 1103
wnd_style        dd 0x73FFFFFF
1104
wnd_x            dd 100
1105
wnd_y            dd 100
1106
image_padding    dd 5
1107
toolbar_height   dd 31
1108
bg_color         dd 0x00ffffff
1004 diamond 1109
 
1110
;-----------------------------------------------------------------------------
1111
;-----------------------------------------------------------------------------
1112
 
1113
align 4
1114
@IMPORT:
1115
 
1570 dunkaist 1116
library             \
1117
    libio  , 'libio.obj'  , \
1118
    libgfx , 'libgfx.obj' , \
1119
    libimg , 'libimg.obj' , \
1120
    libini , 'libini.obj' , \
1121
    sort   , 'sort.obj'   , \
1122
    proc_lib ,'proc_lib.obj'
1004 diamond 1123
 
1511 mario79 1124
 
1570 dunkaist 1125
import  libio             , \
1126
    libio.init , 'lib_init'   , \
1127
    file.size  , 'file_size'  , \
1128
    file.open  , 'file_open'  , \
1129
    file.read  , 'file_read'  , \
1130
    file.close , 'file_close'
1004 diamond 1131
 
1570 dunkaist 1132
import  libgfx              , \
1133
    libgfx.init   , 'lib_init'  , \
1134
    gfx.open      , 'gfx_open'  , \
1135
    gfx.close     , 'gfx_close' , \
1136
    gfx.pen.color , 'gfx_pen_color' , \
1137
    gfx.line      , 'gfx_line'
1004 diamond 1138
 
1570 dunkaist 1139
import  libimg             , \
1140
    libimg.init , 'lib_init'   , \
1141
    img.is_img  , 'img_is_img' , \
1142
    img.to_rgb2 , 'img_to_rgb2', \
1143
    img.decode  , 'img_decode' , \
1144
    img.flip    , 'img_flip'   , \
1145
    img.rotate  , 'img_rotate' , \
1146
    img.destroy , 'img_destroy', \
1147
    img.draw    , 'img_draw'
1004 diamond 1148
 
1570 dunkaist 1149
import  libini, \
1150
    ini_get_shortcut, 'ini_get_shortcut'
1427 diamond 1151
 
1144 diamond 1152
import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
1016 diamond 1153
 
1570 dunkaist 1154
import  proc_lib, \
1155
    OpenDialog_Init, 'OpenDialog_init', \
1156
    OpenDialog_Start,'OpenDialog_start'
1511 mario79 1157
 
1570 dunkaist 1158
bFirstDraw  db  0
3116 dunkaist 1159
bSlideShow  db  0
1160
bTglbar     db  0
1004 diamond 1161
;-----------------------------------------------------------------------------
1162
 
1016 diamond 1163
virtual at 0
1164
file 'kivicons.bmp':0xA,4
1165
load offbits dword from 0
1166
end virtual
3116 dunkaist 1167
numimages = 10
1016 diamond 1168
openbtn = 0
1169
backbtn = 1
1170
forwardbtn = 2
1171
bgrbtn = 3
1172
fliphorzbtn = 4
1173
flipvertbtn = 5
1174
rotcwbtn = 6
1175
rotccwbtn = 7
1176
rot180btn = 8
3116 dunkaist 1177
slidebtn = 9
1016 diamond 1178
 
1004 diamond 1179
palette:
1570 dunkaist 1180
    file 'kivicons.bmp':0x36,offbits-0x36
1016 diamond 1181
buttons:
1570 dunkaist 1182
    file 'kivicons.bmp':offbits
1004 diamond 1183
repeat 10
1184
y = % - 1
1185
z = 20 - %
1016 diamond 1186
repeat numimages*5
1187
load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
1188
load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
1189
store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
1190
store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
1004 diamond 1191
end repeat
1192
end repeat
1193
 
1570 dunkaist 1194
inifilename db  '/sys/media/kiv.ini',0
1195
aShortcuts  db  'Shortcuts',0
1196
aNext       db  'Next',0
1197
aPrev       db  'Prev',0
3116 dunkaist 1198
aSlide      db  'SlideShow',0
1199
aTglbar     db  'ToggleBar',0
1427 diamond 1200
 
1201
align 4
1202
check_modifier_table:
1570 dunkaist 1203
    dd  check_modifier_0
1204
    dd  check_modifier_1
1205
    dd  check_modifier_2
1206
    dd  check_modifier_3
1207
    dd  check_modifier_4
1427 diamond 1208
 
1470 mario79 1209
;---------------------------------------------------------------------
1210
align 4
1211
OpenDialog_data:
1570 dunkaist 1212
.type           dd 0
1213
.procinfo       dd procinfo ;+4
1214
.com_area_name      dd communication_area_name ;+8
1215
.com_area       dd 0 ;+12
1216
.opendir_pach       dd temp_dir_pach ;+16
1217
.dir_default_pach   dd communication_area_default_pach ;+20
1218
.start_path     dd open_dialog_path ;+24
1219
.draw_window        dd draw_window ;+28
1220
.status         dd 0 ;+32
1221
.openfile_pach      dd path  ;openfile_pach ;+36
1222
.filename_area      dd 0    ;+40
1223
.filter_area        dd Filter
1582 mario79 1224
.x:
1225
.x_size			dw 420 ;+48 ; Window X size
1226
.x_start		dw 10 ;+50 ; Window X position
1227
.y:
1228
.y_size			dw 320 ;+52 ; Window y size
1229
.y_start		dw 10 ;+54 ; Window Y position
1004 diamond 1230
 
1470 mario79 1231
communication_area_name:
1570 dunkaist 1232
    db 'FFFFFFFF_open_dialog',0
1701 lrz 1233
 
1470 mario79 1234
open_dialog_path:
1701 lrz 1235
if __nightbuild eq yes
1236
    db '/sys/MANAGERS/opendial',0
1237
else
1570 dunkaist 1238
    db '/sys/File Managers/opendial',0
1701 lrz 1239
end if
1470 mario79 1240
communication_area_default_pach:
1570 dunkaist 1241
    db '/rd/1',0
1004 diamond 1242
 
1470 mario79 1243
Filter:
1244
dd Filter.end - Filter
1245
.1:
1246
db 'BMP',0
1247
db 'GIF',0
1248
db 'JPG',0
1249
db 'JPEG',0
1250
db 'JPE',0
1251
db 'PNG',0
1252
db 'ICO',0
1253
db 'CUR',0
3116 dunkaist 1254
db 'TGA',0
1570 dunkaist 1255
db 'PCX',0
1922 dunkaist 1256
db 'XCF',0
2389 dunkaist 1257
db 'PBM',0
1258
db 'PGM',0
1259
db 'PNM',0
1260
db 'TIF',0
1261
db 'TIFF',0
2394 dunkaist 1262
db 'WBMP',0
1470 mario79 1263
.end:
1264
db 0
1004 diamond 1265
 
1470 mario79 1266
draw_window_fake:
1570 dunkaist 1267
    ret
1470 mario79 1268
;------------------------------------------------------------------------------
1016 diamond 1269
readdir_fileinfo:
1570 dunkaist 1270
    dd  1
1271
    dd  0
1272
    dd  0
1273
readblocks dd   0
1274
directory_ptr   dd  0
1470 mario79 1275
;------------------------------------------------------------------------------
1004 diamond 1276
I_END:
1570 dunkaist 1277
curdir      rb  1024
1016 diamond 1278
 
1279
align 4
1004 diamond 1280
img_data     dd ?
1281
img_data_len dd ?
1570 dunkaist 1282
fh       dd ?
1283
image        dd ?
3116 dunkaist 1284
wnd_width   dd  100
1285
wnd_height  dd  100
1286
draw_x      dd  ?
1287
draw_y      dd  ?
1570 dunkaist 1288
draw_width  dd  ?
1289
draw_height dd  ?
1290
last_name_component dd  ?
1291
cur_file_idx    dd  ?
1292
cur_frame_time  dd  ?
1293
cur_frame   dd  ?
1004 diamond 1294
 
1570 dunkaist 1295
next_mod    dd  ?
1296
next_key    dd  ?
1297
prev_mod    dd  ?
1298
prev_key    dd  ?
3116 dunkaist 1299
slide_mod   dd  ?
1300
slide_key   dd  ?
1301
tglbar_mod  dd  ?
1302
tglbar_key  dd  ?
1004 diamond 1303
 
3116 dunkaist 1304
toolbar_height_old   rd 1
1305
 
1306
procinfo    process_information
1570 dunkaist 1307
path:       rb  4096  ;1024+16
1308
real_header rb  256
1470 mario79 1309
@PARAMS rb 4096  ;512
1310
;---------------------------------------------------------------------
1311
temp_dir_pach:
1312
        rb 4096
1313
;---------------------------------------------------------------------
1570 dunkaist 1314
    rb 4096
1470 mario79 1315
stacktop:
1316
;---------------------------------------------------------------------
1922 dunkaist 1317
F_END: