Subversion Repositories Kolibri OS

Rev

Rev 2036 | Rev 2394 | 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]
2036 dunkaist 341
    test    [eax + Image.Flags], Image.IsAnimated
342
    jnz .not_in_row
343
    push eax
344
@@: cmp [eax + Image.Next], 0
345
    jz  @f
346
    mov eax, [eax + Image.Next]
347
    add edx, [eax + Image.Width]
348
    inc edx
349
    jmp @b
350
@@: pop eax
351
.not_in_row:
1570 dunkaist 352
    mov [draw_width], edx
353
    add edx, 19
354
    cmp edx, 40 + 25*9
355
    jae @f
356
    mov edx, 40 + 25*9
1004 diamond 357
@@:
1570 dunkaist 358
    mov [wnd_width], edx
359
    mov esi, [eax + Image.Height]
2036 dunkaist 360
    test    [eax + Image.Flags], Image.IsAnimated
361
    jnz .max_equals_first
362
    push eax
363
@@: cmp [eax + Image.Next], 0
364
    jz  @f
365
    mov eax, [eax + Image.Next]
366
    cmp esi, [eax + Image.Height]
367
    jae @b
368
    mov esi, [eax + Image.Height]
369
    jmp @b
370
@@: pop eax
371
.max_equals_first:
1570 dunkaist 372
    mov [draw_height], esi
373
    add esi, 44
374
    mov [wnd_height], esi
375
    popf
376
    jz  .no_resize
377
    mcall   48, 4
378
    add esi, eax
379
    mcall   67,-1,-1
1004 diamond 380
.no_resize:
1570 dunkaist 381
    ret
1004 diamond 382
 
1016 diamond 383
set_as_bgr:
1570 dunkaist 384
    mov esi, [image]
385
    mov ecx, [esi + Image.Width]
386
    mov edx, [esi + Image.Height]
387
    mcall   15, 1
1016 diamond 388
 
1570 dunkaist 389
    mcall   15, 6
390
    test    eax, eax
391
    jz  @f
1016 diamond 392
 
1570 dunkaist 393
    push    eax
394
    invoke  img.to_rgb2, esi, eax
395
    pop ecx
396
    mcall   15, 7
1016 diamond 397
 
398
@@:
1570 dunkaist 399
    mcall   15, 3
400
    ret
1016 diamond 401
 
1427 diamond 402
; seek to ESI image files
403
; esi>0 means next file, esi<0 - prev file
404
next_or_prev_image:
1570 dunkaist 405
    push    esi
406
    call    load_directory
407
    pop esi
408
    mov ebx, [directory_ptr]
409
    test    ebx, ebx
410
    jz  .ret
411
    cmp dword[ebx+4], 0
412
    jz  .ret
413
    mov eax, [cur_file_idx]
414
    cmp eax, -1
415
    jnz @f
416
    test    esi, esi
417
    jns @f
418
    mov eax, [ebx+4]
1016 diamond 419
@@:
1570 dunkaist 420
    push    [image]
421
    add eax, esi
1427 diamond 422
@@:
1570 dunkaist 423
    test    eax, eax
424
    jns @f
425
    add eax, [ebx+4]
426
    jmp @b
1016 diamond 427
@@:
1570 dunkaist 428
    cmp eax, [ebx+4]
429
    jb  @f
430
    sub eax, [ebx+4]
431
    jmp @b
1427 diamond 432
@@:
1570 dunkaist 433
    push    eax
1427 diamond 434
.scanloop:
1570 dunkaist 435
    push    eax ebx esi
436
    imul    esi, eax, 304
437
    add esi, [directory_ptr]
438
    add esi, 32 + 40
439
    mov edi, curdir
1016 diamond 440
@@:
1570 dunkaist 441
    inc edi
442
    cmp byte [edi-1], 0
443
    jnz @b
444
    mov byte [edi-1], '/'
1016 diamond 445
@@:
1570 dunkaist 446
    lodsb
447
    stosb
448
    test    al, al
449
    jnz @b
450
    mov eax, curdir
451
    call    load_image
452
    pushf
453
    mov esi, curdir
454
    push    esi
455
    mov edi, @PARAMS
456
    mov ecx, 4096/4
457
    rep movsd
458
    mov byte [edi-1], 0
459
    pop esi
1040 diamond 460
@@:
1570 dunkaist 461
    lodsb
462
    test    al, al
463
    jnz @b
1040 diamond 464
@@:
1570 dunkaist 465
    dec esi
466
    cmp byte [esi], '/'
467
    jnz @b
468
    mov byte [esi], 0
469
    popf
470
    pop esi ebx eax
471
    jnc .loadedok
472
    test    esi, esi
473
    js  .try_prev
1427 diamond 474
.try_next:
1570 dunkaist 475
    inc eax
476
    cmp eax, [ebx+4]
477
    jb  @f
478
    xor eax, eax
1016 diamond 479
@@:
1427 diamond 480
.try_common:
1570 dunkaist 481
    cmp eax, [esp]
482
    jz  .notfound
483
    jmp .scanloop
1427 diamond 484
.try_prev:
1570 dunkaist 485
    dec eax
486
    jns @f
487
    mov eax, [ebx+4]
488
    dec eax
1016 diamond 489
@@:
1570 dunkaist 490
    jmp .try_common
1427 diamond 491
.loadedok:
1570 dunkaist 492
    mov [cur_file_idx], eax
493
    pop eax
494
    invoke  img.destroy
495
    call    generate_header
1016 diamond 496
.ret:
1570 dunkaist 497
    ret
1016 diamond 498
.notfound:
1570 dunkaist 499
    pop eax
500
    pop [image]
501
    call    init_frame
502
    ret
1016 diamond 503
 
504
load_directory:
1570 dunkaist 505
    cmp [directory_ptr], 0
506
    jnz .ret
507
    mov esi, @PARAMS
508
    mov edi, curdir
509
    mov ecx, [last_name_component]
510
    sub ecx, esi
511
    dec ecx
512
    js  @f
513
    rep movsb
1427 diamond 514
@@:
1570 dunkaist 515
    mov byte [edi], 0
516
    mcall   68, 12, 0x1000
517
    test    eax, eax
518
    jz  .ret
519
    mov ebx, readdir_fileinfo
520
    mov dword [ebx+12], (0x1000 - 32) / 304
521
    mov dword [ebx+16], eax
522
    mcall   70
523
    cmp eax, 6
524
    jz  .dirok
525
    test    eax, eax
526
    jnz free_directory
527
    mov edx, [directory_ptr]
528
    mov ecx, [edx+8]
529
    mov [readblocks], ecx
530
    imul    ecx, 304
531
    add ecx, 32
532
    mcall   68, 20
533
    test    eax, eax
534
    jz  free_directory
535
    mov [directory_ptr], eax
536
    mcall   70, readdir_fileinfo
1016 diamond 537
.dirok:
1570 dunkaist 538
    cmp ebx, 0
539
    jle free_directory
540
    mov eax, [directory_ptr]
541
    add eax, 32
542
    mov edi, eax
543
    push    0
1016 diamond 544
.dirskip:
1570 dunkaist 545
    push    eax
546
    test    byte [eax], 18h
547
    jnz .nocopy
548
    lea esi, [eax+40]
549
    mov ecx, esi
1016 diamond 550
@@:
1570 dunkaist 551
    lodsb
552
    test    al, al
553
    jnz @b
1016 diamond 554
@@:
1570 dunkaist 555
    dec esi
556
    cmp esi, ecx
557
    jb  .noext
558
    cmp byte [esi], '.'
559
    jnz @b
560
    inc esi
561
    mov ecx, [esi]
562
    or  ecx, 0x202020
563
    cmp ecx, 'jpg'
564
    jz  .copy
565
    cmp ecx, 'bmp'
566
    jz  .copy
567
    cmp ecx, 'gif'
568
    jz  .copy
569
    cmp ecx, 'png'
570
    jz  .copy
571
    cmp ecx, 'jpe'
572
    jz  .copy
573
    cmp ecx, 'ico'
574
    jz  .copy
575
    cmp ecx, 'cur'
576
    jz  .copy
1575 dunkaist 577
; dunkaist [
578
    cmp ecx, 'pcx'
579
    jz  .copy
1922 dunkaist 580
    cmp ecx, 'xcf'
581
    jz  .copy
2389 dunkaist 582
    cmp ecx, 'pbm'
583
    jz  .copy
584
    cmp ecx, 'pgm'
585
    jz  .copy
586
    cmp ecx, 'pnm'
587
    jz  .copy
588
    cmp ecx, 'tif'
589
    jz  .copy
590
    cmp ecx, 'tiff'
591
    jz  @f
1575 dunkaist 592
; dunkaist ]
1570 dunkaist 593
    cmp ecx, 'jpeg'
594
    jz  @f
595
    cmp ecx, 'jpeG'
596
    jnz .nocopy
1016 diamond 597
@@:
1570 dunkaist 598
    cmp byte [esi+4], 0
599
    jnz .nocopy
1016 diamond 600
.copy:
1570 dunkaist 601
    mov esi, [esp]
602
    mov ecx, 304 / 4
603
    rep movsd
604
    inc dword [esp+4]
1016 diamond 605
.nocopy:
606
.noext:
1570 dunkaist 607
    pop eax
608
    add eax, 304
609
    dec ebx
610
    jnz .dirskip
611
    mov eax, [directory_ptr]
612
    pop ebx
613
    mov [eax+4], ebx
614
    test    ebx, ebx
615
    jz  free_directory
616
    push    0   ; sort mode
617
    push    ebx
618
    add eax, 32
619
    push    eax
620
    call    [SortDir]
621
    xor eax, eax
622
    mov edi, [directory_ptr]
623
    add edi, 32 + 40
1016 diamond 624
.scan:
1570 dunkaist 625
    mov esi, [last_name_component]
626
    push    edi
627
    invoke  strcmpi
628
    pop edi
629
    jz  .found
630
    inc eax
631
    add edi, 304
632
    dec ebx
633
    jnz .scan
634
    or  eax, -1
1016 diamond 635
.found:
1570 dunkaist 636
    mov [cur_file_idx], eax
1016 diamond 637
.ret:
1570 dunkaist 638
    ret
1016 diamond 639
 
640
free_directory:
1570 dunkaist 641
    mcall   68, 13, [directory_ptr]
642
    and [directory_ptr], 0
643
    ret
1016 diamond 644
 
1427 diamond 645
; in: esi->full name (e.g. /path/to/file.png)
646
; out: [last_name_component]->last component (e.g. file.png)
647
find_last_name_component:
1570 dunkaist 648
    mov ecx, esi
1427 diamond 649
@@:
1570 dunkaist 650
    lodsb
651
    test    al, al
652
    jnz @b
1427 diamond 653
@@:
1570 dunkaist 654
    dec esi
655
    cmp esi, ecx
656
    jb  @f
657
    cmp byte [esi], '/'
658
    jnz @b
1427 diamond 659
@@:
1570 dunkaist 660
    inc esi
661
    mov [last_name_component], esi
662
    ret
1427 diamond 663
 
1080 diamond 664
init_frame:
1570 dunkaist 665
    push    eax
666
    mov eax, [image]
667
    mov [cur_frame], eax
668
    test    byte [eax + Image.Flags], Image.IsAnimated
669
    jz  @f
670
    push    ebx
671
    mcall   26, 9
672
    pop ebx
673
    mov [cur_frame_time], eax
1080 diamond 674
@@:
1570 dunkaist 675
    pop eax
676
    ret
1080 diamond 677
 
1004 diamond 678
draw_window:
1570 dunkaist 679
    cmp [bFirstDraw], 0
680
    jz  .posok
681
    or  ecx, -1
682
    mcall   9, procinfo
1040 diamond 683
 
1570 dunkaist 684
    cmp dword [ebx + 66], 0
685
    jle .posok
1040 diamond 686
 
1570 dunkaist 687
    mov edx, ecx
688
    mov esi, ecx
689
    cmp dword [ebx + 42], 40 + 25 * 9
690
    jae @f
691
    mov edx, 40 + 25 * 9
1040 diamond 692
@@:
1570 dunkaist 693
    cmp dword [ebx + 46], 70
694
    jae @f
695
    mov esi, 70
1040 diamond 696
@@:
1570 dunkaist 697
    mov eax, edx
698
    and eax, esi
699
    cmp eax, -1
700
    jz  @f
701
    mov ebx, ecx
702
    mcall   67
1040 diamond 703
@@:
704
 
705
.posok:
1570 dunkaist 706
    mcall   12, 1
707
    mcall   48, 4
708
    mov ebp, eax    ; save skin height
709
    add eax, [wnd_height]
710
    __mov   ebx, 100, 0
711
    add ebx, [wnd_width]
712
    lea ecx, [100*65536 + eax]
713
    mcall   0, , , 0x73FFFFFF, 0, real_header
1004 diamond 714
 
1570 dunkaist 715
    mcall   9, procinfo, -1
716
    mov [bFirstDraw], 1
717
    cmp dword [ebx + 66], 0
718
    jle .nodraw
719
    mov ebx, [ebx + 62]
720
    inc ebx
721
    mcall   13, , <0, 35>, 0xFFFFFF
722
    mov ecx, [procinfo + 66]
723
    inc ecx
2036 dunkaist 724
;    mov esi, [draw_height]          ; we can not use [draw_height] here because for *.ico files containing several frames
725
    mov esi, [image]                 ; with different size window height should depend on maximum frame height, not the first one
726
    mov esi, [esi+Image.Height]      ;
1570 dunkaist 727
    add esi, 35
728
    sub ecx, esi
729
    jbe @f
730
    push    esi
731
    shl esi, 16
732
    add ecx, esi
733
    pop esi
734
    mcall
735
    xor ecx, ecx
1040 diamond 736
@@:
1570 dunkaist 737
    add ecx, esi
738
    add ecx, 35*10000h - 35
739
    __mov   ebx, 0, 5
740
    mcall
2036 dunkaist 741
;    mov esi, [draw_width]           ; we can not use [draw_width] here because for *.ico files containing several frames
742
    mov esi, [image]                 ; with different size window width should depend on the sum of width of all frames
743
    mov esi, [esi + Image.Width]     ;
1570 dunkaist 744
    add esi, ebx
745
    mov ebx, [procinfo+62]
746
    inc ebx
747
    sub ebx, esi
748
    jbe @f
749
    shl esi, 16
750
    add ebx, esi
751
    mcall
1040 diamond 752
@@:
1004 diamond 753
 
1570 dunkaist 754
    mov ebx, [procinfo + 62]
755
    push    ebx
756
    mcall   38, , <30, 30>, 0x007F7F7F
757
    mcall   , <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
758
    mcall   , <10 + 25 * 3, 10 + 25 * 3>
759
    mcall   , <15 + 25 * 4, 15 + 25 * 4>
760
    pop ebx
761
    sub ebx, 25 * 5 + 10
762
    push    ebx
763
    imul    ebx, 10001h
764
    mcall
1004 diamond 765
 
1570 dunkaist 766
    mcall   8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
767
    mcall   , <10 + 25 * 1, 20>, , 'bck'+40000000h
768
    mcall   , <10 + 25 * 2, 20>, , 'fwd'+40000000h
