MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / Draw

Method Draw

Sources/Jazz2/UI/FormattedTextBlock.cpp:130–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128 }
129
130 void FormattedTextBlock::Draw(Canvas* canvas, Rectf bounds, std::uint16_t depth, std::int32_t& charOffset, float angleOffset, float varianceX, float varianceY, float speed)
131 {
132 if (_parts.empty() || _proposedWidth != bounds.W) {
133 _proposedWidth = bounds.W;
134 RecreateCache();
135 }
136
137 /*for (auto& part : _background) {
138 if (part.Bounds.H > 5) {
139 // TODO
140 // Rounded rectangle
141 Color outlineColor = (part.CurrentColor.GetR() + part.CurrentColor.GetG() + part.CurrentColor.GetB() < 3 * 128
142 ? Color::FromArgb(180, part.CurrentColor.GetR() + 60, part.CurrentColor.GetG() + 60, part.CurrentColor.GetB() + 60)
143 : Color::FromArgb(110, part.CurrentColor.GetR() - 120, part.CurrentColor.GetG() - 120, part.CurrentColor.GetB() - 120));
144
145 g.FillRoundedRectangle(part.CurrentColor, outlineColor, part.Bounds.Offset(Point(bounds.X, bounds.Y)));
146 } else {
147 // Dotted line
148 for (std::int32_t y = 0; y < part.Bounds.H; y++) {
149 for (std::int32_t x = 1; x < part.Bounds.W; x += part.Bounds.H * 2) {
150 g.FillPixelsUnsafe(part.CurrentColor, part.Bounds.X + bounds.X + x, part.Bounds.Y + bounds.Y + y, part.Bounds.H);
151 }
152 }
153 }
154 }*/
155
156 std::int32_t charOffsetShadow = charOffset;
157
158 auto it = _parts.begin();
159 while (it != _parts.end()) {
160 if (it->Location.Y + it->Height > bounds.H) {
161 break;
162 }
163
164 Vector2f p = it->Location;
165 p.X += bounds.X;
166 p.Y += bounds.Y;
167
168 String textPart = (it->Begin == Ellipsis ? "..."_s : StringView(_text.data() + it->Begin, it->Length));
169 _font->DrawString(canvas, textPart, charOffsetShadow, p.X, p.Y + 2.8f * _defaultScale, depth - 80, Alignment::Left,
170 Colorf(0.0f, 0.0f, 0.0f, 0.29f), it->Scale, it->AllowVariance ? angleOffset : 0.0f, varianceX, varianceY, speed, it->CharSpacing);
171
172 ++it;
173 }
174
175 it = _parts.begin();
176 while (it != _parts.end()) {
177 if (it->Location.Y + it->Height > bounds.H) {
178 break;
179 }
180
181 Vector2f p = it->Location;
182 p.X += bounds.X;
183 p.Y += bounds.Y;
184
185 String textPart = (it->Begin == Ellipsis ? "..."_s : StringView(_text.data() + it->Begin, it->Length));
186 _font->DrawString(canvas, textPart, charOffset, p.X, p.Y, depth, Alignment::Left,
187 it->CurrentColor, it->Scale, it->AllowVariance ? angleOffset : 0.0f, varianceX, varianceY, speed, it->CharSpacing);

Callers 2

OnDrawMethod · 0.45
OnDrawClippedMethod · 0.45

Calls 6

DrawStringMethod · 0.80
ColorfClass · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected