From 42d63d972a72540b62e8f5c73427534c2f976690 Mon Sep 17 00:00:00 2001 From: Joseph Lavoie <63205161+Vadenez@users.noreply.github.com> Date: Sun, 10 May 2020 19:43:07 -0600 Subject: [PATCH 1/3] Added 2 void functions. Srry i couldn't figure out the format of cvui.h, so this better work. Also 25% of the time these wouldn't work for me lol. --- inputText.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 inputText.h diff --git a/inputText.h b/inputText.h new file mode 100644 index 0000000..10e0475 --- /dev/null +++ b/inputText.h @@ -0,0 +1,104 @@ +#include "cvui.h" + +using namespace cvui; + +/** +Allows for input via keyboard when inputField is true, no mater where or what you type, it will be placed at the X and Y cords. + +WARNING: this is not good at all, it doesnt always regester your press, infact in my experences it only got about 25% of it. + +\param theWhere frame where its rendered. +\param theX the X cordinate. +\param theY the Y cordinate. +\param millisecondDelay the delay wait for a key press (seems to influence how effective it is), also calculates to FPS (Frames Per Second). +\param theFontScale the size of input text. +\param textColor the color of the text, default is light grey. + +\sa text() +*/ +void inputField(cv::Mat &theWhere, int theX, int theY, int millisecondDelay = 10, double theFontScale = DEFAULT_FONT_SCALE, unsigned int textColor = 0xCECECE) { + + char keyChar; + std::string keyString; + static std::string totalString; + + keyChar = cv::waitKey(millisecondDelay); + + if (std::size(totalString) <= 0 && keyChar == 8 || keyChar == 127) + totalString = totalString; + + else if (keyChar == 8 || keyChar == 127) + totalString.erase(std::prev(totalString.end())); + + else if ((keyChar < 8 || keyChar > 9) && keyChar != 27 && keyChar < 32 && keyChar > 127) + totalString = totalString; + + else if (keyChar != -1) { + + keyString = (1, keyChar); + totalString += keyString; + + } + + cvui::text(theWhere, theX, theY, totalString, theFontScale); +} + +/** +Allows for input via keyboard after you click the area its located, oce clicked anything you type will be placed in the box (Hopefully). + +WARNING: this is not good at all, it doesnt always regester your press, infact in my experences it only got about 25% of it. + +\param theWhere frame where its rendered. +\param theX the X cordinate. +\param theY the Y cordinate. +\param theWidth width of the text box. +\param theHeight height of the text box. +\param millisecondDelay the delay wait for a key press (seems to influence how effective it is), also calculates to FPS (Frames Per Second). +\param theBorderColor color of text box's border in the format `0xRRGGBB`, e.g. `0xff0000` for red. +\param theFillingColor color of rectangle's filling in the format `0xAARRGGBB`, e.g. `0x00ff0000` for red, `0xff000000` for transparent filling. +\param theFontScale the size of input text. +\param textColor the color of the text, default is light grey. + +\sa text() +\sa rect() +\sa iarea() +*/ +void inputBox(cv::Mat& theWhere, int theX, int theY, int theWidth, int theHeight, int millisecondDelay = 10, unsigned int theBorderColor = 0xc9c9c9, unsigned int theFillingColor = 0x676054, double theFontScale = DEFAULT_FONT_SCALE, unsigned int textColor = 0xCECECE) { + + char keyChar; + std::string keyString; + static std::string totalString; + static bool allowInput = false; + + keyChar = cv::waitKey(millisecondDelay); + + rect(theWhere, theX, theY, theWidth, theHeight, theBorderColor, theFillingColor); + + int status = iarea(theX, theY, theWidth, theHeight); + + if (status == OUT && mouse(DOWN)) + allowInput = false; + + else if (status == CLICK) + allowInput = true; + + if (allowInput == true) { + + if (std::size(totalString) <= 0 && keyChar == 8 || keyChar == 127) + totalString = totalString; + + else if (keyChar == 8 || keyChar == 127) + totalString.erase(std::prev(totalString.end())); + + else if ((keyChar < 8 || keyChar > 9) && keyChar != 27 && keyChar < 32 && keyChar > 127) + totalString = totalString; + + else if (keyChar != -1) { + + keyString = (1, keyChar); + totalString += keyString; + + } + } + cvui::text(theWhere, (theX + 5), (theY + (theHeight / 2)), totalString, theFontScale); +} \ No newline at end of file From 766f0dd71af4bf0a21da182163982e86a0c34a16 Mon Sep 17 00:00:00 2001 From: Joseph Lavoie <63205161+Vadenez@users.noreply.github.com> Date: Mon, 11 May 2020 17:09:06 -0600 Subject: [PATCH 2/3] Made better Made both input functions strings, and improved consistancy, bout 60% of the time it gets it right. --- inputText.h | 62 ++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/inputText.h b/inputText.h index 10e0475..a6f58f7 100644 --- a/inputText.h +++ b/inputText.h @@ -5,20 +5,22 @@ using namespace cvui; /** Allows for input via keyboard when inputField is true, no mater where or what you type, it will be placed at the X and Y cords. -WARNING: this is not good at all, it doesnt always regester your press, infact in my experences it only got about 25% of it. +WARNING: It doesnt always regester your press, infact in my experences it only got about 50% of it. + +WARNING: It can't tell the differece between one textBox and another, they will use the same string. \param theWhere frame where its rendered. \param theX the X cordinate. \param theY the Y cordinate. \param millisecondDelay the delay wait for a key press (seems to influence how effective it is), also calculates to FPS (Frames Per Second). \param theFontScale the size of input text. -\param textColor the color of the text, default is light grey. +\param textColor the color of the text. \sa text() */ -void inputField(cv::Mat &theWhere, int theX, int theY, int millisecondDelay = 10, double theFontScale = DEFAULT_FONT_SCALE, unsigned int textColor = 0xCECECE) { +std::string inputField(cv::Mat &theWhere, int theX, int theY, int millisecondDelay = 10, double theFontScale = DEFAULT_FONT_SCALE, unsigned int textColor = 0xCECECE) { - char keyChar; + char key, keyChar; std::string keyString; static std::string totalString; @@ -27,51 +29,52 @@ void inputField(cv::Mat &theWhere, int theX, int theY, int millisecondDelay = 10 if (std::size(totalString) <= 0 && keyChar == 8 || keyChar == 127) totalString = totalString; - else if (keyChar == 8 || keyChar == 127) - totalString.erase(std::prev(totalString.end())); - else if ((keyChar < 8 || keyChar > 9) && keyChar != 27 && keyChar < 32 && keyChar > 127) totalString = totalString; + else if (keyChar == 8 || keyChar == 127) + totalString.erase(std::prev(totalString.end())); + else if (keyChar != -1) { keyString = (1, keyChar); totalString += keyString; } - + cvui::text(theWhere, theX, theY, totalString, theFontScale); + + return totalString; } /** Allows for input via keyboard after you click the area its located, oce clicked anything you type will be placed in the box (Hopefully). -WARNING: this is not good at all, it doesnt always regester your press, infact in my experences it only got about 25% of it. +WARNING: It doesnt always regester your press, infact in my experences it only got about 50% of it. + +WARNING: It can't tell the differece between one textBox and another, they will use the same string. \param theWhere frame where its rendered. \param theX the X cordinate. \param theY the Y cordinate. +\param textY helps align text into the text box \param theWidth width of the text box. \param theHeight height of the text box. -\param millisecondDelay the delay wait for a key press (seems to influence how effective it is), also calculates to FPS (Frames Per Second). +\param millisecondDelay the delay wait for a key press (seems to influence how effective typing is), also calculates to FPS (Frames Per Second). \param theBorderColor color of text box's border in the format `0xRRGGBB`, e.g. `0xff0000` for red. \param theFillingColor color of rectangle's filling in the format `0xAARRGGBB`, e.g. `0x00ff0000` for red, `0xff000000` for transparent filling. \param theFontScale the size of input text. -\param textColor the color of the text, default is light grey. +\param textColor the color of the text. -\sa text() -\sa rect() +\sa inputField() \sa iarea() +\sa rect() +\sa text() */ -void inputBox(cv::Mat& theWhere, int theX, int theY, int theWidth, int theHeight, int millisecondDelay = 10, unsigned int theBorderColor = 0xc9c9c9, unsigned int theFillingColor = 0x676054, double theFontScale = DEFAULT_FONT_SCALE, unsigned int textColor = 0xCECECE) { - - char keyChar; - std::string keyString; - static std::string totalString; +std::string inputBox(cv::Mat& theWhere, int theX, int theY, int textY, int theWidth, int theHeight, int millisecondDelay = 10, unsigned int theBorderColor = 0xc9c9c9, unsigned int theFillingColor = 0x676054, double theFontScale = DEFAULT_FONT_SCALE, unsigned int textColor = 0xCECECE) { + static std::string totalStr; static bool allowInput = false; - keyChar = cv::waitKey(millisecondDelay); - rect(theWhere, theX, theY, theWidth, theHeight, theBorderColor, theFillingColor); int status = iarea(theX, theY, theWidth, theHeight); @@ -84,21 +87,12 @@ void inputBox(cv::Mat& theWhere, int theX, int theY, int theWidth, int theHeight if (allowInput == true) { - if (std::size(totalString) <= 0 && keyChar == 8 || keyChar == 127) - totalString = totalString; - - else if (keyChar == 8 || keyChar == 127) - totalString.erase(std::prev(totalString.end())); + totalStr = (inputField(theWhere, (theX + 5), textY, millisecondDelay, theFontScale, textColor)); - else if ((keyChar < 8 || keyChar > 9) && keyChar != 27 && keyChar < 32 && keyChar > 127) - totalString = totalString; + } - else if (keyChar != -1) { + cvui::text(theWhere, (theX + 5), textY, totalStr, theFontScale); - keyString = (1, keyChar); - totalString += keyString; - } - } - cvui::text(theWhere, (theX + 5), (theY + (theHeight / 2)), totalString, theFontScale); -} \ No newline at end of file + return totalStr; +} From 5edb0cab403db945edee5b1b9eff665dedff6d40 Mon Sep 17 00:00:00 2001 From: Joseph Lavoie <63205161+Vadenez@users.noreply.github.com> Date: Mon, 11 May 2020 17:40:39 -0600 Subject: [PATCH 3/3] removed unneeded char --- inputText.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inputText.h b/inputText.h index a6f58f7..1f4837b 100644 --- a/inputText.h +++ b/inputText.h @@ -20,7 +20,7 @@ WARNING: It can't tell the differece between one textBox and another, they will */ std::string inputField(cv::Mat &theWhere, int theX, int theY, int millisecondDelay = 10, double theFontScale = DEFAULT_FONT_SCALE, unsigned int textColor = 0xCECECE) { - char key, keyChar; + char keyChar; std::string keyString; static std::string totalString;