## Improved Simple Gadgets Part 3

You can post your code snippets here for others to use and learn from
Redlion
Posts: 71
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

### Improved Simple Gadgets Part 3

Hi all,

( Save as G_Check.hws )

Code: Select all

``````; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetCheck(GID, x, y, w, h, Text\$)
SetLineWidth(1)
SetFillStyle(#FILLCOLOR)
Box(x, y, 25, 25, #SILVER)
SetFillStyle(#FILLNONE)
Line(x+1, y+1, x+25-2, y+1, #BLACK)
Line(x+1, y+1, x+1, y+25-2, #BLACK)
Line(x+25-2, y+1, x+25-2, y+25-2, RGB(224,224,224))
Line(x+1, y+25-2, x+25-2, y+25-2, RGB(224,224,224))
SetFont(Font,Size)
SetFontColor(FGC)
TextOut(x+30,y+3,Text\$)
MakeButton(GID, #SIMPLEBUTTON, x, y, 25, 25, Gadget)
EndFunction

Function p_SetCheck(id)
SetFillStyle(#FILLCOLOR)                                ; Set colour fill mode
Box(GadgetX[id] + 2, GadgetY[id] + 2, 21, 21, #SILVER)  ; Blank out X
SetFormStyle(#ANTIALIAS)                                ; Set Antialias
If GadgetState[id] = 0                                  ; Check State if 0
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
SetFormStyle(#NORMAL)
GadgetState[id] = 1                                 ; Set state = 1
Else
Box(GadgetX[id] + 2, GadgetY[id] + 2, 21, 21, #SILVER)  ; Clear check mark
GadgetState[id] = 0                                 ; Set state = 0
EndIf
SetFormStyle(#NORMAL)                                   ; Reset to Normal Style
EndFunction
``````
( Save as G_Option.hws )

Code: Select all

``````; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetOption(GID, x, y, w, h, Text\$, Group)
SetLineWidth(1)
SetFillStyle(#FILLCOLOR)
Box(x, y, 25, 25, #SILVER)
SetFillStyle(#FILLNONE)
Line(x+1, y+1, x+25-2, y+1,#BLACK)
Line(x+1, y+1, x+1, y+25-2,#BLACK)
Line(x+25-2, y+1, x+25-2, y+25-2,RGB(224,224,224))
Line(x+1, y+25-2,x+25-2,y+25-2,RGB(224,224,224))
SetFont(Font,Size)
SetFontColor(FGC)
TextOut(x+30, y+3, Text\$)
MakeButton(GID, #SIMPLEBUTTON, x, y, 25, 25, Gadget)
EndFunction

Function p_SetOption(id)
SetFillStyle(#FILLCOLOR)
For Local t = 1 To MaxGadgets                                       ; Need to set this to highest gadget ID
If GadgetGroup[t] = GadgetGroup[id]                             ; Check if Option group matches ids group
Box(Gadgetx[t] + 3, Gadgety[t] + 3, 19, 19, #SILVER)        ; Turn all options off
GadgetState[t] = 0                                          ; Set state = 0
EndIf
Next
SetFormStyle(#ANTIALIAS)                                            ; Set antialias
SetFormStyle(#NORMAL)                                               ; Rest to Normal Style
GadgetState[id] = 1                                                 ; Set state = 1
EndFunction
``````
( Save as G_Select.hws )

Code: Select all

``````; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetSelect(GID, x, y, w, h, Text\$)
SetFillStyle(#FILLCOLOR)
Box(x, y, w, h, #SILVER)
SetFillStyle(#FILLNONE)
Line(x+1, y+1, x+w-2, y+1, #BLACK)
Line(x+1, y+1, x+1, y+h-2, #BLACK)
Line(x+w-2, y+1, x+w-2, y+h-2,RGB(224,224,224))
Line(x+1, y+h-2, x+w-2, y+h-2, RGB(224,224,224))
Line(x+w-22, y+1, x+w-22, y+h-3, #BLACK)
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
Polygon(x + w - 18, y + 7, DownArrow, 4, #RED)
SetFormStyle(#NORMAL)
SetFont(Font,Size)
SetFontColor(FGC)
TextOut(x + 4,y + 3, Text\$)
MakeButton(GID, #SIMPLEBUTTON, x, y, w, 25, Gadget)
EndFunction

EndFunction

Function p_SetSelect(id)
Select = GadgetState[id]                                            ; Get state
Select = Select + 1                                                 ; Set next selection
If GadgetItem[id][0][Select] = ""                                   ; Find last rest to first
Select = 0
EndIf
GadgetState[id] = Select                                            ; Set new state
SetFillStyle(#FILLCOLOR)                                            ; Set colour fill mode
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
SetFormStyle(#NORMAL)
SetFont(Font,Size)                                                  ; Font used on gadget face
SetFontColor(FC)
SelColumn = 0
EndFunction
``````
( Save as G_Slider.hws )

Code: Select all

``````; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetSlider(GID, x, y, w, h, Start, Stop)
SetFillStyle(#FILLCOLOR)
Box(x, y, w, 25, RGB(160,160,160))
SetFillStyle(#FILLNONE)
Line(x+1, y+1, x+w-2, y+1, #BLACK)
Line(x+1, y+1, x+1, y+25-2, #BLACK)
Line(x+w-2, y+1, x+w-2, y+25-2, RGB(224,224,224))
Line(x+1, y+25-2 ,x+w-2, y+25-2, RGB(224,224,224))
MakeButton(GID, #SIMPLEBUTTON, x, y, w, 25, Gadget)
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
Box(x + 2, y + 3, 19, 18, #GRAY, {roundlevel=25})
SetFillStyle(#FILLNONE)
Box(x + 2, y + 3, 19, 18, \$444444, {roundlevel=25})
SetFormStyle(#NORMAL)
EndFunction

Function p_SetSlider(id)
Repeat
Pressed = 0
Local DPosX = MouseX()
Local DPosY = MouseY()
If DposX < GadgetX[id] + 2
EndIf
EndIf
If IsLeftMouse() = False
Pressed = 1
EndIf
BeginDoubleBuffer()
SetFillStyle(#FILLCOLOR)
SetFormStyle(#ANTIALIAS)
Box(DPosX,GadgetY[id] + 3, 19, 18, #GRAY, {roundlevel=25})
SetFillStyle(#FILLNONE)
Box(DPosX, GadgetY[id] + 3, 19, 18, \$444444, {roundlevel=25})
SetFont(Font, Size)
SetFormStyle(#NORMAL)
Flip()
EndDoubleBuffer()
Until Pressed = 1
SelColumn = 0
SetFillStyle(#FILLCOLOR)
EndFunction
``````
( Save as G_Spin.hws )

Code: Select all

``````; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetSpin(GID, x, y, w, h, Start, Stop)
SetFillStyle(#FILLCOLOR)
Box(x, y, w, h, #SILVER)
SetFillStyle(#FILLNONE)
Line(x+1, y+1, x+w-2, y+1,#BLACK)
Line(x+1, y+1, x+1, y+h-2,#BLACK)
Line(x+w-2, y+1, x+w-2, y+h-2,RGB(224,224,224))
Line(x+1, y+h-2,x+w-2,y+h-2, RGB(224,224,224))
Line(x+w-38, y+1, x+w-38, y+h-3,#BLACK)
Line(x+w-20, y+1, x+w-20, y+h-3,#BLACK)
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
Polygon(x+w-34,y+7, DownArrow, 4, #RED)
Polygon(x+w-16,y+7, UpArrow, 4, #RED)
SetFormStyle(#NORMAL)
TextOut(x+4,y+3,StrStr(Start))
MakeButton(GID, #SIMPLEBUTTON, x, y, w, 25, Gadget)
EndFunction

Function p_SetSpin(id)
Local DPosX = MouseX()
Number = Number -1                                          ; Set next selection
If Number < GadgetRangeLow[id]                              ; Find last rest to first
EndIf
EndIf
Number = Number + 1
If Number > GadgetRangeHigh[id]                             ; Find last rest to first
EndIf
EndIf
GadgetState[id] = Number                                        ; Set new state
SetFillStyle(#FILLCOLOR)                                        ; Set colour fill mode
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
SetFormStyle(#NORMAL)
SetFont(Font,Size)                                              ; Font used on gadget face
SetFontColor(FC)
EndFunction
``````
( Save as G_ColorSelect.hws )

Code: Select all

``````; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetColorSelect(GID, x, y, w, h, ColorTable)
SetFillStyle(#FILLCOLOR)
Box(x, y, w, h, #SILVER)
Box(x+2, y+2, w-4, 21, rgb(160,160,160))
Box(X+w-25, y+3, 18, 18, ColorTable[1])
SetFillStyle(#FILLNONE)
Line(x+1, y+1, x+w-2, y+1, #BLACK)
Line(x+1, y+1 ,x+1, y+h-2, #BLACK)
Line(x+w-2, y+1, x+w-2, y+h-2, RGB(224,224,224))
Line(x+1, y+h-2, x+w-2, y+h-2, RGB(224,224,224))
Line(x+1, y+23, x+w-2 ,y+23, #BLACK)
SetFont(Font,Size)                                            ; Font used on gadget face
SetFontColor(FGC)                                             ; Text colour
TextOut(x+5,y+2 , " Color Selection ")
SetFillStyle(#FILLCOLOR)
For c = 1 To 8
Box(x+2+((C-1)*((w-4)/(8))),Y+24,(W/8),(h-25)/2,ColorTable[C])
Box(x+2+((C-1)*((w-4)/(8))),Y+24+(h-26)/2,(W/8),(h-25)/2,ColorTable[C+8])
Next
MakeButton(GID, #SIMPLEBUTTON, x, y, w, h, Gadget)
EndFunction

Function p_SetColor(msg)
Local DPosX = MouseX()
Local DPosY = MouseY()
SetFillStyle(#FILLCOLOR)