Subversion Repositories Kolibri OS

Rev

Rev 1570 | Rev 1582 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. use32
  2. org 0x0
  3.  
  4. db 'MENUET01'
  5. dd 0x01, START, I_END, F_END, stacktop, @PARAMS, 0x0
  6.  
  7. ;-----------------------------------------------------------------------------
  8.  
  9. FALSE = 0
  10. TRUE  = 1
  11.  
  12. include '../../../proc32.inc'
  13. include '../../../macros.inc'
  14. include 'dll.inc'
  15.  
  16. include '../../../develop/libraries/libs-dev/libio/libio.inc'
  17. include '../../../develop/libraries/libs-dev/libimg/libimg.inc'
  18.  
  19. ;include '../../../develop/libraries/box_lib/asm/trunk/opendial.mac'
  20. ;use_OpenDialog
  21. ;-----------------------------------------------------------------------------
  22.  
  23. START:
  24.     mcall   68, 11
  25.  
  26.     stdcall dll.Load, @IMPORT
  27.     or  eax, eax
  28.     jnz exit
  29.  
  30.     invoke  sort.START, 1
  31.  
  32. ; OpenDialog initialisation
  33.     push    dword OpenDialog_data
  34.     call    [OpenDialog_Init]
  35.  
  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
  42.  
  43. ; initialize keyboard handling
  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
  49.  
  50.     cmp byte [@PARAMS], 0
  51.     jnz params_given
  52.  
  53.     mov [OpenDialog_data.draw_window],draw_window_fake
  54.    
  55. ; OpenDialog Open
  56.     push    dword OpenDialog_data
  57.     call    [OpenDialog_Start]
  58.  
  59.     cmp [OpenDialog_data.status],1
  60.     jne exit
  61.  
  62.     mov [OpenDialog_data.draw_window],draw_window
  63.  
  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
  70.  
  71. set_bgr:
  72.     mcall   15, 4
  73.     mov eax, @PARAMS + 4
  74.     call    load_image
  75.     jc  exit
  76.  
  77.     call    set_as_bgr
  78.     jmp exit
  79.  
  80. params_given:
  81.  
  82.     mov esi, @PARAMS
  83.     push    esi
  84.     call    find_last_name_component
  85.  
  86.     pop eax
  87.     call    load_image
  88.     jc  exit
  89.     call    generate_header
  90.  
  91. ;-----------------------------------------------------------------------------
  92.  
  93. red:
  94.     call    draw_window
  95.  
  96. still:
  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
  113.   @@:
  114.     mcall
  115.     dec eax
  116.     js  red_update_frame
  117.     jz  red
  118.     dec eax
  119.     jnz button
  120.  
  121. key:
  122.     xor esi, esi
  123. keyloop:
  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
  136. .prev:
  137.     dec esi
  138.     jmp keyloop
  139. .next:
  140.     inc esi
  141.     jmp keyloop
  142. keyloopdone:
  143.     test    esi, esi
  144.     jz  still
  145. next_or_prev_handler:
  146.     call    next_or_prev_image
  147.     jmp red
  148.  
  149. red_update_frame:
  150.     mov eax, [cur_frame]
  151.     mov eax, [eax + Image.Next]
  152.     test    eax, eax
  153.     jnz @f
  154.     mov eax, [image]
  155.   @@:
  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
  162.  
  163. button:
  164.     mcall   17
  165.     shr eax, 8
  166.  
  167.     ; flip horizontally
  168.     cmp eax, 'flh'
  169.     jne @f
  170.  
  171.     invoke  img.flip, [image], FLIP_HORIZONTAL
  172.     jmp redraw_image
  173.  
  174.     ; flip vertically
  175.     @@: cmp eax, 'flv'
  176.     jne @f
  177.  
  178.     invoke  img.flip, [image], FLIP_VERTICAL
  179.     jmp redraw_image
  180.  
  181.     ; flip both horizontally and vertically
  182.     @@: cmp eax, 'flb'
  183.     jne @f
  184.  
  185.     invoke  img.flip, [image], FLIP_BOTH
  186.     jmp redraw_image
  187.  
  188.     ; rotate left
  189.     @@: cmp eax, 'rtl'
  190.     jne @f
  191.  
  192.     push    ROTATE_90_CCW
  193. .rotate_common:
  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
  199.  
  200.     ; rotate right
  201.     @@: cmp eax, 'rtr'
  202.     jne @f
  203.  
  204.     push    ROTATE_90_CW
  205.     jmp .rotate_common
  206.  
  207.     ; open new file
  208.     @@: cmp eax, 'opn'
  209.     jne @f
  210.    
  211. ; OpenDialog Open
  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
  228.  
  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.    
  239.     .restore_old:
  240.     pop [image]
  241.     call    init_frame
  242.     jmp still
  243.  
  244.     ; set background
  245.     @@:
  246.     cmp eax, 'bgr'
  247.     jne @f
  248.  
  249.     call    set_as_bgr
  250.     jmp still
  251.  
  252.     @@:
  253.  
  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
  260.  
  261.     cmp eax, 1
  262.     jne still
  263.  
  264.   exit:
  265.     mcall   -1
  266.  
  267.   redraw_image = red
  268.  
  269. load_image:
  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
  290.  
  291. ; img.decode checks for img.is_img
  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
  307.  
  308. .error_free:
  309.     invoke  img.destroy, [image]
  310.     jmp .error
  311.  
  312. .error_pop:
  313.     pop eax
  314.     jmp .error
  315. .error_close:
  316.     invoke  file.close, [fh]
  317. .error:
  318.     call    free_img_data
  319.     stc
  320.     ret
  321.  
  322. free_img_data:
  323.     mov eax, [img_data]
  324.     test    eax, eax
  325.     jz  @f
  326.     stdcall mem.Free, eax
  327. @@:
  328.     ret
  329.  
  330. update_image_sizes:
  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
  338. @@:
  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
  349. .no_resize:
  350.     ret
  351.  
  352. set_as_bgr:
  353.     mov esi, [image]
  354.     mov ecx, [esi + Image.Width]
  355.     mov edx, [esi + Image.Height]
  356.     mcall   15, 1
  357.  
  358.     mcall   15, 6
  359.     test    eax, eax
  360.     jz  @f
  361.  
  362.     push    eax
  363.     invoke  img.to_rgb2, esi, eax
  364.     pop ecx
  365.     mcall   15, 7
  366.  
  367. @@:
  368.     mcall   15, 3
  369.     ret
  370.  
  371. ; seek to ESI image files
  372. ; esi>0 means next file, esi<0 - prev file
  373. next_or_prev_image:
  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]
  388. @@:
  389.     push    [image]
  390.     add eax, esi
  391. @@:
  392.     test    eax, eax
  393.     jns @f
  394.     add eax, [ebx+4]
  395.     jmp @b
  396. @@:
  397.     cmp eax, [ebx+4]
  398.     jb  @f
  399.     sub eax, [ebx+4]
  400.     jmp @b
  401. @@:
  402.     push    eax
  403. .scanloop:
  404.     push    eax ebx esi
  405.     imul    esi, eax, 304
  406.     add esi, [directory_ptr]
  407.     add esi, 32 + 40
  408.     mov edi, curdir
  409. @@:
  410.     inc edi
  411.     cmp byte [edi-1], 0
  412.     jnz @b
  413.     mov byte [edi-1], '/'
  414. @@:
  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
  429. @@:
  430.     lodsb
  431.     test    al, al
  432.     jnz @b
  433. @@:
  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
  443. .try_next:
  444.     inc eax
  445.     cmp eax, [ebx+4]
  446.     jb  @f
  447.     xor eax, eax
  448. @@:
  449. .try_common:
  450.     cmp eax, [esp]
  451.     jz  .notfound
  452.     jmp .scanloop
  453. .try_prev:
  454.     dec eax
  455.     jns @f
  456.     mov eax, [ebx+4]
  457.     dec eax
  458. @@:
  459.     jmp .try_common
  460. .loadedok:
  461.     mov [cur_file_idx], eax
  462.     pop eax
  463.     invoke  img.destroy
  464.     call    generate_header
  465. .ret:
  466.     ret
  467. .notfound:
  468.     pop eax
  469.     pop [image]
  470.     call    init_frame
  471.     ret
  472.  
  473. load_directory:
  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
  483. @@:
  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
  506. .dirok:
  507.     cmp ebx, 0
  508.     jle free_directory
  509.     mov eax, [directory_ptr]
  510.     add eax, 32
  511.     mov edi, eax
  512.     push    0
  513. .dirskip:
  514.     push    eax
  515.     test    byte [eax], 18h
  516.     jnz .nocopy
  517.     lea esi, [eax+40]
  518.     mov ecx, esi
  519. @@:
  520.     lodsb
  521.     test    al, al
  522.     jnz @b
  523. @@:
  524.     dec esi
  525.     cmp esi, ecx
  526.     jb  .noext
  527.     cmp byte [esi], '.'
  528.     jnz @b
  529.     inc esi
  530.     mov ecx, [esi]
  531.     or  ecx, 0x202020
  532.     cmp ecx, 'jpg'
  533.     jz  .copy
  534.     cmp ecx, 'bmp'
  535.     jz  .copy
  536.     cmp ecx, 'gif'
  537.     jz  .copy
  538.     cmp ecx, 'png'
  539.     jz  .copy
  540.     cmp ecx, 'jpe'
  541.     jz  .copy
  542.     cmp ecx, 'ico'
  543.     jz  .copy
  544.     cmp ecx, 'cur'
  545.     jz  .copy
  546. ; dunkaist [
  547.     cmp ecx, 'pcx'
  548.     jz  .copy
  549. ; dunkaist ]
  550.     cmp ecx, 'jpeg'
  551.     jz  @f
  552.     cmp ecx, 'jpeG'
  553.     jnz .nocopy
  554. @@:
  555.     cmp byte [esi+4], 0
  556.     jnz .nocopy
  557. .copy:
  558.     mov esi, [esp]
  559.     mov ecx, 304 / 4
  560.     rep movsd
  561.     inc dword [esp+4]
  562. .nocopy:
  563. .noext:
  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
  581. .scan:
  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
  592. .found:
  593.     mov [cur_file_idx], eax
  594. .ret:
  595.     ret
  596.  
  597. free_directory:
  598.     mcall   68, 13, [directory_ptr]
  599.     and [directory_ptr], 0
  600.     ret
  601.  
  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:
  605.     mov ecx, esi
  606. @@:
  607.     lodsb
  608.     test    al, al
  609.     jnz @b
  610. @@:
  611.     dec esi
  612.     cmp esi, ecx
  613.     jb  @f
  614.     cmp byte [esi], '/'
  615.     jnz @b
  616. @@:
  617.     inc esi
  618.     mov [last_name_component], esi
  619.     ret
  620.  
  621. init_frame:
  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
  631. @@:
  632.     pop eax
  633.     ret
  634.  
  635. draw_window:
  636.     cmp [bFirstDraw], 0
  637.     jz  .posok
  638.     or  ecx, -1
  639.     mcall   9, procinfo
  640.  
  641.     cmp dword [ebx + 66], 0
  642.     jle .posok
  643.  
  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
  649. @@:
  650.     cmp dword [ebx + 46], 70
  651.     jae @f
  652.     mov esi, 70
  653. @@:
  654.     mov eax, edx
  655.     and eax, esi
  656.     cmp eax, -1
  657.     jz  @f
  658.     mov ebx, ecx
  659.     mcall   67
  660. @@:
  661.  
  662. .posok:
  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
  671.  
  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
  691. @@:
  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
  705. @@:
  706.  
  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
  718.  
  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
  736.  
  737.     mov ebp, (numimages-1)*20
  738.  
  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
  756.  
  757.     call    draw_cur_frame
  758.  
  759. .nodraw:
  760.     mcall   12, 2
  761.  
  762.     ret
  763.  
  764. draw_cur_frame:
  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
  782. .done:
  783.     ret
  784. .additional_frames:
  785.     mov ebx, [procinfo+62]
  786.     sub ebx, 4
  787.     jbe .done
  788.     push    5
  789.     pop esi
  790. .afloop:
  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
  813.  
  814. ; void* __stdcall mem.Alloc(unsigned size);
  815. mem.Alloc:
  816.     push    ebx ecx
  817.     mov ecx, [esp+12]
  818.     mcall   68, 12
  819.     pop ecx ebx
  820.     ret 4
  821.  
  822. ; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
  823. mem.ReAlloc:
  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
  830.  
  831. ; void __stdcall mem.Free(void* mptr);
  832. mem.Free:
  833.     push    ebx ecx
  834.     mov ecx, [esp+12]
  835.     mcall   68, 13
  836.     pop ecx ebx
  837.     ret 4
  838.  
  839. check_shortcut:
  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
  874. .not:
  875.     ret
  876.  
  877. check_modifier_0:
  878.     setnz   al
  879.     ret
  880. check_modifier_1:
  881.     setp    al
  882.     ret
  883. check_modifier_2:
  884.     cmp al, 3
  885.     setnz   al
  886.     ret
  887. check_modifier_3:
  888.     cmp al, 1
  889.     setnz   al
  890.     ret
  891. check_modifier_4:
  892.     cmp al, 2
  893.     setnz   al
  894.     ret
  895.  
  896. ; fills real_header with window title
  897. ; window title is generated as '<filename> - Kolibri Image Viewer'
  898. generate_header:
  899.     push    eax
  900.     mov esi, [last_name_component]
  901.     mov edi, real_header
  902. @@:
  903.     lodsb
  904.     test    al, al
  905.     jz  @f
  906.     stosb
  907.     cmp edi, real_header+256
  908.     jb  @b
  909. .overflow:
  910.     mov dword [edi-4], '...'
  911. .ret:
  912.     pop eax
  913.     ret
  914. @@:
  915.     mov esi, s_header
  916. @@:
  917.     lodsb
  918.     stosb
  919.     test    al, al
  920.     jz  .ret
  921.     cmp edi, real_header+256
  922.     jb  @b
  923.     jmp .overflow
  924. ;-----------------------------------------------------------------------------
  925.  
  926. s_header db ' - Kolibri Image Viewer', 0
  927.  
  928. ;-----------------------------------------------------------------------------
  929. ;-----------------------------------------------------------------------------
  930.  
  931. align 4
  932. @IMPORT:
  933.  
  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'
  941.  
  942.  
  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'
  949.  
  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'
  956.  
  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'
  966.  
  967. import  libini, \
  968.     ini_get_shortcut, 'ini_get_shortcut'
  969.  
  970. import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
  971.  
  972. import  proc_lib, \
  973.     OpenDialog_Init, 'OpenDialog_init', \
  974.     OpenDialog_Start,'OpenDialog_start'
  975.  
  976. bFirstDraw  db  0
  977. ;-----------------------------------------------------------------------------
  978.  
  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.  
  994. palette:
  995.     file 'kivicons.bmp':0x36,offbits-0x36
  996. buttons:
  997.     file 'kivicons.bmp':offbits
  998. repeat 10
  999. y = % - 1
  1000. z = 20 - %
  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
  1006. end repeat
  1007. end repeat
  1008.  
  1009. inifilename db  '/sys/media/kiv.ini',0
  1010. aShortcuts  db  'Shortcuts',0
  1011. aNext       db  'Next',0
  1012. aPrev       db  'Prev',0
  1013.  
  1014. align 4
  1015. check_modifier_table:
  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
  1021.  
  1022. ;---------------------------------------------------------------------
  1023. align 4
  1024. OpenDialog_data:
  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
  1037.  
  1038. communication_area_name:
  1039.     db 'FFFFFFFF_open_dialog',0
  1040. open_dialog_path:
  1041.     db '/sys/File Managers/opendial',0
  1042. communication_area_default_pach:
  1043.     db '/rd/1',0
  1044.  
  1045. Filter:
  1046. dd Filter.end - Filter
  1047. .1:
  1048. db 'BMP',0
  1049. db 'GIF',0
  1050. db 'JPG',0
  1051. db 'JPEG',0
  1052. db 'JPE',0
  1053. db 'PNG',0
  1054. db 'ICO',0
  1055. db 'CUR',0
  1056. ; dunkaist [
  1057. db 'PCX',0
  1058. ; dunkaist ]
  1059. .end:
  1060. db 0
  1061.  
  1062. draw_window_fake:
  1063.     ret
  1064. ;------------------------------------------------------------------------------
  1065. readdir_fileinfo:
  1066.     dd  1
  1067.     dd  0
  1068.     dd  0
  1069. readblocks dd   0
  1070. directory_ptr   dd  0
  1071. ;------------------------------------------------------------------------------
  1072. I_END:
  1073. curdir      rb  1024
  1074.  
  1075. align 4
  1076. img_data     dd ?
  1077. img_data_len dd ?
  1078. fh       dd ?
  1079. image        dd ?
  1080. wnd_width   dd  ?
  1081. wnd_height  dd  ?
  1082. draw_width  dd  ?
  1083. draw_height dd  ?
  1084. last_name_component dd  ?
  1085. cur_file_idx    dd  ?
  1086. cur_frame_time  dd  ?
  1087. cur_frame   dd  ?
  1088.  
  1089. next_mod    dd  ?
  1090. next_key    dd  ?
  1091. prev_mod    dd  ?
  1092. prev_key    dd  ?
  1093.  
  1094. procinfo:   rb  1024
  1095. path:       rb  4096  ;1024+16
  1096. real_header rb  256
  1097. @PARAMS rb 4096  ;512
  1098. ;---------------------------------------------------------------------
  1099. temp_dir_pach:
  1100.         rb 4096
  1101. ;---------------------------------------------------------------------
  1102.     rb 4096
  1103. stacktop:
  1104. ;---------------------------------------------------------------------
  1105. F_END: