LEDgadget
Posted: Wed May 11, 2005 3:38 am
here is a little attempt in my largetr scheme to enhance PB functionality and expand the gadget list to many of the advanced and cool gadgets out there. this is a gauge or LED gadget that tracks percent ranges exactly like that of the task manager processor usage window. just compile the code and move the mouse around and you will see. it's in the beginning stages right now, but shouldnt be too difficult to create a fully working PB library.
tell me what you guys think, or give some suggestions.
NOTE: there will be an optional command to "attatch" the gadget to a process that MUST return a value between 0 and 100 to "monitor" anything really desired.
Code: Select all
Structure gauge
imagegad.l
imageid.l
width.l
height.l
imagehwnd.l
precision.l
ticks.l
EndStructure
NewList led.gauge()
ProcedureDLL LEDgadget(number,x,y,width,height,display)
AddElement(led())
SelectElement(led(),number)
led()\width=width
led()\height=height
led()\imageid=CreateImage(#PB_Any,led()\width,led()\height)
StartDrawing(ImageOutput())
Box(0,0,led()\width,led()\height,#Black)
ledheight=led()\height-20
boxwidth=(led()\width-10-1)/2
secondx= 6+boxwidth
tickcount=0
For a=0 To led()\height-20 Step 4
tickcount=tickcount+1
Box(5,a,boxwidth,3,$7F00)
Box(secondx,a,boxwidth,3,$7F00)
Next
led()\ticks=tickcount
Locate((led()\width/2)-10,led()\height-15)
BackColor(0,0,0)
FrontColor(0, $FF, 0)
DrawText("0%")
StopDrawing()
led()\imagegad=ImageGadget(#PB_Any,x,y,width,height,UseImage(led()\imageid),#PB_Image_Border)
ProcedureReturn led()\imagegad
EndProcedure
ProcedureDLL setLEDstate(led,percent)
SelectElement(led(),led)
tickcount=led()\ticks
perc.f=100/led()\ticks
percents.f=(percent/100)
finalpercent.f=percents*tickcount
stringpercent.s=StrF(finalpercent)
Result.f = Round(finalpercent, 1)
finalresult=led()\ticks-Result
ledheight=led()\height-20
boxwidth=(led()\width-10-1)/2
secondx=6+boxwidth
UseImage(led()\imageid)
StartDrawing(ImageOutput())
tickcount=0
For a=0 To led()\height-20 Step 4
tickcount=tickcount+1
If tickcount>=finalresult
Box(5,a,boxwidth,3,$FF00)
Box(secondx,a,boxwidth,3,$FF00)
Else
Box(5,a,boxwidth,3,$7F00)
Box(secondx,a,boxwidth,3,$7F00)
EndIf
Next
Box(0,led()\height-15,led()\width,15,#Black)
Locate((led()\width/2)-10,led()\height-15)
BackColor(0,0,0)
FrontColor(0, $FF, 0)
DrawText(Str(percent)+"%")
StopDrawing()
SetGadgetState(led()\imagegad,UseImage(led()\imageid))
EndProcedure
#WindowWidth = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, #PB_Window_MinimizeGadget, "")
If CreateGadgetList(WindowID(0))
led=LEDgadget(0,50,50,75,200,0)
EndIf
Repeat
setLEDstate(0,Random(100))
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case led
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
EndIf
End
NOTE: there will be an optional command to "attatch" the gadget to a process that MUST return a value between 0 and 100 to "monitor" anything really desired.