04-04-2025, 08:25 PM
Yes, that is another approach, text conversion into its own hardware image.
What I find cool is it really doesn't slow things down much to make that conversion possible. I even included a _limit 30 to save the cpu from running wild, and it still performed fast enough for typing purposes.
Suggestions going forward:
Fix backspace to remove the first character. It misses that one. This means changing a few ASC() conditions to accomplish that without throwing errors.
Make an option to also include the text background in the image, so it blocks out the input field and makes the text input appear with a blank background instead of overlapping only what is directly underneath the characters.
An advantage of text over both hardware and graphics is the inclusion of a flashing text cursor. I included one in the sample, below.
Anyway, here is a copy of those added suggestions. See what you think...
I would have responded sooner, but after I made the post in the other thread, I had to take off and do errands... FLY MOTHER ******. Oops, I still don't have that flying AI car Elon promised me.
Pete
What I find cool is it really doesn't slow things down much to make that conversion possible. I even included a _limit 30 to save the cpu from running wild, and it still performed fast enough for typing purposes.
Suggestions going forward:
Fix backspace to remove the first character. It misses that one. This means changing a few ASC() conditions to accomplish that without throwing errors.
Make an option to also include the text background in the image, so it blocks out the input field and makes the text input appear with a blank background instead of overlapping only what is directly underneath the characters.
An advantage of text over both hardware and graphics is the inclusion of a flashing text cursor. I included one in the sample, below.
Anyway, here is a copy of those added suggestions. See what you think...
Code: (Select All)
Screen 0
_DisplayOrder _Software , _Hardware ' this says only what must be shown
Dim As Long Img1, Img2, Img3, Img1H, Img2H, Img3H, PopImg, PopImgH
Dim As Integer X, Y, Mb, Xm, Ym, PopUp, InK, PW, PH
Dim Taken As String
' here it creates a square to overlap menu to make the shadow of selection
PW = 16
Img1 = _NewImage(8 * PW, 16 * 1, 32)
_Dest Img1
Cls , _RGBA32(127, 205, 255, 125)
Img1H = _CopyImage(Img1, 33)
_FreeImage Img1
' here it creates the Button image
Img2 = _NewImage(100, 50, 32)
_Dest Img2
Cls , _RGBA32(127, 0, 255, 180)
Color _RGBA32(183, 10, 140, 180), _RGBA32(0, 0, 0, 100)
_PrintString (10, 17), "Click Here"
Img2H = _CopyImage(Img2, 33)
_FreeImage Img2
' it creates image of popup from screen 0
PH = 4
Img3 = _NewImage(8 * PW, 16 * PH, 32)
_Dest Img3
Color _RGBA32(211, 166, 6, 255), _RGBA32(44, 44, 255, 255)
'4 lines
_PrintString (1, 1), "Rename....Ctrl+N" ' 16 characters
_PrintString (1, 16), "Change....Ctrl+O"
_PrintString (1, 32), "Search....Ctrl+X"
_PrintString (1, 48), "Quit......Ctrl+Q"
Img3H = _CopyImage(Img3, 33)
_FreeImage Img3
Screen 0
' inizialization and main loop
_Dest 0
Color 11, 3
Cls , 2
X = 0
Y = 0
Xm = 0
Ym = 0
Mb = 0
PopUp = 0 ' no popup showed
Taken = "" ' no input taken
Do
''_Limit 30
Cls , 2
Locate 1, 1: Print "Left click to show popup menu"; ' it shows help on first line of text
Print " Input Taken>"; Taken
_PutImage (300, 300), Img2H, 0 ' button
If _MouseInput Then ' taking mouse input
X = _MouseX
Y = _MouseY
If _MouseButton(1) Then Mb = 1
If _MouseButton(2) Then Mb = 2
End If
' it manages input
If Mb = 1 Then
If X < 1 Or X + PW > 80 Or Y < 1 Or Y + PH - 1 > 24 Then
' out of range for menu dimensions
If PopUp = 0 Then
'popup must be made but mouse's popup menu goes out of window's area
Beep
ElseIf PopUp = 1 Then
' left click out of range of area showable
PopUp = 0
Xm = 0
Ym = 0
End If
Else
' in the range of window's area showable popup
Select Case PopUp
Case 0
' if no popup then it makes popup
Xm = X: Ym = Y ' X and Y for popup and hovering menu
PopUp = 1 ' popup menu showed
Case 1
' popup already showed
If (X < Xm Or X > Xm + PW) Or (Y < Ym Or Y > Ym + PH - 1) Then
'left click out of menu area
PopUp = 0
Xm = 0
Ym = 0
'if click is out of popup menu it cancels menu
ElseIf Y = Ym And (X >= Xm And X <= Xm + PW) Then
' if click is on the first row of popup it activates the input keyboard
PopUp = 2
End If
Case Else
End Select
End If
Mb = 0 ' it resets Mb state
ElseIf Mb = 2 Then
End
End If
'it executes popup
If PopUp = 1 Or PopUp = 2 Then
' popup must be showed
If Xm And Ym Then
' popup is showed
_PutImage (1 + ((Xm - 1) * 8), 1 + ((Ym - 1) * 16)), Img3H, 0
' hover / selection item of popup menu
If (X >= Xm And X <= Xm + PW) And (Y >= Ym And Y <= Ym + PH - 1) Then _PutImage ((Xm - 1) * 8, (Y - 1) * 16), Img1H, 0
'input must be taken and showed
If PopUp = 2 Then GoSub PopUpInput
Else
' no cohordinates Xmenu and Ymenu = no PopUp Menu
PopUp = 0
End If
Else
''input must be taken and showed
'GoSub PopUpInput
End If
_Display
Loop
_FreeImage Img1H
_FreeImage Img2H
_FreeImage Img3H
End
PopUpInput:
' here it takes keyboard input
Taken = "-Type something"
GoSub ShowPopInput
Do
InK = _KeyHit
Select Case InK
Case 8
'backspace key
If Len(Taken) Then ' <------------------------- Needed to avoid len of zero asc() error due to change in code, below.
If Asc(Taken, 1) = 45 Then
Taken = ""
Else ' <------------------------- Changed to same as > zero instead of 1 so 1st character can also be removed.
Taken = Left$(Taken, Len(Taken) - 1)
GoSub ShowPopInput
' _Delay 0.5
End If
End If
Case 13
' enter key
GoSub ShowPopInput
_Delay .5
Exit Do
Case 27
' escape key
Taken = ""
GoSub ShowPopInput
' _Delay .5
Exit Do
Case 32, 48 To 57, 65 To 90, 97 To 122
If Left$(Taken, 1) = "-" Then Taken = "" ' (Changed to avoid asc(0) error).
If Len(Taken) < 16 - 1 Then
Taken = Taken + Chr$(InK) ' <------------------ Limited to input field.
GoSub ShowPopInput
End If
End Select
If Abs(z1 - Timer) > .2 Then
CursorFlash` = Not CursorFlash`
GoSub ShowPopInput
z1 = Timer
End If
Loop
PopUp = 1 ' only popup must be showed
_KeyClear
Return
ShowPopInput:
PopImg = _NewImage(8 * PW, 16, 32) ' <------------------------- Creates the background field.
_Dest PopImg
Cls , _RGB32(67, 67, 100)
Color _RGBA32(222, 200, 6, 255), _RGBA32(67, 67, 100, 255)
If CursorFlash` Then temp$ = Taken + "_" Else temp$ = Taken ' <------Flashing 1/2 sec cursor.
_PrintString (0, 0), temp$ ' <---------------------------------Changed to 0, 0).
PopImgH = _CopyImage(PopImg, 33)
_Dest 0
' all hardware images must be redrawn before a _DISPLAY
_PutImage (300, 300), Img2H, 0 ' button
' popup is showed
_PutImage (1 + ((Xm - 1) * 8), 1 + ((Ym - 1) * 16)), Img3H, 0 ' <-------------------------Slight shift to left.
' input is showed
''''_PutImage ((Xm - 1) * 8, (Y - 1) * 16), PopImgH, 0
_PutImage ((Xm - 1) * 8 + 1, (Y - 1) * 16), PopImgH, 0
_Display
_FreeImage PopImg
_FreeImage PopImgH
Return
I would have responded sooner, but after I made the post in the other thread, I had to take off and do errands... FLY MOTHER ******. Oops, I still don't have that flying AI car Elon promised me.
Pete