public override bool Initialize(GameHost host) { tabletDriver = new TabletDriver { // for now let's keep things simple and always use absolute mode. // this will likely be a user setting in the future. OutputMode = new AbsoluteTabletMode(this) }; updateOutputArea(host.Window); host.Window.Resized += () => updateOutputArea(host.Window); AreaOffset.BindValueChanged(_ => updateInputArea()); AreaSize.BindValueChanged(_ => updateInputArea(), true); Rotation.BindValueChanged(_ => updateInputArea(), true); tabletDriver.TabletChanged += (sender, e) => updateInputArea(); tabletDriver.ReportReceived += (sender, report) => { switch (report) { case ITabletReport tabletReport: handleTabletReport(tabletReport); break; case IAuxReport auxiliaryReport: handleAuxiliaryReport(auxiliaryReport); break; } }; Enabled.BindValueChanged(d => { if (d.NewValue) { if (tabletDriver.Tablet == null) { tabletDriver.DetectTablet(); } } tabletDriver.EnableInput = d.NewValue; }, true); return(true); }
private void updateInputArea() { if (tabletDriver.Tablet == null) { tablet.Value = null; return; } float inputWidth = tabletDriver.Tablet.Digitizer.Width; float inputHeight = tabletDriver.Tablet.Digitizer.Height; AreaSize.Default = new Vector2(inputWidth, inputHeight); // if it's clear the user has not configured the area, take the full area from the tablet that was just found. if (AreaSize.Value == Vector2.Zero) { AreaSize.SetDefault(); } AreaOffset.Default = new Vector2(inputWidth / 2, inputHeight / 2); // likewise with the position, use the centre point if it has not been configured. // it's safe to assume no user would set their centre point to 0,0 for now. if (AreaOffset.Value == Vector2.Zero) { AreaOffset.SetDefault(); } tablet.Value = new TabletInfo(tabletDriver.Tablet.TabletProperties.Name, AreaSize.Default); switch (tabletDriver.OutputMode) { case AbsoluteOutputMode absoluteOutputMode: { // Set input area in millimeters absoluteOutputMode.Input = new Area { Width = AreaSize.Value.X, Height = AreaSize.Value.Y, Position = new System.Numerics.Vector2(AreaOffset.Value.X, AreaOffset.Value.Y), Rotation = 0 }; break; } } }
public void SetTabletSize(Vector2 size) { tablet.Value = size != Vector2.Zero ? new TabletInfo($"test tablet T-{RNG.Next(999):000}", size) : null; AreaSize.Default = new Vector2(size.X, size.Y); // if it's clear the user has not configured the area, take the full area from the tablet that was just found. if (AreaSize.Value == Vector2.Zero) { AreaSize.SetDefault(); } AreaOffset.Default = new Vector2(size.X / 2, size.Y / 2); // likewise with the position, use the centre point if it has not been configured. // it's safe to assume no user would set their centre point to 0,0 for now. if (AreaOffset.Value == Vector2.Zero) { AreaOffset.SetDefault(); } }
public override bool Initialize(GameHost host) { outputMode = new AbsoluteTabletMode(this); host.Window.Resized += () => updateOutputArea(host.Window); AreaOffset.BindValueChanged(_ => updateInputArea(device)); AreaSize.BindValueChanged(_ => updateInputArea(device), true); Rotation.BindValueChanged(_ => updateInputArea(device), true); Enabled.BindValueChanged(d => { if (d.NewValue && tabletDriver == null) { tabletDriver = TabletDriver.Create(); tabletDriver.TabletsChanged += (s, e) => { device = e.Any() ? tabletDriver.InputDevices.First() : null; if (device != null) { device.OutputMode = outputMode; outputMode.Tablet = device.CreateReference(); updateInputArea(device); updateOutputArea(host.Window); } }; tabletDriver.DeviceReported += handleDeviceReported; tabletDriver.Detect(); } else if (!d.NewValue && tabletDriver != null) { tabletDriver.Dispose(); tabletDriver = null; } }, true); return(true); }