Make stuff work better
This commit is contained in:
parent
dbaf076506
commit
487c104f47
20
src/main.cpp
20
src/main.cpp
|
@ -5,9 +5,10 @@
|
||||||
|
|
||||||
int main(int argc, char* args[]) {
|
int main(int argc, char* args[]) {
|
||||||
std::cout << "Hello there" << std::endl;
|
std::cout << "Hello there" << std::endl;
|
||||||
std::vector<char> textboxVector({'d', 'i', 'n', 'g', 'u', 's'});
|
std::vector<char> textboxVector;
|
||||||
char textbox[textboxVector.size()];
|
char textbox[textboxVector.size()];
|
||||||
copy(textboxVector.begin(),textboxVector.end(),textbox);
|
copy(textboxVector.begin(),textboxVector.end(),textbox);
|
||||||
|
std::vector<std::string> previousLines;
|
||||||
|
|
||||||
const int SCREEN_WIDTH = 800; // Define screen dimensions
|
const int SCREEN_WIDTH = 800; // Define screen dimensions
|
||||||
const int SCREEN_HEIGHT = 600;
|
const int SCREEN_HEIGHT = 600;
|
||||||
|
@ -64,6 +65,8 @@ int main(int argc, char* args[]) {
|
||||||
|
|
||||||
bool caps = false;
|
bool caps = false;
|
||||||
|
|
||||||
|
int lineNum = 0;
|
||||||
|
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
while (SDL_PollEvent(&e) !=0) {
|
while (SDL_PollEvent(&e) !=0) {
|
||||||
if (e.type == SDL_QUIT) {
|
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;
|
std::cout << "Key pressed is " << SDL_GetKeyName(e.key.keysym.sym) << std::endl;
|
||||||
if (e.key.keysym.sym == SDLK_SPACE) {
|
if (e.key.keysym.sym == SDLK_SPACE) {
|
||||||
textboxVector.push_back(' ');
|
textboxVector.push_back(' ');
|
||||||
|
} else if (e.key.keysym.sym == SDLK_RETURN) {
|
||||||
|
lineNum++;
|
||||||
} else if (e.key.keysym.sym == SDLK_BACKSPACE) {
|
} 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) {
|
} else if (e.key.keysym.sym == SDLK_CAPSLOCK) {
|
||||||
if (caps) {
|
if (caps) {
|
||||||
caps = false;
|
caps = false;
|
||||||
|
@ -94,10 +103,13 @@ int main(int argc, char* args[]) {
|
||||||
textboxVector.push_back(tolower(SDL_GetKeyName(e.key.keysym.sym)[0]));
|
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];
|
char* textbox = new char[textboxVector.size() + 1];
|
||||||
copy(textboxVector.begin(),textboxVector.end(),textbox);
|
copy(textboxVector.begin(),textboxVector.end(),textbox);
|
||||||
textbox[textboxVector.size()] = '\0';
|
textbox[textboxVector.size()] = '\0';
|
||||||
std::cout << "Textbox is " << textbox << std::endl;
|
|
||||||
SDL_DestroyTexture(textTexture);
|
SDL_DestroyTexture(textTexture);
|
||||||
SDL_Surface* newTextSurface = TTF_RenderText_Solid(font, textbox, textColour);
|
SDL_Surface* newTextSurface = TTF_RenderText_Solid(font, textbox, textColour);
|
||||||
textTexture = SDL_CreateTextureFromSurface(renderer, newTextSurface);
|
textTexture = SDL_CreateTextureFromSurface(renderer, newTextSurface);
|
||||||
|
@ -123,7 +135,7 @@ int main(int argc, char* args[]) {
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
SDL_Rect renderQuad = {
|
SDL_Rect renderQuad = {
|
||||||
0, 0,
|
0, 18 * lineNum,
|
||||||
textWidth,
|
textWidth,
|
||||||
textHeight
|
textHeight
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user