public void Run()
 {
     foreach (var p in popups)
     {
         if (p.DoOpen)
         {
             p.Data.DoFocus = p.Data.First = true;
             ImGui.OpenPopup(p.Title);
             p.DoOpen = false;
         }
         bool open = true;
         bool beginval;
         if (!p.Data.NoClose)
         {
             beginval = ImGui.BeginPopupModal(p.Title, ref open, p.Flags);
         }
         else
         {
             beginval = ImGuiExt.BeginModalNoClose(p.Title, p.Flags);
         }
         if (beginval)
         {
             p.DrawAction(p.Data);
             if (p.Data.First)
             {
                 p.Data.First = false;
             }
             else
             {
                 p.Data.DoFocus = false;
             }
             ImGui.EndPopup();
         }
     }
 }
示例#2
0
        public unsafe ImGuiHelper(Game game)
        {
            this.game                = game;
            game.Keyboard.KeyDown   += Keyboard_KeyDown;
            game.Keyboard.KeyUp     += Keyboard_KeyUp;
            game.Keyboard.TextInput += Keyboard_TextInput;
            context = ImGui.CreateContext();
            ImGui.SetCurrentContext(context);
            SetKeyMappings();

            var io = ImGui.GetIO();

            //IniFilename?
            io.WantSaveIniSettings = false;
            Default = io.Fonts.AddFontDefault();
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.Roboto-Medium.ttf"))
            {
                var ttf = new byte[stream.Length];
                stream.Read(ttf, 0, ttf.Length);
                ttfPtr = Marshal.AllocHGlobal(ttf.Length);
                Marshal.Copy(ttf, 0, ttfPtr, ttf.Length);
                Noto = io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, 15);
            }
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.checkerboard.png"))
            {
                checkerboard   = LibreLancer.ImageLib.Generic.FromStream(stream);
                CheckerboardId = RegisterTexture(checkerboard);
            }
            ImGuiExt.BuildFontAtlas((IntPtr)io.Fonts.NativePtr);
            byte *fontBytes;
            int   fontWidth, fontHeight;

            io.Fonts.GetTexDataAsAlpha8(out fontBytes, out fontWidth, out fontHeight);
            io.Fonts.TexUvWhitePixel = new Vector2(10, 10);
            fontTexture = new Texture2D(fontWidth, fontHeight, false, SurfaceFormat.R8);
            var bytes = new byte[fontWidth * fontHeight];

            Marshal.Copy((IntPtr)fontBytes, bytes, 0, fontWidth * fontHeight);
            fontTexture.SetData(bytes);
            fontTexture.SetFiltering(TextureFiltering.Linear);
            io.Fonts.SetTexID((IntPtr)FONT_TEXTURE_ID);
            io.Fonts.ClearTexData();
            textShader  = new Shader(vertex_source, text_fragment_source);
            colorShader = new Shader(vertex_source, color_fragment_source);
            dot         = new Texture2D(1, 1, false, SurfaceFormat.Color);
            var c = new Color4b[] { Color4b.White };

            dot.SetData(c);
            Theme.Apply();
            //Required for clipboard function on non-Windows platforms
            utf8buf    = Marshal.AllocHGlobal(8192);
            instance   = this;
            setTextDel = SetClipboardText;
            getTextDel = GetClipboardText;

            io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(getTextDel);
            io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(setTextDel);
        }
示例#3
0
        public static bool VerticalTab(string text, bool v)
        {
            var font  = ImGuiNative.igGetFont();
            var dlist = ImGuiNative.igGetWindowDrawList();

            var style      = ImGui.GetStyle();
            var text_color = ImGui.GetColorU32(ImGuiCol.Text);
            var color      = style.Colors[(int)ImGuiCol.Button];

            if (v)
            {
                color = style.Colors[(int)ImGuiCol.ButtonActive];
            }

            var   textSize = ImGui.CalcTextSize(text);
            float pad      = style.FramePadding.X;
            var   pos      = (Vector2)ImGui.GetCursorScreenPos() + new Vector2(pad, textSize.X + pad);

            ImGui.PushStyleColor(ImGuiCol.Button, color);
            ImGui.PushID(text);
            bool ret = ImGui.Button("", new Vector2(textSize.Y + pad * 2,
                                                    textSize.X + pad * 2));

            ImGui.PopStyleColor();
            foreach (var c in text.Reverse())
            {
                var glyph = ImGuiExt.igFontFindGlyph(font, c);
                ImGuiNative.ImDrawList_PrimReserve(
                    dlist, 6, 4
                    );
                ImGuiNative.ImDrawList_PrimQuadUV(
                    dlist,
                    pos + new Vector2(font->FontSize - glyph->Y0, -glyph->X0),
                    pos + new Vector2(font->FontSize - glyph->Y0, -glyph->X1),
                    pos + new Vector2(font->FontSize - glyph->Y1, -glyph->X1),
                    pos + new Vector2(font->FontSize - glyph->Y1, -glyph->X0),
                    new Vector2(glyph->U1, glyph->V0),
                    new Vector2(glyph->U0, glyph->V0),
                    new Vector2(glyph->U0, glyph->V1),
                    new Vector2(glyph->U1, glyph->V1),
                    text_color
                    );
                pos.Y -= glyph->AdvanceX;
            }
            ImGui.PopID();
            return(ret);
        }
示例#4
0
        public unsafe ImGuiHelper(Game game)
        {
            this.game                = game;
            game.Keyboard.KeyDown   += Keyboard_KeyDown;
            game.Keyboard.KeyUp     += Keyboard_KeyUp;
            game.Keyboard.TextInput += Keyboard_TextInput;
            context = ImGui.CreateContext();
            ImGui.SetCurrentContext(context);
            SetKeyMappings();
            var io = ImGui.GetIO();

            io.WantSaveIniSettings    = false;
            io.NativePtr->IniFilename = (byte *)0; //disable ini!!
            var fontConfigA = new ImFontConfigPtr(ImFontConfig_ImFontConfig());
            var fontConfigB = new ImFontConfigPtr(ImFontConfig_ImFontConfig());
            var fontConfigC = new ImFontConfigPtr(ImFontConfig_ImFontConfig());

            ushort[] glyphRangesFull = new ushort[]
            {
                0x0020, 0x00FF, //Basic Latin + Latin Supplement,
                0x0400, 0x052F, //Cyrillic + Cyrillic Supplement
                0x2DE0, 0x2DFF, //Cyrillic Extended-A
                0xA640, 0xA69F, //Cyrillic Extended-B
                ImGuiExt.ReplacementHash, ImGuiExt.ReplacementHash,
                0
            };
            var rangesPtrFull = Marshal.AllocHGlobal(sizeof(short) * glyphRangesFull.Length);

            for (int i = 0; i < glyphRangesFull.Length; i++)
            {
                ((ushort *)rangesPtrFull)[i] = glyphRangesFull[i];
            }
            ushort[] glyphRangesLatin = new ushort[]
            {
                0x0020, 0x00FF, //Basic Latin + Latin Supplement
                ImGuiExt.ReplacementHash, ImGuiExt.ReplacementHash,
                0
            };
            var rangesPtrLatin = Marshal.AllocHGlobal(sizeof(short) * glyphRangesLatin.Length);

            for (int i = 0; i < glyphRangesLatin.Length; i++)
            {
                ((ushort *)rangesPtrLatin)[i] = glyphRangesLatin[i];
            }
            fontConfigA.GlyphRanges = rangesPtrLatin;
            fontConfigB.GlyphRanges = rangesPtrFull;
            fontConfigC.GlyphRanges = rangesPtrFull;
            Default = io.Fonts.AddFontDefault(fontConfigA);
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.Roboto-Medium.ttf"))
            {
                var ttf = new byte[stream.Length];
                stream.Read(ttf, 0, ttf.Length);
                ttfPtr = Marshal.AllocHGlobal(ttf.Length);
                Marshal.Copy(ttf, 0, ttfPtr, ttf.Length);
                Noto = io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, 15, fontConfigB);
            }
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.checkerboard.png"))
            {
                checkerboard   = LibreLancer.ImageLib.Generic.FromStream(stream);
                CheckerboardId = RegisterTexture(checkerboard);
            }
            var monospace = Platform.GetMonospaceBytes();

            fixed(byte *mmPtr = monospace)
            {
                SystemMonospace = io.Fonts.AddFontFromMemoryTTF((IntPtr)mmPtr, monospace.Length, 16, fontConfigC);
            }

            ImGuiExt.BuildFontAtlas((IntPtr)io.Fonts.NativePtr);
            byte *fontBytes;
            int   fontWidth, fontHeight;

            io.Fonts.GetTexDataAsAlpha8(out fontBytes, out fontWidth, out fontHeight);
            io.Fonts.TexUvWhitePixel = new Vector2(10, 10);
            fontTexture = new Texture2D(fontWidth, fontHeight, false, SurfaceFormat.R8);
            var bytes = new byte[fontWidth * fontHeight];

            Marshal.Copy((IntPtr)fontBytes, bytes, 0, fontWidth * fontHeight);
            fontTexture.SetData(bytes);
            fontTexture.SetFiltering(TextureFiltering.Linear);
            io.Fonts.SetTexID((IntPtr)FONT_TEXTURE_ID);
            io.Fonts.ClearTexData();
            textShader  = new Shader(vertex_source, text_fragment_source);
            colorShader = new Shader(vertex_source, color_fragment_source);
            dot         = new Texture2D(1, 1, false, SurfaceFormat.Color);
            var c = new Color4b[] { Color4b.White };

            dot.SetData(c);
            Theme.Apply();
            //Required for clipboard function on non-Windows platforms
            utf8buf    = Marshal.AllocHGlobal(8192);
            instance   = this;
            setTextDel = SetClipboardText;
            getTextDel = GetClipboardText;

            io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(getTextDel);
            io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(setTextDel);
        }
 void UpdateRenderTitle()
 {
     RenderTitle = ImGuiExt.IDWithExtra(_title, Unique.ToString());
 }
示例#6
0
 public void Menu()
 {
     if (data.Files.Count <= 0)
     {
         Theme.IconMenuItem(Icons.Open, "Open Recent", false);
     }
     else
     {
         if (Theme.BeginIconMenu(Icons.Open, "Open Recent"))
         {
             int    i        = 0;
             string toOpen   = null;
             string toDelete = null;
             foreach (var item in ((IEnumerable <string>)data.Files).Reverse())
             {
                 var fn      = Path.GetFileName(item);
                 var dir     = Path.GetDirectoryName(item);
                 var builder = new StringBuilder(32);
                 //Build shortened directory name
                 while (builder.Length < 32)
                 {
                     var n2 = Path.GetDirectoryName(dir);
                     if (n2 == null)
                     {
                         break;
                     }
                     if (n2 == "/" || n2.EndsWith(":"))
                     {
                         string s = dir;
                         if (!Path.EndsInDirectorySeparator(dir))
                         {
                             s += Path.DirectorySeparatorChar;
                         }
                         builder.Insert(0, s);
                         break;
                     }
                     builder.Insert(0, $"{dir.Substring(n2.Length + 1)}{Path.DirectorySeparatorChar}");
                     dir = n2;
                 }
                 dir = builder.ToString();
                 //Do things
                 if (ImGui.MenuItem(ImGuiExt.IDWithExtra($"{fn} ({dir})", i++)))
                 {
                     if (!File.Exists(item))
                     {
                         openError = true;
                         errorText = $"File {item} was not found";
                         toDelete  = item;
                     }
                     else
                     {
                         toOpen = item;
                     }
                 }
             }
             if (toOpen != null)
             {
                 open(toOpen);
             }
             if (toDelete != null)
             {
                 data.Files.Remove(toDelete);
                 Save();
             }
             ImGui.EndMenu();
         }
     }
 }
示例#7
0
        public unsafe ImGuiHelper(Game game, float scale)
        {
            Scale                    = scale;
            this.game                = game;
            game.Keyboard.KeyDown   += Keyboard_KeyDown;
            game.Keyboard.KeyUp     += Keyboard_KeyUp;
            game.Keyboard.TextInput += Keyboard_TextInput;
            context                  = ImGui.CreateContext();
            ImGui.SetCurrentContext(context);
            SetKeyMappings();
            var io = ImGui.GetIO();

            io.WantSaveIniSettings    = false;
            io.NativePtr->IniFilename = (byte *)0; //disable ini!!
            var fontConfigA = new ImFontConfigPtr(ImFontConfig_ImFontConfig());
            var fontConfigB = new ImFontConfigPtr(ImFontConfig_ImFontConfig());
            var fontConfigC = new ImFontConfigPtr(ImFontConfig_ImFontConfig());

            ushort[] glyphRangesFull = new ushort[]
            {
                0x0020, 0x00FF, //Basic Latin + Latin Supplement,
                0x0400, 0x052F, //Cyrillic + Cyrillic Supplement
                0x2DE0, 0x2DFF, //Cyrillic Extended-A
                0xA640, 0xA69F, //Cyrillic Extended-B
                ImGuiExt.ReplacementHash, ImGuiExt.ReplacementHash,
                0
            };
            var rangesPtrFull = Marshal.AllocHGlobal(sizeof(short) * glyphRangesFull.Length);

            for (int i = 0; i < glyphRangesFull.Length; i++)
            {
                ((ushort *)rangesPtrFull)[i] = glyphRangesFull[i];
            }
            ushort[] glyphRangesLatin = new ushort[]
            {
                0x0020, 0x00FF, //Basic Latin + Latin Supplement
                ImGuiExt.ReplacementHash, ImGuiExt.ReplacementHash,
                0
            };
            var rangesPtrLatin = Marshal.AllocHGlobal(sizeof(short) * glyphRangesLatin.Length);

            for (int i = 0; i < glyphRangesLatin.Length; i++)
            {
                ((ushort *)rangesPtrLatin)[i] = glyphRangesLatin[i];
            }
            fontConfigA.GlyphRanges = rangesPtrLatin;
            fontConfigB.GlyphRanges = rangesPtrFull;
            fontConfigC.GlyphRanges = rangesPtrFull;

            Default = io.Fonts.AddFontDefault(fontConfigA);
            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.Roboto-Medium.ttf"))
            {
                var ttf = new byte[stream.Length];
                stream.Read(ttf, 0, ttf.Length);
                ttfPtr = Marshal.AllocHGlobal(ttf.Length);
                Marshal.Copy(ttf, 0, ttfPtr, ttf.Length);
                Noto = io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, (int)(15 * Scale), fontConfigB);
            }

            using (var stream =
                       typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.fa-solid-900.ttf"))
            {
                var iconFontConfig = new ImFontConfigPtr(ImFontConfig_ImFontConfig());
                iconFontConfig.MergeMode        = true;
                iconFontConfig.GlyphMinAdvanceX = iconFontConfig.GlyphMaxAdvanceX = (int)(20 * Scale);
                var glyphs = new List <ushort>();
                foreach (var chars in Icons.GetChars())
                {
                    glyphs.Add(chars);
                    glyphs.Add(chars);
                }
                glyphs.Add(0);
                var rangesPtrIcon = Marshal.AllocHGlobal(sizeof(short) * glyphs.Count);
                for (int i = 0; i < glyphs.Count; i++)
                {
                    ((ushort *)rangesPtrIcon)[i] = glyphs[i];
                }
                iconFontConfig.GlyphRanges = rangesPtrIcon;
                var ttf = new byte[stream.Length];
                stream.Read(ttf, 0, ttf.Length);
                ttfPtr = Marshal.AllocHGlobal(ttf.Length);
                Marshal.Copy(ttf, 0, ttfPtr, ttf.Length);
                io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, (int)(15 * Scale), iconFontConfig);
            }

            using (var stream =
                       typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.empty-bullet.ttf"))
            {
                var iconFontConfig = new ImFontConfigPtr(ImFontConfig_ImFontConfig());
                iconFontConfig.MergeMode = true;
                var glyphs        = new ushort[] { Icons.BulletEmpty, Icons.BulletEmpty, 0 };
                var rangesPtrIcon = Marshal.AllocHGlobal(sizeof(short) * glyphs.Length);
                for (int i = 0; i < glyphs.Length; i++)
                {
                    ((ushort *)rangesPtrIcon)[i] = glyphs[i];
                }
                iconFontConfig.GlyphRanges = rangesPtrIcon;
                var ttf = new byte[stream.Length];
                stream.Read(ttf, 0, ttf.Length);
                ttfPtr = Marshal.AllocHGlobal(ttf.Length);
                Marshal.Copy(ttf, 0, ttfPtr, ttf.Length);
                io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, (int)(15 * Scale), iconFontConfig);
            }

            using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.checkerboard.png"))
            {
                checkerboard   = (Texture2D)LibreLancer.ImageLib.Generic.FromStream(stream);
                CheckerboardId = RegisterTexture(checkerboard);
            }
            var monospace = Platform.GetMonospaceBytes();

            fixed(byte *mmPtr = monospace)
            {
                SystemMonospace = io.Fonts.AddFontFromMemoryTTF((IntPtr)mmPtr, monospace.Length, (int)(16 * Scale), fontConfigC);
            }

            ImGuiExt.BuildFontAtlas((IntPtr)io.Fonts.NativePtr);
            byte *fontBytes;
            int   fontWidth, fontHeight;

            io.Fonts.GetTexDataAsRGBA32(out fontBytes, out fontWidth, out fontHeight);
            io.Fonts.TexUvWhitePixel = new Vector2(10, 10);
            Icons.TintGlyphs(fontBytes, fontWidth, fontHeight, Noto);
            fontTexture = new Texture2D(fontWidth, fontHeight, false, SurfaceFormat.Color);
            var bytes = new byte[fontWidth * fontHeight * 4];

            Marshal.Copy((IntPtr)fontBytes, bytes, 0, fontWidth * fontHeight * 4);
            fontTexture.SetData(bytes);
            fontTexture.SetFiltering(TextureFiltering.Linear);
            io.Fonts.SetTexID((IntPtr)FONT_TEXTURE_ID);
            io.Fonts.ClearTexData();
            string glslVer = RenderContext.GLES ? "300 es\nprecision mediump float;" : "140";

            textShader  = new Shader(vertex_source.Replace("{0}", glslVer), text_fragment_source.Replace("{0}", glslVer));
            colorShader = new Shader(vertex_source.Replace("{0}", glslVer), color_fragment_source.Replace("{0}", glslVer));
            dot         = new Texture2D(1, 1, false, SurfaceFormat.Color);
            var c = new Color4b[] { Color4b.White };

            dot.SetData(c);
            Theme.Apply(scale);
            //Required for clipboard function on non-Windows platforms
            utf8buf    = Marshal.AllocHGlobal(8192);
            instance   = this;
            setTextDel = SetClipboardText;
            getTextDel = GetClipboardText;

            io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(getTextDel);
            io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(setTextDel);
        }