(ded4a3e0a) v0.9.0.7

This commit is contained in:
Joonas Rikkonen
2019-06-25 16:00:44 +03:00
parent e5ae622c77
commit 4a51db77b5
1777 changed files with 421528 additions and 917 deletions
@@ -0,0 +1,82 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Drawing;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)]
public class CellAttribute : Attribute
{
public string Name;
public Type Type;
public CellAttribute(Type type)
{
Type = type;
}
}
public class CellBase
{
public string Category { get; set; }
public object Value { get; set; }
public string DisplayValue { get; set; }
public string Text { get; set; }
public bool Editable { get; set; }
public int Height { get; set; }
public Action OnKill;
protected EventHandler _eventHandler;
protected Rectangle _lastRec;
protected Type _type;
public void Create(string category, string name, object value, Type type, EventHandler eventHandler = null)
{
Category = category;
Value = value;
DisplayValue = (value == null) ? "" : value.ToString();
Text = name;
Editable = true;
Height = DrawInfo.TextHeight;
_eventHandler = eventHandler;
_type = type;
OnCreate();
}
public virtual void OnCreate()
{
}
public virtual void Edit(PixelLayout control)
{
}
public virtual void Draw(Graphics g, Rectangle rec, int separatorPos, bool selected)
{
if (selected)
g.FillRectangle(SystemColors.Highlight, rec);
g.DrawText(SystemFonts.Default(), DrawInfo.GetTextColor(selected, false), rec.X + 5, rec.Y + (rec.Height - Height) / 2, Text);
g.FillRectangle(DrawInfo.GetBackgroundColor(selected), separatorPos - 6, rec.Y, rec.Width, rec.Height);
DrawCell(g, rec, separatorPos, selected);
}
public virtual void DrawCell(Graphics g, Rectangle rec, int separatorPos, bool selected)
{
_lastRec = rec;
_lastRec.X += separatorPos;
_lastRec.Width -= separatorPos - 1;
g.DrawText(SystemFonts.Default(), DrawInfo.GetTextColor(selected, !Editable), separatorPos + 5, rec.Y + (rec.Height - Height) / 2, DisplayValue);
}
}
}
@@ -0,0 +1,56 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Drawing;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(bool))]
public class CellBool : CellBase
{
private bool _draw;
public CellBool()
{
_draw = true;
}
public override void Edit(PixelLayout control)
{
_draw = false;
var checkbox = new CheckBox();
checkbox.Tag = this;
checkbox.Checked = (bool?)Value;
checkbox.ThreeState = (Value == null);
checkbox.Text = (checkbox.Checked == null) ? "Not Set" : checkbox.Checked.ToString();
checkbox.Width = _lastRec.Width - 10;
checkbox.Height = _lastRec.Height;
control.Add(checkbox, _lastRec.X + 10, _lastRec.Y);
checkbox.CheckedChanged += (sender, e) => checkbox.Text = (checkbox.Checked == null) ? "Not Set" : checkbox.Checked.ToString();
OnKill += delegate
{
OnKill = null;
if (_eventHandler == null || checkbox.Checked == null)
return;
_draw = true;
Value = checkbox.Checked;
_eventHandler(Value, EventArgs.Empty);
};
}
public override void DrawCell(Graphics g, Rectangle rec, int separatorPos, bool selected)
{
if (_draw)
base.DrawCell(g, rec, separatorPos, selected);
}
}
}
@@ -0,0 +1,57 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(char))]
public class CellChar : CellBase
{
public override void OnCreate()
{
DisplayValue = ((int)(char)Value) + " (" + Value + ")";
}
public override void Edit(PixelLayout control)
{
var editText = new TextBox();
editText.Tag = this;
editText.Style = "OverrideSize";
editText.Width = _lastRec.Width;
editText.Height = _lastRec.Height;
char value;
char.TryParse(Value.ToString(), out value);
editText.Text = ((int)value).ToString();
control.Add(editText, _lastRec.X, _lastRec.Y);
editText.Focus();
editText.CaretIndex = editText.Text.Length;
OnKill += delegate
{
OnKill = null;
if (_eventHandler == null)
return;
int num;
if (!int.TryParse(editText.Text, out num))
return;
_eventHandler((char)num, EventArgs.Empty);
};
editText.KeyDown += (sender, e) =>
{
if (e.Key == Keys.Enter)
OnKill.Invoke();
};
}
}
}
@@ -0,0 +1,46 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Drawing;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(Microsoft.Xna.Framework.Color))]
public class CellColor : CellBase
{
private Color color;
public override void OnCreate()
{
if (Value != null)
{
var tmp = (Microsoft.Xna.Framework.Color)Value;
color = new Color(tmp.R / 255f, tmp.G / 255f, tmp.B / 255f, tmp.A / 255f);
}
else
color = new Color();
}
public override void Edit(PixelLayout control)
{
var dialog = new ColorDialog();
dialog.Color = color;
if (dialog.ShowDialog(control) == DialogResult.Ok && _eventHandler != null && dialog.Color != color)
{
var col = new Microsoft.Xna.Framework.Color(dialog.Color.Rb, dialog.Color.Gb, dialog.Color.Bb, dialog.Color.Ab);
_eventHandler(col, EventArgs.Empty);
}
}
public override void DrawCell(Graphics g, Rectangle rec, int separatorPos, bool selected)
{
var border = rec.Height / 5;
g.FillRectangle(color, separatorPos + border, rec.Y + border, rec.Width - separatorPos - 2 * border, rec.Height - 2 * border);
}
}
}
@@ -0,0 +1,82 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(Enum))]
[CellAttribute(typeof(ImporterTypeDescription))]
[CellAttribute(typeof(ProcessorTypeDescription))]
public class CellCombo : CellBase
{
public override void OnCreate()
{
if (Value is ImporterTypeDescription)
DisplayValue = (Value as ImporterTypeDescription).DisplayName;
else if (Value is ProcessorTypeDescription)
DisplayValue = (Value as ProcessorTypeDescription).DisplayName;
}
public override void Edit(PixelLayout control)
{
var combo = new DropDown();
if (_type.IsSubclassOf(typeof(Enum)))
{
var values = Enum.GetValues(_type);
foreach (var v in values)
{
combo.Items.Add(v.ToString());
if (Value != null && v.ToString() == Value.ToString())
combo.SelectedIndex = combo.Items.Count - 1;
}
}
else if (_type == typeof(ImporterTypeDescription))
{
foreach (var v in PipelineTypes.Importers)
{
combo.Items.Add(v.DisplayName);
if (Value != null && v.DisplayName == (Value as ImporterTypeDescription).DisplayName)
combo.SelectedIndex = combo.Items.Count - 1;
}
}
else
{
foreach (var v in PipelineTypes.Processors)
{
combo.Items.Add(v.DisplayName);
if (Value != null && v.DisplayName == (Value as ProcessorTypeDescription).DisplayName)
combo.SelectedIndex = combo.Items.Count - 1;
}
}
combo.Style = "OverrideSize";
combo.Width = _lastRec.Width;
combo.Height = _lastRec.Height;
control.Add(combo, _lastRec.X, _lastRec.Y);
combo.SelectedIndexChanged += delegate
{
if (_eventHandler == null || combo.SelectedIndex < 0)
return;
if (_type.IsSubclassOf(typeof(Enum)))
_eventHandler(Enum.Parse(_type, combo.SelectedValue.ToString()), EventArgs.Empty);
else if (_type == typeof(ImporterTypeDescription))
_eventHandler(PipelineTypes.Importers[combo.SelectedIndex], EventArgs.Empty);
else
_eventHandler(PipelineTypes.Processors[combo.SelectedIndex], EventArgs.Empty);
combo.Enabled = true;
control.Add(combo, _lastRec.X, _lastRec.Y);
};
}
}
}
@@ -0,0 +1,78 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.ComponentModel;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(short))]
[CellAttribute(typeof(int))]
[CellAttribute(typeof(long))]
[CellAttribute(typeof(ushort))]
[CellAttribute(typeof(uint))]
[CellAttribute(typeof(ulong))]
[CellAttribute(typeof(float))]
[CellAttribute(typeof(double))]
[CellAttribute(typeof(decimal))]
public class CellNumber : CellBase
{
private TypeConverter _converter;
public override void OnCreate()
{
_converter = TypeDescriptor.GetConverter(_type);
if (_type == typeof(float) || _type == typeof(double) || _type == typeof(decimal))
{
if (_type == typeof(float))
DisplayValue = ((float)Value).ToString("0.00");
else if (_type == typeof(double))
DisplayValue = ((double)Value).ToString("0.00");
else
DisplayValue = ((decimal)Value).ToString("0.00");
DisplayValue = (DisplayValue.Length > Value.ToString().Length) ? DisplayValue : Value.ToString();
}
}
public override void Edit(PixelLayout control)
{
var editText = new TextBox();
editText.Tag = this;
editText.Style = "OverrideSize";
editText.Width = _lastRec.Width;
editText.Height = _lastRec.Height;
editText.Text = DisplayValue;
editText.Tag = this;
control.Add(editText, _lastRec.X, _lastRec.Y);
editText.Focus();
editText.CaretIndex = editText.Text.Length;
OnKill += delegate
{
OnKill = null;
if (_eventHandler == null)
return;
try
{
_eventHandler(_converter.ConvertFrom(editText.Text), EventArgs.Empty);
}
catch { }
};
editText.KeyDown += (sender, e) =>
{
if (e.Key == Keys.Enter)
OnKill.Invoke();
};
}
}
}
@@ -0,0 +1,28 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(string), Name = "IntermediateDir")]
[CellAttribute(typeof(string), Name = "OutputDir")]
public class CellPath : CellBase
{
public override void OnCreate()
{
if (Value == null)
Value = "";
}
public override void Edit(PixelLayout control)
{
var dialog = new PathDialog(PipelineController.Instance, Value.ToString());
if (dialog.ShowModal(control) && _eventHandler != null)
_eventHandler(dialog.Path, EventArgs.Empty);
}
}
}
@@ -0,0 +1,42 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.IO;
using System.Collections.Generic;
using Eto.Forms;
using Eto.Drawing;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(List<string>), Name = "References")]
public class CellRefs : CellBase
{
public override void OnCreate()
{
if (Value == null)
Value = new List<string>();
var list = Value as List<string>;
var displayValue = "";
foreach (var value in list)
displayValue += Environment.NewLine + Path.GetFileNameWithoutExtension (value);
DisplayValue = (Value as List<string>).Count > 0 ? displayValue.Trim(Environment.NewLine.ToCharArray()) : "None";
Height = Height * Math.Max(list.Count, 1);
}
public override void Edit(PixelLayout control)
{
var dialog = new ReferenceDialog(PipelineController.Instance, (Value as List<string>).ToArray());
if (dialog.ShowModal(control) && _eventHandler != null)
{
_eventHandler(dialog.References, EventArgs.Empty);
PipelineController.Instance.OnReferencesModified();
}
}
}
}
@@ -0,0 +1,45 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
[CellAttribute(typeof(string))]
public class CellText : CellBase
{
public override void Edit(PixelLayout control)
{
var editText = new TextBox();
editText.Tag = this;
editText.Style = "OverrideSize";
editText.Width = _lastRec.Width;
editText.Height = _lastRec.Height;
editText.Text = (Value == null) ? "" : Value.ToString();
control.Add(editText, _lastRec.X, _lastRec.Y);
editText.Focus();
editText.CaretIndex = editText.Text.Length;
OnKill += delegate
{
OnKill = null;
if (_eventHandler == null)
return;
_eventHandler(editText.Text, EventArgs.Empty);
};
editText.KeyDown += (sender, e) =>
{
if (e.Key == Keys.Enter)
OnKill.Invoke();
};
}
}
}