Page 2 of 2

Re: SpeedbarGadget

Posted: Wed Jul 04, 2012 7:54 am
by Kukulkan
Very nice! Well done! Looks great! :D

Kukulkan

Re: SpeedbarGadget

Posted: Wed Oct 03, 2012 2:44 am
by Phantomas
Not correct:

Code: Select all

*d\MaxItems = DesktopWidth(0)
If user have > 1 displays.

Re: SpeedbarGadget

Posted: Wed Oct 03, 2012 9:02 am
by uwekel
Thanks Phantomas,

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

Uwe

Re: SpeedbarGadget

Posted: Wed Oct 03, 2012 9:35 am
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.

Re: SpeedbarGadget

Posted: Wed Oct 03, 2012 1:03 pm
by uwekel
Thank you, Lord!
Source fixed and uploaded.

Re: SpeedbarGadget

Posted: Wed Oct 03, 2012 1:19 pm
by akee
1 word... Cute! :)

Re: SpeedbarGadget

Posted: Thu Oct 04, 2012 4:49 am
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

Re: SpeedbarGadget

Posted: Thu Oct 04, 2012 7:59 pm
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

Re: SpeedbarGadget

Posted: Thu Oct 04, 2012 10:55 pm
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

Re: SpeedbarGadget

Posted: Mon Nov 05, 2012 7:53 pm
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.

Re: SpeedbarGadget

Posted: Fri Feb 22, 2013 8:05 pm
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.

Re: SpeedbarGadget

Posted: Fri Jun 28, 2019 6:54 pm
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.