QB64 Phoenix Edition
Peek-a-boo Hardware Form Concept - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Works in Progress (https://qb64phoenix.com/forum/forumdisplay.php?fid=9)
+---- Thread: Peek-a-boo Hardware Form Concept (/showthread.php?tid=3584)

Pages: 1 2


Peek-a-boo Hardware Form Concept - Pete - 04-04-2025

So the concept is to make a hardware form with a transparent input slot in which our SCREEN 0 program can display text.

Note: Each entry in this post is a WIP progression. See the last entry for the latest (done!) entry.

Code: (Select All)
$Color:32
w = _Width: h = _Height
fw = _FontWidth: fh = _FontHeight
Dim As Long t, img
t = _NewImage(250, 100, 32)
_Dest t
Color _RGB32(90, 90, 90)
For h = 1 To 100 \ fh
    Locate h, 1
    For i = 1 To 250 \ fw ' Build form out of solid blocks except over text input area.
        If h = 4 Then
            If i >= 9 And i <= 29 Then
                Locate , Pos(0) + 1
            Else
                Print Chr$(219);
            End If
        Else
            Print Chr$(219);
        End If
    Next
Next
Color White, _RGB(90, 90, 90) ' add text to the form and outline the input bo.
Locate 2, 13: Print "My Form"
Locate 4, 3: Print "Text:"
Line (fw * 8 - 3, fh * 3 - 3)-(fw * 29 + 2, fh * 4 + 2), _RGB32(255, 255, 255), B
img = _CopyImage(t, 33)
_FreeImage t
_Dest 0
Color 15, 0
Locate 4, 9, 1, 7, 7 ' Show cursor.
Do
    _Limit 30
    _PutImage (0, 0), img
    b$ = InKey$
    If b$ = Chr$(8) And Pos(0) > 9 Then
        Locate , Pos(0) - 1: Print " ";: Locate , Pos(0) - 1
        _Continue
    End If
    If b$ = Chr$(27) Then System
    If Len(b$) = 1 And Pos(0) < 29 Then
        If Asc(b$) >= 32 And Asc(b$) <= 122 Then
            Print b$;
        End If
    End If
_Display
Loop

For folks who are very comfortable in graphics, the line with BF statement could have been used multiple times to make the block minus the input slot.

If anyone thinks they have an easier method, using a hardware form on top of Screen 0, let me know. It would be a fun discussion.

Okay, next evolution. Relative variables so the popup can be manipulated.

Code: (Select All)
$Color:32
Dim As Long t, img
Dim As Integer h, i, iw, ih, MenuL, MenuT, yfld, xfld, fldlen, ytag, xtag
w = _Width: h = _Height
fw = _FontWidth: fh = _FontHeight
iw = 250 ' Image width.
ih = 100 ' Image height.
MenuT = 1
MenuL = 1
MenuW = iw \ fw
ytag = 4
xtag = 3
yfld = ytag
xfld = 9
fldlen = 20
t = _NewImage(iw, ih, 32)
_Dest t
title$ = "My Form"
Color _RGB32(90, 90, 90)
For h = 1 To ih \ fh
Locate (MenuT - 1) + h, (MenuL - 1) + 1
For i = 1 To iw \ fw ' Build form out of solid blocks except over text input area.
If h = yfld Then
If i >= xfld And i <= xfld + fldlen Then
Locate , Pos(0) + 1
Else
Print Chr$(219);
End If
Else
Print Chr$(219);
End If
Next
Next
Color White, _RGB(90, 90, 90) ' add text to the form and outline the input bo.
If Len(title$) Then Locate 2 + (MenuT - 1), MenuW \ 2 - Len(title$) \ 2 + 1: Print title$;
Locate ytag + (MenuT - 1), xtag: Print "Text:"
Line ((fw + (MenuL - 1)) * (xfld - 1) - 3, (fh + (MenuT - 1)) * (yfld - 1) - 3)-((fw + (MenuL - 1)) * (xfld + fldlen) + 2, (fh + (MenuT - 1)) * yfld + 2), _RGB32(255, 255, 255), B
img = _CopyImage(t, 33)
_FreeImage t
_Dest 0
Palette 5, 63
Cls , 5
MenuT = 9
MenuL = 27
Color 15, 0
Locate yfld + (MenuT - 1), xfld + (MenuL - 1): Print Space$(21);
Locate yfld + (MenuT - 1), xfld + (MenuL - 1), 1, 7, 7 ' Show cursor.
Do
_Limit 30
_PutImage ((MenuL - 1) * fw, (MenuT - 1) * fh), img
b$ = InKey$
If b$ = Chr$(8) And Pos(0) > xfld + (MenuL - 1) Then
Locate , Pos(0) - 1: Print " ";: Locate , Pos(0) - 1
_Continue
End If
If b$ = Chr$(27) Then System
If Len(b$) = 1 And Pos(0) < xfld + fldlen + (MenuL - 1) Then
If Asc(b$) >= 32 And Asc(b$) <= 122 Then
Print b$;
End If
End If
_Display
Loop

So here is the next progression, movable popup by mouse drag (near top) or arrow keys.

What's interesting is that 'hollow' space we created. Ah, drag that over stuff and the stuff underneath it keeps peeking through. We don't want that s the solution is to mask the hollowed out popup with a lookalike one. Now that imposter popup can be dragged without any undesirable effects. I tell you, it's always something!

Code: (Select All)
$Color:32
Dim As Long t, img, imgmask
Dim As Integer h, i, iw, ih, MenuL, MenuT, yfld, xfld, fldlen, ytag, xtag
w = _Width: h = _Height
fw = _FontWidth: fh = _FontHeight
iw = 250 ' Image width.
ih = 100 ' Image height.
MenuT = 1
MenuL = 1
MenuW = iw \ fw
ytag = 4
xtag = 3
yfld = ytag
xfld = 9
fldlen = 20
title$ = "My Form"
t = _NewImage(iw, ih, 32)
_Dest t
Color _RGB32(90, 90, 90)
For h = 1 To ih \ fh
Locate (MenuT - 1) + h, (MenuL - 1) + 1
For i = 1 To iw \ fw ' Build form out of solid blocks except over text input area.
If h = yfld Then
If i >= xfld And i <= xfld + fldlen Then
Locate , Pos(0) + 1
Else
Print Chr$(219);
End If
Else
Print Chr$(219);
End If
Next
Next
Color White, _RGB(90, 90, 90) ' add text to the form and outline the input bo.
If Len(title$) Then Locate 2 + (MenuT - 1), MenuW \ 2 - Len(title$) \ 2 + 1: Print title$;
Locate ytag + (MenuT - 1), xtag: Print "Text:"
Line ((fw + (MenuL - 1)) * (xfld - 1) - 3, (fh + (MenuT - 1)) * (yfld - 1) - 3)-((fw + (MenuL - 1)) * (xfld + fldlen) + 2, (fh + (MenuT - 1)) * yfld + 2), _RGB32(255, 255, 255), B
img = _CopyImage(t, 33)
_FreeImage t
_Dest 0
Palette 5, 63
Cls , 5
MenuT = 9
MenuL = 27
Color 15, 0
Locate yfld + (MenuT - 1), xfld + (MenuL - 1): Print Space$(21);
Locate yfld + (MenuT - 1), xfld + (MenuL - 1), 1, 7, 7 ' Show cursor.
oldy = CsrLin: oldx = Pos(0)
Do
_Limit 60
If mask Then
_PutImage ((MenuL - 1) * fw, (MenuT - 1) * fh), imgmask
Else
_PutImage ((MenuL - 1) * fw, (MenuT - 1) * fh), img
End If
While _MouseInput: Wend
mx = _MouseX
my = _MouseY
lb = _MouseButton(1)
b$ = InKey$
If lb Then
If mx >= MenuL And mx <= MenuL + 30 And my = MenuT Then
If mask = 0 Then
Locate , , 0: drag = mx - MenuL: ccp% = Pos(0) - MenuL
GoSub popmask
End If
End If
Else
If mask Then
drag = 0: mask = 0: m1 = 0: m2 = 0
Locate oldy + m1, oldx + m2: GoSub popmove
Locate yfld + (MenuT - 1), MenuL + ccp%, 1
End If
End If
If drag Then
If mx <> oldmx Or my <> oldmy Then
m1 = my - MenuT: m2 = mx - (MenuL + drag)
If MenuT + m1 < 1 Or MenuT + m1 + 5 > _Height Then m1 = 0
If MenuL + m2 < 1 Or MenuL + m2 + 30 > _Width Then m2 = 0
If m1 + m2 Then MenuT = MenuT + m1: MenuL = MenuL + m2
Rem MenuT = my: MenuL = mx - drag (Used when no text printing is present).
End If
End If
oldmy = my: oldmx = mx
If Len(b$) Then
oldy = CsrLin: oldx = Pos(0)
Select Case b$
Case Chr$(27): System
Case Chr$(8)
If Pos(0) > xfld + (MenuL - 1) Then
Locate , Pos(0) - 1: Print " ";: Locate , Pos(0) - 1
text$ = Mid$(text$, 1, Len(text$) - 1)
End If
Case " " To "z"
If Pos(0) < xfld + fldlen + (MenuL - 1) Then
Print b$;
text$ = text$ + b$
End If
Case Chr$(0) + "H"
If MenuT > 1 Then
m1 = -1: m2 = 0: GoSub popmove
End If
Case Chr$(0) + "P"
If MenuT + 5 < _Height Then
m1 = 1: m2 = 0: GoSub popmove
End If
Case Chr$(0) + "K"
If MenuL > 1 Then
m1 = 0: m2 = -1: GoSub popmove
End If
Case Chr$(0) + "M"
If MenuL + 30 < _Width Then
m1 = 0: m2 = 1: GoSub popmove
End If
End Select
End If
_Display
Loop

popmove:
Color 5, 5: Locate yfld + (MenuT - 1), xfld + (MenuL - 1): Print Space$(21);: Color 15, 0
MenuT = MenuT + m1: MenuL = MenuL + m2
Locate yfld + (MenuT - 1), xfld + (MenuL - 1): Print Space$(21);
Locate yfld + (MenuT - 1), xfld + (MenuL - 1): Print text$;
Locate oldy + m1, oldx + m2
Return

popmask:
mask = -1
t = _NewImage(iw, ih, 32)
_Dest t
Color _RGB32(90, 90, 90)
For h = 1 To ih \ fh
Locate h, 1
For i = 1 To iw \ fw
Print Chr$(219);
Next
Next
Color White, _RGB(90, 90, 90) ' add text to the form and outline the input bo.
If Len(title$) Then Locate 2, MenuW \ 2 - Len(title$) \ 2 + 1: Print title$;
Locate ytag, xtag: Print "Text:"
Line (fw * (xfld - 1) - 3, fh * (yfld - 1) - 3)-(fw * (xfld + fldlen) + 2, fh * yfld + 2), _RGB32(255, 255, 255), B
Color White, Black
Locate yfld, xfld: Print Space$(21);
Locate yfld, xfld: Print text$;
imgmask = _CopyImage(t, 33)
_FreeImage t
_Dest 0
Color 5, 5: Locate yfld + (MenuT - 1), xfld + (MenuL - 1): Print Space$(21);: Color 15, 0
Return

FINAL INSTALLMENT - All the goodies. Added F1 - F4 to display various combinations of title bar, shadow, and form. Drag a title bar with mouse or use arrow keys to move form (Arrow keys will move form if a title bar isn't present.) Added TAB key to toggle form on and off.

Code: (Select All)
$Color:32
Dim As _Bit FormOpen, HoverClose, sdw, tbr
Dim As Long t1, t2, t3, t4, img, imgmask, TBar, TBarRed
Dim As Integer FormType, ShdwTran, h, i, iw, ih
Dim As Integer FormL, FormT, FormTx, FormW, FormH, FormHx, 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), 1, 7, 7 ' Show cursor.
oldy = CsrLin: oldx = Pos(0) ' Assign these tracking variables here to avoid zero location error on first use.
Do
_Limit 60
If FormOpen Then
If mask Then
_PutImage ((FormL - 1) * fw, (FormT - 1 + tbr) * fh), imgmask
Else
_PutImage ((FormL - 1) * fw, (FormT - 1 + tbr) * fh), img
End If
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 PCopy 1, 0: Locate , , 0: FormOpen = Not FormOpen ' Left click on 'X' hover closed the form.
If my = FormT - 1 Then ' Mouse cursor at tile bar level.
If mx >= FormL And mx <= FormL + FormW - 3 Then ' Mouse cursor within title bar.
If mask = 0 Then ' Get mask.
Locate , , 0: drag = mx - FormL: ccp% = Pos(0) - FormL
GoSub Form_Mask
End If
End If
End If
Else
If mask Then ' Form move with mouse finished so remove mask.
drag = 0: mask = 0: m1 = 0: m2 = 0
Locate oldy + m1, oldx + m2: GoSub FormMove
Locate yfld + (FormT - 1), FormL + ccp%, 1
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.
Rem FormT = my: FormL = mx - drag (Used when no text printing is present).
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$(9) ' Form toggle.
FormOpen = Not FormOpen: PCopy 1, 0: Locate , , 0
If FormOpen Then Locate , , 1: m1 = 0: m2 = 0: GoSub FormMove
Case Chr$(27)
FormOpen = Not FormOpen: PCopy 1, 0: Locate , , 0 ' Closes the form.
Case Chr$(8) ' Backspace
If Pos(0) > xfld + (FormL - 1) Then
Locate , Pos(0) - 1: Print " ";: Locate , Pos(0) - 1
text$ = Mid$(text$, 1, Len(text$) - 1)
End If
Case " " To "z" ' Allowed text characters.
If Pos(0) < xfld + fldlen + (FormL - 1) Then
Print b$;
text$ = text$ + b$
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: PCopy 1, 0: Locate , , 0
If FormOpen Then Locate , , 1: m1 = 0: m2 = 0: GoSub FormMove
Case Chr$(27): System
End Select
End If
oldmy = my: oldmx = mx ' Tracks prior mouse position.
_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:
FormTx = 1: FormLx = 1 ' Sets form in upper left corner of screen.
FormWx = FormW
FormHx = FormH
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.
If tbr = -1 And sdw = -1 Then
t1 = _NewImage(iw + 2 * fw, ih + fh, 32) ' Form with title bar and shadow.
ElseIf tbr And sdw = 0 Then
t1 = _NewImage(iw, ih, 32) ' Form and title bar.
ElseIf tbr = 0 And sdw Then ' Form and shadow.
t1 = _NewImage(iw + 2 * fw, ih + fh, 32)
Else
t1 = _NewImage(iw, ih, 32) ' Form only.
End If
_Dest t1
Color _RGB32(90, 90, 90) ' Form color.
For h = 1 To FormH
Locate (FormTx - 1) + h, (FormLx - 1) + 1
For i = 1 To FormW ' Build form using solid blocks except over text input area.
If h = yfld Then ' At input row.
If i >= xfld And i <= xfld + fldlen Then ' Skips input field.
Locate , Pos(0) + 1
Else
Print Chr$(219); ' Solid blocks.
End If
Else
Print Chr$(219); ' Solid blocks always over non-input field rows.
End If
Next
Next
Color White, _RGB(90, 90, 90) ' Add text to the form and outline the input box.
If Len(title$) Then Locate 2 + (FormTx - 1), FormW \ 2 - Len(title$) \ 2 + 1: Print title$;
Locate ytag + (FormTx - 1), xtag: Print "Text:"
Line ((fw + (FormLx - 1)) * (xfld - 1) - 3, (fh + (FormTx - 1)) * (yfld - 1) - 3)-((fw + (FormLx - 1)) * (xfld + fldlen) + 2, (fh + (FormTx - 1)) * yfld + 2), _RGB32(255, 255, 255), B ' Text field outline.
If sdw Then Line ((FormLx + FormW - 1) * fw, (FormTx + 1 - 1) * fw)-((FormLx + FormW + 1) * fw, (FormTx + FormH) * fh), _RGBA32(0, 0, 0, ShdwTran), BF ' Shadow right side.
If sdw Then Line (2 * fw, (FormTx + FormH - 1) * fh)-(FormW * fw - 1, FormTx + (FormTx + FormH) * fh), _RGBA32(0, 0, 0, ShdwTran), BF ' Shadow bottom.
If img Then _FreeImage img: img = 0
If tbr Then ' Title bar present.
GoSub Title_Bar
img = _CopyImage(t4, 33)
_FreeImage t4: t4 = 0
Else
img = _CopyImage(t1, 33) ' No title bar, so copy the finished the image here to memory.
End If
_FreeImage t1: t1 = 0 ' Free the image and zero the handle.
_Dest 0 ' Back to Screen 0.
Return

Form_Mask:
mask = -1
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) ' Use same colors as form being masked.
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 ' Mask over the transparent input field with a non-transparent duplicate here...
Locate yfld, xfld: Print Space$(fldlen + 1);
Locate yfld, xfld: Print text$;
If tbr Then ' Title bar present...
GoSub Title_Bar
If imgmask Then _FreeImage imgmask: imgmask = 0 ' Note: Zeroing handles is necessary because freeing the image doesn't zero the handle.
imgmask = _CopyImage(t4, 33) ' Now we have on screen t4 the combined images of title bar and form.
_FreeImage t4: t4 = 0 ' Free and zero the combined image screen t4.
Else
imgmask = _CopyImage(t2, 33) ' Non-title bar images are copied here from scren t2.
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 accomodate 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.
If mask Then ' Places the solid form to our combo screen, right below the title bar.
_PutImage (0, fh), t2
imgmask = _CopyImage(t3, 33)
Else ' Places the see-thru input field form below our title bar.
_PutImage (0, fh), t1
img = _CopyImage(t3, 33)
End If
_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:
If imgmask Then _FreeImage imgmask: imgmask = 0
FormT = FormT + m1: FormL = FormL + m2 ' Change form cordinates.
_Display ' Update the screen so we can toss the old hardware form.
PCopy 1, 0 ' Restore the software background. (Removes the software input.)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.
_PutImage ((FormL - 1) * fw, (FormT - 1 + tbr) * fh), img ' Move hardware image.
Return

