1
votes

In a friend's program written in Pascal (a basic bowling game), the game elements (ball, backouground, etc.) are drawn in a TShape's canvas (Shape1.Canvas)

The problem is that the element drawn on that Canvas are cropped in a small rectangle on the top left canvas of this TShape. See this screenshot: Screenshot of the glitch

Note that I already seen this kind of problem with another Pascal program also using Lazarus/LCL (lazarus's main graphic/ui library) and that this bowling program is running without any bug in Windows, the bug is only experienced in Linux I guess ...

Note also that when drawing on this canvas from a procedure other than the timer's one (for example in OnFormCreate or something), the whole canvas is drawn.

Here are the drawing operations performed (in the timer's procedure):

procedure TForm2.Timer1Timer(Sender: TObject);
var
  i: integer;
  affich:word;
begin
  Shape1.Canvas.Clear;
  Lapiste.display(shape1.Canvas);
  Laboule.move(Coupcourant, Lapiste);
  Laboule.display(Shape1.Canvas);
  //LeTabQuilles.collision(CoupCourant);
  for i := 1 to 10 do
    begin
      LeTabQuilles.tab[i].check(LaBoule, CoupCourant);
      (LeTabQuilles.tab[i] as CQuille).display(shape1.Canvas);
    end; 

// ... (rest of the procedure) 

The drawing operations (.display) basically draw bitmaps in the canvas given as an attribute ...

1
Any reason you draw in a shape's canvas rather than a TImage or TPaintBox? Just wondering. And is there any special meaning attached to the dimensions of the rectangle that gets drawn? (e.g. is it the design-time shape size, etc... or is it random) - Thomas
As said in the post below, we draw this on a TShape and not on TForm mainly because drawing it on TForm causes some graphical glitches (labels disappearing, etc.); Why did we draw it on a TShape and not a TImage or TPaintBox ? ... I don't really know. As those tree objects all have a canvas, we just chose one of them: TShape. Could it cause any bug ? For the shape of the rectangle drawn, as seen in the screenshot, it looks like it has the same ratio as the TShape ... But notice that the content of the canvas is cropped, not resized. - halflings
I don't think it would cause any bug, it just seemed a strange choice. It could be a bug with the Linux widgetset but I wouldn't know, is it possible to see some code? - Thomas
From a Windows point of view (but I guess Lazarus will handle the same on Linux) you should only prepare the positions of what and where you want to render, ask system for control refresh and the rendering keep in the OnPaint event. It seems the shape is painting itself over your element, but it's still just a guess. - TLama
Could you try to build and run this project on Linux ? - TLama

1 Answers

0
votes

It seems like not all Canvases are born equal :).

The problem was solved by simply replacing the TShape by a TImage. Note that this problem is really frequent (at least in my school, and only in Linux) and also happens if you draw directly on the Form's canvas (which is kind of stupid btw).