Recent

Author Topic: TProgress Bar Colour  (Read 11263 times)

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: TProgress Bar Colour
« Reply #15 on: June 24, 2016, 01:14:48 am »
The TPaintBox will solve your problem with ease. You are in full control in how it renders.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

lainz

  • Hero Member
  • *****
  • Posts: 3630
    • Lainz
Re: TProgress Bar Colour
« Reply #16 on: June 24, 2016, 01:24:09 am »
The TPaintBox will solve your problem with ease. You are in full control in how it renders.

If you need it more than one time... you know.

Please check the FlashProgressBar code and change it at your needs, is quite simple to change the paint code and create your own component, or as said before use the
BGRAFlashProgressBar1Redraw event...
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: TProgress Bar Colour
« Reply #17 on: June 24, 2016, 01:57:15 am »
Here is a very quick and dirty example of TPaintBox to solve your progress bar problem.
Start a new LCL application. Drop a TrackBar and PaintBox on the form. Set the Min and Max values of the TrackBar. Assign the TrackBar1.OnChange event to the event handler shown below. Assign the PaintBox1.OnPaint event handler to the one shown below. Now run the project. I tested with trackbar ranges:  -50..50 & -30..90 etc.

You can obviously improve the code and rendering of the PaintBox to look much prettier than what I supplied here.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PaintBox1Paint(Sender: TObject);
  2. var
  3.   lTotal: integer;
  4.   lZeroPoint: integer;
  5.   lPos: integer;
  6.   lEnd: integer;
  7. begin
  8.   with PaintBox1 do
  9.   begin
  10.     // paint background
  11.     Canvas.Brush.Color := clSilver;
  12.     Canvas.Rectangle(0, 0, Width, Height);
  13.     Canvas.Font.Color := clWhite;
  14.     if TrackBar1.Position = 0 then
  15.       Exit;
  16.     // paint progress
  17.     if TrackBar1.Position > 0 then
  18.       Canvas.Brush.Color := clRed
  19.     else
  20.       Canvas.Brush.Color := clGreen;
  21.  
  22.     lTotal := TrackBar1.Max - TrackBar1.Min;
  23.     lZeroPoint := round((abs(TrackBar1.Min) / lTotal) * PaintBox1.Width);
  24.     if Trackbar1.Position > 0 then
  25.     begin
  26.       lPos := Abs(TrackBar1.Min) + Trackbar1.Position;
  27.       Canvas.Rectangle(lZeroPoint, 0, round((lPos / lTotal) * PaintBox1.Width), PaintBox1.Height);
  28.     end
  29.     else
  30.     begin
  31.       lPos := Abs(Trackbar1.Position);
  32.       Canvas.Rectangle(round(lZeroPoint - ((lPos / lTotal) * PaintBox1.Width)), 0, lZeroPoint, PaintBox1.Height);
  33.     end;
  34.  
  35.     Canvas.TextOut(lZeroPoint, PaintBox1.Height div 2, IntToStr(TrackBar1.Position));
  36.  
  37.     // draw midpoint
  38.     Canvas.Line(lZeroPoint, 0, lZeroPoint, 5);
  39.     Canvas.Line(lZeroPoint, PaintBox1.Height, lZeroPoint, PaintBox1.Height-5);
  40.   end;
  41. end;
  42.  
  43. procedure TForm1.TrackBar1Change(Sender: TObject);
  44. begin
  45.   PaintBox1.Invalidate;
  46. end;
  47.  
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: TProgress Bar Colour
« Reply #18 on: June 24, 2016, 02:03:38 am »
If you need it more than one time... you know.
Nothing stops a developer from creating a TPaintBox descendant and reusing that class as needed. You don't even need a descendant component. Simply place the PaintBox's OnPaint event handler in a common unit so you can hook any TPaintBox.OnPaint to it in code.

We are all programmers here, and it ain't rocket science.  ;)

Just because original author needs a progress bar [like] component which is simple to implement, doesn't mean he needs to start adding 3rd party dependencies like BGRAGraphics & BRGAControls to his project.  BGRA* is a rather large dependency for such a small problem.

From experience with commercial Delphi projects, I have learned the hard way - keep 3rd party dependencies to a minimum.
« Last Edit: June 24, 2016, 02:10:16 am by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

lainz

  • Hero Member
  • *****
  • Posts: 3630
    • Lainz
Re: TProgress Bar Colour
« Reply #19 on: June 24, 2016, 02:35:41 am »
Code: Pascal  [Select][+][-]
  1. Nothing stops a developer from creating a TPaintBox descendant and reusing that class as needed. You don't even need a descendant component. Simply place the PaintBox's OnPaint event handler in a common unit so you can hook any TPaintBox.OnPaint to it in code.


It's ok ;) Is basically the same paint event :)
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: TProgress Bar Colour
« Reply #20 on: June 24, 2016, 11:20:15 am »
Hi again,
Thanks for the TPaint example. It will do absolutely fine with, as you say, some enhancements. It's also very simple.
Thanks again.

Brian

Blaazen

  • Hero Member
  • *****
  • Posts: 2837
  • POKE 54296,15
    • Eye-Candy Controls
Re: TProgress Bar Colour
« Reply #21 on: June 24, 2016, 01:05:44 pm »
Set property ProgressFromMiddle to True.
Lazarus 2.1.0 r63594 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

lainz

  • Hero Member
  • *****
  • Posts: 3630
    • Lainz
Re: TProgress Bar Colour
« Reply #22 on: June 24, 2016, 03:20:24 pm »
Set property ProgressFromMiddle to True.

I think he solved it with no extra packages, not EyeCandy, not BGRA.. it's ok
https://lainz.github.io - My Website
https://lazpaint.github.io/ - LazPaint Downloads

Blaazen

  • Hero Member
  • *****
  • Posts: 2837
  • POKE 54296,15
    • Eye-Candy Controls
Re: TProgress Bar Colour
« Reply #23 on: June 24, 2016, 05:28:45 pm »
I didn't noticed that this thread is on two pages, I replied to the last comment of the first page, my fault.
Lazarus 2.1.0 r63594 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: TProgress Bar Colour
« Reply #24 on: June 24, 2016, 08:41:11 pm »
Hi all,
Just to say it is all installed and working fine in my program with no extra packages needed - nice and simple.

Thanks all

Brian

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: TProgress Bar Colour
« Reply #25 on: June 25, 2016, 12:10:46 pm »
I didn't noticed that this thread is on two pages, I replied to the last comment of the first page, my fault.
The joys of using a forum that doesn't support a tree hierarchy of messages. Have I mentioned how much I hate forum software and Gmail! :-( Give me a NNTP news client with a treeview of messages any time of day!
« Last Edit: June 29, 2016, 02:07:57 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

bulrush

  • Jr. Member
  • **
  • Posts: 84
Re: TProgress Bar Colour
« Reply #26 on: June 27, 2016, 08:13:18 pm »
Hi,

  You can try this package, http://wiki.freepascal.org/Eye-Candy_Controls.

Is there somewhere I can download an EXE for Windows file so I can look at all the controls and how they work? I don't want to have to install all that and make my own test program at the moment.

Thanks!
Lazarus 1.6.0, FPC 3.0.0, Win 7 64-bit, current Perl programmer.

Blaazen

  • Hero Member
  • *****
  • Posts: 2837
  • POKE 54296,15
    • Eye-Candy Controls
Re: TProgress Bar Colour
« Reply #27 on: June 27, 2016, 09:03:04 pm »
No. At least I don't provide any. There are only screenshots on wiki. Some releases come with bundled demos but you need to install EC-C anyway.
Lazarus 2.1.0 r63594 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018