I would like to create flat buttons with a different background color when the mouse cursor is hovered on the item. So far, no problem. But I would like that he has a color border around it, like this picture:

So far the code:
Code: Select all
Procedure HoverGad(Gad)
Protected Pt.Point,Rc.Rect
GetCursorPos_(Pt)
GetWindowRect_(GadgetID(Gad),Rc)
ProcedureReturn PtInRect_(@Rc,Pt\X|Pt\Y<<32)
EndProcedure
;==================================================================================================
Macro GadRGB(Gad,Front=#White,Back=#Black)
SetGadgetColor(Gad,#PB_Gadget_FrontColor,Front)
SetGadgetColor(Gad,#PB_Gadget_BackColor,Back)
EndMacro
;==================================================================================================
Procedure CheckOver(Ev,Gad,HoverTextRGB=#Red,HoverBackRGB=#Green,TextRGB=#Blue,BackRGB=#White)
Static Hover
If MMk=0 And Ev=#WM_MOUSEMOVE
If HoverGad(Gad)
If Hover=0
GadRGB(Gad,HoverTextRGB,HoverBackRGB)
Hover=Gad
EndIf
ElseIf Hover=Gad
GadRGB(Gad,TextRGB,BackRGB)
Hover=0
EndIf
EndIf
EndProcedure
;==================================================================================================
TextRGB=#Blue
BackRGB=$F0F0F0
BorderColor=#Black; unused at this time
;==================================================================================================
HoverTextRGB=#Red
HoverBackRGB=$FFE0C2
HoverBorderColor=$FF9933; unused at this time
SelectTextRGB=#Green
;==================================================================================================
OpenWindow(0, 0, 0, 300, 500, "TextGadget as Button", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0,$f0f0f0)
MyfontId=FontID(LoadFont(#PB_Any,"Segoe UI",9))
TextGadget(1, 10, 100, 190,20,"Borderless Button", #PB_Text_Center|#SS_NOTIFY)
SetGadgetFont(1,MyfontId)
GadRGB(1,TextRGB,BackRGB)
TextGadget(2, 10, 150, 190,18,"Button 2", #PB_Text_Center|#WS_BORDER|#SS_NOTIFY)
SetGadgetFont(2,MyFontID)
GadRGB(2,TextRGB,BackRGB)
Repeat
If GetAsyncKeyState_(27)&$8000 : End : EndIf
Ev = WaitWindowEvent()
If Ev = #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "Clicked on button #1"
GadRGB(EventGadget(),SelectTextRGB,BackRGB)
Case 2
Debug "Clicked on button #2"
GadRGB(EventGadget(),SelectTextRGB,BackRGB)
EndSelect
Else
CheckOver(Ev,1,HoverTextRGB,HoverBackRGB,TextRGB,BackRGB)
CheckOver(Ev,2,HoverTextRGB,HoverBackRGB,TextRGB,BackRGB)
EndIf
Until Ev = #PB_Event_CloseWindow
;==================================================================================================
The Button2 has a fixed black color, using the flag #WS_BORDER, should normally not be changed.
Thanks in advance.