Lazarus

Programming => Widgetset => GTK => Topic started by: taazz on October 10, 2012, 01:09:12 am

Title: GTK2 and StretchDraw.
Post by: taazz on October 10, 2012, 01:09:12 am
I have a problem that I am sure is something I have overlooked but I can't seem to pin point it.

I have a component that when it is created it run the following procedure.
the FBmp variable is part of component's private section just copied it here to help the tests.

Code: [Select]
procedure CreateRGBGradient;
var
  g, b: integer;
  FBmp : TBitmap=nil;
begin
  if FBmp = nil then
  begin
    FBmp := TBitmap .Create;
    FBmp.PixelFormat := pf32bit;
    FBmp.Width := 256;
    FBmp.Height := 256;
  end;

  for g := 255 downto 0 do
  begin
    for b := 0 to 255 do
      FBmp.Canvas.Pixels[b,255-g] := RGB(FR, g, b);
  end;
  //FBmp.SaveToFile('D:\jkoz\Lazarus\Projects\To Convert\Components\mbColorLib\Test\RAxisColor.bmp');

end;       

My custom component is based on TCustomControl and I have override the paint method with this one.

Code: [Select]
begin
  {$IFDEF LCLWIN32}
  Canvas.StretchDraw(ClientRect, FBmp);
  {$ENDIF}
  {$IFDEF LCLGTK2}
  Canvas.StretchDraw(Rect(0, 0, Width, Height), FBmp);
//  Canvas.Brush.Color := clFuchsia;
//  canvas.Rectangle(0,0,100,100);
  {$ENDIF}
  CorrectCoords(mxx, myy);
  DrawMarker(mxx, myy);
end;


Everything works as expected with the windows widget set the image is rendered on the component and I can see it on my application. But if I change my compilation to use GTK2 nothing is rendered on the component just to make sure that I haven't step out of some boundaries I added the rectangle call and this rectangle is rendered and shown.
This tells me that there is something else I should be aware about GTK2 that I am not.

I'm attaching 3 files

Any one can shed some light on the the problem?

Testing Environment
Lazarus 1.1 r38674 FPC 2.6.1 i386-win32-win32/win64
Title: Re: GTK2 and StrechDraw.
Post by: taazz on October 10, 2012, 01:12:30 am
Sorry for the second post but I couldn't make the images any smaller and the forum soft did not allow me more than 250K of images.

EDIT:

I am attaching a small Test Case Project for you to try out.
When the application first starts it creates a fuchsia rectangle in the shape, after press create Bitmap button it should replace that rectangle with the bitmap whichcontains a gradient that is calculated on the fly. In windows widget set everything works as expected in GTK2 the bitmap never draws on the shape.
EDIT 2:

There is definitely something wrong with the bitmap. If I save it to a memory stream and then loaded again then everything works fine. There is something I am not setting that GTK needs to function properly.

Thank you in advance
Regards.