[Lazarus] Drawing problem in Linux based on GTK2/QT4
GroundCAD Algeria
groundcad at gmail.com
Fri Sep 4 19:39:59 CEST 2015
Hi
I developed a 2D CAD ( GroundCAD www.groundcad.com ) software using
Lazarus ( working with LCL only ).
In windows, the software is stable in the processing and in the drawing.
I ported my project to linux 32 (mint 17.2) using Lazarus 1.4.2 configured
on GTK2, When I zoomed In my drawing in the maximum scale (range of 1mm ) I
get a duplicated lines (the drawing of entities outside the screen system).
In my code, Before the drawing, I check if entity position is inside the
canvas and I have the same problem.
As solution, I tested a custom method to draw a line,using Bresenham's line
algorithm. and I add a check In the pixel position (X,Y) must be inside the
canvas ( 0 --> width ; 0 --> Height ) before the drawing.
The result of this method is good and correct but slow. If I apply a
maximum scale in my drawing .
I have 2 questions
- In Linux GTK2/QT4, where is the problem if I apply a maximum scale ?
- Can I add a check on pixel position inside the canvas methods
(line,polylin,polygon,rectangle,ellipse ...)
Best regards
Naoum Mabkhout
Test drawing line Unit :
procedure TCadLine.DrawLine(workspace:TCanvas);
VAR
a,b : INTEGER;
d : INTEGER;
diag_inc : INTEGER;
dx_diag : INTEGER;
dx_nondiag : INTEGER;
dy_diag : INTEGER;
dy_nondiag : INTEGER;
i : INTEGER;
nondiag_inc : INTEGER;
swap : INTEGER;
X,Y : INTEGER; // Pixel position
BEGIN
if self.IsCreated=true then
BEGIN
if plan.ApplyZoomOrPan=true then
begin
self.XstartScreen := plan.GetXscreenFromX(self.Xstart,workspace);
self.YstartScreen := plan.GetYscreenFromY(self.Ystart,workspace);
self.ZstartScreen := round(self.Zstart);
self.XendScreen := plan.GetXscreenFromX(self.Xend,workspace);
self.YendScreen := plan.GetYscreenFromY(self.Yend,workspace);
self.ZendScreen := round(self.Zend);
self.XmidScreen := plan.GetXscreenFromX(self.GetMidX,workspace);
self.YmidScreen := plan.GetYscreenFromY(self.GetMidY,workspace);
self.ZmidScreen := round(self.GetMidZ);
end;
X := self.XstartScreen;
Y := self.YstartScreen;
a := self.XendScreen - self.XstartScreen;
b := self.YendScreen - self.YstartScreen;
IF a < 0 THEN
BEGIN
a := -a;
dx_diag := -1
END
ELSE
dx_diag := 1;
IF b < 0 THEN
BEGIN
b := -b;
dy_diag := -1
END
ELSE
dy_diag := 1;
IF a < b THEN
BEGIN
swap := a;
a := b;
b := swap;
dx_nondiag := 0;
dy_nondiag := dy_diag
END
ELSE
BEGIN
dx_nondiag := dx_diag;
dy_nondiag := 0
END;
d := b + b - a;
nondiag_inc := b + b;
diag_inc := b + b - a - a;
FOR i := 0 TO a DO
BEGIN
// Must Add a check if pixel position X,Y
// inside the canvas before draw the pixel
if (X>=0) and (X<= workspace.Width )
and (Y>=0) and (Y<= workspace.Height ) then
workspace.Pixels[X,Y] := self.Color;
IF d < 0 THEN
BEGIN
x := x + dx_nondiag;
y := y + dy_nondiag;
d := d + nondiag_inc
END
ELSE
BEGIN
x := x + dx_diag;
y := y + dy_diag;
d := d + diag_inc
END
END;
END;
END;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150904/7e5d623b/attachment-0002.html>
More information about the Lazarus
mailing list