I have an issue writing a FireMonkey component.


I have an issue writing a FireMonkey component. It is very basic! I cannot draw a rectangle with a line thickness of one pixel. Is always draw at least two pixels. On the bottom of the image is the rectangle drawn. Above is the lower left corner of a TTabControl. My rectangle has two pixels while the tabcontrol has a border of one pixel. How can I do that?

I wrote a simple component to reproduce the issue:
unit RectangleControl;

interface

uses
    System.SysUtils, System.Classes, System.UITypes,
    FMX.Types, FMX.Controls, FMX.Graphics;

type
    TRectControl = class(TControl)
    private
    protected
        procedure Paint; override;
    public
    published
        property Position;
        property Width;
        property Height;
    end;

procedure Register;

implementation

procedure Register;
begin
    RegisterComponents('Samples', [TRectControl]);
end;

procedure TRectControl.Paint;
begin
    Canvas.Stroke.Kind     := TBrushKind.bkSolid;
    Canvas.Stroke.Color    := TAlphaColors.Black;
    Canvas.StrokeThickness := 1;
    Canvas.DrawRect(BoundsRect, 0, 0, [], 1);
end;

end.

As you can see, it is difficult to find a simpler component. And yet it doesn't work as expected: the rectangle border is 2 pixels instead of only one. And beside that, the colour is also wrong. It looks like some antialiasing is in action.

What am I missing?

Comments