Improved Simple Gadgets Part 2

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

Improved Simple Gadgets Part 2

Postby Redlion » Fri Sep 25, 2015 5:07 pm

Hi all,

Here are some of the gadget files. I will write some simple instructions and post them at the end.

(Save as G_Label.hws )
Code: Select all
; ************************************************************************************************
; Gadget Include
; GadgetLabel -  Text only gadget. Read, Write no Input.
; Gadget Type = 1
; By Leo den Hollander
; *************************************************************************************************

Function GadgetLabel(GID,x,y,w,h,Text$,Border)
    GadgetBColor[GID] = BGC
    GadgetFColor[GID] = FGC
    If Border = 0
        SetFillStyle(#FILLCOLOR)
     Box(x, y, w, h, ScreenC)
        GadgetBColor[GID] = ScreenC
    ElseIf Border = 1
        SetFillStyle(#FILLCOLOR)
        Box(x, y, w, h, BGC)
    ElseIf Border = 2
        SetFillStyle(#FILLCOLOR)
        Box(x, y, w, h, #BLACK)
        Box(x+1, y+1, w-2, h-2,BGC)
    EndIf
    SetFont(Font,Size)
    SetFontColor(FGC)
    TextOut(x+4,y+3,Text$)
    GadgetX[GID] = x
    GadgetY[GID] = y
    GadgetW[GID] = w
    GadgetH[GID] = h
    GadgetText[GID] = Text$
    GadgetType[GID] = 1
    GadgetState[GID] = 0
    GadgetBorder[GID] = Border
    GadgetRangeLow[GID] = 0
    GadgetRangeHigh[GID] = 0
    GadgetGroup[GID] = 0
    GadgetItemCount[GID] = 0
    GadgetItem[GID][0][0] = ""
    GadgetFont[GID] = Font
    GadgetFontSize[GID] = Size
    MaxGadgets = MaxGadgets + 1
EndFunction


(Save as G_String.hws )
Code: Select all
; ************************************************************************************************
; Gadget Include
; GadgetString -  String. Read, Write and Input.
; Gadget Type = 2
; By Leo den Hollander
; *************************************************************************************************

Function GadgetString(GID, x, y, w, h, Text$)
    SetFillStyle(#FILLCOLOR)                                                                     
    Box(x, y, w, h, #SILVER)
    Box(x+2, y+2, w-4, h-4, #WHITE)
    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))
    TextOut(x+4, y+3, Text$)
    MakeButton(GID, #SIMPLEBUTTON, x, y, w, h, Gadget)
    GadgetX[GID] = x
    GadgetY[GID] = y
    GadgetW[GID] = w
    GadgetH[GID] = h
    GadgetText[GID] = Text$
    GadgetType[GID] = 2
    GadgetState[GID] = 0
    GadgetBorder[GID] = 0
    GadgetRangeLow[GID] = 0
    GadgetRangeHigh[GID] = 0
    GadgetGroup[GID] = 0
    GadgetItemCount[GID] = 0
    GadgetItem[GID][0][0] = ""
    GadgetFont[GID] = Font
    GadgetFontSize[GID] = Size
    GadgetBColor[GID] = #WHITE
    GadgetFColor[GID] = FGC
    MaxGadgets = MaxGadgets + 1
EndFunction   


( Save as G_Button.hws )
Code: Select all
; ************************************************************************************************
; Gadget Include
; Gadget Button - Input.
; Gadget Type = 3
; By Leo den Hollander
; *************************************************************************************************

Function GadgetButton(GID, x, y, w, h, Text$)
    SetLineWidth(1)
    SetFillStyle(#FILLCOLOR)                                      ; Gadget bevel
    Box(x, y, w, h, #SILVER)                                      ; Draw bevel
    SetFillStyle(#FILLNONE)                                       ; BC fill drawing
    Line(x+1, y+1, x+w-2, y+1,RGB(224,224,224))                   ; Inner bevel
    Line(x+1, y+1, x+1, y+h-2,RGB(224,224,224))                   ; Inner bevel
    Line(x+w-2, y+1, x+w-2, y+h-2, #BLACK)                        ; Inner bevel
    Line(x+1, y+h-2, x+w-2, y+h-2, #BLACK)                        ; Gadget face
    SetFont(Font,Size)                                            ; Font used on gadget face
    Local TW = TextWidth(Text$)                                   ; size of text on gadget face
    Local BW =(w / 2) - (TW / 2)                                  ; Centre text position
    Local TH = TextHeight(Text$)                                  ; size of text on gadget face
    Local BH =(h / 2) - (TH / 2) 
    SetFontColor(FGC)                                             ; Text colour
    TextOut(x + BW,y + BH, Text$)
    MakeButton(GID, #SIMPLEBUTTON, x, y, w, h, Button)
    GadgetX[GID] = x
    GadgetY[GID] = y
    GadgetW[GID] = w
    GadgetH[GID] = h
    GadgetText[GID] = Text$
    GadgetType[GID] = 3
    GadgetState[GID] = 0
    GadgetBorder[GID] = 0
    GadgetRangeLow[GID] = 0
    GadgetRangeHigh[GID] = 0
    GadgetGroup[GID] = 0
    GadgetItemCount[GID] = 0
    GadgetItem[GID][0][0] = ""
    GadgetFont[GID] = Font
    GadgetFontSize[GID] = Size
    GadgetBColor[GID] = BGC
    GadgetFColor[GID] = FGC
    MaxGadgets = MaxGadgets + 1   
EndFunction 


Leo
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
User avatar
Redlion
 
Posts: 62
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Return to Code snippets area

Who is online

Users browsing this forum: No registered users and 1 guest