Exemplo n.º 1
0
        public void Draw(ShaderEditorGraph graph)
        {
            ImDrawListPtr list = ImGui.GetWindowDrawList();

            list.AddCircle(new Vector2(0.5f, 0.5f), 0.5f, 0, 8, 1.0f);
            list.AddLine(new Vector2(0.0f, 0.0f), new Vector2(10.0f, 10.0f), 1);
        }
Exemplo n.º 2
0
 public static void Draw3DLine(ImDrawListPtr drawList, Vector3 from, Vector3 to, UIViewport viewport, uint color, float thickness = 1.0f)
 {
     (Vector2 p1, Vector2 p2) = ScreenClipLine(from, to, viewport.mvp);
     if (p1 != p2)
     {
         Vector2 imageSize = viewport.size;
         drawList.AddLine(viewport.leftTop + p1 * imageSize, viewport.leftTop + p2 * imageSize, color, thickness);
     }
 }
Exemplo n.º 3
0
        private static bool SequencerAddDelButton(ImDrawListPtr draw_list, Vector2 pos, bool add = true)
        {
            var io       = ImGui.GetIO();
            var delRect  = new ImRect(pos, new Vector2(pos.X + ButtonSize, pos.Y + ButtonSize));
            var overDel  = delRect.Contains(io.MousePos);
            var delColor = overDel ? 0xFFAAAAAAu : 0x50000000u;
            var midy     = pos.Y + 16 / 2 - 0.5f;
            var midx     = pos.X + 16 / 2 - 0.5f;

            draw_list.AddRect(delRect.Min, delRect.Max, delColor, 4);
            draw_list.AddLine(new Vector2(delRect.Min.X + 3, midy), new Vector2(delRect.Max.X - 3, midy), delColor, 2);
            if (add)
            {
                draw_list.AddLine(new Vector2(midx, delRect.Min.Y + 3), new Vector2(midx, delRect.Max.Y - 3), delColor, 2);
            }

            return(overDel);
        }
Exemplo n.º 4
0
        private static void DrawPreviewZoomEnvelope(PlottedGraph plot, Vector2 subGraphPosition)
        {
            ImDrawListPtr imdp         = ImGui.GetWindowDrawList();
            float         previewBaseY = subGraphPosition.Y + EachGraphHeight;

            plot.GetPreviewVisibleRegion(new Vector2(EachGraphWidth, EachGraphHeight), PreviewProjection, out Vector2 TopLeft, out Vector2 BaseRight);

            float C1Y = previewBaseY - TopLeft.Y;
            float C2Y = previewBaseY - BaseRight.Y;

            bool verySmall = Math.Abs(C1Y - C2Y) < 20;
            uint colour    = verySmall ? Themes.GetThemeColourUINT(Themes.eThemeColour.Emphasis1) :
                             Themes.GetThemeColourUINT(Themes.eThemeColour.PreviewZoomEnvelope);

            float C1X = Math.Max(subGraphPosition.X + TopLeft.X, subGraphPosition.X);
            float C2X = Math.Min(subGraphPosition.X + BaseRight.X, subGraphPosition.X + EachGraphWidth - 1);

            C1Y = Math.Min(previewBaseY - 1, C1Y);
            C2Y = Math.Max(subGraphPosition.Y, C2Y);

            if (C1Y > subGraphPosition.Y && C1Y < previewBaseY && C2X > subGraphPosition.X)
            {
                imdp.AddLine(new Vector2(C1X, C1Y), new Vector2(C2X, C1Y), colour);
            }

            if (C2Y > subGraphPosition.Y && C2Y < previewBaseY)
            {
                imdp.AddLine(new Vector2(C2X, C2Y), new Vector2(C1X, C2Y), colour);
            }

            if (C2Y < previewBaseY && C1Y > subGraphPosition.Y)
            {
                C2Y = Math.Max(C2Y, subGraphPosition.Y);
                if (C2X > subGraphPosition.X && C2X < subGraphPosition.X + EachGraphWidth)
                {
                    imdp.AddLine(new Vector2(C2X, C1Y), new Vector2(C2X, C2Y), colour);
                }
                if (C1X > subGraphPosition.X && C1X < subGraphPosition.X + EachGraphWidth)
                {
                    imdp.AddLine(new Vector2(C1X, C2Y), new Vector2(C1X, C1Y), colour);
                }
            }
        }
Exemplo n.º 5
0
        private static void DrawLines(IReadOnlyList <Vector2> points, Vector2 location, float size)
        {
            uint          iconColor = ImGui.ColorConvertFloat4ToU32(new Vector4(1, 1, 1, 1));
            ImDrawListPtr drawList  = ImGui.GetWindowDrawList();

            for (int i = 0; i < points.Count; i += 2)
            {
                Vector2 vector1 = (points[i] / 100) * size;
                Vector2 vector2 = (points[i + 1] / 100) * size;
                drawList.AddLine(location + vector1, location + vector2, iconColor);
            }
        }
Exemplo n.º 6
0
        public static unsafe void RenderArrowsForHorizontalBar(ImDrawListPtr draw_list, Vector2 pos, Vector2 half_sz, float bar_w, float alpha)
        {
            Vector4 OuterColor = new Vector4(255f, 255f, 255f, alpha);
            Vector4 InnerColor = new Vector4(145f, 0f, 145f, alpha);

            RenderArrowPointingAt(draw_list, new Vector2(pos.X, pos.Y + half_sz.Y + 1), half_sz, ImGuiDir.Down, OuterColor);
            RenderArrowPointingAt(draw_list, new Vector2(pos.X, pos.Y + half_sz.Y), half_sz, ImGuiDir.Down, InnerColor);

            RenderArrowPointingAt(draw_list, new Vector2(pos.X, pos.Y + bar_w - 1), half_sz, ImGuiDir.Up, OuterColor);
            RenderArrowPointingAt(draw_list, new Vector2(pos.X, pos.Y + bar_w), half_sz, ImGuiDir.Up, InnerColor);

            draw_list.AddLine(new Vector2(pos.X, pos.Y + half_sz.Y + 1), new Vector2(pos.X, pos.Y + bar_w + 1), 0xffffffff);
        }
Exemplo n.º 7
0
        public static void Display()
        {
            if (ImGui.Begin("Size Demo"))
            {
                var getCursorScreenPos1st = ImGui.GetCursorScreenPos();
                var getCursorPos1st       = ImGui.GetCursorPos();
                ImGui.Columns(2, "", true);



                var getCursorStartPos = ImGui.GetCursorStartPos();
                _windowPos = ImGui.GetWindowPos();


                var getContentRegionMax   = ImGui.GetContentRegionMax();
                var getContentRegionAvail = ImGui.GetContentRegionAvail();

                var getWindowSize               = ImGui.GetWindowSize();
                var getWindowContentRegionMax   = ImGui.GetWindowContentRegionMax();
                var getWindowContentRegionMin   = ImGui.GetWindowContentRegionMin();
                var getWindowContentRegionWidth = ImGui.GetWindowContentRegionWidth();

                var getFontSize = ImGui.GetFontSize();

                var getFrameHeight            = ImGui.GetFrameHeight();
                var getFrameHeightWithSpacing = ImGui.GetFrameHeightWithSpacing();

                var getTextLineHeight            = ImGui.GetTextLineHeight();
                var getTextLineHeightWithSpacing = ImGui.GetTextLineHeightWithSpacing();

                var getColomnWidth = ImGui.GetColumnWidth();

                var getColomnOffset = ImGui.GetColumnOffset(1);

                var itemStartPos = new Vector2();


                var cursorScreenStartPos = _windowPos + getCursorStartPos;

                DoPoint("GetCursorStartPos", getCursorStartPos, FrameOfReference.Window);
                DoPoint("GetCursorPos (1st call in window)", getCursorPos1st, FrameOfReference.Window);

                DoPoint("GetWindowPos", _windowPos, FrameOfReference.Screen);
                DoPoint("GetCursorScreenPos (1st call in window)", getCursorScreenPos1st, FrameOfReference.Screen);

                DoPoint("WindowPos + CursorStartPos", _windowPos + getCursorStartPos, FrameOfReference.Screen);

                var getCursorScreenPos = ImGui.GetCursorScreenPos();
                DoPoint("GetCursorScreenPos (before this item)", getCursorScreenPos, FrameOfReference.Screen);

                var getCursorPos = ImGui.GetCursorPos();
                DoPoint("GetCursorPos (before this item)", getCursorPos, FrameOfReference.Window);


                DoRectangle("GetWindowSize", _windowPos, getWindowSize);

                var windowContentRegionStart = new Vector2(cursorScreenStartPos.X, _windowPos.Y);//this seems a bit obtuse
                DoRectangle("GetWindowContentRegionMax", windowContentRegionStart, getWindowContentRegionMax);
                DoRectangle("GetWindowContentRegionMin", cursorScreenStartPos, getWindowContentRegionMin);

                DoRectangle("GetContentRegionMax", _windowPos, getContentRegionMax);
                DoRectangle("GetContentRegionAvail", cursorScreenStartPos, getContentRegionAvail);



                itemStartPos = ImGui.GetCursorScreenPos();
                DoHLine("GetWindowContentRegionWidth", cursorScreenStartPos, getWindowContentRegionWidth);


                var colomnWidthstart = new Vector2(_windowPos.X, cursorScreenStartPos.Y);
                DoHLine("GetColomnWidth", colomnWidthstart, getColomnWidth);

                DoHLine("GetColomnOffset (colomn[1])", colomnWidthstart, getColomnOffset);

                itemStartPos = ImGui.GetCursorScreenPos();
                DoVLine("GetFontSize", itemStartPos, getFontSize);

                itemStartPos = ImGui.GetCursorScreenPos();
                DoVLine("GetTextLineHeight", itemStartPos, getTextLineHeight);

                itemStartPos = ImGui.GetCursorScreenPos();
                DoVLine("GetTextLineHeightWithSpacing", itemStartPos, getTextLineHeightWithSpacing);

                itemStartPos = ImGui.GetCursorScreenPos();
                DoVLine("GetFrameHeight", itemStartPos, getFrameHeight);

                itemStartPos = ImGui.GetCursorScreenPos();
                DoVLine("GetFrameHeightWithSpacing", itemStartPos, getFrameHeightWithSpacing);


                //we have to code the following one in full because we need to call GetItemRectSize after Imgui.Text()
                //so we can't just send it off to DoRectangle();
                itemStartPos = ImGui.GetCursorScreenPos();
                ImGui.Text("GetItemRectSize");
                var getItemRectSize = ImGui.GetItemRectSize();
                if (ImGui.IsItemHovered())
                {
                    var endRect = itemStartPos + getItemRectSize;
                    _wdl.AddRect(itemStartPos, endRect, _lineColour);
                    DrawCrosshair(itemStartPos, 3);
                }
                ImGui.NextColumn();
                ImGui.Text(getItemRectSize.ToString());
                ImGui.NextColumn();



                //we have to code the following one in full because we need to call GetItemRectSize after Imgui.Text()
                //so we can't just send it off to DoRectangle();
                itemStartPos = ImGui.GetCursorScreenPos();
                ImGui.Text("GetCursorScreenPos before & after");
                var itemEndPos = ImGui.GetCursorScreenPos();
                var height     = itemEndPos.Y - itemStartPos.Y;
                if (ImGui.IsItemHovered())
                {
                    _wdl.AddLine(itemStartPos, itemEndPos, _lineColour);
                    DrawCrosshair(itemStartPos, 3);
                }
                ImGui.NextColumn();
                ImGui.Text(height.ToString());
                ImGui.NextColumn();



                ImGui.Columns(0);
                ImGui.NewLine();
                ImGui.NewLine();
                ImGui.Text("Note: DrawList.AddRect takes two positions, not position and size");

                ImGui.End();
            }

            void DoPoint(string name, Vector2 point, FrameOfReference foR)
            {
                ImGui.Text(name);
                if (ImGui.IsItemHovered())
                {
                    if (foR == FrameOfReference.Window)
                    {
                        DrawCrosshair(_windowPos + point, 3);
                    }
                    else
                    {
                        DrawCrosshair(point, 3);
                    }
                }
                ImGui.NextColumn();
                ImGui.Text(point.ToString());
                ImGui.SameLine();
                if (foR == FrameOfReference.Window)
                {
                    ImGui.Text("Frame of Reference: Window");
                }
                else
                {
                    ImGui.Text("Frame of Reference: Screen");
                }
                ImGui.NextColumn();
            }

            void DoRectangle(string name, Vector2 start, Vector2 size)
            {
                ImGui.Text(name);
                if (ImGui.IsItemHovered())
                {
                    var endRect = start + size;
                    _wdl.AddRect(start, endRect, _lineColour);
                    DrawCrosshair(start, 3);
                }
                ImGui.NextColumn();
                ImGui.Text(size.ToString());
                ImGui.NextColumn();
            }

            void DoHLine(string name, Vector2 start, float width)
            {
                ImGui.Text(name);
                if (ImGui.IsItemHovered())
                {
                    var endPos = start;
                    endPos.X += width;
                    _wdl.AddLine(start, endPos, _lineColour);
                    DrawCrosshair(start, 3);
                }
                ImGui.NextColumn();
                ImGui.Text(width.ToString());
                ImGui.NextColumn();
            }

            void DoVLine(string name, Vector2 start, float height)
            {
                ImGui.Text(name);
                if (ImGui.IsItemHovered())
                {
                    var endPos = start;
                    endPos.Y += height;
                    _wdl.AddLine(start, endPos, _lineColour);
                    DrawCrosshair(start, 3);
                }
                ImGui.NextColumn();
                ImGui.Text(height.ToString());
                ImGui.NextColumn();
            }

            void DrawCrosshair(Vector2 atPos, float radius)
            {
                var p1 = new Vector2(atPos.X - radius, atPos.Y);
                var p2 = new Vector2(atPos.X + radius, atPos.Y);
                var p3 = new Vector2(atPos.X, atPos.Y - radius);
                var p4 = new Vector2(atPos.X, atPos.Y + radius);

                _wdl.AddLine(p1, p2, _pointColour);
                _wdl.AddLine(p3, p4, _pointColour);
            }
        }
Exemplo n.º 8
0
        private void OnLayout()
        {
            ImGui.SetNextWindowPos(Vector2.zero);
            ImGui.SetNextWindowSize(new Vector2(Screen.width, Screen.height));
            ImGui.SetNextWindowContentSize(Vector2.one * 20000f);
            ImGui.SetNextWindowFocus();
            if (ImGui.Begin("Choreographer", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoScrollbar))
            {
                ScrollPosition.x = ImGui.GetScrollX();
                ScrollPosition.y = ImGui.GetScrollY();
                if (ImGui.IsMouseDragging(ImGuiMouseButton.Right))
                {
                    ScrollPosition -= ImGui.GetMouseDragDelta(ImGuiMouseButton.Right) / ImGui.GetIO().FontGlobalScale;
                    ImGui.ResetMouseDragDelta(ImGuiMouseButton.Right);
                    ImGui.SetScrollX(ScrollPosition.x);
                    ImGui.SetScrollY(ScrollPosition.y);
                    ScrollPosition.x = ImGui.GetScrollX();
                    ScrollPosition.y = ImGui.GetScrollY();
                }

                ImDrawListPtr bgDrawList = ImGui.GetBackgroundDrawList(), fgDrawList = ImGui.GetForegroundDrawList();
                bgDrawList.AddRectFilled(Vector2.zero, new Vector2(2000f, 2000f), ColorBackground);
                for (var i = 1; i < 19; ++i)
                {
                    bgDrawList.AddLine(new Vector2(0f, i * 100f), new Vector2(2000f, i * 100f), ColorGridLineHorizontal, 1f);
                    bgDrawList.AddLine(new Vector2(i * 100f, 0f), new Vector2(i * 100f, 2000f), ColorGridLineVertical, 1f);
                }

                var imGuiStyle = ImGui.GetStyle();
                foreach (var node in Nodes)
                {
                    node.Style.Push();
                    ImGui.SetNextWindowPos(Scale(node.Pos - ScrollPosition), ImGuiCond.Always, _half);
                    ImGui.SetNextWindowSize(Scale(node.Size), ImGuiCond.Always);
                    if (ImGui.Begin(node.Name, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoScrollbar))
                    {
                        var drawList = ImGui.IsWindowFocused() | ImGui.IsWindowHovered() ? ImGui.GetForegroundDrawList() : ImGui.GetBackgroundDrawList();
                        CustomEvent.Trigger(gameObject, "OnNode", drawList, node);
                        ImGui.Columns(2, "Column", false);
                        ImGui.SetColumnWidth(0, Scale(node.LeftSize.x));
                        ImGui.SetColumnOffset(1, Scale(node.LeftSize.x));
                        ImGui.SetColumnWidth(1, Scale(node.RightSize.x));
                        for (var i = 0; i < node.RowHeights.Length; ++i)
                        {
                            if (i < node.Inputs.Length)
                            {
                                ImGui.PushID(node.Inputs[i].Id);
                                if (ImGui.Selectable(node.Inputs[i].Name, false, ReadOnly ? ImGuiSelectableFlags.Disabled : ImGuiSelectableFlags.None, Scale(new Vector2(node.LeftSize.x, node.RowHeights[i]))))
                                {
                                    CustomEvent.Trigger(gameObject, "OnInput", drawList, node.Inputs[i].Id);
                                }
                                CustomEvent.Trigger(gameObject, "OnConnection", drawList, new Vector2(ImGui.GetItemRectMin().x, (ImGui.GetItemRectMin().y + ImGui.GetItemRectMax().y) / 2f), -1, node.Inputs[i].Id, ReadOnly);
                                ImGui.PopID();
                            }

                            ImGui.NextColumn();
                            if (i < node.Outputs.Length)
                            {
                                ImGui.PushID(node.Outputs[i].Id);
                                ImGui.PushStyleVar(ImGuiStyleVar.SelectableTextAlign, new Vector2(1.0f, 0f));
                                ImGui.Unindent(imGuiStyle.ItemSpacing.x);
                                if (ImGui.Selectable(node.Outputs[i].Name, false, ReadOnly ? ImGuiSelectableFlags.Disabled : ImGuiSelectableFlags.None, Scale(new Vector2(node.RightSize.x, node.RowHeights[i]))))
                                {
                                    CustomEvent.Trigger(gameObject, "OnOutput", drawList, node.Outputs[i].Id);
                                }
                                CustomEvent.Trigger(gameObject, "OnConnection", drawList, new Vector2(ImGui.GetItemRectMax().x, (ImGui.GetItemRectMin().y + ImGui.GetItemRectMax().y) / 2f), 1, node.Outputs[i].Id, ReadOnly);
                                ImGui.Indent(imGuiStyle.ItemSpacing.x);
                                ImGui.PopStyleVar();
                                ImGui.PopID();
                            }
                            ImGui.NextColumn();
                        }
                        ImGui.Columns();
                    }
                    ImGui.End();
                    node.Style.Pop();

                    // TODO: Don't draw connections if neither node is visible? Edge Case: If the viewport is in-between the two nodes, the line should be visible.

                    foreach (var connection in node.Connections)
                    {
                        var parentNode = _nodes[connection.Parent];
                        switch (connection.Type)
                        {
                        case Connection.ConnectionType.Inherited:
                            DrawCurvedLine(fgDrawList, new Vector2(parentNode.Pos.x + parentNode.Size.x / 2f, parentNode.Pos.y - parentNode.Size.y / 2f), node.Pos - node.Size / 2f);
                            break;

                        case Connection.ConnectionType.Recursive:
                            DrawCurvedLine(fgDrawList, new Vector2(parentNode.Pos.x + parentNode.Size.x / 2f, parentNode.Pos.y + parentNode.Size.y / 2f), node.Pos + new Vector2(-node.Size.x / 2f, node.Size.y / 2f));
                            break;
                        }
                    }
                }
            }
            ImGui.End();

            if (ImGui.BeginMainMenuBar())
            {
                ImGui.Checkbox("Read Only", ref ReadOnly);
                if (ImGui.GetIO().KeyCtrl)
                {
                    ImGui.GetIO().FontGlobalScale = Mathf.Max(0.1f, Mathf.Min(2f, ImGui.GetIO().FontGlobalScale + ImGui.GetIO().MouseWheel * 0.1f));
                }
                ImGui.SliderFloat("Zoom", ref ImGui.GetIO().FontGlobalScale, 0.1f, 2f, "%.2f");
                ImGui.EndMainMenuBar();
            }

            CustomEvent.Trigger(gameObject, "OnLayout");
        }
Exemplo n.º 9
0
        internal override void Display()
        {
            if (_entityState != _state.LastClickedEntity)//If the selected entity has changed
            {
                SetEntity(_state.LastClickedEntity);
            }
            //If the player has activated the menu and there is a body that can be displayed show the menu
            if (IsActive && CanActive && ImGui.Begin("Power Display " + _entityState.Name, ref IsActive, _flags))
            {
                ImGui.Text("Current Load: ");
                ImGui.SameLine();
                ImGui.Text(_energyGenDB.Load.ToString());

                ImGui.Text("Current Output: ");
                ImGui.SameLine();

                ImGui.Text(_energyGenDB.Output.ToString() + " / " + _energyGenDB.TotalOutputMax);

                ImGui.Text("Current Demand: ");
                ImGui.SameLine();
                ImGui.Text(_energyGenDB.Demand.ToString());

                ImGui.Text("Stored: ");
                ImGui.SameLine();
                string stor = _energyGenDB.EnergyStored[_energyGenDB.EnergyType.ID].ToString();
                string max  = _energyGenDB.EnergyStoreMax[_energyGenDB.EnergyType.ID].ToString();
                ImGui.Text(stor + " / " + max);

                //

                //ImGui.PlotLines()
                var           colour1   = ImGui.GetColorU32(ImGuiCol.Text);
                var           colour2   = ImGui.GetColorU32(ImGuiCol.PlotLines);
                var           colour3   = ImGui.GetColorU32(ImGuiCol.Button);
                ImDrawListPtr draw_list = ImGui.GetWindowDrawList();

                var plotPos = ImGui.GetCursorScreenPos();
                ImGui.InvisibleButton("PowerPlot", _plotSize);


                var hg = _energyGenDB.Histogram;

                int hgFirstIdx = _energyGenDB.HistogramIndex;
                int hgLastIdx;
                if (hgFirstIdx == 0)
                {
                    hgLastIdx = hg.Count - 1;
                }
                else
                {
                    hgLastIdx = hgFirstIdx - 1;
                }

                var hgFirstObj = hg[hgFirstIdx];
                var hgLastObj  = hg[hgLastIdx];


                float xstep    = _plotSize.X / hgLastObj.seconds;
                float ystep    = (float)(_plotSize.Y / _energyGenDB.EnergyStoreMax[_energyGenDB.EnergyType.ID]);
                float posX     = 0;
                float posYBase = plotPos.Y + _plotSize.Y;
                int   index    = _energyGenDB.HistogramIndex;
                var   thisData = _energyGenDB.Histogram[index];
                float posYO    = ystep * (float)thisData.outputval;
                float posYD    = ystep * (float)thisData.demandval;
                float posYS    = ystep * (float)thisData.storval;
                //float ypos = plotPos.Y + _plotSize.Y;

                for (int i = 0; i < _energyGenDB.HistogramSize; i++)
                {
                    int idx = index + i;
                    if (idx >= _energyGenDB.HistogramSize)
                    {
                        idx -= _energyGenDB.HistogramSize;
                    }
                    thisData = _energyGenDB.Histogram[idx];

                    float nextX  = xstep * thisData.seconds;
                    float nextYO = ystep * (float)thisData.outputval;
                    float nextYD = ystep * (float)thisData.demandval;
                    float nextYS = ystep * (float)thisData.storval;
                    draw_list.AddLine(new Vector2(plotPos.X + posX, posYBase - posYO), new Vector2(plotPos.X + nextX, posYBase - nextYO), colour1);
                    draw_list.AddLine(new Vector2(plotPos.X + posX, posYBase - posYD), new Vector2(plotPos.X + nextX, posYBase - nextYD), colour2);
                    draw_list.AddLine(new Vector2(plotPos.X + posX, posYBase - posYS), new Vector2(plotPos.X + nextX, posYBase - nextYS), colour3);
                    posX  = nextX;
                    posYO = nextYO;
                    posYD = nextYD;
                    posYS = nextYS;
                }
                ImGui.End();
            }
        }