You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.7 KiB

using Calculator;
using NumpadMonitor;
using System;
using System.Windows.Forms;
namespace ChromaController
{
internal class MonitorManager
{
private readonly NumpadMonitorForm monitor;
private readonly KeyConverter keyConverter;
private readonly ColoreOutput coloreOutput;
private readonly Calc calculator;
public MonitorManager(ColoreOutput coloreOutput, KeyConverter keyConverter, Calc calculator)
{
this.keyConverter = keyConverter;
this.coloreOutput = coloreOutput;
this.calculator = calculator;
monitor = NumpadMonitor.Program.Initiate(false, true, false);
monitor.KeyPressEvent += new NumpadMonitorForm.NotifyKeyPressEvent(KeyPressEventHandler);
Application.Run(monitor);
}
public void KeyPressEventHandler(NumpadMonitorForm sender, KeyInfo keyInfo)
{
Console.WriteLine(keyInfo.ToString());
if (keyInfo.Key == Keys.End)
{
Exit();
return;
}
CalculationResponse response = calculator.KeyPressed(keyInfo.Key);
HandleResponse(keyInfo, response);
}
private void HandleResponse(KeyInfo keyInfo, CalculationResponse response)
{
switch (response.Response)
{
case Response.Ok:
coloreOutput.NumpadKeyPressed(keyConverter.ToColoreKey(keyInfo.Key));
break;
case Response.ClearedMemory:
coloreOutput.MemoryCleared();
break;
case Response.Result:
Console.WriteLine(response.Result);
if (response.Result == "∞")
{
coloreOutput.ErrorFlash();
HandleResponse(new KeyInfo(Keys.Delete), calculator.KeyPressed(Keys.Delete));
}
else
{
coloreOutput.PrintNumber(response.Result);
coloreOutput.MemorySet();
}
break;
case Response.WrongInput:
coloreOutput.ErrorFlash();
break;
default:
throw new ArgumentException("Argument is not value within Response Enum", "response.Response");
}
}
private void Exit()
{
monitor.DisposeElements();
monitor.Close();
coloreOutput.Exit();
}
}
}