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">
<HintPath>..\packages\Veldrid.4.6.1\lib\netstandard2.0\Veldrid.dll</HintPath>
</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">
<HintPath>..\packages\Veldrid.SDL2.4.6.1\lib\netstandard2.0\Veldrid.SDL2.dll</HintPath>
</Reference>

@ -5,10 +5,12 @@
namespace ClickableTransparentOverlay
{
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Threading;
using System.Windows.Forms;
using Veldrid;
using Veldrid.ImageSharp;
using Veldrid.Sdl2;
using Veldrid.StartupUtilities;
@ -28,6 +30,7 @@ namespace ClickableTransparentOverlay
private static Vector4 clearColor;
private static int myFps;
private static bool isClosed;
private static Dictionary<string, Texture> loadedImages;
// For Resizing SDL2Window
private static Vector2 futurePos;
@ -58,6 +61,7 @@ namespace ClickableTransparentOverlay
/// </param>
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);
myFps = fps;
isClosed = false;
@ -188,10 +192,37 @@ namespace ClickableTransparentOverlay
hookController.Dispose();
NativeMethods.ShowConsoleWindow();
this.SubmitUI = null;
loadedImages.Clear();
Console.WriteLine("All Overlay resources are cleared.");
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>
/// Infinite While Loop to render the ImGui.
/// </summary>

@ -14,6 +14,7 @@
<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="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.StartupUtilities" version="4.6.1" targetFramework="net472" />
</packages>

@ -76,6 +76,10 @@
<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>
</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>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

@ -2,6 +2,8 @@
{
using ClickableTransparentOverlay;
using ImGuiNET;
using System.IO;
using System.Numerics;
using System.Threading;
class Program
@ -64,6 +66,16 @@
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();
}

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