Page 1 of 1

Dial DLL -ready for download

Posted: Sun Apr 09, 2006 9:59 am
by netmaestro
I made a dll that draws a round dial on your window. It displays values from 0 to 80 with a red needle. The dll uses no directx or windowed screen, it's all straight 2d drawing. You can have several dials on a window moving like mad and cpu usage is negligible (<10% on mine).

This is a work in process, and I'm improving it in the coming days/weeks. Right now it has a big weakness, that is that I'm using the image rotation library of Mischa to point the needles, and this type of rotation, while nice and fast, can appear somewhat poor quality depending on what number the needle is pointing at. I can replace this approach with another one and improve the image quality dramatically, but it's hours of work and I have to see how many people are interested in it before I commit to it.

Anyway, the dll has two functions: _nm_DrawDial and _nm_GetState.

You pick a static image# to use for a dial and call the dll as such:

Callfunction(#Library, "_nm_DrawDial", #image, state.l, backcolor.l)

-You don't create the #image first, the dll will do that. Just pass it a number you want used for the dial.

- State is a number 0-80, numbers outside this range get changed to 0 or 80 depending on whether they were too high or too low.

-Backcolor is a color to paint the box around the round dial so it shows transparent on your window. My windows are RGB(224,223,227) and so that's what I send it in the code example.

CallFunction(#Library, "_nm_GetState, #dial)

- #dial is the #image you used to create the dial, pass the function that number and it will give you back a long containing the current number the needle on the dial is pointing at.

Here is the dll: http://www.networkmaestro.com/dial.dll

And here is an example program just for fun:

Code: Select all

OpenWindow(0,0,0,480,300,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
SetWindowColor(0,RGB(224,223,227))
CreateGadgetList(WindowID(0)) 

OpenLibrary(0,"dial.dll") 

image1 = CallFunction(0,"_nm_DrawDial",0,40,RGB(224,223,227)) 
image2 = CallFunction(0,"_nm_DrawDial",1,0,RGB(224,223,227)) 

ImageGadget(0,50,50,152,152,image1) 
ImageGadget(1,250,50,152,152,image2) 
TextGadget(2,120,210,40,22,"") 
TextGadget(3,320,210,40,22,"") 
i=0 
fwd=#True 
time = ElapsedMilliseconds() 
Repeat 
  ;first image 
  If ElapsedMilliseconds()-time >= 1000 
    image1 = CallFunction(0,"_nm_DrawDial",0,Random(80),RGB(224,223,227)) 
    SetGadgetState(0,image1) 
    time=ElapsedMilliseconds() 
    SetGadgetText(2,Str(CallFunction(0,"_nm_GetState",0))) 
  EndIf 
  If fwd 
    i+1:If i>80:fwd=#False:EndIf 
  Else 
    i-1:If i<0:fwd=#True:EndIf 
  EndIf 
  ;secondimage 
  image2 = CallFunction(0,"_nm_DrawDial",1,i,RGB(224,223,227)) 
  SetGadgetState(1,image2) 
  SetGadgetText(3,Str(CallFunction(0,"_nm_GetState",1))) 
  Delay(1) 
Until WindowEvent()=#WM_CLOSE 
CloseLibrary(0) 
End
If you are interested in seeing it improved, let me know. I can improve the drawing quality a lot, but only if there is demand.

Hope you enjoy it! :wink:

Posted: Sun Apr 09, 2006 10:32 am
by srod
That is pretty cool netmaestro. :) Very nice.

I notice though that the background is not transparent in your example.

Now, if I can find a use for it... :D

Posted: Sun Apr 09, 2006 10:35 am
by netmaestro
Could you be more specific about the transparency? What exactly is not transparent, is there a box around the round dial? If so, you'll have to pass the function the color of your window, since it's probably different than mine.

I added a SetWindowColor line to the example now, it should show transparent.

Posted: Sun Apr 09, 2006 10:47 am
by srod
That's got it. Wasn't sure if that was an oversight or something amis. :D

I think the rotation is smooth enough, I wouldn't say it needs much work there.

Nice job.

Posted: Sun Apr 09, 2006 12:42 pm
by Flype
Nice, it's a good start !

I tried your DLL with this skeleton :

Code: Select all

If OpenLibrary(0,"dial.dll") = #False
  End
EndIf

Prototype _nm_GetState(image.l)
Prototype _nm_DrawDial(image.l, state.l, backcolor.l)

nm_GetState._nm_GetState = GetFunction(0,"_nm_GetState")
nm_DrawDial._nm_DrawDial = GetFunction(0,"_nm_DrawDial") 

If OpenWindow(0,0,0,480,300,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
  
  If CreateGadgetList(WindowID(0)) 
    ImageGadget(0,50,50,152,152,#Null) 
    TextGadget(1,120,210,40,18,"",#PB_Text_Center) 
  EndIf
  
  bgColor.l = $E0E0E0
  SetWindowColor(0,bgColor) 
  SetGadgetColor(1,#PB_Gadget_BackColor,bgColor)
  
  Repeat 
    Select WaitWindowEvent(1)
      Case #PB_Event_CloseWindow
        Break
      Default
        If fwd 
          i + 1 : If i > 80 : fwd = #False : EndIf 
        Else 
          i - 1 : If i < 0 : fwd = #True : EndIf 
        EndIf
        SetGadgetText(1,Str(nm_GetState(0))) 
        SetGadgetState(0,nm_DrawDial(0,i,bgColor)) 
    EndSelect
  ForEver
  
EndIf
I noticed that the nm_GetState() only works on 32 bits desktops.
On 16 bits desktop i only have a plain square instead of transparency, is it normal ?

I was wondering how this stuff could be usable for me.
And, IMHO, here is the functions that might be included in the DLL :

Code: Select all

Prototype _nm_GetVersion()
Prototype _nm_GetState(image.l)
Prototype _nm_SetLimit(image.l, minimum.l, maximum.l)
Prototype _nm_SetBackground(image.l, bgImage.l, bgColor.l)
Prototype _nm_DrawDial(image.l, state.l, bgColor.l, width.l = 152, height.l = 152)

Posted: Sun Apr 09, 2006 6:53 pm
by netmaestro
Thank you Flype, those are all really well-thought and excellent suggestions. If it turns out there's interest in this gadget, I'll probably implement all of it. For now, what's there seems a reasonable starting place. Before I turn it into anything serious though, I have to address the issue of having a really pretty needle at all points of rotation. It looks ok moving all the time, but in practice it won't be doing that.

Posted: Sun Apr 09, 2006 7:32 pm
by Flype
( out of topic )

@netmaestro
I see in your signature that you have a 19" Samsung LCD
Is it the SyncMaster 730gr model ? I have one and it is pretty good.

Posted: Sun Apr 09, 2006 7:34 pm
by netmaestro
It's the 19 inch 910v. I've been really happy with it, best monitor I've ever owned. I've had it just a year now.

Posted: Mon Apr 10, 2006 1:01 am
by Intrigued
I have a 19" SyncMaster (uhg, it's still packed from the move, forgot the model number).

But, it is a quality piece of equipment, that's for sure :!: