mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 05:23:24 -07:00
TextContainer's TextBox on zoom - fix for position, update font size
This commit is contained in:
parent
f494385ef7
commit
d93c9d6a3a
1 changed files with 49 additions and 10 deletions
|
@ -22,6 +22,7 @@
|
||||||
using Greenshot.Drawing.Fields;
|
using Greenshot.Drawing.Fields;
|
||||||
using Greenshot.Helpers;
|
using Greenshot.Helpers;
|
||||||
using Greenshot.Memento;
|
using Greenshot.Memento;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
using GreenshotPlugin.Interfaces.Drawing;
|
using GreenshotPlugin.Interfaces.Drawing;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
@ -155,6 +156,24 @@ namespace Greenshot.Drawing
|
||||||
FieldChanged += TextContainer_FieldChanged;
|
FieldChanged += TextContainer_FieldChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void SwitchParent(Surface newParent)
|
||||||
|
{
|
||||||
|
_parent.SizeChanged -= Parent_SizeChanged;
|
||||||
|
base.SwitchParent(newParent);
|
||||||
|
_parent.SizeChanged += Parent_SizeChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Parent_SizeChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
UpdateTextBoxPosition();
|
||||||
|
UpdateTextBoxFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ApplyBounds(RectangleF newBounds)
|
||||||
|
{
|
||||||
|
base.ApplyBounds(newBounds);
|
||||||
|
UpdateTextBoxPosition();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Invalidate()
|
public override void Invalidate()
|
||||||
{
|
{
|
||||||
|
@ -255,7 +274,8 @@ namespace Greenshot.Drawing
|
||||||
AcceptsTab = true,
|
AcceptsTab = true,
|
||||||
AcceptsReturn = true,
|
AcceptsReturn = true,
|
||||||
BorderStyle = BorderStyle.None,
|
BorderStyle = BorderStyle.None,
|
||||||
Visible = false
|
Visible = false,
|
||||||
|
Font = new Font(FontFamily.GenericSansSerif, 1) // just need something non-default here
|
||||||
};
|
};
|
||||||
|
|
||||||
_textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
|
_textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
|
||||||
|
@ -388,7 +408,6 @@ namespace Greenshot.Drawing
|
||||||
var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
|
var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
|
||||||
_font?.Dispose();
|
_font?.Dispose();
|
||||||
_font = newFont;
|
_font = newFont;
|
||||||
_textBox.Font = _font;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -400,7 +419,6 @@ namespace Greenshot.Drawing
|
||||||
var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
|
var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
|
||||||
_font?.Dispose();
|
_font?.Dispose();
|
||||||
_font = newFont;
|
_font = newFont;
|
||||||
_textBox.Font = _font;
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -413,6 +431,8 @@ namespace Greenshot.Drawing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateTextBoxFont();
|
||||||
|
|
||||||
UpdateAlignment();
|
UpdateAlignment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +443,29 @@ namespace Greenshot.Drawing
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This will create the textbox exactly to the inner size of the element
|
/// Set TextBox font according to the TextContainer font and the parent zoom factor.
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateTextBoxFont()
|
||||||
|
{
|
||||||
|
if (_textBox == null || _font == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var textBoxFontScale = _parent?.ZoomFactor ?? Fraction.Identity;
|
||||||
|
|
||||||
|
var newFont = new Font(
|
||||||
|
_font.FontFamily,
|
||||||
|
_font.Size * textBoxFontScale,
|
||||||
|
_font.Style,
|
||||||
|
GraphicsUnit.Pixel
|
||||||
|
);
|
||||||
|
_textBox.Font.Dispose();
|
||||||
|
_textBox.Font = newFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will align the textbox exactly to the inner size of the element
|
||||||
/// is a bit of a hack, but for now it seems to work...
|
/// is a bit of a hack, but for now it seems to work...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateTextBoxPosition()
|
private void UpdateTextBoxPosition()
|
||||||
|
@ -453,12 +495,9 @@ namespace Greenshot.Drawing
|
||||||
_textBox.Height = displayRectangle.Height - 2 * lineWidth + correction;
|
_textBox.Height = displayRectangle.Height - 2 * lineWidth + correction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ApplyBounds(RectangleF newBounds)
|
/// <summary>
|
||||||
{
|
/// Set TextBox text align and fore color according to field values.
|
||||||
base.ApplyBounds(newBounds);
|
/// </summary>
|
||||||
UpdateTextBoxPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateTextBoxFormat()
|
private void UpdateTextBoxFormat()
|
||||||
{
|
{
|
||||||
if (_textBox == null)
|
if (_textBox == null)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue