mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Fixed editor camera for real
This commit is contained in:
@@ -43,6 +43,8 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
public Vector2 ViewportSize => (Vector2)oldViewportSize;
|
public Vector2 ViewportSize => (Vector2)oldViewportSize;
|
||||||
|
|
||||||
|
private bool _wrappedCursor;
|
||||||
|
|
||||||
protected override void InternalShow()
|
protected override void InternalShow()
|
||||||
{
|
{
|
||||||
ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(1, 1));
|
ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(1, 1));
|
||||||
@@ -56,19 +58,22 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
ShowMenuBar();
|
ShowMenuBar();
|
||||||
|
|
||||||
var viewportSize = ImGui.GetContentRegionAvail();
|
let viewportSize = ImGui.GetContentRegionAvail();
|
||||||
|
|
||||||
if(ImGui.IsWindowHovered() && Input.IsMouseButtonPressing(.RightButton))
|
if(ImGui.IsWindowHovered() && Input.IsMouseButtonPressing(.RightButton))
|
||||||
{
|
{
|
||||||
var currentWindow = ImGui.GetCurrentWindow();
|
let currentWindow = ImGui.GetCurrentWindow();
|
||||||
ImGui.FocusWindow(currentWindow);
|
ImGui.FocusWindow(currentWindow);
|
||||||
|
|
||||||
if (_editor.CurrentCamera.[Friend]BindMouse)
|
|
||||||
WrapMouseInViewport();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_hasFocus = ImGui.IsWindowFocused();
|
_hasFocus = ImGui.IsWindowFocused();
|
||||||
|
|
||||||
|
if (_editor.CurrentCamera.[Friend]BindMouse && _hasFocus)
|
||||||
|
WrapMouseInViewport();
|
||||||
|
|
||||||
|
// If we wrapped this frame we weren't hovering because the cursor has to be out of bounds to wrap
|
||||||
|
_editor.CurrentCamera.AllowMove = _hasFocus && (ImGui.IsWindowHovered() || _wrappedCursor);
|
||||||
|
|
||||||
if (_hasFocus && !_editor.CurrentCamera.InUse)
|
if (_hasFocus && !_editor.CurrentCamera.InUse)
|
||||||
{
|
{
|
||||||
if (Input.IsKeyPressing(.Q))
|
if (Input.IsKeyPressing(.Q))
|
||||||
@@ -123,34 +128,38 @@ namespace GlitchyEditor.EditWindows
|
|||||||
/// Wraps the mouse, so that it always stays in the viewport.
|
/// Wraps the mouse, so that it always stays in the viewport.
|
||||||
private void WrapMouseInViewport()
|
private void WrapMouseInViewport()
|
||||||
{
|
{
|
||||||
var mousePos = (Vector2)ImGui.GetMousePos();
|
_wrappedCursor = false;
|
||||||
var winPos = (Vector2)ImGui.GetWindowPos();
|
|
||||||
var winSize = (Vector2)ImGui.GetWindowSize();
|
let mousePos = (Vector2)ImGui.GetMousePos();
|
||||||
|
let winPos = (Vector2)ImGui.GetWindowPos();
|
||||||
|
let regionMin = winPos + (Vector2)ImGui.GetWindowContentRegionMin();
|
||||||
|
let regionMax = winPos + (Vector2)ImGui.GetWindowContentRegionMax();
|
||||||
|
|
||||||
Vector2 newMousePos = mousePos;
|
Vector2 newMousePos = mousePos;
|
||||||
|
|
||||||
if (mousePos.X < winPos.X)
|
if (mousePos.X < regionMin.X)
|
||||||
{
|
{
|
||||||
newMousePos.X = winPos.X + winSize.X - 1;
|
newMousePos.X = regionMax.X - 1;
|
||||||
}
|
}
|
||||||
else if (mousePos.X > winPos.X + winSize.X)
|
else if (mousePos.X > regionMax.X - 1)
|
||||||
{
|
{
|
||||||
newMousePos.X = winPos.X + 1;
|
newMousePos.X = regionMin.X + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mousePos.Y < winPos.Y)
|
if (mousePos.Y < regionMin.Y)
|
||||||
{
|
{
|
||||||
newMousePos.Y = winPos.Y + winSize.Y - 1;
|
newMousePos.Y = regionMax.Y - 1;
|
||||||
}
|
}
|
||||||
else if (mousePos.Y > winPos.Y + winSize.Y)
|
else if (mousePos.Y > regionMax.Y - 1)
|
||||||
{
|
{
|
||||||
newMousePos.Y = winPos.Y + 1;
|
newMousePos.Y = regionMin.Y + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newMousePos != mousePos)
|
if (newMousePos != mousePos)
|
||||||
{
|
{
|
||||||
Input.SetMousePosition((Int2)newMousePos);
|
Input.SetMousePosition((Int2)newMousePos);
|
||||||
_editor.CurrentCamera.[Friend]MouseCooldown = 2;
|
_editor.CurrentCamera.[Friend]MouseCooldown = 2;
|
||||||
|
_wrappedCursor = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,16 +89,22 @@ namespace ImGui
|
|||||||
return EditVector<4>(label, ref *(float[4]*)&value, (float[4])resetValues, dragSpeed, columnWidth, (float[4])minValue, (float[4])maxValue);
|
return EditVector<4>(label, ref *(float[4]*)&value, (float[4])resetValues, dragSpeed, columnWidth, (float[4])minValue, (float[4])maxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static (Color Default, Color Hovered, Color Active)[?] VectorButtonColors = .(
|
||||||
|
(Color(230, 25, 45), Color(150, 25, 45), Color(230, 90, 90)),
|
||||||
|
(Color(50, 190, 15), Color(50, 120, 15), Color(116, 190, 99)),
|
||||||
|
(Color(55, 55, 230), Color(55, 55, 150), Color(90, 90, 230)),
|
||||||
|
(Color(230, 25, 45), Color(230, 25, 45), Color(230, 25, 45)));
|
||||||
|
|
||||||
public static bool EditVector<NumComponents>(StringView label, ref float[NumComponents] value, float[NumComponents] resetValues = .(), float dragSpeed = 0.1f, float columnWidth = 100f, float[NumComponents] minValue = .(), float[NumComponents] maxValue = .()) where NumComponents : const int32
|
public static bool EditVector<NumComponents>(StringView label, ref float[NumComponents] value, float[NumComponents] resetValues = .(), float dragSpeed = 0.1f, float columnWidth = 100f, float[NumComponents] minValue = .(), float[NumComponents] maxValue = .()) where NumComponents : const int32
|
||||||
{
|
{
|
||||||
const String[?] componentNames = .("X", "Y", "Z", "W");
|
const String[?] componentNames = .("X", "Y", "Z", "W");
|
||||||
const String[?] componentIds = .("##X", "##Y", "##Z", "##W");
|
const String[?] componentIds = .("##X", "##Y", "##Z", "##W");
|
||||||
|
|
||||||
(Color Default, Color Hovered, Color Active)[?] ButtonColors = .(
|
/*(Color Default, Color Hovered, Color Active)[?] VectorButtonColors = .(
|
||||||
(Color(230, 25, 45), Color(150, 25, 45), Color(230, 90, 90)),
|
(Color(230, 25, 45), Color(150, 25, 45), Color(230, 90, 90)),
|
||||||
(Color(50, 190, 15), Color(50, 120, 15), Color(116, 190, 99)),
|
(Color(50, 190, 15), Color(50, 120, 15), Color(116, 190, 99)),
|
||||||
(Color(55, 55, 230), Color(55, 55, 150), Color(90, 90, 230)),
|
(Color(55, 55, 230), Color(55, 55, 150), Color(90, 90, 230)),
|
||||||
(Color(230, 25, 45), Color(230, 25, 45), Color(230, 25, 45)));
|
(Color(230, 25, 45), Color(230, 25, 45), Color(230, 25, 45)));*/
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
@@ -127,9 +133,9 @@ namespace ImGui
|
|||||||
SameLine();
|
SameLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
PushStyleColor(.Button, ButtonColors[i].Default.Value);
|
PushStyleColor(.Button, VectorButtonColors[i].Default.Value);
|
||||||
PushStyleColor(.ButtonHovered, ButtonColors[i].Hovered.Value);
|
PushStyleColor(.ButtonHovered, VectorButtonColors[i].Hovered.Value);
|
||||||
PushStyleColor(.ButtonActive, ButtonColors[i].Active.Value);
|
PushStyleColor(.ButtonActive, VectorButtonColors[i].Active.Value);
|
||||||
|
|
||||||
if (Button(componentNames[i], buttonSize))
|
if (Button(componentNames[i], buttonSize))
|
||||||
{
|
{
|
||||||
@@ -150,5 +156,11 @@ namespace ImGui
|
|||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draws a rectangle with the given color.
|
||||||
|
public static void DrawRect(Vec2 min, Vec2 max, Color color)
|
||||||
|
{
|
||||||
|
ImGui.GetForegroundDrawList().AddRect(min, max, ImGui.GetColorU32(color.Value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ namespace GlitchyEngine.World
|
|||||||
// Gets whether or not the camera is currently being moved.
|
// Gets whether or not the camera is currently being moved.
|
||||||
public bool InUse => BindMouse;
|
public bool InUse => BindMouse;
|
||||||
|
|
||||||
|
/// If true, the camera can be rotated/moved
|
||||||
|
public bool AllowMove;
|
||||||
|
|
||||||
public RenderTargetGroup RenderTarget
|
public RenderTargetGroup RenderTarget
|
||||||
{
|
{
|
||||||
get => _renderTarget;
|
get => _renderTarget;
|
||||||
@@ -160,15 +163,18 @@ namespace GlitchyEngine.World
|
|||||||
|
|
||||||
BindMouse = false;
|
BindMouse = false;
|
||||||
|
|
||||||
if (Input.IsKeyPressed(.Alt))
|
if (AllowMove)
|
||||||
{
|
{
|
||||||
AltController(gameTime);
|
if (Input.IsKeyPressed(.Alt))
|
||||||
_isAltMode = true;
|
{
|
||||||
}
|
AltController(gameTime);
|
||||||
else
|
_isAltMode = true;
|
||||||
{
|
}
|
||||||
FirstPersonController(gameTime);
|
else
|
||||||
_isAltMode = false;
|
{
|
||||||
|
FirstPersonController(gameTime);
|
||||||
|
_isAltMode = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MouseCooldown != 0)
|
if (MouseCooldown != 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user