Hook add sprites button up

This commit is contained in:
Starbeamrainbowlabs 2016-08-03 12:00:14 +01:00
parent 6408d90821
commit fad5799c7e

View file

@ -5,6 +5,7 @@ using System.Linq;
using Gtk;
using Ext.SilentorBit;
using System.Drawing.Imaging;
using System.Runtime.ExceptionServices;
namespace SpritePacker.GUI
{
@ -19,6 +20,8 @@ namespace SpritePacker.GUI
private Button openImageButton;
private Button removeImageButton;
private SpritePacker spritePacker = new SpritePacker();
public MainWindow() : base("SpritePacker GUI")
{
if (!initialised)
@ -72,17 +75,35 @@ namespace SpritePacker.GUI
Filter = spriteListSelectorFilter
};
spriteListSelector.SelectMultiple = true;
spriteListSelector.AddButton("Add Sprites", ResponseType.Ok);
spriteListSelector.AddButton("Cancel", ResponseType.Cancel);
// Create the ListView to display the added sprites
spriteListDisplay = new SpriteListView() { Margin = 10, MarginTop = 5 };
spriteListDisplay.AddItem(new Sprite("/home/sbrl/Pictures/Spaghetti.png"));
openImageButton = new Button("Add sprite") { Margin = 10, MarginTop = 0, MarginBottom = 0 };
removeImageButton = new Button("Remove Sprite") { Margin = 10, MarginTop = 0, MarginBottom = 0 };
openImageButton = new Button("Add Sprites") { Margin = 10, MarginTop = 0, MarginBottom = 0 };
removeImageButton = new Button("Remove Selected Sprites") { Margin = 10, MarginTop = 0, MarginBottom = 0 };
openImageButton.Released += (object sender, EventArgs e) => {
ResponseType response = (ResponseType)spriteListSelector.Run();
spriteListSelector.Hide();
switch(response)
{
case ResponseType.Ok:
Action_AddSprite(spriteListSelector.Filenames);
break;
case ResponseType.DeleteEvent:
case ResponseType.Cancel:
Console.Error.WriteLine("Ignoring sprite file chooser response {0}.", response);
break;
default:
throw new Exception($"Unknown sprite file chooser response type {response}.");
}
};
// Populate the control button row
controlButtonRow.PackStart(removeImageButton, true, false, 0);
controlButtonRow.PackStart(openImageButton, true, false, 0);
controlButtonRow.PackStart(removeImageButton, true, false, 0);
// Populate the left panel
leftPanel.PackStart(controlButtonRow, false, false, 5);
@ -95,6 +116,16 @@ namespace SpritePacker.GUI
// Add the master container to the window itself
Add(masterContainer);
}
void Action_AddSprite(string[] selectedFilenames)
{
foreach (string filename in selectedFilenames)
{
Sprite nextSprite = new Sprite(filename);
spritePacker.Add(nextSprite);
spriteListDisplay.AddItem(nextSprite);
}
}
}
}