04-04-2025, 11:57 AM
Hi
following the idea of Pete to use hardware images in SCREEN 0 for getting different graphic output effects here it follows the evolution of my demo with PopUp menu at mouse location passing through hardware images.
User uses a left click in the area of the window application and he gets back a popup menu (this popup appears over the button if click has been performed over the area of the button) unless the click is too near to the edge of the window and there is no useful area to show popup.
Moving the mouse on the popup it highlightes the item pointed by mouse. When the user makes a leftclick out of menu this last has been canceled/disactivated. When the user makes a leftclick on the first item of popup menu, he activates the inputbox which reacts only to keyboard inputs.
Esc abortes the input action, Enter quits the inputbox returning the input taken, backspace cancel the last character typed, A-Z a-z and space are the characterd allowed.
here screenshots:
![[Image: 1-Hardware-study4.jpg]](https://i.ibb.co/tpFRJsWM/1-Hardware-study4.jpg)
![[Image: 2-hardware-study4.jpg]](https://i.ibb.co/qF1pdZTf/2-hardware-study4.jpg)
![[Image: 3-hardware-study4.jpg]](https://i.ibb.co/Y4fFHXsf/3-hardware-study4.jpg)
![[Image: 4-hardware-study4.jpg]](https://i.ibb.co/sJN5DGnR/4-hardware-study4.jpg)
here the code:
Waiting your feedbacks, comments and ideas.
Thanks for looking at this.
following the idea of Pete to use hardware images in SCREEN 0 for getting different graphic output effects here it follows the evolution of my demo with PopUp menu at mouse location passing through hardware images.
User uses a left click in the area of the window application and he gets back a popup menu (this popup appears over the button if click has been performed over the area of the button) unless the click is too near to the edge of the window and there is no useful area to show popup.
Moving the mouse on the popup it highlightes the item pointed by mouse. When the user makes a leftclick out of menu this last has been canceled/disactivated. When the user makes a leftclick on the first item of popup menu, he activates the inputbox which reacts only to keyboard inputs.
Esc abortes the input action, Enter quits the inputbox returning the input taken, backspace cancel the last character typed, A-Z a-z and space are the characterd allowed.
here screenshots:
![[Image: 1-Hardware-study4.jpg]](https://i.ibb.co/tpFRJsWM/1-Hardware-study4.jpg)
![[Image: 2-hardware-study4.jpg]](https://i.ibb.co/qF1pdZTf/2-hardware-study4.jpg)
![[Image: 3-hardware-study4.jpg]](https://i.ibb.co/Y4fFHXsf/3-hardware-study4.jpg)
![[Image: 4-hardware-study4.jpg]](https://i.ibb.co/sJN5DGnR/4-hardware-study4.jpg)
here the code:
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
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 Asc(Taken, 1) = 45 Then
Taken = ""
ElseIf Len(Taken) > 1 Then
Taken = Left$(Taken, Len(Taken) - 1)
GoSub ShowPopInput
' _Delay 0.5
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 Asc(Taken, 1) = 45 Then Taken = ""
Taken = Taken + Chr$(InK)
GoSub ShowPopInput
End Select
Loop
PopUp = 1 ' only popup must be showed
_KeyClear
Return
ShowPopInput:
PopImg = _NewImage(8 * Len(Taken) + 1, 16 * 1, 32)
_Dest PopImg
Color _RGBA32(222, 200, 6, 255), _RGBA32(67, 67, 100, 255)
_PrintString (1, 1), Taken
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
' input is showed
_PutImage ((Xm - 1) * 8, (Y - 1) * 16), PopImgH, 0
_Display
_FreeImage PopImg
_FreeImage PopImgH
Return
Waiting your feedbacks, comments and ideas.
Thanks for looking at this.