Skip to content

Commit 7a07a1c

Browse files
committed
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.
1 parent a09565a commit 7a07a1c

File tree

7 files changed

+39
-1
lines changed

7 files changed

+39
-1
lines changed

src/gl_text.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ void OpenGLText::SetFont(std::string const& face, int size, bool bold, bool ital
240240
glyphs.clear();
241241
}
242242

243+
void OpenGLText::SetFont(const wxFont& newFont) {
244+
// No change required
245+
if (font == newFont) return;
246+
247+
// Set font
248+
font = newFont;
249+
250+
// Delete all old data
251+
textures.clear();
252+
glyphs.clear();
253+
}
254+
243255
void OpenGLText::SetColour(agi::Color col) {
244256
r = col.r / 255.f;
245257
g = col.g / 255.f;

src/gl_text.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class OpenGLText {
7777
/// @param bold Should the font be bold?
7878
/// @param italics Should the font be italic?
7979
void SetFont(std::string const& face, int size, bool bold, bool italics);
80+
/// @brief Set the currently active font
81+
/// @param font The desired font
82+
void SetFont(const wxFont& newFont);
8083
/// @brief Set the text color
8184
/// @param col Color
8285
void SetColour(agi::Color col);

src/libresrc/default_config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@
576576
"Skip Whitespace" : true
577577
},
578578
"Visual" : {
579+
"Font Face": "Verdana",
580+
"Font Size": 12,
579581
"Autohide": false
580582
}
581583
},

src/libresrc/osx/default_config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@
576576
"Skip Whitespace" : true
577577
},
578578
"Visual" : {
579+
"Font Face": "Verdana",
580+
"Font Size": 12,
579581
"Autohide": false
580582
}
581583
},

src/preferences.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ void Interface(wxTreebook *book, Preferences *parent) {
228228
auto tl_assistant = p->PageSizer(_("Translation Assistant"));
229229
p->OptionAdd(tl_assistant, _("Skip over whitespace"), "Tool/Translation Assistant/Skip Whitespace");
230230

231+
auto visual_tools = p->PageSizer(_("Visual Tools"));
232+
p->OptionAdd(visual_tools, _("Shape handle size"), "Tool/Visual/Shape Handle Size");
233+
p->OptionFont(visual_tools, "Tool/Visual/");
234+
231235
p->SetSizerAndFit(p->sizer);
232236
}
233237

src/visual_tool_cross.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "include/aegisub/context.h"
2525
#include "selection_controller.h"
2626
#include "video_display.h"
27+
#include "utils.h"
2728

2829
#include <libaegisub/color.h>
2930
#include <libaegisub/format.h>
@@ -33,12 +34,25 @@ VisualToolCross::VisualToolCross(VideoDisplay *parent, agi::Context *context)
3334
, gl_text(std::make_unique<OpenGLText>())
3435
{
3536
parent->SetCursor(wxCursor(wxCURSOR_BLANK));
37+
OPT_SUB("Tool/Visual/Font Face", &VisualToolCross::SetFont, this);
38+
OPT_SUB("Tool/Visual/Font Size", &VisualToolCross::SetFont, this);
3639
}
3740

3841
VisualToolCross::~VisualToolCross() {
3942
parent->SetCursor(wxNullCursor);
4043
}
4144

45+
void VisualToolCross::SetFont() {
46+
wxFont font = *wxNORMAL_FONT;
47+
font.SetEncoding(wxFONTENCODING_DEFAULT);
48+
font.MakeBold();
49+
wxString fontname = FontFace("Tool/Visual");
50+
if (!fontname.empty()) font.SetFaceName(fontname);
51+
font.SetPointSize(OPT_GET("Tool/Visual/Font Size")->GetInt());
52+
53+
gl_text->SetFont(font);
54+
}
55+
4256
void VisualToolCross::OnDoubleClick() {
4357
Vector2D d = ToScriptCoords(mouse_pos) - GetLinePosition(active_line);
4458

@@ -79,7 +93,7 @@ void VisualToolCross::Draw() {
7993
std::string mouse_text = Text(ToScriptCoords(shift_down ? video_res - mouse_pos : mouse_pos));
8094

8195
int tw, th;
82-
gl_text->SetFont("Verdana", 12, true, false);
96+
this->SetFont();
8397
gl_text->SetColour(agi::Color(255, 255, 255, 255));
8498
gl_text->GetExtent(mouse_text, tw, th);
8599

src/visual_tool_cross.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class VisualToolCross final : public VisualTool<VisualDraggableFeature> {
3434

3535
void OnDoubleClick() override;
3636
void Draw() override;
37+
void SetFont();
3738
std::string Text(Vector2D v);
3839
public:
3940
VisualToolCross(VideoDisplay *parent, agi::Context *context);

0 commit comments

Comments
 (0)