galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
FontContext.cpp
Go to the documentation of this file.
1
7
8#include "galaxy/core/ServiceLocator.hpp"
10#include "galaxy/error/Log.hpp"
11
12#include "FontContext.hpp"
13
14namespace galaxy
15{
16 namespace graphics
17 {
19 : m_context {nullptr}
20 {
21 m_context = msdfgl_create_context(nullptr);
22 if (!m_context)
23 {
24 GALAXY_LOG(GALAXY_FATAL, "Failed to create font context.");
25 }
26 else
27 {
28 msdfgl_set_missing_glyph_callback(m_context, msdfgl_generate_glyph, nullptr);
29
30 auto& w = core::ServiceLocator<core::Window>::ref();
31
32 const auto scale = w.get_content_scale();
33 set_dpi(scale.x, scale.y);
34 }
35 }
36
38 {
39 if (m_context != nullptr)
40 {
41 msdfgl_destroy_context(m_context);
42 }
43 }
44
45 void FontContext::set_dpi(const float x, const float y) const
46 {
47 msdfgl_set_dpi(m_context, x, y);
48 }
49
50 msdfgl_context_t FontContext::context()
51 {
52 return m_context;
53 }
54 } // namespace graphics
55} // namespace galaxy
#define GALAXY_LOG(level, msg,...)
Definition Log.hpp:28
#define GALAXY_FATAL
Definition Log.hpp:25
msdfgl_context_t m_context
Library context object.
msdfgl_context_t context()
Get font context object.
void set_dpi(const float x, const float y) const
Set font DPI.
Animated.cpp galaxy.
Definition Animated.cpp:16