mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Imgui key mapping
This commit is contained in:
@ -3,11 +3,13 @@ package engine
|
|||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
imgui "github.com/AllenDang/cimgui-go"
|
||||||
newimgui "github.com/AllenDang/cimgui-go"
|
newimgui "github.com/AllenDang/cimgui-go"
|
||||||
"github.com/bloeys/nmage/assert"
|
"github.com/bloeys/nmage/assert"
|
||||||
"github.com/bloeys/nmage/input"
|
"github.com/bloeys/nmage/input"
|
||||||
"github.com/bloeys/nmage/renderer"
|
"github.com/bloeys/nmage/renderer"
|
||||||
"github.com/bloeys/nmage/timing"
|
"github.com/bloeys/nmage/timing"
|
||||||
|
nmageimgui "github.com/bloeys/nmage/ui/imgui"
|
||||||
"github.com/go-gl/gl/v4.1-core/gl"
|
"github.com/go-gl/gl/v4.1-core/gl"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
@ -49,15 +51,12 @@ func (w *Window) handleInputs() {
|
|||||||
case *sdl.KeyboardEvent:
|
case *sdl.KeyboardEvent:
|
||||||
input.HandleKeyboardEvent(e)
|
input.HandleKeyboardEvent(e)
|
||||||
|
|
||||||
if e.Type == sdl.KEYDOWN {
|
if e.Type == sdl.KEYDOWN || e.Type == sdl.KEYUP {
|
||||||
// @TODO: Move to new ImGui input system
|
imIO.AddKeyEvent(nmageimgui.SdlScancodeToImGuiKey(e.Keysym.Scancode), e.Type == sdl.KEYDOWN)
|
||||||
// imIO.KeyPress(int(e.Keysym.Scancode))
|
|
||||||
} else if e.Type == sdl.KEYUP {
|
|
||||||
// imIO.KeyRelease(int(e.Keysym.Scancode))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case *sdl.TextInputEvent:
|
case *sdl.TextInputEvent:
|
||||||
// imIO.AddInputCharacters(string(e.Text[:]))
|
imIO.AddInputCharactersUTF8(e.GetText())
|
||||||
|
|
||||||
case *sdl.MouseButtonEvent:
|
case *sdl.MouseButtonEvent:
|
||||||
input.HandleMouseBtnEvent(e)
|
input.HandleMouseBtnEvent(e)
|
||||||
@ -76,16 +75,12 @@ func (w *Window) handleInputs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
||||||
// x, y, _ := sdl.GetMouseState()
|
x, y, _ := sdl.GetMouseState()
|
||||||
// imIO.SetMousePosition(imgui.Vec2{X: float32(x), Y: float32(y)})
|
imIO.SetMousePos(imgui.Vec2{X: float32(x), Y: float32(y)})
|
||||||
|
|
||||||
imIO.SetMouseButtonDown(0, input.MouseDown(sdl.BUTTON_LEFT))
|
imIO.SetMouseButtonDown(0, input.MouseDown(sdl.BUTTON_LEFT))
|
||||||
imIO.SetMouseButtonDown(1, input.MouseDown(sdl.BUTTON_RIGHT))
|
imIO.SetMouseButtonDown(1, input.MouseDown(sdl.BUTTON_RIGHT))
|
||||||
imIO.SetMouseButtonDown(2, input.MouseDown(sdl.BUTTON_MIDDLE))
|
imIO.SetMouseButtonDown(2, input.MouseDown(sdl.BUTTON_MIDDLE))
|
||||||
|
|
||||||
// imIO.KeyShift(sdl.SCANCODE_LSHIFT, sdl.SCANCODE_RSHIFT)
|
|
||||||
// imIO.KeyCtrl(sdl.SCANCODE_LCTRL, sdl.SCANCODE_RCTRL)
|
|
||||||
// imIO.KeyAlt(sdl.SCANCODE_LALT, sdl.SCANCODE_RALT)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) handleWindowResize() {
|
func (w *Window) handleWindowResize() {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/bloeys/nmage/materials"
|
"github.com/bloeys/nmage/materials"
|
||||||
"github.com/bloeys/nmage/timing"
|
"github.com/bloeys/nmage/timing"
|
||||||
"github.com/go-gl/gl/v4.1-core/gl"
|
"github.com/go-gl/gl/v4.1-core/gl"
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImguiInfo struct {
|
type ImguiInfo struct {
|
||||||
@ -219,97 +220,223 @@ func NewImGui() ImguiInfo {
|
|||||||
imguiInfo.Mat.EnableAttribute("Color")
|
imguiInfo.Mat.EnableAttribute("Color")
|
||||||
imguiInfo.Mat.UnBind()
|
imguiInfo.Mat.UnBind()
|
||||||
|
|
||||||
// //Init imgui input mapping
|
|
||||||
// keys := map[int]int{
|
|
||||||
// newimgui.KeyTab: sdl.SCANCODE_TAB,
|
|
||||||
// newimgui.KeyLeftArrow: sdl.SCANCODE_LEFT,
|
|
||||||
// newimgui.KeyRightArrow: sdl.SCANCODE_RIGHT,
|
|
||||||
// newimgui.KeyUpArrow: sdl.SCANCODE_UP,
|
|
||||||
// newimgui.KeyDownArrow: sdl.SCANCODE_DOWN,
|
|
||||||
// newimgui.KeyPageUp: sdl.SCANCODE_PAGEUP,
|
|
||||||
// newimgui.KeyPageDown: sdl.SCANCODE_PAGEDOWN,
|
|
||||||
// newimgui.KeyHome: sdl.SCANCODE_HOME,
|
|
||||||
// newimgui.KeyEnd: sdl.SCANCODE_END,
|
|
||||||
// newimgui.KeyInsert: sdl.SCANCODE_INSERT,
|
|
||||||
// newimgui.KeyDelete: sdl.SCANCODE_DELETE,
|
|
||||||
// newimgui.KeyBackspace: sdl.SCANCODE_BACKSPACE,
|
|
||||||
// newimgui.KeySpace: sdl.SCANCODE_BACKSPACE,
|
|
||||||
// newimgui.KeyEnter: sdl.SCANCODE_RETURN,
|
|
||||||
// newimgui.KeyEscape: sdl.SCANCODE_ESCAPE,
|
|
||||||
// newimgui.KeyA: sdl.SCANCODE_A,
|
|
||||||
// newimgui.KeyC: sdl.SCANCODE_C,
|
|
||||||
// newimgui.KeyV: sdl.SCANCODE_V,
|
|
||||||
// newimgui.KeyX: sdl.SCANCODE_X,
|
|
||||||
// newimgui.KeyY: sdl.SCANCODE_Y,
|
|
||||||
// newimgui.KeyZ: sdl.SCANCODE_Z,
|
|
||||||
// }
|
|
||||||
|
|
||||||
return imguiInfo
|
return imguiInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// func newImGUI() ImguiInfo {
|
func SdlScancodeToImGuiKey(scancode sdl.Scancode) newimgui.Key {
|
||||||
|
|
||||||
// imguiInfo := ImguiInfo{
|
switch scancode {
|
||||||
// ImCtx: imgui.CreateContext(nil),
|
case sdl.SCANCODE_TAB:
|
||||||
// Mat: materials.NewMaterialSrc("ImGUI Mat", []byte(imguiShdrSrc)),
|
return newimgui.KeyTab
|
||||||
// }
|
case sdl.SCANCODE_LEFT:
|
||||||
|
return newimgui.KeyLeftArrow
|
||||||
// imIO := imgui.CurrentIO()
|
case sdl.SCANCODE_RIGHT:
|
||||||
// imIO.SetBackendFlags(imIO.GetBackendFlags() | imgui.BackendFlagsRendererHasVtxOffset)
|
return newimgui.KeyRightArrow
|
||||||
|
case sdl.SCANCODE_UP:
|
||||||
// gl.GenVertexArrays(1, &imguiInfo.VaoID)
|
return newimgui.KeyUpArrow
|
||||||
// gl.GenBuffers(1, &imguiInfo.VboID)
|
case sdl.SCANCODE_DOWN:
|
||||||
// gl.GenBuffers(1, &imguiInfo.IndexBufID)
|
return newimgui.KeyDownArrow
|
||||||
// gl.GenTextures(1, &imguiInfo.TexID)
|
case sdl.SCANCODE_PAGEUP:
|
||||||
|
return newimgui.KeyPageUp
|
||||||
// // Upload font to gpu
|
case sdl.SCANCODE_PAGEDOWN:
|
||||||
// gl.BindTexture(gl.TEXTURE_2D, imguiInfo.TexID)
|
return newimgui.KeyPageDown
|
||||||
// gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
case sdl.SCANCODE_HOME:
|
||||||
// gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
return newimgui.KeyHome
|
||||||
// gl.PixelStorei(gl.UNPACK_ROW_LENGTH, 0)
|
case sdl.SCANCODE_END:
|
||||||
|
return newimgui.KeyEnd
|
||||||
// image := imIO.Fonts().TextureDataAlpha8()
|
case sdl.SCANCODE_INSERT:
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(image.Width), int32(image.Height), 0, gl.RED, gl.UNSIGNED_BYTE, image.Pixels)
|
return newimgui.KeyInsert
|
||||||
|
case sdl.SCANCODE_DELETE:
|
||||||
// // Store our identifier
|
return newimgui.KeyDelete
|
||||||
// imIO.Fonts().SetTextureID(imgui.TextureID(imguiInfo.TexID))
|
case sdl.SCANCODE_BACKSPACE:
|
||||||
|
return newimgui.KeyBackspace
|
||||||
// //Shader attributes
|
case sdl.SCANCODE_SPACE:
|
||||||
// imguiInfo.Mat.Bind()
|
return newimgui.KeySpace
|
||||||
// imguiInfo.Mat.EnableAttribute("Position")
|
case sdl.SCANCODE_RETURN:
|
||||||
// imguiInfo.Mat.EnableAttribute("UV")
|
return newimgui.KeyEnter
|
||||||
// imguiInfo.Mat.EnableAttribute("Color")
|
case sdl.SCANCODE_ESCAPE:
|
||||||
// imguiInfo.Mat.UnBind()
|
return newimgui.KeyEscape
|
||||||
|
case sdl.SCANCODE_APOSTROPHE:
|
||||||
// //Init imgui input mapping
|
return newimgui.KeyApostrophe
|
||||||
// keys := map[int]int{
|
case sdl.SCANCODE_COMMA:
|
||||||
// imgui.KeyTab: sdl.SCANCODE_TAB,
|
return newimgui.KeyComma
|
||||||
// imgui.KeyLeftArrow: sdl.SCANCODE_LEFT,
|
case sdl.SCANCODE_MINUS:
|
||||||
// imgui.KeyRightArrow: sdl.SCANCODE_RIGHT,
|
return newimgui.KeyMinus
|
||||||
// imgui.KeyUpArrow: sdl.SCANCODE_UP,
|
case sdl.SCANCODE_PERIOD:
|
||||||
// imgui.KeyDownArrow: sdl.SCANCODE_DOWN,
|
return newimgui.KeyPeriod
|
||||||
// imgui.KeyPageUp: sdl.SCANCODE_PAGEUP,
|
case sdl.SCANCODE_SLASH:
|
||||||
// imgui.KeyPageDown: sdl.SCANCODE_PAGEDOWN,
|
return newimgui.KeySlash
|
||||||
// imgui.KeyHome: sdl.SCANCODE_HOME,
|
case sdl.SCANCODE_SEMICOLON:
|
||||||
// imgui.KeyEnd: sdl.SCANCODE_END,
|
return newimgui.KeySemicolon
|
||||||
// imgui.KeyInsert: sdl.SCANCODE_INSERT,
|
case sdl.SCANCODE_EQUALS:
|
||||||
// imgui.KeyDelete: sdl.SCANCODE_DELETE,
|
return newimgui.KeyEqual
|
||||||
// imgui.KeyBackspace: sdl.SCANCODE_BACKSPACE,
|
case sdl.SCANCODE_LEFTBRACKET:
|
||||||
// imgui.KeySpace: sdl.SCANCODE_BACKSPACE,
|
return newimgui.KeyLeftBracket
|
||||||
// imgui.KeyEnter: sdl.SCANCODE_RETURN,
|
case sdl.SCANCODE_BACKSLASH:
|
||||||
// imgui.KeyEscape: sdl.SCANCODE_ESCAPE,
|
return newimgui.KeyBackslash
|
||||||
// imgui.KeyA: sdl.SCANCODE_A,
|
case sdl.SCANCODE_RIGHTBRACKET:
|
||||||
// imgui.KeyC: sdl.SCANCODE_C,
|
return newimgui.KeyRightBracket
|
||||||
// imgui.KeyV: sdl.SCANCODE_V,
|
case sdl.SCANCODE_GRAVE:
|
||||||
// imgui.KeyX: sdl.SCANCODE_X,
|
return newimgui.KeyGraveAccent
|
||||||
// imgui.KeyY: sdl.SCANCODE_Y,
|
case sdl.SCANCODE_CAPSLOCK:
|
||||||
// imgui.KeyZ: sdl.SCANCODE_Z,
|
return newimgui.KeyCapsLock
|
||||||
// }
|
case sdl.SCANCODE_SCROLLLOCK:
|
||||||
|
return newimgui.KeyScrollLock
|
||||||
// // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array.
|
case sdl.SCANCODE_NUMLOCKCLEAR:
|
||||||
// for imguiKey, nativeKey := range keys {
|
return newimgui.KeyNumLock
|
||||||
// imIO.KeyMap(imguiKey, nativeKey)
|
case sdl.SCANCODE_PRINTSCREEN:
|
||||||
// }
|
return newimgui.KeyPrintScreen
|
||||||
|
case sdl.SCANCODE_PAUSE:
|
||||||
// return imguiInfo
|
return newimgui.KeyPause
|
||||||
// }
|
case sdl.SCANCODE_KP_0:
|
||||||
|
return newimgui.KeyKeypad0
|
||||||
|
case sdl.SCANCODE_KP_1:
|
||||||
|
return newimgui.KeyKeypad1
|
||||||
|
case sdl.SCANCODE_KP_2:
|
||||||
|
return newimgui.KeyKeypad2
|
||||||
|
case sdl.SCANCODE_KP_3:
|
||||||
|
return newimgui.KeyKeypad3
|
||||||
|
case sdl.SCANCODE_KP_4:
|
||||||
|
return newimgui.KeyKeypad4
|
||||||
|
case sdl.SCANCODE_KP_5:
|
||||||
|
return newimgui.KeyKeypad5
|
||||||
|
case sdl.SCANCODE_KP_6:
|
||||||
|
return newimgui.KeyKeypad6
|
||||||
|
case sdl.SCANCODE_KP_7:
|
||||||
|
return newimgui.KeyKeypad7
|
||||||
|
case sdl.SCANCODE_KP_8:
|
||||||
|
return newimgui.KeyKeypad8
|
||||||
|
case sdl.SCANCODE_KP_9:
|
||||||
|
return newimgui.KeyKeypad9
|
||||||
|
case sdl.SCANCODE_KP_PERIOD:
|
||||||
|
return newimgui.KeyKeypadDecimal
|
||||||
|
case sdl.SCANCODE_KP_DIVIDE:
|
||||||
|
return newimgui.KeyKeypadDivide
|
||||||
|
case sdl.SCANCODE_KP_MULTIPLY:
|
||||||
|
return newimgui.KeyKeypadMultiply
|
||||||
|
case sdl.SCANCODE_KP_MINUS:
|
||||||
|
return newimgui.KeyKeypadSubtract
|
||||||
|
case sdl.SCANCODE_KP_PLUS:
|
||||||
|
return newimgui.KeyKeypadAdd
|
||||||
|
case sdl.SCANCODE_KP_ENTER:
|
||||||
|
return newimgui.KeyKeypadEnter
|
||||||
|
case sdl.SCANCODE_KP_EQUALS:
|
||||||
|
return newimgui.KeyKeypadEqual
|
||||||
|
case sdl.SCANCODE_LSHIFT:
|
||||||
|
return newimgui.KeyLeftShift
|
||||||
|
case sdl.SCANCODE_LCTRL:
|
||||||
|
return newimgui.KeyLeftCtrl
|
||||||
|
case sdl.SCANCODE_LALT:
|
||||||
|
return newimgui.KeyLeftAlt
|
||||||
|
case sdl.SCANCODE_LGUI:
|
||||||
|
return newimgui.KeyLeftSuper
|
||||||
|
case sdl.SCANCODE_RSHIFT:
|
||||||
|
return newimgui.KeyRightShift
|
||||||
|
case sdl.SCANCODE_RCTRL:
|
||||||
|
return newimgui.KeyRightCtrl
|
||||||
|
case sdl.SCANCODE_RALT:
|
||||||
|
return newimgui.KeyRightAlt
|
||||||
|
case sdl.SCANCODE_RGUI:
|
||||||
|
return newimgui.KeyRightSuper
|
||||||
|
case sdl.SCANCODE_MENU:
|
||||||
|
return newimgui.KeyMenu
|
||||||
|
case sdl.SCANCODE_0:
|
||||||
|
return newimgui.Key0
|
||||||
|
case sdl.SCANCODE_1:
|
||||||
|
return newimgui.Key1
|
||||||
|
case sdl.SCANCODE_2:
|
||||||
|
return newimgui.Key2
|
||||||
|
case sdl.SCANCODE_3:
|
||||||
|
return newimgui.Key3
|
||||||
|
case sdl.SCANCODE_4:
|
||||||
|
return newimgui.Key4
|
||||||
|
case sdl.SCANCODE_5:
|
||||||
|
return newimgui.Key5
|
||||||
|
case sdl.SCANCODE_6:
|
||||||
|
return newimgui.Key6
|
||||||
|
case sdl.SCANCODE_7:
|
||||||
|
return newimgui.Key7
|
||||||
|
case sdl.SCANCODE_8:
|
||||||
|
return newimgui.Key8
|
||||||
|
case sdl.SCANCODE_9:
|
||||||
|
return newimgui.Key9
|
||||||
|
case sdl.SCANCODE_A:
|
||||||
|
return newimgui.KeyA
|
||||||
|
case sdl.SCANCODE_B:
|
||||||
|
return newimgui.KeyB
|
||||||
|
case sdl.SCANCODE_C:
|
||||||
|
return newimgui.KeyC
|
||||||
|
case sdl.SCANCODE_D:
|
||||||
|
return newimgui.KeyD
|
||||||
|
case sdl.SCANCODE_E:
|
||||||
|
return newimgui.KeyE
|
||||||
|
case sdl.SCANCODE_F:
|
||||||
|
return newimgui.KeyF
|
||||||
|
case sdl.SCANCODE_G:
|
||||||
|
return newimgui.KeyG
|
||||||
|
case sdl.SCANCODE_H:
|
||||||
|
return newimgui.KeyH
|
||||||
|
case sdl.SCANCODE_I:
|
||||||
|
return newimgui.KeyI
|
||||||
|
case sdl.SCANCODE_J:
|
||||||
|
return newimgui.KeyJ
|
||||||
|
case sdl.SCANCODE_K:
|
||||||
|
return newimgui.KeyK
|
||||||
|
case sdl.SCANCODE_L:
|
||||||
|
return newimgui.KeyL
|
||||||
|
case sdl.SCANCODE_M:
|
||||||
|
return newimgui.KeyM
|
||||||
|
case sdl.SCANCODE_N:
|
||||||
|
return newimgui.KeyN
|
||||||
|
case sdl.SCANCODE_O:
|
||||||
|
return newimgui.KeyO
|
||||||
|
case sdl.SCANCODE_P:
|
||||||
|
return newimgui.KeyP
|
||||||
|
case sdl.SCANCODE_Q:
|
||||||
|
return newimgui.KeyQ
|
||||||
|
case sdl.SCANCODE_R:
|
||||||
|
return newimgui.KeyR
|
||||||
|
case sdl.SCANCODE_S:
|
||||||
|
return newimgui.KeyS
|
||||||
|
case sdl.SCANCODE_T:
|
||||||
|
return newimgui.KeyT
|
||||||
|
case sdl.SCANCODE_U:
|
||||||
|
return newimgui.KeyU
|
||||||
|
case sdl.SCANCODE_V:
|
||||||
|
return newimgui.KeyV
|
||||||
|
case sdl.SCANCODE_W:
|
||||||
|
return newimgui.KeyW
|
||||||
|
case sdl.SCANCODE_X:
|
||||||
|
return newimgui.KeyX
|
||||||
|
case sdl.SCANCODE_Y:
|
||||||
|
return newimgui.KeyY
|
||||||
|
case sdl.SCANCODE_Z:
|
||||||
|
return newimgui.KeyZ
|
||||||
|
case sdl.SCANCODE_F1:
|
||||||
|
return newimgui.KeyF1
|
||||||
|
case sdl.SCANCODE_F2:
|
||||||
|
return newimgui.KeyF2
|
||||||
|
case sdl.SCANCODE_F3:
|
||||||
|
return newimgui.KeyF3
|
||||||
|
case sdl.SCANCODE_F4:
|
||||||
|
return newimgui.KeyF4
|
||||||
|
case sdl.SCANCODE_F5:
|
||||||
|
return newimgui.KeyF5
|
||||||
|
case sdl.SCANCODE_F6:
|
||||||
|
return newimgui.KeyF6
|
||||||
|
case sdl.SCANCODE_F7:
|
||||||
|
return newimgui.KeyF7
|
||||||
|
case sdl.SCANCODE_F8:
|
||||||
|
return newimgui.KeyF8
|
||||||
|
case sdl.SCANCODE_F9:
|
||||||
|
return newimgui.KeyF9
|
||||||
|
case sdl.SCANCODE_F10:
|
||||||
|
return newimgui.KeyF10
|
||||||
|
case sdl.SCANCODE_F11:
|
||||||
|
return newimgui.KeyF11
|
||||||
|
case sdl.SCANCODE_F12:
|
||||||
|
return newimgui.KeyF12
|
||||||
|
default:
|
||||||
|
return newimgui.KeyNone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user