static void drawPostProcessors() { // first, we check our list of inspectors and sync it up with the current list of PostProcessors in the Scene for (var i = 0; i < Core.scene.rawPostProcessorList.length; i++) { var postProcessor = Core.scene.rawPostProcessorList.buffer[i]; if (_postProcessorInspectors.Where(inspector => inspector.postProcessor == postProcessor).Count() == 0) { _postProcessorInspectors.Add(new PostProcessorInspector(postProcessor)); } } for (var i = _postProcessorInspectors.Count - 1; i >= 0; i--) { if (!_postProcessorInspectors[i].postProcessor.isAttachedToScene) { _postProcessorInspectors.RemoveAt(i); } else { _postProcessorInspectors[i].draw(); NezImGui.smallVerticalSpace(); } } }
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 } }
public void draw() { // check to see if we are still alive if (entity.isDestroyed) { Core.getGlobalManager <ImGuiManager>().stopInspectingEntity(this); return; } if (_shouldFocusWindow) { _shouldFocusWindow = false; ImGui.SetNextWindowFocus(); ImGui.SetNextWindowCollapsed(false); } ImGui.SetNextWindowSize(new Num.Vector2(335, 400), ImGuiCond.FirstUseEver); ImGui.SetNextWindowSizeConstraints(new Num.Vector2(335, 200), new Num.Vector2(Screen.width, Screen.height)); var open = true; if (ImGui.Begin($"Entity Inspector: {entity.name}", ref open)) { var enabled = entity.enabled; if (ImGui.Checkbox("Enabled", ref enabled)) { entity.enabled = enabled; } var updateInterval = (int)entity.updateInterval; if (ImGui.SliderInt("Update Interval", ref updateInterval, 1, 100)) { entity.updateInterval = (uint)updateInterval; } var tag = entity.tag; if (ImGui.InputInt("Tag", ref tag)) { entity.tag = tag; } NezImGui.mediumVerticalSpace(); for (var i = _componentInspectors.Count - 1; i >= 0; i--) { _componentInspectors[i].draw(); NezImGui.mediumVerticalSpace(); } ImGui.End(); } if (!open) { Core.getGlobalManager <ImGuiManager>().stopInspectingEntity(this); } }
static 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)) { 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]); } var anisotropy = Core.defaultSamplerState.MaxAnisotropy; if (ImGui.InputInt("MaxAnisotropy", ref anisotropy)) { Core.defaultSamplerState.MaxAnisotropy = anisotropy; } var addressU = (int)Core.defaultSamplerState.AddressU; if (ImGui.Combo("AddressU", ref addressU, _textureAddressModes, _textureAddressModes.Length)) { Core.defaultSamplerState.AddressU = (TextureAddressMode)addressU; } var addressV = (int)Core.defaultSamplerState.AddressV; if (ImGui.Combo("AddressV", ref addressV, _textureAddressModes, _textureAddressModes.Length)) { Core.defaultSamplerState.AddressV = (TextureAddressMode)addressV; } var addressW = (int)Core.defaultSamplerState.AddressW; if (ImGui.Combo("AddressW", ref addressW, _textureAddressModes, _textureAddressModes.Length)) { Core.defaultSamplerState.AddressW = (TextureAddressMode)addressW; } } }
/// <summary> /// Draws a control disabled if a condition is met. /// Intended to draw a single ImGui control. /// </summary> public static void DrawDisabledIf(bool disabled, Action a) { if (a == null) { return; } if (disabled) { ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f); NezImGui.DisableNextWidget(); } a(); if (disabled) { ImGui.PopStyleVar(); } }
public void Draw() { // check to see if we are still alive if (Entity.IsDestroyed) { Core.GetGlobalManager <ImGuiManager>().StopInspectingEntity(this); return; } if (_shouldFocusWindow) { _shouldFocusWindow = false; ImGui.SetNextWindowFocus(); ImGui.SetNextWindowCollapsed(false); } // every 60 frames we check for newly added Components and add them if (Time.FrameCount % 60 == 0) { for (var i = 0; i < Entity.Components.Count; i++) { var component = Entity.Components[i]; if (_componentInspectors .Where(inspector => inspector.Component != null && inspector.Component == component) .Count() == 0) { _componentInspectors.Insert(0, new ComponentInspector(component)); } } } ImGui.SetNextWindowSize(new System.Numerics.Vector2(335, 400), ImGuiCond.FirstUseEver); ImGui.SetNextWindowSizeConstraints(new System.Numerics.Vector2(335, 200), new System.Numerics.Vector2(Screen.Width, Screen.Height)); var open = true; if (ImGui.Begin($"Entity Inspector: {Entity.Name}###" + _entityWindowId, ref open)) { var enabled = Entity.Enabled; if (ImGui.Checkbox("Enabled", ref enabled)) { Entity.Enabled = enabled; } ImGui.InputText("Name", ref Entity.Name, 25); var updateInterval = (int)Entity.UpdateInterval; if (ImGui.SliderInt("Update Interval", ref updateInterval, 1, 100)) { Entity.UpdateInterval = (uint)updateInterval; } var tag = Entity.Tag; if (ImGui.InputInt("Tag", ref tag)) { Entity.Tag = tag; } NezImGui.MediumVerticalSpace(); _transformInspector.Draw(); NezImGui.MediumVerticalSpace(); // watch out for removed Components for (var i = _componentInspectors.Count - 1; i >= 0; i--) { if (_componentInspectors[i].Entity == null) { _componentInspectors.RemoveAt(i); continue; } _componentInspectors[i].Draw(); NezImGui.MediumVerticalSpace(); } if (NezImGui.CenteredButton("Add Component", 0.6f)) { _componentNameFilter = ""; ImGui.OpenPopup("component-selector"); } DrawComponentSelectorPopup(); ImGui.End(); } if (!open) { Core.GetGlobalManager <ImGuiManager>().StopInspectingEntity(this); } }
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(); } }
void DrawLeftPane() { Origin OriginIndex(Vector2 origin) { switch (origin) { case Vector2 o when o.X == 0 && o.Y == 0: // tl return(Origin.TopLeft); case Vector2 o when o.X == 0.5f && o.Y == 0: // t return(Origin.Top); case Vector2 o when o.X == 1 && o.Y == 0: // tr return(Origin.TopRight); case Vector2 o when o.X == 0 && o.Y == 0.5f: // l return(Origin.Left); case Vector2 o when o.X == 0.5f && o.Y == 0.5f: // center return(Origin.Center); case Vector2 o when o.X == 1 && o.Y == 0.5f: // right return(Origin.Right); case Vector2 o when o.X == 0 && o.Y == 1: // bl return(Origin.BottomLeft); case Vector2 o when o.X == 0.5f && o.Y == 1: // b return(Origin.Bottom); case Vector2 o when o.X == 1 && o.Y == 1: // br return(Origin.BottomRight); default: return(Origin.Custom); } } Vector2 OriginValue(Origin origin, Vector2 currentOrigin) { switch (origin) { case Origin.TopLeft: return(new Vector2(0, 0)); case Origin.Top: return(new Vector2(0.5f, 0)); case Origin.TopRight: return(new Vector2(1, 0)); case Origin.Left: return(new Vector2(0, 0.5f)); case Origin.Center: return(new Vector2(0.5f, 0.5f)); case Origin.Right: return(new Vector2(1, 0.5f)); case Origin.BottomLeft: return(new Vector2(0, 1)); case Origin.Bottom: return(new Vector2(0.5f, 1)); case Origin.BottomRight: return(new Vector2(1, 1)); default: return(currentOrigin + new Vector2(0.01f, 0.01f)); } } if (NezImGui.CenteredButton("Set All Origins", 0.75f)) { _globalOriginEnumValue = 7; ImGui.OpenPopup("set-all-origins"); } NezImGui.MediumVerticalSpace(); if (ImGui.BeginPopup("set-all-origins")) { ImGui.Combo("###global-origin", ref _globalOriginEnumValue, _originEnumNames, _originEnumNames.Length); if (ImGui.Button("Set All Origins")) { for (var i = 0; i < _atlasData.Origins.Count; i++) { _atlasData.Origins[i] = OriginValue((Origin)_globalOriginEnumValue, _atlasData.Origins[i]); } ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } for (var i = 0; i < _atlasData.Origins.Count; i++) { ImGui.PushID(i); var name = _atlasData.Names[i]; if (ImGui.InputText("Name", ref name, 25)) { _atlasData.Names[i] = name; } var origin = _atlasData.Origins[i].ToNumerics(); if (ImGui.SliderFloat2("Origin", ref origin, 0f, 1f)) { _atlasData.Origins[i] = origin.ToXNA(); } var originEnum = OriginIndex(_atlasData.Origins[i]); var originEnumValue = (int)originEnum; if (ImGui.Combo($"###enum_{i}", ref originEnumValue, _originEnumNames, _originEnumNames.Length)) { _atlasData.Origins[i] = OriginValue((Origin)originEnumValue, _atlasData.Origins[i]); } ImGui.Separator(); ImGui.PopID(); } }