Visual Computing Library
Loading...
Searching...
No Matches
text_drawer.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BGFX_DRAWERS_TEXT_DRAWER_H
24#define VCL_BGFX_DRAWERS_TEXT_DRAWER_H
25
26#include <vclib/bgfx/text/text_view.h>
27#include <vclib/render/drawers/plain_drawer.h>
28
29namespace vcl {
30
31template<typename DerivedRenderApp>
32class TextDrawer : public PlainDrawer<DerivedRenderApp>
33{
34 TextView mTextView;
35
36public:
37 TextDrawer() : TextDrawer(1, 1) {}
38
39 TextDrawer(uint width, uint height)
40 {
41 // TODO: this should be done in the member function onInit()
42 // however, when using glfw the onInit is called just before the
43 // show method is called, making impossible to add text before
44 // the window is shown
45 mTextView.init(width, height);
46 }
47
48 void onResize(uint width, uint height) override final
49 {
50 mTextView.resize(width, height);
51 }
52
53 void onDraw(uint viewId) override final
54 {
55 auto fbh = DerivedRenderApp::DRW::canvasFrameBuffer(derived());
56 mTextView.frame(fbh);
57 }
58
59 // text
60 void enableText(bool b = true) { mTextView.enableText(b); }
61
62 bool isTextEnabled() const { return mTextView.isTextEnabled(); }
63
64 void setTextFont(VclFont::Enum font, uint fontSize)
65 {
66 mTextView.setTextFont(font, fontSize);
67 }
68
69 void setTextFont(const std::string& fontName, uint fontSize)
70 {
71 mTextView.setTextFont(fontName, fontSize);
72 }
73
74 void clearText() { mTextView.clearText(); }
75
76 void appendStaticText(
77 const Point2f& pos,
78 const std::string& text,
79 const Color& color = Color::Black)
80 {
81 mTextView.appendStaticText(pos, text, color);
82 }
83
84 void appendTransientText(
85 const Point2f& pos,
86 const std::string& text,
87 const Color& color = Color::Black)
88 {
89 mTextView.appendTransientText(pos, text, color);
90 }
91
92private:
93 auto* derived() { return static_cast<DerivedRenderApp*>(this); }
94
95 const auto* derived() const
96 {
97 return static_cast<const DerivedRenderApp*>(this);
98 }
99};
100
101} // namespace vcl
102
103#endif // VCL_BGFX_DRAWERS_TEXT_DRAWER_H
The Color class represents a 32 bit color.
Definition color.h:48
Definition plain_drawer.h:32
The Point class represents an N-dimensional point containing N scalar values.
Definition point.h:58
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Definition text_drawer.h:33
Definition text_view.h:32