Code : Tout sélectionner
; PureBasic 3.93
; Idea from Localmotion34
Structure Bargraph
x.l
y.l
width.l
height.l
medium.f
hight.f
full.f
Image.l
Gadget.l
EndStructure
ProcedureDLL BargraphH(x,y,width,height,medium.f,hight.f,full.f)
; Initialise the LinkedList the first call
Static Init
If Init=0
NewList BargraphHLList.Bargraph()
EndIf
Init=1
; Fill the Structure
AddElement(BargraphHLList())
BargraphHLList()\x=x
BargraphHLList()\y=y
BargraphHLList()\width=width
BargraphHLList()\height=height
BargraphHLList()\medium=medium
BargraphHLList()\hight=hight
BargraphHLList()\full=full
BargraphHLList()\Image=CreateImage(#PB_Any,width,height)
; create the gadget & show the image
BargraphHLList()\Gadget=ImageGadget(#PB_Any,x,y,width,height,UseImage(BargraphHLList()\Image),#PB_Image_Border)
; Return the gadget id
ProcedureReturn ListIndex(BargraphHLList())
EndProcedure
ProcedureDLL BargraphHSet(id,value.f)
SelectElement(BargraphHLList(),id)
Ptr.f= ( value / BargraphHLList()\full )*BargraphHLList()\width
; Rouge
color=RGB(255,0,0)
; Jaune
If value > BargraphHLList()\medium
color=RGB(255,255,0)
EndIf
; Vert
If value > BargraphHLList()\hight
color=RGB(0,255,0)
EndIf
; dessine
UseImage(BargraphHLList()\Image)
StartDrawing(ImageOutput())
Box(0,0,Ptr,BargraphHLList()\height,color)
StopDrawing()
SetGadgetState(BargraphHLList()\Gadget,UseImage(BargraphHLList()\Image))
EndProcedure
;/ Test
OpenWindow(0, 0, 0, 250, 250, #PB_Window_SystemMenu | #PB_Window_ScreenCentered , "Bargraph")
CreateGadgetList(WindowID())
a=BargraphH(10,10,228,50,3000,6000,9000)
b=BargraphH(10,80,228,10,1500,3000,4500)
c=BargraphH(10,110,228,50,3000,8000,18000)
For n= -5000 To 9000 Step 20
BargraphHSet(a,n)
BargraphHSet(b,n)
BargraphHSet(c,n)
Delay(10)
If WindowEvent()= #PB_Event_CloseWindow : End : EndIf
Next
Delay(2000)