769
    mcall   , <15 + 25 * 3, 20>, , 'bgr'+40000000h
770
    pop ebx
771
    add ebx, 5
772
    shl ebx, 16
773
    mov bl, 20
774
    mcall   , , , 'flh'+40000000h
775
    add ebx, 25 * 65536
776
    mcall   , , , 'flv'+40000000h
777
    add ebx, 30 * 65536
778
    mcall   , , , 'rtr'+40000000h
779
    add ebx, 25 * 65536
780
    mcall   , , , 'rtl'+40000000h
781
    add ebx, 25 * 65536
782
    mcall   , , , 'flb'+40000000h
1004 diamond 783
 
1570 dunkaist 784
    mov ebp, (numimages-1)*20
1004 diamond 785
 
1570 dunkaist 786
    mcall   65, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
787
    mcall   , buttons+backbtn*20, , <10 + 25 * 1, 5>
788
    mcall   , buttons+forwardbtn*20, , <10 + 25 * 2, 5>
789
    mcall   , buttons+bgrbtn*20, , <15 + 25 * 3, 5>
790
    mov edx, [procinfo + 62]
791
    sub edx, 25 * 5 + 4
792
    shl edx, 16
793
    mov dl, 5
794
    mcall   , buttons+fliphorzbtn*20
795
    add edx, 25 * 65536
796
    mcall   , buttons+flipvertbtn*20
797
    add edx, 30 * 65536
798
    mcall   , buttons+rotcwbtn*20
799
    add edx, 25 * 65536
800
    mcall   , buttons+rotccwbtn*20
801
    add edx, 25 * 65536
802
    mcall   , buttons+rot180btn*20
1004 diamond 803
 
1570 dunkaist 804
    call    draw_cur_frame
1004 diamond 805
 
1087 diamond 806
.nodraw:
1570 dunkaist 807
    mcall   12, 2
1040 diamond 808
 
1570 dunkaist 809
    ret
1004 diamond 810
 
1080 diamond 811
draw_cur_frame:
1570 dunkaist 812
    push    0   ; ypos
813
    push    0   ; xpos
814
    mov eax, [procinfo+66]
815
    sub eax, 34
816
    push    eax ; max height
817
    mov eax, [procinfo+62]
818
    sub eax, 4
819
    push    eax ; max width
820
    push    35  ; y
821
    push    5   ; x
822
    push    [cur_frame]
823
    call    [img.draw]
824
    mov eax, [image]
825
    test    [eax + Image.Flags], Image.IsAnimated
826
    jnz .done
827
    cmp [eax + Image.Next], 0
828
    jnz .additional_frames
1102 diamond 829
.done:
1570 dunkaist 830
    ret
1102 diamond 831
.additional_frames:
1570 dunkaist 832
    mov ebx, [procinfo+62]
833
    sub ebx, 4
834
    jbe .done
835
    push    5
836
    pop esi
1102 diamond 837
.afloop:
1570 dunkaist 838
    sub ebx, [eax + Image.Width]
839
    jbe .done
840
    dec ebx
841
    jz  .done
842
    add esi, [eax + Image.Width]
843
    mov eax, [eax + Image.Next]
844
    push    eax
845
    inc esi
846
    push    0   ; ypos
847
    push    0   ; xpos
848
    mov ecx, [procinfo+66]
849
    sub ecx, 34
850
    push    ecx ; max height
851
    push    ebx ; max width
852
    push    35  ; y
853
    push    esi ; x
854
    push    eax ; image
855
    call    [img.draw]
856
    pop eax
857
    cmp [eax + Image.Next], 0
858
    jnz .afloop
859
    ret
1080 diamond 860
 
1004 diamond 861
; void* __stdcall mem.Alloc(unsigned size);
862
mem.Alloc:
1570 dunkaist 863
    push    ebx ecx
864
    mov ecx, [esp+12]
865
    mcall   68, 12
866
    pop ecx ebx
867
    ret 4
1004 diamond 868
 
869
; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
870
mem.ReAlloc:
1570 dunkaist 871
    push    ebx ecx edx
872
    mov edx, [esp+16]
873
    mov ecx, [esp+20]
874
    mcall   68, 20
875
    pop edx ecx ebx
876
    ret 8
1004 diamond 877
 
878
; void __stdcall mem.Free(void* mptr);
879
mem.Free:
1570 dunkaist 880
    push    ebx ecx
881
    mov ecx, [esp+12]
882
    mcall   68, 13
883
    pop ecx ebx
884
    ret 4
1004 diamond 885
 
1427 diamond 886
check_shortcut:
1570 dunkaist 887
; in:   cl = scancode (from sysfn 2),
888
;   eax = state of modifiers (from sysfn 66.3),
889
;   edx -> shortcut descriptor
890
; out:  ZF set <=> fail
891
    cmp cl, [edx+4]
892
    jnz .not
893
    push    eax
894
    mov esi, [edx]
895
    and esi, 0xF
896
    and al, 3
897
    call    dword [check_modifier_table+esi*4]
898
    test    al, al
899
    pop eax
900
    jnz .not
901
    push    eax
902
    mov esi, [edx]
903
    shr esi, 4
904
    and esi, 0xF
905
    shr al, 2
906
    and al, 3
907
    call    dword [check_modifier_table+esi*4]
908
    test    al, al
909
    pop eax
910
    jnz .not
911
    push    eax
912
    mov esi, [edx]
913
    shr esi, 8
914
    and esi, 0xF
915
    shr al, 4
916
    and al, 3
917
    call    dword [check_modifier_table+esi*4]
918
    test    al, al
919
    pop eax
920
;   jnz .not
1427 diamond 921
.not:
1570 dunkaist 922
    ret
1427 diamond 923
 
924
check_modifier_0:
1570 dunkaist 925
    setnz   al
926
    ret
1427 diamond 927
check_modifier_1:
1570 dunkaist 928
    setp    al
929
    ret
1427 diamond 930
check_modifier_2:
1570 dunkaist 931
    cmp al, 3
932
    setnz   al
933
    ret
1427 diamond 934
check_modifier_3:
1570 dunkaist 935
    cmp al, 1
936
    setnz   al
937
    ret
1427 diamond 938
check_modifier_4:
1570 dunkaist 939
    cmp al, 2
940
    setnz   al
941
    ret
1427 diamond 942
 
943
; fills real_header with window title
944
; window title is generated as ' - Kolibri Image Viewer'
945
generate_header:
1570 dunkaist 946
    push    eax
947
    mov esi, [last_name_component]
948
    mov edi, real_header
1427 diamond 949
@@:
1570 dunkaist 950
    lodsb
951
    test    al, al
952
    jz  @f
953
    stosb
954
    cmp edi, real_header+256
955
    jb  @b
1427 diamond 956
.overflow:
1570 dunkaist 957
    mov dword [edi-4], '...'
1427 diamond 958
.ret:
1570 dunkaist 959
    pop eax
960
    ret
1427 diamond 961
@@:
1570 dunkaist 962
    mov esi, s_header
1427 diamond 963
@@:
1570 dunkaist 964
    lodsb
965
    stosb
966
    test    al, al
967
    jz  .ret
968
    cmp edi, real_header+256
969
    jb  @b
970
    jmp .overflow
1004 diamond 971
;-----------------------------------------------------------------------------
972
 
1427 diamond 973
s_header db ' - Kolibri Image Viewer', 0
1004 diamond 974
 
975
;-----------------------------------------------------------------------------
976
;-----------------------------------------------------------------------------
977
 
978
align 4
979
@IMPORT:
980
 
1570 dunkaist 981
library             \
982
    libio  , 'libio.obj'  , \
983
    libgfx , 'libgfx.obj' , \
