twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

ui_darwin.go (2396B)


      1 // Copyright 2016 Hajime Hoshi
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 // +build !ios
     16 
     17 package glfw
     18 
     19 // #cgo CFLAGS: -x objective-c
     20 // #cgo LDFLAGS: -framework AppKit
     21 //
     22 // #import <AppKit/AppKit.h>
     23 //
     24 // static void currentMonitorPos(uintptr_t windowPtr, int* x, int* y) {
     25 //   NSScreen* screen = [NSScreen mainScreen];
     26 //   if (windowPtr) {
     27 //     NSWindow* window = (NSWindow*)windowPtr;
     28 //     if ([window isVisible]) {
     29 //       // When the window is visible, the window is already initialized.
     30 //       // [NSScreen mainScreen] sometimes tells a lie when the window is put across monitors (#703).
     31 //       screen = [window screen];
     32 //     }
     33 //   }
     34 //   NSDictionary* screenDictionary = [screen deviceDescription];
     35 //   NSNumber* screenID = [screenDictionary objectForKey:@"NSScreenNumber"];
     36 //   CGDirectDisplayID aID = [screenID unsignedIntValue];
     37 //   const CGRect bounds = CGDisplayBounds(aID);
     38 //   *x = bounds.origin.x;
     39 //   *y = bounds.origin.y;
     40 // }
     41 import "C"
     42 
     43 import (
     44 	"github.com/hajimehoshi/ebiten/v2/internal/glfw"
     45 )
     46 
     47 func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
     48 	return x
     49 }
     50 
     51 func (u *UserInterface) fromGLFWPixel(x float64) float64 {
     52 	return x
     53 }
     54 
     55 func (u *UserInterface) toGLFWPixel(x float64) float64 {
     56 	return x
     57 }
     58 
     59 func (u *UserInterface) toFramebufferPixel(x float64) float64 {
     60 	return x
     61 }
     62 
     63 func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
     64 	return x, y
     65 }
     66 
     67 func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
     68 	x := C.int(0)
     69 	y := C.int(0)
     70 	// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use w here.
     71 	win := w.GetCocoaWindow()
     72 	C.currentMonitorPos(C.uintptr_t(win), &x, &y)
     73 	for _, m := range glfw.GetMonitors() {
     74 		mx, my := m.GetPos()
     75 		if int(x) == mx && int(y) == my {
     76 			return m
     77 		}
     78 	}
     79 	return nil
     80 }
     81 
     82 func (u *UserInterface) nativeWindow() uintptr {
     83 	return u.window.GetCocoaWindow()
     84 }