Skip to content

Commit

Permalink
Made Auto Select feature use the DynamicArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Noscka committed Jul 1, 2022
1 parent 382bcb5 commit acae900
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 55 deletions.
57 changes: 8 additions & 49 deletions SWT/Features/Features.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "Features.h"

#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS

#pragma region GlobalFunctions
COORD GlobalFunctions::GetConsoleCursorPosition(HANDLE hConsoleOutput)
{
Expand Down Expand Up @@ -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<wchar_t> AutoSelectClass::InputStorageArray = DynamicArray<wchar_t>(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);

Expand All @@ -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<wchar_t> tempArray = DynamicArray<wchar_t>();
tempArray.ArrayAppend((wchar_t*)temp.c_str(), temp.length(), false);
Expand Down
6 changes: 1 addition & 5 deletions SWT/Features/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<wchar_t> InputStorageArray; // Dynamic Array for function

static bool AddToDynamicCharArray(char Character);
static void RemovePreviousCharacter();
static void FinishFeature(KBDLLHOOKSTRUCT kbdStruct);
};
Expand Down
2 changes: 1 addition & 1 deletion SWT/SWT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit acae900

Please sign in to comment.