Skip to content

Commit

Permalink
Merge pull request #29 from fox32-arch/textbox_sl
Browse files Browse the repository at this point in the history
`textbox_sl` Single-line textbox widgets
  • Loading branch information
ry755 authored Jun 16, 2024
2 parents 9a46d8d + 94e5f38 commit 7f90022
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 33 deletions.
2 changes: 1 addition & 1 deletion applications/fetcher/OS.okm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(* FIXME: this module should probably be moved somewhere global so all applications can use it *)

MODULE OS;
CONST WINDOW_STRUCT_SIZE = 36;
CONST WINDOW_STRUCT_SIZE = 40;
CONST FILE_STRUCT_SIZE = 32;

EXTERN PROCEDURE new_window, destroy_window, draw_str_to_overlay, get_window_overlay_number,
Expand Down
4 changes: 2 additions & 2 deletions applications/foxpaint/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ drag_or_close_tools_window:
ret

canvas_window_title: data.strz "FoxPaint canvas"
canvas_window_struct: data.fill 0, 36
canvas_window_struct: data.fill 0, 40

tools_window_title: data.strz "FoxPaint tools"
tools_window_struct: data.fill 0, 36
tools_window_struct: data.fill 0, 40

color_section_text: data.strz "Color "
color_button_black_widget:
Expand Down
2 changes: 1 addition & 1 deletion applications/launcher/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ close_window:
call end_current_task

window_title: data.strz "Launcher"
window_struct: data.fill 0, 36
window_struct: data.fill 0, 40

terminal_button_fxf: data.strz "terminal.fxf"
terminal_button_widget:
Expand Down
2 changes: 1 addition & 1 deletion applications/okmpaint/OkmPaint.okm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MODULE OkmPaint;
drawing: CHAR;
size: CHAR;
color: INT;
canvasWindow: ARRAY 36 OF CHAR;
canvasWindow: ARRAY 40 OF CHAR;

PROCEDURE Main();
BEGIN
Expand Down
2 changes: 1 addition & 1 deletion applications/terminal/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ sh_fxf_missing_yield_loop:
rjmp sh_fxf_missing_yield_loop

window_title: data.strz "Terminal"
window_struct: data.fill 0, 36
window_struct: data.fill 0, 40

sh_fxf_name: data.strz "sh.fxf"
sh_fxf_missing_str: data.str "sh could not be launched! hanging here" data.8 10 data.8 0
Expand Down
8 changes: 6 additions & 2 deletions fox32os.def
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,19 @@ copy: jmp [0x00000D30]
; widget jump table
draw_widgets_to_window: jmp [0x00000E10]
handle_widget_click: jmp [0x00000E14]
handle_widget_key_down: jmp [0x00000E18]
handle_widget_key_up: jmp [0x00000E1C]

; resource jump table
get_resource: jmp [0x00000F10]

; event types
const EVENT_TYPE_BUTTON_CLICK: 0x80000000
const EVENT_TYPE_BUTTON_CLICK: 0x80000000
const EVENT_TYPE_TEXTBOX_REFRESH: 0x80000001

; widget types
const WIDGET_TYPE_BUTTON: 0x00000000
const WIDGET_TYPE_BUTTON: 0x00000000
const WIDGET_TYPE_TEXTBOX_SL: 0x00000001

; window flags
const WINDOW_FLAG_ALWAYS_BACKGROUND: 1
2 changes: 2 additions & 0 deletions kernel/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ jump_table:
org.pad 0x00000610
data.32 draw_widgets_to_window
data.32 handle_widget_click
data.32 handle_widget_key_down
data.32 handle_widget_key_up

; resource jump table
org.pad 0x00000710
Expand Down
87 changes: 87 additions & 0 deletions kernel/widget/textbox_sl.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
; textbox_sl widget routines

; textbox_sl widget struct:
; data.32 next_ptr - pointer to next widget, or 0 for none
; data.32 id - the ID number of this widget
; data.32 type - the type of this widget
; data.32 buffer_ptr - pointer to null-terminated input string
; data.32 foreground_color - text foreground color
; data.32 background_color - textbox_sl background color
; data.16 width - width of this textbox_sl
; data.16 buffer_max - maximum input length including null-terminator
; data.16 x_pos - X coordinate of this widget
; data.16 y_pos - Y coordinate of this widget

const TEXTBOX_SL_WIDGET_STRUCT_SIZE: 32 ; 8 words = 32 bytes
const TEXTBOX_SL_HEIGHT: 20

; draw a textbox_sl widget to a window
; inputs:
; r0: pointer to window struct
; r1: pointer to a null-terminated input string
; r2: foreground color
; r3: background color
; r4: textbox_sl width
; r5: X coordinate
; r6: Y coordinate
; r7: non-zero if textbox is active
draw_textbox_sl_widget:
push r0
push r1
push r2
push r3
push r4
push r5
push r10

call get_window_overlay_number
mov r10, r0

push r1
push r2
push r3
push r4
push r5
mov r0, r5
mov r1, r6
mov r2, r4
mov r4, r3
push r4
cmp r7, 0
ifz jmp draw_textbox_sl_widget_not_active
not r4
or r4, 0xFF000000
draw_textbox_sl_widget_not_active:
mov r3, TEXTBOX_SL_HEIGHT
mov r5, r10
call draw_filled_rectangle_to_overlay
sub r2, 4
sub r3, 4
add r0, 2
add r1, 2
pop r4
call draw_filled_rectangle_to_overlay
pop r5
pop r4
pop r3
pop r2
pop r1

mov r4, r3
mov r3, r2
mov r0, r1
mov r1, r5
add r1, 2
mov r2, r6
add r2, 2
mov r5, r10
call draw_str_to_overlay

pop r10
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
ret
Loading

0 comments on commit 7f90022

Please sign in to comment.