String Gadget Highlight
Posted: Tue Jun 03, 2008 9:40 am
I haven't posted any tips in a long time, so here's a quick one:
Highligth current string gadget!
It can be edited for any type of gadget, but i needed this for strings
You can also colour other things like the background, etc...
Highligth current string gadget!
It can be edited for any type of gadget, but i needed this for strings

You can also colour other things like the background, etc...
Code: Select all
;- GadgetHighlight
Procedure GadgetHighLigth()
Static Last_Gadget.l, Last_Gadget_Color.l
current_gadget.l = GetActiveGadget()
If IsGadget(current_gadget)
If current_gadget<>last_gadget
If GadgetType(current_gadget) = #PB_GadgetType_String
current_color.l = GetGadgetColor(current_gadget, #PB_Gadget_FrontColor) ;Font colour, but can be anything supported!
SetGadgetColor(current_gadget, #PB_Gadget_FrontColor, RGB(255,0,0))
If IsGadget(Last_Gadget)
SetGadgetColor(Last_Gadget, #PB_Gadget_FrontColor, Last_Gadget_Color)
EndIf
Last_Gadget = current_gadget
Last_Gadget_Color = current_color.l
ElseIf IsGadget(Last_Gadget)
If GadgetType(current_gadget)<>#PB_GadgetType_String And GadgetType(last_gadget) = #PB_GadgetType_String
If IsGadget(Last_Gadget)
SetGadgetColor(Last_Gadget, #PB_Gadget_FrontColor, Last_Gadget_Color)
Last_Gadget = current_gadget
EndIf
EndIf
EndIf
EndIf
EndIf
EndProcedure
;- Window Constants
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#String_0
#String_1
#String_2
#Listview_0
#String_3
#Button_0
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 234, 187, 424, 279, "Gadget Higlight", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
StringGadget(#String_0, 35, 25, 130, 25, "1st String")
StringGadget(#String_1, 35, 65, 130, 25, "2nd String")
StringGadget(#String_2, 35, 105, 130, 25, "3rd String")
ListViewGadget(#Listview_0, 200, 25, 195, 140)
StringGadget(#String_3, 200, 170, 195, 25, "4th string")
ButtonGadget(#Button_0, 140, 220, 120, 40, "test button")
EndIf
EndIf
EndProcedure
Open_Window_0()
SetActiveGadget(#String_1)
Repeat ; Start of the event loop
Event = WaitWindowEvent() ;
WindowID = EventWindow() ;
GadgetID = EventGadget() ;
EventType = EventType() ;
If Event = #PB_Event_Gadget
; /// Call the Highlight procedure here
GadgetHighLigth()
If GadgetID = #String_0
ElseIf GadgetID = #String_1
ElseIf GadgetID = #String_2
ElseIf GadgetID = #Listview_0
ElseIf GadgetID = #String_3
ElseIf GadgetID = #Button_0
EndIf
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End