diff --git a/src/main.cpp b/src/main.cpp index eea7e0a..ad3ff06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,9 +5,10 @@ int main(int argc, char* args[]) { std::cout << "Hello there" << std::endl; - std::vector textboxVector({'d', 'i', 'n', 'g', 'u', 's'}); + std::vector textboxVector; char textbox[textboxVector.size()]; copy(textboxVector.begin(),textboxVector.end(),textbox); + std::vector previousLines; const int SCREEN_WIDTH = 800; // Define screen dimensions const int SCREEN_HEIGHT = 600; @@ -64,6 +65,8 @@ int main(int argc, char* args[]) { bool caps = false; + int lineNum = 0; + while (!quit) { while (SDL_PollEvent(&e) !=0) { if (e.type == SDL_QUIT) { @@ -73,8 +76,14 @@ int main(int argc, char* args[]) { std::cout << "Key pressed is " << SDL_GetKeyName(e.key.keysym.sym) << std::endl; if (e.key.keysym.sym == SDLK_SPACE) { textboxVector.push_back(' '); + } else if (e.key.keysym.sym == SDLK_RETURN) { + lineNum++; } else if (e.key.keysym.sym == SDLK_BACKSPACE) { - textboxVector.pop_back(); + if (textboxVector.size() <= 1) { + textboxVector.clear(); + } else { + textboxVector.pop_back(); + } } else if (e.key.keysym.sym == SDLK_CAPSLOCK) { if (caps) { caps = false; @@ -94,10 +103,13 @@ int main(int argc, char* args[]) { textboxVector.push_back(tolower(SDL_GetKeyName(e.key.keysym.sym)[0])); } } + if (textboxVector.size() == 0) { + SDL_DestroyTexture(textTexture); + continue; + } char* textbox = new char[textboxVector.size() + 1]; copy(textboxVector.begin(),textboxVector.end(),textbox); textbox[textboxVector.size()] = '\0'; - std::cout << "Textbox is " << textbox << std::endl; SDL_DestroyTexture(textTexture); SDL_Surface* newTextSurface = TTF_RenderText_Solid(font, textbox, textColour); textTexture = SDL_CreateTextureFromSurface(renderer, newTextSurface); @@ -123,7 +135,7 @@ int main(int argc, char* args[]) { SDL_RenderClear(renderer); SDL_Rect renderQuad = { - 0, 0, + 0, 18 * lineNum, textWidth, textHeight };