mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/glfwwin: split GDK part to a new package internal/microsoftgdk
Updates #1162
This commit is contained in:
parent
7f46938ff7
commit
ad380a32f4
@ -9,6 +9,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
)
|
||||
|
||||
func findPixelFormatAttribValue(attribs []int32, values []int32, attrib int32) int32 {
|
||||
@ -329,7 +331,7 @@ func destroyContextWGL(window *Window) error {
|
||||
}
|
||||
|
||||
func initWGL() error {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return fmt.Errorf("glfwwin: WGL is not available in Xbox")
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
)
|
||||
|
||||
func createKeyTables() {
|
||||
@ -168,7 +170,7 @@ func createHelperWindow() error {
|
||||
_ShowWindow(_glfw.win32.helperWindowHandle, _SW_HIDE)
|
||||
|
||||
// Register for HID device notifications
|
||||
if !isXbox() {
|
||||
if !microsoftgdk.IsXbox() {
|
||||
_GUID_DEVINTERFACE_HID := windows.GUID{
|
||||
Data1: 0x4d1e55b2,
|
||||
Data2: 0xf16f,
|
||||
@ -238,7 +240,7 @@ func platformInit() error {
|
||||
createKeyTables()
|
||||
|
||||
if isWindows10CreatorsUpdateOrGreaterWin32() {
|
||||
if !isXbox() {
|
||||
if !microsoftgdk.IsXbox() {
|
||||
if err := _SetProcessDpiAwarenessContext(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); err != nil && !errors.Is(err, windows.ERROR_ACCESS_DENIED) {
|
||||
return err
|
||||
}
|
||||
@ -258,10 +260,10 @@ func platformInit() error {
|
||||
if err := createHelperWindow(); err != nil {
|
||||
return err
|
||||
}
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
// On Xbox, APIs to get monitors are not available.
|
||||
// Create a pseudo monitor instance instead.
|
||||
w, h := monitorResolution()
|
||||
w, h := microsoftgdk.MonitorResolution()
|
||||
mode := &VidMode{
|
||||
Width: w,
|
||||
Height: h,
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
)
|
||||
|
||||
func monitorCallback(handle _HMONITOR, dc _HDC, rect *_RECT, monitor *Monitor /* _LPARAM */) uintptr /* _BOOL */ {
|
||||
@ -66,7 +68,7 @@ func createMonitor(adapter *_DISPLAY_DEVICEW, display *_DISPLAY_DEVICEW) (*Monit
|
||||
}
|
||||
|
||||
func pollMonitorsWin32() error {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -234,7 +236,7 @@ func getMonitorContentScaleWin32(handle _HMONITOR) (xscale, yscale float32, err
|
||||
}
|
||||
|
||||
func (m *Monitor) platformGetMonitorPos() (xpos, ypos int, ok bool) {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return 0, 0, true
|
||||
}
|
||||
|
||||
@ -246,7 +248,7 @@ func (m *Monitor) platformGetMonitorPos() (xpos, ypos int, ok bool) {
|
||||
}
|
||||
|
||||
func (m *Monitor) platformGetMonitorContentScale() (xscale, yscale float32, err error) {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return 1, 1, nil
|
||||
}
|
||||
|
||||
@ -254,8 +256,8 @@ func (m *Monitor) platformGetMonitorContentScale() (xscale, yscale float32, err
|
||||
}
|
||||
|
||||
func (m *Monitor) platformGetMonitorWorkarea() (xpos, ypos, width, height int) {
|
||||
if isXbox() {
|
||||
w, h := monitorResolution()
|
||||
if microsoftgdk.IsXbox() {
|
||||
w, h := microsoftgdk.MonitorResolution()
|
||||
return 0, 0, w, h
|
||||
}
|
||||
|
||||
@ -320,7 +322,7 @@ loop:
|
||||
}
|
||||
|
||||
func (m *Monitor) platformGetVideoMode() *VidMode {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return m.modes[0]
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
)
|
||||
|
||||
func (w *Window) getWindowStyle() uint32 {
|
||||
@ -122,7 +124,7 @@ func createIcon(image *Image, xhot, yhot int, icon bool) (_HICON, error) {
|
||||
}
|
||||
|
||||
func getFullWindowSize(style uint32, exStyle uint32, contentWidth, contentHeight int, dpi uint32) (fullWidth, fullHeight int, err error) {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return contentWidth, contentHeight, nil
|
||||
}
|
||||
|
||||
@ -718,7 +720,7 @@ func windowProc(hWnd windows.HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM)
|
||||
|
||||
scancode := uint32((_HIWORD(uint32(lParam)) & (_KF_EXTENDED | 0xff)))
|
||||
if scancode == 0 {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
break
|
||||
}
|
||||
// NOTE: Some synthetic key messages have a scancode of zero
|
||||
@ -1215,7 +1217,7 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er
|
||||
|
||||
handleToWindow[w.win32.handle] = w
|
||||
|
||||
if !isXbox() && _IsWindows7OrGreater() {
|
||||
if !microsoftgdk.IsXbox() && _IsWindows7OrGreater() {
|
||||
if err := _ChangeWindowMessageFilterEx(w.win32.handle, _WM_DROPFILES, _MSGFLT_ALLOW, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1232,7 +1234,7 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er
|
||||
// Adjust window rect to account for DPI scaling of the window frame and
|
||||
// (if enabled) DPI scaling of the content area
|
||||
// This cannot be done until we know what monitor the window was placed on
|
||||
if !isXbox() && w.monitor == nil {
|
||||
if !microsoftgdk.IsXbox() && w.monitor == nil {
|
||||
rect := _RECT{
|
||||
left: 0,
|
||||
top: 0,
|
||||
@ -1298,7 +1300,7 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er
|
||||
}
|
||||
}
|
||||
|
||||
if !isXbox() {
|
||||
if !microsoftgdk.IsXbox() {
|
||||
_DragAcceptFiles(w.win32.handle, true)
|
||||
}
|
||||
|
||||
@ -1343,7 +1345,7 @@ func registerWindowClassWin32() error {
|
||||
// In the original GLFW implementation, an embedded resource GLFW_ICON is used if possible.
|
||||
// See https://www.glfw.org/docs/3.3/group__window.html
|
||||
|
||||
if !isXbox() {
|
||||
if !microsoftgdk.IsXbox() {
|
||||
icon, err := _LoadImageW(0, _IDI_APPLICATION, _IMAGE_ICON, 0, 0, _LR_DEFAULTSIZE|_LR_SHARED)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -2129,7 +2131,7 @@ func (c *Cursor) platformCreateCursor(image *Image, xhot, yhot int) error {
|
||||
}
|
||||
|
||||
func (c *Cursor) platformCreateStandardCursor(shape StandardCursor) error {
|
||||
if isXbox() {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,16 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
var theGraphics Graphics
|
||||
|
||||
func Get() *Graphics {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return nil
|
||||
}
|
||||
return &theGraphics
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
//go:build microsoftgdk
|
||||
// +build microsoftgdk
|
||||
|
||||
package glfwwin
|
||||
package microsoftgdk
|
||||
|
||||
// Unfortunately, some functions like XSystemGetDeviceType is not implemented in a DLL,
|
||||
// so LoadLibrary is not available.
|
||||
@ -40,12 +40,12 @@ const (
|
||||
_XSystemDeviceType_XboxScarlettDevkit = 0x08
|
||||
)
|
||||
|
||||
func isXbox() bool {
|
||||
func IsXbox() bool {
|
||||
t := C.XSystemGetDeviceType()
|
||||
return t != _XSystemDeviceType_Unknown && t != _XSystemDeviceType_Pc
|
||||
}
|
||||
|
||||
func monitorResolution() (int, int) {
|
||||
func MonitorResolution() (int, int) {
|
||||
switch C.XSystemGetDeviceType() {
|
||||
case _XSystemDeviceType_XboxOne, _XSystemDeviceType_XboxOneS:
|
||||
return 1920, 1080
|
@ -12,15 +12,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !microsoftgdk
|
||||
// +build !microsoftgdk
|
||||
//go:build !windows || !microsoftgdk
|
||||
// +build !windows !microsoftgdk
|
||||
|
||||
package glfwwin
|
||||
package microsoftgdk
|
||||
|
||||
func isXbox() bool {
|
||||
func IsXbox() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func monitorResolution() (int, int) {
|
||||
panic("glfwwin: monitorResolution is not implemented in this environment")
|
||||
func MonitorResolution() (int, int) {
|
||||
panic("microsoftgdk: MonitorResolution is not implemented in this environment")
|
||||
}
|
Loading…
Reference in New Issue
Block a user