diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-08 17:26:51 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-08 17:26:51 +0100 |
| commit | ed620f42c980270a69ebc346bdc40b79861c057c (patch) | |
| tree | d5e0ea8f2790e51ccdfd71710b66630749c1cb8d /src/GraphicObjects/TextRun.cs | |
| parent | 9dd647069f3fe6234d360242617a1cb59b62d5cb (diff) | |
Simplify Alignment Enum; add HorizontalStretch and VerticalStretch to GraphicObject
Diffstat (limited to 'src/GraphicObjects/TextRun.cs')
| -rw-r--r-- | src/GraphicObjects/TextRun.cs | 103 |
1 files changed, 44 insertions, 59 deletions
diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs index 76dde9a8..a426bdee 100644 --- a/src/GraphicObjects/TextRun.cs +++ b/src/GraphicObjects/TextRun.cs @@ -30,7 +30,9 @@ namespace Crow #region private and protected fields protected string _text = "label"; - Alignment _textAlignment = Alignment.LeftCenter; + Alignment _textAlignment = Alignment.Left; + bool horizontalStretch = false; + bool verticalStretch = false; bool _multiline; bool wordWrap; protected Rectangle rText; @@ -41,12 +43,34 @@ namespace Crow #endregion - [XmlAttributeAttribute()][DefaultValue(Alignment.LeftCenter)] + [XmlAttributeAttribute()][DefaultValue(Alignment.Left)] public Alignment TextAlignment { get { return _textAlignment; } set { _textAlignment = value; } } + [XmlAttributeAttribute()][DefaultValue(false)] + public virtual bool HorizontalStretch { + get { return horizontalStretch; } + set { + if (horizontalStretch == value) + return; + horizontalStretch = value; + registerForGraphicUpdate (); + NotifyValueChanged ("HorizontalStretch", horizontalStretch); + } + } + [XmlAttributeAttribute()][DefaultValue(false)] + public virtual bool VerticalStretch { + get { return verticalStretch; } + set { + if (verticalStretch == value) + return; + verticalStretch = value; + NotifyValueChanged ("VerticalStretch", verticalStretch); + + } + } [XmlAttributeAttribute()][DefaultValue("label")] public string Text { @@ -185,63 +209,45 @@ namespace Crow rText.X = cb.X; rText.Y = cb.Y; }else { - + if (horizontalStretch) { + widthRatio = (float)cb.Width / rText.Width; + if (!verticalStretch) + heightRatio = widthRatio; + }if (verticalStretch) { + heightRatio = (float)cb.Height / rText.Height; + if (!horizontalStretch) + widthRatio = heightRatio; + } + + rText.Width = (int)(widthRatio * cb.Width); + rText.Height = (int)(heightRatio * cb.Height); + switch (TextAlignment) { - case Alignment.None: - break; case Alignment.TopLeft: //ok rText.X = cb.X; rText.Y = cb.Y; break; - case Alignment.TopCenter: //ok + case Alignment.Top: //ok rText.Y = cb.Y; rText.X = cb.X + cb.Width / 2 - rText.Width / 2; break; case Alignment.TopRight: //ok - rText.X = cb.Right - rText.Width; - rText.Y = cb.Y; - break; - case Alignment.TopStretch://ok - heightRatio = widthRatio = (float)cb.Width / rText.Width; - rText.X = cb.X; rText.Y = cb.Y; - rText.Width = cb.Width; - rText.Height = (int)(rText.Height * heightRatio); + rText.X = cb.Right - rText.Width; break; - case Alignment.LeftCenter://ok + case Alignment.Left://ok rText.X = cb.X; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; - case Alignment.LeftStretch://ok - heightRatio = widthRatio = (float)cb.Height / rText.Height; - rText.X = cb.X; - rText.Y = cb.Y; - rText.Height = cb.Height; - rText.Width = (int)(widthRatio * cb.Width); - break; - case Alignment.RightCenter://ok + case Alignment.Right://ok rText.X = cb.X + cb.Width - rText.Width; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; - case Alignment.RightStretch://ok - heightRatio = widthRatio = (float)cb.Height / rText.Height; - rText.Height = cb.Height; - rText.Width = (int)(widthRatio * cb.Width); - rText.X = cb.X; - rText.Y = cb.Y; - break; - case Alignment.BottomCenter://ok + case Alignment.Bottom://ok rText.X = cb.Width / 2 - rText.Width / 2; rText.Y = cb.Height - rText.Height; break; - case Alignment.BottomStretch://ok - heightRatio = widthRatio = (float)cb.Width / rText.Width; - rText.Width = cb.Width; - rText.Height = (int)(rText.Height * heightRatio); - rText.Y = cb.Bottom - rText.Height; - rText.X = cb.X; - break; case Alignment.BottomLeft://ok rText.X = cb.X; rText.Y = cb.Bottom - rText.Height; @@ -254,27 +260,6 @@ namespace Crow rText.X = cb.X + cb.Width / 2 - rText.Width / 2; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; - case Alignment.Fit://ok, peut ĂȘtre mieu alignĂ© - widthRatio = (float)cb.Width / rText.Width; - heightRatio = (float)cb.Height / rText.Height; - rText = cb; - break; - case Alignment.HorizontalStretch://ok - heightRatio = widthRatio = (float)cb.Width / rText.Width; - rText.Width = cb.Width; - rText.Height = (int)(heightRatio * rText.Height); - rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; - rText.X = cb.X; - break; - case Alignment.VerticalStretch://ok - heightRatio = widthRatio = (float)cb.Height / rText.Height; - rText.Height = cb.Height; - rText.Width = (int)(widthRatio * rText.Width); - rText.X = cb.X + cb.Width / 2 - rText.Width / 2; - rText.Y = cb.Y; - break; - default: - break; } } |