Skip to content

Commit 0a09705

Browse files
Palette (#8)
* Colorpicker * VS Cleanup * Current palette set * VS Cleanup * Right panel in scrollbar * Update readme * Palete button icons * Palette commands without IO; Tab size stretch * Palettes IO * Palette list button; Empty PaletteWindow * Palette selection * Palette rename
1 parent aebc99f commit 0a09705

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1296
-229
lines changed

Pixed.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.11.35208.52
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pixed", "Pixed\Pixed.csproj", "{CE3A10C1-6BEB-4A34-9CED-0542EA04D6BB}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pixed", "Pixed\Pixed.csproj", "{CE3A10C1-6BEB-4A34-9CED-0542EA04D6BB}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Pixed/ActionCommand.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace Pixed
55
internal class ActionCommand<T> : ICommand
66
{
77
#region Fields
8-
private readonly Action<T> action;
8+
private readonly Action<T> _action;
99
#endregion
1010
#region Events
1111
public event EventHandler? CanExecuteChanged;
1212
#endregion
1313
#region Constructors
1414
public ActionCommand(Action<T> action)
1515
{
16-
this.action = action;
16+
this._action = action;
1717
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
1818
}
1919

@@ -31,28 +31,28 @@ public void Execute(object? parameter)
3131
return;
3232
}
3333

34-
action?.Invoke((T)parameter);
34+
_action?.Invoke((T)parameter);
3535
}
3636

3737
public void Execute(T parameter)
3838
{
39-
action?.Invoke(parameter);
39+
_action?.Invoke(parameter);
4040
}
4141
#endregion
4242
}
4343

4444
internal class ActionCommand : ICommand
4545
{
4646
#region Fields
47-
private readonly Action action;
47+
private readonly Action _action;
4848
#endregion
4949
#region Events
5050
public event EventHandler? CanExecuteChanged;
5151
#endregion
5252
#region Constructors
5353
public ActionCommand(Action action)
5454
{
55-
this.action = action;
55+
this._action = action;
5656
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
5757
}
5858

@@ -70,7 +70,43 @@ public void Execute(object? parameter)
7070

7171
public void Execute()
7272
{
73-
action?.Invoke();
73+
_action?.Invoke();
74+
}
75+
#endregion
76+
}
77+
78+
internal class StaticActionCommand<T> : ICommand
79+
{
80+
#region Fields
81+
private readonly Action<T> _action;
82+
private readonly T _parameter;
83+
#endregion
84+
#region Events
85+
public event EventHandler? CanExecuteChanged;
86+
#endregion
87+
#region Constructors
88+
public StaticActionCommand(Action<T> action, T param)
89+
{
90+
this._action = action;
91+
_parameter = param;
92+
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
93+
}
94+
95+
#endregion
96+
#region Public Methods
97+
public bool CanExecute(object? parameter)
98+
{
99+
return true;
100+
}
101+
102+
public void Execute(object? parameter)
103+
{
104+
Execute();
105+
}
106+
107+
public void Execute()
108+
{
109+
_action?.Invoke(_parameter);
74110
}
75111
#endregion
76112
}

Pixed/App.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
xmlns:local="clr-namespace:Pixed"
55
StartupUri="MainWindow.xaml">
66
<Application.Resources>
7-
<ResourceDictionary Source="Styles.xaml"/>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Styles.xaml"/>
10+
<ResourceDictionary Source="pack://application:,,,/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
813
</Application.Resources>
914
</Application>

