mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-23 14:55:19 +00:00
Create new core:sys/darwin/CoreGraphics package (#6147)
* Add Darwin mouse cursor-related bindings Create CoreGraphics package in the process * Remove unneeded semicolons * Define some CG types in CoreFoundation instead This matches where Darwin's C header files defines these types
This commit is contained in:
18
core/sys/darwin/CoreFoundation/CFCGTypes.odin
Normal file
18
core/sys/darwin/CoreFoundation/CFCGTypes.odin
Normal file
@@ -0,0 +1,18 @@
|
||||
package CoreFoundation
|
||||
|
||||
CGFloat :: distinct (f32 when size_of(uint) == 4 else f64)
|
||||
|
||||
CGPoint :: struct {
|
||||
x: CGFloat,
|
||||
y: CGFloat,
|
||||
}
|
||||
|
||||
CGRect :: struct {
|
||||
using origin: CGPoint,
|
||||
using size: CGSize,
|
||||
}
|
||||
|
||||
CGSize :: struct {
|
||||
width: CGFloat,
|
||||
height: CGFloat,
|
||||
}
|
||||
57
core/sys/darwin/CoreGraphics/CoreGraphics.odin
Normal file
57
core/sys/darwin/CoreGraphics/CoreGraphics.odin
Normal file
@@ -0,0 +1,57 @@
|
||||
package CoreGraphics
|
||||
|
||||
import "core:c"
|
||||
import CF "core:sys/darwin/CoreFoundation"
|
||||
|
||||
@(require)
|
||||
foreign import "system:CoreGraphics.framework"
|
||||
|
||||
@(link_prefix="CG", default_calling_convention="c")
|
||||
foreign CoreGraphics {
|
||||
AssociateMouseAndMouseCursorPosition :: proc(connected: b32) -> Error ---
|
||||
DisplayIDToOpenGLDisplayMask :: proc(display: DirectDisplayID) -> OpenGLDisplayMask ---
|
||||
DisplayMoveCursorToPoint :: proc(display: DirectDisplayID, point: Point) -> Error ---
|
||||
EventSourceKeyState :: proc(stateID: EventSourceStateID, key: KeyCode) -> bool ---
|
||||
GetActiveDisplayList :: proc(maxDisplays: c.uint32_t, activeDisplays: [^]DirectDisplayID, displayCount: ^c.uint32_t) -> Error ---
|
||||
GetDisplaysWithOpenGLDisplayMask :: proc(mask: OpenGLDisplayMask, maxDisplays: c.uint32_t, displays: [^]DirectDisplayID, matchingDisplayCount: ^c.uint32_t) -> Error ---
|
||||
GetDisplaysWithPoint :: proc(point: Point, maxDisplays: c.uint32_t, displays: [^]DirectDisplayID, matchingDisplayCount: ^c.uint32_t) -> Error ---
|
||||
GetDisplaysWithRect :: proc(rect: Rect, maxDisplays: c.uint32_t, displays: [^]DirectDisplayID, matchingDisplayCount: ^c.uint32_t) -> Error ---
|
||||
GetOnlineDisplayList :: proc(maxDisplays: c.uint32_t, onlineDisplays: [^]DirectDisplayID, displayCount: ^c.uint32_t) -> Error ---
|
||||
MainDisplayID :: proc() -> DirectDisplayID ---
|
||||
OpenGLDisplayMaskToDisplayID :: proc(mask: OpenGLDisplayMask) -> DirectDisplayID ---
|
||||
WarpMouseCursorPosition :: proc(newCursorPosition: Point) -> Error ---
|
||||
}
|
||||
|
||||
DirectDisplayID :: c.uint32_t
|
||||
|
||||
Error :: enum c.int32_t {
|
||||
Success = 0,
|
||||
Failure = 1000,
|
||||
IllegalArgument = 1001,
|
||||
InvalidConnection = 1002,
|
||||
InvalidContext = 1003,
|
||||
CannotComplete = 1004,
|
||||
NotImplemented = 1006,
|
||||
RangeCheck = 1007,
|
||||
TypeCheck = 1008,
|
||||
InvalidOperation = 1010,
|
||||
NoneAvailable = 1011,
|
||||
}
|
||||
|
||||
EventSourceStateID :: enum c.int32_t {
|
||||
Private = -1,
|
||||
CombinedSessionState = 0,
|
||||
HIDSystemState = 1,
|
||||
}
|
||||
|
||||
Float :: CF.CGFloat
|
||||
|
||||
KeyCode :: c.uint16_t
|
||||
|
||||
OpenGLDisplayMask :: c.uint32_t
|
||||
|
||||
Point :: CF.CGPoint
|
||||
|
||||
Rect :: CF.CGRect
|
||||
|
||||
Size :: CF.CGSize
|
||||
@@ -3,6 +3,19 @@ package objc_Foundation
|
||||
@(objc_class="NSCursor")
|
||||
Cursor :: struct {using _: Object}
|
||||
|
||||
@(objc_type=Cursor, objc_name="hide", objc_is_class_method=true)
|
||||
Cursor_hide :: proc() {
|
||||
msgSend(nil, Cursor, "hide")
|
||||
}
|
||||
@(objc_type=Cursor, objc_name="unhide", objc_is_class_method=true)
|
||||
Cursor_unhide :: proc() {
|
||||
msgSend(nil, Cursor, "unhide")
|
||||
}
|
||||
@(objc_type=Cursor, objc_name="setHiddenUntilMouseMoves", objc_is_class_method=true)
|
||||
Cursor_setHiddenUntilMouseMoves :: proc(flag: BOOL) {
|
||||
msgSend(nil, Cursor, "setHiddenUntilMouseMoves:", flag)
|
||||
}
|
||||
|
||||
@(objc_type=Cursor, objc_name="set")
|
||||
Cursor_set :: proc(self: ^Cursor) {
|
||||
msgSend(EventType, self, "set")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package objc_Foundation
|
||||
|
||||
import "base:intrinsics"
|
||||
import CF "core:sys/darwin/CoreFoundation"
|
||||
|
||||
@(private) msgSend :: intrinsics.objc_send
|
||||
|
||||
@@ -34,17 +35,11 @@ ComparisonResult :: enum Integer {
|
||||
|
||||
NotFound :: IntegerMax
|
||||
|
||||
Float :: distinct (f32 when size_of(uint) == 4 else f64)
|
||||
Float :: CF.CGFloat
|
||||
|
||||
Point :: struct {
|
||||
x: Float,
|
||||
y: Float,
|
||||
}
|
||||
Point :: CF.CGPoint
|
||||
|
||||
Size :: struct {
|
||||
width: Float,
|
||||
height: Float,
|
||||
}
|
||||
Size :: CF.CGSize
|
||||
|
||||
when size_of(UInteger) == 8 {
|
||||
_UINTEGER_ENCODING :: "Q"
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
package objc_Foundation
|
||||
|
||||
import "core:strings"
|
||||
import CF "core:sys/darwin/CoreFoundation"
|
||||
import "base:runtime"
|
||||
import "base:intrinsics"
|
||||
|
||||
Rect :: struct {
|
||||
using origin: Point,
|
||||
using size: Size,
|
||||
Rect :: CF.CGRect
|
||||
MaxX :: proc(aRect: Rect) -> Float {
|
||||
return aRect.origin.x + aRect.size.width
|
||||
}
|
||||
MaxY :: proc(aRect: Rect) -> Float {
|
||||
return aRect.origin.y + aRect.size.height
|
||||
}
|
||||
MidX :: proc(aRect: Rect) -> Float {
|
||||
return aRect.origin.x + aRect.size.width*0.5
|
||||
}
|
||||
MidY :: proc(aRect: Rect) -> Float {
|
||||
return aRect.origin.y + aRect.size.height*0.5
|
||||
}
|
||||
MinX :: proc(aRect: Rect) -> Float {
|
||||
return aRect.origin.x
|
||||
}
|
||||
MinY :: proc(aRect: Rect) -> Float {
|
||||
return aRect.origin.y
|
||||
}
|
||||
|
||||
Depth :: enum UInteger {
|
||||
@@ -988,3 +1004,7 @@ Window_contentRectForFrameRectInstance :: proc "c" (self: ^Window, frameRect: Re
|
||||
Window_frameRectForContentRectInstance :: proc "c" (self: ^Window, contentRect: Rect) -> Rect {
|
||||
return msgSend(Rect, self, "frameRectForContentRect:", contentRect)
|
||||
}
|
||||
@(objc_type = Window, objc_name = "screen")
|
||||
Window_screen :: proc "c" (self: ^Window) -> ^Screen {
|
||||
return msgSend(^Screen, self, "screen")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user