Skip to content

Commit

Permalink
More Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Scavanger committed Mar 12, 2016
1 parent 57029da commit 8b2f45b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 90 deletions.
2 changes: 0 additions & 2 deletions SUMDJoy/AboutForm.Designer.cs

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

10 changes: 0 additions & 10 deletions SUMDJoy/AboutForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,11 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
System.Diagnostics.Process.Start("http://www.github.com/scavanger/sumdjoy");
}

private void AboutForm_Load(object sender, EventArgs e)
{

}

private void pictureBoxLicence_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://creativecommons.org/licenses/by-nc-sa/4.0/");
}

private void labelLicence_Click(object sender, EventArgs e)
{

}

private void button_OK_Click(object sender, EventArgs e)
{
Close();
Expand Down
5 changes: 3 additions & 2 deletions SUMDJoy/MainForm.Designer.cs

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

155 changes: 81 additions & 74 deletions SUMDJoy/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public MainForm()
{
_channelComboBoxes.Add(Controls.Find("comboBoxChannel" + i, true).FirstOrDefault() as ComboBox);
_channelComboBoxes[i - 1].Tag = i;
_channelComboBoxes[i - 1].BindingContext = new BindingContext();
}

}
Expand All @@ -51,23 +52,12 @@ private void Form1_Load(object sender, EventArgs e)
else
labelVJoyINfo.Text = "vJoy Driver not enabled.";

_channelComboBoxes.ForEach(comboBox =>
{
comboBox.BindingContext = new BindingContext();
comboBox.DataSource = new BindingSource(_sumdTovJoy.Assignments.Keys.ToList(), null);
comboBox.DisplayMember = "Name";
comboBox.ValueMember = "Name";
comboBox.SelectedItem = _sumdTovJoy.Assignments.Where(a => a.Value == (int)comboBox.Tag).FirstOrDefault().Key;
if (comboBox.SelectedItem == null)
comboBox.SelectedItem = new NoneAssingment();
});

SetChannelComboBoxes();
_currentSettingsFile = Properties.Settings.Default.LastUserSettingsFile;
LoadSettings();
labelSumdStatus.Text = "Not connected";

_sumdTovJoy.Start();
_ignorChannelComboBoxes = false;
LoadSettings();
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
Expand Down Expand Up @@ -99,21 +89,8 @@ private void comboBoxvJoyDevice_SelectedValueChanged(object sender, EventArgs e)
{
_sumdTovJoy.vJoyDevice = (uint)comboBoxvJoyDevice.SelectedItem;
_sumdTovJoy.GetvJoyInfos();
//_currentSettingsFile = string.Empty;
//Text = Application.ProductName;

_ignorChannelComboBoxes = true;
_channelComboBoxes.ForEach(comboBox =>
{
comboBox.DataSource = new BindingSource(_sumdTovJoy.Assignments.Keys.ToList(), null);
comboBox.DisplayMember = "Name";
comboBox.ValueMember = "Name";
comboBox.SelectedItem = _sumdTovJoy.Assignments.Where(a => a.Value == (int)comboBox.Tag).FirstOrDefault().Key;
if (comboBox.SelectedItem == null)
comboBox.SelectedItem = new NoneAssingment();
});
_ignorChannelComboBoxes = false;
SetChannelComboBoxes();
LoadSettings(true);

}
Expand All @@ -133,42 +110,56 @@ private void comboBoxChannel_SelectedValueChanged(object sender, EventArgs e)
if (comboBox.SelectedItem != null)
_sumdTovJoy.Assignments[comboBox.SelectedItem as Assignment] = (int)comboBox.Tag;
});

//ComboBox comboBox = sender as ComboBox;
//int channel = (int)comboBox.Tag;

//DeleteChannel(channel);
//_sumdTovJoy.Assignments[comboBox.SelectedItem as Assignment] = channel;
}
}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveSettings();
}

