mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
TextEdit: Change font size with Ctrl+Mouse Wheel Up/Down
This commit is contained in:
parent
55b83157e7
commit
bc9f9b1c6a
@ -1452,10 +1452,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
|
||||
}
|
||||
|
||||
if (mb.pressed) {
|
||||
if (mb.button_index==BUTTON_WHEEL_UP) {
|
||||
if (mb.button_index==BUTTON_WHEEL_UP && !mb.mod.command) {
|
||||
v_scroll->set_val( v_scroll->get_val() -3 );
|
||||
}
|
||||
if (mb.button_index==BUTTON_WHEEL_DOWN) {
|
||||
if (mb.button_index==BUTTON_WHEEL_DOWN && !mb.mod.command) {
|
||||
v_scroll->set_val( v_scroll->get_val() +3 );
|
||||
}
|
||||
if (mb.button_index==BUTTON_WHEEL_LEFT) {
|
||||
|
@ -516,7 +516,7 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
|
||||
|
||||
if (tex.texture.is_null()) {
|
||||
tex.texture.instance();
|
||||
tex.texture->create_from_image(img,0/*Texture::FLAG_FILTER*/);
|
||||
tex.texture->create_from_image(img,Texture::FLAG_VIDEO_SURFACE);
|
||||
} else {
|
||||
tex.texture->set_data(img); //update
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "editor_settings.h"
|
||||
#include "scene/gui/margin_container.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/resources/dynamic_font.h"
|
||||
#include "os/keyboard.h"
|
||||
|
||||
void GotoLineDialog::popup_find_line(TextEdit *p_edit) {
|
||||
@ -974,6 +975,48 @@ FindReplaceDialog::FindReplaceDialog() {
|
||||
|
||||
/*** CODE EDITOR ****/
|
||||
|
||||
void CodeTextEditor::_text_editor_input_event(const InputEvent& p_event) {
|
||||
|
||||
if (p_event.type==InputEvent::MOUSE_BUTTON) {
|
||||
|
||||
const InputEventMouseButton& mb=p_event.mouse_button;
|
||||
|
||||
if (mb.pressed && mb.mod.command) {
|
||||
|
||||
if (mb.button_index==BUTTON_WHEEL_UP) {
|
||||
|
||||
font_resize_val+=1;
|
||||
|
||||
if (font_resize_timer->get_time_left()==0)
|
||||
font_resize_timer->start();
|
||||
|
||||
} else if (mb.button_index==BUTTON_WHEEL_DOWN) {
|
||||
|
||||
font_resize_val-=1;
|
||||
|
||||
if (font_resize_timer->get_time_left()==0)
|
||||
font_resize_timer->start();
|
||||
}
|
||||
}
|
||||
} else if (p_event.type==InputEvent::KEY) {
|
||||
|
||||
const InputEventKey& k=p_event.key;
|
||||
|
||||
if (k.pressed && k.mod.command) {
|
||||
|
||||
if (k.scancode==KEY_0) { // reset source font size to default
|
||||
|
||||
Ref<DynamicFont> font = text_editor->get_font("font");
|
||||
|
||||
if (font.is_valid()) {
|
||||
EditorSettings::get_singleton()->set("global/source_font_size",14);
|
||||
font->set_size(14);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CodeTextEditor::_line_col_changed() {
|
||||
|
||||
String text = String()+TTR("Line:")+" "+itos(text_editor->cursor_get_line()+1)+", "+TTR("Col:")+" "+itos(text_editor->cursor_get_column());
|
||||
@ -1011,6 +1054,22 @@ void CodeTextEditor::_complete_request() {
|
||||
text_editor->code_complete(strs);
|
||||
}
|
||||
|
||||
void CodeTextEditor::_font_resize_timeout() {
|
||||
|
||||
Ref<DynamicFont> font = text_editor->get_font("font");
|
||||
|
||||
if (font.is_valid()) {
|
||||
int size=font->get_size()+font_resize_val;
|
||||
|
||||
if (size>=8 && size<=96) {
|
||||
EditorSettings::get_singleton()->set("global/source_font_size",size);
|
||||
font->set_size(size);
|
||||
}
|
||||
|
||||
font_resize_val=0;
|
||||
}
|
||||
}
|
||||
|
||||
void CodeTextEditor::set_error(const String& p_error) {
|
||||
|
||||
if (p_error!="") {
|
||||
@ -1026,15 +1085,15 @@ void CodeTextEditor::_update_font() {
|
||||
|
||||
// FONTS
|
||||
String editor_font = EDITOR_DEF("text_editor/font", "");
|
||||
bool font_overrode = false;
|
||||
bool font_overridden = false;
|
||||
if (editor_font!="") {
|
||||
Ref<Font> fnt = ResourceLoader::load(editor_font);
|
||||
if (fnt.is_valid()) {
|
||||
text_editor->add_font_override("font",fnt);
|
||||
font_overrode = true;
|
||||
font_overridden = true;
|
||||
}
|
||||
}
|
||||
if(!font_overrode)
|
||||
if(!font_overridden)
|
||||
text_editor->add_font_override("font",get_font("source","EditorFonts"));
|
||||
}
|
||||
|
||||
@ -1078,12 +1137,14 @@ void CodeTextEditor::_notification(int p_what) {
|
||||
|
||||
void CodeTextEditor::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method("_text_editor_input_event",&CodeTextEditor::_text_editor_input_event);
|
||||
ObjectTypeDB::bind_method("_line_col_changed",&CodeTextEditor::_line_col_changed);
|
||||
ObjectTypeDB::bind_method("_text_changed",&CodeTextEditor::_text_changed);
|
||||
ObjectTypeDB::bind_method("_on_settings_change",&CodeTextEditor::_on_settings_change);
|
||||
ObjectTypeDB::bind_method("_text_changed_idle_timeout",&CodeTextEditor::_text_changed_idle_timeout);
|
||||
ObjectTypeDB::bind_method("_code_complete_timer_timeout",&CodeTextEditor::_code_complete_timer_timeout);
|
||||
ObjectTypeDB::bind_method("_complete_request",&CodeTextEditor::_complete_request);
|
||||
ObjectTypeDB::bind_method("_font_resize_timeout",&CodeTextEditor::_font_resize_timeout);
|
||||
}
|
||||
|
||||
CodeTextEditor::CodeTextEditor() {
|
||||
@ -1139,6 +1200,7 @@ CodeTextEditor::CodeTextEditor() {
|
||||
line_col->set_valign(Label::VALIGN_CENTER);
|
||||
|
||||
|
||||
text_editor->connect("input_event", this,"_text_editor_input_event");
|
||||
text_editor->connect("cursor_changed", this,"_line_col_changed");
|
||||
text_editor->connect("text_changed", this,"_text_changed");
|
||||
text_editor->connect("request_completion", this,"_complete_request");
|
||||
@ -1151,5 +1213,12 @@ CodeTextEditor::CodeTextEditor() {
|
||||
|
||||
code_complete_timer->connect("timeout", this,"_code_complete_timer_timeout");
|
||||
|
||||
font_resize_val=0;
|
||||
font_resize_timer = memnew(Timer);
|
||||
add_child(font_resize_timer);
|
||||
font_resize_timer->set_one_shot(true);
|
||||
font_resize_timer->set_wait_time(0.07);
|
||||
font_resize_timer->connect("timeout", this, "_font_resize_timeout");
|
||||
|
||||
EditorSettings::get_singleton()->connect("settings_changed",this,"_on_settings_change");
|
||||
}
|
||||
|
@ -202,22 +202,27 @@ class CodeTextEditor : public VBoxContainer {
|
||||
Timer *code_complete_timer;
|
||||
bool enable_complete_timer;
|
||||
|
||||
Timer *font_resize_timer;
|
||||
int font_resize_val;
|
||||
|
||||
Label *error;
|
||||
|
||||
void _on_settings_change();
|
||||
|
||||
void _update_font();
|
||||
void _complete_request();
|
||||
void _font_resize_timeout();
|
||||
|
||||
void _text_editor_input_event(const InputEvent& p_event);
|
||||
|
||||
protected:
|
||||
|
||||
void set_error(const String& p_error);
|
||||
|
||||
|
||||
virtual void _load_theme_settings() {}
|
||||
virtual void _validate_script()=0;
|
||||
virtual void _code_complete_script(const String& p_code, List<String>* r_options) {};
|
||||
|
||||
|
||||
void _text_changed_idle_timeout();
|
||||
void _code_complete_timer_timeout();
|
||||
void _text_changed();
|
||||
@ -225,7 +230,6 @@ protected:
|
||||
void _notification(int);
|
||||
static void _bind_methods();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
TextEdit *get_text_edit() { return text_editor; }
|
||||
|
@ -515,7 +515,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
|
||||
set("global/font_size",14);
|
||||
hints["global/font_size"]=PropertyInfo(Variant::INT,"global/font_size",PROPERTY_HINT_RANGE,"10,40,1",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED);
|
||||
set("global/source_font_size",14);
|
||||
hints["global/source_font_size"]=PropertyInfo(Variant::INT,"global/source_font_size",PROPERTY_HINT_RANGE,"10,40,1",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED);
|
||||
hints["global/source_font_size"]=PropertyInfo(Variant::INT,"global/source_font_size",PROPERTY_HINT_RANGE,"8,96,1",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED);
|
||||
set("global/custom_font","");
|
||||
hints["global/custom_font"]=PropertyInfo(Variant::STRING,"global/custom_font",PROPERTY_HINT_GLOBAL_FILE,"*.fnt",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED);
|
||||
set("global/custom_theme","");
|
||||
|
Loading…
Reference in New Issue
Block a user