kiv: Add a button to switch scaling modes.

Two scaling modes (fit to the window, no scaling) were implemented
some time ago. One can switch them with not obvious shortcuts 'w' and
'=' (like in sxiv). This commit adds a button to the toolbar to do the
same.

Also, the window title now mentions the number of supported images in
the current directory, not the total number of files in it.

Align code to the kernel style guide.


git-svn-id: svn://kolibrios.org@7860 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2020-05-04 00:27:28 +00:00
parent 78851ff66b
commit 5a520e0752
2 changed files with 342 additions and 323 deletions

View File

@ -152,6 +152,10 @@ still:
jz button jz button
mouse: mouse:
mov eax, [need_scrollbar_v]
add eax, [need_scrollbar_h]
test eax, eax
jz .done
mov [pict_moved], 0 mov [pict_moved], 0
invoke scrollbar_vert_mouse, scroll_bar_data_vertical invoke scrollbar_vert_mouse, scroll_bar_data_vertical
@ -518,6 +522,19 @@ button:
jmp redraw_all jmp redraw_all
@@: @@:
cmp eax, 'scl'
jnz .not_scl
mov eax, LIBIMG_SCALE_NONE
cmp [scale_mode], LIBIMG_SCALE_NONE
jnz @f
mov eax, LIBIMG_SCALE_FIT_MIN
@@:
call set_scale_mode
jz @f
call recalc_work
@@:
jmp redraw_all
.not_scl:
or esi, -1 or esi, -1
cmp eax, 'bck' cmp eax, 'bck'
jz next_or_prev_handler jz next_or_prev_handler
@ -968,8 +985,7 @@ proc find_last_name_component
endp endp
proc init_frame _img proc init_frame uses ebx edx, _img
push ebx edx
mov eax, [orig_image] mov eax, [orig_image]
cmp eax, [_img] cmp eax, [_img]
jz .exit jz .exit
@ -997,7 +1013,6 @@ proc init_frame _img
mov [pict.top], 0 mov [pict.top], 0
mov [pict.left], 0 mov [pict.left], 0
.exit: .exit:
pop edx ebx
ret ret
endp endp
@ -1077,8 +1092,7 @@ proc draw_window
endp endp
proc draw_view proc draw_view uses ebx esi edi
push ebx esi edi
cmp [scale_mode], LIBIMG_SCALE_FIT_MIN cmp [scale_mode], LIBIMG_SCALE_FIT_MIN
jnz .scale_none jnz .scale_none
mov ecx, [cur_frame] mov ecx, [cur_frame]
@ -1114,14 +1128,30 @@ proc draw_view
push [view_abs_left] ; xpos push [view_abs_left] ; xpos
invoke img.draw, [cur_frame] invoke img.draw, [cur_frame]
.done: .done:
pop edi esi ebx
ret ret
endp endp
proc draw_scale_button
pushad
mcall 65, buttons+scalebtn*20, <20,20>, [scale_button_xy], 8, palette
mov ebx, [scale_button_xy]
add ebx, 0x00050006
; print letter(s) corresponding to the current scaling mode
mov edi, 2
mov [scale_button_letter], 'x1'
cmp [scale_mode], LIBIMG_SCALE_NONE
jz @f
add ebx, 0x00020001
mov edi, 1
mov [scale_button_letter], 'W'
; cmp [scale_mode], LIBIMG_SCALE_FIT_MIN
@@:
mcall 4, , 0x800100ff, scale_button_letter
popad
ret
endp
proc draw_toolbar proc draw_toolbar uses ebx esi edi
push ebx esi edi
cmp [toolbar.height], 0 cmp [toolbar.height], 0
jz .quit jz .quit
mov ebx, [toolbar_abs_left] mov ebx, [toolbar_abs_left]
@ -1154,6 +1184,8 @@ proc draw_toolbar
mcall mcall
add ebx, ((5+25*2) SHL 16)+(5+25*2) add ebx, ((5+25*2) SHL 16)+(5+25*2)
mcall mcall
add ebx, ((5+25*1) SHL 16)+(5+25*1)
mcall
mov ebx, [toolbar_abs_left] mov ebx, [toolbar_abs_left]
add ebx, [toolbar.width] add ebx, [toolbar.width]
sub ebx, 25*5+10 sub ebx, 25*5+10
@ -1178,6 +1210,8 @@ proc draw_toolbar
mcall , , , 'bgr'+40000000h mcall , , , 'bgr'+40000000h
add ebx, (0+25*1) SHL 16 add ebx, (0+25*1) SHL 16
mcall , , , 'sld'+40000000h mcall , , , 'sld'+40000000h
add ebx, (5+25*1) SHL 16
mcall , , , 'scl'+40000000h
mov ebx, [toolbar_abs_left] mov ebx, [toolbar_abs_left]
add ebx, [toolbar.width] add ebx, [toolbar.width]
sub ebx, 25*5+10 sub ebx, 25*5+10
@ -1209,6 +1243,10 @@ proc draw_toolbar
mcall , buttons+bgrbtn *20 mcall , buttons+bgrbtn *20
add edx, ((0+25*1) SHL 16)+0 add edx, ((0+25*1) SHL 16)+0
mcall , buttons+slidebtn *20 mcall , buttons+slidebtn *20
add edx, ((5+25*1) SHL 16)+0
; mcall , buttons+scalebtn *20
mov [scale_button_xy], edx
call draw_scale_button
mov edx, [client_abs_left] mov edx, [client_abs_left]
add edx, [client.width] add edx, [client.width]
sub edx, 25*5+4 sub edx, 25*5+4
@ -1226,7 +1264,6 @@ proc draw_toolbar
mcall , buttons+rot180btn*20 mcall , buttons+rot180btn*20
.quit: .quit:
pop edi esi ebx
ret ret
endp endp
@ -1539,29 +1576,6 @@ proc bin2dec
endp endp
proc is_root_dir _path
push ecx esi
mov esi, [_path]
xor ecx, ecx
@@:
lodsb
test al, al
jz .done
cmp al, '/'
jnz @b
inc ecx
jmp @b
.done:
xor eax, eax
cmp ecx, 3
jz @f
mov eax, -2
@@:
pop esi ecx
ret
endp
; fills window_header with window title ; fills window_header with window title
; window title is generated as '[k/n] <filename> - Kolibri Image Viewer' ; window title is generated as '[k/n] <filename> - Kolibri Image Viewer'
; n = total files in dir ; n = total files in dir
@ -1579,8 +1593,8 @@ proc generate_window_header
call bin2dec call bin2dec
mov byte[edi], '/' mov byte[edi], '/'
inc edi inc edi
stdcall is_root_dir, path mov eax, [directory_ptr]
add eax, [files_num] mov eax, [eax+4]
call bin2dec call bin2dec
mov word[edi], '] ' mov word[edi], '] '
add edi, 2 add edi, 2
@ -2145,6 +2159,8 @@ proc recalc_work
jnz .recalc_canvas jnz .recalc_canvas
stdcall cmp_box, canvas, canvas_prev stdcall cmp_box, canvas, canvas_prev
jnz .recalc_canvas jnz .recalc_canvas
cmp [bScaleModeChanged], 0
jnz .recalc_canvas
jmp .recalc_canvas_done jmp .recalc_canvas_done
.recalc_canvas: .recalc_canvas:
stdcall recalc_canvas stdcall recalc_canvas
@ -2173,7 +2189,7 @@ DATA
s_header db ' - Kolibri Image Viewer',0 s_header db ' - Kolibri Image Viewer',0
window_style dd 0x53FFFFFF window_style dd 0x53FFFFFF
window BOX 101, 144, 750, 600 ; left top width height window BOX 101, 144, 529, 324 ; left top width height
window_prev BOX 0, 0, 0, 0 window_prev BOX 0, 0, 0, 0
window_save BOX 0, 0, 0, 0 ; restore after slide show window_save BOX 0, 0, 0, 0 ; restore after slide show
client BOX 0, 0, 0, 0 client BOX 0, 0, 0, 0
@ -2345,7 +2361,7 @@ virtual at 0
file 'kivicons.bmp':0xA,4 file 'kivicons.bmp':0xA,4
load offbits dword from 0 load offbits dword from 0
end virtual end virtual
numimages = 10 numimages = 11
openbtn = 0 openbtn = 0
backbtn = 1 backbtn = 1
forwardbtn = 2 forwardbtn = 2
@ -2356,12 +2372,13 @@ rotcwbtn = 6
rotccwbtn = 7 rotccwbtn = 7
rot180btn = 8 rot180btn = 8
slidebtn = 9 slidebtn = 9
scalebtn = 10
palette: palette:
file 'kivicons.bmp':0x36,offbits-0x36 file 'kivicons.bmp':0x36,offbits-0x36
buttons: buttons:
file 'kivicons.bmp':offbits file 'kivicons.bmp':offbits
repeat 10 repeat 11
y = %-1 y = %-1
z = 20-% z = 20-%
repeat numimages*5 repeat numimages*5
@ -2492,7 +2509,7 @@ readdir_fileinfo:
dd 0 dd 0
readblocks dd 0 readblocks dd 0
directory_ptr dd 0 directory_ptr dd 0
curdir db 1024 dup (?) curdir rb 1024
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
I_END: I_END:
@ -2520,6 +2537,8 @@ last_name_component rd 1
toolbar.height_old rd 1 toolbar.height_old rd 1
procinfo process_information procinfo process_information
scale_button_xy dd ?
scale_button_letter dd ? ; i.e. 'x1',0
align 16 align 16
path rb 4096 path rb 4096
window_header rb 256 window_header rb 256

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB