internal DrawTextCommand(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font) { this.Text = Text; this.Pos = Pos; this.Color = Color; this.Font = Font; }
internal DemoMemoryEditor() { var R = new Random((int)DateTime.Now.Ticks); R.NextBytes(MemoryBuffer); // Settings Open = true; ReadOnly = false; Cols = 16; OptShowOptions = true; OptShowDataPreview = false; OptShowHexII = false; OptShowAscii = true; OptGreyOutZeroes = true; OptUpperCaseHex = true; OptMidColsCount = 8; OptAddrDigitsCount = 0; HighlightColor = new LGuiColor(255, 255, 255, 50); // State/Internals ContentsWidthChanged = false; DataPreviewAddr = DataEditingAddr = (int)-1; DataEditingTakeFocus = false; GotoAddr = 4 - 1; HighlightMin = HighlightMax = (int)-1; PreviewEndianess = 0; PreviewDataType = DataType.DataType_S32; }
public override void DrawRect(LGuiRect Rect, LGuiColor Color, bool IsFill, bool IsRound) { if (IsRound) { if (IsFill) { Device_.FillPath(BrushCache.GetOrCreate(Color), GenerateRectPath((int)Rect.X, (int)Rect.Y, (int)Rect.Width, (int)Rect.Height, 10, 10)); } else { Device_.DrawPath(PenCache.GetOrCreate(Color), GenerateRectPath((int)Rect.X, (int)Rect.Y, (int)Rect.Width, (int)Rect.Height, 10, 10)); } } else { if (IsFill) { Device_.FillRectangle(BrushCache.GetOrCreate(Color), new Rectangle((int)Rect.X, (int)Rect.Y, (int)Rect.Width, (int)Rect.Height)); } else { Device_.DrawRectangle(PenCache.GetOrCreate(Color), new Rectangle((int)Rect.X, (int)Rect.Y, (int)Rect.Width, (int)Rect.Height)); } } }
internal DrawRectCommand(LGuiRect Rect, LGuiColor Color, bool IsFill, bool IsRound) { this.Rect = Rect; this.Color = Color; this.IsFill = IsFill; this.IsRound = IsRound; }
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); }
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); }
internal DrawCircleCommand(LGuiVec2 Center, float Radius, LGuiColor Color, bool IsFill) { this.Center = Center; this.Radius = Radius; this.Color = Color; this.IsFill = IsFill; }
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; }
internal static void OnProcess(LGuiColor Color, string Format, params object[] Args) { var Text = string.Format(Format, Args); var Size = LGuiConvert.GetTextSize(Text, LGuiContext.Font); var Rect = LGuiLayout.DoLayout(Size); OnProcess(Color, Text, Rect); }
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)); }
internal static Pen GetOrCreate(LGuiColor GuiColor) { var Hash = GuiColor.GetHashCode(); if (!PenCache_.ContainsKey(Hash)) { PenCache_.Add(Hash, new Pen(ColorCache.GetOrCreate(GuiColor))); } return(PenCache_[Hash]); }
internal static Brush GetOrCreate(LGuiColor GuiColor) { var Hash = GuiColor.GetHashCode(); if (!BrushCache_.ContainsKey(Hash)) { BrushCache_.Add(Hash, new SolidBrush(ColorCache.GetOrCreate(GuiColor))); } return(BrushCache_[Hash]); }
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))); } }
internal static void OnProcess(LGuiColor Color, string Text, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Text); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return; } LGuiMisc.CheckAndSetContextID(ref Rect, ID); LGuiGraphics.DrawText(Text, Rect.Pos, Color, LGuiContext.Font); }
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); }
internal static Color GetOrCreate(LGuiColor GuiColor) { return(Color.FromArgb( (int)(GuiColor.A * 255), (int)(GuiColor.R * 255), (int)(GuiColor.G * 255), (int)(GuiColor.B * 255))); // Hash Conflict var Hash = GuiColor.GetHashCode(); if (!ColorCache_.ContainsKey(Hash)) { ColorCache_.Add(Hash, Color.FromArgb( (int)(GuiColor.A * 255), (int)(GuiColor.R * 255), (int)(GuiColor.G * 255), (int)(GuiColor.B * 255))); } return(ColorCache_[Hash]); }
internal static bool OnProcess(string Title, LGuiColor Color, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID); LGuiGraphics.DrawRect(Rect, Color, true); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false); if (LGuiMisc.CheckAndSetFocusID(ID)) { return(true); } return(false); }
public void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font) { var Cmd = new DrawTextCommand(Text, Pos, Color, Font); AddCommand(Cmd); }
// 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);*/ }
public abstract void DrawRect(LGuiRect Rect, LGuiColor Color, bool IsFill, bool IsRound);
internal static void DrawCircle(LGuiVec2 Center, float Radius, LGuiColor Color, bool IsFill) { GetCurrentList().DrawCircle(Center, Radius, Color, IsFill); }
public abstract void DrawLine(LGuiVec2 BeginPos, LGuiVec2 EndPos, LGuiColor Color);
public abstract void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font);
public abstract void DrawCircle(LGuiVec2 Center, float Radius, LGuiColor Color, bool IsFill);
internal static void DrawLine(LGuiVec2 BeginPos, LGuiVec2 EndPos, LGuiColor Color) { GetCurrentList().DrawLine(BeginPos, EndPos, Color); }
internal static void DrawTriangle(LGuiVec2 Vert1, LGuiVec2 Vert2, LGuiVec2 Vert3, LGuiColor Color, bool IsFill) { GetCurrentList().DrawTriangle(Vert1, Vert2, Vert3, Color, IsFill); }
internal static void DrawRect(LGuiRect Rect, LGuiColor Color, bool IsFill, bool IsRound = true) { GetCurrentList().DrawRect(Rect, Color, IsFill, IsRound); }
public abstract void DrawTriangle(LGuiVec2 Vert1, LGuiVec2 Vert2, LGuiVec2 Vert3, LGuiColor Color, bool IsFill);
internal DrawLineCommand(LGuiVec2 BeginPos, LGuiVec2 EndPos, LGuiColor Color) { this.BeginPos = BeginPos; this.EndPos = EndPos; this.Color = Color; }
internal static void DrawText(string Text, LGuiVec2 Pos, LGuiColor Color, LGuiFont Font) { GetCurrentList().DrawText(Text, Pos, Color, Font); }