A2osX/LIB/LIBGUI.S.MENU.txt
2022-10-25 08:05:54 +02:00

1032 lines
16 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
*--------------------------------------
* NewMenu(pMENU, x, y)
*--------------------------------------
MENU.New >PULLW DY
>PULLW DX
>PULLYA
>STYA ZPPtr1 MENU definition
>STYA ZPObjPtr for pass #2
ldx MENU.Stack.Cnt
cpx #MENU.MAX
beq .90
jsr MENU.GetSize
>SYSCALL2 GetMem
bcs .99
>STYA ZPMENUPtr
txa hMenu
ldx MENU.Stack.Cnt
sta MENU.Stack,x
lda #S.OBJ.T.MENU
sta (ZPMENUPtr) S.OBJ.T
lda #0
ldy #S.MENU.Items-1
.1 sta (ZPMENUPtr),y
dey
bne .1
ldx #3
ldy #S.OBJ.X1+3
.2 lda DX,x
sta (ZPMENUPtr),y
dey
dex
bpl .2
>LDYA ZPObjPtr
>STYA ZPPtr1 MENU definition
jsr MENU.GetData
ldx MENU.Stack.Cnt
lda MENU.Stack,x
>SYSCALL2 GetMemPtr
>STYA ZPMENUPtr
jsr MENU.SetMenuSizePos
ldx MENU.Stack.Cnt
lda MENU.Stack,x
inc MENU.Stack.Cnt
clc
rts
.90 lda #E.OOH
sec
.99
MENU.New.RTS rts
*--------------------------------------
* ZPPtr1 = defintion
*--------------------------------------
MENU.GetSize lda #S.MENU.Items+1 Ending\0
sta Counter
stz Counter+1
.1 lda (ZPPtr1)
beq .8
lda #S.MITEM
clc
adc Counter
sta Counter
bcc .2
inc Counter+1
.2 lda (ZPPtr1)
cmp #S.MITEM.T.SEP
bne .3
inc ZPPtr1
bne .1
inc ZPPtr1+1
bra .1
.3 cmp #S.MITEM.T.ITEM
bne .4
lda #6 T+ID+KEMOD+KEY+pICON+"TEXT"
bra .5
.4 lda #5 T+pMENU+pICON+"TEXT"
.5 jsr SkipAPtr1
jsr SkipStrZPtr1 skip "TEXT\0"
bra .1
.8 >LDYA Counter
rts
*--------------------------------------
* ZPPtr1 = defintion
* ZPMENUPtr = DstBuf
*--------------------------------------
MENU.GetData lda ZPMENUPtr
clc
adc #S.MENU.Items
sta ZPMENUPtr
bcc .1
inc ZPMENUPtr+1
.1 lda (ZPPtr1)
sta (ZPMENUPtr)
beq .8
cmp #S.MITEM.T.SEP
bne .2
inc ZPPtr1 skip 1 byte
bne .5
inc ZPPtr1+1
bra .5
*--------------------------------------
.2 cmp #S.MITEM.T.ITEM
bne .3
ldy #1 T+ID+KEMOD+KEY+pICON+"text"
lda (ZPPtr1),y
ldy #S.MITEM.ID
sta (ZPMENUPtr),y
ldy #2
lda (ZPPtr1),y
tax
iny
lda (ZPPtr1),y
ldy #S.MITEM.KEYMOD+1
sta (ZPMENUPtr),y
dey KEY
txa
sta (ZPMENUPtr),y
lda #4
bra .4 skip 4 bytes
*--------------------------------------
.3 ldy #1 skip T+pMENU+pICON+"text"
lda (ZPPtr1),y
tax
iny
lda (ZPPtr1),y
ldy #S.MITEM.pMENU+1
sta (ZPMENUPtr),y
dey
txa
sta (ZPMENUPtr),y
lda #3 skip 3 bytes
.4 jsr SkipAPtr1
ldy #1
lda (ZPPtr1),y
ldy #S.MITEM.pICON+1
sta (ZPMENUPtr),y
dey
lda (ZPPtr1)
sta (ZPMENUPtr),y
lda #2 skip pICON
jsr SkipAPtr1
ldy #S.MITEM.pTEXT
lda ZPPtr1
sta (ZPMENUPtr),y
iny
lda ZPPtr1+1
sta (ZPMENUPtr),y
jsr SkipStrZPtr1 skip "TEXT\0"
ldy #S.MITEM.S
lda #0
sta (ZPMENUPtr),y
.5 lda ZPMENUPtr
clc
adc #S.MITEM
sta ZPMENUPtr
bcc .1
inc ZPMENUPtr+1
bra .1
.8 clc
rts
*--------------------------------------
MENU.SetMenuSizePos
stz IY Icon Margin W
stz IE Max Text W
stz IE+1
stz INE Max Mod-Key W
stz INE+1
lda #2 2px Borders
sta DY Menu H
stz DY+1
jsr MENU.GetMItems
.1 lda (ZPPtr1)
beq .3
cmp #S.MITEM.T.SEP
beq .2
jsr MENU.GetMItemW
.2 jsr MENU.NextMItemDY
bra .1
.3 lda #2+MENU.LMargin+MENU.RMargin 2px Borders+5 LMARGIN (Checked) +5 RMARGIN (SubMenu)
clc
adc IY Icon W
sta DX
stz DX+1
lda DX
sec 1px sep
adc IE Max Text W
sta DX
lda DX+1
adc IE+1
sta DX+1
lda DX
sec 1px sep
adc INE Max Mod-Key W
sta DX
bcc .4
inc DX+1
.4 ldy #S.OBJ.W
sta (ZPMENUPtr),y
iny
lda DX+1
sta (ZPMENUPtr),y
iny #S.OBJ.H
lda DY
sta (ZPMENUPtr),y
iny
lda DY+1
sta (ZPMENUPtr),y
ldy #S.MENU.iW
lda IY
sta (ZPMENUPtr),y
ldy #S.MENU.tW
lda IE
sta (ZPMENUPtr),y
iny
lda IE+1
sta (ZPMENUPtr),y
iny #S.MENU.kW
lda INE
sta (ZPMENUPtr),y
iny
lda INE+1
sta (ZPMENUPtr),y
ldy #S.OBJ.Y1
lda DY
clc
adc (ZPMENUPtr),y
tax
iny
lda DY+1
adc (ZPMENUPtr),y
cpx WND.Screen+S.OBJ.H
sbc WND.Screen+S.OBJ.H+1
bcc .5
ldy #S.OBJ.Y1
lda (ZPMENUPtr),y
* sec
sbc DY
sta (ZPMENUPtr),y
iny
lda (ZPMENUPtr),y
sbc DY+1
sta (ZPMENUPtr),y
.5 >LDYA ZPMENUPtr
jsr OBJ.SetX2Y2
rts
*--------------------------------------
MENU.GetMItemW ldy #S.MITEM.pICON
lda (ZPPtr1),y
iny
ora (ZPPtr1),y
beq .1
lda #17 Reserve space for Icon W + 1px SEP
sta IY
.1 jsr MENU.GetText
ldx hSYSFON
jsr FON.GetTextSize
ldx CB.Cache+S.CB.SrcW
cpx IE
lda CB.Cache+S.CB.SrcW+1
sbc IE+1
bcc .2
stx IE Set Max text W
lda CB.Cache+S.CB.SrcW+1
sta IE+1
.2 jsr MENU.GetKeyString
bcs .8
ldx hSYSFON
jsr FON.GetTextSize
ldx CB.Cache+S.CB.SrcW
cmp INE
lda CB.Cache+S.CB.SrcW+1
sbc INE+1
bcc .8
stx INE set Max Mod-key W
lda CB.Cache+S.CB.SrcW+1
sta INE+1
.8 rts
*--------------------------------------
* hMENU8, ItemID8, Prop8, Value16
*--------------------------------------
MENU.SetMItemProp
ldy #4 hMENU
lda (pStack),y
>SYSCALL2 GetMemPtr
>STYA ZPMENUPtr
ldy #3 ID8
lda (pStack),y
tax
jsr MENU.FindMItemByID
bcs .9
ldy #2 Prop8
lda (pStack),y
tay
>PULLA Value16
sta (ZPPtr1),y
iny
>PULLA
sta (ZPPtr1),y
* clc
.8 >POP 3
.9 rts
*--------------------------------------
MENU.FindMItemByID
jsr MENU.GetMItems
.1 lda (ZPPtr1)
beq .9
cmp #S.MITEM.T.SEP
beq .7
txa
ldy #S.MITEM.ID
cmp (ZPPtr1),y
beq .8
.7 jsr MENU.NextMItem
bra .1
.8 clc
rts
.9 sec
rts
*--------------------------------------
MENU.Enter jsr MENU.GetDXDY
stz D
stz D+1
ldy #S.OBJ.X2
lda DX X1
clc
adc (ZPMENUPtr),y
sta IE IE = X2
iny
lda DX+1
adc (ZPMENUPtr),y
sta IE+1
jsr MENU.GetMItems
.1 lda (ZPPtr1)
beq .4
cmp #S.MITEM.T.SEP
beq .2
lda DY Y1
clc
adc SYSFON.Hp2
sta INE INE = Y2
lda DY+1
adc #0
sta INE+1
>LDYAI DX X1,X2,Y1,Y2
jsr MOU.InRectYA
bcc .3
ldy #S.MITEM.S
lda (ZPPtr1),y
bpl .2
eor #S.MITEM.S.SELECTED
sta (ZPPtr1),y was selected before...
jsr CB.GetBuf
bcs .9
jsr MENU.DrawMItem
.2 jsr MENU.NextMItemDY
bra .1
*--------------------------------------
.3 ldy #S.MITEM.S
lda (ZPPtr1),y
bmi .5 already selected, nothing to do
eor #S.MITEM.S.SELECTED
sta (ZPPtr1),y
jsr CB.GetBuf
bcs .9
jsr MENU.DrawMItem
.30 ldx MENU.Stack.Idx
inx
cpx MENU.Stack.Cnt
beq .31
jsr MENU.Destroy
bra .30
.31 lda (ZPPtr1)
cmp #S.MITEM.T.SUBMENU
bne .2
ldy #S.MITEM.pMENU
lda (ZPPtr1),y
sta D
iny
lda (ZPPtr1),y
sta D+1
lda DY
sta Counter
lda DY+1
sta Counter+1
bra .2
*--------------------------------------
.8 clc
.9 rts
*--------------------------------------
.4 >LDYA L.WND.Screen
jsr CB.FlushBufToYA
lda D
ora D+1
beq .5
>PUSHW D pMENU
ldy #S.OBJ.X2+1
lda (ZPMENUPtr),y
>PUSHA
dey
lda (ZPMENUPtr),y
>PUSHA
>PUSHW Counter
jsr MENU.New
bcs .9
jmp MENU.Draw
*--------------------------------------
.5 lda MSG+S.MSG.S
bit #S.MSG.S.CLK
beq .8
lda #S.MSG.T.ID
sta MSG+S.MSG.T
ldy #S.MITEM.ID
lda (ZPPtr1),y
sta MSG+S.MSG.ID
jmp MENU.DestroyAll
*--------------------------------------
* DrawMenu(hMENU)
*--------------------------------------
MENU.Draw >SYSCALL2 GetMemPtr
>STYA ZPMENUPtr
jsr MENU.Save
bcs .9
jsr CB.GetBuf
bcs .9
>LDYA ZPMENUPtr
ldx #0
jsr OBJ.DrawBorders
jsr MENU.GetDXDY
jsr MENU.GetMItems
.1 lda (ZPPtr1)
beq .8
jsr MENU.DrawMItem
jsr MENU.NextMItemDY
bra .1
.8 >LDYA L.WND.Screen
jmp CB.FlushBufToYA
.9 rts
*--------------------------------------
MENU.DrawMItem jsr MENU.ResetX1Y1X2
lda (ZPPtr1)
cmp #S.MITEM.T.SEP
bne MENU.DrawMItem1
lda #S.CB.CMD.HLINE
sta CB.Cache+S.CB.CMD
lda #S.CB.OP.SET
sta CB.Cache+S.CB.OP
lda #S.CB.M.MONO
sta CB.Cache+S.CB.M
lda PREFS.BorderColor
sta CB.Cache+S.CB.COLOR
jmp CB.Cache2CBBuf
*--------------------------------------
MENU.DrawMItem1 lda #S.CB.CMD.FILLRECT
sta CB.Cache+S.CB.CMD
lda #S.CB.OP.SET
sta CB.Cache+S.CB.OP
lda #S.CB.M.MONO
sta CB.Cache+S.CB.M
ldx PREFS.MenuColor
jsr MENU.IsSelected
bcc .15
txa
eor #C.WHITE
tax
.15 stx CB.Cache+S.CB.COLOR
lda CB.Cache+S.CB.Y1
sec
adc SYSFON.H
sta CB.Cache+S.CB.Y2
lda CB.Cache+S.CB.Y1+1
adc #0
sta CB.Cache+S.CB.Y2+1
jsr CB.Cache2CBBuf
*--------------------------------------
inc CB.Cache+S.CB.Y1 Y1:1px margin
bne .12
inc CB.Cache+S.CB.Y1+1
.12 lda CB.Cache+S.CB.X1
clc
adc #MENU.LMargin TODO : Checked
sta CB.Cache+S.CB.X1
bcc .11
inc CB.Cache+S.CB.X1+1
.11 jsr MENU.GetIcon
beq .2
jsr DRAW.yaBM
.2 lda CB.Cache+S.CB.X1
clc
ldy #S.MENU.iW
adc (ZPMENUPtr),y
sta CB.Cache+S.CB.X1
bcc .21
inc CB.Cache+S.CB.X1+1
.21 jsr MENU.GetText
jsr MENU.IsSelected
ldx hSYSFON
jsr DRAW.YAText
lda CB.Cache+S.CB.X1
sec
ldy #S.MENU.tW
adc (ZPMENUPtr),y
sta CB.Cache+S.CB.X1
lda CB.Cache+S.CB.X1+1
iny
adc (ZPMENUPtr),y
sta CB.Cache+S.CB.X1+1
lda (ZPPtr1)
cmp #S.MITEM.T.ITEM
bne .3
jsr MENU.GetKeyString
bcs .3
jsr MENU.IsSelected
ldx hSYSFON
jsr DRAW.YAText
.3 lda (ZPPtr1)
cmp #S.MITEM.T.SUBMENU
bne .8
lda CB.Cache+S.CB.X1
sec
ldy #S.MENU.kW
adc (ZPMENUPtr),y
sta CB.Cache+S.CB.X1
lda CB.Cache+S.CB.X1+1
iny
adc (ZPMENUPtr),y
sta CB.Cache+S.CB.X1+1
ldx #BM.ID.RIGHT
jmp DRAW.xBM
.8 clc
rts
*--------------------------------------
MENU.GetIcon ldy #S.MITEM.pICON+1
lda (ZPPtr1),y
bne .1
dey
lda (ZPPtr1),y
beq .8
tax
ldy L.BMs,x
lda L.BMs+1,x NON ZERO
.8 rts
.1 pha
dey
lda (ZPPtr1),y
tay
pla NON ZERO
rts
*--------------------------------------
MENU.IsSelected phy
pha
ldy #S.MITEM.S
lda (ZPPtr1),y
asl
.9 pla
ply
rts
*--------------------------------------
MENU.GetText ldy #S.MITEM.pTEXT
lda (ZPPtr1),y
pha
iny
lda (ZPPtr1),y
ply
rts
*--------------------------------------
* ZPPtr1 = pMITEM
*--------------------------------------
MENU.GetKeyString
ldy #S.MITEM.KEY
lda (ZPPtr1),y
dey S.MITEM.KEYMOD
ora (ZPPtr1),y
beq .9
ldx #0
lda (ZPPtr1),y
beq .3
bit #KEYMOD.CTRL
beq .1
ldy #KEYMOD.S.CTRL
jsr .4
.1 bit #KEYMOD.OA
beq .2
ldy #KEYMOD.S.OA
jsr .4
.2 bit #KEYMOD.CA
beq .3
ldy #KEYMOD.S.CA
jsr .4
.3 ldy #S.MITEM.KEY
lda (ZPPtr1),y
sta TEXTBUF,x
stz TEXTBUF+1,x
>LDYA L.TEXTBUF
clc
rts
*--------------------------------------
.4 pha
.5 lda KEYMOD.S,y
sta TEXTBUF,x
beq .6
inx
iny
bra .5
.6 pla
rts
.9 sec
rts
*--------------------------------------
MENU.Save lda #S.CB.CMD.GETRECTBUFSIZE
jsr CB.InitCacheA
ldy #S.OBJ.X1
ldx #0
.1 lda (ZPMENUPtr),y
sta CB.Cache+S.CB.X1,x
iny
inx
cpx #8 X1,Y1,X2,Y2
bne .1
jsr CB.GFXWrite
>SYSCALL2 NewStkObj
bcs .9
stx CB.Cache+S.CB.DstPtr
txa
ldy #S.MENU.hSAVEBUF
sta (ZPMENUPtr),y
lda #S.CB.CMD.BITBLT
sta CB.Cache+S.CB.CMD
lda #S.CB.OP.SAVE
sta CB.Cache+S.CB.OP
ldy #S.OBJ.W
ldx #0
.2 lda (ZPMENUPtr),y
sta CB.Cache+S.CB.SrcW,x
iny
inx
cpx #4 W,H
bne .2
jsr CB.GFXWrite
clc
.9 rts
*--------------------------------------
MENU.GetDXDY ldy #S.OBJ.X1
lda (ZPMENUPtr),y
clc
adc #1
sta DX
iny
lda (ZPMENUPtr),y
adc #0
sta DX+1
ldy #S.OBJ.Y1
lda (ZPMENUPtr),y
clc
adc #1
sta DY
iny
lda (ZPMENUPtr),y
adc #0
sta DY+1
rts
*--------------------------------------
MENU.ResetX1Y1X2
ldy #S.OBJ.X1
lda (ZPMENUPtr),y
clc
adc #1
sta CB.Cache+S.CB.X1
iny
lda (ZPMENUPtr),y
adc #0
sta CB.Cache+S.CB.X1+1
lda DY
sta CB.Cache+S.CB.Y1
lda DY+1
sta CB.Cache+S.CB.Y1+1
ldy #S.OBJ.X2
lda (ZPMENUPtr),y
sec
sbc #1
sta CB.Cache+S.CB.X2
iny
lda (ZPMENUPtr),y
sbc #0
sta CB.Cache+S.CB.X2+1
rts
*--------------------------------------
MENU.FindSelected
>LDYA ZPPtr1
>STYA D
jsr MENU.GetMItems
.1 lda (ZPPtr1)
beq .9
cmp #S.MITEM.T.SEP
beq .2
ldy #S.MITEM.S
lda (ZPPtr1),y
bmi .8
.2 jsr MENU.NextMItem
bra .1
.8 clc
rts
.9 >LDYA D
>STYA ZPPtr1
sec
rts
*--------------------------------------
MENU.GetMItems lda ZPMENUPtr
clc
adc #S.MENU.Items
sta ZPPtr1
lda ZPMENUPtr+1
adc /S.MENU.Items
sta ZPPtr1+1
rts
*--------------------------------------
MENU.NextMItemDY
lda (ZPPtr1)
sec
eor #S.MITEM.T.SEP
beq .1
lda SYSFON.Hp2
clc
.1 adc DY
sta DY
bcc MENU.NextMItem
inc DY+1
MENU.NextMItem lda #S.MITEM
jmp SkipAPtr1
*--------------------------------------
MENU.DestroyAll sec
.HS 90 BCC
MENU.Destroy clc
ldx MENU.Stack.Cnt
beq .8
php
bit PTR.bVisible
bpl .1
jsr PTR.Hide.I
.1 lda #S.CB.CMD.BITBLT
jsr CB.InitCacheA
lda #S.CB.OP.RESTORE
sta CB.Cache+S.CB.OP
plp
.2 php
ldx MENU.Stack.Cnt
lda MENU.Stack-1,x
>SYSCALL2 GetMemPtr
>STYA ZPObjPtr
ldy #S.OBJ.X1
ldx #0
.3 lda (ZPObjPtr),y
sta CB.Cache+S.CB.X1,x
iny
inx
cpx #8 X1,Y1,X2,Y2
bne .3
ldy #S.OBJ.W
ldx #0
.4 lda (ZPObjPtr),y
sta CB.Cache+S.CB.SrcW,x
iny
inx
cpx #4 W,H
bne .4
ldy #S.MENU.hSAVEBUF
lda (ZPObjPtr),y
sta CB.Cache+S.CB.DstPtr
jsr CB.GFXWrite
lda CB.Cache+S.CB.DstPtr
>SYSCALL2 FreeStkObj
ldx MENU.Stack.Cnt
lda MENU.Stack-1,x
>SYSCALL2 FreeMem
plp Destroy all ?
dec MENU.Stack.Cnt
bcc .7 no
bne .2
.7 bit PTR.bVisible
bpl .8
jmp PTR.Show.I
.8 clc
rts
*--------------------------------------
MAN
SAVE usr/src/lib/libgui.s.menu
LOAD usr/src/lib/libgui.s
ASM