It is currently Mon May 20, 2013 4:37 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: SpeedbarGadget
PostPosted: Wed Jul 04, 2012 7:54 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 577
Location: germany
Very nice! Well done! Looks great! :D

Kukulkan

_________________
There is not nothing that not might happen.


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Wed Oct 03, 2012 2:44 am 
Offline
User
User

Joined: Wed Jul 01, 2009 12:59 pm
Posts: 69
Not correct:
Code:
*d\MaxItems = DesktopWidth(0)

If user have > 1 displays.


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Wed Oct 03, 2012 9:02 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 03, 2011 5:54 pm
Posts: 252
Thanks Phantomas,

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

Uwe

_________________
Purebasic 5.11 | Fedora 18 (32-bit)


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Wed Oct 03, 2012 9:35 am 
Offline
User
User

Joined: Tue May 26, 2009 2:11 pm
Posts: 94
Hi!

Nice Gadget, but now the line 152
Code:
      y = (h - 1) * i / sy
produces an IMA if window is dragged to small in hight,
because in line 149
Code:
sy = h / (th * 2)
sy becomes zero.


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Wed Oct 03, 2012 1:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 03, 2011 5:54 pm
Posts: 252
Thank you, Lord!
Source fixed and uploaded.

_________________
Purebasic 5.11 | Fedora 18 (32-bit)


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Wed Oct 03, 2012 1:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Aug 18, 2004 9:52 am
Posts: 370
Location: Penang, Malaysia
1 word... Cute! :)


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Thu Oct 04, 2012 4:49 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
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:
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:
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


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Thu Oct 04, 2012 7:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 03, 2011 5:54 pm
Posts: 252
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

_________________
Purebasic 5.11 | Fedora 18 (32-bit)


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Thu Oct 04, 2012 10:55 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
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:
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

Quote:
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


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Mon Nov 05, 2012 7:53 pm 
Offline
User
User

Joined: Sat Sep 08, 2012 2:32 pm
Posts: 10
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.


Top
 Profile  
 
 Post subject: Re: SpeedbarGadget
PostPosted: Fri Feb 22, 2013 8:05 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Dec 03, 2011 5:54 pm
Posts: 252
@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.

_________________
Purebasic 5.11 | Fedora 18 (32-bit)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: horst and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye