Skip to content

Commit 1c1a862

Browse files
authored
Merge pull request #41 from Pharap/add-invert-action
Add Invert Action
2 parents abca710 + adde66b commit 1c1a862

File tree

8 files changed

+97
-1
lines changed

8 files changed

+97
-1
lines changed

ABSpriteEditor/ABSpriteEditor/ABSpriteEditor.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@
367367
</ItemGroup>
368368
<ItemGroup>
369369
<Content Include="FrameIcon.ico" />
370+
<None Include="Resources\UI\SpriteEditor\Actions\InvertIcon32.png" />
371+
<None Include="Resources\UI\SpriteEditor\Actions\InvertIcon16.png" />
370372
<None Include="Resources\UI\SpriteEditor\Actions\NudgeUp32.png" />
371373
<None Include="Resources\UI\SpriteEditor\Actions\NudgeUp16.png" />
372374
<None Include="Resources\UI\SpriteEditor\Actions\NudgeRight32.png" />

ABSpriteEditor/ABSpriteEditor/Controls/ActionPanel.Designer.cs

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

ABSpriteEditor/ABSpriteEditor/Controls/ActionPanel.cs

+22
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ public void RollDown()
196196
this.OnAfterAction(EventArgs.Empty);
197197
}
198198

199+
public void Invert()
200+
{
201+
// If there is no image
202+
if (this.Image == null)
203+
// Exit early
204+
return;
205+
206+
// Raise before action event
207+
this.OnBeforeAction(EventArgs.Empty);
208+
209+
// Invert the image
210+
BitmapHelper.Invert(this.Image);
211+
212+
// Raise after action event
213+
this.OnAfterAction(EventArgs.Empty);
214+
}
215+
199216
#endregion
200217

201218
#region Event Handlers
@@ -279,6 +296,11 @@ private void rollDownToolStripButton_Click(object sender, EventArgs e)
279296
this.RollDown();
280297
}
281298

299+
private void invertToolStripButton_Click(object sender, EventArgs e)
300+
{
301+
this.Invert();
302+
}
303+
282304
#endregion
283305
}
284306
}

ABSpriteEditor/ABSpriteEditor/Properties/Resources.Designer.cs

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

ABSpriteEditor/ABSpriteEditor/Properties/Resources.resx

+6
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,10 @@
382382
<data name="NudgeUp32" type="System.Resources.ResXFileRef, System.Windows.Forms">
383383
<value>..\Resources\UI\SpriteEditor\Actions\NudgeUp32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
384384
</data>
385+
<data name="InvertIcon16" type="System.Resources.ResXFileRef, System.Windows.Forms">
386+
<value>..\Resources\UI\SpriteEditor\Actions\InvertIcon16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
387+
</data>
388+
<data name="InvertIcon32" type="System.Resources.ResXFileRef, System.Windows.Forms">
389+
<value>..\Resources\UI\SpriteEditor\Actions\InvertIcon32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
390+
</data>
385391
</root>
Loading
Loading

ABSpriteEditor/ABSpriteEditor/Utilities/BitmapHelper.cs

+28
Original file line numberDiff line numberDiff line change
@@ -642,5 +642,33 @@ private static void FloodFill(Bitmap bitmap, Point point, Color fillColour, Colo
642642
}
643643

644644
#endregion
645+
646+
#region Inversion
647+
648+
public static Color Invert(Color colour)
649+
{
650+
var alpha = colour.A;
651+
var red = (byte.MaxValue - colour.R);
652+
var green = (byte.MaxValue - colour.G);
653+
var blue = (byte.MaxValue - colour.B);
654+
655+
return Color.FromArgb(alpha, red, green, blue);
656+
}
657+
658+
public static void Invert(Bitmap bitmap)
659+
{
660+
// Iterate through all pixels of the bitmap
661+
for (int y = 0; y < bitmap.Height; ++y)
662+
for (int x = 0; x < bitmap.Width; ++x)
663+
{
664+
// Retrieve the value of the current pixe
665+
var colour = bitmap.GetPixel(x, y);
666+
667+
// Set the current pixel to the inverse of the retrieved value
668+
bitmap.SetPixel(x, y, Invert(colour));
669+
}
670+
}
671+
672+
#endregion
645673
}
646674
}

0 commit comments

Comments
 (0)