Esempio n. 1
0
        public DetailsView(BohemianArtifact bbshelf, Vector3 position, Vector3 size)
        {
            bookshelf = bbshelf;
            bookshelf.Library.SelectedArtifactChanged += new ArtifactLibrary.SelectedArtifactHandler(library_SelectedArtifactChanged);
            bookshelf.Library.LanguageChanged += new ArtifactLibrary.ChangeLanguageHandler(Library_LanguageChanged);
            this.position = position;
            this.size = size;
            font = bookshelf.Content.Load<SpriteFont>("Arial");

            titleText = new SelectableText(font, "Details", new Vector3(0.4f, 0, 0), bookshelf.GlobalTextColor, Color.White);
            titleText.InverseScale(0.8f, size.X, size.Y);

            boundingBox = new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 0), Color.Black, 0.005f);
            roundedBox = new RoundedBoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 0), new Color(200, 200, 200), 0.008f, this);
            float maxWidth = 0.5f; // as a percentage of the width of the details box

            maxImageBox = new SelectableQuad(new Vector2(0, 0), new Vector2(maxWidth, maxWidth * size.X / size.Y), Color.White);
            rotationRange = new FloatRange(0, 10, 1, (float)(-Math.PI / 24), (float)(Math.PI / 24));

            batch = new SpriteBatch(XNA.GraphicsDevice);
            headerScale = 0.9f;
            subheaderScale = 0.7f;
            bodyScale = 0.55f;

            heightOfBodyLine = font.MeasureString("Eg").Y * bodyScale; // Eg = a high capital letter + low-hanging lowercase to fill the space
            heightofSpaceBetweenLines = font.MeasureString("Eg\nEg").Y * bodyScale - 2 * heightOfBodyLine;

            //setLengths(bbshelf.Library.Artifacts); // for debugging

            maxImageBox.TouchReleased += new TouchReleaseEventHandler(maxImageBox_TouchReleased);
            //bbshelf.SelectableObjects.AddObject(maxImageBox); // for debugging
        }
        public TimelineView(BohemianArtifact bbshelf, Vector3 p, Vector3 s)
        {
            bookshelf = bbshelf;
            bookshelf.Library.SelectedArtifactChanged += new ArtifactLibrary.SelectedArtifactHandler(library_SelectedArtifactChanged);
            position = p;
            size = s;
            font = bookshelf.Content.Load<SpriteFont>("Kootenay");
            lineBookTable = new Hashtable();

            CreateLinesFromBooks();

            cross1 = new SelectableLine(new Vector3(0, 0.2f, 0), new Vector3(0, 0.9f, 0), Color.Blue, 10);
            cross2 = new SelectableLine(new Vector3(1, 0.2f, 0), new Vector3(1, 0.9f, 0), Color.Red, 10);

            titleText = new SelectableText(font, "Timeline View", new Vector3(0.4f, 0, 0), bookshelf.GlobalTextColor, Color.White);
            titleText.InverseScale(0.5f, size.X, size.Y);

            topBar = new SelectableQuad(new Vector2(0, 0.1f), new Vector2(1, 0.1f), Color.LightGray);
            bookshelf.SelectableObjects.AddObject(topBar);
            bottomBar = new SelectableQuad(new Vector2(0, 0.9f), new Vector2(1, 0.1f), Color.LightGray);
            bookshelf.SelectableObjects.AddObject(bottomBar);

            topOffset = 0;
            bottomOffset = 1;
        }
Esempio n. 3
0
        protected override void LoadContent()
        {
            string filename = System.Windows.Forms.Application.ExecutablePath;
            string path = System.IO.Path.GetDirectoryName(filename) + "\\Resources\\";

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

            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            rasterizerState.MultiSampleAntiAlias = true;
            XNA.GraphicsDevice.RasterizerState = rasterizerState;
            BlendState bs = BlendState.NonPremultiplied;
            //BlendState bs1 = BlendState.Additive;
            blendState = new BlendState();
            blendState.AlphaBlendFunction = BlendFunction.Add;
            blendState.ColorBlendFunction = BlendFunction.Add;
            blendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
            blendState.AlphaSourceBlend = Blend.SourceAlpha;
            blendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
            blendState.ColorSourceBlend = Blend.SourceAlpha;
            blendState = BlendState.AlphaBlend;

            // this creates an origin at screen coordinates 0, 0 and makes the Y axis increase as you move down the screen
            Matrix world = Matrix.CreateTranslation(-presentation.BackBufferWidth / 2, -presentation.BackBufferHeight / 2, 0) * Matrix.CreateScale(1, -1, 1);
            Matrix 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);
            Matrix projection = Matrix.CreateOrthographic(Program.WindowSize.Width, Program.WindowSize.Height, 0.01f, 100.0f);

            // initialize the global effect with the world, view, and projection matricies and several drawing flags
            XNA.Effect.World = world;
            XNA.Effect.View = view;
            XNA.Effect.Projection = projection;
            XNA.VertexColor = true;
            XNA.Texturing = false;
            XNA.ApplyEffect();

            // 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.Red, Vector2.Zero);
            touchCrosshair[1] = new VertexPositionColorTexture(new Vector3(2, 0, 0), Color.Green, Vector2.Zero);
            touchCrosshair[2] = new VertexPositionColorTexture(new Vector3(0, -2, 0), Color.Blue, Vector2.Zero);
            touchCrosshair[3] = new VertexPositionColorTexture(new Vector3(0, 2, 0), Color.Yellow, Vector2.Zero);

            // initialize the graphics device for all selectable objects
            SelectableObject.SetGraphicsDevice(GraphicsDevice);
            // initialize the graphics device for SelectableText elements
            SelectableText.Initialize();
            // and load our fonts
            spriteFont = Content.Load<SpriteFont>("Arial");
            XNA.Font = spriteFont;

            globalTextColor = new Color(0.7f, 0.7f, 0.7f, 1);

            // create the selectable object manager which will issue colors to all objects that need hit testing
            selectableObjects = new SelectableObjectManager();

            // load the book library
            //library = new ArtifactLibrary("small_sample.xml");
            library = new ArtifactLibrary("large_sample_sorted_colors.xml");
            Console.WriteLine("loaded library");

            // create the visualization objects
            // we are using the screen width for the x and y calculation, so the max y value is 9/16 (0.5625f)
            float viewPadding = 0.025f;

            float languageSize = 0.04f;
            float languageLeft = 0.002f;
            float languageTop = 0.002f;

            float materialSize = 0.3f;
            float materialLeft = viewPadding;
            float materialTop = viewPadding;

            float colorSize = materialSize;
            float colorLeft = materialLeft + materialSize + viewPadding;
            float colorTop = viewPadding;

            float keywordSize = materialSize;
            float keywordLeft = colorLeft + materialSize + viewPadding;
            float keywordTop = viewPadding;
            float infoSize = materialSize;
            float infoLeft = viewPadding;
            float infoTop = materialTop + materialSize + viewPadding;
            float timelineSize = 0.6f; // timeline is only 0.3 * size in height (e.g. 0.15)
            float timelineLeft = infoLeft + infoSize + viewPadding;
            float timelineTop = keywordTop + keywordSize + viewPadding;

            float detailsWidth = 0.3f;
            float detailsHeight = 0.2f;
            float detailsLeft = viewPadding;
            float detailsTop = keywordTop + keywordSize + viewPadding;

            //float timelineTop = 1 - timelineSize * 0.3f - viewPadding;
            languageView = new LanguageView(this, new Vector3(languageLeft * presentation.BackBufferWidth, languageTop * presentation.BackBufferWidth, 0), new Vector3(languageSize * presentation.BackBufferWidth, languageSize * presentation.BackBufferWidth, 1));
            materialView = new MaterialsView(this, new Vector3(materialLeft * presentation.BackBufferWidth, materialTop * presentation.BackBufferWidth, 0), new Vector3(materialSize * presentation.BackBufferWidth, materialSize * presentation.BackBufferWidth, 1));
            colorView = new ColorView(this, new Vector3(colorLeft * presentation.BackBufferWidth, colorTop * presentation.BackBufferWidth, 0), new Vector3(colorSize * presentation.BackBufferWidth, colorSize * presentation.BackBufferWidth, 1));
            keywordView = new KeywordView(this, new Vector3(keywordLeft * presentation.BackBufferWidth, keywordTop * presentation.BackBufferWidth, 0), new Vector3(keywordSize * presentation.BackBufferWidth, keywordSize * presentation.BackBufferWidth, 1));
            timelineView = new TimelineView(this, new Vector3(timelineLeft * presentation.BackBufferWidth, timelineTop * presentation.BackBufferWidth, 0), new Vector3(timelineSize * presentation.BackBufferWidth, timelineSize * presentation.BackBufferWidth, 1));
            detailsView = new DetailsView(this, new Vector3(detailsLeft * presentation.BackBufferWidth, detailsTop * presentation.BackBufferWidth, 0), new Vector3(detailsWidth * presentation.BackBufferWidth, detailsHeight * presentation.BackBufferWidth, 1));
            //timelineView = new TimelineView(this, new Vector3(400, 400, 0), new Vector3(1500, 1500, 1));

            // select a random artifact
            int numArtifacts = library.Artifacts.Count;
            int artifactIndex = random.Next(numArtifacts);
            artifactIndex = 0;
            library.SelectArtifact(library.Artifacts[artifactIndex]);

            FileStream file = new FileStream("texture\\material\\metal_2.jpg", FileMode.Open);
            Texture2D texture = Texture2D.FromStream(GraphicsDevice, file);
            file.Close();
            blobTest1 = new SelectableBlob(new Vector2(100, 1000), new Vector2(300, 1200), -10, 20, 10, Color.LightGray, Color.LightGray, Color.White, ref blob1Angle);
            //blobTest2 = new SelectableBlob(new Vector2(1000, 500), 80, Color.White, texture);
            blobTest2 = new SelectableBlob(new Vector2(1000, 500), 0*(float)Math.PI / 4, 0, 0, 10, Color.Red, Color.Blue, Color.Green, texture);
            blobTest2.CircleRadius = 40;
            blobTest2.MiddleRadius = 0;
            timer = new Timer(1);
            selectableObjects.AddObject(blobTest2);

            Color c1 = Color.Navy;
            //c1.A = 127;
            Color c2 = new Color(0.0f, 1.0f, 0.0f, 1.0f);
            //c2.A = 127;
            rectTest1 = new SelectableQuad(new Vector3(100, 100, -10), new Vector3(400, 100, -10), new Vector3(400, 800, -10), new Vector3(100, 800, -10), c1);
            rectTest2 = new SelectableQuad(new Vector3(200, 200, 0), new Vector3(600, 200, 0), new Vector3(600, 600, 0), new Vector3(200, 600, 0), c2);
            rectTest2.Points[0].Color = Color.Transparent;
            rectTest2.Points[3].Color.A = 0;
            /* test the Selectable objects
            lineTest = new SelectableLine(new Vector3(50, 50, 0), new Vector3(2000, 1000, 0), Color.Red, 20);
            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, "Kootenay", new Vector3(980, 780, 0), 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, 0, 0), Color.Red);
            verts[1] = new VertexPositionColor(new Vector3(2000, 0, 0), Color.Green);
            verts[2] = new VertexPositionColor(new Vector3(1000, 2000, 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);
            //*/
        }
Esempio n. 4
0
 private void setImageLocation(Artifact selectedArtifact)
 {
     int w = selectedArtifact.Texture.Width, h = selectedArtifact.Texture.Height;
     if (w > h)
         imageBox = new SelectableQuad(new Vector2(0, 0), new Vector2(w / 512f * maxImageBox.Width, h / 512f * maxImageBox.Height), Color.White);
     else
         imageBox = new SelectableQuad(new Vector2(0, 0), new Vector2(w / 512f * maxImageBox.Width, h / 512f * maxImageBox.Height), Color.White);
 }