예제 #1
0
 internal DrawTextCommand(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font)
 {
     this.Text  = Text;
     this.Pos   = Pos;
     this.Color = Color;
     this.Font  = Font;
 }
예제 #2
0
        internal static int OnProcess(string Title, int Index, int Value, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

            if (!LGuiMisc.CheckVisible(ref Rect))
            {
                return(Value);
            }

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.FrameActived :
                               LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.FrameHovered : LGuiStyleColorIndex.Frame;

            var Radius      = LGuiStyle.GetValue(LGuiStyleValueIndex.RadioButtonRadius);
            var RadioCenter = new LGuiVec2(Rect.X + Radius, Rect.Y + Rect.Height / 2.0f);

            LGuiGraphics.DrawCircle(RadioCenter, Radius, BgColorIndex, true);
            LGuiGraphics.DrawCircle(RadioCenter, Radius, LGuiStyleColorIndex.Border, false);
            if (Index == Value)
            {
                LGuiGraphics.DrawCircle(RadioCenter, Radius - 3, LGuiStyleColorIndex.CheckMask, true);
            }
            LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + Radius * 2 + 3, Rect.Y + 1), LGuiStyleColorIndex.Text);

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
                Value = Index;
            }

            return(Value);
        }
예제 #3
0
        internal static void RenderHueRect(LGuiRect Rect)
        {
            var Width  = (int)Rect.Width;
            var Height = (int)Rect.Height;

            var Vertices = new LGuiVec2[Width * Height];
            var Colors   = new LGuiColor[Width * Height];
            var Indices  = new int[Width * Height * 2];
            var Index    = 0;

            for (var Y = 0; Y < Height; ++Y)
            {
                for (var X = 0; X < Width; ++X)
                {
                    Colors[Index]   = LGuiColor.Hsv2Rgb(new LGuiColor(X / (float)(Width - 1), 1, 1));
                    Vertices[Index] = new LGuiVec2(X, Y);

                    Indices[Index * 2 + 0] = Index;
                    Indices[Index * 2 + 1] = Index;
                    Index++;
                }
            }

            LGuiGraphics.DrawPrimitive(Rect, Vertices, Colors, Indices);
        }
예제 #4
0
        internal static void OnProcess(int TextureID, LGuiRect SrcRect, LGuiVec2 DstSize)
        {
            var ID = LGuiHash.CalculateID(LGuiSettings.DefaultTextureTitle + TextureID);

            LGuiContext.SetPreviousControlID(ID);

            if (SrcRect.Width == 0 || SrcRect.Height == 0)
            {
                SrcRect.Size = LGuiConvert.GetTextureIDSize(TextureID);
            }

            if (DstSize.X == 0 || DstSize.Y == 0)
            {
                DstSize = LGuiConvert.GetTextureIDSize(TextureID);
            }

            var DstRect = LGuiLayout.DoLayout(DstSize);

            if (!LGuiMisc.CheckVisible(ref DstRect))
            {
                return;
            }

            LGuiMisc.CheckAndSetContextID(ref DstRect, ID, true);

            LGuiGraphics.DrawTexture(TextureID, SrcRect, DstRect);
        }
예제 #5
0
 internal DrawCircleCommand(LGuiVec2 Center, float Radius, LGuiColor Color, bool IsFill)
 {
     this.Center = Center;
     this.Radius = Radius;
     this.Color  = Color;
     this.IsFill = IsFill;
 }
예제 #6
0
        internal static bool HandleHsvSlider(string Title, ref LGuiColor Hsv, LGuiVec2 Pos, float Length)
        {
            var TitleWidth      = LGuiContext.Font.FontWidth * 2.5f;
            var SpacingY        = LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY);
            var SliderSize      = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);
            var HsvValueChanged = false;

            LGuiGraphics.DrawText("H:", new LGuiVec2(Pos.X, Pos.Y), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_HueSlider", ref Hsv.R, 0.0f, 1.0f, 0.005f, true, "{0:0.00}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y, Length - TitleWidth, SliderSize)))
            {
                HsvValueChanged = true;
            }

            LGuiGraphics.DrawText("S:", new LGuiVec2(Pos.X, Pos.Y + SliderSize + SpacingY), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_SaturationSlider", ref Hsv.G, 0.0f, 1.0f, 0.005f, true, "{0:0.00}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + SliderSize + SpacingY, Length - TitleWidth, SliderSize)))
            {
                HsvValueChanged = true;
            }

            LGuiGraphics.DrawText("V:", new LGuiVec2(Pos.X, Pos.Y + (SliderSize + SpacingY) * 2.0f), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_ValueSlider", ref Hsv.B, 0.0f, 1.0f, 0.005f, true, "{0:0.00}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + (SliderSize + SpacingY) * 2.0f, Length - TitleWidth, SliderSize)))
            {
                HsvValueChanged = true;
            }

            return(HsvValueChanged);
        }
예제 #7
0
 internal DrawTriangleCommand(LGuiVec2 Vert1, LGuiVec2 Vert2, LGuiVec2 Vert3, LGuiColor Color, bool IsFill)
 {
     this.Vert1  = Vert1;
     this.Vert2  = Vert2;
     this.Vert3  = Vert3;
     this.Color  = Color;
     this.IsFill = IsFill;
 }
예제 #8
0
        internal static void OnProcess(LGuiColor Color)
        {
            var FrameContext = LGuiContext.GetCurrentFrame();
            var Size         = new LGuiVec2(FrameContext.Size.X, 1);
            var Rect         = LGuiLayout.DoLayout(Size);

            OnProcess(Color, new LGuiVec2(Rect.Left, Rect.CenterY), new LGuiVec2(Rect.Right, Rect.CenterY));
        }
예제 #9
0
        private static LGuiRect CalculateGrabRect(ref LGuiRect Rect, LGuiVec2 GrabSize, LGuiVec2 MinSize, float Percent, bool IsHorizontal)
        {
            var GrabWidth   = IsHorizontal ? LGuiMisc.Max(MinSize.X, GrabSize.X) : Rect.Width - 4;
            var GrabHeight  = IsHorizontal ? Rect.Height - 4 : LGuiMisc.Max(MinSize.Y, GrabSize.Y);
            var GrabCenterX = IsHorizontal ? LGuiMisc.Lerp(Rect.Left + GrabWidth / 2.0f + 2, Rect.Right - GrabWidth / 2.0f - 2, Percent) : Rect.CenterX;
            var GrabCenterY = IsHorizontal ? Rect.CenterY : LGuiMisc.Lerp(Rect.Top + GrabHeight / 2.0f + 2, Rect.Bottom - GrabHeight / 2.0f - 2, Percent);
            var GrabRect    = LGuiRect.CreateWithCenter(GrabCenterX, GrabCenterY, GrabWidth, GrabHeight);

            return(GrabRect);
        }
예제 #10
0
 public override void DrawTriangle(LGuiVec2 Vert1, LGuiVec2 Vert2, LGuiVec2 Vert3, LGuiColor Color, bool IsFill)
 {
     if (IsFill)
     {
         Device_.FillPath(BrushCache.GetOrCreate(Color), GenerateTrianglePath((int)Vert1.X, (int)Vert1.Y, (int)Vert2.X, (int)Vert2.Y, (int)Vert3.X, (int)Vert3.Y));
     }
     else
     {
         Device_.DrawPath(PenCache.GetOrCreate(Color), GenerateTrianglePath((int)Vert1.X, (int)Vert1.Y, (int)Vert2.X, (int)Vert2.Y, (int)Vert3.X, (int)Vert3.Y));
     }
 }
예제 #11
0
 public override void DrawCircle(LGuiVec2 Center, float Radius, LGuiColor Color, bool IsFill)
 {
     if (IsFill)
     {
         Device_.FillEllipse(BrushCache.GetOrCreate(Color),
                             new Rectangle((int)(Center.X - Radius), (int)(Center.Y - Radius), (int)(Radius * 2), (int)(Radius * 2)));
     }
     else
     {
         Device_.DrawEllipse(PenCache.GetOrCreate(Color),
                             new Rectangle((int)(Center.X - Radius), (int)(Center.Y - Radius), (int)(Radius * 2), (int)(Radius * 2)));
     }
 }
예제 #12
0
        internal static bool OnProcess(string Title, ref string Value, uint MaxLength, LGuiInputTextFlags Flags)
        {
            var TextSize = LGuiConvert.GetTextSize(Value, LGuiContext.Font);

            var Size = new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength), TextSize.Y + 2);

            if ((Flags & LGuiInputTextFlags.Multiline) == LGuiInputTextFlags.Multiline)
            {
                Size.Y = LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength);
            }

            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, ref Value, Rect, MaxLength, Flags));
        }
예제 #13
0
        internal static bool Begin(LGuiVec2 Size)
        {
            if (!LGuiMisc.PreviousControlIsHovered())
            {
                return(false);
            }

            var Pos  = LGuiContext.IO.MousePos + new LGuiVec2(20, 5);
            var Rect = new LGuiRect(Pos, Size);

            LGuiGraphics.SetCurrentLevel(LGuiCommandLevel.Tips);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true);
            LGuiFrame.Begin(LGuiSettings.DefaultToolTipsTitle, Rect, false);
            return(true);
        }
예제 #14
0
        internal static bool HandleRgbSlider(string Title, ref LGuiColor Color, LGuiVec2 Pos, float Length)
        {
            var A               = (int)(Color.A * 255.0f);
            var R               = (int)(Color.R * 255.0f);
            var G               = (int)(Color.G * 255.0f);
            var B               = (int)(Color.B * 255.0f);
            var TitleWidth      = LGuiContext.Font.FontWidth * 2.5f;
            var SpacingY        = LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY);
            var SliderSize      = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize);
            var RgbValueChanged = false;

            LGuiGraphics.DrawText("R:", new LGuiVec2(Pos.X, Pos.Y), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_RedSlider", ref R, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            LGuiGraphics.DrawText("G:", new LGuiVec2(Pos.X, Pos.Y + SliderSize + SpacingY), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_GreenSlider", ref G, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + SliderSize + SpacingY, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            LGuiGraphics.DrawText("B:", new LGuiVec2(Pos.X, Pos.Y + (SliderSize + SpacingY) * 2.0f), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_BlueSlider", ref B, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + (SliderSize + SpacingY) * 2.0f, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            LGuiGraphics.DrawText("A:", new LGuiVec2(Pos.X, Pos.Y + (SliderSize + SpacingY) * 3.0f), LGuiStyleColorIndex.Text);
            if (LGuiSlider.OnProcess($"{Title}_AlphaSlider", ref A, 0, 255, 1, true, "{0}",
                                     new LGuiRect(Pos.X + TitleWidth, Pos.Y + (SliderSize + SpacingY) * 3.0f, Length - TitleWidth, SliderSize)))
            {
                RgbValueChanged = true;
            }

            if (RgbValueChanged)
            {
                Color = new LGuiColor(R, G, B, A);
            }

            return(RgbValueChanged);
        }
예제 #15
0
        internal DemoManager(LGuiVec2 WinSize)
        {
            this.WinSize = WinSize;

            TextFont_ = new Font("Arial", 10);

            WinConvert.Register();
            Executor_ = new GdiCommandExecutor();
            LGui.SetCommandExecutor(Executor_);

            var IO = LGui.GetIO();

            IO.DisplaySize = new LGuiVec2(960, 540);

            FileHelper.AddSearchPath($"{AppContext.BaseDirectory}..\\..\\Res\\");

            var Mapper = new LGuiMapper();

            Input.OnKeyEvent   += (Key, IsKeyDown) => { IO.SetKeyState(Mapper.ToLGuiKey(Key), IsKeyDown); };
            Input.OnMouseEvent += (Btn, X, Y, IsMouseDown, IsMouseMove) => { IO.SetMouseState(Mapper.ToLGuiMouseBtn(Btn), X, Y, IsMouseDown, IsMouseMove); };
        }
예제 #16
0
        internal static void OnProcess(string Title, float Value)
        {
            var Size = new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength), LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize));

            OnProcess(Title, Value, Size);
        }
예제 #17
0
        internal static bool OnProcess(string Title, ref int ItemIndex, string[] Items, LGuiVec2 Size)
        {
            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, ref ItemIndex, Items, Rect));
        }
예제 #18
0
 internal static void DrawTriangle(LGuiVec2 Vert1, LGuiVec2 Vert2, LGuiVec2 Vert3, LGuiColor Color, bool IsFill)
 {
     GetCurrentList().DrawTriangle(Vert1, Vert2, Vert3, Color, IsFill);
 }
예제 #19
0
        internal static void OnProcess(string Title, float Value, LGuiVec2 Size)
        {
            var Rect = LGuiLayout.DoLayout(Size);

            OnProcess(Title, Value, Rect);
        }
예제 #20
0
        // Memory Editor contents only
        void DrawContents(byte[] mem_data_void_ptr, int mem_size, int base_display_addr = 0x0000)
        {
            var CmdList = LGui.CreateCommandList();

            var   mem_data = mem_data_void_ptr;
            Sizes s        = new Sizes();

            CalcSizes(ref s, mem_size, base_display_addr);
            var IO = LGui.GetIO();

            // We begin into our scrolling region with the 'ImGuiWindowFlags_NoMove' in order to prevent click from moving the window.
            // This is used as a facility since our main click detection code doesn't assign an ActiveId so the click would normally be caught as a window-move.
            float height_separator = 5;

            int line_total_count = (int)((mem_size + Cols - 1) / Cols);

            /*ImGuiListClipper clipper(line_total_count, s.LineHeight);
             * const size_t visible_start_addr = clipper.DisplayStart * Cols;
             * const size_t visible_end_addr = clipper.DisplayEnd * Cols;*/

            var DisplayStart       = (int)(LGui.GetFrameScrollY() / (s.LineHeight + 3));
            var DisplayEnd         = (int)((LGui.GetFrameScrollY() + 500) / (s.LineHeight + 3));
            int visible_start_addr = DisplayStart * Cols;
            int visible_end_addr   = DisplayEnd * Cols;

            bool data_next = false;

            if (ReadOnly || DataEditingAddr >= mem_size)
            {
                DataEditingAddr = (int)-1;
            }
            if (DataPreviewAddr >= mem_size)
            {
                DataPreviewAddr = (int)-1;
            }

            int preview_data_type_size = OptShowDataPreview ? DataTypeGetSize(PreviewDataType) : 0;

            int data_editing_addr_backup = DataEditingAddr;
            int data_editing_addr_next   = (int)-1;

            if (DataEditingAddr != (int)-1)
            {
                // Move cursor but only apply on next frame so scrolling with be synchronized (because currently we can't change the scrolling while the window is being rendered)
                if (IO.IsKeyPressed(LGuiKeys.Up) && DataEditingAddr >= (int)Cols)
                {
                    data_editing_addr_next = DataEditingAddr - Cols; DataEditingTakeFocus = true;
                }
                else if (IO.IsKeyPressed(LGuiKeys.Down) && DataEditingAddr < mem_size - Cols)
                {
                    data_editing_addr_next = DataEditingAddr + Cols; DataEditingTakeFocus = true;
                }
                else if (IO.IsKeyPressed(LGuiKeys.Left) && DataEditingAddr > 0)
                {
                    data_editing_addr_next = DataEditingAddr - 1; DataEditingTakeFocus = true;
                }
                else if (IO.IsKeyPressed(LGuiKeys.Right) && DataEditingAddr < mem_size - 1)
                {
                    data_editing_addr_next = DataEditingAddr + 1; DataEditingTakeFocus = true;
                }
            }
            if (data_editing_addr_next != (int)-1 && (data_editing_addr_next / Cols) != (data_editing_addr_backup / Cols))
            {
                // Track cursor movements
                int  scroll_offset  = ((int)(data_editing_addr_next / Cols) - (int)(data_editing_addr_backup / Cols));
                bool scroll_desired = (scroll_offset < 0 && data_editing_addr_next < visible_start_addr + Cols * 2) || (scroll_offset > 0 && data_editing_addr_next > visible_end_addr - Cols * 2);
                if (scroll_desired)
                {
                    LGui.SetFrameScrollY(LGui.GetFrameScrollY() + scroll_offset * (s.LineHeight + 3));
                }
            }

            // Draw vertical separator
            LGuiVec2 window_pos = new LGuiVec2(5, 5);

            if (OptShowAscii)
            {
                CmdList.DrawLine(
                    new LGuiVec2(window_pos.X + s.PosAsciiStart - s.GlyphWidth, window_pos.Y),
                    new LGuiVec2(window_pos.X + s.PosAsciiStart - s.GlyphWidth, window_pos.Y + 9999),
                    new LGuiColor(0.43f, 0.43f, 0.50f, 0.50f));
            }

            var color_text     = new LGuiColor(1.00f, 1.00f, 1.00f, 1.00f);
            var color_disabled = OptGreyOutZeroes ? new LGuiColor(0.50f, 0.50f, 0.50f, 1.00f) : color_text;

            var format_address    = OptUpperCaseHex ? "{0:X4}: " : "{0:X4}: ";
            var format_data       = OptUpperCaseHex ? "{0:X4}: " : "{0:X4}: ";
            var format_range      = OptUpperCaseHex ? "Range {0:X4}..{1:X4}" : "Range {0:X4}..{1:X4}";
            var format_byte       = OptUpperCaseHex ? "{0:X2}" : "{0:X2}";
            var format_byte_space = OptUpperCaseHex ? "{0:X2}" : "{0:X2}";

            for (int line_i = 0; line_i < mem_size / Cols; ++line_i)
            {
                int addr = (int)(line_i * Cols);

                LGui.Text(format_address, base_display_addr + addr);

                for (int n = 0; n < Cols && addr < mem_size; ++n, ++addr)
                {
                    LGui.PushID(addr);

                    float byte_pos_x = s.PosHexStart + s.HexCellWidth * n;
                    if (OptMidColsCount > 0)
                    {
                        byte_pos_x += (n / OptMidColsCount) * s.SpacingBetweenMidCols;
                    }
                    LGui.SameLine(byte_pos_x);

                    // Draw highlight
                    bool is_highlight_from_user_range = (addr >= HighlightMin && addr < HighlightMax);
                    bool is_highlight_from_preview    = (addr >= DataPreviewAddr && addr < DataPreviewAddr + preview_data_type_size);
                    if (is_highlight_from_user_range || is_highlight_from_preview)
                    {
                        var   pos                      = LGui.GetCursorPos();
                        float highlight_width          = s.GlyphWidth * 2;
                        bool  is_next_byte_highlighted = (addr + 1 < mem_size) && ((HighlightMax != (int)-1 && addr + 1 < HighlightMax));
                        if (is_next_byte_highlighted || (n + 1 == Cols))
                        {
                            highlight_width = s.HexCellWidth;
                            if (OptMidColsCount > 0 && n > 0 && (n + 1) < Cols && ((n + 1) % OptMidColsCount) == 0)
                            {
                                highlight_width += s.SpacingBetweenMidCols;
                            }
                        }
                        CmdList.DrawRect(new LGuiRect(pos, new LGuiVec2(highlight_width, s.LineHeight)), HighlightColor, true, false);
                    }
                    if (DataEditingAddr == addr)
                    {// Display text input on current byte
                        bool data_write = false;
                        if (DataEditingTakeFocus)
                        {
                            AddrInputBuf = string.Format(format_data, s.AddrDigitsCount, base_display_addr + addr);
                            DataInputBuf = string.Format(format_byte, mem_data[addr]);
                        }
                        var itemwidth = s.GlyphWidth * 2;

                        /*struct UserData
                         * {
                         *  // FIXME: We should have a way to retrieve the text edit cursor position more easily in the API, this is rather tedious. This is such a ugly mess we may be better off not using InputText() at all here.
                         *  static int Callback(ImGuiInputTextCallbackData* data)
                         *  {
                         *      UserData* user_data = (UserData*)data->UserData;
                         *      if (!data->HasSelection())
                         *          user_data->CursorPos = data->CursorPos;
                         *      if (data->SelectionStart == 0 && data->SelectionEnd == data->BufTextLen)
                         *      {
                         *          // When not editing a byte, always rewrite its content (this is a bit tricky, since InputText technically "owns" the master copy of the buffer we edit it in there)
                         *          data->DeleteChars(0, data->BufTextLen);
                         *          data->InsertChars(0, user_data->CurrentBufOverwrite);
                         *          data->SelectionStart = 0;
                         *          data->SelectionEnd = data->CursorPos = 2;
                         *      }
                         *      return 0;
                         *  }
                         *  char CurrentBufOverwrite[3];  // Input
                         *  int CursorPos;               // Output
                         * };
                         * UserData user_data;
                         * user_data.CursorPos = -1;
                         * sprintf(user_data.CurrentBufOverwrite, format_byte, ReadFn? ReadFn(mem_data, addr) : mem_data[addr]);
                         * ImGuiInputTextFlags flags = ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_AlwaysInsertMode | ImGuiInputTextFlags_CallbackAlways;
                         * if (ImGui::InputText("##data", DataInputBuf, 32, flags, UserData::Callback, &user_data))
                         *  data_write = data_next = true;
                         * else if (!DataEditingTakeFocus && !ImGui::IsItemActive())
                         *  DataEditingAddr = data_editing_addr_next = (size_t)-1;
                         * DataEditingTakeFocus = false;
                         * if (user_data.CursorPos >= 2)
                         *  data_write = data_next = true;
                         * if (data_editing_addr_next != (size_t)-1)
                         *  data_write = data_next = false;
                         * int data_input_value;
                         * if (data_write && sscanf(DataInputBuf, "%X", &data_input_value) == 1)
                         * {
                         *  if (WriteFn)
                         *      WriteFn(mem_data, addr, (u8) data_input_value);
                         *  else
                         *      mem_data[addr] = (u8) data_input_value;
                         * }*/


                        var Flags = LGuiInputTextFlags.CharsHexadecimal | /*LGuiInputTextFlags.AutoSelectAll |*/
                                    LGuiInputTextFlags.InsertMode | LGuiInputTextFlags.EnterReturnsTrue;
                        if (LGui.InputText("##data", ref DataInputBuf, 2,
                                           new LGuiVec2(itemwidth + 5, LGuiFont.Default.FontHeight + 2), Flags))
                        {
                            data_write = data_next = true;
                        }
                        else if (!DataEditingTakeFocus && !LGui.PreviousControlIsActive())
                        {
                            DataEditingAddr = data_editing_addr_next = (int)-1;
                        }

                        //LGui.PreviousControlFocus();

                        int data_input_value;
                        if (data_write && int.TryParse(DataInputBuf, NumberStyles.HexNumber, null, out data_input_value))
                        {
                            mem_data[addr] = (byte)data_input_value;
                        }
                    }
                    else
                    {
                        byte b = mem_data[addr];

                        if (OptShowHexII)
                        {
                            if ((b >= 32 && b < 128))
                            {
                                LGui.Text(".{0}", (char)b);
                            }
                            else if (b == 0xFF && OptGreyOutZeroes)
                            {
                                LGui.Text(color_disabled, "##");
                            }
                            else if (b == 0x00)
                            {
                                LGui.Text("  ");
                            }
                            else
                            {
                                LGui.Text(format_byte_space, b);
                            }
                        }
                        else
                        {
                            if (b == 0 && OptGreyOutZeroes)
                            {
                                LGui.Text(color_disabled, "00");
                            }
                            else
                            {
                                LGui.Text(format_byte_space, b);
                            }
                        }

                        if (!ReadOnly && LGui.PreviousControlIsHovered() && IO.IsMouseClick(LGuiMouseButtons.Left))
                        {
                            DataEditingTakeFocus   = true;
                            data_editing_addr_next = addr;
                        }
                    }

                    LGui.PopID();
                }

                if (OptShowAscii)
                {
                    // Draw ASCII values
                    LGui.SameLine(s.PosAsciiStart);
                    var pos = LGui.GetCursorPos();
                    addr = line_i * Cols;
                    LGui.PushID(line_i);
                    if (LGui.InvisibleButton("ascii", new LGuiVec2(s.PosAsciiEnd - s.PosAsciiStart, s.LineHeight)))
                    {
                        DataEditingAddr      = DataPreviewAddr = addr + (int)((LGui.GetIO().MousePos.X - pos.X) / s.GlyphWidth);
                        DataEditingTakeFocus = true;
                    }
                    LGui.PopID();
                    for (int n = 0; n < Cols && addr < mem_size; n++, addr++)
                    {
                        if (addr == DataEditingAddr)
                        {
                            CmdList.DrawRect(new LGuiRect(pos, new LGuiVec2(s.GlyphWidth, s.LineHeight)), new LGuiColor(0.16f, 0.29f, 0.48f, 0.54f), true, false);
                            CmdList.DrawRect(new LGuiRect(pos, new LGuiVec2(s.GlyphWidth, s.LineHeight)), new LGuiColor(0.26f, 0.59f, 0.98f, 0.35f), true, false);
                        }
                        byte c         = mem_data[addr];
                        char display_c = (c < 32 || c >= 128) ? '.' : (char)c;
                        LGui.SameLine(pos.X);
                        LGui.Text((display_c == '.') ? color_disabled : color_text, "{0}", display_c.ToString());
                        //LGuiGraphics.DrawText(display_c.ToString(), pos, new LGuiTextStyle(LGuiFontStyle.Default, (display_c == '.') ? color_disabled : color_text));
                        pos.X += s.GlyphWidth;
                    }
                }
            }


            if (data_next && DataEditingAddr < mem_size)
            {
                DataEditingAddr      = DataPreviewAddr = DataEditingAddr + 1;
                DataEditingTakeFocus = true;
            }
            else if (data_editing_addr_next != (int)-1)
            {
                DataEditingAddr = DataPreviewAddr = data_editing_addr_next;
            }

            LGui.AddCommandList(CmdList);

            /*for (int line_i = clipper.DisplayStart; line_i < clipper.DisplayEnd; line_i++) // display only visible lines
             * {
             *  int addr = (int)(line_i * Cols);
             *
             *  LGui.Text(format_address, base_display_addr + addr);
             *
             *  // Draw Hexadecimal
             *  for (int n = 0; n < Cols && addr < mem_size; n++, addr++)
             *  {
             *      float byte_pos_x = s.PosHexStart + s.HexCellWidth * n;
             *      if (OptMidColsCount > 0)
             *          byte_pos_x += (n / OptMidColsCount) * s.SpacingBetweenMidCols;
             *      ImGui::SameLine(byte_pos_x);
             *
             *      // Draw highlight
             *      bool is_highlight_from_user_range = (addr >= HighlightMin && addr < HighlightMax);
             *      bool is_highlight_from_user_func = (HighlightFn && HighlightFn(mem_data, addr));
             *      bool is_highlight_from_preview = (addr >= DataPreviewAddr && addr < DataPreviewAddr + preview_data_type_size);
             *      if (is_highlight_from_user_range || is_highlight_from_user_func || is_highlight_from_preview)
             *      {
             *          ImVec2 pos = ImGui::GetCursorScreenPos();
             *          float highlight_width = s.GlyphWidth * 2;
             *          bool is_next_byte_highlighted = (addr + 1 < mem_size) && ((HighlightMax != (size_t) - 1 && addr + 1 < HighlightMax) || (HighlightFn && HighlightFn(mem_data, addr + 1)));
             *          if (is_next_byte_highlighted || (n + 1 == Cols))
             *          {
             *              highlight_width = s.HexCellWidth;
             *              if (OptMidColsCount > 0 && n > 0 && (n + 1) < Cols && ((n + 1) % OptMidColsCount) == 0)
             *                  highlight_width += s.SpacingBetweenMidCols;
             *          }
             *          draw_list->AddRectFilled(pos, ImVec2(pos.x + highlight_width, pos.y + s.LineHeight), HighlightColor);
             *      }
             *
             *      if (DataEditingAddr == addr)
             *      {
             *          // Display text input on current byte
             *          bool data_write = false;
             *          ImGui::PushID((void*)addr);
             *          if (DataEditingTakeFocus)
             *          {
             *              ImGui::SetKeyboardFocusHere();
             *              ImGui::CaptureKeyboardFromApp(true);
             *              sprintf(AddrInputBuf, format_data, s.AddrDigitsCount, base_display_addr + addr);
             *              sprintf(DataInputBuf, format_byte, ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]);
             *          }
             *          ImGui::PushItemWidth(s.GlyphWidth * 2);
             *          struct UserData
             *          {
             *              // FIXME: We should have a way to retrieve the text edit cursor position more easily in the API, this is rather tedious. This is such a ugly mess we may be better off not using InputText() at all here.
             *              static int Callback(ImGuiInputTextCallbackData* data)
             *              {
             *                  UserData* user_data = (UserData*)data->UserData;
             *                  if (!data->HasSelection())
             *                      user_data->CursorPos = data->CursorPos;
             *                  if (data->SelectionStart == 0 && data->SelectionEnd == data->BufTextLen)
             *                  {
             *                      // When not editing a byte, always rewrite its content (this is a bit tricky, since InputText technically "owns" the master copy of the buffer we edit it in there)
             *                      data->DeleteChars(0, data->BufTextLen);
             *                      data->InsertChars(0, user_data->CurrentBufOverwrite);
             *                      data->SelectionStart = 0;
             *                      data->SelectionEnd = data->CursorPos = 2;
             *                  }
             *                  return 0;
             *              }
             *              char CurrentBufOverwrite[3];  // Input
             *              int CursorPos;               // Output
             *          };
             *          UserData user_data;
             *          user_data.CursorPos = -1;
             *          sprintf(user_data.CurrentBufOverwrite, format_byte, ReadFn? ReadFn(mem_data, addr) : mem_data[addr]);
             *          ImGuiInputTextFlags flags = ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_AlwaysInsertMode | ImGuiInputTextFlags_CallbackAlways;
             *          if (ImGui::InputText("##data", DataInputBuf, 32, flags, UserData::Callback, &user_data))
             *              data_write = data_next = true;
             *          else if (!DataEditingTakeFocus && !ImGui::IsItemActive())
             *              DataEditingAddr = data_editing_addr_next = (size_t)-1;
             *          DataEditingTakeFocus = false;
             *          ImGui::PopItemWidth();
             *          if (user_data.CursorPos >= 2)
             *              data_write = data_next = true;
             *          if (data_editing_addr_next != (size_t)-1)
             *              data_write = data_next = false;
             *          int data_input_value;
             *          if (data_write && sscanf(DataInputBuf, "%X", &data_input_value) == 1)
             *          {
             *              if (WriteFn)
             *                  WriteFn(mem_data, addr, (u8) data_input_value);
             *              else
             *                  mem_data[addr] = (u8) data_input_value;
             *          }
             *          ImGui::PopID();
             *      }
             *      else
             *      {
             *          // NB: The trailing space is not visible but ensure there's no gap that the mouse cannot click on.
             *          u8 b = ReadFn ? ReadFn(mem_data, addr) : mem_data[addr];
             *
             *          if (OptShowHexII)
             *          {
             *              if ((b >= 32 && b< 128))
             *                  ImGui::Text(".%c ", b);
             *              else if (b == 0xFF && OptGreyOutZeroes)
             *                  ImGui::TextDisabled("## ");
             *              else if (b == 0x00)
             *                  ImGui::Text("   ");
             *              else
             *                  ImGui::Text(format_byte_space, b);
             *          }
             *          else
             *          {
             *              if (b == 0 && OptGreyOutZeroes)
             *                  ImGui::TextDisabled("00 ");
             *              else
             *                  ImGui::Text(format_byte_space, b);
             *          }
             *          if (!ReadOnly && ImGui::IsItemHovered() && ImGui::IsMouseClicked(0))
             *          {
             *              DataEditingTakeFocus = true;
             *              data_editing_addr_next = addr;
             *          }
             *      }
             *  }
             *
             *  if (OptShowAscii)
             *  {
             *      // Draw ASCII values
             *      ImGui::SameLine(s.PosAsciiStart);
             *      ImVec2 pos = ImGui::GetCursorScreenPos();
             * addr = line_i* Cols;
             * ImGui::PushID(line_i);
             *      if (ImGui::InvisibleButton("ascii", ImVec2(s.PosAsciiEnd - s.PosAsciiStart, s.LineHeight)))
             *      {
             *          DataEditingAddr = DataPreviewAddr = addr + (size_t) ((ImGui::GetIO().MousePos.x - pos.x) / s.GlyphWidth);
             *          DataEditingTakeFocus = true;
             *      }
             *      ImGui::PopID();
             *      for (int n = 0; n<Cols && addr<mem_size; n++, addr++)
             *      {
             *          if (addr == DataEditingAddr)
             *          {
             *              draw_list->AddRectFilled(pos, ImVec2(pos.x + s.GlyphWidth, pos.y + s.LineHeight), ImGui::GetColorU32(ImGuiCol_FrameBg));
             *              draw_list->AddRectFilled(pos, ImVec2(pos.x + s.GlyphWidth, pos.y + s.LineHeight), ImGui::GetColorU32(ImGuiCol_TextSelectedBg));
             *          }
             *          unsigned char c = ReadFn ? ReadFn(mem_data, addr) : mem_data[addr];
             * char display_c = (c < 32 || c >= 128) ? '.' : c;
             * draw_list->AddText(pos, (display_c == '.') ? color_disabled : color_text, &display_c, &display_c + 1);
             *          pos.x += s.GlyphWidth;
             *      }
             *  }
             * }
             * clipper.End();
             * ImGui::PopStyleVar(2);
             * ImGui::EndChild();
             *
             * if (data_next && DataEditingAddr<mem_size)
             * {
             *  DataEditingAddr = DataPreviewAddr = DataEditingAddr + 1;
             *  DataEditingTakeFocus = true;
             * }
             * else if (data_editing_addr_next != (size_t)-1)
             * {
             *  DataEditingAddr = DataPreviewAddr = data_editing_addr_next;
             * }
             *
             * bool next_show_data_preview = OptShowDataPreview;
             * if (OptShowOptions)
             * {
             *  ImGui::Separator();
             *
             *  // Options menu
             *
             *  if (ImGui::Button("Options"))
             *      ImGui::OpenPopup("context");
             *  if (ImGui::BeginPopup("context"))
             *  {
             *      ImGui::PushItemWidth(56);
             *      if (ImGui::DragInt("##cols", &Cols, 0.2f, 4, 32, "%d cols")) { ContentsWidthChanged = true; }
             *      ImGui::PopItemWidth();
             *      ImGui::Checkbox("Show Data Preview", &next_show_data_preview);
             *      ImGui::Checkbox("Show HexII", &OptShowHexII);
             *      if (ImGui::Checkbox("Show Ascii", &OptShowAscii)) { ContentsWidthChanged = true; }
             *      ImGui::Checkbox("Grey out zeroes", &OptGreyOutZeroes);
             *      ImGui::Checkbox("Uppercase Hex", &OptUpperCaseHex);
             *
             *      ImGui::EndPopup();
             *  }
             *
             *  ImGui::SameLine();
             *  ImGui::Text(format_range, s.AddrDigitsCount, base_display_addr, s.AddrDigitsCount, base_display_addr + mem_size - 1);
             *  ImGui::SameLine();
             *  ImGui::PushItemWidth((s.AddrDigitsCount + 1) * s.GlyphWidth + style.FramePadding.x* 2.0f);
             *  if (ImGui::InputText("##addr", AddrInputBuf, 32, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue))
             *  {
             *      size_t goto_addr;
             *      if (sscanf(AddrInputBuf, "%" _PRISizeT "X", &goto_addr) == 1)
             *      {
             *          GotoAddr = goto_addr - base_display_addr;
             *          HighlightMin = 3 = (size_t)-1;
             *      }
             *  }
             *  ImGui::PopItemWidth();
             *
             *  if (GotoAddr != (size_t)-1)
             *  {
             *      if (GotoAddr<mem_size)
             *      {
             *          ImGui::BeginChild("##scrolling");
             *          ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + (GotoAddr / Cols) * ImGui::GetTextLineHeight());
             *          ImGui::EndChild();
             *          DataEditingAddr = DataPreviewAddr = GotoAddr;
             *          DataEditingTakeFocus = true;
             *      }
             *      GotoAddr = (size_t)-1;
             *  }
             * }
             *
             * if (OptShowDataPreview)
             * {
             *  ImGui::Separator();
             *  ImGui::AlignTextToFramePadding();
             *  ImGui::Text("Preview as:");
             *  ImGui::SameLine();
             *  ImGui::PushItemWidth((s.GlyphWidth* 10.0f) + style.FramePadding.x* 2.0f + style.ItemInnerSpacing.x);
             *  if (ImGui::BeginCombo("##combo_type", DataTypeGetDesc(PreviewDataType), ImGuiComboFlags_HeightLargest))
             *  {
             *      for (int n = 0; n<DataType_COUNT; n++)
             *          if (ImGui::Selectable(DataTypeGetDesc((DataType) n), PreviewDataType == n))
             *              PreviewDataType = (DataType) n;
             * ImGui::EndCombo();
             *  }
             *  ImGui::PopItemWidth();
             *  ImGui::SameLine();
             *  ImGui::PushItemWidth((s.GlyphWidth* 6.0f) + style.FramePadding.x* 2.0f + style.ItemInnerSpacing.x);
             *  ImGui::Combo("##combo_endianess", &PreviewEndianess, "LE\0BE\0\0");
             *  ImGui::PopItemWidth();
             *
             *  char buf[128];
             * float x = s.GlyphWidth * 6.0f;
             * bool has_value = DataPreviewAddr != (size_t) - 1;
             *  if (has_value)
             *      DisplayPreviewData(DataPreviewAddr, mem_data, mem_size, PreviewDataType, DataFormat_Dec, buf, (size_t) IM_ARRAYSIZE(buf));
             * ImGui::Text("Dec"); ImGui::SameLine(x); ImGui::TextUnformatted(has_value? buf : "N/A");
             *  if (has_value)
             *      DisplayPreviewData(DataPreviewAddr, mem_data, mem_size, PreviewDataType, DataFormat_Hex, buf, (size_t) IM_ARRAYSIZE(buf));
             * ImGui::Text("Hex"); ImGui::SameLine(x); ImGui::TextUnformatted(has_value? buf : "N/A");
             *  if (has_value)
             *      DisplayPreviewData(DataPreviewAddr, mem_data, mem_size, PreviewDataType, DataFormat_Bin, buf, (size_t) IM_ARRAYSIZE(buf));
             * ImGui::Text("Bin"); ImGui::SameLine(x); ImGui::TextUnformatted(has_value? buf : "N/A");
             * }
             *
             * OptShowDataPreview = next_show_data_preview;
             *
             * // Notify the main window of our ideal child content size (FIXME: we are missing an API to get the contents size from the child)
             * ImGui::SetCursorPosX(s.WindowWidth);*/
        }
예제 #21
0
        internal static bool OnProcess(string Title, ref string Value, uint MaxLength, LGuiVec2 Size, LGuiInputTextFlags Flags)
        {
            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, ref Value, Rect, MaxLength, Flags));
        }
예제 #22
0
 public abstract void DrawLine(LGuiVec2 BeginPos, LGuiVec2 EndPos, LGuiColor Color);
예제 #23
0
 public abstract void DrawTriangle(LGuiVec2 Vert1, LGuiVec2 Vert2, LGuiVec2 Vert3, LGuiColor Color, bool IsFill);
예제 #24
0
 public abstract void DrawCircle(LGuiVec2 Center, float Radius, LGuiColor Color, bool IsFill);
예제 #25
0
 public abstract void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font);
예제 #26
0
 internal static void DrawCircle(LGuiVec2 Center, float Radius, LGuiColor Color, bool IsFill)
 {
     GetCurrentList().DrawCircle(Center, Radius, Color, IsFill);
 }
예제 #27
0
 internal static void DrawCircle(LGuiVec2 Center, float Radius, LGuiStyleColorIndex ColorIndex, bool IsFill)
 {
     GetCurrentList().DrawCircle(Center, Radius, LGuiStyle.GetColor(ColorIndex), IsFill);
 }
예제 #28
0
 internal DrawLineCommand(LGuiVec2 BeginPos, LGuiVec2 EndPos, LGuiColor Color)
 {
     this.BeginPos = BeginPos;
     this.EndPos   = EndPos;
     this.Color    = Color;
 }
예제 #29
0
 internal static void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font)
 {
     GetCurrentList().DrawText(Text, Pos, Color, Font);
 }
예제 #30
0
 internal static void DrawText(string Text, LGuiVec2 Pos, LGuiStyleColorIndex ColorIndex)
 {
     GetCurrentList().DrawText(Text, Pos, LGuiStyle.GetColor(ColorIndex), LGuiContext.Font);
 }