Add scroll up/down buttons, space handling

This commit is contained in:
shikhin 2023-03-26 05:24:39 +05:30
parent f3a1e6ca5f
commit 3c7741bdc9
1 changed files with 96 additions and 31 deletions

View File

@ -8,7 +8,7 @@ WINDOW_STATUS_RESIZE equ 2
; Resize button, title, space, close button
WINDOW_MIN_WIDTH equ 1 + 8 + 1 + 1
WINDOW_MIN_HEIGHT equ 2
WINDOW_MIN_HEIGHT equ 3
; 0x0000
jmp near process_event
@ -52,15 +52,9 @@ initialize:
mov [cur_file_address + 2], ax
mov [cur_file_address], bx
mov [beg_file_address], bx
shl cx, 1 ; 2
shl cx, 1 ; 4
shl cx, 1 ; 8
shl cx, 1 ; 16
shl cx, 1 ; 32
shl cx, 1 ; 64
shl cx, 1 ; 128
shl cx, 1 ; 256
shl cx, 1 ; 512
mov ch, cl
xor cl, cl
shl cx, 1 ; Multiply by 512
add bx, cx
mov [end_file_address], bx
@ -484,7 +478,7 @@ event_click:
call deallocate_own_memory
; We don't need to call request_redraw here, since
; it will be called unconditionally above
jmp .title_bar_end
jmp .end
.not_close:
; Did the user click on the resize button?
@ -492,7 +486,7 @@ event_click:
jne .not_resize
.resize:
mov byte [window_status], WINDOW_STATUS_RESIZE
jmp .title_bar_end
jmp .end
.not_resize:
; Clicking on the title bar signals beginning of a window
@ -501,9 +495,46 @@ event_click:
mov ax, [window_x]
sub ax, cx
mov [window_move_x_offset], ax
.title_bar_end:
.not_title_bar:
jmp .end
.not_title_bar:
mov ax, [window_x]
add ax, [window_width]
dec ax
cmp ax, cx
jne .not_scroll_bar
; Scroll up button?
mov ax, [window_y]
inc ax
cmp ax, bx
jne .not_scroll_up
.scroll_up:
call file_prev_line
test dx, dx
jz .end
call render_window
call request_redraw
jmp .end
.not_scroll_up:
; Scroll down button?
add ax, [window_height]
dec ax
dec ax
cmp ax, bx
jne .not_scroll_down
.scroll_down:
call file_next_line
test dx, dx
jz .end
call render_window
call request_redraw
.not_scroll_down:
.not_scroll_bar:
.end:
pop ax
ret
@ -518,23 +549,44 @@ event_click:
event_keyboard:
cmp ch, 0x50 ; down key
jne .up_key_check
call file_next_line
test dx, dx
jz .ret
.down_key:
call file_next_line
test dx, dx
jz .ret
call render_window
call request_redraw
ret
call render_window
call request_redraw
.up_key_check:
cmp ch, 0x48 ; up key
jne .space_check
.up_key:
call file_prev_line
test dx, dx
jz .ret
call render_window
call request_redraw
ret
.space_check:
cmp cl, ' '
jne .ret
call file_prev_line
test dx, dx
jz .ret
call render_window
call request_redraw
.space:
; Go down eight lines
xor ax, ax
mov cx, 8
.loop:
call file_next_line
or ax, dx
loop .loop
test ax, ax
jz .ret
call render_window
call request_redraw
.ret:
ret
@ -720,6 +772,19 @@ render_window:
add di, [window_width]
call print_file
add di, [window_width]
add di, [window_width]
sub di, 2
mov byte [di], 0x1E ; up
mov ax, [window_width]
mov cx, [window_height]
sub cx, 2
shl cx, 1
mul cx
add di, ax
mov byte [di], 0x1F ; down
pop di
pop si
pop dx
@ -893,10 +958,10 @@ beg_file_address: dw 0
end_file_address: dw 0
window_next dw 0xffff
window_x dw 4
window_y dw 12
window_width dw 32
window_height dw 8
window_x dw 17
window_y dw 7
window_width dw 52
window_height dw 16
window_mouse_released_inside db 0
window_status db WINDOW_STATUS_NORMAL