summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--font.c3
-rw-r--r--window.c44
2 files changed, 40 insertions, 7 deletions
diff --git a/font.c b/font.c
index 00b7f4d..69e500b 100644
--- a/font.c
+++ b/font.c
@@ -49,6 +49,9 @@ BDFFontInfo font_load(const char *filename)
result.bounds.h = 0;
result.chars = NULL;
result.num_chars = 0;
+ for (int i = 0; i < 128; i++) {
+ result.char_index_for_code_point[i] = 0;
+ }
fp = fopen(filename, "r");
if (fp == NULL) {
diff --git a/window.c b/window.c
index b3b54f0..81bf634 100644
--- a/window.c
+++ b/window.c
@@ -1,6 +1,9 @@
#include "window.h"
#include <SDL2/SDL.h>
+
+#include "buffer.h"
+#include "editor.h"
#include "font.h"
static SDL_Window *window = NULL;
@@ -47,23 +50,50 @@ int window_handle_event()
return 1;
}
-void window_redraw(struct editor_state *editor)
+static void draw_font_text(struct append_buffer *buffer)
{
- const char *testmsg = "Hello, welcome to the bitmap font test!";
- SDL_RenderClear(renderer);
SDL_Rect dstrect = { 0, 0, 0, 0 };
- for (int i = 0; i < strlen(testmsg); i++) {
- const char letter = testmsg[i];
+ for (int i = 0; i < buffer->length; i++) {
+ const char letter = buffer->buffer[i];
+ if (letter > 128) {
+ printf("TODO: Non-ASCII characters are not currently supported.\n");
+ continue;
+ }
+
const int char_index = font.char_index_for_code_point[letter];
BDFFontChar *glyph = &font.chars[char_index];
+ if (glyph == NULL) {
+ fprintf(stderr, "Font doesn't have character %c", letter);
+ continue;
+ }
dstrect.w = glyph->bounds.w;
dstrect.h = glyph->bounds.h;
SDL_RenderCopy(renderer, font_texture, &glyph->bounds, &dstrect);
- dstrect.x += glyph->next_glyph_offset.x;
- dstrect.y += glyph->next_glyph_offset.y;
+ if (letter == '\n') {
+ dstrect.x = 0;
+ dstrect.y += font.bounds.h;
+ } else {
+ dstrect.x += glyph->next_glyph_offset.x;
+ dstrect.y += glyph->next_glyph_offset.y;
+ }
}
+}
+
+void window_redraw(struct editor_state *editor)
+{
+ SDL_RenderClear(renderer);
+
+ editor_scroll(editor);
+ struct append_buffer buffer = ABUF_INIT;
+
+ editor_draw_rows(editor, &buffer);
+ editor_draw_status_bar(editor, &buffer);
+ editor_draw_message_bar(editor, &buffer);
+
+ draw_font_text(&buffer);
+
SDL_RenderPresent(renderer);
SDL_UpdateWindowSurface(window);
}