Skip to content

Commit

Permalink
+adding config save for paintings path
Browse files Browse the repository at this point in the history
  • Loading branch information
bahstrike committed Feb 26, 2022
1 parent 2ae0463 commit e26a714
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 36 deletions.
12 changes: 12 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DyeAtlas.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<userSettings>
<DyeAtlas.Properties.Settings>
<setting name="MyPaintings" serializeAs="String">
<value />
</setting>
</DyeAtlas.Properties.Settings>
</userSettings>
</configuration>
85 changes: 74 additions & 11 deletions DyeAtlas.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 31 additions & 6 deletions DyeAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Palette LoadPalette()

public static Palette palette;// defer loading until form load.. make sure config files are nice

private void Form1_Load(object sender, EventArgs e)
private void DyeAtlas_Load(object sender, EventArgs e)
{
palette = LoadPalette();

Expand All @@ -46,6 +46,24 @@ private void Form1_Load(object sender, EventArgs e)
preview.BackgroundImage = bk;

resolution.SelectedIndex = 1;// 256x256

// load settings
mypaintings.Text = Properties.Settings.Default.MyPaintings;
}

private void DyeAtlas_FormClosed(object sender, FormClosedEventArgs e)
{
// save settings
Properties.Settings.Default.MyPaintings = mypaintings.Text;
}

// convenience
public string MyPaintingsPath
{
get
{
return mypaintings.Text;
}
}

private void Form1_DragEnter(object sender, DragEventArgs e)
Expand Down Expand Up @@ -86,8 +104,6 @@ public void SaveFile(string file)
}
}

public string lastOpenedFile = null;

public Size ExportDimensions
{
get
Expand Down Expand Up @@ -162,7 +178,7 @@ public void OpenFile(string file)
pnt = PNTImage.GenerateFromBitmap(bmp, dithering.Checked);
}

lastOpenedFile = file;
currentfile.Text = file;
resolution.Text = $"{pnt.width}x{pnt.height}";

preview.Image = pnt.GenerateBitmap();
Expand All @@ -188,6 +204,9 @@ private void openButton_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();

if (Directory.Exists(MyPaintingsPath))
ofd.InitialDirectory = MyPaintingsPath;

ofd.Filter = "Compatible Files (*.pnt;*.png;*.bmp;*.jpg)|*.pnt;*.png;*.bmp;*.jpg|Paint Files (*.pnt)|*.pnt|Image Files (*.png;*.bmp;*.jpg)|*.png;*.bmp;*.jpg|All Files (*.*)|*.*";

if (ofd.ShowDialog() != DialogResult.OK)
Expand All @@ -198,7 +217,7 @@ private void openButton_Click(object sender, EventArgs e)

private void dithering_CheckedChanged(object sender, EventArgs e)
{
OpenFile(lastOpenedFile);
OpenFile(currentfile.Text);
}

private void savePNTButton_Click(object sender, EventArgs e)
Expand All @@ -209,6 +228,9 @@ private void savePNTButton_Click(object sender, EventArgs e)

SaveFileDialog sfd = new SaveFileDialog();

if (Directory.Exists(MyPaintingsPath))
sfd.InitialDirectory = MyPaintingsPath;

sfd.Filter = "Paint File (*.pnt)|*.pnt|All Files (*.*)|*.*";

if (sfd.ShowDialog() != DialogResult.OK)
Expand All @@ -225,6 +247,9 @@ private void savePNGButton_Click(object sender, EventArgs e)

SaveFileDialog sfd = new SaveFileDialog();

if (Directory.Exists(MyPaintingsPath))
sfd.InitialDirectory = MyPaintingsPath;

sfd.RestoreDirectory = true;// if we are exporting image to desktop or whatever then we should not mess with open file
sfd.Filter = "PNG File (*.png)|*.png|Image Files (*.png;*.bmp;*.jpg)|*.png;*.bmp;*.jpg|All Files (*.*)|*.*";

Expand All @@ -236,7 +261,7 @@ private void savePNGButton_Click(object sender, EventArgs e)

private void resolution_TextChanged(object sender, EventArgs e)
{
OpenFile(lastOpenedFile);
OpenFile(currentfile.Text);
}
}
}
3 changes: 3 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new DyeAtlas());

Properties.Settings.Default.Save();
}
}
}
34 changes: 21 additions & 13 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DyeAtlas.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="MyPaintings" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

0 comments on commit e26a714

Please sign in to comment.