Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }