1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-10 14:26:15 -05:00
OpenDiablo2/d2core/d2render/d2render.go

107 lines
2.8 KiB
Go
Raw Normal View History

package d2render
import (
"errors"
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
var (
// ErrWasInit holding an error instance for initialized rendering system
ErrWasInit = errors.New("rendering system is already initialized")
// ErrNotInit holding an error instance for non-initialized rendering system
ErrNotInit = errors.New("rendering system has not been initialized")
// ErrInvalidRenderer holding an error instance for invalid rendering system specification
ErrInvalidRenderer = errors.New("invalid rendering system specified")
)
var singleton d2interface.Renderer
// Initialize the renderer
func Initialize(rend d2interface.Renderer) error {
2020-02-09 14:12:04 -05:00
verifyNotInit()
singleton = rend
log.Printf("Initialized the %s renderer...", singleton.GetRendererName())
return nil
}
// SetWindowIcon sets the window icon by a given file name as string
2020-02-09 14:12:04 -05:00
func SetWindowIcon(fileName string) {
verifyWasInit()
singleton.SetWindowIcon(fileName)
}
// Run will run the renderer
func Run(f func(d2interface.Surface) error, width, height int, title string) error {
2020-02-09 14:12:04 -05:00
verifyWasInit()
singleton.Run(f, width, height, title)
return nil
}
// IsDrawingSkipped checks whether the drawing is skipped
2020-02-09 14:12:04 -05:00
func IsDrawingSkipped() bool {
verifyWasInit()
return singleton.IsDrawingSkipped()
}
// CreateSurface creates a new surface, which returns the newly created surface or error
func CreateSurface(surface d2interface.Surface) (d2interface.Surface, error) {
2020-02-09 14:12:04 -05:00
verifyWasInit()
return singleton.CreateSurface(surface)
}
// NewSurface adds a new surface, and returns the new surface or error
func NewSurface(width, height int, filter d2interface.Filter) (d2interface.Surface, error) {
2020-02-09 14:12:04 -05:00
verifyWasInit()
return singleton.NewSurface(width, height, filter)
}
// IsFullScreen checks whether the window is on full screen
2020-02-09 14:12:04 -05:00
func IsFullScreen() bool {
verifyWasInit()
return singleton.IsFullScreen()
}
// SetFullScreen sets the window in fullscreen or windowed mode depending on the fullScreen flag
2020-02-09 14:12:04 -05:00
func SetFullScreen(fullScreen bool) {
verifyWasInit()
singleton.SetFullScreen(fullScreen)
}
// SetVSyncEnabled sets or unsets the VSync depending on the given vsync parameter flag
2020-02-09 14:12:04 -05:00
func SetVSyncEnabled(vsync bool) {
verifyWasInit()
singleton.SetVSyncEnabled(vsync)
}
// GetVSyncEnabled checks whether the VSync is enabled or not
2020-02-09 14:12:04 -05:00
func GetVSyncEnabled() bool {
verifyWasInit()
return singleton.GetVSyncEnabled()
}
// GetCursorPos returns the exact current position of the cursor
2020-02-09 14:12:04 -05:00
func GetCursorPos() (int, int) {
verifyWasInit()
return singleton.GetCursorPos()
}
// CurrentFPS returns the current frames per second
2020-02-09 14:12:04 -05:00
func CurrentFPS() float64 {
verifyWasInit()
return singleton.CurrentFPS()
}
func verifyWasInit() {
if singleton == nil {
2020-02-09 14:12:04 -05:00
panic(ErrNotInit)
}
}
func verifyNotInit() {
if singleton != nil {
panic(ErrWasInit)
}
}