예제 #1
0
        private static Bitmap Regenerate2DImageForLayer(Layer2D l, int width, int height)
        {
            Bitmap   b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            Dictionary <int, LayerColor> colors = l.GetLayerColors();

            int[] data = l.GenerateData(LayerFlowImageGeneration.X, LayerFlowImageGeneration.Y, width, height);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    while (true)
                    {
                        try
                        {
                            if (colors != null && colors.ContainsKey(data[x + y * width]))
                            {
                                LayerColor lc = colors[data[x + y * (width)]];
                                SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                                g.FillRectangle(
                                    sb,
                                    new Rectangle(x, y, 1, 1)
                                    );
                            }
                            else
                            {
                                g.FillRectangle(
                                    m_UnknownAssociation,
                                    new Rectangle(x, y, 1, 1)
                                    );
                            }
                            break;
                        }
                        catch (InvalidOperationException)
                        {
                            // Graphics can be in use elsewhere, but we don't care; just try again.
                        }
                    }
                }
            }
            return(b);
        }
예제 #2
0
        private static Bitmap Regenerate3DImageForLayer(Layer3D l, int width, int height)
        {
            Bitmap   b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.White);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            Dictionary <int, LayerColor> colors = l.GetLayerColors();

            int[] data = l.GenerateData(LayerFlowImageGeneration.X, LayerFlowImageGeneration.Y, LayerFlowImageGeneration.Z, RenderWidth, RenderHeight, RenderDepth);

            /* Our world is laid out in memory in terms of X / Y, but
             * we are rendering isometric, which means that the rendering
             * order for tiles must be like so:
             *
             *               North
             *        1  3  5  9  13 19 25
             *        2  6  10 14 20 26 32
             *        4  8  15 21 27 33 37
             *  East  7  12 18 28 34 38 42  West
             *        11 17 24 31 39 43 45
             *        16 23 30 36 41 46 48
             *        22 29 35 40 44 47 49
             *               South
             *
             * We also need to account for situations where the user rotates
             * the isometric view.
             */

            /*
             *                      North
             *         0    0.5  1     1.5  2    2.5  3
             *        -0.5  0    0.5   1    1.5  2    2.5
             *        -1   -0.5  0     0.5  1    1.5  2
             *  East  -1.5 -1   -0.5   0    0.5  1    1.5  West
             *        -2   -1.5 -1    -0.5  0    0.5  1
             *        -2.5 -2   -1.5  -1   -0.5  0    0.5
             *        -3   -2.5 -2    -1.5 -1   -0.5  0
             *                      South
             *
             *  v = (x - y) / 2.0
             */

            int[] render  = GetCellRenderOrder(RenderToNE);
            int   ztop    = RenderDepth;
            int   zbottom = 0;

            for (int z = zbottom; z < ztop; z++)
            {
                int rcx = width / 2 - 1;
                int rcy = height / 2 - 31;
                int rw  = 2;
                int rh  = 1;
                for (int i = 0; i < render.Length; i++)
                {
                    // Calculate the X / Y of the tile in the grid.
                    int x = render[i] % RenderWidth;
                    int y = render[i] / RenderWidth;

                    // Calculate the render position on screen.
                    int rx = rcx + (int)((x - y) / 2.0 * rw);// (int)(x / ((RenderWidth + 1) / 2.0) * rw);
                    int ry = rcy + (x + y) * rh - (rh / 2 * (RenderWidth + RenderHeight)) - (z - zbottom) * 1;

                    while (true)
                    {
                        try
                        {
                            if (l.IsLayerColorsFlags())
                            {
                                Color accum = Color.FromArgb(0, 0, 0, 0);
                                foreach (KeyValuePair <int, LayerColor> kv in colors)
                                {
                                    LayerColor lc = kv.Value;
                                    SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                                    if ((data[x + y * RenderWidth + z * RenderWidth * RenderHeight] & kv.Key) != 0)
                                    {
                                        accum = Color.FromArgb(
                                            Math.Min(255, accum.A + sb.Color.A),
                                            Math.Min((byte)255, (byte)(accum.R + sb.Color.R * (sb.Color.A / 255.0) / colors.Count)),
                                            Math.Min((byte)255, (byte)(accum.G + sb.Color.G * (sb.Color.A / 255.0) / colors.Count)),
                                            Math.Min((byte)255, (byte)(accum.B + sb.Color.B * (sb.Color.A / 255.0) / colors.Count))
                                            );
                                    }
                                }
                                if (accum.R == 255 && accum.G == 255 && accum.B == 255)
                                {
                                    accum = Color.FromArgb(63, 0, 0, 0);
                                }
                                g.FillRectangle(
                                    new SolidBrush(accum),
                                    new Rectangle(rx, ry, rw, rh)
                                    );
                                break;
                            }
                            else
                            {
                                if (colors != null && colors.ContainsKey(data[x + y * RenderWidth + z * RenderWidth * RenderHeight]))
                                {
                                    LayerColor lc = colors[data[x + y * RenderWidth + z * RenderWidth * RenderHeight]];
                                    SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                                    //sb.Color = Color.FromArgb(255, sb.Color);
                                    g.FillRectangle(
                                        sb,
                                        new Rectangle(rx, ry, rw, rh)
                                        );
                                }
                                break;
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            // Graphics can be in use elsewhere, but we don't care; just try again.
                        }
                    }
                }
            }

            return(b);
        }
예제 #3
0
        private static Bitmap RenderPartial3D(Layer l, int sx, int sy, int sz, int width, int height, int depth)
        {
            Bitmap   b = new Bitmap(width * 2, height * 3);
            Graphics g = Graphics.FromImage(b);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            Dictionary <int, LayerColor> brushes = l.GetLayerColors();

            int[] data = null;
            try
            {
                data = l.GenerateData(LayerFlowImageGeneration.X + sx, LayerFlowImageGeneration.Y + sy, LayerFlowImageGeneration.Z + sz, width, height, depth);

                int[] render  = GetCellRenderOrder(RenderToNE, width, height, depth);
                int   ztop    = depth;
                int   zbottom = 0;
                for (int z = zbottom; z < ztop; z++)
                {
                    int rcx = width / 2 - 1 + 16;
                    int rcy = height / 2 - 15 + 32;
                    int rw  = 2;
                    int rh  = 1;
                    for (int i = 0; i < render.Length; i++)
                    {
                        // Calculate the X / Y of the tile in the grid.
                        int x = render[i] % width;
                        int y = render[i] / width;

                        // Calculate the render position on screen.
                        int rx = rcx + (int)((x - y) / 2.0 * rw);// (int)(x / ((RenderWidth + 1) / 2.0) * rw);
                        int ry = rcy + (x + y) * rh - (rh / 2 * (width + height)) - (z - zbottom) * 1;

                        while (true)
                        {
                            try
                            {
                                if (l.IsLayerColorsFlags())
                                {
                                    Color accum = Color.FromArgb(0, 0, 0, 0);
                                    foreach (KeyValuePair <int, LayerColor> kv in brushes)
                                    {
                                        SolidBrush sb = new SolidBrush(Color.FromArgb(
                                                                           kv.Value.A,
                                                                           kv.Value.R,
                                                                           kv.Value.G,
                                                                           kv.Value.B));
                                        if ((data[x + y * width + z * width * height] & kv.Key) != 0)
                                        {
                                            accum = Color.FromArgb(
                                                Math.Min(255, accum.A + sb.Color.A),
                                                Math.Min((byte)255, (byte)(accum.R + sb.Color.R * (sb.Color.A / 255.0) / brushes.Count)),
                                                Math.Min((byte)255, (byte)(accum.G + sb.Color.G * (sb.Color.A / 255.0) / brushes.Count)),
                                                Math.Min((byte)255, (byte)(accum.B + sb.Color.B * (sb.Color.A / 255.0) / brushes.Count))
                                                );
                                        }
                                    }
                                    if (accum.R == 255 && accum.G == 255 && accum.B == 255)
                                    {
                                        accum = Color.FromArgb(63, 0, 0, 0);
                                    }
                                    g.FillRectangle(
                                        new SolidBrush(accum),
                                        new Rectangle(rx, ry, rw, rh)
                                        );
                                    break;
                                }
                                else
                                {
                                    if (brushes != null && brushes.ContainsKey(data[x + y * width + z * width * height]))
                                    {
                                        LayerColor lc = brushes[data[x + y * width + z * width * height]];
                                        SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B));
                                        //sb.Color = Color.FromArgb(255, sb.Color);
                                        g.FillRectangle(
                                            sb,
                                            new Rectangle(rx, ry, rw, rh)
                                            );
                                    }
                                    break;
                                }
                            }
                            catch (InvalidOperationException)
                            {
                                // Graphics can be in use elsewhere, but we don't care; just try again.
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(b);
        }