SpeedbarGadget

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: SpeedbarGadget

Post by Kukulkan »

Very nice! Well done! Looks great! :D

Kukulkan
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

Re: SpeedbarGadget

Post by Phantomas »

Not correct:

Code: Select all

*d\MaxItems = DesktopWidth(0)
If user have > 1 displays.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: SpeedbarGadget

Post by uwekel »

Thanks Phantomas,

i just updated the source code. You can download it from the top message.

Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
Lord
Addict
Addict
Posts: 849
Joined: Tue May 26, 2009 2:11 pm

Re: SpeedbarGadget

Post by Lord »

Hi!

Nice Gadget, but now the line 152

Code: Select all

      y = (h - 1) * i / sy
produces an IMA if window is dragged to small in hight,
because in line 149

Code: Select all

sy = h / (th * 2)
sy becomes zero.
Image
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: SpeedbarGadget

Post by uwekel »

Thank you, Lord!
Source fixed and uploaded.
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
akee
Enthusiast
Enthusiast
Posts: 477
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: SpeedbarGadget

Post by akee »

1 word... Cute! :)
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: SpeedbarGadget

Post by Guimauve »

Hello,

A little command to free the Gadget. It's not really an issue if the SpeedBarGadget() is used on the main window but if it's used in a child window the SpeedBarGadget() will generate a memory leak because the memory is not released when the gadget is destroyed.

Code: Select all

Procedure FreeSpeedBarGadget(Gadget)
  
  Protected *d._SpeedBar = GetGadgetData(Gadget)
  
  If *d <> #Null
    FreeMemory(*d)
    FreeGadget(Gadget)
  EndIf
  
EndProcedure
When you allocate the memory for extra information needed for the SpeedBarGadget, it's better to use InitializeStructure() instead of NewList to initialize the Linked List.

Code: Select all

Procedure SpeedBarGadget(Gadget, x, y, w, h, Flags=0)
  ;create new speedbar
  Protected f, *d._SpeedBar, desktops, i
  ;build canvas flags
  If Flags & #SpeedBarBorder
    f | #PB_Canvas_Border
  EndIf
  ;create additional speedbar object data

  *d = AllocateMemory(SizeOf(_SpeedBar))
  InitializeStructure(*d, _SpeedBar)
  ; NewList *d\Values() <--- With InitializeStructure(), NewList is no longer needed !

  *d\Canvas = CanvasGadget(Gadget, x, y, w, h, f)
  *d\Flags = Flags
  *d\Font = FontID(LoadFont(#PB_Any, "", 8))
  *d\Maximum = 100
  *d\BackColor = $000000
  *d\GridColor = $1C1C1C
  *d\ValueColor = $0000FF
  
  ;store object in gadget data
  If Gadget = #PB_Any
    SetGadgetData(*d\Canvas, *d)
  Else
    SetGadgetData(Gadget, *d)
  EndIf
  ;maximum number of values to store is limited to desktop width
  desktops = ExamineDesktops()
  For i = 0 To desktops - 1
    If *d\MaxItems < DesktopWidth(i)
      *d\MaxItems = DesktopWidth(i)
    EndIf
  Next
  ;return gadget id
  ProcedureReturn *d\Canvas
EndProcedure
Otherwise, nice Gadget !

Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: SpeedbarGadget

Post by uwekel »

Hello Guimauve,

thank your your suggestion!

Indeed i have overseen that freeing the objects data memory is required. The structure is 52 bytes of size or double on 64-bit machines. Not a big deal, but i will include a SpeedBarFree() command for that. Btw, i prefer to always start the procedures with the component name (SpeedBar...) so it is easy to find with code completion.

Source code is updated!

Are there any advantages to use InitializeStructure() instead of NewList in my special case?

Best regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: SpeedbarGadget

Post by Guimauve »

Hello again,

First, I'm sorry but the command for freeing the gadget isn't right i think. This one will really do the job !

Code: Select all

Procedure SpeedBarFreeGadget(Gadget)
  
  Protected *d._SpeedBar = GetGadgetData(Gadget)
  
  If *d <> #Null
    
    ; All Basic field set to 0 
    ; (it's for a purist, a maniac or a crazy programmer)
    *d\Canvas = 0
    *d\Flags = 0
    *d\MaxItems = 0
    *d\Maximum = 0
    *d\BackColor = 0
    *d\GridColor = 0
    *d\ValueColor = 0
    *d\SplitsX = 0
    *d\SplitsY = 0
    *d\Digits = 0
    
    ; Freeing the font
    If *d\Font <> 0
      FreeFont(*d\Font)
      *d\Font = 0 ; The same comment as for previous basic fields apply here too !
    EndIf
    
    ; Deleting all Values elements
    ClearList(*d\Values())

    FreeMemory(*d)
    FreeGadget(Gadget)
    
  EndIf
  
EndProcedure
Are there any advantages to use InitializeStructure() instead of NewList in my special case?
Personally I prefer to use NewList, Map and Dim for any Linked List, Map and Dynamic Array used outside structured variable (loose inside a code, inside procedures, and so on) and use InitializeStructure() on structure containing Linked List, Map and Dynamic Array. Furthermore InitializeStructure() has been specifically designed for this purpose.

Best regards
Guimauve
Dear Optimist, Pessimist,
and Realist,

While you guys were
busy arguing about the
glass of water, I DRANK IT !

Sincerely,
the Opportunist
Longshot
User
User
Posts: 12
Joined: Sat Sep 08, 2012 2:32 pm

Re: SpeedbarGadget

Post by Longshot »

First off, I wanted to say that this Gadget is fantastic. I like the look of it, and how it displays data. :)


I have one question/request/not sure:

Is there any way to increase either the size of the lines or space between the data points so that the actual output can be bigger? I'd love to use this to display data about historical usage on a machine, but an entire day's worth of data is only 143 data points, which fills a really tiny amount. I'm looking at other charting examples I've found on this forum, but so far the vast majority have just confused me or caused me to spend hours trying to add in things like data added during run time.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: SpeedbarGadget

Post by uwekel »

@Longshot: At the moment this gadget does not support bigger lines. But if you want to fill up the gadget with just 143 data points, e.g. you could add each point twice or more to fill the gadget with a whole day.
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: SpeedbarGadget

Post by vwidmer »

Just found this its very nice..

Is there a way to set the lower/minimum value?

Like if I want from 100-200 instead of 0-200?

Thank you.
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
Post Reply