public TimelineView(BookLibrary lib, Vector3 p, Vector3 s)
        {
            library = lib;
            library.SelectedBookChanged += new BookLibrary.SelectedBookHandler(library_SelectedBookChanged);
            position = p;
            size = s;
            cross1 = new SelectableLine(new Vector3(0, 0, 0), new Vector3(1, 1, 0), Color.Purple, 10);
            cross2 = new SelectableLine(new Vector3(1, 0, 0), new Vector3(0, 1, 0), Color.Pink, 10);
            //text1 = new SelectableText(new Vector2(0.5f, 0.5f), "Timeline View", Color.Black);

            lineList = new SelectableLine[10];
            for (int i = 0; i < 10; i++)
            {
                lineList[i] = new SelectableLine(new Vector3(i * 0.1f, 0, 0), new Vector3(i * 0.1f, 1, 0), Color.Red, 10);
            }
        }
Exemple #2
0
        protected override void LoadContent()
        {
            //whiteTexture = Content.Load<Texture2D>("white");

            string filename = System.Windows.Forms.Application.ExecutablePath;
            string path = System.IO.Path.GetDirectoryName(filename) + "\\Resources\\";

            // setup the render target for picking objects
            PresentationParameters pickerPP = GraphicsDevice.PresentationParameters;
            colorPickerTarget = new RenderTarget2D(GraphicsDevice, pickerPP.BackBufferWidth, pickerPP.BackBufferHeight, false, pickerPP.BackBufferFormat, pickerPP.DepthStencilFormat);
            colorPickerData = new Color[pickerPP.BackBufferWidth * pickerPP.BackBufferHeight];

            // this creates an origin at screen coordinates 0, 0 and makes the Y axis increase as you move down the screen
            world = Matrix.CreateTranslation(0, 0, 0) * Matrix.CreateScale(1, 1, 1);
            //world = Matrix.CreateTranslation(0, 0, 0);
            view = Matrix.CreateLookAt(new Vector3(0, 0, 30), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            //projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.01f, 100f);//graphics.GraphicsDevice.DrawPrimitives(PrimitiveType.LineList, 0, 1);
            projection = Matrix.CreateOrthographic(Program.WindowSize.Width, Program.WindowSize.Height, 0.01f, 100.0f);

            // setup the effect we will use to render with. the important part is the view and projection matricies, and vertex coloring.
            basicEffect = new BasicEffect(GraphicsDevice);
            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.VertexColorEnabled = true;

            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            rasterizerState.MultiSampleAntiAlias = true;
            GraphicsDevice.RasterizerState = rasterizerState;

            // this creates two lines that form a crosshair to show where the user is touching. this crosshair should be scaled to the size of the touchpoint
            touchCrosshair = new VertexPositionColorTexture[4];
            touchCrosshair[0] = new VertexPositionColorTexture(new Vector3(-2, 0, 0), Color.DarkGray, Vector2.Zero);
            touchCrosshair[1] = new VertexPositionColorTexture(new Vector3(2, 0, 0), Color.DarkGray, Vector2.Zero);
            touchCrosshair[2] = new VertexPositionColorTexture(new Vector3(0, -2, 0), Color.DarkGray, Vector2.Zero);
            touchCrosshair[3] = new VertexPositionColorTexture(new Vector3(0, 2, 0), Color.DarkGray, Vector2.Zero);

            // load the book library
            library = new BookLibrary("library.txt");

            // initialize the graphics device for SelectableText elements
            SelectableText.Initialize(GraphicsDevice);
            // and load our fonts
            //kootenayFont = Content.Load<SpriteFont>("Kootenay");

            // create the selectable object manager which will issue colors to all objects that need hit testing
            selectableObjects = new SelectableObjectManager();
            // create the timeline object
            timelineView = new TimelineView(library, new Vector3(100, 100, 0), new Vector3(1200, 800, 1));

            //* load testing quads and quads with emissive color. regular quads win in performance
            int numBoxes = 2000;
            int boxSize = 15;
            int radius = 700;
            quads = new SelectableQuad[numBoxes];
            Vector3[] points = new Vector3[4];
            for (int i = 0; i < numBoxes; i++)
            {
                points[0] = new Vector3(-boxSize, -boxSize, 0);
                points[1] = new Vector3(boxSize, -boxSize, 0);
                points[2] = new Vector3(boxSize, boxSize, 0);
                points[3] = new Vector3(-boxSize, boxSize, 0);
                Color newColor = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
                SelectableQuad newQuad = new SelectableQuad(points[0], points[1], points[2], points[3], newColor);
                // give this box a random position
                newQuad.Position = Vector3.Transform(new Vector3((float)Math.Sqrt(r.NextDouble()) * radius, 0, 0), Matrix.CreateRotationZ((float)(r.NextDouble() * 2 * Math.PI)));
                newQuad.RotationSpeed = 5 * (float)r.NextDouble() / (float)Math.Sqrt(Math.Abs(newQuad.Position.X));
                quads[i] = newQuad;
                selectableObjects.AddObject(newQuad);
            }
            //*/

            /* test the Selectable objects
            lineTest = new SelectableLine(new Vector3(50, 50, 0), new Vector3(2000, 1000, 0), Color.Red, 10);
            rectTest1 = new SelectableQuad(new Vector3(100, 100, 0), new Vector3(400, 100, 0), new Vector3(400, 800, 0), new Vector3(100, 800, 0), Color.Navy);
            rectTest2 = new SelectableQuad(new Vector3(700, 100, 0), new Vector3(1000, 100, 0), new Vector3(1000, 800, 0), new Vector3(700, 800, 0), Color.Green);
            textTest = new SelectableText(kootenayFont, "T", new Vector2(980, 780), Color.Red, Color.Orange);
            //textTest.SetQuadColor(new Color(1, 0.7f, 0, 0.1f));
            //textTest.Rotation = 1;
            //textTest.Recompute();

            selectableObjects.AddObject(lineTest);
            selectableObjects.AddObject(rectTest1);
            selectableObjects.AddObject(rectTest2);
            selectableObjects.AddObject(textTest);
            //*/

            // this is to test rendering triangles and lines with user defined primary objects
            //verts = new VertexPositionColor[5];
            //verts[0] = new VertexPositionColor(new Vector3(0, 100, 0), Color.Red);
            //verts[1] = new VertexPositionColor(new Vector3(-100, -50, 0), Color.Green);
            //verts[2] = new VertexPositionColor(new Vector3(100, -50, 0), Color.Blue);

            //verts[3] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Yellow);
            //verts[4] = new VertexPositionColor(new Vector3(500, 100, 0), Color.Yellow);

            // this is to test loading of the screen with a grid of many many vertical and horizontal lines
            //int pixelsPerLine = 2;
            //hLines = new VertexPositionColor[2 * GraphicsDevice.DisplayMode.Width / pixelsPerLine];
            //vLines = new VertexPositionColor[2 * GraphicsDevice.DisplayMode.Height / pixelsPerLine];
            //for (int i = 0; i < 2 * GraphicsDevice.DisplayMode.Width / pixelsPerLine; i += 2)
            //{
            //    hLines[i] = new VertexPositionColor(new Vector3(i * pixelsPerLine / 2, 0, 0), Color.White);
            //    hLines[i + 1] = new VertexPositionColor(new Vector3(i * pixelsPerLine / 2, GraphicsDevice.DisplayMode.Height, 0), Color.Gray);
            //}
            //for (int i = 0; i < 2 * GraphicsDevice.DisplayMode.Height / pixelsPerLine; i += 2)
            //{
            //    vLines[i] = new VertexPositionColor(new Vector3(0, i * pixelsPerLine / 2, 0), Color.White);
            //    vLines[i + 1] = new VertexPositionColor(new Vector3(GraphicsDevice.DisplayMode.Width, i * pixelsPerLine / 2, 0), Color.Gray);
            //}
            //*/

            // test drawing text to the screen, including a background color behind the text (eventually for hit testing)
            //spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            //Vector2 textSize = spriteFont.MeasureString("Testing");
            //spriteTexture = new Texture2D(GraphicsDevice, (int)textSize.X, (int)textSize.Y);
            //Color[] textureColor = new Color[(int)textSize.X * (int)textSize.Y];
            //for (int i = 0; i < textureColor.Length; i++)
            //{
            //    textureColor[i] = Color.Salmon;
            //    textureColor[i].A = 200;
            //}
            //spriteTexture.SetData<Color>(textureColor);

            // test the backbuffer renderer
            /*
            GraphicsDevice.SetRenderTarget(colorPickerTarget);
            Draw(new GameTime());
            GraphicsDevice.SetRenderTarget(null);
            FileStream pngFile = new FileStream("pickerTarget.png", FileMode.Create);
            colorPickerTarget.SaveAsPng(pngFile, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            //*/
        }