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

633 lines
20 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using IntelOrca.Launchpad;
using IntelOrca.LaunchpadTests;
namespace Kidd_s_Passwort_Generator
{
public partial class _8x8EingabeFeld : Form
{
private bool appEnd = false;
private long delay;
private int speed = 4;
Point ChosenPoint;
int[,] FieldValues;
Point currentTrailPoint;
Point TargetPoint;
string currentPasswordChunk = "";
private string processMode = "Horizontal_Green";
Button[,] InputField = new Button[8, 8];
// in combination with codepage gives the range of chars that are
private string characterSet = "CharsOnly";
Random FieldValRandomizer;
Random NoiseRandomizer;
//Default Seed
int Seed = 12345;
//Default Private Key
int privateKey = 54321;
Random CharValRandomizer;
//Default Codepage
Queue<string> ImageList;
private long CurrentTicks = 0;
PWGenerator generator = null;
//for steady update a background worker is used
BackgroundWorker BgWorker;
public enum animationColorMode { Green2Red, Red2Green, Green2Green, Red2Red };
private Dictionary<string, Color> stateColors = new Dictionary<string, Color>();
animationColorMode currentMode = animationColorMode.Green2Green;
public _8x8EingabeFeld(PWGenerator Generator)
{
InitializeComponent();
fillInputField();
stateColors.Clear();
stateColors.Add("Basic", SystemColors.ControlDarkDark);
stateColors.Add("GreenLow", Color.DarkGreen);
stateColors.Add("GreenMedium", Color.Green);
stateColors.Add("GreenFull", Color.LightGreen);
stateColors.Add("RedLow", Color.PaleVioletRed);
stateColors.Add("RedMedium", Color.MediumVioletRed);
stateColors.Add("RedFull", Color.Red);
stateColors.Add("YellowFull", Color.LightGoldenrodYellow);
stateColors.Add("YellowMedium", Color.Goldenrod);
stateColors.Add("YellowLow", Color.DarkGoldenrod);
this.generator = Generator;
//Randomizer with always different Timestamp
NoiseRandomizer = new Random(Convert.ToInt32((new TimeSpan(DateTime.UtcNow.Ticks - new DateTime(2013, 06, 08).Ticks).TotalMinutes)));
//Randomizer to always generate different chars from the current field value depending on the current chunk
CharValRandomizer = new Random(privateKey);
//Set field Values depending on given private Key
FieldValues = new int[8, 8];
BgWorker = new BackgroundWorker();
BgWorker.DoWork += backgroundWorker_DoWork;
BgWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
}
public new void Update()
{
//TODO:
//Aktuell kein update der ButtonBackgrounds
base.Update();
BgWorker.RunWorkerAsync();
}
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//UI update
System.Threading.Thread.Sleep(500);
Update();
}
private void fillInputField()
{
InputField[0, 0] = button_00;
InputField[0, 1] = button_01;
InputField[0, 2] = button_02;
InputField[0, 3] = button_03;
InputField[0, 4] = button_04;
InputField[0, 5] = button_05;
InputField[0, 6] = button_06;
InputField[0, 7] = button_07;
InputField[1, 0] = button_10;
InputField[1, 1] = button_11;
InputField[1, 2] = button_12;
InputField[1, 3] = button_13;
InputField[1, 4] = button_14;
InputField[1, 5] = button_15;
InputField[1, 6] = button_16;
InputField[1, 7] = button_17;
InputField[2, 0] = button_20;
InputField[2, 1] = button_21;
InputField[2, 2] = button_22;
InputField[2, 3] = button_23;
InputField[2, 4] = button_24;
InputField[2, 5] = button_25;
InputField[2, 6] = button_26;
InputField[2, 7] = button_27;
InputField[3, 0] = button_30;
InputField[3, 1] = button_31;
InputField[3, 2] = button_32;
InputField[3, 3] = button_33;
InputField[3, 4] = button_34;
InputField[3, 5] = button_35;
InputField[3, 6] = button_36;
InputField[3, 7] = button_37;
InputField[4, 0] = button_40;
InputField[4, 1] = button_41;
InputField[4, 2] = button_42;
InputField[4, 3] = button_43;
InputField[4, 4] = button_44;
InputField[4, 5] = button_45;
InputField[4, 6] = button_46;
InputField[4, 7] = button_47;
InputField[5, 0] = button_50;
InputField[5, 1] = button_51;
InputField[5, 2] = button_52;
InputField[5, 3] = button_53;
InputField[5, 4] = button_54;
InputField[5, 5] = button_55;
InputField[5, 6] = button_56;
InputField[5, 7] = button_57;
InputField[6, 0] = button_60;
InputField[6, 1] = button_61;
InputField[6, 2] = button_62;
InputField[6, 3] = button_63;
InputField[6, 4] = button_64;
InputField[6, 5] = button_65;
InputField[6, 6] = button_66;
InputField[6, 7] = button_67;
InputField[7, 0] = button_70;
InputField[7, 1] = button_71;
InputField[7, 2] = button_72;
InputField[7, 3] = button_73;
InputField[7, 4] = button_74;
InputField[7, 5] = button_75;
InputField[7, 6] = button_76;
InputField[7, 7] = button_77;
}
private void UpdatePositions()
{
//Get the curent button color by checking the color of the logical field in the generator
for (int buttonX = 0; buttonX < 8; buttonX++)
{
for (int buttonY = 0; buttonY < 8; buttonY++)
{
virtualButton TempButton = new virtualButton();
TempButton.IntensityGreen = generator.getFieldColor(buttonX, buttonY, "Green");
TempButton.IntensityRed = generator.getFieldColor(buttonX, buttonY, "Red");
InputField[buttonX, buttonY].BackColor = translateButtonColor(TempButton);
InputField[buttonX, buttonY].Invalidate();
}
}
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
if (BgWorker.CancellationPending == true)
{
e.Cancel = true;
break;
}
else
{
// Update of all logic routines
UpdatePositions();
}
}
}
#region Buttonpresses
private void button_00_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 0);
}
private void button_10_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 0);
}
private void button_20_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 0);
}
private void button_30_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 0);
}
private void button_40_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 0);
}
private void button_50_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 0);
}
private void button_60_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 0);
}
private void button_70_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 0);
}
private void button_01_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 1);
}
private void button_11_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 1);
}
private void button_21_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 1);
}
private void button_31_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 1);
}
private void button_41_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 1);
}
private void button_51_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 1);
}
private void button_61_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 1);
}
private void button_71_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 1);
}
private void button_02_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 2);
}
private void button_12_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 2);
}
private void button_22_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 2);
}
private void button_32_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 2);
}
private void button_42_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 2);
}
private void button_52_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 2);
}
private void button_62_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 2);
}
private void button_72_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 2);
}
private void button_03_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 3);
}
private void button_13_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 3);
}
private void button_23_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 3);
}
private void button_33_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 3);
}
private void button_43_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 3);
}
private void button_53_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 3);
}
private void button_63_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 3);
}
private void button_73_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 3);
}
private void button_04_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 4);
}
private void button_14_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 4);
}
private void button_24_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 4);
}
private void button_34_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 4);
}
private void button_44_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 4);
}
private void button_54_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 4);
}
private void button_64_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 4);
}
private void button_74_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 4);
}
private void button_05_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 5);
}
private void button_15_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 5);
}
private void button_25_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 5);
}
private void button_35_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 5);
}
private void button_45_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 5);
}
private void button_55_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 5);
}
private void button_65_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 5);
}
private void button_75_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 5);
}
private void button_06_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 6);
}
private void button_16_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 6);
}
private void button_26_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 6);
}
private void button_36_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 6);
}
private void button_46_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 6);
}
private void button_56_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 6);
}
private void button_66_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 6);
}
private void button_76_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 6);
}
private void button_07_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 0, 7);
}
private void button_17_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 1, 7);
}
private void button_27_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 2, 7);
}
private void button_37_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 3, 7);
}
private void button_47_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 4, 7);
}
private void button_57_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 5, 7);
}
private void button_67_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 6, 7);
}
private void button_77_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Grid", 7, 7);
}
#endregion
private void button_Modus_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("ChangeProcessMode", 0, 0);
}
private void button_Bestätigen_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Enter", 0, 0);
this.Close();
}
private void button_Abbruch_Click(object sender, EventArgs e)
{
generator.virtualButtonPress("Cancel", 0, 0);
}
private Color translateButtonColor(virtualButton button)
{
// Translate the intensity and button position with its control needed color
Color usedColor = SystemColors.ControlDarkDark;
ButtonBrightness TempGreen, TempRed;
TempGreen = button.IntensityGreen;
TempRed = button.IntensityRed;
switch (TempGreen.ToString() + TempRed.ToString())
{
#region Yellows
case "33":
//Full+Full
usedColor = stateColors["YellowFull"];
break;
case "22":
//Medium + Medium
usedColor = stateColors["YellowMedium"];
break;
case "11":
//Low + Low
usedColor = stateColors["YellowLow"];
break;
#endregion
#region Greens
case "30":
case "31":
case "32":
//Full Green Variations (No mixvalues allowed -> All become greenFull
usedColor = stateColors["GreenFull"];
break;
case "20":
case "21":
//Medium Green Variations (No mixvalues allowed -> All become greenFull
usedColor = stateColors["GreenMedium"];
break;
case "10":
//Low Green Variations (No mixvalues allowed -> All become greenFull
usedColor = stateColors["GreenLow"];
break;
#endregion
#region Reds
case "03":
case "13":
case "23":
//Full Red Variations (No mixvalues allowed -> All become greenFull
usedColor = stateColors["RedFull"];
break;
case "02":
case "12":
//Medium Red Variations (No mixvalues allowed -> All become greenFull
usedColor = stateColors["RedMedium"];
break;
case "01":
//Low Red Variations (No mixvalues allowed -> All become greenFull
usedColor = stateColors["RedLow"];
break;
#endregion
case "00":
// Off + Off = No Color (Basic Background Color)
usedColor = stateColors["Basic"];
break;
}
return usedColor;
}
}
}