summaryrefslogtreecommitdiff
path: root/tools/editor
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2016-06-17 21:58:50 +0200
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2016-06-18 18:47:11 +0200
commitbc9f9b1c6ae0e5858790fe2463a175b451580fba (patch)
tree7af4be9df275f3a73ef5adffc02b906e0cf88e68 /tools/editor
parent55b83157e70a34a933a2a73f14a0052a832d0287 (diff)
TextEdit: Change font size with Ctrl+Mouse Wheel Up/Down
Diffstat (limited to 'tools/editor')
-rw-r--r--tools/editor/code_editor.cpp75
-rw-r--r--tools/editor/code_editor.h10
-rw-r--r--tools/editor/editor_settings.cpp2
3 files changed, 80 insertions, 7 deletions
diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp
index be5d9c47ff..644478923c 100644
--- a/tools/editor/code_editor.cpp
+++ b/tools/editor/code_editor.cpp
@@ -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");
}
diff --git a/tools/editor/code_editor.h b/tools/editor/code_editor.h
index 2e1bf46c02..bdfd295ded 100644
--- a/tools/editor/code_editor.h
+++ b/tools/editor/code_editor.h
@@ -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; }
diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp
index 4100644311..15c67cb548 100644
--- a/tools/editor/editor_settings.cpp
+++ b/tools/editor/editor_settings.cpp
@@ -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","");