├── MenuConsoleKey ├── head.h ├── ConsoleMenu.vcxproj.user ├── ConsoleMenu.vcxproj.filters ├── Demo.cpp ├── Objetos.h ├── objetos.h ├── Main.cpp ├── Cars.hpp ├── snake.hpp ├── TiroTorre.hpp ├── ConsoleMenu.vcxproj ├── Objetos.cpp └── objetos.cpp ├── .gitignore ├── LICENSE └── README.md /MenuConsoleKey/head.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "objetos.h" -------------------------------------------------------------------------------- /MenuConsoleKey/ConsoleMenu.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 SrShadowy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### MiniMenuConsoleAplication 2 | 3 | [GitHub Sponsors](https://github.com/SrShadowy) 4 | [![forthebadge](https://forthebadge.com/images/badges/made-with-c-plus-plus.svg)](https://forthebadge.com) 5 | 6 | *Um menu em c++ sem muita pespectiva. 7 | mas funcional* 8 | 9 | ![Ilustrativo](https://i.imgur.com/Eka8veq.gif) 10 | 11 | ![Movimentando](https://i.imgur.com/Wat5jfH.gif) 12 | 13 | **Como usar** 14 | 15 | CADA UM OBJETO É UM TIPO DE INTERAÇÃO PARA O USUÁRIO, CHECKBOX, TEXTEDIT, TRACKBAR, COMBOBOX E PROGRESSBAR; 16 | 17 | Declaração dos objetos: 18 | NOME, **Func* & *Id** 19 | 20 | **NOME** é o unico **Obrigatorio** em todos. 21 | 22 | | Operating Systems | Supported 32-bit | Supported 64-bit | 23 | |:-------------------:|:----------------:|:----------------:| 24 | | Windows 10 | ✔ | ✔ | 25 | 26 | 27 | 28 | ###### ex: 29 | ```Cpp 30 | checkbox checkbox1("caixa1"); 31 | checkbox checkbox2("checked", true); 32 | TextEdit text1("Texto","Shadowy"); 33 | TrackBar trackbar1("Num", 0, 10); 34 | ComboBox cb1("Textos"); 35 | ``` 36 | 37 | Editar valor: 38 | ** use a função .ChangeValue(int pos); 39 | 40 | Pos = Posição atual dos objetos:** 41 | 42 | - [x] Se a posição for igual o id. 43 | 44 | - [ ] Se a posição for diferente do id. 45 | 46 | se a posição for igual o id do objeto ele é marcado assim como também é possivel alterar. 47 | -------------------------------------------------------------------------------- /MenuConsoleKey/ConsoleMenu.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Arquivos de Origem 20 | 21 | 22 | Arquivos de Origem 23 | 24 | 25 | 26 | 27 | Arquivos de Cabeçalho 28 | 29 | 30 | Arquivos de Cabeçalho 31 | 32 | 33 | -------------------------------------------------------------------------------- /MenuConsoleKey/Demo.cpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | #include "TiroTorre.hpp" 3 | #include "snake.hpp" 4 | #include "Cars.hpp" 5 | 6 | 7 | int main() 8 | { 9 | 10 | 11 | 12 | 13 | bool change = true; 14 | int pos = 0; 15 | int max = 0; 16 | bool menu = true; 17 | while (menu) 18 | { 19 | if (change) 20 | { 21 | int i = 0; 22 | std::cout << "\t Demo menu"; 23 | square(30, 5, 2, 0, 1); 24 | setCursorPosition(3, 2); 25 | 26 | pos == i ? std::cout << "> " << "Cars" << std::endl 27 | : std::cout << " " << "Cars" << std::endl; 28 | 29 | ++i; 30 | 31 | setCursorPosition(3, 3); 32 | 33 | pos == i ? std::cout << "> " << "Snake" << std::endl 34 | : std::cout << " " << "Snake" << std::endl; 35 | 36 | ++i; 37 | 38 | setCursorPosition(3, 4); 39 | 40 | pos == i ? std::cout << "> " << "Nave" << std::endl 41 | : std::cout << " " << "Nave" << std::endl; 42 | 43 | ++i; 44 | 45 | setCursorPosition(3, 5); 46 | 47 | pos == i ? std::cout << "> " << "Sair" << std::endl 48 | : std::cout << " " << "Sair" << std::endl; 49 | 50 | std::cout.flush(); 51 | max = i; 52 | change = false; 53 | } 54 | 55 | if (GetAsyncKeyState(VK_UP)) 56 | { 57 | --pos; 58 | if (pos < 0) 59 | pos = max; 60 | change = true; 61 | } 62 | if (GetAsyncKeyState(VK_DOWN)) 63 | { 64 | ++pos; 65 | if (pos > max) 66 | pos = 0; 67 | change = true; 68 | } 69 | 70 | if (GetAsyncKeyState(VK_RETURN)) 71 | { 72 | if ( pos == 0 ) 73 | MenuCar(); 74 | if (pos == 1) 75 | menu_snake(); 76 | if (pos == 2) 77 | Menu_tiro(); 78 | if (pos == max) menu = !menu; 79 | change = true; 80 | } 81 | 82 | 83 | Sleep(100); 84 | } 85 | cls(); 86 | 87 | 88 | std::cin.get(); 89 | 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /MenuConsoleKey/Objetos.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | void ExConsole(); 3 | void setCursorPosition(int x, int y); 4 | void setConsoleColour(unsigned short colour); 5 | void cls(); 6 | void helpQuard(); 7 | void square(int width, int hight, int type, int posX, int posY); 8 | void help(); 9 | 10 | class checkbox 11 | { 12 | public: 13 | checkbox(std::string name, bool check, int id); 14 | checkbox(std::string name, bool check); 15 | checkbox(std::string name); 16 | 17 | void show(int pos); 18 | void ChangeValue(int pos); 19 | 20 | std::string name; bool check; 21 | private: 22 | int id; 23 | 24 | }; 25 | 26 | class TextEdit 27 | { 28 | public: 29 | TextEdit(std::string textedit, int lenght, std::string buffer, int id); 30 | TextEdit(std::string textedit, std::string buffer); 31 | TextEdit(std::string textedit, int lenght); 32 | 33 | void show(int pos); 34 | void changeValue(int pos); 35 | 36 | std::string name; size_t length; 37 | private: 38 | std::string buffer; 39 | int id; 40 | }; 41 | 42 | class TrackBar 43 | { 44 | public: 45 | TrackBar(std::string textBar, int min, int max, int value, UINT32 id); 46 | TrackBar(std::string textBar, int min, int max, UINT32 id); 47 | TrackBar(std::string textBar, int min, int max); 48 | void Show(int pos); 49 | void changeValue(int pos); 50 | std::string name; int value; 51 | private: 52 | int max, min; 53 | int id; 54 | }; 55 | 56 | class ComboBox 57 | { 58 | public: 59 | ComboBox(std::string name, std::vectorlist, std::string text, UINT id); 60 | ComboBox(std::string name, UINT id); 61 | ComboBox(std::string name); 62 | void Show(int pos); 63 | void ChangeValue(int pos); 64 | 65 | std::vectorlist; 66 | std::string text; 67 | private: 68 | UINT id; 69 | std::string name; 70 | 71 | 72 | }; 73 | 74 | class ProgressBar 75 | { 76 | public: 77 | ProgressBar(std::string name, float value, UINT id); 78 | ProgressBar(std::string name, float value); 79 | ProgressBar(std::string name); 80 | void Show(int pos); 81 | void ChangeValue(int pos); 82 | 83 | float value; 84 | 85 | 86 | private: 87 | UINT id; 88 | float max = 100.0f; 89 | float min = 0.0f; 90 | 91 | std::string name; 92 | }; 93 | 94 | 95 | class timer 96 | { 97 | private: 98 | uint64_t internal_tick = 0; 99 | uint32_t interval = 0; 100 | bool enable = true; 101 | bool tick_count = false; 102 | void tick() 103 | { 104 | if (enable) 105 | tick_count = (GetTickCount64() > internal_tick); 106 | else 107 | tick_count = false; 108 | 109 | if (tick_count) 110 | internal_tick = GetTickCount64() + interval; 111 | } 112 | 113 | public: 114 | 115 | timer() 116 | { 117 | timer::interval = 100; 118 | timer::enable = true; 119 | internal_tick = GetTickCount64() + interval; 120 | } 121 | 122 | timer(int interval, bool enable) 123 | { 124 | timer::interval = interval; 125 | timer::enable = enable; 126 | internal_tick = GetTickCount64() + interval; 127 | } 128 | 129 | // check_tick 130 | bool timer_on() 131 | { 132 | tick(); 133 | return tick_count; 134 | } 135 | // stop tick 136 | void stop() 137 | { 138 | enable = false; 139 | } 140 | // start again 141 | void start() 142 | { 143 | enable = true; 144 | } 145 | // change interval 146 | void set_new_interval(int new_interval) 147 | { 148 | interval = new_interval; 149 | } 150 | }; -------------------------------------------------------------------------------- /MenuConsoleKey/objetos.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | void ExConsole(); 3 | void setCursorPosition(int x, int y); 4 | void setConsoleColour(unsigned short colour); 5 | void cls(); 6 | void helpQuard(); 7 | void square(int width, int hight, int type, int posX, int posY); 8 | void help(); 9 | 10 | class checkbox 11 | { 12 | public: 13 | checkbox(std::string name, bool check, int id); 14 | checkbox(std::string name, bool check); 15 | checkbox(std::string name); 16 | 17 | void show(int pos); 18 | void ChangeValue(int pos); 19 | 20 | std::string name; bool check; 21 | private: 22 | int id; 23 | 24 | }; 25 | 26 | class TextEdit 27 | { 28 | public: 29 | TextEdit(std::string textedit, int lenght, std::string buffer, int id); 30 | TextEdit(std::string textedit, std::string buffer); 31 | TextEdit(std::string textedit, int lenght); 32 | 33 | void show(int pos); 34 | void changeValue(int pos); 35 | 36 | std::string name; size_t length; 37 | private: 38 | std::string buffer; 39 | int id; 40 | }; 41 | 42 | class TrackBar 43 | { 44 | public: 45 | TrackBar(std::string textBar, int min, int max, int value, UINT32 id); 46 | TrackBar(std::string textBar, int min, int max, UINT32 id); 47 | TrackBar(std::string textBar, int min, int max); 48 | void Show(int pos); 49 | void changeValue(int pos); 50 | std::string name; int value; 51 | private: 52 | int max, min; 53 | int id; 54 | }; 55 | 56 | class ComboBox 57 | { 58 | public: 59 | ComboBox(std::string name, std::vectorlist, std::string text, UINT id); 60 | ComboBox(std::string name, UINT id); 61 | ComboBox(std::string name); 62 | void Show(int pos); 63 | void ChangeValue(int pos); 64 | 65 | std::vectorlist; 66 | std::string text; 67 | private: 68 | UINT id; 69 | std::string name; 70 | 71 | 72 | }; 73 | 74 | class ProgressBar 75 | { 76 | public: 77 | ProgressBar(std::string name, float value, UINT id); 78 | ProgressBar(std::string name, float value); 79 | ProgressBar(std::string name); 80 | void Show(int pos); 81 | void ChangeValue(int pos); 82 | 83 | float value; 84 | 85 | 86 | private: 87 | UINT id; 88 | float max = 100.0f; 89 | float min = 0.0f; 90 | 91 | std::string name; 92 | }; 93 | 94 | 95 | class timer 96 | { 97 | private: 98 | uint64_t internal_tick = 0; 99 | uint32_t interval = 0; 100 | bool enable = true; 101 | bool tick_count = false; 102 | void tick() 103 | { 104 | if (enable) 105 | tick_count = (GetTickCount64() > internal_tick); 106 | else 107 | tick_count = false; 108 | 109 | if (tick_count) 110 | internal_tick = GetTickCount64() + interval; 111 | } 112 | 113 | public: 114 | 115 | timer() 116 | { 117 | timer::interval = 100; 118 | timer::enable = true; 119 | internal_tick = GetTickCount64() + interval; 120 | } 121 | 122 | timer(int interval, bool enable) 123 | { 124 | timer::interval = interval; 125 | timer::enable = enable; 126 | internal_tick = GetTickCount64() + interval; 127 | } 128 | 129 | // check_tick 130 | bool timer_on() 131 | { 132 | tick(); 133 | return tick_count; 134 | } 135 | // stop tick 136 | void stop() 137 | { 138 | enable = false; 139 | } 140 | // start again 141 | void start() 142 | { 143 | enable = true; 144 | } 145 | // change interval 146 | void set_new_interval(int new_interval) 147 | { 148 | interval = new_interval; 149 | } 150 | }; -------------------------------------------------------------------------------- /MenuConsoleKey/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | const char* space = "\t\t"; 3 | HWND console = nullptr; 4 | POINT PosConsole = { 200,200 }; 5 | POINT sizeConsole = { 300,200 }; 6 | 7 | void move_console(int pos, int max) 8 | { 9 | if (pos == max) 10 | { 11 | system("cls"); 12 | std::cout << "\nUSE ARRAW TO MOVE CONSOLE\nSpace increcent the speed\nAND USE F2 TO EXIT MOVE"; 13 | bool finish = false; 14 | while (!finish) 15 | { 16 | SetWindowPos(console, NULL, PosConsole.x, PosConsole.y, sizeConsole.x , sizeConsole.y, NULL); 17 | int speed = 1; 18 | if (GetAsyncKeyState(VK_SPACE)) 19 | speed += 2; 20 | 21 | if (GetAsyncKeyState(VK_UP)) 22 | PosConsole.y -= speed; 23 | 24 | if (GetAsyncKeyState(VK_DOWN)) 25 | ++PosConsole.y += speed; 26 | 27 | 28 | if (GetAsyncKeyState(VK_RIGHT)) 29 | PosConsole.x += speed; 30 | 31 | if (GetAsyncKeyState(VK_LEFT)) 32 | PosConsole.x -= speed; 33 | 34 | if (GetAsyncKeyState(VK_F2)) 35 | finish = true; 36 | Sleep(1); 37 | } 38 | } 39 | } 40 | 41 | void loading() 42 | { 43 | ProgressBar prog("", 0, 0); 44 | bool exit = true; 45 | while (exit) 46 | { 47 | //cls(); 48 | setCursorPosition(0, 0); 49 | if (prog.value < 25) 50 | setConsoleColour(0x4); 51 | else if (prog.value < 50) 52 | setConsoleColour(0xE); 53 | else 54 | setConsoleColour(0xA); 55 | 56 | std::cout << "LOADING..." << std::endl; 57 | prog.Show(0); 58 | Sleep(10); 59 | prog.ChangeValue(0); 60 | std::cout.flush(); 61 | if (prog.value == 100.0F) 62 | exit = false; 63 | } 64 | 65 | } 66 | 67 | void menu() 68 | { 69 | cls(); 70 | 71 | //Exemple :) 72 | setConsoleColour(0x7); 73 | bool change = true; 74 | bool finish = false; 75 | int pos = 0; 76 | int max = 0; 77 | checkbox checkbox1("caixa1"); 78 | checkbox checkbox2("checked", true); 79 | TextEdit text1("Texto","Shadowy"); 80 | TrackBar trackbar1("Num", 0, 10); 81 | ComboBox cb1("Textos"); 82 | timer tmr1(100, true); 83 | 84 | while (!finish) 85 | { 86 | if (tmr1.timer_on()) 87 | { 88 | if (change) 89 | { 90 | square(30, 9, 1, 0, 0); 91 | setCursorPosition(8, 0); 92 | size_t i = 0; 93 | setConsoleColour(FOREGROUND_BLUE); 94 | std::cout << "Menu\r"; 95 | setCursorPosition(10, 1); 96 | setConsoleColour(FOREGROUND_RED); 97 | std::cout << "Shadowy\r"; 98 | setConsoleColour(0x7); 99 | std::cout << std::endl; 100 | setCursorPosition(2, 2); 101 | checkbox1.show(pos); 102 | ++i; 103 | setCursorPosition(2, 3); 104 | checkbox2.show(pos); 105 | ++i; 106 | setCursorPosition(2, 4); 107 | text1.show(pos); 108 | ++i; 109 | setCursorPosition(2, 5); 110 | trackbar1.Show(pos); 111 | ++i; 112 | setCursorPosition(2, 6); 113 | cb1.Show(pos); 114 | ++i; 115 | setCursorPosition(2, 7); 116 | pos == i ? std::cout << "> " << "MOVE MENU" << std::endl 117 | : std::cout << " " << "MOVE MENU" << std::endl; 118 | ++i; 119 | setCursorPosition(2, 8); 120 | pos == i ? std::cout << "> " << "Exit" << std::endl 121 | : std::cout << " " << "Exit" << std::endl; 122 | std::cout.flush(); 123 | 124 | max = i; 125 | change = false; 126 | } 127 | 128 | if (GetAsyncKeyState(VK_UP)) 129 | { 130 | --pos; 131 | if (pos < 0) 132 | pos = max; 133 | change = true; 134 | } 135 | if (GetAsyncKeyState(VK_DOWN)) 136 | { 137 | ++pos; 138 | if (pos > max) 139 | pos = 0; 140 | change = true; 141 | } 142 | if (GetAsyncKeyState(VK_RIGHT)) 143 | { 144 | checkbox1.ChangeValue(pos); 145 | checkbox2.ChangeValue(pos); 146 | text1.changeValue(pos); 147 | trackbar1.changeValue(pos); 148 | cb1.ChangeValue(pos); 149 | move_console(pos, max - 1); 150 | pos == max ? finish = true : finish = false; 151 | change = true; 152 | } 153 | 154 | 155 | setCursorPosition(15, 8); 156 | setConsoleColour(FOREGROUND_BLUE); 157 | std::cout << "Menu"; 158 | setCursorPosition(16, 9); 159 | setConsoleColour(FOREGROUND_RED); 160 | std::cout << "Shadowy"; 161 | setConsoleColour(0x7); 162 | std::cout.flush(); 163 | } 164 | Sleep(1); 165 | } 166 | } 167 | 168 | int main() 169 | { 170 | console = GetConsoleWindow(); 171 | SetWindowPos(console, NULL, PosConsole.x, PosConsole.y, sizeConsole.x, sizeConsole.y, NULL); 172 | SetWindowLong(console, GWL_STYLE, WS_BORDER ); 173 | ShowWindow(console, SW_SHOW); 174 | ExConsole(); 175 | loading(); 176 | menu(); 177 | return 0; 178 | } -------------------------------------------------------------------------------- /MenuConsoleKey/Cars.hpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | 3 | POINT Tam; 4 | POINT sq = { 40,45 }; 5 | POINT gamePos; 6 | int points = 0; 7 | int position = 5; 8 | 9 | 10 | POINT PlayerPos; 11 | int vidaPlayer = 3; 12 | void playercar() 13 | { 14 | setCursorPosition(PlayerPos.x, gamePos.y); 15 | setConsoleColour(0x4); 16 | std::cout << "#"; 17 | setCursorPosition(PlayerPos.x - 1, gamePos.y + 1); 18 | std::cout << "###"; 19 | setCursorPosition(PlayerPos.x, gamePos.y + 2); 20 | std::cout << "#"; 21 | setCursorPosition(PlayerPos.x - 1, gamePos.y + 3); 22 | std::cout << "# #"; 23 | } 24 | 25 | 26 | void maximize_window() 27 | { 28 | HWND consoleWindow = GetConsoleWindow(); 29 | ShowWindow(consoleWindow, SW_MAXIMIZE); 30 | } 31 | 32 | class EnimyCar 33 | { 34 | public: 35 | EnimyCar(); 36 | void Run(); 37 | void destroyme(); 38 | int y = sq.y - (sq.y - 2); 39 | int velo = 1; 40 | 41 | private: 42 | int pox_max = sq.x; 43 | int pox_min = sq.x - (sq.x - 3); 44 | int x = rand() % pox_max + pox_min; 45 | }; 46 | 47 | 48 | EnimyCar::EnimyCar() 49 | { 50 | 51 | 52 | } 53 | 54 | void EnimyCar::Run() 55 | { 56 | 57 | setCursorPosition(x, y); 58 | setConsoleColour(0x3C); 59 | std::cout << "#"; 60 | setCursorPosition(x - 1, y + 1); 61 | std::cout << "###"; 62 | setCursorPosition(x, y + 2); 63 | std::cout << "#"; 64 | setCursorPosition(x - 1, y + 3); 65 | std::cout << "###"; 66 | y += velo; 67 | 68 | if (GetAsyncKeyState(VK_UP)) y += 1; 69 | 70 | if ((y + 2) >= PlayerPos.y && x <= PlayerPos.x + 2 && x >= PlayerPos.x - 2) 71 | { 72 | --vidaPlayer; 73 | destroyme(); 74 | } 75 | 76 | if (y >= sq.y) 77 | destroyme(); 78 | 79 | } 80 | 81 | void EnimyCar::destroyme() 82 | { 83 | y = sq.y - (sq.y - 2); 84 | pox_max = sq.x - 2; 85 | pox_min = sq.x - (sq.x - 3); 86 | x = rand() % pox_max + pox_min; 87 | points += 2; 88 | } 89 | 90 | 91 | 92 | int x = 0; 93 | EnimyCar Car1; 94 | EnimyCar Car2; 95 | EnimyCar Car3; 96 | EnimyCar Car4; 97 | EnimyCar Car5; 98 | bool loser = true; 99 | 100 | void DrawnPist() 101 | { 102 | setCursorPosition(5, 1); 103 | std::cout << "Pontos: " << points << " Vidas: " << vidaPlayer; 104 | square(sq.x, sq.y, 2, 1, 2); 105 | Car1.Run(); 106 | if (points > 20) 107 | Car2.Run(); 108 | if (points > 50) 109 | Car3.Run(); 110 | if (points > 250) 111 | Car4.Run(); 112 | if (points > 550) 113 | Car5.Run(); 114 | 115 | playercar(); 116 | if (GetAsyncKeyState(VK_RIGHT)) 117 | { 118 | ++PlayerPos.x; 119 | if (PlayerPos.x >= sq.x) PlayerPos.x = sq.x; 120 | } 121 | 122 | if (GetAsyncKeyState(VK_LEFT)) 123 | { 124 | --PlayerPos.x; 125 | if (PlayerPos.x <= sq.x - (sq.x - 3)) PlayerPos.x = sq.x - (sq.x - 3); 126 | } 127 | 128 | 129 | 130 | std::cout.flush(); 131 | } 132 | 133 | 134 | void game_car() 135 | { 136 | 137 | Car2.velo = 2; 138 | Car3.velo = 4; 139 | Car4.velo = 2; 140 | Car5.velo = 4; 141 | while (loser) 142 | { 143 | srand((unsigned)time(NULL)); 144 | DrawnPist(); 145 | setConsoleColour(0xA0); 146 | vidaPlayer <= 0 ? loser = false : loser = true; 147 | 148 | Sleep(50); 149 | } 150 | cls(); 151 | std::cout << "Voce perdeu\nSua pontacao eh: " << points; 152 | } 153 | 154 | void MenuCar() 155 | { 156 | 157 | cls(); 158 | 159 | maximize_window(); 160 | Tam.x = 2; 161 | Tam.y = 2; 162 | gamePos.x = (sq.x / 2); 163 | gamePos.y = (sq.y - 4); 164 | PlayerPos.x = gamePos.x; 165 | PlayerPos.y = gamePos.y; 166 | TrackBar CarVida("Vidas", 1, 10); 167 | 168 | bool change = true; 169 | int pos = 0; 170 | int max = 0; 171 | bool menu = true; 172 | while (menu) 173 | { 174 | if (change) 175 | { 176 | int i = 0; 177 | std::cout << "\t Game de carrinhos"; 178 | square(30, 4, 2, 0, 1); 179 | setCursorPosition(3, 2); 180 | CarVida.Show(pos); 181 | ++i; 182 | 183 | setCursorPosition(3, 4); 184 | pos == i ? std::cout << "> " << "Start" << std::endl 185 | : std::cout << " " << "Start" << std::endl; 186 | 187 | std::cout.flush(); 188 | max = i; 189 | change = false; 190 | } 191 | 192 | if (GetAsyncKeyState(VK_UP)) 193 | { 194 | --pos; 195 | if (pos < 0) 196 | pos = max; 197 | change = true; 198 | } 199 | if (GetAsyncKeyState(VK_DOWN)) 200 | { 201 | ++pos; 202 | if (pos > max) 203 | pos = 0; 204 | change = true; 205 | } 206 | 207 | if (GetAsyncKeyState(VK_RETURN)) 208 | { 209 | CarVida.changeValue(pos); 210 | vidaPlayer = CarVida.value; 211 | 212 | if (pos == max) menu = !menu; 213 | change = true; 214 | } 215 | 216 | 217 | Sleep(100); 218 | } 219 | cls(); 220 | game_car(); 221 | } -------------------------------------------------------------------------------- /MenuConsoleKey/snake.hpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | //My Vars 3 | bool atravessar = true; 4 | bool cobra_tail = false; 5 | int vida = 1; 6 | int score = 0; 7 | 8 | int drawnX = 30; 9 | int drawnY = 15; 10 | 11 | //Snake vars 12 | POINT playerPos = { drawnX / 2,drawnY / 2 }; 13 | bool positions[4] = {}; 14 | int tam = 1; 15 | std::vector posX; 16 | std::vector posY; 17 | int anteriorX, anteriorX2; 18 | int anteriorY, anteriorY2; 19 | 20 | 21 | void player() 22 | { 23 | if (atravessar) 24 | { 25 | if (playerPos.x >= drawnX + 1) 26 | playerPos.x = 2; 27 | if (playerPos.y >= drawnY + 1) 28 | playerPos.y = 2; 29 | 30 | if (playerPos.x <= 1) 31 | playerPos.x = drawnX; 32 | if (playerPos.y <= 1) 33 | playerPos.y = drawnY; 34 | } 35 | else 36 | { 37 | if (playerPos.x >= drawnX || playerPos.x <= 0 || playerPos.y >= drawnY || playerPos.y <= 0) 38 | { 39 | --vida; 40 | playerPos = { drawnX / 2,drawnY / 2 }; 41 | } 42 | for (int i = 0; i < tam; ++i) 43 | if (playerPos.x == posX[i] && playerPos.y == posY[i]) 44 | --vida; 45 | } 46 | 47 | setCursorPosition(playerPos.x, playerPos.y); 48 | setConsoleColour(0xE); 49 | std::cout << "*"; 50 | 51 | 52 | if (cobra_tail) 53 | { 54 | 55 | } 56 | 57 | anteriorX = posX[0]; 58 | anteriorY = posY[0]; 59 | posX[0] = playerPos.x; 60 | posY[0] = playerPos.y; 61 | 62 | for (int i = 1; i < tam; i++) 63 | { 64 | setCursorPosition(anteriorX, anteriorY); 65 | std::cout << '#'; 66 | 67 | anteriorX2 = posX[i]; 68 | anteriorY2 = posY[i]; 69 | posX[i] = anteriorX; 70 | posY[i] = anteriorY; 71 | anteriorX = anteriorX2; 72 | anteriorY = anteriorY2; 73 | 74 | } 75 | 76 | std::cout.flush(); 77 | } 78 | 79 | int xFrute = rand() % (drawnX - 2) + 1; 80 | int yFrute = rand() % (drawnY - 2) + 1; 81 | 82 | void frute(POINT player) 83 | { 84 | setCursorPosition(xFrute, yFrute); 85 | setConsoleColour(0xC); 86 | std::cout << 'o'; 87 | if (player.x == xFrute and player.y == yFrute) 88 | { 89 | score += 5; 90 | ++tam; 91 | posX.push_back(0); 92 | posY.push_back(0); 93 | xFrute = rand() % (drawnX - 2) + 2; 94 | yFrute = rand() % (drawnY - 2) + 2; 95 | } 96 | std::cout.flush(); 97 | } 98 | 99 | void snake() 100 | { 101 | 102 | posX.push_back(0); 103 | positions[2] = true; 104 | posY.push_back(0); 105 | srand((unsigned)time(NULL)); 106 | //square(35, 15, 1, 1, 1); 107 | bool pause = true; 108 | bool quit = true; 109 | while (quit) 110 | { 111 | 112 | if (GetAsyncKeyState('p') || GetAsyncKeyState('P')) 113 | pause = !pause; 114 | 115 | setCursorPosition(0, 0); 116 | std::cout << " Vida: " << vida << "\t\tPontos: " << score; 117 | if (pause) 118 | { 119 | square(drawnX, drawnY, 2, 0, 1); 120 | 121 | 122 | if (vida <= 0) 123 | quit = false; 124 | 125 | if (GetAsyncKeyState(VK_UP)) 126 | { 127 | for (int i = 0; i < 4; ++i) positions[i] = false; 128 | positions[0] = true; 129 | } 130 | 131 | if (GetAsyncKeyState(VK_DOWN)) 132 | { 133 | for (int i = 0; i < 4; ++i) positions[i] = false; 134 | positions[1] = true; 135 | } 136 | 137 | if (GetAsyncKeyState(VK_RIGHT)) 138 | { 139 | for (int i = 0; i < 4; ++i) positions[i] = false; 140 | positions[2] = true; 141 | } 142 | 143 | if (GetAsyncKeyState(VK_LEFT)) 144 | { 145 | for (int i = 0; i < 4; ++i) positions[i] = false; 146 | positions[3] = true; 147 | } 148 | 149 | 150 | if (positions[0]) //Up 151 | --playerPos.y; 152 | if (positions[1]) //Down 153 | ++playerPos.y; 154 | if (positions[2]) //Esquerda 155 | ++playerPos.x; 156 | if (positions[3]) //Direita 157 | --playerPos.x; 158 | 159 | 160 | player(); 161 | frute(playerPos); 162 | } 163 | std::cout.flush(); 164 | Sleep(50); 165 | } 166 | 167 | } 168 | 169 | 170 | void menu_snake() 171 | { 172 | cls(); 173 | bool change = true; 174 | checkbox check_atr("Atravessar", atravessar); 175 | TrackBar Vidas("vidas", 1, 10, vida, 1); 176 | int pos = 0; 177 | int max = 0; 178 | bool menu = true; 179 | while (menu) 180 | { 181 | if (change) 182 | { 183 | int i = 0; 184 | std::cout << "\t Game da cobrinha"; 185 | square(30, 4, 2, 0, 1); 186 | setCursorPosition(3, 2); 187 | check_atr.show(pos); 188 | ++i; 189 | 190 | setCursorPosition(3, 3); 191 | Vidas.Show(pos); 192 | ++i; 193 | 194 | setCursorPosition(3, 4); 195 | pos == i ? std::cout << "> " << "Start" << std::endl 196 | : std::cout << " " << "Start" << std::endl; 197 | 198 | std::cout.flush(); 199 | max = i; 200 | change = false; 201 | } 202 | 203 | if (GetAsyncKeyState(VK_UP)) 204 | { 205 | --pos; 206 | if (pos < 0) 207 | pos = max; 208 | change = true; 209 | } 210 | if (GetAsyncKeyState(VK_DOWN)) 211 | { 212 | ++pos; 213 | if (pos > max) 214 | pos = 0; 215 | change = true; 216 | } 217 | 218 | if (GetAsyncKeyState(VK_RETURN)) 219 | { 220 | check_atr.ChangeValue(pos); 221 | Vidas.changeValue(pos); 222 | 223 | atravessar = check_atr.check; 224 | vida = Vidas.value; 225 | if (pos == max) menu = !menu; 226 | change = true; 227 | } 228 | 229 | Sleep(100); 230 | } 231 | cls(); 232 | snake(); 233 | cls(); 234 | std::cout << "O jogo acabou sua pontuacao eh: " << score; 235 | std::cout << std::endl; 236 | } 237 | -------------------------------------------------------------------------------- /MenuConsoleKey/TiroTorre.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "head.h" 3 | 4 | POINT quadrado = { 30,15 }; 5 | int downSpeed = 1; 6 | 7 | 8 | 9 | class Bullet 10 | { 11 | public: 12 | Bullet(){} 13 | Bullet(int x, int y) 14 | { 15 | bx = x; 16 | by = y; 17 | } 18 | bool checkDualBullet() { 19 | return dualBullet; 20 | } 21 | void shoot(); 22 | bool finish = false; 23 | int bx = 0; 24 | int by = 0; 25 | private: 26 | std::string bullet = "|"; 27 | int velo = 1; 28 | bool dualBullet = true; 29 | }; 30 | 31 | void Bullet::shoot() 32 | { 33 | if (dualBullet) 34 | { 35 | setCursorPosition(bx - 1, by); 36 | std::cout << bullet << " " << bullet; 37 | 38 | }else 39 | { 40 | 41 | setCursorPosition(bx, by); 42 | std::cout << bullet; 43 | } 44 | 45 | by -= velo; 46 | if (by <= 0) 47 | { 48 | by = 99; 49 | finish = false;; 50 | } 51 | 52 | } 53 | 54 | int tiro_points = 0; 55 | int tiro_vida = 1; 56 | 57 | class Player 58 | { 59 | public: 60 | Player(); 61 | void me(); 62 | void setVida(int qtVida) 63 | { 64 | tiro_vida += qtVida; 65 | } 66 | void incPoint(int moreP) 67 | { 68 | tiro_points += moreP; 69 | } 70 | 71 | int showPoints() 72 | { 73 | return tiro_points; 74 | } 75 | std::vector myShoot = { Bullet() }; 76 | 77 | int mybullets() 78 | { 79 | return myShoot.size(); 80 | } 81 | void incBullets() 82 | { 83 | myShoot.push_back({ Bullet() }); 84 | } 85 | 86 | int x = (quadrado.x / 2) - 2; 87 | int y = quadrado.y - 3; 88 | 89 | private: 90 | 91 | 92 | }; 93 | 94 | Player::Player() 95 | { 96 | 97 | } 98 | 99 | inline void Player::me() 100 | { 101 | 102 | if (GetAsyncKeyState(VK_SPACE)) 103 | { 104 | for (int i = 0; i < mybullets(); ++i) 105 | { 106 | 107 | if (!myShoot[i].finish) 108 | { 109 | myShoot[i] = Bullet(x + 1, y - 1); 110 | myShoot[i].finish = true; 111 | break; 112 | } 113 | } 114 | 115 | } 116 | 117 | if (GetAsyncKeyState('a') || GetAsyncKeyState('A')) 118 | { 119 | --x; 120 | if (x <= quadrado.x - (quadrado.x - 1)) x = quadrado.x - (quadrado.x - 1); 121 | } 122 | 123 | if (GetAsyncKeyState('d') || GetAsyncKeyState('D')) 124 | { 125 | ++x; 126 | if (x >= quadrado.x - 2) x = quadrado.x - 2; 127 | } 128 | 129 | for (int i = 0; i< mybullets(); ++i) 130 | { 131 | if (myShoot[i].finish) 132 | { 133 | myShoot[i].shoot(); 134 | } 135 | } 136 | 137 | setCursorPosition(x, y); 138 | 139 | std::cout << "@ @"; 140 | setCursorPosition(x, y + 1); 141 | std::cout << "@@@"; 142 | 143 | 144 | } 145 | 146 | 147 | class Bloco 148 | { 149 | public: 150 | Bloco() 151 | { 152 | srand((unsigned)time(NULL)); 153 | posXBloco = rand() % quadrado.x + 1;; 154 | } 155 | Bloco(int posBlc) 156 | { 157 | posXBloco = posBlc; 158 | if (posXBloco > quadrado.x) posXBloco -= quadrado.x; 159 | } 160 | void showBloco(Player PB); 161 | void updateBloco(); 162 | 163 | bool destroy = false; 164 | private: 165 | std::string bloco = "#"; 166 | int va = 1; 167 | int posXBloco = 0; 168 | 169 | }; 170 | 171 | inline void Bloco::showBloco(Player PB) 172 | { 173 | 174 | for(auto bullet : PB.myShoot) 175 | { 176 | if (bullet.checkDualBullet()) 177 | { 178 | if ((bullet.bx -1 == posXBloco || bullet.bx + 1 == posXBloco) && bullet.by == va) 179 | { 180 | PB.incPoint(2); 181 | destroy = true; 182 | } 183 | } 184 | else if (bullet.bx == posXBloco && bullet.by == va) 185 | { 186 | PB.incPoint(2); 187 | destroy = true; 188 | } 189 | } 190 | if (posXBloco <= PB.x + 1 && posXBloco >= PB.x - 1 && va >= PB.y) 191 | { 192 | PB.setVida(-1); 193 | destroy = true; 194 | } 195 | setCursorPosition(posXBloco, va); 196 | std::cout << bloco; 197 | //std::cout.flush(); 198 | 199 | } 200 | 201 | inline void Bloco::updateBloco() 202 | { 203 | va+= downSpeed; 204 | if (va > quadrado.y) 205 | va = 0; 206 | } 207 | 208 | 209 | int update = 50; 210 | void gaming() 211 | { 212 | cls(); 213 | Player Me; 214 | Me.incBullets(); 215 | Me.incBullets(); 216 | std::vector blocks; 217 | blocks.push_back({}); 218 | int count = 0; // 50 counts of 50ms new block 219 | bool lose = true; 220 | while(lose) 221 | { 222 | 223 | square(quadrado.x, quadrado.y, 1, 0, 0); 224 | if (count >= update) 225 | { 226 | for (size_t i = 0; i < blocks.size(); i++) 227 | blocks[i].updateBloco(); 228 | 229 | int newblocs = rand() % quadrado.x + 1; 230 | if (newblocs > 1) 231 | { 232 | for(int i = 0; i < newblocs; ++i) 233 | blocks.push_back({newblocs+i}); 234 | } 235 | 236 | blocks.push_back({}); 237 | count = 0; 238 | } 239 | for (size_t i = 0; i < blocks.size(); i++) 240 | { 241 | blocks[i].showBloco(Me); 242 | 243 | if (blocks[i].destroy) 244 | blocks.erase(blocks.begin() + i); 245 | } 246 | 247 | Me.me(); 248 | 249 | setCursorPosition(0 , quadrado.y+1); 250 | std::cout << "Pontos:"<< Me.showPoints(); 251 | std::string thisBullets = ""; 252 | for (int i = 0; i < Me.mybullets(); i++) 253 | thisBullets += "/"; 254 | 255 | setCursorPosition((quadrado.x / 2), quadrado.y + 1); 256 | std::cout <<"Vida: " << tiro_vida << " Balas: " << thisBullets; 257 | if (tiro_vida < 0) lose = false; 258 | std::cout.flush(); 259 | 260 | //system("cls"); 261 | count++; 262 | Sleep(50); 263 | } 264 | cls(); 265 | std::cout << "Voce perdeu sua pontuacao eh: " << tiro_points << std::endl; 266 | 267 | } 268 | 269 | void Menu_tiro() 270 | { 271 | cls(); 272 | 273 | bool change = true; 274 | int pos = 0; 275 | int max = 0; 276 | bool menu = true; 277 | TrackBar velo("Velocidade", 1, 10, update/10 , 0); 278 | 279 | while (menu) 280 | { 281 | if (change) 282 | { 283 | 284 | int i = 0; 285 | std::cout << "\t Game de nave"; 286 | square(30, 4, 2, 0, 1); 287 | setCursorPosition(3, 2); 288 | velo.Show(pos); 289 | ++i; 290 | 291 | setCursorPosition(3, 4); 292 | pos == i ? std::cout << "> " << "Start" << std::endl 293 | : std::cout << " " << "Start" << std::endl; 294 | 295 | std::cout.flush(); 296 | max = i; 297 | change = false; 298 | } 299 | 300 | if (GetAsyncKeyState(VK_UP)) 301 | { 302 | --pos; 303 | if (pos < 0) 304 | pos = max; 305 | change = true; 306 | } 307 | if (GetAsyncKeyState(VK_DOWN)) 308 | { 309 | ++pos; 310 | if (pos > max) 311 | pos = 0; 312 | change = true; 313 | } 314 | 315 | if (GetAsyncKeyState(VK_RETURN)) 316 | { 317 | velo.changeValue(pos); 318 | update = velo.value * 10; 319 | tiro_vida = 2; 320 | if (pos == max) menu = !menu; 321 | change = true; 322 | } 323 | 324 | 325 | Sleep(100); 326 | } 327 | cls(); 328 | gaming(); 329 | 330 | } -------------------------------------------------------------------------------- /MenuConsoleKey/ConsoleMenu.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {9dbd7912-a6b3-46a6-936d-09eb7cfe2335} 25 | ConsoleMenu 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /MenuConsoleKey/Objetos.cpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | #include "objetos.h" 3 | 4 | UINT ID_itens = 0; 5 | // Checkbox 6 | void ExConsole() 7 | { 8 | CONSOLE_SCREEN_BUFFER_INFO SBInfo; 9 | COORD NewSBSize; 10 | int Status; 11 | 12 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 13 | 14 | GetConsoleScreenBufferInfo(hOut, &SBInfo); 15 | NewSBSize.X = SBInfo.dwSize.X; 16 | NewSBSize.Y = SBInfo.dwSize.Y; 17 | 18 | Status = SetConsoleScreenBufferSize(hOut, NewSBSize); 19 | if (Status == 0) 20 | { 21 | Status = GetLastError(); 22 | std::cout << "SetConsoleScreenBufferSize() failed! Reason : " << Status << std::endl; 23 | exit(Status); 24 | } 25 | 26 | GetConsoleScreenBufferInfo(hOut, &SBInfo); 27 | } 28 | std::string Shadow[5] = { "","\xB0","\xB1","\xB2"," " }; 29 | std::string Style[5][12] = { 30 | {""," "," "," "," "," "," "," "," "," "," "," " }, 31 | {"","\xDA","\xC4","\xBF","\xB3","\xD9","\xC0","\xC3","\xB4","\xC2","\xB3","\xC1"}, 32 | {"","\xC9","\xCD","\xBB","\xBA","\xBC","\xC8","\xCC","\xB9","\xCB","\xBA","\xCA"}, 33 | {"","\xD5","\xCD","\xB8","\xB3","\xBE","\xD4","\xC6","\xB9","\xD1","\xB3","\xCF"}, 34 | {"","\xD6","\xC4","\xB7","\xBA","\xBD","\xD3","\xC7","\xC6","\xD2","\xBA","\xD0"} 35 | }; 36 | 37 | void helpQuard() 38 | { 39 | std::cout << "SHADOW" << std::endl; 40 | for (int i = 0; i < 5; ++i) 41 | std::cout << " " << Shadow[i]; 42 | std::cout << std::endl; 43 | std::cout << "Quard type 1" << std::endl; 44 | for (int i = 0; i < 12; ++i) 45 | std::cout << Style[1][i]; 46 | std::cout << std::endl; 47 | std::cout << "Quard type 2" << std::endl; 48 | for (int i = 0; i < 12; ++i) 49 | std::cout << Style[2][i]; 50 | std::cout << std::endl; 51 | std::cout << "Quard type 3" << std::endl; 52 | for (int i = 0; i < 12; ++i) 53 | std::cout << Style[3][i]; 54 | std::cout << std::endl; 55 | std::cout << "Quard type 4" << std::endl; 56 | for (int i = 0; i < 12; ++i) 57 | std::cout << Style[4][i]; 58 | 59 | } 60 | 61 | void help() 62 | { 63 | cls(); 64 | std::cout << "Help command use HELP or ?\n"; 65 | 66 | std::cout << "\t\t*HELP*\n"; 67 | std::cout << "[quard] use this for drawn a square you need this paraments : widht, hight, type, Position X and Y\n"; 68 | std::cout << "[SetCursorPosition] use this for set position for next text or drawn, paraments needed is : Position X and Y\n"; 69 | std::cout << "[setConsoleColour] use this for set color for next text or drawn, paraments needed is : int color\n"; 70 | std::cout << "[cls] use this for clear all text\n"; 71 | std::cout << "[checkbox] Drawn one checkbox, for set true or false value return, paraments needed is : name, check, id\n"; 72 | std::cout << "Or only Name, for use this is .show() and change value is .ChangeValue(POSITION)\n"; 73 | std::cout << "[TextEdit] Drawn one TextEdit, for set new text value, paraments needed is: name, lenght , buffer, id\n"; 74 | std::cout << "for show use .show(), and change value use .ChangeValue(POSITION)\n"; 75 | std::cout << "[TrackBar] Drawn one TrackBar, for set value or change value, paraments needed is: name, min, max, value, id\n"; 76 | std::cout << "Or only Name, Min, Max, for show this use : .show(), and chenge value is .ChangeValue(POSIITION)\n"; 77 | std::cout << "[ComboBox] Drawn one ComboBox, for set new text value, paraments needed is: name, list, lenght, id\n"; 78 | std::cout << "Or only Name, for show this use : .show(), and chenge value is .ChangeValue(POSIITION)\n"; 79 | std::cout << "[ProgressBar] Drawn one progressBar, for show and value or load anything, paramets needed is: name, value, max and id\n"; 80 | std::cout << "Or only Name, for show this use : .show(), and chenge value is .ChangeValue(POSIITION)\n"; 81 | } 82 | 83 | 84 | void square(int width, int hight, int type, int posX, int posY) 85 | { 86 | 87 | std::string space = std::string(width, ' '); 88 | //Desenha a primiera curva superior 89 | setCursorPosition(posX, posY); 90 | std::cout << Style[type][1]; 91 | 92 | //Desenha a superior inferior horizontal 93 | for (int i = 0; i < width; ++i) std::cout << Style[type][2]; 94 | //Desenha a segunda curva superior 95 | std::cout << Style[type][3]; 96 | int line = 1; 97 | for (line = 1; line < hight; ++line) 98 | { 99 | //Desenha a primeira linha vertical 100 | setCursorPosition(posX, posY + line); 101 | std::cout << Style[type][4]; 102 | 103 | //Limpa as linhas 104 | setCursorPosition(posX + 1, posY + line); 105 | std::cout << space; 106 | 107 | //Desenha a segunda linha vertical 108 | setCursorPosition(width + 1, posY + line); 109 | std::cout << Style[type][4]; 110 | } 111 | //desenha a primeira curva inferior 112 | setCursorPosition(posX, posY + line); 113 | std::cout << Style[type][6]; 114 | 115 | //Desenha a linha inferior horizontal 116 | for (int i = 0; i < width; ++i) std::cout << Style[type][2]; 117 | //desenha a segunda curva inferior 118 | std::cout << Style[type][5]; 119 | 120 | } 121 | 122 | void setCursorPosition(int x, int y) 123 | { 124 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 125 | std::cout.flush(); 126 | COORD coord = { (SHORT)x, (SHORT)y }; 127 | SetConsoleCursorPosition(hOut, coord); 128 | } 129 | 130 | void setConsoleColour(unsigned short colour) 131 | { 132 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 133 | std::cout.flush(); 134 | SetConsoleTextAttribute(hOut, colour); 135 | } 136 | 137 | void cls() 138 | { 139 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 140 | CONSOLE_SCREEN_BUFFER_INFO csbi; 141 | COORD topLeft = { 0, 0 }; 142 | std::cout.flush(); 143 | if (!GetConsoleScreenBufferInfo(hOut, &csbi)) 144 | abort(); 145 | 146 | DWORD length = csbi.dwSize.X * csbi.dwSize.Y; 147 | DWORD written; 148 | FillConsoleOutputCharacter(hOut, TEXT(' '), length, topLeft, &written); 149 | FillConsoleOutputAttribute(hOut, csbi.wAttributes, length, topLeft, &written); 150 | SetConsoleCursorPosition(hOut, topLeft); 151 | } 152 | 153 | /* 154 | * Name, check and id 155 | */ 156 | checkbox::checkbox(std::string name, bool check, int id) 157 | { 158 | checkbox::check = check; 159 | checkbox::id = id; 160 | checkbox::name = name; 161 | ++ID_itens; 162 | } 163 | /* 164 | * Name and check 165 | */ 166 | checkbox::checkbox(std::string name, bool check) 167 | { 168 | checkbox::check = check; 169 | checkbox::id = ID_itens; 170 | checkbox::name = name; 171 | ++ID_itens; 172 | } 173 | /* 174 | * Name only 175 | */ 176 | checkbox::checkbox(std::string name) 177 | { 178 | checkbox::check = false; 179 | checkbox::id = ID_itens; 180 | checkbox::name = name; 181 | ++ID_itens; 182 | } 183 | 184 | void checkbox::show(int pos) 185 | { 186 | if (pos == checkbox::id) 187 | checkbox::check ? std::cout << "> [X]" << checkbox::name << "\n" 188 | : std::cout << "> [*]" << checkbox::name << "\n"; 189 | else 190 | checkbox::check ? std::cout << " [X]" << checkbox::name << "\n" 191 | : std::cout << " [*]" << checkbox::name << "\n"; 192 | } 193 | 194 | void checkbox::ChangeValue(int pos) 195 | { 196 | if (id == pos) 197 | checkbox::check = !checkbox::check; 198 | } 199 | 200 | //Text Edit 201 | 202 | /* 203 | Needed name length and buffer with ID 204 | */ 205 | TextEdit::TextEdit(std::string textedit, int lenght, std::string buffer, int id) 206 | { 207 | TextEdit::name = textedit; 208 | TextEdit::length = lenght; 209 | TextEdit::buffer = buffer; 210 | TextEdit::id = id; 211 | ++ID_itens; 212 | } 213 | /* 214 | Only Name and Buffer Length is according to the buffer 215 | */ 216 | TextEdit::TextEdit(std::string textedit, std::string buffer) 217 | { 218 | TextEdit::name = textedit; 219 | TextEdit::length = buffer.length()+2; 220 | TextEdit::buffer = buffer; 221 | TextEdit::id = ID_itens; 222 | ++ID_itens; 223 | } 224 | /* 225 | Only Name and Length 226 | */ 227 | TextEdit::TextEdit(std::string textedit, int lenght) 228 | { 229 | TextEdit::name = textedit; 230 | TextEdit::length = lenght; 231 | TextEdit::buffer = ""; 232 | TextEdit::id = ID_itens; 233 | ++ID_itens; 234 | } 235 | 236 | 237 | void TextEdit::show(int pos) 238 | { 239 | std::string ca = "_"; 240 | 241 | std::string texts = name; 242 | texts.clear(); 243 | texts.append("["); 244 | for (size_t x = 0; x < length - 2; ++x) 245 | texts.append(ca); 246 | 247 | texts.erase(1, buffer.size()); 248 | texts.insert(1, buffer); 249 | if (texts.size() > length) 250 | texts.erase(length - 1, name.size() + 1); 251 | 252 | texts.append("]"); 253 | 254 | if ((id == pos)) 255 | std::cout << "> " << texts << name << std::endl; 256 | else 257 | std::cout << " " << texts << name << std::endl; 258 | } 259 | 260 | void TextEdit::changeValue(int pos) 261 | { 262 | if (pos == TextEdit::id) 263 | { 264 | cls(); 265 | std::cout << "Write Now: "; 266 | std::getline(std::cin, TextEdit::buffer); 267 | cls(); 268 | } 269 | 270 | } 271 | // TrackBar 272 | 273 | /* 274 | * Name, min value, max value, value current and ID 275 | */ 276 | TrackBar::TrackBar(std::string textBar, int min, int max, int value, UINT32 id) 277 | { 278 | TrackBar::name = textBar; 279 | TrackBar::id = id; 280 | TrackBar::max = max; 281 | TrackBar::min = min; 282 | TrackBar::value = value; 283 | ++ID_itens; 284 | } 285 | 286 | /* 287 | * Name, min value, max value and ID 288 | */ 289 | 290 | TrackBar::TrackBar(std::string textBar, int min, int max, UINT32 id) 291 | { 292 | TrackBar::name = textBar; 293 | TrackBar::id = id; 294 | TrackBar::max = max; 295 | TrackBar::min = min; 296 | TrackBar::value = 0; 297 | ++ID_itens; 298 | } 299 | 300 | /* 301 | * Name, min value and max value 302 | */ 303 | TrackBar::TrackBar(std::string textBar, int min, int max) 304 | { 305 | TrackBar::name = textBar; 306 | TrackBar::id = ID_itens; 307 | TrackBar::max = max; 308 | TrackBar::min = min; 309 | TrackBar::value = 0; 310 | ++ID_itens; 311 | } 312 | 313 | void TrackBar::Show(int pos) 314 | { 315 | std::string points = "."; 316 | std::string track = "|"; 317 | 318 | std::string texts; 319 | texts.clear(); 320 | texts.append("["); 321 | for (int x = 0; x <= max; ++x) 322 | { 323 | if (x == value) 324 | texts.append(track); 325 | else if (x < value) 326 | texts.append("-"); 327 | else 328 | texts.append(points); 329 | } 330 | texts.append("]"); 331 | 332 | if ((id == pos)) 333 | std::cout << "> " << texts << name << std::endl; 334 | else 335 | std::cout << " " << texts << name << std::endl; 336 | } 337 | 338 | void TrackBar::changeValue(int pos) 339 | { 340 | if (id == pos) 341 | { 342 | ++value; 343 | if (value > max) 344 | value = min; 345 | } 346 | } 347 | 348 | /* 349 | * name, list, text show and ID 350 | */ 351 | ComboBox::ComboBox(std::string name, std::vector list, std::string text, UINT id) 352 | { 353 | ComboBox::id = id; 354 | ComboBox::name = name; 355 | ComboBox::list = list; 356 | ComboBox::text = text; 357 | ++ID_itens; 358 | } 359 | 360 | /* 361 | * name and ID 362 | */ 363 | ComboBox::ComboBox(std::string name, UINT id) 364 | { 365 | 366 | ComboBox::id = id; 367 | ComboBox::name = name; 368 | ComboBox::text = ""; 369 | ++ID_itens; 370 | } 371 | 372 | /* 373 | * name only 374 | */ 375 | ComboBox::ComboBox(std::string name) 376 | { 377 | ComboBox::id = ID_itens; 378 | //ComboBox::id = id; 379 | ComboBox::name = name; 380 | ComboBox::text = ""; 381 | ++ID_itens; 382 | } 383 | 384 | void ComboBox::Show(int pos) 385 | { 386 | std::string box; 387 | box.append("["); 388 | box.append(text); 389 | box.append("]"); 390 | 391 | if ((id == pos)) 392 | std::cout << "> " << box << name << std::endl; 393 | else 394 | std::cout << " " << box << name << std::endl; 395 | 396 | } 397 | 398 | void ComboBox::ChangeValue(int pos) 399 | { 400 | if (pos == id) 401 | { 402 | cls(); 403 | bool complete = true; 404 | int lis_pos = 0, total = 3; 405 | std::string options[] = { "|Add|", "|Remove|", "|Select|", "|End|" }; 406 | bool ReWrite = true; 407 | while (complete) 408 | { 409 | if (GetAsyncKeyState(VK_UP)) 410 | { 411 | 412 | --lis_pos; 413 | if (lis_pos < 0) 414 | lis_pos = total; 415 | 416 | ReWrite = true; 417 | } 418 | if (GetAsyncKeyState(VK_DOWN)) 419 | { 420 | ++lis_pos; 421 | if (lis_pos > total) 422 | lis_pos = 0; 423 | 424 | ReWrite = true; 425 | } 426 | if (ReWrite) 427 | { 428 | system("cls"); 429 | std::cout << std::endl; 430 | std::cout << "---------------------" << std::endl; 431 | for (auto line : list) 432 | { 433 | std::cout << "[" << line << "]" << std::endl; 434 | } 435 | std::cout << "---------------------" << std::endl; 436 | std::cout << "->" << " " << options[lis_pos] << std::endl; 437 | ReWrite = false; 438 | } 439 | if (GetAsyncKeyState(VK_RIGHT)) 440 | { 441 | if (lis_pos == 0) 442 | { 443 | std::string newItem; 444 | std::cout << "Write new item: "; 445 | std::cin >> newItem; 446 | std::cin.clear(); 447 | list.push_back(newItem); 448 | text = list[0]; 449 | ReWrite = true; 450 | 451 | } 452 | if (lis_pos == 1) 453 | { 454 | int rm_num = 0; 455 | for (auto line : list) 456 | { 457 | std::cout << "["<< rm_num << "][" << line << "]" << std::endl; 458 | rm_num++; 459 | } 460 | std::cout << "Write number of want delete > "; 461 | std::cin >> rm_num; 462 | std::cin.clear(); 463 | list.erase(list.begin() + rm_num); 464 | ReWrite = true; 465 | } 466 | if (lis_pos == 2) 467 | { 468 | int rm_num = 0; 469 | for (auto line : list) 470 | { 471 | std::cout << "[" << rm_num << "][" << line << "]" << std::endl; 472 | rm_num++; 473 | } 474 | std::cout << "Number of you want show: "; 475 | std::cin >> rm_num; 476 | std::cin.clear(); 477 | text = list[rm_num]; 478 | std::cout << "Text: " << text << std::endl; 479 | 480 | ReWrite = true; 481 | } 482 | if (lis_pos == total) 483 | { 484 | complete = false; 485 | cls(); 486 | } 487 | 488 | 489 | } 490 | 491 | Sleep(100); 492 | } 493 | } 494 | 495 | } 496 | 497 | ProgressBar::ProgressBar(std::string name, float value, UINT id) 498 | { 499 | ProgressBar::id = id; 500 | ProgressBar::name = name; 501 | ProgressBar::value = value; 502 | } 503 | 504 | ProgressBar::ProgressBar(std::string name, float value) 505 | { 506 | ProgressBar::id = ID_itens; 507 | ProgressBar::name = name; 508 | ProgressBar::value = value; 509 | ++ID_itens; 510 | } 511 | 512 | ProgressBar::ProgressBar(std::string name) 513 | { 514 | ProgressBar::id = ID_itens; 515 | ProgressBar::name = name; 516 | ProgressBar::value = 0; 517 | ++ID_itens; 518 | } 519 | 520 | void ProgressBar::Show(int pos) 521 | { 522 | std::string bar; 523 | bar.clear(); 524 | bar.append("["); 525 | for (int x = 0; x <= max; ++x) 526 | { 527 | if (x <= value) 528 | bar.append("|"); 529 | else 530 | bar.append("."); 531 | } 532 | bar.append("]"); 533 | std::cout << bar << name << std::endl; 534 | 535 | } 536 | 537 | void ProgressBar::ChangeValue(int pos) 538 | { 539 | value += 0.5f; 540 | } 541 | -------------------------------------------------------------------------------- /MenuConsoleKey/objetos.cpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | #include "objetos.h" 3 | 4 | UINT ID_itens = 0; 5 | // Checkbox 6 | void ExConsole() 7 | { 8 | CONSOLE_SCREEN_BUFFER_INFO SBInfo; 9 | COORD NewSBSize; 10 | int Status; 11 | 12 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 13 | 14 | GetConsoleScreenBufferInfo(hOut, &SBInfo); 15 | NewSBSize.X = SBInfo.dwSize.X; 16 | NewSBSize.Y = SBInfo.dwSize.Y; 17 | 18 | Status = SetConsoleScreenBufferSize(hOut, NewSBSize); 19 | if (Status == 0) 20 | { 21 | Status = GetLastError(); 22 | std::cout << "SetConsoleScreenBufferSize() failed! Reason : " << Status << std::endl; 23 | exit(Status); 24 | } 25 | 26 | GetConsoleScreenBufferInfo(hOut, &SBInfo); 27 | } 28 | std::string Shadow[5] = { "","\xB0","\xB1","\xB2"," " }; 29 | std::string Style[5][12] = { 30 | {""," "," "," "," "," "," "," "," "," "," "," " }, 31 | {"","\xDA","\xC4","\xBF","\xB3","\xD9","\xC0","\xC3","\xB4","\xC2","\xB3","\xC1"}, 32 | {"","\xC9","\xCD","\xBB","\xBA","\xBC","\xC8","\xCC","\xB9","\xCB","\xBA","\xCA"}, 33 | {"","\xD5","\xCD","\xB8","\xB3","\xBE","\xD4","\xC6","\xB9","\xD1","\xB3","\xCF"}, 34 | {"","\xD6","\xC4","\xB7","\xBA","\xBD","\xD3","\xC7","\xC6","\xD2","\xBA","\xD0"} 35 | }; 36 | 37 | void helpQuard() 38 | { 39 | std::cout << "SHADOW" << std::endl; 40 | for (int i = 0; i < 5; ++i) 41 | std::cout << " " << Shadow[i]; 42 | std::cout << std::endl; 43 | std::cout << "Quard type 1" << std::endl; 44 | for (int i = 0; i < 12; ++i) 45 | std::cout << Style[1][i]; 46 | std::cout << std::endl; 47 | std::cout << "Quard type 2" << std::endl; 48 | for (int i = 0; i < 12; ++i) 49 | std::cout << Style[2][i]; 50 | std::cout << std::endl; 51 | std::cout << "Quard type 3" << std::endl; 52 | for (int i = 0; i < 12; ++i) 53 | std::cout << Style[3][i]; 54 | std::cout << std::endl; 55 | std::cout << "Quard type 4" << std::endl; 56 | for (int i = 0; i < 12; ++i) 57 | std::cout << Style[4][i]; 58 | 59 | } 60 | 61 | void help() 62 | { 63 | cls(); 64 | std::cout << "Help command use HELP or ?\n"; 65 | 66 | std::cout << "\t\t*HELP*\n"; 67 | std::cout << "[quard] use this for drawn a square you need this paraments : widht, hight, type, Position X and Y\n"; 68 | std::cout << "[SetCursorPosition] use this for set position for next text or drawn, paraments needed is : Position X and Y\n"; 69 | std::cout << "[setConsoleColour] use this for set color for next text or drawn, paraments needed is : int color\n"; 70 | std::cout << "[cls] use this for clear all text\n"; 71 | std::cout << "[checkbox] Drawn one checkbox, for set true or false value return, paraments needed is : name, check, id\n"; 72 | std::cout << "Or only Name, for use this is .show() and change value is .ChangeValue(POSITION)\n"; 73 | std::cout << "[TextEdit] Drawn one TextEdit, for set new text value, paraments needed is: name, lenght , buffer, id\n"; 74 | std::cout << "for show use .show(), and change value use .ChangeValue(POSITION)\n"; 75 | std::cout << "[TrackBar] Drawn one TrackBar, for set value or change value, paraments needed is: name, min, max, value, id\n"; 76 | std::cout << "Or only Name, Min, Max, for show this use : .show(), and chenge value is .ChangeValue(POSIITION)\n"; 77 | std::cout << "[ComboBox] Drawn one ComboBox, for set new text value, paraments needed is: name, list, lenght, id\n"; 78 | std::cout << "Or only Name, for show this use : .show(), and chenge value is .ChangeValue(POSIITION)\n"; 79 | std::cout << "[ProgressBar] Drawn one progressBar, for show and value or load anything, paramets needed is: name, value, max and id\n"; 80 | std::cout << "Or only Name, for show this use : .show(), and chenge value is .ChangeValue(POSIITION)\n"; 81 | } 82 | 83 | 84 | void square(int width, int hight, int type, int posX, int posY) 85 | { 86 | 87 | std::string space = std::string(width, ' '); 88 | //Desenha a primiera curva superior 89 | setCursorPosition(posX, posY); 90 | std::cout << Style[type][1]; 91 | 92 | //Desenha a superior inferior horizontal 93 | for (int i = 0; i < width; ++i) std::cout << Style[type][2]; 94 | //Desenha a segunda curva superior 95 | std::cout << Style[type][3]; 96 | int line = 1; 97 | for (line = 1; line < hight; ++line) 98 | { 99 | //Desenha a primeira linha vertical 100 | setCursorPosition(posX, posY + line); 101 | std::cout << Style[type][4]; 102 | 103 | //Limpa as linhas 104 | setCursorPosition(posX + 1, posY + line); 105 | std::cout << space; 106 | 107 | //Desenha a segunda linha vertical 108 | setCursorPosition(width + 1, posY + line); 109 | std::cout << Style[type][4]; 110 | } 111 | //desenha a primeira curva inferior 112 | setCursorPosition(posX, posY + line); 113 | std::cout << Style[type][6]; 114 | 115 | //Desenha a linha inferior horizontal 116 | for (int i = 0; i < width; ++i) std::cout << Style[type][2]; 117 | //desenha a segunda curva inferior 118 | std::cout << Style[type][5]; 119 | 120 | } 121 | 122 | void setCursorPosition(int x, int y) 123 | { 124 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 125 | std::cout.flush(); 126 | COORD coord = { (SHORT)x, (SHORT)y }; 127 | SetConsoleCursorPosition(hOut, coord); 128 | } 129 | 130 | void setConsoleColour(unsigned short colour) 131 | { 132 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 133 | std::cout.flush(); 134 | SetConsoleTextAttribute(hOut, colour); 135 | } 136 | 137 | void cls() 138 | { 139 | static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 140 | CONSOLE_SCREEN_BUFFER_INFO csbi; 141 | COORD topLeft = { 0, 0 }; 142 | std::cout.flush(); 143 | if (!GetConsoleScreenBufferInfo(hOut, &csbi)) 144 | abort(); 145 | 146 | DWORD length = csbi.dwSize.X * csbi.dwSize.Y; 147 | DWORD written; 148 | FillConsoleOutputCharacter(hOut, TEXT(' '), length, topLeft, &written); 149 | FillConsoleOutputAttribute(hOut, csbi.wAttributes, length, topLeft, &written); 150 | SetConsoleCursorPosition(hOut, topLeft); 151 | } 152 | 153 | /* 154 | * Name, check and id 155 | */ 156 | checkbox::checkbox(std::string name, bool check, int id) 157 | { 158 | checkbox::check = check; 159 | checkbox::id = id; 160 | checkbox::name = name; 161 | ++ID_itens; 162 | } 163 | /* 164 | * Name and check 165 | */ 166 | checkbox::checkbox(std::string name, bool check) 167 | { 168 | checkbox::check = check; 169 | checkbox::id = ID_itens; 170 | checkbox::name = name; 171 | ++ID_itens; 172 | } 173 | /* 174 | * Name only 175 | */ 176 | checkbox::checkbox(std::string name) 177 | { 178 | checkbox::check = false; 179 | checkbox::id = ID_itens; 180 | checkbox::name = name; 181 | ++ID_itens; 182 | } 183 | 184 | void checkbox::show(int pos) 185 | { 186 | if (pos == checkbox::id) 187 | checkbox::check ? std::cout << "> [X]" << checkbox::name << "\n" 188 | : std::cout << "> [*]" << checkbox::name << "\n"; 189 | else 190 | checkbox::check ? std::cout << " [X]" << checkbox::name << "\n" 191 | : std::cout << " [*]" << checkbox::name << "\n"; 192 | } 193 | 194 | void checkbox::ChangeValue(int pos) 195 | { 196 | if (id == pos) 197 | checkbox::check = !checkbox::check; 198 | } 199 | 200 | //Text Edit 201 | 202 | /* 203 | Needed name length and buffer with ID 204 | */ 205 | TextEdit::TextEdit(std::string textedit, int lenght, std::string buffer, int id) 206 | { 207 | TextEdit::name = textedit; 208 | TextEdit::length = lenght; 209 | TextEdit::buffer = buffer; 210 | TextEdit::id = id; 211 | ++ID_itens; 212 | } 213 | /* 214 | Only Name and Buffer Length is according to the buffer 215 | */ 216 | TextEdit::TextEdit(std::string textedit, std::string buffer) 217 | { 218 | TextEdit::name = textedit; 219 | TextEdit::length = buffer.length()+2; 220 | TextEdit::buffer = buffer; 221 | TextEdit::id = ID_itens; 222 | ++ID_itens; 223 | } 224 | /* 225 | Only Name and Length 226 | */ 227 | TextEdit::TextEdit(std::string textedit, int lenght) 228 | { 229 | TextEdit::name = textedit; 230 | TextEdit::length = lenght; 231 | TextEdit::buffer = ""; 232 | TextEdit::id = ID_itens; 233 | ++ID_itens; 234 | } 235 | 236 | 237 | void TextEdit::show(int pos) 238 | { 239 | std::string ca = "_"; 240 | 241 | std::string texts = name; 242 | texts.clear(); 243 | texts.append("["); 244 | for (size_t x = 0; x < length - 2; ++x) 245 | texts.append(ca); 246 | 247 | texts.erase(1, buffer.size()); 248 | texts.insert(1, buffer); 249 | if (texts.size() > length) 250 | texts.erase(length - 1, name.size() + 1); 251 | 252 | texts.append("]"); 253 | 254 | if ((id == pos)) 255 | std::cout << "> " << texts << name << std::endl; 256 | else 257 | std::cout << " " << texts << name << std::endl; 258 | } 259 | 260 | void TextEdit::changeValue(int pos) 261 | { 262 | if (pos == TextEdit::id) 263 | { 264 | cls(); 265 | std::cout << "Write Now: "; 266 | std::getline(std::cin, TextEdit::buffer); 267 | cls(); 268 | } 269 | 270 | } 271 | // TrackBar 272 | 273 | /* 274 | * Name, min value, max value, value current and ID 275 | */ 276 | TrackBar::TrackBar(std::string textBar, int min, int max, int value, UINT32 id) 277 | { 278 | TrackBar::name = textBar; 279 | TrackBar::id = id; 280 | TrackBar::max = max; 281 | TrackBar::min = min; 282 | TrackBar::value = value; 283 | ++ID_itens; 284 | } 285 | 286 | /* 287 | * Name, min value, max value and ID 288 | */ 289 | 290 | TrackBar::TrackBar(std::string textBar, int min, int max, UINT32 id) 291 | { 292 | TrackBar::name = textBar; 293 | TrackBar::id = id; 294 | TrackBar::max = max; 295 | TrackBar::min = min; 296 | TrackBar::value = 0; 297 | ++ID_itens; 298 | } 299 | 300 | /* 301 | * Name, min value and max value 302 | */ 303 | TrackBar::TrackBar(std::string textBar, int min, int max) 304 | { 305 | TrackBar::name = textBar; 306 | TrackBar::id = ID_itens; 307 | TrackBar::max = max; 308 | TrackBar::min = min; 309 | TrackBar::value = 0; 310 | ++ID_itens; 311 | } 312 | 313 | void TrackBar::Show(int pos) 314 | { 315 | std::string points = "."; 316 | std::string track = "|"; 317 | 318 | std::string texts; 319 | texts.clear(); 320 | texts.append("["); 321 | for (int x = 0; x <= max; ++x) 322 | { 323 | if (x == value) 324 | texts.append(track); 325 | else if (x < value) 326 | texts.append("-"); 327 | else 328 | texts.append(points); 329 | } 330 | texts.append("]"); 331 | 332 | if ((id == pos)) 333 | std::cout << "> " << texts << name << std::endl; 334 | else 335 | std::cout << " " << texts << name << std::endl; 336 | } 337 | 338 | void TrackBar::changeValue(int pos) 339 | { 340 | if (id == pos) 341 | { 342 | ++value; 343 | if (value > max) 344 | value = min; 345 | } 346 | } 347 | 348 | /* 349 | * name, list, text show and ID 350 | */ 351 | ComboBox::ComboBox(std::string name, std::vector list, std::string text, UINT id) 352 | { 353 | ComboBox::id = id; 354 | ComboBox::name = name; 355 | ComboBox::list = list; 356 | ComboBox::text = text; 357 | ++ID_itens; 358 | } 359 | 360 | /* 361 | * name and ID 362 | */ 363 | ComboBox::ComboBox(std::string name, UINT id) 364 | { 365 | 366 | ComboBox::id = id; 367 | ComboBox::name = name; 368 | ComboBox::text = ""; 369 | ++ID_itens; 370 | } 371 | 372 | /* 373 | * name only 374 | */ 375 | ComboBox::ComboBox(std::string name) 376 | { 377 | ComboBox::id = ID_itens; 378 | //ComboBox::id = id; 379 | ComboBox::name = name; 380 | ComboBox::text = ""; 381 | ++ID_itens; 382 | } 383 | 384 | void ComboBox::Show(int pos) 385 | { 386 | std::string box; 387 | box.append("["); 388 | box.append(text); 389 | box.append("]"); 390 | 391 | if ((id == pos)) 392 | std::cout << "> " << box << name << std::endl; 393 | else 394 | std::cout << " " << box << name << std::endl; 395 | 396 | } 397 | 398 | void ComboBox::ChangeValue(int pos) 399 | { 400 | if (pos == id) 401 | { 402 | cls(); 403 | bool complete = true; 404 | int lis_pos = 0, total = 3; 405 | std::string options[] = { "|Add|", "|Remove|", "|Select|", "|End|" }; 406 | bool ReWrite = true; 407 | while (complete) 408 | { 409 | if (GetAsyncKeyState(VK_UP)) 410 | { 411 | 412 | --lis_pos; 413 | if (lis_pos < 0) 414 | lis_pos = total; 415 | 416 | ReWrite = true; 417 | } 418 | if (GetAsyncKeyState(VK_DOWN)) 419 | { 420 | ++lis_pos; 421 | if (lis_pos > total) 422 | lis_pos = 0; 423 | 424 | ReWrite = true; 425 | } 426 | if (ReWrite) 427 | { 428 | system("cls"); 429 | std::cout << std::endl; 430 | std::cout << "---------------------" << std::endl; 431 | for (auto line : list) 432 | { 433 | std::cout << "[" << line << "]" << std::endl; 434 | } 435 | std::cout << "---------------------" << std::endl; 436 | std::cout << "->" << " " << options[lis_pos] << std::endl; 437 | ReWrite = false; 438 | } 439 | if (GetAsyncKeyState(VK_RIGHT)) 440 | { 441 | if (lis_pos == 0) 442 | { 443 | std::string newItem; 444 | std::cout << "Write new item: "; 445 | std::cin >> newItem; 446 | std::cin.clear(); 447 | list.push_back(newItem); 448 | text = list[0]; 449 | ReWrite = true; 450 | 451 | } 452 | if (lis_pos == 1) 453 | { 454 | int rm_num = 0; 455 | for (auto line : list) 456 | { 457 | std::cout << "["<< rm_num << "][" << line << "]" << std::endl; 458 | rm_num++; 459 | } 460 | std::cout << "Write number of want delete > "; 461 | std::cin >> rm_num; 462 | std::cin.clear(); 463 | list.erase(list.begin() + rm_num); 464 | ReWrite = true; 465 | } 466 | if (lis_pos == 2) 467 | { 468 | int rm_num = 0; 469 | for (auto line : list) 470 | { 471 | std::cout << "[" << rm_num << "][" << line << "]" << std::endl; 472 | rm_num++; 473 | } 474 | std::cout << "Number of you want show: "; 475 | std::cin >> rm_num; 476 | std::cin.clear(); 477 | text = list[rm_num]; 478 | std::cout << "Text: " << text << std::endl; 479 | 480 | ReWrite = true; 481 | } 482 | if (lis_pos == total) 483 | { 484 | complete = false; 485 | cls(); 486 | } 487 | 488 | 489 | } 490 | 491 | Sleep(100); 492 | } 493 | } 494 | 495 | } 496 | 497 | ProgressBar::ProgressBar(std::string name, float value, UINT id) 498 | { 499 | ProgressBar::id = id; 500 | ProgressBar::name = name; 501 | ProgressBar::value = value; 502 | } 503 | 504 | ProgressBar::ProgressBar(std::string name, float value) 505 | { 506 | ProgressBar::id = ID_itens; 507 | ProgressBar::name = name; 508 | ProgressBar::value = value; 509 | ++ID_itens; 510 | } 511 | 512 | ProgressBar::ProgressBar(std::string name) 513 | { 514 | ProgressBar::id = ID_itens; 515 | ProgressBar::name = name; 516 | ProgressBar::value = 0; 517 | ++ID_itens; 518 | } 519 | 520 | void ProgressBar::Show(int pos) 521 | { 522 | std::string bar; 523 | bar.clear(); 524 | bar.append("["); 525 | for (int x = 0; x <= max; ++x) 526 | { 527 | if (x <= value) 528 | bar.append("|"); 529 | else 530 | bar.append("."); 531 | } 532 | bar.append("]"); 533 | std::cout << bar << name << std::endl; 534 | 535 | } 536 | 537 | void ProgressBar::ChangeValue(int pos) 538 | { 539 | value += 0.5f; 540 | } 541 | --------------------------------------------------------------------------------