1
1
using System ;
2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
+ using System . Collections . ObjectModel ;
5
+ using System . Data ;
4
6
using System . Windows ;
5
7
using System . Windows . Controls ;
6
8
using System . Windows . Media ;
@@ -10,7 +12,9 @@ namespace UnityLauncherPro
10
12
public partial class ThemeEditor : Window
11
13
{
12
14
// TODO take from mainwindow?
13
- Dictionary < string , SolidColorBrush > origResourceColors = new Dictionary < string , SolidColorBrush > ( ) ;
15
+ //Dictionary<string, SolidColorBrush> origResourceColors = new Dictionary<string, SolidColorBrush>();
16
+ //public static List<ThemeColor> themeColors;
17
+ public static ObservableCollection < ThemeColor > themeColors = new ObservableCollection < ThemeColor > ( ) ;
14
18
15
19
public ThemeEditor ( )
16
20
{
@@ -19,53 +23,71 @@ public ThemeEditor()
19
23
20
24
private void Window_Loaded ( object sender , RoutedEventArgs e )
21
25
{
26
+ themeColors . Clear ( ) ;
27
+
22
28
// get original colors
23
29
foreach ( DictionaryEntry item in Application . Current . Resources . MergedDictionaries [ 0 ] )
24
30
{
25
31
// take original colors, so can reset them
26
- origResourceColors [ item . Key . ToString ( ) ] = ( SolidColorBrush ) item . Value ;
27
- var col = ( SolidColorBrush ) item . Value ;
32
+ // origResourceColors[item.Key.ToString()] = (SolidColorBrush)item.Value;
33
+ // var col = (SolidColorBrush)item.Value;
28
34
//Console.WriteLine(item.Key.ToString() + "=" + col);
29
-
35
+ var themeColorPair = new ThemeColor ( ) ;
36
+ themeColorPair . Key = item . Key . ToString ( ) ;
37
+ themeColorPair . Brush = ( SolidColorBrush ) item . Value ;
38
+ themeColors . Add ( themeColorPair ) ;
30
39
//var col = new BrushConverter().ConvertFrom(row[1].Trim());
31
40
// apply color
32
41
//Application.Current.Resources[row[0]] = (SolidColorBrush)col;
33
42
}
34
43
35
44
// display current theme keys and values
36
- gridThemeColors . ItemsSource = origResourceColors ;
45
+ //gridThemeColors.ItemsSource = origResourceColors;
46
+ gridThemeColors . ItemsSource = themeColors ;
47
+ //gridThemeColors.DataContext = themeColors;
37
48
38
49
}
39
50
40
- string selectedKey = null ;
51
+ int selectedRow = - 1 ;
52
+ bool forceValue = false ;
41
53
42
54
private void GridThemeColors_SelectionChanged ( object sender , System . Windows . Controls . SelectionChangedEventArgs e )
43
55
{
44
56
if ( gridThemeColors . SelectedItem == null ) return ;
45
57
//Console.WriteLine(gridThemeColors.SelectedItem);
46
- var k = gridThemeColors . SelectedItem as KeyValuePair < string , SolidColorBrush > ? ;
47
- selectedKey = k . Value . Key ;
58
+ var item = gridThemeColors . SelectedItem as ThemeColor ;
59
+
60
+ //selectedRow = gridThemeColors.SelectedIndex;
61
+
62
+ //selectedKey = k.Value.Key;
48
63
//Console.WriteLine("Selected: " +selectedKey + "=" + origResourceColors[selectedKey].ToString());
49
64
50
65
// show color
51
66
// TODO show current color AND modified color next to each other
52
- rectSelectedColor . Fill = origResourceColors [ selectedKey ] ;
67
+ //rectSelectedColor.Fill = origResourceColors[selectedKey];
68
+ //var item = (string, SolidColorBrush)gridThemeColors.SelectedItem;
69
+ rectSelectedColor . Fill = item . Brush ;
53
70
54
71
//txtSelectedColorHex.Text = origResourceColors[selectedKey].ToString();
55
72
56
- sliderRed . Value = origResourceColors [ selectedKey ] . Color . R ;
57
- sliderGreen . Value = origResourceColors [ selectedKey ] . Color . G ;
58
- sliderBlue . Value = origResourceColors [ selectedKey ] . Color . B ;
59
-
73
+ forceValue = true ;
74
+ sliderRed . Value = item . Brush . Color . R ;
75
+ forceValue = true ;
76
+ sliderGreen . Value = item . Brush . Color . G ;
77
+ forceValue = true ;
78
+ sliderBlue . Value = item . Brush . Color . B ;
79
+ forceValue = true ;
80
+ sliderAlpha . Value = item . Brush . Color . A ;
81
+ forceValue = false ;
60
82
}
61
83
62
84
void UpdateColorPreview ( )
63
85
{
64
86
var newColor = new Color ( ) ;
65
- newColor . A = 255 ;
66
87
newColor . R = byte . Parse ( ( ( int ) sliderRed . Value ) . ToString ( ) ) ;
67
88
newColor . G = byte . Parse ( ( ( int ) sliderGreen . Value ) . ToString ( ) ) ;
68
89
newColor . B = byte . Parse ( ( ( int ) sliderBlue . Value ) . ToString ( ) ) ;
90
+ newColor . A = byte . Parse ( ( ( int ) sliderAlpha . Value ) . ToString ( ) ) ;
69
91
var newColorBrush = new SolidColorBrush ( newColor ) ;
70
92
rectSelectedColor . Fill = newColorBrush ;
71
93
@@ -74,34 +96,64 @@ void UpdateColorPreview()
74
96
//origResourceColors[selectedKey] = newColorBrush;
75
97
//gridThemeColors.Items.Refresh();
76
98
99
+ //DataRowView rowView = gridThemeColors.Items[ as DataRowView;
100
+ //rowView.BeginEdit();
101
+ //rowView[1] = "Change cell here";
102
+ //rowView.EndEdit();
103
+ //gridThemeColors.Items.Refresh();
104
+ //Console.WriteLine(1234);
105
+
106
+ //themeColors[gridThemeColors.SelectedIndex].Key = "asdf";
107
+ themeColors [ gridThemeColors . SelectedIndex ] . Brush = newColorBrush ;
108
+
109
+ // NOTE slow but works..
110
+ gridThemeColors . Items . Refresh ( ) ;
111
+
77
112
// TODO apply color changes to mainwindow
78
113
}
79
114
80
115
private void SliderRed_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
81
116
{
117
+ if ( forceValue == true ) return ;
82
118
// onchanged is called before other components are ready..wpf :D
83
119
if ( txtRed == null ) return ;
84
120
txtRed . Text = ( ( int ) ( ( Slider ) sender ) . Value ) . ToString ( ) ;
85
121
UpdateColorPreview ( ) ;
122
+ forceValue = false ;
86
123
}
87
124
88
125
private void SliderGreen_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
89
126
{
127
+ if ( forceValue == true ) return ;
90
128
if ( txtGreen == null ) return ;
91
129
txtGreen . Text = ( ( int ) ( ( Slider ) sender ) . Value ) . ToString ( ) ;
92
130
UpdateColorPreview ( ) ;
131
+ forceValue = false ;
93
132
}
94
133
95
134
private void SliderBlue_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
96
135
{
136
+ if ( forceValue == true ) return ;
97
137
if ( txtBlue == null ) return ;
98
138
txtBlue . Text = ( ( int ) ( ( Slider ) sender ) . Value ) . ToString ( ) ;
99
139
UpdateColorPreview ( ) ;
140
+ forceValue = false ;
141
+ }
142
+
143
+ private void SliderAlpha_ValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
144
+ {
145
+ if ( forceValue == true ) return ;
146
+ if ( txtAlpha == null ) return ;
147
+ txtAlpha . Text = ( ( int ) ( ( Slider ) sender ) . Value ) . ToString ( ) ;
148
+ UpdateColorPreview ( ) ;
149
+ forceValue = false ;
100
150
}
101
151
102
152
private void BtnSaveTheme_Click ( object sender , RoutedEventArgs e )
103
153
{
104
154
Console . WriteLine ( "TODO save theme to file.." ) ;
105
155
}
156
+
157
+
106
158
}
107
159
}
0 commit comments