Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to set text vertical display of the node? (Read 2878 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to set text vertical display of the node?
Dec 31st, 2014 at 9:03am
Print Post  
how to set text vertical display of the node, when I draw node in the override Draw method?
Code
Select All
 public FormattedText GetFormattedText()
       {
           FormattedText formattedText = new FormattedText(this.Text,
               CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.ToString()), EvFlowDirection,
               new Typeface(EvFontFamily, EvFontStyle, EvFontWeight, EvFontStretch), EvFontSize,
               EvFontBrush);
            formattedText.MaxTextWidth = Bounds.Width;
            formattedText.MaxTextHeight = Bounds.Height;
            formattedText.SetFontSize(EvFontSize, 0, 0);
            formattedText.SetFontWeight(EvFontWeight, 0, 0);
            formattedText.SetForegroundBrush(EvFontBrush);
            formattedText.SetFontStyle(EvFontStyle, 0, 0);
            formattedText.TextAlignment = EvTextAlignment;
            textStartX = 0;
           if (EvTextVerticalAlignment== AlignmentY.Top)
           {
               textStartY = 0;
           }
           else if (EvTextVerticalAlignment == AlignmentY.Center)
           {
               textStartY = Bounds.Height / 2 - formattedText.Height/2;
           }
           else
           {
               textStartY = Bounds.Height - formattedText.Height;
           }
            textSize.Width = formattedText.Width;
            textSize.Height = formattedText.Height;
            return formattedText;
       }

       public override void Draw(DrawingContext graphics, RenderOptions options)
       {
           FormattedText  tempFormattedText = GetFormattedText();
           Size tempBounds = this.Bounds.Size;
           if (this.Bounds.Size.Height < textSize.Height || this.Bounds.Size.Width < textSize.Width)
           {
               tempBounds.Height = textSize.Height > this.Bounds.Size.Height ? textSize.Height : this.Bounds.Size.Height;
               tempBounds.Width = textSize.Width > this.Bounds.Size.Width ? textSize.Width : this.Bounds.Size.Width;
           }
           graphics.DrawRectangle(EvBrush, this.Pen, new Rect(new Point(0, 0), tempBounds));
           graphics.DrawText(tempFormattedText, new Point(textStartX, textStartY));
           this.AnchorPattern = new AnchorPattern();
           AnchorPattern.Points.Add(new AnchorPoint(0, 50, true, false, MarkStyle.None));
           AnchorPattern.Points.Add(new AnchorPoint(100, 50, false, true, MarkStyle.None));
       }
 

  

verticalDisplay.jpg (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to set text vertical display of the node?
Reply #1 - Jan 5th, 2015 at 8:29am
Print Post  
You could set the ShapeNode.TextRotationAngle property. If you prefer drawing the text yourself, call DrawingContext.PushTransform(new RotateTransform(...)) before DrawText and DrawingContext.Pop() after that.

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


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to set text vertical display of the node?
Reply #2 - Jan 6th, 2015 at 8:10am
Print Post  
hi Stoyan,
  I try as you told, but I find when I change the node's size, the text will out of the node? could you please tell how to solve it ?
Code
Select All
public FormattedText GetFormattedText()
        {
            FormattedText formattedText = new FormattedText(this.Text,
                CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.ToString()), FlowDirection,
                new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize,
                Brushes.Black);
            formattedText.SetFontSize(FontSize, 0, 0);
            formattedText.SetFontWeight(FontWeight, 0, 0);
            formattedText.SetForegroundBrush(Brushes.Black);
            formattedText.SetFontStyle(FontStyle, 0, 0);
            formattedText.TextAlignment = TextAlignment;

            textStartX = 0;
            if (TextVerticalAlignment == AlignmentY.Top)
            {
                textStartY = 0;
            }
            else if (TextVerticalAlignment == AlignmentY.Center)
            {
                textStartY = Bounds.Height / 2 - formattedText.Height / 2;
            }
            else
            {
                textStartY = Bounds.Height - formattedText.Height;
            }

            textSize.Width = formattedText.Width;
            textSize.Height = formattedText.Height;
            return formattedText;
        }

       public override void Draw(DrawingContext graphics, RenderOptions options)
       {
           FormattedText tempFormattedText = GetFormattedText();
           Size tempBounds = this.Bounds.Size;
           if (this.Bounds.Size.Height < textSize.Height || this.Bounds.Size.Width < textSize.Width)
           {
               tempBounds.Height = textSize.Height > this.Bounds.Size.Height ? textSize.Height : this.Bounds.Size.Height;
               tempBounds.Width = textSize.Width > this.Bounds.Size.Width ? textSize.Width : this.Bounds.Size.Width;
           }

           graphics.DrawRectangle(EvBrush, EvPen, new Rect(new Point(0, 0), tempBounds));

            tempFormattedText.MaxTextWidth = Bounds.Height;
            tempFormattedText.MaxTextHeight = Bounds.Width;
            RotateTransform rotateTransform = new RotateTransform(90, tempBounds.Width / 2, tempBounds.Height / 2);
            graphics.PushTransform(rotateTransform);
            graphics.DrawText(tempFormattedText, new Point(textStartX, textStartY));
            graphics.Pop();


           this.AnchorPattern = new AnchorPattern();
           AnchorPattern.Points.Add(new AnchorPoint(0, 50, true, false, MarkStyle.None));
           AnchorPattern.Points.Add(new AnchorPoint(100, 50, false, true, MarkStyle.None));
       }
    }
 

]
  

EvSwitch_004.rar ( 55 KB | 86 Downloads )
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to set text vertical display of the node?
Reply #3 - Jan 6th, 2015 at 3:22pm
Print Post  
That seems the expected position when you draw the text at 0,0 but rotate around node's center. The 0,0 point gets transformed toward node's top-right corner in that case. If you want the rotated text to be centered too, you should change its position to center - text size:

Code
Select All
var rotateTransform = new RotateTransform(90, tempBounds.Width / 2, tempBounds.Height / 2);
graphics.PushTransform(rotateTransform);
graphics.DrawText(tempFormattedText, new Point(
		rotateTransform.CenterX - tempFormattedText.Width / 2,
		rotateTransform.CenterY - tempFormattedText.Height / 2));
graphics.Pop(); 



If you need rotated text drawn at top-left corner, use these coordinates for rotation and text:

Code
Select All
var rotateTransform = new RotateTransform(90, 0, 0);
graphics.PushTransform(rotateTransform);
graphics.DrawText(tempFormattedText, new Point(0, -tempFormattedText.Height));
graphics.Pop(); 



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


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to set text vertical display of the node?
Reply #4 - Jan 26th, 2015 at 7:27am
Print Post  
hi Stoyan,
I use RotationAngle instead Customer-drawing.
thanks for your help.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint