public static string GetDragDropPayload() { ImGuiPayloadPtr ptr = ImGui.GetDragDropPayload(); string str = Marshal.PtrToStringUni(ptr.Data); ptr.Clear(); return(str); }
unsafe void OnFunctionDragDrop(INodeGraph bp) { ImGuiPayloadPtr pPayload = ImGui.AcceptDragDropPayload("FUNCTION_DRAG"); if (pPayload.NativePtr != null) { int fucntionID = *(int *)pPayload.Data; CreateFunctionCallNode(bp, fucntionID); } }
public static unsafe string AcceptDragDropPayload(string type) { ImGuiPayloadPtr payload = ImGui.AcceptDragDropPayload(type); if (payload.NativePtr != null) { string str = Marshal.PtrToStringUni(payload.Data); payload.Clear(); return(str); } return(null); }
unsafe void OnVarDragDrop(INodeGraph bp) { ImGuiPayloadPtr pPayload = ImGui.AcceptDragDropPayload("VAR_DRAG"); if (pPayload.NativePtr == null) { return; } int varID = *(int *)pPayload.Data; m_PopupVarGetSet.Show(varID, OnSelectVarGetSet); Logger.Info("Var Drop. ID:" + varID); }
private void DrawViewport() { var size = ImGui.GetWindowSize(); if (Pipeline.Width != (int)size.X || Pipeline.Height != (int)size.Y) { Pipeline.Width = (int)size.X; Pipeline.Height = (int)size.Y; Pipeline.OnResize(); } Pipeline.RenderScene(); if ((ImGui.IsWindowFocused() && _mouseDown) || ImGui.IsWindowFocused() && ImGui.IsWindowHovered() || _mouseDown) { if (!onEnter) { Pipeline.ResetPrevious(); onEnter = true; } //Only update scene when necessary if (ImGuiController.ApplicationHasFocus) { UpdateCamera(); } } else { onEnter = false; //Reset drag/dropped model data if mouse leaves the viewport during a drag event if (DragDroppedModel != null) { DragDroppedModel.DragDroppedOnLeave(); DragDroppedModel = null; } } var id = Pipeline.GetViewportTexture(); ImGui.Image((IntPtr)id, size, new System.Numerics.Vector2(0, 1), new System.Numerics.Vector2(1, 0)); if (ImGui.BeginDragDropTarget()) { ImGuiPayloadPtr outlinerDrop = ImGui.AcceptDragDropPayload("OUTLINER_ITEM", ImGuiDragDropFlags.AcceptNoDrawDefaultRect | ImGuiDragDropFlags.AcceptBeforeDelivery); if (outlinerDrop.IsValid()) { //Drag/drop things onto meshes var mouseInfo = CreateMouseState(); var picked = Pipeline.GetPickedObject(mouseInfo); //Picking object changed. if (DragDroppedModel != picked) { //Set exit drop event for previous model if (DragDroppedModel != null) { DragDroppedModel.DragDroppedOnLeave(); } DragDroppedModel = picked; //Model has changed so call the enter event if (picked != null) { picked.DragDroppedOnEnter(); } } if (picked != null) { //Set the drag/drop event var node = Outliner.GetDragDropNode(); picked.DragDropped(node.Tag); } if (mouseInfo.LeftButton == ButtonState.Released) { DragDroppedModel = null; } } ImGui.EndDragDropTarget(); } }
public static unsafe bool IsValid(this ImGuiPayloadPtr payload) { return(payload.NativePtr != null); }
private void AnimationFrameEditor(Dictionary <string, SpriteAnimationData> anims) { AnimatedSprite currentFileContext = _currentAsset !.Content !; SpriteAnimationData selAnim = anims[_selectedAnimation]; ImGui.BeginChild("Animation", new Vector2(-1, -1), true); ImGui.Text("Frames: (Drag and Drop to rearrange)"); SpriteAnimationFrameSource frameSource = currentFileContext.FrameSource; _draggedFrame = EditorHelpers.DragAndDropList(selAnim.FrameIndices, _draggedFrame, true); if (selAnim.FrameIndices.Length == 0) { EditorHelpers.ButtonSizedHole(""); } ImGui.PushItemWidth(150); if (ImGui.InputInt("", ref _addFrameInput)) { _addFrameInput = Maths.Clamp(_addFrameInput, 0, frameSource.GetFrameCount() - 1); } ImGui.SameLine(); if (ImGui.Button("Add Frame")) { selAnim.FrameIndices = selAnim.FrameIndices.AddToArray(_addFrameInput); if (_addFrameInput < frameSource.GetFrameCount() - 2) { _addFrameInput++; } _controller.Reset(); UnsavedChanges(); } ImGui.SameLine(); ImGui.Button("Remove (Drop Here)"); if (ImGui.BeginDragDropTarget()) { ImGuiPayloadPtr dataPtr = ImGui.AcceptDragDropPayload("UNUSED"); unsafe { if ((IntPtr)dataPtr.NativePtr != IntPtr.Zero && dataPtr.IsDelivery()) { int[] indices = selAnim.FrameIndices; for (int i = _draggedFrame; i < indices.Length - 1; i++) { indices[i] = indices[i + 1]; } Array.Resize(ref selAnim.FrameIndices, selAnim.FrameIndices.Length - 1); _controller.Reset(); _draggedFrame = -1; UnsavedChanges(); } } ImGui.EndDragDropTarget(); } ImGui.PushItemWidth(150); ImGui.Text("Duration"); ImGui.SameLine(); if (ImGui.InputInt("###DurInput", ref selAnim.TimeBetweenFrames)) { _controller.Reset(); UnsavedChanges(); } ImGui.SameLine(); if (selAnim.FrameIndices.Length > 0) { ImGui.Text($"Total Duration: {selAnim.TimeBetweenFrames * selAnim.FrameIndices.Length}"); } var loopType = (int)selAnim.LoopType; if (ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType))))) { selAnim.LoopType = (AnimationLoopType)loopType; _controller.Reset(); UnsavedChanges(); } }
public void Render() { //Menu if (ImGui.BeginMenuBar()) { if (ImGui.BeginMenu("View Setting")) { if (ImGui.BeginMenu("Background")) { ImGui.Checkbox("Display", ref DrawableBackground.Display); ImGui.ColorEdit3("Color Top", ref DrawableBackground.BackgroundTop); ImGui.ColorEdit3("Color Bottom", ref DrawableBackground.BackgroundBottom); ImGui.EndMenu(); } if (ImGui.BeginMenu("Grid")) { ImGui.Checkbox("Display", ref DrawableFloor.Display); ImGui.ColorEdit4("Grid Color", ref DrawableFloor.GridColor); ImGui.InputInt("Grid Cell Count", ref Toolbox.Core.Runtime.GridSettings.CellAmount); ImGui.InputFloat("Grid Cell Size", ref Toolbox.Core.Runtime.GridSettings.CellSize); ImGui.EndMenu(); } // ImGui.Checkbox("VSync", ref Toolbox.Core.Runtime.EnableVSync); ImGui.Checkbox("Wireframe", ref Toolbox.Core.Runtime.RenderSettings.Wireframe); ImGui.Checkbox("WireframeOverlay", ref Toolbox.Core.Runtime.RenderSettings.WireframeOverlay); ImGui.EndMenu(); } if (ImGui.BeginMenu($"Shading [{Runtime.DebugRendering}]")) { foreach (var mode in Enum.GetValues(typeof(Runtime.DebugRender))) { bool isSelected = (Runtime.DebugRender)mode == Runtime.DebugRendering; if (ImGui.Selectable(mode.ToString(), isSelected)) { Runtime.DebugRendering = (Runtime.DebugRender)mode; } if (isSelected) { ImGui.SetItemDefaultFocus(); } } ImGui.EndMenu(); } if (ImGui.BeginMenu("Camera")) { if (ImGui.Button("Reset Transform")) { Pipeline._context.Camera.TargetPosition = new OpenTK.Vector3(0, 1, -5); Pipeline._context.Camera.RotationX = 0; Pipeline._context.Camera.RotationY = 0; Pipeline._context.Camera.UpdateMatrices(); } ImGuiHelper.InputFromBoolean("Orthographic", Pipeline._context.Camera, "IsOrthographic"); ImGuiHelper.InputFromFloat("Fov (Degrees)", Pipeline._context.Camera, "FovDegrees", true, 1f); if (Pipeline._context.Camera.FovDegrees != 45) { ImGui.SameLine(); if (ImGui.Button("Reset")) { Pipeline._context.Camera.FovDegrees = 45; } } ImGuiHelper.InputFromFloat("ZFar", Pipeline._context.Camera, "ZFar", true, 1f); if (Pipeline._context.Camera.ZFar != 100000.0f) { ImGui.SameLine(); if (ImGui.Button("Reset")) { Pipeline._context.Camera.ZFar = 100000.0f; } } ImGuiHelper.InputFromFloat("ZNear", Pipeline._context.Camera, "ZNear", true, 0.1f); if (Pipeline._context.Camera.ZNear != 0.1f) { ImGui.SameLine(); if (ImGui.Button("Reset")) { Pipeline._context.Camera.ZNear = 0.1f; } } ImGuiHelper.InputFromFloat("Zoom Speed", Pipeline._context.Camera, "ZoomSpeed", true, 0.1f); if (Pipeline._context.Camera.ZoomSpeed != 1.0f) { ImGui.SameLine(); if (ImGui.Button("Reset")) { Pipeline._context.Camera.ZoomSpeed = 1.0f; } } ImGuiHelper.InputFromFloat("Pan Speed", Pipeline._context.Camera, "PanSpeed", true, 0.1f); if (Pipeline._context.Camera.PanSpeed != 1.0f) { ImGui.SameLine(); if (ImGui.Button("Reset")) { Pipeline._context.Camera.PanSpeed = 1.0f; } } ImGui.EndMenu(); } if (ImGui.BeginMenu("Reset Animations")) { parentWindow.Reset(); ImGui.EndMenu(); } ImGui.EndMenuBar(); var menuBG = ImGui.GetStyle().Colors[(int)ImGuiCol.MenuBarBg]; ImGui.PushStyleColor(ImGuiCol.WindowBg, menuBG); ImGui.PushStyleColor(ImGuiCol.ChildBg, menuBG); if (ImGui.BeginChild("viewport_menu2", new System.Numerics.Vector2(350, 22))) { ImGui.AlignTextToFramePadding(); ImGui.Text("Active Model(s)"); ImGui.SameLine(); if (ImGui.BeginCombo("##model_select", selectedModel)) { bool isSelected = "All Models" == selectedModel; if (ImGui.Selectable("All Models", isSelected)) { selectedModel = "All Models"; } if (isSelected) { ImGui.SetItemDefaultFocus(); } foreach (var file in Pipeline.Files) { string name = file.Renderer.Name; isSelected = name == selectedModel; if (ImGui.Selectable(name, isSelected)) { selectedModel = name; } if (isSelected) { ImGui.SetItemDefaultFocus(); } } ImGui.EndCombo(); } } ImGui.EndChild(); ImGui.PopStyleColor(2); } //Make sure the entire viewport is within a child window to have accurate mouse and window sizing relative to the space it uses. if (ImGui.BeginChild("viewport_child1")) { var size = ImGui.GetWindowSize(); if (Pipeline.Width != (int)size.X || Pipeline.Height != (int)size.Y) { Pipeline.Width = (int)size.X; Pipeline.Height = (int)size.Y; Pipeline.OnResize(); } Pipeline.RenderScene(); if (ImGui.IsWindowFocused() && ImGui.IsWindowHovered() || ForceUpdate || _mouseDown) { ForceUpdate = false; if (!onEnter) { Pipeline.ResetPrevious(); onEnter = true; } //Only update scene when necessary UpdateCamera(); } else { onEnter = false; //Reset drag/dropped model data if mouse leaves the viewport during a drag event if (DragDroppedModel != null) { DragDroppedModel.DragDroppedOnLeave(); DragDroppedModel = null; } } var id = Pipeline.GetViewportTexture(); ImGui.Image((IntPtr)id, size, new System.Numerics.Vector2(0, 1), new System.Numerics.Vector2(1, 0)); if (ImGui.BeginDragDropTarget()) { ImGuiPayloadPtr outlinerDrop = ImGui.AcceptDragDropPayload("OUTLINER_ITEM", ImGuiDragDropFlags.AcceptNoDrawDefaultRect | ImGuiDragDropFlags.AcceptBeforeDelivery); if (outlinerDrop.IsValid()) { //Drag/drop things onto meshes var mouseInfo = CreateMouseState(); var picked = Pipeline.GetPickedObject(mouseInfo); //Picking object changed. if (DragDroppedModel != picked) { //Set exit drop event for previous model if (DragDroppedModel != null) { DragDroppedModel.DragDroppedOnLeave(); } DragDroppedModel = picked; //Model has changed so call the enter event if (picked != null) { picked.DragDroppedOnEnter(); } } if (picked != null) { //Set the drag/drop event var node = Outliner.GetDragDropNode(); picked.DragDropped(node.Tag); } } ImGui.EndDragDropTarget(); } } ImGui.EndChild(); }
public static int DragAndDropList <T>(T[] list, int draggedState, bool horizontal = false) { //draggedState = -1; for (var i = 0; i < list.Length; i++) { T item = list[i]; if (item == null) { continue; } if (i == draggedState) { ImGui.PushStyleColor(ImGuiCol.Button, 0); ImGui.PushStyleColor(ImGuiCol.Text, 0); } ImGui.PushID($"Item {i}"); ImGui.Button(item.ToString()); ImGui.PopID(); if (i == draggedState) { ImGui.PopStyleColor(); ImGui.PopStyleColor(); } if (ImGui.BeginDragDropSource()) { draggedState = i; ImGui.PushID("carrying"); ImGui.Text(item.ToString()); ImGui.PopID(); ImGui.SetDragDropPayload("UNUSED", IntPtr.Zero, 0); ImGui.EndDragDropSource(); } if (ImGui.BeginDragDropTarget()) { ImGuiPayloadPtr dataPtr = ImGui.AcceptDragDropPayload("UNUSED"); unsafe { if ((IntPtr)dataPtr.NativePtr != IntPtr.Zero && dataPtr.IsDelivery()) { int idxDragged = draggedState; (list[idxDragged], list[i]) = (list[i], list[idxDragged]); draggedState = -1; } } ImGui.EndDragDropTarget(); } // Check if drag/drop ended. ImGuiPayloadPtr payLoad = ImGui.GetDragDropPayload(); unsafe { if ((IntPtr)payLoad.NativePtr == IntPtr.Zero) { draggedState = -1; } } if (horizontal && i != list.Length - 1) { ImGui.SameLine(); } } return(draggedState); }