public void Initialize(TabletDriver driver, Configuration config) { this.driver = driver; this.config = config; if (initialArea == null) { initialArea = new Area(config.TabletAreas?[0]); currentArea = new Area(initialArea); //maximumArea = config.TabletFullArea; } }
// // Constructor // public MainWindow() { // Set the current directory as TabletDriverGUI.exe's directory. try { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); } catch (Exception) { } // // Prevent triggering input field events // isLoadingSettings = true; // Initialize WPF InitializeComponent(); // Version text textVersion.Text = this.Version; // Set culture to en-US to force decimal format and etc. CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); // Create notify icon notifyIcon = new System.Windows.Forms.NotifyIcon { // Icon Icon = Properties.Resources.AppIcon, // Menu items ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[] { new System.Windows.Forms.MenuItem("TabletDriverGUI " + Version), new System.Windows.Forms.MenuItem("Restart Driver", NotifyRestartDriver), new System.Windows.Forms.MenuItem("Show", NotifyShowWindow), new System.Windows.Forms.MenuItem("Exit", NotifyExit) }) }; notifyIcon.ContextMenu.MenuItems[0].Enabled = false; notifyIcon.Text = ""; notifyIcon.DoubleClick += NotifyIcon_DoubleClick; notifyIcon.Click += NotifyIcon_DoubleClick; notifyIcon.Visible = true; IsRealExit = false; // Create command history list commandHistory = new List <string> { "" }; commandHistoryIndex = 0; // Init tablet driver driver = new TabletDriver("TabletDriverService.exe"); driverCommands = new Dictionary <string, string>(); driver.MessageReceived += OnDriverMessageReceived; driver.ErrorReceived += OnDriverErrorReceived; driver.StatusReceived += OnDriverStatusReceived; driver.Started += OnDriverStarted; driver.Stopped += OnDriverStopped; running = false; // Restart timer timerRestart = new DispatcherTimer { Interval = new TimeSpan(0, 0, 5) }; timerRestart.Tick += TimerRestart_Tick; // Statusbar timer timerStatusbar = new DispatcherTimer { Interval = new TimeSpan(0, 0, 5) }; timerStatusbar.Tick += TimerStatusbar_Tick; // Timer console update timerConsoleUpdate = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 200) }; timerConsoleUpdate.Tick += TimerConsoleUpdate_Tick; // Tooltip timeout ToolTipService.ShowDurationProperty.OverrideMetadata( typeof(DependencyObject), new FrameworkPropertyMetadata(60000)); if (App.exp_no_vmulti) { radioModeAbsolute.IsEnabled = radioModeDigitizer.IsEnabled = radioModeRelative.IsEnabled = false; } // // Buttom Map ComboBoxes // comboBoxButton1.Items.Clear(); comboBoxButton2.Items.Clear(); comboBoxButton3.Items.Clear(); comboBoxButton1.Items.Add("Disable"); comboBoxButton2.Items.Add("Disable"); comboBoxButton3.Items.Add("Disable"); for (int i = 1; i <= 5; i++) { comboBoxButton1.Items.Add("Mouse " + i); comboBoxButton2.Items.Add("Mouse " + i); comboBoxButton3.Items.Add("Mouse " + i); } comboBoxButton1.Items.Add("Extra"); comboBoxButton2.Items.Add("Extra"); comboBoxButton3.Items.Add("Extra"); comboBoxButton1.SelectedIndex = 0; comboBoxButton2.SelectedIndex = 0; comboBoxButton3.SelectedIndex = 0; extraTipEventBox.Items.Clear(); extraBottomEventBox.Items.Clear(); extraTopEventBox.Items.Clear(); extraTipEventBox.Items.Add("None"); extraBottomEventBox.Items.Add("None"); extraTopEventBox.Items.Add("None"); extraTipEventBox.Items.Add("Mouse Wheel"); extraBottomEventBox.Items.Add("Mouse Wheel"); extraTopEventBox.Items.Add("Mouse Wheel"); extraTipEventBox.Items.Add("Disable Tablet"); extraBottomEventBox.Items.Add("Disable Tablet"); extraTopEventBox.Items.Add("Disable Tablet"); extraTipEventBox.Items.Add("Keyboard"); extraBottomEventBox.Items.Add("Keyboard"); extraTopEventBox.Items.Add("Keyboard"); // // Smoothing rate ComboBox // comboBoxSmoothingRate.Items.Clear(); for (int i = 1; i <= 8; i++) { comboBoxSmoothingRate.Items.Add((1000.0 / i).ToString("0") + " Hz"); } comboBoxSmoothingRate.SelectedIndex = 3; // Process command line arguments ProcessCommandLineArguments(); // Events Closing += MainWindow_Closing; Loaded += MainWindow_Loaded; SizeChanged += MainWindow_SizeChanged; switch (ConfigurationManager.Method) { case ConfigurationManager.ListenMethod.Stop: { disableAutoSwitch.IsChecked = true; break; } case ConfigurationManager.ListenMethod.Poll_L: { fdm_Poll.IsChecked = true; break; } case ConfigurationManager.ListenMethod.Poll_M: { fdm_PollH.IsChecked = true; break; } case ConfigurationManager.ListenMethod.Poll_X: { fdm_PollL.IsChecked = true; break; } case ConfigurationManager.ListenMethod.Callback_WinEventHook: { fdm_WEHook.IsChecked = true; break; } } // // Allow input field events // isLoadingSettings = false; ConfigurationManager.ConfigurationChanged += () => LoadSettingsFromConfiguration(); ConfigurationManager.ConfigurationChanged += () => driver.SendCommand("status"); }
// // Constructor // public MainWindow() { // Set the current directory as TabletDriverGUI.exe's directory. try { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); } catch (Exception) { } // // Prevent triggering input field events // isLoadingSettings = true; // Initialize WPF InitializeComponent(); // Version text textVersion.Text = this.Version; // Set culture to en-US to force decimal format and etc. CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); // Create notify icon notifyIcon = new System.Windows.Forms.NotifyIcon { // Icon Icon = Properties.Resources.AppIcon, // Menu items ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[] { new System.Windows.Forms.MenuItem("TabletDriverGUI " + Version), new System.Windows.Forms.MenuItem("Restart Driver", NotifyRestartDriver), new System.Windows.Forms.MenuItem("Show", NotifyShowWindow), new System.Windows.Forms.MenuItem("Exit", NotifyExit) }) }; notifyIcon.ContextMenu.MenuItems[0].Enabled = false; notifyIcon.Text = ""; notifyIcon.MouseClick += NotifyIcon_Click; notifyIcon.Visible = true; IsRealExit = false; // Create command history list commandHistory = new List <string> { "" }; commandHistoryIndex = 0; // Init setting commands list settingCommands = new List <string>(); // Init tablet driver driver = new TabletDriver("TabletDriverService.exe"); driverCommands = new Dictionary <string, string>(); driver.MessageReceived += OnDriverMessageReceived; driver.ErrorReceived += OnDriverErrorReceived; driver.StatusReceived += OnDriverStatusReceived; driver.Started += OnDriverStarted; driver.Stopped += OnDriverStopped; running = false; // Restart timer timerRestart = new DispatcherTimer { Interval = new TimeSpan(0, 0, 5) }; timerRestart.Tick += TimerRestart_Tick; // Statusbar timer timerStatusbar = new DispatcherTimer { Interval = new TimeSpan(0, 0, 5) }; timerStatusbar.Tick += TimerStatusbar_Tick; // Timer console update timerConsoleUpdate = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 200) }; timerConsoleUpdate.Tick += TimerConsoleUpdate_Tick; // Tooltip timeout ToolTipService.ShowDurationProperty.OverrideMetadata( typeof(DependencyObject), new FrameworkPropertyMetadata(60000)); // // Hide tablet button mapping // groupBoxTabletButtons.Visibility = Visibility.Collapsed; // Ink canvas undo history inkCanvasUndoHistory = new StrokeCollection(); // Ink canvas drawing attributes inkCanvasDrawingAttributes = new DrawingAttributes { Width = 10, Height = 10, Color = Color.FromRgb(0x55, 0x55, 0x55), StylusTip = StylusTip.Ellipse, FitToCurve = false }; inkCanvas.DefaultDrawingAttributes = inkCanvasDrawingAttributes; // Process command line arguments ProcessCommandLineArguments(); // Events Closing += MainWindow_Closing; Loaded += MainWindow_Loaded; SizeChanged += MainWindow_SizeChanged; }
// // Constructor // public MainWindow() { // Set the current directory as TabletDriverGUI.exe's directory. try { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); } catch (Exception) { } // // Prevent triggering input field events // isLoadingSettings = true; // Initialize WPF InitializeComponent(); // Version text textVersion.Text = this.Version; // Set culture to en-US to force decimal format and etc. CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); // Create notify icon notifyIcon = new System.Windows.Forms.NotifyIcon { // Icon Icon = Properties.Resources.AppIcon, // Menu items ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[] { new System.Windows.Forms.MenuItem("TabletDriverGUI " + Version), new System.Windows.Forms.MenuItem("Restart Driver", NotifyRestartDriver), new System.Windows.Forms.MenuItem("Show", NotifyShowWindow), new System.Windows.Forms.MenuItem("Exit", NotifyExit) }) }; notifyIcon.ContextMenu.MenuItems[0].Enabled = false; notifyIcon.Text = ""; notifyIcon.MouseClick += NotifyIcon_Click; notifyIcon.Visible = true; IsRealExit = false; // Create command history list commandHistory = new List <string> { "" }; commandHistoryIndex = 0; // Init setting commands list settingCommands = new List <string>(); // Init tablet driver driver = new TabletDriver("TabletDriverService.exe"); driverCommands = new Dictionary <string, string>(); driver.MessageReceived += OnDriverMessageReceived; driver.ErrorReceived += OnDriverErrorReceived; driver.StatusReceived += OnDriverStatusReceived; driver.Started += OnDriverStarted; driver.Stopped += OnDriverStopped; running = false; // Restart timer timerRestart = new DispatcherTimer { Interval = new TimeSpan(0, 0, 5) }; timerRestart.Tick += TimerRestart_Tick; // Statusbar timer timerStatusbar = new DispatcherTimer { Interval = new TimeSpan(0, 0, 5) }; timerStatusbar.Tick += TimerStatusbar_Tick; // Timer console update timerConsoleUpdate = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 200) }; timerConsoleUpdate.Tick += TimerConsoleUpdate_Tick; // Tooltip timeout ToolTipService.ShowDurationProperty.OverrideMetadata( typeof(DependencyObject), new FrameworkPropertyMetadata(60000)); // // Hide tablet button mapping // groupBoxTabletButtons.Visibility = Visibility.Collapsed; // // Create tablet button map WrapPanel items // for (int i = 0; i < 16; i++) { GroupBox groupBox = new GroupBox { Width = 90, Header = "Button " + (i + 1).ToString() }; Button button = new Button { Height = 22, Content = "", Padding = new Thickness(2, 0, 2, 0), ToolTip = "Empty", Background = Brushes.White }; button.Click += ButtonMap_Click; button.ToolTipOpening += ButtonMap_ToolTipOpening; groupBox.Content = button; wrapPanelTabletButtons.Children.Add(groupBox); } CheckBox checkBox = new CheckBox { Content = "Disable buttons" }; checkBox.Checked += CheckboxChanged; checkBox.Unchecked += CheckboxChanged; checkBox.VerticalAlignment = VerticalAlignment.Bottom; checkBox.Margin = new Thickness(5, 5, 5, 10); wrapPanelTabletButtons.Children.Add(checkBox); // // Smoothing rate ComboBox // comboBoxSmoothingRate.Items.Clear(); for (int i = 1; i <= 8; i++) { comboBoxSmoothingRate.Items.Add((1000.0 / i).ToString("0") + " Hz"); } comboBoxSmoothingRate.SelectedIndex = 3; // Ink canvas undo history inkCanvasUndoHistory = new StrokeCollection(); // Ink canvas drawing attributes inkCanvasDrawingAttributes = new DrawingAttributes { Width = 10, Height = 10, Color = Color.FromRgb(0x55, 0x55, 0x55), StylusTip = StylusTip.Ellipse }; inkCanvas.DefaultDrawingAttributes = inkCanvasDrawingAttributes; // Process command line arguments ProcessCommandLineArguments(); // Events Closing += MainWindow_Closing; Loaded += MainWindow_Loaded; SizeChanged += MainWindow_SizeChanged; // // Allow input field events // isLoadingSettings = false; }
// // Tablet View Constructor // public WindowTabletView(Configuration config, TabletDriver driver) { if (config.TabletView.Borderless) { WindowStyle = WindowStyle.None; } InitializeComponent(); this.config = config; this.driver = driver; // Tablet renderer tabletRenderer = new TabletRenderer(config); canvasTabletView.Children.Add(tabletRenderer); // Offset texts Canvas.SetLeft(textTabletInfo, Canvas.GetLeft(textTabletInfo) + config.TabletView.OffsetText.X); Canvas.SetTop(textTabletInfo, Canvas.GetTop(textTabletInfo) + config.TabletView.OffsetText.Y); Canvas.SetLeft(textInput, Canvas.GetLeft(textInput) + config.TabletView.OffsetText.X); Canvas.SetTop(textInput, Canvas.GetTop(textInput) + config.TabletView.OffsetText.Y); Canvas.SetLeft(textOutput, Canvas.GetLeft(textOutput) + config.TabletView.OffsetText.X); Canvas.SetTop(textOutput, Canvas.GetTop(textOutput) + config.TabletView.OffsetText.Y); Canvas.SetLeft(textLatency, Canvas.GetLeft(textLatency) + config.TabletView.OffsetText.X); Canvas.SetTop(textLatency, Canvas.GetTop(textLatency) + config.TabletView.OffsetText.Y); // Background color Brush brush; try { brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(config.TabletView.BackgroundColor)); } catch (Exception) { brush = Brushes.White; } canvasTabletView.Background = brush; Background = brush; // Text colors try { brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(config.TabletView.InfoColor)); } catch (Exception) { brush = Brushes.Black; } textTabletInfo.Foreground = brush; try { brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(config.TabletView.LatencyColor)); } catch (Exception) { brush = Brushes.Black; } textLatency.Foreground = brush; textInput.Foreground = tabletRenderer.brushInput; textOutput.Foreground = tabletRenderer.brushOutput; // Text font try { FontFamilyConverter fontConverter = new FontFamilyConverter(); FontFamily fontFamily = (FontFamily)fontConverter.ConvertFromString(config.TabletView.Font); textTabletInfo.FontFamily = fontFamily; textInput.FontFamily = fontFamily; textOutput.FontFamily = fontFamily; textLatency.FontFamily = fontFamily; } catch (Exception) { } // Font size textTabletInfo.FontSize = config.TabletView.FontSize; textInput.FontSize = config.TabletView.FontSize; textOutput.FontSize = config.TabletView.FontSize; textLatency.FontSize = config.TabletView.FontSize; // Info text textTabletInfo.Text = config.TabletName + " - " + Utils.GetNumberString(config.TabletAreas[0].Width) + " x " + Utils.GetNumberString(config.TabletAreas[0].Height) + " mm → " + Utils.GetNumberString(config.ScreenAreas[0].Width, "0") + " x " + Utils.GetNumberString(config.ScreenAreas[0].Height, "0") + " px"; // // Update/draw timer // timer = new MultimediaTimer { Interval = 2 }; timer.Tick += UpdateTimer_Tick; // Last values lastPosition = new Vector(0, 0); lastUpdate = DateTime.Now; lastPressure = 0; // Average values velocity = 0; latency = 0; // Input loss hadInputLoss = true; lastInputStartTime = DateTime.Now; // Window events Loaded += WindowTabletView_Loaded; Closing += WindowTabletView_Closing; KeyDown += WindowTabletView_KeyDown; MouseDown += WindowTabletView_MouseDown; MouseUp += WindowTabletView_MouseUp; // Set GC mode to low latency GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency; }
// // Send settings to the driver // public void SendToDriver(TabletDriver driver) { if (!driver.IsRunning) { return; } // Commands before settings if (CommandsBefore.Length > 0) { foreach (string command in CommandsBefore) { string tmp = command.Trim(); if (tmp.Length > 0) { driver.SendCommand(tmp); } } } // Desktop size driver.SendCommand("DesktopSize " + DesktopWidth + " " + DesktopHeight); // Screen area driver.SendCommand("ScreenArea " + Utils.GetNumberString(ScreenArea.Width) + " " + Utils.GetNumberString(ScreenArea.Height) + " " + Utils.GetNumberString(ScreenArea.X) + " " + Utils.GetNumberString(ScreenArea.Y) ); // // Tablet area // // Inverted if (Invert) { driver.SendCommand("TabletArea " + Utils.GetNumberString(TabletArea.Width) + " " + Utils.GetNumberString(TabletArea.Height) + " " + Utils.GetNumberString(TabletFullArea.Width - TabletArea.X) + " " + Utils.GetNumberString(TabletFullArea.Height - TabletArea.Y) ); driver.SendCommand("Rotate " + Utils.GetNumberString(TabletArea.Rotation + 180)); } // Normal else { driver.SendCommand("TabletArea " + Utils.GetNumberString(TabletArea.Width) + " " + Utils.GetNumberString(TabletArea.Height) + " " + Utils.GetNumberString(TabletArea.X) + " " + Utils.GetNumberString(TabletArea.Y) ); driver.SendCommand("Rotate " + Utils.GetNumberString(TabletArea.Rotation)); } // Output Mode switch (OutputMode) { case Configuration.OutputModes.Absolute: driver.SendCommand("Mode Absolute"); break; case Configuration.OutputModes.Relative: driver.SendCommand("Mode Relative"); driver.SendCommand("Sensitivity " + Utils.GetNumberString(ScreenArea.Width / TabletArea.Width)); break; case Configuration.OutputModes.Digitizer: driver.SendCommand("Mode Digitizer"); break; case Configuration.OutputModes.SendInput: driver.SendCommand("Mode sendinputabs"); break; } // Button map if (DisableButtons) { driver.SendCommand("ButtonMap 0 0 0"); } else { driver.SendCommand("ButtonMap " + String.Join(" ", ButtonMap)); } // Smoothing filter if (SmoothingEnabled) { driver.SendCommand("FilterTimerInterval " + Utils.GetNumberString(SmoothingInterval)); driver.SendCommand("Smoothing " + Utils.GetNumberString(SmoothingLatency)); } else { driver.SendCommand("Smoothing 0"); } // Noise filter if (NoiseFilterEnabled) { driver.SendCommand("Noise " + Utils.GetNumberString(NoiseFilterBuffer) + " " + Utils.GetNumberString(NoiseFilterThreshold)); } else { driver.SendCommand("Noise 0"); } // Anti-smoothing filter if (AntiSmoothingEnabled) { driver.SendCommand("AntiSmoothing " + Utils.GetNumberString(AntiSmoothingShape) + " " + Utils.GetNumberString(AntiSmoothingCompensation) + " " + (AntiSmoothingIgnoreWhenDragging ? "true" : "false")); } else { driver.SendCommand("AntiSmoothing 0"); } // Extra Buttons driver.SendCommand("Extra 0 " + ExtraButtonEvents[0].ToString() + " " + ExtraButtonEventTag[0]); driver.SendCommand("Extra 1 " + ExtraButtonEvents[1].ToString() + " " + ExtraButtonEventTag[1]); driver.SendCommand("Extra 2 " + ExtraButtonEvents[2].ToString() + " " + ExtraButtonEventTag[2]); // Commands after settings if (CommandsAfter.Length > 0) { foreach (string command in CommandsAfter) { string tmp = command.Trim(); if (tmp.Length > 0) { driver.SendCommand(tmp); } } } }