MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / renderImpl

Method renderImpl

source/windowing/StarTextBoxWidget.cpp:35–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35void TextBoxWidget::renderImpl() {
36 float blueRate = 0;
37 if (m_isHover && !m_isPressed)
38 blueRate = 0.2f;
39 else
40 blueRate = 0.0f;
41
42 float cursorOffset = (float)getCursorDrawOffset() / context()->interfaceScale();
43 Vec2F pos(screenPosition());
44 if (m_hAnchor == HorizontalAnchor::HMidAnchor)
45 pos[0] += size()[0] / 2.0f;
46 else if (m_hAnchor == HorizontalAnchor::RightAnchor)
47 pos[0] += size()[0];
48
49 context()->setTextStyle(m_textStyle);
50 if ((m_maxWidth != -1) && m_overfillMode) {
51 float shift = std::max(0.f, cursorOffset - m_maxWidth);
52 pos[0] -= shift;
53 }
54
55 if (m_text.empty()) {
56 context()->setFontColor(Color::rgba(m_textStyle.color).mix(Color::rgbf(0.3f, 0.3f, 0.3f), 0.8f).mix(Color::rgbf(0.0f, 0.0f, 1.0f), blueRate).toRgba());
57 context()->renderInterfaceText(m_hint, {pos, m_hAnchor, m_vAnchor});
58 } else {
59 context()->setFontColor(Color::rgba(m_textStyle.color).mix(Color::rgbf(0, 0, 1), blueRate).toRgba());
60 if (m_textHidden) {
61 String hiddenText('*', m_text.length());
62 context()->renderInterfaceText(hiddenText, { pos, m_hAnchor, m_vAnchor });
63 }
64 else
65 context()->renderInterfaceText(m_text, { pos, m_hAnchor, m_vAnchor });
66 }
67 context()->clearTextStyle();
68
69 if (hasFocus()) {
70 // render cursor
71 float cc = 0.6f + 0.4f * std::sin((double)Time::monotonicMilliseconds() / 300.0);
72 Color cursorColor = Color::rgbf(cc, cc, cc);
73
74 float fontSize = m_textStyle.fontSize;
75 context()->drawInterfaceLine(
76 pos + Vec2F(cursorOffset, fontSize * m_cursorVert[0]),
77 pos + Vec2F(cursorOffset, fontSize * m_cursorVert[1]),
78 cursorColor.toRgba());
79 context()->drawInterfaceLine(
80 pos + Vec2F(cursorOffset + fontSize * m_cursorHoriz[0], fontSize * m_cursorVert[0]),
81 pos + Vec2F(cursorOffset + fontSize * m_cursorHoriz[1], fontSize * m_cursorVert[0]),
82 cursorColor.toRgba());
83 }
84
85 if (m_drawBorder)
86 context()->drawInterfacePolyLines(PolyF(screenBoundRect()), Color(Color::White).toRgba());
87}
88
89int TextBoxWidget::getCursorDrawOffset() const { // horizontal only
90 float scale;

Callers

nothing calls this directly

Calls 13

sizeFunction · 0.85
ColorClass · 0.85
setTextStyleMethod · 0.80
toRgbaMethod · 0.80
renderInterfaceTextMethod · 0.80
drawInterfaceLineMethod · 0.80
interfaceScaleMethod · 0.45
emptyMethod · 0.45
setFontColorMethod · 0.45
mixMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected