Skip to content

Commit 86a33c0

Browse files
committed
adding more settings (grid alpha, default resolution), #build
1 parent 0e1881e commit 86a33c0

File tree

7 files changed

+71
-18
lines changed

7 files changed

+71
-18
lines changed

PixelArtTool/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
<setting name="gridDarkColor" serializeAs="String">
1717
<value>Black</value>
1818
</setting>
19+
<setting name="defaultResolution" serializeAs="String">
20+
<value>16</value>
21+
</setting>
22+
<setting name="gridAlpha" serializeAs="String">
23+
<value>64</value>
24+
</setting>
1925
</PixelArtTool.Properties.Settings>
2026
</userSettings>
2127
</configuration>

PixelArtTool/MainWindow.xaml.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void Start()
147147
// setup background grid
148148
gridBitmap = new WriteableBitmap(canvasResolutionX, canvasResolutionY, dpiX, dpiY, PixelFormats.Bgra32, null);
149149
gridImage.Source = gridBitmap;
150-
DrawBackgroundGrid(gridBitmap, canvasResolutionX, canvasResolutionY, lightColor, darkColor);
150+
DrawBackgroundGrid(gridBitmap, canvasResolutionX, canvasResolutionY, lightColor, darkColor, gridAlpha);
151151

152152
// build drawing area
153153
canvasBitmap = new WriteableBitmap(canvasResolutionX, canvasResolutionY, dpiX, dpiY, PixelFormats.Bgra32, null);
@@ -1376,8 +1376,7 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
13761376
switch (result)
13771377
{
13781378
case true: // ok
1379-
// TODO: update things using settings
1380-
1379+
// TODO: update things using settings, better read from settings instead so can reuse it
13811380
var b1 = (SolidColorBrush)dlg.settingsLightColor.Fill;
13821381
lightColor.Red = b1.Color.R;
13831382
lightColor.Green = b1.Color.G;
@@ -1388,7 +1387,9 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
13881387
darkColor.Green = b2.Color.G;
13891388
darkColor.Blue = b2.Color.B;
13901389

1391-
DrawBackgroundGrid(gridBitmap, canvasResolutionX, canvasResolutionY, lightColor, darkColor);
1390+
gridAlpha = (byte)dlg.sldGridAlpha.Value;
1391+
1392+
DrawBackgroundGrid(gridBitmap, canvasResolutionX, canvasResolutionY, lightColor, darkColor, gridAlpha);
13921393
break;
13931394
case false: // cancelled
13941395
break;

PixelArtTool/Properties/Settings.Designer.cs

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PixelArtTool/Properties/Settings.settings

+6
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@
88
<Setting Name="gridDarkColor" Type="System.Drawing.Color" Scope="User">
99
<Value Profile="(Default)">Black</Value>
1010
</Setting>
11+
<Setting Name="defaultResolution" Type="System.Byte" Scope="User">
12+
<Value Profile="(Default)">16</Value>
13+
</Setting>
14+
<Setting Name="gridAlpha" Type="System.Byte" Scope="User">
15+
<Value Profile="(Default)">64</Value>
16+
</Setting>
1117
</Settings>
1218
</SettingsFile>

PixelArtTool/Settings.xaml

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@
77
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="PixelArtTool.Settings"
88
mc:Ignorable="d"
99
Title="Settings" Height="330" Width="300" Background="#FF252525" Closing="Window_Closing">
10-
<Grid>
10+
<Grid>
1111
<StackPanel>
1212
<Separator Height="20" Margin="0"/>
1313
<StackPanel Orientation="Horizontal">
14-
<CheckBox Content="Show grid"/>
1514
<Label>Light Color</Label>
1615
<Rectangle x:Name="settingsLightColor" Fill="#FFFFFFFF" HorizontalAlignment="Left" Height="28" Stroke="Black" VerticalAlignment="Top" Width="28" MouseDown="settingsLightColor_MouseDown"/>
1716
<Label>Dark Color</Label>
1817
<Rectangle x:Name="settingsDarkColor" Fill="#00000000" HorizontalAlignment="Left" Height="28" Stroke="Black" VerticalAlignment="Top" Width="28" MouseDown="settingsDarkColor_MouseDown"/>
1918
</StackPanel>
20-
19+
<Label>Grid Transparency</Label>
20+
<Slider x:Name="sldGridAlpha" Maximum="255" SmallChange="1" LargeChange="10" TickFrequency="10" Value="64" AutoToolTipPlacement="TopLeft" Margin="10,10,10,0" />
21+
2122
<Separator Height="20" Margin="0"/>
2223
<Label>Default Resolution</Label>
23-
<TextBlock HorizontalAlignment="Center" FontWeight="Bold" Margin="117.07,0,133.93,0"><Run Text="{Binding Value, ElementName=sliderResolution, StringFormat=\{0:#\}}"/><Run Text=" "/><Run Text="x"/><Run Text=" "/><Run Text="{Binding Value, ElementName=sliderResolution, StringFormat=\{0:#\}}"/></TextBlock>
24-
<Slider x:Name="sliderResolution" Minimum="8" Maximum="64" SmallChange="8" TickFrequency="8" LargeChange="8" TickPlacement="Both" Value="16" AutoToolTipPlacement="TopLeft" IsSnapToTickEnabled="True" Margin="0,0,0,0"/>
24+
<TextBlock HorizontalAlignment="Center" FontWeight="Bold" Margin="0" Width="54"><Run Text="{Binding Value, ElementName=sliderResolution, StringFormat=\{0:#\}}"/><Run Text=" "/><Run Text="x"/><Run Text=" "/><Run Text="{Binding Value, ElementName=sliderResolution, StringFormat=\{0:#\}}"/></TextBlock>
25+
<Slider x:Name="sliderResolution" Minimum="8" Maximum="64" SmallChange="8" TickFrequency="8" LargeChange="8" TickPlacement="Both" Value="16" AutoToolTipPlacement="TopLeft" IsSnapToTickEnabled="True" Margin="10,0"/>
2526

2627
<Separator Height="20" Margin="0"/>
27-
<Rectangle x:Name="defaultColor" Fill="#FF000000" HorizontalAlignment="Left" Height="28" Stroke="Black" VerticalAlignment="Top" Width="28"/>
28-
<Button x:Name="okButton" IsDefault="True" Content="OK" Click="OnOkButtonClick" Margin="80,0,137,0" Height="50"/>
29-
<Button x:Name="cancelButton" IsCancel="True" Content="Cancel" Margin="0,0,217,0" Height="50"/>
28+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
29+
<Button x:Name="resetButton" HorizontalAlignment="Left" Content="Reset" ToolTip="Reset to default settings" Height="50" Width="50" Margin="0,0,25,0" Click="resetButton_Click"/>
30+
<Button x:Name="cancelButton" IsCancel="True" HorizontalAlignment="Left" Content="Cancel" Height="50" Width="50" Margin="0,0,25,0"/>
31+
<Button x:Name="okButton" IsDefault="True" Content="OK" Click="OnOkButtonClick" Height="50" Width="100" Margin="0" HorizontalAlignment="Right"/>
32+
</StackPanel>
3033
</StackPanel>
3134
</Grid>
3235
</Window>

PixelArtTool/Settings.xaml.cs

+17-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ void Start()
2222
// TODO load all current settings
2323
settingsLightColor.Fill = ConvertSystemDrawingColorToSolidColorBrush(Properties.Settings.Default.gridLightColor);
2424
settingsDarkColor.Fill = ConvertSystemDrawingColorToSolidColorBrush(Properties.Settings.Default.gridDarkColor);
25+
sldGridAlpha.Value = Properties.Settings.Default.gridAlpha;
26+
sliderResolution.Value = Properties.Settings.Default.defaultResolution;
2527
}
2628

