mirror of
https://github.com/vale981/VoiDPlugins
synced 2025-03-04 16:51:38 -05:00
Box unmanaged data
This commit is contained in:
parent
ce43c5e93c
commit
148e542528
5 changed files with 30 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
|||
using System.Numerics;
|
||||
using OpenTabletDriver.Plugin.Platform.Pointer;
|
||||
using OpenTabletDriver.Plugin.Tablet;
|
||||
using VoiDPlugins.Library;
|
||||
using VoiDPlugins.Library.VMulti;
|
||||
using VoiDPlugins.Library.VMulti.Device;
|
||||
using static VoiDPlugins.OutputMode.WindowsInkConstants;
|
||||
|
@ -16,14 +17,14 @@ namespace VoiDPlugins.OutputMode
|
|||
{
|
||||
Instance = VMultiInstanceManager.RetrieveVMultiInstance("WindowsInk", tabletReference, () => new DigitizerInputReport());
|
||||
Instance.InitializeData(POINTER, this);
|
||||
Instance.InitializeData(ERASER_STATE, false);
|
||||
Instance.InitializeData(MANUAL_ERASER, false);
|
||||
Instance.InitializeData(ERASER_STATE, new Boxed<bool>(false));
|
||||
Instance.InitializeData(MANUAL_ERASER, new Boxed<bool>(false));
|
||||
RawPointer = Instance.Pointer;
|
||||
}
|
||||
|
||||
public void SetEraser(bool isEraser)
|
||||
{
|
||||
if (!Instance!.GetData<bool>(MANUAL_ERASER))
|
||||
if (!Instance!.GetData<Boxed<bool>>(MANUAL_ERASER).Value)
|
||||
{
|
||||
WinInkButtonHandler.EraserStateTransition(Instance, ref GetEraser(), isEraser);
|
||||
}
|
||||
|
@ -49,9 +50,9 @@ namespace VoiDPlugins.OutputMode
|
|||
Instance!.Write();
|
||||
}
|
||||
|
||||
private ref bool GetEraser()
|
||||
private ref Boxed<bool> GetEraser()
|
||||
{
|
||||
return ref Instance!.GetData<bool>(ERASER_STATE);
|
||||
return ref Instance!.GetData<Boxed<bool>>(ERASER_STATE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using OpenTabletDriver.Plugin;
|
||||
using OpenTabletDriver.Plugin.Attributes;
|
||||
using OpenTabletDriver.Plugin.Tablet;
|
||||
using VoiDPlugins.Library;
|
||||
using VoiDPlugins.Library.VMulti;
|
||||
using VoiDPlugins.Library.VMulti.Device;
|
||||
using static VoiDPlugins.OutputMode.WindowsInkConstants;
|
||||
|
@ -50,7 +51,7 @@ namespace VoiDPlugins.OutputMode
|
|||
switch (Button)
|
||||
{
|
||||
case "Pen Tip":
|
||||
_instance!.EnableButtonBit((int)(eraserState ? ButtonBits.Eraser : ButtonBits.Press));
|
||||
_instance!.EnableButtonBit((int)(eraserState.Value ? ButtonBits.Eraser : ButtonBits.Press));
|
||||
break;
|
||||
|
||||
case "Pen Button":
|
||||
|
@ -59,7 +60,7 @@ namespace VoiDPlugins.OutputMode
|
|||
|
||||
case "Eraser (Toggle)":
|
||||
IsManuallySet = true;
|
||||
EraserStateTransition(_instance!, ref eraserState, !eraserState);
|
||||
EraserStateTransition(_instance!, ref eraserState, !eraserState.Value);
|
||||
break;
|
||||
|
||||
case "Eraser (Hold)":
|
||||
|
@ -87,11 +88,11 @@ namespace VoiDPlugins.OutputMode
|
|||
}
|
||||
}
|
||||
|
||||
public static void EraserStateTransition(VMultiInstance instance, ref bool eraserState, bool isEraser)
|
||||
public static void EraserStateTransition(VMultiInstance instance, ref Boxed<bool> eraserState, bool isEraser)
|
||||
{
|
||||
if (eraserState != isEraser)
|
||||
if (eraserState.Value != isEraser)
|
||||
{
|
||||
eraserState = isEraser;
|
||||
eraserState.Value = isEraser;
|
||||
var report = (DigitizerInputReport*)instance.Header;
|
||||
var buttons = report->Header.Buttons;
|
||||
var pressure = report->Pressure;
|
||||
|
@ -107,21 +108,21 @@ namespace VoiDPlugins.OutputMode
|
|||
|
||||
// Send In-Range but no tips
|
||||
instance.EnableButtonBit((int)ButtonBits.InRange);
|
||||
if (eraserState)
|
||||
if (eraserState.Value)
|
||||
instance.EnableButtonBit((int)ButtonBits.Invert);
|
||||
|
||||
instance.Write();
|
||||
|
||||
// Set Proper Report
|
||||
if (VMultiInstance.HasBit(buttons, (int)(ButtonBits.Press | ButtonBits.Eraser)))
|
||||
instance.EnableButtonBit((int)(eraserState ? ButtonBits.Eraser : ButtonBits.Press));
|
||||
instance.EnableButtonBit((int)(eraserState.Value ? ButtonBits.Eraser : ButtonBits.Press));
|
||||
report->Pressure = pressure;
|
||||
}
|
||||
}
|
||||
|
||||
private ref bool GetEraser()
|
||||
private ref Boxed<bool> GetEraser()
|
||||
{
|
||||
return ref _instance!.GetData<bool>(ERASER_STATE);
|
||||
return ref _instance!.GetData<Boxed<bool>>(ERASER_STATE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<VMultiLibrary>true</VMultiLibrary>
|
||||
<VoiDLibrary>true</VoiDLibrary>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace VoiDPlugins.Library.VMulti
|
|||
_data[i] = data!;
|
||||
}
|
||||
|
||||
public unsafe ref T GetData<T>(int i)
|
||||
public unsafe ref T GetData<T>(int i) where T : class
|
||||
{
|
||||
return ref Unsafe.AsRef<T>(Unsafe.AsPointer(ref _data[i]));
|
||||
}
|
||||
|
|
12
VoiDPlugins.Library/VoiD/Boxed.cs
Normal file
12
VoiDPlugins.Library/VoiD/Boxed.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace VoiDPlugins.Library
|
||||
{
|
||||
public class Boxed<T> where T : unmanaged
|
||||
{
|
||||
public Boxed(T value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public T Value { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue