Subversion Repositories Kolibri OS

Rev

Rev 1575 | Rev 1594 | 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
1575 dunkaist 546
; dunkaist [
547
    cmp ecx, 'pcx'
548
    jz  .copy
549
; dunkaist ]
1570 dunkaist 550
    cmp ecx, 'jpeg'
551
    jz  @f
552
    cmp ecx, 'jpeG'
553
    jnz .nocopy
1016 diamond 554
@@:
1570 dunkaist 555
    cmp byte [esi+4], 0
556
    jnz .nocopy
1016 diamond 557
.copy:
1570 dunkaist 558
    mov esi, [esp]
559
    mov ecx, 304 / 4
560
    rep movsd
561
    inc dword [esp+4]
1016 diamond 562
.nocopy:
563
.noext:
1570 dunkaist 564
    pop eax
565
    add eax, 304
566
    dec ebx
567
    jnz .dirskip
568
    mov eax, [directory_ptr]
569
    pop ebx
570
    mov [eax+4], ebx
571
    test    ebx, ebx
572
    jz  free_directory
573
    push    0   ; sort mode
574
    push    ebx
575
    add eax, 32
576
    push    eax
577
    call    [SortDir]
578
    xor eax, eax
579
    mov edi, [directory_ptr]
580
    add edi, 32 + 40
1016 diamond 581
.scan:
1570 dunkaist 582
    mov esi, [last_name_component]
583
    push    edi
584
    invoke  strcmpi
585
    pop edi
586
    jz  .found
587
    inc eax
588
    add edi, 304
589
    dec ebx
590
    jnz .scan
591
    or  eax, -1
1016 diamond 592
.found:
1570 dunkaist 593
    mov [cur_file_idx], eax
1016 diamond 594
.ret:
1570 dunkaist 595
    ret
1016 diamond 596
 
597
free_directory:
1570 dunkaist 598
    mcall   68, 13, [directory_ptr]
599
    and [directory_ptr], 0
600
    ret
1016 diamond 601
 
1427 diamond 602
; in: esi->full name (e.g. /path/to/file.png)
603
; out: [last_name_component]->last component (e.g. file.png)
604
find_last_name_component:
1570 dunkaist 605
    mov ecx, esi
1427 diamond 606
@@:
1570 dunkaist 607
    lodsb
608
    test    al, al
609
    jnz @b
1427 diamond 610
@@:
1570 dunkaist 611
    dec esi
612
    cmp esi, ecx
613
    jb  @f
614
    cmp byte [esi], '/'
615
    jnz @b
1427 diamond 616
@@:
1570 dunkaist 617
    inc esi
618
    mov [last_name_component], esi
619
    ret
1427 diamond 620
 
1080 diamond 621
init_frame:
1570 dunkaist 622
    push    eax
623
    mov eax, [image]
624
    mov [cur_frame], eax
625
    test    byte [eax + Image.Flags], Image.IsAnimated
626
    jz  @f
627
    push    ebx
628
    mcall   26, 9
629
    pop ebx
630
    mov [cur_frame_time], eax
1080 diamond 631
@@:
1570 dunkaist 632
    pop eax
633
    ret
1080 diamond 634
 
1004 diamond 635
draw_window:
1570 dunkaist 636
    cmp [bFirstDraw], 0
637
    jz  .posok
638
    or  ecx, -1
639
    mcall   9, procinfo
1040 diamond 640
 
1570 dunkaist 641
    cmp dword [ebx + 66], 0
642
    jle .posok
1040 diamond 643
 
1570 dunkaist 644
    mov edx, ecx
645
    mov esi, ecx
646
    cmp dword [ebx + 42], 40 + 25 * 9
647
    jae @f
648
    mov edx, 40 + 25 * 9
1040 diamond 649
@@:
1570 dunkaist 650
    cmp dword [ebx + 46], 70
651
    jae @f
652
    mov esi, 70
1040 diamond 653
@@:
1570 dunkaist 654
    mov eax, edx
655
    and eax, esi
656
    cmp eax, -1
657
    jz  @f
658
    mov ebx, ecx
659
    mcall   67
1040 diamond 660
@@:
661
 
662
.posok:
1570 dunkaist 663
    mcall   12, 1
664
    mcall   48, 4
665
    mov ebp, eax    ; save skin height
666
    add eax, [wnd_height]
667
    __mov   ebx, 100, 0
668
    add ebx, [wnd_width]
669
    lea ecx, [100*65536 + eax]
670
    mcall   0, , , 0x73FFFFFF, 0, real_header
1004 diamond 671
 
1570 dunkaist 672
    mcall   9, procinfo, -1
673
    mov [bFirstDraw], 1
674
    cmp dword [ebx + 66], 0
675
    jle .nodraw
676
    mov ebx, [ebx + 62]
677
    inc ebx
678
    mcall   13, , <0, 35>, 0xFFFFFF
679
    mov ecx, [procinfo + 66]
680
    inc ecx
681
    mov esi, [draw_height]
682
    add esi, 35
683
    sub ecx, esi
684
    jbe @f
685
    push    esi
686
    shl esi, 16
687
    add ecx, esi
688
    pop esi
689
    mcall
690
    xor ecx, ecx
1040 diamond 691
@@:
1570 dunkaist 692
    add ecx, esi
693
    add ecx, 35*10000h - 35
694
    __mov   ebx, 0, 5
695
    mcall
696
    mov esi, [draw_width]
697
    add esi, ebx
698
    mov ebx, [procinfo+62]
699
    inc ebx
700
    sub ebx, esi
701
    jbe @f
702
    shl esi, 16
703
    add ebx, esi
704
    mcall
1040 diamond 705
@@:
1004 diamond 706
 
1570 dunkaist 707
    mov ebx, [procinfo + 62]
708
    push    ebx
709
    mcall   38, , <30, 30>, 0x007F7F7F
710
    mcall   , <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
711
    mcall   , <10 + 25 * 3, 10 + 25 * 3>
712
    mcall   , <15 + 25 * 4, 15 + 25 * 4>
713
    pop ebx
714
    sub ebx, 25 * 5 + 10
715
    push    ebx
716
    imul    ebx, 10001h
717
    mcall
1004 diamond 718
 
1570 dunkaist 719
    mcall   8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
720
    mcall   , <10 + 25 * 1, 20>, , 'bck'+40000000h
721
    mcall   , <10 + 25 * 2, 20>, , 'fwd'+40000000h
722
    mcall   , <15 + 25 * 3, 20>, , 'bgr'+40000000h
723
    pop ebx
724
    add ebx, 5
725
    shl ebx, 16
726
    mov bl, 20
727
    mcall   , , , 'flh'+40000000h
728
    add ebx, 25 * 65536
729
    mcall   , , , 'flv'+40000000h
730
    add ebx, 30 * 65536
731
    mcall   , , , 'rtr'+40000000h
732
    add ebx, 25 * 65536
733
    mcall   , , , 'rtl'+40000000h
734
    add ebx, 25 * 65536
735
    mcall   , , , 'flb'+40000000h
1004 diamond 736
 
1570 dunkaist 737
    mov ebp, (numimages-1)*20
1004 diamond 738
 
1570 dunkaist 739
    mcall   65, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
740
    mcall   , buttons+backbtn*20, , <10 + 25 * 1, 5>
741
    mcall   , buttons+forwardbtn*20, , <10 + 25 * 2, 5>
742
    mcall   , buttons+bgrbtn*20, , <15 + 25 * 3, 5>
743
    mov edx, [procinfo + 62]
744
    sub edx, 25 * 5 + 4
745
    shl edx, 16
746
    mov dl, 5
747
    mcall   , buttons+fliphorzbtn*20
748
    add edx, 25 * 65536
749
    mcall   , buttons+flipvertbtn*20
750
    add edx, 30 * 65536
751
    mcall   , buttons+rotcwbtn*20
752
    add edx, 25 * 65536
753
    mcall   , buttons+rotccwbtn*20
754
    add edx, 25 * 65536
755
    mcall   , buttons+rot180btn*20
1004 diamond 756
 
1570 dunkaist 757
    call    draw_cur_frame
1004 diamond 758
 
1087 diamond 759
.nodraw:
1570 dunkaist 760
    mcall   12, 2
1040 diamond 761
 
1570 dunkaist 762
    ret
1004 diamond 763
 
1080 diamond 764
draw_cur_frame:
1570 dunkaist 765
    push    0   ; ypos
766
    push    0   ; xpos
767
    mov eax, [procinfo+66]
768
    sub eax, 34
769
    push    eax ; max height
770
    mov eax, [procinfo+62]
771
    sub eax, 4
772
    push    eax ; max width
773
    push    35  ; y
774
    push    5   ; x
775
    push    [cur_frame]
776
    call    [img.draw]
777
    mov eax, [image]
778
    test    [eax + Image.Flags], Image.IsAnimated
779
    jnz .done
780
    cmp [eax + Image.Next], 0
781
    jnz .additional_frames
1102 diamond 782
.done:
1570 dunkaist 783
    ret
1102 diamond 784
.additional_frames:
1570 dunkaist 785
    mov ebx, [procinfo+62]
786
    sub ebx, 4
787
    jbe .done
788
    push    5
789
    pop esi
1102 diamond 790
.afloop:
1570 dunkaist 791
    sub ebx, [eax + Image.Width]
792
    jbe .done
793
    dec ebx
794
    jz  .done
795
    add esi, [eax + Image.Width]
796
    mov eax, [eax + Image.Next]
797
    push    eax
798
    inc esi
799
    push    0   ; ypos
800
    push    0   ; xpos
801
    mov ecx, [procinfo+66]
802
    sub ecx, 34
803
    push    ecx ; max height
804
    push    ebx ; max width
805
    push    35  ; y
806
    push    esi ; x
807
    push    eax ; image
808
    call    [img.draw]
809
    pop eax
810
    cmp [eax + Image.Next], 0
811
    jnz .afloop
812
    ret
1080 diamond 813
 
1004 diamond 814
; void* __stdcall mem.Alloc(unsigned size);
815
mem.Alloc:
1570 dunkaist 816
    push    ebx ecx
817
    mov ecx, [esp+12]
818
    mcall   68, 12
819
    pop ecx ebx
820
    ret 4
1004 diamond 821
 
822
; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
823
mem.ReAlloc:
1570 dunkaist 824
    push    ebx ecx edx
825
    mov edx, [esp+16]
826
    mov ecx, [esp+20]
827
    mcall   68, 20
828
    pop edx ecx ebx
829
    ret 8
1004 diamond 830
 
831
; void __stdcall mem.Free(void* mptr);
832
mem.Free:
1570 dunkaist 833
    push    ebx ecx
834
    mov ecx, [esp+12]
835
    mcall   68, 13
836
    pop ecx ebx
837
    ret 4
1004 diamond 838
 
1427 diamond 839
check_shortcut:
1570 dunkaist 840
; in:   cl = scancode (from sysfn 2),
841
;   eax = state of modifiers (from sysfn 66.3),
842
;   edx -> shortcut descriptor
843
; out:  ZF set <=> fail
844
    cmp cl, [edx+4]
845
    jnz .not
846
    push    eax
847
    mov esi, [edx]
848
    and esi, 0xF
849
    and al, 3
850
    call    dword [check_modifier_table+esi*4]
851
    test    al, al
852
    pop eax
853
    jnz .not
854
    push    eax
855
    mov esi, [edx]
856
    shr esi, 4
857
    and esi, 0xF
858
    shr al, 2
859
    and al, 3
860
    call    dword [check_modifier_table+esi*4]
861
    test    al, al
862
    pop eax
863
    jnz .not
864
    push    eax
865
    mov esi, [edx]
866
    shr esi, 8
867
    and esi, 0xF
868
    shr al, 4
869
    and al, 3
870
    call    dword [check_modifier_table+esi*4]
871
    test    al, al
872
    pop eax
873
;   jnz .not
1427 diamond 874
.not:
1570 dunkaist 875
    ret
1427 diamond 876
 
877
check_modifier_0:
1570 dunkaist 878
    setnz   al
879
    ret
1427 diamond 880
check_modifier_1:
1570 dunkaist 881
    setp    al
882
    ret
1427 diamond 883
check_modifier_2:
1570 dunkaist 884
    cmp al, 3
885
    setnz   al
886
    ret
1427 diamond 887
check_modifier_3:
1570 dunkaist 888
    cmp al, 1
889
    setnz   al
890
    ret
1427 diamond 891
check_modifier_4:
1570 dunkaist 892
    cmp al, 2
893
    setnz   al
894
    ret
1427 diamond 895
 
896
; fills real_header with window title
897
; window title is generated as ' - Kolibri Image Viewer'
898
generate_header:
1570 dunkaist 899
    push    eax
900
    mov esi, [last_name_component]
901
    mov edi, real_header
1427 diamond 902
@@:
1570 dunkaist 903
    lodsb
904
    test    al, al
905
    jz  @f
906
    stosb
907
    cmp edi, real_header+256
908
    jb  @b
1427 diamond 909
.overflow:
1570 dunkaist 910
    mov dword [edi-4], '...'
1427 diamond 911
.ret:
1570 dunkaist 912
    pop eax
913
    ret
1427 diamond 914
@@:
1570 dunkaist 915
    mov esi, s_header
1427 diamond 916
@@:
1570 dunkaist 917
    lodsb
918
    stosb
919
    test    al, al
920
    jz  .ret
921
    cmp edi, real_header+256
922
    jb  @b
923
    jmp .overflow
1004 diamond 924
;-----------------------------------------------------------------------------
925
 
1427 diamond 926
s_header db ' - Kolibri Image Viewer', 0
1004 diamond 927
 
928
;-----------------------------------------------------------------------------
929
;-----------------------------------------------------------------------------
930
 
931
align 4
932
@IMPORT:
933
 
1570 dunkaist 934
library             \
935
    libio  , 'libio.obj'  , \
936
    libgfx , 'libgfx.obj' , \
937
    libimg , 'libimg.obj' , \
938
    libini , 'libini.obj' , \
939
    sort   , 'sort.obj'   , \
940
    proc_lib ,'proc_lib.obj'
1004 diamond 941
 
1511 mario79 942
 
1570 dunkaist 943
import  libio             , \
944
    libio.init , 'lib_init'   , \
945
    file.size  , 'file_size'  , \
946
    file.open  , 'file_open'  , \
947
    file.read  , 'file_read'  , \
948
    file.close , 'file_close'
1004 diamond 949
 
1570 dunkaist 950
import  libgfx              , \
951
    libgfx.init   , 'lib_init'  , \
952
    gfx.open      , 'gfx_open'  , \
953
    gfx.close     , 'gfx_close' , \
954
    gfx.pen.color , 'gfx_pen_color' , \
955
    gfx.line      , 'gfx_line'
1004 diamond 956
 
1570 dunkaist 957
import  libimg             , \
958
    libimg.init , 'lib_init'   , \
959
    img.is_img  , 'img_is_img' , \
960
    img.to_rgb2 , 'img_to_rgb2', \
961
    img.decode  , 'img_decode' , \
962
    img.flip    , 'img_flip'   , \
963
    img.rotate  , 'img_rotate' , \
964
    img.destroy , 'img_destroy', \
965
    img.draw    , 'img_draw'
1004 diamond 966
 
1570 dunkaist 967
import  libini, \
968
    ini_get_shortcut, 'ini_get_shortcut'
1427 diamond 969
 
1144 diamond 970
import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
1016 diamond 971
 
1570 dunkaist 972
import  proc_lib, \
973
    OpenDialog_Init, 'OpenDialog_init', \
974
    OpenDialog_Start,'OpenDialog_start'
1511 mario79 975
 
1570 dunkaist 976
bFirstDraw  db  0
1004 diamond 977
;-----------------------------------------------------------------------------
978
 
1016 diamond 979
virtual at 0
980
file 'kivicons.bmp':0xA,4
981
load offbits dword from 0
982
end virtual
983
numimages = 9
984
openbtn = 0
985
backbtn = 1
986
forwardbtn = 2
987
bgrbtn = 3
988
fliphorzbtn = 4
989
flipvertbtn = 5
990
rotcwbtn = 6
991
rotccwbtn = 7
992
rot180btn = 8
993
 
1004 diamond 994
palette:
1570 dunkaist 995
    file 'kivicons.bmp':0x36,offbits-0x36
1016 diamond 996
buttons:
1570 dunkaist 997
    file 'kivicons.bmp':offbits
1004 diamond 998
repeat 10
999
y = % - 1
1000
z = 20 - %
1016 diamond 1001
repeat numimages*5
1002
load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
1003
load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
1004
store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
1005
store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
1004 diamond 1006
end repeat
1007
end repeat
1008
 
1570 dunkaist 1009
inifilename db  '/sys/media/kiv.ini',0
1010
aShortcuts  db  'Shortcuts',0
1011
aNext       db  'Next',0
1012
aPrev       db  'Prev',0
1427 diamond 1013
 
1014
align 4
1015
check_modifier_table:
1570 dunkaist 1016
    dd  check_modifier_0
1017
    dd  check_modifier_1
1018
    dd  check_modifier_2
1019
    dd  check_modifier_3
1020
    dd  check_modifier_4
1427 diamond 1021
 
1470 mario79 1022
;---------------------------------------------------------------------
1023
align 4
1024
OpenDialog_data:
1570 dunkaist 1025
.type           dd 0
1026
.procinfo       dd procinfo ;+4
1027
.com_area_name      dd communication_area_name ;+8
1028
.com_area       dd 0 ;+12
1029
.opendir_pach       dd temp_dir_pach ;+16
1030
.dir_default_pach   dd communication_area_default_pach ;+20
1031
.start_path     dd open_dialog_path ;+24
1032
.draw_window        dd draw_window ;+28
1033
.status         dd 0 ;+32
1034
.openfile_pach      dd path  ;openfile_pach ;+36
1035
.filename_area      dd 0    ;+40
1036
.filter_area        dd Filter
1582 mario79 1037
.x:
1038
.x_size			dw 420 ;+48 ; Window X size
1039
.x_start		dw 10 ;+50 ; Window X position
1040
.y:
1041
.y_size			dw 320 ;+52 ; Window y size
1042
.y_start		dw 10 ;+54 ; Window Y position
1004 diamond 1043
 
1470 mario79 1044
communication_area_name:
1570 dunkaist 1045
    db 'FFFFFFFF_open_dialog',0
1470 mario79 1046
open_dialog_path:
1570 dunkaist 1047
    db '/sys/File Managers/opendial',0
1470 mario79 1048
communication_area_default_pach:
1570 dunkaist 1049
    db '/rd/1',0
1004 diamond 1050
 
1470 mario79 1051
Filter:
1052
dd Filter.end - Filter
1053
.1:
1054
db 'BMP',0
1055
db 'GIF',0
1056
db 'JPG',0
1057
db 'JPEG',0
1058
db 'JPE',0
1059
db 'PNG',0
1060
db 'ICO',0
1061
db 'CUR',0
1575 dunkaist 1062
; dunkaist [
1570 dunkaist 1063
db 'PCX',0
1575 dunkaist 1064
; dunkaist ]
1470 mario79 1065
.end:
1066
db 0
1004 diamond 1067
 
1470 mario79 1068
draw_window_fake:
1570 dunkaist 1069
    ret
1470 mario79 1070
;------------------------------------------------------------------------------
1016 diamond 1071
readdir_fileinfo:
1570 dunkaist 1072
    dd  1
1073
    dd  0
1074
    dd  0
1075
readblocks dd   0
1076
directory_ptr   dd  0
1470 mario79 1077
;------------------------------------------------------------------------------
1004 diamond 1078
I_END:
1570 dunkaist 1079
curdir      rb  1024
1016 diamond 1080
 
1081
align 4
1004 diamond 1082
img_data     dd ?
1083
img_data_len dd ?
1570 dunkaist 1084
fh       dd ?
1085
image        dd ?
1086
wnd_width   dd  ?
1087
wnd_height  dd  ?
1088
draw_width  dd  ?
1089
draw_height dd  ?
1090
last_name_component dd  ?
1091
cur_file_idx    dd  ?
1092
cur_frame_time  dd  ?
1093
cur_frame   dd  ?
1004 diamond 1094
 
1570 dunkaist 1095
next_mod    dd  ?
1096
next_key    dd  ?
1097
prev_mod    dd  ?
1098
prev_key    dd  ?
1004 diamond 1099
 
1570 dunkaist 1100
procinfo:   rb  1024
1101
path:       rb  4096  ;1024+16
1102
real_header rb  256
1470 mario79 1103
@PARAMS rb 4096  ;512
1104
;---------------------------------------------------------------------
1105
temp_dir_pach:
1106
        rb 4096
1107
;---------------------------------------------------------------------
1570 dunkaist 1108
    rb 4096
1470 mario79 1109
stacktop:
1110
;---------------------------------------------------------------------
1111
F_END: