Fixed the calibration and added the JSON serialising

This commit is contained in:
2023-05-05 15:00:39 +02:00
parent 2c2239427c
commit 16be9bf7ef
13 changed files with 205 additions and 72 deletions

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Test_Merge
{
@@ -49,6 +50,11 @@ namespace Test_Merge
lsbDrivers.DataSource = null;
lsbDrivers.DataSource = DriverList;
if (Directory.Exists(ConfigurationTool.CONFIGS_FOLDER_NAME))
{
lsbPresets.DataSource = null;
lsbPresets.DataSource = Directory.GetFiles(ConfigurationTool.CONFIGS_FOLDER_NAME);
}
if (CreatingZone)
{
if (ZoneP1 == new Point(-1, -1))
@@ -85,7 +91,8 @@ namespace Test_Merge
if (Config != null)
{
pbxMain.Image = Config.MainZone.Draw();
pbxDriverZone.Image = Config.MainZone.Zones[0].ZoneImage;
if(Config.MainZone.Zones.Count > 0)
pbxDriverZone.Image = Config.MainZone.Zones[0].Draw();
}
}
private void CreateNewZone(Point p1, Point p2)
@@ -129,6 +136,7 @@ namespace Test_Merge
{
string newDriver = tbxDriverName.Text;
DriverList.Add(newDriver);
tbxDriverName.Text = "";
RefreshUI();
}
@@ -150,6 +158,10 @@ namespace Test_Merge
else
{
CreatingZone = true;
if (Config != null)
Config.ResetMainZone();
if (CreatingWindow)
SwitchWindowCreation();
@@ -176,6 +188,9 @@ namespace Test_Merge
{
CreatingWindow = true;
if (Config != null)
Config.ResetWindows();
if (CreatingZone)
SwitchZoneCreation();
@@ -194,19 +209,17 @@ namespace Test_Merge
{
SwitchWindowCreation();
}
private void pbxMain_Click(object sender, EventArgs e)
private void pbxMain_MouseClick(object sender, MouseEventArgs e)
{
if (CreatingZone && pbxMain.Image != null)
{
Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y));
//Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y));
Point coordinates = e.Location;
float xOffset = (float)pbxMain.Image.Width / (float)pbxMain.Width;
float yOffset = (float)pbxMain.Image.Height / (float)pbxMain.Height;
Point newPoint = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset));
//Point newPoint = new Point(coordinates.X - pbxMain.Left, coordinates.Y - pbxMain.Top);
//newPoint = new Point(Convert.ToInt32((float)newPoint.X * xOffset),Convert.ToInt32((float)newPoint.Y * yOffset));
MessageBox.Show("Coordinates" + Environment.NewLine + "Old : " + coordinates.ToString() + Environment.NewLine + "New : " + newPoint.ToString());
//MessageBox.Show("Coordinates" + Environment.NewLine + "Old : " + coordinates.ToString() + Environment.NewLine + "New : " + newPoint.ToString());
if (ZoneP1 == new Point(-1, -1))
{
@@ -215,31 +228,21 @@ namespace Test_Merge
else
{
ZoneP2 = newPoint;
/*
//Correction
if(ZoneP1.Y > ZoneP2.Y)
{
ZoneP1 = new Point(ZoneP1.X,ZoneP1.Y + pbxMain.Top);
}
else
{
ZoneP2 = new Point(ZoneP2.X, ZoneP2.Y - pbxMain.Top);
}
*/
CreateNewZone(ZoneP1, ZoneP2);
SwitchZoneCreation();
}
RefreshUI();
}
}
private void pbxDriverZone_Click(object sender, EventArgs e)
private void pbxMain_Click(object sender, EventArgs e)
{
//Not the right one to use visibly
}
private void pbxDriverZone_MouseClick(object sender, MouseEventArgs e)
{
if (CreatingWindow && pbxDriverZone.Image != null)
{
Point coordinates = pbxDriverZone.PointToClient(new Point(MousePosition.X, MousePosition.Y));
Point coordinates = e.Location;
float xOffset = (float)pbxDriverZone.Image.Width / (float)pbxDriverZone.Width;
float yOffset = (float)pbxDriverZone.Image.Height / (float)pbxDriverZone.Height;
@@ -262,12 +265,19 @@ namespace Test_Merge
}
else
{
WindowP1 = new Point(WindowP1.X, 0);
WindowP2 = new Point(WindowP2.X, pbxDriverZone.Image.Height);
CreateWindows(WindowsToAdd);
SwitchWindowCreation();
}
}
RefreshUI();
}
}
private void pbxDriverZone_Click(object sender, EventArgs e)
{
//Not the right one to use visibly
}
private Rectangle CreateAbsoluteRectangle(Point p1, Point p2)
{
Point newP1 = new Point();
@@ -357,5 +367,23 @@ namespace Test_Merge
Emulator.Stop();
}
}
private void btnResetDriver_Click(object sender, EventArgs e)
{
if (Emulator != null)
{
Emulator.ResetDriver();
}
}
private void btnSavePreset_Click(object sender, EventArgs e)
{
string presetName = tbxPresetName.Text;
if (Config != null)
{
Config.SaveToJson(DriverList,presetName);
}
RefreshUI();
}
}
}