Improved Simple Gadgets Part 5

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

Improved Simple Gadgets Part 5

Postby Redlion » Fri Sep 25, 2015 7:27 pm

Hi all,

Forgot a few things,

( Save as G_SetBGColor.hws )
Code: Select all
; ************************************************************************************************
; Gadget Include
; Set Gadget Background Color
; Gadget Type 1,2,3,4,5
; By Leo den Hollander
; *************************************************************************************************

Function SetGadgetBColor(GID,BGC)
    SetFillStyle(#FILLCOLOR)
    SetFont(GadgetFont[GID], GadgetFontSize[GID])
    GadgetBColor[GID] = BGC
    SetFontColor(GadgetFColor[GID])
    If GadgetType[GID] = 1
        If GadgetBorder[GID] = 0
            Box(GadgetX[GID], GadgetY[GID], GadgetW[GID], GadgetH[GID], ScreenC)
        ElseIf GadgetBorder[GID] = 1   
            Box(GadgetX[GID], GadgetY[GID], GadgetW[GID], GadgetH[GID], BGC)
        ElseIf GadgetBorder[GID] = 2
            Box(GadgetX[GID], GadgetY[GID], GadgetW[GID], GadgetH[GID], #BLACK)
            Box(GadgetX[GID] + 1, GadgetY[GID] + 1, GadgetW[GID] - 2, GadgetH[GID] - 2, BGC)
        EndIf
        TextOut(GadgetX[GID] + 4, GadgetY[GID]+3, GadgetText[GID])
    ElseIf GadgetType[GID] = 2 
        Box( GadgetX[GID] + 2, GadgetY[GID] + 2, GadgetW[GID] - 4, GadgetH[GID] - 4, GadgetBColor[GID])
        TextOut(GadgetX[GID] + 4, GadgetY[GID] + 3, GadgetText[GID])
    ElseIf GadgetType[GID] = 3
        Local TW = TextWidth(GadgetText[GID])                                         ; size of text on gadget face
        Local BW =(GadgetW[GID] / 2) - (TW / 2)                                       ; Centre text position
        Local TH = TextHeight(GadgetText[GID])                                        ; size of text on gadget face
        Local BH = (GadgetH[GID] / 2) - (TH / 2) 
        Box(GadgetX[GID] + 3, GadgetY[GID] + 3, GadgetW[GID] - 6, GadgetH[GID] - 6, GadgetBColor[GID])
        TextOut(GadgetX[GID] + BW, GadgetY[GID] + BH, GadgetText[GID])
    ElseIf GadgetType[GID] = 4 Or GadgetType[GID] = 5
        Box(GadgetX[GID] + 2, GadgetY[GID] + 2, GadgetW[GID] - 4, GadgetH[GID] - 4, GadgetBColor[GID])
        TextOut(GadgetX[GID] + 4, GadgetY[GID] + 3, GadgetText[GID])
    EndIf
EndFunction 


( Save as G_SetFGColor.hws )
Code: Select all
; ************************************************************************************************
; Gadget Include
; Set Gadget Front Color
; Gadget Type 1,2,3,4,5
; By Leo den Hollander
; *************************************************************************************************

Function SetGadgetFColor(GID,FGC)
    SetFillStyle(#FILLCOLOR)
    SetFont(GadgetFont[GID], GadgetFontSize[GID]) 
    GadgetFColor[GID] = FGC
    SetFontColor(GadgetFColor[GID])
    If GadgetType[GID] = 1 Or GadgetType[GID] = 2
        Box(GadgetX[GID] + 2, GadgetY[GID] + 2, GadgetW[GID] - 4, GadgetH[GID] - 4, GadgetBColor[GID])
        TextOut(GadgetX[GID] + 4, GadgetY[GID] + 3, GadgetText[GID])
    ElseIf GadgetType[GID] = 3
        Local TW = TextWidth(GadgetText[GID])                                         ; size of text on gadget face
        Local BW = (GadgetW[GID] / 2) - (TW / 2)                                             ; Centre text position
        Local TH = TextHeight(GadgetText[GID])                                        ; size of text on gadget face
       Local BH = (GadgetH[GID] / 2) - (TH / 2) 
        Box(GadgetX[GID] + 3, GadgetY[GID] + 3, GadgetW[GID] - 6, GadgetH[GID] - 6, GadgetBColor[GID])
        TextOut(GadgetX[GID] + BW, GadgetY[Gid] + BH, GadgetText[GID])
    ElseIf GadgetType[GID] = 4 Or GadgetType[GID] = 5
        Box(GadgetX[GID] + 2, GadgetY[GID] + 2, GadgetW[GID] - 4, GadgetH[GID] - 4, GadgetBColor[GID])
        TextOut(GadgetX[GID] + 30, GadgetY[GID] + 3, adgetText[GID])
    EndIf
EndFunction


( Save as G_SetText.hws )
Code: Select all
; ************************************************************************************************
; Gadget Include
; Set Gadget Text
; Gadget Type 1,2,3,4,5
; By Leo den Hollander
; *************************************************************************************************

Function SetGadgetText(GID, Text$)
    SetFillStyle(#FILLCOLOR)
    SetFont(GadgetFont[GID],GadgetFontSize[GID]) 
    GadgetText[GID] = Text$
    If GadgetType[GID] = 1 Or GadgetType[GID] = 2
        Box(GadgetX[GID] + 2, GadgetY[GID] + 2, GadgetW[GID] - 4, GadgetH[GID] - 4, GadgetBColor[GID])
        Data$ = Text$
        Local TW = TextWidth(Text$)
        If TW > GadgetW[GID] - 6
            While TW > GadgetW[GID] - 17
                 Data$ = UnleftStr(Data$, 1)
                 TW = TextWidth(Data$)
            Wend
            TextOut(GadgetX[GID] + 4, GadgetY[GID] + 3, Data$.."...")
        Else
            TextOut(GadgetX[GID] + 4, GadgetY[GID] + 3, Data$)
        EndIf
    ElseIf GadgetType[GID] = 3   
        TW = TextWidth(Text$)                                         ; size of text on gadget face
        Local BW =(GadgetW[GID] / 2) - (TW / 2)                                              ; Centre text position
        Local TH = TextHeight(GadgetText[GID])                                        ; size of text on gadget face
        Local BH =(GadgetH[GID] / 2) - (TH / 2) 
        Box(GadgetX[GID] + 3, GadgetY[GID] + 3, GadgetW[GID] - 6, GadgetH[GID] - 6, GadgetBColor[GID])
        TextOut(GadgetX[GID]+BW,GadgetY[Gid]+BH,GadgetText[GID])
    ElseIf GadgetType[GID] = 4 Or GadgetType[GID] = 5
        Box(GadgetX[GID] + 2, GadgetY[GID] + 2, GadgetW[GID] - 4, GadgetH[GID] - 4, GadgetBColor[GID])
        TextOut(GadgetX[GID] + 4, GadgetY[GID] + 3,GadgetText[GID])
    EndIf
EndFunction
 


I think thats all.

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

cron