mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
internal/ui: refactoring: add userInterfaceImplNative for each OS
This commit is contained in:
parent
d0fa68691c
commit
a57560105f
@ -65,8 +65,6 @@ type userInterfaceImpl struct {
|
||||
maxWindowHeightInDIP int
|
||||
|
||||
running uint32
|
||||
origWindowPosX int
|
||||
origWindowPosY int
|
||||
runnableOnUnfocused bool
|
||||
fpsMode FPSModeType
|
||||
iconImages []image.Image
|
||||
@ -117,6 +115,8 @@ type userInterfaceImpl struct {
|
||||
// t is the main thread == the rendering thread.
|
||||
t thread.Thread
|
||||
m sync.RWMutex
|
||||
|
||||
native userInterfaceImplNative
|
||||
}
|
||||
|
||||
const (
|
||||
@ -132,8 +132,6 @@ func init() {
|
||||
minWindowHeightInDIP: glfw.DontCare,
|
||||
maxWindowWidthInDIP: glfw.DontCare,
|
||||
maxWindowHeightInDIP: glfw.DontCare,
|
||||
origWindowPosX: invalidPos,
|
||||
origWindowPosY: invalidPos,
|
||||
initCursorMode: CursorModeVisible,
|
||||
initWindowDecorated: true,
|
||||
initWindowPositionXInDIP: invalidPos,
|
||||
@ -143,6 +141,7 @@ func init() {
|
||||
initFocused: true,
|
||||
fpsMode: FPSModeVsyncOn,
|
||||
}
|
||||
theUI.native.initialize()
|
||||
theUI.input.ui = &theUI.userInterfaceImpl
|
||||
theUI.iwindow.ui = &theUI.userInterfaceImpl
|
||||
}
|
||||
@ -1662,23 +1661,6 @@ func (u *userInterfaceImpl) setWindowTitle(title string) {
|
||||
u.window.SetTitle(title)
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) origWindowPos() (int, int) {
|
||||
if x, y, ok := u.origWindowPosByOS(); ok {
|
||||
return x, y
|
||||
}
|
||||
return u.origWindowPosX, u.origWindowPosY
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) setOrigWindowPos(x, y int) {
|
||||
// TODO: The original position should be updated at a 'PosCallback'.
|
||||
|
||||
if u.setOrigWindowPosByOS(x, y) {
|
||||
return
|
||||
}
|
||||
u.origWindowPosX = x
|
||||
u.origWindowPosY = y
|
||||
}
|
||||
|
||||
// forceToRefreshIfNeeded forces to refresh the framebuffer by resizing the window quickly.
|
||||
// This is a very dirty but necessary hack for DirectX (#2050).
|
||||
// With DirectX, the framebuffer is not rendered correctly when the window is resized by dragging
|
||||
|
@ -287,6 +287,9 @@ func (*graphicsDriverCreatorImpl) newMetal() (graphicsdriver.Graphics, error) {
|
||||
// clearVideoModeScaleCache must be called from the main thread.
|
||||
func clearVideoModeScaleCache() {}
|
||||
|
||||
type userInterfaceImplNative struct {
|
||||
}
|
||||
|
||||
// dipFromGLFWMonitorPixel must be called from the main thread.
|
||||
func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 {
|
||||
return x
|
||||
@ -391,23 +394,25 @@ func initializeWindowAfterCreation(w *glfw.Window) {
|
||||
C.initializeWindow(C.uintptr_t(w.GetCocoaWindow()))
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) origWindowPosByOS() (int, int, bool) {
|
||||
func (u *userInterfaceImpl) origWindowPos() (int, int) {
|
||||
if !u.isNativeFullscreen() {
|
||||
return invalidPos, invalidPos, true
|
||||
return invalidPos, invalidPos
|
||||
}
|
||||
var cx, cy C.int
|
||||
C.windowOriginalPosition(C.uintptr_t(u.window.GetCocoaWindow()), &cx, &cy)
|
||||
x := int(cx)
|
||||
y := flipY(int(cy)) - u.windowHeightInDIP
|
||||
return x, y, true
|
||||
return x, y
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) setOrigWindowPosByOS(x, y int) bool {
|
||||
func (u *userInterfaceImpl) setOrigWindowPos(x, y int) {
|
||||
if !u.isNativeFullscreen() {
|
||||
return true
|
||||
return
|
||||
}
|
||||
cx := C.int(x)
|
||||
cy := C.int(flipY(y + u.windowHeightInDIP))
|
||||
C.setWindowOriginalPosition(C.uintptr_t(u.window.GetCocoaWindow()), cx, cy)
|
||||
return true
|
||||
}
|
||||
|
||||
func (u *userInterfaceImplNative) initialize() {
|
||||
}
|
||||
|
@ -142,6 +142,11 @@ func videoModeScaleUncached(m *glfw.Monitor) float64 {
|
||||
return 1
|
||||
}
|
||||
|
||||
type userInterfaceImplNative struct {
|
||||
origWindowPosX int
|
||||
origWindowPosY int
|
||||
}
|
||||
|
||||
// dipFromGLFWMonitorPixel must be called from the main thread.
|
||||
func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 {
|
||||
return x / (videoModeScale(monitor) * u.deviceScaleFactor(monitor))
|
||||
@ -231,10 +236,16 @@ func initializeWindowAfterCreation(w *glfw.Window) {
|
||||
// For more details, see the discussion in #1829.
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) origWindowPosByOS() (int, int, bool) {
|
||||
return 0, 0, false
|
||||
func (u *userInterfaceImpl) origWindowPos() (int, int) {
|
||||
return u.native.origWindowPosX, u.native.origWindowPosY
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) setOrigWindowPosByOS(x, y int) bool {
|
||||
return false
|
||||
func (u *userInterfaceImpl) setOrigWindowPos(x, y int) {
|
||||
u.native.origWindowPosX = x
|
||||
u.native.origWindowPosY = y
|
||||
}
|
||||
|
||||
func (u *userInterfaceImplNative) initialize() {
|
||||
u.native.origWindowPosX = invalidPos
|
||||
u.native.origWindowPosY = invalidPos
|
||||
}
|
||||
|
@ -137,6 +137,11 @@ func _GetCursorPos() (int32, int32, error) {
|
||||
return pt.x, pt.y, nil
|
||||
}
|
||||
|
||||
type userInterfaceImplNative struct {
|
||||
origWindowPosX int
|
||||
origWindowPosY int
|
||||
}
|
||||
|
||||
// clearVideoModeScaleCache must be called from the main thread.
|
||||
func clearVideoModeScaleCache() {}
|
||||
|
||||
@ -262,10 +267,16 @@ func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode)
|
||||
func initializeWindowAfterCreation(w *glfw.Window) {
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) origWindowPosByOS() (int, int, bool) {
|
||||
return 0, 0, false
|
||||
func (u *userInterfaceImpl) origWindowPos() (int, int) {
|
||||
return u.native.origWindowPosX, u.native.origWindowPosY
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) setOrigWindowPosByOS(x, y int) bool {
|
||||
return false
|
||||
func (u *userInterfaceImpl) setOrigWindowPos(x, y int) {
|
||||
u.native.origWindowPosX = x
|
||||
u.native.origWindowPosY = y
|
||||
}
|
||||
|
||||
func (u *userInterfaceImplNative) initialize() {
|
||||
u.origWindowPosX = invalidPos
|
||||
u.origWindowPosY = invalidPos
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user