mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 00:53:51 -07:00
Editor: Added horizontal and vertical alignment for text boxes.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2435 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
771fc93d6b
commit
c0fbac4c53
18 changed files with 801 additions and 499 deletions
|
@ -23,9 +23,9 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Drawing.Fields;
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Plugin;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using Greenshot.Memento;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
@ -42,6 +42,7 @@ namespace Greenshot.Drawing {
|
|||
// This is set to true AFTER the first change is made, as there is already a "add element" on the undo stack
|
||||
private bool makeUndoable = false;
|
||||
private Font font;
|
||||
StringFormat stringFormat = new StringFormat();
|
||||
|
||||
private string text;
|
||||
// there is a binding on the following property!
|
||||
|
@ -76,12 +77,16 @@ namespace Greenshot.Drawing {
|
|||
AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);
|
||||
AddField(GetType(), FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
|
||||
AddField(GetType(), FieldType.FONT_SIZE, 11f);
|
||||
AddField(GetType(), FieldType.TEXT_HORIZONTAL_ALIGNMENT, HorizontalAlignment.Center);
|
||||
AddField(GetType(), FieldType.TEXT_VERTICAL_ALIGNMENT, VerticalAlignment.CENTER);
|
||||
|
||||
stringFormat.Trimming = StringTrimming.EllipsisWord;
|
||||
}
|
||||
|
||||
[OnDeserializedAttribute()]
|
||||
private void OnDeserialized(StreamingContext context) {
|
||||
Init();
|
||||
UpdateFont();
|
||||
UpdateFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,7 +130,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
public void FitToText() {
|
||||
UpdateFont();
|
||||
UpdateFormat();
|
||||
Size textSize = TextRenderer.MeasureText(text, font);
|
||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||
Width = textSize.Width + lineThickness;
|
||||
|
@ -152,7 +157,7 @@ namespace Greenshot.Drawing {
|
|||
UpdateTextBoxFormat();
|
||||
textBox.Invalidate();
|
||||
} else {
|
||||
UpdateFont();
|
||||
UpdateFormat();
|
||||
//Invalidate();
|
||||
}
|
||||
font.Dispose();
|
||||
|
@ -192,7 +197,7 @@ namespace Greenshot.Drawing {
|
|||
parent.Controls.Remove(textBox);
|
||||
}
|
||||
|
||||
private void UpdateFont() {
|
||||
private void UpdateFormat() {
|
||||
string fontFamily = GetFieldValueAsString(FieldType.FONT_FAMILY);
|
||||
bool fontBold = GetFieldValueAsBool(FieldType.FONT_BOLD);
|
||||
bool fontItalic = GetFieldValueAsBool(FieldType.FONT_ITALIC);
|
||||
|
@ -231,6 +236,9 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
fontInvalidated = false;
|
||||
}
|
||||
|
||||
stringFormat.Alignment = (StringAlignment)GetFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT);
|
||||
stringFormat.LineAlignment = (StringAlignment)GetFieldValue(FieldType.TEXT_VERTICAL_ALIGNMENT);
|
||||
}
|
||||
|
||||
private void UpdateTextBoxPosition() {
|
||||
|
@ -246,7 +254,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
private void UpdateTextBoxFormat() {
|
||||
UpdateFont();
|
||||
UpdateFormat();
|
||||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||
textBox.ForeColor = lineColor;
|
||||
textBox.Font = font;
|
||||
|
@ -268,7 +276,7 @@ namespace Greenshot.Drawing {
|
|||
|
||||
public override void Draw(Graphics graphics, RenderMode rm) {
|
||||
base.Draw(graphics, rm);
|
||||
UpdateFont();
|
||||
UpdateFormat();
|
||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||
|
@ -302,7 +310,7 @@ namespace Greenshot.Drawing {
|
|||
shadowRect.Inflate(-textOffset, -textOffset);
|
||||
}
|
||||
using (Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100))) {
|
||||
graphics.DrawString(text, font, fontBrush, shadowRect);
|
||||
graphics.DrawString(text, font, fontBrush, shadowRect, stringFormat);
|
||||
currentStep++;
|
||||
alpha = alpha - basealpha / steps;
|
||||
}
|
||||
|
@ -316,7 +324,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||
using (Brush fontBrush = new SolidBrush(lineColor)) {
|
||||
graphics.DrawString(text, font, fontBrush, fontRect);
|
||||
graphics.DrawString(text, font, fontBrush, fontRect, stringFormat);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue