Skip to content

Commit

Permalink
Merge pull request #7 from BeastLe9enD/master
Browse files Browse the repository at this point in the history
Update to newest version
  • Loading branch information
dovker authored Aug 14, 2022
2 parents a7abd9a + 7f4de73 commit 80faed9
Show file tree
Hide file tree
Showing 161 changed files with 348 additions and 43,897 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
obj/
.vs/
.idea/
Binary file removed MonoGame.ImGui/.DS_Store
Binary file not shown.
25 changes: 0 additions & 25 deletions MonoGame.ImGui/.vs/MonoGame.ImGui/xs/UserPrefs.xml

This file was deleted.

This file was deleted.

Empty file.
Binary file not shown.
22 changes: 10 additions & 12 deletions MonoGame.ImGui/Data/IndexData.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Microsoft.Xna.Framework.Graphics;

namespace MonoGame.ImGui.Data
{
/// <summary>
/// Contains information regarding the index buffer used by the GUIRenderer.
/// </summary>
public class IndexData
{
public byte[] Data;
public int BufferSize;
public IndexBuffer Buffer;
}
}
namespace MonoGame.ImGui.Data;

/// <summary>
/// Contains information regarding the index buffer used by the GUIRenderer.
/// </summary>
public class IndexData {
public IndexBuffer Buffer;
public int BufferSize;
public byte[] Data;
}
128 changes: 61 additions & 67 deletions MonoGame.ImGui/Data/InputData.cs
Original file line number Diff line number Diff line change
@@ -1,85 +1,79 @@
using System.Collections.Generic;
using ImGuiNET;
using ImGuiNET;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Vector2 = System.Numerics.Vector2;

namespace MonoGame.ImGui.Data
{
/// <summary>
/// Contains the GUIRenderer's input data elements.
/// </summary>
public class InputData
{
public int Scrollwheel;
public List<int> KeyMap;
namespace MonoGame.ImGui.Data;

public void Update(GraphicsDevice device)
{
var io = ImGuiNET.ImGui.GetIO();
var mouse = Mouse.GetState();
var keyboard = Keyboard.GetState();
/// <summary>
/// Contains the GUIRenderer's input data elements.
/// </summary>
public class InputData {
public List<int> KeyMap;
public int Scrollwheel;

for (int i = 0; i < KeyMap.Count; i++)
io.KeysDown[KeyMap[i]] = keyboard.IsKeyDown((Keys) KeyMap[i]);
public InputData() {
Scrollwheel = 0;
KeyMap = new List<int>();
}

public void Update(GraphicsDevice device) {
var io = ImGuiNET.ImGui.GetIO();
var mouse = Mouse.GetState();
var keyboard = Keyboard.GetState();

io.KeyShift = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift);
io.KeyCtrl = keyboard.IsKeyDown(Keys.LeftControl) || keyboard.IsKeyDown(Keys.RightControl);
io.KeyAlt = keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt);
io.KeySuper = keyboard.IsKeyDown(Keys.LeftWindows) || keyboard.IsKeyDown(Keys.RightWindows);
for (var i = 0; i < KeyMap.Count; i++)
io.KeysDown[KeyMap[i]] = keyboard.IsKeyDown((Keys) KeyMap[i]);

io.DisplaySize = new System.Numerics.Vector2(device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight);
io.DisplayFramebufferScale = new System.Numerics.Vector2(1f, 1f);
io.KeyShift = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift);
io.KeyCtrl = keyboard.IsKeyDown(Keys.LeftControl) || keyboard.IsKeyDown(Keys.RightControl);
io.KeyAlt = keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt);
io.KeySuper = keyboard.IsKeyDown(Keys.LeftWindows) || keyboard.IsKeyDown(Keys.RightWindows);

io.MousePos = new System.Numerics.Vector2(mouse.X, mouse.Y);
io.DisplaySize = new Vector2(device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight);
io.DisplayFramebufferScale = new Vector2(1f, 1f);

io.MouseDown[0] = mouse.LeftButton == ButtonState.Pressed;
io.MouseDown[1] = mouse.RightButton == ButtonState.Pressed;
io.MouseDown[2] = mouse.MiddleButton == ButtonState.Pressed;
io.MousePos = new Vector2(mouse.X, mouse.Y);

var scrollDelta = mouse.ScrollWheelValue - Scrollwheel;
io.MouseWheel = scrollDelta > 0 ? 1 : scrollDelta < 0 ? -1 : 0;
Scrollwheel = mouse.ScrollWheelValue;
}
io.MouseDown[0] = mouse.LeftButton == ButtonState.Pressed;
io.MouseDown[1] = mouse.RightButton == ButtonState.Pressed;
io.MouseDown[2] = mouse.MiddleButton == ButtonState.Pressed;

public InputData Initialize(Game game)
{
var io = ImGuiNET.ImGui.GetIO();
var scrollDelta = mouse.ScrollWheelValue - Scrollwheel;
io.MouseWheel = scrollDelta > 0 ? 1 : scrollDelta < 0 ? -1 : 0;
Scrollwheel = mouse.ScrollWheelValue;
}

KeyMap.Add(io.KeyMap[(int) ImGuiKey.Tab] = (int) Keys.Tab);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.LeftArrow] = (int) Keys.Left);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.RightArrow] = (int) Keys.Right);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.UpArrow] = (int) Keys.Up);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.DownArrow] = (int) Keys.Down);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.PageUp] = (int) Keys.PageUp);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.PageDown] = (int) Keys.PageDown);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Home] = (int) Keys.Home);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.End] = (int) Keys.End);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Delete] = (int) Keys.Delete);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Backspace] = (int) Keys.Back);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Enter] = (int) Keys.Enter);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Escape] = (int) Keys.Escape);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.A] = (int) Keys.A);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.C] = (int) Keys.C);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.V] = (int) Keys.V);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.X] = (int) Keys.X);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Y] = (int) Keys.Y);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Z] = (int) Keys.Z);
public InputData Initialize(Game game) {
var io = ImGuiNET.ImGui.GetIO();

game.Window.TextInput += (sender, args) =>
{
if (args.Character != '\t')
io.AddInputCharacter(args.Character);
};
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Tab] = (int) Keys.Tab);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.LeftArrow] = (int) Keys.Left);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.RightArrow] = (int) Keys.Right);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.UpArrow] = (int) Keys.Up);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.DownArrow] = (int) Keys.Down);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.PageUp] = (int) Keys.PageUp);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.PageDown] = (int) Keys.PageDown);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Home] = (int) Keys.Home);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.End] = (int) Keys.End);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Delete] = (int) Keys.Delete);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Backspace] = (int) Keys.Back);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Enter] = (int) Keys.Enter);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Escape] = (int) Keys.Escape);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.A] = (int) Keys.A);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.C] = (int) Keys.C);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.V] = (int) Keys.V);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.X] = (int) Keys.X);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Y] = (int) Keys.Y);
KeyMap.Add(io.KeyMap[(int) ImGuiKey.Z] = (int) Keys.Z);

io.Fonts.AddFontDefault();
return this;
}
game.Window.TextInput += (sender, args) => {
if (args.Character != '\t')
io.AddInputCharacter(args.Character);
};

public InputData()
{
Scrollwheel = 0;
KeyMap = new List<int>();
}
io.Fonts.AddFontDefault();
return this;
}
}
38 changes: 16 additions & 22 deletions MonoGame.ImGui/Data/TextureData.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Graphics;

namespace MonoGame.ImGui.Data
{
/// <summary>
/// Contains the GUIRenderer's texture data element.
/// </summary>
public class TextureData
{
public int TextureID;
public IntPtr? FontTextureID;
public Dictionary<IntPtr, Texture2D> Loaded;
namespace MonoGame.ImGui.Data;

public int GetTextureID()
{
return TextureID++;
}
/// <summary>
/// Contains the GUIRenderer's texture data element.
/// </summary>
public class TextureData {
public IntPtr? FontTextureID;
public Dictionary<IntPtr, Texture2D> Loaded;
public int TextureID;

public TextureData()
{
Loaded = new Dictionary<IntPtr, Texture2D>();
}
public TextureData() {
Loaded = new Dictionary<IntPtr, Texture2D>();
}
}

public int GetNextTextureId() {
return TextureID++;
}
}
22 changes: 10 additions & 12 deletions MonoGame.ImGui/Data/VertexData.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Microsoft.Xna.Framework.Graphics;

namespace MonoGame.ImGui.Data
{
/// <summary>
/// Contains information regarding the vertex buffer used by the GUIRenderer.
/// </summary>
public class VertexData
{
public byte[] Data;
public int BufferSize;
public VertexBuffer Buffer;
}
}
namespace MonoGame.ImGui.Data;

/// <summary>
/// Contains information regarding the vertex buffer used by the GUIRenderer.
/// </summary>
public class VertexData {
public VertexBuffer Buffer;
public int BufferSize;
public byte[] Data;
}
15 changes: 6 additions & 9 deletions MonoGame.ImGui/DrawText.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
namespace MonoGame.ImGui
{
public static class DrawText
{
public static void Perform(string text)
{
ImGuiNET.ImGui.Text(text);
}
namespace MonoGame.ImGui;

public static class DrawText {
public static void Perform(string text) {
ImGuiNET.ImGui.Text(text);
}
}
}
25 changes: 12 additions & 13 deletions MonoGame.ImGui/DrawVertDecleration.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using ImGuiNET;
using Microsoft.Xna.Framework.Graphics;

namespace MonoGame.ImGui
{
public static class DrawVertDeclaration
{
public static readonly int Size;
public static readonly VertexDeclaration Declaration;
namespace MonoGame.ImGui;

static DrawVertDeclaration()
{
unsafe { Size = sizeof(ImDrawVert); }
public static class DrawVertDeclaration {
public static readonly int Size;
public static readonly VertexDeclaration Declaration;

var position = new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0);
var uv = new VertexElement(8, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0);
var color = new VertexElement(16, VertexElementFormat.Color, VertexElementUsage.Color, 0);
Declaration = new VertexDeclaration(Size, position, uv, color);
static DrawVertDeclaration() {
unsafe {
Size = sizeof(ImDrawVert);
}

var position = new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0);
var uv = new VertexElement(8, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0);
var color = new VertexElement(16, VertexElementFormat.Color, VertexElementUsage.Color, 0);
Declaration = new VertexDeclaration(Size, position, uv, color);
}
}
25 changes: 8 additions & 17 deletions MonoGame.ImGui/Exceptions/MissingLoadedTextureKeyException.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
using System;
namespace MonoGame.ImGui.Exceptions;

namespace MonoGame.ImGui.Exceptions
{
public class MissingLoadedTextureKeyException
: InvalidOperationException
{
public override string Message
{
get { return string.Format("Could not find a texture with id {0}, please check your bindings", _texture_id); }
}
public class MissingLoadedTextureKeyException : InvalidOperationException {
private readonly IntPtr _textureId;

public MissingLoadedTextureKeyException(IntPtr texture_id)
{
_texture_id = texture_id;
}

private readonly IntPtr _texture_id;
public MissingLoadedTextureKeyException(IntPtr textureId) {
_textureId = textureId;
}
}

public override string Message => $"Could not find a texture with id {_textureId}, please check your bindings";
}
Loading

0 comments on commit 80faed9

Please sign in to comment.