MCPcopy Create free account
hub / github.com/SolarLune/masterplan / QuickRenderText

Method QuickRenderText

textrenderer.go:414–470  ·  view source on GitHub ↗
(text string, pos Vector, sizeMultiplier float32, color, outlineColor Color, alignment string)

Source from the content-addressed store, hash-verified

412}
413
414func (tr *TextRenderer) QuickRenderText(text string, pos Vector, sizeMultiplier float32, color, outlineColor Color, alignment string) {
415
416 textSize := tr.MeasureText([]rune(text), sizeMultiplier)
417
418 switch alignment {
419 case AlignCenter:
420 pos.X -= textSize.X / 2
421 case AlignRight:
422 pos.X -= textSize.X
423 }
424
425 startX := pos.X
426
427 for _, c := range text {
428
429 glyph := tr.Glyph(c)
430
431 if glyph == nil {
432 continue
433 }
434
435 if c == '\n' {
436 pos.X = startX
437 pos.Y += globals.GridSize * sizeMultiplier
438 continue
439 } else if glyph == nil {
440 continue
441 }
442
443 tex := glyph.Texture()
444 tex.SetBlendMode(sdl.BLENDMODE_BLEND) // We set the blend mode here as well
445
446 if outlineColor != nil {
447 for y := -1; y <= 1; y++ {
448 for x := -1; x <= 1; x++ {
449 if x == 0 && y == 0 {
450 continue
451 }
452 dst := &sdl.FRect{pos.X + float32(x), pos.Y + float32(y), float32(glyph.Width()) * sizeMultiplier, float32(glyph.Height()) * sizeMultiplier}
453 tex.SetColorMod(outlineColor.RGB())
454 tex.SetAlphaMod(outlineColor[3])
455 globals.Renderer.RenderTexture(tex, nil, dst)
456 }
457 }
458 }
459
460 dst := &sdl.FRect{pos.X, pos.Y, float32(glyph.Width()) * sizeMultiplier, float32(glyph.Height()) * sizeMultiplier}
461
462 tex.SetColorMod(color.RGB())
463 tex.SetAlphaMod(color[3])
464
465 globals.Renderer.RenderTexture(tex, nil, dst)
466 pos.X += float32(glyph.Width()) * sizeMultiplier
467
468 }
469
470}
471

Callers 7

DrawMethod · 0.80
DrawCardMethod · 0.80
DrawGridMethod · 0.80
DrawLabelFunction · 0.80
DrawMethod · 0.80
DrawOnTopMethod · 0.80
mainFunction · 0.80

Calls 6

MeasureTextMethod · 0.95
GlyphMethod · 0.95
RGBMethod · 0.80
TextureMethod · 0.45
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected