Skip to content

Commit

Permalink
fixed typos and added option to load image from path
Browse files Browse the repository at this point in the history
  • Loading branch information
RonenNess committed Sep 28, 2023
1 parent b0538ba commit d977d72
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,5 @@ __pycache__/

# Cake - Uncomment if you are using it
# tools/
nuget.exe
nuget.exe
GeonBit.UI/Content/GeonBit.UI.DataTypes.dll
Binary file modified GeonBit.UI/Content/GeonBit.UI.DataTypes.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GeonBit.UI/Source/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public Rectangle InternalDestRect
/// Create the entity.
/// </summary>
/// <param name="size">Entity size, in pixels.</param>
/// <param name="anchor">Poisition anchor.</param>
/// <param name="anchor">Position anchor.</param>
/// <param name="offset">Offset from anchor position.</param>
public Entity(Vector2? size = null, Anchor anchor = Anchor.Auto, Vector2? offset = null)
{
Expand Down
2 changes: 1 addition & 1 deletion GeonBit.UI/Source/Entities/Icon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public IconType IconType
/// <param name="background">Whether or not to show icon inventory-like background.</param>
/// <param name="offset">Offset from anchor position.</param>
public Icon(IconType icon, Anchor anchor = Anchor.Auto, float scale = 1.0f, bool background = false, Vector2? offset = null) :
base(null, USE_DEFAULT_SIZE, ImageDrawMode.Stretch, anchor, offset)
base((Texture2D)null, USE_DEFAULT_SIZE, ImageDrawMode.Stretch, anchor, offset)
{
// set scale and basic properties
Scale = scale;
Expand Down
19 changes: 15 additions & 4 deletions GeonBit.UI/Source/Entities/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
// Since: 2016.
//-----------------------------------------------------------------------------
#endregion
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GeonBit.UI.DataTypes;

namespace GeonBit.UI.Entities
{
Expand Down Expand Up @@ -71,7 +69,7 @@ public string TextureName
/// <param name="texture">Image texture.</param>
/// <param name="size">Image size.</param>
/// <param name="drawMode">How to draw the image (see ImageDrawMode for more info).</param>
/// <param name="anchor">Poisition anchor.</param>
/// <param name="anchor">Position anchor.</param>
/// <param name="offset">Offset from anchor position.</param>
public Image(Texture2D texture, Vector2? size = null, ImageDrawMode drawMode = ImageDrawMode.Stretch, Anchor anchor = Anchor.Auto, Vector2? offset = null) :
base(size, anchor, offset)
Expand All @@ -84,10 +82,23 @@ public Image(Texture2D texture, Vector2? size = null, ImageDrawMode drawMode = I
UpdateStyle(DefaultStyle);
}

/// <summary>
/// Create image from texture path.
/// </summary>
/// <param name="texture">Texture path, under active theme folder.</param>
/// <param name="size">Image size.</param>
/// <param name="drawMode">How to draw the image (see ImageDrawMode for more info).</param>
/// <param name="anchor">Position anchor.</param>
/// <param name="offset">Offset from anchor position.</param>
public Image(string texture, Vector2? size = null, ImageDrawMode drawMode = ImageDrawMode.Stretch, Anchor anchor = Anchor.Auto, Vector2? offset = null) :
this(Resources.Instance.LoadTexture(texture), size, drawMode, anchor, offset)
{
}

/// <summary>
/// Create image without texture.
/// </summary>
public Image() : this(null)
public Image() : this((Texture2D)null)
{
}

Expand Down
2 changes: 1 addition & 1 deletion GeonBit.UI/Source/Input/DefaultInputProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public string GetTextInput(string txt, int lineWidth, ref int pos)
}

/// <summary>
/// Get current mouse poisition.
/// Get current mouse Position.
/// </summary>
public Vector2 MousePosition
{
Expand Down
2 changes: 1 addition & 1 deletion GeonBit.UI/Source/Input/IMouseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface IMouseInput
void Update(GameTime gameTime);

/// <summary>
/// Get current mouse poisition.
/// Get current mouse Position.
/// </summary>
Vector2 MousePosition { get; }

Expand Down
10 changes: 10 additions & 0 deletions GeonBit.UI/Source/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,16 @@ private void LoadDefaultStyles(StyleSheet sheet, string entityName, string theme
FillDefaultStyles(sheet, EntityState.MouseDown, LoadXmlStyles($"{stylesheetBase}-MouseDown", content));
}

/// <summary>
/// Load texture from path.
/// </summary>
/// <param name="path">Texture path, under theme folder.</param>
/// <returns>Texture instance.</returns>
public Texture2D LoadTexture(string path)
{
return _content.Load<Texture2D>(System.IO.Path.Combine(_root, path));
}

/// <summary>
/// Fill a set of default styles into a given stylesheet.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,8 @@ For older MonoGame versions, see [tag 2.1.0.0](https://github.com/RonenNess/Geon
- - In addition, renamed 'DropDown.SelectedPanelHeight' to 'DropDown.DefaultSelectedTextPanelHeight', and this property will only be used if 'DropDownSelectedPanel' stylesheet is missing, or define default height to 1 or 0.
- Removed compile warnings by adding defaults and `= null!`.
- Changed Slider and Progress bar Min and Max properties to support negative numbers. Now sliders can go negative!
- Fixed typos.
- Added option to create Image from path.

## Credits

Expand Down

0 comments on commit d977d72

Please sign in to comment.