diff options
-rw-r--r-- | command.c | 28 | ||||
-rw-r--r-- | config.c | 1 | ||||
-rw-r--r-- | main.c | 37 | ||||
-rw-r--r-- | ted.cfg | 2 | ||||
-rw-r--r-- | ted.h | 1 |
5 files changed, 49 insertions, 20 deletions
@@ -481,20 +481,24 @@ void command_execute(Ted *ted, Command c, i64 argument) { menu_open(ted, MENU_COMMAND_SELECTOR); break; - case CMD_TEXT_SIZE_INCREASE: { - i64 new_text_size = settings->text_size + argument; - if (new_text_size >= TEXT_SIZE_MIN && new_text_size <= TEXT_SIZE_MAX) { - settings->text_size = (u16)new_text_size; - ted_load_fonts(ted); + case CMD_TEXT_SIZE_INCREASE: + if (argument != 0) { + i64 new_text_size = settings->text_size + argument; + if (new_text_size >= TEXT_SIZE_MIN && new_text_size <= TEXT_SIZE_MAX) { + settings->text_size = (u16)new_text_size; + ted_load_fonts(ted); + } } - } break; - case CMD_TEXT_SIZE_DECREASE: { - i64 new_text_size = settings->text_size - argument; - if (new_text_size >= TEXT_SIZE_MIN && new_text_size <= TEXT_SIZE_MAX) { - settings->text_size = (u16)new_text_size; - ted_load_fonts(ted); + break; + case CMD_TEXT_SIZE_DECREASE: + if (argument != 0) { + i64 new_text_size = settings->text_size - argument; + if (new_text_size >= TEXT_SIZE_MIN && new_text_size <= TEXT_SIZE_MAX) { + settings->text_size = (u16)new_text_size; + ted_load_fonts(ted); + } } - } break; + break; case CMD_VIEW_ONLY: if (buffer) buffer->view_only = !buffer->view_only; @@ -114,6 +114,7 @@ static SettingFloat const settings_float[] = { {"cursor-blink-time-on", &settings_zero.cursor_blink_time_on, 0, 1000, true}, {"cursor-blink-time-off", &settings_zero.cursor_blink_time_off, 0, 1000, true}, {"hover-time", &settings_zero.hover_time, 0, INFINITY, true}, + {"ctrl-scroll-adjust-text-size", &settings_zero.ctrl_scroll_adjust_text_size, -10, 10, true}, }; static SettingString const settings_string[] = { {"build-default-command", settings_zero.build_default_command, sizeof settings_zero.build_default_command, true}, @@ -585,6 +585,7 @@ int main(int argc, char **argv) { } double start_time = time_get_seconds(); + double scroll_wheel_text_size_change = 0.0; while (!ted->quit) { double frame_start = time_get_seconds(); @@ -620,14 +621,20 @@ int main(int argc, char **argv) { command_execute(ted, CMD_QUIT, 1); break; case SDL_MOUSEWHEEL: { - // scroll with mouse wheel - Sint32 dx = event.wheel.x, dy = -event.wheel.y; - Autocomplete *ac = &ted->autocomplete; - if (ac->open && rect_contains_point(ac->rect, ted->mouse_pos)) { - autocomplete_scroll(ted, dy); - } else { - ted->scroll_total_x += dx; - ted->scroll_total_y += dy; + if (ctrl_down) { + // adjust text size with ctrl+scroll + Settings *settings = ted_active_settings(ted); + scroll_wheel_text_size_change += settings->ctrl_scroll_adjust_text_size * event.wheel.preciseY; + } else if (key_modifier == 0) { + // scroll with mouse wheel + Sint32 dx = event.wheel.x, dy = -event.wheel.y; + Autocomplete *ac = &ted->autocomplete; + if (ac->open && rect_contains_point(ac->rect, ted->mouse_pos)) { + autocomplete_scroll(ted, dy); + } else { + ted->scroll_total_x += dx; + ted->scroll_total_y += dy; + } } } break; case SDL_MOUSEBUTTONDOWN: { @@ -803,6 +810,20 @@ int main(int argc, char **argv) { Uint32 time_this_frame = SDL_GetTicks(); frame_dt = 0.001 * (time_this_frame - time_at_last_frame); time_at_last_frame = time_this_frame; + + + } + + { + // when the user ctrl+scrolls, only actually change the text size + // every 100ms, to avoid loading the font over and over again super fast + static double last_font_adjust = 0; + if (ted->frame_time - last_font_adjust > 0.1) { + last_font_adjust = ted->frame_time; + int dsize = (int)floor(scroll_wheel_text_size_change); + command_execute(ted, CMD_TEXT_SIZE_INCREASE, dsize); + scroll_wheel_text_size_change -= dsize; + } } TextBuffer *active_buffer = ted->active_buffer; @@ -68,6 +68,8 @@ max-file-size = 20000000 # absolute maximum file size. # ted will produce an error if a file larger than this is loaded. max-file-size-view-only = 100000000 +# how much ctrl+scroll wheel changes the text size (0 for no change, negative to invert change) +ctrl-scroll-adjust-text-size = 1.0 # whether to use vsync or not. you probably want this on. vsync = on @@ -108,6 +108,7 @@ typedef struct { u32 colors[COLOR_COUNT]; float cursor_blink_time_on, cursor_blink_time_off; float hover_time; + float ctrl_scroll_adjust_text_size; u32 max_file_size; u32 max_file_size_view_only; u16 framerate_cap; |