MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / draw

Method draw

modules/gui/gui/src/backend/text_server/text_line.cpp:359–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357}
358
359void TextLine::draw(RID p_canvas, const Vector2& p_pos, const Color& p_color) const
360{
361 const_cast<TextLine*>(this)->_shape();
362
363 Vector2 ofs = p_pos;
364
365 float length = TS->shaped_text_get_width(rid);
366 if (width > 0)
367 {
368 switch (alignment)
369 {
370 case HORIZONTAL_ALIGNMENT_FILL:
371 case HORIZONTAL_ALIGNMENT_LEFT:
372 break;
373 case HORIZONTAL_ALIGNMENT_CENTER: {
374 if (length <= width)
375 {
376 if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL)
377 {
378 ofs.x += ::floor((width - length) / 2.0);
379 }
380 else
381 {
382 ofs.y += ::floor((width - length) / 2.0);
383 }
384 }
385 else if (TS->shaped_text_get_inferred_direction(rid) == TextServer::DIRECTION_RTL)
386 {
387 if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL)
388 {
389 ofs.x += width - length;
390 }
391 else
392 {
393 ofs.y += width - length;
394 }
395 }
396 }
397 break;
398 case HORIZONTAL_ALIGNMENT_RIGHT: {
399 if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL)
400 {
401 ofs.x += width - length;
402 }
403 else
404 {
405 ofs.y += width - length;
406 }
407 }
408 break;
409 }
410 }
411
412 float clip_l;
413 if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL)
414 {
415 ofs.y += TS->shaped_text_get_ascent(rid);
416 clip_l = MAX(0, p_pos.x - ofs.x);

Callers 2

draw_stringMethod · 0.45
draw_multiline_stringMethod · 0.45

Calls 3

_shapeMethod · 0.80
shaped_text_drawMethod · 0.80
floorFunction · 0.50

Tested by

no test coverage detected