mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-25 08:22:15 +00:00
finally getting back to working on the new gui system
This commit is contained in:
@@ -10,11 +10,13 @@ namespace MonoGame.Extended.Content.Pipeline.Animations
|
||||
public override ContentImporterResult<AstridAnimatorFile> Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
using (var streamReader = new StreamReader(filename))
|
||||
using (var jsonReader = new JsonTextReader(streamReader))
|
||||
{
|
||||
var serializer = new JsonSerializer();
|
||||
var data = serializer.Deserialize<AstridAnimatorFile>(jsonReader);
|
||||
return new ContentImporterResult<AstridAnimatorFile>(filename, data);
|
||||
using (var jsonReader = new JsonTextReader(streamReader))
|
||||
{
|
||||
var serializer = new JsonSerializer();
|
||||
var data = serializer.Deserialize<AstridAnimatorFile>(jsonReader);
|
||||
return new ContentImporterResult<AstridAnimatorFile>(filename, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -10,10 +10,12 @@ namespace MonoGame.Extended.Content.Pipeline.TextureAtlases
|
||||
public override TexturePackerFile Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
using (var streamReader = new StreamReader(filename))
|
||||
using (var jsonReader = new JsonTextReader(streamReader))
|
||||
{
|
||||
var serializer = new JsonSerializer();
|
||||
return serializer.Deserialize<TexturePackerFile>(jsonReader);
|
||||
using (var jsonReader = new JsonTextReader(streamReader))
|
||||
{
|
||||
var serializer = new JsonSerializer();
|
||||
return serializer.Deserialize<TexturePackerFile>(jsonReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,16 +41,18 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
|
||||
var decodedData = Convert.FromBase64String(encodedData);
|
||||
|
||||
using (var stream = OpenStream(decodedData, data.Compression))
|
||||
using (var reader = new BinaryReader(stream))
|
||||
{
|
||||
data.Tiles = new List<TmxDataTile>();
|
||||
|
||||
for (var y = 0; y < width; y++)
|
||||
using (var reader = new BinaryReader(stream))
|
||||
{
|
||||
for (var x = 0; x < height; x++)
|
||||
data.Tiles = new List<TmxDataTile>();
|
||||
|
||||
for (var y = 0; y < width; y++)
|
||||
{
|
||||
var gid = reader.ReadUInt32();
|
||||
tileList.Add(new TmxDataTile((int) gid));
|
||||
for (var x = 0; x < height; x++)
|
||||
{
|
||||
var gid = reader.ReadUInt32();
|
||||
tileList.Add(new TmxDataTile((int) gid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
namespace MonoGame.Extended.Gui.Controls
|
||||
using MonoGame.Extended.Gui.Keepers;
|
||||
using MonoGame.Extended.InputListeners;
|
||||
using MonoGame.Extended.TextureAtlases;
|
||||
|
||||
namespace MonoGame.Extended.Gui.Controls
|
||||
{
|
||||
public class GuiButton : GuiControl
|
||||
{
|
||||
public GuiButton()
|
||||
{
|
||||
}
|
||||
|
||||
public GuiButton(TextureRegion2D textureRegion)
|
||||
{
|
||||
BackgroundRegion = textureRegion;
|
||||
Size = BackgroundRegion.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.ComponentModel;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MonoGame.Extended.Gui.Keepers;
|
||||
using MonoGame.Extended.InputListeners;
|
||||
using MonoGame.Extended.SceneGraphs;
|
||||
using MonoGame.Extended.Shapes;
|
||||
using MonoGame.Extended.TextureAtlases;
|
||||
@@ -13,6 +15,7 @@ namespace MonoGame.Extended.Gui.Controls
|
||||
{
|
||||
BackgroundColor = Color.White;
|
||||
TextColor = Color.White;
|
||||
IsEnabled = true;
|
||||
Children = new GuiControlCollection(this);
|
||||
}
|
||||
|
||||
@@ -36,5 +39,49 @@ namespace MonoGame.Extended.Gui.Controls
|
||||
public Color TextColor { get; set; }
|
||||
|
||||
public GuiControlCollection Children { get; }
|
||||
|
||||
private bool _isEnabled;
|
||||
public bool IsEnabled
|
||||
{
|
||||
get { return _isEnabled; }
|
||||
set
|
||||
{
|
||||
_isEnabled = value;
|
||||
SetStyle(!_isEnabled ? _disabledStyle : null);
|
||||
}
|
||||
}
|
||||
|
||||
private GuiControlStyle _disabledStyle;
|
||||
public GuiControlStyle DisabledStyle
|
||||
{
|
||||
get { return _disabledStyle; }
|
||||
set
|
||||
{
|
||||
_disabledStyle = value;
|
||||
SetStyle(!_isEnabled ? _disabledStyle : null);
|
||||
}
|
||||
}
|
||||
|
||||
public GuiControlStyle HoverStyle { get; set; }
|
||||
|
||||
public virtual void MouseMoved(MouseEventArgs args)
|
||||
{
|
||||
if(IsEnabled)
|
||||
SetStyle(BoundingRectangle.Contains(args.Position) ? HoverStyle : null);
|
||||
}
|
||||
|
||||
private GuiControlStyle _currentStyle;
|
||||
|
||||
protected void SetStyle(GuiControlStyle style)
|
||||
{
|
||||
if (_currentStyle != style)
|
||||
{
|
||||
_currentStyle?.Revert(this);
|
||||
_currentStyle = style;
|
||||
_currentStyle?.Apply(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using MonoGame.Extended.Gui.Controls;
|
||||
|
||||
namespace MonoGame.Extended.Gui
|
||||
{
|
||||
public class GuiScreen
|
||||
{
|
||||
public GuiScreen()
|
||||
{
|
||||
Controls = new GuiControlCollection();
|
||||
}
|
||||
|
||||
public GuiControlCollection Controls { get; }
|
||||
}
|
||||
}
|
||||
@@ -9,22 +9,20 @@ namespace MonoGame.Extended.Gui
|
||||
{
|
||||
public class GuiSpriteBatchRenderer
|
||||
{
|
||||
private readonly GuiControlCollection _controls;
|
||||
private readonly BitmapFont _defaultFont;
|
||||
private readonly SpriteBatch _spriteBatch;
|
||||
|
||||
public GuiSpriteBatchRenderer(GuiControlCollection controls, GraphicsDevice graphicsDevice, BitmapFont defaultFont)
|
||||
public GuiSpriteBatchRenderer(GraphicsDevice graphicsDevice, BitmapFont defaultFont)
|
||||
{
|
||||
_controls = controls;
|
||||
_defaultFont = defaultFont;
|
||||
_spriteBatch = new SpriteBatch(graphicsDevice);
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
public void Draw(GuiScreen screen)
|
||||
{
|
||||
_spriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend);
|
||||
|
||||
DrawChildren(_controls, Vector2.Zero);
|
||||
DrawChildren(screen.Controls, Vector2.Zero);
|
||||
|
||||
_spriteBatch.End();
|
||||
}
|
||||
@@ -49,9 +47,7 @@ namespace MonoGame.Extended.Gui
|
||||
_spriteBatch.Draw(control.BackgroundRegion, destinationRectangle, control.BackgroundColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
_spriteBatch.FillRectangle(location, size, control.BackgroundColor);
|
||||
}
|
||||
|
||||
if (_defaultFont != null && !string.IsNullOrWhiteSpace(control.Text))
|
||||
{
|
||||
|
||||
@@ -1,44 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MonoGame.Extended.Gui.Controls;
|
||||
|
||||
namespace MonoGame.Extended.Gui.Keepers
|
||||
{
|
||||
//public class GuiControlStyle
|
||||
//{
|
||||
// private Dictionary<string, object> _previousState;
|
||||
public class GuiControlStyle
|
||||
{
|
||||
private Dictionary<string, object> _previousState;
|
||||
|
||||
// public GuiControlStyle(Type targetType)
|
||||
// {
|
||||
// TargetType = targetType;
|
||||
// Setters = new Dictionary<string, object>();
|
||||
// }
|
||||
public GuiControlStyle(Type targetType)
|
||||
{
|
||||
TargetType = targetType;
|
||||
Setters = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
// public Type TargetType { get; }
|
||||
// public Dictionary<string, object> Setters { get; set; }
|
||||
public Type TargetType { get; }
|
||||
public Dictionary<string, object> Setters { get; set; }
|
||||
|
||||
// public void Apply(GuiControl control)
|
||||
// {
|
||||
// _previousState = Setters
|
||||
// .ToDictionary(i => i.Key, i => TargetType.GetRuntimeProperty(i.Key).GetValue(control));
|
||||
public void Apply(GuiControl control)
|
||||
{
|
||||
_previousState = Setters
|
||||
.ToDictionary(i => i.Key, i => TargetType.GetRuntimeProperty(i.Key).GetValue(control));
|
||||
|
||||
// ChangePropertyValues(control, Setters);
|
||||
// }
|
||||
ChangePropertyValues(control, Setters);
|
||||
}
|
||||
|
||||
// public void Revert(GuiControl control)
|
||||
// {
|
||||
// if (_previousState != null)
|
||||
// ChangePropertyValues(control, _previousState);
|
||||
public void Revert(GuiControl control)
|
||||
{
|
||||
if (_previousState != null)
|
||||
ChangePropertyValues(control, _previousState);
|
||||
|
||||
// _previousState = null;
|
||||
// }
|
||||
_previousState = null;
|
||||
}
|
||||
|
||||
// private static void ChangePropertyValues(GuiControl control, Dictionary<string, object> setters)
|
||||
// {
|
||||
// var targetType = control.GetType();
|
||||
private static void ChangePropertyValues(GuiControl control, Dictionary<string, object> setters)
|
||||
{
|
||||
var targetType = control.GetType();
|
||||
|
||||
// foreach (var propertyName in setters.Keys)
|
||||
// {
|
||||
// var propertyInfo = targetType.GetRuntimeProperty(propertyName);
|
||||
// var value = setters[propertyName];
|
||||
// propertyInfo.SetValue(control, value);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
foreach (var propertyName in setters.Keys)
|
||||
{
|
||||
var propertyInfo = targetType.GetRuntimeProperty(propertyName);
|
||||
var value = setters[propertyName];
|
||||
propertyInfo.SetValue(control, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@
|
||||
<Compile Include="Controls\GuiControl.cs" />
|
||||
<Compile Include="Controls\GuiControlCollection.cs" />
|
||||
<Compile Include="Controls\GuiPanel.cs" />
|
||||
<Compile Include="GuiScreen.cs" />
|
||||
<Compile Include="GuiSkin.cs" />
|
||||
<Compile Include="GuiSpriteBatchRenderer.cs" />
|
||||
<Compile Include="Keepers\GuiControlStyle.cs" />
|
||||
|
||||
@@ -89,6 +89,7 @@ namespace MonoGame.Extended.Tiled.Renderers
|
||||
_graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
|
||||
|
||||
foreach (var pass in _basicEffect.CurrentTechnique.Passes)
|
||||
{
|
||||
foreach (var renderDetails in _currentRenderDetails)
|
||||
{
|
||||
_graphicsDevice.SetVertexBuffer(renderDetails.VertexBuffer);
|
||||
@@ -121,6 +122,7 @@ namespace MonoGame.Extended.Tiled.Renderers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual MapRenderDetails BuildRenderDetails()
|
||||
@@ -149,31 +151,37 @@ namespace MonoGame.Extended.Tiled.Renderers
|
||||
|
||||
mapDetails.AddGroup(group);
|
||||
}
|
||||
else if (objectLayer != null)
|
||||
else
|
||||
{
|
||||
if (!_config.DrawObjectLayers)
|
||||
continue;
|
||||
if (objectLayer != null)
|
||||
{
|
||||
if (!_config.DrawObjectLayers)
|
||||
continue;
|
||||
|
||||
var groups = CreateGroupsByTileset(
|
||||
objectLayer.Objects.Reverse(),
|
||||
objectLayer,
|
||||
o => (o.ObjectType != TiledObjectType.Tile) || !o.IsVisible,
|
||||
o => (o.Position - new Vector2(0, o.Height)).ToPoint(),
|
||||
o => new SizeF(o.Width, o.Height));
|
||||
var groups = CreateGroupsByTileset(
|
||||
objectLayer.Objects.Reverse(),
|
||||
objectLayer,
|
||||
o => (o.ObjectType != TiledObjectType.Tile) || !o.IsVisible,
|
||||
o => (o.Position - new Vector2(0, o.Height)).ToPoint(),
|
||||
o => new SizeF(o.Width, o.Height));
|
||||
|
||||
foreach (var groupRenderDetails in groups)
|
||||
mapDetails.AddGroup(groupRenderDetails);
|
||||
}
|
||||
else if (tileLayer != null)
|
||||
{
|
||||
var groups = CreateGroupsByTileset(
|
||||
GetTilesGroupedByTileset(tileLayer),
|
||||
tileLayer,
|
||||
t => t.IsBlank,
|
||||
t => tileLayer.GetTileLocation(t));
|
||||
foreach (var groupRenderDetails in groups)
|
||||
mapDetails.AddGroup(groupRenderDetails);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tileLayer != null)
|
||||
{
|
||||
var groups = CreateGroupsByTileset(
|
||||
GetTilesGroupedByTileset(tileLayer),
|
||||
tileLayer,
|
||||
t => t.IsBlank,
|
||||
t => tileLayer.GetTileLocation(t));
|
||||
|
||||
foreach (var groupRenderDetails in groups)
|
||||
mapDetails.AddGroup(groupRenderDetails);
|
||||
foreach (var groupRenderDetails in groups)
|
||||
mapDetails.AddGroup(groupRenderDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,14 +123,18 @@ namespace MonoGame.Extended.Tiled
|
||||
else
|
||||
shape = new PolylineF(points);
|
||||
}
|
||||
else if (objectType == TiledObjectType.Ellipse)
|
||||
else
|
||||
{
|
||||
var center = new Vector2(x + width / 2.0f, y + height / 2.0f);
|
||||
shape = new EllipseF(center, width / 2.0f, height / 2.0f);
|
||||
}
|
||||
else if ((objectType == TiledObjectType.Rectangle) || (objectType == TiledObjectType.Tile))
|
||||
{
|
||||
shape = new RectangleF(x, y, width, height);
|
||||
if (objectType == TiledObjectType.Ellipse)
|
||||
{
|
||||
var center = new Vector2(x + width / 2.0f, y + height / 2.0f);
|
||||
shape = new EllipseF(center, width / 2.0f, height / 2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((objectType == TiledObjectType.Rectangle) || (objectType == TiledObjectType.Tile))
|
||||
shape = new RectangleF(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
objects[i] = new TiledObject(objectType, id, gid >= 0 ? gid : (int?)null, shape, x, y, tilesetTile)
|
||||
@@ -225,6 +229,7 @@ namespace MonoGame.Extended.Tiled
|
||||
input.GetData(data);
|
||||
|
||||
for (var i = 0; i < input.Width * input.Height; i++)
|
||||
{
|
||||
if ((data[i].R == color.R) && (data[i].G == color.G) && (data[i].B == color.B))
|
||||
{
|
||||
data[i].R = 0;
|
||||
@@ -232,6 +237,7 @@ namespace MonoGame.Extended.Tiled
|
||||
data[i].B = 0;
|
||||
data[i].A = 0;
|
||||
}
|
||||
}
|
||||
|
||||
var output = new Texture2D(graphicsDevice, input.Width, input.Height);
|
||||
output.SetData(data);
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace MonoGame.Extended.Tiled
|
||||
var index = 0;
|
||||
|
||||
for (var y = 0; y < Height; y++)
|
||||
{
|
||||
for (var x = 0; x < Width; x++)
|
||||
{
|
||||
var id = data[index];
|
||||
@@ -44,6 +45,7 @@ namespace MonoGame.Extended.Tiled
|
||||
tiles[x + y * Width] = new TiledTile(id, x, y, tilesetTile);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
@@ -124,29 +126,37 @@ namespace MonoGame.Extended.Tiled
|
||||
private IEnumerable<TiledTile> GetTilesRightDown(int left, int top, int right, int bottom)
|
||||
{
|
||||
for (var y = top; y < bottom; y++)
|
||||
{
|
||||
for (var x = left; x < right; x++)
|
||||
yield return GetTile(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<TiledTile> GetTilesRightUp(int left, int top, int right, int bottom)
|
||||
{
|
||||
for (var y = bottom - 1; y >= top; y--)
|
||||
{
|
||||
for (var x = left; x < right; x++)
|
||||
yield return GetTile(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<TiledTile> GetTilesLeftDown(int left, int top, int right, int bottom)
|
||||
{
|
||||
for (var y = top; y < bottom; y++)
|
||||
{
|
||||
for (var x = right - 1; x >= left; x--)
|
||||
yield return GetTile(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<TiledTile> GetTilesLeftUp(int left, int top, int right, int bottom)
|
||||
{
|
||||
for (var y = bottom - 1; y >= top; y--)
|
||||
{
|
||||
for (var x = right - 1; x >= left; x--)
|
||||
yield return GetTile(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,11 +37,13 @@ namespace MonoGame.Extended.Tiled
|
||||
_regions = new Dictionary<int, TextureRegion2D>();
|
||||
|
||||
for (var y = Margin; y < texture.Height - Margin; y += TileHeight + Spacing)
|
||||
{
|
||||
for (var x = Margin; x < texture.Width - Margin; x += TileWidth + Spacing)
|
||||
{
|
||||
_regions.Add(id, new TextureRegion2D(Texture, x, y, TileWidth, TileHeight));
|
||||
id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextureRegion2D GetTileRegion(int id)
|
||||
|
||||
@@ -83,15 +83,15 @@ namespace MonoGame.Extended.Animations.SpriteSheets
|
||||
}
|
||||
|
||||
if (IsLooping)
|
||||
{
|
||||
if (IsReversed)
|
||||
{
|
||||
frameIndex = frameIndex%length;
|
||||
frameIndex = length - frameIndex - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
frameIndex = frameIndex%length;
|
||||
}
|
||||
}
|
||||
else
|
||||
frameIndex = IsReversed ? Math.Max(length - frameIndex - 1, 0) : Math.Min(length - 1, frameIndex);
|
||||
|
||||
|
||||
@@ -116,10 +116,13 @@ namespace MonoGame.Extended
|
||||
{
|
||||
if (value < MinimumZoom)
|
||||
Zoom = MinimumZoom;
|
||||
else if (value > MaximumZoom)
|
||||
Zoom = MaximumZoom;
|
||||
else
|
||||
Zoom = value;
|
||||
{
|
||||
if (value > MaximumZoom)
|
||||
Zoom = MaximumZoom;
|
||||
else
|
||||
Zoom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void LookAt(Vector2 position)
|
||||
|
||||
@@ -77,9 +77,7 @@ namespace MonoGame.Extended.Collections
|
||||
var count = array.Length;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
_items = _emptyArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
_items = new T[count];
|
||||
@@ -196,16 +194,20 @@ namespace MonoGame.Extended.Collections
|
||||
{
|
||||
var arrayIndex = GetArrayIndex(index);
|
||||
if (arrayIndex == -1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index),
|
||||
"Index was out of range. Must be non-negative and less than the size of the collection.");
|
||||
}
|
||||
return _items[arrayIndex];
|
||||
}
|
||||
set
|
||||
{
|
||||
var arrayIndex = GetArrayIndex(index);
|
||||
if (arrayIndex == -1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index),
|
||||
"Index was out of range. Must be non-negative and less than the size of the collection.");
|
||||
}
|
||||
_items[arrayIndex] = value;
|
||||
}
|
||||
}
|
||||
@@ -281,9 +283,7 @@ namespace MonoGame.Extended.Collections
|
||||
|
||||
int index;
|
||||
if (Count <= _items.Length - _frontArrayIndex)
|
||||
{
|
||||
index = Array.IndexOf(_items, item, _frontArrayIndex, Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = Array.IndexOf(_items, item, _frontArrayIndex, _items.Length - _frontArrayIndex);
|
||||
@@ -348,40 +348,46 @@ namespace MonoGame.Extended.Collections
|
||||
{
|
||||
RemoveFromFront();
|
||||
}
|
||||
else if (index == Count - 1)
|
||||
{
|
||||
RemoveFromBack();
|
||||
}
|
||||
else if (index < Count/2)
|
||||
{
|
||||
var arrayIndex = GetArrayIndex(index);
|
||||
// shift the array from 0 to before the index to remove by 1 to the right
|
||||
// the element to remove is replaced by the copy
|
||||
Array.Copy(_items, 0, _items, 1, arrayIndex);
|
||||
// the first element in the arrya is now either a duplicate or it's default value
|
||||
// to be safe set it to it's default value regardless of circumstance
|
||||
_items[0] = default(T);
|
||||
// if we shifted the front element, adjust the front index
|
||||
if (_frontArrayIndex < arrayIndex)
|
||||
_frontArrayIndex = (_frontArrayIndex + 1)%_items.Length;
|
||||
// decrement the count so the back index is calculated correctly
|
||||
Count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
var arrayIndex = GetArrayIndex(index);
|
||||
// shift the array from the center of the array to before the index to remove by 1 to the right
|
||||
// the element to remove is replaced by the copy
|
||||
var arrayCenterIndex = _items.Length/2;
|
||||
Array.Copy(_items, arrayCenterIndex, _items, arrayCenterIndex + 1, _items.Length - 1 - arrayIndex);
|
||||
// the last element in the array is now either a duplicate or it's default value
|
||||
// to be safe set it to it's default value regardless of circumstance
|
||||
_items[_items.Length - 1] = default(T);
|
||||
// if we shifted the front element, adjust the front index
|
||||
if (_frontArrayIndex < arrayIndex)
|
||||
_frontArrayIndex = (_frontArrayIndex + 1)%_items.Length;
|
||||
// decrement the count so the back index is calculated correctly
|
||||
Count--;
|
||||
if (index == Count - 1)
|
||||
{
|
||||
RemoveFromBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index < Count/2)
|
||||
{
|
||||
var arrayIndex = GetArrayIndex(index);
|
||||
// shift the array from 0 to before the index to remove by 1 to the right
|
||||
// the element to remove is replaced by the copy
|
||||
Array.Copy(_items, 0, _items, 1, arrayIndex);
|
||||
// the first element in the arrya is now either a duplicate or it's default value
|
||||
// to be safe set it to it's default value regardless of circumstance
|
||||
_items[0] = default(T);
|
||||
// if we shifted the front element, adjust the front index
|
||||
if (_frontArrayIndex < arrayIndex)
|
||||
_frontArrayIndex = (_frontArrayIndex + 1)%_items.Length;
|
||||
// decrement the count so the back index is calculated correctly
|
||||
Count--;
|
||||
}
|
||||
else
|
||||
{
|
||||
var arrayIndex = GetArrayIndex(index);
|
||||
// shift the array from the center of the array to before the index to remove by 1 to the right
|
||||
// the element to remove is replaced by the copy
|
||||
var arrayCenterIndex = _items.Length/2;
|
||||
Array.Copy(_items, arrayCenterIndex, _items, arrayCenterIndex + 1, _items.Length - 1 - arrayIndex);
|
||||
// the last element in the array is now either a duplicate or it's default value
|
||||
// to be safe set it to it's default value regardless of circumstance
|
||||
_items[_items.Length - 1] = default(T);
|
||||
// if we shifted the front element, adjust the front index
|
||||
if (_frontArrayIndex < arrayIndex)
|
||||
_frontArrayIndex = (_frontArrayIndex + 1)%_items.Length;
|
||||
// decrement the count so the back index is calculated correctly
|
||||
Count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,9 +420,7 @@ namespace MonoGame.Extended.Collections
|
||||
Array.Clear(_items, 0, _frontArrayIndex + Count - _items.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Clear(_items, _frontArrayIndex, Count);
|
||||
}
|
||||
Count = 0;
|
||||
_frontArrayIndex = 0;
|
||||
}
|
||||
@@ -477,8 +481,10 @@ namespace MonoGame.Extended.Collections
|
||||
throw new ArgumentOutOfRangeException(nameof(arrayIndex), "Index was less than the array's lower bound.");
|
||||
|
||||
if (arrayIndex >= array.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(arrayIndex),
|
||||
"Index was greater than the array's upper bound.");
|
||||
}
|
||||
|
||||
if (array.Length - arrayIndex < Count)
|
||||
throw new ArgumentException("Destination array was not long enough.");
|
||||
@@ -491,9 +497,7 @@ namespace MonoGame.Extended.Collections
|
||||
{
|
||||
var loopsAround = Count > _items.Length - _frontArrayIndex;
|
||||
if (!loopsAround)
|
||||
{
|
||||
Array.Copy(_items, _frontArrayIndex, array, arrayIndex, Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(_items, _frontArrayIndex, array, arrayIndex, Capacity - _frontArrayIndex);
|
||||
|
||||
@@ -13,9 +13,7 @@ namespace MonoGame.Extended
|
||||
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
if (hsl.Y == 0.0f)
|
||||
{
|
||||
color.X = color.Y = color.Z = hsl.Z;
|
||||
}
|
||||
else
|
||||
{
|
||||
var q = hsl.Z < 0.5f ? hsl.Z*(1.0f + hsl.Y) : hsl.Z + hsl.Y - hsl.Z*hsl.Y;
|
||||
|
||||
@@ -16,10 +16,12 @@ namespace MonoGame.Extended.Content
|
||||
var newPathNodes = new List<string>();
|
||||
|
||||
foreach (var relativeNode in relativeNodes)
|
||||
{
|
||||
if (relativeNode == "..")
|
||||
relativeIndex--;
|
||||
else
|
||||
newPathNodes.Add(relativeNode);
|
||||
}
|
||||
|
||||
var values = assetNodes
|
||||
.Take(relativeIndex)
|
||||
|
||||
@@ -265,17 +265,23 @@ namespace MonoGame.Extended.InputListeners
|
||||
|
||||
if (leftStrength > 0)
|
||||
_vibrationDurationLeft = new TimeSpan(0, 0, 0, 0, durationMs);
|
||||
else if (lstrength > 0)
|
||||
_vibrationDurationLeft -= _gameTime.TotalGameTime - _vibrationStart;
|
||||
else
|
||||
_leftVibrating = false;
|
||||
{
|
||||
if (lstrength > 0)
|
||||
_vibrationDurationLeft -= _gameTime.TotalGameTime - _vibrationStart;
|
||||
else
|
||||
_leftVibrating = false;
|
||||
}
|
||||
|
||||
if (rightStrength > 0)
|
||||
_vibrationDurationRight = new TimeSpan(0, 0, 0, 0, durationMs);
|
||||
else if (rstrength > 0)
|
||||
_vibrationDurationRight -= _gameTime.TotalGameTime - _vibrationStart;
|
||||
else
|
||||
_rightVibrating = false;
|
||||
{
|
||||
if (rstrength > 0)
|
||||
_vibrationDurationRight -= _gameTime.TotalGameTime - _vibrationStart;
|
||||
else
|
||||
_rightVibrating = false;
|
||||
}
|
||||
|
||||
_vibrationStart = _gameTime.TotalGameTime;
|
||||
|
||||
@@ -325,13 +331,16 @@ namespace MonoGame.Extended.InputListeners
|
||||
else
|
||||
_leftTriggerDown = true;
|
||||
}
|
||||
else if (prevdown && (curstate < debounce))
|
||||
else
|
||||
{
|
||||
RaiseButtonUp(button);
|
||||
if (button == Buttons.RightTrigger)
|
||||
_rightTriggerDown = false;
|
||||
else
|
||||
_leftTriggerDown = false;
|
||||
if (prevdown && (curstate < debounce))
|
||||
{
|
||||
RaiseButtonUp(button);
|
||||
if (button == Buttons.RightTrigger)
|
||||
_rightTriggerDown = false;
|
||||
else
|
||||
_leftTriggerDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
var prevstate = getButtonState(_lastTriggerState);
|
||||
@@ -343,10 +352,13 @@ namespace MonoGame.Extended.InputListeners
|
||||
_lastTriggerState = _currentState;
|
||||
}
|
||||
}
|
||||
else if (prevstate > TriggerDeltaTreshold)
|
||||
else
|
||||
{
|
||||
TriggerMoved?.Invoke(this, MakeArgs(button, curstate));
|
||||
_lastTriggerState = _currentState;
|
||||
if (prevstate > TriggerDeltaTreshold)
|
||||
{
|
||||
TriggerMoved?.Invoke(this, MakeArgs(button, curstate));
|
||||
_lastTriggerState = _currentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,22 +400,28 @@ namespace MonoGame.Extended.InputListeners
|
||||
else
|
||||
_leftStickDown = true;
|
||||
}
|
||||
else if (prevdown && (curVector.Length() < debounce))
|
||||
else
|
||||
{
|
||||
RaiseButtonUp(prevdir);
|
||||
if (button == Buttons.RightStick)
|
||||
_rightStickDown = false;
|
||||
if (prevdown && (curVector.Length() < debounce))
|
||||
{
|
||||
RaiseButtonUp(prevdir);
|
||||
if (button == Buttons.RightStick)
|
||||
_rightStickDown = false;
|
||||
else
|
||||
_leftStickDown = false;
|
||||
}
|
||||
else
|
||||
_leftStickDown = false;
|
||||
}
|
||||
else if (prevdown && curdown && (curdir != prevdir))
|
||||
{
|
||||
RaiseButtonUp(prevdir);
|
||||
if (right)
|
||||
_lastRightStickDirection = curdir;
|
||||
else
|
||||
_lastLeftStickDirection = curdir;
|
||||
RaiseButtonDown(curdir);
|
||||
{
|
||||
if (prevdown && curdown && (curdir != prevdir))
|
||||
{
|
||||
RaiseButtonUp(prevdir);
|
||||
if (right)
|
||||
_lastRightStickDirection = curdir;
|
||||
else
|
||||
_lastLeftStickDirection = curdir;
|
||||
RaiseButtonDown(curdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var prevVector = getButtonState(_lastThumbStickState);
|
||||
@@ -415,10 +433,13 @@ namespace MonoGame.Extended.InputListeners
|
||||
_lastThumbStickState = _currentState;
|
||||
}
|
||||
}
|
||||
else if (prevVector.Length() > ThumbStickDeltaTreshold)
|
||||
else
|
||||
{
|
||||
ThumbStickMoved?.Invoke(this, MakeArgs(button, thumbStickState: curVector));
|
||||
_lastThumbStickState = _currentState;
|
||||
if (prevVector.Length() > ThumbStickDeltaTreshold)
|
||||
{
|
||||
ThumbStickMoved?.Invoke(this, MakeArgs(button, thumbStickState: curVector));
|
||||
_lastThumbStickState = _currentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,6 +449,7 @@ namespace MonoGame.Extended.InputListeners
|
||||
return;
|
||||
|
||||
foreach (PlayerIndex index in Enum.GetValues(typeof(PlayerIndex)))
|
||||
{
|
||||
if (GamePad.GetState(index).IsConnected ^ _gamePadConnections[(int) index])
|
||||
// We need more XORs in this world
|
||||
{
|
||||
@@ -435,6 +457,7 @@ namespace MonoGame.Extended.InputListeners
|
||||
ControllerConnectionChanged?.Invoke(null,
|
||||
new GamePadEventArgs(GamePadState.Default, GamePad.GetState(index), TimeSpan.Zero, index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckVibrate()
|
||||
@@ -493,10 +516,13 @@ namespace MonoGame.Extended.InputListeners
|
||||
ButtonRepeated?.Invoke(this, MakeArgs(_lastButton));
|
||||
_repeatedButtonTimer = RepeatDelay + RepeatInitialDelay;
|
||||
}
|
||||
else if (_repeatedButtonTimer > RepeatInitialDelay + RepeatDelay*2)
|
||||
else
|
||||
{
|
||||
ButtonRepeated?.Invoke(this, MakeArgs(_lastButton));
|
||||
_repeatedButtonTimer = RepeatDelay + RepeatInitialDelay;
|
||||
if (_repeatedButtonTimer > RepeatInitialDelay + RepeatDelay*2)
|
||||
{
|
||||
ButtonRepeated?.Invoke(this, MakeArgs(_lastButton));
|
||||
_repeatedButtonTimer = RepeatDelay + RepeatInitialDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,10 +130,9 @@ namespace MonoGame.Extended.InputListeners
|
||||
button);
|
||||
|
||||
if (_mouseDownArgs.Button == args.Button)
|
||||
{
|
||||
if (_dragging)
|
||||
{
|
||||
MouseDrag?.Invoke(this, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only start to drag based on DragThreshold
|
||||
@@ -145,6 +144,7 @@ namespace MonoGame.Extended.InputListeners
|
||||
MouseDragStart?.Invoke(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +180,10 @@ namespace MonoGame.Extended.InputListeners
|
||||
|
||||
// Handle mouse wheel events.
|
||||
if (_previousState.ScrollWheelValue != _currentState.ScrollWheelValue)
|
||||
{
|
||||
MouseWheelMoved?.Invoke(this,
|
||||
new MouseEventArgs(ViewportAdapter, gameTime.TotalGameTime, _previousState, _currentState));
|
||||
}
|
||||
|
||||
_previousState = _currentState;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace MonoGame.Extended.InputListeners
|
||||
var touchCollection = TouchPanel.GetState();
|
||||
|
||||
foreach (var touchLocation in touchCollection)
|
||||
{
|
||||
switch (touchLocation.State)
|
||||
{
|
||||
case TouchLocationState.Pressed:
|
||||
@@ -41,6 +42,7 @@ namespace MonoGame.Extended.InputListeners
|
||||
TouchCancelled?.Invoke(this, new TouchEventArgs(touchLocation));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,6 +250,7 @@ namespace MonoGame.Extended.NuclexGui.Controls.Desktop
|
||||
protected override void OnMousePressed(MouseButton button)
|
||||
{
|
||||
if (button == MouseButton.Left)
|
||||
{
|
||||
if (OpeningLocator != null)
|
||||
{
|
||||
var absoluteBounds = GetAbsoluteBounds();
|
||||
@@ -261,6 +262,7 @@ namespace MonoGame.Extended.NuclexGui.Controls.Desktop
|
||||
// Nope, our renderer is being secretive
|
||||
MoveCaretToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Handles user text input by a physical keyboard</summary>
|
||||
|
||||
@@ -116,8 +116,10 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// Look for name collisions with our siblings
|
||||
var parent = Parent;
|
||||
if (parent != null)
|
||||
{
|
||||
if (parent._children.IsNameTaken(value))
|
||||
throw new InvalidOperationException("Another control is already using this name");
|
||||
}
|
||||
|
||||
// Everything seems to be ok, accept the new name
|
||||
_name = value;
|
||||
@@ -169,9 +171,11 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// control not living in any GUI hierarchy and thus, does not have
|
||||
// absolute bounds yet.
|
||||
if (ReferenceEquals(_screen, null))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Obtaining absolute bounds requires the control to be part of a screen"
|
||||
);
|
||||
}
|
||||
|
||||
// Transform the unified coordinate bounds into absolute pixel coordinates
|
||||
// for the screen's dimensions
|
||||
|
||||
@@ -167,8 +167,10 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// If we're a control that can appear on top of or below our siblings in
|
||||
// the z order, bring us into foreground since the user just clicked on us.
|
||||
if (_activatedControl != this)
|
||||
{
|
||||
if (_activatedControl._affectsOrdering)
|
||||
_children.MoveToStart(_children.IndexOf(_activatedControl));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the buttons to the list of mouse buttons being held down. This is used
|
||||
@@ -313,20 +315,24 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// messages. This enables some exotic uses for the mouse wheel, such as holding
|
||||
// an object with the mouse button and scaling it with the wheel at the same time.
|
||||
if (_activatedControl != null)
|
||||
{
|
||||
if (_activatedControl != this)
|
||||
{
|
||||
_activatedControl.ProcessMouseWheel(ticks);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If the mouse wheel has been used normally, send the wheel notifications to
|
||||
// the control the mouse is over.
|
||||
if (_mouseOverControl != null)
|
||||
{
|
||||
if (_mouseOverControl != this)
|
||||
{
|
||||
_mouseOverControl.ProcessMouseWheel(ticks);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We're the control the mouse is over, let the user code handle
|
||||
// the mouse wheel rotation
|
||||
@@ -380,10 +386,12 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// ensures that key presses will not be delivered to windows sitting behind
|
||||
// another window. Other siblings that are not windows are asked still.
|
||||
if (child._affectsOrdering)
|
||||
{
|
||||
if (encounteredOrderingControl)
|
||||
continue;
|
||||
else
|
||||
encounteredOrderingControl = true;
|
||||
}
|
||||
|
||||
// Does this child feel responsible for the key press?
|
||||
if (child.ProcessKeyPress(keyCode, repetition))
|
||||
|
||||
@@ -93,8 +93,10 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
protected override void OnMousePressed(MouseButton button)
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
if (button == MouseButton.Left)
|
||||
_pressedDownByMouse = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Called when a mouse button has been released again</summary>
|
||||
@@ -109,8 +111,10 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// The user can move the mouse cursor away from the control while still holding
|
||||
// the mouse button down to do the well-known last-second-abort.
|
||||
if (_mouseHovering && Enabled)
|
||||
{
|
||||
if (!Depressed)
|
||||
OnPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,11 +126,13 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
protected override bool OnButtonPressed(Buttons button)
|
||||
{
|
||||
if (ShortcutButton.HasValue)
|
||||
{
|
||||
if (button == ShortcutButton.Value)
|
||||
{
|
||||
_pressedDownByGamepadShortcut = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -136,13 +142,17 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
protected override void OnButtonReleased(Buttons button)
|
||||
{
|
||||
if (ShortcutButton.HasValue)
|
||||
{
|
||||
if (_pressedDownByGamepadShortcut)
|
||||
{
|
||||
if (button == ShortcutButton.Value)
|
||||
{
|
||||
_pressedDownByGamepadShortcut = false;
|
||||
if (!Depressed)
|
||||
OnPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Called when a key on the keyboard has been pressed down</summary>
|
||||
@@ -153,17 +163,21 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
protected override bool OnKeyPressed(Keys keyCode)
|
||||
{
|
||||
if (ShortcutButton.HasValue)
|
||||
{
|
||||
if (keyCode == KeyFromButton(ShortcutButton.Value))
|
||||
{
|
||||
_pressedDownByKeyboardShortcut = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (HasFocus)
|
||||
{
|
||||
if (keyCode == Keys.Space)
|
||||
{
|
||||
_pressedDownByKeyboard = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -173,20 +187,26 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
protected override void OnKeyReleased(Keys keyCode)
|
||||
{
|
||||
if (_pressedDownByKeyboardShortcut)
|
||||
{
|
||||
if (ShortcutButton.HasValue)
|
||||
{
|
||||
if (keyCode == KeyFromButton(ShortcutButton.Value))
|
||||
{
|
||||
_pressedDownByKeyboardShortcut = false;
|
||||
if (!Depressed)
|
||||
OnPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_pressedDownByKeyboard)
|
||||
{
|
||||
if (keyCode == Keys.Space)
|
||||
{
|
||||
_pressedDownByKeyboard = false;
|
||||
if (!Depressed)
|
||||
OnPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Called when the control is pressed</summary>
|
||||
|
||||
@@ -103,8 +103,10 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// that this operation usually only happens once, there's no point in adding
|
||||
// the overhead of managing a synchronized look-up dictionary here.
|
||||
for (var index = 0; index < Count; ++index)
|
||||
{
|
||||
if (base[index].Name == name)
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we reach this point, no control is using the specified name.
|
||||
return false;
|
||||
@@ -167,8 +169,10 @@ namespace MonoGame.Extended.NuclexGui.Controls
|
||||
// We also do not allow a child control to have the same id as an existing
|
||||
// control (with the exception of an empty name)
|
||||
if (IsNameTaken(proposedChild.Name))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"The name of the added control has already been taken by another child");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,8 +200,10 @@ namespace MonoGame.Extended.NuclexGui
|
||||
public void Draw(GameTime gameTime)
|
||||
{
|
||||
if (_guiVisualizer != null)
|
||||
{
|
||||
if (_screen != null)
|
||||
_guiVisualizer.Draw(_screen);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Handles second-stage initialization of the GUI manager</summary>
|
||||
@@ -349,6 +351,7 @@ namespace MonoGame.Extended.NuclexGui
|
||||
var inputService = (IGuiInputService) serviceProvider.GetService(typeof(IGuiInputService));
|
||||
|
||||
if (inputService == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Using the GUI with the default input capturer requires the IInputService. " +
|
||||
"Please either add the IInputService to Game.Services by using the " +
|
||||
@@ -356,6 +359,7 @@ namespace MonoGame.Extended.NuclexGui
|
||||
"implementation for the GUI and assign it before GuiManager.Initialize() " +
|
||||
"is called."
|
||||
);
|
||||
}
|
||||
|
||||
return inputService;
|
||||
}
|
||||
@@ -371,6 +375,7 @@ namespace MonoGame.Extended.NuclexGui
|
||||
(IGraphicsDeviceService) serviceProvider.GetService(typeof(IGraphicsDeviceService));
|
||||
|
||||
if (graphicsDeviceService == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Using the GUI with the default visualizer requires the IGraphicsDeviceService. " +
|
||||
"Please either add an IGraphicsDeviceService to Game.Services by using " +
|
||||
@@ -378,6 +383,7 @@ namespace MonoGame.Extended.NuclexGui
|
||||
"IGuiVisualizer implementation for the GUI and assign it before " +
|
||||
"GuiManager.Initialize() is called."
|
||||
);
|
||||
}
|
||||
|
||||
return graphicsDeviceService;
|
||||
}
|
||||
|
||||
@@ -278,6 +278,7 @@ namespace MonoGame.Extended.NuclexGui
|
||||
// the entire tree for a responder.
|
||||
var focusedControl = _focusedControl.Target;
|
||||
if (focusedControl != null)
|
||||
{
|
||||
if (focusedControl.ProcessKeyPress(keyCode, false))
|
||||
{
|
||||
_activatedControl = focusedControl;
|
||||
@@ -288,6 +289,7 @@ namespace MonoGame.Extended.NuclexGui
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Focused control didn't process the notification, now let the desktop
|
||||
// control traverse the entire control tree is earch for a handler.
|
||||
@@ -387,11 +389,13 @@ namespace MonoGame.Extended.NuclexGui
|
||||
// the entire tree for a responder.
|
||||
var focusedControl = _focusedControl.Target;
|
||||
if (focusedControl != null)
|
||||
{
|
||||
if (focusedControl.ProcessButtonPress(button))
|
||||
{
|
||||
_activatedControl = focusedControl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Focused control didn't process the notification, now let the desktop
|
||||
// control traverse the entire control tree is earch for a handler.
|
||||
@@ -539,11 +543,14 @@ namespace MonoGame.Extended.NuclexGui
|
||||
if (distanceX > distanceY)
|
||||
return float.NaN;
|
||||
}
|
||||
else if (leavesRight)
|
||||
else
|
||||
{
|
||||
var distanceX = Math.Abs(closestPointX - ownBounds.Right);
|
||||
if (distanceX > distanceY)
|
||||
return float.NaN;
|
||||
if (leavesRight)
|
||||
{
|
||||
var distanceX = Math.Abs(closestPointX - ownBounds.Right);
|
||||
if (distanceX > distanceY)
|
||||
return float.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -583,11 +590,14 @@ namespace MonoGame.Extended.NuclexGui
|
||||
if (distanceY > distanceX)
|
||||
return float.NaN;
|
||||
}
|
||||
else if (leavesBottom)
|
||||
else
|
||||
{
|
||||
var distanceY = Math.Abs(closestPointY - ownBounds.Bottom);
|
||||
if (distanceY > distanceX)
|
||||
return float.NaN;
|
||||
if (leavesBottom)
|
||||
{
|
||||
var distanceY = Math.Abs(closestPointY - ownBounds.Bottom);
|
||||
if (distanceY > distanceX)
|
||||
return float.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,11 +82,13 @@ namespace MonoGame.Extended.NuclexGui.Input
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_inputService != null)
|
||||
{
|
||||
UnsubscribeInputDevices();
|
||||
_inputService = null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
|
||||
// TODO: set large fields to null.
|
||||
@@ -164,14 +166,23 @@ namespace MonoGame.Extended.NuclexGui.Input
|
||||
{
|
||||
if ((e.Button & Buttons.DPadUp) != 0)
|
||||
_inputReceiver.InjectCommand(Command.Up);
|
||||
else if ((e.Button & Buttons.DPadDown) != 0)
|
||||
_inputReceiver.InjectCommand(Command.Down);
|
||||
else if ((e.Button & Buttons.DPadLeft) != 0)
|
||||
_inputReceiver.InjectCommand(Command.Left);
|
||||
else if ((e.Button & Buttons.DPadRight) != 0)
|
||||
_inputReceiver.InjectCommand(Command.Right);
|
||||
else
|
||||
_inputReceiver.InjectButtonPress(e.Button);
|
||||
{
|
||||
if ((e.Button & Buttons.DPadDown) != 0)
|
||||
_inputReceiver.InjectCommand(Command.Down);
|
||||
else
|
||||
{
|
||||
if ((e.Button & Buttons.DPadLeft) != 0)
|
||||
_inputReceiver.InjectCommand(Command.Left);
|
||||
else
|
||||
{
|
||||
if ((e.Button & Buttons.DPadRight) != 0)
|
||||
_inputReceiver.InjectCommand(Command.Right);
|
||||
else
|
||||
_inputReceiver.InjectButtonPress(e.Button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _gamePadListener_ButtonUp(object sender, GamePadEventArgs e)
|
||||
@@ -189,6 +200,7 @@ namespace MonoGame.Extended.NuclexGui.Input
|
||||
var inputService = (IGuiInputService) serviceProvider.GetService(typeof(IGuiInputService));
|
||||
|
||||
if (inputService == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Using the GUI with the DefaultInputCapturer requires the IInputService. " +
|
||||
"Please either add the IInputService to Game.Services by using the " +
|
||||
@@ -196,6 +208,7 @@ namespace MonoGame.Extended.NuclexGui.Input
|
||||
"implementation for the GUI and assign it before GuiManager.Initialize() " +
|
||||
"is called."
|
||||
);
|
||||
}
|
||||
|
||||
return inputService;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ namespace MonoGame.Extended.NuclexGui.Support
|
||||
// value which might actually appear in the enumeration.
|
||||
var highestValue = values[0];
|
||||
for (var index = 1; index < values.Length; ++index)
|
||||
{
|
||||
if (values[index].CompareTo(highestValue) > 0)
|
||||
highestValue = values[index];
|
||||
}
|
||||
|
||||
return highestValue;
|
||||
}
|
||||
@@ -47,8 +49,10 @@ namespace MonoGame.Extended.NuclexGui.Support
|
||||
// value which might actually appear in the enumeration.
|
||||
var lowestValue = values[0];
|
||||
for (var index = 1; index < values.Length; ++index)
|
||||
{
|
||||
if (values[index].CompareTo(lowestValue) < 0)
|
||||
lowestValue = values[index];
|
||||
}
|
||||
|
||||
return lowestValue;
|
||||
}
|
||||
|
||||
@@ -90,8 +90,10 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat
|
||||
|
||||
// Draw the text in all anchor locations defined by the skin
|
||||
for (var index = 0; index < frame.Texts.Length; ++index)
|
||||
{
|
||||
_spriteBatch.DrawString(frame.Texts[index].Font, text,
|
||||
PositionText(ref frame.Texts[index], bounds, text), frame.Texts[index].Color);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawImage(RectangleF bounds, Texture2D texture, Rectangle sourceRectangle)
|
||||
|
||||
@@ -63,13 +63,19 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat
|
||||
|
||||
if (hPlacement == "left")
|
||||
_leftBorderWidth = Math.Max(_leftBorderWidth, token.Value<int>("w"));
|
||||
else if (hPlacement == "right")
|
||||
_rightBorderWidth = Math.Max(_rightBorderWidth, token.Value<int>("w"));
|
||||
else
|
||||
{
|
||||
if (hPlacement == "right")
|
||||
_rightBorderWidth = Math.Max(_rightBorderWidth, token.Value<int>("w"));
|
||||
}
|
||||
|
||||
if (vPlacement == "top")
|
||||
_topBorderWidth = Math.Max(_topBorderWidth, token.Value<int>("h"));
|
||||
else if (vPlacement == "bottom")
|
||||
_bottomBorderWidth = Math.Max(_bottomBorderWidth, token.Value<int>("h"));
|
||||
else
|
||||
{
|
||||
if (vPlacement == "bottom")
|
||||
_bottomBorderWidth = Math.Max(_bottomBorderWidth, token.Value<int>("h"));
|
||||
}
|
||||
}
|
||||
|
||||
// Parse each region
|
||||
|
||||
@@ -65,9 +65,11 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat
|
||||
// Do we have only one character left to check?
|
||||
// -> Opening is either to its left or to its right.
|
||||
if (right - left <= 1)
|
||||
{
|
||||
if (x - leftX <= rightX - x)
|
||||
return left;
|
||||
else return right;
|
||||
}
|
||||
|
||||
// The position of the opening is still not absolutely clear, cut the string
|
||||
// in the middle of the search range so we can close in further.
|
||||
|
||||
+8
-3
@@ -32,11 +32,16 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers
|
||||
// Determine the style to use for the button
|
||||
var stateIndex = 0;
|
||||
if (control.Enabled)
|
||||
{
|
||||
if (control.Depressed)
|
||||
stateIndex = 3;
|
||||
else if (control.MouseHovering || control.HasFocus)
|
||||
stateIndex = 2;
|
||||
else stateIndex = 1;
|
||||
else
|
||||
{
|
||||
if (control.MouseHovering || control.HasFocus)
|
||||
stateIndex = 2;
|
||||
else stateIndex = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the button's frame
|
||||
graphics.DrawElement(_states[stateIndex], controlBounds);
|
||||
|
||||
+8
-3
@@ -34,11 +34,16 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers
|
||||
// Determine the index of the state we're going to display
|
||||
var stateIndex = control.Selected ? 4 : 0;
|
||||
if (control.Enabled)
|
||||
{
|
||||
if (control.Depressed)
|
||||
stateIndex += 3;
|
||||
else if (control.MouseHovering)
|
||||
stateIndex += 2;
|
||||
else stateIndex += 1;
|
||||
else
|
||||
{
|
||||
if (control.MouseHovering)
|
||||
stateIndex += 2;
|
||||
else stateIndex += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the pixel coordinates of the region covered by the control on
|
||||
// the screen
|
||||
|
||||
+6
-3
@@ -27,9 +27,12 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers
|
||||
|
||||
if (control.ThumbDepressed)
|
||||
graphics.DrawElement("slider.horizontal.depressed", thumbBounds);
|
||||
else if (control.MouseOverThumb)
|
||||
graphics.DrawElement("slider.horizontal.highlighted", thumbBounds);
|
||||
else graphics.DrawElement("slider.horizontal.normal", thumbBounds);
|
||||
else
|
||||
{
|
||||
if (control.MouseOverThumb)
|
||||
graphics.DrawElement("slider.horizontal.highlighted", thumbBounds);
|
||||
else graphics.DrawElement("slider.horizontal.normal", thumbBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,10 +65,14 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers
|
||||
// If the input box is in focus, also draw the caret so the user knows
|
||||
// where characters will be inserted into the text.
|
||||
if (control.HasFocus)
|
||||
{
|
||||
if (control.MillisecondsSinceLastCaretMovement%500 < 250)
|
||||
{
|
||||
graphics.DrawCaret(
|
||||
"input.normal", controlBounds, control.Text, control.CaretPosition
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Let the control know that we can provide it with additional informations
|
||||
|
||||
+8
-3
@@ -34,11 +34,16 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers
|
||||
// Determine the index of the state we're going to display
|
||||
var stateIndex = control.Selected ? 4 : 0;
|
||||
if (control.Enabled)
|
||||
{
|
||||
if (control.Depressed)
|
||||
stateIndex += 3;
|
||||
else if (control.MouseHovering)
|
||||
stateIndex += 2;
|
||||
else stateIndex += 1;
|
||||
else
|
||||
{
|
||||
if (control.MouseHovering)
|
||||
stateIndex += 2;
|
||||
else stateIndex += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the pixel coordinates of the region covered by the control on
|
||||
// the screen
|
||||
|
||||
+6
-3
@@ -30,9 +30,12 @@ namespace MonoGame.Extended.NuclexGui.Visuals.Flat.Renderers
|
||||
|
||||
if (control.ThumbDepressed)
|
||||
graphics.DrawElement("slider.vertical.depressed", thumbBounds);
|
||||
else if (control.MouseOverThumb)
|
||||
graphics.DrawElement("slider.vertical.highlighted", thumbBounds);
|
||||
else graphics.DrawElement("slider.vertical.normal", thumbBounds);
|
||||
else
|
||||
{
|
||||
if (control.MouseOverThumb)
|
||||
graphics.DrawElement("slider.vertical.highlighted", thumbBounds);
|
||||
else graphics.DrawElement("slider.vertical.normal", thumbBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,13 @@ namespace MonoGame.Extended.Particles
|
||||
|
||||
if (r == max)
|
||||
h = (60*(g - b)/chroma + 360)%360;
|
||||
else if (g == max)
|
||||
h = 60*(b - r)/chroma + 120f;
|
||||
else
|
||||
h = 60*(r - g)/chroma + 240f;
|
||||
{
|
||||
if (g == max)
|
||||
h = 60*(b - r)/chroma + 120f;
|
||||
else
|
||||
h = 60*(r - g)/chroma + 240f;
|
||||
}
|
||||
|
||||
var s = l <= 0.5f ? chroma/sum : chroma/(2f - sum);
|
||||
|
||||
|
||||
+12
-6
@@ -29,10 +29,13 @@ namespace MonoGame.Extended.Particles.Modifiers.Containers
|
||||
xPos = left + (left - xPos);
|
||||
xVel = -xVel*RestitutionCoefficient;
|
||||
}
|
||||
else if (particle->Position.X > right)
|
||||
else
|
||||
{
|
||||
xPos = right - (xPos - right);
|
||||
xVel = -xVel*RestitutionCoefficient;
|
||||
if (particle->Position.X > right)
|
||||
{
|
||||
xPos = right - (xPos - right);
|
||||
xVel = -xVel*RestitutionCoefficient;
|
||||
}
|
||||
}
|
||||
|
||||
if (particle->Position.Y < top)
|
||||
@@ -40,10 +43,13 @@ namespace MonoGame.Extended.Particles.Modifiers.Containers
|
||||
yPos = top + (top - yPos);
|
||||
yVel = -yVel*RestitutionCoefficient;
|
||||
}
|
||||
else if ((int) particle->Position.Y > bottom)
|
||||
else
|
||||
{
|
||||
yPos = bottom - (yPos - bottom);
|
||||
yVel = -yVel*RestitutionCoefficient;
|
||||
if ((int) particle->Position.Y > bottom)
|
||||
{
|
||||
yPos = bottom - (yPos - bottom);
|
||||
yVel = -yVel*RestitutionCoefficient;
|
||||
}
|
||||
}
|
||||
particle->Position = new Vector2(xPos, yPos);
|
||||
particle->Velocity = new Vector2(xVel, yVel);
|
||||
|
||||
+10
-4
@@ -22,13 +22,19 @@ namespace MonoGame.Extended.Particles.Modifiers.Containers
|
||||
|
||||
if ((int) particle->Position.X < left)
|
||||
xPos = particle->Position.X + Width;
|
||||
else if ((int) particle->Position.X > right)
|
||||
xPos = particle->Position.X - Width;
|
||||
else
|
||||
{
|
||||
if ((int) particle->Position.X > right)
|
||||
xPos = particle->Position.X - Width;
|
||||
}
|
||||
|
||||
if ((int) particle->Position.Y < top)
|
||||
yPos = particle->Position.Y + Height;
|
||||
else if ((int) particle->Position.Y > bottom)
|
||||
yPos = particle->Position.Y - Height;
|
||||
else
|
||||
{
|
||||
if ((int) particle->Position.Y > bottom)
|
||||
yPos = particle->Position.Y - Height;
|
||||
}
|
||||
particle->Position = new Vector2(xPos, yPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,7 @@ namespace MonoGame.Extended.Particles.Modifiers
|
||||
var deltaColor = VelocityColor - StationaryColor;
|
||||
|
||||
if (velocity2 >= velocityThreshold2)
|
||||
{
|
||||
VelocityColor.CopyTo(out particle->Color);
|
||||
}
|
||||
else
|
||||
{
|
||||
var t = (float) Math.Sqrt(velocity2)/VelocityThreshold;
|
||||
|
||||
@@ -13,12 +13,18 @@ namespace MonoGame.Extended.Particles.Profiles
|
||||
|
||||
if (value < Width) // Top
|
||||
offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f), Height*-0.5f);
|
||||
else if (value < 2*Width) // Bottom
|
||||
offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f), Height*0.5f);
|
||||
else if (value < 2*Width + Height) // Left
|
||||
offset = new Vector2(Width*-0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
|
||||
else // Right
|
||||
offset = new Vector2(Width*0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
|
||||
else
|
||||
{
|
||||
if (value < 2*Width) // Bottom
|
||||
offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f), Height*0.5f);
|
||||
else
|
||||
{
|
||||
if (value < 2*Width + Height) // Left
|
||||
offset = new Vector2(Width*-0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
|
||||
else // Right
|
||||
offset = new Vector2(Width*0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
Random.NextUnitVector(out heading);
|
||||
}
|
||||
|
||||
@@ -298,13 +298,19 @@ namespace MonoGame.Extended.Primitives
|
||||
// For each coordinate axis, if the point coordinate value is outside box, clamp it to the box, else keep it as is
|
||||
if (result.X < minimum.X)
|
||||
result.X = minimum.X;
|
||||
else if (result.X > maximum.X)
|
||||
result.X = maximum.X;
|
||||
else
|
||||
{
|
||||
if (result.X > maximum.X)
|
||||
result.X = maximum.X;
|
||||
}
|
||||
|
||||
if (result.Y < minimum.Y)
|
||||
result.Y = minimum.Y;
|
||||
else if (result.Y > maximum.Y)
|
||||
result.Y = maximum.Y;
|
||||
else
|
||||
{
|
||||
if (result.Y > maximum.Y)
|
||||
result.Y = maximum.Y;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -148,9 +148,7 @@ namespace MonoGame.Extended.Primitives
|
||||
// Segment intersects the 2 slabs.
|
||||
|
||||
if (minimumDistance <= 0)
|
||||
{
|
||||
intersectionPoint = Start;
|
||||
}
|
||||
else
|
||||
{
|
||||
intersectionPoint = minimumDistance*direction;
|
||||
|
||||
@@ -59,15 +59,19 @@ namespace MonoGame.Extended
|
||||
public bool IsInBetween(T value, bool minValueExclusive = false, bool maxValueExclusive = false)
|
||||
{
|
||||
if (minValueExclusive)
|
||||
{
|
||||
if (value.CompareTo(Min) <= 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.CompareTo(Min) < 0)
|
||||
return false;
|
||||
|
||||
if (maxValueExclusive)
|
||||
{
|
||||
if (value.CompareTo(Max) >= 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return value.CompareTo(Max) <= 0;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace MonoGame.Extended.SceneGraphs
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
foreach (var drawable in Entities.OfType<ISpriteBatchDrawable>())
|
||||
{
|
||||
if (drawable.IsVisible)
|
||||
{
|
||||
var texture = drawable.TextureRegion.Texture;
|
||||
@@ -75,6 +76,7 @@ namespace MonoGame.Extended.SceneGraphs
|
||||
spriteBatch.Draw(texture, position, sourceRectangle, drawable.Color, rotation, drawable.Origin,
|
||||
scale, drawable.Effect, 0);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var child in Children)
|
||||
child.Draw(spriteBatch);
|
||||
|
||||
@@ -416,9 +416,7 @@ namespace MonoGame.Extended.Shapes
|
||||
result = new RectangleF(leftSide, topSide, rightSide - leftSide, bottomSide - topSide);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new RectangleF(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -183,6 +183,7 @@ namespace MonoGame.Extended.TextureAtlases
|
||||
var yIncrement = regionHeight + spacing;
|
||||
|
||||
for (var y = margin; y < height; y += yIncrement)
|
||||
{
|
||||
for (var x = margin; x < width; x += xIncrement)
|
||||
{
|
||||
var regionName = $"{texture.Name ?? "region"}{count}";
|
||||
@@ -192,6 +193,7 @@ namespace MonoGame.Extended.TextureAtlases
|
||||
if (count >= maxRegionCount)
|
||||
return textureAtlas;
|
||||
}
|
||||
}
|
||||
|
||||
return textureAtlas;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,14 @@ namespace MonoGame.Extended.TextureAtlases
|
||||
var regionCount = reader.ReadInt32();
|
||||
|
||||
for (var i = 0; i < regionCount; i++)
|
||||
{
|
||||
atlas.CreateRegion(
|
||||
reader.ReadString(),
|
||||
reader.ReadInt32(),
|
||||
reader.ReadInt32(),
|
||||
reader.ReadInt32(),
|
||||
reader.ReadInt32());
|
||||
}
|
||||
|
||||
return atlas;
|
||||
}
|
||||
|
||||
@@ -290,9 +290,7 @@ namespace MonoGame.Extended
|
||||
Matrix2D.Multiply(ref matrix, ref localMatrix, out matrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
matrix = localMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void RecalculateLocalMatrix(out Matrix2D matrix)
|
||||
|
||||
@@ -102,10 +102,13 @@ namespace MonoGame.Extended.ViewportAdapters
|
||||
|
||||
if ((height >= viewport.Height) && (width < viewport.Width))
|
||||
BoxingMode = BoxingMode.Pillarbox;
|
||||
else if ((width >= viewport.Height) && (height < viewport.Height))
|
||||
BoxingMode = BoxingMode.Letterbox;
|
||||
else
|
||||
BoxingMode = BoxingMode.None;
|
||||
{
|
||||
if ((width >= viewport.Height) && (height < viewport.Height))
|
||||
BoxingMode = BoxingMode.Letterbox;
|
||||
else
|
||||
BoxingMode = BoxingMode.None;
|
||||
}
|
||||
|
||||
var x = viewport.Width/2 - width/2;
|
||||
var y = viewport.Height/2 - height/2;
|
||||
|
||||
Reference in New Issue
Block a user