## Improved Simple Gadgets Part 4

You can post your code snippets here for others to use and learn from

### Improved Simple Gadgets Part 4

Hi all,

Part 4,

(Save as G_Table.hws )
Code: Select all
; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

SetFillStyle(#FILLCOLOR)
Box(x, y, w, h, #SILVER)
Box(x+2, y+2, w-22, 21, 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+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-20, y+2, x+w-20 ,y+h-3, #BLACK)
Line(x+1, y+23, x+w-21, y+23, #BLACK)
Line(x+W-19, y+h-22, x+w-3, y+h-22, #BLACK)
Line(x+W-19, y+h-42, x+w-3, y+h-42, #BLACK)
SetFormStyle(#NORMAL)
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
Polygon(x+w-16,y + h - 38, UpArrow, 4, #RED)
Polygon(x+w-16,y + h - 17, DownArrow, 4, #RED)
SetFormStyle(#NORMAL)
SetFont(Font,Size)
SetFontColor(FC)
TextOut(x + 4,y + 3,Text\$)
MakeButton(GID, #SIMPLEBUTTON, x, y, w, h, Gadget)
EndFunction

Local ColNo = GadgetColumn[GID][0] + 1
Data\$ = Text\$
Local TW = TextWidth(Data\$)
If TW > Col - 15
While TW > Col - 15
Data\$ = UnleftStr(Data\$, 1)
TW = TextWidth(Data\$)
Wend
Data\$ = Data\$.."..."
EndIf
SetFillStyle(#FILLCOLOR)
SetFont(Font,Size)
SetFormStyle(#NORMAL)
EndFunction

Function ChangeTableCell(GID, Text\$ ,Col, Row)
SetFillStyle(#FILLCOLOR)
SetFont(Font,Size)
Local L = 1
For C = 1 To GadgetColumn[GID][0]
If C < 2
Local TW = TextWidth(Data\$)
If TW > GadgetColumn[GID][1] - 15
While TW > GadgetColumn[GID][1] - 15
Data\$ = UnleftStr(Data\$, 1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
Else
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$, 1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
EndIf
Next
L = L + 1
Next
EndIf
SetFormStyle(#NORMAL)
EndFunction

Local Row = GadgetItemCount[GID] + 1
array, I = SplitStr(Text\$, "|")
For Local Col = 1 To I
Next
Local Displayheight = Int((GadgetH[GID] - 27) / 20)
If Displayheight > Row
EndIf
If Row > Displayheight
EndIf
SetFillStyle(#FILLCOLOR)
SetFont(Font,Size)
Local L = 1
For Local C = 1 To GadgetColumn[GID][0]
If C < 2
Local TW = TextWidth(Data\$)
If TW > GadgetColumn[GID][1] - 15
While TW > GadgetColumn[GID][1] - 15
Data\$ = UnleftStr(Data\$, 1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
Else
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$, 1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
EndIf
Next
L = L + 1
Next
Else
EndIf
SetFormStyle(#NORMAL)
EndFunction

Function p_SetTable(id)
Local DPosX = MouseX()
Local DPosY = MouseY()
EndIf
SelColumn = 0
For WC = 0 To GadgetColumn[id][0]
SelColumn = WC+1
EndIf
Next
SetFillStyle(#FILLCOLOR)
SetFillStyle(#FILLCOLOR)
Local L = 1
For Local C = 1 To GadgetColumn[id][0]
If C < 2
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$,1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
Else
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$,1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
EndIf
Next
L = L +1
Next
SetFormStyle(#NORMAL)
EndIf
EndIf
EndIf
L = 1
SetFillStyle(#FILLCOLOR)
EndIf
For Local C = 1 To GadgetColumn[id][0]
If C < 2
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$,1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
Else
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$,1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
EndIf
Next
L = L +1
Next
EndIf
EndIf
L = 1
SetFillStyle(#FILLCOLOR)
EndIf
For Local C = 1 To GadgetColumn[id][0]
If C < 2
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$,1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
Else
Local TW = TextWidth(Data\$)
Data\$ = UnleftStr(Data\$,1)
TW = TextWidth(Data\$)
Wend
Else
EndIf
EndIf
Next
L = L +1
Next
EndIf
EndIf
SetFillStyle(#FILLCOLOR)
Endif
SetFormStyle(#NORMAL)
EndIf
EndFunction

( Save as G_Frame.hws )
Code: Select all
; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetFrame(GID, x, y, w, h, Text\$, Border)
If Border = 0
SetFillStyle(#FILLNONE)
Box(x, y + 9, w, h, BGC)
ElseIf Border = 1
SetFillStyle(#FILLNONE)
Box(x, y + 8, w, h, BGC)
Box(x + 2, y + 10, w - 4, h - 4, BGC)
EndIf
SetFont(Font,Size)
SetFontColor(FGC)
SetFillStyle(#FILLCOLOR)
Box(x + 3, y, TextWidth(Text\$) + 5, TextHeight(Text\$), ScreenC)
TextOut(x + 5, y, Text\$)
EndFunction

(Save as G_ImageButton.hws )
Code: Select all
; ************************************************************************************************
; By Leo den Hollander
; *************************************************************************************************

Function GadgetButtonImage(GID, x, y, w, h, File\$)
SetLineWidth(1)
SetFillStyle(#FILLCOLOR)
Box(x, y, w, h, #SILVER)
SetFillStyle(#FILLNONE)
Line(x+1, y+1, x+w-2, y+1, RGB(224,224,224))
Line(x+1, y+1, x+1, y+h-2, RGB(224,224,224))
Line(x+w-2, y+1, x+w-2, y+h-2, #BLACK)
Line(x+1, y+h-2, x+w-2, y+h-2, #BLACK)
DisplayBrush(GID,x + 3, y + 3, {width = w-6, height = h-6})
MakeButton(GID, #SIMPLEBUTTON, x + 3, y + 3, w - 6, h - 6, Button)
EndFunction

Thats it for the time being, sorry to spread it over so many posts but my internet is not stable at the moment.

There are a few small issues that I will need to address, but from what testing I have done it seems usable.

I will try and get the panel gadget working, but it is proving to be a little difficult to do without layers.

Most of the code should be easy to follow.

Give it a try and let me know if it works for you.

Regards
Leo
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32

Redlion

Posts: 65
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia