|
2 | 2 | using System;
|
3 | 3 | using System.Collections.Generic;
|
4 | 4 | using System.ComponentModel;
|
5 |
| -using System.Globalization; |
6 | 5 | using System.IO;
|
7 | 6 | using System.Runtime.CompilerServices;
|
8 | 7 | using System.Runtime.InteropServices;
|
9 | 8 | using System.Windows;
|
10 | 9 | using System.Windows.Controls;
|
11 | 10 | using System.Windows.Data;
|
12 | 11 | using System.Windows.Input;
|
13 |
| -using System.Windows.Markup; |
14 | 12 | using System.Windows.Media;
|
15 | 13 | using System.Windows.Media.Imaging;
|
16 | 14 |
|
@@ -76,17 +74,16 @@ public partial class MainWindow : Window, INotifyPropertyChanged
|
76 | 74 | // modes
|
77 | 75 | BlendMode blendMode;
|
78 | 76 |
|
79 |
| - // TEST property binding |
80 |
| - private ToolMode myVar = ToolMode.Fill; |
| 77 | + private ToolMode _currentTool = ToolMode.Draw; |
81 | 78 | public ToolMode CurrentTool
|
82 | 79 | {
|
83 | 80 | get
|
84 | 81 | {
|
85 |
| - return myVar; |
| 82 | + return _currentTool; |
86 | 83 | }
|
87 | 84 | set
|
88 | 85 | {
|
89 |
| - myVar = value; |
| 86 | + _currentTool = value; |
90 | 87 | OnPropertyChanged();
|
91 | 88 | }
|
92 | 89 | }
|
@@ -157,16 +154,16 @@ void Start()
|
157 | 154 | //paletteImage.MouseRightButtonDown += new MouseButtonEventHandler(PaletteRightButtonDown);
|
158 | 155 |
|
159 | 156 | // init
|
160 |
| - LoadPalette(); |
| 157 | + LoadPalette("pack://application:,,,/Resources/Palettes/aap-64-1x.png"); |
161 | 158 | currentColorIndex = 5;
|
162 | 159 | currentColor = palette[currentColorIndex];
|
163 | 160 | UpdateCurrentColor();
|
164 | 161 | }
|
165 | 162 |
|
166 | 163 |
|
167 |
| - void LoadPalette() |
| 164 | + void LoadPalette(string path) |
168 | 165 | {
|
169 |
| - Uri uri = new Uri("pack://application:,,,/Resources/Palettes/aap-64-1x.png"); |
| 166 | + Uri uri = new Uri(path); |
170 | 167 | var img = new BitmapImage(uri);
|
171 | 168 |
|
172 | 169 | // get colors
|
@@ -699,6 +696,20 @@ void OnKeyDown(object sender, KeyEventArgs e)
|
699 | 696 | // TODO: add tool shortcut keys
|
700 | 697 | switch (e.Key)
|
701 | 698 | {
|
| 699 | + case Key.X: // swap current/secondary colors |
| 700 | + var tempcolor = rectCurrentColor.Fill; |
| 701 | + rectCurrentColor.Fill = rectSecondaryColor.Fill; |
| 702 | + rectSecondaryColor.Fill = tempcolor; |
| 703 | + // TODO move to converter |
| 704 | + var c = new PixelColor(); |
| 705 | + var t = ((SolidColorBrush)rectCurrentColor.Fill).Color; |
| 706 | + c.Red = t.R; |
| 707 | + c.Green = t.G; |
| 708 | + c.Blue = t.B; |
| 709 | + c.Alpha = t.A; |
| 710 | + currentColor = c; |
| 711 | + |
| 712 | + break; |
702 | 713 | case Key.B: // brush
|
703 | 714 | CurrentTool = ToolMode.Draw;
|
704 | 715 | break;
|
@@ -942,6 +953,41 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
942 | 953 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
943 | 954 | }
|
944 | 955 |
|
| 956 | + void BitmapFlip(bool horizontal) |
| 957 | + { |
| 958 | + // clone canvas, FIXME not really needed..could just copy pixels to array or backbuffer directly |
| 959 | + var tempCanvasBitmap = new WriteableBitmap(canvasResolutionX, canvasResolutionY, dpiX, dpiY, PixelFormats.Bgra32, null); |
| 960 | + tempCanvasBitmap = canvasBitmap.Clone(); |
| 961 | + for (int x = 0; x < canvasResolutionX; x++) |
| 962 | + { |
| 963 | + for (int y = 0; y < canvasResolutionY; y++) |
| 964 | + { |
| 965 | + int xx = horizontal ? (canvasResolutionX - x - 1) : x; |
| 966 | + int yy = !horizontal ? (canvasResolutionY - y - 1) : y; |
| 967 | + var c = GetPixelColor(xx, yy, tempCanvasBitmap); |
| 968 | + SetPixel(canvasBitmap, x, y, (int)c.ColorBGRA); |
| 969 | + } |
| 970 | + } |
| 971 | + } |
| 972 | + |
| 973 | + private void OnFlipXButtonDown(object sender, RoutedEventArgs e) |
| 974 | + { |
| 975 | + BitmapFlip(horizontal: true); |
| 976 | + } |
| 977 | + |
| 978 | + private void OnFlipYButtonDown(object sender, RoutedEventArgs e) |
| 979 | + { |
| 980 | + BitmapFlip(horizontal: false); |
| 981 | + } |
| 982 | + |
| 983 | + private void OnLoadPaletteButton(object sender, RoutedEventArgs e) |
| 984 | + { |
| 985 | + OpenFileDialog openFileDialog = new OpenFileDialog(); |
| 986 | + if (openFileDialog.ShowDialog() == true) |
| 987 | + { |
| 988 | + LoadPalette(openFileDialog.FileName); |
| 989 | + } |
| 990 | + } |
945 | 991 | } // class
|
946 | 992 |
|
947 | 993 | // https://stackoverflow.com/a/2908885/5452781
|
|
0 commit comments