Moving back to trunk!

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1602 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-01-24 19:24:36 +00:00
parent ad265b2c54
commit 8d458998a1
332 changed files with 17647 additions and 9466 deletions

View file

@ -19,18 +19,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Runtime.Serialization;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.Plugin.Drawing;
using Greenshot.Memento;
namespace Greenshot.Drawing {
/// <summary>
@ -39,16 +36,28 @@ namespace Greenshot.Drawing {
[Serializable()]
public class TextContainer : RectangleContainer, ITextContainer {
private bool fontInvalidated = true;
// If makeUndoable is true the next text-change will make the change undoable.
// 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;
private string text;
// there is a binding on the following property!
public string Text {
get { return text; }
set {
if((text == null && value != null) || !text.Equals(value)) {
text = value;
OnPropertyChanged("Text");
}
ChangeText(value, true);
}
}
internal void ChangeText(string newText, bool allowUndoable) {
if ((text == null && newText != null) || !text.Equals(newText)) {
if (makeUndoable && allowUndoable) {
makeUndoable = false;
parent.MakeUndoable(new TextChangeMemento(this), false);
}
text = newText;
OnPropertyChanged("Text");
}
}
@ -57,9 +66,9 @@ namespace Greenshot.Drawing {
public TextContainer(Surface parent) : base(parent) {
Init();
AddField(GetType(), FieldType.LINE_THICKNESS, 1);
AddField(GetType(), FieldType.LINE_THICKNESS, 2);
AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
AddField(GetType(), FieldType.SHADOW, false);
AddField(GetType(), FieldType.SHADOW, true);
AddField(GetType(), FieldType.FONT_ITALIC, false);
AddField(GetType(), FieldType.FONT_BOLD, false);
AddField(GetType(), FieldType.FILL_COLOR, Color.Transparent);
@ -96,8 +105,12 @@ namespace Greenshot.Drawing {
*/
protected virtual void Dispose(bool disposing) {
if (disposing) {
if(textBox != null) textBox.Dispose();
if(font != null) font.Dispose();
if (textBox != null) {
textBox.Dispose();
}
if (font != null) {
font.Dispose();
}
}
textBox = null;
font = null;
@ -118,23 +131,22 @@ namespace Greenshot.Drawing {
}
void TextContainer_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if(e.PropertyName.Equals("Selected")) {
if(!Selected && textBox.Visible) HideTextBox();
else if(Selected && Status==EditStatus.DRAWING) {
if (e.PropertyName.Equals("Selected")) {
if (!Selected && textBox.Visible) {
HideTextBox();
} else if (Selected && Status==EditStatus.DRAWING) {
ShowTextBox();
}
//else if(!textBox.Visible) ShowTextBox();
}
if(textBox.Visible) {
if (textBox.Visible) {
UpdateTextBoxPosition();
UpdateTextBoxFormat();
textBox.Invalidate();
}
}
void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e)
{
if(textBox.Visible) {
void TextContainer_FieldChanged(object sender, FieldChangedEventArgs e) {
if (textBox.Visible) {
UpdateTextBoxFormat();
textBox.Invalidate();
} else {
@ -148,6 +160,7 @@ namespace Greenshot.Drawing {
public override void OnDoubleClick() {
ShowTextBox();
textBox.Focus();
}
private void CreateTextBox() {
@ -189,34 +202,32 @@ namespace Greenshot.Drawing {
bool hasStyle = false;
using(FontFamily fam = new FontFamily(fontFamily)) {
bool boldAvailable = fam.IsStyleAvailable(FontStyle.Bold);
if(fontBold && boldAvailable) {
fs |= FontStyle.Bold;
if (fontBold && boldAvailable) {
fs |= FontStyle.Bold;
hasStyle = true;
}
bool italicAvailable = fam.IsStyleAvailable(FontStyle.Italic);
if(fontItalic && italicAvailable) {
if (fontItalic && italicAvailable) {
fs |= FontStyle.Italic;
hasStyle = true;
}
if(!hasStyle) {
if (!hasStyle) {
bool regularAvailable = fam.IsStyleAvailable(FontStyle.Regular);
if(regularAvailable) {
if (regularAvailable) {
fs = FontStyle.Regular;
} else {
if(boldAvailable) {
if (boldAvailable) {
fs = FontStyle.Bold;
} else if(italicAvailable) {
fs = FontStyle.Italic;
}
}
}
font = new Font(fam, fontSize, fs, GraphicsUnit.Pixel);
}
fontInvalidated = false;
}
}
@ -243,6 +254,8 @@ namespace Greenshot.Drawing {
}
void textBox_LostFocus(object sender, EventArgs e) {
// next change will be made undoable
makeUndoable = true;
HideTextBox();
}
@ -265,7 +278,7 @@ namespace Greenshot.Drawing {
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
int textOffset = (lineThickness>0) ? (int)Math.Ceiling(lineThickness/2d) : 0;
// draw shadow before anything else
if ( shadow && (fillColor == Color.Transparent || fillColor == Color.Empty)) {
if (shadow && (fillColor == Color.Transparent || fillColor == Color.Empty)) {
int basealpha = 100;
int alpha = basealpha;
int steps = 5;
@ -273,7 +286,7 @@ namespace Greenshot.Drawing {
while (currentStep <= steps) {
int offset = currentStep;
Rectangle shadowRect = GuiRectangle.GetGuiRectangle(Left + offset, Top + offset, Width, Height);
if(lineThickness > 0) {
if (lineThickness > 0) {
shadowRect.Inflate(-textOffset, -textOffset);
}
using (Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100))) {
@ -286,12 +299,18 @@ namespace Greenshot.Drawing {
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
Rectangle fontRect = rect;
if(lineThickness > 0) {
if (lineThickness > 0) {
fontRect.Inflate(-textOffset,-textOffset);
}
using (Brush fontBrush = new SolidBrush(lineColor)) {
g.DrawString(text, font, fontBrush, fontRect);
}
}
public override bool ClickableAt(int x, int y) {
Rectangle r = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
r.Inflate(5, 5);
return r.Contains(x, y);
}
}
}