Lazarus

Programming => General => Topic started by: krolikbest on December 03, 2019, 01:48:39 pm

Title: millimeter paper
Post by: krolikbest on December 03, 2019, 01:48:39 pm
Hello,

 need to use as a backgroud on a canvas millimeter paper. Is there to use something ready or have to invent my own? At first glance comes to mind use lines and moveto but it doesn't look good. meantime found:https://wiki.freepascal.org/PlotPanel (https://wiki.freepascal.org/PlotPanel) and thought also about chart components but i'm not sure in which direction to go... Do you have ideas?
Title: Re: millimeter paper
Post by: wp on December 03, 2019, 01:54:15 pm
For what do you need the millimeter paper? For plotting? Then use TAChart, otherwise you'll have to reinvent scaling of coordinates, generation of axis labels, positioning titles and legends and a lot more. PlotPanel might work too, it is not actively maintained, and in fact, I don't know whether it even compile.

For using TAChart you should have a look at the introductory tutorial: wiki.lazarus.freepascal.org/TAChart_Tutorial:_Getting_started
Title: Re: millimeter paper
Post by: krolikbest on December 03, 2019, 02:27:58 pm
It has to be only as a background on a canvas. It won't be plotted nor printed. Ok, try TChart
Title: Re: millimeter paper
Post by: wp on December 03, 2019, 03:36:14 pm
No, for decorative purposes TAChart is overkill. Simply paint the grid on the canvas by using Canvas.Line instructions.

Since this smells like some homework assignment I am showing you here only a partial solution for the vertical lines:
Code: Pascal  [Select]
  1. procedure TForm1.Panel1Paint(Sender: TObject);
  2. const
  3.   COLOR1 = TColor($F0F0F0);
  4.   COLOR2 = TColor($E0E0E0);
  5. var
  6.   dx: Integer;
  7.   x: Integer;
  8.   i: Integer;
  9. begin
  10.   dx := round(ScreenInfo.PixelsPerInchX / 25.4);
  11.   with Panel1 do begin
  12.     Canvas.Brush.Color := clWhite;
  13.     Canvas.FillRect(0, 0, Width, Height);
  14.     Canvas.Pen.Width := 1;
  15.     Canvas.Pen.Style := psSolid;
  16.     // vertical grid lines
  17.     x := 0;
  18.     for i := 0 to MaxInt do
  19.     begin
  20.       if i mod 10 = 0 then
  21.         Canvas.Pen.Color := COLOR2
  22.       else
  23.         Canvas.Pen.Color := COLOR1;
  24.       Canvas.Line(x, 0, x, Height);
  25.       inc(x, dx);
  26.       if x > Width then break;
  27.     end;
  28.     // horizontal grid lines
  29.     // ...
  30.   end;
  31. end;
Title: Re: millimeter paper
Post by: krolikbest on December 03, 2019, 03:52:21 pm
oh, how nice already with a code!
Thanks :)
Title: Re: millimeter paper
Post by: avra on December 04, 2019, 11:46:49 am
https://wiki.freepascal.org/Eye-Candy_Controls#TECRuler
Title: Re: millimeter paper
Post by: krolikbest on December 04, 2019, 05:32:21 pm
Yes, know Eye-Candy Controls and find them simply awsome!. Some years ago did my own CNC program for milling machine https://www.youtube.com/watch?v=0xt6NM7tVxY (https://www.youtube.com/watch?v=0xt6NM7tVxY) in Delphi 7 Personal.
Had to write the same background grid (that is the reason why I asked if is there something ready to use). As you can see i use in this project a ruler but forgot where it came from.