a litte improvement ...
that "marks" the last leftclicked gadget.
Code: Select all
EnableExplicit
;
Prototype flatprototype(Pointer, Event = 0)
;
Structure flat_border_button_datas
Gadget.i
Drawing.flatprototype
Text.s
TextColor.i
InnerColor.i
BorderColor.i
BackGroundColor.i
Font.i
ExtraData.i
EndStructure
;
Global lastgadget.i
;
Procedure FlatBorderButtonDraw(*p.flat_border_button_datas, Event = 0)
Protected x, y, th
If *p
If IsGadget(*p\Gadget)
If StartDrawing(CanvasOutput(*p\Gadget))
Select Event
Case 0
; »»» The New Segment
DrawingMode(#PB_2DDrawing_Default)
If lastgadget = *p\Gadget
Box(0,0,OutputWidth(),OutputHeight(),*p\BorderColor)
Box(1,1,OutputWidth()-2,OutputHeight()-2,*p\BackGroundColor)
Else
Box(0,0,OutputWidth(),OutputHeight(),*p\BackGroundColor)
EndIf
; »»» The New Segment Ends
Case 1
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,OutputWidth(),OutputHeight(),*p\BorderColor)
Box(1,1,OutputWidth()-2,OutputHeight()-2,*p\InnerColor)
EndSelect
If IsFont(*p\Font)
DrawingFont(FontID(*p\Font))
EndIf
x = (OutputWidth()/2) - (TextWidth(*p\Text)/2)
y = (OutputHeight()/2) - (TextHeight(*p\Text)/2)
DrawingMode(#PB_2DDrawing_Default|#PB_2DDrawing_Transparent)
DrawText(x,y,*p\Text,*p\TextColor)
StopDrawing()
EndIf
EndIf
EndIf
EndProcedure
;
Procedure FlatBorderButton(Gadget, x, y, Width, Height, Text.s, TextColor, BackGroundColor, InnerColor, BorderColor, Font)
Protected *p.flat_border_button_datas = AllocateMemory(SizeOf(flat_border_button_datas))
Protected ID
If Not *p : ProcedureReturn #False : EndIf
InitializeStructure(*p, flat_border_button_datas)
ID = CanvasGadget(Gadget, x, y, Width, Height)
If Gadget = #PB_Any : Gadget = ID : EndIf
SetGadgetData(Gadget, *p)
*p\Gadget = Gadget
*p\Text = Text
*p\BorderColor = BorderColor
*p\BackGroundColor = BackGroundColor
*p\InnerColor = InnerColor
*p\Font = Font
*p\Drawing = @FlatBorderButtonDraw()
*p\Drawing(*p, 0)
ProcedureReturn ID
EndProcedure
;
Procedure FlatBorderButtonEvents(Gadget, Event, EventType)
Protected *p.flat_border_button_datas
Protected *q.flat_border_button_datas ; »»» need to declare the last active gadget
If IsGadget(Gadget)
*p = GetGadgetData(Gadget)
If *p
If Event = #PB_Event_Gadget
Select EventType
Case #PB_EventType_MouseEnter, #PB_EventType_MouseMove, #PB_EventType_RightButtonDown
*p\Drawing(*p, 1)
Case #PB_EventType_LeftButtonDown ; »»» declares the lastgadget to the new click and delete the old
If IsGadget(lastgadget)
*q = GetGadgetData(lastgadget)
lastgadget = *p\Gadget
If *q
*q\Drawing(*q, 0)
EndIf
EndIf
lastgadget = *p\Gadget
*p\Drawing(*p, 1)
Default
*p\Drawing(*p, 0)
EndSelect
EndIf
EndIf
EndIf
EndProcedure
;
DisableExplicit
OpenWindow(0,200,300,800,600,"TestWindow")
Font = LoadFont(#PB_Any, "Segoe UI", 9)
FlatBorderButton(1, 20, 25, 300, 25, "Printer", 0, $F0F0F0, $FFE0C2, $FF9933, Font)
FlatBorderButton(2, 20, 50, 300, 25, "Computer", 0, $F0F0F0, $FFE0C2, $FF9933, Font)
FlatBorderButton(3, 20, 75, 300, 25, "Mouse", 0, $F0F0F0, $FFE0C2, $FF9933, Font)
FlatBorderButton(4, 20, 100, 300, 25, "Keyboard", 0, $F0F0F0, $FFE0C2, $FF9933, Font)
FlatBorderButton(5, 20, 125, 300, 25, "Hard Disk", 0, $F0F0F0, $FFE0C2, $FF9933, Font)
*p.flat_border_button_datas
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_LeftClick ; »»» need to delete the last mark if click somewhere in window
If IsGadget(lastgadget)
*p = GetGadgetData(lastgadget)
If *p
lastgadget = -1
*p\Drawing(*p, 0)
EndIf
EndIf
lastgadget = -1 ; »»» make sure that no gadget can have this number
Case #PB_Event_Gadget
FlatBorderButtonEvents(EventGadget(), Event, EventType())
Select EventType()
Case #PB_EventType_LeftClick
Select EventGadget()
Case 1
Debug "Click on Printer"
Case 2
Debug "Click on Computer"
Case 3
Debug "Click on Mouse"
Case 4
Debug "Click on Keyboard"
Case 5
Debug "Click on HardDisk"
EndSelect
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit > 0