Click here to Skip to main content
15,883,929 members
Articles / Programming Languages / C#

DeltaScope

Rate me:
Please Sign up or sign in to vote.
4.96/5 (10 votes)
1 Sep 2009CPOL2 min read 37.5K   408   17  
A reusable delta engine with GDI+ front-end controls.
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace ErkerTech.DeltaScope.View.Models
{
    public class MoveStruct
    {
        public int LeftMove;
        public int RightMove;

        public MoveStruct ()
        {
            LeftMove = -1;
            RightMove = -1;
        }

        public MoveStruct(int tnLeft, int tnRight)
        {
            LeftMove = tnLeft * -1;
            RightMove = tnRight * -1;
        }
    }

    public class LineInfo
    {
        public string Line;
        public int Top;
        public int Height;

        public LineInfo(string tsLine)
        {
            Line = tsLine;
            Top	= 0;
            Height = 0;
        }

        public LineInfo(string tsLine, int tnTop, int tnHeight)
        {
            Line = tsLine;
            Top = tnTop;
            Height = tnHeight;
        }
    }

    public class SideStructure
    {
        public string Text;
        public LineInfo [] ALines;
        public Rectangle Rect;

        public SideStructure(string tsText)
        {
            Text = tsText;
            Rect = Rectangle.Empty;
            ALines = ParseText(tsText);
        }

        public SideStructure ( IList<string> tsTextList )
        {
            Rect = Rectangle.Empty;

            var sb = new StringBuilder();
            for (var i = 0; i < tsTextList.Count; i++)
                sb.AppendLine(tsTextList[i]);

            Text = sb.ToString();
            ALines = ParseText(Text);
        }

        public void MoveRectTop(int tnTopDelta)
        {
            Rect = new Rectangle(Rect.Left, Rect.Top + tnTopDelta, Rect.Width, Rect.Height);
            foreach (var loLine in ALines)
                loLine.Top += tnTopDelta;
        }

        private static LineInfo[] ParseText(string tsText)
        {
            var loList = new List<LineInfo>();
            foreach (var lsLine in tsText.Split('\n'))
                loList.Add(new LineInfo(lsLine));

            return loList.ToArray();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions