using System; using System.Collections.Generic; using System.Linq; using Gtk; using Ext.SilentorBit; using System.Drawing.Imaging; namespace SpritePacker.GUI { public class MainWindow : Window { private static bool initialised = false; private SpriteListView spriteListDisplay; private FileChooserWidget spriteListSelector; private FileFilter spriteListSelectorFilter; public MainWindow() : base("SpritePacker GUI") { if (!initialised) throw new InvalidOperationException("Error: Gtk hasn't been initialised yet, so you can't create a new window."); SetDefaultSize(500, 300); SetPosition(WindowPosition.Center); // Quit when the close button is pressed DeleteEvent += (object o, DeleteEventArgs args) => { Application.Quit(); }; setupWidgets(); } /// /// Initilise GTK# to make it ready for use. /// public static void Init() { initialised = true; Application.Init(); } public void Start() { ShowAll(); Application.Run(); } private void setupWidgets() { // Create the layout containers HBox masterContainer = new HBox(true, 10); VBox leftPanel = new VBox(false, 0) { MarginRight = 5 }; VBox rightPanel = new VBox(false, 0) { MarginLeft = 5 }; Frame leftPanelFrame = new Frame("Sprites") { Child = leftPanel, Margin = 10, MarginRight = 5 }; Frame rightPanelFrame = new Frame("Preview") { Child = rightPanel, Margin = 10, MarginLeft = 5 }; // Create the file selector filter spriteListSelectorFilter = new FileFilter() { Name = "Images" }; foreach (ImageCodecInfo currentDecoder in ImageCodecInfo.GetImageDecoders()) spriteListSelectorFilter.AddMimeType(currentDecoder.MimeType); // Create the file selector spriteListSelector = new FileChooserWidget(FileChooserAction.Open) { Margin = 10, PreviewWidgetActive = true, Filter = spriteListSelectorFilter }; // Create the ListView to display the added sprites spriteListDisplay = new SpriteListView() { Margin = 10 }; spriteListDisplay.AddItem(new Sprite("/home/sbrl/Pictures/Spaghetti.png")); // Populate the left panel leftPanel.PackStart(spriteListSelector, true, true, 0); leftPanel.PackStart(spriteListDisplay, true, true, 0); // Pack the master container masterContainer.PackStart(leftPanelFrame, true, true, 0); masterContainer.PackStart(rightPanelFrame, true, true, 0); // Add the master container to the window itself Add(masterContainer); } } }