Skip to content

Commit

Permalink
Merge pull request #12 from Pharap/fix-colour-selection-oversight
Browse files Browse the repository at this point in the history
Fix Colour Selection Oversight
  • Loading branch information
Pharap authored Apr 28, 2022
2 parents aa04f63 + c71e986 commit 4e05727
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
9 changes: 5 additions & 4 deletions ABSpriteEditor/ABSpriteEditor/Controls/ColourSelectPanel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using ABSpriteEditor.Sprites;

//
// Copyright (C) 2022 Pharap (@Pharap)
Expand All @@ -22,7 +23,7 @@ namespace ABSpriteEditor.Controls
{
public partial class ColourSelectPanel : UserControl
{
private Color colour = Color.Black;
private Color colour = SpriteColours.Black;

public event EventHandler ColourChanged;

Expand All @@ -43,7 +44,7 @@ public Color Colour
public void SelectBlack()
{
// Set the colour
this.ChangeColour(Color.Black);
this.ChangeColour(SpriteColours.Black);

// Uncheck all colours
this.UncheckAll(this.colourToolStrip);
Expand All @@ -58,7 +59,7 @@ public void SelectBlack()
public void SelectWhite()
{
// Set the colour
this.ChangeColour(Color.White);
this.ChangeColour(SpriteColours.White);

// Uncheck all colours
this.UncheckAll(this.colourToolStrip);
Expand All @@ -73,7 +74,7 @@ public void SelectWhite()
public void SelectTransparent()
{
// Set the colour
this.ChangeColour(Color.Transparent);
this.ChangeColour(SpriteColours.Transparent);

// Uncheck all colours
this.UncheckAll(this.colourToolStrip);
Expand Down
30 changes: 30 additions & 0 deletions ABSpriteEditor/ABSpriteEditor/Sprites/SpriteColours.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace ABSpriteEditor.Sprites
{
public static class SpriteColours
{
private static readonly Color black = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
private static readonly Color white = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
private static readonly Color transparent = Color.FromArgb(0x00, 0x00, 0x00, 0x00);

public static Color Black
{
get { return black; }
}

public static Color White
{
get { return white; }
}

public static Color Transparent
{
get { return transparent; }
}
}
}
4 changes: 2 additions & 2 deletions ABSpriteEditor/ABSpriteEditor/Sprites/SpriteHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public static Bitmap CreateMonochromeTransparentCopy(Bitmap bitmap)
private static Color SimplifyColour(Color colour)
{
if(colour.A < 255)
return Color.Transparent;
return SpriteColours.Transparent;

return (Average(colour) > 127) ? Color.White : Color.Black;
return (Average(colour) > 127) ? SpriteColours.White : SpriteColours.Black;
}

// A helper function for figuring out the average value of a pixel
Expand Down

0 comments on commit 4e05727

Please sign in to comment.