An advanced sprite packing tool. Currently a work in progress.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.cs 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Gtk;
  5. using Ext.SilentorBit;
  6. using System.Drawing.Imaging;
  7. namespace SpritePacker.GUI
  8. {
  9. public class MainWindow : Window
  10. {
  11. private static bool initialised = false;
  12. private SpriteListView spriteListDisplay;
  13. private FileChooserWidget spriteListSelector;
  14. private FileFilter spriteListSelectorFilter;
  15. public MainWindow() : base("SpritePacker GUI")
  16. {
  17. if (!initialised)
  18. throw new InvalidOperationException("Error: Gtk hasn't been initialised yet, so you can't create a new window.");
  19. SetDefaultSize(500, 300);
  20. SetPosition(WindowPosition.Center);
  21. // Quit when the close button is pressed
  22. DeleteEvent += (object o, DeleteEventArgs args) => {
  23. Application.Quit();
  24. };
  25. setupWidgets();
  26. }
  27. /// <summary>
  28. /// Initilise GTK# to make it ready for use.
  29. /// </summary>
  30. public static void Init()
  31. {
  32. initialised = true;
  33. Application.Init();
  34. }
  35. public void Start()
  36. {
  37. ShowAll();
  38. Application.Run();
  39. }
  40. private void setupWidgets()
  41. {
  42. // Create the layout containers
  43. HBox masterContainer = new HBox(true, 10);
  44. VBox leftPanel = new VBox(false, 0) { MarginRight = 5 };
  45. VBox rightPanel = new VBox(false, 0) { MarginLeft = 5 };
  46. Frame leftPanelFrame = new Frame("Sprites") { Child = leftPanel, Margin = 10, MarginRight = 5 };
  47. Frame rightPanelFrame = new Frame("Preview") { Child = rightPanel, Margin = 10, MarginLeft = 5 };
  48. // Create the file selector filter
  49. spriteListSelectorFilter = new FileFilter() { Name = "Images" };
  50. foreach (ImageCodecInfo currentDecoder in ImageCodecInfo.GetImageDecoders())
  51. spriteListSelectorFilter.AddMimeType(currentDecoder.MimeType);
  52. // Create the file selector
  53. spriteListSelector = new FileChooserWidget(FileChooserAction.Open) {
  54. Margin = 10,
  55. PreviewWidgetActive = true,
  56. Filter = spriteListSelectorFilter
  57. };
  58. // Create the ListView to display the added sprites
  59. spriteListDisplay = new SpriteListView() { Margin = 10 };
  60. spriteListDisplay.AddItem(new Sprite("/home/sbrl/Pictures/Spaghetti.png"));
  61. // Populate the left panel
  62. leftPanel.PackStart(spriteListSelector, true, true, 0);
  63. leftPanel.PackStart(spriteListDisplay, true, true, 0);
  64. // Pack the master container
  65. masterContainer.PackStart(leftPanelFrame, true, true, 0);
  66. masterContainer.PackStart(rightPanelFrame, true, true, 0);
  67. // Add the master container to the window itself
  68. Add(masterContainer);
  69. }
  70. }
  71. }