Skip to content

Commit

Permalink
Workaround OTD API break
Browse files Browse the repository at this point in the history
  • Loading branch information
X9VoiD committed Mar 24, 2022
1 parent 13c8a3b commit 10b4b00
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 16 deletions.
11 changes: 8 additions & 3 deletions src/OutputMode/VMultiMode/Output/VMultiAbsoluteMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenTabletDriver.Plugin.Output;
using OpenTabletDriver.Plugin.Platform.Display;
using OpenTabletDriver.Plugin.Platform.Pointer;
using OpenTabletDriver.Plugin.Tablet;

namespace VoiDPlugins.OutputMode
{
Expand All @@ -19,10 +20,14 @@ public IServiceProvider ServiceProvider
set => _virtualScreen = (IVirtualScreen)value.GetService(typeof(IVirtualScreen))!;
}

[OnDependencyLoad]
public void Initialize()
public override TabletReference Tablet
{
_pointer = new VMultiAbsolutePointer(Tablet, _virtualScreen!);
get => base.Tablet;
set
{
base.Tablet = value;
_pointer = new VMultiAbsolutePointer(value, _virtualScreen!);
}
}

public override IAbsolutePointer Pointer
Expand Down
12 changes: 8 additions & 4 deletions src/OutputMode/VMultiMode/Output/VMultiRelativeMode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OpenTabletDriver.Plugin.Attributes;
using OpenTabletDriver.Plugin.DependencyInjection;
using OpenTabletDriver.Plugin.Output;
using OpenTabletDriver.Plugin.Platform.Pointer;
using OpenTabletDriver.Plugin.Tablet;

namespace VoiDPlugins.OutputMode
{
Expand All @@ -10,10 +10,14 @@ public class VMultiRelativeMode : RelativeOutputMode
{
private VMultiRelativePointer? _pointer;

[OnDependencyLoad]
public void Initialize()
public override TabletReference Tablet
{
_pointer = new VMultiRelativePointer(Tablet);
get => base.Tablet;
set
{
base.Tablet = value;
_pointer = new VMultiRelativePointer(value);
}
}

public override IRelativePointer Pointer
Expand Down
2 changes: 1 addition & 1 deletion src/OutputMode/VMultiMode/Pointer/VMultiAbsolutePointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public unsafe class VMultiAbsolutePointer : IAbsolutePointer, ISynchronousPointe

public VMultiAbsolutePointer(TabletReference tabletReference, IVirtualScreen virtualScreen)
{
_instance = GlobalStore<VMultiInstance>.GetOrInitialize(tabletReference, () => new VMultiInstance<AbsoluteInputReport>("VMultiAbs", new AbsoluteInputReport()));
_instance = GlobalStore<VMultiInstance>.Set(tabletReference, () => new VMultiInstance<AbsoluteInputReport>("VMultiAbs", new AbsoluteInputReport()));
_rawPointer = _instance.Pointer;
_conversionFactor = new Vector2(32767, 32767) / new Vector2(virtualScreen.Width, virtualScreen.Height);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OutputMode/VMultiMode/Pointer/VMultiRelativePointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public unsafe class VMultiRelativePointer : IRelativePointer, ISynchronousPointe

public VMultiRelativePointer(TabletReference tabletReference)
{
_instance = GlobalStore<VMultiInstance>.GetOrInitialize(tabletReference, () => new VMultiInstance<RelativeInputReport>("VMultiAbs", new RelativeInputReport()));
_instance = GlobalStore<VMultiInstance>.Set(tabletReference, () => new VMultiInstance<RelativeInputReport>("VMultiAbs", new RelativeInputReport()));
_rawPointer = _instance.Pointer;
}

Expand Down
11 changes: 8 additions & 3 deletions src/OutputMode/WindowsInk/Output/WinInkAbsoluteMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenTabletDriver.Plugin.Output;
using OpenTabletDriver.Plugin.Platform.Display;
using OpenTabletDriver.Plugin.Platform.Pointer;
using OpenTabletDriver.Plugin.Tablet;

namespace VoiDPlugins.OutputMode
{
Expand All @@ -19,10 +20,14 @@ public IServiceProvider ServiceProvider
set => _virtualScreen = (IVirtualScreen)value.GetService(typeof(IVirtualScreen))!;
}

[OnDependencyLoad]
public void Initialize()
public override TabletReference Tablet
{
_pointer = new WinInkAbsolutePointer(Tablet, _virtualScreen!);
get => base.Tablet;
set
{
base.Tablet = value;
_pointer = new WinInkAbsolutePointer(value, _virtualScreen!);
}
}

public override IAbsolutePointer Pointer
Expand Down
11 changes: 8 additions & 3 deletions src/OutputMode/WindowsInk/Output/WinInkRelativeMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenTabletDriver.Plugin.Output;
using OpenTabletDriver.Plugin.Platform.Display;
using OpenTabletDriver.Plugin.Platform.Pointer;
using OpenTabletDriver.Plugin.Tablet;

namespace VoiDPlugins.OutputMode
{
Expand All @@ -19,10 +20,14 @@ public IServiceProvider ServiceProvider
set => _virtualScreen = (IVirtualScreen)value.GetService(typeof(IVirtualScreen))!;
}

[OnDependencyLoad]
public void Initialize()
public override TabletReference Tablet
{
_pointer = new WinInkRelativePointer(Tablet, _virtualScreen!);
get => base.Tablet;
set
{
base.Tablet = value;
_pointer = new WinInkRelativePointer(value, _virtualScreen!);
}
}

public override IRelativePointer Pointer
Expand Down
2 changes: 1 addition & 1 deletion src/OutputMode/WindowsInk/Pointer/WinInkBasePointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public unsafe abstract class WinInkBasePointer : IPressureHandler, ITiltHandler,
public WinInkBasePointer(string name, TabletReference tabletReference)
{
Instance = new VMultiInstance<DigitizerInputReport>(name, new DigitizerInputReport());
SharedStore = GlobalStore<SharedStore>.GetOrInitialize(tabletReference, () => new SharedStore());
SharedStore = GlobalStore<SharedStore>.Set(tabletReference, () => new SharedStore());
SharedStore.InitializeData(INSTANCE, Instance);
SharedStore.InitializeData(POINTER, this);
SharedStore.InitializeData(ERASER_STATE, new Boxed<bool>(false));
Expand Down
10 changes: 10 additions & 0 deletions src/VoiDPlugins.Library/VoiD/GlobalStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public static class GlobalStore<T> where T : class
private static readonly object _syncLock = new();
private static readonly Dictionary<string, T> _map = new();

public static U Set<U>(TabletReference tabletReference, Func<U> factory) where U : T
{
lock (_syncLock)
{
ref var instance = ref CollectionsMarshal.GetValueRefOrAddDefault(_map, tabletReference.Properties.Name, out var exists);
instance = factory();
return (U)instance;
}
}

public static U GetOrInitialize<U>(TabletReference tabletReference, Func<U> initialValue) where U : T
{
lock (_syncLock)
Expand Down

0 comments on commit 10b4b00

Please sign in to comment.