Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable font for visual tool cross #145

Open
wants to merge 1 commit into
base: feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -620,6 +620,8 @@
"Skip Whitespace" : true
},
"Visual" : {
"Font Face": "Verdana",
"Font Size": 12,
"Perspective": {
"Outer": false,
"Outer Locked": 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 @@ -620,6 +620,8 @@
"Skip Whitespace" : true
},
"Visual" : {
"Font Face": "Verdana",
"Font Size": 12,
"Perspective": {
"Outer": false,
"Outer Locked": false,
Expand Down
1 change: 1 addition & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ void Interface(wxTreebook *book, Preferences *parent) {

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/");

auto color_picker = p->PageSizer(_("Colour Picker"));
p->OptionAdd(color_picker, _("Restrict Screen Picker to Window"), "Tool/Colour Picker/Restrict to Window");
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 @@ -34,12 +35,25 @@ VisualToolCross::VisualToolCross(VideoDisplay *parent, agi::Context *context)
, gl_text(agi::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 @@ -80,7 +94,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
Loading