Browse Source

Add file selector with auto populated filter.

tags/v0.1
Starbeamrainbowlabs 2 years ago
parent
commit
054d7d5169
2 changed files with 24 additions and 3 deletions
  1. 23
    3
      SpritePacker-GUI/MainWindow.cs
  2. 1
    0
      SpritePacker-GUI/SpritePacker-GUI.csproj

+ 23
- 3
SpritePacker-GUI/MainWindow.cs View File

@@ -4,6 +4,7 @@ using System.Linq;
4 4
 
5 5
 using Gtk;
6 6
 using Ext.SilentorBit;
7
+using System.Drawing.Imaging;
7 8
 
8 9
 namespace SpritePacker.GUI
9 10
 {
@@ -12,6 +13,8 @@ namespace SpritePacker.GUI
12 13
 		private static bool initialised = false;
13 14
 
14 15
 		private SpriteListView spriteListDisplay;
16
+		private FileChooserWidget spriteListSelector;
17
+		private FileFilter spriteListSelectorFilter;
15 18
 
16 19
 		public MainWindow() : base("SpritePacker GUI")
17 20
 		{
@@ -26,7 +29,7 @@ namespace SpritePacker.GUI
26 29
 				Application.Quit();
27 30
 			};
28 31
 
29
-			setupLayout();
32
+			setupWidgets();
30 33
 		}
31 34
 
32 35
 		/// <summary>
@@ -44,23 +47,40 @@ namespace SpritePacker.GUI
44 47
 			Application.Run();
45 48
 		}
46 49
 
47
-		private void setupLayout()
50
+		private void setupWidgets()
48 51
 		{
52
+			// Create the layout containers
49 53
 			HBox masterContainer = new HBox(true, 10);
50 54
 			VBox leftPanel = new VBox(false, 0) { MarginRight = 5 };
51 55
 			VBox rightPanel = new VBox(false, 0) { MarginLeft = 5 };
52 56
 			Frame leftPanelFrame = new Frame("Sprites") { Child = leftPanel, Margin = 10, MarginRight = 5 };
53 57
 			Frame rightPanelFrame = new Frame("Preview") { Child = rightPanel, Margin = 10, MarginLeft = 5 };
54 58
 
59
+			// Create the file selector filter
60
+			spriteListSelectorFilter = new FileFilter() { Name = "Images" };
61
+			foreach (ImageCodecInfo currentDecoder in ImageCodecInfo.GetImageDecoders())
62
+				spriteListSelectorFilter.AddMimeType(currentDecoder.MimeType);
63
+
64
+			// Create the file selector
65
+			spriteListSelector = new FileChooserWidget(FileChooserAction.Open) {
66
+				Margin = 10,
67
+				PreviewWidgetActive = true,
68
+				Filter = spriteListSelectorFilter
69
+			};
70
+
71
+			// Create the ListView to display the added sprites
55 72
 			spriteListDisplay = new SpriteListView() { Margin = 10 };
56 73
 			spriteListDisplay.AddItem(new Sprite("/home/sbrl/Pictures/Spaghetti.png"));
57 74
 
58
-			leftPanel.OverrideBackgroundColor(StateFlags.Normal, Gdk.RGBA.Zero);
75
+			// Populate the left panel
76
+			leftPanel.PackStart(spriteListSelector, true, true, 0);
59 77
 			leftPanel.PackStart(spriteListDisplay, true, true, 0);
60 78
 
79
+			// Pack the master container
61 80
 			masterContainer.PackStart(leftPanelFrame, true, true, 0);
62 81
 			masterContainer.PackStart(rightPanelFrame, true, true, 0);
63 82
 
83
+			// Add the master container to the window itself
64 84
 			Add(masterContainer);
65 85
 		}
66 86
 	}

+ 1
- 0
SpritePacker-GUI/SpritePacker-GUI.csproj View File

@@ -52,6 +52,7 @@
52 52
     <Reference Include="pango-sharp">
53 53
       <HintPath>..\packages\GtkSharp.3.1.3\lib\net45\pango-sharp.dll</HintPath>
54 54
     </Reference>
55
+    <Reference Include="System.Drawing" />
55 56
   </ItemGroup>
56 57
   <ItemGroup>
57 58
     <Compile Include="Program.cs" />

Loading…
Cancel
Save