diff options
-rw-r--r-- | editor.c | 3 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | window.c | 18 | ||||
-rw-r--r-- | window.h | 3 |
4 files changed, 18 insertions, 8 deletions
@@ -28,8 +28,7 @@ void init_editor(struct editor_state* editor) editor->status_message_time = 0; editor->syntax = NULL; - if (get_window_size(&editor->screen_rows, &editor->screen_cols) == -1) - die("get_window_size"); + window_get_size(&editor->screen_rows, &editor->screen_cols); editor->screen_rows -= 2; } @@ -5,7 +5,7 @@ int main(int argc, char** argv) { - window_init(); + window_init("Text editor", 40, 80); struct editor_state editor; init_editor(&editor); @@ -13,7 +13,7 @@ static SDL_Texture *font_texture = NULL; static PSFFont font; -void window_init() +void window_init(const char *title, int rows, int cols) { /* TODO: There should be a 'panic' method of sorts to be reused here. */ if (SDL_Init(SDL_INIT_VIDEO) != 0) { @@ -21,8 +21,11 @@ void window_init() return; } - window = SDL_CreateWindow("Bitmap font test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - 640, 480, SDL_WINDOW_SHOWN); + font = font_load("terminus/ter-u12n.psf"); + int window_width = cols * font.width; + int window_height = rows * font.height; + + window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, 0); if (window == NULL) { fprintf(stderr, "Failed to create a window: %s\n", SDL_GetError()); return; @@ -34,7 +37,6 @@ void window_init() return; } - font = font_load("terminus/ter-u12n.psf"); font_texture = font_create_texture(renderer, &font); SDL_ShowWindow(window); @@ -144,6 +146,14 @@ void window_redraw(struct editor_state *editor) SDL_UpdateWindowSurface(window); } +void window_get_size(int *rows, int *cols) +{ + int w, h; + SDL_GetWindowSize(window, &w, &h); + *cols = w / font.width; + *rows = h / font.height; +} + void window_destroy() { font_destroy(&font); @@ -3,9 +3,10 @@ struct editor_state; -void window_init(); +void window_init(const char *title, int rows, int cols); int window_handle_event(struct editor_state *editor); void window_redraw(struct editor_state *editor); +void window_get_size(int *rows, int *cols); void window_destroy(); #endif |