I might come back and edit if any bugs get found.

This one was fun, mixing hardware with software backgorund and text looking like it is being printed to the hardware image. I might make another version to demo Tempoid's concept of making the text into a hardware image of its own, so it can just be displayed on top of the hardware form. The only other method that comes to mind is to swith the display order and make the background a hardware image, the form a hardware image (layer #2) and then print text, as usual, on the hardware form. All valid approaches, and it really just depends on what your needs are in regard to multi-layer visual effects.

EDIT: WE DON'T NEED NO STINKIN' MASK!!!!

Looking for some ways to optimize the code, and decided to drop the mask. Worked out the display to do the job.

Code: (Select All)
$Color:32
Dim As _Bit FormOpen, HoverClose, sdw, tbr
Dim As Long t1, t2, t3, img, TBar, TBarRed
Dim As Integer FormType, ShdwTran, h, i, iw, ih
Dim As Integer FormL, FormT, FormTx, FormW, FormH, FormHx, 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
Color 15, 0 ' White on black text color.
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.
GoSub Reprint_Text
Do
_Limit 60
If FormOpen Then
If drag = 0 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 drag Then ' Mouse drag to move our form.
If mx <> oldmx Or my <> oldmy Then
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.
PCopy 1, 0 ' First paste the original software layer back to screen 0.
GoSub Reprint_Text
End If
Rem FormT = my: FormL = mx - drag (Used when no text printing is present).
End If
_PutImage ((FormL - 1) * fw, (FormT - 1 + tbr) * fh), img
End If
If tbr Then
If lb Then ' Mouse actions on Form.
If HoverClose Then FormOpen = Not FormOpen: GoSub Close_Form ' Left click on 'X' hover closed the form.
If my = FormT - 1 Then ' Mouse cursor at tile bar level.
If mx >= FormL And mx <= FormL + FormW - 3 Then ' Mouse cursor within title bar.
If drag = 0 Then
Locate , , 0: drag = mx - FormL
End If
End If
End If
Else
If drag Then
drag = 0: Locate , , 1
End If
End If
End If
If Len(b$) Then ' Keyboard when form is open.
Select Case b$
Case Chr$(9) ' Form toggle.
FormOpen = Not FormOpen: GoSub Close_Form
Case Chr$(13), Chr$(27)
FormOpen = Not FormOpen: GoSub Close_Form
Case Chr$(8) ' Backspace
If Len(text$) Then
ccp% = ccp% - 1
Locate , Pos(0) - 1: Print " ";: Locate , Pos(0) - 1
text$ = Mid$(text$, 1, Len(text$) - 1)
End If
Case " " To "z" ' Allowed text characters.
If Len(text$) < fldlen Then
ccp% = ccp% + 1
Print b$;
text$ = text$ + b$
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 Reprint_Text: Locate , , 1
Case Chr$(27): System
End Select
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:
FormTx = 1: FormLx = 1 ' Sets form in upper left corner of screen.
FormWx = FormW
FormHx = FormH
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.
If tbr = -1 And sdw = -1 Then
t1 = _NewImage(iw + 2 * fw, ih + fh, 32) ' Form with title bar and shadow.
ElseIf tbr And sdw = 0 Then
t1 = _NewImage(iw, ih, 32) ' Form and title bar.
ElseIf tbr = 0 And sdw Then ' Form and shadow.
t1 = _NewImage(iw + 2 * fw, ih + fh, 32)
Else
t1 = _NewImage(iw, ih, 32) ' Form only.
End If
_Dest t1
Color _RGB32(90, 90, 90) ' Form color.
For h = 1 To FormH
Locate (FormTx - 1) + h, (FormLx - 1) + 1
For i = 1 To FormW ' Build form using solid blocks except over text input area.
If h = yfld Then ' At input row.
If i >= xfld And i <= xfld + fldlen Then ' Skips input field.
Locate , Pos(0) + 1
Else
Print Chr$(219); ' Solid blocks.
End If
Else
Print Chr$(219); ' Solid blocks always over non-input field rows.
End If
Next
Next
Color White, _RGB(90, 90, 90) ' Add text to the form and outline the input box.
If Len(title$) Then Locate 2 + (FormTx - 1), FormW \ 2 - Len(title$) \ 2 + 1: Print title$;
Locate ytag + (FormTx - 1), xtag: Print "Text:"
Line ((fw + (FormLx - 1)) * (xfld - 1) - 3, (fh + (FormTx - 1)) * (yfld - 1) - 3)-((fw + (FormLx - 1)) * (xfld + fldlen) + 2, (fh + (FormTx - 1)) * yfld + 2), _RGB32(255, 255, 255), B ' Text field outline.
If sdw Then Line ((FormLx + FormW - 1) * fw, (FormTx + 1 - 1) * fw)-((FormLx + FormW + 1) * fw, (FormTx + FormH) * fh), _RGBA32(0, 0, 0, ShdwTran), BF ' Shadow right side.
If sdw Then Line (2 * fw, (FormTx + FormH - 1) * fh)-(FormW * fw - 1, FormTx + (FormTx + FormH) * fh), _RGBA32(0, 0, 0, ShdwTran), BF ' Shadow bottom.
If img Then _FreeImage img: img = 0
If tbr Then ' Title bar present.
GoSub Title_Bar
img = _CopyImage(t3, 33)
_FreeImage t3: t3 = 0
Else
img = _CopyImage(t1, 33) ' No title bar, so copy the finished the image here to memory.
End If
_FreeImage t1: t1 = 0 ' Free the image and zero the handle.
_Dest 0 ' Back to Screen 0.
Return

Title_Bar:
t2 = _NewImage(iw, fh, 32) ' Creates a dragable title bar on this screen.
_Dest t2
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(t2, 33)
Else ' Copy the image of the title bar without the red box. This is now the image that remains on screen t2 to be copied in then next routine.
TBar = _CopyImage(t2, 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 accomodate a shadow effect.
t3 = _NewImage(iw + 2 * fw, ih + 2 * fh, 32) ' Form with title bar and shadow.
ElseIf tbr And sdw = 0 Then
t3 = _NewImage(iw, ih + fh + 2 * fh, 32) ' Form and title bar with no shadow screen.
End If
_Dest t3
_PutImage (0, 0), t2 ' Places the image that remains on screen t2 to the top of screen t3.
_PutImage (0, fh), t1
img = _CopyImage(t2, 33)
_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 t2: t2 = 0 ' Free screen t2 and zero the handle.
Return ' Note: We will get back to screen 0 destination and free t3 back in the calling routine.

FormMove:
FormT = FormT + m1: FormL = FormL + m2 ' Change form cordinates.
_Display ' Update the screen so we can toss the old hardware form.
PCopy 1, 0 ' Restore the software background. (Removes the software input.)
GoSub Reprint_Text
_PutImage ((FormL - 1) * fw, (FormT - 1 + tbr) * fh), img ' Move hardware image.
Return

Reprint_Text:
Locate yfld + (FormT - 1), xfld + (FormL - 1): Print Space$(fldlen + 1);
Locate yfld + (FormT - 1), xfld + (FormL - 1): Print text$;
Locate FormT - 1 + yfld, FormL - 1 + xfld + ccp%, 1 ' Reposition and show cursor.
Return

Close_Form:
PCopy 1, 0: Locate , , 0: text$ = "": ccp% = 0
Return

Pete


RE: Peek-a-boo Hardware Form Concept - PhilOfPerth - 04-04-2025

(04-04-2025, 01:20 AM)Pete Wrote: So the concept is to make a hardware form with a transparent input slot in which our SCREEN 0 program can display text.

Code: (Select All)
$Color:32
w = _Width: h = _Height
fw = _FontWidth: fh = _FontHeight
Dim As Long t, img
t = _NewImage(250, 100, 32)
_Dest t
Color _RGB32(90, 90, 90)
For h = 1 To 100 \ fh
    Locate h, 1
    For i = 1 To 250 \ fw ' Build form out of solid blocks except over text input area.
        If h = 4 Then
            If i >= 9 And i <= 29 Then
                Locate , Pos(0) + 1
            Else
                Print Chr$(219);
            End If
        Else
            Print Chr$(219);
        End If
    Next
Next
Color White, _RGB(90, 90, 90) ' add text to the form and outline the input bo.
Locate 2, 13: Print "My Form"
Locate 4, 3: Print "Text:"
Line (fw * 8 - 3, fh * 3 - 3)-(fw * 29 + 2, fh * 4 + 2), _RGB32(255, 255, 255), B
img = _CopyImage(t, 33)
_FreeImage t
_Dest 0
Color 15, 0
Locate 4, 9, 1, 7, 7 ' Show cursor.
Do
    _Limit 30
    _PutImage (0, 0), img
    b$ = InKey$
    If b$ = Chr$(8) And Pos(0) > 9 Then
        Locate , Pos(0) - 1: Print " ";: Locate , Pos(0) - 1
        _Continue
    End If
    If b$ = Chr$(27) Then System
    If Len(b$) = 1 And Pos(0) < 29 Then
        If Asc(b$) >= 32 And Asc(b$) <= 122 Then
            Print b$;
        End If
    End If
Loop

For folks who are very comfortable in graphics, the line with BF statement could have been used multiple times to make the block minus the input slot.

If anyone thinks they have an easier method, using a hardware form on top of Screen 0, let me know. It would be a fun discussion.

Pete

Fascinating, and ingenious! (not that I'm ever likely to use screen zero).
Great for Zerophiles!  Big Grin


RE: Peek-a-boo Hardware Form Concept - Pete - 04-04-2025

That's Zero-ASCII-ters and not to be confused with Zoroasters who obviously worship a lesser god. 

Big Grin Big Grin Big Grin


RE: Peek-a-boo Hardware Form Concept - TempodiBasic - 04-04-2025

Hi Pete
I find it remarkable!

here output

[Image: Hardware-image-form-by-Pete.jpg]

I find that sometimes the image of form flickers.

Please take a loot at this https://qb64phoenix.com/forum/showthread.php?tid=3586


RE: Peek-a-boo Hardware Form Concept - Pete - 04-04-2025

@TempodiBasic

I don't get any flicker effect using _Limit 30 on mine. Try changing that to _Limit 60 and let me know if the problem is solved.

I'm glad you have an interest in this area. This is the next revolution of SCREEN 0. (The screen that just won't die!!!!) Big Grin 

Pete


RE: Peek-a-boo Hardware Form Concept - Pete - 04-05-2025

Third installment is a movable popup and something interesting had to be done to mask that hollow input space...

Post #1, code box 3.

I'll probably finish this thread by adding a shadow and chaotic background to the final example.

Pete


RE: Peek-a-boo Hardware Form Concept - TempodiBasic - 04-06-2025

(04-04-2025, 04:07 PM)Pete Wrote: @TempodiBasic

I don't get any flicker effect using _Limit 30 on mine. Try changing that to _Limit 60 and let me know if the problem is solved.

I'm glad you have an interest in this area. This is the next revolution of SCREEN 0. (The screen that just won't die!!!!) Big Grin 

Pete

Yeah, i confirm that a _limit 60 works fine on my notebook Ideapad towards _limit 30.
And I can assure that a _Display typed just after _Putimage(0,0),img works fine too.

Again well done man!


RE: Peek-a-boo Hardware Form Concept - Pete - 04-07-2025

Finished the final stage of this little venture.

Added some neat effects. See the 4th code box for a description and the finished routine.

Pete


RE: Peek-a-boo Hardware Form Concept - bplus - 04-08-2025

Shouldn't it poof with an enter or escape Keypress?

Maybe you'd like to try an exploding type poof! Big Grin give it a little pizzazz like the title bar gradient.


RE: Peek-a-boo Hardware Form Concept - TempodiBasic - 04-08-2025

Fine

[Image: Screen-0-system-with-hardware-images-by-Pete.jpg]