16 void setMin(T& _var,
const T& _newValue)
23 void setMax(T& _var,
const T& _newValue)
34 void set(
size_t _position,
const UString::const_iterator& _space_point,
size_t _count,
float _width)
37 space_point = _space_point;
53 float getWidth()
const
59 size_t getCount()
const
65 size_t getPosition()
const
71 UString::const_iterator getTextIter()
const
79 UString::const_iterator space_point;
85 void TextView::update(
90 VertexColourType _format,
93 mFontHeight = _height;
96 static const char convert_colour[64] = {
97 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0};
102 RollBackPoint roll_back;
108 for (
auto& line : mLineInfo)
110 size_t current_line = 0;
111 int font_height = _font->getDefaultHeight();
113 UString::const_iterator end = _text.end();
114 UString::const_iterator index = _text.begin();
119 result.height += _height;
121 Char previousChar = 0;
123 for (; index != end; ++index)
125 if (current_line == mLineInfo.size())
126 mLineInfo.emplace_back();
127 auto& line_info = mLineInfo[current_line];
128 Char character = *index;
135 UString::const_iterator peeki = index;
141 line_info.width = (int)std::ceil(width);
142 line_info.count = count;
143 mLength += line_info.count + 1;
145 result.height += _height;
146 setMax(result.width, line_info.width);
158 if (character == U
'#')
170 if (character != U
'#')
173 uint32 colour = convert_colour[(character - 48) & 0x3F];
176 for (
char i = 0; i < 5; i++)
185 colour += convert_colour[((*index) - 48) & 0x3F];
191 line_info.symbols.emplace_back(colour);
197 const GlyphInfo* info = _font->getGlyphInfo(character);
207 roll_back.set(line_info.symbols.size(), index, count, width);
210 float char_width = info->
width;
211 float char_height = info->height;
212 float char_advance = info->advance;
213 float char_bearingX = info->bearingX;
214 float char_bearingY = info->bearingY;
215 float kerning = (previousChar != 0) ? _font->getKerning(previousChar, character) : 0.0f;
217 if (_height != font_height)
219 float scale = (float)_height / font_height;
222 char_height *= scale;
223 char_advance *= scale;
224 char_bearingX *= scale;
225 char_bearingY *= scale;
229 float char_fullAdvance = char_advance + kerning;
232 if (_maxWidth != -1 && (width + char_fullAdvance) > _maxWidth)
234 if (!roll_back.empty())
237 width = roll_back.getWidth();
238 count = roll_back.getCount();
239 index = roll_back.getTextIter();
240 line_info.symbols.erase(
241 line_info.symbols.begin() + roll_back.getPosition(),
242 line_info.symbols.end());
246 line_info.width = (int)std::ceil(width);
247 line_info.count = count;
248 mLength += line_info.count + 1;
250 result.height += _height;
251 setMax(result.width, line_info.width);
259 if (!roll_back.empty())
265 line_info.symbols.emplace_back(
273 width += char_fullAdvance;
274 previousChar = character;
278 mLineInfo.resize(current_line + 1);
279 auto& line_info = mLineInfo[current_line];
280 line_info.width = (int)std::ceil(width);
281 line_info.count = count;
282 mLength += line_info.count;
284 setMax(result.width, line_info.width);
287 for (
auto& line : mLineInfo)
289 if (_align.isRight())
290 line.offset = result.width - line.width;
291 else if (_align.isHCenter())
292 line.offset = (result.width - line.width) / 2;
298 size_t TextView::getCursorPosition(
const IntPoint& _value)
const
303 for (VectorLineInfo::const_iterator line = mLineInfo.begin(); line != mLineInfo.end(); ++line)
305 bool lastline = line + 1 == mLineInfo.end();
307 if (top + mFontHeight <= _value.top && !lastline)
310 result += line->count + 1;
314 float left = (float)line->offset;
317 for (
const auto& sym : line->symbols)
322 float fullAdvance = sym.getAdvance() + sym.getKerning();
323 if (left + fullAdvance / 2.0f > _value.left)
339 IntPoint TextView::getCursorPoint(
size_t _position)
const
341 setMin(_position, mLength);
346 for (
const auto& line : mLineInfo)
348 left = (float)line.offset;
349 if (position + line.count >= _position)
351 for (
const auto& sym : line.symbols)
356 if (position == _position)
360 left += sym.getAdvance() + sym.getKerning();
364 position += line.count + 1;
368 return {(int)left, top};
371 const IntSize& TextView::getViewSize()
const
376 size_t TextView::getTextLength()
const
#define MYGUI_DEBUG_ASSERT(exp, dest)
void convertColour(uint32 &_colour, VertexColourType _format)
std::vector< LineInfo > VectorLineInfo
types::TPoint< int > IntPoint
types::TSize< int > IntSize