Beispiel #1
0
 void EditTriangle(InterfaceImage mdl)
 {
     ImGui.Text("Texture Coordinates");
     EditPoints("##texcoords", mdl.TexCoords, (x, y, w, h) =>
     {
         ImGui.Image((IntPtr)foundTextureId, new Vector2(w, h), new Vector2(0, 1), new Vector2(1, 0));
     }, new Point(foundTexture.Width, foundTexture.Height));
     ImGui.Text("Vertices");
     EditPoints("##vertices", mdl.DisplayCoords, (x, y, w, h) =>
     {
         var drawList = ImGui.GetWindowDrawList();
         var mf       = new Vector2(x, y);
         var dim      = new Vector2(w, h);
         var dc       = mdl.DisplayCoords;
         var tc       = mdl.TexCoords;
         var pA       = mf + new Vector2(dc.X0, dc.Y0) * dim;
         var pB       = mf + new Vector2(dc.X1, dc.Y1) * dim;
         var pC       = mf + new Vector2(dc.X2, dc.Y2) * dim;
         var tA       = new Vector2(tc.X0, 1 - tc.Y0);
         var tB       = new Vector2(tc.X1, 1 - tc.Y1);
         var tC       = new Vector2(tc.X2, 1 - tc.Y2);
         drawList.AddImageQuad((IntPtr)foundTextureId, pA, pB, pC, pC, tA, tB, tC, tC, UInt32.MaxValue);
     });
 }
Beispiel #2
0
 // This returns an image
 public Image GetImage(InterfaceImage interfaceimage)
 {
     return(General.Colors.InDarkMode ? darkimages[interfaceimage] : normalimages[interfaceimage]);
 }
Beispiel #3
0
        private CImage Compile(string path, InterfaceImage res)
        {
            var cimage = new CImage();

            cimage.Texture = Texture.FindLoad(
                RootDirectory,
                ResolveLink(path, res.Texture),
                (Image <Rgba32> img) =>
            {
                int tw = img.Width;
                int th = img.Height;

                var pixels = new TextureCompiler.CColor[tw * th];
                if (res.VerticalFrames)
                {
                    th /= res.FrameCount;

                    for (int f = 0; f < res.FrameCount; f++)
                    {
                        for (int y = 0; y < th; y++)
                        {
                            for (int x = 0; x < tw; x++)
                            {
                                var p = img[x, f * th + th - 1 - y];
                                pixels[f * tw * th + y * tw + x] = new TextureCompiler.CColor(p);
                            }
                        }
                    }
                }
                else
                {
                    tw /= res.FrameCount;

                    for (int f = 0; f < res.FrameCount; f++)
                    {
                        for (int y = 0; y < th; y++)
                        {
                            for (int x = 0; x < tw; x++)
                            {
                                var p = img[f * tw + x, th - 1 - y];
                                pixels[f * tw * th + y * tw + x] = new TextureCompiler.CColor(p);
                            }
                        }
                    }
                }

                return(pixels);
            },
                (Image <Rgba32> img) =>
            {
                int w = img.Width;
                int h = img.Height;
                if (res.VerticalFrames)
                {
                    h /= res.FrameCount;
                }
                else
                {
                    w /= res.FrameCount;
                }
                return(new TextureCompiler.CColor[] { new TextureCompiler.CColor((uint)w), new TextureCompiler.CColor((uint)h) });
            }
                );

            cimage.Color   = new TextureCompiler.CColor(res.Color);
            cimage.Stretch = CImage.StretchType.Solid;
            if (cimage.Texture >= 0)
            {
                switch (res.Stretch)
                {
                case InterfaceTextureStretchType.Repeat: cimage.Stretch = CImage.StretchType.Repeat; break;

                case InterfaceTextureStretchType.Scale: cimage.Stretch = CImage.StretchType.Scale; break;
                }
            }
            return(cimage);
        }
        void DoImagePreview(InterfaceImage mdl)
        {
            if (foundTexture == null)
            {
                ImGui.TextColored(Color4.Red, "Texture not found");
                return;
            }

            if (mdl.Type == InterfaceImageKind.Triangle)
            {
                EditTriangle(mdl);
            }
            else
            {
                if (ImGui.Button("0°"))
                {
                    mdl.Rotation = QuadRotation.None;
                }
                ImGui.SameLine();
                if (ImGui.Button("90°"))
                {
                    mdl.Rotation = QuadRotation.Rotate90;
                }
                ImGui.SameLine();
                if (ImGui.Button("180°"))
                {
                    mdl.Rotation = QuadRotation.Rotate180;
                }
                ImGui.SameLine();
                if (ImGui.Button("270°"))
                {
                    mdl.Rotation = QuadRotation.Rotate270;
                }
                ImGui.Text($"Rotation: {(int)mdl.Rotation * 90}°");
                var szX = (int)ImGui.GetColumnWidth() - 5;
                szX = Math.Min(szX, 150);
                var ratio = foundTexture.Height / (float)foundTexture.Width;
                var szY   = (int)(szX * ratio);
                //source
                ImGui.Text("Source:");
                ImGui.SliderFloat("X", ref mdl.TexCoords.X0, 0, 1);
                ImGui.SliderFloat("Y", ref mdl.TexCoords.Y0, 0, 1);
                ImGui.SliderFloat("Width", ref mdl.TexCoords.X3, 0, 1);
                ImGui.SliderFloat("Height", ref mdl.TexCoords.Y3, 0, 1);
                //res
                var x0 = mdl.TexCoords.X0;
                var x1 = mdl.TexCoords.X0 + mdl.TexCoords.X3;
                var y0 = mdl.TexCoords.Y0;
                var y1 = mdl.TexCoords.Y0 + mdl.TexCoords.Y3;
                var a  = new Vector2(x0, y0);
                var b  = new Vector2(x1, y0);
                var c  = new Vector2(x0, y1);
                var d  = new Vector2(x1, y1);
                if (mdl.Flip)
                {
                    a.Y = b.Y = y1;
                    c.Y = d.Y = y0;
                }
                Vector2 tl = a, tr = b, bl = c, br = d;
                if (mdl.Rotation == QuadRotation.Rotate90)
                {
                    tl = c;
                    tr = a;
                    bl = d;
                    br = b;
                }
                else if (mdl.Rotation == QuadRotation.Rotate180)
                {
                    tl = d;
                    tr = c;
                    bl = b;
                    br = a;
                }
                else if (mdl.Rotation == QuadRotation.Rotate270)
                {
                    tl = b;
                    tr = d;
                    bl = a;
                    br = c;
                }

                //pos
                var cPos   = (Vector2)ImGui.GetCursorPos();
                var wPos   = (Vector2)ImGui.GetWindowPos();
                var scrPos = -ImGui.GetScrollY();
                var xy     = cPos + wPos + new Vector2(0, scrPos);
                var sz     = new Vector2(szX, szY);

                ImGui.GetWindowDrawList().AddImageQuad(
                    (IntPtr)foundTextureId,
                    xy,
                    new Vector2(xy.X + sz.X, xy.Y),
                    xy + sz,
                    new Vector2(xy.X, xy.Y + sz.Y),
                    tl, tr, br, bl,
                    UInt32.MaxValue
                    );
                ImGui.Dummy(new Vector2(szX, szY));
            }
        }
 // This returns an image
 public Image GetImage(InterfaceImage interfaceimage)
 {
     return General.Colors.InDarkMode ? darkimages[interfaceimage] : normalimages[interfaceimage];
 }