Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Overview control strange behavior (Read 2893 times)
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Overview control strange behavior
Apr 29th, 2010 at 1:10pm
Print Post  
Hello Stoyan,

I have my diagram nodes and cells custom drawn.

I want to add the Overview control to my application to enhance the functionality but I'm seeing strange behavior on this control: the tables and cells are not painted, I'm seeing just the text and the links in the overview window.

Has this anything to do with the fact that the nodes and cells are custom painted (using Diagram.DrawNode and DrawCell events)? How to overcome this and see in the Overview window correct painted nodes and cells?

Thanks,
Bogdan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Overview control strange behavior
Reply #1 - Apr 29th, 2010 at 3:42pm
Print Post  
Hi Bogdan,

The Overview should call the same custom drawing code as for the DiagramView, however with a scale transform applied to the Graphics object. Could you post a sample of your drawing code?

Stoyan
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Overview control strange behavior
Reply #2 - Apr 29th, 2010 at 7:29pm
Print Post  
Sure, this is:

Code
Select All
void CustomDiagram_DrawNode(object sender, DrawNodeEventArgs e)
        {
            MFDrawing.IGraphics g = e.Graphics;
            SmoothingMode smoothingMode = g.SmoothingMode;
            g.SmoothingMode = SmoothingMode.None;

            DiagramView view = GetDiagramView();

            if (e.Shadow)
            {
                Rectangle shadowBoundsView = view.DocToClient(e.Node.Bounds);

                //reposition and resize the bounds in pixels
                shadowBoundsView.Inflate(_hShadowWidth, _vShadowWidth);

                Matrix t = g.Transform;
                GraphicsUnit gu = g.PageUnit;

                g.PageUnit = GraphicsUnit.Pixel;
                g.ResetTransform();

                Bitmap shadowBitmap = null;

                if (shadowBoundsView.Width <= 0)
                    shadowBoundsView.Width = 1;
                if (shadowBoundsView.Height <= 0)
                    shadowBoundsView.Height = 1;

                ThemeManager.StretchBitmap(Theme_table_shadow,
                    ref shadowBitmap, new Size(shadowBoundsView.Width, shadowBoundsView.Height), 10, 10);

                g.DrawImage(shadowBitmap, shadowBoundsView);

                g.Transform = t;
                g.PageUnit = gu;
            }
            else
            {
                TableNode tableNode = e.Node as TableNode;

                float captionHeight = this.TableCaptionHeight;

                RectangleF captionBounds = new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, captionHeight);
                RectangleF bodyBounds = new RectangleF(e.Bounds.X, e.Bounds.Y + captionHeight, e.Bounds.Width, e.Bounds.Height - captionHeight);

                Rectangle captionBoundsView = view.DocToClient(captionBounds);
                Rectangle bodyBoundsView = view.DocToClient(bodyBounds);

                Matrix t = g.Transform;
                GraphicsUnit gu = g.PageUnit;

                g.PageUnit = GraphicsUnit.Pixel;
                g.ResetTransform();

                Bitmap captionBitmap = null;
                Bitmap bodyBitmap = null;

                if (captionBoundsView.Width <= 0)
                    captionBoundsView.Width = 1;
                if (captionBoundsView.Height <= 0)
                    captionBoundsView.Height = 1;

                if (bodyBoundsView.Width <= 0)
                    bodyBoundsView.Width = 1;
                if (bodyBoundsView.Height <= 0)
                    bodyBoundsView.Height = 1;


                ThemeManager.StretchBitmap(Theme_table_header,
                    ref captionBitmap, new Size(captionBoundsView.Width, captionBoundsView.Height), 8, 5);

                ThemeManager.StretchBitmap(Theme_table_back,
                    ref bodyBitmap, new Size(bodyBoundsView.Width, bodyBoundsView.Height), 10, 10);

                g.DrawImage(captionBitmap, captionBoundsView);
                g.DrawImage(bodyBitmap, bodyBoundsView);

                g.Transform = t;
                g.PageUnit = gu;

                //this.DrawStyledText(g, tableNode.Caption, tableNode.Font, captionBounds, tableNode.CaptionFormat);

                g.DrawString(tableNode.Caption,
                    tableNode.Font, new SolidBrush(tableNode.CaptionColor), captionBounds, tableNode.CaptionFormat);
            }

            e.Graphics.SmoothingMode = smoothingMode;
        }
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Overview control strange behavior
Reply #3 - Apr 30th, 2010 at 5:47am
Print Post  
Hi Bogdan,

The rectangle returned by DiagramView.DocToClient is correct only for the DiagramView, and probably it's very far from the Overview's visible area. You will get similar problems if you export to PDF or SVG, where the graphics transform applied will be different than the DiagramView's one in the general case. Try calling the MindFusion.Utilities.DocToDevice(IGraphics graphics, RectangleF r) method instead the DiagramView's one to be independent from the rendering target.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Overview control strange behavior
Reply #4 - Apr 30th, 2010 at 10:13am
Print Post  
Thanks, it's working but I'm still facing an issue:

In my DrawCell event handler I calculate the size of the custom check box to be drawn, using the DiagramView.ZoomFactor:

Code
Select All
float newCheckImageWidth = chkImg.Width * view.ZoomFactor / 100;

float newCheckImageHeight = chkImg.Height * view.ZoomFactor / 100;
 



Obviously, in the Overview, the checkboxes are drawn too big.

I would check if the sender is an Overview and in this case I would multiply the check box width/height also by Overview.ScaleFactor but the "sender" parameter is always set to the Diagram so I can't make the difference on when it's called to paint the Diagram and when it's called to paint the Overview.

So, I tried to change the way the checkbox size is updated (to remove the DiagramView.ZoomFactor dependency ) , by using only the current painted row height like:

Code
Select All
double newCheckImageWidth = Math.Floor(contentBoundsView.Height * 0.6);

double newCheckImageHeight = newCheckImageWidth;
 



But even if I Math.Floor the result, I can get different values because the row height is not always the same:

For example, I have

Code
Select All
Rectangle boundsView = MindFusion.Utilities.DocToDevice(g, e.Bounds);
SizeF sizeViewF = MindFusion.Utilities.DocToDeviceF(g, e.Bounds.Size);
 



The sizeViewF returns for every row W= 6.803... H=6.803... but the boundsView returns for some rows W=7 H=7 (as it should) and for others W=7 H=6.

I don't understand why DocToDevice returns different values for height when e.Bound.Height is the same for every rows and also DocToDeviceF returns same height for every row. Is it a bug?

Should I manually correct the height of the "boundsView" to make it equal to the height returned by the "sizeViewF"?

PS. Id I use the view.DocToClient I get the same inconsistency regarding the returned height.
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Overview control strange behavior
Reply #5 - Apr 30th, 2010 at 10:38am
Print Post  
Yes, it seems that if I manually correct the height of the "boundsView" to make it equal to the height returned by the "sizeViewF", that do the trick, the checkboxes are now having all the same height.

But still, seems to me like a bug in DocToDevice height calculation. Isn't it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Overview control strange behavior
Reply #6 - Apr 30th, 2010 at 3:36pm
Print Post  
I think it happens because the method that returns a Rectangle aligns the rectangle sides to the nearest integer pixel coordinates, and so you get either 6 or 7 as height, depending on the initial vertical position in floating point coordinates.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint