Subversion Repositories Kolibri OS

Rev

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

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