Skip to content

Commit

Permalink
fixed some keys not being forwarded to imgui
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Nov 9, 2022
1 parent 0a5862a commit f14da04
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CUE4Parse
2 changes: 1 addition & 1 deletion FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<PackageReference Include="AvalonEdit" Version="6.1.3.50" />
<PackageReference Include="CSCore" Version="1.2.1.2" />
<PackageReference Include="DiscordRichPresence" Version="1.0.175" />
<PackageReference Include="ImGui.NET" Version="1.87.3" />
<PackageReference Include="ImGui.NET" Version="1.88.0" />
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.2.16" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NVorbis" Version="0.10.4" />
Expand Down
122 changes: 101 additions & 21 deletions FModel/Framework/ImGuiController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -55,7 +55,7 @@ public ImGuiController(int width, int height)
io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset;
io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable;
io.Fonts.Flags |= ImFontAtlasFlags.NoBakedLines;

CreateDeviceResources();
SetKeyMappings();
Expand Down Expand Up @@ -235,16 +235,18 @@ private void UpdateImGuiInput(GameWindow wnd)
var mState = wnd.MouseState;
var kState = wnd.KeyboardState;

io.AddMousePosEvent(mState.X, mState.Y);
io.AddMouseButtonEvent(0, mState[MouseButton.Left]);
io.AddMouseButtonEvent(1, mState[MouseButton.Right]);
io.AddMouseButtonEvent(2, mState[MouseButton.Middle]);

io.AddMousePosEvent(mState.X, mState.Y);
io.AddMouseButtonEvent(3, mState[MouseButton.Button1]);
io.AddMouseButtonEvent(4, mState[MouseButton.Button2]);
io.AddMouseWheelEvent(mState.ScrollDelta.X, mState.ScrollDelta.Y);

foreach (Keys key in Enum.GetValues(typeof(Keys)))
{
if (key == Keys.Unknown) continue;
io.AddKeyEvent((ImGuiKey) (int)key, kState.IsKeyDown(key));
io.AddKeyEvent((ImGuiKey) io.KeyMap[(int) key], kState.IsKeyDown(key));
}

foreach (var c in PressedChars)
Expand All @@ -253,43 +255,121 @@ private void UpdateImGuiInput(GameWindow wnd)
}
PressedChars.Clear();

io.KeyShift = kState.IsKeyDown(Keys.LeftShift) || kState.IsKeyDown(Keys.RightShift);
io.KeyCtrl = kState.IsKeyDown(Keys.LeftControl) || kState.IsKeyDown(Keys.RightControl);
io.KeyAlt = kState.IsKeyDown(Keys.LeftAlt) || kState.IsKeyDown(Keys.RightAlt);
io.KeyShift = kState.IsKeyDown(Keys.LeftShift) || kState.IsKeyDown(Keys.RightShift);
io.KeySuper = kState.IsKeyDown(Keys.LeftSuper) || kState.IsKeyDown(Keys.RightSuper);
}

internal void PressChar(char keyChar)
public void PressChar(char keyChar)
{
PressedChars.Add(keyChar);
}

internal void MouseScroll(Vector2 offset)
{
ImGuiIOPtr io = ImGui.GetIO();
io.MouseWheel = offset.Y;
io.MouseWheelH = offset.X;
}

