Пример #1
0
 public ImageData(Bitmap image)
 {
     Width = image.Width;
     Height = image.Height;
     data = new VColor[Width,Height];
     foreach (var point in GetPoints())
     {
         var c = new VColor(image.GetPixel(point.X, point.Y));
         this[point] = c;
     }
 }
Пример #2
0
 public PixelErrorData(IntVector2 point, ImageData source)
 {
     targetColor = source[point];
 }
Пример #3
0
 public Food(string name, string description, int value, VColor color, int size) : base(name, description, value, color)
 {
     Size = size;
 }
Пример #4
0
        public override void DrawSlice(Graphics g, double From, double To, bool AllInOne, bool Collapsed)
        {
            base.DrawSlice(g, From, To, AllInOne, Collapsed);


            TLColorKeyFrame kfc;
            float           left, width;
            Color           c1, c2;
            RectangleF      r;

            float sliceHeight = FPin.Height / FPin.SliceCount;

            width = g.ClipBounds.Width;

            g.FillRectangle(new HatchBrush(HatchStyle.LargeCheckerBoard, Color.White, Color.Gray), g.ClipBounds);

            //draw all keyframes that have a right neighbour
            for (int i = 0; i < FInvalidKeyFrames.Count - 1; i++)
            {
                kfc = FInvalidKeyFrames[i] as TLColorKeyFrame;

                left  = kfc.GetTimeAsX();
                c1    = kfc.RGBAColor.Color;
                c2    = (FInvalidKeyFrames[i + 1] as TLColorKeyFrame).RGBAColor.Color;
                width = FInvalidKeyFrames[i + 1].GetTimeAsX() - left;
                r     = new RectangleF(left, 0, width, sliceHeight);

                using (Brush b = new LinearGradientBrush(r, c1, c2, LinearGradientMode.Horizontal))
                {
                    g.FillRectangle(b, r);
                }
            }

            if (FInvalidKeyFrames.Count > 0)
            {
                //System.Console.Beep();
                //draw left of first keyframe
                if (FInvalidKeyFrames[0] == FKeyFrames[0])
                {
                    left  = 0;
                    width = FKeyFrames[0].GetTimeAsX();
                    c1    = (FKeyFrames[0] as TLColorKeyFrame).RGBAColor.Color;
                    r     = new RectangleF(left, 0, width, sliceHeight);

                    using (Brush b = new SolidBrush(c1))
                    {
                        g.FillRectangle(b, r);
                    }
                }

                //draw right of last keyframe
                if (FInvalidKeyFrames[FInvalidKeyFrames.Count - 1] == FKeyFrames[FKeyFrames.Count - 1])
                {
                    left  = FKeyFrames[FKeyFrames.Count - 1].GetTimeAsX();
                    width = g.ClipBounds.Width - left;

                    c1 = (FKeyFrames[FKeyFrames.Count - 1] as TLColorKeyFrame).RGBAColor.Color;
                    r  = new RectangleF(left, 0, width, sliceHeight);

                    using (Brush b = new SolidBrush(c1))
                    {
                        g.FillRectangle(b, r);
                    }
                }
            }

            //draw infos to visible
            if (Collapsed)
            {
                DrawCollapsedKeyFrames(g);
            }
            else
            {
                foreach (TLColorKeyFrame k in FInvalidKeyFrames)
                {
                    float x   = k.GetTimeAsX();
                    Color inv = VColor.Offset(k.RGBAColor, 0.5).Color;

                    if (k.Selected)
                    {
                        using (Pen p = new Pen(inv))
                            g.DrawRectangle(p, x - 20, 0, 40, sliceHeight);

                        //draw color values hsva
                        string s = "H: " + (k.Hue).ToString("f2", TimelinerPlugin.GNumberFormat);
                        using (Brush b = new SolidBrush(inv))
                        {
                            g.DrawString(s, FFont, b, x - 20, 0);
                            s = "S: " + k.Saturation.ToString("f2", TimelinerPlugin.GNumberFormat);
                            g.DrawString(s, FFont, b, x - 20, 10);
                            s = "V: " + k.Value.ToString("f2", TimelinerPlugin.GNumberFormat);
                            g.DrawString(s, FFont, b, x - 20, 20);
                            s = "A: " + (k.Alpha).ToString("f2", TimelinerPlugin.GNumberFormat);
                            g.DrawString(s, FFont, b, x - 20, 30);
                        }

                        using (Brush b = new SolidBrush(Color.White))
                            g.DrawString(k.Time.ToString("f2", TimelinerPlugin.GNumberFormat) + "s", FFont, b, x - 20, 45);
                    }
                    else
                    {
                        using (Pen p = new Pen(Color.Silver))
                            g.DrawRectangle(p, x - 20, 0, 40, sliceHeight);
                    }

                    SizeF sz = g.MeasureString(OutputAsString, FFont);
                    inv = inv = VColor.Offset(FOutput, 0.5).Color;

                    using (Brush b = new SolidBrush(FOutput.Color))
                        g.FillRectangle(b, new RectangleF(g.ClipBounds.Width - sz.Width, sliceHeight - sz.Height, sz.Width, sz.Height));
                    using (Pen p = new Pen(Color.Silver))
                        g.DrawLine(p, x, 0, x, 3);
                    using (Brush b = new SolidBrush(inv))
                        g.DrawString(OutputAsString, FFont, b, g.ClipBounds.Width - sz.Width - 2, sliceHeight - sz.Height);
                }
            }
        }
Пример #5
0
        public override void Evaluate(double CurrentTime)
        {
            base.Evaluate(CurrentTime);

            if (FKeyFrames.Count == 0)
            {
                FOutput = VColor.Black;
            }
            else
            {
                TLColorKeyFrame from = (TLColorKeyFrame)FKeyFrames.FindLast(delegate(TLBaseKeyFrame k) { return(k.Time <= CurrentTime); });
                TLColorKeyFrame to   = (TLColorKeyFrame)FKeyFrames.Find(delegate(TLBaseKeyFrame k) { return(k.Time > CurrentTime); });

                if (from == null)
                {
                    from = to;
                }
                if (to == null)
                {
                    to = from;
                }

                /*
                 *
                 * int a1, r1, g1, b1, a2, r2, g2, b2;
                 * a1 = from.Color.A;
                 * a2 = to.Color.A;
                 * r1 = from.Color.R;
                 * r2 = to.Color.R;
                 * g1 = from.Color.G;
                 * g2 = to.Color.G;
                 * b1 = from.Color.B;
                 * b2 = to.Color.B;
                 *
                 * double tSpan, f, tCurrent;
                 * tSpan = to.Time - from.Time;
                 * tCurrent = CurrentTime - from.Time;
                 *
                 * if (tSpan == 0)
                 *      f = 0;
                 * else
                 *      f = tCurrent / tSpan;
                 *
                 * ;
                 *
                 * int a, r, g, b;
                 *
                 * a = (int) Math.Round(a2 * f + a1 * (1-f));
                 * r = (int) Math.Round(r2 * f + r1 * (1-f));
                 * g = (int) Math.Round(g2 * f + g1 * (1-f));
                 * b = (int) Math.Round(b2 * f + b1 * (1-f));
                 */

                double tSpan, f, tCurrent;
                tSpan    = to.Time - from.Time;
                tCurrent = CurrentTime - from.Time;

                if (tSpan == 0)
                {
                    f = 0;
                }
                else
                {
                    f = tCurrent / tSpan;
                }
                FOutput = VColor.LerpRGBA(from.RGBAColor, to.RGBAColor, f);
            }

            double h, s, v, a;

            VColor.RGBtoHSV(FOutput.R, FOutput.G, FOutput.B, out h, out s, out v);
            a = FOutput.A;

            OutputAsString = "H: " + h.ToString("f2") + " S: " + s.ToString("f2") + " V: " + v.ToString("f2") + " A: " + a.ToString("f2");
        }
Пример #6
0
    public static VTile VoxToTile(byte[] vox)
    {
        VTile tile = new VTile();

        VPalette pal = tile.GetPalette();

        for (int j = 0; j < 256; j++)
        {
            byte[] bits = System.BitConverter.GetBytes(vox_default_palette[j]);
            VColor c    = new VColor(bits[0], bits[1], bits[2], bits[3]);
            if (j >= pal.GetCount())
            {
                pal.AddColor(c);
            }
            else
            {
                pal.SetColor(j, c);
            }
        }

        int    i     = 0;
        string chunk = "" + (char)vox[i + 0] + (char)vox[i + 1] + (char)vox[i + 2] + (char)vox[i + 3];

        i += 4;
        if (chunk != "VOX ")
        {
            throw new System.Exception("Invalid VOX file");
        }
        int version = System.BitConverter.ToInt32(vox, i);

        i += 4;
        if (version != 150)
        {
            throw new System.Exception("Unsupported VOX version (expected 150, got " + version + ")");
        }

        while (i < vox.Length)
        {
            chunk = "" + (char)vox[i + 0] + (char)vox[i + 1] + (char)vox[i + 2] + (char)vox[i + 3];
            i    += 4;
            int contentLength = System.BitConverter.ToInt32(vox, i);
            i += 4;
            //int childrenLength = System.BitConverter.ToInt32(vox, i);
            i += 4;
            if (chunk == "MAIN")
            {
            }
            else if (chunk == "PACK")
            {
                int numModels = System.BitConverter.ToInt32(vox, i);
                i += 4;
                if (numModels > 1)
                {
                    throw new System.Exception("Unsupported VOX feature (cannot read multi-model pack files)");
                }
            }
            else if (chunk == "SIZE")
            {
                int x = System.BitConverter.ToInt32(vox, i);
                i += 4;
                int y = System.BitConverter.ToInt32(vox, i);
                i += 4;
                int z = System.BitConverter.ToInt32(vox, i);
                i += 4;
                tile.Resize(x, z, y);
            }
            else if (chunk == "XYZI")
            {
                int count = System.BitConverter.ToInt32(vox, i);
                i += 4;
                for (int j = 0; j < count; j++)
                {
                    byte x = vox[i + 0];
                    byte y = vox[i + 1];
                    byte z = vox[i + 2];
                    byte c = vox[i + 3];
                    tile.GetChunk(0, 0, 0).SetPaletteIndexAt(x, z, tile.GetDepth() - y - 1, (byte)(255 - c + 1));
                    i += 4;
                }
            }
            else if (chunk == "RGBA")
            {
                for (int j = 0; j < 256; j++)
                {
                    VColor c = new VColor(vox[i + 0], vox[i + 1], vox[i + 2], vox[i + 3]);
                    i += 4;
                    // Palette color 0 is always transparent
                    if (j == 255)
                    {
                        c.a = 0;
                    }
                    if (j >= pal.GetCount())
                    {
                        pal.AddColor(c);
                    }
                    else
                    {
                        pal.SetColor(255 - j, c);
                    }
                }
            }
            else
            {
                i += contentLength;
            }
        }

        return(tile);
    }
Пример #7
0
 public static void SetVVVVBackgroundColor(this SvgDocument doc, RGBAColor col)
 {
     doc.CustomAttributes["VVVVBackgroundColor"] = VColor.Serialze(col);
 }
Пример #8
0
 private MessagePriority(string name, string description, int value, VColor color) : base(name, description, value, color)
 {
 }
Пример #9
0
 public ChangePaletteColorAct(VColor color, int index)
 {
     this.color = new VColor(color);
     this.index = index;
 }
Пример #10
0
 public StorageType(string nameText, VColor nameForeground)
 {
     NameText       = nameText;
     NameForeground = nameForeground;
 }
