Dial DLL -ready for download

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Dial DLL -ready for download

Post 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:
Last edited by netmaestro on Sun Apr 09, 2006 10:38 am, edited 1 time in total.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post 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 :!:
Intrigued - Registered PureBasic, lifetime updates user
Post Reply