Videogamers0 / MGUI

UI framework for MonoGame game engine.
MIT License
69 stars 8 forks source link

Are background images supported ? #23

Open orosbogdan opened 2 days ago

orosbogdan commented 2 days ago

Are background images supported for panels/windows or just background colors ?

Videogamers0 commented 2 days ago

You can use any implementation of MGUI.Core.UI.Brushes.Fill_Brushes.IFillBrush for the BackgroundBrush of any MGElement. You would want to use an MGTextureFillBrush.

Other built-in implementations of IFillBrush are: MGSolidFillBrush (for using single solid color backgrounds. Colors are automatically converted to solid fill brushes in XAML), MGGradientFillBrush (for using a gradient colored background), MGDiagonalGradientFillBrush (just a simpler version of MGGradientFillBrush that only interpolates between 2 colors instead of all 4 corners), MGPaddedFillBrush, MGBorderedFillBrush, MGProgressBarGradientBrush, MGCompositedFillBrush (draws multiple IFillBrushes overtop of each other to combine multiple functionality)

EX:

Texture2D sampleTexture = Content.Load<Texture2D>("mytexture");
MGTextureFillBrush textureBrush = new MGTextureFillBrush(new MGTextureData(sampleTexture), Stretch.Uniform);
MGBorder borderWithTexturedBackground = new MGBorder(...);
borderWithTexturedBackground.BackgroundBrush.SetAll(textureBrush);

Or in XAML, assuming you've already added an MGTextureData named "Sample1" to your MGResources via `MGResources.AddTexture(name, data):

<Border Width="100" Height="100">
    <Border.Background>
        <TextureFillBrush Color="White" SourceName="Sample1" Stretch="Uniform" />
    </Border.Background>
</Border>