Skip to content

Commit

Permalink
Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Apr 3, 2011
1 parent d19c146 commit 447699a
Showing 1 changed file with 69 additions and 71 deletions.
140 changes: 69 additions & 71 deletions Pinta.Gui.Widgets/Dialogs/SimpleEffectDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public class SimpleEffectDialog : Gtk.Dialog
{
[ThreadStatic]
Random random = new Random ();

const uint event_delay_millis = 100;
uint event_delay_timeout_id;

public SimpleEffectDialog (string title, Gdk.Pixbuf icon, object effectData)
: base (title, Pinta.Core.PintaCore.Chrome.MainWindow, Gtk.DialogFlags.Modal,
Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Ok, Gtk.ResponseType.Ok)
Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Ok, Gtk.ResponseType.Ok)
{
Icon = icon;
EffectData = effectData;
Expand All @@ -56,15 +56,15 @@ public SimpleEffectDialog (string title, Gdk.Pixbuf icon, object effectData)
VBox.Spacing = 12;
WidthRequest = 400;
DefaultResponse = Gtk.ResponseType.Ok;
AlternativeButtonOrder = new int[] { (int) Gtk.ResponseType.Ok, (int) Gtk.ResponseType.Cancel };
AlternativeButtonOrder = new int[] { (int)Gtk.ResponseType.Ok, (int)Gtk.ResponseType.Cancel };

BuildDialog ();
}

public object EffectData { get; private set; }

public event PropertyChangedEventHandler EffectDataChanged;

#region EffectData Parser
private void BuildDialog ()
{
Expand All @@ -75,12 +75,12 @@ private void BuildDialog ()

if (mType == null)
continue;

string caption = null;
string hint = null;
bool skip = false;
bool combo = false;

object[] attrs = mi.GetCustomAttributes (false);

foreach (var attr in attrs) {
Expand All @@ -92,7 +92,7 @@ private void BuildDialog ()
hint = ((HintAttribute)attr).Hint;
else if (attr is StaticListAttribute)
combo = true;

}

if (skip || string.Compare (mi.Name, "IsDefault", true) == 0)
Expand All @@ -107,7 +107,7 @@ private void BuildDialog ()
AddWidget (CreateSlider (Catalog.GetString (caption), EffectData, mi, attrs));
else if (mType == typeof (double) && (caption == "Angle" || caption == "Rotation"))
AddWidget (CreateAnglePicker (Catalog.GetString (caption), EffectData, mi, attrs));
else if (mType == typeof(double))
else if (mType == typeof (double))
AddWidget (CreateDoubleSlider (Catalog.GetString (caption), EffectData, mi, attrs));
else if (combo && mType == typeof (string))
AddWidget (CreateComboBox (Catalog.GetString (caption), EffectData, mi, attrs));
Expand All @@ -119,7 +119,7 @@ private void BuildDialog ()
AddWidget (CreateOffsetPicker (Catalog.GetString (caption), EffectData, mi, attrs));
else if (mType.IsEnum)
AddWidget (CreateEnumComboBox (Catalog.GetString (caption), EffectData, mi, attrs));

if (hint != null)
AddWidget (CreateHintLabel (Catalog.GetString (hint)));
}
Expand All @@ -133,30 +133,28 @@ private void AddWidget (Gtk.Widget widget)
#endregion

#region Control Builders


private ComboBoxWidget CreateEnumComboBox (string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
{
Type myType = GetTypeForMember (member);
string[] entries = Enum.GetNames(myType);
string[] entries = Enum.GetNames (myType);

ComboBoxWidget widget = new ComboBoxWidget (entries);

widget.Label = caption;
widget.AddEvents ((int)Gdk.EventMask.ButtonPressMask);
widget.Active = ((IList)entries).IndexOf (GetValue (member, o).ToString());
widget.Active = ((IList)entries).IndexOf (GetValue (member, o).ToString ());

widget.Changed += delegate (object sender, EventArgs e) {
SetValue (member, o, Enum.Parse(myType, widget.ActiveText));
SetValue (member, o, Enum.Parse (myType, widget.ActiveText));
};

return widget;
}

private ComboBoxWidget CreateComboBox (string caption, object o, System.Reflection.MemberInfo member, System.Object[] attributes)
{
Dictionary<string, object> dict = null;;
string dictName;
Dictionary<string, object> dict = null;

foreach (var attr in attributes) {
if (attr is StaticListAttribute)
dict = (Dictionary<string, object>)GetValue (((StaticListAttribute)attr).dictionaryName, o);
Expand All @@ -165,104 +163,104 @@ private ComboBoxWidget CreateComboBox (string caption, object o, System.Reflecti
List<string> entries = new List<string> ();
foreach (string str in dict.Keys)
entries.Add (str);

ComboBoxWidget widget = new ComboBoxWidget (entries.ToArray ());

widget.Label = caption;
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) {
SetValue (member, o, widget.ActiveText);
};

return widget;
}

private HScaleSpinButtonWidget CreateDoubleSlider (string caption, object o, MemberInfo member, object[] attributes)
{
HScaleSpinButtonWidget widget = new HScaleSpinButtonWidget ();

int min_value = -100;
int max_value = 100;
double inc_value = 0.01;
int digits_value = 2;
int max_value = 100;
double inc_value = 0.01;
int digits_value = 2;

foreach (var attr in attributes) {
if (attr is MinimumValueAttribute)
min_value = ((MinimumValueAttribute)attr).Value;
else if (attr is MaximumValueAttribute)
max_value = ((MaximumValueAttribute)attr).Value;
else if (attr is IncrementValueAttribute)
inc_value = ((IncrementValueAttribute)attr).Value;
else if (attr is DigitsValueAttribute)
digits_value = ((DigitsValueAttribute)attr).Value;
else if (attr is IncrementValueAttribute)
inc_value = ((IncrementValueAttribute)attr).Value;
else if (attr is DigitsValueAttribute)
digits_value = ((DigitsValueAttribute)attr).Value;
}

widget.Label = caption;
widget.MinimumValue = min_value;
widget.MaximumValue = max_value;
widget.IncrementValue = inc_value;
widget.DigitsValue = digits_value;
widget.IncrementValue = inc_value;
widget.DigitsValue = digits_value;
widget.DefaultValue = (double)GetValue (member, o);

widget.ValueChanged += delegate (object sender, EventArgs e) {

if (event_delay_timeout_id != 0)
GLib.Source.Remove (event_delay_timeout_id);

event_delay_timeout_id = GLib.Timeout.Add (event_delay_millis, () => {
event_delay_timeout_id = 0;
SetValue (member, o, widget.Value);
return false;
});
};

return widget;
}

private HScaleSpinButtonWidget CreateSlider (string caption, object o, MemberInfo member, object[] attributes)
{
HScaleSpinButtonWidget widget = new HScaleSpinButtonWidget ();

int min_value = -100;
int max_value = 100;
double inc_value = 1.0;
int digits_value = 0;
int max_value = 100;
double inc_value = 1.0;
int digits_value = 0;

foreach (var attr in attributes) {
if (attr is MinimumValueAttribute)
min_value = ((MinimumValueAttribute)attr).Value;
else if (attr is MaximumValueAttribute)
max_value = ((MaximumValueAttribute)attr).Value;
else if (attr is IncrementValueAttribute)
inc_value = ((IncrementValueAttribute)attr).Value;
else if (attr is DigitsValueAttribute)
digits_value = ((DigitsValueAttribute)attr).Value;
else if (attr is IncrementValueAttribute)
inc_value = ((IncrementValueAttribute)attr).Value;
else if (attr is DigitsValueAttribute)
digits_value = ((DigitsValueAttribute)attr).Value;
}

widget.Label = caption;
widget.MinimumValue = min_value;
widget.MaximumValue = max_value;
widget.IncrementValue = inc_value;
widget.DigitsValue = digits_value;
widget.IncrementValue = inc_value;
widget.DigitsValue = digits_value;
widget.DefaultValue = (int)GetValue (member, o);

widget.ValueChanged += delegate (object sender, EventArgs e) {

if (event_delay_timeout_id != 0)
GLib.Source.Remove (event_delay_timeout_id);

event_delay_timeout_id = GLib.Timeout.Add (event_delay_millis, () => {
event_delay_timeout_id = 0;
SetValue (member, o, widget.ValueAsInt);
return false;
});
};

return widget;
}

private Gtk.CheckButton CreateCheckBox (string caption, object o, MemberInfo member, object[] attributes)
{
Gtk.CheckButton widget = new Gtk.CheckButton ();
Expand All @@ -280,7 +278,7 @@ private Gtk.CheckButton CreateCheckBox (string caption, object o, MemberInfo mem
private PointPickerWidget CreateOffsetPicker (string caption, object o, MemberInfo member, object[] attributes)
{
PointPickerWidget widget = new PointPickerWidget ();

widget.Label = caption;
widget.DefaultOffset = (Cairo.PointD)GetValue (member, o);

Expand All @@ -294,7 +292,7 @@ private PointPickerWidget CreateOffsetPicker (string caption, object o, MemberIn
private PointPickerWidget CreatePointPicker (string caption, object o, MemberInfo member, object[] attributes)
{
PointPickerWidget widget = new PointPickerWidget ();

widget.Label = caption;
widget.DefaultPoint = (Gdk.Point)GetValue (member, o);

Expand All @@ -311,11 +309,11 @@ private AnglePickerWidget CreateAnglePicker (string caption, object o, MemberInf

widget.Label = caption;
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)
GLib.Source.Remove (event_delay_timeout_id);

event_delay_timeout_id = GLib.Timeout.Add (event_delay_millis, () => {
event_delay_timeout_id = 0;
SetValue (member, o, widget.Value);
Expand All @@ -325,19 +323,19 @@ private AnglePickerWidget CreateAnglePicker (string caption, object o, MemberInf

return widget;
}

private Gtk.Label CreateHintLabel (string hint)
{
Gtk.Label label = new Gtk.Label (hint);
label.LineWrap = true;

return label;
}

private ReseedButtonWidget CreateSeed (string caption, object o, MemberInfo member, object[] attributes)
{
ReseedButtonWidget widget = new ReseedButtonWidget ();

widget.Clicked += delegate (object sender, EventArgs e) {
SetValue (member, o, random.Next ());
};
Expand All @@ -359,11 +357,11 @@ private static object GetValue (MemberInfo mi, object o)
}

private void SetValue (MemberInfo mi, object o, object val)
{
{
var fi = mi as FieldInfo;
var pi = mi as PropertyInfo;
string fieldName = null;

if (fi != null) {
fi.SetValue (o, val);
fieldName = fi.Name;
Expand All @@ -372,9 +370,9 @@ private void SetValue (MemberInfo mi, object o, object val)
setMethod.Invoke (o, new object[] { val });
fieldName = pi.Name;
}

if (EffectDataChanged != null)
EffectDataChanged (this, new PropertyChangedEventArgs(fieldName));
EffectDataChanged (this, new PropertyChangedEventArgs (fieldName));
}

// Returns the type for fields and properties and null for everything else
Expand All @@ -384,7 +382,7 @@ private static Type GetTypeForMember (MemberInfo mi)
return ((FieldInfo)mi).FieldType;
else if (mi is PropertyInfo)
return ((PropertyInfo)mi).PropertyType;

return null;
}

Expand All @@ -408,17 +406,17 @@ private static string MakeCaption (string name)
sb.Append (c);
}
}

return sb.ToString ();
}
private object GetValue(string name, object o)

private object GetValue (string name, object o)
{
var fi = o.GetType ().GetField (name);
if (fi != null)
return fi.GetValue (o);
var pi = o.GetType ().GetProperty (name);
if (pi == null)
if (pi == null)
return null;
var getMethod = pi.GetGetMethod ();
return getMethod.Invoke (o, new object[0]);
Expand Down

0 comments on commit 447699a

Please sign in to comment.