From a99dd304ed8581fdc4789140137231645f1fb89c Mon Sep 17 00:00:00 2001 From: bloeys Date: Mon, 24 Jul 2023 21:14:09 +0400 Subject: [PATCH] Complete basic imgui integration --- engine/engine.go | 21 ++++++++++++++++++--- main.go | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index 204f0bf..6267c81 100755 --- a/engine/engine.go +++ b/engine/engine.go @@ -49,10 +49,25 @@ func (w *Window) handleInputs() { imIO.AddMouseWheelDelta(float32(xDelta), float32(yDelta)) case *sdl.KeyboardEvent: - input.HandleKeyboardEvent(e) - if e.Type == sdl.KEYDOWN || e.Type == sdl.KEYUP { - imIO.AddKeyEvent(nmageimgui.SdlScancodeToImGuiKey(e.Keysym.Scancode), e.Type == sdl.KEYDOWN) + input.HandleKeyboardEvent(e) + imIO.AddKeyEvent(nmageimgui.SdlScancodeToImGuiKey(e.Keysym.Scancode), e.Type == sdl.KEYDOWN) + + // Send modifier key updates to imgui + if e.Keysym.Sym == sdl.K_LCTRL || e.Keysym.Sym == sdl.K_RCTRL { + imIO.SetKeyCtrl(e.Type == sdl.KEYDOWN) + } + + if e.Keysym.Sym == sdl.K_LSHIFT || e.Keysym.Sym == sdl.K_RSHIFT { + imIO.SetKeyShift(e.Type == sdl.KEYDOWN) + } + + if e.Keysym.Sym == sdl.K_LALT || e.Keysym.Sym == sdl.K_RALT { + imIO.SetKeyAlt(e.Type == sdl.KEYDOWN) + } + + if e.Keysym.Sym == sdl.K_LGUI || e.Keysym.Sym == sdl.K_RGUI { + imIO.SetKeySuper(e.Type == sdl.KEYDOWN) } case *sdl.TextInputEvent: diff --git a/main.go b/main.go index fccdad2..6ebd8b7 100755 --- a/main.go +++ b/main.go @@ -287,6 +287,9 @@ func (g *OurGame) Update() { simpleMat.SetUnifVec3("lightColor1", lightColor1) } + // an cimgui text box using cimgui + newimgui.InputTextWithHint("Test", "", &testString, newimgui.InputTextFlagsAllowTabInput, nil) + if input.KeyClicked(sdl.K_F4) { fmt.Printf("Pos: %s; Forward: %s; |Forward|: %f\n", cam.Pos.String(), cam.Forward.String(), cam.Forward.Mag()) } @@ -294,6 +297,8 @@ func (g *OurGame) Update() { g.Win.SDLWin.SetTitle(fmt.Sprint("nMage (", timing.GetAvgFPS(), " fps)")) } +var testString string + func (g *OurGame) updateCameraLookAround() { mouseX, mouseY := input.GetMouseMotion()