Esempio n. 1
0
        /// <summary>
        /// Event handler updates the spinning triangle control when
        /// one of the three vertex color combo boxes is altered.
        /// </summary>
        void vertexColor_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            // Which vertex was changed?
            int vertexIndex;

            if (sender == vertexColor1)
            {
                vertexIndex = 0;
            }
            else if (sender == vertexColor2)
            {
                vertexIndex = 1;
            }
            else if (sender == vertexColor3)
            {
                vertexIndex = 2;
            }
            else
            {
                return;
            }

            // Which color was selected?
            ComboBox combo = (ComboBox)sender;

            string colorName = combo.SelectedItem.ToString();

            GdiColor gdiColor = GdiColor.FromName(colorName);

            XnaColor xnaColor = new XnaColor(gdiColor.R, gdiColor.G, gdiColor.B);

            // Update the spinning triangle control with the new color.
            spinningTriangleControl.Vertices[vertexIndex].Color = xnaColor;
        }
        static void DrawEnemyIndicator(THMHJ.Game __instance, SpriteBatch spriteBatch)
        {
            var _this = __instance.AsDynamic();

            if (_this.stm.IsBossed())
            {
                float x = _this.stm.GetBosspos().X;
                float a = 0.0f;
                if (x >= 50.0f && x <= 390.0f)
                {
                    a = 1f;
                }
                if (x < 50.0f)
                {
                    a = x >= 0.0f ? x / 50f : 0.0f;
                }
                else if (x > 390.0f)
                {
                    a = x <= 440.0f ? (x - 390.0f) / 50.0f : 0.0f;
                }
                Vector2 position = new Vector2(x, 482f);
                var     color    = new XnaColor(1f, 1f, 1f, a);
                spriteBatch.Draw(_this.gr.bosslist.RealObject, position, srcRec, color, 0.0f, origin, 1f, none, 0.0f);
            }
        }
Esempio n. 3
0
        private void drawBoxes()
        {
            XnaColor constantBox = XnaColor.Lerp(Level.BackgroundColor.Inverted, XnaColor.Red, .5f);
            XnaColor screenBox   = XnaColor.Lerp(Level.BackgroundColor.Inverted, XnaColor.Blue, .5f);

            Vector topLeft  = ActiveCamera.getGameCoordinate(Vector.Zero);
            Vector botRight = ActiveCamera.getGameCoordinate(new Vector(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight));



            //draw screen-box
            int    screenWidth  = 1280;
            int    screenHeight = 720;
            Vector screenSize   = new Vector(screenWidth, screenHeight);
            Vector center       = (topLeft + botRight) / 2;

            Vector screenTopLeft  = center - screenSize / 2;
            Vector screenBotRight = center + screenSize / 2;
            Vector screenBoxSize  = screenBotRight - screenTopLeft;



            drawBox(spriteBatch, screenBox, .02f, 4, screenTopLeft, screenBotRight);
            drawBox(spriteBatch, constantBox, .03f, 8, Vector.Zero, Vector.Zero + screenSize);

            if (Level.PreviewHud)
            {
                spriteBatch.Draw(hudObjectsTarget, screenTopLeft, null, XnaColor.White);
            }
        }
Esempio n. 4
0
        private void drawLine(SpriteBatch spriteBatch, XnaColor color, float depth, Vector start, Vector end, float thickness)
        {
            Vector diff = end - start;

            thickness /= (ActiveCamera.Zoom / .5f);
            spriteBatch.Draw(getPixel(), start, null, color, (float)Math.Atan2(diff.Y, diff.X), new Vector2(0, .5f), new Vector(diff.Length, thickness), SpriteEffects.None, depth);
        }
Esempio n. 5
0
 private void drawBox(SpriteBatch spriteBatch, XnaColor color, float depth, float thickness, Vector topLeft, Vector botRight)
 {
     drawLine(spriteBatch, color, depth, topLeft, new Vector(botRight.X, topLeft.Y), thickness);
     drawLine(spriteBatch, color, depth, topLeft, new Vector(topLeft.X, botRight.Y), thickness);
     drawLine(spriteBatch, color, depth, botRight, new Vector(topLeft.X, botRight.Y), thickness); //bottom line
     drawLine(spriteBatch, color, depth, botRight, new Vector(botRight.X, topLeft.Y), thickness);
 }
Esempio n. 6
0
 protected XnaDrawObject()
 {
     Name = "";
     Fill = new XnaColor(Color.Transparent);
     Id   = 0;
     SetId();
 }
Esempio n. 7
0
        private void drawGrid()
        {
            Vector topLeft  = ActiveCamera.getGameCoordinate(Vector.Zero);
            Vector botRight = ActiveCamera.getGameCoordinate(new Vector(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight));
            Vector size     = botRight - topLeft;


            float    intensity = Level.BackgroundColor.Intensity;
            XnaColor lineColor = Level.BackgroundColor.Inverted;

            if (intensity > .4f && intensity < .6f)
            {
                lineColor = XnaColor.Lerp(lineColor, XnaColor.White, 1 - Math.Abs(.5f - intensity));
            }


            float currY = GridManager.Instance.snapY(topLeft.Y);//topLeft.Y - (topLeft.Y % gridSize);

            while (currY < botRight.Y)
            {
                XnaColor color = lineColor;
                if (currY == 0)
                {
                    color = Level.BackgroundColor.Inverted;
                }
                drawLine(spriteBatch, ((WhiskeyColor)lineColor).Inverted, 0f, new Vector(topLeft.X, currY), new Vector(botRight.X, currY), 8f);
                drawLine(spriteBatch, color, .01f, new Vector(topLeft.X, currY), new Vector(botRight.X, currY), 4f);
                spriteBatch.DrawString(WhiskeyControl.Resources.getDefaultFont(), "" + currY, new Vector2(topLeft.X, currY - WhiskeyControl.Resources.getDefaultFont().MeasureString("A").Y), XnaColor.Tomato, 0, Vector2.Zero, 1 / ActiveCamera.Zoom, SpriteEffects.None, .04f);

                currY += GridManager.Instance.GridSizeY;
            }

            float currX = GridManager.Instance.snapX(topLeft.X);//topLeft.X - (topLeft.X % gridSize);

            while (currX < botRight.X)
            {
                XnaColor color = lineColor;
                if (currX == 0)
                {
                    color = Level.BackgroundColor.Inverted;
                }
                drawLine(spriteBatch, ((WhiskeyColor)lineColor).Inverted, 0f, new Vector(currX, topLeft.Y), new Vector(currX, botRight.Y), 8.0f);
                drawLine(spriteBatch, color, .01f, new Vector(currX, topLeft.Y), new Vector(currX, botRight.Y), 4.0f);

                spriteBatch.DrawString(WhiskeyControl.Resources.getDefaultFont(), "" + currX, new Vector2(currX - WhiskeyControl.Resources.getDefaultFont().MeasureString("A").X, topLeft.Y), XnaColor.Tomato, (float)Math.PI / 2f, Vector2.Zero, 1 / ActiveCamera.Zoom, SpriteEffects.None, .04f);


                currX += GridManager.Instance.GridSizeX;
            }
        }
Esempio n. 8
0
        public XnaColor GetPixel(int x, int y)
        {
            var target = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);

            GraphicsDevice.SetRenderTarget(target);
            HandleDeviceReset();

            Draw(_spriteBatch);

            GraphicsDevice.SetRenderTarget(null);

            var data = new XnaColor[GraphicsDevice.Viewport.Width * GraphicsDevice.Viewport.Height];

            target.GetData(data);

            return(data[GraphicsDevice.Viewport.Width * y + x]);
        }
Esempio n. 9
0
        /// <summary>
        /// Create a Conic Light based on the size, field of view, and near plane distance.
        /// </summary>
        /// <param name="device">Your game's GraphicsDevice</param>
        /// <param name="size">Maximum size</param>
        /// <param name="FOV">Maximum Field of View</param>
        /// <param name="nearPlaneDistance">Prevents texture from being drawn at this plane distance, originating from the center of light</param>
        /// <returns>Light Texture</returns>
        public static Texture2D CreateConicLight(GraphicsDevice device, int size, float FOV, float nearPlaneDistance)
        {
            /*if (!IsPowerOfTwo(size))
             *  throw new Exception("The size must be a power of 2");*/
            float[,] Data = new float[size, size];

            float center = size / 2;

            FOV = FOV / 2;

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    float Distance = Vector2.Distance(new Vector2(x, y), new Vector2(center));

                    Vector2 Difference = new Vector2(x, y) - new Vector2(center);
                    float   Angle      = (float)Math.Atan2(Difference.Y, Difference.X);

                    if (Distance <= center && Distance >= nearPlaneDistance && Math.Abs(Angle) <= FOV)
                    {
                        Data[x, y] = (center - Distance) / center;
                    }
                    else
                    {
                        Data[x, y] = 0;
                    }
                }
            }

            Texture2D tex = new Texture2D(device, size, size);

            XnaColor[] Data1D = new XnaColor[size * size];
            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    Data1D[x + y * size] = new XnaColor(new Vector3(Data[x, y]));
                }
            }

            tex.SetData <XnaColor>(Data1D);

            return(tex);
        }
Esempio n. 10
0
        public XnaColor GetPixel(int x, int y)
        {
            RenderTarget2D target = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);

            GraphicsDevice.SetRenderTarget(target);
            HandleDeviceReset();

            Draw();

            GraphicsDevice.SetRenderTarget(null);

#if false
            XnaColor[] data = new XnaColor[1];
            target.GetData(0, new Rectangle(x, y, 1, 1), data, 0, data.Length);
            return(data[0]);
#else
            XnaColor[] data = new XnaColor[GraphicsDevice.Viewport.Width * GraphicsDevice.Viewport.Height];
            target.GetData(data);

            return(data[GraphicsDevice.Viewport.Width * y + x]);
#endif
        }
Esempio n. 11
0
        private void bgColorComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            String colorName = bgColorComboBox.Text;

            if (colorName != "Custom...")
            {
                PropertyInfo colorProperty = typeof(XnaColor).GetProperty(colorName);
                if (colorProperty != null)
                {
                    XnaColor color = (XnaColor)colorProperty.GetValue(typeof(XnaColor),
                                                                      BindingFlags.Static | BindingFlags.Public, null, null, null);

                    modelViewPanel.BackgroundColor = color;

                    redCustomColorBar.Value   = color.R;
                    greenCustomColorBar.Value = color.G;
                    blueCustomColorBar.Value  = color.B;
                }

                RLabel.Enabled              = false;
                GLabel.Enabled              = false;
                BLabel.Enabled              = false;
                redCustomColorBar.Enabled   = false;
                greenCustomColorBar.Enabled = false;
                blueCustomColorBar.Enabled  = false;
            }
            else
            {
                RLabel.Enabled              = true;
                GLabel.Enabled              = true;
                BLabel.Enabled              = true;
                redCustomColorBar.Enabled   = true;
                greenCustomColorBar.Enabled = true;
                blueCustomColorBar.Enabled  = true;
            }
        }
        public static Vector2 Draw4(SpriteFontX __inst, SpriteBatch sb, char[] str, Vector2 position, Vector2 maxBound, Vector2 scale, XnaColor color)
        {
            Func <Vector2, Vector2> DrawSp = (newPos) => __inst.Draw(sb, str, newPos, maxBound, scale, color);
            var config               = Resource.Config;
            var alterTextCfg         = config.AlterTextCfg;
            var alterFontCfg         = alterTextCfg.AlterFontCfg;
            var protagonistLineColor = alterFontCfg.ProtagonistLineColor;
            var antagonistLineColor  = alterFontCfg.AntagonistLineColor;

            if (TestColor(color, XnaColor.Black))
            {
                if (alterTextCfg.Enabled && alterTextCfg.UseBlackBorder)
                {
                    position.X--; position.Y--;
                    float X = position.X, Y = position.Y;
                    position = new Vector2(X - borderSize, Y - borderSize);
                    DrawSp(position);
                    position = new Vector2(X + borderSize, Y - borderSize);
                    DrawSp(position);
                    position = new Vector2(X + borderSize, Y + borderSize);
                    DrawSp(position);
                    position = new Vector2(X - borderSize, Y + borderSize);
                    DrawSp(position);
                    position = new Vector2(X, Y + borderSize);
                    DrawSp(position);
                    position = new Vector2(X, Y - borderSize);
                    DrawSp(position);
                    position = new Vector2(X - borderSize, Y);
                    DrawSp(position);
                    position = new Vector2(X + borderSize, Y);
                    return(DrawSp(position));
                }
            }
            return(DrawSp(position));
        }
 static public bool TestColor(XnaColor input, XnaColor solid)
 {
     return(input.R == solid.R && input.G == solid.G && input.B == solid.B);
 }
 public static Vector2 Draw3(SpriteFontX __inst, SpriteBatch sb, string str, Vector2 position, Vector2 maxBound, Vector2 scale, XnaColor color)
 {
     return(Draw4(__inst, sb, str.ToCharArray(), position, maxBound, scale, color));
 }
 public static Vector2 Draw2(SpriteFontX __inst, SpriteBatch sb, char[] str, Vector2 position, XnaColor color)
 {
     return(Draw4(__inst, sb, str, position, new Vector2(float.MaxValue, float.MaxValue), Vector2.One, color));
 }
Esempio n. 16
0
 private void drawLine(SpriteBatch spriteBatch, XnaColor color, float depth, Vector start, Vector end)
 {
     drawLine(spriteBatch, color, depth, start, end, 2.0f);
 }
Esempio n. 17
0
        public XnaColor GetPixel( int x, int y )
        {
            var target = new RenderTarget2D( GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None );

            GraphicsDevice.SetRenderTarget( target );
            HandleDeviceReset();

            Draw(_spriteBatch);

            GraphicsDevice.SetRenderTarget( null );

            var data = new XnaColor[ GraphicsDevice.Viewport.Width * GraphicsDevice.Viewport.Height ];
            target.GetData( data );

            return data[ GraphicsDevice.Viewport.Width * y + x ];
        }
 public static Vector2 Draw1(SpriteFontX __inst, SpriteBatch sb, string str, Vector2 position, XnaColor color)
 {
     return(Draw4(__inst, sb, str.ToCharArray(), position, new Vector2(float.MaxValue, float.MaxValue), Vector2.One, color));
 }