Add the initial floor lighting button in the UI.

This also refactors the panel button code to rely less on WPF bindings.
They just get in the way for anything nontrivial.  Doing it this way
lets us treat the panel buttons as an interface for setting colors, to
handle the different fields that are set for the panel colors and floor
color.
master
Glenn Maynard 6 years ago
parent 84c467a485
commit 9ae9a506c6
  1. 16
      smx-config/DiagnosticsWidgets.cs
  2. 76
      smx-config/MainWindow.xaml
  3. 90
      smx-config/MainWindow.xaml.cs
  4. 287
      smx-config/Widgets.cs

@ -9,6 +9,22 @@ namespace smx_config
{ {
public class DiagnosticsPanelButton: PanelSelectButton public class DiagnosticsPanelButton: PanelSelectButton
{ {
public static readonly DependencyProperty PanelProperty = DependencyProperty.RegisterAttached("Panel",
typeof(int), typeof(PanelSelectButton), new FrameworkPropertyMetadata(0));
public int Panel {
get { return (int) this.GetValue(PanelProperty); }
set { this.SetValue(PanelProperty, value); }
}
// Which panel is currently selected.
public static readonly DependencyProperty SelectedPanelProperty = DependencyProperty.RegisterAttached("SelectedPanel",
typeof(int), typeof(PanelSelectButton), new FrameworkPropertyMetadata(0));
public int SelectedPanel {
get { return (int) this.GetValue(SelectedPanelProperty); }
set { this.SetValue(SelectedPanelProperty, value); }
}
// True if this panel is being pressed. // True if this panel is being pressed.
public static readonly DependencyProperty PressedProperty = DependencyProperty.Register("Pressed", public static readonly DependencyProperty PressedProperty = DependencyProperty.Register("Pressed",
typeof(bool), typeof(DiagnosticsPanelButton), new FrameworkPropertyMetadata(false)); typeof(bool), typeof(DiagnosticsPanelButton), new FrameworkPropertyMetadata(false));

@ -289,8 +289,7 @@ Use if the platform is too sensitive.</clr:String>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type controls:ColorButton}">
<Style TargetType="{x:Type controls:PanelColorButton}">
<Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Width" Value="25" /> <Setter Property="Width" Value="25" />
<Setter Property="AllowDrop" Value="True" /> <Setter Property="AllowDrop" Value="True" />
@ -304,7 +303,7 @@ Use if the platform is too sensitive.</clr:String>
<Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type controls:PanelColorButton}"> <ControlTemplate TargetType="{x:Type controls:ColorButton}">
<Border x:Name="border" <Border x:Name="border"
Background="{TemplateBinding PanelColor}" Background="{TemplateBinding PanelColor}"
BorderBrush="#000000" BorderThickness="1" SnapsToDevicePixels="true"> BorderBrush="#000000" BorderThickness="1" SnapsToDevicePixels="true">
@ -328,6 +327,16 @@ Use if the platform is too sensitive.</clr:String>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type controls:PanelColorButton}"
BasedOn="{StaticResource {x:Type controls:ColorButton}}">
</Style>
<Style TargetType="{x:Type controls:FloorColorButton}"
BasedOn="{StaticResource {x:Type controls:ColorButton}}">
<Setter Property="Width" Value="100" />
</Style>
<Style TargetType="{x:Type controls:ColorPicker}"> <Style TargetType="{x:Type controls:ColorPicker}">
<Setter Property="Template"> <Setter Property="Template">
@ -728,38 +737,43 @@ Use if the platform is too sensitive.</clr:String>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<!-- The duplication here could be factored out, but with WPF it's not really worth it: --> <!-- The duplication here could be factored out, but with WPF it's not really worth it: -->
<Grid x:Name="PanelColorP1" Background="#FFE5E5E5" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Top"> <StackPanel x:Name="PanelColorP1" Orientation="Vertical">
<controls:PanelColorButton Panel="0" Content="↖" Margin="-60,-50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <Grid Width="100" Height="100">
<controls:PanelColorButton Panel="1" Content="↑" Margin="0,-50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P1_0" Panel="0" Content="↖" Margin="-60,-50,0,0" />
<controls:PanelColorButton Panel="2" Content="↗" Margin="60,-50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P1_1" Panel="1" Content="↑" Margin="0,-50,0,0" />
<controls:PanelColorButton x:Name="P1_2" Panel="2" Content="↗" Margin="60,-50,0,0" />
<controls:PanelColorButton Panel="3" Content="←" Margin="-60,0,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" />
<controls:PanelColorButton Panel="4" Content="☐" Margin="0,0,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P1_3" Panel="3" Content="←" Margin="-60,0,0,0" />
<controls:PanelColorButton Panel="5" Content="→" Margin="60,0,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P1_4" Panel="4" Content="☐" Margin="0,0,0,0" />
<controls:PanelColorButton x:Name="P1_5" Panel="5" Content="→" Margin="60,0,0,0" />
<controls:PanelColorButton Panel="6" Content="↙" Margin="-60,50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" />
<controls:PanelColorButton Panel="7" Content="↓" Margin="0,50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P1_6" Panel="6" Content="↙" Margin="-60,50,0,0" />
<controls:PanelColorButton Panel="8" Content="↘" Margin="60,50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P1_7" Panel="7" Content="↓" Margin="0,50,0,0" />
</Grid> <controls:PanelColorButton x:Name="P1_8" Panel="8" Content="↘" Margin="60,50,0,0" />
</Grid>
<Grid x:Name="PanelColorP2" Background="#FFE5E5E5" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Top"> <controls:FloorColorButton x:Name="P1_Floor" Pad="0" Content="=" Margin="0,0,0,0" />
<controls:PanelColorButton Panel="9" Content="↖" Margin="-60,-50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> </StackPanel>
<controls:PanelColorButton Panel="10" Content="↑" Margin="0,-50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" />
<controls:PanelColorButton Panel="11" Content="↗" Margin="60,-50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <StackPanel x:Name="PanelColorP2" Orientation="Vertical">
<Grid Width="100" Height="100">
<controls:PanelColorButton Panel="12" Content="←" Margin="-60,0,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P2_0" Panel="9" Content="↖" Margin="-60,-50,0,0" />
<controls:PanelColorButton Panel="13" Content="☐" Margin="0,0,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P2_1" Panel="10" Content="↑" Margin="0,-50,0,0" />
<controls:PanelColorButton Panel="14" Content="→" Margin="60,0,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P2_2" Panel="11" Content="↗" Margin="60,-50,0,0" />
<controls:PanelColorButton Panel="15" Content="↙" Margin="-60,50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P2_3" Panel="12" Content="←" Margin="-60,0,0,0" />
<controls:PanelColorButton Panel="16" Content="↓" Margin="0,50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P2_4" Panel="13" Content="☐" Margin="0,0,0,0" />
<controls:PanelColorButton Panel="17" Content="↘" Margin="60,50,0,0" SelectedPanel="{Binding Path=SelectedPanel, Mode=TwoWay, ElementName=AutoLightsColor}" /> <controls:PanelColorButton x:Name="P2_5" Panel="14" Content="→" Margin="60,0,0,0" />
</Grid>
<controls:PanelColorButton x:Name="P2_6" Panel="15" Content="↙" Margin="-60,50,0,0" />
<controls:PanelColorButton x:Name="P2_7" Panel="16" Content="↓" Margin="0,50,0,0" />
<controls:PanelColorButton x:Name="P2_8" Panel="17" Content="↘" Margin="60,50,0,0" />
</Grid>
<controls:FloorColorButton x:Name="P2_Floor" Pad="1" Content="=" Margin="0,0,0,10" />
</StackPanel>
</StackPanel> </StackPanel>
<controls:ColorPicker <controls:ColorPicker
x:Name="AutoLightsColor" Focusable="false" x:Name="AutoLightsColor" Focusable="false"
controls:ColorPicker.SelectedPanel="0"
/> />
<Button x:Name="SetAllPanelsToCurrentColor" Content="Set all panels to this color" HorizontalAlignment="Center" Padding="6,2" Margin="0,6,0,0" /> <Button x:Name="SetAllPanelsToCurrentColor" Content="Set all panels to this color" HorizontalAlignment="Center" Padding="6,2" Margin="0,6,0,0" />

@ -3,6 +3,7 @@ using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
namespace smx_config namespace smx_config
{ {
@ -96,33 +97,34 @@ namespace smx_config
SetAllPanelsToCurrentColor.Click += delegate(object sender, RoutedEventArgs e) SetAllPanelsToCurrentColor.Click += delegate(object sender, RoutedEventArgs e)
{ {
int SelectedPanel = AutoLightsColor.SelectedPanel % 9; // Get the color of the selected color button, and apply it to all other buttons.
int SelectedPad = AutoLightsColor.SelectedPanel < 9? 0:1; Color color = selectedButton.getColor();
// Get the color of the selected pad. ColorButton[] colorButtons = getColorPickerButtons();
SMX.SMXConfig copyFromConfig; foreach(ColorButton button in colorButtons)
if(!SMX.SMX.GetConfig(SelectedPad, out copyFromConfig))
return;
// Don't use ActivePad.ActivePads here, since the lights UI handles multiple pads on its own.
for(int pad = 0; pad < 2; ++pad)
{ {
SMX.SMXConfig config; // Only apply this to panel colors, not the floor color.
if(!SMX.SMX.GetConfig(pad, out config)) if((button as PanelColorButton) == null)
continue; continue;
// Set all stepColors to the color of the selected panel. button.setColor(color);
for(int i = 0; i < 9; ++i)
{
config.stepColor[i*3+0] = copyFromConfig.stepColor[SelectedPanel*3+0];
config.stepColor[i*3+1] = copyFromConfig.stepColor[SelectedPanel*3+1];
config.stepColor[i*3+2] = copyFromConfig.stepColor[SelectedPanel*3+2];
}
SMX.SMX.SetConfig(pad, config);
} }
CurrentSMXDevice.singleton.FireConfigurationChanged(null); CurrentSMXDevice.singleton.FireConfigurationChanged(null);
}; };
// Listen to clicks on the panel color buttons.
ColorButton[] buttons = getColorPickerButtons();
foreach(ColorButton button in buttons)
{
button.Click += delegate(object sender, RoutedEventArgs e)
{
ColorButton clickedButton = sender as ColorButton;
selectedButton = clickedButton;
RefreshSelectedColorPicker();
};
}
} }
private void PressedColorModeButton(object sender, RoutedEventArgs e) private void PressedColorModeButton(object sender, RoutedEventArgs e)
@ -177,6 +179,7 @@ namespace smx_config
RefreshConnectedPadList(args); RefreshConnectedPadList(args);
RefreshUploadPadText(args); RefreshUploadPadText(args);
RefreshSelectedColorPicker();
// If a second controller has connected and we're on Both, see if we need to prompt // If a second controller has connected and we're on Both, see if we need to prompt
// to sync configs. We only actually need to do this if a controller just connected. // to sync configs. We only actually need to do this if a controller just connected.
@ -184,6 +187,53 @@ namespace smx_config
CheckConfiguringBothPads(args); CheckConfiguringBothPads(args);
} }
ColorButton selectedButton;
// Return all color picker buttons.
ColorButton[] getColorPickerButtons()
{
return new ColorButton[] {
P1_0, P1_1, P1_2,
P1_3, P1_4, P1_5,
P1_6, P1_7, P1_8,
P1_Floor,
P2_0, P2_1, P2_2,
P2_3, P2_4, P2_5,
P2_6, P2_7, P2_8,
P2_Floor,
};
}
// Update the selected color picker based on the value of selectedButton.
private void RefreshSelectedColorPicker()
{
LoadFromConfigDelegateArgs args = CurrentSMXDevice.singleton.GetState();
ColorButton[] buttons = getColorPickerButtons();
// If our selected button isn't enabled (or no button is selected), try to select a
// different one.
if(selectedButton == null || !selectedButton.isEnabled(args))
{
foreach(ColorButton button in buttons)
{
if(button.isEnabled(args))
{
selectedButton = button;
break;
}
}
}
// Tell the buttons which one is selected.
foreach(ColorButton button in buttons)
button.IsSelected = button == selectedButton;
// Tell the color slider which button is selected.
AutoLightsColor.colorButton = selectedButton;
}
// Update which of the "Leave this application running", etc. blocks to display. // Update which of the "Leave this application running", etc. blocks to display.
private void RefreshUploadPadText(LoadFromConfigDelegateArgs args) private void RefreshUploadPadText(LoadFromConfigDelegateArgs args)
{ {

@ -431,26 +431,7 @@ namespace smx_config
// A base class for buttons used to select a panel to work with. // A base class for buttons used to select a panel to work with.
public class PanelSelectButton: Button public class PanelSelectButton: Button
{ {
// Which panel this is (P1 0-8, P2 9-17): // Whether this button is selected.
public static readonly DependencyProperty PanelProperty = DependencyProperty.RegisterAttached("Panel",
typeof(int), typeof(PanelSelectButton), new FrameworkPropertyMetadata(0, RefreshIsSelectedCallback));
public int Panel {
get { return (int) this.GetValue(PanelProperty); }
set { this.SetValue(PanelProperty, value); }
}
// Which panel is currently selected. If this == Panel, this panel is selected. This is
// bound to ColorPicker.SelectedPanel, so changing this changes which panel the picker edits.
public static readonly DependencyProperty SelectedPanelProperty = DependencyProperty.RegisterAttached("SelectedPanel",
typeof(int), typeof(PanelSelectButton), new FrameworkPropertyMetadata(0, RefreshIsSelectedCallback));
public int SelectedPanel {
get { return (int) this.GetValue(SelectedPanelProperty); }
set { this.SetValue(SelectedPanelProperty, value); }
}
// Whether this panel is selected. This is true if Panel == SelectedPanel.
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.RegisterAttached("IsSelected", public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.RegisterAttached("IsSelected",
typeof(bool), typeof(PanelSelectButton), new FrameworkPropertyMetadata(false)); typeof(bool), typeof(PanelSelectButton), new FrameworkPropertyMetadata(false));
@ -458,89 +439,49 @@ namespace smx_config
get { return (bool) this.GetValue(IsSelectedProperty); } get { return (bool) this.GetValue(IsSelectedProperty); }
set { this.SetValue(IsSelectedProperty, value); } set { this.SetValue(IsSelectedProperty, value); }
} }
// When Panel or SelectedPanel change, update IsSelected.
private static void RefreshIsSelectedCallback(DependencyObject target, DependencyPropertyChangedEventArgs args)
{
PanelSelectButton self = target as PanelSelectButton;
self.RefreshIsSelected();
}
private void RefreshIsSelected()
{
IsSelected = Panel == SelectedPanel;
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
RefreshIsSelected();
}
} }
// This button shows the color configured for that panel, and chooses which color is being // A button that selects which color is being set.
// edited by the ColorPicker. public abstract class ColorButton: PanelSelectButton
public class PanelColorButton: PanelSelectButton
{ {
// The color configured for this panel: // The color configured for this panel:
public static readonly DependencyProperty PanelColorProperty = DependencyProperty.RegisterAttached("PanelColor", public static readonly DependencyProperty PanelColorProperty = DependencyProperty.RegisterAttached("PanelColor",
typeof(SolidColorBrush), typeof(PanelColorButton), new FrameworkPropertyMetadata(new SolidColorBrush())); typeof(SolidColorBrush), typeof(ColorButton), new FrameworkPropertyMetadata(new SolidColorBrush()));
public SolidColorBrush PanelColor { public SolidColorBrush PanelColor {
get { return (SolidColorBrush) this.GetValue(PanelColorProperty); } get { return (SolidColorBrush) this.GetValue(PanelColorProperty); }
set { this.SetValue(PanelColorProperty, value); } set { this.SetValue(PanelColorProperty, value); }
} }
// Return 0 if this is for the P1 pad, or 1 if it's for P2.
protected abstract int getPadNo();
// Return true if this panel is enabled and should be selectable.
public abstract bool isEnabled(LoadFromConfigDelegateArgs args);
// Get and set our color to the pad configuration.
abstract public Color getColor();
abstract public void setColor(Color color);
public override void OnApplyTemplate() public override void OnApplyTemplate()
{ {
base.OnApplyTemplate(); base.OnApplyTemplate();
OnConfigChange onConfigChange; OnConfigChange onConfigChange;
onConfigChange = new OnConfigChange(this, delegate (LoadFromConfigDelegateArgs args) { onConfigChange = new OnConfigChange(this, delegate (LoadFromConfigDelegateArgs args) {
int pad = Panel < 9? 0:1; LoadUIFromConfig(args);
LoadUIFromConfig(args.controller[pad].config);
}); });
} }
protected override void OnClick()
{
base.OnClick();
// Select this panel.
SelectedPanel = Panel;
// Fire configuration changed, so the color slider updates to show this panel.
CurrentSMXDevice.singleton.FireConfigurationChanged(this);
}
// Set PanelColor. This widget doesn't change the color, it only reflects the current configuration. // Set PanelColor. This widget doesn't change the color, it only reflects the current configuration.
private void LoadUIFromConfig(SMX.SMXConfig config) private void LoadUIFromConfig(LoadFromConfigDelegateArgs args)
{ {
int PanelIndex = Panel % 9; SMX.SMXConfig config = args.controller[getPadNo()].config;
// Hide color buttons for disabled panels. // Hide disabled color buttons.
bool[] enabledPanels = config.GetEnabledPanels(); Visibility = isEnabled(args)? Visibility.Visible:Visibility.Hidden;
Visibility = enabledPanels[PanelIndex]? Visibility.Visible:Visibility.Hidden;
// If this panel is selected but its panel isn't enabled, try to select a Color rgb = getColor();
// different panel.
if(!enabledPanels[PanelIndex] && IsSelected)
{
for(int panel = 0; panel < 9; ++panel)
{
if(enabledPanels[panel])
{
SelectedPanel = panel;
break;
}
}
}
Color rgb = Helpers.UnscaleColor(Color.FromRgb(
config.stepColor[PanelIndex*3+0],
config.stepColor[PanelIndex*3+1],
config.stepColor[PanelIndex*3+2]));
PanelColor = new SolidColorBrush(rgb); PanelColor = new SolidColorBrush(rgb);
} }
@ -583,32 +524,132 @@ namespace smx_config
if(data == null) if(data == null)
return false; return false;
// Parse the color being dragged onto us. // Parse the color being dragged onto us, and set it.
Color color = Helpers.ParseColorString(data.GetData(typeof(string)) as string); Color color = Helpers.ParseColorString(data.GetData(typeof(string)) as string);
setColor(color);
// Update the panel color.
return true;
}
protected override void OnDrop(DragEventArgs e)
{
if(!HandleDrop(e))
base.OnDrop(e);
}
}
// A ColorButton for setting a panel color.
public class PanelColorButton: ColorButton
{
// Which panel this is (P1 0-8, P2 9-17):
public static readonly DependencyProperty PanelProperty = DependencyProperty.RegisterAttached("Panel",
typeof(int), typeof(PanelColorButton), new FrameworkPropertyMetadata(0));
public int Panel {
get { return (int) this.GetValue(PanelProperty); }
set { this.SetValue(PanelProperty, value); }
}
protected override int getPadNo()
{
return Panel < 9? 0:1;
}
// A panel is enabled if it's enabled in the panel mask, which can be
// changed on the advanced tab.
public override bool isEnabled(LoadFromConfigDelegateArgs args)
{
int pad = getPadNo();
SMX.SMXConfig config = args.controller[pad].config;
if(!args.controller[pad].info.connected)
return false;
int PanelIndex = Panel % 9; int PanelIndex = Panel % 9;
int Pad = Panel < 9? 0:1; bool[] enabledPanels = config.GetEnabledPanels();
return enabledPanels[PanelIndex];
}
public override void setColor(Color color)
{
// Apply the change and save it to the device.
int pad = getPadNo();
SMX.SMXConfig config; SMX.SMXConfig config;
if(!SMX.SMX.GetConfig(Pad, out config)) if(!SMX.SMX.GetConfig(pad, out config))
return false; return;
// Light colors are 8-bit values, but we only use values between 0-170. Higher values // Light colors are 8-bit values, but we only use values between 0-170. Higher values
// don't make the panel noticeably brighter, and just draw more power. // don't make the panel noticeably brighter, and just draw more power.
color = Helpers.ScaleColor(color); int PanelIndex = Panel % 9;
config.stepColor[PanelIndex*3+0] = color.R; config.stepColor[PanelIndex*3+0] = Helpers.ScaleColor(color.R);
config.stepColor[PanelIndex*3+1] = color.G; config.stepColor[PanelIndex*3+1] = Helpers.ScaleColor(color.G);
config.stepColor[PanelIndex*3+2] = color.B; config.stepColor[PanelIndex*3+2] = Helpers.ScaleColor(color.B);
SMX.SMX.SetConfig(Pad, config); SMX.SMX.SetConfig(pad, config);
CurrentSMXDevice.singleton.FireConfigurationChanged(this); CurrentSMXDevice.singleton.FireConfigurationChanged(this);
return true;
} }
protected override void OnDrop(DragEventArgs e) // Return the color set for this panel in config.
public override Color getColor()
{ {
if(!HandleDrop(e)) int pad = getPadNo();
base.OnDrop(e); SMX.SMXConfig config;
if(!SMX.SMX.GetConfig(pad, out config))
return Color.FromRgb(0,0,0);
int PanelIndex = Panel % 9;
return Helpers.UnscaleColor(Color.FromRgb(
config.stepColor[PanelIndex*3+0],
config.stepColor[PanelIndex*3+1],
config.stepColor[PanelIndex*3+2]));
}
}
public class FloorColorButton: ColorButton
{
// 0 if this is for P1, 1 for P2.
public static readonly DependencyProperty PadProperty = DependencyProperty.RegisterAttached("Pad",
typeof(int), typeof(FloorColorButton), new FrameworkPropertyMetadata(0));
public int Pad {
get { return (int) this.GetValue(PadProperty); }
set { this.SetValue(PadProperty, value); }
}
protected override int getPadNo() { return Pad; }
// The floor color button is available if the firmware is v4 or greater.
public override bool isEnabled(LoadFromConfigDelegateArgs args)
{
int pad = getPadNo();
SMX.SMXConfig config = args.controller[pad].config;
return config.masterVersion >= 4;
}
public override void setColor(Color color)
{
// Apply the change and save it to the device.
int pad = getPadNo();
SMX.SMXConfig config;
if(!SMX.SMX.GetConfig(pad, out config))
return;
config.platformStripColor[0] = color.R;
config.platformStripColor[1] = color.G;
config.platformStripColor[2] = color.B;
SMX.SMX.SetConfig(pad, config);
CurrentSMXDevice.singleton.FireConfigurationChanged(this);
}
// Return the color set for this panel in config.
public override Color getColor()
{
int pad = getPadNo();
SMX.SMXConfig config;
if(!SMX.SMX.GetConfig(pad, out config))
return Color.FromRgb(0,0,0);
return Color.FromRgb(config.platformStripColor[0], config.platformStripColor[1], config.platformStripColor[2]);
} }
} }
@ -680,18 +721,24 @@ namespace smx_config
public class ColorPicker: Control public class ColorPicker: Control
{ {
// Which panel is currently selected:
public static readonly DependencyProperty SelectedPanelProperty = DependencyProperty.Register("SelectedPanel",
typeof(int), typeof(ColorPicker), new FrameworkPropertyMetadata(0));
public int SelectedPanel {
get { return (int) this.GetValue(SelectedPanelProperty); }
set { this.SetValue(SelectedPanelProperty, value); }
}
ColorPickerSlider HueSlider; ColorPickerSlider HueSlider;
public delegate void Event(); public delegate void Event();
// The selected ColorButton. This handles getting and setting the color to the
// config.
ColorButton _colorButton;
public ColorButton colorButton {
get { return _colorButton; }
set {
_colorButton = value;
// Refresh on change.
LoadFromConfigDelegateArgs args = CurrentSMXDevice.singleton.GetState();
LoadUIFromConfig(args);
}
}
public event Event StartedDragging, StoppedDragging; public event Event StartedDragging, StoppedDragging;
public override void OnApplyTemplate() public override void OnApplyTemplate()
{ {
@ -716,52 +763,36 @@ namespace smx_config
HueSlider.Ticks = ticks; HueSlider.Ticks = ticks;
OnConfigChange onConfigChange; OnConfigChange onConfigChange;
onConfigChange = new OnConfigChange(this, delegate (LoadFromConfigDelegateArgs args) { onConfigChange = new OnConfigChange(this, delegate(LoadFromConfigDelegateArgs args) {
int pad = SelectedPanel < 9? 0:1; LoadUIFromConfig(args);
LoadUIFromConfig(args.controller[pad].config);
}); });
} }
private void SaveToConfig() private void SaveToConfig()
{ {
if(UpdatingUI) if(UpdatingUI || _colorButton == null)
return; return;
// Apply the change and save it to the device.
int pad = SelectedPanel < 9? 0:1;
SMX.SMXConfig config;
if(!SMX.SMX.GetConfig(pad, out config))
return;
Color color = Helpers.FromHSV(HueSlider.Value, 1, 1); Color color = Helpers.FromHSV(HueSlider.Value, 1, 1);
// If we're set to the minimum value, use white instead. // If we're set to the minimum value, use white instead.
if(HueSlider.Value == HueSlider.Minimum) if(HueSlider.Value == HueSlider.Minimum)
color = Color.FromRgb(255,255,255); color = Color.FromRgb(255,255,255);
// Light colors are 8-bit values, but we only use values between 0-170. Higher values _colorButton.setColor(color);
// don't make the panel noticeably brighter, and just draw more power.
int PanelIndex = SelectedPanel % 9;
config.stepColor[PanelIndex*3+0] = Helpers.ScaleColor(color.R);
config.stepColor[PanelIndex*3+1] = Helpers.ScaleColor(color.G);
config.stepColor[PanelIndex*3+2] = Helpers.ScaleColor(color.B);
SMX.SMX.SetConfig(pad, config);
CurrentSMXDevice.singleton.FireConfigurationChanged(this);
} }
bool UpdatingUI = false; bool UpdatingUI = false;
private void LoadUIFromConfig(SMX.SMXConfig config) private void LoadUIFromConfig(LoadFromConfigDelegateArgs args)
{ {
if(UpdatingUI || _colorButton == null)
return;
// Make sure SaveToConfig doesn't treat these as the user changing values. // Make sure SaveToConfig doesn't treat these as the user changing values.
UpdatingUI = true; UpdatingUI = true;
// Reverse the scaling we applied in SaveToConfig. // Reverse the scaling we applied in SaveToConfig.
int PanelIndex = SelectedPanel % 9; Color rgb = _colorButton.getColor();
Color rgb = Helpers.UnscaleColor(Color.FromRgb(
config.stepColor[PanelIndex*3+0],
config.stepColor[PanelIndex*3+1],
config.stepColor[PanelIndex*3+2]));
double h, s, v; double h, s, v;
Helpers.ToHSV(rgb, out h, out s, out v); Helpers.ToHSV(rgb, out h, out s, out v);

Loading…
Cancel
Save