Recent

Author Topic: Canvas.Pen.Pattern  (Read 8233 times)

HomePlaneR

  • New Member
  • *
  • Posts: 34
Canvas.Pen.Pattern
« on: April 16, 2013, 11:26:07 pm »
Hi everyone.

Following code does not want to work:
Code: [Select]
Canvas.Pen.Color := clRed;
 Canvas.Pen.Style := psPattern;
 Canvas.Pen.Pattern := $AAAAAAAA;    //101010...
 Canvas.Line(0,0,100,0);

It gives a black line, but I expected to have red dotted line. What I'm doing wrong?

Thanks in advance.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Canvas.Pen.Pattern
« Reply #1 on: April 17, 2013, 12:00:25 am »
Style psPattern does not work here too. Maybe it's not implemented yet or it works only on some widgetsets. Of course there is psDot - you probably know.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 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/

HomePlaneR

  • New Member
  • *
  • Posts: 34
Re: Canvas.Pen.Pattern
« Reply #2 on: April 17, 2013, 05:23:16 pm »
Style psPattern does not work here too. Maybe it's not implemented yet or it works only on some widgetsets. Of course there is psDot - you probably know.

That's what I thought. Thanks anyway.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Canvas.Pen.Pattern
« Reply #3 on: December 20, 2014, 07:54:02 pm »
Just for the case:

psPattern works but method SetPattern must be used (property Pattern does nothing).

Code: [Select]
var aPenPattern: TPenPattern;
begin
  Canvas.Pen.Style := psPattern;
  SetLength(aPenPattern, 2);
  aPenPattern[0] := 1;  //line [pixels]
  aPenPattern[1] := 1;  //space [pixels]
  ...
  Canvas.Pen.Width := 1;
  Canvas.Line(...);
This code will paint subtle dotted line.

The array can be longer, the first number is always length of dash, the second is the space.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 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/

PawelO

  • New Member
  • *
  • Posts: 16
    • Polish railway traffic and interlocking simulator developed with Lazarus
Re: Canvas.Pen.Pattern
« Reply #4 on: March 22, 2015, 11:36:36 am »
It works for me only when Pen.Width > 1. When Pen.Width=1, it draws always black solid line (Lazarus v1.2.6, Win XP).

Code: [Select]
    Canvas.Pen.Color := clRed;
    Canvas.Pen.Style := psPattern;
    SetLength(aPenPattern, 2);
    aPenPattern[0] := 3;  //line [pixels]
    aPenPattern[1] := 3;  //space [pixels]
    Canvas.Pen.SetPattern(aPenPattern);
    Canvas.Pen.Width := 1{2};
    Canvas.Line(50,50,100,50);

 

TinyPortal © 2005-2018