示例#1
0
        public static void DrawDottedCircle(float radius, Vector2 center, int segments, float rotation, Renderer renderer, 
            Color col)
        {
            if (segments == 0)
                return;
            VertexPositionColorTexture[] arr = new VertexPositionColorTexture[segments];

            int c = 0;
            Vector2 off = center;
            for (double i = 0; i <= Math.PI * 2 - 0.001d; i += Math.PI * 2 / segments)
            {
                arr[c] = new VertexPositionColorTexture(
                    new Vector3((float)Math.Cos(i + rotation) * radius + off.X, (float)Math.Sin(i + rotation) * radius + off.Y, 0),
                    col, new Vector2());
                c++;
            }

            bool a = renderer.IsDrawing;
            bool b = renderer.IsScaeld;
            if (!renderer.IsDrawing)
                renderer.BeginUnscaled();
            Main.renderer.Draw(MicroWorld.Graphics.GraphicsEngine.pixel, new Rectangle(0, 0, 0, 0), Color.White);
            renderer.End();

            renderer.GraphicsDevice.DrawUserPrimitives<VertexPositionColorTexture>(PrimitiveType.LineList,
                arr, 0, arr.Length / 2);

            if (a) renderer.Begin(b);
        }
示例#2
0
        //MaxValue for screenborder
        public static void DrawDottedLines(float[] x1, float[] y1, float[] x2, float[] y2, Color color, Renderer renderer, 
            bool areGameCoords = false, bool animate = true)
        {
            if (x1.Length == 0 || x1.Length != x2.Length || x1.Length != y1.Length || y1.Length != y2.Length)
                throw new Exception("All coord arrays should be the same length and should not be empty");
            bool a = renderer.IsDrawing;
            bool b = renderer.IsScaeld;
            if (a) renderer.End();
            renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None,
                RasterizerState.CullNone);
            Rectangle r = new Rectangle();
            var vr = GraphicsEngine.camera.VisibleRectangle;
            int animation = -(int)(Main.Ticks % 32) / 4;
            for (int i = 0; i < x1.Length; i++)
            {
                if (areGameCoords)//convert
                {
                    if (x1[i] == float.MaxValue) x1[i] = vr.X + vr.Width;
                    if (y1[i] == float.MaxValue) y1[i] = vr.Y + vr.Height;
                    if (x2[i] == float.MaxValue) x2[i] = vr.X + vr.Width;
                    if (y2[i] == float.MaxValue) y2[i] = vr.Y + vr.Height;

                    Utilities.Tools.GameToScreenCoords(ref x1[i], ref y1[i]);
                    Utilities.Tools.GameToScreenCoords(ref x2[i], ref y2[i]);
                }
                else
                {
                    if (x1[i] == float.MaxValue) x1[i] = Main.WindowWidth;
                    if (y1[i] == float.MaxValue) y1[i] = Main.WindowHeight;
                    if (x2[i] == float.MaxValue) x2[i] = Main.WindowWidth;
                    if (y2[i] == float.MaxValue) y2[i] = Main.WindowHeight;
                }
                r.X = (int)x1[i];
                r.Y = (int)y1[i];
                r.Width = (int)(x2[i] - x1[i]);
                r.Height = (int)(y2[i] - y1[i]);
                r.Width = r.Width <= 0 ? 1 : r.Width;
                r.Height = r.Height <= 0 ? 1 : r.Height;
                if (animate)
                {
                    renderer.Draw(dottedOutline, r,
                        new Rectangle((int)(r.Height == 1 ? r.X + animation : r.X),
                                     (int)(r.Width == 1 ? r.Y + animation : r.Y),
                                     r.Width, r.Height),
                            color);
                }
                else
                    renderer.Draw(dottedOutline, r, r, color);
            }
            renderer.End();
            if (a) renderer.Begin(b);
        }
示例#3
0
        private void DrawDigits(MicroWorld.Graphics.Renderer renderer, float state)
        {
            var    g  = selectedCore.Graphics as Graphics.CoreGraphics;
            int    t  = (int)(state * 100);
            String ts = t.ToString();
            int    w  = Graphics.CoreGraphics.percent.Width + ts.Length * 16;

            w /= 4;
            Vector2 pos = new Vector2((Main.windowWidth - 602) / 2 + 247 + (101 - w * 2) / 2, (Main.WindowHeight - 338) / 2 + circleCenter.Y - 7f);

            for (int i = 0; i < ts.Length; i++)
            {
                renderer.Draw(Graphics.CoreGraphics.digits[ts[i] - '0'], new Rectangle((int)pos.X + i * 8, (int)pos.Y, 8, 10), Color.White);
            }
            renderer.Draw(Graphics.CoreGraphics.percent, new Rectangle((int)pos.X + ts.Length * 8, (int)pos.Y, 12, 10), Color.White);
        }
示例#4
0
        public override void Draw(Renderer renderer)
        {
            renderer.Draw(GraphicsEngine.pixel, new Rectangle(0, 0, Main.WindowWidth, Main.WindowHeight), Shortcuts.BG_COLOR * fadeopacity);

            Vector2 position = new Vector2((Main.WindowWidth - 602) / 2, (Main.WindowHeight - 317) / 2);
            Vector2 size = new Vector2(602, 317);
            bool b = OffsetX != 0;
            if (b)
            {
                renderer.SetScissorRectangle(position.X, position.Y, size.X, size.Y, false);
                renderer.End();
                renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, null,
                    null, MicroWorld.Graphics.GraphicsEngine.s_ScissorsOn, null, Matrix.CreateTranslation(OffsetX, 0, 0));
            }

            renderer.Draw(bg, position, Color.White);
            base.Draw(renderer);
            renderer.Draw(progressbar, new Vector2(position.X + 22, position.Y + 197), Color.White);

            if (b)
                renderer.ResetScissorRectangle();
        }
示例#5
0
        public override void Draw(Renderer renderer)
        {
            renderer.Draw(GraphicsEngine.pixel, new Rectangle(0, 0, Main.WindowWidth, Main.WindowHeight), Shortcuts.BG_COLOR * fadeopacity);

            Vector2 position = new Vector2((Main.WindowWidth - 602) / 2, (Main.WindowHeight - 338) / 2);
            Vector2 size = new Vector2(602, 338);
            bool b = OffsetX != 0;
            if (b)
            {
                renderer.SetScissorRectangle(position.X, position.Y, size.X, size.Y, false);
                renderer.End();
                renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, null,
                    null, MicroWorld.Graphics.GraphicsEngine.s_ScissorsOn, null, Matrix.CreateTranslation(OffsetX, 0, 0));
            }

            renderer.Draw(bg, position, Color.White);
            base.Draw(renderer);

            float p = (selectedCore.Logics as Logics.CoreLogics).CorrectPercent;
            if (Settings.GameState == Settings.GameStates.Stopped)
                p = 0;

            renderer.End();
            DrawCircle(renderer, p);
            renderer.BeginUnscaled();
            if (b)
            {
                renderer.SetScissorRectangle(position.X, position.Y, size.X, size.Y, false);
                renderer.End();
                renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, null,
                    null, MicroWorld.Graphics.GraphicsEngine.s_ScissorsOn, null, Matrix.CreateTranslation(OffsetX, 0, 0));
            }
            renderer.Draw(progressbar, new Vector2(position.X+22, position.Y+280), Color.White);
            DrawDigits(renderer, p);

            if (b)
                renderer.ResetScissorRectangle();
        }
示例#6
0
        //TODO optimize
        public void Render(RenderTarget2D fbo, RenderTarget2D bufferFBO, Renderer renderer, Texture2D distortionTexture = null)
        {
            if (fbo == null || bufferFBO == null || fbo.Width != W || fbo.Height != H || bufferFBO.Width != W || bufferFBO.Height != H)
                return;
            if (distortionTexture == null)
                distortionTexture = MicroWorld.Graphics.Effects.Effects.liquidDistortionTexture;

            bool b = renderer.IsDrawing;
            bool s = renderer.IsScaeld;
            var cfbo = renderer.CurFBO;
            if (b)
                renderer.End();
            if (cfbo == bufferFBO)
                renderer.DisableFBO();
            renderer.GraphicsDevice.Textures[0] = null;

            Color[] fboarr = new Color[W * H];

            fixed(TileMapElement* ptrmap = tileMap)
            fixed (Color* ptrfbo = fboarr)
            {
                for (int x = 0; x < W; x++)
                {
                    for (int y = 0; y < H; y++)
                    {
                        *(ptrfbo + x + y * W) = (*(ptrmap + y + x * H)).level <= 1 ? Color.Transparent : Color.White;
                    }
                }
            }
            bufferFBO.SetData<Color>(fboarr);

            renderer.EnableFBO(fbo);
            renderer.GraphicsDevice.Clear(Color.Transparent);
            _setUpShader(distortionTexture);
            renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone,
                MicroWorld.Graphics.Effects.Effects.liquid);
            renderer.Draw(bufferFBO, new Vector2(), new Color(0, 108, 255));
            renderer.End();

            if (cfbo == fbo)
                renderer.EnableFBO(bufferFBO);
            if (b)
                renderer.Begin(s);
        }
示例#7
0
        private void DrawCircle(MicroWorld.Graphics.Renderer renderer, float state)
        {
            Vector2   Position = new Vector2((Main.WindowWidth - 602) / 2, (Main.WindowHeight - 338) / 2);
            Texture2D circle   = Graphics.CoreGraphics.circle;
            Vector2   Center   = circleCenter + Position;

            state = state > 1 ? 1 : state < 0 ? 0 : state;
            float acur = astart + 2 * (float)Math.PI * state;
            List <VertexPositionColorTexture> vs = new List <VertexPositionColorTexture>();

            vs.Add(new VertexPositionColorTexture(
                       new Vector3(Center.X, Center.Y, 0),
                       circleColor,
                       new Vector2(0.5f, 0.5f)));
            vs.Add(GetVForAngle(astart));
            if (acur > Math.PI * 5 / 4)
            {
                vs.Add(new VertexPositionColorTexture(
                           new Vector3(Center.X - circle.Width / 2 / divider, Center.Y + circle.Height / 2 / divider, 0),
                           circleColor,
                           new Vector2(0f, 1f)));
                vs.Add(vs[vs.Count - 1]);
                vs.Add(vs[0]);
            }
            if (acur > Math.PI * 7 / 4)
            {
                vs.Add(new VertexPositionColorTexture(
                           new Vector3(Center.X + circle.Width / 2 / divider, Center.Y + circle.Height / 2 / divider, 0),
                           circleColor,
                           new Vector2(1f, 1f)));
                vs.Add(vs[vs.Count - 1]);
                vs.Add(vs[0]);
            }
            if (acur > Math.PI * 9 / 4)
            {
                vs.Add(new VertexPositionColorTexture(
                           new Vector3(Center.X + circle.Width / 2 / divider, Center.Y - circle.Height / 2 / divider, 0),
                           circleColor,
                           new Vector2(1f, 0f)));
                vs.Add(vs[vs.Count - 1]);
                vs.Add(vs[0]);
            }
            if (acur > Math.PI * 11 / 4)
            {
                vs.Add(new VertexPositionColorTexture(
                           new Vector3(Center.X - circle.Width / 2 / divider, Center.Y - circle.Height / 2 / divider, 0),
                           circleColor,
                           new Vector2(0f, 0f)));
                vs.Add(vs[vs.Count - 1]);
                vs.Add(vs[0]);
            }


            vs.Add(GetVForAngle(acur));


            var a = vs.ToArray();

            renderer.GraphicsDevice.Textures[0] = circle;
            renderer.GraphicsDevice.DrawUserPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, a, 0, a.Length / 3);
        }
示例#8
0
        public static void SmartDrawRectangleHollow(Texture2D texture, int border, int x, int y, int w, int h, Color c, Renderer r)
        {
            r.Draw(texture, new Rectangle(x, y, border, border), new Rectangle(0, 0, border, border), c);//0,0
            r.Draw(texture, new Rectangle(x + border, y, w - border * 2, border), new Rectangle(border, 0, texture.Width - border * 2, border), c);//1,0
            r.Draw(texture, new Rectangle(x + w - border, y, border, border), new Rectangle(texture.Width - border, 0, border, border), c);//2,0

            r.Draw(texture, new Rectangle(x, y + border, border, h - border * 2), new Rectangle(0, border, border, texture.Height - border * 2), c);//0,1
            r.Draw(texture, new Rectangle(x + w - border, y + border, border, h - border * 2), new Rectangle(texture.Width - border, border, border, texture.Height - border * 2), c);//2,1

            r.Draw(texture, new Rectangle(x, y + h - border, border, border), new Rectangle(0, texture.Height - border, border, border), c);//0,2
            r.Draw(texture, new Rectangle(x + border, y + h - border, w - border * 2, border), new Rectangle(border, texture.Height - border, texture.Width - border * 2, border), c);//1,2
            r.Draw(texture, new Rectangle(x + w - border, y + h - border, border, border), new Rectangle(texture.Width - border, texture.Height - border, border, border), c);//2,2
        }
示例#9
0
 public static void DrawDottedOutline(double x, double y, double w, double h, bool coordsScaled, Renderer r)
 {
     if (!coordsScaled)
     {
         Utilities.Tools.GameToScreenCoords(ref x, ref y, ref w, ref h);
     }
     x -= 2;
     y -= 2;
     w += 4;
     h += 4;
     int offset = -(int)(Main.Ticks % (dottedOutline.Width * 4)) / 4;//- for direction, 8 for smoothness
     bool b = r.IsScaeld;
     r.End();
     r.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None,
         RasterizerState.CullNone);
     //top
     r.Draw(dottedOutline, new Rectangle((int)x, (int)y, (int)w, (int)2),
         new Rectangle(offset, 0, (int)w, (int)2), outlineColor);
     //bottom
     r.Draw(dottedOutline, new Rectangle((int)x, (int)(y + h - 1), (int)w, (int)2),
         new Rectangle(offset, (int)(h - 2), (int)w, (int)2), outlineColor);
     //left
     r.Draw(dottedOutline, new Rectangle((int)x, (int)y, (int)2, (int)h - 2),
         new Rectangle(0, offset, (int)2, (int)h), outlineColor);
     //right
     r.Draw(dottedOutline, new Rectangle((int)(x + w - 2), (int)y, (int)2, (int)h - 1),
         new Rectangle((int)(w - 2), offset, (int)2, (int)h), outlineColor);
     r.End();
     r.Begin(b);
 }
示例#10
0
 public static void DrawDottedLinesToBorders(Point[] p, Color color, Renderer renderer,
     bool areGameCoords = false, bool animate = true)
 {
     if (p == null || p.Length == 0)
         throw new Exception("Array must not be empty");
     Vector2[] r = new Vector2[p.Length];
     for (int i = 0; i < p.Length; i++)
     {
         r[i] = new Vector2(p[i].X, p[i].Y);
     }
     DrawDottedLinesToBorders(r, color, renderer, areGameCoords, animate);
 }
示例#11
0
 public static void DrawDottedLinesToBorders(Vector2[] p, Color color, Renderer renderer,
     bool areGameCoords = false, bool animate = true)
 {
     if (p == null || p.Length == 0)
         throw new Exception("Array must not be empty");
     bool a = renderer.IsDrawing;
     bool b = renderer.IsScaeld;
     if (a) renderer.End();
     renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None,
         RasterizerState.CullNone);
     Rectangle r = new Rectangle();
     var vr = GraphicsEngine.camera.VisibleRectangle;
     int animation = -(int)(Main.Ticks % 32) / 4;
     float xw = vr.X + vr.Width;
     float yh = vr.Y + vr.Height;
     Utilities.Tools.GameToScreenCoords(ref xw, ref yh);
     for (int i = 0; i < p.Length; i++)
     {
         if (areGameCoords)//convert
         {
             Utilities.Tools.GameToScreenCoords(ref p[i].X, ref p[i].Y);
         }
         //stretch by x
         r.X = (int)p[i].X;
         r.Y = (int)p[i].Y;
         r.Width = (int)(xw - p[i].X);
         r.Height = 1;
         if (animate)
         {
             renderer.Draw(dottedOutline, r,
                 new Rectangle((int)(r.Height == 1 ? r.X + animation : r.X),
                              (int)(r.Width == 1 ? r.Y + animation : r.Y),
                              r.Width, r.Height),
                     color);
         }
         else
             renderer.Draw(dottedOutline, r, r, color);
         //stretch by y
         r.X = (int)p[i].X;
         r.Y = (int)p[i].Y;
         r.Width = 1;
         r.Height = (int)(yh - p[i].Y);
         if (animate)
         {
             renderer.Draw(dottedOutline, r,
                 new Rectangle((int)(r.Height == 1 ? r.X + animation : r.X),
                              (int)(r.Width == 1 ? r.Y + animation : r.Y),
                              r.Width, r.Height),
                     color);
         }
         else
             renderer.Draw(dottedOutline, r, r, color);
     }
     renderer.End();
     if (a) renderer.Begin(b);
 }
示例#12
0
        public override void Draw(Renderer renderer)
        {
            if (Opacity > 0)
            {
                float o = DimOpacity ? Opacity / 4f : Opacity;
                //bg
                renderer.Draw(GraphicsEngine.pixel, new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y), bgColor * o);
                //borger
                renderer.Draw(GraphicsEngine.pixel, new Rectangle((int)position.X, (int)position.Y, 1, (int)size.Y), Color.White * o);
                renderer.Draw(GraphicsEngine.pixel, new Rectangle((int)position.X, (int)position.Y, (int)size.X, 1), Color.White * o);
                renderer.Draw(GraphicsEngine.pixel, new Rectangle((int)(position.X + size.X - 1), (int)position.Y, 1, (int)size.Y), Color.White * o);
                renderer.Draw(GraphicsEngine.pixel, new Rectangle((int)position.X, (int)(position.Y + size.Y - 1), (int)size.X, 1), Color.White * o);

                renderer.End();
                GraphicsEngine.Renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None,
                    RasterizerState.CullNone);
                renderer.Draw(fbo, position, Color.White * o);
                renderer.End();
                renderer.BeginUnscaled();
            }
        }
示例#13
0
 public virtual void DrawFBO(Renderer renderer)
 {
     base.Draw(renderer);
 }