Page 1 of 1

Bug in SimpleGraph ???

PostPosted: June 14th, 2004, 11:21 am
by P_G
SimpleGraph 1.21

First of all: Congratulations for this great component. It's very useful and stable.
But I noticed a bug in the new zoom-feature (or at least I think it's a bug): If the node contains a graphic, this graphic is not displayed properly when zooming. It seems theres a problem with the bounding-box. :shock:

C.U. P_G

PostPosted: June 14th, 2004, 1:15 pm
by Kambiz
I couldn't regenerate the case.

Could you please attach a screenshot and its associated sgp file?

Sorry !!!

PostPosted: June 14th, 2004, 2:39 pm
by P_G
Sorry, Kambiz.
My fault - there's no bug in displaying graphics while zooming. The problem ocurred because I modificated the procedure TGraphNode.DrawBackground to use Metafiles instead of Bitmaps in graphics. This caused the bug I referred to (so I produced this bug by myself). :oops:
Nevertheless I do not have success in implementing this feature: I need the possibility of attaching a metafile or a bitmap into the node's picture.
Do you have any ideas?

C.U. P_G

PostPosted: June 14th, 2004, 5:36 pm
by Kambiz
The Background property of TGraphNode is TPicture. So, it can be assigned or loaded by any Delphi supported image format (Bitmap, Icon, JPEG, Metafile).

Code: Select all
if SimpleGraph.Objects[I] is TGraphNode then
  TGraphNode(SimpleGraph.Objects[I]).Background.LoadFromFile('D:\Sample.wmf');

Code: Select all
if SimpleGraph.Objects[I] is TGraphNode then
  TGraphNode(SimpleGraph.Objects[I]).Background := Image1.Picture;

Code: Select all
if SimpleGraph.Objects[I] is TGraphNode then
  TGraphNode(SimpleGraph.Objects[I]).Background.Assign(AMetafile);

Code: Select all
if SimpleGraph.Objects[I] is TGraphNode then
  TGraphNode(SimpleGraph.Objects[I]).Background.Graphic := ABitmap;

Yip, I know this.

PostPosted: June 15th, 2004, 7:58 am
by P_G
Kambiz wrote:The Background property of TGraphNode is TPicture. So, it can be assigned or loaded by any Delphi supported image format (Bitmap, Icon, JPEG, Metafile).


This is true of course. There's only the problem that the DrawBackGround-procedure converts the Metafile to a Bitmap. So if you stretch the node, you can see the pixels of the graphic. To avoid this effect I tried to change the DrawBackGround to work with Metafiles (Stretch instead of StretchBLT). This worked fine but caused the discribed bug in the new version. :cry:
Any help of you would be apreciated.

C.U. P_G

PostPosted: June 15th, 2004, 9:12 am
by Kambiz
Some printer drivers only accept DIB bitmaps to draw on their canvas. Althought, for a metafile that doesn't contain a DDB bitmap there's no problem. However, the code is written in a general manner.

Interesting ...

PostPosted: June 15th, 2004, 9:26 am
by P_G
Hi Kambiz,

Actually I didn't check printer results. I just saw the results on the monitor and it was a matter of quality for me. Is there no way to implement a workaround for the StretchBLT so that vectorgraphics are displayed properly on the monitor and the zoomfunction stills works correct? :(

C.U. P_G

PostPosted: June 15th, 2004, 3:08 pm
by Kambiz
The following code may help you.

Code: Select all
procedure TGraphNode.DrawBackground(Canvas: TCanvas);
var
  Rgn: HRGN;
begin
  if (Background.Graphic <> nil) and (Background.Graphic is TMetaFile) then
  begin
    Rgn := CreateTargetRegion(Canvas);
    try
      SelectClipRgn(Canvas.Handle, Rgn);
    finally
      DeleteObject(Rgn);
    end;
    try
      PlayEnhMetaFile(Canvas.Handle, TMetaFile(Background.Graphic).Handle, BoundsRect);
    finally
      SelectClipRgn(Canvas.Handle, 0);
    end;
    Canvas.Brush.Style := bsClear;
  end;
end;

Fantastic !!!

PostPosted: June 15th, 2004, 3:20 pm
by P_G
Thanks alot, Kambiz !
:D :D :D