diff options
| author | Bernhard Liebl | 2017-11-01 21:49:39 +0100 |
|---|---|---|
| committer | Bernhard Liebl | 2017-11-21 09:11:39 +0100 |
| commit | 80ad8afc85a90e6fda1b136b13c1eb42e35c115e (patch) | |
| tree | bc145bc5c008a2abfa159f4d5437c8d0b8813aca /editor/code_editor.cpp | |
| parent | 5ff84070ca3604b43e86562a3d000ed924a604a2 (diff) | |
| download | godot-80ad8afc85a90e6fda1b136b13c1eb42e35c115e.tar.gz godot-80ad8afc85a90e6fda1b136b13c1eb42e35c115e.tar.zst godot-80ad8afc85a90e6fda1b136b13c1eb42e35c115e.zip | |
Diffstat (limited to 'editor/code_editor.cpp')
| -rw-r--r-- | editor/code_editor.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index c7012a0c1..216f2027f 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -979,6 +979,23 @@ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { } } + Ref<InputEventMagnifyGesture> magnify_gesture = p_event; + if (magnify_gesture.is_valid()) { + + Ref<DynamicFont> font = text_editor->get_font("font"); + + if (font.is_valid()) { + if (font->get_size() != (int)font_size) { + font_size = font->get_size(); + } + + font_size *= powf(magnify_gesture->get_factor(), 0.25); + + _add_font_size((int)font_size - font->get_size()); + } + return; + } + Ref<InputEventKey> k = p_event; if (k.is_valid()) { @@ -999,14 +1016,15 @@ void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) { void CodeTextEditor::_zoom_in() { font_resize_val += EDSCALE; - - if (font_resize_timer->get_time_left() == 0) - font_resize_timer->start(); + _zoom_changed(); } void CodeTextEditor::_zoom_out() { font_resize_val -= EDSCALE; + _zoom_changed(); +} +void CodeTextEditor::_zoom_changed() { if (font_resize_timer->get_time_left() == 0) font_resize_timer->start(); } @@ -1067,16 +1085,25 @@ void CodeTextEditor::_complete_request() { void CodeTextEditor::_font_resize_timeout() { + if (_add_font_size(font_resize_val)) { + font_resize_val = 0; + } +} + +bool CodeTextEditor::_add_font_size(int p_delta) { + Ref<DynamicFont> font = text_editor->get_font("font"); if (font.is_valid()) { - int new_size = CLAMP(font->get_size() + font_resize_val, 8 * EDSCALE, 96 * EDSCALE); + int new_size = CLAMP(font->get_size() + p_delta, 8 * EDSCALE, 96 * EDSCALE); if (new_size != font->get_size()) { EditorSettings::get_singleton()->set("interface/editor/source_font_size", new_size / EDSCALE); font->set_size(new_size); } - font_resize_val = 0; + return true; + } else { + return false; } } @@ -1285,6 +1312,7 @@ CodeTextEditor::CodeTextEditor() { code_complete_timer->connect("timeout", this, "_code_complete_timer_timeout"); font_resize_val = 0; + font_size = -1; font_resize_timer = memnew(Timer); add_child(font_resize_timer); font_resize_timer->set_one_shot(true); |
