But I have problems with the "Delete/Backspace" routine. I just don't get how best to store the typed data to be able, to remove chars from screen where you hit "DEL/BACKSPACE".
Code: Select all
/*
** Letter Maker
*/
@VERSION 10,0 ; requires Hollywood 10.0
@OPTIONS {DPIAware = True}
@APPTITLE "Letter Maker"
@APPVERSION "$VER: alpha 1 (25.09.24)"
@APPCOPYRIGHT "(C) Philipp Lonke"
@APPAUTHOR "Philipp Lonke"
@APPDESCRIPTION "Tool for making a nice letter with music and effects"
Const #DEBUG = True
Const #SCRWD = 640
Const #SCRHT = 480
@DISPLAY 1,{Title = "LetterMaker alpha", X = #CENTER, Y = #CENTER, Width = #SCRWD, Height = #SCRHT, Color = #BLACK, hidden = True, layers = True}
x,y,t,oldt,count=0
textlist=CreateList()
savetext=CreateList()
objlist=CreateList()
w$=""
Function textedit(msg)
; HideLayer("cursor")
; Box(x,y,font.size,font.size,#BLACK)
; Cls()
Switch msg.key
Case "ESC"
For i,v In Pairs(savetext)
w$=w$ .. v.key
Next
r$=RightStr(w$,1)
w$=r$..UnleftStr(w$,1)
If #DEBUG=True Then DebugPrint(w$)
End
Case "DOWN"
y=y+font.size
If y>#SCRHT-font.size Then y=#SCRHT-font.size
a={key="^DOWN",x=x,y=y,width=0, cnt=0}
InsertItem(savetext,a)
Case "UP"
y=y-font.size
If y<0 Then y=0
a={key="^UP",x=x,y=y,width=0, cnt=0}
InsertItem(savetext,a)
Case "RIGHT"
x=x+info
If x>#SCRWD
x=0
y=y+font.size
EndIf
a={key="^RIGHT",x=x,y=y,width=0, cnt=0}
InsertItem(savetext,a)
Case "LEFT"
x=x-info
If x<0
x=#SCRWD-info
y=y-font.size
If y<0 Then y=y+font.size
EndIf
a={key="^LEFT",x=x,y=y,width=0, cnt=0}
InsertItem(savetext,a)
Case "ENTER"
x=0
y=y+font.size
a={key="^ENTER",x=x,y=y,width=0, cnt=0}
InsertItem(savetext,a)
Case "RETURN"
x=0
y=y+font.size
a={key="^RETURN",x=x,y=y,width=0, cnt=0}
InsertItem(savetext,a)
Case "BACKSPACE"
count=count-1
If count<0 Then count=0
x=x-GetAttribute(#TEXTOBJECT,objlist[count],#ATTRWIDTH)
; RemoveSprite(textlist[count].cnt)
; Undo(#TEXTOBJECT,ToNumber(objlist[count],#LIGHTUSERDATA))
RemoveLayer(objlist[count])
RemoveItem(textlist)
a={key="^BACKSPACE",x=x,y=y,width=0, cnt=0}
InsertItem(savetext,a)
Default
Local t1=CreateTextObject(Nil,msg.key)
ConvertToBrush(#TEXTOBJECT,t1,Nil)
SetLayerName(Nil,ToString(t1))
charwd=GetAttribute(#TEXTOBJECT,t1, #ATTRWIDTH)
If x < 0 Then x = 0
If x > 640-charwd x = 0 y = y + font.size EndIf
If y < 0 Then y = 0
If y >480 Then y = 480
If #DEBUG Then DebugPrint(ToNumber(t1,#LIGHTUSERDATA))
; DisplayTextObject(t1,x,y,{Name=ToString(t1)})
; InsertItem(objlist,t1)
DisplayBrush(id,x,y)
InsertItem(objlist,GetAttribute(#BRUSH,id,#ATTRLAYERID))
count=count+1
If msg.key="^"
Local a={key="^"..msg.key,x=x,y=y,width=charwd, cnt=t}
Else
Local a={key=msg.key,x=x,y=y,width=charwd, cnt=t}
EndIf
InsertItem(textlist,a)
InsertItem(savetext,a)
x=x+charwd
EndSwitch
a={}
ShowLayer("cursor",x,y)
EndFunction
font=FontRequest("Zeichensatz auswählen",{x=#CENTER,y=#CENTER})
SetFont(font.name,font.size)
SetFontColor(font.color)
CreateBrush(1,font.size/2,font.size,font.color) ; cursor
DisplayBrush(1,0,0,{name="cursor"}) ; show it
col = ColorRequest("Hintergrundfarbe",{x=#CENTER,y=#CENTER})
SetDisplayAttributes({color = col})
OpenDisplay(1)
ActivateDisplay(1)
InstallEventHandler({OnKeyDown = textedit})
Repeat
WaitEvent
Forever