mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -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
89
Greenshot/Drawing/Fields/Binding/AlignmentConverter.cs
Normal file
89
Greenshot/Drawing/Fields/Binding/AlignmentConverter.cs
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using Greenshot.Plugin;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Greenshot.Drawing.Fields.Binding {
|
||||
/// <summary>
|
||||
/// Converting horizontal alignment to its StringAlignment representation and vice versa.
|
||||
/// Beware: there's currently no RTL support.
|
||||
/// </summary>
|
||||
public class HorizontalAlignmentConverter : AbstractBindingConverter<HorizontalAlignment, StringAlignment> {
|
||||
|
||||
private static HorizontalAlignmentConverter uniqueInstance;
|
||||
|
||||
protected override HorizontalAlignment convert(StringAlignment stringAlignment) {
|
||||
switch(stringAlignment) {
|
||||
case StringAlignment.Near: return HorizontalAlignment.Left;
|
||||
case StringAlignment.Center: return HorizontalAlignment.Center;
|
||||
case StringAlignment.Far: return HorizontalAlignment.Right;
|
||||
default: throw new NotImplementedException("Cannot handle: "+ stringAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
protected override StringAlignment convert(HorizontalAlignment horizontalAligment) {
|
||||
switch(horizontalAligment) {
|
||||
case HorizontalAlignment.Left: return StringAlignment.Near;
|
||||
case HorizontalAlignment.Center: return StringAlignment.Center;
|
||||
case HorizontalAlignment.Right: return StringAlignment.Far;
|
||||
default: throw new NotImplementedException("Cannot handle: "+ horizontalAligment);
|
||||
}
|
||||
}
|
||||
|
||||
public static HorizontalAlignmentConverter GetInstance() {
|
||||
if(uniqueInstance == null) uniqueInstance = new HorizontalAlignmentConverter();
|
||||
return uniqueInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converting vertical alignment to its StringAlignment representation and vice versa.
|
||||
/// </summary>
|
||||
public class VerticalAlignmentConverter : AbstractBindingConverter<VerticalAlignment, StringAlignment> {
|
||||
|
||||
private static VerticalAlignmentConverter uniqueInstance;
|
||||
|
||||
protected override VerticalAlignment convert(StringAlignment stringAlignment) {
|
||||
switch(stringAlignment) {
|
||||
case StringAlignment.Near: return VerticalAlignment.TOP;
|
||||
case StringAlignment.Center: return VerticalAlignment.CENTER;
|
||||
case StringAlignment.Far: return VerticalAlignment.BOTTOM;
|
||||
default: throw new NotImplementedException("Cannot handle: "+ stringAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
protected override StringAlignment convert(VerticalAlignment verticalAligment) {
|
||||
switch(verticalAligment) {
|
||||
case VerticalAlignment.TOP: return StringAlignment.Near;
|
||||
case VerticalAlignment.CENTER: return StringAlignment.Center;
|
||||
case VerticalAlignment.BOTTOM: return StringAlignment.Far;
|
||||
default: throw new NotImplementedException("Cannot handle: "+ verticalAligment);
|
||||
}
|
||||
}
|
||||
|
||||
public static VerticalAlignmentConverter GetInstance() {
|
||||
if(uniqueInstance == null) uniqueInstance = new VerticalAlignmentConverter();
|
||||
return uniqueInstance;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,8 @@ namespace Greenshot.Drawing.Fields {
|
|||
public static readonly FieldType FONT_FAMILY = new FieldType("FONT_FAMILY");
|
||||
public static readonly FieldType FONT_ITALIC = new FieldType("FONT_ITALIC");
|
||||
public static readonly FieldType FONT_SIZE = new FieldType("FONT_SIZE");
|
||||
public static readonly FieldType TEXT_HORIZONTAL_ALIGNMENT = new FieldType("TEXT_HORIZONTAL_ALIGNMENT");
|
||||
public static readonly FieldType TEXT_VERTICAL_ALIGNMENT = new FieldType("TEXT_VERTICAL_ALIGNMENT");
|
||||
public static readonly FieldType HIGHLIGHT_COLOR = new FieldType("HIGHLIGHT_COLOR");
|
||||
public static readonly FieldType LINE_COLOR = new FieldType("LINE_COLOR");
|
||||
public static readonly FieldType LINE_THICKNESS = new FieldType("LINE_THICKNESS");
|
||||
|
@ -56,6 +58,8 @@ namespace Greenshot.Drawing.Fields {
|
|||
FONT_FAMILY,
|
||||
FONT_ITALIC,
|
||||
FONT_SIZE,
|
||||
TEXT_HORIZONTAL_ALIGNMENT,
|
||||
TEXT_VERTICAL_ALIGNMENT,
|
||||
HIGHLIGHT_COLOR,
|
||||
LINE_COLOR,
|
||||
LINE_THICKNESS,
|
||||
|
|
|
@ -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