]> git.lizzy.rs Git - nothing.git/commitdiff
(#965) Make LabelLayer render edit_field inside of the world
authorrexim <reximkut@gmail.com>
Sun, 21 Jul 2019 17:47:42 +0000 (00:47 +0700)
committerrexim <reximkut@gmail.com>
Sun, 21 Jul 2019 17:47:42 +0000 (00:47 +0700)
src/game/level/level_editor/label_layer.c
src/ui/edit_field.c

index bf743ac3a8ec015e29f9eb8837b4bdf330e0e2a2..de7a9a649a414ae868de6c082d9222cb425ea213 100644 (file)
@@ -184,11 +184,10 @@ int label_layer_render(const LabelLayer *label_layer,
     /* TODO(#891): LabelLayer doesn't show the final position of Label after the animation */
     for (size_t i = 0; i < n; ++i) {
         if (label_layer->state == LABEL_LAYER_EDIT_TEXT) {
-            // TODO(#965): LabelLayer Edit Field should be rendered inside of the world
-            if (edit_field_render_screen(
+            if (edit_field_render_world(
                     label_layer->edit_field,
                     camera,
-                    camera_point(camera, positions[i])) < 0) {
+                    positions[i]) < 0) {
                 return -1;
             }
         } else {
index cb47ae5f6b90a0364f5cbd69cb1b64c28ce5651f..199caaced920b3151f2c001e66dea771eb8b36eb 100644 (file)
@@ -97,7 +97,28 @@ int edit_field_render_world(const Edit_field *edit_field,
 {
     trace_assert(edit_field);
     trace_assert(camera);
-    (void) world_position;
+
+    const float cursor_y_overflow = 10.0f;
+    const float cursor_width = 2.0f;
+
+    if (camera_render_text(
+            camera,
+            edit_field->buffer,
+            edit_field->font_size,
+            edit_field->font_color,
+            world_position) < 0) {
+        return -1;
+    }
+
+    if (camera_fill_rect(
+            camera,
+            rect(world_position.x + (float) edit_field->cursor * (float) FONT_CHAR_WIDTH * edit_field->font_size.x,
+                 world_position.y - cursor_y_overflow,
+                 cursor_width,
+                 FONT_CHAR_HEIGHT * edit_field->font_size.y + cursor_y_overflow * 2.0f),
+            edit_field->font_color) < 0) {
+        return -1;
+    }
 
     return 0;
 }