"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs" between
pinta-1.7.tar.gz and pinta-1.7.1.tar.gz

About: Pinta is a powerful image drawing and editing program (modeled after Paint.NET).

SimpleEffectDialog.cs  (pinta-1.7):SimpleEffectDialog.cs  (pinta-1.7.1)
skipping to change at line 48 skipping to change at line 48
namespace Pinta.Gui.Widgets namespace Pinta.Gui.Widgets
{ {
public class SimpleEffectDialog : Gtk.Dialog public class SimpleEffectDialog : Gtk.Dialog
{ {
[ThreadStatic] [ThreadStatic]
Random random = new Random (); Random random = new Random ();
const uint event_delay_millis = 100; const uint event_delay_millis = 100;
uint event_delay_timeout_id; uint event_delay_timeout_id;
GLib.TimeoutHandler timeout_func;
/// Since this dialog is used by add-ins, the IAddinLocalizer all ows for translations to be /// Since this dialog is used by add-ins, the IAddinLocalizer all ows for translations to be
/// fetched from the appropriate place. /// fetched from the appropriate place.
/// </param> /// </param>
public SimpleEffectDialog (string title, Gdk.Pixbuf icon, object effectData, public SimpleEffectDialog (string title, Gdk.Pixbuf icon, object effectData,
IAddinLocalizer localizer) IAddinLocalizer localizer)
: base (title, Pinta.Core.PintaCore.Chrome.MainWindow, Gt k.DialogFlags.Modal, : base (title, Pinta.Core.PintaCore.Chrome.MainWindow, Gt k.DialogFlags.Modal,
Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.St ock.Ok, Gtk.ResponseType.Ok) Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.St ock.Ok, Gtk.ResponseType.Ok)
{ {
Icon = icon; Icon = icon;
skipping to change at line 74 skipping to change at line 75
DefaultResponse = Gtk.ResponseType.Ok; DefaultResponse = Gtk.ResponseType.Ok;
AlternativeButtonOrder = new int[] { (int)Gtk.ResponseTyp e.Ok, (int)Gtk.ResponseType.Cancel }; AlternativeButtonOrder = new int[] { (int)Gtk.ResponseTyp e.Ok, (int)Gtk.ResponseType.Cancel };
BuildDialog (localizer); BuildDialog (localizer);
} }
public object EffectData { get; private set; } public object EffectData { get; private set; }
public event PropertyChangedEventHandler EffectDataChanged; public event PropertyChangedEventHandler EffectDataChanged;
public override void Destroy ()
{
// If there is a timeout that hasn't been invoked yet, run it before
closing the dialog.
if (event_delay_timeout_id != 0)
{
GLib.Source.Remove (event_delay_timeout_id);
timeout_func.Invoke ();
}
base.Destroy ();
}
#region EffectData Parser #region EffectData Parser
private void BuildDialog (IAddinLocalizer localizer) private void BuildDialog (IAddinLocalizer localizer)
{ {
var members = EffectData.GetType ().GetMembers (); var members = EffectData.GetType ().GetMembers ();
foreach (var mi in members) { foreach (var mi in members) {
Type mType = GetTypeForMember (mi); Type mType = GetTypeForMember (mi);
if (mType == null) if (mType == null)
continue; continue;
skipping to change at line 156 skipping to change at line 169
string[] member_names = Enum.GetNames (myType); string[] member_names = Enum.GetNames (myType);
var labels = new List<string> (); var labels = new List<string> ();
var label_to_member = new Dictionary<string, string> (); var label_to_member = new Dictionary<string, string> ();
foreach (var member_name in member_names) foreach (var member_name in member_names)
{ {
var members = myType.GetMember (member_name); var members = myType.GetMember (member_name);
// Look for a Caption attribute that provides a ( translated) description. // Look for a Caption attribute that provides a ( translated) description.
string label; string label;
var attrs = members [0].GetCustomAttributes (type of(CaptionAttribute), false); var attrs = members [0].GetCustomAttributes (type of (CaptionAttribute), false);
if (attrs.Length > 0) if (attrs.Length > 0)
label = Catalog.GetString (((CaptionAttri bute)attrs [0]).Caption); label = Catalog.GetString (((CaptionAttri bute)attrs [0]).Caption);
else else
label = Catalog.GetString (member_name); label = Catalog.GetString (member_name);
label_to_member [label] = member_name; label_to_member [label] = member_name;
labels.Add (label); labels.Add (label);
} }
ComboBoxWidget widget = new ComboBoxWidget (labels.ToArra y ()); ComboBoxWidget widget = new ComboBoxWidget (labels.ToArra y ());
widget.Label = caption; widget.Label = caption;
widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask); widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask);
widget.Active = ((IList)member_names).IndexOf (GetValue ( member, o).ToString ()); widget.Active = ((IList)member_names).IndexOf (GetValue ( member, o).ToString ());
widget.Changed += delegate (object sender, EventArgs e) { widget.Changed += delegate (object sender, EventArgs e) {
SetValue (member, o, Enum.Parse (myType, label_to _member[widget.ActiveText])); SetValue (member, o, Enum.Parse (myType, label_to _member [widget.ActiveText]));
}; };
return widget; return widget;
} }
private ComboBoxWidget CreateComboBox (string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes) private ComboBoxWidget CreateComboBox (string caption, object o, System.Reflection.MemberInfo member, System.Object [] attributes)
{ {
Dictionary<string, object> dict = null; Dictionary<string, object> dict = null;
foreach (var attr in attributes) { foreach (var attr in attributes) {
if (attr is StaticListAttribute) if (attr is StaticListAttribute)
dict = (Dictionary<string, object>)GetVal ue (((StaticListAttribute)attr).dictionaryName, o); dict = (Dictionary<string, object>)GetVal ue (((StaticListAttribute)attr).dictionaryName, o);
} }
List<string> entries = new List<string> (); List<string> entries = new List<string> ();
foreach (string str in dict.Keys) foreach (string str in dict.Keys)
skipping to change at line 205 skipping to change at line 218
widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask); widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask);
widget.Active = entries.IndexOf ((string)GetValue (member , o)); widget.Active = entries.IndexOf ((string)GetValue (member , o));
widget.Changed += delegate (object sender, EventArgs e) { widget.Changed += delegate (object sender, EventArgs e) {
SetValue (member, o, widget.ActiveText); SetValue (member, o, widget.ActiveText);
}; };
return widget; return widget;
} }
private HScaleSpinButtonWidget CreateDoubleSlider (string caption , object o, MemberInfo member, object[] attributes) private HScaleSpinButtonWidget CreateDoubleSlider (string caption , object o, MemberInfo member, object [] attributes)
{ {
HScaleSpinButtonWidget widget = new HScaleSpinButtonWidge t (); HScaleSpinButtonWidget widget = new HScaleSpinButtonWidge t ();
int min_value = -100; int min_value = -100;
int max_value = 100; int max_value = 100;
double inc_value = 0.01; double inc_value = 0.01;
int digits_value = 2; int digits_value = 2;
foreach (var attr in attributes) { foreach (var attr in attributes) {
if (attr is MinimumValueAttribute) if (attr is MinimumValueAttribute)
skipping to change at line 233 skipping to change at line 246
} }
widget.Label = caption; widget.Label = caption;
widget.MinimumValue = min_value; widget.MinimumValue = min_value;
widget.MaximumValue = max_value; widget.MaximumValue = max_value;
widget.IncrementValue = inc_value; widget.IncrementValue = inc_value;
widget.DigitsValue = digits_value; widget.DigitsValue = digits_value;
widget.DefaultValue = (double)GetValue (member, o); widget.DefaultValue = (double)GetValue (member, o);
widget.ValueChanged += delegate (object sender, EventArgs e) { widget.ValueChanged += delegate (object sender, EventArgs e) {
DelayedUpdate( () => {
if (event_delay_timeout_id != 0)
GLib.Source.Remove (event_delay_timeout_i
d);
event_delay_timeout_id = GLib.Timeout.Add (event_
delay_millis, () => {
event_delay_timeout_id = 0;
SetValue (member, o, widget.Value); SetValue (member, o, widget.Value);
return false; return false;
}); });
}; };
return widget; return widget;
} }
private HScaleSpinButtonWidget CreateSlider (string caption, obje ct o, MemberInfo member, object[] attributes) private HScaleSpinButtonWidget CreateSlider (string caption, obje ct o, MemberInfo member, object [] attributes)
{ {
HScaleSpinButtonWidget widget = new HScaleSpinButtonWidge t (); HScaleSpinButtonWidget widget = new HScaleSpinButtonWidge t ();
int min_value = -100; int min_value = -100;
int max_value = 100; int max_value = 100;
double inc_value = 1.0; double inc_value = 1.0;
int digits_value = 0; int digits_value = 0;
foreach (var attr in attributes) { foreach (var attr in attributes) {
if (attr is MinimumValueAttribute) if (attr is MinimumValueAttribute)
skipping to change at line 275 skipping to change at line 283
} }
widget.Label = caption; widget.Label = caption;
widget.MinimumValue = min_value; widget.MinimumValue = min_value;
widget.MaximumValue = max_value; widget.MaximumValue = max_value;
widget.IncrementValue = inc_value; widget.IncrementValue = inc_value;
widget.DigitsValue = digits_value; widget.DigitsValue = digits_value;
widget.DefaultValue = (int)GetValue (member, o); widget.DefaultValue = (int)GetValue (member, o);
widget.ValueChanged += delegate (object sender, EventArgs e) { widget.ValueChanged += delegate (object sender, EventArgs e) {
DelayedUpdate( () => {
if (event_delay_timeout_id != 0)
GLib.Source.Remove (event_delay_timeout_i
d);
event_delay_timeout_id = GLib.Timeout.Add (event_
delay_millis, () => {
event_delay_timeout_id = 0;
SetValue (member, o, widget.ValueAsInt); SetValue (member, o, widget.ValueAsInt);
return false; return false;
}); });
}; };
return widget; return widget;
} }
private Gtk.CheckButton CreateCheckBox (string caption, object o, MemberInfo member, object[] attributes) private Gtk.CheckButton CreateCheckBox (string caption, object o, MemberInfo member, object [] attributes)
{ {
Gtk.CheckButton widget = new Gtk.CheckButton (); Gtk.CheckButton widget = new Gtk.CheckButton ();
widget.Label = caption; widget.Label = caption;
widget.Active = (bool)GetValue (member, o); widget.Active = (bool)GetValue (member, o);
widget.Toggled += delegate (object sender, EventArgs e) { widget.Toggled += delegate (object sender, EventArgs e) {
SetValue (member, o, widget.Active); SetValue (member, o, widget.Active);
}; };
return widget; return widget;
} }
private PointPickerWidget CreateOffsetPicker (string caption, obj ect o, MemberInfo member, object[] attributes) private PointPickerWidget CreateOffsetPicker (string caption, obj ect o, MemberInfo member, object [] attributes)
{ {
PointPickerWidget widget = new PointPickerWidget (); PointPickerWidget widget = new PointPickerWidget ();
widget.Label = caption; widget.Label = caption;
widget.DefaultOffset = (Cairo.PointD)GetValue (member, o) ; widget.DefaultOffset = (Cairo.PointD)GetValue (member, o) ;
widget.PointPicked += delegate (object sender, EventArgs e) { widget.PointPicked += delegate (object sender, EventArgs e) {
SetValue (member, o, widget.Offset); SetValue (member, o, widget.Offset);
}; };
return widget; return widget;
} }
private PointPickerWidget CreatePointPicker (string caption, obje ct o, MemberInfo member, object[] attributes) private PointPickerWidget CreatePointPicker (string caption, obje ct o, MemberInfo member, object [] attributes)
{ {
PointPickerWidget widget = new PointPickerWidget (); PointPickerWidget widget = new PointPickerWidget ();
widget.Label = caption; widget.Label = caption;
widget.DefaultPoint = (Gdk.Point)GetValue (member, o); widget.DefaultPoint = (Gdk.Point)GetValue (member, o);
widget.PointPicked += delegate (object sender, EventArgs e) { widget.PointPicked += delegate (object sender, EventArgs e) {
SetValue (member, o, widget.Point); SetValue (member, o, widget.Point);
}; };
return widget; return widget;
} }
private AnglePickerWidget CreateAnglePicker (string caption, obje ct o, MemberInfo member, object[] attributes) private AnglePickerWidget CreateAnglePicker (string caption, obje ct o, MemberInfo member, object [] attributes)
{ {
AnglePickerWidget widget = new AnglePickerWidget (); AnglePickerWidget widget = new AnglePickerWidget ();
widget.Label = caption; widget.Label = caption;
widget.DefaultValue = (double)GetValue (member, o); widget.DefaultValue = (double)GetValue (member, o);
widget.ValueChanged += delegate (object sender, EventArgs e) { widget.ValueChanged += delegate (object sender, EventArgs e) {
if (event_delay_timeout_id != 0) DelayedUpdate( () => {
GLib.Source.Remove (event_delay_timeout_i
d);
event_delay_timeout_id = GLib.Timeout.Add (event_
delay_millis, () => {
event_delay_timeout_id = 0;
SetValue (member, o, widget.Value); SetValue (member, o, widget.Value);
return false; return false;
}); });
}; };
return widget; return widget;
} }
private Gtk.Label CreateHintLabel (string hint) private Gtk.Label CreateHintLabel (string hint)
{ {
Gtk.Label label = new Gtk.Label (hint); Gtk.Label label = new Gtk.Label (hint);
label.LineWrap = true; label.LineWrap = true;
return label; return label;
} }
private ReseedButtonWidget CreateSeed (string caption, object o, MemberInfo member, object[] attributes) private ReseedButtonWidget CreateSeed (string caption, object o, MemberInfo member, object [] attributes)
{ {
ReseedButtonWidget widget = new ReseedButtonWidget (); ReseedButtonWidget widget = new ReseedButtonWidget ();
widget.Clicked += delegate (object sender, EventArgs e) { widget.Clicked += delegate (object sender, EventArgs e) {
SetValue (member, o, random.Next ()); SetValue (member, o, random.Next ());
}; };
return widget; return widget;
} }
#endregion #endregion
#region Static Reflection Methods #region Static Reflection Methods
private static object GetValue (MemberInfo mi, object o) private static object GetValue (MemberInfo mi, object o)
{ {
var fi = mi as FieldInfo; var fi = mi as FieldInfo;
if (fi != null) if (fi != null)
return fi.GetValue (o); return fi.GetValue (o);
var pi = mi as PropertyInfo; var pi = mi as PropertyInfo;
var getMethod = pi.GetGetMethod (); var getMethod = pi.GetGetMethod ();
return getMethod.Invoke (o, new object[0]); return getMethod.Invoke (o, new object [0]);
} }
private void SetValue (MemberInfo mi, object o, object val) private void SetValue (MemberInfo mi, object o, object val)
{ {
var fi = mi as FieldInfo; var fi = mi as FieldInfo;
var pi = mi as PropertyInfo; var pi = mi as PropertyInfo;
string fieldName = null; string fieldName = null;
if (fi != null) { if (fi != null) {
fi.SetValue (o, val); fi.SetValue (o, val);
fieldName = fi.Name; fieldName = fi.Name;
} else if (pi != null) { } else if (pi != null) {
var setMethod = pi.GetSetMethod (); var setMethod = pi.GetSetMethod ();
setMethod.Invoke (o, new object[] { val }); setMethod.Invoke (o, new object [] { val });
fieldName = pi.Name; fieldName = pi.Name;
} }
if (EffectDataChanged != null) if (EffectDataChanged != null)
EffectDataChanged (this, new PropertyChangedEvent Args (fieldName)); EffectDataChanged (this, new PropertyChangedEvent Args (fieldName));
} }
// Returns the type for fields and properties and null for everyt hing else // Returns the type for fields and properties and null for everyt hing else
private static Type GetTypeForMember (MemberInfo mi) private static Type GetTypeForMember (MemberInfo mi)
{ {
skipping to change at line 447 skipping to change at line 446
private object GetValue (string name, object o) private object GetValue (string name, object o)
{ {
var fi = o.GetType ().GetField (name); var fi = o.GetType ().GetField (name);
if (fi != null) if (fi != null)
return fi.GetValue (o); return fi.GetValue (o);
var pi = o.GetType ().GetProperty (name); var pi = o.GetType ().GetProperty (name);
if (pi == null) if (pi == null)
return null; return null;
var getMethod = pi.GetGetMethod (); var getMethod = pi.GetGetMethod ();
return getMethod.Invoke (o, new object[0]); return getMethod.Invoke (o, new object [0]);
} }
#endregion
} private void DelayedUpdate (GLib.TimeoutHandler handler)
{
if (event_delay_timeout_id != 0)
{
GLib.Source.Remove (event_delay_timeout_id);
if (handler != timeout_func)
timeout_func.Invoke ();
}
timeout_func = handler;
event_delay_timeout_id = GLib.Timeout.Add (event_delay_mi
llis, () => {
event_delay_timeout_id = 0;
timeout_func.Invoke ();
timeout_func = null;
return false;
});
}
#endregion
}
/// <summary> /// <summary>
/// Wrapper around Pinta's translation template. /// Wrapper around Pinta's translation template.
/// </summary> /// </summary>
public class PintaLocalizer : IAddinLocalizer public class PintaLocalizer : IAddinLocalizer
{ {
public string GetString (string msgid) public string GetString (string msgid)
{ {
return Mono.Unix.Catalog.GetString (msgid); return Mono.Unix.Catalog.GetString (msgid);
} }
 End of changes. 19 change blocks. 
38 lines changed or deleted 51 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)