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

Method getCursorDrawOffset

source/windowing/StarTextBoxWidget.cpp:89–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89int TextBoxWidget::getCursorDrawOffset() const { // horizontal only
90 float scale;
91 context()->setTextStyle(m_textStyle);
92 if (m_hAnchor == HorizontalAnchor::LeftAnchor) {
93 scale = 1.0;
94 } else if (m_hAnchor == HorizontalAnchor::HMidAnchor) {
95 scale = 0.5;
96 } else if (m_hAnchor == HorizontalAnchor::RightAnchor) {
97 scale = -1.0;
98 if (m_textHidden) {
99 int width = context()->stringWidth("*");
100 size_t chars = m_text.size();
101 return (width * chars) * scale + (width * (chars - m_cursorOffset));
102 } else {
103 return context()->stringWidth(m_text) * scale
104 + context()->stringWidth(m_text.substr(m_cursorOffset, m_text.size()));
105 }
106 } else {
107 throw GuiException("Somehow, the value of m_hAnchor became bad");
108 }
109
110 if (m_textHidden) {
111 int width = context()->stringWidth("*");
112 size_t chars = m_text.size();
113 return (int)std::ceil((width * chars) * scale - (width * (chars - m_cursorOffset)));
114 } else {
115 return (int)std::ceil(context()->stringWidth(m_text) * scale
116 - context()->stringWidth(m_text.substr(m_cursorOffset, m_text.size())));
117 }
118}
119
120void TextBoxWidget::update(float dt) {
121 Widget::update(dt);

Callers

nothing calls this directly

Calls 4

setTextStyleMethod · 0.80
stringWidthMethod · 0.45
sizeMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected