Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ packages
*.user
tools
TestResults*
.vs/**
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
2 changes: 1 addition & 1 deletion Demos/UiDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override void LoadContent() {
};
var untexturedStyle = new UntexturedStyle(this.SpriteBatch) {
TextScale = style.TextScale,
Font = style.Font
Font = style.Font,
};
// set the defined style as the current one
this.UiSystem.Style = style;
Expand Down
1 change: 1 addition & 0 deletions MLEM.Ui/Elements/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
this.Texture = this.Texture.OrStyle(style.ButtonTexture);
this.NormalColor = this.NormalColor.OrStyle(style.ButtonColor);
this.HoveredTexture = this.HoveredTexture.OrStyle(style.ButtonHoveredTexture);
this.HoveredColor = this.HoveredColor.OrStyle(style.ButtonHoveredColor);
this.DisabledTexture = this.DisabledTexture.OrStyle(style.ButtonDisabledTexture);
Expand Down
25 changes: 23 additions & 2 deletions MLEM.Ui/Elements/Checkbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class Checkbox : Element {
/// </summary>
public StyleProp<NinePatch> Texture;
/// <summary>
/// The color that this checkbox uses for drawing.
/// </summary>
public StyleProp<Color> BackColor;
/// <summary>
/// The texture that this checkbox uses when it is hovered.
/// If this is null, the default <see cref="Texture"/> is used.
/// </summary>
Expand All @@ -39,6 +43,16 @@ public class Checkbox : Element {
/// The texture that is rendered on top of this checkbox when it is <see cref="Checked"/>.
/// </summary>
public StyleProp<TextureRegion> Checkmark;
/// <summary>
/// The color of the check mark that is rendered on top of this checkbox when it is <see cref="Checked"/>.
/// </summary>
public StyleProp<Color> CheckColor;
/// <summary>
/// The color of the check mark that is rendered on top of this checkbox when it is not <see cref="Checked"/>.
/// Set alpha to 0 to disable this behavior.
/// </summary>
public StyleProp<Color> UncheckColor;

/// <summary>
/// The label <see cref="Paragraph"/> that displays next to this checkbox
/// </summary>
Expand Down Expand Up @@ -117,7 +131,7 @@ public override void SetAreaAndUpdateChildren(RectangleF area) {
/// <inheritdoc />
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
var tex = this.Texture;
var color = Color.White * alpha;
var color = this.BackColor.OrDefault(Color.White) * alpha;
if (this.IsDisabled) {
tex = this.DisabledTexture.OrDefault(tex);
color = (Color) this.DisabledColor * alpha;
Expand All @@ -128,20 +142,27 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB

var boxDisplayArea = new RectangleF(this.DisplayArea.Location, new Vector2(this.DisplayArea.Height));
batch.Draw(tex, boxDisplayArea, color, this.Scale);
var uncheckedColor = this.UncheckColor.OrDefault(Color.Transparent);
if (this.Checked)
batch.Draw(this.Checkmark, boxDisplayArea, Color.White * alpha);
batch.Draw(this.Checkmark, boxDisplayArea, this.CheckColor.OrDefault(Color.White) * alpha);
else if(uncheckedColor.A != 0) {
batch.Draw(this.Checkmark, boxDisplayArea, uncheckedColor * alpha);
}
base.Draw(time, batch, alpha, context);
}

/// <inheritdoc />
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
this.Texture = this.Texture.OrStyle(style.CheckboxTexture);
this.BackColor = this.BackColor.OrStyle(style.CheckboxColor);
this.HoveredTexture = this.HoveredTexture.OrStyle(style.CheckboxHoveredTexture);
this.HoveredColor = this.HoveredColor.OrStyle(style.CheckboxHoveredColor);
this.DisabledTexture = this.DisabledTexture.OrStyle(style.CheckboxDisabledTexture);
this.DisabledColor = this.DisabledColor.OrStyle(style.CheckboxDisabledColor);
this.Checkmark = this.Checkmark.OrStyle(style.CheckboxCheckmark);
this.CheckColor = this.CheckColor.OrStyle(style.CheckboxCheckColor);
this.UncheckColor = this.UncheckColor.OrStyle(style.CheckboxUncheckedColor);
this.TextOffsetX = this.TextOffsetX.OrStyle(style.CheckboxTextOffsetX);
}

Expand Down
4 changes: 4 additions & 0 deletions MLEM.Ui/Elements/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ public StyleProp<UiStyle> Style {
/// </summary>
public StyleProp<NinePatch> SelectionIndicator;
/// <summary>
/// A style property that contains the color of the selection indicator that is displayed on this element if it is the <see cref="RootElement.SelectedElement"/>
/// </summary>
public StyleProp<Color> SelectionColor;
/// <summary>
/// A style property that contains the sound effect that is played when this element's <see cref="OnPressed"/> is called
/// </summary>
public StyleProp<SoundEffectInfo> ActionSound;
Expand Down
3 changes: 3 additions & 0 deletions MLEM.Ui/Elements/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ public RadioButton(Anchor anchor, Vector2 size, string label, bool defaultChecke
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
this.Texture = this.Texture.OrStyle(style.RadioTexture);
this.BackColor = this.BackColor.OrStyle(style.RadioColor);
this.HoveredTexture = this.HoveredTexture.OrStyle(style.RadioHoveredTexture);
this.HoveredColor = this.HoveredColor.OrStyle(style.RadioHoveredColor);
this.Checkmark = this.Checkmark.OrStyle(style.RadioCheckmark);
this.CheckColor = this.CheckColor.OrStyle(style.RadioCheckColor);
this.UncheckColor = this.UncheckColor.OrStyle(style.RadioUncheckedColor);
}

}
Expand Down
14 changes: 12 additions & 2 deletions MLEM.Ui/Elements/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ public class ScrollBar : Element {
/// </summary>
public StyleProp<NinePatch> Background;
/// <summary>
/// The background color for this scroll bar
/// </summary>
public StyleProp<Color> BackColor;
/// <summary>
/// The texture of this scroll bar's scroller indicator
/// </summary>
public StyleProp<NinePatch> ScrollerTexture;
/// <summary>
/// The color of this scroll bar's scroller indicator
/// </summary>
public StyleProp<Color> ScrollerColor;
/// <summary>
/// Whether smooth scrolling should be enabled for this scroll bar.
/// Smooth scrolling causes the <see cref="CurrentValue"/> to change gradually rather than instantly when scrolling.
/// </summary>
Expand Down Expand Up @@ -231,10 +239,10 @@ private void ScrollToPos(Vector2 position) {

/// <inheritdoc />
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
batch.Draw(this.Background, this.DisplayArea, Color.White * alpha, this.Scale);
batch.Draw(this.Background, this.DisplayArea, this.BackColor.OrDefault(Color.White) * alpha, this.Scale);
if (this.MaxValue > 0) {
var scrollerRect = new RectangleF(this.ScrollerPosition, this.ScrollerSize * this.Scale);
batch.Draw(this.ScrollerTexture, scrollerRect, Color.White * alpha, this.Scale);
batch.Draw(this.ScrollerTexture, scrollerRect, this.ScrollerColor.OrDefault(Color.White) * alpha, this.Scale);
}
base.Draw(time, batch, alpha, context);
}
Expand All @@ -243,7 +251,9 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
this.Background = this.Background.OrStyle(style.ScrollBarBackground);
this.BackColor = this.BackColor.OrStyle(style.ScrollBarBackColor);
this.ScrollerTexture = this.ScrollerTexture.OrStyle(style.ScrollBarScrollerTexture);
this.ScrollerColor = this.ScrollerColor.OrStyle(style.ScrollBarScrollerColor);
this.SmoothScrolling = this.SmoothScrolling.OrStyle(style.ScrollBarSmoothScrolling);
this.SmoothScrollFactor = this.SmoothScrollFactor.OrStyle(style.ScrollBarSmoothScrollFactor);
}
Expand Down
8 changes: 7 additions & 1 deletion MLEM.Ui/Elements/TextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public class TextField : Element {
/// </summary>
public StyleProp<NinePatch> Texture;
/// <summary>
/// This text field's background color
/// </summary>
public StyleProp<Color> BackColor;
/// <summary>
/// This text field's texture while it is hovered
/// </summary>
public StyleProp<NinePatch> HoveredTexture;
Expand Down Expand Up @@ -239,7 +243,7 @@ public override void Update(GameTime time) {
/// <inheritdoc />
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
var tex = this.Texture;
var color = Color.White * alpha;
var color = (Color) this.BackColor * alpha;
if (this.IsMouseOver) {
tex = this.HoveredTexture.OrDefault(tex);
color = (Color) this.HoveredColor * alpha;
Expand Down Expand Up @@ -278,7 +282,9 @@ protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
this.TextScale = this.TextScale.OrStyle(style.TextScale);
this.Font = this.Font.OrStyle(style.Font);
this.TextColor = this.TextColor.OrStyle(style.TextFieldTextColor);
this.Texture = this.Texture.OrStyle(style.TextFieldTexture);
this.BackColor = this.BackColor.OrStyle(style.TextFieldColor);
this.HoveredTexture = this.HoveredTexture.OrStyle(style.TextFieldHoveredTexture);
this.HoveredColor = this.HoveredColor.OrStyle(style.TextFieldHoveredColor);
this.TextOffsetX = this.TextOffsetX.OrStyle(style.TextFieldTextOffsetX);
Expand Down
1 change: 1 addition & 0 deletions MLEM.Ui/Elements/Tooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public override void ForceUpdateArea() {
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);
this.Texture = this.Texture.OrStyle(style.TooltipBackground);
this.DrawColor = this.DrawColor.OrStyle(style.TooltipBackColor);
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset);
this.MouseAnchor = this.MouseAnchor.OrStyle(style.TooltipMouseAnchor);
Expand Down
66 changes: 66 additions & 0 deletions MLEM.Ui/Style/UiStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public NinePatch SelectionIndicator;
/// <summary>
/// The color of the selector that is rendered on top of the <see cref="UiControls.SelectedElement"/>
/// </summary>
public Color SelectionColor = Color.White;
/// <summary>
/// A <see cref="UiAnimation"/> that is played when the mouse enters an element.
/// </summary>
public UiAnimation MouseEnterAnimation;
Expand All @@ -35,6 +39,10 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public NinePatch ButtonTexture;
/// <summary>
/// The color that the <see cref="Button"/> element renders
/// </summary>
public Color ButtonColor = Color.White;
/// <summary>
/// The texture that the <see cref="Button"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
/// Note that, if you just want to change the button's color when hovered, use <see cref="ButtonHoveredColor"/>.
/// </summary>
Expand Down Expand Up @@ -76,10 +84,18 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public float PanelScrollBarOffset = 1;
/// <summary>
/// The text color of text the <see cref="TextField"/> element uses
/// </summary>
public Color TextFieldTextColor = Color.White;
/// <summary>
/// The texture that the <see cref="TextField"/> element uses
/// </summary>
public NinePatch TextFieldTexture;
/// <summary>
/// The color that the <see cref="TextField"/> renders with when it is idle
/// </summary>
public Color TextFieldColor = Color.LightGray;
/// <summary>
/// The texture that the <see cref="TextField"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
/// </summary>
public NinePatch TextFieldHoveredTexture;
Expand All @@ -100,10 +116,18 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public NinePatch ScrollBarBackground;
/// <summary>
/// The background color that the <see cref="ScrollBar"/> element uses
/// </summary>
public Color ScrollBarBackColor = Color.White;
/// <summary>
/// The texture that the scroll indicator of the <see cref="ScrollBar"/> element uses
/// </summary>
public NinePatch ScrollBarScrollerTexture;
/// <summary>
/// The color that the scroll indicator of the <see cref="ScrollBar"/> element uses
/// </summary>
public Color ScrollBarScrollerColor = Color.White;
/// <summary>
/// Whether or not a <see cref="ScrollBar"/> should use smooth scrolling
/// </summary>
public bool ScrollBarSmoothScrolling;
Expand All @@ -116,6 +140,10 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public NinePatch CheckboxTexture;
/// <summary>
/// The color that the <see cref="Checkbox"/> element uses
/// </summary>
public Color CheckboxColor = Color.White;
/// <summary>
/// The texture that the <see cref="Checkbox"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
/// </summary>
public NinePatch CheckboxHoveredTexture;
Expand All @@ -136,6 +164,15 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public TextureRegion CheckboxCheckmark;
/// <summary>
/// The color of the check mark that the <see cref="Checkbox"/> element uses when it is <see cref="Checkbox.Checked"/>
/// </summary>
public Color CheckboxCheckColor = Color.White;
/// <summary>
/// The color of the check mark that the <see cref="Checkbox"/> element uses when it is not <see cref="Checkbox.Checked"/>.
/// Set alpha to 0 to disable this behavior
/// </summary>
public Color CheckboxUncheckedColor = Color.Transparent;
/// <summary>
/// The width of the space between a <see cref="Checkbox"/> and its <see cref="Checkbox.Label"/>
/// </summary>
public float CheckboxTextOffsetX = 2;
Expand All @@ -144,6 +181,10 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public NinePatch RadioTexture;
/// <summary>
/// The color that the <see cref="RadioButton"/> element uses
/// </summary>
public Color RadioColor = Color.White;
/// <summary>
/// The texture that the <see cref="RadioButton"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
/// </summary>
public NinePatch RadioHoveredTexture;
Expand All @@ -156,10 +197,23 @@ public class UiStyle : GenericDataHolder {
/// </summary>
public TextureRegion RadioCheckmark;
/// <summary>
/// The color of the check mark that the <see cref="RadioButton"/> uses when it is <see cref="Checkbox.Checked"/>
/// </summary>
public Color RadioCheckColor = Color.White;
/// <summary>
/// The color of the check mark that the <see cref="RadioButton"/> uses when it is not <see cref="Checkbox.Checked"/>
/// Set the alpha to 0 to disable this behavior
/// </summary>
public Color RadioUncheckedColor = Color.Transparent;
/// <summary>
/// The texture that the <see cref="Tooltip"/> uses for its background
/// </summary>
public NinePatch TooltipBackground;
/// <summary>
/// The color that the <see cref="Tooltip"/> uses for its background
/// </summary>
public Color TooltipBackColor = Color.White;
/// <summary>
/// The offset of the <see cref="Tooltip"/> element's top left corner from the mouse position
/// </summary>
public Vector2 TooltipOffset = new Vector2(8, 16);
Expand Down Expand Up @@ -286,9 +340,11 @@ public UiStyle() {}
/// <param name="original">The original style settings, to copy into the new instance.</param>
public UiStyle(UiStyle original) {
this.SelectionIndicator = original.SelectionIndicator;
this.SelectionColor = original.SelectionColor;
this.MouseEnterAnimation = original.MouseEnterAnimation;
this.MouseExitAnimation = original.MouseExitAnimation;
this.ButtonTexture = original.ButtonTexture;
this.ButtonColor = original.ButtonColor;
this.ButtonHoveredTexture = original.ButtonHoveredTexture;
this.ButtonHoveredColor = original.ButtonHoveredColor;
this.ButtonDisabledTexture = original.ButtonDisabledTexture;
Expand All @@ -300,26 +356,36 @@ public UiStyle(UiStyle original) {
this.PanelScrollerSize = original.PanelScrollerSize;
this.PanelScrollBarOffset = original.PanelScrollBarOffset;
this.TextFieldTexture = original.TextFieldTexture;
this.TextFieldColor = original.TextFieldColor;
this.TextFieldHoveredTexture = original.TextFieldHoveredTexture;
this.TextFieldHoveredColor = original.TextFieldHoveredColor;
this.TextFieldTextOffsetX = original.TextFieldTextOffsetX;
this.TextFieldCaretWidth = original.TextFieldCaretWidth;
this.ScrollBarBackground = original.ScrollBarBackground;
this.ScrollBarBackColor = original.ScrollBarBackColor;
this.ScrollBarScrollerTexture = original.ScrollBarScrollerTexture;
this.ScrollBarScrollerColor = original.ScrollBarScrollerColor;
this.ScrollBarSmoothScrolling = original.ScrollBarSmoothScrolling;
this.ScrollBarSmoothScrollFactor = original.ScrollBarSmoothScrollFactor;
this.CheckboxTexture = original.CheckboxTexture;
this.CheckboxColor = original.CheckboxColor;
this.CheckboxHoveredTexture = original.CheckboxHoveredTexture;
this.CheckboxHoveredColor = original.CheckboxHoveredColor;
this.CheckboxDisabledTexture = original.CheckboxDisabledTexture;
this.CheckboxDisabledColor = original.CheckboxDisabledColor;
this.CheckboxCheckmark = original.CheckboxCheckmark;
this.CheckboxCheckColor = original.CheckboxCheckColor;
this.CheckboxUncheckedColor = original.CheckboxUncheckedColor;
this.CheckboxTextOffsetX = original.CheckboxTextOffsetX;
this.RadioTexture = original.RadioTexture;
this.RadioColor = original.RadioColor;
this.RadioHoveredTexture = original.RadioHoveredTexture;
this.RadioHoveredColor = original.RadioHoveredColor;
this.RadioCheckmark = original.RadioCheckmark;
this.RadioCheckColor = original.RadioCheckColor;
this.RadioUncheckedColor = original.RadioUncheckedColor;
this.TooltipBackground = original.TooltipBackground;
this.TooltipBackColor = original.TooltipBackColor;
this.TooltipOffset = original.TooltipOffset;
this.TooltipAutoNavOffset = original.TooltipAutoNavOffset;
this.TooltipAutoNavAnchor = original.TooltipAutoNavAnchor;
Expand Down
Loading
Loading