diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-04 17:18:15 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-04 17:18:15 -0500 |
commit | 306505e714b7caf146b8ec8386b407d57555563d (patch) | |
tree | 9cebf2eaf83899a7aa80fff70dd4d56cf4aa29d6 /ted-base.c | |
parent | 16ab3629d435d52539b6345d79433e27c367ce83 (diff) |
commands to change the font size
Diffstat (limited to 'ted-base.c')
-rw-r--r-- | ted-base.c | 72 |
1 files changed, 49 insertions, 23 deletions
@@ -1,26 +1,3 @@ -typedef struct { - u32 line_number; // config line number where this was set - Command command; // this will be 0 (COMMAND_UNKNOWN) if there's no action for the key - i64 argument; -} KeyAction; - -#define SCANCODE_COUNT 0x120 // SDL scancodes should be less than this value. -// a "key combo" is some subset of {control, shift, alt} + some key. -#define KEY_COMBO_COUNT (SCANCODE_COUNT << 3) -#define KEY_MODIFIER_CTRL_BIT 0 -#define KEY_MODIFIER_SHIFT_BIT 1 -#define KEY_MODIFIER_ALT_BIT 2 -#define KEY_MODIFIER_CTRL (1<<KEY_MODIFIER_CTRL_BIT) -#define KEY_MODIFIER_SHIFT (1<<KEY_MODIFIER_SHIFT_BIT) -#define KEY_MODIFIER_ALT (1<<KEY_MODIFIER_ALT_BIT) -// ctrl+alt+c is encoded as SDL_SCANCODE_C << 3 | KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT - -typedef struct { - TextBuffer *active_buffer; - Settings settings; - KeyAction key_actions[KEY_COMBO_COUNT]; - char error[256]; -} Ted; // this is a macro so we get -Wformat warnings #define ted_seterr(buffer, ...) \ @@ -56,3 +33,52 @@ static void *ted_realloc(Ted *ted, void *p, size_t new_size) { return ret; } +// should the working directory be searched for files? set to true if the executable isn't "installed" +static bool ted_search_cwd = false; +#if _WIN32 +// @TODO +#else +static char const *const ted_global_data_dir = "/usr/share/ted"; +#endif + +// Check the various places a file could be, and return the full path. +static Status ted_get_file(char const *name, char *out, size_t outsz) { +#if _WIN32 + #error "@TODO(windows)" +#else + if (ted_search_cwd && fs_file_exists(name)) { + // check in current working directory + str_cpy(out, outsz, name); + return true; + } + + char *home = getenv("HOME"); + if (home) { + str_printf(out, outsz, "%s/.local/share/ted/%s", home, name); + if (!fs_file_exists(out)) { + str_printf(out, outsz, "%s/%s", ted_global_data_dir, name); + if (!fs_file_exists(out)) + return false; + } + } + return true; +#endif +} + +static void ted_load_font(Ted *ted) { + char font_filename[TED_PATH_MAX]; + if (ted_get_file("assets/font.ttf", font_filename, sizeof font_filename)) { + Font *font = text_font_load(font_filename, ted->settings.text_size); + if (font) { + if (ted->font) { + text_font_free(ted->font); + } + ted->font = font; + } else { + ted_seterr(ted, "Couldn't load font: %s", text_get_err()); + text_clear_err(); + } + } else { + ted_seterr(ted, "Couldn't find font file. There is probably a problem with your ted installation."); + } +} |