From e801c95f84a360092601fc53b58cb71eb39bf203 Mon Sep 17 00:00:00 2001 From: RKrom Date: Tue, 24 Jun 2014 11:49:54 +0200 Subject: [PATCH] Fixes for allowing resizing text based containers, rotating still doesn't work. --- Greenshot/Drawing/StepLabelContainer.cs | 25 ++++++++++++++++++++++-- Greenshot/Drawing/TextContainer.cs | 26 ++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Greenshot/Drawing/StepLabelContainer.cs b/Greenshot/Drawing/StepLabelContainer.cs index 5405c8cf2..86e358e5c 100644 --- a/Greenshot/Drawing/StepLabelContainer.cs +++ b/Greenshot/Drawing/StepLabelContainer.cs @@ -41,6 +41,8 @@ namespace Greenshot.Drawing { private readonly bool _drawAsRectangle = false; + private float fontSize = 16; + public StepLabelContainer(Surface parent) : base(parent) { parent.AddStepLabel(this); InitContent(); @@ -151,6 +153,26 @@ namespace Greenshot.Drawing { return true; } + /// + /// Make sure the size of the font is scaled + /// + /// + public override void Transform(Matrix matrix) { + Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); + int widthBefore = rect.Width; + int heightBefore = rect.Height; + + // Transform this container + base.Transform(matrix); + rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); + + int widthAfter = rect.Width; + int heightAfter = rect.Height; + float factor = (((float)widthAfter / widthBefore) + ((float)heightAfter / heightBefore)) / 2; + + fontSize *= factor; + } + /// /// Override the parent, calculate the label number, than draw /// @@ -172,8 +194,7 @@ namespace Greenshot.Drawing { EllipseContainer.DrawEllipse(rect, graphics, rm, 0, Color.Transparent, fillColor, false); } using (FontFamily fam = new FontFamily(FontFamily.GenericSansSerif.Name)) { - float factor = (((float)rect.Width / DefaultSize.Width) + ((float)rect.Height / DefaultSize.Height)) / 2; - using (Font _font = new Font(fam, 16 * factor, FontStyle.Bold, GraphicsUnit.Pixel)) { + using (Font _font = new Font(fam, fontSize, FontStyle.Bold, GraphicsUnit.Pixel)) { TextContainer.DrawText(graphics, rect, 0, lineColor, false, _stringFormat, text, _font); } } diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs index ed10195fb..aecda59b6 100644 --- a/Greenshot/Drawing/TextContainer.cs +++ b/Greenshot/Drawing/TextContainer.cs @@ -214,7 +214,31 @@ namespace Greenshot.Drawing { _parent.KeysLocked = false; _parent.Controls.Remove(_textBox); } - + + /// + /// Make sure the size of the font is scaled + /// + /// + public override void Transform(Matrix matrix) { + Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); + int widthBefore = rect.Width; + int heightBefore = rect.Height; + + // Transform this container + base.Transform(matrix); + rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); + + int widthAfter = rect.Width; + int heightAfter = rect.Height; + float factor = (((float)widthAfter / widthBefore) + ((float)heightAfter / heightBefore)) / 2; + + float fontSize = GetFieldValueAsFloat(FieldType.FONT_SIZE); + fontSize *= factor; + SetFieldValue(FieldType.FONT_SIZE, fontSize); + + fontInvalidated = true; + } + protected void UpdateFormat() { string fontFamily = GetFieldValueAsString(FieldType.FONT_FAMILY); bool fontBold = GetFieldValueAsBool(FieldType.FONT_BOLD);