Subversion Repositories Kolibri OS

Rev

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