create error constants, hookup imgui_backend init and shutdown
This commit is contained in:
parent
dd39ca8b8d
commit
6736cc5067
@ -18,9 +18,14 @@ var (
|
||||
imguiContext *imgui.Context
|
||||
)
|
||||
|
||||
var (
|
||||
ErrAlreadyInit = errors.New("imgui backend is already initialized")
|
||||
ErrWasNotInit = errors.New("imgui backend was not initialized")
|
||||
)
|
||||
|
||||
func Init() error {
|
||||
if imguiIsInit {
|
||||
return errors.New("imgui backend is already initialized")
|
||||
return ErrAlreadyInit
|
||||
}
|
||||
|
||||
imguiContext = imgui.CreateContext(nil)
|
||||
@ -56,14 +61,14 @@ func Init() error {
|
||||
}
|
||||
|
||||
imguiFontTexture = createFontTexture()
|
||||
|
||||
imguiIsInit = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Shutdown() error {
|
||||
if !imguiIsInit {
|
||||
return errors.New("imgui backend was not initialized")
|
||||
return ErrWasNotInit
|
||||
}
|
||||
|
||||
imguiIsInit = false
|
||||
@ -79,7 +84,7 @@ func Shutdown() error {
|
||||
|
||||
func NewFrame(windowSize math.Vec2i) error {
|
||||
if !imguiIsInit {
|
||||
return errors.New("imgui backend was not initialized")
|
||||
return ErrWasNotInit
|
||||
}
|
||||
|
||||
// Setup display size (every frame to accommodate for window resizing)
|
||||
@ -116,7 +121,7 @@ func NewFrame(windowSize math.Vec2i) error {
|
||||
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
||||
func ProcessEvent(event sdl.Event) (bool, error) {
|
||||
if !imguiIsInit {
|
||||
return false, errors.New("imgui backend was not initialized")
|
||||
return false, ErrWasNotInit
|
||||
}
|
||||
|
||||
switch io := imgui.CurrentIO(); event.GetType() {
|
||||
@ -176,7 +181,7 @@ func ProcessEvent(event sdl.Event) (bool, error) {
|
||||
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
|
||||
func Render(windowSize, fbSize math.Vec2i, drawData imgui.DrawData) error {
|
||||
if !imguiIsInit {
|
||||
return errors.New("imgui backend was not initialized")
|
||||
return ErrWasNotInit
|
||||
}
|
||||
|
||||
drawData.ScaleClipRects(imgui.Vec2{
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/FooSoft/lazarus/platform/imgui_backend"
|
||||
"github.com/go-gl/gl/v2.1/gl"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
@ -14,9 +15,14 @@ var (
|
||||
platformWindows []Window
|
||||
)
|
||||
|
||||
var (
|
||||
ErrAlreadyInit = errors.New("platform is already initialized")
|
||||
ErrWasNotInit = errors.New("platform was not initialized")
|
||||
)
|
||||
|
||||
func Init() error {
|
||||
if platformIsInit {
|
||||
return errors.New("platform is already initialized")
|
||||
return ErrAlreadyInit
|
||||
}
|
||||
|
||||
runtime.LockOSThread()
|
||||
@ -29,13 +35,38 @@ func Init() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := imgui_backend.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
platformIsInit = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func Shutdown() error {
|
||||
if !platformIsInit {
|
||||
return ErrWasNotInit
|
||||
}
|
||||
|
||||
for _, w := range platformWindows {
|
||||
if err := w.Destroy(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := imgui_backend.Shutdown(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
platformWindows = nil
|
||||
platformIsInit = false
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessEvents() error {
|
||||
if !platformIsInit {
|
||||
return errors.New("platform was not initialized")
|
||||
return ErrWasNotInit
|
||||
}
|
||||
|
||||
var terminate bool
|
||||
@ -54,26 +85,9 @@ func ProcessEvents() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Shutdown() error {
|
||||
if !platformIsInit {
|
||||
return errors.New("platform was not initialized")
|
||||
}
|
||||
|
||||
for _, w := range platformWindows {
|
||||
if err := w.Destroy(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
platformWindows = nil
|
||||
platformIsInit = false
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateWindow(title string, width, height int) (Window, error) {
|
||||
if !platformIsInit {
|
||||
return nil, errors.New("platform was not initialized")
|
||||
return nil, ErrWasNotInit
|
||||
}
|
||||
|
||||
window, err := newWindow(title, width, height)
|
||||
|
Loading…
Reference in New Issue
Block a user