コード例 #1
0
        private void LoadTextureIcon(NodeBase node)
        {
            if (((STGenericTexture)node.Tag).RenderableTex == null)
            {
                ((STGenericTexture)node.Tag).LoadRenderableTexture();
            }

            //Render textures loaded in GL as an icon
            if (((STGenericTexture)node.Tag).RenderableTex != null)
            {
                var tex = ((STGenericTexture)node.Tag);
                //Turn the texture to a cached icon
                IconManager.LoadTexture(node.Header, tex);
                ImGui.SameLine();
            }
        }
コード例 #2
0
        static void DrawBackground(ShaderProgram shader)
        {
            var backgroundTexture = IconManager.GetTextureIcon("CHECKERBOARD");

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, backgroundTexture);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            shader.SetInt("backgroundTexture", 1);

            shader.SetVector2("scale", new Vector2(30));
            shader.SetVector2("texCoordScale", new Vector2(30));

            shader.SetVector4("uColor", new Vector4(1));

            //Draw background
            vao.Enable(shader);
            vao.Use();
            GL.DrawArrays(PrimitiveType.TriangleStrip, 0, Length);
        }
コード例 #3
0
        public void DrawNode(NodeBase node, float itemHeight)
        {
            bool HasText = node.Header != null &&
                           node.Header.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0;

            char icon = IconManager.FOLDER_ICON;

            if (node.Children.Count == 0)
            {
                icon = IconManager.FILE_ICON;
            }
            if (node.Tag is STGenericMesh)
            {
                icon = IconManager.MESH_ICON;
            }
            if (node.Tag is STGenericModel)
            {
                icon = IconManager.MODEL_ICON;
            }

            ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags.None;

            flags |= ImGuiTreeNodeFlags.SpanFullWidth;

            if (node.Children.Count == 0 || isSearch)
            {
                flags |= ImGuiTreeNodeFlags.Leaf;
            }
            else
            {
                flags |= ImGuiTreeNodeFlags.OpenOnDoubleClick;
                flags |= ImGuiTreeNodeFlags.OpenOnArrow;
            }

            if (node.IsExpanded && !isSearch)
            {
                flags |= ImGuiTreeNodeFlags.DefaultOpen;
            }

            //Node was selected manually outside the outliner so update the list
            if (node.IsSelected && !SelectedNodes.Contains(node))
            {
                SelectedNodes.Add(node);
            }

            //Node was deselected manually outside the outliner so update the list
            if (!node.IsSelected && SelectedNodes.Contains(node))
            {
                SelectedNodes.Remove(node);
            }

            if (SelectedNodes.Contains(node))
            {
                flags |= ImGuiTreeNodeFlags.Selected;
            }

            if (isSearch && HasText || !isSearch)
            {
                //Add active file format styling. This determines what file to save.
                //For files inside archives, it gets the parent of the file format to save.
                bool isActiveFile = false;
                isActiveFile = ActiveFileFormat == node.Tag;

                bool isRenaming = node == renameNode && isNameEditing && node.Tag is IRenamableNode;

                //Improve tree node spacing.
                var spacing = ImGui.GetStyle().ItemSpacing;
                ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(spacing.X, 1));

                //Make the active file noticable
                if (isActiveFile)
                {
                    ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.834f, 0.941f, 1.000f, 1.000f));
                }

                //Align the text to improve selection sizing.
                ImGui.AlignTextToFramePadding();

                //Disable selection view in renaming handler to make text more clear
                if (isRenaming)
                {
                    flags &= ~ImGuiTreeNodeFlags.Selected;
                    flags &= ~ImGuiTreeNodeFlags.SpanFullWidth;
                }

                //Load the expander or selection
                if (isSearch)
                {
                    ImGui.Selectable(node.ID, flags.HasFlag(ImGuiTreeNodeFlags.Selected));
                }
                else
                {
                    node.IsExpanded = ImGui.TreeNodeEx(node.ID, flags, $"");
                }

                ImGui.SameLine(); ImGuiHelper.IncrementCursorPosX(3);

                bool leftClicked         = ImGui.IsItemClicked(ImGuiMouseButton.Left);
                bool rightClicked        = ImGui.IsItemClicked(ImGuiMouseButton.Right);
                bool nodeFocused         = ImGui.IsItemFocused();
                bool isToggleOpened      = ImGui.IsItemToggledOpen();
                bool beginDragDropSource = !isRenaming && node.Tag is IDragDropNode && ImGui.BeginDragDropSource();

                if (beginDragDropSource)
                {
                    //Placeholder pointer data. Instead use drag/drop nodes from GetDragDropNode()
                    GCHandle handle1 = GCHandle.Alloc(node.ID);
                    ImGui.SetDragDropPayload("OUTLINER_ITEM", (IntPtr)handle1, sizeof(int), ImGuiCond.Once);
                    handle1.Free();

                    dragDroppedNode = node;

                    //Display icon for texture types
                    if (node.Tag is STGenericTexture)
                    {
                        LoadTextureIcon(node);
                    }

                    //Display text for item being dragged
                    ImGui.Button($"{node.Header}");
                    ImGui.EndDragDropSource();
                }

                bool hasContextMenu = node is IContextMenu || node is IExportReplaceNode || node.Tag is ICheckableNode ||
                                      node.Tag is IContextMenu || node.Tag is IExportReplaceNode ||
                                      node.Tag is STGenericTexture;

                //Apply a pop up menu for context items. Only do this if the menu has possible items used
                if (hasContextMenu && SelectedNodes.Contains(node))
                {
                    ImGui.PushID(node.Header);
                    if (ImGui.BeginPopupContextItem("##OUTLINER_POPUP", ImGuiPopupFlags.MouseButtonRight))
                    {
                        SetupRightClickMenu(node);
                        ImGui.EndPopup();
                    }
                    ImGui.PopID();
                }

                if (node.HasCheckBox)
                {
                    ImGui.SetItemAllowOverlap();

                    ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(2, 2));

                    bool check = node.IsChecked;

                    if (ImGui.Checkbox($"##check{node.ID}", ref check))
                    {
                        foreach (var n in SelectedNodes)
                        {
                            n.IsChecked = check;
                        }
                    }
                    ImGui.PopStyleVar();

                    ImGui.SameLine(); ImGuiHelper.IncrementCursorPosX(3);
                }

                //Load the icon
                if (node.Tag is STGenericTexture)
                {
                    LoadTextureIcon(node);
                }
                else
                {
                    IconManager.DrawIcon(icon);
                    ImGui.SameLine(); ImGuiHelper.IncrementCursorPosX(3);
                }

                ImGui.AlignTextToFramePadding();

                //if (node.Tag is ICheckableNode)
                //  ImGuiHelper.IncrementCursorPosY(-2);

                if (!isRenaming)
                {
                    ImGui.Text(node.Header);
                }
                else
                {
                    var renamable = node.Tag as IRenamableNode;

                    var bg = ImGui.GetStyle().Colors[(int)ImGuiCol.WindowBg];

                    //Make the textbox frame background blend with the tree background
                    //This is so we don't see the highlight color and can see text clearly
                    ImGui.PushStyleColor(ImGuiCol.FrameBg, bg);
                    ImGui.PushStyleColor(ImGuiCol.Border, new Vector4(1, 1, 1, 1));
                    ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1);

                    var length = ImGui.CalcTextSize(renameText).X + 20;
                    ImGui.PushItemWidth(length);

                    if (ImGui.InputText("##RENAME_NODE", ref renameText, 512,
                                        ImGuiInputTextFlags.EnterReturnsTrue | ImGuiInputTextFlags.CallbackCompletion |
                                        ImGuiInputTextFlags.CallbackHistory | ImGuiInputTextFlags.NoHorizontalScroll))
                    {
                        renamable.Renamed(renameText);
                        node.Header = renameText;

                        isNameEditing = false;
                    }
                    if (!ImGui.IsItemHovered() && ImGui.IsMouseClicked(ImGuiMouseButton.Left))
                    {
                        isNameEditing = false;
                    }

                    ImGui.PopItemWidth();
                    ImGui.PopStyleVar();
                    ImGui.PopStyleColor(2);
                }
                ImGui.PopStyleVar();

                if (isActiveFile)
                {
                    ImGui.PopStyleColor();
                }

                if (!isRenaming)
                {
                    //Check for rename selection on selected renamable node
                    if (node.IsSelected && node.Tag is IRenamableNode && RENAME_ENABLE)
                    {
                        bool renameStarting = renameClickTime != 0;
                        bool wasCancelled   = false;

                        //Mouse click before editing started cancels the event
                        if (renameStarting && leftClicked)
                        {
                            renameClickTime = 0;
                            renameStarting  = false;
                            wasCancelled    = true;
                        }

                        //Check for delay
                        if (renameStarting)
                        {
                            //Create a delay between actions. This can be cancelled out during a mouse click
                            var diff = ImGui.GetTime() - renameClickTime;
                            if (diff > RENAME_DELAY_TIME)
                            {
                                //Name edit executed. Setup data for renaming.
                                isNameEditing = true;
                                renameNode    = node;
                                renameText    = ((IRenamableNode)node.Tag).GetRenameText();
                                //Reset the time
                                renameClickTime = 0;
                            }
                        }

                        //User has started a rename click. Start a time check
                        if (leftClicked && renameClickTime == 0 && !wasCancelled)
                        {
                            //Do a small delay for the rename event
                            renameClickTime = ImGui.GetTime();
                        }
                    }

                    //Click event executed on item
                    if ((leftClicked || rightClicked) && !isToggleOpened) //Prevent selection change on toggle
                    {
                        //Reset all selection unless shift/control held down
                        if (!ImGui.GetIO().KeyCtrl&& !ImGui.GetIO().KeyShift)
                        {
                            foreach (var n in SelectedNodes)
                            {
                                n.IsSelected = false;
                            }
                            SelectedNodes.Clear();
                        }

                        //Check selection range
                        if (ImGui.GetIO().KeyShift)
                        {
                            SelectedRangeIndex = node.DisplayIndex;
                            SelectRange        = true;
                        }
                        else
                        {
                            SelectedIndex = node.DisplayIndex;
                        }

                        //Add the clicked node to selection.
                        SelectedNodes.Add(node);
                        node.IsSelected = true;
                    }
                    else if (nodeFocused && !isToggleOpened && !node.IsSelected)
                    {
                        if (!ImGui.GetIO().KeyCtrl&& !ImGui.GetIO().KeyShift)
                        {
                            foreach (var n in SelectedNodes)
                            {
                                n.IsSelected = false;
                            }
                            SelectedNodes.Clear();
                        }

                        //Add the clicked node to selection.
                        SelectedNodes.Add(node);
                        node.IsSelected = true;
                    }

                    if (leftClicked && node.IsSelected)
                    {
                        if (node is ArchiveHiearchy && node.Tag == null)
                        {
                            var archiveWrapper = (ArchiveHiearchy)node;
                            archiveWrapper.OpenFileFormat();
                            archiveWrapper.IsExpanded = true;
                        }
                    }

                    //Update the active file format when selected. (updates dockspace layout and file menus)
                    if (node.Tag is IFileFormat && node.IsSelected)
                    {
                        if (ActiveFileFormat != node.Tag)
                        {
                            ActiveFileFormat = (IFileFormat)node.Tag;
                        }
                    }
                    else if (node.IsSelected && node.Parent != null)
                    {
                    }
                }
            }

            if (isSearch || node.IsExpanded)
            {
                //Todo find a better alternative to clip parents
                //Clip only the last level
                if (ClipNodes && node.Children.Count > 0 && node.Children[0].Children.Count == 0)
                {
                    var children = node.Children.ToList();
                    if (isSearch)
                    {
                        children = GetSearchableNodes(children);
                    }

                    var clipper = new ImGuiListClipper2(children.Count, itemHeight);
                    clipper.ItemsCount = children.Count;

                    for (int line_i = clipper.DisplayStart; line_i < clipper.DisplayEnd; line_i++) // display only visible items
                    {
                        DrawNode(children[line_i], itemHeight);
                    }
                }
                else
                {
                    foreach (var child in node.Children)
                    {
                        DrawNode(child, itemHeight);
                    }
                }

                if (!isSearch)
                {
                    ImGui.TreePop();
                }
            }
        }
