コード例 #1
0
        void DrawSettings()
        {
            _frameRateArray[_frameRateArrayIndex] = ImGui.GetIO().Framerate;
            _frameRateArrayIndex = (_frameRateArrayIndex + 1) % _frameRateArray.Length;

            ImGui.PlotLines("##hidelabel", ref _frameRateArray[0], _frameRateArray.Length, _frameRateArrayIndex, $"FPS: {ImGui.GetIO().Framerate:0}", 0, 60, new Num.Vector2(ImGui.GetContentRegionAvail().X, 50));

            NezImGui.SmallVerticalSpace();

            if (ImGui.CollapsingHeader("Core Settings", ImGuiTreeNodeFlags.DefaultOpen))
            {
                ImGui.Checkbox("exitOnEscapeKeypress", ref Core.ExitOnEscapeKeypress);
                ImGui.Checkbox("pauseOnFocusLost", ref Core.PauseOnFocusLost);
                ImGui.Checkbox("debugRenderEnabled", ref Core.DebugRenderEnabled);
            }

            if (ImGui.CollapsingHeader("Core.defaultSamplerState", ImGuiTreeNodeFlags.DefaultOpen))
            {
                #if !FNA
                ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f);
                NezImGui.DisableNextWidget();
                #endif

                var currentTextureFilter = (int)Core.DefaultSamplerState.Filter;
                if (ImGui.Combo("Filter", ref currentTextureFilter, _textureFilters, _textureFilters.Length))
                {
                    Core.DefaultSamplerState.Filter = (TextureFilter)Enum.Parse(typeof(TextureFilter), _textureFilters[currentTextureFilter]);
                }

                #if !FNA
                ImGui.PopStyleVar();
                #endif
            }
        }
コード例 #2
0
ファイル: SpriteAtlasEditorWindow.cs プロジェクト: foxnne/Nez
        void DrawRightPane()
        {
            if (!_atlasAllowsAnimationEditing)
            {
                ImGui.PushStyleColor(ImGuiCol.Text, Color.Red.PackedValue);
                ImGui.TextWrapped("Edit/Add animations at your own risk! The loaded atlas either does not have contiguous frames or contains animations that are not contiguous.");
                ImGui.PopStyleColor();
                NezImGui.MediumVerticalSpace();
            }

            if (NezImGui.CenteredButton("Add Animation", 0.5f))
            {
                ImGui.OpenPopup("add-animation");
            }

            NezImGui.MediumVerticalSpace();

            for (var i = 0; i < _atlasData.AnimationNames.Count; i++)
            {
                var isEditable = !_nonEditableAnimations.Contains(i);
                ImGui.PushID(i);
                var didNotDeleteAnimation = true;
                if (ImGui.CollapsingHeader(_atlasData.AnimationNames[i] + $"###anim{i}", ref didNotDeleteAnimation))
                {
                    var name = _atlasData.AnimationNames[i];
                    if (ImGui.InputText("Name", ref name, 25))
                    {
                        _atlasData.AnimationNames[i] = name;
                    }

                    var fps = _atlasData.Framerates[i];
                    if (ImGui.SliderInt("Frame Rate", ref fps, 0, 24))
                    {
                        _atlasData.Framerates[i] = fps;
                    }


                    var frames = _atlasData.AnimationFrames[i];
                    if (isEditable)
                    {
                        if (frames.Count == 0)
                        {
                            _startEndInt.Start = _startEndInt.End = 0;
                        }
                        else if (frames.Count == 1)
                        {
                            _startEndInt.Start = frames[0];
                            _startEndInt.End   = frames[0];
                        }
                        else
                        {
                            _startEndInt.Start = frames[0];
                            _startEndInt.End   = frames.LastItem();
                        }

                        var framesChanged = ImGui.SliderInt("Start Frame", ref _startEndInt.Start, 0, _startEndInt.End);
                        framesChanged |= ImGui.SliderInt("End Frame", ref _startEndInt.End, _startEndInt.Start, _atlasData.SourceRects.Count - 1);

                        if (framesChanged)
                        {
                            frames.Clear();
                            for (var j = _startEndInt.Start; j <= _startEndInt.End; j++)
                            {
                                frames.Add(j);
                            }
                        }
                    }

                    if (frames.Count > 0)
                    {
                        var secondsPerFrame   = 1 / (float)fps;
                        var iterationDuration = secondsPerFrame * (float)frames.Count;
                        var currentElapsed    = Time.TotalTime % iterationDuration;
                        var desiredFrame      = Mathf.FloorToInt(currentElapsed / secondsPerFrame);

                        var rect = _atlasData.SourceRects[frames[desiredFrame]];
                        var uv0  = rect.Location.ToNumerics() / _textureSize;
                        var uv1  = rect.GetSize().ToNumerics() / _textureSize;

                        var size = CalcBestFitRegion(new Num.Vector2(_animationPreviewSize), rect.GetSize().ToNumerics());
                        ImGui.SetCursorPosX((ImGui.GetWindowContentRegionWidth() - size.X) / 2f);
                        ImGui.Image(_texturePtr, size, uv0, uv0 + uv1);
                    }

                    NezImGui.SmallVerticalSpace();
                }

                if (!didNotDeleteAnimation)
                {
                    _atlasData.AnimationNames.RemoveAt(i);
                    _atlasData.AnimationFrames.RemoveAt(i);
                    _atlasData.Framerates.RemoveAt(i);
                    break;
                }
                ImGui.PopID();
            }

            NezImGui.SmallVerticalSpace();
            ImGui.SliderInt("Preview Size", ref _animationPreviewSize, 50, 150);

            if (ImGui.BeginPopup("add-animation"))
            {
                ImGui.Text("Animation Name");
                ImGui.InputText("##animationName", ref _stringBuffer, 25);

                if (ImGui.Button("Cancel"))
                {
                    _stringBuffer = "";
                    ImGui.CloseCurrentPopup();
                }

                ImGui.SameLine(ImGui.GetContentRegionAvail().X - ImGui.GetItemRectSize().X);

                ImGui.PushStyleColor(ImGuiCol.Button, Color.Green.PackedValue);
                if (ImGui.Button("Create"))
                {
                    _stringBuffer = _stringBuffer.Length > 0 ? _stringBuffer : Utils.RandomString(8);
                    _atlasData.AnimationNames.Add(_stringBuffer);
                    _atlasData.Framerates.Add(8);
                    _atlasData.AnimationFrames.Add(new List <int>());

                    _stringBuffer = "";
                    ImGui.CloseCurrentPopup();
                }
                ImGui.PopStyleColor();

                ImGui.EndPopup();
            }
        }