private void saveasToolStripMenuItem_Click(object sender, EventArgs e)
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.AddExtension = true;
sfd.DefaultExt = "xlm";
sfd.ValidateNames = true;
sfd.Filter = "SUMDJoy XML Config File (*.xml) |*.xml";
sfd.RestoreDirectory = true;
OpenFileDialog ofd = new OpenFileDialog();
ofd.AddExtension = true;
ofd.Multiselect = false;
ofd.DefaultExt = "xml";
ofd.ValidateNames = true;
ofd.Filter = "SUMDJoy XML Config File (*.xml) |*.xml";
ofd.RestoreDirectory = true;
try
{
if (sfd.ShowDialog() == DialogResult.OK)
if (ofd.ShowDialog() == DialogResult.OK)
{
_currentSettingsFile = sfd.FileName;
SaveSettings();
_currentSettingsFile = ofd.FileName;
LoadSettings();
_sumdTovJoy.Start();
}
}
catch (Exception ex)
{
toolStripStatusLabel1.Text = "Can't load settings. " + ex.Message;
_currentSettingsFile = string.Empty;
Text = Application.ProductName;
}
}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
try {
if (string.IsNullOrEmpty(_currentSettingsFile))
SaveAs();
else
SaveSettings();
}
catch (Exception ex)
{
toolStripStatusLabel1.Text = "Can't save settings. " + ex.Message;
_currentSettingsFile = string.Empty;
Text = Application.ProductName;
}
}

private void saveasToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveAs();
}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutForm aboutForm = new AboutForm();
Expand All @@ -184,6 +175,24 @@ private void _sumdTovJoy_NewFrameRecieved(object sender, EventArgs e)

#region Methods

private void SetChannelComboBoxes()
{
bool setBack = _ignorChannelComboBoxes;
_ignorChannelComboBoxes = true;

_channelComboBoxes.ForEach(comboBox =>
{
comboBox.DataSource = new BindingSource(_sumdTovJoy.Assignments.Keys.ToList(), null);
comboBox.DisplayMember = "Name";
comboBox.ValueMember = "Name";
comboBox.SelectedItem = _sumdTovJoy.Assignments.Where(a => a.Value == (int)comboBox.Tag).FirstOrDefault().Key;
if (comboBox.SelectedItem == null)
comboBox.SelectedItem = new NoneAssingment();
});
_ignorChannelComboBoxes = setBack;
}

private void LoadSettings(bool ignoreDevice = false)
{
if (File.Exists(_currentSettingsFile))
Expand Down Expand Up @@ -229,6 +238,30 @@ private void LoadSettings(bool ignoreDevice = false)
}
}

private void SaveAs()
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.AddExtension = true;
sfd.DefaultExt = "xlm";
sfd.ValidateNames = true;
sfd.Filter = "SUMDJoy XML Config File (*.xml) |*.xml";
sfd.RestoreDirectory = true;
try
{
if (sfd.ShowDialog() == DialogResult.OK)
{
_currentSettingsFile = sfd.FileName;
SaveSettings();
}
}
catch (Exception ex)
{
toolStripStatusLabel1.Text = "Can't save settings. " + ex.Message;
_currentSettingsFile = string.Empty;
Text = Application.ProductName;
}
}

private void SaveSettings()
{
_settings.vJoyConfig.Assignments = _sumdTovJoy.Assignments;
Expand All @@ -237,9 +270,7 @@ private void SaveSettings()

_settings.vJoyConfig.COMPort = comboBoxComPorts.SelectedItem as string;
_settings.vJoyConfig.vJoyDevice = (uint)comboBoxvJoyDevice.SelectedItem;

_settings.Save(_currentSettingsFile);

toolStripStatusLabel1.Text = "Settings saved.";
}

Expand Down Expand Up @@ -267,29 +298,5 @@ private void button2_Click(object sender, EventArgs e)
labelSumdStatus.Text = "Not connected";

}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.AddExtension = true;
ofd.Multiselect = false;
ofd.DefaultExt = "xml";
ofd.ValidateNames = true;
ofd.Filter = "SUMDJoy XML Config File (*.xml) |*.xml";
ofd.RestoreDirectory = true;
try
{
if (ofd.ShowDialog() == DialogResult.OK)
{
_currentSettingsFile = ofd.FileName;
LoadSettings();
_sumdTovJoy.Start();
}
}
catch (Exception ex)
{
toolStripStatusLabel1.Text = "Can't load settings. " + ex.Message;
}
}
}
}
4 changes: 2 additions & 2 deletions SUMDJoy/SUMDToVJoy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace SUMDJoy
{
public class SUMDToVJoy
{
private const int MAX_POS = 0x1c20;
private const int MIN_POS = 0x41a0;
private const int MAX_POS = 0x41a0;
private const int MIN_POS = 0x1c20;


private SUMD _sumd;
Expand Down

0 comments on commit 8b2f45b

Please sign in to comment.