Exemplo n.º 1
0
        public MainForm(string[] args)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            // lock width
            MaximumSize = new Size(Size.Width, 10000);
            MinimumSize = new Size(Size.Width, Size.Height);

            Instance = this;

            Channels = new int[256];

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                vJoyEnumerator = (VJoyCollectionBase)Activator.CreateInstance(Type.GetType("vJoySerialFeeder.VJoyCollectionWindows"));
                break;

            case PlatformID.Unix:
                vJoyEnumerator = (VJoyCollectionBase)Activator.CreateInstance(Type.GetType("vJoySerialFeeder.VJoyCollectionLinux"));
                break;

            default:
                ErrorMessageBox("Unsupported platform", "Fatal");
                Application.Exit();
                break;
            }

            comboPorts.FormattingEnabled = true;
            comboPorts.Format           += (o, e) =>
            {
                // strip /dev/ on Linux, to be more compact
                e.Value = e.Value.ToString().Replace("/dev/", "");
            };
            reloadComPorts();
            reloadJoysticks();
            ChannelDataUpdate += onChannelDataUpdate;

            config = Configuration.Load();

            reloadProfiles();

            var defaultProfile = config.GetProfile(config.DefaultProfile);

            if (defaultProfile == null && comboProfiles.Items.Count > 0)
            {
                var first = comboProfiles.Items[0].ToString();
                defaultProfile     = config.GetProfile(first);
                comboProfiles.Text = first;
            }

            if (defaultProfile != null)
            {
                comboProfiles.Text = config.DefaultProfile;
                loadProfile(defaultProfile);
            }
            else
            {
                resetProfile();
            }

            toolStripStatusLabel.Text = "Disconnected";

            // initialize COM on windows platforms
            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                comAutomation = ComAutomation.GetInstance();
            }

            if (System.Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                // hide the Game Controllers shortcut on non-windows platforms
                menuGameControllers.Visible = false;
            }

            reloadGlobalOptions();

            // autoconnect
            if (config.Autoconnect)
            {
                connect();
            }
        }
Exemplo n.º 2
0
        private void initializePanel()
        {
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                vJoyEnumerator = (VJoyCollectionBase)Activator.CreateInstance(Type.GetType("vJoySerialFeeder.VJoyCollectionWindows"));
                break;

            case PlatformID.Unix:
                vJoyEnumerator = (VJoyCollectionBase)Activator.CreateInstance(Type.GetType("vJoySerialFeeder.VJoyCollectionLinux"));
                break;

            default:
                ErrorMessageBox("Unsupported platform", "Fatal");
                Application.Exit();
                break;
            }

            panel = new FlowLayoutPanel();
            panel.SuspendLayout();
            panel.Size = new Size(670, 30);

            var label = new Label();

            label.Text      = "Channel:";
            label.Size      = new Size(52, 20);
            label.TextAlign = ContentAlignment.MiddleLeft;
            panel.Controls.Add(label);

            channelSpinner               = new NumericUpDown();
            channelSpinner.Minimum       = 0;
            channelSpinner.Maximum       = 255;
            channelSpinner.Size          = new Size(42, 20);
            channelSpinner.Value         = Channel + 1;
            channelSpinner.ValueChanged += onChannelChange;
            panel.Controls.Add(channelSpinner);

            label           = new Label();
            label.Text      = "Button:";
            label.Size      = new Size(42, 20);
            label.TextAlign = ContentAlignment.MiddleLeft;
            panel.Controls.Add(label);

            buttonSpinner               = new NumericUpDown();
            buttonSpinner.Minimum       = 0;
            buttonSpinner.Maximum       = 128;
            buttonSpinner.Size          = new Size(42, 20);
            buttonSpinner.Value         = Button + 1;
            buttonSpinner.ValueChanged += onButtonChange;
            panel.Controls.Add(buttonSpinner);


            label           = new Label();
            label.Text      = "Input:";
            label.Size      = new Size(42, 20);
            label.TextAlign = ContentAlignment.MiddleLeft;
            panel.Controls.Add(label);

            inputLabel           = new Label();
            inputLabel.Text      = "-";
            inputLabel.Size      = new Size(42, 20);
            inputLabel.TextAlign = ContentAlignment.MiddleLeft;
            panel.Controls.Add(inputLabel);

            label           = new Label();
            label.Text      = "Output:";
            label.Size      = new Size(42, 20);
            label.TextAlign = ContentAlignment.MiddleLeft;
            panel.Controls.Add(label);

            buttonStateBox        = new PictureBox();
            buttonStateBox.Size   = new Size(80, 20);
            buttonStateBox.Paint += onButtonStatePaint;
            panel.Controls.Add(buttonStateBox);

            var button = new Button();

            button.Text   = "Setup";
            button.Click += onSetupClick;
            button.Size   = new Size(50, 20);
            panel.Controls.Add(button);

            button        = new Button();
            button.Text   = "Remove";
            button.Click += onRemoveClick;
            button.Size   = new Size(55, 20);
            panel.Controls.Add(button);

            joystickDropDown = new ComboBox();
            joystickDropDown.DropDownStyle = ComboBoxStyle.DropDownList;
            joystickDropDown.Size          = new Size(72, 20);
            joystickDropDown.Items.AddRange(vJoyEnumerator.GetJoysticks());
            joystickDropDown.SelectedIndex         = Joystick;
            joystickDropDown.SelectedIndexChanged += onJoystickChange;
            panel.Controls.Add(joystickDropDown);

            panel.ResumeLayout();
        }