예제 #1
0
 private void InitializeComponent()
 {
     this._meterButtonRight  = new MeterButton();
     this._actionButton      = new ImageButton();
     this._meterButtonLeft   = new MeterButton();
     this._meterButtonTop    = new MeterButton();
     this._meterButtonBottom = new MeterButton();
     this.timer1             = new System.Windows.Forms.Timer();
     this.SuspendLayout();
     //
     // _meterButtonRight
     //
     this._meterButtonRight.Location = new System.Drawing.Point(332, 230);
     this._meterButtonRight.Name     = "_meterButtonRight";
     this._meterButtonRight.Size     = new System.Drawing.Size(115, 100);
     //
     // _actionButton
     //
     this._actionButton.Location = new System.Drawing.Point(180, 220);
     this._actionButton.Name     = "_actionButton";
     this._actionButton.Size     = new System.Drawing.Size(120, 120);
     this._actionButton.TabIndex = 0;
     //
     // _meterButtonLeft
     //
     this._meterButtonLeft.Location = new System.Drawing.Point(32, 230);
     this._meterButtonLeft.Name     = "_meterButtonLeft";
     this._meterButtonLeft.Size     = new System.Drawing.Size(115, 100);
     //
     // _meterButtonTop
     //
     this._meterButtonTop.Location = new System.Drawing.Point(190, 72);
     this._meterButtonTop.Name     = "_meterButtonTop";
     this._meterButtonTop.Size     = new System.Drawing.Size(100, 115);
     //
     // _meterButtonBottom
     //
     this._meterButtonBottom.Location = new System.Drawing.Point(190, 372);
     this._meterButtonBottom.Name     = "_meterButtonBottom";
     this._meterButtonBottom.Size     = new System.Drawing.Size(100, 115);
     //
     // timer1
     //
     this.timer1.Interval = 50;
     this.timer1.Tick    += new System.EventHandler(this.timer1_Tick);
     //
     // MouseControl
     //
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     this.Controls.Add(this._meterButtonBottom);
     this.Controls.Add(this._meterButtonTop);
     this.Controls.Add(this._meterButtonLeft);
     this.Controls.Add(this._meterButtonRight);
     this.Controls.Add(this._actionButton);
     this.Name = "MouseControl";
     this.Size = new System.Drawing.Size(480, 560);
     this.ResumeLayout(false);
 }
예제 #2
0
        private double _threshHold = 1; //2.0;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!this.HasFocus())
            {
                timer1.Enabled = false;
            }
            AccelerationVector vector = _gSensor.GetAccelerationVector();

            double maxValue = 9.8 - _threshHold;

            double xValue = Math.Abs(vector.X);

            Dictionary <MeterButton[], double> pairs = new Dictionary <MeterButton[], double>();

            pairs.Add(new MeterButton[] { _meterButtonLeft, _meterButtonRight }, vector.X);
            pairs.Add(new MeterButton[] { _meterButtonTop, _meterButtonBottom }, vector.Y);

            foreach (MeterButton[] pair in pairs.Keys)
            {
                double vectorValue = pairs[pair];
                double scalarValue = Math.Abs(vectorValue);

                if (scalarValue >= _threshHold)
                {
                    MeterButton button    = (vectorValue < 0) ? pair[0] : pair[1];
                    MeterButton offButton = (vectorValue < 0) ? pair[1] : pair[0];

                    scalarValue = scalarValue - _threshHold;

                    int    count    = button.MeterCount;
                    double interval = maxValue / count;

                    double testValue = 0;
                    int    index     = 0;

                    for (int i = 0; i < count; ++i)
                    {
                        if (scalarValue > testValue)
                        {
                            index      = i;
                            testValue += interval;
                        }
                        else
                        {
                            break;
                        }
                    }

                    button.MeterAmount    = index;
                    offButton.MeterAmount = 0;
                }
                else
                {
                    pair[0].MeterAmount = pair[1].MeterAmount = 0;
                }
            }

            short dx = 0, dy = 0;
            int   xMeter = 0, yMeter = 0;

            if (_meterButtonBottom.MeterAmount > 0)
            {
                dy     = 1;
                yMeter = _meterButtonBottom.MeterAmount;
            }
            if (_meterButtonTop.MeterAmount > 0)
            {
                dy     = -1;
                yMeter = _meterButtonTop.MeterAmount;
            }
            if (_meterButtonRight.MeterAmount > 0)
            {
                dx     = 1;
                xMeter = _meterButtonRight.MeterAmount;
            }
            if (_meterButtonLeft.MeterAmount > 0)
            {
                dx     = -1;
                xMeter = _meterButtonLeft.MeterAmount;
            }

            if (dx != 0 || dy != 0)
            {
                MoveMouse(dx, dy, xMeter, yMeter);
            }
        }