Skip to content

Commit

Permalink
Expose font settings for crosshair coordinates
Browse files Browse the repository at this point in the history
Stop hard-coding the font face and size of the crosshair coordinates
(currently Verdana 12px). Expose the options to the user and move the
coordinates' current font settings to the default profile.
  • Loading branch information
0tkl committed Jan 4, 2025
1 parent a09565a commit e83491a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/gl_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/gl_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/libresrc/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@
"Skip Whitespace" : true
},
"Visual" : {
"Font Face": "Verdana",
"Font Size": 12,
"Autohide": false
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/libresrc/osx/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@
"Skip Whitespace" : true
},
"Visual" : {
"Font Face": "Verdana",
"Font Size": 12,
"Autohide": false
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 15 additions & 1 deletion src/visual_tool_cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "include/aegisub/context.h"
#include "selection_controller.h"
#include "video_display.h"
#include "utils.h"

#include <libaegisub/color.h>
#include <libaegisub/format.h>
Expand All @@ -33,12 +34,25 @@ VisualToolCross::VisualToolCross(VideoDisplay *parent, agi::Context *context)
, gl_text(std::make_unique<OpenGLText>())
{
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);

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/visual_tool_cross.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class VisualToolCross final : public VisualTool<VisualDraggableFeature> {

void OnDoubleClick() override;
void Draw() override;
void SetFont();
std::string Text(Vector2D v);
public:
VisualToolCross(VideoDisplay *parent, agi::Context *context);
Expand Down

0 comments on commit e83491a

Please sign in to comment.