Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Nov 9, 2023
1 parent e50f650 commit 66c432d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
4 changes: 2 additions & 2 deletions samples/Myra.Samples.AllWidgets/AllWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public AllWidgets()
public void OpenFile()
{
var fileDialog = new FileDialog(FileDialogMode.OpenFile);
fileDialog.ShowModal(Desktop, darkening: true);
fileDialog.ShowModal(Desktop);

fileDialog.Closed += (s, a) =>
{
Expand All @@ -175,7 +175,7 @@ public void OpenFile()
public void SaveFile()
{
var fileDialog = new FileDialog(FileDialogMode.SaveFile);
fileDialog.ShowModal(Desktop, darkening: true);
fileDialog.ShowModal(Desktop);

fileDialog.Closed += (s, a) =>
{
Expand Down
1 change: 1 addition & 0 deletions samples/Myra.Samples.AllWidgets/AllWidgetsGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected override void LoadContent()
base.LoadContent();

MyraEnvironment.Game = this;
MyraEnvironment.EnableWindowDarkening = true;

_allWidgets = new AllWidgets();

Expand Down
1 change: 1 addition & 0 deletions samples/Myra.Samples.Silk.NET/AllWidgetsGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private void OnLoad()

_platform = new SilkPlatform(_window.CreateInput());
MyraEnvironment.Platform = _platform;
MyraEnvironment.EnableWindowDarkening = true;
OnResize(_window.Size);

_allWidgets = new AllWidgets();
Expand Down
24 changes: 21 additions & 3 deletions src/Myra/Graphics2D/RenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? s
#if MONOGAME || FNA || STRIDE
sz = new Vector2(texture.Width, texture.Height);
#else
var p = _fontStashRenderer.TextureManager.GetTextureSize(texture);
Point p;
if (_fontStashRenderer != null)
{
p = _fontStashRenderer.TextureManager.GetTextureSize(texture);
} else
{
p = _fontStashRenderer2.TextureManager.GetTextureSize(texture);
}

sz = new Vector2(p.X, p.Y);
#endif
}
Expand Down Expand Up @@ -267,8 +275,18 @@ public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle
}
else
{
var size = new Vector2(scale.X * sourceRectangle.Value.Width, scale.Y * sourceRectangle.Value.Height);
_renderer.DrawQuad(texture, color, position, ref Transform.Matrix, depth, size, sourceRectangle.Value,
Rectangle r;
if (sourceRectangle != null)
{
r = sourceRectangle.Value;
} else
{
var textureSize = _fontStashRenderer2.TextureManager.GetTextureSize(texture);
r = new Rectangle(0, 0, textureSize.X, textureSize.Y);
}

var size = new Vector2(scale.X * r.Width, scale.Y * r.Height);
_renderer.DrawQuad(texture, color, position, ref Transform.Matrix, depth, size, r,
ref _topLeft, ref _topRight, ref _bottomLeft, ref _bottomRight);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Myra/Graphics2D/UI/Desktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public void RenderVisual()
{
if (widget.Visible)
{
if (widget.IsDarkening)
if (MyraEnvironment.EnableWindowDarkening)
{
_renderContext.FillRectangle(bounds, MyraEnvironment.DarkeningColor);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Myra/Graphics2D/UI/Misc/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,15 @@ private void InternalShow(Desktop desktop, Point? position = null)
}
}

public void Show(Desktop desktop, Point? position = null, bool darkening = false)
public void Show(Desktop desktop, Point? position = null)
{
IsModal = false;
IsDarkening = darkening;
InternalShow(desktop, position);
}

public void ShowModal(Desktop desktop, Point? position = null, bool darkening = false)
public void ShowModal(Desktop desktop, Point? position = null)
{
IsModal = true;
IsDarkening = darkening;
InternalShow(desktop, position);

_previousKeyboardFocus = desktop.FocusedKeyboardWidget;
Expand Down
4 changes: 0 additions & 4 deletions src/Myra/Graphics2D/UI/Widget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,6 @@ internal set
[Browsable(false)]
public bool IsModal { get; set; }

[XmlIgnore]
[Browsable(false)]
public bool IsDarkening { get; set; }

[Category("Appearance")]
[DefaultValue(1.0f)]
public float Opacity
Expand Down
3 changes: 3 additions & 0 deletions src/Myra/MyraEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#else
using Myra.Platform;
using System.Drawing;
using Color = FontStashSharp.FSColor;
#endif

namespace Myra
Expand Down Expand Up @@ -252,6 +253,8 @@ public static AssetManager DefaultAssetManager
/// Makes the text rendering more smooth(especially when scaling) for the cost of sacrificing some performance
/// </summary>
public static bool SmoothText { get; set; }
public static bool EnableWindowDarkening { get; set; } = true;

public static Color DarkeningColor { get; set; } = new Color(0, 0, 0, 192);

private static void GameOnDisposed(object sender, EventArgs eventArgs)
Expand Down

0 comments on commit 66c432d

Please sign in to comment.