Skip to content

Instantly share code, notes, and snippets.

@cwensley
Forked from phrohdoh/pal-edit.cs
Last active August 29, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwensley/1216ef2a625ff497e297 to your computer and use it in GitHub Desktop.
Save cwensley/1216ef2a625ff497e297 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using Eto;
using Eto.Forms;
using Eto.Drawing;
namespace ShpSharp
{
public class PalEditorForm : Form
{
public readonly Drawable Drawable;
public PalEditorForm()
{
Title = "Palette Editor";
ClientSize = new Size(400, 300);
Drawable = new Drawable();
Drawable.Paint += HandlePaint;
Drawable.Visible = true;
#region Open files
var openFileDlg = new OpenFileDialog
{
CheckFileExists = true,
MultiSelect = false,
Directory = new Uri(EtoEnvironment.GetFolderPath(EtoSpecialFolder.ApplicationResources))
};
var openFileCmd = new Command
{
MenuText = "Open Pal...",
ToolBarText = "Open Pal",
ToolTip = "Open a palette for editing",
Shortcut = Application.Instance.CommonModifier | Keys.O
};
openFileCmd.Executed += (sender, e) =>
{
var result = openFileDlg.ShowDialog(this);
if (result == DialogResult.Cancel)
return;
var file = openFileDlg.FileName;
MessageBox.Show(this, "TODO: Open pal: " + file);
};
#endregion
var newPalCmd = new Command
{
MenuText = "New Pal",
ToolBarText = "New Pal",
ToolTip = "Create a new palette",
};
newPalCmd.Executed += (sender, e) =>
{
Debug.WriteLine("newPalCmd");
//palette = new PaletteData();
//palette.Entries = new PaletteEntry[256];
Drawable.Invalidate();
};
var invalidateBtn = new Button
{
Text = "Invalidate Drawable",
Visible = true,
};
invalidateBtn.Click += (sender, e) => Drawable.Invalidate();
ToolBar = new ToolBar
{
Items =
{
openFileCmd,
newPalCmd
}
};
var layout = new TableLayout
(
new TableRow(Drawable) { ScaleHeight = true },
invalidateBtn
);
Content = layout;
}
void HandlePaint(object sender, PaintEventArgs e)
{
Debug.WriteLine("HandlePaint from " + sender.ToString());
var g = e.Graphics;
g.DrawPolygon(Colors.Blue, new []
{
new PointF(10, 10),
new PointF(50, 10),
new PointF(50, 50),
new PointF(10, 10),
});
}
IEnumerable<FileDialogFilter> GetFilters()
{
yield return new FileDialogFilter("Palettes (.pal)", "pal");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment