2019-12-24 16:05:56 +01:00
|
|
|
// Copyright 2019 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2023-10-01 16:14:47 +02:00
|
|
|
//go:build !android && !ios && !js && !nintendosdk && !playstation5
|
2019-12-24 16:05:56 +01:00
|
|
|
|
2022-02-06 08:08:22 +01:00
|
|
|
package ui
|
2019-12-24 16:05:56 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2022-08-15 09:22:28 +02:00
|
|
|
"runtime"
|
2019-12-24 16:05:56 +01:00
|
|
|
|
2020-10-03 19:35:13 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
2019-12-24 16:05:56 +01:00
|
|
|
)
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
type glfwWindow struct {
|
2023-10-14 19:51:23 +02:00
|
|
|
ui *UserInterface
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) IsDecorated() bool {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return false
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
return w.ui.isInitWindowDecorated()
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
var v bool
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
a, err := w.ui.window.GetAttrib(glfw.Decorated)
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
v = a == glfw.True
|
2019-12-24 16:05:56 +01:00
|
|
|
})
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetDecorated(decorated bool) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
w.ui.setInitWindowDecorated(decorated)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.setWindowDecorated(decorated); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) ResizingMode() WindowResizingMode {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return 0
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
2021-12-29 14:08:59 +01:00
|
|
|
w.ui.m.Lock()
|
|
|
|
mode := w.ui.windowResizingMode
|
|
|
|
w.ui.m.Unlock()
|
|
|
|
return mode
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
2021-12-29 14:08:59 +01:00
|
|
|
var mode WindowResizingMode
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2021-12-29 14:08:59 +01:00
|
|
|
mode = w.ui.windowResizingMode
|
2019-12-24 16:05:56 +01:00
|
|
|
})
|
2021-12-29 14:08:59 +01:00
|
|
|
return mode
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetResizingMode(mode WindowResizingMode) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
2021-12-29 14:08:59 +01:00
|
|
|
w.ui.m.Lock()
|
|
|
|
w.ui.windowResizingMode = mode
|
|
|
|
w.ui.m.Unlock()
|
2019-12-24 16:05:56 +01:00
|
|
|
return
|
|
|
|
}
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.setWindowResizingMode(mode); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) IsFloating() bool {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return false
|
|
|
|
}
|
2020-03-20 13:46:23 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
return w.ui.isInitWindowFloating()
|
|
|
|
}
|
|
|
|
var v bool
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
a, err := w.ui.window.GetAttrib(glfw.Floating)
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
v = a == glfw.True
|
2020-03-20 13:46:23 +01:00
|
|
|
})
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetFloating(floating bool) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2020-03-20 13:46:23 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
w.ui.setInitWindowFloating(floating)
|
|
|
|
return
|
|
|
|
}
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.setWindowFloating(floating); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2020-03-20 13:46:23 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) IsMaximized() bool {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return false
|
|
|
|
}
|
2020-03-21 11:26:28 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
return w.ui.isInitWindowMaximized()
|
|
|
|
}
|
2021-12-29 14:08:59 +01:00
|
|
|
if w.ResizingMode() != WindowResizingModeEnabled {
|
2022-02-10 11:31:38 +01:00
|
|
|
return false
|
|
|
|
}
|
2020-03-21 11:26:28 +01:00
|
|
|
var v bool
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
m, err := w.ui.isWindowMaximized()
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
v = m
|
2020-03-21 11:26:28 +01:00
|
|
|
})
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) Maximize() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-10 11:31:38 +01:00
|
|
|
// Do not allow maximizing the window when the window is not resizable.
|
|
|
|
// On Windows, it is possible to restore the window from being maximized by mouse-dragging,
|
2022-08-10 15:18:53 +02:00
|
|
|
// and this can be an unexpected behavior (#1990).
|
2021-12-29 14:08:59 +01:00
|
|
|
if w.ResizingMode() != WindowResizingModeEnabled {
|
2022-08-10 15:18:53 +02:00
|
|
|
return
|
2022-08-20 15:24:08 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:34:17 +02:00
|
|
|
if !w.ui.isWindowMaximizable() {
|
2022-08-20 15:24:08 +02:00
|
|
|
return
|
2020-03-28 14:00:40 +01:00
|
|
|
}
|
2022-08-10 15:18:53 +02:00
|
|
|
|
2020-03-21 11:26:28 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
w.ui.setInitWindowMaximized(true)
|
|
|
|
return
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
w.ui.mainThread.Call(func() {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.maximizeWindow(); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
})
|
2020-03-21 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) IsMinimized() bool {
|
2020-03-21 11:26:28 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
var v bool
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
a, err := w.ui.window.GetAttrib(glfw.Iconified)
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
v = a == glfw.True
|
2020-03-21 11:26:28 +01:00
|
|
|
})
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) Minimize() {
|
2020-03-21 11:26:28 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
// Do nothing
|
|
|
|
return
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
w.ui.mainThread.Call(func() {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.iconifyWindow(); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
})
|
2020-03-21 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) Restore() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2022-09-01 15:34:17 +02:00
|
|
|
if !w.ui.isWindowMaximizable() {
|
2022-08-20 15:35:57 +02:00
|
|
|
return
|
|
|
|
}
|
2020-03-21 11:26:28 +01:00
|
|
|
if !w.ui.isRunning() {
|
|
|
|
// Do nothing
|
|
|
|
return
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
w.ui.mainThread.Call(func() {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.restoreWindow(); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
})
|
2020-03-21 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
2023-08-30 14:02:04 +02:00
|
|
|
func (w *glfwWindow) SetMonitor(monitor *Monitor) {
|
|
|
|
if monitor == nil {
|
|
|
|
panic("ui: monitor cannot be nil at SetMonitor")
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-08-30 14:02:04 +02:00
|
|
|
if !w.ui.isRunning() {
|
2023-09-23 10:27:57 +02:00
|
|
|
w.ui.setInitMonitor(monitor)
|
2023-08-30 14:02:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.setWindowMonitor(monitor); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2023-08-30 14:02:04 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) Position() (int, int) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return 0, 0
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
2022-02-06 08:08:22 +01:00
|
|
|
panic("ui: WindowPosition can't be called before the main loop starts")
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
var x, y int
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
f, err := w.ui.isFullscreen()
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-24 16:05:56 +01:00
|
|
|
var wx, wy int
|
2023-10-03 16:07:53 +02:00
|
|
|
if f {
|
2022-04-08 08:59:16 +02:00
|
|
|
wx, wy = w.ui.origWindowPos()
|
2019-12-24 16:05:56 +01:00
|
|
|
} else {
|
2023-10-03 16:07:53 +02:00
|
|
|
x, y, err := w.ui.window.GetPos()
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
wx, wy = x, y
|
|
|
|
}
|
|
|
|
m, err := w.ui.currentMonitor()
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
2023-09-29 17:20:59 +02:00
|
|
|
wx -= m.boundsInGLFWPixels.Min.X
|
|
|
|
wy -= m.boundsInGLFWPixels.Min.Y
|
2024-03-03 15:27:02 +01:00
|
|
|
s := m.DeviceScaleFactor()
|
|
|
|
xf := dipFromGLFWPixel(float64(wx), s)
|
|
|
|
yf := dipFromGLFWPixel(float64(wy), s)
|
2019-12-24 16:05:56 +01:00
|
|
|
x, y = int(xf), int(yf)
|
|
|
|
})
|
|
|
|
return x, y
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetPosition(x, y int) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
2021-10-10 08:38:13 +02:00
|
|
|
w.ui.setInitWindowPositionInDIP(x, y)
|
2019-12-24 16:05:56 +01:00
|
|
|
return
|
|
|
|
}
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
m, err := w.ui.currentMonitor()
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := w.ui.setWindowPositionInDIP(x, y, m); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) Size() (int, int) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return 0, 0
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
2021-10-10 08:38:13 +02:00
|
|
|
ww, wh := w.ui.getInitWindowSizeInDIP()
|
|
|
|
return w.ui.adjustWindowSizeBasedOnSizeLimitsInDIP(ww, wh)
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
2022-08-10 06:28:46 +02:00
|
|
|
var ww, wh int
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2022-09-24 19:03:27 +02:00
|
|
|
// Unlike origWindowPos, origWindow{Width,Height}InDPI are always updated via the callback.
|
|
|
|
ww = w.ui.origWindowWidthInDIP
|
|
|
|
wh = w.ui.origWindowHeightInDIP
|
2021-04-20 12:35:52 +02:00
|
|
|
})
|
2019-12-24 16:05:56 +01:00
|
|
|
return ww, wh
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetSize(width, height int) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
2022-08-15 09:22:28 +02:00
|
|
|
// If the window is initially maximized, the set size is ignored anyway.
|
2021-10-10 08:38:13 +02:00
|
|
|
w.ui.setInitWindowSizeInDIP(width, height)
|
2019-12-24 16:05:56 +01:00
|
|
|
return
|
|
|
|
}
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
m, err := w.ui.isWindowMaximized()
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if m && runtime.GOOS != "darwin" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := w.ui.setWindowSizeInDIP(width, height, true); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2022-08-15 09:22:28 +02:00
|
|
|
return
|
|
|
|
}
|
2020-10-16 21:21:07 +02:00
|
|
|
})
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SizeLimits() (minw, minh, maxw, maxh int) {
|
2021-10-10 08:38:13 +02:00
|
|
|
return w.ui.getWindowSizeLimitsInDIP()
|
2021-04-16 19:27:04 +02:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetSizeLimits(minw, minh, maxw, maxh int) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2021-10-10 08:38:13 +02:00
|
|
|
if !w.ui.setWindowSizeLimitsInDIP(minw, minh, maxw, maxh) {
|
2021-04-16 19:27:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if !w.ui.isRunning() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-09-02 08:24:59 +02:00
|
|
|
w.ui.mainThread.Call(func() {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.updateWindowSizeLimits(); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2023-09-02 08:24:59 +02:00
|
|
|
})
|
2021-04-16 19:27:04 +02:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetIcon(iconImages []image.Image) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2021-02-07 13:16:09 +01:00
|
|
|
// The icons are actually set at (*UserInterface).loop.
|
|
|
|
w.ui.setIconImages(iconImages)
|
2019-12-24 16:05:56 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetTitle(title string) {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
if !w.ui.isRunning() {
|
2021-12-29 14:26:56 +01:00
|
|
|
w.ui.m.Lock()
|
|
|
|
w.ui.title = title
|
|
|
|
w.ui.m.Unlock()
|
2019-12-24 16:05:56 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
w.ui.title = title
|
2022-12-28 07:59:53 +01:00
|
|
|
w.ui.mainThread.Call(func() {
|
2023-09-02 08:24:59 +02:00
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.setWindowTitle(title); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2019-12-24 16:05:56 +01:00
|
|
|
})
|
|
|
|
}
|
2021-06-13 13:52:14 +02:00
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) SetClosingHandled(handled bool) {
|
2021-06-13 13:52:14 +02:00
|
|
|
w.ui.setWindowClosingHandled(handled)
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:26:28 +02:00
|
|
|
func (w *glfwWindow) IsClosingHandled() bool {
|
2021-06-13 13:52:14 +02:00
|
|
|
return w.ui.isWindowClosingHandled()
|
|
|
|
}
|
2023-09-18 10:48:07 +02:00
|
|
|
|
|
|
|
func (w *glfwWindow) SetMousePassthrough(enabled bool) {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !w.ui.isRunning() {
|
|
|
|
w.ui.setInitWindowMousePassthrough(enabled)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.ui.mainThread.Call(func() {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
if err := w.ui.setWindowMousePassthrough(enabled); err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
2023-09-18 10:48:07 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *glfwWindow) IsMousePassthrough() bool {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !w.ui.isRunning() {
|
|
|
|
return w.ui.isInitWindowMousePassthrough()
|
|
|
|
}
|
|
|
|
var v bool
|
|
|
|
w.ui.mainThread.Call(func() {
|
|
|
|
if w.ui.isTerminated() {
|
|
|
|
return
|
|
|
|
}
|
2023-10-03 16:07:53 +02:00
|
|
|
a, err := w.ui.window.GetAttrib(glfw.MousePassthrough)
|
|
|
|
if err != nil {
|
2023-10-15 08:50:39 +02:00
|
|
|
w.ui.setError(err)
|
2023-10-03 16:07:53 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
v = a == glfw.True
|
2023-09-18 10:48:07 +02:00
|
|
|
})
|
|
|
|
return v
|
|
|
|
}
|