Ejemplo n.º 1
0
    void ChangeViewportScale(ScaleControl control, float dz)
    {
        // 以鼠标的竖直位置为缩放中心.
        var centerScreen = (rect.worldToLocalMatrix * Input.mousePosition).y;
        // 换坐标系, 从上往下.
        var centerScreenLocal = rect.rect.height - centerScreen;
        // 算出比例.
        var rate = centerScreenLocal / rect.rect.height;
        // 算出轴上对应点.
        var center = rate * (control.endPoint - control.beginPoint) + control.beginPoint;

        float nextBegin = 0, nextEnd = 0;

        if (dz < 0)
        {
            nextBegin = (control.beginPoint - center) * scaleSpeed + center;
            nextEnd   = (control.endPoint - center) * scaleSpeed + center;
        }
        else if (dz > 0)
        {
            nextBegin = (control.beginPoint - center) / scaleSpeed + center;
            nextEnd   = (control.endPoint - center) / scaleSpeed + center;
        }

        control.beginPoint = nextBegin;
        control.endPoint   = nextEnd;
    }
Ejemplo n.º 2
0
    private void OnEnable()
    {
        this.transform.localScale = Vector3.one * kScale;
        ScaleControl scaleControl = GameObject.Find("ScaleControl").GetComponent <ScaleControl>();

        scaleControl.SetTargetModel(this.transform);
        scaleControl.OnValueChanged(kScale);
    }
Ejemplo n.º 3
0
    void ChangeViewportPos(ScaleControl control, float dz)
    {
        var delta = -dz * moveSpeed / rect.rect.height * (control.endPoint - control.beginPoint);

        if (control.beginPoint + delta < 0)
        {
            delta = delta.ClampAbs(control.beginPoint);
        }
        if (control.endPoint + delta > 1)
        {
            delta = delta.ClampAbs(1 - control.endPoint);
        }
        control.beginPoint += delta;
        control.endPoint   += delta;
    }
Ejemplo n.º 4
0
    /**
     * Apply the given tool to the given GameObject.
     */
    private void SetupToolOnObj(GameObject obj, Tool tool)
    {
        switch (tool)
        {
        case Tool.ADD:
        case Tool.REMOVE:
            toolObj = Instantiate(toolPrefab);
            break;

        case Tool.POSITION:
            if (selectedObj != null)
            {
                toolObj = Instantiate(toolPrefab, obj.transform.position, Quaternion.identity);
                PositionControl positionControl = toolObj.GetComponent <PositionControl>();
                positionControl.LinkObject(selectedObj);
            }
            break;

        case Tool.ROTATION:
            if (selectedObj != null)
            {
                toolObj = Instantiate(toolPrefab, obj.transform.position, obj.transform.rotation);
                RotationControl rotationControl = toolObj.GetComponent <RotationControl>();
                rotationControl.LinkObject(selectedObj);
            }
            break;

        case Tool.SCALE:
            if (selectedObj != null)
            {
                toolObj = Instantiate(toolPrefab, obj.transform.position, obj.transform.rotation);
                ScaleControl scaleControl = toolObj.GetComponent <ScaleControl>();
                scaleControl.LinkObject(selectedObj);
            }
            break;

        case Tool.TEXT:
            if (selectedObj != null)
            {
                labelPanel.SetActive(true);
            }
            break;
        }
    }
Ejemplo n.º 5
0
    /**
     * Apply the given tool to the given GameObject.
     */
    private void SetupToolOnObj(GameObject obj, Tool tool)
    {
        switch (tool)
        {
        case Tool.POSITION:
            toolObj = Instantiate(toolPrefab, obj.transform.position, Quaternion.identity);
            PositionControl positionControl = toolObj.GetComponent <PositionControl>();
            positionControl.LinkObject(selectedObj);
            break;

        case Tool.ROTATION:
            toolObj = Instantiate(toolPrefab, obj.transform.position, obj.transform.rotation);
            RotationControl rotationControl = toolObj.GetComponent <RotationControl>();
            rotationControl.LinkObject(selectedObj);
            break;

        case Tool.SCALE:
            toolObj = Instantiate(toolPrefab, obj.transform.position, obj.transform.rotation);
            ScaleControl scaleControl = toolObj.GetComponent <ScaleControl>();
            scaleControl.LinkObject(selectedObj);
            break;
        }
    }
Ejemplo n.º 6
0
		public void GetScaledBoundsTest ()
		{
			ScaleControl c = new ScaleControl ();
			
			Rectangle r = new Rectangle (10, 20, 30, 40);

			Assert.AreEqual (new Rectangle (20, 10, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
			Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
			Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
			Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
			Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
			Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
			
			c.PublicSetTopLevel (true);

			Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A7");
			Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A8");
			Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A9");
			Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A10");
			Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A11");
			Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A12");

			c = new ScaleControl ();
			c.PublicSetStyle (ControlStyles.FixedHeight, true);
			c.PublicSetStyle (ControlStyles.FixedWidth, true);

			Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A13");
			Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A14");
			Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A15");
			Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A16");
			Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A17");
			Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A18");
		}
Ejemplo n.º 7
0
		public void ScaleControlTest ()
		{
			ScaleControl c = new ScaleControl ();
			
			c.Location = new Point (5, 10);
			c.Size = new Size (15, 20);
			
			Assert.AreEqual (new Rectangle (5, 10, 15, 20), c.Bounds, "A1");

			c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.All);
			Assert.AreEqual (new Rectangle (8, 13, 22, 26), c.Bounds, "A2");

			c.PublicScaleControl (new SizeF (2f, 1.5f), BoundsSpecified.Location);
			Assert.AreEqual (new Rectangle (16, 20, 22, 26), c.Bounds, "A3");

			c.PublicScaleControl (new SizeF (1.5f, 2f), BoundsSpecified.Size);
			Assert.AreEqual (new Rectangle (16, 20, 33, 52), c.Bounds, "A4");

			c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.Width);
			Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A5");

			c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.None);
			Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A6");
			
			// Test with ScaleChildren
			c = new ScaleControl ();

			c.Location = new Point (5, 10);
			c.Size = new Size (50, 50);
			
			Control c2 = new Control ();
			c2.Location = new Point (15, 15);
			c2.Size = new Size (25, 25);
			c.Controls.Add (c2);

			Assert.AreEqual (new Rectangle (5, 10, 50, 50), c.Bounds, "B1");
			Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B2");

			c.scale_children = false;

			c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
			Assert.AreEqual (new Rectangle (10, 20, 100, 100), c.Bounds, "B3");
			Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B4");

			c.scale_children = true;

			// Will not scale children in ScaleControl
			c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
			Assert.AreEqual (new Rectangle (20, 40, 200, 200), c.Bounds, "B5");
			Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B6");
			
			// Does scale children in Scale
			c.Scale (new SizeF (2f, 2f));
			Assert.AreEqual (new Rectangle (40, 80, 400, 400), c.Bounds, "B7");
			Assert.AreEqual (new Rectangle (30, 30, 50, 50), c2.Bounds, "B8");
		}
Ejemplo n.º 8
0
        private void Loading()
        {
            _tp = _ge.testsparams.First(t => t.idt == _testid);
            switch (_testid)
            {
            case (int)EnumPTests.KettellC:    //TODO:это все поместить в фабрику отчетов с функцие добавления пустых ответов
                //create fool kettellanswers
                KettellAnswers ka = new KettellAnswers();
                for (int a = 0; a < 104; a++)
                {
                    ka.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializer = new XmlSerializer(typeof(KettellAnswers));
                StringWriter  myWriter     = new StringWriter();
                mySerializer.Serialize(myWriter, ka);
                _human = _fe.humans.First(h => h.idh == _humanid);
                KettellCTestReport kcr = new KettellCTestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.KettellC, myWriter.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < kcr.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = kcr.ListScales[i];
                }
                break;

            case (int)EnumPTests.PNN:
                PNNAnswers pa = new PNNAnswers();
                for (int a = 0; a < 104; a++)
                {
                    pa.Add(PnnSignalType.Green, PnnKeyType.AnyKey, DateTime.Now, 0);
                }
                XmlSerializer mySerializerp = new XmlSerializer(typeof(PNNAnswers));
                StringWriter  myWriterp     = new StringWriter();
                mySerializerp.Serialize(myWriterp, pa);
                _human = _fe.humans.First(h => h.idh == _humanid);
                PNNTestReport pnr = new PNNTestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.PNN, myWriterp.ToString(), "manual"), _ge, _fe);
                for (int i = 0; i < pnr.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = pnr.ListScales[i];
                }
                break;

            case (int)EnumPTests.Adaptability:
                DAnswers kd = new DAnswers();
                for (int a = 0; a < 165; a++)
                {
                    kd.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializerd = new XmlSerializer(typeof(DAnswers));
                StringWriter  myWriterd     = new StringWriter();
                mySerializerd.Serialize(myWriterd, kd);
                _human = _fe.humans.First(h => h.idh == _humanid);
                DTestReport kdr = new DTestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.Adaptability, myWriterd.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < kdr.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = kdr.ListScales[i];
                }
                break;

            case (int)EnumPTests.FPI:
                FPIAnswers kfpi = new FPIAnswers();
                for (int a = 0; a < 114; a++)
                {
                    kfpi.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializerfpi = new XmlSerializer(typeof(FPIAnswers));
                StringWriter  myWriterfpi     = new StringWriter();
                mySerializerfpi.Serialize(myWriterfpi, kfpi);
                _human = _fe.humans.First(h => h.idh == _humanid);
                FPITestReport kfr = new FPITestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.FPI, myWriterfpi.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < kfr.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = kfr.ListScales[i];
                }
                break;

            case (int)EnumPTests.KettellA:
                KettellAnswers kaa = new KettellAnswers();
                for (int a = 0; a < 185; a++)
                {
                    kaa.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializera = new XmlSerializer(typeof(KettellAnswers));
                StringWriter  myWritera     = new StringWriter();
                mySerializera.Serialize(myWritera, kaa);
                _human = _fe.humans.First(h => h.idh == _humanid);
                KettellATestReport kar = new KettellATestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.KettellA, myWritera.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < kar.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = kar.ListScales[i];
                }
                break;

            case (int)EnumPTests.Contrasts:
                ContrastsAnswers mkd = new ContrastsAnswers();
                for (int a = 0; a < 6; a++)
                {
                    mkd.Add(DateTime.Now, 0);
                }
                XmlSerializer mySerializermd = new XmlSerializer(typeof(ContrastsAnswers));
                StringWriter  myWritermd     = new StringWriter();
                mySerializermd.Serialize(myWritermd, mkd);
                _human = _fe.humans.First(h => h.idh == _humanid);
                ContrastsTestReport mkdr = new ContrastsTestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.Contrasts, myWritermd.ToString(), "manual"), _ge, _fe);
                for (int i = 0; i < mkdr.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = mkdr.ListScales[i];
                }
                break;

            case (int)EnumPTests.Prognoz:
                PAnswers paa = new PAnswers();
                for (int a = 0; a < 86; a++)
                {
                    paa.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializerpr = new XmlSerializer(typeof(PAnswers));
                StringWriter  myWriterpr     = new StringWriter();
                mySerializerpr.Serialize(myWriterpr, paa);
                _human = _fe.humans.First(h => h.idh == _humanid);
                PTestReport par = new PTestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.Prognoz, myWriterpr.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < par.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = par.ListScales[i];
                }
                break;

            case (int)EnumPTests.Addictive:
                AAnswers aaa = new AAnswers();
                for (int a = 0; a < 30; a++)
                {
                    aaa.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializeraa = new XmlSerializer(typeof(AAnswers));
                StringWriter  myWriteraa     = new StringWriter();
                mySerializeraa.Serialize(myWriteraa, aaa);
                _human = _fe.humans.First(h => h.idh == _humanid);
                ATestReport aar = new ATestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.Addictive, myWriteraa.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < aar.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = aar.ListScales[i];
                }
                break;

            case (int)EnumPTests.NPNA:
                NPNAnswers npn = new NPNAnswers();
                for (int a = 0; a < 276; a++)
                {
                    npn.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializernpn = new XmlSerializer(typeof(NPNAnswers));
                StringWriter  myWriternpn     = new StringWriter();
                mySerializernpn.Serialize(myWriternpn, npn);
                _human = _fe.humans.First(h => h.idh == _humanid);
                NPNTestReport npnr = new NPNTestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.NPNA, myWriternpn.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < npnr.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = npnr.ListScales[i];
                }
                break;

            case (int)EnumPTests.Leongard:
                LAnswers lpn = new LAnswers();
                for (int a = 0; a < 88; a++)
                {
                    lpn.Add(0, "", "", a, "");
                }
                XmlSerializer mySerializerlpn = new XmlSerializer(typeof(LAnswers));
                StringWriter  myWriterlpn     = new StringWriter();
                mySerializerlpn.Serialize(myWriterlpn, lpn);
                _human = _fe.humans.First(h => h.idh == _humanid);
                LTestReport lpnr = new LTestReport(_human, testresult.Createtestresult(0, _humanid, DateTime.Now, (int)EnumPTests.Leongard, myWriterlpn.ToString(), "manual"), _ge, _fe, true);
                for (int i = 0; i < lpnr.ListScales.Count(); i++)
                {
                    ScaleControl sc = new ScaleControl();
                    this.flp_parent.Controls.Add(sc);
                    sc.ControlScale = lpnr.ListScales[i];
                }
                break;
            }
        }