aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
authorjp <jp_bruyere@hotmail.com>2016-04-14 23:50:44 +0200
committerjp <jp_bruyere@hotmail.com>2016-04-14 23:50:44 +0200
commitbbe51d8097fd368a1f87086af3fdda668ec75b6e (patch)
tree90f402599aafdcb0cba79bc92977157681c8a5a4 /src/GraphicObjects
parenta01e514c4aacd93a2541416466716d0454ad1e2c (diff)
several fix, proportional Spinner
Diffstat (limited to 'src/GraphicObjects')
-rw-r--r--src/GraphicObjects/Label.cs115
1 files changed, 55 insertions, 60 deletions
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index 0a909b73..769220dd 100644
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -357,7 +357,7 @@ namespace Crow
if (lc == 0)
lc = 1;
- return (int)(fe.Height * lc) + Margin * 2;
+ return (int)Math.Ceiling(fe.Height * lc) + Margin * 2;
}
foreach (string s in lines) {
@@ -396,70 +396,65 @@ namespace Crow
Rectangle cb = ClientRectangle;
- //ignore text alignment if size to content = true
- //TODO: split horizontal and vertical logic
- if (Width == Measure.Fit || Height == Measure.Fit)
+ rText.X = cb.X;
+ rText.Y = cb.Y;
+
+ if (horizontalStretch) {
+ widthRatio = (float)cb.Width / (float)rText.Width;
+ if (!verticalStretch)
+ heightRatio = widthRatio;
+ }
+
+ if (verticalStretch) {
+ heightRatio = (float)cb.Height / (float)rText.Height;
+ if (!horizontalStretch)
+ widthRatio = heightRatio;
+ }
+
+ rText.Width = (int)(widthRatio * (float)rText.Width);
+ rText.Height = (int)(heightRatio * (float)rText.Height);
+
+ switch (TextAlignment)
{
+ case Alignment.TopLeft: //ok
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 * rText.Width);
- rText.Height = (int)(heightRatio * rText.Height);
-
- switch (TextAlignment)
- {
- case Alignment.TopLeft: //ok
- rText.X = cb.X;
- rText.Y = cb.Y;
- break;
- case Alignment.Top: //ok
- rText.Y = cb.Y;
- rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
- break;
- case Alignment.TopRight: //ok
- rText.Y = cb.Y;
- rText.X = cb.Right - rText.Width;
- break;
- case Alignment.Left://ok
- rText.X = cb.X;
- rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
- break;
- 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.Bottom://ok
- rText.X = cb.Width / 2 - rText.Width / 2;
- rText.Y = cb.Height - rText.Height;
- break;
- case Alignment.BottomLeft://ok
- rText.X = cb.X;
- rText.Y = cb.Bottom - rText.Height;
- break;
- case Alignment.BottomRight://ok
- rText.Y = cb.Bottom - rText.Height;
- rText.X = cb.Right - rText.Width;
- break;
- case Alignment.Center://ok
- rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
- rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
- break;
- }
+ break;
+ case Alignment.Top: //ok
+ rText.Y = cb.Y;
+ rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
+ break;
+ case Alignment.TopRight: //ok
+ rText.Y = cb.Y;
+ rText.X = cb.Right - rText.Width;
+ break;
+ case Alignment.Left://ok
+ rText.X = cb.X;
+ rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
+ break;
+ 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.Bottom://ok
+ rText.X = cb.Width / 2 - rText.Width / 2;
+ rText.Y = cb.Height - rText.Height;
+ break;
+ case Alignment.BottomLeft://ok
+ rText.X = cb.X;
+ rText.Y = cb.Bottom - rText.Height;
+ break;
+ case Alignment.BottomRight://ok
+ rText.Y = cb.Bottom - rText.Height;
+ rText.X = cb.Right - rText.Width;
+ break;
+ case Alignment.Center://ok
+ rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
+ rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
+ break;
}
- gr.FontMatrix = new Matrix(widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0);
+ gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0);
fe = gr.FontExtents;
#region draw text cursor