Skip to content

Commit

Permalink
Allow selection of RenderingMode from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
arkypita committed Jun 10, 2024
1 parent 67b85f8 commit bd6b807
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 73 deletions.
2 changes: 1 addition & 1 deletion LaserGRBL/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// utilizzando l'asterisco (*) come descritto di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("7.5.3")]
[assembly: AssemblyVersion ("7.5.4")]
[assembly: NeutralResourcesLanguage("en")]
2 changes: 1 addition & 1 deletion LaserGRBL/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public MainForm()
MultipleInstanceTimer.Enabled = true;
}

previewToolStripMenuItem.Visible = !Settings.LegacyPreview;
previewToolStripMenuItem.Visible = Settings.CurrentGraphicMode != Settings.GraphicMode.GDI;
showLaserOffMovementsToolStripMenuItem.Checked = Core.ShowLaserOffMovements.Value;
showExecutedCommandsToolStripMenuItem.Checked = Core.ShowExecutedCommands.Value;
showDiagnosticDataToolStripMenuItem.Checked = Core.ShowPerformanceDiagnostic.Value;
Expand Down
2 changes: 1 addition & 1 deletion LaserGRBL/PreviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void CreatePanel()
tableLayoutPanel1.Controls.Remove(GrblPanel as Control);
(GrblPanel as Control).Dispose();
}
if (Settings.LegacyPreview)
if (Settings.RequestedGraphicMode == Settings.GraphicMode.GDI)
GrblPanel = new GrblPanel();
else
GrblPanel = new GrblPanel3D();
Expand Down
10 changes: 5 additions & 5 deletions LaserGRBL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ static void Main(string[] args)

foreach (string s in args)
{
if (s != null && s.ToLower() == "nogl")
Settings.LegacyPreview = true;
if (s != null && s.ToLower() == "swgl")
Settings.UseSoftwareOpenGL = true;
if (s != null && Settings.ForcedGraphicMode == Settings.GraphicMode.AUTO && s.ToLower() == "nogl")
Settings.ForcedGraphicMode = Settings.GraphicMode.GDI;
if (s != null && Settings.ForcedGraphicMode == Settings.GraphicMode.AUTO && s.ToLower() == "swgl")
Settings.ForcedGraphicMode = Settings.GraphicMode.DIB;
}

if (!Settings.LegacyPreview && !Settings.UseSoftwareOpenGL)
if (Settings.RequestedGraphicMode != Settings.GraphicMode.DIB && Settings.RequestedGraphicMode != Settings.GraphicMode.GDI)
GraphicInitializer.RequestDedicatedGraphics();

Application.Run(new MainForm(args));
Expand Down
44 changes: 29 additions & 15 deletions LaserGRBL/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,37 @@

namespace LaserGRBL
{
/// <summary>
/// Description of Settings.
/// </summary>
public static class Settings
{
private static System.Threading.Timer Timer = new System.Threading.Timer(OnTimerExpire, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
private static System.Collections.Generic.Dictionary<string, object> dic;
private static string LastCause = null;
private static string LockString = "---- SETTING LOCK ----";
internal static bool LegacyPreview;
internal static bool UseSoftwareOpenGL;
/// <summary>
/// Description of Settings.
/// </summary>
public static class Settings
{
private static System.Threading.Timer Timer = new System.Threading.Timer(OnTimerExpire, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
private static System.Collections.Generic.Dictionary<string, object> dic;
private static string LastCause = null;
private static string LockString = "---- SETTING LOCK ----";

public static bool IsNewFile { get; private set; } = false;
public static Version PrevVersion { get; private set; } = new Version(0, 0, 0);

static string filename
public static Version PrevVersion { get; private set; } = new Version(0, 0, 0);

public enum GraphicMode
{
AUTO = 0,
GDI = 1,
DIB = 2,
FBO = 3,
}

public static GraphicMode ForcedGraphicMode { get; set; } = GraphicMode.AUTO; // forced by command line
public static GraphicMode ConfiguredGraphicMode // stored in settings
{
get { return (GraphicMode)GetObject("ConfiguredGraphicMode", 0); }
set { SetObject("ConfiguredGraphicMode", (int)value); }
}
public static GraphicMode RequestedGraphicMode => ForcedGraphicMode != GraphicMode.AUTO ? ForcedGraphicMode : ConfiguredGraphicMode ;
public static GraphicMode CurrentGraphicMode { get; set; } = GraphicMode.AUTO; // actually in use

static string filename
{
get
{
Expand Down Expand Up @@ -63,7 +78,6 @@ static Settings()
SetObject("Current LaserGRBL Version", Program.CurrentVersion);
}


public static T GetObject<T>(string key, T defval)
{
try
Expand Down
47 changes: 46 additions & 1 deletion LaserGRBL/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 40 additions & 3 deletions LaserGRBL/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using LaserGRBL.UserControls;
using Sound;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

Expand All @@ -17,6 +19,7 @@ public partial class SettingsForm : Form
{
private GrblCore Core;
public static event EventHandler SettingsChanged;
private Settings.GraphicMode PrevGraphicMode;

public SettingsForm(GrblCore core)
{
Expand Down Expand Up @@ -44,6 +47,7 @@ public SettingsForm(GrblCore core)
InitProtocolCB();
InitStreamingCB();
InitThreadingCB();
InitGraphicModeCB();

CBCore.SelectedItem = Settings.GetObject("Firmware Type", Firmware.Grbl);
CBSupportPWM.Checked = Settings.GetObject("Support Hardware PWM", true);
Expand Down Expand Up @@ -101,8 +105,9 @@ public SettingsForm(GrblCore core)
CbDisableSafetyCD.Checked = Settings.GetObject("DisableSafetyCountdown", false);
CbQuietSafetyCB.Checked = Settings.GetObject("QuietSafetyCountdown", false);
CbLegacyIcons.Checked = Settings.GetObject("LegacyIcons", false);
CBGraphicMode.SelectedValue = PrevGraphicMode = Settings.ConfiguredGraphicMode;

groupBox1.ForeColor = groupBox2.ForeColor = groupBox3.ForeColor = ColorScheme.FormForeColor;
groupBox1.ForeColor = groupBox2.ForeColor = groupBox3.ForeColor = ColorScheme.FormForeColor;

SuccesFullLabel.Visible = WarningFullLabel.Visible = ErrorFullLabel.Visible = ConnectFullLabel.Visible = DisconnectFullLabel.Visible = false;

Expand Down Expand Up @@ -180,6 +185,20 @@ private void InitStreamingCB()
CBStreamingMode.EndUpdate();
}

private void InitGraphicModeCB()
{
CBGraphicMode.BeginUpdate();
List<KeyValuePair<string, Settings.GraphicMode>> list = new List<KeyValuePair<string, Settings.GraphicMode>>();
list.Add(new KeyValuePair<string, Settings.GraphicMode>("Auto", Settings.GraphicMode.AUTO));
list.Add(new KeyValuePair<string, Settings.GraphicMode>("Hardware Acceleration", Settings.GraphicMode.FBO));
list.Add(new KeyValuePair<string, Settings.GraphicMode>("Software Rendering", Settings.GraphicMode.DIB));
list.Add(new KeyValuePair<string, Settings.GraphicMode>("Legacy", Settings.GraphicMode.GDI));
CBGraphicMode.DisplayMember = "Key";
CBGraphicMode.ValueMember = "Value";
CBGraphicMode.DataSource = list;
CBGraphicMode.EndUpdate();
}

internal static void CreateAndShowDialog(Form parent, GrblCore core)
{
using (SettingsForm sf = new SettingsForm(core))
Expand Down Expand Up @@ -235,18 +254,33 @@ private void BtnSave_Click(object sender, EventArgs e)
Settings.SetObject("DisableSafetyCountdown", CbDisableSafetyCD.Checked);
Settings.SetObject("QuietSafetyCountdown", CbQuietSafetyCB.Checked);
Settings.SetObject("LegacyIcons", CbLegacyIcons.Checked);
Settings.ConfiguredGraphicMode = (Settings.GraphicMode)CBGraphicMode.SelectedValue;

SettingsChanged?.Invoke(this, null);
SettingsChanged?.Invoke(this, null);

Close();

if (Core.Type != Settings.GetObject("Firmware Type", Firmware.Grbl) && MessageBox.Show(Strings.FirmwareRequireRestartNow, Strings.FirmwareRequireRestart, MessageBoxButtons.OKCancel) == DialogResult.OK)
if (PrevGraphicMode != Settings.ConfiguredGraphicMode && MessageBox.Show(Strings.PreviewChangesRequiresRestart, Strings.FirmwareRequireRestart, MessageBoxButtons.OKCancel) == DialogResult.OK)
RestartNoCommandLine();

if (Core.Type != Settings.GetObject("Firmware Type", Firmware.Grbl) && MessageBox.Show(Strings.FirmwareRequireRestartNow, Strings.FirmwareRequireRestart, MessageBoxButtons.OKCancel) == DialogResult.OK)
Application.Restart();

if (IconsMgr.LegacyIcons != Settings.GetObject("LegacyIcons", false) && MessageBox.Show(Strings.IconsChangesRequiresRestart, Strings.FirmwareRequireRestart, MessageBoxButtons.OKCancel) == DialogResult.OK)
Application.Restart();
}

public static void RestartNoCommandLine()
{
ProcessStartInfo startInfo = Process.GetCurrentProcess().StartInfo;
startInfo.FileName = Application.ExecutablePath;
var exit = typeof(Application).GetMethod("ExitInternal",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Static);
exit.Invoke(null, null);
Process.Start(startInfo);
}

private TimeSpan MaxTs(TimeSpan a, TimeSpan b)
{ return TimeSpan.FromTicks(Math.Max(a.Ticks, b.Ticks)); }

Expand Down Expand Up @@ -341,5 +375,8 @@ private void CbTelegramNotification_CheckedChanged(object sender, EventArgs e)
{
EnableTest();
}

private void BtnRenderingMode_Click(object sender, EventArgs e)
{ Tools.Utils.OpenLink(@"https://lasergrbl.com/configuration/#rendering-mode"); }
}
}
Loading

0 comments on commit bd6b807

Please sign in to comment.