MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / onRender

Method onRender

forms/textedit.cpp:170–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170void TextEdit::onRender()
171{
172 Control::onRender();
173
174 auto u8str = to_ustring(text);
175
176 int xpos = align(TextHAlign, Size.x, font->getFontWidth(u8str));
177 int ypos = align(TextVAlign, Size.y, font->getFontHeight());
178
179 if (editing)
180 {
181 int cxpos = xpos + font->getFontWidth(to_ustring(text.substr(0, SelectionStart))) + 1;
182
183 if (cxpos < 0)
184 {
185 xpos += cxpos;
186 cxpos = xpos + font->getFontWidth(to_ustring(text.substr(0, SelectionStart))) + 1;
187 }
188 if (cxpos > Size.x)
189 {
190 xpos -= cxpos - Size.x;
191 cxpos = xpos + font->getFontWidth(to_ustring(text.substr(0, SelectionStart))) + 1;
192 }
193
194 if (caretDraw)
195 {
196 auto textImage = font->getString(cursor);
197 fw().renderer->draw(textImage, Vec2<float>{cxpos, ypos});
198 }
199 }
200
201 auto textImage = font->getString(u8str);
202 fw().renderer->draw(textImage, Vec2<float>{xpos, ypos});
203}
204
205void TextEdit::update()
206{

Callers

nothing calls this directly

Calls 5

to_ustringFunction · 0.85
getFontWidthMethod · 0.80
getFontHeightMethod · 0.45
getStringMethod · 0.45
drawMethod · 0.45

Tested by

no test coverage detected