Subversion Repositories Kolibri OS

Rev

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