(01-25-2023, 06:50 PM)bplus Wrote: Quote:Umm... but remember to check for "escape" key press or some way to exit the program. Shouldn't be playing games during work hours LOL.
Ah yes! good point and perhaps the whole thing a self contained function that returns the string (on enter chr$(13)) or "" empty string on escape chr$(27). Just feed it, the function, a row number and some text to edit. I think that is what Phil is after, I will update.
The only advantage to this over Input? You can start with some default text and alter colors?
Code: (Select All)
Option _Explicit
_Title "MyCurs Test use left and right arrow keys to move cursor" 'b+ 2023-01-24
Screen _NewImage(800, 600, 32)
Dim text$, output$
_PrintMode _KeepBackground
text$ = "Hello World"
Color &HFF000000, &HFFFFFFFF
Cls
Print text$
_PrintString (20, 5), text$ ' this should blur text because of print mode
output$ = EditLine$(20, text$)
Cls
Print "Your edit was '"; output$; "'"
_PrintString (20, 5), output$ ' this should blur text
Function EditLine$ (row, copytext$) ' assuming a graphics screen for line drawing and measuring character width per line
Dim As Long pm, maxLen, cursCol, kh
Dim defaultColor~&, backGroundColor~&, text$
pm = _PrintMode
defaultColor~& = _DefaultColor: backGroundColor~& = _BackgroundColor
Color backGroundColor~&, defaultColor~&
_PrintMode _FillBackground ' so we can use spaces to "erase" line
text$ = copytext$ ' save original input
maxLen = _Width / 8
cursCol = 1
Do
Locate row, 1: Print Space$(maxLen) 'clear line better that clearing whole screen
Locate row, 1: Print text$; ' current status
myCurs row, cursCol ' show curs location
kh = _KeyHit ' poll keys
' handle key press
If kh = 19200 And cursCol > 1 Then
cursCol = cursCol - 1
ElseIf kh = 19712 And cursCol < maxLen Then
If cursCol + 1 <= Len(text$) + 1 Then cursCol = cursCol + 1
ElseIf (kh >= 32 And kh <= 127) And Len(text$) < maxLen Then
If cursCol <= Len(text$) + 1 Then 'lets not be printing in no mans land!
text$ = Mid$(text$, 1, cursCol - 1) + Chr$(kh&) + Mid$(text$, cursCol)
cursCol = cursCol + 1
End If
ElseIf kh& = 8 Then ' back space
If cursCol > 1 Then
text$ = Mid$(text$, 1, cursCol - 2) + Mid$(text$, cursCol)
cursCol = cursCol - 1
End If
ElseIf kh& = 21248 Then ' delete
text$ = Mid$(text$, 1, cursCol - 2) + Mid$(text$, cursCol)
ElseIf kh& = 13 Then
EditLine$ = text$: Exit Do
ElseIf kh& = 27 Then
EditLine$ = "": Exit Do
End If
_Display
_Limit 60
Loop
Select Case pm 'return printmode before
Case 1: _PrintMode _KeepBackground
Case 2: _PrintMode _OnlyBackground
Case 3: _PrintMode _FillBackground
End Select
Color defaultColor~&, backGroundColor~&
End Function
Sub myCurs (row, col) ' use row col like for Locate
'Locate row, col
Dim c~&
Static As Long lc, toggle
lc = lc + 1
If lc > 1000000 Then lc = 0
If lc Mod 20 = 0 Then toggle = 1 - toggle
If toggle Then c~& = _RGB32(255, 255, 255) Else c~& = _RGB32(0, 0, 0)
Line ((col - 1) * 8, (row - 1) * 16)-Step(0, 15), c~&
End Sub
EDIT: I added some code to see the restoring of _PrintMode (and color) after the call to LineEdit$.
So I am printing over a printed section to see both texts are overlapping.
b = b + ...