Signed-off-by: falkTX <falktx@falktx.com>tags/22.02
| @@ -38,7 +38,10 @@ struct ImGuiTextEditor::PrivateData { | |||||
| ImGuiTextEditor::ImGuiTextEditor() | ImGuiTextEditor::ImGuiTextEditor() | ||||
| : ImGuiWidget(), | : ImGuiWidget(), | ||||
| pData(new PrivateData) {} | |||||
| pData(new PrivateData()) | |||||
| { | |||||
| setUseMonospaceFont(); | |||||
| } | |||||
| ImGuiTextEditor::~ImGuiTextEditor() | ImGuiTextEditor::~ImGuiTextEditor() | ||||
| { | { | ||||
| @@ -28,6 +28,7 @@ struct ImGuiWidget::PrivateData { | |||||
| ImGuiContext* context = nullptr; | ImGuiContext* context = nullptr; | ||||
| bool created = false; | bool created = false; | ||||
| bool fontGenerated = false; | bool fontGenerated = false; | ||||
| bool useMonospacedFont = false; | |||||
| float originalScaleFactor = 0.0f; | float originalScaleFactor = 0.0f; | ||||
| float scaleFactor = 0.0f; | float scaleFactor = 0.0f; | ||||
| @@ -86,17 +87,31 @@ struct ImGuiWidget::PrivateData { | |||||
| fontGenerated = true; | fontGenerated = true; | ||||
| #ifndef DGL_NO_SHARED_RESOURCES | |||||
| ImGuiIO& io(ImGui::GetIO()); | ImGuiIO& io(ImGui::GetIO()); | ||||
| using namespace dpf_resources; | |||||
| ImFontConfig fc; | |||||
| fc.FontDataOwnedByAtlas = false; | |||||
| fc.OversampleH = 1; | |||||
| fc.OversampleV = 1; | |||||
| fc.PixelSnapH = true; | |||||
| io.Fonts->AddFontFromMemoryTTF((void*)dejavusans_ttf, dejavusans_ttf_size, 13.0f * scaleFactor, &fc); | |||||
| io.Fonts->Build(); | |||||
| if (useMonospacedFont) | |||||
| { | |||||
| const std::string fontPath = asset::system("fonts/ShareTechMono-Regular.ttf"); | |||||
| ImFontConfig fc; | |||||
| fc.OversampleH = 1; | |||||
| fc.OversampleV = 1; | |||||
| fc.PixelSnapH = true; | |||||
| io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 13.0f * scaleFactor, &fc); | |||||
| io.Fonts->Build(); | |||||
| } | |||||
| else | |||||
| { | |||||
| #ifndef DGL_NO_SHARED_RESOURCES | |||||
| using namespace dpf_resources; | |||||
| ImFontConfig fc; | |||||
| fc.FontDataOwnedByAtlas = false; | |||||
| fc.OversampleH = 1; | |||||
| fc.OversampleV = 1; | |||||
| fc.PixelSnapH = true; | |||||
| io.Fonts->AddFontFromMemoryTTF((void*)dejavusans_ttf, dejavusans_ttf_size, 13.0f * scaleFactor, &fc); | |||||
| io.Fonts->Build(); | |||||
| #endif | #endif | ||||
| } | |||||
| } | } | ||||
| void resetStyle() | void resetStyle() | ||||
| @@ -170,6 +185,13 @@ void ImGuiWidget::setAsCurrentContext() | |||||
| ImGui::SetCurrentContext(imData->context); | ImGui::SetCurrentContext(imData->context); | ||||
| } | } | ||||
| void ImGuiWidget::setUseMonospaceFont(const bool useMonoFont) | |||||
| { | |||||
| DISTRHO_SAFE_ASSERT_RETURN(!imData->fontGenerated,); | |||||
| imData->useMonospacedFont = useMonoFont; | |||||
| } | |||||
| void ImGuiWidget::onHover(const HoverEvent& e) | void ImGuiWidget::onHover(const HoverEvent& e) | ||||
| { | { | ||||
| ImGui::SetCurrentContext(imData->context); | ImGui::SetCurrentContext(imData->context); | ||||
| @@ -40,6 +40,7 @@ protected: | |||||
| void onSelectKey(const SelectKeyEvent& e) override; | void onSelectKey(const SelectKeyEvent& e) override; | ||||
| void onSelectText(const SelectTextEvent& e) override; | void onSelectText(const SelectTextEvent& e) override; | ||||
| void setAsCurrentContext(); | void setAsCurrentContext(); | ||||
| void setUseMonospaceFont(bool useMonoFont = true); | |||||
| virtual void drawImGui() | virtual void drawImGui() | ||||
| { | { | ||||
| @@ -26,14 +26,31 @@ | |||||
| // -------------------------------------------------------------------------------------------------------------------- | // -------------------------------------------------------------------------------------------------------------------- | ||||
| // defaults | |||||
| #define DEFAULT_LANG "C++" | |||||
| #define DEFAULT_TEXT "" \ | |||||
| "// Welcome to a real text editor inside Cardinal\n\n" \ | |||||
| "#define I_AM_A_MACRO\n\n" \ | |||||
| "int and_i_am_a_variable;\n\n" \ | |||||
| "/* look ma, a comment! */\n" \ | |||||
| "int such_highlight_much_wow() { return 1337; }\n" | |||||
| // defaults (artwork based on content from https://www.asciiart.eu/animals/cats) | |||||
| #define DEFAULT_LANG "None" | |||||
| #define DEFAULT_TEXT "" \ | |||||
| " \n" \ | |||||
| " ^ ^ ,_, \n" \ | |||||
| " (O,O) (.,.) \n" \ | |||||
| " ( ) ( ) \n" \ | |||||
| "--------\"-\"---dwb--\"-\"---dwb- \n" \ | |||||
| " \n" \ | |||||
| " \n" \ | |||||
| " \n" \ | |||||
| " \n" \ | |||||
| " \n" \ | |||||
| " \n" \ | |||||
| " \n" \ | |||||
| " /^--^\\ /^--^\\ /^--^\\ \n" \ | |||||
| " \\____/ \\____/ \\____/ \n" \ | |||||
| " / \\ / \\ / \\ \n" \ | |||||
| " | | | | | | \n" \ | |||||
| " \\__ __/ \\__ __/ \\__ __/ \n" \ | |||||
| "|^|^|^|^\\ \\^|^|^|^/ /^|^|^|^|^\\ \\^|^|^|^|^|^|^|^|^|\n" \ | |||||
| "| | | | |\\ \\| | |/ /| | | | | |\\ \\| | | | | | | | |\n" \ | |||||
| "#########/ /#####\\ \\###########/ /#################\n" \ | |||||
| "| | | | |\\/ | | | \\/| | | | | |\\/ | | | | | | | | |\n" \ | |||||
| "|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n" | |||||
| #define DEFAULT_WIDTH 30 | #define DEFAULT_WIDTH 30 | ||||
| struct TextEditorModule : Module { | struct TextEditorModule : Module { | ||||