Actually while I was making my form with a peek-a-boo field, to let the software layer show through for text writing inside a hardware form, my pal from Italia came up with another method, to convert the text to hardware and put it on the form.
https://qb64phoenix.com/forum/showthread.php?tid=3586
Credit to @TempodiBasic for the concept.
All that is needed is something similar we need to do when we want to write text in graphics, mimic the Screen 0 cursor. In this example we will do that with the simple underline cursor or the overwrite cursor when you press the Insert key.
Keys:
Different form combos with/without title bar and shadow (F1 - F4).
Tab to toggle form on and off screen.
Insert key to change cursor appearance.
Esc key to close form or if form is not on screen, exits.
Arrow keys to move any type of form around the screen.
Character keys to type text.
Mouse:
Hold mouse with left button down over title bar to drag form. (Form type must include a title bar).
Hove mouse over the 'X' in a title bar to change its appearance in preparation to close form.
Click the 'X' in the title bar to close the form. (Tab key will bring it back.)
Since this is a demo of how-to work with hardware and software in screen 0, the text input has been minimized to writing or backspace.
Pete
https://qb64phoenix.com/forum/showthread.php?tid=3586
Credit to @TempodiBasic for the concept.
All that is needed is something similar we need to do when we want to write text in graphics, mimic the Screen 0 cursor. In this example we will do that with the simple underline cursor or the overwrite cursor when you press the Insert key.
Code: (Select All)
$Color:32
Dim As _Bit FormOpen, HoverClose, sdw, tbr
Dim As Long t1, t2, t3, t4, img, TBar, TBarRed, imgtxt
Dim As Integer FormType, ShdwTran, h, i, iw, ih
Dim As Integer FormL, FormT, FormW, FormH, yfld, xfld, fldlen, ytag, xtag
w = _Width: h = _Height
FormType = 0: FormOpen = -1
GoSub Form_Type
Palette 5, 63 ' Use for a bright white background.
Cls , 5
For a = 1 To h ' Draw colorful random characters to the screen.
Locate a, 1
For i = 1 To w
j = Int(Rnd * 14) + 1
k = Int(Rnd * 25) + 1
Color j, 5
Print Chr$(k + 96);
Next
Next
PCopy 0, 1 ' Copy the software screen before the popup opens.
title$ = "My Form" ' Start form here...
FormW = 31: FormH = 6 ' For dimensions.
GoSub Make_Form
FormT = 9 ' Top of form (not including any title bar) at row 9.
FormL = 27 ' Left of form at row 27.
Color 15, 0 ' White on black text color.
Locate yfld + (FormT - 1), xfld + (FormL - 1): Print Space$(fldlen + 1); ' Input field.
Locate yfld + (FormT - 1), xfld + (FormL - 1)
oldy = CsrLin: oldx = Pos(0) ' Assign these tracking variables here to avoid zero location error on first use.
Color 15, 0
Do
_Limit 60
If FormOpen Then
_PutImage ((FormL - 1) * fw, (FormT - 1 + tbr) * fh), img
If drag = 0 And tbr Then ' Only check for hover on x close when form is stationary.
If my = FormT + tbr And mx >= FormL + FormW - 2 And mx <= FormL + FormW Then
_PutImage ((FormL - 1) * fw, (FormT - 2) * fh), TBarRed
If Not HoverClose Then HoverClose = Not HoverClose
Else
If HoverClose Then HoverClose = Not HoverClose
End If
End If
End If
While _MouseInput: Wend
mx = _MouseX
my = _MouseY
lb = _MouseButton(1)
b$ = InKey$
If FormOpen Then
If tbr Then
If lb Then ' Mouse actions on Form.
If HoverClose Then
FormOpen = Not FormOpen ' Left click on 'X' hover closed the form.
GoSub Close_Form
End If
If my = FormT - 1 And drag = 0 Then ' Mouse cursor at tile bar level.
If mx >= FormL And mx <= FormL + FormW - 3 Then ' Mouse cursor within title bar.
drag = mx - FormL
End If
End If
Else
If drag Then ' Drag event completed.
drag = 0
End If
End If
If drag Then ' Mouse drag to move our form.
If mx <> oldmx Or my <> oldmy Then
PCopy 1, 0 ' First paste the original software layer back to screen 0.
m1 = my - FormT - tbr: m2 = mx - (FormL + drag) ' Drag direction.
If FormT + tbr + m1 < 1 Or FormT - 1 + FormH - sdw + m1 > _Height Then m1 = 0 ' Remember sdw is -1 when a shadow is present.
If FormL + m2 < 1 Or FormL - 1 + FormW + m2 - sdw * 2 > _Width Then m2 = 0 ' + 2 Allows for right side shadow.
If m1 + m2 Then FormT = FormT + m1: FormL = FormL + m2 ' A change in either m1 or m2 will cause the text field to be re-positioned to the new form coordinates.
End If
End If
End If
If Len(b$) Then ' Keyboard when form is open.
oldy = CsrLin: oldx = Pos(0)
Select Case b$
Case Chr$(0) + "R" ' Insert key.
CurApr` = Not CurApr`
Case Chr$(9) ' Form toggle.
FormOpen = Not FormOpen: GoSub Close_Form
If FormOpen Then m1 = 0: m2 = 0: GoSub FormMove
Case Chr$(27)
FormOpen = Not FormOpen: GoSub Close_Form ' Closes the form.
Case Chr$(8) ' Backspace
If Len(text$) Then
text$ = Mid$(text$, 1, Len(text$) - 1)
ccp% = ccp% - 1
GoSub Show_Text
End If
Case " " To "z" ' Allowed text characters.
If Len(text$) < fldlen Then
text$ = text$ + b$
ccp% = ccp% + 1
GoSub Show_Text
End If
Case Chr$(0) + "H" ' Arrow up.
If FormT + tbr > 1 Then ' Set top boundary with or without title bar.
m1 = -1: m2 = 0: GoSub FormMove
End If
Case Chr$(0) + "P" ' Arrow down.
If FormT - 1 + FormH - sdw < _Height Then ' Set bottom boundary with or without shadow.
m1 = 1: m2 = 0: GoSub FormMove
End If
Case Chr$(0) + "K" ' Arrow left.
If FormL > 1 Then ' Set left boundary.
m1 = 0: m2 = -1: GoSub FormMove
End If
Case Chr$(0) + "M" ' Arrow right.
If FormL - 1 + FormW - sdw * 2 < _Width Then ' Set right boundary with or without shadow.
m1 = 0: m2 = 1: GoSub FormMove
End If
Case Chr$(0) + Chr$(59) ' F1
If FormType <> 0 Then FormType = 0: GoSub Form_Type: GoSub Make_Form
Case Chr$(0) + Chr$(60) ' F2
If FormType <> 1 Then FormType = 1: GoSub Form_Type: GoSub Make_Form
Case Chr$(0) + Chr$(61) ' F3
If FormType <> 2 Then FormType = 2: GoSub Form_Type: GoSub Make_Form
Case Chr$(0) + Chr$(62) ' F4
If FormType <> 3 Then FormType = 3: GoSub Form_Type: GoSub Make_Form
End Select
End If
Else
Select Case b$ ' Keys in use when a form is not present.
Case Chr$(9) ' Form toggle.
FormOpen = Not FormOpen: GoSub Close_Form
If FormOpen Then m1 = 0: m2 = 0: GoSub FormMove
Case Chr$(27): System
End Select
End If
oldmy = my: oldmx = mx ' Tracks prior mouse position.
If FormOpen Then
If imgtxt Then _PutImage ((FormL - 1 + xfld - 1) * fw, (FormT - 1 + yfld - 1) * fh), imgtxt
If Abs(z1 - Timer) > .25 Then
CursorFlash` = Not CursorFlash`
If CursorFlash` Then
_Dest t1
If CurApr` Then
Line (ccp% * fw, fh / 2 - 1)-(ccp% * fw + fw, fh - 1), _RGB32(255, 255, 255, 128), BF
Else
Line (ccp% * fw, fh - 1)-(ccp% * fw + fw, fh), _RGB32(255, 255, 255), BF
End If
If imgtxt Then _FreeImage imgtxt: imgtxt = 0
imgtxt = _CopyImage(t1, 33)
_Dest 0
Else
_Dest t1
Cls
Print text$;
If imgtxt Then _FreeImage imgtxt: imgtxt = 0
imgtxt = _CopyImage(t1, 33)
_Dest 0
End If
z1 = Timer
End If
End If
_Display ' Show screen changes here.
Loop
Form_Type:
Select Case FormType
Case 0: tbr = -1: sdw = -1 ' Title bar and shadow.
Case 1: tbr = -1: sdw = 0 ' Title bar and no shadow.
Case 2: tbr = 0: sdw = -1 ' No title bar and shadow.
Case 3: tbr = 0: sdw = 0 ' No title bar and no shadow.
End Select
Return
Make_Form:
ShdwTran = 90 ' Shadow transparency (0 - 255) 0 = Transparent.
fw = _FontWidth: fh = _FontHeight
iw = FormW * fw ' Image width.
ih = FormH * fh ' Image height.
ytag = 4 ' Text field tag row.
xtag = 3 ' Text field tag column.
yfld = ytag ' Text input field row. Same as the tag.
xfld = 9 ' Text field column.
fldlen = 20 ' Text input field length.
t1 = _NewImage(fldlen * fw + fw, fh, 32)
If tbr = -1 And sdw = -1 Then
t2 = _NewImage(iw + 2 * fw, ih + fh, 32) ' Form with title bar and shadow.
ElseIf tbr And sdw = 0 Then
t2 = _NewImage(iw, ih + fh, 32) ' Form and title bar.
ElseIf tbr = 0 And sdw Then ' Form and shadow.
t2 = _NewImage(iw + 2 * fw, ih + fh, 32)
Else
t2 = _NewImage(iw, ih, 32) ' Form only.
End If
_Dest t2
Color _RGB32(90, 90, 90) ' Form color.
For h = 1 To FormH ' Makes a solid form without input fields.
Locate h, 1
For i = 1 To FormW
Print Chr$(219);
Next
Next
Color White, _RGB(90, 90, 90) ' Add text to the form and outline the input box.
If Len(title$) Then Locate 2 + (1 - 1), FormW \ 2 - Len(title$) \ 2 + 1: Print title$;
Locate ytag + (1 - 1), xtag: Print "Text:"
Line ((fw + (1 - 1)) * (xfld - 1) - 3, (fh + (1 - 1)) * (yfld - 1) - 3)-((fw + (1 - 1)) * (xfld + fldlen) + 2, (fh + (1 - 1)) * yfld + 2), _RGB32(255, 255, 255), B ' Outline around input field.
If sdw Then Line ((1 + FormW - 1) * fw, (1 + 1 - 1) * fw)-((1 + FormW + 1) * fw, (1 + FormH) * fh), _RGBA32(0, 0, 0, ShdwTran), BF ' Shadow right side.
If sdw Then Line (2 * fw, (1 + FormH - 1) * fh)-(FormW * fw - 1, 1 + (1 + FormH) * fh), _RGBA32(0, 0, 0, ShdwTran), BF ' Shadow bottom.
Color White, Black ' White on black text.
Locate yfld, xfld: Print Space$(fldlen + 1);
Locate yfld, xfld: Print text$;
If tbr Then
GoSub Title_Bar: img = _CopyImage(t4, 33): _FreeImage t4: t4 = 0 ' Free screen t4 and zero the handle.
Else
img = _CopyImage(t2, 33)
End If
_FreeImage t2: t2 = 0 ' Free screen t2 and zero the handle.
_Dest 0 ' Back to Screen 0.
Return
Title_Bar:
t3 = _NewImage(iw, fh, 32) ' Creates a dragable title bar on this screen.
_Dest t3
For j = 1 To 2
Cls , _RGB32(0, 0, 255) ' Title bar background is solid blue.
For i = fh - 2 To 0 Step -1 ' Use this loop to create a progressive lightening of the blue color in each line color statement...
Line (0, 0)-(iw, i + 1), _RGBA32(255, 255, 255, 0 + i * 14), B
Next
If j = 1 Then ' The first loop creates a title bar with a red box around the 'X' close symbol to be displayed on mouse hove.
xcolor& = White: xcolorbg& = DarkRed ' White 'X' symbol on dark red square.
Line (iw - fw * 2 + 0, 1)-(iw - fw * 2 + fw * 2, fh - 1), xcolorbg&, BF ' Adds a red box for our 'X' symbol.
Else
xcolor& = Black ' Black 'X' symbol on title bar background.
End If
Line (iw - fw * 2 + 0 + 4, 0 + 4)-(iw - fw * 2 + 0 + fw * 2 - 4, 0 + fh - 4), xcolor& ' These two diagonal lines make out 'X' symbol.
Line (iw - fw * 2 + 0 + 4, 0 + fh - 4)-(iw - fw * 2 + 0 + fw * 2 - 4, 0 + 4), xcolor&
If j = 1 Then ' Time to copy the image of the title bar with the red box around the 'X' symbol.
If TBarRed Then _FreeImage TBarRed: TBarRed = 0
TBarRed = _CopyImage(t3, 33)
Else ' Copy the image of the title bar without the red box. This is now the image that remains on screen t3 to be copied in then next routine.
TBar = _CopyImage(t3, 33)
End If
Next
If tbr = -1 And sdw = -1 Then ' Screen for combining the title bar and form images. This first condition set the screen size to accommodate a shadow effect.
t4 = _NewImage(iw + 2 * fw, ih + 2 * fh, 32) ' Form with title bar and shadow.
ElseIf tbr And sdw = 0 Then
t4 = _NewImage(iw, ih + fh + 2 * fh, 32) ' Form and title bar with no shadow screen.
End If
_Dest t4
_PutImage (0, 0), t3 ' Places the image that remains on screen t3 to the top of screen t4.
_PutImage (0, fh), t2
_FreeImage TBar: TBar = 0 ' Free the title bar image because it was combined with the form, but we will keep the title bar with red 'x' box in memory for hover events.
_FreeImage t3: t3 = 0 ' Free screen t3 and zero the handle.
Return ' Note: We will get back to screen 0 destination and free t4 back in the calling routine.
FormMove:
FormT = FormT + m1: FormL = FormL + m2 ' Change form cordernates.
PCopy 1, 0 ' Needed.
Locate yfld + (FormT - 1), xfld + (FormL - 1): Print Space$(fldlen + 1); ' Move input slot.
Locate yfld + (FormT - 1), xfld + (FormL - 1): Print text$; ' Move input text.
Locate oldy + m1, oldx + m2 ' Move cursor.
Return
Show_Text:
_Dest t1
If imgtxt Then _FreeImage imgtxt: imgtxt = 0
Cls
Print text$;
imgtxt = _CopyImage(t1, 33)
_Dest 0
Return
Close_Form:
PCopy 1, 0: If imgtxt Then _FreeImage imgtxt: imgtxt = 0
Return
Keys:
Different form combos with/without title bar and shadow (F1 - F4).
Tab to toggle form on and off screen.
Insert key to change cursor appearance.
Esc key to close form or if form is not on screen, exits.
Arrow keys to move any type of form around the screen.
Character keys to type text.
Mouse:
Hold mouse with left button down over title bar to drag form. (Form type must include a title bar).
Hove mouse over the 'X' in a title bar to change its appearance in preparation to close form.
Click the 'X' in the title bar to close the form. (Tab key will bring it back.)
Since this is a demo of how-to work with hardware and software in screen 0, the text input has been minimized to writing or backspace.
Pete