1 #include "LabelBox.hpp"
2 #include "Mathf.hpp"
3 #include "Fonts/chivo_bold.hpp"
4 
5 //#include "Fonts/chivo_bold.hpp"
6 
7 START_NAMESPACE_DISTRHO
8 
LabelBox(Widget * widget,Size<uint> size)9 LabelBox::LabelBox(Widget  *widget, Size<uint> size) noexcept : WolfWidget(widget)
10 {
11     setSize(size);
12 
13     using namespace WOLF_FONTS;
14     createFontFromMemory("chivo_bold", (const uchar *)chivo_bold, chivo_bold_size, 0);
15 }
16 
onNanoDisplay()17 void LabelBox::onNanoDisplay()
18 {
19     const float width = getWidth();
20     const float height = getHeight();
21     const float verticalMargin = 6.0f;
22     const float boxOutlineWidth = 2.0f;
23 
24     //Box background
25     beginPath();
26 
27     fillColor(Color(34, 34, 34, 255));
28     strokeColor(Color(64, 64, 64, 255));
29     strokeWidth(boxOutlineWidth);
30 
31     rect(0, 0, width, height);
32     fill();
33     stroke();
34 
35     closePath();
36 
37     //Shadow at top of box
38     beginPath();
39 
40     strokeColor(0,0,0,255);
41     strokeWidth(boxOutlineWidth);
42 
43     moveTo(boxOutlineWidth, boxOutlineWidth);
44     lineTo(width - boxOutlineWidth, boxOutlineWidth);
45     stroke();
46 
47     closePath();
48 
49     //Text
50     fontFace("chivo_bold");
51     fontSize(16.0f);
52     fillColor(Color(255, 255, 255, 255));
53     textAlign(ALIGN_CENTER | ALIGN_MIDDLE);
54 
55     text(std::round(width / 2.0f), std::round(height / 2.0f + verticalMargin / 2.0f - 2), fText, NULL);
56 
57     closePath();
58 }
59 
setFontSize(float fontSize)60 void LabelBox::setFontSize(float fontSize)
61 {
62     fFontSize = fontSize;
63 }
64 
getFontSize()65 float LabelBox::getFontSize()
66 {
67     return fFontSize;
68 }
69 
setText(const char * text)70 void LabelBox::setText(const char *text)
71 {
72     fText = text;
73 }
74 
getText()75 const char *LabelBox::getText()
76 {
77     return fText;
78 }
79 
setFontId(NanoVG::FontId fontId)80 void LabelBox::setFontId(NanoVG::FontId fontId)
81 {
82     fFontId = fontId;
83 }
84 
getFontId()85 NanoVG::FontId LabelBox::getFontId()
86 {
87     return fFontId;
88 }
89 
90 END_NAMESPACE_DISTRHO