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