/// <summary> /// Draw a preview graph texture on the preview pane /// </summary> /// <param name="plot">The graph being drawn</param> /// <param name="xPadding">horizontal padding</param> /// <param name="captionHeight">height of the caption</param> /// <param name="captionBackgroundcolor">contrast background colour of the caption</param> /// <param name="canHover">output flag states if we can safely draw a mouseover tooltip</param> /// <param name="mainWidgetSize">Size of the maingraph widget, used for projecting the zoom envelope</param> /// <returns>The graph was clicked</returns> private bool DrawPreviewGraph(PlottedGraph plot, float xPadding, float captionHeight, uint captionBackgroundcolor, out bool canHover, Vector2 mainWidgetSize) { ImDrawListPtr imdp = ImGui.GetWindowDrawList(); //draw on and clipped to this window bool clicked = false; canHover = false; if (plot == null) { return(clicked); } int graphNodeCount = plot.GraphNodeCount(); if (graphNodeCount == 0) { return(clicked); } plot.GetLatestTexture(out Texture previewTexture); if (previewTexture == null) { return(clicked); } bool isSelected = plot.TID == selectedGraphTID; canHover = true; //copy in the actual rendered graph ImGui.SetCursorPosY(ImGui.GetCursorPosY()); Vector2 subGraphPosition = ImGui.GetCursorScreenPos() + new Vector2(xPadding, 0); IntPtr CPUframeBufferTextureId = _ImGuiController !.GetOrCreateImGuiBinding(_gd !.ResourceFactory, previewTexture, $"PreviewPlot{plot.TID}"); imdp.AddImage(user_texture_id: CPUframeBufferTextureId, p_min: subGraphPosition, p_max: new Vector2(subGraphPosition.X + EachGraphWidth, subGraphPosition.Y + EachGraphHeight), uv_min: new Vector2(0, 1), uv_max: new Vector2(1, 0)); float borderThickness = Themes.GetThemeSize(Themes.eThemeSize.PreviewSelectedBorder); float halfBorderThickness = (float)Math.Floor(borderThickness / 2f); if (isSelected) { DrawPreviewZoomEnvelope(plot, subGraphPosition); //Draw the thicker selected graph border if (borderThickness > 0) { imdp.AddRect( p_min: new Vector2(subGraphPosition.X + halfBorderThickness, subGraphPosition.Y + halfBorderThickness), p_max: new Vector2((subGraphPosition.X + EachGraphWidth - halfBorderThickness), subGraphPosition.Y + EachGraphHeight - halfBorderThickness), col: GetGraphBorderColour(plot), 0, ImDrawFlags.None, borderThickness); } } //write the caption string Caption = $"TID:{plot.TID} {graphNodeCount} nodes {(isSelected ? "[Selected]" : "")}"; ImGui.SetCursorPosX(ImGui.GetCursorPosX()); Vector2 captionBGStart = subGraphPosition + new Vector2(borderThickness, borderThickness); Vector2 captionBGEnd = new Vector2((captionBGStart.X + EachGraphWidth - borderThickness * 2), captionBGStart.Y + captionHeight); imdp.AddRectFilled(p_min: captionBGStart, p_max: captionBGEnd, col: captionBackgroundcolor); ImGui.PushStyleColor(ImGuiCol.Text, Themes.GetThemeColourUINT(Themes.eThemeColour.PreviewText)); ImGui.SetCursorPosX(ImGui.GetCursorPosX() + CONSTANTS.UI.PREVIEW_PANE_X_PADDING + borderThickness + 1); ImGui.SetCursorPosY(ImGui.GetCursorPosY() + borderThickness); ImGui.Text(Caption); ImGui.PopStyleColor(); ImGui.SetCursorPosX(ImGui.GetCursorPosX() + EachGraphWidth - 48); //live thread activity plot if (ActiveTrace is not null && !ActiveTrace.WasLoadedFromSave) { ImGui.SetCursorPosY(ImGui.GetCursorPosY() - captionHeight); float maxVal; float[]? invalues = null; if (plot.InternalProtoGraph.TraceReader != null) { plot.InternalProtoGraph.TraceReader.RecentMessageRates(out invalues); } if (invalues == null || invalues.Length == 0) { invalues = new List <float>() { 0, 0, 0, 0, 0 }.ToArray(); maxVal = 100; } else { maxVal = invalues.Max(); } ImGui.PushStyleColor(ImGuiCol.FrameBg, captionBackgroundcolor); ImGui.PlotLines("", ref invalues[0], invalues.Length, 0, "", 0, maxVal, new Vector2(40, captionHeight)); if (ImGui.IsItemHovered()) { canHover = false; //The PlotLines widget doesn't allow disabling the mouseover, so have to prevent our mousover to avoid a merged tooltip } ImGui.PopStyleColor(); } //invisible button to detect graph click ImGui.SetCursorPos(new Vector2(1, ImGui.GetCursorPosY() - (float)(captionHeight))); if (ImGui.InvisibleButton("PrevGraphBtn" + plot.TID, new Vector2(EachGraphWidth, EachGraphHeight - 2)) || ImGui.IsItemActive()) { clicked = true; if (isSelected) { Vector2 clickPos = ImGui.GetMousePos(); Vector2 clickOffset = clickPos - subGraphPosition; clickOffset.Y = EachGraphHeight - clickOffset.Y; plot.MoveCameraToPreviewClick(clickOffset, new Vector2(EachGraphWidth, EachGraphHeight), mainGraphWidgetSize: mainWidgetSize, PreviewProjection); } } return(clicked); }
/// <summary> /// Draw the preview graph widget /// </summary> public void DrawWidget(Vector2 mainWidgetSize) { bool showToolTip = false; PlottedGraph?latestHoverGraph = null; TraceRecord? activeTrace = ActiveTrace; if (activeTrace == null) { return; } float captionHeight = ImGui.CalcTextSize("123456789").Y; DrawnPreviewGraphs = activeTrace.GetPlottedGraphs(); List <int> indexes = GetGraphOrder(trace: activeTrace, graphs: DrawnPreviewGraphs); uint captionBackgroundcolor = Themes.GetThemeColourUINT(Themes.eThemeColour.PreviewTextBackground); ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(0, CONSTANTS.UI.PREVIEW_PANE_Y_SEP)); //Graph drawing loop if (ImGui.BeginTable("PrevGraphsTable", 1, ImGuiTableFlags.Borders, new Vector2(CONSTANTS.UI.PREVIEW_PANE_WIDTH, ImGui.GetContentRegionAvail().Y))) { foreach (int graphIdx in indexes) { PlottedGraph plot = DrawnPreviewGraphs[graphIdx]; float xPadding = CONSTANTS.UI.PREVIEW_PANE_X_PADDING; if (plot == null || plot.GraphNodeCount() == 0) { continue; } ImGui.TableNextRow(); ImGui.TableSetColumnIndex(0); if (DrawPreviewGraph(plot, xPadding, captionHeight, captionBackgroundcolor, out bool canHover, mainWidgetSize)) { var MainGraphs = plot.InternalProtoGraph.TraceData.GetPlottedGraphs(); HandleClickedGraph(MainGraphs[graphIdx]); } if (canHover && ImGui.IsItemHovered(ImGuiHoveredFlags.None) && !(ImGui.IsMouseDown(ImGuiMouseButton.Left))) { latestHoverGraph = plot; showToolTip = true; } } ImGui.EndTable(); } ImGui.PopStyleVar(); ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(5, 5)); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(5, 5)); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(5, 5)); ImGui.PushStyleColor(ImGuiCol.Border, 0x77999999); HoveredGraph = latestHoverGraph; bool showedCtx = HandlePreviewGraphContextMenu(); bool veryRecentPopup = showedCtx || _lastCtxMenu.AddMilliseconds(250) > DateTime.Now; if (showToolTip && !veryRecentPopup && HoveredGraph is not null) { DrawGraphTooltip(HoveredGraph); } ImGui.PopStyleVar(3); ImGui.PopStyleColor(); }