Renderer:

+ Font.BaselineAdjust

Utils:
+ GameControllerState.AnyInteractions
This commit is contained in:
Michel Fedde 2021-05-21 16:05:52 +02:00
parent 89de4258e1
commit dffa581596
18 changed files with 70 additions and 40 deletions

View file

@ -1,6 +1,6 @@
using SharpDX.XInput;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public struct GameController
{

View file

@ -2,7 +2,7 @@
using OpenTK;
using SharpDX.XInput;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public struct GameControllerState
{
@ -12,7 +12,7 @@ namespace SM.Optionals.Controls
public GameControllerStateButtons Buttons;
public bool FromConnected { get; }
public bool AnyInteraction => Buttons.AnyInteraction || DPad.AnyInteraction || Triggers.AnyInteraction || Thumbs.AnyInteraction;
internal GameControllerState(bool empty)
{
FromConnected = false;

View file

@ -1,6 +1,6 @@
using SharpDX.XInput;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public struct GameControllerStateButtons
{
@ -19,8 +19,13 @@ namespace SM.Optionals.Controls
public bool LeftThumb;
public bool RightThumb;
public bool Start;
public bool Back;
public bool this[GamepadButtonFlags flags] => _buttonFlags.HasFlag(flags);
public bool AnyInteraction { get; }
internal GameControllerStateButtons(GamepadButtonFlags flags)
{
_buttonFlags = flags;
@ -35,6 +40,11 @@ namespace SM.Optionals.Controls
LeftThumb = flags.HasFlag(GamepadButtonFlags.LeftThumb);
RightThumb = flags.HasFlag(GamepadButtonFlags.RightThumb);
Start = flags.HasFlag(GamepadButtonFlags.Start);
Back = flags.HasFlag(GamepadButtonFlags.Back);
AnyInteraction = (int) flags >= 16;
}
public override string ToString()

View file

@ -1,6 +1,6 @@
using SharpDX.XInput;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public struct GameControllerStateDPad
{
@ -11,12 +11,16 @@ namespace SM.Optionals.Controls
public bool Left;
public bool Right;
public bool AnyInteraction { get; }
internal GameControllerStateDPad(GamepadButtonFlags flags)
{
Up = flags.HasFlag(GamepadButtonFlags.DPadUp);
Down = flags.HasFlag(GamepadButtonFlags.DPadDown);
Left = flags.HasFlag(GamepadButtonFlags.DPadLeft);
Right = flags.HasFlag(GamepadButtonFlags.DPadRight);
AnyInteraction = (int)flags > 0 && (int) flags < 16;
}
public override string ToString()

View file

@ -1,6 +1,6 @@
using OpenTK;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public struct GameControllerStateThumbs
{
@ -13,6 +13,8 @@ namespace SM.Optionals.Controls
public bool PressedLeft;
public bool PressedRight;
public bool AnyInteraction => Left != Vector2.Zero || Right != Vector2.Zero || PressedLeft || PressedRight;
public override string ToString()
{
return $"Left: ({Left.X}; {Left.Y}){(PressedLeft ? " Pressed" : "")}; Right: ({Right.X}; {Right.Y}){(PressedRight ? " Pressed" : "")}";

View file

@ -1,4 +1,4 @@
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public struct GameControllerStateTriggers
{
@ -6,6 +6,9 @@
public float Left;
public float Right;
public bool AnyInteraction => Left != 0f || Right != 0f;
public override string ToString()
{
return $"Left: {Left}; Right: {Right}";

View file

@ -1,6 +1,6 @@
using System;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public class GameKeybind
{

View file

@ -1,6 +1,6 @@
using OpenTK.Input;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public enum GameKeybindActorType
{

View file

@ -1,6 +1,6 @@
using OpenTK.Input;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public struct GameKeybindContext
{

View file

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public class GameKeybindHost
{

View file

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace SM.Optionals.Controls
namespace SM.Utils.Controls
{
public class GameKeybindList : List<KeyValuePair<string, GameKeybind>>
{

View file

@ -39,9 +39,16 @@ namespace SM.Base.Drawing
/// <summary>
/// Returns the current model matrix.
/// </summary>
/// <param name="force">If set to true, it will always (re-)calculate the model matrix.</param>
/// <returns></returns>
public Matrix4 GetMatrix()
public Matrix4 GetMatrix(bool force = false)
{
if (force)
{
_lastFrame = SMRenderer.CurrentFrame;
return _modelMatrix = RequestMatrix();
}
if (Ignore) return Matrix4.Identity;
if (_lastFrame != SMRenderer.CurrentFrame)

View file

@ -40,6 +40,12 @@ namespace SM.Base.Drawing.Text
/// </summary>
public float FontSize { get; set; } = 12;
/// <summary>
/// Allows to adjust the baseline to fix clipping issues.
/// <para>Due to some issues with the calculations, this is a temporary fix.</para>
/// </summary>
public float BaselineAdjust { get; set; } = 1f;
/// <summary>
/// The character positions.
/// </summary>
@ -64,6 +70,8 @@ namespace SM.Base.Drawing.Text
public void RegenerateTexture()
{
Width = Height = 0;
//Height = Math.Abs(_fontFace.BBox.Bottom) + _fontFace.BBox.Top;
Positions = new Dictionary<char, CharParameter>();
_fontFace.SetCharSize(0, FontSize, 0, 96);
@ -83,7 +91,7 @@ namespace SM.Base.Drawing.Text
float bBoxHeight = (Math.Abs(_fontFace.BBox.Bottom) + _fontFace.BBox.Top);
float bBoxTopScale = _fontFace.BBox.Top / bBoxHeight;
float baseline = Height * bBoxTopScale + 1;
float baseline = (Height * bBoxTopScale) + BaselineAdjust;
Map = new Bitmap(Width, Height);
using (Graphics g = Graphics.FromImage(Map))
@ -95,8 +103,7 @@ namespace SM.Base.Drawing.Text
{
_fontFace.LoadChar(keyvalue.Key, LoadFlags.Render, LoadTarget.Normal);
int y = ((int)baseline - (int)_fontFace.Glyph.Metrics.HorizontalBearingY);
int y = ((int)baseline - (int) _fontFace.Glyph.Metrics.HorizontalBearingY);
g.DrawImageUnscaled(_fontFace.Glyph.Bitmap.ToGdipBitmap(Color.White), (int)keyvalue.Value[1], y);
Vector2 offset = new Vector2(keyvalue.Value[1] / Width, 0);