From 7a07a1c0a24468c1702c789ae2ea32edc91a2a8c Mon Sep 17 00:00:00 2001 From: 0tkl <118708188+0tkl@users.noreply.github.com> Date: Sun, 5 Jan 2025 03:41:14 +0800 Subject: [PATCH] Expose font settings for crosshair coordinates Stop hard-coding the font face and size of the crosshair coordinates (currently Verdana 12pt). Expose the options to the user and move the coordinates' current font settings to the default profile. --- src/gl_text.cpp | 12 ++++++++++++ src/gl_text.h | 3 +++ src/libresrc/default_config.json | 2 ++ src/libresrc/osx/default_config.json | 2 ++ src/preferences.cpp | 4 ++++ src/visual_tool_cross.cpp | 16 +++++++++++++++- src/visual_tool_cross.h | 1 + 7 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/gl_text.cpp b/src/gl_text.cpp index 94f866961a..79d718981c 100644 --- a/src/gl_text.cpp +++ b/src/gl_text.cpp @@ -240,6 +240,18 @@ void OpenGLText::SetFont(std::string const& face, int size, bool bold, bool ital glyphs.clear(); } +void OpenGLText::SetFont(const wxFont& newFont) { + // No change required + if (font == newFont) return; + + // Set font + font = newFont; + + // Delete all old data + textures.clear(); + glyphs.clear(); +} + void OpenGLText::SetColour(agi::Color col) { r = col.r / 255.f; g = col.g / 255.f; diff --git a/src/gl_text.h b/src/gl_text.h index e25045f124..42e44a18ff 100644 --- a/src/gl_text.h +++ b/src/gl_text.h @@ -77,6 +77,9 @@ class OpenGLText { /// @param bold Should the font be bold? /// @param italics Should the font be italic? void SetFont(std::string const& face, int size, bool bold, bool italics); + /// @brief Set the currently active font + /// @param font The desired font + void SetFont(const wxFont& newFont); /// @brief Set the text color /// @param col Color void SetColour(agi::Color col); diff --git a/src/libresrc/default_config.json b/src/libresrc/default_config.json index 8eb910fee4..8481f0be50 100644 --- a/src/libresrc/default_config.json +++ b/src/libresrc/default_config.json @@ -576,6 +576,8 @@ "Skip Whitespace" : true }, "Visual" : { + "Font Face": "Verdana", + "Font Size": 12, "Autohide": false } }, diff --git a/src/libresrc/osx/default_config.json b/src/libresrc/osx/default_config.json index 9d912ea94d..92f28f0963 100644 --- a/src/libresrc/osx/default_config.json +++ b/src/libresrc/osx/default_config.json @@ -576,6 +576,8 @@ "Skip Whitespace" : true }, "Visual" : { + "Font Face": "Verdana", + "Font Size": 12, "Autohide": false } }, diff --git a/src/preferences.cpp b/src/preferences.cpp index 1b0033b057..bbb65fb23f 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -228,6 +228,10 @@ void Interface(wxTreebook *book, Preferences *parent) { auto tl_assistant = p->PageSizer(_("Translation Assistant")); p->OptionAdd(tl_assistant, _("Skip over whitespace"), "Tool/Translation Assistant/Skip Whitespace"); + auto visual_tools = p->PageSizer(_("Visual Tools")); + p->OptionAdd(visual_tools, _("Shape handle size"), "Tool/Visual/Shape Handle Size"); + p->OptionFont(visual_tools, "Tool/Visual/"); + p->SetSizerAndFit(p->sizer); } diff --git a/src/visual_tool_cross.cpp b/src/visual_tool_cross.cpp index 2036cbea61..f8d2963624 100644 --- a/src/visual_tool_cross.cpp +++ b/src/visual_tool_cross.cpp @@ -24,6 +24,7 @@ #include "include/aegisub/context.h" #include "selection_controller.h" #include "video_display.h" +#include "utils.h" #include #include @@ -33,12 +34,25 @@ VisualToolCross::VisualToolCross(VideoDisplay *parent, agi::Context *context) , gl_text(std::make_unique()) { parent->SetCursor(wxCursor(wxCURSOR_BLANK)); + OPT_SUB("Tool/Visual/Font Face", &VisualToolCross::SetFont, this); + OPT_SUB("Tool/Visual/Font Size", &VisualToolCross::SetFont, this); } VisualToolCross::~VisualToolCross() { parent->SetCursor(wxNullCursor); } +void VisualToolCross::SetFont() { + wxFont font = *wxNORMAL_FONT; + font.SetEncoding(wxFONTENCODING_DEFAULT); + font.MakeBold(); + wxString fontname = FontFace("Tool/Visual"); + if (!fontname.empty()) font.SetFaceName(fontname); + font.SetPointSize(OPT_GET("Tool/Visual/Font Size")->GetInt()); + + gl_text->SetFont(font); +} + void VisualToolCross::OnDoubleClick() { Vector2D d = ToScriptCoords(mouse_pos) - GetLinePosition(active_line); @@ -79,7 +93,7 @@ void VisualToolCross::Draw() { std::string mouse_text = Text(ToScriptCoords(shift_down ? video_res - mouse_pos : mouse_pos)); int tw, th; - gl_text->SetFont("Verdana", 12, true, false); + this->SetFont(); gl_text->SetColour(agi::Color(255, 255, 255, 255)); gl_text->GetExtent(mouse_text, tw, th); diff --git a/src/visual_tool_cross.h b/src/visual_tool_cross.h index 8172a40f8e..c9daf606a6 100644 --- a/src/visual_tool_cross.h +++ b/src/visual_tool_cross.h @@ -34,6 +34,7 @@ class VisualToolCross final : public VisualTool { void OnDoubleClick() override; void Draw() override; + void SetFont(); std::string Text(Vector2D v); public: VisualToolCross(VideoDisplay *parent, agi::Context *context);