private static void SetKeyMappings()
{
ImGuiIOPtr io = ImGui.GetIO();
io.KeyMap[(int)ImGuiKey.Tab] = (int)Keys.Tab;
io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)Keys.Left;
io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Keys.Right;
io.KeyMap[(int)ImGuiKey.ModShift] = (int)Keys.LeftShift;
// io.KeyMap[(int)ImGuiKey.ModShift] = (int)Keys.RightShift;
io.KeyMap[(int)ImGuiKey.ModCtrl] = (int)Keys.LeftControl;
// io.KeyMap[(int)ImGuiKey.ModCtrl] = (int)Keys.RightControl;
io.KeyMap[(int)ImGuiKey.ModAlt] = (int)Keys.LeftAlt;
// io.KeyMap[(int)ImGuiKey.ModAlt] = (int)Keys.RightAlt;
io.KeyMap[(int)ImGuiKey.ModSuper] = (int)Keys.LeftSuper;
// io.KeyMap[(int)ImGuiKey.ModSuper] = (int)Keys.RightSuper;
io.KeyMap[(int)ImGuiKey.Menu] = (int)Keys.Menu;
io.KeyMap[(int)ImGuiKey.UpArrow] = (int)Keys.Up;
io.KeyMap[(int)ImGuiKey.DownArrow] = (int)Keys.Down;
io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)Keys.Left;
io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Keys.Right;
io.KeyMap[(int)ImGuiKey.Enter] = (int)Keys.Enter;
io.KeyMap[(int)ImGuiKey.Escape] = (int)Keys.Escape;
io.KeyMap[(int)ImGuiKey.Space] = (int)Keys.Space;
io.KeyMap[(int)ImGuiKey.Tab] = (int)Keys.Tab;
io.KeyMap[(int)ImGuiKey.Backspace] = (int)Keys.Backspace;
io.KeyMap[(int)ImGuiKey.Insert] = (int)Keys.Insert;
io.KeyMap[(int)ImGuiKey.Delete] = (int)Keys.Delete;
io.KeyMap[(int)ImGuiKey.PageUp] = (int)Keys.PageUp;
io.KeyMap[(int)ImGuiKey.PageDown] = (int)Keys.PageDown;
io.KeyMap[(int)ImGuiKey.Home] = (int)Keys.Home;
io.KeyMap[(int)ImGuiKey.End] = (int)Keys.End;
io.KeyMap[(int)ImGuiKey.Delete] = (int)Keys.Delete;
io.KeyMap[(int)ImGuiKey.Backspace] = (int)Keys.Backspace;
io.KeyMap[(int)ImGuiKey.Enter] = (int)Keys.Enter;
io.KeyMap[(int)ImGuiKey.Escape] = (int)Keys.Escape;
io.KeyMap[(int)ImGuiKey.CapsLock] = (int)Keys.CapsLock;
io.KeyMap[(int)ImGuiKey.ScrollLock] = (int)Keys.ScrollLock;
io.KeyMap[(int)ImGuiKey.PrintScreen] = (int)Keys.PrintScreen;
io.KeyMap[(int)ImGuiKey.Pause] = (int)Keys.Pause;
io.KeyMap[(int)ImGuiKey.NumLock] = (int)Keys.NumLock;
io.KeyMap[(int)ImGuiKey.KeypadDivide] = (int)Keys.KeyPadDivide;
io.KeyMap[(int)ImGuiKey.KeypadMultiply] = (int)Keys.KeyPadMultiply;
io.KeyMap[(int)ImGuiKey.KeypadSubtract] = (int)Keys.KeyPadSubtract;
io.KeyMap[(int)ImGuiKey.KeypadAdd] = (int)Keys.KeyPadAdd;
io.KeyMap[(int)ImGuiKey.KeypadDecimal] = (int)Keys.KeyPadDecimal;
io.KeyMap[(int)ImGuiKey.KeypadEnter] = (int)Keys.KeyPadEnter;
io.KeyMap[(int)ImGuiKey.GraveAccent] = (int)Keys.GraveAccent;
io.KeyMap[(int)ImGuiKey.Minus] = (int)Keys.Minus;
io.KeyMap[(int)ImGuiKey.Equal] = (int)Keys.Equal;
io.KeyMap[(int)ImGuiKey.LeftBracket] = (int)Keys.LeftBracket;
io.KeyMap[(int)ImGuiKey.RightBracket] = (int)Keys.RightBracket;
io.KeyMap[(int)ImGuiKey.Semicolon] = (int)Keys.Semicolon;
io.KeyMap[(int)ImGuiKey.Apostrophe] = (int)Keys.Apostrophe;
io.KeyMap[(int)ImGuiKey.Comma] = (int)Keys.Comma;
io.KeyMap[(int)ImGuiKey.Period] = (int)Keys.Period;
io.KeyMap[(int)ImGuiKey.Slash] = (int)Keys.Slash;
io.KeyMap[(int)ImGuiKey.Backslash] = (int)Keys.Backslash;
io.KeyMap[(int)ImGuiKey.F1] = (int)Keys.F1;
io.KeyMap[(int)ImGuiKey.F2] = (int)Keys.F2;
io.KeyMap[(int)ImGuiKey.F3] = (int)Keys.F3;
io.KeyMap[(int)ImGuiKey.F4] = (int)Keys.F4;
io.KeyMap[(int)ImGuiKey.F5] = (int)Keys.F5;
io.KeyMap[(int)ImGuiKey.F6] = (int)Keys.F6;
io.KeyMap[(int)ImGuiKey.F7] = (int)Keys.F7;
io.KeyMap[(int)ImGuiKey.F8] = (int)Keys.F8;
io.KeyMap[(int)ImGuiKey.F9] = (int)Keys.F9;
io.KeyMap[(int)ImGuiKey.F10] = (int)Keys.F10;
io.KeyMap[(int)ImGuiKey.F11] = (int)Keys.F11;
io.KeyMap[(int)ImGuiKey.F12] = (int)Keys.F12;
io.KeyMap[(int)ImGuiKey.Keypad0] = (int)Keys.KeyPad0;
io.KeyMap[(int)ImGuiKey.Keypad1] = (int)Keys.KeyPad1;
io.KeyMap[(int)ImGuiKey.Keypad2] = (int)Keys.KeyPad2;
io.KeyMap[(int)ImGuiKey.Keypad3] = (int)Keys.KeyPad3;
io.KeyMap[(int)ImGuiKey.Keypad4] = (int)Keys.KeyPad4;
io.KeyMap[(int)ImGuiKey.Keypad5] = (int)Keys.KeyPad5;
io.KeyMap[(int)ImGuiKey.Keypad6] = (int)Keys.KeyPad6;
io.KeyMap[(int)ImGuiKey.Keypad7] = (int)Keys.KeyPad7;
io.KeyMap[(int)ImGuiKey.Keypad8] = (int)Keys.KeyPad8;
io.KeyMap[(int)ImGuiKey.Keypad9] = (int)Keys.KeyPad9;
io.KeyMap[(int)ImGuiKey._0] = (int)Keys.D0;
io.KeyMap[(int)ImGuiKey._1] = (int)Keys.D1;
io.KeyMap[(int)ImGuiKey._2] = (int)Keys.D2;
io.KeyMap[(int)ImGuiKey._3] = (int)Keys.D3;
io.KeyMap[(int)ImGuiKey._4] = (int)Keys.D4;
io.KeyMap[(int)ImGuiKey._5] = (int)Keys.D5;
io.KeyMap[(int)ImGuiKey._6] = (int)Keys.D6;
io.KeyMap[(int)ImGuiKey._7] = (int)Keys.D7;
io.KeyMap[(int)ImGuiKey._8] = (int)Keys.D8;
io.KeyMap[(int)ImGuiKey._9] = (int)Keys.D9;
io.KeyMap[(int)ImGuiKey.A] = (int)Keys.A;
io.KeyMap[(int)ImGuiKey.B] = (int)Keys.B;
io.KeyMap[(int)ImGuiKey.C] = (int)Keys.C;
io.KeyMap[(int)ImGuiKey.D] = (int)Keys.D;
io.KeyMap[(int)ImGuiKey.E] = (int)Keys.E;
io.KeyMap[(int)ImGuiKey.F] = (int)Keys.F;
io.KeyMap[(int)ImGuiKey.G] = (int)Keys.G;
io.KeyMap[(int)ImGuiKey.H] = (int)Keys.H;
io.KeyMap[(int)ImGuiKey.I] = (int)Keys.I;
io.KeyMap[(int)ImGuiKey.J] = (int)Keys.J;
io.KeyMap[(int)ImGuiKey.K] = (int)Keys.K;
io.KeyMap[(int)ImGuiKey.L] = (int)Keys.L;
io.KeyMap[(int)ImGuiKey.M] = (int)Keys.M;
io.KeyMap[(int)ImGuiKey.N] = (int)Keys.N;
io.KeyMap[(int)ImGuiKey.O] = (int)Keys.O;
io.KeyMap[(int)ImGuiKey.P] = (int)Keys.P;
io.KeyMap[(int)ImGuiKey.Q] = (int)Keys.Q;
io.KeyMap[(int)ImGuiKey.R] = (int)Keys.R;
io.KeyMap[(int)ImGuiKey.S] = (int)Keys.S;
io.KeyMap[(int)ImGuiKey.T] = (int)Keys.T;
io.KeyMap[(int)ImGuiKey.U] = (int)Keys.U;
io.KeyMap[(int)ImGuiKey.V] = (int)Keys.V;
io.KeyMap[(int)ImGuiKey.W] = (int)Keys.W;
io.KeyMap[(int)ImGuiKey.X] = (int)Keys.X;
io.KeyMap[(int)ImGuiKey.Y] = (int)Keys.Y;
io.KeyMap[(int)ImGuiKey.Z] = (int)Keys.Z;
Expand Down
2 changes: 1 addition & 1 deletion FModel/Views/Snooper/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void WorldCamera(UObject actor, ref Camera cam)
cam = new Camera(
new Vector3(position.X, position.Y, position.Z),
new Vector3(direction.X, direction.Y, direction.Z),
0.01f, far * 25f, far / 10f);
0.01f, far * 25f, Math.Max(5f, far / 10f));
}

private void WorldMesh(UObject actor, Transform transform)
Expand Down
52 changes: 32 additions & 20 deletions FModel/Views/Snooper/SnimGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void Render(Snooper s)
}
else NoMeshSelected();
PopStyleCompact();
ImGui.End();
}
if (ImGui.Begin("Textures"))
{
Expand All @@ -82,6 +83,33 @@ public void Render(Snooper s)
}
else NoMeshSelected();
PopStyleCompact();
ImGui.End();
}
if (ImGui.Begin("Parameters"))
{
PushStyleCompact();
var guid = s.Renderer.Settings.SelectedModel;
if (s.Renderer.Cache.Models.TryGetValue(guid, out var model) &&
s.Renderer.Settings.TryGetSection(model, out var section))
{
const int width = 50;
var material = model.Materials[section.MaterialIndex];
ImGui.Checkbox("Show Section", ref section.Show);
ImGui.SetNextItemWidth(width); ImGui.DragFloat("Roughness", ref material.Roughness, .01f, 0f, 1f);
ImGui.SetNextItemWidth(width); ImGui.DragFloat("Specular Multiplier", ref material.SpecularMult, .01f, 0f);
ImGui.SetNextItemWidth(width); ImGui.DragFloat("Emissive Multiplier", ref material.EmissiveMult, .01f, 0f);
ImGui.SetNextItemWidth(width); ImGui.DragFloat("UV Scale", ref material.UVScale, .01f, 0f);
if (material.HasM)
{
ImGui.ColorEdit3("Skin Boost Color", ref material.M.SkinBoost.Color, ImGuiColorEditFlags.NoInputs);
ImGui.SetNextItemWidth(width); ImGui.DragFloat("Skin Boost Exponent", ref material.M.SkinBoost.Exponent, .01f, 0f);
ImGui.SetNextItemWidth(width); ImGui.DragFloat("AmbientOcclusion", ref material.M.AmbientOcclusion, .01f, 0f, 1f);
ImGui.SetNextItemWidth(width); ImGui.DragFloat("Cavity", ref material.M.Cavity, .01f, 0f, 1f);
}
}
else NoMeshSelected();
PopStyleCompact();
ImGui.End();
}

DrawUvChannels(s);
Expand Down Expand Up @@ -341,22 +369,6 @@ private void DrawDetails(Snooper s)
ImGui.EndTabItem();
}
}

if (ImGui.Begin("test") && s.Renderer.Settings.TryGetSection(model, out var sec))
{
var material = model.Materials[sec.MaterialIndex];
ImGui.DragFloat("Roughness", ref material.Roughness, .01f, 0f, 1f);
ImGui.DragFloat("Specular Multiplier", ref material.SpecularMult, .01f, 0f);
ImGui.DragFloat("Emissive Multiplier", ref material.EmissiveMult, .01f, 0f);
ImGui.DragFloat("UV Scale", ref material.UVScale, .01f, 0f);
if (material.HasM)
{
ImGui.ColorEdit3("Skin Boost Color", ref material.M.SkinBoost.Color);
ImGui.DragFloat("Skin Boost Exponent", ref material.M.SkinBoost.Exponent, .01f, 0f);
ImGui.DragFloat("AmbientOcclusion", ref material.M.AmbientOcclusion, .01f, 0f, 1f);
ImGui.DragFloat("Cavity", ref material.M.Cavity, .01f, 0f, 1f);
}
}
}
else NoMeshSelected();
PopStyleCompact();
Expand Down Expand Up @@ -484,7 +496,7 @@ private void Draw3DViewport(Snooper s)
// ImGui.SetNextWindowSize(_viewportSize, _firstUse);
// ImGui.SetNextWindowPos(_viewportPosition, _firstUse);
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
ImGui.Begin("3D Viewport");
ImGui.Begin("3D Viewport", flags);
ImGui.PopStyleVar();

var largest = ImGui.GetContentRegionAvail();
Expand Down Expand Up @@ -614,9 +626,9 @@ private void Theme(ImGuiStylePtr style)
style.Colors[(int) ImGuiCol.Button] = new Vector4(0.05f, 0.05f, 0.05f, 0.54f);
style.Colors[(int) ImGuiCol.ButtonHovered] = new Vector4(0.69f, 0.69f, 1.00f, 0.20f);
style.Colors[(int) ImGuiCol.ButtonActive] = new Vector4(0.69f, 0.69f, 1.00f, 0.39f);
style.Colors[(int) ImGuiCol.Header] = new Vector4(0.16f, 0.16f, 0.21f, 1.00f);
style.Colors[(int) ImGuiCol.HeaderHovered] = new Vector4(0.69f, 0.69f, 1.00f, 0.20f);
style.Colors[(int) ImGuiCol.HeaderActive] = new Vector4(0.69f, 0.69f, 1.00f, 0.39f);
style.Colors[(int) ImGuiCol.Header] = new Vector4(0.05f, 0.26f, 0.56f, 1.00f);
style.Colors[(int) ImGuiCol.HeaderHovered] = new Vector4(0.05f, 0.26f, 0.56f, 0.39f);
style.Colors[(int) ImGuiCol.HeaderActive] = new Vector4(0.04f, 0.23f, 0.52f, 1.00f);
style.Colors[(int) ImGuiCol.Separator] = new Vector4(0.43f, 0.43f, 0.50f, 0.50f);
style.Colors[(int) ImGuiCol.SeparatorHovered] = new Vector4(0.10f, 0.40f, 0.75f, 0.78f);
style.Colors[(int) ImGuiCol.SeparatorActive] = new Vector4(0.10f, 0.40f, 0.75f, 1.00f);
Expand Down
9 changes: 0 additions & 9 deletions FModel/Views/Snooper/Snooper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,6 @@ private void ClearWhatHasBeenDrawn()
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
}

protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
if (!IsVisible)
return;

_gui.Controller.MouseScroll(e.Offset);
}

protected override void OnTextInput(TextInputEventArgs e)
{
base.OnTextInput(e);
Expand Down

0 comments on commit f14da04

Please sign in to comment.