q8fuel
(q8fuel)
April 1, 2020, 3:06pm
1
Hi,
I’m making a custom widget such a knob, which some fancy text.
I’d like to setup a custom font:
mFont = APP->window->loadFont(path + "res/fonts/MyFont.ttf");
But I’m not sure how to take the path
variable.
Within a module, I simply do path = asset::plugin(pluginInstance, "")
, but within the widget, I don’t have the instance of the plugin.
I don’t want to pass it to it (separation of context).
Is there any “static” call that I can use from within the Widget to retrieve the module path?
Thanks
23volts
(Rémi Collin)
April 1, 2020, 3:22pm
2
How I personnaly do it is to pass the font as a constructor argument :
TextLabel(const std::shared_ptr<Font> font) {
...
}
Vortico
(VCV - Andrew)
April 1, 2020, 3:26pm
3
This is the correct way.
mFont = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/MyFont.ttf"));
Why not? You need to define it as a global and set it. See any plugin for an example.
q8fuel
(q8fuel)
April 1, 2020, 3:39pm
4
I’m within a Knob.hpp file. I have the path
within plugin.cpp, as the Plugin *pluginInstance;
variabile.
Can’t access from Knob.hpp
Vortico
(VCV - Andrew)
April 1, 2020, 3:43pm
5
Typically you declare that global in plugin.hpp
which should be included by all module source code files. E.g. https://github.com/VCVRack/ESeries/blob/v1/src/plugin.hpp#L7
1 Like
q8fuel
(q8fuel)
April 1, 2020, 3:57pm
6
Ah extern, I see what you mean! Got it, thanks!