|
20 | 20 | */ |
21 | 21 |
|
22 | 22 | #include <lsp-plug.in/tk/tk.h> |
| 23 | +#include <lsp-plug.in/common/debug.h> |
23 | 24 | #include <lsp-plug.in/stdlib/math.h> |
| 25 | +#include <lsp-plug.in/tk/helpers/draw.h> |
24 | 26 | #include <private/tk/style/BuiltinStyle.h> |
25 | 27 |
|
26 | 28 | namespace lsp |
@@ -667,40 +669,14 @@ namespace lsp |
667 | 669 | sFont.get_parameters(s, fscaling, &fp); |
668 | 670 | sFont.get_multitext_parameters(s, &tp, fscaling, &text); |
669 | 671 |
|
670 | | - // Prepare to draw |
671 | | - float halign = lsp_limit(sTextLayout.halign() + 1.0f, 0.0f, 2.0f); |
672 | | - float valign = lsp_limit(sTextLayout.valign() + 1.0f, 0.0f, 2.0f); |
673 | | - float dy = (r.nHeight - tp.Height) * 0.5f; |
674 | | - ssize_t y = r.nTop + dy * valign - fp.Descent; |
| 672 | + // Draw multi-line text |
| 673 | + const float halign = lsp_limit(sTextLayout.halign(), -1.0f, 1.0f); |
| 674 | + const float valign = lsp_limit(sTextLayout.valign(), -1.0f, 1.0f); |
675 | 675 |
|
676 | | - // Estimate text size |
677 | | - ssize_t last = 0, curr = 0, tail = 0, len = text.length(); |
678 | | - |
679 | | - while (curr < len) |
680 | | - { |
681 | | - // Get next line indexes |
682 | | - curr = text.index_of(last, '\n'); |
683 | | - if (curr < 0) |
684 | | - { |
685 | | - curr = len; |
686 | | - tail = len; |
687 | | - } |
688 | | - else |
689 | | - { |
690 | | - tail = curr; |
691 | | - if ((tail > last) && (text.at(tail-1) == '\r')) |
692 | | - --tail; |
693 | | - } |
694 | | - |
695 | | - // Calculate text location |
696 | | - sFont.get_text_parameters(s, &tp, fscaling, &text, last, tail); |
697 | | - float dx = (r.nWidth - tp.Width) * 0.5f; |
698 | | - ssize_t x = r.nLeft + dx * halign - tp.XBearing; |
699 | | - y += fp.Height; |
700 | | - |
701 | | - sFont.draw(s, tcolor, x, y, fscaling, &text, last, tail); |
702 | | - last = curr + 1; |
703 | | - } |
| 676 | + draw_multiline_text( |
| 677 | + s, &sFont, &r, tcolor, |
| 678 | + &fp, &tp, halign, valign, fscaling, |
| 679 | + &text); |
704 | 680 |
|
705 | 681 | s->clip_end(); |
706 | 682 | } |
|
0 commit comments