984
    libimg , 'libimg.obj' , \
985
    libini , 'libini.obj' , \
986
    sort   , 'sort.obj'   , \
987
    proc_lib ,'proc_lib.obj'
1004 diamond 988
 
1511 mario79 989
 
1570 dunkaist 990
import  libio             , \
991
    libio.init , 'lib_init'   , \
992
    file.size  , 'file_size'  , \
993
    file.open  , 'file_open'  , \
994
    file.read  , 'file_read'  , \
995
    file.close , 'file_close'
1004 diamond 996
 
1570 dunkaist 997
import  libgfx              , \
998
    libgfx.init   , 'lib_init'  , \
999
    gfx.open      , 'gfx_open'  , \
1000
    gfx.close     , 'gfx_close' , \
1001
    gfx.pen.color , 'gfx_pen_color' , \
1002
    gfx.line      , 'gfx_line'
1004 diamond 1003
 
1570 dunkaist 1004
import  libimg             , \
1005
    libimg.init , 'lib_init'   , \
1006
    img.is_img  , 'img_is_img' , \
1007
    img.to_rgb2 , 'img_to_rgb2', \
1008
    img.decode  , 'img_decode' , \
1009
    img.flip    , 'img_flip'   , \
1010
    img.rotate  , 'img_rotate' , \
1011
    img.destroy , 'img_destroy', \
1012
    img.draw    , 'img_draw'
1004 diamond 1013
 
1570 dunkaist 1014
import  libini, \
1015
    ini_get_shortcut, 'ini_get_shortcut'
1427 diamond 1016
 
1144 diamond 1017
import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
1016 diamond 1018
 
1570 dunkaist 1019
import  proc_lib, \
1020
    OpenDialog_Init, 'OpenDialog_init', \
1021
    OpenDialog_Start,'OpenDialog_start'
1511 mario79 1022
 
1570 dunkaist 1023
bFirstDraw  db  0
1004 diamond 1024
;-----------------------------------------------------------------------------
1025
 
1016 diamond 1026
virtual at 0
1027
file 'kivicons.bmp':0xA,4
1028
load offbits dword from 0
1029
end virtual
1030
numimages = 9
1031
openbtn = 0
1032
backbtn = 1
1033
forwardbtn = 2
1034
bgrbtn = 3
1035
fliphorzbtn = 4
1036
flipvertbtn = 5
1037
rotcwbtn = 6
1038
rotccwbtn = 7
1039
rot180btn = 8
1040
 
1004 diamond 1041
palette:
1570 dunkaist 1042
    file 'kivicons.bmp':0x36,offbits-0x36
1016 diamond 1043
buttons:
1570 dunkaist 1044
    file 'kivicons.bmp':offbits
1004 diamond 1045
repeat 10
1046
y = % - 1
1047
z = 20 - %
1016 diamond 1048
repeat numimages*5
1049
load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
1050
load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
1051
store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
1052
store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
1004 diamond 1053
end repeat
1054
end repeat
1055
 
1570 dunkaist 1056
inifilename db  '/sys/media/kiv.ini',0
1057
aShortcuts  db  'Shortcuts',0
1058
aNext       db  'Next',0
1059
aPrev       db  'Prev',0
1427 diamond 1060
 
1061
align 4
1062
check_modifier_table:
1570 dunkaist 1063
    dd  check_modifier_0
1064
    dd  check_modifier_1
1065
    dd  check_modifier_2
1066
    dd  check_modifier_3
1067
    dd  check_modifier_4
1427 diamond 1068
 
1470 mario79 1069
;---------------------------------------------------------------------
1070
align 4
1071
OpenDialog_data:
1570 dunkaist 1072
.type           dd 0
1073
.procinfo       dd procinfo ;+4
1074
.com_area_name      dd communication_area_name ;+8
1075
.com_area       dd 0 ;+12
1076
.opendir_pach       dd temp_dir_pach ;+16
1077
.dir_default_pach   dd communication_area_default_pach ;+20
1078
.start_path     dd open_dialog_path ;+24
1079
.draw_window        dd draw_window ;+28
1080
.status         dd 0 ;+32
1081
.openfile_pach      dd path  ;openfile_pach ;+36
1082
.filename_area      dd 0    ;+40
1083
.filter_area        dd Filter
1582 mario79 1084
.x:
1085
.x_size			dw 420 ;+48 ; Window X size
1086
.x_start		dw 10 ;+50 ; Window X position
1087
.y:
1088
.y_size			dw 320 ;+52 ; Window y size
1089
.y_start		dw 10 ;+54 ; Window Y position
1004 diamond 1090
 
1470 mario79 1091
communication_area_name:
1570 dunkaist 1092
    db 'FFFFFFFF_open_dialog',0
1701 lrz 1093
 
1470 mario79 1094
open_dialog_path:
1701 lrz 1095
if __nightbuild eq yes
1096
    db '/sys/MANAGERS/opendial',0
1097
else
1570 dunkaist 1098
    db '/sys/File Managers/opendial',0
1701 lrz 1099
end if
1470 mario79 1100
communication_area_default_pach:
1570 dunkaist 1101
    db '/rd/1',0
1004 diamond 1102
 
1470 mario79 1103
Filter:
1104
dd Filter.end - Filter
1105
.1:
1106
db 'BMP',0
1107
db 'GIF',0
1108
db 'JPG',0
1109
db 'JPEG',0
1110
db 'JPE',0
1111
db 'PNG',0
1112
db 'ICO',0
1113
db 'CUR',0
1575 dunkaist 1114
; dunkaist [
1570 dunkaist 1115
db 'PCX',0
1922 dunkaist 1116
db 'XCF',0
2389 dunkaist 1117
db 'PBM',0
1118
db 'PGM',0
1119
db 'PNM',0
1120
db 'TIF',0
1121
db 'TIFF',0
1575 dunkaist 1122
; dunkaist ]
1470 mario79 1123
.end:
1124
db 0
1004 diamond 1125
 
1470 mario79 1126
draw_window_fake:
1570 dunkaist 1127
    ret
1470 mario79 1128
;------------------------------------------------------------------------------
1016 diamond 1129
readdir_fileinfo:
1570 dunkaist 1130
    dd  1
1131
    dd  0
1132
    dd  0
1133
readblocks dd   0
1134
directory_ptr   dd  0
1470 mario79 1135
;------------------------------------------------------------------------------
1004 diamond 1136
I_END:
1570 dunkaist 1137
curdir      rb  1024
1016 diamond 1138
 
1139
align 4
1004 diamond 1140
img_data     dd ?
1141
img_data_len dd ?
1570 dunkaist 1142
fh       dd ?
1143
image        dd ?
1144
wnd_width   dd  ?
1145
wnd_height  dd  ?
1146
draw_width  dd  ?
1147
draw_height dd  ?
1148
last_name_component dd  ?
1149
cur_file_idx    dd  ?
1150
cur_frame_time  dd  ?
1151
cur_frame   dd  ?
1004 diamond 1152
 
1570 dunkaist 1153
next_mod    dd  ?
1154
next_key    dd  ?
1155
prev_mod    dd  ?
1156
prev_key    dd  ?
1004 diamond 1157
 
1570 dunkaist 1158
procinfo:   rb  1024
1159
path:       rb  4096  ;1024+16
1160
real_header rb  256
1470 mario79 1161
@PARAMS rb 4096  ;512
1162
;---------------------------------------------------------------------
1163
temp_dir_pach:
1164
        rb 4096
1165
;---------------------------------------------------------------------
1570 dunkaist 1166
    rb 4096
1470 mario79 1167
stacktop:
1168
;---------------------------------------------------------------------
1922 dunkaist 1169
F_END: