Add window resizing

This commit is contained in:
shikhin 2023-03-23 07:20:41 +05:30
parent f4b0adc4da
commit 89f2e15d0b
1 changed files with 90 additions and 17 deletions

107
shell.asm
View File

@ -18,6 +18,9 @@ endstruc
WINDOW_MOVE equ 1 WINDOW_MOVE equ 1
WINDOW_RESIZE equ 2 WINDOW_RESIZE equ 2
WINDOW_MIN_WIDTH equ 4
WINDOW_MIN_HEIGHT equ 2
cpu 8086 cpu 8086
bits 16 bits 16
@ -188,7 +191,7 @@ mouse:
.not_move: .not_move:
cmp byte [si + window.status], WINDOW_RESIZE cmp byte [si + window.status], WINDOW_RESIZE
jne .not_resize jne .not_resize
;call window_resize call resize
.not_resize: .not_resize:
sub cx, [si + window.x] sub cx, [si + window.x]
@ -237,6 +240,40 @@ mouse:
call forward_event call forward_event
ret ret
; in:
; ax = window ID
; bx = Y coördinate
; cx = X coördinate
; si = pointer to window structure
resize:
push dx
mov dx, [si + window.res_y]
sub dx, bx
jc .x
cmp dx, WINDOW_MIN_HEIGHT
jl .x
mov [si + window.y], bx
mov [si + window.height], dx
.x:
mov dx, [si + window.res_x]
sub dx, cx
jc .done
cmp dx, WINDOW_MIN_WIDTH
jl .done
mov [si + window.x], cx
mov [si + window.width], dx
.done:
pop dx
call render_file_window
call request_redraw
ret
; in: ; in:
; ax = window ID ; ax = window ID
; bx = Y coördinate ; bx = Y coördinate
@ -287,8 +324,8 @@ click:
; If clicked the window close button ; If clicked the window close button
mov ax, [si + window.x] mov ax, [si + window.x]
;cmp ax, cx cmp ax, cx
;je .resize je .resize
add ax, [si + window.width] add ax, [si + window.width]
dec ax dec ax
cmp ax, cx cmp ax, cx
@ -296,8 +333,17 @@ click:
.move: .move:
mov byte [si + window.status], WINDOW_MOVE mov byte [si + window.status], WINDOW_MOVE
sub cx, [si + window.x] sub cx, [si + window.x]
mov [si + window.res_x], cx mov [si + window.res_x], cx ; In-window x-coordinate of press
jmp .end jmp .end
.resize:
mov byte [si + window.status], WINDOW_RESIZE
add cx, [si + window.width]
mov [si + window.res_x], cx ; Lower right corner + 1
add bx, [si + window.height]
mov [si + window.res_y], bx ; Lower right corner + 1
jmp .end
.close: .close:
call hide_file_window call hide_file_window
jmp .end jmp .end
@ -341,6 +387,43 @@ click:
pop dx pop dx
ret ret
; in
; si = pointer to window structure
render_file_window:
push ax
push cx
push dx
push es
mov ax, cs
mov es, ax
mov di, [si + window.data]
mov cx, [si + window.width]
mov ax, 0x0f00
rep stosw
mov cx, (ROWS-1)*COLUMNS
mov ax, 0xf000
rep stosw
mov di, [si + window.data]
mov byte [di], 'A'
mov byte [di + 2], ':'
add di, [si + window.width]
add di, [si + window.width]
mov byte [di - 2], 'x'
mov cx, [si + window.height]
dec cx
mov dx, [si + window.width]
call print_ls
pop es
pop dx
pop cx
pop ax
ret
show_file_window: show_file_window:
cmp byte [file_window_visible], 0 cmp byte [file_window_visible], 0
jne .already_visible jne .already_visible
@ -356,15 +439,8 @@ show_file_window:
mov [windows + 1*window.size + window.next], ax mov [windows + 1*window.size + window.next], ax
; Populate file window contents ; Populate file window contents
mov ax, cs mov si, windows + 1*window.size
mov es, ax call render_file_window
mov di, file_window
add di, [windows + 1*window.size + window.width]
add di, [windows + 1*window.size + window.width]
mov cx, [windows + 1*window.size + window.height]
dec cx
mov dx, [windows + 1*window.size + window.width]
call print_ls
pop ax pop ax
@ -851,10 +927,7 @@ disk_icon:
db 0x00, 0x0f, 0x00, 0x0f, '|', 0x0f, 0x00, 0x0f, 0x00, 0x0f db 0x00, 0x0f, 0x00, 0x0f, '|', 0x0f, 0x00, 0x0f, 0x00, 0x0f
file_window: file_window:
db 'A', 0x0f, ':', 0x0f times ROWS*COLUMNS db 0, 0xf0
times 37 db ' ', 0x0f
db 'x', 0x0f
times 15*40 db 0, 0xf0
windows: windows:
times window.size db 0 times window.size db 0