summaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2023-01-11 11:18:24 -0700
committercflip <cflip@cflip.net>2023-01-11 11:18:24 -0700
commit61c387397d03c479ca110a02bfa78cd39fa82656 (patch)
treec0c4a538867eef968e9c977053470999e89400bd /window.c
parent9e6f24187ebe2577fde7c7a971a8cc408f4aeaac (diff)
Get editor size from the window instead of the terminal
Previously the editor would resize itself upon startup by finding the size of the current terminal window, but now that it is running in an actual window it should get the number of rows and columns from there. This also adds parameters for the window size in rows and columns to the window_init() function.
Diffstat (limited to 'window.c')
-rw-r--r--window.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/window.c b/window.c
index 315e75e..219c0ca 100644
--- a/window.c
+++ b/window.c
@@ -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);