Skip to content

Commit c715e23

Browse files
committed
Cleanup warnings
- Renamed namespace to match directory - Removed redundant unsafe keyword usage - removed redundant value initializations - Mark fields readonly that can be - Use C# naming conventions (e.g. `_showAnotherWindow` instead of `show_another_window`
1 parent 9654f79 commit c715e23

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

Examples/ExampleMonoGame/DrawVertDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Hexa.NET.ImGui;
22
using Microsoft.Xna.Framework.Graphics;
33

4-
namespace MonoGameExample;
4+
namespace ExampleMonoGame;
55

66
public static class DrawVertDeclaration
77
{

Examples/ExampleMonoGame/ImGuiRenderer.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
using Microsoft.Xna.Framework.Graphics;
77
using Microsoft.Xna.Framework.Input;
88

9-
namespace MonoGameExample;
9+
namespace ExampleMonoGame;
1010

1111
public class ImGuiRenderer
1212
{
1313
private const float WHEEL_DELTA = 120;
1414

15-
private Game _game;
15+
private readonly Game _game;
1616

1717
// Graphics
18-
private GraphicsDevice _graphicsDevice;
18+
private readonly GraphicsDevice _graphicsDevice;
1919
private BasicEffect _effect;
20-
private RasterizerState _rasterizerState;
20+
private readonly RasterizerState _rasterizerState;
2121

2222
private byte[] _vertexData;
2323
private VertexBuffer _vertexBuffer;
@@ -28,13 +28,13 @@ public class ImGuiRenderer
2828
private int _indexBufferSize;
2929

3030
// Textures
31-
private Dictionary<ImTextureID, TextureInfo> _textures;
32-
private int _nextTexId = 0;
31+
private readonly Dictionary<ImTextureID, TextureInfo> _textures;
32+
private int _nextTexId;
3333

3434
// Input
3535
private int _scrollWheelValue;
3636
private int _horizontalScrollWheelValue;
37-
private Keys[] _allKeys = Enum.GetValues<Keys>();
37+
private readonly Keys[] _allKeys = Enum.GetValues<Keys>();
3838

3939

4040
public ImGuiRenderer(Game game)
@@ -62,7 +62,7 @@ public ImGuiRenderer(Game game)
6262
SetupBackendCapabilities();
6363
}
6464

65-
private unsafe void SetupBackendCapabilities()
65+
private void SetupBackendCapabilities()
6666
{
6767
ImGuiIOPtr io = ImGui.GetIO();
6868
io.BackendFlags |= ImGuiBackendFlags.RendererHasTextures;
@@ -109,7 +109,7 @@ public virtual void UnbindTexture(ImTextureRef textureRef)
109109
}
110110
}
111111

