checkkeys will now render text that is input

Also added test functions for multi-line debug text display

Currently this only supports ASCII, as the font doesn't have the correct Latin-1 characters
This commit is contained in:
Sam Lantinga
2022-07-01 12:56:47 -07:00
parent 209f457ea4
commit e9d5060c4c
4 changed files with 346 additions and 18 deletions

View File

@@ -24,8 +24,12 @@
#endif
#include "SDL.h"
#include "SDL_test_font.h"
int done;
static SDL_Window *window;
static SDL_Renderer *renderer;
static SDLTest_TextWindow *textwin;
static int done;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
@@ -163,6 +167,18 @@ loop()
case SDL_KEYDOWN:
case SDL_KEYUP:
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
if (event.type == SDL_KEYDOWN) {
switch (event.key.keysym.sym) {
case SDLK_BACKSPACE:
SDLTest_TextWindowAddText(textwin, "\b");
break;
case SDLK_RETURN:
SDLTest_TextWindowAddText(textwin, "\n");
break;
default:
break;
}
}
break;
case SDL_TEXTEDITING:
PrintText("EDIT", event.edit.text);
@@ -173,6 +189,7 @@ loop()
break;
case SDL_TEXTINPUT:
PrintText("INPUT", event.text.text);
SDLTest_TextWindowAddText(textwin, "%s", event.text.text);
break;
case SDL_FINGERDOWN:
if (SDL_IsTextInputActive()) {
@@ -204,6 +221,13 @@ loop()
break;
}
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDLTest_TextWindowDisplay(textwin, renderer);
SDL_RenderPresent(renderer);
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
@@ -214,9 +238,6 @@ loop()
int
main(int argc, char *argv[])
{
SDL_Window *window;
SDL_Renderer *renderer;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -242,11 +263,14 @@ main(int argc, char *argv[])
quit(2);
}
/* On wayland, no window will actually show until something has
actually been displayed.
*/
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_RenderPresent(renderer);
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
SDL_GetError());
quit(2);
}
textwin = SDLTest_TextWindowCreate(0, 0, 640, 480);
#if __IPHONEOS__
/* Creating the context creates the view, which we need to show keyboard */