Subversion Repositories Kolibri OS

Rev

Rev 6801 | Rev 7421 | 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    SF_WAIT_EVENT
  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    SF_WAIT_EVENT_TIMEOUT
  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    img_resize_to_screen
  347.     call    init_frame
  348.     popf
  349.     call    update_image_sizes
  350.     call    free_img_data
  351.     clc
  352.     ret
  353.  
  354. .error_free:
  355.     invoke  img.destroy, [image]
  356.     jmp .error
  357.  
  358. .error_pop:
  359.     pop eax
  360.     jmp .error
  361. .error_close:
  362.     invoke  file.close, [fh]
  363. .error:
  364.     call    free_img_data
  365.     stc
  366.     ret
  367.  
  368. align 4
  369. proc img_resize_to_screen uses eax ebx ecx edx
  370.         mov ebx, [image]
  371.         cmp     [ebx+Image.Type],Image.bpp24
  372.         jne .end_f
  373.         test [ebx+Image.Flags],Image.IsAnimated
  374.         jnz .end_f
  375.         mov eax, [ebx+Image.Data]      
  376.         mov [buf_0],eax
  377.         mov eax, [ebx+Image.Width]
  378.         mov [buf_0.w],eax
  379.         mov eax, [ebx+Image.Height]
  380.         mov [buf_0.h],eax
  381.  
  382.         mcall SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
  383.         mov edx, [image_padding]
  384.         shl edx, 1
  385.         add edx, eax
  386.         mcall SF_GET_SCREEN_SIZE
  387.         mov ecx, eax
  388.         shr ecx, 17
  389.  
  390.         mov ebx, [image]
  391.         movzx eax,ax
  392.         sub eax, edx
  393.         sub eax, [toolbar_height]
  394.         sub eax, 5-1 ;5 px = border
  395.         cmp eax, 1
  396.         jle .end0
  397.         cmp eax, [ebx+Image.Height]
  398.         jl .end1
  399.         .end0:
  400.                 xor eax,eax
  401.                 jmp .end2
  402.         .end1:
  403.                 mov [ebx+Image.Height],eax
  404.         .end2:
  405.         sub ecx, [image_padding]
  406.         shl ecx, 1
  407.         sub ecx, 10-1 ;10 px = 2 borders
  408.         cmp ecx, 1
  409.         jle .end3
  410.         cmp ecx, [ebx+Image.Width]
  411.         jl .end4
  412.         .end3:
  413.                 xor ecx,ecx
  414.                 jmp .end5
  415.         .end4:
  416.                 mov [ebx+Image.Width],ecx
  417.         .end5:
  418.         cmp eax,ecx
  419.         jne @f
  420.                 test eax,eax
  421.                 jz .end_f
  422.         @@:
  423.         stdcall [buf2d_resize], buf_0, ecx, eax, 2
  424. .end_f:
  425.         ret
  426. endp
  427.  
  428. align 4
  429. free_img_data:
  430.     mov eax, [img_data]
  431.     test    eax, eax
  432.     jz  @f
  433.     stdcall mem.Free, eax
  434. @@:
  435.     ret
  436.  
  437. update_image_sizes:
  438.     pushf
  439.     mov edx, [eax + Image.Width]
  440.     test    [eax + Image.Flags], Image.IsAnimated
  441.     jnz .not_in_row
  442.     push eax
  443. @@: cmp [eax + Image.Next], 0
  444.     jz  @f
  445.     mov eax, [eax + Image.Next]
  446.     add edx, [eax + Image.Width]
  447.     inc edx
  448.     jmp @b
  449. @@: pop eax
  450. .not_in_row:
  451.     mov [draw_width], edx
  452.     add edx, 19
  453.     cmp edx, 50 + 25*numimages
  454.     jae @f
  455.     mov edx, 50 + 25*numimages
  456. @@:
  457. ;    dec edx
  458.     mov [wnd_width], edx
  459.     mov esi, [eax + Image.Height]
  460.     test    [eax + Image.Flags], Image.IsAnimated
  461.     jnz .max_equals_first
  462.     push eax
  463. @@: cmp [eax + Image.Next], 0
  464.     jz  @f
  465.     mov eax, [eax + Image.Next]
  466.     cmp esi, [eax + Image.Height]
  467.     jae @b
  468.     mov esi, [eax + Image.Height]
  469.     jmp @b
  470. @@: pop eax
  471. .max_equals_first:
  472.     mov [draw_height], esi
  473.     add esi, [toolbar_height]
  474.     add esi, [image_padding]
  475.     add esi, [image_padding]
  476.     add esi, 5  ; window bottom frame height
  477.     dec esi
  478.     mov [wnd_height], esi
  479.     popf
  480.     jz  .no_resize
  481.     test [wnd_style], 1 SHL 25
  482.     jz .no_resize
  483.     mcall   SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
  484.     add esi, eax
  485.     mcall   SF_CHANGE_WINDOW,-1,-1
  486. .no_resize:
  487.     ret
  488.  
  489. set_as_bgr:
  490.     mov esi, [image]
  491.     mov ecx, [esi + Image.Width]
  492.     mov edx, [esi + Image.Height]
  493.     mcall   SF_BACKGROUND_SET, SSF_SIZE_BG
  494.  
  495.     mcall   SF_BACKGROUND_SET, SSF_MAP_BG
  496.     test    eax, eax
  497.     jz  @f
  498.  
  499.     push    eax
  500.     invoke  img.to_rgb2, esi, eax
  501.     pop ecx
  502.     mcall   SF_BACKGROUND_SET, SSF_UNMAP_BG
  503.  
  504. @@:
  505.     mcall   SF_BACKGROUND_SET, SSF_REDRAW_BG
  506.     ret
  507.  
  508. slide_show:
  509.     or  byte [bSlideShow], 2
  510.     xor byte [bSlideShow], 1
  511.     btc dword [wnd_style], 25
  512.     jc  @f
  513.     mov eax, [toolbar_height_old]
  514.     mov [toolbar_height], eax
  515.     mov [image_padding], 5
  516.     jmp .toolbar_height_done
  517. @@:
  518.     mov eax, [toolbar_height]
  519.     mov [toolbar_height_old], eax
  520.     mov [toolbar_height], 0
  521.     mov [image_padding], 0
  522. .toolbar_height_done:
  523.     ret
  524.  
  525. ; seek to ESI image files
  526. ; esi>0 means next file, esi<0 - prev file
  527. next_or_prev_image:
  528.     push    esi
  529.     call    load_directory
  530.     pop esi
  531.     mov ebx, [directory_ptr]
  532.     test    ebx, ebx
  533.     jz  .ret
  534.     cmp dword[ebx+4], 0
  535.     jz  .ret
  536.     mov eax, [cur_file_idx]
  537.     cmp eax, -1
  538.     jnz @f
  539.     test    esi, esi
  540.     jns @f
  541.     mov eax, [ebx+4]
  542. @@:
  543.     push    [image]
  544.     add eax, esi
  545. @@:
  546.     test    eax, eax
  547.     jns @f
  548.     add eax, [ebx+4]
  549.     jmp @b
  550. @@:
  551.     cmp eax, [ebx+4]
  552.     jb  @f
  553.     sub eax, [ebx+4]
  554.     jmp @b
  555. @@:
  556.     push    eax
  557. .scanloop:
  558.     push    eax ebx esi
  559.     imul    esi, eax, 304
  560.     add esi, [directory_ptr]
  561.     add esi, 32 + 40
  562.     mov edi, curdir
  563. @@:
  564.     inc edi
  565.     cmp byte [edi-1], 0
  566.     jnz @b
  567.     mov byte [edi-1], '/'
  568. @@:
  569.     lodsb
  570.     stosb
  571.     test    al, al
  572.     jnz @b
  573.     mov eax, curdir
  574.     call    load_image
  575.     pushf
  576.     mov esi, curdir
  577.     push    esi
  578.     mov edi, @PARAMS
  579.     mov ecx, 4096/4
  580.     rep movsd
  581.     mov byte [edi-1], 0
  582.     pop esi
  583. @@:
  584.     lodsb
  585.     test    al, al
  586.     jnz @b
  587. @@:
  588.     dec esi
  589.     cmp byte [esi], '/'
  590.     jnz @b
  591.     mov byte [esi], 0
  592.     popf
  593.     pop esi ebx eax
  594.     jnc .loadedok
  595.     test    esi, esi
  596.     js  .try_prev
  597. .try_next:
  598.     inc eax
  599.     cmp eax, [ebx+4]
  600.     jb  @f
  601.     xor eax, eax
  602. @@:
  603. .try_common:
  604.     cmp eax, [esp]
  605.     jz  .notfound
  606.     jmp .scanloop
  607. .try_prev:
  608.     dec eax
  609.     jns @f
  610.     mov eax, [ebx+4]
  611.     dec eax
  612. @@:
  613.     jmp .try_common
  614. .loadedok:
  615.     mov [cur_file_idx], eax
  616.     pop eax
  617.     invoke  img.destroy
  618.     call    generate_header
  619. .ret:
  620.     ret
  621. .notfound:
  622.     pop eax
  623.     pop [image]
  624.     call    init_frame
  625.     ret
  626.  
  627. load_directory:
  628.     cmp [directory_ptr], 0
  629.     jnz .ret
  630.     mov esi, @PARAMS
  631.     mov edi, curdir
  632.     mov ecx, [last_name_component]
  633.     sub ecx, esi
  634.     dec ecx
  635.     js  @f
  636.     rep movsb
  637. @@:
  638.     mov byte [edi], 0
  639.     mcall   SF_SYS_MISC, SSF_MEM_ALLOC, 0x1000
  640.     test    eax, eax
  641.     jz  .ret
  642.     mov ebx, readdir_fileinfo
  643.     mov dword [ebx+12], (0x1000 - 32) / 304
  644.     mov dword [ebx+16], eax
  645.     mcall   SF_FILE
  646.     cmp eax, 6
  647.     jz  .dirok
  648.     test    eax, eax
  649.     jnz free_directory
  650.     mov edx, [directory_ptr]
  651.     mov ecx, [edx+8]
  652.     mov [readblocks], ecx
  653.     imul    ecx, 304
  654.     add ecx, 32
  655.     mcall   SF_SYS_MISC, SSF_MEM_REALLOC
  656.     test    eax, eax
  657.     jz  free_directory
  658.     mov [directory_ptr], eax
  659.     mcall   SF_FILE, readdir_fileinfo
  660. .dirok:
  661.     cmp ebx, 0
  662.     jle free_directory
  663.     mov eax, [directory_ptr]
  664.     add eax, 32
  665.     mov edi, eax
  666.     push    0
  667. .dirskip:
  668.     push    eax
  669.     test    byte [eax], 18h
  670.     jnz .nocopy
  671.     lea esi, [eax+40]
  672.     mov ecx, esi
  673. @@:
  674.     lodsb
  675.     test    al, al
  676.     jnz @b
  677. @@:
  678.     dec esi
  679.     cmp esi, ecx
  680.     jb  .noext
  681.     cmp byte [esi], '.'
  682.     jnz @b
  683.     inc esi
  684.     mov ecx, [esi]
  685.     cmp byte[esi+3], 0
  686.     jne .not_3
  687.     or  ecx, 0x202020
  688.     cmp ecx, 'jpg'
  689.     jz  .copy
  690.     cmp ecx, 'bmp'
  691.     jz  .copy
  692.     cmp ecx, 'gif'
  693.     jz  .copy
  694.     cmp ecx, 'png'
  695.     jz  .copy
  696.     cmp ecx, 'jpe'
  697.     jz  .copy
  698.     cmp ecx, 'ico'
  699.     jz  .copy
  700.     cmp ecx, 'cur'
  701.     jz  .copy
  702.     cmp ecx, 'tga'
  703.     jz  .copy
  704.     cmp ecx, 'pcx'
  705.     jz  .copy
  706.     cmp ecx, 'xcf'
  707.     jz  .copy
  708.     cmp ecx, 'pbm'
  709.     jz  .copy
  710.     cmp ecx, 'pgm'
  711.     jz  .copy
  712.     cmp ecx, 'pnm'
  713.     jz  .copy
  714.     cmp ecx, 'tif'
  715.     jz  .copy
  716.   .not_3:
  717.     cmp byte[esi+4], 0
  718.     jne .nocopy
  719.     or  ecx, 0x20202020
  720.     cmp ecx, 'tiff'
  721.     jz  @f
  722.     cmp ecx, 'wbmp'
  723.     jz  @f
  724.     cmp ecx, 'jpeg'
  725.     jnz .nocopy
  726. @@:
  727.     cmp byte [esi+4], 0
  728.     jnz .nocopy
  729. .copy:
  730.     mov esi, [esp]
  731.     mov ecx, 304 / 4
  732.     rep movsd
  733.     inc dword [esp+4]
  734. .nocopy:
  735. .noext:
  736.     pop eax
  737.     add eax, 304
  738.     dec ebx
  739.     jnz .dirskip
  740.     mov eax, [directory_ptr]
  741.     pop ebx
  742.     mov [eax+4], ebx
  743.     test    ebx, ebx
  744.     jz  free_directory
  745.     push    0   ; sort mode
  746.     push    ebx
  747.     add eax, 32
  748.     push    eax
  749.     call    [SortDir]
  750.     xor eax, eax
  751.     mov edi, [directory_ptr]
  752.     add edi, 32 + 40
  753. .scan:
  754.     mov esi, [last_name_component]
  755.     push    edi
  756.     invoke  strcmpi
  757.     pop edi
  758.     jz  .found
  759.     inc eax
  760.     add edi, 304
  761.     dec ebx
  762.     jnz .scan
  763.     or  eax, -1
  764. .found:
  765.     mov [cur_file_idx], eax
  766. .ret:
  767.     ret
  768.  
  769. free_directory:
  770.     mcall   SF_SYS_MISC, SSF_MEM_FREE, [directory_ptr]
  771.     and [directory_ptr], 0
  772.     ret
  773.  
  774. ; in: esi->full name (e.g. /path/to/file.png)
  775. ; out: [last_name_component]->last component (e.g. file.png)
  776. find_last_name_component:
  777.     mov ecx, esi
  778. @@:
  779.     lodsb
  780.     test    al, al
  781.     jnz @b
  782. @@:
  783.     dec esi
  784.     cmp esi, ecx
  785.     jb  @f
  786.     cmp byte [esi], '/'
  787.     jnz @b
  788. @@:
  789.     inc esi
  790.     mov [last_name_component], esi
  791.     ret
  792.  
  793. init_frame:
  794.     push    eax
  795.     mov eax, [image]
  796.     mov [cur_frame], eax
  797.     test    byte [eax + Image.Flags], Image.IsAnimated
  798.     jz  @f
  799.     push    ebx
  800.     mcall   SF_SYSTEM_GET, SSF_TIME_COUNT
  801.     pop ebx
  802.     mov [cur_frame_time], eax
  803. @@:
  804.     pop eax
  805.     ret
  806.  
  807. draw_window:
  808.     btr  word [bSlideShow], 1  ; mode changed
  809.     jc .mode_changed
  810.     test byte [bTglbar], 1
  811.     jz .mode_not_changed
  812. .mode_changed:
  813.     test [wnd_style], 1 SHL 25
  814.     jz .mode_slide
  815.     mov [bg_color], 0x00ffffff
  816.     mov eax, [image]
  817.     cmp eax, eax
  818.     call update_image_sizes
  819.     mcall SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
  820.     mov esi, [wnd_height]
  821.     add esi, eax
  822.     test byte [bTglbar], 1
  823.     jz @f
  824.     mcall SF_CHANGE_WINDOW, -1, -1, [wnd_width],
  825.     jmp .mode_not_changed
  826. @@:
  827.     mcall SF_CHANGE_WINDOW, [wnd_x], [wnd_y], [wnd_width],
  828.     jmp .mode_not_changed
  829. .mode_slide:
  830.     mov [bg_color], 0x00000000
  831.     mov eax, [procinfo.box.left]
  832.     mov [wnd_x], eax
  833.     mov eax, [procinfo.box.top]
  834.     mov [wnd_y], eax
  835.     mcall SF_GET_SCREEN_SIZE
  836.     mov edx, eax
  837.     shr edx, 16
  838.     movzx eax, ax
  839.     mov esi, eax
  840.     mcall SF_CHANGE_WINDOW, 0, 0, ,
  841.     jmp .posok.slide_show
  842.  
  843. .mode_not_changed:
  844.     cmp [bFirstDraw], 0
  845.     jz  .posok
  846.     or  ecx, -1
  847.     mcall   SF_THREAD_INFO, procinfo
  848.  
  849.     test byte [procinfo.wnd_state], 0x04
  850.     jnz .posok
  851.  
  852.     mov edx, ecx
  853.     mov esi, ecx
  854.     cmp dword [procinfo.box.width], 50 + 25 * numimages
  855.     jae @f
  856.     mov edx, 50 + 25 * numimages
  857. @@:
  858.     cmp dword [procinfo.box.height], 70
  859.     jae @f
  860.     mov esi, 70
  861. @@:
  862.     mov eax, edx
  863.     and eax, esi
  864.     cmp eax, -1
  865.     jz  @f
  866.     mov ebx, ecx
  867.     mcall   SF_CHANGE_WINDOW
  868. @@:
  869.  
  870. .posok:
  871.     test [wnd_style], 1 SHL 25
  872.     jz .posok.slide_show
  873.     mcall   SF_REDRAW, SSF_BEGIN_DRAW
  874.     mcall   SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
  875.     mov ebp, eax    ; save skin height
  876.     add eax, [wnd_height]
  877.     mov ebx, [wnd_x]
  878.     shl ebx, 16
  879.     add ebx, [wnd_width]
  880.     mov ecx, [wnd_y]
  881.     shl ecx, 16
  882.     add ecx, eax
  883.     mcall   SF_CREATE_WINDOW, , , [wnd_style], 0, real_header
  884.     jmp .posok.common
  885. .posok.slide_show:
  886.     mcall   SF_REDRAW, SSF_BEGIN_DRAW
  887.     mcall SF_GET_SCREEN_SIZE
  888.     mov ebx, eax
  889.     shr ebx, 16
  890.     movzx eax, ax
  891.     mov ecx, eax
  892.     mcall   SF_CREATE_WINDOW, , , [wnd_style], 0, real_header
  893. .posok.common:
  894.     mcall   SF_THREAD_INFO, procinfo, -1
  895.     mov eax, [procinfo.client_box.width]
  896.     sub eax, [image_padding]
  897.     sub eax, [image_padding]
  898.     sub eax, [draw_width]
  899.     sar eax, 1
  900.     test eax, eax
  901.     jns @f
  902.     mov eax, 0
  903. @@:
  904.     add eax, [image_padding]
  905.     mov [draw_x], eax
  906.     mov eax, [procinfo.client_box.height]
  907.     sub eax, [toolbar_height]
  908.     sub eax, [image_padding]
  909.     sub eax, [image_padding]
  910.     sub eax, [draw_height]
  911.     sar eax, 1
  912.     test eax, eax
  913.     jns @f
  914.     mov eax, 0
  915. @@:
  916.     add eax, [toolbar_height]
  917.     add eax, [image_padding]
  918.     mov [draw_y], eax
  919.     mov [bFirstDraw], 1
  920.     cmp dword [procinfo.client_box.height], 0
  921.     jle .nodraw
  922.     mov ebx, [procinfo.client_box.width]
  923.     inc ebx
  924.     mov ecx, [draw_y]
  925.     mcall   SF_DRAW_RECT, , , [bg_color]
  926.     mov ecx, [procinfo.client_box.height]
  927.     inc ecx
  928.     mov esi, [cur_frame]
  929.     mov esi, [esi + Image.Height]
  930.     add esi, [draw_y]
  931.     sub ecx, esi
  932.     jbe @f
  933.     push    esi
  934.     shl esi, 16
  935.     add ecx, esi
  936.     pop esi
  937.     mcall
  938.     xor ecx, ecx
  939. @@:
  940.     add ecx, esi
  941.     mov ebx, [draw_y]
  942.     sub ecx, ebx
  943.     shl ebx, 16
  944.     add ecx, ebx
  945.     mov ebx, [draw_x]
  946.     mcall
  947.     mov esi, [cur_frame]
  948.     mov esi, [esi + Image.Width]
  949.     add esi, ebx
  950.     mov ebx, [procinfo.client_box.width]
  951.     inc ebx
  952.     sub ebx, esi
  953.     jbe @f
  954.     shl esi, 16
  955.     add ebx, esi
  956.     mcall
  957. @@:
  958.  
  959.     test [wnd_style], 1 SHL 25
  960.     jz .slide_show_mode
  961.     mov byte [bTglbar], 0
  962.     cmp byte [toolbar_height], 0
  963.     je .decorations_done
  964.     mov ebx, [procinfo.client_box.width]
  965.     push    ebx
  966.     mcall   SF_DRAW_LINE, , <30, 30>, 0x007F7F7F
  967.     mcall   , <5 + 25 * 1, 5 + 25 * 1>, <0, 30>
  968.     mcall   , <10 + 25 * 3, 10 + 25 * 3>
  969.     mcall   , <15 + 25 * 5, 15 + 25 * 5>
  970.     pop ebx
  971.     sub ebx, 25 * 5 + 10
  972.     push    ebx
  973.     imul    ebx, 10001h
  974.     mcall
  975.  
  976.     mcall   SF_DEFINE_BUTTON, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
  977.     mcall   , <10 + 25 * 1, 20>, , 'bck'+40000000h
  978.     mcall   , <10 + 25 * 2, 20>, , 'fwd'+40000000h
  979.     mcall   , <15 + 25 * 3, 20>, , 'bgr'+40000000h
  980.     mcall   , <15 + 25 * 4, 20>, , 'sld'+40000000h
  981.     pop ebx
  982.     add ebx, 5
  983.     shl ebx, 16
  984.     mov bl, 20
  985.     mcall   , , , 'flh'+40000000h
  986.     add ebx, 25 * 65536
  987.     mcall   , , , 'flv'+40000000h
  988.     add ebx, 30 * 65536
  989.     mcall   , , , 'rtr'+40000000h
  990.     add ebx, 25 * 65536
  991.     mcall   , , , 'rtl'+40000000h
  992.     add ebx, 25 * 65536
  993.     mcall   , , , 'flb'+40000000h
  994.  
  995.     mov ebp, (numimages-1)*20
  996.  
  997.     mcall   SF_PUT_IMAGE_EXT, buttons+openbtn*20, <20, 20>, <5 + 25 * 0, 5>, 8, palette
  998.     mcall   , buttons+backbtn*20,    , <10 + 25 * 1, 5>
  999.     mcall   , buttons+forwardbtn*20, , <10 + 25 * 2, 5>
  1000.     mcall   , buttons+bgrbtn*20,     , <15 + 25 * 3, 5>
  1001.     mcall   , buttons+slidebtn*20,   , <15 + 25 * 4, 5>
  1002.     mov edx, [procinfo.client_box.width]
  1003.     sub edx, 25 * 5 + 4
  1004.     shl edx, 16
  1005.     mov dl, 5
  1006.     mcall   , buttons+fliphorzbtn*20
  1007.     add edx, 25 * 65536
  1008.     mcall   , buttons+flipvertbtn*20
  1009.     add edx, 30 * 65536
  1010.     mcall   , buttons+rotcwbtn*20
  1011.     add edx, 25 * 65536
  1012.     mcall   , buttons+rotccwbtn*20
  1013.     add edx, 25 * 65536
  1014.     mcall   , buttons+rot180btn*20
  1015.     jmp .decorations_done
  1016.  
  1017. .slide_show_mode:
  1018.  
  1019. .decorations_done:
  1020.     call    draw_cur_frame
  1021.  
  1022. .nodraw:
  1023.     mcall   SF_REDRAW, SSF_END_DRAW
  1024.  
  1025.     ret
  1026.  
  1027. draw_cur_frame:
  1028.     push    0   ; ypos
  1029.     push    0   ; xpos
  1030.     mov eax, [procinfo.client_box.height]
  1031.     sub eax, [toolbar_height]
  1032.     sub eax, [image_padding]
  1033.     inc eax
  1034.     push    eax ; max height
  1035.     mov eax, [procinfo.client_box.width]
  1036.     sub eax, [image_padding]
  1037.     inc eax
  1038.     push    eax ; max width
  1039.     push [draw_y]
  1040.     push [draw_x]
  1041.     push    [cur_frame]
  1042.     call    [img.draw]
  1043.     mov eax, [image]
  1044.     test    [eax + Image.Flags], Image.IsAnimated
  1045.     jnz .done
  1046.     cmp [eax + Image.Next], 0
  1047.     jnz .additional_frames
  1048. .done:
  1049.     ret
  1050. .additional_frames:
  1051.     mov ebx, [procinfo.client_box.width]
  1052.     sub ebx, [image_padding]
  1053.     inc ebx
  1054.     jbe .done
  1055.     mov esi, [draw_x]
  1056. .afloop:
  1057.     sub ebx, [eax + Image.Width]
  1058.     jbe .done
  1059.     dec ebx
  1060.     jz  .done
  1061.     add esi, [eax + Image.Width]
  1062.     mov eax, [eax + Image.Next]
  1063.     push    eax
  1064.     inc esi
  1065.     push    0   ; ypos
  1066.     push    0   ; xpos
  1067.     mov ecx, [procinfo.client_box.height]
  1068.     sub ecx, [toolbar_height]
  1069.     sub ecx, [image_padding]
  1070.     inc ecx
  1071. ;    inc ebx
  1072.     push    ecx ; max height
  1073.     push    ebx ; max width
  1074.     push    [draw_y]  ; y
  1075.     push    esi ; x
  1076.     push    eax ; image
  1077.     call    [img.draw]
  1078.     pop eax
  1079.     cmp [eax + Image.Next], 0
  1080.     jnz .afloop
  1081.     ret
  1082.  
  1083.  
  1084. check_shortcut:
  1085. ; in:   cl = scancode (from sysfn 2),
  1086. ;   eax = state of modifiers (from sysfn 66.3),
  1087. ;   edx -> shortcut descriptor
  1088. ; out:  ZF set <=> fail
  1089.     cmp cl, [edx+4]
  1090.     jnz .not
  1091.     push    eax
  1092.     mov esi, [edx]
  1093.     and esi, 0xF
  1094.     and al, 3
  1095.     call    dword [check_modifier_table+esi*4]
  1096.     test    al, al
  1097.     pop eax
  1098.     jnz .not
  1099.     push    eax
  1100.     mov esi, [edx]
  1101.     shr esi, 4
  1102.     and esi, 0xF
  1103.     shr al, 2
  1104.     and al, 3
  1105.     call    dword [check_modifier_table+esi*4]
  1106.     test    al, al
  1107.     pop eax
  1108.     jnz .not
  1109.     push    eax
  1110.     mov esi, [edx]
  1111.     shr esi, 8
  1112.     and esi, 0xF
  1113.     shr al, 4
  1114.     and al, 3
  1115.     call    dword [check_modifier_table+esi*4]
  1116.     test    al, al
  1117.     pop eax
  1118. ;   jnz .not
  1119. .not:
  1120.     ret
  1121.  
  1122. check_modifier_0:
  1123.     setnz   al
  1124.     ret
  1125. check_modifier_1:
  1126.     setp    al
  1127.     ret
  1128. check_modifier_2:
  1129.     cmp al, 3
  1130.     setnz   al
  1131.     ret
  1132. check_modifier_3:
  1133.     cmp al, 1
  1134.     setnz   al
  1135.     ret
  1136. check_modifier_4:
  1137.     cmp al, 2
  1138.     setnz   al
  1139.     ret
  1140.  
  1141. ; fills real_header with window title
  1142. ; window title is generated as '<filename> - Kolibri Image Viewer'
  1143. generate_header:
  1144.     push    eax
  1145.     mov esi, [last_name_component]
  1146.     mov edi, real_header
  1147. @@:
  1148.     lodsb
  1149.     test    al, al
  1150.     jz  @f
  1151.     stosb
  1152.     cmp edi, real_header+256
  1153.     jb  @b
  1154. .overflow:
  1155.     mov dword [edi-4], '...'
  1156. .ret:
  1157.     pop eax
  1158.     ret
  1159. @@:
  1160.     mov esi, s_header
  1161. @@:
  1162.     lodsb
  1163.     stosb
  1164.     test    al, al
  1165.     jz  .ret
  1166.     cmp edi, real_header+256
  1167.     jb  @b
  1168.     jmp .overflow
  1169. ;-----------------------------------------------------------------------------
  1170.  
  1171. s_header db ' - Kolibri Image Viewer', 0
  1172. wnd_style        dd 0x73FFFFFF
  1173. wnd_x            dd 100
  1174. wnd_y            dd 100
  1175. image_padding    dd 5
  1176. toolbar_height   dd 31
  1177. bg_color         dd 0x00ffffff
  1178.  
  1179. ;-----------------------------------------------------------------------------
  1180. ;-----------------------------------------------------------------------------
  1181.  
  1182. align 4
  1183. @IMPORT:
  1184.  
  1185. library             \
  1186.     libio  , 'libio.obj'  , \
  1187.     libgfx , 'libgfx.obj' , \
  1188.     libimg , 'libimg.obj' , \
  1189.     libini , 'libini.obj' , \
  1190.     sort   , 'sort.obj'   , \
  1191.     proc_lib ,'proc_lib.obj',\
  1192.         libbuf2d, 'buf2d.obj'
  1193.  
  1194.  
  1195. import  libio             , \
  1196.     libio.init , 'lib_init'   , \
  1197.     file.size  , 'file_size'  , \
  1198.     file.open  , 'file_open'  , \
  1199.     file.read  , 'file_read'  , \
  1200.     file.close , 'file_close'
  1201.  
  1202. import  libgfx              , \
  1203.     libgfx.init   , 'lib_init'  , \
  1204.     gfx.open      , 'gfx_open'  , \
  1205.     gfx.close     , 'gfx_close' , \
  1206.     gfx.pen.color , 'gfx_pen_color' , \
  1207.     gfx.line      , 'gfx_line'
  1208.  
  1209. import  libimg             , \
  1210.     libimg.init , 'lib_init'   , \
  1211.     img.is_img  , 'img_is_img' , \
  1212.     img.to_rgb2 , 'img_to_rgb2', \
  1213.     img.decode  , 'img_decode' , \
  1214.     img.flip    , 'img_flip'   , \
  1215.     img.rotate  , 'img_rotate' , \
  1216.     img.destroy , 'img_destroy', \
  1217.     img.draw    , 'img_draw'
  1218.  
  1219. import  libini, \
  1220.     ini_get_shortcut, 'ini_get_shortcut'
  1221.  
  1222. import  sort, sort.START, 'START', SortDir, 'SortDir', strcmpi, 'strcmpi'
  1223.  
  1224. import  proc_lib, \
  1225.     OpenDialog_Init, 'OpenDialog_init', \
  1226.     OpenDialog_Start,'OpenDialog_start'
  1227.  
  1228. import  libbuf2d, \
  1229.         buf2d_init, 'lib_init', \
  1230.         buf2d_resize, 'buf2d_resize'
  1231.  
  1232. align 4
  1233. buf_0: dd 0
  1234.         dw 0,0
  1235. .w: dd 0
  1236. .h: dd 0,0
  1237.         db 24 ;+20 bit in pixel
  1238.  
  1239. bFirstDraw  db  0
  1240. bSlideShow  db  0
  1241. bTglbar     db  0
  1242. ;-----------------------------------------------------------------------------
  1243.  
  1244. virtual at 0
  1245. file 'kivicons.bmp':0xA,4
  1246. load offbits dword from 0
  1247. end virtual
  1248. numimages = 10
  1249. openbtn = 0
  1250. backbtn = 1
  1251. forwardbtn = 2
  1252. bgrbtn = 3
  1253. fliphorzbtn = 4
  1254. flipvertbtn = 5
  1255. rotcwbtn = 6
  1256. rotccwbtn = 7
  1257. rot180btn = 8
  1258. slidebtn = 9
  1259.  
  1260. palette:
  1261.     file 'kivicons.bmp':0x36,offbits-0x36
  1262. buttons:
  1263.     file 'kivicons.bmp':offbits
  1264. repeat 10
  1265. y = % - 1
  1266. z = 20 - %
  1267. repeat numimages*5
  1268. load a dword from $ - numimages*20*20 + numimages*20*y + (%-1)*4
  1269. load b dword from $ - numimages*20*20 + numimages*20*z + (%-1)*4
  1270. store dword a at $ - numimages*20*20 + numimages*20*z + (%-1)*4
  1271. store dword b at $ - numimages*20*20 + numimages*20*y + (%-1)*4
  1272. end repeat
  1273. end repeat
  1274.  
  1275. inifilename db  '/sys/media/kiv.ini',0
  1276. aShortcuts  db  'Shortcuts',0
  1277. aNext       db  'Next',0
  1278. aPrev       db  'Prev',0
  1279. aSlide      db  'SlideShow',0
  1280. aTglbar     db  'ToggleBar',0
  1281.  
  1282. align 4
  1283. check_modifier_table:
  1284.     dd  check_modifier_0
  1285.     dd  check_modifier_1
  1286.     dd  check_modifier_2
  1287.     dd  check_modifier_3
  1288.     dd  check_modifier_4
  1289.  
  1290. ;---------------------------------------------------------------------
  1291. align 4
  1292. OpenDialog_data:
  1293. .type           dd 0
  1294. .procinfo       dd procinfo ;+4
  1295. .com_area_name      dd communication_area_name ;+8
  1296. .com_area       dd 0 ;+12
  1297. .opendir_pach       dd temp_dir_pach ;+16
  1298. .dir_default_pach   dd communication_area_default_pach ;+20
  1299. .start_path     dd open_dialog_path ;+24
  1300. .draw_window        dd draw_window ;+28
  1301. .status         dd 0 ;+32
  1302. .openfile_pach      dd path  ;openfile_pach ;+36
  1303. .filename_area      dd 0    ;+40
  1304. .filter_area        dd Filter
  1305. .x:
  1306. .x_size                 dw 420 ;+48 ; Window X size
  1307. .x_start                dw 10 ;+50 ; Window X position
  1308. .y:
  1309. .y_size                 dw 320 ;+52 ; Window y size
  1310. .y_start                dw 10 ;+54 ; Window Y position
  1311.  
  1312. communication_area_name:
  1313.     db 'FFFFFFFF_open_dialog',0
  1314.  
  1315. open_dialog_path:
  1316. if __nightbuild eq yes
  1317.     db '/sys/MANAGERS/opendial',0
  1318. else
  1319.     db '/sys/File Managers/opendial',0
  1320. end if
  1321. communication_area_default_pach:
  1322.     db '/rd/1',0
  1323.  
  1324. Filter:
  1325. dd Filter.end - Filter
  1326. .1:
  1327. db 'BMP',0
  1328. db 'GIF',0
  1329. db 'JPG',0
  1330. db 'JPEG',0
  1331. db 'JPE',0
  1332. db 'PNG',0
  1333. db 'ICO',0
  1334. db 'CUR',0
  1335. db 'TGA',0
  1336. db 'PCX',0
  1337. db 'XCF',0
  1338. db 'PBM',0
  1339. db 'PGM',0
  1340. db 'PNM',0
  1341. db 'TIF',0
  1342. db 'TIFF',0
  1343. db 'WBMP',0
  1344. .end:
  1345. db 0
  1346.  
  1347. draw_window_fake:
  1348.     ret
  1349. ;------------------------------------------------------------------------------
  1350. readdir_fileinfo:
  1351.     dd  1
  1352.     dd  0
  1353.     dd  0
  1354. readblocks dd   0
  1355. directory_ptr   dd  0
  1356. ;------------------------------------------------------------------------------
  1357. I_END:
  1358. curdir      rb  1024
  1359.  
  1360. align 4
  1361. img_data     dd ?
  1362. img_data_len dd ?
  1363. fh       dd ?
  1364. image        dd ?
  1365. wnd_width   dd  100
  1366. wnd_height  dd  100
  1367. draw_x      dd  ?
  1368. draw_y      dd  ?
  1369. draw_width  dd  ?
  1370. draw_height dd  ?
  1371. last_name_component dd  ?
  1372. cur_file_idx    dd  ?
  1373. cur_frame_time  dd  ?
  1374. cur_frame   dd  ?
  1375.  
  1376. next_mod    dd  ?
  1377. next_key    dd  ?
  1378. prev_mod    dd  ?
  1379. prev_key    dd  ?
  1380. slide_mod   dd  ?
  1381. slide_key   dd  ?
  1382. tglbar_mod  dd  ?
  1383. tglbar_key  dd  ?
  1384.  
  1385. toolbar_height_old   rd 1
  1386.  
  1387. procinfo    process_information
  1388. path:       rb  4096  ;1024+16
  1389. real_header rb  256
  1390. @PARAMS rb 4096  ;512
  1391. ;---------------------------------------------------------------------
  1392. temp_dir_pach:
  1393.         rb 4096
  1394. ;---------------------------------------------------------------------
  1395.     rb 4096
  1396. stacktop:
  1397. ;---------------------------------------------------------------------
  1398. F_END:
  1399.