<commit_before>﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace osukps {
	public partial class frmMain : Form {

		private const byte MAX_BUTTONS = 10;
		private const byte INITIAL_BUTTONS = 4;
		private KpsHandler kpsHandler;
		private KpsButton[] btns;
		private byte buttonCount;
		private bool settingsModified;
		private uint recordingstate;
		private const string SETTINGS_FILE = "./osukps.ini";

		public frmMain() {
			CultureInfo customCulture = (CultureInfo) Thread.CurrentThread.CurrentCulture.Clone();
			customCulture.NumberFormat.NumberDecimalSeparator = ".";
			Thread.CurrentThread.CurrentCulture = customCulture;

			InitializeComponent();
			InitializeButtonCountComponent();

			FontHandler.labels.Add(lblKps);
			FontHandler.labels.Add(lblTotal);

			tmrProcess.Interval = TIMER_INTERVAL;

			pnlInfo.MouseUp += f_MouseUp;
			pnlInfo.MouseDown += f_MouseDown;
			pnlInfo.MouseMove += f_MouseMove;
			lblTotal.MouseUp += f_MouseUp;
			lblTotal.MouseDown += f_MouseDown;
			lblTotal.MouseMove += f_MouseMove;
			lblKps.MouseUp += f_MouseUp;
			lblKps.MouseDown += f_MouseDown;
			lblKps.MouseMove += f_MouseMove;
			pnlKeys.MouseUp += f_MouseUp;
			pnlKeys.MouseDown += f_MouseDown;
			pnlKeys.MouseMove += f_MouseMove;

			kpsHandler = new KpsHandler(lblKps, lblTotal);
			btns = new KpsButton[MAX_BUTTONS];
			for (int i = 0; i < MAX_BUTTONS; i++) {
				KpsButton n = new KpsButton(i);
				n.settingChangedEvent += n_settingChangedEvent;
				pnlKeys.Controls.Add(n);
				btns[i] = n;
			}
			SetButtonCount(INITIAL_BUTTONS);

			loadSettings();
			if (FontHandler.currentFont == null) {
				FontHandler.resetFont();
			}
		}

		private void InitializeButtonCountComponent() {
			for (int i = 1; i < MAX_BUTTONS + 1; i++) {
				var b = new ToolStripMenuItem() {
					Tag = i,
					Text = i.ToString(),
				};
				b.Click += ButtonCount_Click;
				b.Click += n_settingChangedEvent;
				buttonCountToolStripMenuItem.DropDownItems.Add(b);
			}
		}

		private void ButtonCount_Click(object sender, EventArgs e) {
			SetButtonCount((byte) (int) (sender as ToolStripItem).Tag);
		}

		private void n_settingChangedEvent(object sender, EventArgs e) {
			settingsModified = true;
		}

		#region inidll
		[DllImport("kernel32")]
		private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
		[DllImport("kernel32")]
		private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
		#endregion

		#region dragcodez
		private bool moveForm;
		private Point moveOffset;

		private void f_MouseDown(object sender, MouseEventArgs e) {
			moveForm = true;
			moveOffset = e.Location;
		}

		private void f_MouseUp(object sender, MouseEventArgs e) {
			moveForm = false;
		}

		private void f_MouseMove(object sender, MouseEventArgs e) {
			if (moveForm) {
				this.Location = new Point(this.Location.X + (e.Location.X - moveOffset.X), this.Location.Y + (e.Location.Y - moveOffset.Y));
			}
		}
		#endregion

		private void tmrProcess_Tick(object sender, EventArgs e) {
			byte keyCount = 0;
			uint eventmask = 0;
			for (int i = 0; i < buttonCount; i++) {
				byte state = btns[i].Process();
				keyCount += state;
				eventmask = (eventmask << 1) | state;
			}
			kpsHandler.Update(keyCount);
			UpdateRecord(eventmask);
		}

		private void SetButtonCount(byte buttonCount) {
			this.buttonCount = Math.Max((byte) 1, Math.Min(MAX_BUTTONS, buttonCount));
			for (int i = 0; i < MAX_BUTTONS; i++) {
				btns[i].Visible = (i < this.buttonCount);
			}
			// because autosize derps
			pnlKeys.Size = new Size(buttonCount * 40, 36);
			Size = new Size(pnlKeys.Width + pnlInfo.Width, 36);<commit_msg>fix recording using wrong buttons if buttoncount < 10<commit_after>﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace osukps {
	public partial class frmMain : Form {

		private const byte MAX_BUTTONS = 10;
		private const byte INITIAL_BUTTONS = 4;
		private KpsHandler kpsHandler;
		private KpsButton[] btns;
		private byte buttonCount;
		private bool settingsModified;
		private uint recordingstate;
		private const string SETTINGS_FILE = "./osukps.ini";

		public frmMain() {
			CultureInfo customCulture = (CultureInfo) Thread.CurrentThread.CurrentCulture.Clone();
			customCulture.NumberFormat.NumberDecimalSeparator = ".";
			Thread.CurrentThread.CurrentCulture = customCulture;

			InitializeComponent();
			InitializeButtonCountComponent();

			FontHandler.labels.Add(lblKps);
			FontHandler.labels.Add(lblTotal);

			tmrProcess.Interval = TIMER_INTERVAL;

			pnlInfo.MouseUp += f_MouseUp;
			pnlInfo.MouseDown += f_MouseDown;
			pnlInfo.MouseMove += f_MouseMove;
			lblTotal.MouseUp += f_MouseUp;
			lblTotal.MouseDown += f_MouseDown;
			lblTotal.MouseMove += f_MouseMove;
			lblKps.MouseUp += f_MouseUp;
			lblKps.MouseDown += f_MouseDown;
			lblKps.MouseMove += f_MouseMove;
			pnlKeys.MouseUp += f_MouseUp;
			pnlKeys.MouseDown += f_MouseDown;
			pnlKeys.MouseMove += f_MouseMove;

			kpsHandler = new KpsHandler(lblKps, lblTotal);
			btns = new KpsButton[MAX_BUTTONS];
			for (int i = 0; i < MAX_BUTTONS; i++) {
				KpsButton n = new KpsButton(i);
				n.settingChangedEvent += n_settingChangedEvent;
				pnlKeys.Controls.Add(n);
				btns[i] = n;
			}
			SetButtonCount(INITIAL_BUTTONS);

			loadSettings();
			if (FontHandler.currentFont == null) {
				FontHandler.resetFont();
			}
		}

		private void InitializeButtonCountComponent() {
			for (int i = 1; i < MAX_BUTTONS + 1; i++) {
				var b = new ToolStripMenuItem() {
					Tag = i,
					Text = i.ToString(),
				};
				b.Click += ButtonCount_Click;
				b.Click += n_settingChangedEvent;
				buttonCountToolStripMenuItem.DropDownItems.Add(b);
			}
		}

		private void ButtonCount_Click(object sender, EventArgs e) {
			SetButtonCount((byte) (int) (sender as ToolStripItem).Tag);
		}

		private void n_settingChangedEvent(object sender, EventArgs e) {
			settingsModified = true;
		}

		#region inidll
		[DllImport("kernel32")]
		private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
		[DllImport("kernel32")]
		private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
		#endregion

		#region dragcodez
		private bool moveForm;
		private Point moveOffset;

		private void f_MouseDown(object sender, MouseEventArgs e) {
			moveForm = true;
			moveOffset = e.Location;
		}

		private void f_MouseUp(object sender, MouseEventArgs e) {
			moveForm = false;
		}

		private void f_MouseMove(object sender, MouseEventArgs e) {
			if (moveForm) {
				this.Location = new Point(this.Location.X + (e.Location.X - moveOffset.X), this.Location.Y + (e.Location.Y - moveOffset.Y));
			}
		}
		#endregion

		private void tmrProcess_Tick(object sender, EventArgs e) {
			byte keyCount = 0;
			uint eventmask = 0;
			for (int i = 0; i < buttonCount; i++) {
				byte state = btns[i].Process();
				keyCount += state;
				eventmask = (eventmask << 1) | state;
			}
			eventmask <<= (MAX_BUTTONS - buttonCount);
			kpsHandler.Update(keyCount);
			UpdateRecord(eventmask);
		}

		private void SetButtonCount(byte buttonCount) {
			this.buttonCount = Math.Max((byte) 1, Math.Min(MAX_BUTTONS, buttonCount));
			for (int i = 0; i < MAX_BUTTONS; i++) {
				btns[i].Visible = (i < this.buttonCount);
			}
			// because autosize derps
			pnlKeys.Size = new Size(buttonCount * 40, 36);
			Size = new Size(pnlKeys.Width + pnlInfo.Width, 36);
{'fraction_non_alphanumeric': 0.10933536276002029, 'fraction_numerical': 0.005834601725012684, 'mean_word_length': 3.990506329113924, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '870323', 'n_tokens_mistral': 2973, 'n_tokens_neox': 2571, 'n_words': 613}