20 #ifndef ofxOuiCommon_h 21 #define ofxOuiCommon_h 86 getInstance().retina_enabled_ = enabled;
87 getInstance().reloadFonts();
94 static bool getRetina() {
return getInstance().retina_enabled_; }
101 getInstance().font_path_ = path;
115 getInstance().font_size_ = font_size;
116 getInstance().reloadFonts();
130 getInstance().line_height_ = line_height;
131 getInstance().reloadFonts();
149 static ofTrueTypeFont*
requestFont(
void* client,
string font_path,
150 float font_size,
float line_height,
151 float letter_spacing) {
152 pair<string, vector<float>> fontSettings(
153 font_path, {font_size, line_height, letter_spacing});
154 for (
auto& f : getInstance().catalog_) {
155 if (f.second.second.count(client) > 0) {
156 if (f.first == fontSettings)
return f.second.first;
157 f.second.second.erase(client);
158 if (f.second.second.empty()) {
159 delete f.second.first;
160 getInstance().catalog_.erase(f.first);
165 auto it = getInstance().catalog_.find(fontSettings);
166 if (it == getInstance().catalog_.end()) {
167 ofTrueTypeFont* font =
new ofTrueTypeFont();
168 font->load(font_path, getRetina() ? font_size * 2. : font_size);
169 font->setLineHeight(getRetina() ? line_height * 2. : line_height);
170 font->setLetterSpacing(letter_spacing);
171 getInstance().catalog_[fontSettings].first = font;
172 getInstance().catalog_.at(fontSettings).second.insert(client);
175 getInstance().catalog_.at(fontSettings).second.insert(client);
176 return it->second.first;
185 for (
auto& f : getInstance().catalog_) {
186 if (f.second.second.count(client) > 0) {
187 f.second.second.erase(client);
188 if (f.second.second.empty()) {
189 delete f.second.first;
190 getInstance().catalog_.erase(f.first);
210 for (
auto& f : catalog_) {
211 f.second.first->load(f.first.first, getRetina()
212 ? f.first.second[0] * 2.
213 : f.first.second[0]);
215 ? f.first.second[1] * 2.
216 : f.first.second[1]);
217 f.second.first->setLetterSpacing(f.first.second[2]);
221 bool retina_enabled_ =
false;
222 string font_path_ =
"Lato-Regular.ttf";
223 float font_size_ = 10.;
224 float line_height_ = 12.;
226 map<pair<string, vector<float>>, pair<ofTrueTypeFont*, set<void*>>>
static void setDefaultLineHeight(float line_height)
Set the default line height.
Definition: ofxOuiCommon.hpp:129
static ofTrueTypeFont * requestFont(void *client, string font_path, float font_size, float line_height, float letter_spacing)
Request a font with a particular setting.
Definition: ofxOuiCommon.hpp:149
void reloadFonts()
Definition: ofxOuiCommon.hpp:209
Shape
Base shape of the UI components.
Definition: ofxOuiCommon.hpp:73
static void setRetina(bool enabled)
Set retina display on/off.
Definition: ofxOuiCommon.hpp:85
Global configuration.
Definition: ofxOuiCommon.hpp:79
static void setDefaultFontPath(string path)
Set the default font path.
Definition: ofxOuiCommon.hpp:100
Type
Type of UI Component.
Definition: ofxOuiCommon.hpp:38
Globals()
Definition: ofxOuiCommon.hpp:198
static Globals & getInstance()
Definition: ofxOuiCommon.hpp:204
static void releaseFont(void *client)
Release a font from a particular client.
Definition: ofxOuiCommon.hpp:184
map< pair< string, vector< float > >, pair< ofTrueTypeFont *, set< void * > > > catalog_
Definition: ofxOuiCommon.hpp:227
static string getDefaultFontPath()
Get the default font path.
Definition: ofxOuiCommon.hpp:108
Definition: ofxOuiColormap.hpp:25
static bool getRetina()
Get the retina setting.
Definition: ofxOuiCommon.hpp:94
static void setDefaultFontSize(float font_size)
Set the default font size.
Definition: ofxOuiCommon.hpp:114
static float getDefaultLineHeight()
Get the default line height.
Definition: ofxOuiCommon.hpp:138
Anchor
Generic Anchor specifier for Text/Image alignment.
Definition: ofxOuiCommon.hpp:57
static float getDefaultFontSize()
Get the default font size.
Definition: ofxOuiCommon.hpp:123