]> git.lizzy.rs Git - nothing.git/blobdiff - src/ui/console.c
(#813) Implement player_layer_render
[nothing.git] / src / ui / console.c
index 8c4c8f5b987d39b8cb46bbbda749ea9ce2a930ef..a7f37b9f63cc68986eb8a178dace20cc8dc84602 100644 (file)
@@ -6,8 +6,6 @@
 #include "ebisp/scope.h"
 #include "ebisp/std.h"
 #include "game/level.h"
-#include "game/level/player/rigid_rect.h"
-#include "game/level_script.h"
 #include "sdl/renderer.h"
 #include "system/log.h"
 #include "system/log_script.h"
@@ -60,11 +58,8 @@ Console *create_console(Broadcast *broadcast,
 {
     Lt *lt = create_lt();
 
-    if (lt == NULL) {
-        return NULL;
-    }
 
-    Console *console = PUSH_LT(lt, nth_alloc(sizeof(Console)), free);
+    Console *console = PUSH_LT(lt, nth_calloc(1, sizeof(Console)), free);
     if (console == NULL) {
         RETURN_LT(lt, NULL);
     }
@@ -81,12 +76,12 @@ Console *create_console(Broadcast *broadcast,
 
     load_std_library(console->gc, &console->scope);
     load_log_library(console->gc, &console->scope);
+    /* TODO(#669): how to report EvalResult error from create_console? */
     broadcast_load_library(broadcast, console->gc, &console->scope);
 
     console->edit_field = PUSH_LT(
         lt,
         create_edit_field(
-            font,
             vec(FONT_WIDTH_SCALE, FONT_HEIGHT_SCALE),
             CONSOLE_FOREGROUND),
         destroy_edit_field);
@@ -106,7 +101,7 @@ Console *create_console(Broadcast *broadcast,
 
     console->eval_result = PUSH_LT(
         lt,
-        nth_alloc(sizeof(char) * CONSOLE_EVAL_RESULT_SIZE),
+        nth_calloc(1, sizeof(char) * CONSOLE_EVAL_RESULT_SIZE),
         free);
     if (console->eval_result == NULL) {
         RETURN_LT(lt, NULL);
@@ -190,7 +185,7 @@ int console_handle_event(Console *console,
                          const SDL_Event *event)
 {
     switch(event->type) {
-    case SDL_KEYDOWN:
+    case SDL_KEYDOWN: {
         switch(event->key.keysym.sym) {
         case SDLK_RETURN:
             return console_eval_input(console);
@@ -209,13 +204,21 @@ int console_handle_event(Console *console,
             history_next(console->history);
             return 0;
         }
-        break;
+
+        return edit_field_keyboard(console->edit_field, &event->key);
+    } break;
+
+    case SDL_TEXTINPUT:
+        return edit_field_text_input(console->edit_field, &event->text);
+
+    default: {}
     }
 
-    return edit_field_handle_event(console->edit_field, event);
+    return 0;
 }
 
 int console_render(const Console *console,
+                   Camera *camera,
                    SDL_Renderer *renderer)
 {
     /* TODO(#364): console doesn't have any padding around the edit fields */
@@ -240,7 +243,7 @@ int console_render(const Console *console,
     }
 
     if (edit_field_render(console->edit_field,
-                          renderer,
+                          camera,
                           vec(0.0f, y + CONSOLE_LOG_HEIGHT)) < 0) {
         return -1;
     }