Skip to content

Commit db58563

Browse files
committed
fix palette picker color index and offset, test appveyor config
1 parent 89a41ca commit db58563

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

PixelArtTool/MainWindow.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,12 @@ void PickPalette(MouseEventArgs e)
301301
{
302302
byte[] ColorData = { 0, 0, 0, 0 }; // B G R !
303303
int x = (int)(e.GetPosition(paletteImage).X / paletteScaleX);
304-
int y = (int)((e.GetPosition(paletteImage).Y - 1) / paletteScaleY); // -1 to fix offset issue
304+
int y = (int)(e.GetPosition(paletteImage).Y / paletteScaleY);
305305
if (x < 0 || x > paletteResolutionX - 1) return;
306306
if (y < 0 || y > paletteResolutionY - 1) return;
307-
currentColorIndex = y * paletteResolutionX + x + 1; // +1 for fix index magic number..
308-
if (currentColorIndex >= palette.Length) currentColorIndex--;
307+
308+
currentColorIndex = y * paletteResolutionX + x;
309+
if (currentColorIndex > palette.Length) currentColorIndex--;
309310
currentColor = palette[currentColorIndex];
310311
ResetCurrentBrightnessPreview(currentColor);
311312
}
@@ -585,6 +586,7 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
585586
// snap preview rectangle to grid
586587
var left = x * canvasScaleX;
587588
var top = y * canvasScaleX;
589+
// NOTE: this causes palette pixels to distort/move?
588590
rectPixelPos.Margin = new Thickness(89 + left, 50 + top, 0, 0);
589591

590592
} // drawingareamousemoved

PixelArtTool/Tools.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ public static Color Win32GetScreenPixel(int x, int y)
4040
return Color.FromArgb(255, (byte)((a >> 0) & 0xff), (byte)((a >> 8) & 0xff), (byte)((a >> 16) & 0xff));
4141
}
4242

43+
public static PixelColor Win32GetScreenPixelColor()
44+
{
45+
CustomPoint cursor;
46+
GetCursorPos(out cursor);
47+
IntPtr desk = GetDesktopWindow();
48+
IntPtr dc = GetWindowDC(desk);
49+
int a = (int)GetPixel(dc, cursor.X, cursor.Y);
50+
ReleaseDC(desk, dc);
51+
var c = new PixelColor();
52+
c.Alpha = 255;
53+
c.Red = (byte)((a >> 0) & 0xff);
54+
c.Green = (byte)((a >> 8) & 0xff);
55+
c.Blue = (byte)((a >> 16) & 0xff);
56+
return c;
57+
}
58+
59+
4360
// fix savefiledialog extension https://stackoverflow.com/a/6104319/5452781
4461
public static void UseDefaultExtensionAsFilterIndex(FileDialog dialog)
4562
{
@@ -95,9 +112,9 @@ public static PixelColor[] LoadPalette(string path, WriteableBitmap targetBitmap
95112
x = y = 0;
96113
for (int i = 0, len = palette.Length; i < len; i++)
97114
{
98-
SetPixel(targetBitmap, x, y, (int)palette[i].ColorBGRA);
99115
x = i % paletteResolutionX;
100116
y = (i % len) / paletteResolutionX;
117+
SetPixel(targetBitmap, x, y, (int)palette[i].ColorBGRA);
101118
}
102119

103120
return palette;

appveyor.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 1.0.{build}
2+
branches:
3+
only:
4+
- master
5+
skip_tags: true
6+
skip_branch_with_pr: true
7+
configuration: Release
8+
build:
9+
verbosity: minimal
10+
after_build:
11+
- cmd: 7z a PixelArtTool.zip %APPVEYOR_BUILD_FOLDER%\PixelArtTool\bin\Release\*.exe %APPVEYOR_BUILD_FOLDER%\PixelArtTool\bin\Release\*.exe.config
12+
artifacts:
13+
- path: PixelArtTool.zip
14+
name: deploy
15+
deploy:
16+
- provider: GitHub
17+
auth_token:
18+
secure: c/GncTkUgNJ4TT+O8brAgr1NUhL7/vcKzsB5GXMpUj1QiI0MJf/9vXJ1yVIRf8Td1OK1kJpWlRmlry7cYeWPu8JxzGihuoJyj11Us6POKDc=
19+
artifact: deploy

0 commit comments

Comments
 (0)