Skip to content

Commit ac8beaa

Browse files
committed
add indicator line for current lightness pos
1 parent 28367a0 commit ac8beaa

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

PixelArtTool/MainWindow.xaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,17 @@
210210
<Rectangle x:Name="tempRect" Width="200" Height="200" Margin="459,130,0,0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" Fill="Black" />
211211
<Rectangle x:Name="rectSaturation" Fill="{StaticResource LevelSaturationBrush}" Width="200" Height="200" Margin="459,130,0,0" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDown="OnLevelSaturationMouseDown" />
212212
<Rectangle x:Name="rectHueBar" Fill="{StaticResource HueBrush}" Width="20" Height="200" Margin="664,130,0,0" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" MouseDown="rectHueBar_MouseDown" HorizontalAlignment="Left" VerticalAlignment="Top" />
213-
<Rectangle x:Name="rectCurrentHue" Width="253" Height="14" Margin="91,316,0,0" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" >
214-
<Rectangle.Fill>
215-
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
216-
<GradientStop Color="Black" Offset="0"/>
217-
<GradientStop Color="White" Offset="1"/>
218-
</LinearGradientBrush>
219-
</Rectangle.Fill>
220-
</Rectangle>
213+
<Grid>
214+
<Rectangle x:Name="rectCurrentHue" Width="253" Height="14" Margin="91,316,0,0" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" >
215+
<Rectangle.Fill>
216+
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
217+
<GradientStop Color="Black" Offset="0"/>
218+
<GradientStop Color="White" Offset="1"/>
219+
</LinearGradientBrush>
220+
</Rectangle.Fill>
221+
</Rectangle>
222+
<Line x:Name="lineCurrentHueLine" X1="91" Y1="312" X2="91" Y2="334" Stroke="Red" StrokeThickness="1" />
223+
</Grid>
221224

222225
</Grid>
223226
</Window>

PixelArtTool/MainWindow.xaml.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged
4343
// colors
4444
PixelColor currentColor;
4545
PixelColor[] palette;
46+
4647
int currentColorIndex = 0;
4748
byte opacity = 255;
4849

@@ -176,8 +177,8 @@ void Start()
176177
palette = LoadPalette("pack://application:,,,/Resources/Palettes/aap-64-1x.png", paletteBitmap, paletteResolutionX, paletteResolutionY);
177178
currentColorIndex = 5;
178179
currentColor = palette[currentColorIndex];
179-
SetRectangleFillColor(rectCurrentColor, currentColor);
180-
UpdateCurrentHue(currentColor);
180+
SetCurrentColorPreviewBox(rectCurrentColor, currentColor);
181+
ResetCurrentBrightnessPreview(currentColor);
181182
}
182183

183184

@@ -318,11 +319,11 @@ void PickPalette(MouseEventArgs e)
318319
currentColorIndex = y * paletteResolutionX + x + 1; // +1 for fix index magic number..
319320
currentColor = palette[currentColorIndex];
320321

321-
UpdateCurrentHue(currentColor);
322+
ResetCurrentBrightnessPreview(currentColor);
322323
}
323324

324325
LinearGradientBrush myBrush;
325-
void UpdateCurrentHue(PixelColor c)
326+
void ResetCurrentBrightnessPreview(PixelColor c)
326327
{
327328
hueLocation = 0.5;
328329

@@ -357,8 +358,9 @@ void UpdateCurrentHue(PixelColor c)
357358

358359
rectCurrentHue.Fill = myBrush;
359360

360-
//myBrush.GradientStops
361-
361+
// move hueline
362+
int offset = (int)(hueLocation * 253);
363+
lineCurrentHueLine.Margin = new Thickness(offset, 0, offset, 0);
362364
}
363365

364366
// https://stackoverflow.com/a/39450207/5452781
@@ -424,7 +426,8 @@ unsafe PixelColor GetPixelColor(int x, int y, WriteableBitmap source)
424426
void PaletteLeftButtonDown(object sender, MouseButtonEventArgs e)
425427
{
426428
PickPalette(e);
427-
SetRectangleFillColor(rectCurrentColor, currentColor);
429+
SetCurrentColorPreviewBox(rectCurrentColor, currentColor);
430+
ResetCurrentBrightnessPreview(currentColor);
428431
}
429432

430433
void DrawingRightButtonDown(object sender, MouseButtonEventArgs e)
@@ -440,8 +443,8 @@ void DrawingMiddleButtonDown(object sender, MouseButtonEventArgs e)
440443
int y = (int)(e.GetPosition(drawingImage).Y / canvasScaleX);
441444

442445
currentColor = GetPixel(x, y);
443-
SetRectangleFillColor(rectCurrentColor, currentColor);
444-
UpdateCurrentHue(currentColor);
446+
SetCurrentColorPreviewBox(rectCurrentColor, currentColor);
447+
ResetCurrentBrightnessPreview(currentColor);
445448
}
446449
}
447450

@@ -526,7 +529,7 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
526529
else if (e.MiddleButton == MouseButtonState.Pressed)
527530
{
528531
currentColor = GetPixel(x, y);
529-
UpdateCurrentHue(currentColor);
532+
ResetCurrentBrightnessPreview(currentColor);
530533
}
531534

532535
ShowMousePos(x, y);
@@ -586,7 +589,12 @@ void DrawingMouseWheel(object sender, MouseWheelEventArgs e)
586589
cc.Blue = c.B;
587590
cc.Alpha = 255;
588591
currentColor = cc;
589-
SetRectangleFillColor(rectCurrentColor, currentColor);
592+
SetCurrentColorPreviewBox(rectCurrentColor, currentColor);
593+
//ResetCurrentBrightnessPreview(currentColor);
594+
595+
// move hueline
596+
int offset = (int)(hueLocation * 253);
597+
lineCurrentHueLine.Margin = new Thickness(offset, 0, offset, 0);
590598
}
591599

592600
private void OnClearButton(object sender, RoutedEventArgs e)
@@ -999,7 +1007,7 @@ private void OnLevelSaturationMouseDown(object sender, MouseButtonEventArgs e)
9991007
c2.Blue = c1.B;
10001008
currentColor = c2;
10011009
rectCurrentColor.Fill = new SolidColorBrush(Color.FromArgb(c2.Alpha, c2.Red, c2.Green, c2.Blue));
1002-
UpdateCurrentHue(currentColor);
1010+
ResetCurrentBrightnessPreview(currentColor);
10031011
}
10041012
} // class
10051013

PixelArtTool/Tools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static void ClearImage(WriteableBitmap targetBitmap, Int32Rect emptyRect,
153153
targetBitmap.WritePixels(emptyRect, emptyPixels, emptyStride, 0);
154154
}
155155

156-
public static void SetRectangleFillColor(Rectangle targetRectangle, PixelColor color)
156+
public static void SetCurrentColorPreviewBox(Rectangle targetRectangle, PixelColor color)
157157
{
158158
var col = Color.FromArgb(color.Alpha, color.Red, color.Green, color.Blue);
159159
targetRectangle.Fill = new SolidColorBrush(col);

0 commit comments

Comments
 (0)