Ejemplo n.º 1
0
    protected override void Init()
    {
        base.Init();

        //get a reference to our input controller
        playerInputController = new PlayerInputController();
        playerInputController.playerCharacter = this;

        //Create our state controller to manage all our states
        playerStateController = new PlayerStateController(this);
        //init player to idle
        TransitionState(PlayerStates.SpearIdle);

        //get our hurtboxes
        hurtBoxController = GetComponentInChildren <HurtBoxController>();

        //get our blocking box and set to unactive
        blockBox = GetComponentInChildren <BlockBox>();
        blockBox.ToggleActive(false);

        //calculate gravity
        gravity         = -(2 * maxJumpHeight) / Mathf.Pow(timeToJumpApex, 2);
        maxJumpVelocity = Mathf.Abs(gravity) * timeToJumpApex;
        minJumpVelocity = Mathf.Sqrt(2 * Mathf.Abs(gravity) * minJumpHeight);
    }
Ejemplo n.º 2
0
        public void OrcBoxRun()
        {
            // Run 0
            string part0 = "abc";
            string part1 = "\xfffc";
            string part2 = "defg";

            AssembledStyles styles     = new AssembledStyles().WithWs(wsEn);
            StringClientRun clientRun0 = new StringClientRun(part0 + part1 + part2, styles);
            var             clientRuns = new List <IClientRun>();

            clientRuns.Add(clientRun0);

            BlockBox box = new BlockBox(styles.WithWs(wsFrn), Color.Red, 72000, 36000);

            TextSource source = new TextSource(clientRuns, (run, offset) => box);

            MapRun[] runs = source.Runs;
            Assert.AreEqual(3, runs.Length);
            VerifyRun(0, clientRun0, 0, 0, part0, runs[0], "first run of complex source with box");
            int len = part0.Length;

            VerifyRun(len, box, len, part0.Length, part1, runs[1], "2nd run of complex source with box");
            len += 1;
            VerifyRun(len, clientRun0, len, part0.Length + 1, part2, runs[2], "3rd run of complex source with box");
            len += part2.Length;
            Assert.AreEqual(len, source.Length, "length of complex source with box");
            VerifyCharProps(source, part0.Length, wsFrn, part0.Length, part0.Length + 1, "props of box");
        }
Ejemplo n.º 3
0
        public void PileOfBlocksLayout()
        {
            var      styles = new AssembledStyles();
            BlockBox box1   = new BlockBox(styles, Color.Red, 72000, 36000);
            BlockBox box2   = new BlockBox(styles, Color.Blue, 108000, 18000);
            BlockBox box3   = new BlockBox(styles, Color.Orange, 72000, 18000);
            RootBox  root   = new RootBox(styles);

            root.AddBox(box1);
            root.AddBox(box2);
            root.AddBox(box3);
            LayoutInfo layoutArgs = MakeLayoutInfo();

            root.Layout(layoutArgs);
            Assert.That(box1.Height, Is.EqualTo(48));
            Assert.That(box2.Height, Is.EqualTo(24));
            Assert.That(root.Height, Is.EqualTo(48 + 24 + 24));
            Assert.That(box1.Left, Is.EqualTo(0));
            Assert.That(box2.Left, Is.EqualTo(0));
            Assert.That(box1.Top, Is.EqualTo(0));
            Assert.That(box2.Top, Is.EqualTo(48));
            Assert.That(box3.Top, Is.EqualTo(48 + 24));
            Assert.That(box1.Width, Is.EqualTo(96));
            Assert.That(box2.Width, Is.EqualTo(144));
            Assert.That(root.Width, Is.EqualTo(144));
        }
Ejemplo n.º 4
0
		public void PaintParaBox()
		{
			AssembledStyles styles = new AssembledStyles();
			var clientRuns = new List<IClientRun>();
			BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box0);
			BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000);
			clientRuns.Add(box1);
			BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000);
			clientRuns.Add(box2);
			BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box3);
			BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000);
			clientRuns.Add(box4);

			TextSource source = new TextSource(clientRuns, null);
			ParaBox para = new ParaBox(styles, source);
			RootBox root = new RootBox(styles);
			root.AddBox(para);

			MockGraphics graphics = new MockGraphics();
			LayoutInfo layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);
			root.Layout(layoutArgs);

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			root.Paint(graphics, ptrans);
			Assert.AreEqual(5, graphics.RectanglesDrawn.Count);
			VerifyRect(2, 2, 96, 48, graphics, 0, Color.Red);
			VerifyRect(2, 48+2, 48, 24, graphics, 1, Color.Blue);
			VerifyRect(2+48, 48 + 2, 32, 24, graphics, 2, Color.Red);
			VerifyRect(2, 24 + 48 + 2, 96, 48, graphics, 3, Color.Red);
			VerifyRect(2, 48 + 24 + 48 + 2, 48, 48, graphics, 4, Color.Red);
		}
Ejemplo n.º 5
0
        public void InsertCharInEmptyLine()
        {
            string contents = "";
            var    engine   = new FakeRenderEngine()
            {
                Ws = 34, SegmentHeight = 13
            };
            var factory = new FakeRendererFactory();

            factory.SetRenderer(34, engine);
            var styles     = new AssembledStyles().WithWs(34);
            var clientRuns = new List <IClientRun>();
            var run        = new StringClientRun(contents, styles);

            clientRuns.Add(run);
            var data1 = new MockData1(34, 35);

            data1.SimpleThree = contents;
            var source = new TextSource(clientRuns, null);
            var para   = new ParaBox(styles, source);
            var hookup = new StringHookup(this, () => data1.SimpleThree, hook => data1.SimpleThreeChanged += hook.StringPropChanged,
                                          hook => data1.SimpleThreeChanged -= hook.StringPropChanged, para);

            hookup.Writer = newVal => data1.SimpleThree = newVal;
            run.Hookup    = hookup;
            var root  = new RootBox(styles);
            var block = new BlockBox(styles, Color.Red, 20000, 10000);

            root.AddBox(block);
            root.AddBox(para);
            var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);

            root.Layout(layoutArgs);
            Assert.That(root.Height, Is.EqualTo(13 + block.Height));
            Assert.That(para.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents)));
            Assert.That(root.Width, Is.EqualTo(block.Width));
            int simulatedWidth = FakeRenderEngine.SimulatedWidth("x");

            Assert.That(root.Width, Is.GreaterThan(para.Width + simulatedWidth));
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);
            MockSite       site   = new MockSite();

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            root.Site         = site;
            var oldRootWidth = root.Width;

            var ip = root.SelectAtEnd();

            ip.InsertText("x");
            Assert.That(root.Height, Is.EqualTo(13 + block.Height));
            Assert.That(root.Width, Is.EqualTo(oldRootWidth));
            Assert.That(para.Width, Is.EqualTo(simulatedWidth));
            var expectedInvalidate = new Rectangle(-RootBox.InvalidateMargin,
                                                   -RootBox.InvalidateMargin + block.Height,
                                                   simulatedWidth + RootBox.InvalidateMargin * 2,
                                                   13 + 2 * RootBox.InvalidateMargin);

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate));
        }
Ejemplo n.º 6
0
        public void PrepareRowFixupMap()
        {
            var styles = new AssembledStyles();
            var row    = new FixedSizeRow(styles, new FixedColumnWidths(new[] { 12 }), 27, 37);
            var root   = new FixedSizeRoot(styles, 49, 59);
            var block  = new BlockBox(styles, Color.Red, 6000, 8000);

            row.AddBox(block);
            root.AddBox(row);
            row.Left   = 5;
            row.Top    = 7;
            block.Left = 10;
            block.Top  = 20;
            var transform = new LayoutInfo(0, 0, 72, 72, 1000, m_gm.VwGraphics, new MockRendererFactory());

            block.Layout(transform);
            //Assert.AreEqual(6, block.Width); // sanity check: we made it 4000 mp wide at 72 dpi, that's 4 points at one point per dot
            var map         = block.PrepareFixupMap();
            var invalidRect = map[block];

            Assert.AreEqual(new Rectangle(5 + 10 - 2, 7 + 20 - 2, 6 + 4, 8 + 4), invalidRect);
            invalidRect = map[row];
            Assert.AreEqual(new Rectangle(5 - 2, 7 - 2, 27 + 4, 37 + 4), invalidRect);
            invalidRect = map[root];
            Assert.AreEqual(new Rectangle(-2, -2, 49 + 4, 59 + 4), invalidRect);
        }
Ejemplo n.º 7
0
        private void InitRedBox()
        {
            AssembledStyles styles = new AssembledStyles();
            RootBox         root   = new RootBox(styles);
            BlockBox        block  = new BlockBox(styles, Color.Red, 72000, 36000);

            root.AddBox(block);
            theSharpView.Root = root;
        }
Ejemplo n.º 8
0
		public void MakeBlockBox()
		{
			AssembledStyles styles = new AssembledStyles();
			BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);

			LayoutInfo transform = MakeLayoutInfo();
			box.Layout(transform);
			Assert.AreEqual(48, box.Height);
			Assert.AreEqual(96, box.Width);
		}
Ejemplo n.º 9
0
        public void MakeBlockBox()
        {
            AssembledStyles styles = new AssembledStyles();
            BlockBox        box    = new BlockBox(styles, Color.Red, 72000, 36000);

            LayoutInfo transform = MakeLayoutInfo();

            box.Layout(transform);
            Assert.AreEqual(48, box.Height);
            Assert.AreEqual(96, box.Width);
        }
Ejemplo n.º 10
0
		public void DragStartsOnMoveInSelection()
		{
			string contents = "This is the day.";
			var engine = new FakeRenderEngine() {Ws = 34, SegmentHeight = 13};
			var factory = new FakeRendererFactory();
			factory.SetRenderer(34, engine);
			var styles = new AssembledStyles().WithWs(34);
			var clientRuns = new List<IClientRun>();
			var run = new StringClientRun(contents, styles);
			clientRuns.Add(run);
			var source = new TextSource(clientRuns, null);
			var para = new ParaBox(styles, source);
			var extraBox = new BlockBox(styles, Color.Red, 50, 72000); // tall, narrow spacer at top
			var root = new RootBoxFdo(styles);
			root.AddBox(extraBox);
			root.AddBox(para);
			var layoutArgs = MakeLayoutInfo(Int32.MaxValue/2, m_gm.VwGraphics, factory);
			root.Layout(layoutArgs);
			Assert.That(root.Height, Is.EqualTo(96 + 13));
			Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents)));

			var ip1 = run.SelectAt(para, 5, false);
			var ip2 = run.SelectAt(para, 7, true);
			var range = new RangeSelection(ip1, ip2);
			range.Install();
			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			var sbox = para.FirstBox as StringBox;
			MockSite site = new MockSite();
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			root.Site = site;
			int indent = FakeRenderEngine.SimulatedWidth("This ");
			root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans);
			root.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans);
			Assert.That(GetStringDropData(site), Is.EqualTo("is"));
			Assert.That(site.LastDoDragDropArgs.AllowedEffects, Is.EqualTo(DragDropEffects.Copy),
				"editing not possible in this paragraph, we can only copy");
			Assert.That(root.Selection, Is.EqualTo(range), "selection should not be changed by drag drop");
			site.LastDoDragDropArgs = null;
			root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 3, 100, 0), Keys.None, m_gm.VwGraphics, ptrans);
			Assert.That(site.LastDoDragDropArgs, Is.Null, "click outside selection should not initiate drag");

			// Tack on an extra check that a read-only view does not handle drop.
			var dataObj = new DataObject(DataFormats.StringFormat, "new ");
			var dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.ControlKey, 10, 8,
				DragDropEffects.Copy | DragDropEffects.Move,
				DragDropEffects.None);
			root.OnDragEnter(dragArgs, new Point(14, 8), m_gm.VwGraphics, ptrans);
			Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None));
			Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere));
		}
Ejemplo n.º 11
0
		public void MakeRootBox()
		{
			AssembledStyles styles = new AssembledStyles();
			BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);

			RootBox root = new RootBox(styles);
			root.AddBox(box);
			LayoutInfo transform = MakeLayoutInfo();
			root.Layout(transform);

			Assert.AreEqual(48, box.Height);
			Assert.AreEqual(96, box.Width);
			Assert.AreEqual(48, root.Height);
			Assert.AreEqual(96, root.Width);

		}
Ejemplo n.º 12
0
		public void PaintBarBox()
		{
			AssembledStyles styles = new AssembledStyles();
			BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);

			RootBox root = new RootBox(styles);
			root.AddBox(box);
			LayoutInfo transform = MakeLayoutInfo();
			root.Layout(transform);

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			MockGraphics graphics = new MockGraphics();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(1, graphics.RectanglesDrawn.Count);
			Assert.AreEqual(new Rectangle(2, 2, 96, 48), graphics.RectanglesDrawn[0]);
			Assert.AreEqual((int)ColorUtil.ConvertColorToBGR(Color.Red), graphics.BackColor);
		}
Ejemplo n.º 13
0
        public void MakeRootBox()
        {
            AssembledStyles styles = new AssembledStyles();
            BlockBox        box    = new BlockBox(styles, Color.Red, 72000, 36000);

            RootBox root = new RootBox(styles);

            root.AddBox(box);
            LayoutInfo transform = MakeLayoutInfo();

            root.Layout(transform);

            Assert.AreEqual(48, box.Height);
            Assert.AreEqual(96, box.Width);
            Assert.AreEqual(48, root.Height);
            Assert.AreEqual(96, root.Width);
        }
Ejemplo n.º 14
0
		public void OneBlockPara()
		{
			AssembledStyles styles = new AssembledStyles();
			List<IClientRun> clientRuns = new List<IClientRun>();
			BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box);

			TextSource source = new TextSource(clientRuns, null);
			ParaBox para = new ParaBox(styles, source);
			RootBox root = new RootBox(styles);
			root.AddBox(para);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			Assert.AreEqual(48, box.Height);
			Assert.AreEqual(96, box.Width);
			Assert.AreEqual(48, root.Height);
			Assert.AreEqual(96, root.Width);
		}
Ejemplo n.º 15
0
        public void NextAndPrevInSelectionSeq()
        {
            var styles = new AssembledStyles();
            var root   = new RootBox(styles);

            Assert.That(root.NextInSelectionSequence(true), Is.Null);
            Assert.That(root.PreviousInSelectionSequence, Is.Null);
            var block = new BlockBox(styles, Color.Red, 6000, 6000);

            root.AddBox(block);
            Assert.That(root.NextInSelectionSequence(true), Is.EqualTo(block));
            Assert.That(block.PreviousInSelectionSequence, Is.EqualTo(root));
            var div = new DivBox(styles);

            root.AddBox(div);
            Assert.That(block.NextInSelectionSequence(true), Is.EqualTo(div));
            Assert.That(div.PreviousInSelectionSequence, Is.EqualTo(block));
            var divChild = new DivBox(styles);

            div.AddBox(divChild);
            var block2 = new BlockBox(styles, Color.Red, 6000, 6000);

            divChild.AddBox(block2);
            var block3 = new BlockBox(styles, Color.Red, 6000, 6000);

            divChild.AddBox(block3);
            var block4 = new BlockBox(styles, Color.Red, 6000, 6000);

            div.AddBox(block4);
            // up and forward
            Assert.That(block3.NextInSelectionSequence(true), Is.EqualTo(block4));
            Assert.That(block4.PreviousInSelectionSequence, Is.EqualTo(block3));
            // Can go back from a box to a previous empty group
            var emptyDiv = new DivBox(styles);

            root.AddBox(emptyDiv);
            var block5 = new BlockBox(styles, Color.Red, 6000, 6000);

            root.AddBox(block5);
            Assert.That(emptyDiv.NextInSelectionSequence(true), Is.EqualTo(block5));
            Assert.That(block5.PreviousInSelectionSequence, Is.EqualTo(emptyDiv));
            Assert.That(div.NextInSelectionSequence(true), Is.EqualTo(divChild));
            Assert.That(div.NextInSelectionSequence(false), Is.EqualTo(emptyDiv));
        }
Ejemplo n.º 16
0
        public void PaintPictureBox()
        {
            AssembledStyles styles = new AssembledStyles();
            Bitmap          bm     = new Bitmap(20, 30);
            ImageBox        box    = new ImageBox(styles.WithMargins(new Thickness(72.0 / 96.0 * 2.0))
                                                  .WithBorders(new Thickness(72.0 / 96.0 * 3.0))
                                                  .WithPads(new Thickness(72.0 / 96.0 * 7.0, 72.0 / 96.0 * 8.0, 72.0 / 96.0 * 11.0, 72.0 / 96.0 * 13.0)), bm);

            RootBox  root  = new RootBox(styles);
            BlockBox block = new BlockBox(styles, Color.Yellow, 2000, 4000);

            root.AddBox(block);
            root.AddBox(box);
            LayoutInfo transform = MakeLayoutInfo();

            root.Layout(transform);
            Assert.That(box.Height, Is.EqualTo(30 + 2 * 2 + 3 * 2 + 8 + 13));
            Assert.That(box.Width, Is.EqualTo(20 + 2 * 2 + 3 * 2 + 7 + 11));
            Assert.That(box.Ascent, Is.EqualTo(box.Height));

            PaintTransform ptrans   = new PaintTransform(2, 4, 96, 96, 10, 40, 96, 96);
            MockGraphics   graphics = new MockGraphics();

            root.Paint(graphics, ptrans);
            Assert.That(graphics.LastRenderPictureArgs, Is.Not.Null);
            Assert.That(graphics.LastRenderPictureArgs.Picture, Is.EqualTo(box.Picture));
            Assert.That(graphics.LastRenderPictureArgs.X, Is.EqualTo(2 - 10 + 2 + 3 + 7));
            Assert.That(graphics.LastRenderPictureArgs.Y, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
            Assert.That(graphics.LastRenderPictureArgs.Cx, Is.EqualTo(20));
            Assert.That(graphics.LastRenderPictureArgs.Cy, Is.EqualTo(30));
            int hmWidth  = box.Picture.Width;
            int hmHeight = box.Picture.Height;

            Assert.That(graphics.LastRenderPictureArgs.XSrc, Is.EqualTo(0));
            Assert.That(graphics.LastRenderPictureArgs.YSrc, Is.EqualTo(hmHeight));
            Assert.That(graphics.LastRenderPictureArgs.CxSrc, Is.EqualTo(hmWidth));
            Assert.That(graphics.LastRenderPictureArgs.CySrc, Is.EqualTo(-hmHeight));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.left, Is.EqualTo(2 - 10 + 2 + 3 + 7));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.top, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.right, Is.EqualTo(2 - 10 + 2 + 3 + 7 + 20));
            Assert.That(graphics.LastRenderPictureArgs.RcWBounds.bottom, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8 + 30));
        }
Ejemplo n.º 17
0
        public void PaintBarBox()
        {
            AssembledStyles styles = new AssembledStyles();
            BlockBox        box    = new BlockBox(styles, Color.Red, 72000, 36000);

            RootBox root = new RootBox(styles);

            root.AddBox(box);
            LayoutInfo transform = MakeLayoutInfo();

            root.Layout(transform);

            PaintTransform ptrans   = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
            MockGraphics   graphics = new MockGraphics();

            root.Paint(graphics, ptrans);
            Assert.AreEqual(1, graphics.RectanglesDrawn.Count);
            Assert.AreEqual(new Rectangle(2, 2, 96, 48), graphics.RectanglesDrawn[0]);
            Assert.AreEqual((int)ColorUtil.ConvertColorToBGR(Color.Red), graphics.BackColor);
        }
Ejemplo n.º 18
0
        public void PaintParaBox()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box0);
            BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000);

            clientRuns.Add(box1);
            BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000);

            clientRuns.Add(box2);
            BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box3);
            BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000);

            clientRuns.Add(box4);

            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para   = new ParaBox(styles, source);
            RootBox    root   = new RootBox(styles);

            root.AddBox(para);

            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);

            root.Paint(graphics, ptrans);
            Assert.AreEqual(5, graphics.RectanglesDrawn.Count);
            VerifyRect(2, 2, 96, 48, graphics, 0, Color.Red);
            VerifyRect(2, 48 + 2, 48, 24, graphics, 1, Color.Blue);
            VerifyRect(2 + 48, 48 + 2, 32, 24, graphics, 2, Color.Red);
            VerifyRect(2, 24 + 48 + 2, 96, 48, graphics, 3, Color.Red);
            VerifyRect(2, 48 + 24 + 48 + 2, 48, 48, graphics, 4, Color.Red);
        }
Ejemplo n.º 19
0
		public void PaintPictureBox()
		{
			AssembledStyles styles = new AssembledStyles();
			Bitmap bm = new Bitmap(20, 30);
			ImageBox box = new ImageBox(styles.WithMargins(new Thickness(72.0 / 96.0 * 2.0))
				.WithBorders(new Thickness(72.0 / 96.0 * 3.0))
				.WithPads(new Thickness(72.0 / 96.0 * 7.0, 72.0 / 96.0 * 8.0, 72.0 / 96.0 * 11.0, 72.0 / 96.0 * 13.0)), bm);

			RootBox root = new RootBox(styles);
			BlockBox block = new BlockBox(styles, Color.Yellow, 2000, 4000);
			root.AddBox(block);
			root.AddBox(box);
			LayoutInfo transform = MakeLayoutInfo();
			root.Layout(transform);
			Assert.That(box.Height, Is.EqualTo(30 + 2*2+3*2+8+13));
			Assert.That(box.Width, Is.EqualTo(20 + 2*2 +3*2 + 7 + 11));
			Assert.That(box.Ascent, Is.EqualTo(box.Height));

			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 10, 40, 96, 96);
			MockGraphics graphics = new MockGraphics();
			root.Paint(graphics, ptrans);
			Assert.That(graphics.LastRenderPictureArgs, Is.Not.Null);
			Assert.That(graphics.LastRenderPictureArgs.Picture, Is.EqualTo(box.Picture));
			Assert.That(graphics.LastRenderPictureArgs.X, Is.EqualTo(2-10 + 2 + 3 + 7));
			Assert.That(graphics.LastRenderPictureArgs.Y, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
			Assert.That(graphics.LastRenderPictureArgs.Cx, Is.EqualTo(20));
			Assert.That(graphics.LastRenderPictureArgs.Cy, Is.EqualTo(30));
			int hmWidth = box.Picture.Width;
			int hmHeight = box.Picture.Height;
			Assert.That(graphics.LastRenderPictureArgs.XSrc, Is.EqualTo(0));
			Assert.That(graphics.LastRenderPictureArgs.YSrc, Is.EqualTo(hmHeight));
			Assert.That(graphics.LastRenderPictureArgs.CxSrc, Is.EqualTo(hmWidth));
			Assert.That(graphics.LastRenderPictureArgs.CySrc, Is.EqualTo(-hmHeight));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.left, Is.EqualTo(2 - 10 + 2 + 3 + 7));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.top, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.right, Is.EqualTo(2 - 10 + 2 + 3 + 7 + 20));
			Assert.That(graphics.LastRenderPictureArgs.RcWBounds.bottom, Is.EqualTo(4 - 40 + block.Height + 2 + 3 + 8 + 30));
		}
Ejemplo n.º 20
0
		public void PrepareDivFixupMap()
		{
			var styles = new AssembledStyles();
			var div = new FixedSizeDiv(styles, 27, 37);
			var root = new FixedSizeRoot(styles, 49, 59);
			var block = new BlockBox(styles, Color.Red, 6000, 8000);
			div.AddBox(block);
			root.AddBox(div);
			div.Left = 5;
			div.Top = 7;
			block.Left = 10;
			block.Top = 20;
			var transform = new LayoutInfo(0, 0, 72, 72, 1000, m_gm.VwGraphics, new MockRendererFactory());
			block.Layout(transform);
			//Assert.AreEqual(6, block.Width); // sanity check: we made it 4000 mp wide at 72 dpi, that's 4 points at one point per dot
			var map = block.PrepareFixupMap();
			var invalidRect = map[block];
			Assert.AreEqual(new Rectangle(5 + 10 - 2, 7 + 20 - 2, 6 + 4, 8 + 4), invalidRect);
			invalidRect = map[div];
			Assert.AreEqual(new Rectangle(5 - 2, 7 - 2, 27 + 4, 37 + 4), invalidRect);
			invalidRect = map[root];
			Assert.AreEqual(new Rectangle(- 2, - 2, 49 + 4, 59 + 4), invalidRect);
		}
Ejemplo n.º 21
0
		public void PileOfBlocksLayout()
		{
			var styles = new AssembledStyles();
			BlockBox box1 = new BlockBox(styles, Color.Red, 72000, 36000);
			BlockBox box2 = new BlockBox(styles, Color.Blue, 108000, 18000);
			BlockBox box3 = new BlockBox(styles, Color.Orange, 72000, 18000);
			RootBox root = new RootBox(styles);
			root.AddBox(box1);
			root.AddBox(box2);
			root.AddBox(box3);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			Assert.That(box1.Height, Is.EqualTo(48));
			Assert.That(box2.Height, Is.EqualTo(24));
			Assert.That(root.Height, Is.EqualTo(48 + 24 + 24) );
			Assert.That(box1.Left, Is.EqualTo(0));
			Assert.That(box2.Left, Is.EqualTo(0));
			Assert.That(box1.Top, Is.EqualTo(0));
			Assert.That(box2.Top, Is.EqualTo(48));
			Assert.That(box3.Top, Is.EqualTo(48 + 24));
			Assert.That(box1.Width, Is.EqualTo(96));
			Assert.That(box2.Width, Is.EqualTo(144));
			Assert.That(root.Width, Is.EqualTo(144));
		}
Ejemplo n.º 22
0
		public void FlashInsertionPoint()
		{
			AssembledStyles styles = new AssembledStyles();
			var clientRuns = new List<IClientRun>();
			BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box0);
			TextSource source = new TextSource(clientRuns, null);
			ParaBox para = new ParaBox(styles, source);
			RootBox root = new RootBox(styles);
			root.AddBox(para);
			MockGraphics graphics = new MockGraphics();
			LayoutInfo layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);
			root.Layout(layoutArgs);

			var sel = new DummySelection();
			root.Selection = sel;

			PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
			root.Paint(graphics, ptrans);

			Assert.AreEqual(graphics, sel.VgUsedToDraw);
			Assert.AreEqual(ptrans, sel.TransformUsedToDraw);

			sel.ClearResults();
			root.FlashInsertionPoint();

			Assert.IsFalse(sel.WasInvalidated, "flash IP should not cause range to be invalidated");

			var ip = new DummySelection();
			ip.SimulateIP = true;
			root.Selection = ip;
			Assert.IsTrue(ip.WasInvalidated);

			// Initial paint after being installed should indeed paint the IP (so it appears at once)
			ip.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(graphics, ip.VgUsedToDraw);
			Assert.AreEqual(ptrans, ip.TransformUsedToDraw);


			// Each flash should invalide it.
			sel.ClearResults();
			root.FlashInsertionPoint();
			Assert.IsTrue(ip.WasInvalidated);

			// The second paint should do nothing to the IP.
			ip.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(null, ip.VgUsedToDraw);

			// One more flash
			ip.ClearResults();
			root.FlashInsertionPoint();
			Assert.IsTrue(ip.WasInvalidated);

			// And now back to drawing the IP.
			ip.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(graphics, ip.VgUsedToDraw);
			Assert.AreEqual(ptrans, ip.TransformUsedToDraw);

			// range should get drawn even though IP was hidden.
			root.FlashInsertionPoint(); // back to hidden
			root.Selection = sel; // back to range.
			sel.ClearResults();
			root.Paint(graphics, ptrans);
			Assert.AreEqual(graphics, sel.VgUsedToDraw);
			Assert.AreEqual(ptrans, sel.TransformUsedToDraw);
		}
Ejemplo n.º 23
0
		public void FiveBlockPara()
		{
			AssembledStyles styles = new AssembledStyles();
			var clientRuns = new List<IClientRun>();
			BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box0);
			BlockBox box1 = new BlockBox(styles, Color.Blue, 36000, 18000);
			clientRuns.Add(box1);
			BlockBox box2 = new BlockBox(styles, Color.Red, 24000, 18000);
			clientRuns.Add(box2);
			BlockBox box3 = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns.Add(box3);
			BlockBox box4 = new BlockBox(styles, Color.Red, 36000, 36000);
			clientRuns.Add(box4);

			TextSource source = new TextSource(clientRuns, null);
			ParaBox para = new ParaBox(styles, source);
			RootBox root = new RootBox(styles);
			root.AddBox(para);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			VerifyBox(box0, 96, 48, box1, para, "box0");
			VerifyBox(box1, 48, 24, box2, para, "box1");
			VerifyBox(box2, 32, 24, box3, para, "box2");
			VerifyBox(box3, 96, 48, box4, para, "box3");
			VerifyBox(box4, 48, 48, null, para, "box4");
			VerifyGroup(para, 96 + 48 + 32 + 96 + 48, 48, null, root, box0, box4, "para");
			VerifyGroup(root, 96 + 48 + 32 + 96 + 48, 48, null, null, para, para, "root");
			VerifyParaLine(para, 0, box0, box4, 0, "para unlimited one line");

			// Check multi-line layout (one line has room for two boxes).
			LayoutInfo layoutArgs2 = MakeLayoutInfo(100, m_gm.VwGraphics);
			root.Layout(layoutArgs2);
			Assert.AreEqual(4, para.Lines.Count, "para1 at 100 has four lines");
			VerifyBox(box0, 96, 48, box1, para, "box0/100");
			VerifyBox(box1, 48, 24, box2, para, "box1/100");
			VerifyBox(box2, 32, 24, box3, para, "box2/100");
			VerifyBox(box3, 96, 48, box4, para, "box3/100");
			VerifyBox(box4, 48, 48, null, para, "box4/100");
			VerifyParaLine(para, 0, box0, box0, 0, "para/100 first");
			VerifyParaLine(para, 1, box1, box2, 48, "para/100 second");
			VerifyParaLine(para, 2, box3, box3, 48 + 24, "para/100 third");
			VerifyParaLine(para, 3, box4, box4, 48 + 24 + 48, "para/100 fourth");
			// At 100 pixels wide, box0 goes on the first line, boxes 1 and 2 on the third, box 3 and box4 take the fourth and fifth.
			// Multiple lines means the paragraph occupies its full width.
			int height100 = 48 + 24 + 48 + 48;
			VerifyGroup(para, 100, height100, null, root, box0, box4, "para/100");
			VerifyGroup(root, 100, height100, null, null, para, para, "root/100");

			// Check layout when some boxes won't fit on a whole line.
			LayoutInfo layoutArgs3 = MakeLayoutInfo(50, m_gm.VwGraphics);
			root.Layout(layoutArgs3);
			Assert.AreEqual(5, para.Lines.Count, "para1 at 50 has five lines");
			VerifyBox(box0, 96, 48, box1, para, "box0/50");
			VerifyParaLine(para, 0, box0, box0, 0, "para/50 first");
			VerifyParaLine(para, 1, box1, box1, 48, "para/50 second");
			VerifyParaLine(para, 2, box2, box2, 48 + 24, "para/50 third");
			VerifyParaLine(para, 3, box3, box3, 48 + 24 + 24, "para/50 fourth");
			VerifyParaLine(para, 4, box4, box4, 48 + 24 + 24 +48, "para/50 fifth");
			// At 100 pixels wide, box0 goes on the first line, boxes 1 and 2 on the third, box 3 and box4 take the fourth and fifth.
			// Multiple lines means the paragraph occupies its full width.
			int height50 = 48 + 24 + 24 + 48 + 48;
			VerifyGroup(para, 96, height50, null, root, box0, box4, "para/50");
			VerifyGroup(root, 96, height50, null, null, para, para, "root/50");
		}
Ejemplo n.º 24
0
        public void FlashInsertionPoint()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns.Add(box0);
            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para   = new ParaBox(styles, source);
            RootBox    root   = new RootBox(styles);

            root.AddBox(para);
            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            var sel = new DummySelection();

            root.Selection = sel;

            PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);

            root.Paint(graphics, ptrans);

            Assert.AreEqual(graphics, sel.VgUsedToDraw);
            Assert.AreEqual(ptrans, sel.TransformUsedToDraw);

            sel.ClearResults();
            root.FlashInsertionPoint();

            Assert.IsFalse(sel.WasInvalidated, "flash IP should not cause range to be invalidated");

            var ip = new DummySelection();

            ip.SimulateIP  = true;
            root.Selection = ip;
            Assert.IsTrue(ip.WasInvalidated);

            // Initial paint after being installed should indeed paint the IP (so it appears at once)
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, ip.VgUsedToDraw);
            Assert.AreEqual(ptrans, ip.TransformUsedToDraw);


            // Each flash should invalide it.
            sel.ClearResults();
            root.FlashInsertionPoint();
            Assert.IsTrue(ip.WasInvalidated);

            // The second paint should do nothing to the IP.
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(null, ip.VgUsedToDraw);

            // One more flash
            ip.ClearResults();
            root.FlashInsertionPoint();
            Assert.IsTrue(ip.WasInvalidated);

            // And now back to drawing the IP.
            ip.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, ip.VgUsedToDraw);
            Assert.AreEqual(ptrans, ip.TransformUsedToDraw);

            // range should get drawn even though IP was hidden.
            root.FlashInsertionPoint();       // back to hidden
            root.Selection = sel;             // back to range.
            sel.ClearResults();
            root.Paint(graphics, ptrans);
            Assert.AreEqual(graphics, sel.VgUsedToDraw);
            Assert.AreEqual(ptrans, sel.TransformUsedToDraw);
        }
Ejemplo n.º 25
0
        public void DragStartsOnMoveInSelection()
        {
            string contents = "This is the day.";
            var    engine   = new FakeRenderEngine()
            {
                Ws = 34, SegmentHeight = 13
            };
            var factory = new FakeRendererFactory();

            factory.SetRenderer(34, engine);
            var styles     = new AssembledStyles().WithWs(34);
            var clientRuns = new List <IClientRun>();
            var run        = new StringClientRun(contents, styles);

            clientRuns.Add(run);
            var source   = new TextSource(clientRuns, null);
            var para     = new ParaBox(styles, source);
            var extraBox = new BlockBox(styles, Color.Red, 50, 72000);             // tall, narrow spacer at top
            var root     = new RootBoxFdo(styles);

            root.AddBox(extraBox);
            root.AddBox(para);
            var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);

            root.Layout(layoutArgs);
            Assert.That(root.Height, Is.EqualTo(96 + 13));
            Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents)));

            var ip1   = run.SelectAt(para, 5, false);
            var ip2   = run.SelectAt(para, 7, true);
            var range = new RangeSelection(ip1, ip2);

            range.Install();
            PaintTransform ptrans = new PaintTransform(2, 2, 96, 96, 0, 0, 96, 96);
            var            sbox   = para.FirstBox as StringBox;
            MockSite       site   = new MockSite();

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            root.Site         = site;
            int indent = FakeRenderEngine.SimulatedWidth("This ");

            root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans);
            root.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, indent + 5, 100, 0), Keys.None, m_gm.VwGraphics, ptrans);
            Assert.That(GetStringDropData(site), Is.EqualTo("is"));
            Assert.That(site.LastDoDragDropArgs.AllowedEffects, Is.EqualTo(DragDropEffects.Copy),
                        "editing not possible in this paragraph, we can only copy");
            Assert.That(root.Selection, Is.EqualTo(range), "selection should not be changed by drag drop");
            site.LastDoDragDropArgs = null;
            root.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 3, 100, 0), Keys.None, m_gm.VwGraphics, ptrans);
            Assert.That(site.LastDoDragDropArgs, Is.Null, "click outside selection should not initiate drag");

            // Tack on an extra check that a read-only view does not handle drop.
            var dataObj  = new DataObject(DataFormats.StringFormat, "new ");
            var dragArgs = new DragEventArgs(dataObj, (int)DragDropKeyStates.ControlKey, 10, 8,
                                             DragDropEffects.Copy | DragDropEffects.Move,
                                             DragDropEffects.None);

            root.OnDragEnter(dragArgs, new Point(14, 8), m_gm.VwGraphics, ptrans);
            Assert.That(dragArgs.Effect, Is.EqualTo(DragDropEffects.None));
            Assert.That(root.DragState, Is.EqualTo(WindowDragState.DraggingHere));
        }
Ejemplo n.º 26
0
        public void NestedDivsLayout()
        {
            var      styles = new AssembledStyles();
            BlockBox box1   = new BlockBox(styles, Color.Red, 72000, 36000);
            BlockBox box2   = new BlockBox(styles, Color.Blue, 108000, 18000);
            BlockBox box3   = new BlockBox(styles, Color.Orange, 72000, 18000);
            BlockBox box4   = new BlockBox(styles, Color.Orange, 72000, 18000);
            var      div1   = new DivBox(styles);
            var      div2   = new DivBox(styles);

            div1.AddBox(box1);
            div1.AddBox(box2);
            div2.AddBox(box3);
            div2.AddBox(box4);
            RootBox root = new RootBox(styles);

            root.AddBox(div1);
            root.AddBox(div2);
            LayoutInfo layoutArgs = MakeLayoutInfo();

            root.Layout(layoutArgs);
            Assert.That(box1.Height, Is.EqualTo(48));
            Assert.That(box2.Height, Is.EqualTo(24));
            Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24));
            Assert.That(box1.Left, Is.EqualTo(0));
            Assert.That(box2.Left, Is.EqualTo(0));
            Assert.That(box1.Top, Is.EqualTo(0));
            Assert.That(box2.Top, Is.EqualTo(48));
            Assert.That(div2.Top, Is.EqualTo(48 + 24));
            Assert.That(box4.Top, Is.EqualTo(24));
            Assert.That(box1.Width, Is.EqualTo(96));
            Assert.That(box2.Width, Is.EqualTo(144));
            Assert.That(root.Width, Is.EqualTo(144));

            // Now try changing the size of a block.
            MockSite site = new MockSite();

            root.Site = site;
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            box2.UpdateSize(144000, 36000);
            Assert.That(box2.Width, Is.EqualTo(96 * 2));
            Assert.That(box2.Height, Is.EqualTo(48));
            Assert.That(div1.Height, Is.EqualTo(96));                // two children now both 48 high.
            Assert.That(root.Height, Is.EqualTo(48 + 48 + 24 + 24)); // new heights of 4 children.
            Assert.That(root.Width, Is.EqualTo(96 * 2));
            // Since it got both wider and higher, we should invalidate at least the whole current size.
            var bigInvalidate = root.InvalidateRect;

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 36000);
            Assert.That(root.Height, Is.EqualTo(48 + 48 + 24 + 24)); // unchanged this time
            Assert.That(root.Width, Is.EqualTo(144));                // narrower box2 still determines it
            // Got narrower, at least the whole old invalidate rectangle should be invalidated.
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24)); // new smaller value
            Assert.That(root.Width, Is.EqualTo(144));                //  unchanged this time
            // It got shorter. We want an optimized invalidate rectangle that does not
            // include the top box. But it must include the space at the bottom that the root box used to occupy.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (its in the fixmap so its own Relayout does this);
            // the shrinkage area at the bottom of div2;
            // and the area computed because div2 moved.
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 48);             // old box2
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24);        // shrinkage of div1
            // This is from the new top of div2 to its old bottom (old bottom was 48 + 48 + 24 + 24)
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 72000);
            Assert.That(root.Height, Is.EqualTo(48 + 96 + 24 + 24)); // new larger value
            Assert.That(root.Width, Is.EqualTo(144));                //  unchanged this time
            // It got longer. We want an optimized invalidate rectangle that does not
            // include the top box. But it must include the space at the bottom where the root box grew.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it returns true from Relayout);
            // the growth area at the bottom of div2;
            // and the area computed because div2 moved.
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96);             // new box2
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24);   // new part of div1 occupied by box2
            // This is from the old top of div2 to its new bottom (48 + 96 + 24 + 24)
            VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
        }
Ejemplo n.º 27
0
		public void InsertGrowsPara()
		{
			string contents = "This is the day.";
			var engine = new FakeRenderEngine() { Ws = 34, SegmentHeight = 13 };
			var factory = new FakeRendererFactory();
			factory.SetRenderer(34, engine);
			var styles = new AssembledStyles().WithWs(34);
			var clientRuns = new List<IClientRun>();
			var run = new StringClientRun(contents, styles);
			clientRuns.Add(run);
			var data1 = new MockData1(34, 35);
			data1.SimpleThree = contents;
			var source = new TextSource(clientRuns, null);
			var para = new ParaBox(styles, source);
			var hookup = new StringHookup(this, () => data1.SimpleThree, hook => data1.SimpleThreeChanged += hook.StringPropChanged,
				hook => data1.SimpleThreeChanged -= hook.StringPropChanged, para);
			hookup.Writer = newVal => data1.SimpleThree = newVal;
			run.Hookup = hookup;
			var extraBox = new BlockBox(styles, Color.Red, 50, 72000);
			var root = new RootBoxFdo(styles);
			root.SizeChanged += root_SizeChanged;
			root.AddBox(para);
			root.AddBox(extraBox);
			var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);
			root.Layout(layoutArgs);
			Assert.IsTrue(m_sizeChangedCalled);
			Assert.That(root.Height, Is.EqualTo(13 + 96));
			Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents)));

			int widthThisIsThe = FakeRenderEngine.SimulatedWidth("This is the");
			layoutArgs = MakeLayoutInfo(widthThisIsThe + 2, m_gm.VwGraphics, factory);
			root.Layout(layoutArgs);
			Assert.That(root.Height, Is.EqualTo(26 + 96), "two line para is twice the height");
			Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "two-line para occupies full available width");
			Assert.That(extraBox.Top, Is.EqualTo(26));

			PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);
			MockSite site = new MockSite();
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			root.Site = site;
			m_sizeChangedCalled = false;
			var ip = para.SelectAtEnd();

			ip.InsertText(" We will be");
			Assert.That(para.Height, Is.EqualTo(39), "inserted text makes para a line higher");
			Assert.That(root.Height, Is.EqualTo(39 + 96), "root grows when para does");
			Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "three-line para occupies full available width");
			Assert.That(extraBox.Top, Is.EqualTo(39));
			Assert.IsTrue(m_sizeChangedCalled);
		}
Ejemplo n.º 28
0
        public void RenderRuns()
        {
            string          part0      = "abc def";
            AssembledStyles styles     = new AssembledStyles().WithWs(wsEn);
            StringClientRun clientRun0 = new StringClientRun(part0, styles);
            var             clientRuns = new List <IClientRun>();

            clientRuns.Add(clientRun0);

            string          part0a      = " frn";
            StringClientRun clientRun0a = new StringClientRun(part0a, styles.WithWs(wsFrn));

            clientRuns.Add(clientRun0a);

            // Run 1
            string     part1 = " ghijk";        // english
            string     part2 = " lmno";         // french
            ITsString  tss   = tsf.MakeString(part1, wsEn);
            ITsStrBldr bldr  = tss.GetBldr();

            bldr.Replace(bldr.Length, bldr.Length, part2, ttpFrn);
            TssClientRun clientRun1 = new TssClientRun(bldr.GetString(), styles);

            clientRuns.Add(clientRun1);

            // Run 2a
            string    part2a    = " french insert";
            string    part2b    = " insert";       // english
            ITsString tssInsert = tsf.MakeString(part2b, wsEn);

            bldr = tssInsert.GetBldr();
            bldr.Replace(0, 0, part2a, ttpFrn);
            TssClientRun clientRun2b = new TssClientRun(bldr.GetString(), styles);

            clientRuns.Add(clientRun2b);

            // IRuntem 2
            string          part3      = " pq";
            string          part4      = "\xfffc";
            StringClientRun clientRun2 = new StringClientRun(part3 + part4, styles);

            clientRuns.Add(clientRun2);

            // Run 3
            string          part5      = "more french";
            string          part6      = "\xfffc";
            StringClientRun clientRun3 = new StringClientRun(part5 + part6, styles.WithWs(wsFrn));

            clientRuns.Add(clientRun3);

            // Run 4
            string          part7      = "English";
            StringClientRun clientRun4 = new StringClientRun(part7, styles.WithWs(wsFrn));

            clientRuns.Add(clientRun4);

            BlockBox box = new BlockBox(styles.WithWs(wsFrn), Color.Red, 72000, 36000);

            TextSource source = new TextSource(clientRuns, (run, offset) => (run == clientRun2 ? new StringClientRun(orcText, run.UniformRunStyles(0).WithWs(wsFrn)) : (IClientRun)box));

            List <IRenderRun> renderRuns = source.RenderRuns;

            VerifyRenderRun(renderRuns[0], 0, part0.Length, "first - en");
            int len = part0.Length;

            VerifyRenderRun(renderRuns[1], len, part0a.Length, "0a - frn");
            len += part0a.Length;
            VerifyRenderRun(renderRuns[2], len, part1.Length, "part1 - en");
            len += part1.Length;
            VerifyRenderRun(renderRuns[3], len, part2.Length + part2a.Length, "part2 & 2a (french)");
            len += part2.Length + part2a.Length;
            VerifyRenderRun(renderRuns[4], len, part2b.Length + part3.Length, "2b and 2 (Eng)");
            len += part2b.Length + part3.Length;
            VerifyRenderRun(renderRuns[5], len, orcText.Length + part5.Length, "orc + other french");
            len += orcText.Length + part5.Length;
            VerifyRenderRun(renderRuns[6], len, 1, "single box");
            len += 1;
            VerifyRenderRun(renderRuns[7], len, part7.Length, "run with same props as preceding box");
            Assert.AreEqual(8, renderRuns.Count);
        }
Ejemplo n.º 29
0
        public void EmptyRuns()
        {
            // Run 0
            string          part0      = "";
            AssembledStyles styles     = new AssembledStyles().WithWs(wsEn);
            StringClientRun clientRun0 = new StringClientRun(part0, styles);
            var             clientRuns = new List <IClientRun>();

            clientRuns.Add(clientRun0);

            // We want an empty run if it's the only thing in the paragraph.
            TextSource source = new TextSource(clientRuns, MockInterpretOrc);

            MapRun[] runs = source.Runs;
            Assert.AreEqual(1, runs.Length);
            VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of empty source");
            Assert.AreEqual(0, source.Length, "length of empty source");
            VerifyCharProps(source, 0, wsEn, 0, 0, "props at 0 in empty string");

            // We don't want an empty run adjacent to a non-empty one.

            string          part1      = "abc";
            StringClientRun clientRun1 = new StringClientRun(part1, styles);

            clientRuns.Add(clientRun1);
            source = new TextSource(clientRuns, MockInterpretOrc);
            runs   = source.Runs;
            Assert.AreEqual(1, runs.Length);
            VerifyRun(0, clientRun1, 0, 0, part1, runs[0], "first run of (empty, abc) source");
            Assert.AreEqual(part1.Length, source.Length, "length of (empty, abc) source");

            // (empty, box) keeps empty
            BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);

            clientRuns[1] = box;
            source        = new TextSource(clientRuns, MockInterpretOrc);
            runs          = source.Runs;
            Assert.AreEqual(2, runs.Length);
            VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of (empty, box) source");
            VerifyRun(0, box, 0, 0, "\xfffc", runs[1], "2nd run of (empty, box) source");
            Assert.AreEqual(1, source.Length, "length of (empty, box) source");

            // Two adjacent empty strings produce a single run for the first client run.

            clientRuns.RemoveAt(1);
            StringClientRun clientRun1e = new StringClientRun(part0, styles);

            clientRuns.Add(clientRun1e);
            source = new TextSource(clientRuns, MockInterpretOrc);
            runs   = source.Runs;
            Assert.AreEqual(1, runs.Length);
            VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of (empty, empty) source");
            Assert.AreEqual(0, source.Length, "length of (empty, empty) source");

            // (something,empty) keeps the something.
            clientRuns[0] = clientRun1;
            source        = new TextSource(clientRuns, MockInterpretOrc);
            runs          = source.Runs;
            Assert.AreEqual(1, runs.Length);
            VerifyRun(0, clientRun1, 0, 0, part1, runs[0], "first run of (abc, empty) source");
            Assert.AreEqual(part1.Length, source.Length, "length of (abc, empty) source");

            // (box, empty) keeps empty
            clientRuns[0] = box;
            source        = new TextSource(clientRuns, MockInterpretOrc);
            runs          = source.Runs;
            Assert.AreEqual(2, runs.Length);
            VerifyRun(0, box, 0, 0, "\xfffc", runs[0], "first run of (box, empty) source");
            VerifyRun(1, clientRun1e, 1, 0, "", runs[1], "2nd run of (box, empty) source");
            Assert.AreEqual(1, source.Length, "length of (box, empty) source");
        }
Ejemplo n.º 30
0
		public void InsertCharInEmptyLine()
		{
			string contents = "";
			var engine = new FakeRenderEngine() { Ws = 34, SegmentHeight = 13 };
			var factory = new FakeRendererFactory();
			factory.SetRenderer(34, engine);
			var styles = new AssembledStyles().WithWs(34);
			var clientRuns = new List<IClientRun>();
			var run = new StringClientRun(contents, styles);
			clientRuns.Add(run);
			var data1 = new MockData1(34, 35);
			data1.SimpleThree = contents;
			var source = new TextSource(clientRuns, null);
			var para = new ParaBox(styles, source);
			var hookup = new StringHookup(this, () => data1.SimpleThree, hook => data1.SimpleThreeChanged += hook.StringPropChanged,
				hook => data1.SimpleThreeChanged -= hook.StringPropChanged, para);
			hookup.Writer = newVal => data1.SimpleThree = newVal;
			run.Hookup = hookup;
			var root = new RootBox(styles);
			var block = new BlockBox(styles, Color.Red, 20000, 10000);
			root.AddBox(block);
			root.AddBox(para);
			var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);
			root.Layout(layoutArgs);
			Assert.That(root.Height, Is.EqualTo(13 + block.Height));
			Assert.That(para.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents)));
			Assert.That(root.Width, Is.EqualTo(block.Width));
			int simulatedWidth = FakeRenderEngine.SimulatedWidth("x");
			Assert.That(root.Width, Is.GreaterThan(para.Width + simulatedWidth));
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);
			MockSite site = new MockSite();
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			root.Site = site;
			var oldRootWidth = root.Width;

			var ip = root.SelectAtEnd();
			ip.InsertText("x");
			Assert.That(root.Height, Is.EqualTo(13 + block.Height));
			Assert.That(root.Width, Is.EqualTo(oldRootWidth));
			Assert.That(para.Width, Is.EqualTo(simulatedWidth));
			var expectedInvalidate = new Rectangle(-RootBox.InvalidateMargin,
							- RootBox.InvalidateMargin + block.Height,
							simulatedWidth + RootBox.InvalidateMargin * 2,
							13 + 2 * RootBox.InvalidateMargin);
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(expectedInvalidate));
		}
Ejemplo n.º 31
0
		public void NextAndPrevInSelectionSeq()
		{
			var styles = new AssembledStyles();
			var root = new RootBox(styles);
			Assert.That(root.NextInSelectionSequence(true), Is.Null);
			Assert.That(root.PreviousInSelectionSequence, Is.Null);
			var block = new BlockBox(styles, Color.Red, 6000, 6000);
			root.AddBox(block);
			Assert.That(root.NextInSelectionSequence(true), Is.EqualTo(block));
			Assert.That(block.PreviousInSelectionSequence, Is.EqualTo(root));
			var div = new DivBox(styles);
			root.AddBox(div);
			Assert.That(block.NextInSelectionSequence(true), Is.EqualTo(div));
			Assert.That(div.PreviousInSelectionSequence, Is.EqualTo(block));
			var divChild = new DivBox(styles);
			div.AddBox(divChild);
			var block2 = new BlockBox(styles, Color.Red, 6000, 6000);
			divChild.AddBox(block2);
			var block3 = new BlockBox(styles, Color.Red, 6000, 6000);
			divChild.AddBox(block3);
			var block4 = new BlockBox(styles, Color.Red, 6000, 6000);
			div.AddBox(block4);
			// up and forward
			Assert.That(block3.NextInSelectionSequence(true), Is.EqualTo(block4));
			Assert.That(block4.PreviousInSelectionSequence, Is.EqualTo(block3));
			// Can go back from a box to a previous empty group
			var emptyDiv = new DivBox(styles);
			root.AddBox(emptyDiv);
			var block5 = new BlockBox(styles, Color.Red, 6000, 6000);
			root.AddBox(block5);
			Assert.That(emptyDiv.NextInSelectionSequence(true), Is.EqualTo(block5));
			Assert.That(block5.PreviousInSelectionSequence, Is.EqualTo(emptyDiv));
			Assert.That(div.NextInSelectionSequence(true), Is.EqualTo(divChild));
			Assert.That(div.NextInSelectionSequence(false), Is.EqualTo(emptyDiv));

		}
Ejemplo n.º 32
0
        public void ValidSelections()
        {
            AssembledStyles styles     = new AssembledStyles();
            var             clientRuns = new List <IClientRun>();
            var             run0       = new StringClientRun("First run", styles);
            var             run1       = new StringClientRun("Middle run", styles);
            BlockBox        box0       = new BlockBox(styles, Color.Red, 72000, 36000);
            var             run2       = new StringClientRun("Last run", styles);

            clientRuns.Add(run0);
            clientRuns.Add(run1);
            clientRuns.Add(box0);
            clientRuns.Add(run2);
            TextSource source = new TextSource(clientRuns, null);
            ParaBox    para0  = new ParaBox(styles, source);

            run0.Hookup = new LiteralStringParaHookup(para0, para0);
            run1.Hookup = new LiteralStringParaHookup(para0, para0);
            run2.Hookup = new LiteralStringParaHookup(para0, para0);
            DivBox  div  = new DivBox(styles);
            RootBox root = new RootBox(styles);

            para0.Container = div;
            MockGraphics graphics   = new MockGraphics();
            LayoutInfo   layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);

            root.Layout(layoutArgs);

            root.AddBox(div);
            var sel = para0.SelectAtStart();

            root.Selection = sel;

            Assert.That(!root.Selection.IsValid);

            div.AddBox(para0);
            root.RemoveBoxes(div, div);
            div.Container = root;

            Assert.That(!root.Selection.IsValid);

            root.AddBox(div);

            Assert.That(root.Selection.IsValid);

            (root.Selection as InsertionPoint).Hookup.ClientRunIndex = 4;

            Assert.That(!root.Selection.IsValid);

            (root.Selection as InsertionPoint).Hookup.ClientRunIndex = 2;

            Assert.That(!root.Selection.IsValid);

            (root.Selection as InsertionPoint).Hookup.ClientRunIndex = 0;
            (root.Selection as InsertionPoint).StringPosition        = 10;

            Assert.That(!root.Selection.IsValid);

            (root.Selection as InsertionPoint).StringPosition = 0;
            run0.Hookup = null;

            Assert.That(!root.Selection.IsValid);

            run0.Hookup    = new LiteralStringParaHookup(para0, para0);
            sel            = para0.SelectAtStart();
            root.Selection = sel;

            Assert.That(root.Selection.IsValid);
        }
Ejemplo n.º 33
0
		public void RenderRuns()
		{
			string part0 = "abc def";
			AssembledStyles styles = new AssembledStyles().WithWs(wsEn);
			StringClientRun clientRun0 = new StringClientRun(part0, styles);
			var clientRuns = new List<IClientRun>();
			clientRuns.Add(clientRun0);

			string part0a = " frn";
			StringClientRun clientRun0a = new StringClientRun(part0a, styles.WithWs(wsFrn));
			clientRuns.Add(clientRun0a);

			// Run 1
			string part1 = " ghijk"; // english
			string part2 = " lmno"; // french
			ITsString tss = tsf.MakeString(part1, wsEn);
			ITsStrBldr bldr = tss.GetBldr();
			bldr.Replace(bldr.Length, bldr.Length, part2, ttpFrn);
			TssClientRun clientRun1 = new TssClientRun(bldr.GetString(), styles);
			clientRuns.Add(clientRun1);

			// Run 2a
			string part2a = " french insert";
			string part2b = " insert"; // english
			ITsString tssInsert = tsf.MakeString(part2b, wsEn);
			bldr = tssInsert.GetBldr();
			bldr.Replace(0, 0, part2a, ttpFrn);
			TssClientRun clientRun2b = new TssClientRun(bldr.GetString(), styles);
			clientRuns.Add(clientRun2b);

			// IRuntem 2
			string part3 = " pq";
			string part4 = "\xfffc";
			StringClientRun clientRun2 = new StringClientRun(part3 + part4, styles);
			clientRuns.Add(clientRun2);

			// Run 3
			string part5 = "more french";
			string part6 = "\xfffc";
			StringClientRun clientRun3 = new StringClientRun(part5 + part6, styles.WithWs(wsFrn));
			clientRuns.Add(clientRun3);

			// Run 4
			string part7 = "English";
			StringClientRun clientRun4 = new StringClientRun(part7, styles.WithWs(wsFrn));
			clientRuns.Add(clientRun4);

			BlockBox box = new BlockBox(styles.WithWs(wsFrn), Color.Red, 72000, 36000);

			TextSource source = new TextSource(clientRuns, (run, offset) => (run == clientRun2 ? new StringClientRun(orcText, run.UniformRunStyles(0).WithWs(wsFrn)) : (IClientRun)box));

			List<IRenderRun> renderRuns = source.RenderRuns;
			VerifyRenderRun(renderRuns[0], 0, part0.Length, "first - en");
			int len = part0.Length;
			VerifyRenderRun(renderRuns[1], len, part0a.Length, "0a - frn");
			len += part0a.Length;
			VerifyRenderRun(renderRuns[2], len, part1.Length, "part1 - en");
			len += part1.Length;
			VerifyRenderRun(renderRuns[3], len, part2.Length + part2a.Length, "part2 & 2a (french)");
			len += part2.Length + part2a.Length;
			VerifyRenderRun(renderRuns[4], len, part2b.Length + part3.Length, "2b and 2 (Eng)");
			len += part2b.Length + part3.Length;
			VerifyRenderRun(renderRuns[5], len, orcText.Length + part5.Length, "orc + other french");
			len += orcText.Length + part5.Length;
			VerifyRenderRun(renderRuns[6], len, 1, "single box");
			len += 1;
			VerifyRenderRun(renderRuns[7], len, part7.Length, "run with same props as preceding box");
			Assert.AreEqual(8, renderRuns.Count);

		}
Ejemplo n.º 34
0
        public void InsertGrowsPara()
        {
            string contents = "This is the day.";
            var    engine   = new FakeRenderEngine()
            {
                Ws = 34, SegmentHeight = 13
            };
            var factory = new FakeRendererFactory();

            factory.SetRenderer(34, engine);
            var styles     = new AssembledStyles().WithWs(34);
            var clientRuns = new List <IClientRun>();
            var run        = new StringClientRun(contents, styles);

            clientRuns.Add(run);
            var data1 = new MockData1(34, 35);

            data1.SimpleThree = contents;
            var source = new TextSource(clientRuns, null);
            var para   = new ParaBox(styles, source);
            var hookup = new StringHookup(this, () => data1.SimpleThree, hook => data1.SimpleThreeChanged += hook.StringPropChanged,
                                          hook => data1.SimpleThreeChanged -= hook.StringPropChanged, para);

            hookup.Writer = newVal => data1.SimpleThree = newVal;
            run.Hookup    = hookup;
            var extraBox = new BlockBox(styles, Color.Red, 50, 72000);
            var root     = new RootBoxFdo(styles);

            root.SizeChanged += root_SizeChanged;
            root.AddBox(para);
            root.AddBox(extraBox);
            var layoutArgs = MakeLayoutInfo(Int32.MaxValue / 2, m_gm.VwGraphics, factory);

            root.Layout(layoutArgs);
            Assert.IsTrue(m_sizeChangedCalled);
            Assert.That(root.Height, Is.EqualTo(13 + 96));
            Assert.That(root.Width, Is.EqualTo(FakeRenderEngine.SimulatedWidth(contents)));

            int widthThisIsThe = FakeRenderEngine.SimulatedWidth("This is the");

            layoutArgs = MakeLayoutInfo(widthThisIsThe + 2, m_gm.VwGraphics, factory);
            root.Layout(layoutArgs);
            Assert.That(root.Height, Is.EqualTo(26 + 96), "two line para is twice the height");
            Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "two-line para occupies full available width");
            Assert.That(extraBox.Top, Is.EqualTo(26));

            PaintTransform ptrans = new PaintTransform(2, 4, 96, 100, 0, 10, 120, 128);
            MockSite       site   = new MockSite();

            site.m_transform    = ptrans;
            site.m_vwGraphics   = m_gm.VwGraphics;
            root.Site           = site;
            m_sizeChangedCalled = false;
            var ip = para.SelectAtEnd();

            ip.InsertText(" We will be");
            Assert.That(para.Height, Is.EqualTo(39), "inserted text makes para a line higher");
            Assert.That(root.Height, Is.EqualTo(39 + 96), "root grows when para does");
            Assert.That(root.Width, Is.EqualTo(widthThisIsThe + 2), "three-line para occupies full available width");
            Assert.That(extraBox.Top, Is.EqualTo(39));
            Assert.IsTrue(m_sizeChangedCalled);
        }
Ejemplo n.º 35
0
		public void OrcBoxRun()
		{
			// Run 0
			string part0 = "abc";
			string part1 = "\xfffc";
			string part2 = "defg";

			AssembledStyles styles = new AssembledStyles().WithWs(wsEn);
			StringClientRun clientRun0 = new StringClientRun(part0+part1+part2, styles);
			var clientRuns = new List<IClientRun>();
			clientRuns.Add(clientRun0);

			BlockBox box = new BlockBox(styles.WithWs(wsFrn), Color.Red, 72000, 36000);

			TextSource source = new TextSource(clientRuns, (run, offset) => box);

			MapRun[] runs = source.Runs;
			Assert.AreEqual(3, runs.Length);
			VerifyRun(0, clientRun0, 0, 0, part0, runs[0], "first run of complex source with box");
			int len = part0.Length;
			VerifyRun(len, box, len, part0.Length, part1, runs[1], "2nd run of complex source with box");
			len += 1;
			VerifyRun(len, clientRun0, len, part0.Length+1, part2, runs[2], "3rd run of complex source with box");
			len += part2.Length;
			Assert.AreEqual(len, source.Length, "length of complex source with box");
			VerifyCharProps(source, part0.Length, wsFrn, part0.Length, part0.Length + 1, "props of box");
		}
Ejemplo n.º 36
0
		public void EmptyRuns()
		{
			// Run 0
			string part0 = "";
			AssembledStyles styles = new AssembledStyles().WithWs(wsEn);
			StringClientRun clientRun0 = new StringClientRun(part0, styles);
			var clientRuns = new List<IClientRun>();
			clientRuns.Add(clientRun0);

			// We want an empty run if it's the only thing in the paragraph.
			TextSource source = new TextSource(clientRuns, MockInterpretOrc);
			MapRun[] runs = source.Runs;
			Assert.AreEqual(1, runs.Length);
			VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of empty source");
			Assert.AreEqual(0, source.Length, "length of empty source");
			VerifyCharProps(source, 0, wsEn, 0, 0, "props at 0 in empty string");

			// We don't want an empty run adjacent to a non-empty one.

			string part1 = "abc";
			StringClientRun clientRun1 = new StringClientRun(part1, styles);
			clientRuns.Add(clientRun1);
			source = new TextSource(clientRuns, MockInterpretOrc);
			runs = source.Runs;
			Assert.AreEqual(1, runs.Length);
			VerifyRun(0, clientRun1, 0, 0, part1, runs[0], "first run of (empty, abc) source");
			Assert.AreEqual(part1.Length, source.Length, "length of (empty, abc) source");

			// (empty, box) keeps empty
			BlockBox box = new BlockBox(styles, Color.Red, 72000, 36000);
			clientRuns[1] = box;
			source = new TextSource(clientRuns, MockInterpretOrc);
			runs = source.Runs;
			Assert.AreEqual(2, runs.Length);
			VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of (empty, box) source");
			VerifyRun(0, box, 0, 0, "\xfffc", runs[1], "2nd run of (empty, box) source");
			Assert.AreEqual(1, source.Length, "length of (empty, box) source");

			// Two adjacent empty strings produce a single run for the first client run.

			clientRuns.RemoveAt(1);
			StringClientRun clientRun1e = new StringClientRun(part0, styles);
			clientRuns.Add(clientRun1e);
			source = new TextSource(clientRuns, MockInterpretOrc);
			runs = source.Runs;
			Assert.AreEqual(1, runs.Length);
			VerifyRun(0, clientRun0, 0, 0, "", runs[0], "first run of (empty, empty) source");
			Assert.AreEqual(0, source.Length, "length of (empty, empty) source");

			// (something,empty) keeps the something.
			clientRuns[0] = clientRun1;
			source = new TextSource(clientRuns, MockInterpretOrc);
			runs = source.Runs;
			Assert.AreEqual(1, runs.Length);
			VerifyRun(0, clientRun1, 0, 0, part1, runs[0], "first run of (abc, empty) source");
			Assert.AreEqual(part1.Length, source.Length, "length of (abc, empty) source");

			// (box, empty) keeps empty
			clientRuns[0] = box;
			source = new TextSource(clientRuns, MockInterpretOrc);
			runs = source.Runs;
			Assert.AreEqual(2, runs.Length);
			VerifyRun(0, box, 0, 0, "\xfffc", runs[0], "first run of (box, empty) source");
			VerifyRun(1, clientRun1e, 1, 0, "", runs[1], "2nd run of (box, empty) source");
			Assert.AreEqual(1, source.Length, "length of (box, empty) source");


		}
Ejemplo n.º 37
0
		public void NestedDivsLayout()
		{
			var styles = new AssembledStyles();
			BlockBox box1 = new BlockBox(styles, Color.Red, 72000, 36000);
			BlockBox box2 = new BlockBox(styles, Color.Blue, 108000, 18000);
			BlockBox box3 = new BlockBox(styles, Color.Orange, 72000, 18000);
			BlockBox box4 = new BlockBox(styles, Color.Orange, 72000, 18000);
			var div1 = new DivBox(styles);
			var div2 = new DivBox(styles);
			div1.AddBox(box1);
			div1.AddBox(box2);
			div2.AddBox(box3);
			div2.AddBox(box4);
			RootBox root = new RootBox(styles);
			root.AddBox(div1);
			root.AddBox(div2);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			Assert.That(box1.Height, Is.EqualTo(48));
			Assert.That(box2.Height, Is.EqualTo(24));
			Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24));
			Assert.That(box1.Left, Is.EqualTo(0));
			Assert.That(box2.Left, Is.EqualTo(0));
			Assert.That(box1.Top, Is.EqualTo(0));
			Assert.That(box2.Top, Is.EqualTo(48));
			Assert.That(div2.Top, Is.EqualTo(48 + 24));
			Assert.That(box4.Top, Is.EqualTo(24));
			Assert.That(box1.Width, Is.EqualTo(96));
			Assert.That(box2.Width, Is.EqualTo(144));
			Assert.That(root.Width, Is.EqualTo(144));

			// Now try changing the size of a block.
			MockSite site = new MockSite();
			root.Site = site;
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			box2.UpdateSize(144000, 36000);
			Assert.That(box2.Width, Is.EqualTo(96*2));
			Assert.That(box2.Height, Is.EqualTo(48));
			Assert.That(div1.Height, Is.EqualTo(96)); // two children now both 48 high.
			Assert.That(root.Height, Is.EqualTo(48 +48 + 24 + 24)); // new heights of 4 children.
			Assert.That(root.Width, Is.EqualTo(96*2));
			// Since it got both wider and higher, we should invalidate at least the whole current size.
			var bigInvalidate = root.InvalidateRect;
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 36000);
			Assert.That(root.Height, Is.EqualTo(48 + 48 + 24 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(144)); // narrower box2 still determines it
			// Got narrower, at least the whole old invalidate rectangle should be invalidated.
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24 + 24 + 24)); // new smaller value
			Assert.That(root.Width, Is.EqualTo(144)); //  unchanged this time
			// It got shorter. We want an optimized invalidate rectangle that does not
			// include the top box. But it must include the space at the bottom that the root box used to occupy.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (its in the fixmap so its own Relayout does this);
			// the shrinkage area at the bottom of div2;
			// and the area computed because div2 moved.
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 48); // old box2
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of div1
			// This is from the new top of div2 to its old bottom (old bottom was 48 + 48 + 24 + 24)
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 72000);
			Assert.That(root.Height, Is.EqualTo(48 + 96 + 24 + 24)); // new larger value
			Assert.That(root.Width, Is.EqualTo(144)); //  unchanged this time
			// It got longer. We want an optimized invalidate rectangle that does not
			// include the top box. But it must include the space at the bottom where the root box grew.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it returns true from Relayout);
			// the growth area at the bottom of div2;
			// and the area computed because div2 moved.
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
			// This is from the old top of div2 to its new bottom (48 + 96 + 24 + 24)
			VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
		}
Ejemplo n.º 38
0
		public void ValidSelections()
		{
			AssembledStyles styles = new AssembledStyles();
			var clientRuns = new List<IClientRun>();
			var run0 = new StringClientRun("First run", styles);
			var run1 = new StringClientRun("Middle run", styles);
			BlockBox box0 = new BlockBox(styles, Color.Red, 72000, 36000);
			var run2 = new StringClientRun("Last run", styles);
			clientRuns.Add(run0);
			clientRuns.Add(run1);
			clientRuns.Add(box0);
			clientRuns.Add(run2);
			TextSource source = new TextSource(clientRuns, null);
			ParaBox para0 = new ParaBox(styles, source);
			run0.Hookup = new LiteralStringParaHookup(para0, para0);
			run1.Hookup = new LiteralStringParaHookup(para0, para0);
			run2.Hookup = new LiteralStringParaHookup(para0, para0);
			DivBox div = new DivBox(styles);
			RootBox root = new RootBox(styles);
			para0.Container = div;
			MockGraphics graphics = new MockGraphics();
			LayoutInfo layoutArgs = ParaBuilderTests.MakeLayoutInfo(100, graphics);
			root.Layout(layoutArgs);

			root.AddBox(div);
			var sel = para0.SelectAtStart();
			root.Selection = sel;

			Assert.That(!root.Selection.IsValid);

			div.AddBox(para0);
			root.RemoveBoxes(div, div);
			div.Container = root;

			Assert.That(!root.Selection.IsValid);

			root.AddBox(div);

			Assert.That(root.Selection.IsValid);

			(root.Selection as InsertionPoint).Hookup.ClientRunIndex = 4;

			Assert.That(!root.Selection.IsValid);

			(root.Selection as InsertionPoint).Hookup.ClientRunIndex = 2;

			Assert.That(!root.Selection.IsValid);

			(root.Selection as InsertionPoint).Hookup.ClientRunIndex = 0;
			(root.Selection as InsertionPoint).StringPosition = 10;

			Assert.That(!root.Selection.IsValid);

			(root.Selection as InsertionPoint).StringPosition = 0;
			run0.Hookup = null;

			Assert.That(!root.Selection.IsValid);

			run0.Hookup = new LiteralStringParaHookup(para0, para0);
			sel = para0.SelectAtStart();
			root.Selection = sel;

			Assert.That(root.Selection.IsValid);
		}