コード例 #4
0
        public void Render(STGenericTexture texture)
        {
            if (ImageCanvas == null)
            {
                Init();
            }

            var size = ImGui.GetWindowSize();

            ActiveTexture = texture;

            var menuSize           = new Vector2(22, 22);
            var propertyWindowSize = new Vector2(size.X, size.Y / 2 - 20);
            var canvasWindowSize   = new Vector2(size.X, size.Y / 2 - 20);

            if (ImGui.BeginChild("##IMAGE_TABMENU", propertyWindowSize, true))
            {
                ImGui.BeginTabBar("image_menu");
                if (ImguiCustomWidgets.BeginTab("image_menu", "Properties"))
                {
                    ImGuiHelper.LoadProperties(ActiveTexture.DisplayProperties, ActiveTexture.DisplayPropertiesChanged);
                    ImGui.EndTabItem();
                }
                if (ImguiCustomWidgets.BeginTab("image_menu", "Channels"))
                {
                    ImGui.EndTabItem();
                }
                if (ImguiCustomWidgets.BeginTab("image_menu", "User Data"))
                {
                    ImGui.EndTabItem();
                }
                ImGui.EndTabBar();
            }
            ImGui.EndChild();

            if (ImGui.BeginChild("CANVAS_WINDOW", canvasWindowSize, false,
                                 ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.MenuBar))
            {
                if (ImGui.BeginMenuBar())
                {
                    if (ImGui.BeginMenu("File"))
                    {
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("Edit"))
                    {
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("View"))
                    {
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("Image"))
                    {
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("Adjustments"))
                    {
                        ImGui.EndMenu();
                    }
                    ImGui.PushItemWidth(150);
                    if (ImGui.BeginCombo("##imageCB", selectedBackground))
                    {
                        if (ImGui.Selectable("Checkerboard"))
                        {
                            selectedBackground = "Checkerboard";
                        }
                        ;
                        if (ImGui.Selectable("Black"))
                        {
                            selectedBackground = "Black";
                        }
                        ;
                        if (ImGui.Selectable("White"))
                        {
                            selectedBackground = "White";
                        }
                        ;
                        if (ImGui.Selectable("Custom"))
                        {
                            selectedBackground = "White";
                        }
                        ;

                        ImGui.EndMenu();
                    }
                    ImGui.PopItemWidth();

                    ImGui.EndMenuBar();
                }

                //Make icon buttons invisible aside from the icon itself.
                ImGui.PushStyleColor(ImGuiCol.Button, new Vector4());
                {
                    //Draw icon bar
                    ImGui.ImageButton((IntPtr)IconManager.GetTextureIcon("SAVE_BUTTON"), menuSize);
                    ImGui.SameLine();
                    ImGui.ImageButton((IntPtr)IconManager.GetTextureIcon("IMG_EDIT_BUTTON"), menuSize);
                    ImGui.SameLine();
                    ImguiCustomWidgets.ImageButtonToggle(
                        IconManager.GetTextureIcon("IMG_ALPHA_BUTTON"),
                        IconManager.GetTextureIcon("IMG_NOALPHA_BUTTON"), ref DisplayAlpha, menuSize);
                }
                ImGui.PopStyleColor();

                //Draw the array and mip level counter buttons
                ImGui.AlignTextToFramePadding();
                ImGui.Text("Array Level " + $"{currentArrayLevel} / {texture.ArrayCount - 1}");
                ImGui.SameLine();
                if (ImGui.Button("<", menuSize))
                {
                    AdjustArrayLevel(-1);
                }
                ImGui.SameLine();
                if (ImGui.Button(">", menuSize))
                {
                    AdjustArrayLevel(1);
                }
                ImGui.SameLine();

                ImGui.Text("Mip Level " + $"{currentMipLevel} / {texture.MipCount - 1}");
                ImGui.SameLine();
                if (ImGui.Button("<", menuSize))
                {
                    AdjustMipLevel(-1);
                }
                ImGui.SameLine();
                if (ImGui.Button(">", menuSize))
                {
                    AdjustMipLevel(1);
                }

                //Draw the main image canvas
                DrawImageCanvas(canvasWindowSize);
            }
            ImGui.EndChild();

            /*   if (ImGui.BeginMenuBar())
             * {
             *
             * }*/
        }