Pixed/Constants.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Drawing;
2-
3-
namespace Pixed
1+
namespace Pixed
42
{
53
internal static class Constants
64
{

Pixed/Controls/ColorGrid.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<UserControl x:Class="Pixed.Controls.ColorGrid"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Pixed.Controls"
7+
mc:Ignorable="d"
8+
d:DesignHeight="450" d:DesignWidth="800">
9+
<StackPanel Name="colorStack" MinHeight="30">
10+
11+
</StackPanel>
12+
</UserControl>

Pixed/Controls/ColorGrid.xaml.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Collections.ObjectModel;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using System.Windows.Media;
5+
6+
namespace Pixed.Controls
7+
{
8+
/// <summary>
9+
/// Interaction logic for ColorGrid.xaml
10+
/// </summary>
11+
public partial class ColorGrid : UserControl
12+
{
13+
public int Columns
14+
{
15+
get { return (int)GetValue(ColumnsProperty); }
16+
set { SetValue(ColumnsProperty, value); }
17+
}
18+
19+
internal ObservableCollection<UniColor> Colors
20+
{
21+
get { return (ObservableCollection<UniColor>)GetValue(ColorsProperty); }
22+
set { SetValue(ColorsProperty, value); }
23+
}
24+
25+
public static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register("Columns", typeof(int), typeof(ColorGrid), new PropertyMetadata(1));
26+
public static readonly DependencyProperty ColorsProperty = DependencyProperty.Register("Colors", typeof(ObservableCollection<UniColor>), typeof(ColorGrid), new PropertyMetadata(new ObservableCollection<UniColor>(), OnColorsChanged));
27+
public ColorGrid()
28+
{
29+
InitializeComponent();
30+
}
31+
32+
private void RefreshControls()
33+
{
34+
colorStack.Children.Clear();
35+
36+
int gridCount = (int)Math.Ceiling((double)Colors.Count / (double)Columns);
37+
int colorIndex = 0;
38+
39+
for (int g = 0; g < gridCount; g++)
40+
{
41+
Grid grid = new();
42+
grid.Height = 30;
43+
44+
for (int a = 0; a < Columns; a++)
45+
{
46+
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
47+
}
48+
49+
for (int a = 0; a < Columns; a++)
50+
{
51+
if (colorIndex >= Colors.Count)
52+
{
53+
break;
54+
}
55+
56+
Button colorButton = new Button();
57+
colorButton.BorderBrush = new SolidColorBrush(Colors[colorIndex]);
58+
colorButton.Background = new SolidColorBrush(Colors[colorIndex]);
59+
colorButton.Command = new ActionCommand<UniColor>(Subjects.PrimaryColorChange.OnNext);
60+
colorButton.CommandParameter = Colors[colorIndex];
61+
colorButton.Width = 30;
62+
colorButton.Height = 30;
63+
Grid.SetColumn(colorButton, a);
64+
65+
grid.Children.Add(colorButton);
66+
colorIndex++;
67+
}
68+
69+
colorStack.Children.Add(grid);
70+
}
71+
}
72+
73+
private static void OnColorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
74+
{
75+
if (e.NewValue == null)
76+
{
77+
return;
78+
}
79+
var grid = (ColorGrid)d;
80+
grid.RefreshControls();
81+
}
82+
}
83+
}

Pixed/Converters/TabSizeConverter.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows.Controls;
7+
using System.Windows.Data;
8+
9+
namespace Pixed.Converters
10+
{
11+
public class TabSizeConverter : IMultiValueConverter
12+
{
13+
public object Convert(object[] values, Type targetType, object parameter,
14+
System.Globalization.CultureInfo culture)
15+
{
16+
TabControl tabControl = values[0] as TabControl;
17+
double width = tabControl.ActualWidth / tabControl.Items.Count;
18+
return (width <= 1) ? 0 : (width - tabControl.Items.Count);
19+
}
20+
21+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
22+
System.Globalization.CultureInfo culture)
23+
{
24+
throw new NotSupportedException();
25+
}
26+
}
27+
}

Pixed/Global.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using Pixed.Models;
22
using Pixed.Selection;
33
using Pixed.Services.Keyboard;
4+
using Pixed.Services.Palette;
45
using Pixed.Tools;
56

67
namespace Pixed
78
{
89
internal static class Global
910
{
11+
public static string DataFolder { get; set; }
1012
public static ShortcutService? ShortcutService { get; set; }
13+
public static PaletteService? PaletteService { get; set; }
1114
public static SelectionManager? SelectionManager { get; set; }
1215
public static Settings UserSettings { get; set; } = new Settings();
1316
public static BaseTool ToolSelected { get; set; }
@@ -19,5 +22,7 @@ internal static class Global
1922
public static Frame CurrentFrame => CurrentModel.Frames[CurrentFrameIndex];
2023
public static Layer CurrentLayer => CurrentFrame.Layers[CurrentLayerIndex];
2124
public static ToolSelector ToolSelector { get; set; }
25+
public static UniColor PrimaryColor { get; set; }
26+
public static UniColor SecondaryColor { get; set; }
2227
}
2328
}

0 commit comments

Comments
 (0)