<div dir="ltr"><div><div><div><div><div><div><div><div><div><div>Hi<br></div>I developed a 2D CAD ( GroundCAD <a href="http://www.groundcad.com">www.groundcad.com</a> ) software using Lazarus ( working with LCL only ).<br><br></div>In windows, the software is stable in the processing and in the drawing.<br><br></div>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).<br><br></div></div><div>In my code, Before the drawing, I check if entity position is inside the canvas and I have the same problem.<br></div><div><br></div>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.<br><br></div>The result of this method is good and correct but slow. If I apply a maximum scale in my drawing .<br><br></div>I have 2 questions<br>- In Linux GTK2/QT4, where is the problem if I apply a maximum scale ?<br></div>- Can I add a check on pixel position inside the canvas methods (line,polylin,polygon,rectangle,ellipse ...)<br><br></div>Best regards<br></div>Naoum Mabkhout<br><br><br><br><span style="font-family:"courier new";font-size:9pt">Test drawing line Unit :<br>
procedure TCadLine.DrawLine(workspace:TCanvas);<br>
VAR<br>
a,b : INTEGER;<br>
d : INTEGER;<br>
diag_inc : INTEGER;<br>
dx_diag : INTEGER;<br>
dx_nondiag : INTEGER;<br>
dy_diag : INTEGER;<br>
dy_nondiag : INTEGER;<br>
i : INTEGER;<br>
nondiag_inc : INTEGER;<br>
swap : INTEGER;<br>
X,Y : INTEGER; // Pixel position<br><br>
BEGIN<br>
<br>
if self.IsCreated=true then<br>
BEGIN<br>
if plan.ApplyZoomOrPan=true then<br>
begin<br>
self.XstartScreen := plan.GetXscreenFromX(self.Xstart,workspace);<br>
self.YstartScreen := plan.GetYscreenFromY(self.Ystart,workspace);<br>
self.ZstartScreen := round(self.Zstart);<br>
self.XendScreen := plan.GetXscreenFromX(self.Xend,workspace);<br>
self.YendScreen := plan.GetYscreenFromY(self.Yend,workspace);<br>
self.ZendScreen := round(self.Zend);<br>
self.XmidScreen := plan.GetXscreenFromX(self.GetMidX,workspace);<br>
self.YmidScreen := plan.GetYscreenFromY(self.GetMidY,workspace);<br>
self.ZmidScreen := round(self.GetMidZ);<br>
end;<br>
<br>
X := self.XstartScreen;<br>
Y := self.YstartScreen;<br>
<br>
a := self.XendScreen - self.XstartScreen;<br>
b := self.YendScreen - self.YstartScreen;<br>
<br>
IF a < 0 THEN<br>
BEGIN<br>
a := -a;<br>
dx_diag := -1<br>
END<br>
ELSE<br>
dx_diag := 1;<br>
<br>
IF b < 0 THEN<br>
BEGIN<br>
b := -b;<br>
dy_diag := -1<br>
END<br>
ELSE<br>
dy_diag := 1;<br>
<br>
IF a < b THEN<br>
BEGIN<br>
swap := a;<br>
a := b;<br>
b := swap;<br>
dx_nondiag := 0;<br>
dy_nondiag := dy_diag<br>
END<br>
ELSE<br>
BEGIN<br>
dx_nondiag := dx_diag;<br>
dy_nondiag := 0<br>
END;<br>
d := b + b - a;<br>
nondiag_inc := b + b;<br>
diag_inc := b + b - a - a;<br>
<br>
FOR i := 0 TO a DO<br>
BEGIN<br>
<br>
// Must Add a check if pixel position X,Y<br>
// inside the canvas before draw the pixel<br>
<br>
if (X>=0) and (X<= workspace.Width )<br>
and (Y>=0) and (Y<= workspace.Height ) then <br>
workspace.Pixels[X,Y] := self.Color;<br>
<br>
IF d < 0 THEN<br>
BEGIN<br>
x := x + dx_nondiag;<br>
y := y + dy_nondiag;<br>
d := d + nondiag_inc<br>
END<br>
ELSE<br>
BEGIN<br>
x := x + dx_diag;<br>
y := y + dy_diag;<br>
d := d + diag_inc<br>
END<br>
END;<br>
<br>
END;<br>
END; <br>
</span><br><div><div><div><div><div><div><div><div> <br></div></div></div></div></div></div></div></div></div>