Browse Source

Set up monospaced font in text editor, use it for art

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.02
falkTX 3 years ago
parent
commit
2e4fb8975e
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 61 additions and 18 deletions
  1. +4
    -1
      plugins/Cardinal/src/ImGuiTextEditor.cpp
  2. +31
    -9
      plugins/Cardinal/src/ImGuiWidget.cpp
  3. +1
    -0
      plugins/Cardinal/src/ImGuiWidget.hpp
  4. +25
    -8
      plugins/Cardinal/src/TextEditor.cpp

+ 4
- 1
plugins/Cardinal/src/ImGuiTextEditor.cpp View File

@@ -38,7 +38,10 @@ struct ImGuiTextEditor::PrivateData {

ImGuiTextEditor::ImGuiTextEditor()
: ImGuiWidget(),
pData(new PrivateData) {}
pData(new PrivateData())
{
setUseMonospaceFont();
}

ImGuiTextEditor::~ImGuiTextEditor()
{


+ 31
- 9
plugins/Cardinal/src/ImGuiWidget.cpp View File

@@ -28,6 +28,7 @@ struct ImGuiWidget::PrivateData {
ImGuiContext* context = nullptr;
bool created = false;
bool fontGenerated = false;
bool useMonospacedFont = false;
float originalScaleFactor = 0.0f;
float scaleFactor = 0.0f;

@@ -86,17 +87,31 @@ struct ImGuiWidget::PrivateData {

fontGenerated = true;

#ifndef DGL_NO_SHARED_RESOURCES
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
}
}

void resetStyle()
@@ -170,6 +185,13 @@ void ImGuiWidget::setAsCurrentContext()
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)
{
ImGui::SetCurrentContext(imData->context);


+ 1
- 0
plugins/Cardinal/src/ImGuiWidget.hpp View File

@@ -40,6 +40,7 @@ protected:
void onSelectKey(const SelectKeyEvent& e) override;
void onSelectText(const SelectTextEvent& e) override;
void setAsCurrentContext();
void setUseMonospaceFont(bool useMonoFont = true);

virtual void drawImGui()
{


+ 25
- 8
plugins/Cardinal/src/TextEditor.cpp View File

@@ -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

struct TextEditorModule : Module {


Loading…
Cancel
Save