Subversion Repositories Kolibri OS

Rev

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