diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-05-29 11:37:26 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-05-29 11:37:52 -0300 |
commit | 3e8eb396d7cfec8a96efb78719c0556f1beccf68 (patch) | |
tree | 3f6e9adbac4c20989812b338ca7bc3a0b65f568d /tools/editor | |
parent | a5777994cbc06183af7db7d8233434f245d5b089 (diff) |
Finalized DynamicFont implementation
-DynamicFont uses Freetype by default
-Editor fonts are now scalable thanks to this
-Cleaned up documentation browser and added fonts for this
Diffstat (limited to 'tools/editor')
-rw-r--r-- | tools/editor/code_editor.cpp | 25 | ||||
-rw-r--r-- | tools/editor/code_editor.h | 1 | ||||
-rw-r--r-- | tools/editor/editor_fonts.cpp | 57 | ||||
-rw-r--r-- | tools/editor/editor_help.cpp | 56 | ||||
-rw-r--r-- | tools/editor/editor_node.cpp | 2 | ||||
-rw-r--r-- | tools/editor/editor_settings.cpp | 8 | ||||
-rw-r--r-- | tools/editor/icons/SCsub | 4 |
7 files changed, 113 insertions, 40 deletions
diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp index c92b40628c..d605a41600 100644 --- a/tools/editor/code_editor.cpp +++ b/tools/editor/code_editor.cpp @@ -544,7 +544,7 @@ void CodeTextEditor::set_error(const String& p_error) { } -void CodeTextEditor::_on_settings_change() { +void CodeTextEditor::_update_font() { // FONTS String editor_font = EDITOR_DEF("text_editor/font", ""); @@ -557,7 +557,12 @@ void CodeTextEditor::_on_settings_change() { } } if(!font_overrode) - text_editor->add_font_override("font",get_font("source","Fonts")); + text_editor->add_font_override("font",get_font("source","EditorFonts")); +} + +void CodeTextEditor::_on_settings_change() { + + _update_font(); // AUTO BRACE COMPLETION text_editor->set_auto_brace_completion( @@ -588,6 +593,9 @@ void CodeTextEditor::_notification(int p_what) { if (p_what==EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) _load_theme_settings(); + if (p_what==NOTIFICATION_ENTER_TREE) { + _update_font(); + } } void CodeTextEditor::_bind_methods() { @@ -607,19 +615,6 @@ CodeTextEditor::CodeTextEditor() { text_editor->set_area_as_parent_rect(); text_editor->set_margin(MARGIN_BOTTOM,20); - String editor_font = EDITOR_DEF("text_editor/font", ""); - bool font_overrode = 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; - } - } - - if (!font_overrode) - text_editor->add_font_override("font",get_font("source","Fonts")); - text_editor->set_show_line_numbers(true); text_editor->set_brace_matching(true); text_editor->set_auto_indent(true); diff --git a/tools/editor/code_editor.h b/tools/editor/code_editor.h index e28517c601..f1a1a7072f 100644 --- a/tools/editor/code_editor.h +++ b/tools/editor/code_editor.h @@ -135,6 +135,7 @@ class CodeTextEditor : public Control { void _on_settings_change(); + void _update_font(); void _complete_request(); protected: diff --git a/tools/editor/editor_fonts.cpp b/tools/editor/editor_fonts.cpp index a3ec08f986..e04dce294a 100644 --- a/tools/editor/editor_fonts.cpp +++ b/tools/editor/editor_fonts.cpp @@ -30,6 +30,9 @@ #include "doc_font.h" #include "doc_title_font.h" #include "doc_code_font.h" +#include "builtin_fonts.h" +#include "editor_settings.h" +#include "scene/resources/dynamic_font.h" static Ref<BitmapFont> make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref<Texture> &p_texture) { @@ -64,12 +67,54 @@ static Ref<BitmapFont> make_font(int p_height,int p_ascent, int p_valign, int p_ void editor_register_fonts(Ref<Theme> p_theme) { + Ref<DynamicFontData> dfd; + dfd.instance(); + dfd->set_font_ptr(_font_droid_sans,_font_droid_sans_size); + dfd->set_force_autohinter(true); //just looks better..i think? - Ref<BitmapFont> doc_font = make_font(_bi_font_doc_font_height,_bi_font_doc_font_ascent,0,_bi_font_doc_font_charcount,_bi_font_doc_font_characters,p_theme->get_icon("DocFont","EditorIcons")); - Ref<BitmapFont> doc_code_font = make_font(_bi_font_doc_code_font_height,_bi_font_doc_code_font_ascent,0,_bi_font_doc_code_font_charcount,_bi_font_doc_code_font_characters,p_theme->get_icon("DocCodeFont","EditorIcons")); - Ref<BitmapFont> doc_title_font = make_font(_bi_font_doc_title_font_height,_bi_font_doc_title_font_ascent,0,_bi_font_doc_title_font_charcount,_bi_font_doc_title_font_characters,p_theme->get_icon("DocTitleFont","EditorIcons")); - p_theme->set_font("doc","EditorFonts",doc_font); - p_theme->set_font("doc_code","EditorFonts",doc_code_font); - p_theme->set_font("doc_title","EditorFonts",doc_title_font); + Ref<DynamicFontData> dfmono; + dfmono.instance(); + dfmono->set_font_ptr(_font_source_code_pro,_font_source_code_pro_size); + //dfd->set_force_autohinter(true); //just looks better..i think? + + Ref<DynamicFont> df; + df.instance(); + df->set_size(int(EditorSettings::get_singleton()->get("global/font_size"))); + df->set_font_data(dfd); + + + p_theme->set_default_theme_font(df); + +// Ref<BitmapFont> doc_font = make_font(_bi_font_doc_font_height,_bi_font_doc_font_ascent,0,_bi_font_doc_font_charcount,_bi_font_doc_font_characters,p_theme->get_icon("DocFont","EditorIcons")); +// Ref<BitmapFont> doc_title_font = make_font(_bi_font_doc_title_font_height,_bi_font_doc_title_font_ascent,0,_bi_font_doc_title_font_charcount,_bi_font_doc_title_font_characters,p_theme->get_icon("DocTitleFont","EditorIcons")); +// Ref<BitmapFont> doc_code_font = make_font(_bi_font_doc_code_font_height,_bi_font_doc_code_font_ascent,0,_bi_font_doc_code_font_charcount,_bi_font_doc_code_font_characters,p_theme->get_icon("DocCodeFont","EditorIcons")); + + Ref<DynamicFont> df_title; + df_title.instance(); + df_title->set_size(int(EDITOR_DEF("help/help_title_font_size",18))); + df_title->set_font_data(dfd); + + Ref<DynamicFont> df_doc; + df_doc.instance(); + df_doc->set_size(int(EDITOR_DEF("help/help_font_size",16))); + df_doc->set_font_data(dfd); + + p_theme->set_font("doc","EditorFonts",df_doc); + p_theme->set_font("doc_title","EditorFonts",df_title); + + + Ref<DynamicFont> df_code; + df_code.instance(); + df_code->set_size(int(EditorSettings::get_singleton()->get("global/source_font_size"))); + df_code->set_font_data(dfmono); + + p_theme->set_font("source","EditorFonts",df_code); + + Ref<DynamicFont> df_doc_code; + df_doc_code.instance(); + df_doc_code->set_size(int(EDITOR_DEF("help/help_source_font_size",14))); + df_doc_code->set_font_data(dfmono); + + p_theme->set_font("doc_source","EditorFonts",df_doc_code); } diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp index 616037c545..b426def503 100644 --- a/tools/editor/editor_help.cpp +++ b/tools/editor/editor_help.cpp @@ -130,6 +130,7 @@ void EditorHelpSearch::_update_search() { else cicon=def_icon; + for(int i=0;i<c.methods.size();i++) { if( (term.begins_with(".") && c.methods[i].name.begins_with(term.right(1))) || (term.ends_with("(") && c.methods[i].name.ends_with(term.left(term.length()-1).strip_edges())) @@ -697,13 +698,13 @@ Error EditorHelp::_goto_desc(const String& p_class,int p_vscr) { //edited_class->show(); - DocData::ClassDoc &cd=doc->class_list[p_class]; + DocData::ClassDoc cd=doc->class_list[p_class]; //make a copy, so we can sort without worrying Color h_color; - Ref<Font> doc_font = get_font("normal","Fonts"); - Ref<Font> doc_code_font = get_font("source","Fonts"); - Ref<Font> doc_title_font = get_font("large","Fonts"); + Ref<Font> doc_font = get_font("doc","EditorFonts"); + Ref<Font> doc_title_font = get_font("doc_title","EditorFonts"); + Ref<Font> doc_code_font = get_font("doc_source","EditorFonts"); h_color=Color(1,1,1,1); @@ -794,7 +795,7 @@ Error EditorHelp::_goto_desc(const String& p_class,int p_vscr) { //class_desc->add_newline(); class_desc->add_newline(); class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color")); - class_desc->push_font( get_font("normal","Fonts") ); + class_desc->push_font( doc_font ); class_desc->push_indent(1); _add_text(cd.brief_description); class_desc->pop(); @@ -805,9 +806,14 @@ Error EditorHelp::_goto_desc(const String& p_class,int p_vscr) { } bool method_descr=false; + bool sort_methods = EditorSettings::get_singleton()->get("help/sort_functions_alphabetically"); + if (cd.methods.size()) { + if (sort_methods) + cd.methods.sort(); + class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); class_desc->push_font(doc_title_font); class_desc->add_text(TTR("Public Methods:")); @@ -979,6 +985,9 @@ Error EditorHelp::_goto_desc(const String& p_class,int p_vscr) { } if (cd.signals.size()) { + if (sort_methods) { + cd.signals.sort(); + } class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); class_desc->push_font(doc_title_font); class_desc->add_text(TTR("Signals:")); @@ -1098,7 +1107,7 @@ Error EditorHelp::_goto_desc(const String& p_class,int p_vscr) { class_desc->add_newline(); class_desc->add_newline(); class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color")); - class_desc->push_font( get_font("normal","Fonts") ); + class_desc->push_font( doc_font ); class_desc->push_indent(1); _add_text(cd.description); class_desc->pop(); @@ -1168,7 +1177,7 @@ Error EditorHelp::_goto_desc(const String& p_class,int p_vscr) { class_desc->add_newline(); class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color")); - class_desc->push_font( get_font("normal","Fonts") ); + class_desc->push_font( doc_font ); class_desc->push_indent(1); _add_text(cd.methods[i].description); class_desc->pop(); @@ -1248,9 +1257,12 @@ void EditorHelp::_add_text(const String& p_bbcode) { class_desc->push_indent(1);*/ int pos = 0; + Ref<Font> doc_font = get_font("doc","EditorFonts"); + Ref<Font> doc_code_font = get_font("doc_source","EditorFonts"); + String bbcode=p_bbcode.replace("\t"," ").replace("\r"," ").strip_edges(); - //find double newlines, keep them + //change newlines for double newlines for(int i=0;i<bbcode.length();i++) { //find valid newlines (double) @@ -1269,10 +1281,13 @@ void EditorHelp::_add_text(const String& p_bbcode) { if (dnl) { bbcode[i]=0xFFFF; + //keep i=j; } else { - bbcode[i]=' '; - i=j-1; + bbcode=bbcode.insert(i,"\n"); + i++; + //bbcode[i]=' '; + //i=j-1; } } } @@ -1280,7 +1295,7 @@ void EditorHelp::_add_text(const String& p_bbcode) { //remove double spaces or spaces after newlines for(int i=0;i<bbcode.length();i++) { - if (bbcode[i]==' ' || bbcode[i]==0xFFFF) { + if (bbcode[i]==' ' || bbcode[i]=='\n' || bbcode[i]==0xFFFF) { for(int j=i+1;j<p_bbcode.length();j++) { if (bbcode[j]==' ') { @@ -1353,35 +1368,45 @@ void EditorHelp::_add_text(const String& p_bbcode) { } else if (tag.begins_with("method ")) { String m = tag.substr(7,tag.length()); + class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); class_desc->push_meta("@"+m); class_desc->add_text(m+"()"); class_desc->pop(); + class_desc->pop(); pos=brk_end+1; } else if (doc->class_list.has(tag)) { + class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); class_desc->push_meta("#"+tag); class_desc->add_text(tag); class_desc->pop(); + class_desc->pop(); pos=brk_end+1; } else if (tag=="b") { //use bold font - class_desc->push_font(get_font("source","Fonts")); + class_desc->push_font(doc_code_font); pos=brk_end+1; tag_stack.push_front(tag); } else if (tag=="i") { //use italics font - class_desc->push_font(get_font("italic","Fonts")); + Color text_color = EditorSettings::get_singleton()->get("text_editor/text_color"); + //no italics so emphasize with color + text_color.r*=1.1; + text_color.g*=1.1; + text_color.b*=1.1; + class_desc->push_color(text_color); + //class_desc->push_font(get_font("italic","Fonts")); pos=brk_end+1; tag_stack.push_front(tag); } else if (tag=="code" || tag=="codeblock") { //use monospace font - class_desc->push_font(get_font("source","EditorFonts")); + class_desc->push_font(doc_code_font); pos=brk_end+1; tag_stack.push_front(tag); } else if (tag=="center") { @@ -1496,7 +1521,7 @@ void EditorHelp::_add_text(const String& p_bbcode) { if (font.is_valid()) class_desc->push_font(font); else { - class_desc->push_font(get_font("source","rFonts")); + class_desc->push_font(doc_font); } pos=brk_end+1; @@ -1618,6 +1643,7 @@ EditorHelp::EditorHelp() { VBoxContainer *vbc = this; + EDITOR_DEF("help/sort_functions_alphabetically",true); //class_list->connect("meta_clicked",this,"_class_list_select"); //class_list->set_selection_enabled(true); diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index fedf738af4..8313e38f02 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -5225,7 +5225,7 @@ EditorNode::EditorNode() { //theme->set_icon("folder","EditorFileDialog",Theme::get_default()->get_icon("folder","EditorFileDialog")); //theme->set_color("files_disabled","EditorFileDialog",Color(0,0,0,0.7)); - String global_font = EditorSettings::get_singleton()->get("global/font"); + String global_font = EditorSettings::get_singleton()->get("global/custom_font"); if (global_font!="") { Ref<Font> fnt = ResourceLoader::load(global_font); if (fnt.is_valid()) { diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 0b7e389773..96ced0d5e3 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -443,8 +443,12 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { } set("global/show_script_in_scene_tabs",false); - set("global/font",""); - hints["global/font"]=PropertyInfo(Variant::STRING,"global/font",PROPERTY_HINT_GLOBAL_FILE,"*.fnt"); + 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); + 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/autoscan_project_path",""); hints["global/autoscan_project_path"]=PropertyInfo(Variant::STRING,"global/autoscan_project_path",PROPERTY_HINT_GLOBAL_DIR); set("global/default_project_path",""); diff --git a/tools/editor/icons/SCsub b/tools/editor/icons/SCsub index addf6879a2..14d2be66f6 100644 --- a/tools/editor/icons/SCsub +++ b/tools/editor/icons/SCsub @@ -35,7 +35,9 @@ def make_editor_icons_action(target, source, env): s.write("static Ref<ImageTexture> make_icon(const uint8_t* p_png) {\n") s.write("\tRef<ImageTexture> texture( memnew( ImageTexture ) );\n") - s.write("\ttexture->create_from_image( Image(p_png),ImageTexture::FLAG_FILTER );\n") + s.write("\tImage img(p_png);\n") + #s.write("\timg.expand_x2_hq2x();\n") + s.write("\ttexture->create_from_image( img,ImageTexture::FLAG_FILTER );\n") s.write("\treturn texture;\n") s.write("}\n\n") |