Example #1
0
        //
        // Constructor
        //
        public TabletDriver(string servicePath, AreaRandomizer randomizer)
        {
            this.servicePath       = servicePath;
            processService         = null;
            DoNotKill              = false;
            timerWatchdog          = new Timer(2000);
            timerWatchdog.Elapsed += TimerWatchdog_Elapsed;

            ConsoleMaxLines    = 300;
            ConsoleBuffer      = new List <string>(ConsoleMaxLines);
            mutexConsoleUpdate = new System.Threading.Mutex();

            commands = new Dictionary <string, string>();

            messageBuilder = new StringBuilder();

            pipeInput  = new NamedPipeClient("TabletDriverOutput");
            pipeOutput = new NamedPipeClient("TabletDriverInput");
            pipeState  = new NamedPipeClient("TabletDriverState");

            stateBytes = new byte[Marshal.SizeOf(typeof(TabletState))];
            pipeInput.MessageReceived += PipeInput_MessageReceived;
            pipeState.MessageReceived += PipeState_MessageReceived;

            pipeInput.Connected  += (snd, e) => { pipeInput.WriteMessage("\n"); };
            pipeOutput.Connected += (snd, e) =>
            {
                pipeOutput.WriteMessage("\n");
            };
            pipeState.Connected += (snd, e) => { pipeState.WriteMessage("\n"); };


            // Invoke driver started event
            Started?.Invoke(this, new EventArgs());

            this.randomizer = randomizer;
        }
Example #2
0
        //
        // 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>();

            randomizer = new AreaRandomizer();
            // Init tablet driver
            driver                  = new TabletDriver("TabletDriverService.exe", randomizer);
            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;

            // Timer randomizer area update
            timerAreaUpdate = new DispatcherTimer
            {
                Interval = new TimeSpan(0, 0, 0, 0, 200)
            };
            timerAreaUpdate.Tick += TimerAreaUpdate_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;
        }