112-
public virtual unsafe void UpdateTexture(ImTextureDataPtr textureData)
112+
public virtual void UpdateTexture(ImTextureDataPtr textureData)
113113
{
114114
switch (textureData.Status)
115115
{
@@ -468,8 +468,8 @@ private unsafe void UpdateBuffers(ImDrawData* drawData)
468468
{
469469
fixed (void* idxDstPtr = &_indexData[idxOffset * sizeof(ushort)])
470470
{
471-
Buffer.MemoryCopy((void*)cmdList->VtxBuffer.Data, vtxDstPtr, _vertexData.Length, cmdList->VtxBuffer.Size * DrawVertDeclaration.Size);
472-
Buffer.MemoryCopy((void*)cmdList->IdxBuffer.Data, idxDstPtr, _indexData.Length, cmdList->IdxBuffer.Size * sizeof(ushort));
471+
Buffer.MemoryCopy(cmdList->VtxBuffer.Data, vtxDstPtr, _vertexData.Length, cmdList->VtxBuffer.Size * DrawVertDeclaration.Size);
472+
Buffer.MemoryCopy(cmdList->IdxBuffer.Data, idxDstPtr, _indexData.Length, cmdList->IdxBuffer.Size * sizeof(ushort));
473473
}
474474
}
475475

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
using var game = new MonoGameExample.SampleGame();
1+
using ExampleMonoGame;
2+
3+
using var game = new SampleGame();
24
game.Run();

Examples/ExampleMonoGame/SampleGame.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Microsoft.Xna.Framework.Graphics;
66
using Num = System.Numerics;
77

8-
namespace MonoGameExample;
8+
namespace ExampleMonoGame;
99

1010
/// <summary>
1111
/// Simple Monogame + ImGui example
@@ -53,7 +53,7 @@ protected override void LoadContent()
5353

5454
protected override void Draw(GameTime gameTime)
5555
{
56-
GraphicsDevice.Clear(new Color(clear_color.X, clear_color.Y, clear_color.Z));
56+
GraphicsDevice.Clear(new Color(_clearColor.X, _clearColor.Y, _clearColor.Z));
5757

5858
// Call BeforeLayout first to set things up
5959
_imGuiRenderer.BeforeLayout(gameTime);
@@ -68,29 +68,29 @@ protected override void Draw(GameTime gameTime)
6868
}
6969

7070
// Direct port of the example at https://github.com/ocornut/imgui/blob/master/examples/example_sdl2_opengl2/main.cpp
71-
private float f = 0.0f;
72-
73-
private bool show_test_window = false;
74-
private bool show_another_window = false;
75-
private Num.Vector3 clear_color = new Num.Vector3(114f / 255f, 144f / 255f, 154f / 255f);
76-
private byte[] _textBuffer = new byte[100];
71+
private float _floatValue;
72+
73+
private bool _showTestWindow;
74+
private bool _showAnotherWindow;
75+
private Num.Vector3 _clearColor = new Num.Vector3(114f / 255f, 144f / 255f, 154f / 255f);
76+
private readonly byte[] _textBuffer = new byte[100];
7777

7878
protected virtual void ImGuiLayout()
7979
{
8080
// 1. Show a simple window
8181
// Tip: if we don't call ImGui.Begin()/ImGui.End() the widgets appears in a window automatically called "Debug"
8282
{
8383
ImGui.Text("Hello, world!"u8);
84-
ImGui.SliderFloat("float"u8, ref f, 0.0f, 1.0f, string.Empty);
85-
ImGui.ColorEdit3("clear color", ref clear_color);
84+
ImGui.SliderFloat("float"u8, ref _floatValue, 0.0f, 1.0f, string.Empty);
85+
ImGui.ColorEdit3("clear color", ref _clearColor);
8686
if (ImGui.Button("Test Window"u8))
8787
{
88-
show_test_window = !show_test_window;
88+
_showTestWindow = !_showTestWindow;
8989
}
9090

9191
if (ImGui.Button("Another Window"u8))
9292
{
93-
show_another_window = !show_another_window;
93+
_showAnotherWindow = !_showAnotherWindow;
9494
}
9595

9696
// Use StrBuilder for dynamic text instead of string.Format
@@ -117,19 +117,19 @@ protected virtual void ImGuiLayout()
117117
}
118118

119119
// 2. Show another simple window, this time using an explicit Begin/End pair
120-
if (show_another_window)
120+
if (_showAnotherWindow)
121121
{
122122
ImGui.SetNextWindowSize(new Num.Vector2(200, 100), ImGuiCond.FirstUseEver);
123-
ImGui.Begin("Another Window"u8, ref show_another_window);
123+
ImGui.Begin("Another Window"u8, ref _showAnotherWindow);
124124
ImGui.Text("Hello"u8);
125125
ImGui.End();
126126
}
127127

128128
// 3. Show the ImGui test window. Most of the sample code is in ImGui.ShowTestWindow()
129-
if (show_test_window)
129+
if (_showTestWindow)
130130
{
131131
ImGui.SetNextWindowPos(new Num.Vector2(650, 20), ImGuiCond.FirstUseEver);
132-
ImGui.ShowDemoWindow(ref show_test_window);
132+
ImGui.ShowDemoWindow(ref _showTestWindow);
133133
}
134134
}
135135

Examples/ExampleMonoGame/TextureInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.Xna.Framework.Graphics;
22

3-
namespace MonoGameExample;
3+
namespace ExampleMonoGame;
44

55
public sealed class TextureInfo
66
{

0 commit comments

Comments
 (0)