added API to Add images

also, added sample code
master
Zaafar Ahmed 6 years ago
parent bc1cca7825
commit 0d3f689f40
  1. 3
      ClickableTransparentOverlay/ClickableTransparentOverlay.csproj
  2. 31
      ClickableTransparentOverlay/Overlay.cs
  3. 1
      ClickableTransparentOverlay/packages.config
  4. 4
      DriverProgram/DriverProgram.csproj
  5. 12
      DriverProgram/Program.cs
  6. 1
      DriverProgram/packages.config

@ -105,6 +105,9 @@
<Reference Include="Veldrid, Version=4.6.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Veldrid, Version=4.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Veldrid.4.6.1\lib\netstandard2.0\Veldrid.dll</HintPath> <HintPath>..\packages\Veldrid.4.6.1\lib\netstandard2.0\Veldrid.dll</HintPath>
</Reference> </Reference>
<Reference Include="Veldrid.ImageSharp, Version=4.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Veldrid.ImageSharp.4.6.1\lib\netstandard2.0\Veldrid.ImageSharp.dll</HintPath>
</Reference>
<Reference Include="Veldrid.SDL2, Version=4.6.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Veldrid.SDL2, Version=4.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Veldrid.SDL2.4.6.1\lib\netstandard2.0\Veldrid.SDL2.dll</HintPath> <HintPath>..\packages\Veldrid.SDL2.4.6.1\lib\netstandard2.0\Veldrid.SDL2.dll</HintPath>
</Reference> </Reference>

@ -5,10 +5,12 @@
namespace ClickableTransparentOverlay namespace ClickableTransparentOverlay
{ {
using System; using System;
using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Veldrid; using Veldrid;
using Veldrid.ImageSharp;
using Veldrid.Sdl2; using Veldrid.Sdl2;
using Veldrid.StartupUtilities; using Veldrid.StartupUtilities;
@ -28,6 +30,7 @@ namespace ClickableTransparentOverlay
private static Vector4 clearColor; private static Vector4 clearColor;
private static int myFps; private static int myFps;
private static bool isClosed; private static bool isClosed;
private static Dictionary<string, Texture> loadedImages;
// For Resizing SDL2Window // For Resizing SDL2Window
private static Vector2 futurePos; private static Vector2 futurePos;
@ -58,6 +61,7 @@ namespace ClickableTransparentOverlay
/// </param> /// </param>
public Overlay(int x, int y, int width, int height, int fps, bool debug) public Overlay(int x, int y, int width, int height, int fps, bool debug)
{ {
loadedImages = new Dictionary<string, Texture>();
clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f); clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
myFps = fps; myFps = fps;
isClosed = false; isClosed = false;
@ -188,10 +192,37 @@ namespace ClickableTransparentOverlay
hookController.Dispose(); hookController.Dispose();
NativeMethods.ShowConsoleWindow(); NativeMethods.ShowConsoleWindow();
this.SubmitUI = null; this.SubmitUI = null;
loadedImages.Clear();
Console.WriteLine("All Overlay resources are cleared."); Console.WriteLine("All Overlay resources are cleared.");
Application.Exit(); Application.Exit();
} }
/// <summary>
/// Adds the image to the Graphic Device as a texture.
/// Then returns the pointer of the added texture. It also
/// cache the image internally rather than creating a new texture on every call,
/// so this function can be called multiple times per image (per FPS).
/// </summary>
/// <param name="filePath">
/// Path to the image on disk. If the image is loaded in the memory
/// save it on the disk before sending to this function. Reason for this
/// is to cache the Image Texture using filePath as the key.
/// </param>
/// <returns>
/// A pointer to the Texture in the Graphic Device.
/// </returns>
public IntPtr AddOrGetImagePointer(string filePath)
{
if (!loadedImages.TryGetValue(filePath, out Texture texture))
{
ImageSharpTexture imgSharpTexture = new ImageSharpTexture(filePath);
texture = imgSharpTexture.CreateDeviceTexture(graphicsDevice, graphicsDevice.ResourceFactory);
loadedImages.Add(filePath, texture);
}
return imController.GetOrCreateImGuiBinding(graphicsDevice.ResourceFactory, texture);
}
/// <summary> /// <summary>
/// Infinite While Loop to render the ImGui. /// Infinite While Loop to render the ImGui.
/// </summary> /// </summary>

@ -14,6 +14,7 @@
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" /> <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" /> <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
<package id="Veldrid" version="4.6.1" targetFramework="net472" /> <package id="Veldrid" version="4.6.1" targetFramework="net472" />
<package id="Veldrid.ImageSharp" version="4.6.1" targetFramework="net472" />
<package id="Veldrid.SDL2" version="4.6.1" targetFramework="net472" /> <package id="Veldrid.SDL2" version="4.6.1" targetFramework="net472" />
<package id="Veldrid.StartupUtilities" version="4.6.1" targetFramework="net472" /> <package id="Veldrid.StartupUtilities" version="4.6.1" targetFramework="net472" />
</packages> </packages>

@ -76,6 +76,10 @@
<Reference Include="ImGui.NET, Version=1.70.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ImGui.NET, Version=1.70.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ImGui.NET.1.70.0\lib\netstandard2.0\ImGui.NET.dll</HintPath> <HintPath>..\packages\ImGui.NET.1.70.0\lib\netstandard2.0\ImGui.NET.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>

@ -2,6 +2,8 @@
{ {
using ClickableTransparentOverlay; using ClickableTransparentOverlay;
using ImGuiNET; using ImGuiNET;
using System.IO;
using System.Numerics;
using System.Threading; using System.Threading;
class Program class Program
@ -64,6 +66,16 @@
showImGuiDemo = true; showImGuiDemo = true;
} }
ImGui.NewLine();
if (File.Exists("image.png"))
{
ImGui.Image(overlay.AddOrGetImagePointer("image.png"), new Vector2(600, 400));
}
else
{
ImGui.Text("Put any image where the exe is, name is 'image.png'");
}
ImGui.End(); ImGui.End();
} }

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="ImGui.NET" version="1.70.0" targetFramework="net472" /> <package id="ImGui.NET" version="1.70.0" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
</packages> </packages>
Loading…
Cancel
Save