Skip to content

hsapp: remove hsinput; use giu implementation of imput handler #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/go-resty/resty/v2 v2.6.0 // indirect
github.com/gravestench/osinfo v0.0.0-20210525170338-34eb1ac010f7
github.com/hajimehoshi/oto v0.7.1 // indirect
github.com/ianling/giu v0.5.1-0.20210524205023-4d3114338b69
github.com/ianling/giu v0.5.1-0.20210619154109-b35b66c84649
github.com/ianling/imgui-go v1.12.1-0.20210420174252-e90a22fb87e6
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
Expand All @@ -25,6 +25,6 @@ require (
golang.org/x/exp v0.0.0-20210526181343-b47a03e3048a // indirect
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e // indirect
golang.org/x/mobile v0.0.0-20210527171505-7e972142eb43 // indirect
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ github.com/hajimehoshi/oto v0.7.1 h1:I7maFPz5MBCwiutOrz++DLdbr4rTzBsbBuV2VpgU9kk
github.com/hajimehoshi/oto v0.7.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos=
github.com/ianling/giu v0.5.1-0.20210524205023-4d3114338b69 h1:8/TnUIv7dy6smaOQiWsOB9MMHbiOgHrllYXRimQPx+Y=
github.com/ianling/giu v0.5.1-0.20210524205023-4d3114338b69/go.mod h1:twqK/c83RuUbBV8sWkV9TMpcdaBs3Pec2FBN5gC+hEA=
github.com/ianling/giu v0.5.1-0.20210619154109-b35b66c84649 h1:V+knrBNqCF2mrLnQRSiS27DwlSlOqzQxwE7Nx0dQCfA=
github.com/ianling/giu v0.5.1-0.20210619154109-b35b66c84649/go.mod h1:twqK/c83RuUbBV8sWkV9TMpcdaBs3Pec2FBN5gC+hEA=
github.com/ianling/imgui-go v1.12.1-0.20210420174252-e90a22fb87e6 h1:cYyhJBJpHS3ccwS/Hn9SI4T3SUzORnfiBvB+/1mopLs=
github.com/ianling/imgui-go v1.12.1-0.20210420174252-e90a22fb87e6/go.mod h1:XJ3IHn74S/5gKA6R5tYya4x7bsucY4tHgfnGO94FmEc=
github.com/jakecoffman/cp v1.0.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
Expand Down Expand Up @@ -162,6 +164,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
6 changes: 1 addition & 5 deletions hsapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/OpenDiablo2/HellSpawner/hscommon/hsfiletypes"
"github.com/OpenDiablo2/HellSpawner/hscommon/hsproject"
"github.com/OpenDiablo2/HellSpawner/hsconfig"
"github.com/OpenDiablo2/HellSpawner/hsinput"
"github.com/OpenDiablo2/HellSpawner/hswindow/hsdialog/hsaboutdialog"
"github.com/OpenDiablo2/HellSpawner/hswindow/hsdialog/hspreferencesdialog"
"github.com/OpenDiablo2/HellSpawner/hswindow/hsdialog/hsprojectpropertiesdialog"
Expand Down Expand Up @@ -95,7 +94,6 @@ type App struct {
diabloBoldFont imgui.Font
diabloRegularFont imgui.Font

InputManager *hsinput.InputManager
TextureLoader hscommon.TextureLoader

showUsage bool
Expand All @@ -108,7 +106,6 @@ func Create() (*App, error) {
editors: make([]hscommon.EditorWindow, 0),
editorConstructors: make(map[hsfiletypes.FileType]editorConstructor),
TextureLoader: hscommon.NewTextureLoader(),
InputManager: hsinput.NewInputManager(),
abyssWrapper: abysswrapper.Create(),
}

Expand All @@ -128,7 +125,7 @@ func (a *App) Run() (err error) {
// setting up the logging here, as opposed to inside of app.setup(),
// because of the deferred call to logfile.Close()
if a.config.LoggingToFile || *a.Flags.logFile != "" {
var path = a.config.LogFilePath
path := a.config.LogFilePath
if *a.Flags.logFile != "" {
path = *a.Flags.logFile
}
Expand Down Expand Up @@ -157,7 +154,6 @@ func (a *App) Run() (err error) {
}
}

a.masterWindow.SetInputCallback(a.InputManager.HandleInput)
a.masterWindow.Run(a.render)

return nil
Expand Down
25 changes: 15 additions & 10 deletions hsapp/menubar.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,26 +354,31 @@ func (a *App) renderEditors() {
if !editor.IsVisible() {
editor.Cleanup()

if editor.HasFocus() {
a.focusedEditor = nil
}

a.editors = append(a.editors[:idx], a.editors[idx+1:]...)

continue
}

hadFocus := editor.HasFocus()

// common shortcut
editor.RegisterKeyboardShortcuts(
g.WindowShortcut{
Key: g.KeyS,
Modifier: g.ModControl,
Callback: func() {
editor.Save()
},
},
)

editor.RegisterKeyboardShortcuts(
editor.KeyboardShortcuts()...,
)

editor.Build()

// if this window didn't have focus before, but it does now,
// unregister any other window's shortcuts, and register this window's keyboard shortcuts instead
if !hadFocus && editor.HasFocus() {
a.InputManager.UnregisterWindowShortcuts()

editor.RegisterKeyboardShortcuts(a.InputManager)

a.focusedEditor = editor
}

Expand Down
30 changes: 16 additions & 14 deletions hsapp/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ func (a *App) setupMainMpqExplorer() error {

func (a *App) setupProjectExplorer() error {
x, y := float32(projectExplorerDefaultX), float32(projectExplorerDefaultY)

window, err := hsprojectexplorer.Create(a.TextureLoader,
a.openEditor, x, y)

if err != nil {
return fmt.Errorf("error creating a project explorer: %w", err)
}
Expand Down Expand Up @@ -248,17 +248,19 @@ func (a *App) setupFonts() {
}

func (a *App) registerGlobalKeyboardShortcuts() {
a.InputManager.RegisterShortcut(a.onNewProjectClicked, g.KeyN, g.ModControl+g.ModShift, true)
a.InputManager.RegisterShortcut(a.onOpenProjectClicked, g.KeyO, g.ModControl, true)
a.InputManager.RegisterShortcut(a.Save, g.KeyS, g.ModControl, true)
a.InputManager.RegisterShortcut(a.onFilePreferencesClicked, g.KeyP, g.ModAlt, true)
a.InputManager.RegisterShortcut(a.Quit, g.KeyQ, g.ModAlt, true)
a.InputManager.RegisterShortcut(a.onHelpAboutClicked, g.KeyF1, g.ModNone, true)

a.InputManager.RegisterShortcut(a.closeActiveEditor, g.KeyW, g.ModControl, true)
a.InputManager.RegisterShortcut(func() { a.closePopups(); a.closeActiveEditor() }, g.KeyEscape, g.ModNone, true)

a.InputManager.RegisterShortcut(a.toggleMPQExplorer, g.KeyM, g.ModControl+g.ModShift, true)
a.InputManager.RegisterShortcut(a.toggleProjectExplorer, g.KeyP, g.ModControl+g.ModShift, true)
a.InputManager.RegisterShortcut(a.toggleConsole, g.KeyC, g.ModControl+g.ModShift, true)
a.masterWindow.RegisterKeyboardShortcuts(
g.WindowShortcut{Key: g.KeyN, Modifier: g.ModControl + g.ModShift, Callback: a.onNewProjectClicked},
g.WindowShortcut{Key: g.KeyO, Modifier: g.ModControl, Callback: a.onOpenProjectClicked},
g.WindowShortcut{Key: g.KeyS, Modifier: g.ModControl, Callback: a.Save},
g.WindowShortcut{Key: g.KeyP, Modifier: g.ModAlt, Callback: a.onFilePreferencesClicked},
g.WindowShortcut{Key: g.KeyQ, Modifier: g.ModAlt, Callback: a.Quit},
g.WindowShortcut{Key: g.KeyF1, Modifier: g.ModNone, Callback: a.onHelpAboutClicked},

g.WindowShortcut{Key: g.KeyW, Modifier: g.ModControl, Callback: a.closeActiveEditor},
g.WindowShortcut{Key: g.KeyEscape, Modifier: g.ModNone, Callback: func() { a.closePopups(); a.closeActiveEditor() }},

g.WindowShortcut{Key: g.KeyM, Modifier: g.ModControl + g.ModShift, Callback: a.toggleMPQExplorer},
g.WindowShortcut{Key: g.KeyP, Modifier: g.ModControl + g.ModShift, Callback: a.toggleProjectExplorer},
g.WindowShortcut{Key: g.KeyC, Modifier: g.ModControl + g.ModShift, Callback: a.toggleConsole},
)
}
9 changes: 5 additions & 4 deletions hscommon/renderable.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package hscommon

import (
"github.com/OpenDiablo2/HellSpawner/hsinput"
)
import "github.com/ianling/giu"

// Renderable represents renderable objects
type Renderable interface {
Build()
Cleanup()
RegisterKeyboardShortcuts(inputManager *hsinput.InputManager)
// KeyboardShortcuts returns a list of keyboard shortcuts
KeyboardShortcuts() []giu.WindowShortcut
IsVisible() bool
// RegisterKeyboardShortcuts wraps giu.RegisterKeyboardShortcuts
RegisterKeyboardShortcuts(...giu.WindowShortcut)
}
97 changes: 0 additions & 97 deletions hsinput/input_handler.go

This file was deleted.

100 changes: 0 additions & 100 deletions hsinput/input_handler_test.go

This file was deleted.

Loading