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

Method Draw

gui.go:845–909  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

843}
844
845func (button *Button) Draw() {
846
847 buttonRect := button.Rectangle()
848
849 if button.BackgroundColor[3] > 0 {
850 // gfx.RoundedRectangleColor(globals.Renderer, int32(buttonRect.X), int32(buttonRect.Y), int32(buttonRect.X)+int32(buttonRect.W), int32(buttonRect.Y)+int32(buttonRect.H), 4, button.BackgroundColor.SDLColor())
851 globals.Renderer.SetDrawColor(button.BackgroundColor.RGBA())
852 globals.Renderer.RenderFillRect(buttonRect)
853 }
854
855 if len(button.Label.Text) > 0 {
856 button.Label.Draw()
857 }
858
859 mousePos := globals.Mouse.Position()
860
861 if button.WorldSpace {
862 mousePos = globals.Mouse.WorldPosition()
863 }
864
865 button.Highlighter.Highlighting = (mousePos.Inside(buttonRect) || !button.FadeOnInactive) && !button.Disabled
866
867 button.Highlighter.SetRect(buttonRect)
868 button.Highlighter.Draw()
869
870 color := getThemeColor(GUIFontColor)
871
872 if button.IconSrc != nil {
873
874 guiTexture := globals.GUITexture.Texture
875
876 guiTexture.SetAlphaMod(uint8(button.Label.Alpha * 255))
877 if button.TintByFontColor {
878 guiTexture.SetColorMod(color.RGB())
879 } else {
880 guiTexture.SetColorMod(255, 255, 255)
881 }
882 guiTexture.SetBlendMode(sdl.BLENDMODE_BLEND)
883 tx := float32(0)
884 if button.Label.RendererResult != nil {
885 tx = button.Label.RendererResult.TextSize.X
886 }
887 dst := &sdl.FRect{buttonRect.X + (buttonRect.W / 2) - (tx / 2) - float32(button.IconSrc.W), buttonRect.Y, float32(button.IconSrc.W), float32(button.IconSrc.H)}
888 // textHalfWidth := button.Label.RendererResult.TextSize.X / 2
889 // dst := &sdl.FRect{buttonRect.X + (buttonRect.W / 2) - float32(button.IconSrc.W) - textHalfWidth, buttonRect.Y, float32(button.IconSrc.W), float32(button.IconSrc.H)}
890
891 if button.WorldSpace {
892 dst = globals.Project.Camera.TranslateRect(dst)
893 }
894
895 globals.Renderer.RenderTexture(guiTexture, button.IconSrc, dst)
896
897 }
898
899 if globals.DebugMode == DebugModeUI {
900 dst := &sdl.FRect{buttonRect.X, buttonRect.Y, buttonRect.W, buttonRect.H}
901 if button.WorldSpace {
902 dst = globals.Project.Camera.TranslateRect(dst)

Callers

nothing calls this directly

Calls 10

RectangleMethod · 0.95
getThemeColorFunction · 0.85
RGBAMethod · 0.80
WorldPositionMethod · 0.80
InsideMethod · 0.80
SetRectMethod · 0.80
RGBMethod · 0.80
TranslateRectMethod · 0.80
DrawMethod · 0.65
PositionMethod · 0.45

Tested by

no test coverage detected