Пример #11
0
    public void Refresh()
    {
        // The preview chunk uses -1 for all indices, so don't try to grab an actual chunk
        if (layerIndex != -1)
        {
            cachedVChunk = tile.GetTile().GetChunk(layerIndex, animationIndex, frameIndex);
        }

        bool layerTrans = (layerIndex >= 0) ? tile.GetTile().GetLayer(layerIndex).GetTransparent() : false;
        bool layerLine  = (layerIndex >= 0) ? tile.GetTile().GetLayer(layerIndex).GetOutline() : false;

        if (!mesh)
        {
            mesh = new Mesh();
        }
        mesh.Clear();

        v = 0;

        for (int x = 0; x < tile.width; x++)
        {
            for (int y = 0; y < tile.height; y++)
            {
                for (int z = 0; z < tile.depth; z++)
                {
                    VColor c = GetColor(x, y, z);
                    if (GetColor(x, y, z).a == 0)
                    {
                        continue;
                    }
                    Vector3 p = new Vector3(x, y, z);

                    bool useSubMesh = c.a < 255 || layerTrans || layerLine;

                    if (x == 0 || (GetColor(x - 1, y, z).a < 255 && GetColor(x - 1, y, z) != c))
                    {
                        verts.Add(p + new Vector3(0f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(0f, 0f, 0f));

                        AddFace(x, y, z, Vector3.left, useSubMesh);
                    }
                    if (x == tile.width - 1 || (GetColor(x + 1, y, z).a < 255 && GetColor(x + 1, y, z) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 0f, 1f));

                        AddFace(x, y, z, Vector3.right, useSubMesh);
                    }
                    if (y == 0 || (GetColor(x, y - 1, z).a < 255 && GetColor(x, y - 1, z) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 0f));
                        verts.Add(p + new Vector3(1f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 0f));

                        AddFace(x, y, z, Vector3.down, useSubMesh);
                    }
                    if (y == tile.height - 1 || (GetColor(x, y + 1, z).a < 255 && GetColor(x, y + 1, z) != c))
                    {
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));

                        AddFace(x, y, z, Vector3.up, useSubMesh);
                    }
                    if (z == 0 || (GetColor(x, y, z - 1).a < 255 && GetColor(x, y, z - 1) != c))
                    {
                        verts.Add(p + new Vector3(0f, 0f, 0f));
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 0f, 0f));

                        AddFace(x, y, z, Vector3.back, useSubMesh);
                    }
                    if (z == tile.depth - 1 || (GetColor(x, y, z + 1).a < 255 && GetColor(x, y, z + 1) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 1f));

                        AddFace(x, y, z, Vector3.forward, useSubMesh);
                    }
                }
            }
        }

        mesh.subMeshCount = (subTris.Count > 0) ? 2 : 1;

        mesh.vertices = verts.ToArray();
        mesh.normals  = normals.ToArray();
        mesh.uv       = uvs.ToArray();

        mesh.SetTriangles(tris.ToArray(), 0);
        if (mesh.subMeshCount > 1)
        {
            mesh.SetTriangles(subTris.ToArray(), 1);
        }

        mesh.RecalculateBounds();

        verts.Clear();
        normals.Clear();
        uvs.Clear();
        tris.Clear();
        subTris.Clear();

        if (mf)
        {
            mf.sharedMesh = mesh;
        }
        if (mc)
        {
            mc.sharedMesh = null;
            mc.sharedMesh = mesh;
        }
        if (mr)
        {
            if (mesh.subMeshCount > 1)
            {
                mr.sharedMaterials = new[] { tile.mat0, tile.mat1 }
            }
            ;
            else
            {
                mr.sharedMaterials = new[] { tile.mat0 }
            };
            foreach (Material mat in mr.materials)
            {
                mat.SetTexture("_Pattern", (layerTrans) ? ((layerLine) ? transLineTex : transTex) : ((layerLine) ? lineTex : null));
            }
        }
    }

    void AddFace(int x, int y, int z, Vector3 normal, bool subMesh)
    {
        normals.Add(normal);
        normals.Add(normal);
        normals.Add(normal);
        normals.Add(normal);

        List <int> triList = (subMesh) ? subTris : tris;

        triList.Add(v + 0);
        triList.Add(v + 1);
        triList.Add(v + 2);

        triList.Add(v + 0);
        triList.Add(v + 2);
        triList.Add(v + 3);

        v += 4;

        int i = GetIndex(x, y, z);

        Vector2 uv = new Vector2(i + 0.5f, 0.5f) / 256f;

        uvs.Add(uv);
        uvs.Add(uv);
        uvs.Add(uv);
        uvs.Add(uv);
    }
}
Пример #12
0
 public void AddColor(VColor color)
 {
     colors.Add(color);
     SetDirty();
 }
Пример #13
0
 public void SetColor(int index, VColor color)
 {
     colors[index] = color;
     SetDirty();
 }
Пример #14
0
    public static Mesh TileToMesh(VTile tile)
    {
        Mesh mesh = new Mesh();

        v = 0;

        for (int x = 0; x < tile.GetWidth(); x++)
        {
            for (int y = 0; y < tile.GetHeight(); y++)
            {
                for (int z = 0; z < tile.GetDepth(); z++)
                {
                    VColor c = GetColor(tile, x, y, z);
                    if (GetColor(tile, x, y, z).a == 0)
                    {
                        continue;
                    }
                    Vector3 p = new Vector3(x, y, z);

                    bool useSubMesh = c.a < 255;

                    if (x == 0 || (GetColor(tile, x - 1, y, z).a < 255 && GetColor(tile, x - 1, y, z) != c))
                    {
                        verts.Add(p + new Vector3(0f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(0f, 0f, 0f));

                        AddFace(tile, x, y, z, Vector3.left, useSubMesh);
                    }
                    if (x == tile.GetWidth() - 1 || (GetColor(tile, x + 1, y, z).a < 255 && GetColor(tile, x + 1, y, z) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 0f, 1f));

                        AddFace(tile, x, y, z, Vector3.right, useSubMesh);
                    }
                    if (y == 0 || (GetColor(tile, x, y - 1, z).a < 255 && GetColor(tile, x, y - 1, z) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 0f));
                        verts.Add(p + new Vector3(1f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 0f));

                        AddFace(tile, x, y, z, Vector3.down, useSubMesh);
                    }
                    if (y == tile.GetHeight() - 1 || (GetColor(tile, x, y + 1, z).a < 255 && GetColor(tile, x, y + 1, z) != c))
                    {
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));

                        AddFace(tile, x, y, z, Vector3.up, useSubMesh);
                    }
                    if (z == 0 || (GetColor(tile, x, y, z - 1).a < 255 && GetColor(tile, x, y, z - 1) != c))
                    {
                        verts.Add(p + new Vector3(0f, 0f, 0f));
                        verts.Add(p + new Vector3(0f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 1f, 0f));
                        verts.Add(p + new Vector3(1f, 0f, 0f));

                        AddFace(tile, x, y, z, Vector3.back, useSubMesh);
                    }
                    if (z == tile.GetDepth() - 1 || (GetColor(tile, x, y, z + 1).a < 255 && GetColor(tile, x, y, z + 1) != c))
                    {
                        verts.Add(p + new Vector3(1f, 0f, 1f));
                        verts.Add(p + new Vector3(1f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 1f, 1f));
                        verts.Add(p + new Vector3(0f, 0f, 1f));

                        AddFace(tile, x, y, z, Vector3.forward, useSubMesh);
                    }
                }
            }
        }

        mesh.vertices  = verts.ToArray();
        mesh.normals   = normals.ToArray();
        mesh.uv        = uvs.ToArray();
        mesh.triangles = tris.ToArray();

        mesh.RecalculateBounds();

        verts.Clear();
        normals.Clear();
        uvs.Clear();
        tris.Clear();

        return(mesh);
    }
Пример #15
0
 public ColouredPoint(int x, int y, VColor color)
     : base(x, y)
 {
     Color = color;
 }
Пример #16
0
 public override void Do()
 {
     oldColor = new VColor(Edit.use.tile.GetPalette().GetColor(index));
     Edit.use.tile.GetPalette().SetColor(index, new VColor(color));
 }
Пример #17
0
 public ColouredPoint(IntVector2 point, VColor color)
     : base(point)
 {
     Color = color;
 }
Пример #18
0
 public Food(string nameText, VColor nameForeground, int size = 1) : base(nameText, nameForeground, size)
 {
 }