here is a version where you can change the foreground, background and line/box color on the fly. it uses custom messages sent to the window procedure of the meter, and changes the userdata values before the next update.
Code: Select all
Structure Meter
PBimg.l
width.l
height.l
offset.l
values.l[1024]
FGcolor.l
BGcolor.l
Linecolor.l
EndStructure
Structure gauge
imagegad.l
imageid.l
width.l
height.l
imagehwnd.l
precision.l
ticks.l
textgad.l
texthwnd.l
state.l
numstates.l
FGcolor.l
BGcolor.l
Boxcolor.l
EndStructure
Global theThread.l ,themeter.l,nextmeter.l
#WM_UPDATEMETER = #WM_USER+1500
#WM_SETFGCOLOR = #WM_USER+1501
#WM_SETBGCOLOR = #WM_USER+1502
#WM_SETLNCOLOR = #WM_USER+1503
#WM_STATICREFRESH = #WM_USER+1504
#WM_METERCLEAR=#WM_USER+1505
#BGDefault=#Black
#FGdefault=$7F00
#LineDefault=$FF00
#BoxDefault=$FF00
;-Meter Control
Procedure MeterProc(hwnd,msg,wParam,lParam)
Select msg
Case #WM_SETFGCOLOR
*mr.Meter=GetWindowLong_(hwnd,#GWL_USERDATA)
*mr\FGcolor=lParam
SetWindowLong_(hwnd,#GWL_USERDATA,*mr)
Case #WM_SETBGCOLOR
*mr.Meter=GetWindowLong_(hwnd,#GWL_USERDATA)
*mr\BGcolor=lParam
SetWindowLong_(hwnd,#GWL_USERDATA,*mr)
Case #WM_SETLNCOLOR
*mr.Meter=GetWindowLong_(hwnd,#GWL_USERDATA)
*mr\Linecolor=lParam
SetWindowLong_(hwnd,#GWL_USERDATA,*mr)
Case #WM_UPDATEMETER
*mr.Meter=GetWindowLong_(hwnd,#GWL_USERDATA)
If *mr\offset=10
*mr\offset=0
EndIf
For d=0 To *mr\width-1
*mr\values[d]=*mr\values[d+1]
Next
*mr\values[*mr\width-1]=lParam
StartDrawing(ImageOutput(*mr\PBimg))
Box(0,0,*mr\width,*mr\height,*mr\BGcolor)
For a=0 To *mr\height Step 10
LineXY(0,a,*mr\width,a,*mr\FGcolor)
Next
For a=0 To *mr\width+*mr\offset Step 10
LineXY(a-*mr\offset,0,a-*mr\offset,*mr\height,*mr\FGcolor)
Next
For d=0 To *mr\width
bottom.l=*mr\height
thepercent.f=(*mr\values[d]/100)
actualheight.l=Int(thepercent* *mr\height)
Y1.l=bottom-actualheight
thepercent.f=(*mr\values[d+1]/100)
actualheight.l=Int(thepercent* *mr\height)
Y2.l=bottom-actualheight
LineXY(d+1,Y1,d+1,Y2,*mr\Linecolor)
Next
*mr\offset+1
StopDrawing()
SetWindowLong_(hwnd,#GWL_USERDATA,*mr)
SendMessage_(hwnd,#STM_SETIMAGE,#IMAGE_BITMAP,ImageID(*mr\PBimg))
EndSelect
ProcedureReturn CallWindowProc_(GetProp_(hwnd,"oldproc"),hwnd,msg,wParam,lParam)
EndProcedure
Procedure MeterControl(id.l,x,Y,width,height,FGcolor.l, BGcolor.l,LNcolor.l)
image=CreateImage(#PB_Any,width,height)
StartDrawing(ImageOutput(image))
Box(0,0,width,height,#Black)
For a=0 To height Step 10
LineXY(0,a,width,a,$7F00)
Next
For a=0 To width Step 10
LineXY(a,0,a,height,$7F00)
Next
StopDrawing()
imagegad.l=ImageGadget(id,x,Y,width,height,ImageID(image),#PB_Image_Border)
setprop_(GadgetID(imagegad),"oldproc",SetWindowLong_(GadgetID(imagegad),#GWL_WNDPROC,@MeterProc()))
If id=#PB_Any
hwndreturn=imagegad
hwnd=GadgetID(imagegad)
Else
hwndreturn=imagegad
hwnd=imagegad
EndIf
*mtr.Meter=AllocateMemory(SizeOf(Meter))
*mtr\PBimg=image
*mtr\width=width
*mtr\height=height
*mtr\FGcolor=FGcolor
*mtr\BGcolor=BGcolor
*mtr\Linecolor=LNcolor
SetWindowLong_(hwnd,#GWL_USERDATA,*mtr)
ProcedureReturn hwndreturn
EndProcedure
Procedure GetMeterImage(id.l)
*mr.Meter=GetWindowLong_(GadgetID(id),#GWL_USERDATA)
bitmapreturn.l=*mr\PBimg
ProcedureReturn bitmapreturn
EndProcedure
;- LED Gadget Graph
ProcedureDLL LEDgadget(number,x,Y,width,height,FGcolor.l, BGcolor.l,Boxcolor.l)
*led.gauge =ReAllocateMemory(*led.gauge,SizeOf(gauge))
*led\width=width
*led\height=height
*led\FGcolor=FGcolor
*led\BGcolor=BGcolor
*led\Boxcolor=Boxcolor
*led\imageid=CreateImage(#PB_Any,*led\width,*led\height)
StartDrawing(ImageOutput(*led\imageid))
Box(0,0,*led\width,*led\height,*led\BGcolor)
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,*led\FGcolor)
Box(secondx,a,boxwidth,3,*led\FGcolor)
Next
*led\ticks=tickcount
BackColor(*led\BGcolor)
FrontColor(*led\Boxcolor)
DrawText((*led\width/2)-10,*led\height-15,"0%")
StopDrawing()
StaticCtl.l=ImageGadget(number,x,Y,width,height,ImageID(*led\imageid),#PB_Image_Border)
If number=#PB_Any
*led\imagegad=StaticCtl
SetWindowLong_(GadgetID(StaticCtl),#GWL_USERDATA,*led.gauge)
ProcedureReturn *led\imagegad
Else
*led\imagegad=number
SetWindowLong_(GadgetID(number),#GWL_USERDATA,*led.gauge)
ProcedureReturn StaticCtl
EndIf
EndProcedure
ProcedureDLL setLEDstate(led,percent)
*led.gauge=GetWindowLong_(GadgetID(led),#GWL_USERDATA)
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
ImageID(*led\imageid)
StartDrawing(ImageOutput(*led\imageid))
tickcount=0
Box(0,0,*led\width,*led\height,*led\BGcolor)
For a=0 To *led\height-20 Step 4
tickcount=tickcount+1
If tickcount>=finalresult
Box(5,a,boxwidth,3,*led\Boxcolor)
Box(secondx,a,boxwidth,3,*led\Boxcolor)
Else
Box(5,a,boxwidth,3,*led\FGcolor)
Box(secondx,a,boxwidth,3,*led\FGcolor)
EndIf
Next
Box(0,*led\height-15,*led\width,15,*led\BGcolor)
BackColor(*led\BGcolor)
FrontColor(*led\Boxcolor)
DrawText((*led\width/2)-10,*led\height-15,Str(percent)+"%")
StopDrawing()
SetGadgetState(*led\imagegad,ImageID(*led\imageid))
EndProcedure
Procedure SetLEDcolors(id,FGcolor.l, BGcolor.l,Boxcolor.l)
*gg.gauge=GetWindowLong_(GadgetID(id),#GWL_USERDATA)
If FGcolor=#PB_Ignore
Else
*gg\FGcolor=FGcolor
EndIf
If BGcolor=#PB_Ignore
Else
*gg\BGcolor=BGcolor
EndIf
If Boxcolor=#PB_Ignore
Else
*gg\Boxcolor=Boxcolor
EndIf
SetWindowLong_(GadgetID(id),#GWL_USERDATA,*gg.gauge)
EndProcedure
Procedure cpuproc()
Repeat
cpuuse.l=Int(CpuUsage())
SendMessage_(GadgetID(themeter),#WM_UPDATEMETER,0,cpuuse)
SendMessage_(GadgetID(nextmeter),#WM_UPDATEMETER,0,cpuuse)
setLEDstate(10,cpuuse)
Delay(100)
ForEver
EndProcedure
OpenWindow(0,0,0,770,460,"Meter Control",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
themeter.l=MeterControl(#PB_Any,140,10,300,200,#FGdefault,#BGDefault,#LineDefault)
nextmeter.l=MeterControl(#PB_Any,460,10,300,200,#FGdefault,#BGDefault,#LineDefault)
LEDgadget(10,30,10,95,200,#FGdefault,#BGDefault,#BoxDefault)
TrackBarGadget(20,110,300,260,30,0,100)
ButtonGadget(21,160,350,140,20,"Save Meter Image")
ButtonGadget(22,160,370,140,20,"Change Foreground")
ButtonGadget(23,160,390,140,20,"Change Background")
ButtonGadget(24,160,410,140,20,"Change Line\Box Color")
CheckBoxGadget(30,210,220,120,20,"Suspend CPU Query")
theThread.l=CreateThread(@cpuproc(),0)
;SendMessage_(GadgetID(themeter), #WM_SETFGCOLOR,0,#Red)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
If GetGadgetState(30)=1
SendMessage_(GadgetID(themeter),#WM_UPDATEMETER,0,GetGadgetState(20))
SendMessage_(GadgetID(nextmeter),#WM_UPDATEMETER,0,GetGadgetState(20))
setLEDstate(10,GetGadgetState(20))
EndIf
Select EventGadget()
Case 21
Pattern$ + "Bitmap (*.bmp)|*.bmp|"
Pattern = 0
filename.s=SaveFileRequester("Please Choose The File Name To Save", "", Pattern$, Pattern)
If filename
If GetExtensionPart(filename)<>"bmp"
filename+".bmp"
EndIf
SaveImage(GetMeterImage(themeter),filename,#PB_ImagePlugin_BMP)
EndIf
Case 22
color=ColorRequester()
If color
SendMessage_(GadgetID(themeter), #WM_SETFGCOLOR,0,color)
SendMessage_(GadgetID(nextmeter), #WM_SETFGCOLOR,0,color)
SetLEDcolors(10,color,#PB_Ignore,#PB_Ignore)
EndIf
Case 23
color=ColorRequester()
If color
SendMessage_(GadgetID(themeter), #WM_SETBGCOLOR,0,color)
SendMessage_(GadgetID(nextmeter), #WM_SETBGCOLOR,0,color)
SetLEDcolors(10,#PB_Ignore,color,#PB_Ignore)
EndIf
Case 24
color=ColorRequester()
If color
SendMessage_(GadgetID(themeter), #WM_SETLNCOLOR,0,color)
SendMessage_(GadgetID(nextmeter), #WM_SETLNCOLOR,0,color)
SetLEDcolors(10,#PB_Ignore,#PB_Ignore,color)
EndIf
Case 30
If GetGadgetState(30)=1
PauseThread(theThread)
ElseIf GetGadgetState(30)=0
ResumeThread(theThread)
EndIf
EndSelect
Case #PB_Event_CloseWindow
;KillThread(theThread)
Quit=1
EndSelect
Until Quit=1