4747#include " editor/plugins/script_editor_plugin.h"
4848#include " editor/themes/editor_scale.h"
4949#include " scene/gui/line_edit.h"
50+ #include " scene/gui/separator.h"
5051
5152#include " modules/modules_enabled.gen.h" // For gdscript, mono.
5253
@@ -331,7 +332,111 @@ void EditorHelp::_class_desc_select(const String &p_select) {
331332 }
332333}
333334
334- void EditorHelp::_class_desc_input (const Ref<InputEvent> &p_input) {
335+ void EditorHelp::_class_desc_input (const Ref<InputEvent> &p_event) {
336+ Ref<InputEventMouseButton> mb = p_event;
337+
338+ if (mb.is_valid () && mb->is_command_or_control_pressed ()) {
339+ if (mb->is_pressed ()) {
340+ if (mb->get_button_index () == MouseButton::WHEEL_UP) {
341+ _zoom_in ();
342+ accept_event ();
343+ return ;
344+ }
345+ if (mb->get_button_index () == MouseButton::WHEEL_DOWN) {
346+ _zoom_out ();
347+ accept_event ();
348+ return ;
349+ }
350+ } else {
351+ // Prevents of button's 'released' event propagation, causing RichTextLabel scroll while zooming.
352+ if (mb->get_button_index () == MouseButton::WHEEL_UP || mb->get_button_index () == MouseButton::WHEEL_DOWN) {
353+ accept_event ();
354+ return ;
355+ }
356+ }
357+ }
358+
359+ Ref<InputEventMagnifyGesture> magnify_gesture = p_event;
360+ if (magnify_gesture.is_valid ()) {
361+ _zoom_to (zoom_factor * powf (magnify_gesture->get_factor (), 0 .25f ));
362+ accept_event ();
363+ return ;
364+ }
365+
366+ Ref<InputEventKey> k = p_event;
367+ if (k.is_valid () && k->is_pressed ()) {
368+ if (ED_IS_SHORTCUT (" script_editor/zoom_in" , p_event)) {
369+ _zoom_in ();
370+ accept_event ();
371+ return ;
372+ }
373+ if (ED_IS_SHORTCUT (" script_editor/zoom_out" , p_event)) {
374+ _zoom_out ();
375+ accept_event ();
376+ return ;
377+ }
378+ if (ED_IS_SHORTCUT (" script_editor/reset_zoom" , p_event)) {
379+ _zoom_to (1 );
380+ accept_event ();
381+ return ;
382+ }
383+ }
384+ }
385+
386+ void EditorHelp::_zoom_popup_id_pressed (int p_idx) {
387+ _zoom_to (zoom_button->get_popup ()->get_item_metadata (p_idx));
388+ }
389+
390+ void EditorHelp::_zoom_in () {
391+ int s = class_desc->get_theme_font_size (" normal_font_size" );
392+ _zoom_to (zoom_factor * (s + MAX (1 .0f , EDSCALE)) / s);
393+ }
394+
395+ void EditorHelp::_zoom_out () {
396+ int s = class_desc->get_theme_font_size (" normal_font_size" );
397+ _zoom_to (zoom_factor * (s - MAX (1 .0f , EDSCALE)) / s);
398+ }
399+
400+ void EditorHelp::_zoom_to (float p_zoom_factor) {
401+ if (zoom_factor == p_zoom_factor) {
402+ return ;
403+ }
404+
405+ float old_zoom_factor = zoom_factor;
406+
407+ set_zoom_factor (p_zoom_factor);
408+
409+ if (old_zoom_factor != zoom_factor) {
410+ emit_signal (SNAME (" zoomed" ), zoom_factor);
411+ }
412+ }
413+
414+ void EditorHelp::set_zoom_factor (float p_zoom_factor) {
415+ int preset_count = sizeof (ZOOM_FACTOR_PRESETS) / sizeof (float );
416+ zoom_factor = CLAMP (p_zoom_factor, ZOOM_FACTOR_PRESETS[0 ], ZOOM_FACTOR_PRESETS[preset_count - 1 ]);
417+
418+ int neutral_help_font_size = int (EDITOR_GET (" text_editor/help/help_font_size" )) * EDSCALE;
419+ int neutral_help_title_font_size = int (EDITOR_GET (" text_editor/help/help_title_font_size" )) * EDSCALE;
420+ int neutral_help_source_font_size = int (EDITOR_GET (" text_editor/help/help_source_font_size" )) * EDSCALE;
421+ int neutral_help_kb_font_size = (int (EDITOR_GET (" text_editor/help/help_source_font_size" )) - 1 ) * EDSCALE;
422+
423+ int new_help_font_size = Math::round (zoom_factor * neutral_help_font_size);
424+ int new_help_title_font_size = Math::round (zoom_factor * neutral_help_title_font_size);
425+ int new_help_source_font_size = Math::round (zoom_factor * neutral_help_source_font_size);
426+ int new_help_kb_font_size = Math::round (zoom_factor * neutral_help_kb_font_size);
427+
428+ theme_cache.doc_font_size = new_help_font_size;
429+ theme_cache.doc_title_font_size = new_help_title_font_size;
430+ theme_cache.doc_code_font_size = new_help_source_font_size;
431+ theme_cache.doc_kbd_font_size = new_help_kb_font_size;
432+
433+ _update_doc ();
434+ _class_desc_resized (true );
435+ zoom_button->set_text (itos (Math::round (zoom_factor * 100 )) + " %" );
436+ }
437+
438+ float EditorHelp::get_zoom_factor () const {
439+ return zoom_factor;
335440}
336441
337442void EditorHelp::_class_desc_resized (bool p_force_update_theme) {
@@ -926,8 +1031,6 @@ void EditorHelp::_update_doc() {
9261031 return ;
9271032 }
9281033
929- scroll_locked = true ;
930-
9311034 class_desc->clear ();
9321035 method_line.clear ();
9331036 section_line.clear ();
@@ -1027,11 +1130,13 @@ void EditorHelp::_update_doc() {
10271130
10281131 class_desc->push_indent (1 );
10291132 class_desc->push_font (theme_cache.doc_bold_font );
1133+ class_desc->push_font_size (theme_cache.doc_code_font_size );
10301134 class_desc->push_color (theme_cache.text_color );
10311135
10321136 _add_text (brief_class_descr);
10331137
10341138 class_desc->pop (); // color
1139+ class_desc->pop (); // font_size
10351140 class_desc->pop (); // font
10361141 class_desc->pop (); // indent
10371142 }
@@ -2263,9 +2368,6 @@ void EditorHelp::_update_doc() {
22632368 class_desc->add_newline ();
22642369 class_desc->add_newline ();
22652370
2266- // Free the scroll.
2267- scroll_locked = false ;
2268-
22692371#undef HANDLE_DOC
22702372}
22712373
@@ -2349,7 +2451,7 @@ void EditorHelp::_help_callback(const String &p_topic) {
23492451 }
23502452}
23512453
2352- static void _add_text_to_rt (const String &p_bbcode, RichTextLabel *p_rt, const Control *p_owner_node, const String &p_class) {
2454+ static void _add_text_to_rt (const String &p_bbcode, RichTextLabel *p_rt, const Control *p_owner_node, const String &p_class, int p_doc_code_font_size = 0 , int p_doc_kbd_font_size = 0 ) {
23532455 const DocTools *doc = EditorHelp::get_doc_data ();
23542456
23552457 bool is_native = false ;
@@ -2368,8 +2470,15 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
23682470 const Ref<Font> doc_code_font = p_owner_node->get_theme_font (SNAME (" doc_source" ), EditorStringName (EditorFonts));
23692471 const Ref<Font> doc_kbd_font = p_owner_node->get_theme_font (SNAME (" doc_keyboard" ), EditorStringName (EditorFonts));
23702472
2371- const int doc_code_font_size = p_owner_node->get_theme_font_size (SNAME (" doc_source_size" ), EditorStringName (EditorFonts));
2372- const int doc_kbd_font_size = p_owner_node->get_theme_font_size (SNAME (" doc_keyboard_size" ), EditorStringName (EditorFonts));
2473+ int doc_code_font_size = p_doc_code_font_size;
2474+ int doc_kbd_font_size = p_doc_kbd_font_size;
2475+
2476+ if (doc_code_font_size <= 0 ) {
2477+ doc_code_font_size = p_owner_node->get_theme_font_size (SNAME (" doc_source_size" ), EditorStringName (EditorFonts));
2478+ }
2479+ if (doc_kbd_font_size <= 0 ) {
2480+ doc_kbd_font_size = p_owner_node->get_theme_font_size (SNAME (" doc_keyboard_size" ), EditorStringName (EditorFonts));
2481+ }
23732482
23742483 const Color type_color = p_owner_node->get_theme_color (SNAME (" type_color" ), SNAME (" EditorHelp" ));
23752484 const Color code_color = p_owner_node->get_theme_color (SNAME (" code_color" ), SNAME (" EditorHelp" ));
@@ -2837,7 +2946,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
28372946}
28382947
28392948void EditorHelp::_add_text (const String &p_bbcode) {
2840- _add_text_to_rt (p_bbcode, class_desc, this , edited_class);
2949+ _add_text_to_rt (p_bbcode, class_desc, this , edited_class, theme_cache. doc_code_font_size , theme_cache. doc_kbd_font_size );
28412950}
28422951
28432952int EditorHelp::doc_generation_count = 0 ;
@@ -3085,6 +3194,7 @@ void EditorHelp::_bind_methods() {
30853194
30863195 ADD_SIGNAL (MethodInfo (" go_to_help" ));
30873196 ADD_SIGNAL (MethodInfo (" request_save_history" ));
3197+ ADD_SIGNAL (MethodInfo (" zoomed" , PropertyInfo (Variant::FLOAT, " zoom_factor" )));
30883198}
30893199
30903200void EditorHelp::init_gdext_pointers () {
@@ -3097,6 +3207,10 @@ EditorHelp::EditorHelp() {
30973207
30983208 EDITOR_DEF (" text_editor/help/sort_functions_alphabetically" , true );
30993209
3210+ ED_SHORTCUT (" script_editor/zoom_in" , TTR (" Zoom In" ), KeyModifierMask::CMD_OR_CTRL | Key::EQUAL);
3211+ ED_SHORTCUT (" script_editor/zoom_out" , TTR (" Zoom Out" ), KeyModifierMask::CMD_OR_CTRL | Key::MINUS);
3212+ ED_SHORTCUT (" script_editor/reset_zoom" , TTR (" Reset Zoom" ), KeyModifierMask::CMD_OR_CTRL | Key::KEY_0);
3213+
31003214 class_desc = memnew (RichTextLabel);
31013215 class_desc->set_tab_size (8 );
31023216 add_child (class_desc);
@@ -3123,6 +3237,27 @@ EditorHelp::EditorHelp() {
31233237 toggle_scripts_button->set_flat (true );
31243238 toggle_scripts_button->connect (SceneStringName (pressed), callable_mp (this , &EditorHelp::_toggle_scripts_pressed));
31253239 status_bar->add_child (toggle_scripts_button);
3240+ status_bar->add_spacer ();
3241+ status_bar->add_child (memnew (VSeparator));
3242+
3243+ // Zoom
3244+ zoom_button = memnew (MenuButton);
3245+ status_bar->add_child (zoom_button);
3246+ zoom_button->set_flat (true );
3247+ zoom_button->set_v_size_flags (SIZE_EXPAND | SIZE_SHRINK_CENTER);
3248+ zoom_button->set_tooltip_text (TTR (" Zoom factor" ));
3249+ zoom_button->set_text (" 100 %" );
3250+
3251+ PopupMenu *zoom_menu = zoom_button->get_popup ();
3252+ int preset_count = sizeof (ZOOM_FACTOR_PRESETS) / sizeof (float );
3253+
3254+ for (int i = 0 ; i < preset_count; i++) {
3255+ float z = ZOOM_FACTOR_PRESETS[i];
3256+ zoom_menu->add_item (itos (Math::round (z * 100 )) + " %" );
3257+ zoom_menu->set_item_metadata (i, z);
3258+ }
3259+
3260+ zoom_menu->connect (SceneStringName (id_pressed), callable_mp (this , &EditorHelp::_zoom_popup_id_pressed));
31263261
31273262 class_desc->set_selection_enabled (true );
31283263 class_desc->set_context_menu_enabled (true );
0 commit comments