Change Camera Sync setting to use ToggleSwitch

This commit is contained in:
John Lewin 2015-03-19 10:25:34 -07:00
parent e7586477c0
commit 4fe6fcb9d4

View file

@ -21,6 +21,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage
Button openGcodeTerminalButton;
Button openCameraButton;
private ToggleSwitchFactory toggleSwitchFactory = new ToggleSwitchFactory();
DisableableWidget eePromControlsContainer;
DisableableWidget terminalCommunicationsContainer;
DisableableWidget printLevelingContainer;
@ -65,8 +67,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage
}
EditLevelingSettingsWindow editLevelingSettingsWindow;
Button enablePrintLevelingButton;
Button disablePrintLevelingButton;
TextWidget printLevelingStatusLabel;
private FlowLayoutWidget GetAutoLevelControl()
{
@ -125,15 +125,17 @@ namespace MatterHackers.MatterControl.ConfigurationPage
ImageWidget levelingIcon = new ImageWidget(levelingImage);
levelingIcon.Margin = new BorderDouble (right: 6);
enablePrintLevelingButton = textImageButtonFactory.Generate("Enable".Localize().ToUpper());
enablePrintLevelingButton.Margin = new BorderDouble(left:6);
enablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
enablePrintLevelingButton.Click += new EventHandler(enablePrintLeveling_Click);
GuiWidget levelingSwitchContainer = new FlowLayoutWidget();
levelingSwitchContainer.VAnchor = VAnchor.ParentCenter;
disablePrintLevelingButton = textImageButtonFactory.Generate("Disable".Localize().ToUpper());
disablePrintLevelingButton.Margin = new BorderDouble(left:6);
disablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
disablePrintLevelingButton.Click += new EventHandler(disablePrintLeveling_Click);
ToggleSwitch printLevelingSwitch = GenerateToggleSwitch(levelingSwitchContainer, PrinterSettings.Instance.get("PublishBedImage") == "true");
printLevelingSwitch.SwitchState = ActivePrinterProfile.Instance.DoPrintLeveling;
printLevelingSwitch.SwitchStateChanged += (sender, e) =>
{
ActivePrinterProfile.Instance.DoPrintLeveling = printLevelingSwitch.SwitchState;
};
levelingSwitchContainer.SetBoundsToEncloseChildren();
printLevelingStatusLabel = new TextWidget ("");
printLevelingStatusLabel.AutoExpandBoundsToText = true;
@ -153,8 +155,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
buttonRow.AddChild(printLevelingStatusLabel);
buttonRow.AddChild(editButton);
buttonRow.AddChild(new HorizontalSpacer());
buttonRow.AddChild(enablePrintLevelingButton);
buttonRow.AddChild(disablePrintLevelingButton);
buttonRow.AddChild(levelingSwitchContainer);
buttonRow.AddChild(runPrintLevelingButton);
SetPrintLevelButtonVisiblity();
return buttonRow;
@ -168,7 +169,22 @@ namespace MatterHackers.MatterControl.ConfigurationPage
}
base.OnClosed(e);
}
ToggleSwitch GenerateToggleSwitch(GuiWidget parentContainer, bool initiallyChecked)
{
TextWidget toggleLabel = new TextWidget(initiallyChecked ? "On" : "Off", pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor);
toggleLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
ToggleSwitch toggleSwitch = toggleSwitchFactory.GenerateGivenTextWidget(toggleLabel, "On", "Off", initiallyChecked);
toggleSwitch.VAnchor = Agg.UI.VAnchor.ParentCenter;
toggleSwitch.SwitchState = initiallyChecked;
toggleSwitch.Margin = new BorderDouble (0, 0, 12, 0);
parentContainer.AddChild(toggleLabel);
parentContainer.AddChild(toggleSwitch);
return toggleSwitch;
}
private FlowLayoutWidget GetCameraControl()
{
@ -185,28 +201,25 @@ namespace MatterHackers.MatterControl.ConfigurationPage
ImageWidget cameraIcon = new ImageWidget(cameraIconImage);
cameraIcon.Margin = new BorderDouble(right: 6, bottom: 6);
TextWidget gcodeTerminalLabel = new TextWidget("Camera");
TextWidget gcodeTerminalLabel = new TextWidget("Camera Sync");
gcodeTerminalLabel.AutoExpandBoundsToText = true;
gcodeTerminalLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
gcodeTerminalLabel.VAnchor = VAnchor.ParentCenter;
openCameraButton = textImageButtonFactory.Generate("Preview".Localize().ToUpper());
openCameraButton.Click += new EventHandler(openCameraPreview_Click);
openCameraButton.Margin = new BorderDouble(left:6);
buttonRow.AddChild(cameraIcon);
buttonRow.AddChild(gcodeTerminalLabel);
buttonRow.AddChild(new HorizontalSpacer());
#if __ANDROID__
CheckBox syncCameraCheckbox = new CheckBox(0, 0, "Sync".Localize(), 10);
syncCameraCheckbox.Margin = new BorderDouble(0,0,12,0);
syncCameraCheckbox.VAnchor = VAnchor.ParentCenter;
syncCameraCheckbox.Checked = PrinterSettings.Instance.get("PublishBedImage") == "true";
syncCameraCheckbox.Click += (sender, e) =>
ToggleSwitch toggleSwitch = GenerateToggleSwitch(buttonRow, PrinterSettings.Instance.get("PublishBedImage") == "true");
toggleSwitch.SwitchStateChanged += (sender, e) =>
{
CheckBox thisControl = sender as CheckBox;
PrinterSettings.Instance.set("PublishBedImage", thisControl.Checked ? "true" : "false");
ToggleSwitch thisControl = sender as ToggleSwitch;
PrinterSettings.Instance.set("PublishBedImage", thisControl.SwitchState ? "true" : "false");
};
buttonRow.AddChild(syncCameraCheckbox);
#endif
buttonRow.AddChild(openCameraButton);
@ -358,21 +371,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage
this.Invalidate();
}
void enablePrintLeveling_Click(object sender, EventArgs mouseEvent)
{
ActivePrinterProfile.Instance.DoPrintLeveling = true;
}
void disablePrintLeveling_Click(object sender, EventArgs mouseEvent)
{
ActivePrinterProfile.Instance.DoPrintLeveling = false;
}
void SetPrintLevelButtonVisiblity()
{
enablePrintLevelingButton.Visible = !ActivePrinterProfile.Instance.DoPrintLeveling;
disablePrintLevelingButton.Visible = ActivePrinterProfile.Instance.DoPrintLeveling;
if (ActivePrinterProfile.Instance.DoPrintLeveling)
{
printLevelingStatusLabel.Text = LocalizedString.Get("Automatic Print Leveling (enabled)");