From acae9008af5bb968e0d7742ad24dae6cba67951f Mon Sep 17 00:00:00 2001 From: Noscka Date: Fri, 1 Jul 2022 14:23:35 +0100 Subject: [PATCH] Made Auto Select feature use the DynamicArray --- SWT/Features/Features.cpp | 57 ++++++--------------------------------- SWT/Features/Features.h | 6 +---- SWT/SWT.cpp | 2 +- 3 files changed, 10 insertions(+), 55 deletions(-) diff --git a/SWT/Features/Features.cpp b/SWT/Features/Features.cpp index 034bb59..8296520 100644 --- a/SWT/Features/Features.cpp +++ b/SWT/Features/Features.cpp @@ -1,7 +1,5 @@ #include "Features.h" -#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS - #pragma region GlobalFunctions COORD GlobalFunctions::GetConsoleCursorPosition(HANDLE hConsoleOutput) { @@ -148,75 +146,36 @@ void EquationClass::FinishFeature(KBDLLHOOKSTRUCT kbdStruct) #pragma region Auto Select Region bool AutoSelectClass::Enabled = false; -char *AutoSelectClass::InputStorageArray = new char[InputStorageArraySize](); -int AutoSelectClass::InputStorageArrayIndexPointer = 0; -int AutoSelectClass::InputStorageArraySize = 128; -int AutoSelectClass::ArrayStep = 20; -bool AutoSelectClass::AddToDynamicCharArray(char CharaterToAdd) -{ - try - { - if (InputStorageArrayIndexPointer >= InputStorageArraySize) // if Current Index pointer is more then the array size (trying to add to OutOfRange space) - { - char* TempArray = new char[InputStorageArraySize](); // Create new array which will store the original values - - for (int i = 0; i < InputStorageArraySize; i++) // assign/copy all values from CharArray to Temp - { - TempArray[i] = InputStorageArray[i]; - } - - InputStorageArraySize += ArrayStep; // expand the Array size - InputStorageArray = new char[InputStorageArraySize](); // over ride CharArray with new, bigger, array - - /* - ArraySize-2 calculates TempArray size - Copy all values from Temp array to "old" expanded array - */ - for (int i = 0; i < InputStorageArraySize - ArrayStep; i++) - { - InputStorageArray[i] = TempArray[i]; - } - - delete[] TempArray; - } +DynamicArray AutoSelectClass::InputStorageArray = DynamicArray(20, 10); - InputStorageArray[InputStorageArrayIndexPointer] = CharaterToAdd; - InputStorageArrayIndexPointer++; - } - catch (...) - { - return false; - } - return true; -} void AutoSelectClass::RemovePreviousCharacter() { // Coord for backspace cursor position editing COORD NewCoord; - if (AutoSelectClass::InputStorageArrayIndexPointer > 0) + if (AutoSelectClass::InputStorageArray.ArrayIndexPointer > 0) { NewCoord = { (SHORT)(GlobalFunctions::GetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE)).X - 1), GlobalFunctions::GetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE)).Y }; // create new coord with x-1 and same y SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), NewCoord); // use new coord wprintf(L" "); // delete character SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), NewCoord); // go back 1 space - AutoSelectClass::InputStorageArrayIndexPointer--; + AutoSelectClass::InputStorageArray.ArrayIndexPointer--; } - AutoSelectClass::InputStorageArray[AutoSelectClass::InputStorageArrayIndexPointer] = NULL; + AutoSelectClass::InputStorageArray[AutoSelectClass::InputStorageArray.ArrayIndexPointer] = NULL; } + void AutoSelectClass::FinishFeature(KBDLLHOOKSTRUCT kbdStruct) { GlobalFunctions::clear_screen(); int DirectionCount = 0; - std::string StrInput = AutoSelectClass::InputStorageArray; + std::wstring StrInput = AutoSelectClass::InputStorageArray.GetArray(); if (!StrInput.empty()) { DirectionCount = std::stoi(StrInput); // clear Auto Select array and zero Array Index Pointer - AutoSelectClass::InputStorageArray = new char[AutoSelectClass::InputStorageArraySize](); - AutoSelectClass::InputStorageArrayIndexPointer = 0; + AutoSelectClass::InputStorageArray.Clear(); //keybd_event(VK_SHIFT, (UINT)kbdStruct.scanCode, 0, 0); @@ -236,7 +195,7 @@ void AutoSelectClass::FinishFeature(KBDLLHOOKSTRUCT kbdStruct) AutoSelectClass::Enabled = false; { - std::string temp = "Moved " + std::to_string(DirectionCount) + " Spaces Right" + '\n'; + std::wstring temp = L"Moved " + std::to_wstring(DirectionCount) + L" Spaces Right" + L'\n'; DynamicArray tempArray = DynamicArray(); tempArray.ArrayAppend((wchar_t*)temp.c_str(), temp.length(), false); diff --git a/SWT/Features/Features.h b/SWT/Features/Features.h index 9851d1d..c229308 100644 --- a/SWT/Features/Features.h +++ b/SWT/Features/Features.h @@ -48,12 +48,8 @@ static class AutoSelectClass public: static bool Enabled; - static char* InputStorageArray; // Auto Select Char Array - static int InputStorageArraySize; // InputStorageArray Array Size - static int InputStorageArrayIndexPointer; // Auto Select Array Index Pointer - static int ArrayStep; // how much the array will get increased by when it reaches the limit + static DynamicArray InputStorageArray; // Dynamic Array for function - static bool AddToDynamicCharArray(char Character); static void RemovePreviousCharacter(); static void FinishFeature(KBDLLHOOKSTRUCT kbdStruct); }; diff --git a/SWT/SWT.cpp b/SWT/SWT.cpp index e6024fa..03d4149 100644 --- a/SWT/SWT.cpp +++ b/SWT/SWT.cpp @@ -114,7 +114,7 @@ LRESULT CALLBACK HookCallback(int nCode, WPARAM wParam, LPARAM lParam) case 56: // 8 case 57: // 9 std::wcout << UnicodeCharacter; - AutoSelectClass::AddToDynamicCharArray(UnicodeCharacter[0]); + AutoSelectClass::InputStorageArray.Append(UnicodeCharacter[0]); return -1; case 8: // {BACKSPACE}