Subversion Repositories Kolibri OS

Rev

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