Subversion Repositories Kolibri OS

Rev

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