private void DrawRingEdgesAndTrack(ImDrawListPtr drawList, float percent, Vector2 position) { var size = 256; drawList.PushClipRect(position, position + new Vector2(size, size)); drawList.AddImage(RingTrackTexture.ImGuiHandle, position, position + new Vector2(size, size)); drawList.AddImage(RingBaseTexture.ImGuiHandle, position, position + new Vector2(size, size)); ImageDrawing.ImageRotated(drawList, RingEndTexture.ImGuiHandle, new Vector2(position.X + size / 2f, position.Y + size / 2f), new Vector2(RingEndTexture.Width, RingEndTexture.Height), Math.Min(percent, 1) * 0.75f * (float)Math.PI * 2); drawList.PopClipRect(); }
/// <summary> /// Places an image at position relative to the base position of the attached interface object, while being able to define what part of the image to draw. /// </summary> /// <param name="image"></param> /// <param name="size">(width, height)</param> /// <param name="position">(top, left)</param> /// <param name="imageArea">(left, top, width, height)</param> public void DrawImage(ImDrawListPtr d, TextureWrap image, Vector2 size, Vector2 position, Vector4 imageArea) { var basePosition = ImGui.GetItemRectMin(); var imageWidth = image.Width; var imageHeight = image.Height; var finalPosition = basePosition + position; d.AddImage(image.ImGuiHandle, finalPosition, finalPosition + size, finalPosition + new Vector2(imageArea.X / imageWidth, imageArea.Y / imageHeight), finalPosition + new Vector2((imageArea.X + imageArea.Z) / imageWidth, (imageArea.Y + imageArea.W) / imageHeight)); }
private void DrawExperience(ImDrawListPtr drawList, int experience, int maxExp) { int size = (int)Math.Ceiling(256 * Ui.Configuration.Scale); var drawPosition = ImGui.GetItemRectMin() + new Vector2(0, (int)HealthY); ExperienceRingBg.Draw(drawList, 1, drawPosition, 4, Ui.Configuration.Scale); ExperienceRing.Draw(drawList, experience / (float)maxExp, drawPosition, 4, Ui.Configuration.Scale); drawList.PushClipRect(drawPosition, drawPosition + new Vector2(size, size)); drawList.AddImage(RingExperienceBgTexture.ImGuiHandle, drawPosition, drawPosition + new Vector2(size, size)); drawList.PopClipRect(); int iconSize = 64; ImageDrawing.DrawIcon(Pi, drawList, (ushort)(62000 + Pi.ClientState.LocalPlayer.ClassJob.Id), new Vector2(iconSize, iconSize), new Vector2((int)(size / 2f - iconSize / 2f), (int)(size / 2f - iconSize / 2f)) + new Vector2(0, (int)HealthY)); }
/// <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); }