Move to API

This commit is contained in:
saintfrater 2026-02-09 11:51:58 +01:00
commit 3df0ede39e
3 changed files with 169 additions and 174 deletions

View file

@ -59,7 +59,7 @@ section .text
%include "./gui/lib.asm" %include "./gui/lib.asm"
%include "./gui/draw.asm" %include "./gui/draw.asm"
reset: entrycode:
cli cli
; il n'existe aucun 'stack' par défaut ; il n'existe aucun 'stack' par défaut
mov ax, STACK_SEG mov ax, STACK_SEG
@ -112,7 +112,7 @@ reset:
main_loop: main_loop:
call gui_process_all call gui_process_all
GUI GUI_GET_VAL, 5 ; slider GUI OBJ_GET_VAL, 5 ; slider
;GFX GOTOXY, 5, 20 ;GFX GOTOXY, 5, 20
;call print_word_hex ;call print_word_hex
@ -131,77 +131,23 @@ build_interface:
; mais on configure DS=GUI_RAM_SEG pour l'allocation ; mais on configure DS=GUI_RAM_SEG pour l'allocation
; Créer Bouton 1 "QUITTER" ; Créer Bouton 1 "QUITTER"
call gui_alloc_widget ; Retourne SI = Pointeur nouveau slot GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 10, 10, 80, 16, str_quit, cs
jc .mem_full
; Remplir les propriétés
mov word [gs:si + widget.x], 10
mov word [gs:si + widget.y], 10
mov word [gs:si + widget.w], 80
mov word [gs:si + widget.h], 16
mov word [gs:si + widget.text_ofs], str_quit
; mov byte [gs:si + widget.user_id], 1 ; Style "Bouton par défaut" (OK)
mov word [gs:si + widget.text_seg], cs ; Texte est dans la ROM
mov word [gs:si + widget.event_click], on_click_quit ; Fonction à appeler
mov byte [gs:si + widget.type], WIDGET_TYPE_ROUND_BUTTON
; Créer Bouton 2 "HELLO" ; Créer Bouton 2 "HELLO"
call gui_alloc_widget GUI OBJ_CREATE, OBJ_TYPE_BUTTON_ROUNDED, 100, 50, 80, 16, str_hello, cs
jc .mem_full
mov word [gs:si + widget.x], 100
mov word [gs:si + widget.y], 50
mov word [gs:si + widget.w], 80
mov word [gs:si + widget.h], 16
mov word [gs:si + widget.text_ofs], str_hello
mov word [gs:si + widget.text_seg], cs
mov byte [gs:si + widget.type], WIDGET_TYPE_ROUND_BUTTON
; Créer checkbox 3 "option 1" ; Créer checkbox 3 "option 1"
call gui_alloc_widget GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50, 100, 15, str_option1, cs
jc .mem_full GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16, 100, 15, str_option2, cs
GUI OBJ_CREATE, OBJ_TYPE_CHECKBOX, 200, 50+16*2, 100, 15, str_option3, cs
mov word [gs:si + widget.x], 200
mov word [gs:si + widget.y], 50
mov word [gs:si + widget.w], 100
mov word [gs:si + widget.h], 15
mov word [gs:si + widget.text_ofs], str_option1
mov word [gs:si + widget.text_seg], cs
mov byte [gs:si + widget.type], WIDGET_TYPE_CHECKBOX
; Pas de callback
; Créer checkbox 3 "option 2"
call gui_alloc_widget
jc .mem_full
mov word [gs:si + widget.x], 200
mov word [gs:si + widget.y], 50+16
mov word [gs:si + widget.w], 100
mov word [gs:si + widget.h], 15
mov word [gs:si + widget.text_ofs], str_option2
mov word [gs:si + widget.text_seg], cs
mov byte [gs:si + widget.type], WIDGET_TYPE_CHECKBOX
; Créer checkbox 3 "option 2"
call gui_alloc_widget
jc .mem_full
mov word [gs:si + widget.x], 200
mov word [gs:si + widget.y], 50+16*2
mov word [gs:si + widget.w], 100
mov word [gs:si + widget.h], 15
mov word [gs:si + widget.text_ofs], str_option3
mov word [gs:si + widget.text_seg], cs
mov byte [gs:si + widget.type], WIDGET_TYPE_CHECKBOX
; Créer Slider (Drag) ; Créer Slider (Drag)
; GUI OBJ_CREATE, OBJ_TYPE_SLIDER,
call gui_alloc_widget call gui_alloc_widget
jc .mem_full jc .mem_full
mov word [gs:si + widget.x], 10 mov word [gs:si + widget.x], 10
mov word [gs:si + widget.y], 100 mov word [gs:si + widget.y], 100
mov word [gs:si + widget.w], 150 mov word [gs:si + widget.w], 150
mov word [gs:si + widget.h], 12 mov word [gs:si + widget.h], 12
mov byte [gs:si + widget.type], WIDGET_TYPE_SLIDER mov byte [gs:si + widget.type],OBJ_TYPE_SLIDER
mov byte [gs:si + widget.attr_mode], SLIDER_HORIZONTAL mov byte [gs:si + widget.attr_mode], SLIDER_HORIZONTAL
mov word [gs:si + widget.attr_min], 10 ; X Min mov word [gs:si + widget.attr_min], 10 ; X Min
mov word [gs:si + widget.attr_max], 140 ; X Max (Widget.x + W - ThumbW) mov word [gs:si + widget.attr_max], 140 ; X Max (Widget.x + W - ThumbW)
@ -216,7 +162,7 @@ build_interface:
mov word [gs:si + widget.y], 10 mov word [gs:si + widget.y], 10
mov word [gs:si + widget.w], 16 mov word [gs:si + widget.w], 16
mov word [gs:si + widget.h], 150 mov word [gs:si + widget.h], 150
mov byte [gs:si + widget.type], WIDGET_TYPE_SLIDER mov byte [gs:si + widget.type], OBJ_TYPE_SLIDER
mov byte [gs:si + widget.attr_mode], SLIDER_VERTICAL mov byte [gs:si + widget.attr_mode], SLIDER_VERTICAL
mov word [gs:si + widget.attr_min], 10 ; X Min mov word [gs:si + widget.attr_min], 10 ; X Min
mov word [gs:si + widget.attr_max], 140 ; X Max (Widget.x + W - ThumbW) mov word [gs:si + widget.attr_max], 140 ; X Max (Widget.x + W - ThumbW)
@ -268,7 +214,7 @@ global reset_vector
reset_vector: reset_vector:
; code minimal au reset ; code minimal au reset
jmp 0xF000:reset jmp 0xF000:entrycode
builddate: builddate:
db __DATE__ db __DATE__

View file

@ -51,25 +51,30 @@ gui_draw_single_widget:
mov [gs:si + widget.y2], dx mov [gs:si + widget.y2], dx
; Dispatch selon le type ; Dispatch selon le type
cmp byte [gs:si + widget.type], WIDGET_TYPE_SLIDER cmp byte [gs:si + widget.type], OBJ_TYPE_LABEL
jne .case_1
jmp .done
.case_1:
cmp byte [gs:si + widget.type], OBJ_TYPE_SLIDER
jne .case_2 jne .case_2
call draw_slider call draw_slider
jmp .done jmp .done
.case_2: .case_2:
cmp byte [gs:si + widget.type], WIDGET_TYPE_BUTTON cmp byte [gs:si + widget.type], OBJ_TYPE_BUTTON
jne .case_3 jne .case_3
call draw_button call draw_button
jmp .done jmp .done
.case_3: .case_3:
cmp byte [gs:si + widget.type], WIDGET_TYPE_ROUND_BUTTON cmp byte [gs:si + widget.type], OBJ_TYPE_BUTTON_ROUNDED
jne .case_4 jne .case_4
call draw_round_button call draw_round_button
jmp .done jmp .done
.case_4: .case_4:
cmp byte [gs:si + widget.type], WIDGET_TYPE_CHECKBOX cmp byte [gs:si + widget.type], OBJ_TYPE_CHECKBOX
jne .case_5 jne .case_5
call draw_checkbox call draw_checkbox
jmp .done jmp .done

View file

@ -35,13 +35,14 @@
%define GUI_STATE_DISABLED 4 ; Grisé %define GUI_STATE_DISABLED 4 ; Grisé
; --- Types de Widgets --- ; --- Types de Widgets ---
%define WIDGET_TYPE_BUTTON 0 %define OBJ_TYPE_LABEL 0
%define WIDGET_TYPE_SLIDER 1 %define OBJ_TYPE_BUTTON 1
%define WIDGET_TYPE_LABEL 2 %define OBJ_TYPE_SLIDER 2
%define WIDGET_TYPE_ROUND_BUTTON 3 %define OBJ_TYPE_BUTTON_ROUNDED 3
%define WIDGET_TYPE_CHECKBOX 4 %define OBJ_TYPE_CHECKBOX 4
; --- Widgets attributs --- ; --- Widgets attributs ---
%define BUTTON_DEFAULT 0
%define BUTTON_OK 1 %define BUTTON_OK 1
%define SLIDER_HORIZONTAL 1 %define SLIDER_HORIZONTAL 1
@ -51,11 +52,11 @@
; SECTION : API ACTIONS ; SECTION : API ACTIONS
; ============================================================================= ; =============================================================================
%define GUI_CREATE 0 %define OBJ_CREATE 0
%define GUI_DESTROY 1 %define OBJ_DESTROY 1
%define GUI_GET_STATE 2 %define OBJ_GET_STATE 2
%define GUI_GET_TYPE 3 %define OBJ_GET_TYPE 3
%define GUI_GET_VAL 4 %define OBJ_GET_VAL 4
gui_api_table: gui_api_table:
dw gui_api_create dw gui_api_create
@ -110,21 +111,62 @@ endstruc
; gui_api_create ; gui_api_create
; Crée un widget et retourne son ID ; Crée un widget et retourne son ID
; Out: AX = ID ou -1 si erreur ; Out: AX = ID ou -1 si erreur
;
; widget_type, x, y, w, h, text_ofs, text_seg
;
; ----------------------------------------------------------------------------- ; -----------------------------------------------------------------------------
%define .type word [bp+4]
%define .x word [bp+6]
%define .y word [bp+8]
%define .w word [bp+10]
%define .h word [bp+12]
%define .text_ofs word [bp+14]
%define .text_seg word [bp+16]
gui_api_create: gui_api_create:
push bp
mov bp, sp
push gs
mov ax, GUI_RAM_SEG
mov gs, ax
call gui_alloc_widget ; Returns GS:SI call gui_alloc_widget ; Returns GS:SI
jc .error mov ax, -1
jc .done
; ID = SI / widget_size ; ID = SI / widget_size
mov ax, si mov ax, si
xor dx, dx xor dx, dx
mov cx, widget_size mov cx, widget_size
div cx div cx
ret
.error: mov ax, .type
mov ax, -1 mov byte [gs:si + widget.type], al
mov ax, .x
mov word [gs:si + widget.x], ax
mov ax, .y
mov word [gs:si + widget.y], ax
mov ax, .w
mov word [gs:si + widget.w], ax
mov ax, .h
mov word [gs:si + widget.h], ax
mov ax, .text_ofs
mov word [gs:si + widget.text_ofs], ax
mov ax, .text_seg
mov word [gs:si + widget.text_seg], ax
mov byte [gs:si + widget.state], GUI_STATE_NORMAL
mov byte [gs:si + widget.oldstate], 0
.done:
leave
pop gs
ret ret
%undef .type
%undef .x
%undef .y
%undef .w
%undef .h
%undef .text_ofs
%undef .text_seg
; ----------------------------------------------------------------------------- ; -----------------------------------------------------------------------------
; gui_api_get_state ; gui_api_get_state
@ -319,7 +361,7 @@ gui_alloc_widget:
.found: .found:
; On initialise le slot trouvé ; On initialise le slot trouvé
mov byte [gs:si + widget.state], GUI_STATE_NORMAL ; Marquer comme occupé mov byte [gs:si + widget.state], GUI_STATE_NORMAL ; Marquer comme occupé
mov byte [gs:si + widget.type], WIDGET_TYPE_BUTTON ; Type par défaut mov byte [gs:si + widget.type], OBJ_TYPE_BUTTON ; Type par défaut
mov byte [gs:si + widget.oldstate], 0 ; doit etre dessiné mov byte [gs:si + widget.oldstate], 0 ; doit etre dessiné
; Reset des champs critiques pour éviter les déchets ; Reset des champs critiques pour éviter les déchets
@ -475,43 +517,41 @@ gui_update_logic:
mov bl, [BDA_MOUSE + mouse.status] mov bl, [BDA_MOUSE + mouse.status]
.case_0:
cmp byte [gs:si + widget.type], OBJ_TYPE_LABEL
jne .case_1
call gui_logic_label
jmp .done
.case_1:
; Dispatch selon le type ; Dispatch selon le type
cmp byte [gs:si + widget.type], WIDGET_TYPE_SLIDER cmp byte [gs:si + widget.type], OBJ_TYPE_SLIDER
jne .case_2 jne .case_2
call gui_logic_slider call gui_logic_slider
jmp .done jmp .done
.case_2: .case_2:
cmp byte [gs:si + widget.type], WIDGET_TYPE_BUTTON cmp byte [gs:si + widget.type], OBJ_TYPE_BUTTON
jne .case_3 jne .case_3
call gui_logic_button call gui_logic_button
jmp .done jmp .done
.case_3: .case_3:
cmp byte [gs:si + widget.type], WIDGET_TYPE_ROUND_BUTTON cmp byte [gs:si + widget.type], OBJ_TYPE_BUTTON_ROUNDED
jne .case_4 jne .case_4
call gui_logic_button call gui_logic_button
jmp .done jmp .done
.case_4: .case_4:
cmp byte [gs:si + widget.type], WIDGET_TYPE_CHECKBOX cmp byte [gs:si + widget.type], OBJ_TYPE_CHECKBOX
jne .case_5 jne .case_5
call gui_logic_checkbox call gui_logic_checkbox
jmp .done
.case_5: .case_5:
jmp .done jmp .done
.miss: .miss:
; Si on n'est plus dessus, mais qu'on l'était avant (HOVER/PRESSED), il faut redessiner !
cmp byte [gs:si + widget.state], GUI_STATE_NORMAL
je .done ; Déjà normal, rien à faire
; Cas particulier : si c'est un slider en cours de drag, on continue la logique
; cmp byte [gs:si + widget.type], WIDGET_TYPE_SLIDER
; jne .reset_state
; cmp byte [gs:si + widget.state], GUI_STATE_PRESSED
; je .gui_logic_slider
.reset_state:
mov byte [gs:si + widget.state], GUI_STATE_NORMAL mov byte [gs:si + widget.state], GUI_STATE_NORMAL
xor ax, ax xor ax, ax
@ -519,6 +559,10 @@ gui_update_logic:
pop ds pop ds
ret ret
; --- Logique spécifique LABEL ---
gui_logic_label:
ret
; --- Logique spécifique Bouton --- ; --- Logique spécifique Bouton ---
gui_logic_button: gui_logic_button:
test bl, 1 ; Clic gauche ? test bl, 1 ; Clic gauche ?