Subversion Repositories Kolibri OS

Rev

Rev 2389 | Rev 3116 | 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. include '../../../config.inc'           ;for nightbuild
  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.     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
  38.  
  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.  
  51. ; initialize keyboard handling
  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
  57.  
  58.     cmp byte [@PARAMS], 0
  59.     jnz params_given
  60.  
  61.     mov [OpenDialog_data.draw_window],draw_window_fake
  62.    
  63. ; OpenDialog Open
  64.     push    dword OpenDialog_data
  65.     call    [OpenDialog_Start]
  66.  
  67.     cmp [OpenDialog_data.status],1
  68.     jne exit
  69.  
  70.     mov [OpenDialog_data.draw_window],draw_window
  71.  
  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
  78.  
  79. set_bgr:
  80.     mcall   15, 4
  81.     mov eax, @PARAMS + 4
  82.     call    load_image
  83.     jc  exit
  84.  
  85.     call    set_as_bgr
  86.     jmp exit
  87.  
  88. params_given:
  89.  
  90.     mov esi, @PARAMS
  91.     push    esi
  92.     call    find_last_name_component
  93.  
  94.     pop eax
  95.     call    load_image
  96.     jc  exit
  97.     call    generate_header
  98.  
  99. ;-----------------------------------------------------------------------------
  100.  
  101. red:
  102.     call    draw_window
  103.  
  104. still:
  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
  121.   @@:
  122.     mcall
  123.     dec eax
  124.     js  red_update_frame
  125.     jz  red
  126.     dec eax
  127.     jnz button
  128.  
  129. key:
  130.     xor esi, esi
  131. keyloop:
  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
  144. .prev:
  145.     dec esi
  146.     jmp keyloop
  147. .next:
  148.     inc esi
  149.     jmp keyloop
  150. keyloopdone:
  151.     test    esi, esi
  152.     jz  still
  153. next_or_prev_handler:
  154.     call    next_or_prev_image
  155.     jmp red
  156.  
  157. red_update_frame:
  158.     mov eax, [cur_frame]
  159.     mov eax, [eax + Image.Next]
  160.     test    eax, eax
  161.     jnz @f
  162.     mov eax, [image]
  163.   @@:
  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
  170.  
  171. button:
  172.     mcall   17
  173.     shr eax, 8
  174.  
  175.     ; flip horizontally
  176.     cmp eax, 'flh'
  177.     jne @f
  178.  
  179.     invoke  img.flip, [image], FLIP_HORIZONTAL
  180.     jmp redraw_image
  181.  
  182.     ; flip vertically
  183.     @@: cmp eax, 'flv'
  184.     jne @f
  185.  
  186.     invoke  img.flip, [image], FLIP_VERTICAL
  187.     jmp redraw_image
  188.  
  189.     ; flip both horizontally and vertically
  190.     @@: cmp eax, 'flb'
  191.     jne @f
  192.  
  193.     invoke  img.flip, [image], FLIP_BOTH
  194.     jmp redraw_image
  195.  
  196.     ; rotate left
  197.     @@: cmp eax, 'rtl'
  198.     jne @f
  199.  
  200.     push    ROTATE_90_CCW
  201. .rotate_common:
  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
  207.  
  208.     ; rotate right
  209.     @@: cmp eax, 'rtr'
  210.     jne @f
  211.  
  212.     push    ROTATE_90_CW
  213.     jmp .rotate_common
  214.  
  215.     ; open new file
  216.     @@: cmp eax, 'opn'
  217.     jne @f
  218.    
  219. ; OpenDialog Open
  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
  236.  
  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.    
  247.     .restore_old:
  248.     pop [image]
  249.     call    init_frame
  250.     jmp still
  251.  
  252.     ; set background
  253.     @@:
  254.     cmp eax, 'bgr'
  255.     jne @f
  256.  
  257.     call    set_as_bgr
  258.     jmp still
  259.  
  260.     @@:
  261.  
  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
  268.  
  269.     cmp eax, 1
  270.     jne still
  271.  
  272.   exit:
  273.     mcall   -1
  274.  
  275.   redraw_image = red
  276.  
  277. load_image:
  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
  298.  
  299. ; img.decode checks for img.is_img
  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
  315.  
  316. .error_free:
  317.     invoke  img.destroy, [image]
  318.     jmp .error
  319.  
  320. .error_pop:
  321.     pop eax
  322.     jmp .error
  323. .error_close:
  324.     invoke  file.close, [fh]
  325. .error:
  326.     call    free_img_data
  327.     stc
  328.     ret
  329.  
  330. free_img_data:
  331.     mov eax, [img_data]
  332.     test    eax, eax
  333.     jz  @f
  334.     stdcall mem.Free, eax
  335. @@:
  336.     ret
  337.  
  338. update_image_sizes:
  339.     pushf
  340.     mov edx, [eax + Image.Width]
  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:
  352.     mov [draw_width], edx
  353.     add edx, 19
  354.     cmp edx, 40 + 25*9
  355.     jae @f
  356.     mov edx, 40 + 25*9
  357. @@:
  358.     mov [wnd_width], edx
  359.     mov esi, [eax + Image.Height]
  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:
  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
  380. .no_resize:
  381.     ret
  382.  
  383. set_as_bgr:
  384.     mov esi, [image]
  385.     mov ecx, [esi + Image.Width]
  386.     mov edx, [esi + Image.Height]
  387.     mcall   15, 1
  388.  
  389.     mcall   15, 6
  390.     test    eax, eax
  391.     jz  @f
  392.  
  393.     push    eax
  394.     invoke  img.to_rgb2, esi, eax
  395.     pop ecx
  396.     mcall   15, 7
  397.  
  398. @@:
  399.     mcall   15, 3
  400.     ret
  401.  
  402. ; seek to ESI image files
  403. ; esi>0 means next file, esi<0 - prev file
  404. next_or_prev_image:
  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]
  419. @@:
  420.     push    [image]
  421.     add eax, esi
  422. @@:
  423.     test    eax, eax
  424.     jns @f
  425.     add eax, [ebx+4]
  426.     jmp @b
  427. @@:
  428.     cmp eax, [ebx+4]
  429.     jb  @f
  430.     sub eax, [ebx+4]
  431.     jmp @b
  432. @@:
  433.     push    eax
  434. .scanloop:
  435.     push    eax ebx esi
  436.     imul    esi, eax, 304
  437.     add esi, [directory_ptr]
  438.     add esi, 32 + 40
  439.     mov edi, curdir
  440. @@:
  441.     inc edi
  442.     cmp byte [edi-1], 0
  443.     jnz @b
  444.     mov byte [edi-1], '/'
  445. @@:
  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
  460. @@:
  461.     lodsb
  462.     test    al, al
  463.     jnz @b
  464. @@:
  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
  474. .try_next:
  475.     inc eax
  476.     cmp eax, [ebx+4]
  477.     jb  @f
  478.     xor eax, eax
  479. @@:
  480. .try_common:
  481.     cmp eax, [esp]
  482.     jz  .notfound
  483.     jmp .scanloop
  484. .try_prev:
  485.     dec eax
  486.     jns @f
  487.     mov eax, [ebx+4]
  488.     dec eax
  489. @@:
  490.     jmp .try_common
  491. .loadedok:
  492.     mov [cur_file_idx], eax
  493.     pop eax
  494.     invoke  img.destroy
  495.     call    generate_header
  496. .ret:
  497.     ret
  498. .notfound:
  499.     pop eax
  500.     pop [image]
  501.     call    init_frame
  502.     ret
  503.  
  504. load_directory:
  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
  514. @@:
  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
  537. .dirok:
  538.     cmp ebx, 0
  539.     jle free_directory
  540.     mov eax, [directory_ptr]
  541.     add eax, 32
  542.     mov edi, eax
  543.     push    0
  544. .dirskip:
  545.     push    eax
  546.     test    byte [eax], 18h
  547.     jnz .nocopy
  548.     lea esi, [eax+40]
  549.     mov ecx, esi
  550. @@:
  551.     lodsb
  552.     test    al, al
  553.     jnz @b
  554. @@:
  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
  577. ; dunkaist [
  578.     cmp ecx, 'pcx'
  579.     jz  .copy
  580.     cmp ecx, 'xcf'
  581.     jz  .copy
  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
  592.     cmp ecx, 'wbmp'
  593.     jz  @f
  594. ; dunkaist ]
  595.     cmp ecx, 'jpeg'
  596.     jz  @f
  597.     cmp ecx, 'jpeG'
  598.     jnz .nocopy
  599. @@:
  600.     cmp byte [esi+4], 0
  601.     jnz .nocopy
  602. .copy:
  603.     mov esi, [esp]
  604.     mov ecx, 304 / 4
  605.     rep movsd
  606.     inc dword [esp+4]
  607. .nocopy:
  608. .noext:
  609.     pop eax
  610.     add eax, 304
  611.     dec ebx
  612.     jnz .dirskip
  613.     mov eax, [directory_ptr]
  614.     pop ebx
  615.     mov [eax+4], ebx
  616.     test    ebx, ebx
  617.     jz  free_directory
  618.     push    0   ; sort mode
  619.     push    ebx
  620.     add eax, 32
  621.     push    eax
  622.     call    [SortDir]
  623.     xor eax, eax
  624.     mov edi, [directory_ptr]
  625.     add edi, 32 + 40
  626. .scan:
  627.     mov esi, [last_name_component]
  628.     push    edi
  629.     invoke  strcmpi
  630.     pop edi
  631.     jz  .found
  632.     inc eax
  633.     add edi, 304
  634.     dec ebx
  635.     jnz .scan
  636.     or  eax, -1
  637. .found:
  638.     mov [cur_file_idx], eax
  639. .ret:
  640.     ret
  641.  
  642. free_directory:
  643.     mcall   68, 13, [directory_ptr]
  644.     and [directory_ptr], 0
  645.     ret
  646.  
  647. ; in: esi->full name (e.g. /path/to/file.png)
  648. ; out: [last_name_component]->last component (e.g. file.png)
  649. find_last_name_component:
  650.     mov ecx, esi
  651. @@:
  652.     lodsb
  653.     test    al, al
  654.     jnz @b
  655. @@:
  656.     dec esi
  657.     cmp esi, ecx
  658.     jb  @f
  659.     cmp byte [esi], '/'
  660.     jnz @b
  661. @@:
  662.     inc esi
  663.     mov [last_name_component], esi
  664.     ret
  665.  
  666. init_frame:
  667.     push    eax
  668.     mov eax, [image]
  669.     mov [cur_frame], eax
  670.     test    byte [eax + Image.Flags], Image.IsAnimated
  671.     jz  @f
  672.     push    ebx
  673.     mcall   26, 9
  674.     pop ebx
  675.     mov [cur_frame_time], eax
  676. @@:
  677.     pop eax
  678.     ret
  679.  
  680. draw_window:
  681.     cmp [bFirstDraw], 0
  682.     jz  .posok
  683.     or  ecx, -1
  684.     mcall   9, procinfo
  685.  
  686.     cmp dword [ebx + 66], 0
  687.     jle .posok
  688.  
  689.     mov edx, ecx
  690.     mov esi, ecx
  691.     cmp dword [ebx + 42], 40 + 25 * 9
  692.     jae @f
  693.     mov edx, 40 + 25 * 9
  694. @@:
  695.     cmp dword [ebx + 46], 70
  696.     jae @f
  697.     mov esi, 70
  698. @@:
  699.     mov eax, edx
  700.     and eax, esi
  701.     cmp eax, -1
  702.     jz  @f
  703.     mov ebx, ecx
  704.     mcall   67
  705. @@:
  706.  
  707. .posok:
  708.     mcall   12, 1
  709.     mcall   48, 4
  710.     mov ebp, eax    ; save skin height
  711.     add eax, [wnd_height]
  712.     __mov   ebx, 100, 0
  713.     add ebx, [wnd_width]
  714.     lea ecx, [100*65536 + eax]
  715.     mcall   0, , , 0x73FFFFFF, 0, real_header
  716.  
  717.     mcall   9, procinfo, -1
  718.     mov [bFirstDraw], 1
  719.     cmp dword [ebx + 66], 0
  720.     jle .nodraw
  721.     mov ebx, [ebx + 62]
  722.     inc ebx
  723.     mcall   13, , <0, 35>, 0xFFFFFF
  724.     mov ecx, [procinfo + 66]
  725.     inc ecx
  726. ;    mov esi, [draw_height]          ; we can not use [draw_height] here because for *.ico files containing several frames
  727.     mov esi, [image]                 ; with different size window height should depend on maximum frame height, not the first one
  728.     mov esi, [esi+Image.Height]      ;
  729.     add esi, 35
  730.     sub ecx, esi
  731.     jbe @f
  732.     push    esi
  733.     shl esi, 16
  734.     add ecx, esi
  735.     pop esi
  736.     mcall
  737.     xor ecx, ecx
  738. @@:
  739.     add ecx, esi
  740.     add ecx, 35*10000h - 35
  741.     __mov   ebx, 0, 5
  742.     mcall
  743. ;    mov esi, [draw_width]           ; we can not use [draw_width] here because for *.ico files containing several frames
  744.     mov esi, [image]                 ; with different size window width should depend on the sum of width of all frames
  745.     mov esi, [esi + Image.Width]     ;
  746.     add esi, ebx
  747.     mov ebx, [procinfo+62]
  748.     inc ebx
  749.     sub ebx, esi
  750.     jbe @f
  751.     shl esi, 16
  752.     add ebx, esi
  753.     mcall
  754. @@:
  755.  
  756.     mov ebx, [procinfo + 62]
  757.     push    ebx
  758.     mcall   38, , <30, 30>, 0x007F7F7F
  759.     mcall   , <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
  760.     mcall   , <10 + 25 * 3, 10 + 25 * 3>
  761.     mcall   , <15 + 25 * 4, 15 + 25 * 4>
  762.     pop ebx
  763.     sub ebx, 25 * 5 + 10
  764.     push    ebx
  765.     imul    ebx, 10001h
  766.     mcall
  767.  
  768.     mcall   8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
  769.     mcall   , <10 + 25 * 1, 20>, , 'bck'+40000000h
  770.     mcall   , <10 + 25 * 2, 20>, , 'fwd'+40000000h
  771.     mcall   , <15 + 25 * 3, 20>, , 'bgr'+40000000h
  772.     pop ebx
  773.     add ebx, 5
  774.     shl ebx, 16
  775.     mov bl, 20
  776.     mcall   , , , 'flh'+40000000h
  777.     add ebx, 25 * 65536
  778.     mcall   , , , 'flv'+40000000h
  779.     add ebx, 30 * 65536
  780.     mcall   , , , 'rtr'+40000000h
  781.     add ebx, 25 * 65536
  782.     mcall   , , , 'rtl'+40000000h
  783.     add ebx, 25 * 65536
  784.     mcall   , , , 'flb'+40000000h
  785.  
  786.     mov ebp, (numimages-1)*20
  787.  
  788.     mcall   65, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
  789.     mcall   , buttons+backbtn*20, , <10 + 25 * 1, 5>
  790.     mcall   , buttons+forwardbtn*20, , <10 + 25 * 2, 5>
  791.     mcall   , buttons+bgrbtn*20, , <15 + 25 * 3, 5>
  792.     mov edx, [procinfo + 62]
  793.     sub edx, 25 * 5 + 4
  794.     shl edx, 16
  795.     mov dl, 5
  796.     mcall   , buttons+fliphorzbtn*20
  797.     add edx, 25 * 65536
  798.     mcall   , buttons+flipvertbtn*20
  799.     add edx, 30 * 65536
  800.     mcall   , buttons+rotcwbtn*20
  801.     add edx, 25 * 65536
  802.     mcall   , buttons+rotccwbtn*20
  803.     add edx, 25 * 65536
  804.     mcall   , buttons+rot180btn*20
  805.  
  806.     call    draw_cur_frame
  807.  
  808. .nodraw:
  809.     mcall   12, 2
  810.  
  811.     ret
  812.  
  813. draw_cur_frame:
  814.     push    0   ; ypos
  815.     push    0   ; xpos
  816.     mov eax, [procinfo+66]
  817.     sub eax, 34
  818.     push    eax ; max height
  819.     mov eax, [procinfo+62]
  820.     sub eax, 4
  821.     push    eax ; max width
  822.     push    35  ; y
  823.     push    5   ; x
  824.     push    [cur_frame]
  825.     call    [img.draw]
  826.     mov eax, [image]
  827.     test    [eax + Image.Flags], Image.IsAnimated
  828.     jnz .done
  829.     cmp [eax + Image.Next], 0
  830.     jnz .additional_frames
  831. .done:
  832.     ret
  833. .additional_frames:
  834.     mov ebx, [procinfo+62]
  835.     sub ebx, 4
  836.     jbe .done
  837.     push    5
  838.     pop esi
  839. .afloop:
  840.     sub ebx, [eax + Image.Width]
  841.     jbe .done
  842.     dec ebx
  843.     jz  .done
  844.     add esi, [eax + Image.Width]
  845.     mov eax, [eax + Image.Next]
  846.     push    eax
  847.     inc esi
  848.     push    0   ; ypos
  849.     push    0   ; xpos
  850.     mov ecx, [procinfo+66]
  851.     sub ecx, 34
  852.     push    ecx ; max height
  853.     push    ebx ; max width
  854.     push    35  ; y
  855.     push    esi ; x
  856.     push    eax ; image
  857.     call    [img.draw]
  858.     pop eax
  859.     cmp [eax + Image.Next], 0
  860.     jnz .afloop
  861.     ret
  862.  
  863. ; void* __stdcall mem.Alloc(unsigned size);
  864. mem.Alloc:
  865.     push    ebx ecx
  866.     mov ecx, [esp+12]
  867.     mcall   68, 12
  868.     pop ecx ebx
  869.     ret 4
  870.  
  871. ; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
  872. mem.ReAlloc:
  873.     push    ebx ecx edx
  874.     mov edx, [esp+16]
  875.     mov ecx, [esp+20]
  876.     mcall   68, 20
  877.     pop edx ecx ebx
  878.     ret 8
  879.  
  880. ; void __stdcall mem.Free(void* mptr);
  881. mem.Free:
  882.     push    ebx ecx
  883.     mov ecx, [esp+12]
  884.     mcall   68, 13
  885.     pop ecx ebx
  886.     ret 4
  887.  
  888. check_shortcut:
  889. ; in:   cl = scancode (from sysfn 2),
  890. ;   eax = state of modifiers (from sysfn 66.3),
  891. ;   edx -> shortcut descriptor
  892. ; out:  ZF set <=> fail
  893.     cmp cl, [edx+4]
  894.     jnz .not
  895.     push    eax
  896.     mov esi, [edx]
  897.     and esi, 0xF
  898.     and al, 3
  899.     call    dword [check_modifier_table+esi*4]
  900.     test    al, al
  901.     pop eax
  902.     jnz .not
  903.     push    eax
  904.     mov esi, [edx]
  905.     shr esi, 4
  906.     and esi, 0xF
  907.     shr al, 2
  908.     and al, 3
  909.     call    dword [check_modifier_table+esi*4]
  910.     test    al, al
  911.     pop eax
  912.     jnz .not
  913.     push    eax
  914.     mov esi, [edx]
  915.     shr esi, 8
  916.     and esi, 0xF
  917.     shr al, 4
  918.     and al, 3
  919.     call    dword [check_modifier_table+esi*4]
  920.     test    al, al
  921.     pop eax
  922. ;   jnz .not
  923. .not:
  924.     ret
  925.  
  926. check_modifier_0:
  927.     setnz   al
  928.     ret
  929. check_modifier_1:
  930.     setp    al
  931.     ret
  932. check_modifier_2:
  933.     cmp al, 3
  934.     setnz   al
  935.     ret
  936. check_modifier_3:
  937.     cmp al, 1
  938.     setnz   al
  939.     ret
  940. check_modifier_4:
  941.     cmp al, 2
  942.     setnz   al
  943.     ret
  944.  
  945. ; fills real_header with window title
  946. ; window title is generated as '<filename> - Kolibri Image Viewer'
  947. generate_header:
  948.     push    eax
  949.     mov esi, [last_name_component]
  950.     mov edi, real_header
  951. @@:
  952.     lodsb
  953.     test    al, al
  954.     jz  @f
  955.     stosb
  956.     cmp edi, real_header+256
  957.     jb  @b
  958. .overflow:
  959.     mov dword [edi-4], '...'
  960. .ret:
  961.     pop eax
  962.     ret
  963. @@:
  964.     mov esi, s_header
  965. @@:
  966.     lodsb
  967.     stosb
  968.     test    al, al
  969.     jz  .ret
  970.     cmp edi, real_header+256
  971.     jb  @b
  972.     jmp .overflow
  973. ;-----------------------------------------------------------------------------
  974.  
  975. s_header db ' - Kolibri Image Viewer', 0
  976.  
  977. ;-----------------------------------------------------------------------------
  978. ;-----------------------------------------------------------------------------
  979.  
  980. align 4
  981. @IMPORT:
  982.  
  983. library             \
  984.     libio  , 'libio.obj'  , \
  985.     libgfx , 'libgfx.obj' , \
  986.     libimg , 'libimg.obj' , \
  987.     libini , 'libini.obj' , \
  988.     sort   , 'sort.obj'   , \
  989.     proc_lib ,'proc_lib.obj'
  990.  
  991.  
  992. import  libio             , \
  993.     libio.init , 'lib_init'   , \
  994.     file.size  , 'file_size'  , \
  995.     file.open  , 'file_open'  , \
  996.     file.read  , 'file_read'  , \
  997.     file.close , 'file_close'
  998.  
  999. import  libgfx              , \
  1000.     libgfx.init   , 'lib_init'  , \
  1001.     gfx.open      , 'gfx_open'  , \
  1002.     gfx.close     , 'gfx_close' , \
  1003.     gfx.pen.color , 'gfx_pen_color' , \
  1004.     gfx.line      , 'gfx_line'
  1005.  
  1006. import  libimg             , \
  1007.     libimg.init , 'lib_init'   , \
  1008.     img.is_img  , 'img_is_img' , \
  1009.     img.to_rgb2 , 'img_to_rgb2', \
  1010.     img.decode  , 'img_decode' , \
  1011.     img.flip    , 'img_flip'   , \
  1012.     img.rotate  , 'img_rotate' , \
  1013.     img.destroy , 'img_destroy', \
  1014.     img.draw    , 'img_draw'
  1015.  
  1016. import  libini, \
  1017.     ini_get_shortcut, 'ini_get_shortcut'
  1018.  
  1019. import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
  1020.  
  1021. import  proc_lib, \
  1022.     OpenDialog_Init, 'OpenDialog_init', \
  1023.     OpenDialog_Start,'OpenDialog_start'
  1024.  
  1025. bFirstDraw  db  0
  1026. ;-----------------------------------------------------------------------------
  1027.  
  1028. virtual at 0
  1029. file 'kivicons.bmp':0xA,4
  1030. load offbits dword from 0
  1031. end virtual
  1032. numimages = 9
  1033. openbtn = 0
  1034. backbtn = 1
  1035. forwardbtn = 2
  1036. bgrbtn = 3
  1037. fliphorzbtn = 4
  1038. flipvertbtn = 5
  1039. rotcwbtn = 6
  1040. rotccwbtn = 7
  1041. rot180btn = 8
  1042.  
  1043. palette:
  1044.     file 'kivicons.bmp':0x36,offbits-0x36
  1045. buttons:
  1046.     file 'kivicons.bmp':offbits
  1047. repeat 10
  1048. y = % - 1
  1049. z = 20 - %
  1050. repeat numimages*5
  1051. load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
  1052. load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
  1053. store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
  1054. store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
  1055. end repeat
  1056. end repeat
  1057.  
  1058. inifilename db  '/sys/media/kiv.ini',0
  1059. aShortcuts  db  'Shortcuts',0
  1060. aNext       db  'Next',0
  1061. aPrev       db  'Prev',0
  1062.  
  1063. align 4
  1064. check_modifier_table:
  1065.     dd  check_modifier_0
  1066.     dd  check_modifier_1
  1067.     dd  check_modifier_2
  1068.     dd  check_modifier_3
  1069.     dd  check_modifier_4
  1070.  
  1071. ;---------------------------------------------------------------------
  1072. align 4
  1073. OpenDialog_data:
  1074. .type           dd 0
  1075. .procinfo       dd procinfo ;+4
  1076. .com_area_name      dd communication_area_name ;+8
  1077. .com_area       dd 0 ;+12
  1078. .opendir_pach       dd temp_dir_pach ;+16
  1079. .dir_default_pach   dd communication_area_default_pach ;+20
  1080. .start_path     dd open_dialog_path ;+24
  1081. .draw_window        dd draw_window ;+28
  1082. .status         dd 0 ;+32
  1083. .openfile_pach      dd path  ;openfile_pach ;+36
  1084. .filename_area      dd 0    ;+40
  1085. .filter_area        dd Filter
  1086. .x:
  1087. .x_size                 dw 420 ;+48 ; Window X size
  1088. .x_start                dw 10 ;+50 ; Window X position
  1089. .y:
  1090. .y_size                 dw 320 ;+52 ; Window y size
  1091. .y_start                dw 10 ;+54 ; Window Y position
  1092.  
  1093. communication_area_name:
  1094.     db 'FFFFFFFF_open_dialog',0
  1095.  
  1096. open_dialog_path:
  1097. if __nightbuild eq yes
  1098.     db '/sys/MANAGERS/opendial',0
  1099. else
  1100.     db '/sys/File Managers/opendial',0
  1101. end if
  1102. communication_area_default_pach:
  1103.     db '/rd/1',0
  1104.  
  1105. Filter:
  1106. dd Filter.end - Filter
  1107. .1:
  1108. db 'BMP',0
  1109. db 'GIF',0
  1110. db 'JPG',0
  1111. db 'JPEG',0
  1112. db 'JPE',0
  1113. db 'PNG',0
  1114. db 'ICO',0
  1115. db 'CUR',0
  1116. ; dunkaist [
  1117. db 'PCX',0
  1118. db 'XCF',0
  1119. db 'PBM',0
  1120. db 'PGM',0
  1121. db 'PNM',0
  1122. db 'TIF',0
  1123. db 'TIFF',0
  1124. db 'WBMP',0
  1125. ; dunkaist ]
  1126. .end:
  1127. db 0
  1128.  
  1129. draw_window_fake:
  1130.     ret
  1131. ;------------------------------------------------------------------------------
  1132. readdir_fileinfo:
  1133.     dd  1
  1134.     dd  0
  1135.     dd  0
  1136. readblocks dd   0
  1137. directory_ptr   dd  0
  1138. ;------------------------------------------------------------------------------
  1139. I_END:
  1140. curdir      rb  1024
  1141.  
  1142. align 4
  1143. img_data     dd ?
  1144. img_data_len dd ?
  1145. fh       dd ?
  1146. image        dd ?
  1147. wnd_width   dd  ?
  1148. wnd_height  dd  ?
  1149. draw_width  dd  ?
  1150. draw_height dd  ?
  1151. last_name_component dd  ?
  1152. cur_file_idx    dd  ?
  1153. cur_frame_time  dd  ?
  1154. cur_frame   dd  ?
  1155.  
  1156. next_mod    dd  ?
  1157. next_key    dd  ?
  1158. prev_mod    dd  ?
  1159. prev_key    dd  ?
  1160.  
  1161. procinfo:   rb  1024
  1162. path:       rb  4096  ;1024+16
  1163. real_header rb  256
  1164. @PARAMS rb 4096  ;512
  1165. ;---------------------------------------------------------------------
  1166. temp_dir_pach:
  1167.         rb 4096
  1168. ;---------------------------------------------------------------------
  1169.     rb 4096
  1170. stacktop:
  1171. ;---------------------------------------------------------------------
  1172. F_END:
  1173.