2729
private void OnOkButtonClick(object sender, RoutedEventArgs e)
@@ -68,10 +70,21 @@ private void settingsDarkColor_MouseDown(object sender, MouseButtonEventArgs e)
6870

6971
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
7072
{
71-
// TODO save to settings
72-
Properties.Settings.Default.gridDarkColor = ConvertBrushToSystemDrawingColor(settingsDarkColor.Fill);
73-
Properties.Settings.Default.gridLightColor = ConvertBrushToSystemDrawingColor(settingsLightColor.Fill);
74-
Properties.Settings.Default.Save();
73+
if (this.DialogResult==true)
74+
{
75+
// TODO save all settings
76+
Properties.Settings.Default.gridDarkColor = ConvertBrushToSystemDrawingColor(settingsDarkColor.Fill);
77+
Properties.Settings.Default.gridLightColor = ConvertBrushToSystemDrawingColor(settingsLightColor.Fill);
78+
Properties.Settings.Default.gridAlpha = (byte)sldGridAlpha.Value;
79+
Properties.Settings.Default.defaultResolution = (byte)sliderResolution.Value;
80+
Properties.Settings.Default.Save();
81+
}
82+
}
83+
84+
private void resetButton_Click(object sender, RoutedEventArgs e)
85+
{
86+
// TODO: reset to default settings
87+
Console.WriteLine("TODO reset");
7588
}
7689
} // class
7790
}

PixelArtTool/Tools.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static int Repeat(int val, int max)
191191
return result;
192192
}
193193

194-
public static void DrawBackgroundGrid(WriteableBitmap targetBitmap, int canvasResolutionX, int canvasResolutionY, PixelColor c1, PixelColor c2)
194+
public static void DrawBackgroundGrid(WriteableBitmap targetBitmap, int canvasResolutionX, int canvasResolutionY, PixelColor c1, PixelColor c2, byte alpha)
195195
{
196196
Console.WriteLine(123);
197197
PixelColor c = new PixelColor();
@@ -205,7 +205,7 @@ public static void DrawBackgroundGrid(WriteableBitmap targetBitmap, int canvasRe
205205
// c.Red = v;
206206
// c.Green = v;
207207
// c.Blue = v;
208-
//v.Alpha = 255;
208+
v.Alpha = alpha;
209209
SetPixel(targetBitmap, x, y, (int)v.ColorBGRA);
210210
}
211211
}

0 commit comments

Comments
 (0)