mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Add MetalKit; Add NSApplication NSMenu NSMenuItem; Improve Metal classes
This commit is contained in:
+95
@@ -0,0 +1,95 @@
|
||||
package objc_Foundation
|
||||
|
||||
import "core:intrinsics"
|
||||
|
||||
ActivationPolicy :: enum UInteger {
|
||||
Regular = 0,
|
||||
Accessory = 1,
|
||||
Prohibited = 2,
|
||||
}
|
||||
|
||||
ApplicationDelegate :: struct {
|
||||
willFinishLaunching: proc "c" (self: ^ApplicationDelegate, notification: ^Notification),
|
||||
didFinishLaunching: proc "c" (self: ^ApplicationDelegate, notification: ^Notification),
|
||||
shouldTerminateAfterLastWindowClosed: proc "c" (self: ^ApplicationDelegate, sender: ^Application),
|
||||
|
||||
user_data: rawptr,
|
||||
}
|
||||
|
||||
@(objc_class="NSApplication")
|
||||
Application :: struct {using _: Object}
|
||||
|
||||
@(objc_type=Application, objc_name="sharedApplication", objc_is_class_method=true)
|
||||
Application_sharedApplication :: proc() -> ^Application {
|
||||
return msgSend(^Application, Application, "sharedApplication")
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="setDelegate")
|
||||
Application_setDelegate :: proc(self: ^Application, delegate: ^ApplicationDelegate) {
|
||||
willFinishLaunching :: proc "c" (self: ^Value, _: SEL, notification: ^Notification) {
|
||||
del := (^ApplicationDelegate)(self->pointerValue())
|
||||
del->willFinishLaunching(notification)
|
||||
}
|
||||
didFinishLaunching :: proc "c" (self: ^Value, _: SEL, notification: ^Notification) {
|
||||
del := (^ApplicationDelegate)(self->pointerValue())
|
||||
del->didFinishLaunching(notification)
|
||||
}
|
||||
shouldTerminateAfterLastWindowClosed :: proc "c" (self: ^Value, _: SEL, application: ^Application) {
|
||||
del := (^ApplicationDelegate)(self->pointerValue())
|
||||
del->shouldTerminateAfterLastWindowClosed(application)
|
||||
}
|
||||
|
||||
wrapper := Value.valueWithPointer(delegate)
|
||||
|
||||
class_addMethod(intrinsics.objc_find_class("NSValue"), intrinsics.objc_find_selector("applicationWillFinishLaunching:"), auto_cast willFinishLaunching, "v@:@")
|
||||
class_addMethod(intrinsics.objc_find_class("NSValue"), intrinsics.objc_find_selector("applicationDidFinishLaunching:"), auto_cast didFinishLaunching, "v@:@")
|
||||
class_addMethod(intrinsics.objc_find_class("NSValue"), intrinsics.objc_find_selector("applicationShouldTerminateAfterLastWindowClosed:"), auto_cast shouldTerminateAfterLastWindowClosed, "B@:@")
|
||||
|
||||
msgSend(nil, self, "setDelegate:", wrapper)
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="setActivationPolicy")
|
||||
Application_setActivationPolicy :: proc(self: ^Application, activationPolicy: ActivationPolicy) -> BOOL {
|
||||
return msgSend(BOOL, self, "setActivationPolicy:", activationPolicy)
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="activateIgnoringOtherApps")
|
||||
Application_activateIgnoringOtherApps :: proc(self: ^Application, ignoreOtherApps: BOOL) {
|
||||
msgSend(nil, self, "activateIgnoringOtherApps:", ignoreOtherApps)
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="setMainMenu")
|
||||
Application_setMainMenu :: proc(self: ^Application, menu: ^Menu) {
|
||||
msgSend(nil, self, "setMainMenu:", menu)
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="windows")
|
||||
Application_windows :: proc(self: ^Application) -> ^Array {
|
||||
return msgSend(^Array, self, "windows")
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="run")
|
||||
Application_run :: proc(self: ^Application) {
|
||||
msgSend(nil, self, "run")
|
||||
}
|
||||
|
||||
|
||||
@(objc_type=Application, objc_name="terminate")
|
||||
Application_terminate :: proc(self: ^Application, sender: ^Object) {
|
||||
msgSend(nil, self, "terminate:", sender)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@(objc_class="NSRunningApplication")
|
||||
RunningApplication :: struct {using _: Object}
|
||||
|
||||
@(objc_type=RunningApplication, objc_name="currentApplication", objc_is_class_method=true)
|
||||
RunningApplication_currentApplication :: proc() -> ^RunningApplication {
|
||||
return msgSend(^RunningApplication, RunningApplication, "currentApplication")
|
||||
}
|
||||
|
||||
@(objc_type=RunningApplication, objc_name="localizedName")
|
||||
RunningApplication_localizedName :: proc(self: ^RunningApplication) -> ^String {
|
||||
return msgSend(^String, self, "localizedName")
|
||||
}
|
||||
Vendored
+103
@@ -0,0 +1,103 @@
|
||||
package objc_Foundation
|
||||
|
||||
import "core:builtin"
|
||||
import "core:intrinsics"
|
||||
|
||||
KeyEquivalentModifierFlag :: enum UInteger {
|
||||
CapsLock = 16, // Set if Caps Lock key is pressed.
|
||||
Shift = 17, // Set if Shift key is pressed.
|
||||
Control = 18, // Set if Control key is pressed.
|
||||
Option = 19, // Set if Option or Alternate key is pressed.
|
||||
Command = 20, // Set if Command key is pressed.
|
||||
NumericPad = 21, // Set if any key in the numeric keypad is pressed.
|
||||
Help = 22, // Set if the Help key is pressed.
|
||||
Function = 23, // Set if any function key is pressed.
|
||||
}
|
||||
KeyEquivalentModifierMask :: distinct bit_set[KeyEquivalentModifierFlag; UInteger]
|
||||
|
||||
// Used to retrieve only the device-independent modifier flags, allowing applications to mask off the device-dependent modifier flags, including event coalescing information.
|
||||
KeyEventModifierFlagDeviceIndependentFlagsMask := transmute(KeyEquivalentModifierMask)_KeyEventModifierFlagDeviceIndependentFlagsMask
|
||||
@(private) _KeyEventModifierFlagDeviceIndependentFlagsMask := UInteger(0xffff0000)
|
||||
|
||||
|
||||
MenuItemCallback :: proc "c" (unused: rawptr, name: SEL, sender: ^Object)
|
||||
|
||||
|
||||
@(objc_class="NSMenuItem")
|
||||
MenuItem :: struct {using _: Object}
|
||||
|
||||
@(objc_type=MenuItem, objc_name="alloc", objc_is_class_method=true)
|
||||
MenuItem_alloc :: proc() -> ^MenuItem {
|
||||
return msgSend(^MenuItem, MenuItem, "alloc")
|
||||
}
|
||||
@(objc_type=MenuItem, objc_name="registerActionCallback", objc_is_class_method=true)
|
||||
MenuItem_registerActionCallback :: proc(name: cstring, callback: MenuItemCallback) -> SEL {
|
||||
s := string(name)
|
||||
n := len(s)
|
||||
sel: SEL
|
||||
if n > 0 && s[n-1] != ':' {
|
||||
col_name := intrinsics.alloca(n+2, 1)
|
||||
builtin.copy(col_name[:n], s)
|
||||
col_name[n] = ':'
|
||||
col_name[n+1] = 0
|
||||
sel = sel_registerName(cstring(col_name))
|
||||
} else {
|
||||
sel = sel_registerName(name)
|
||||
}
|
||||
if callback != nil {
|
||||
class_addMethod(intrinsics.objc_find_class("NSObject"), sel, auto_cast callback, "v@:@")
|
||||
}
|
||||
return sel
|
||||
}
|
||||
|
||||
@(objc_type=MenuItem, objc_name="init")
|
||||
MenuItem_init :: proc(self: ^MenuItem) -> ^MenuItem {
|
||||
return msgSend(^MenuItem, self, "init")
|
||||
}
|
||||
|
||||
@(objc_type=MenuItem, objc_name="setKeyEquivalentModifierMask")
|
||||
MenuItem_setKeyEquivalentModifierMask :: proc(self: ^MenuItem, modifierMask: KeyEquivalentModifierMask) {
|
||||
msgSend(nil, self, "setKeyEquivalentModifierMask:", modifierMask)
|
||||
}
|
||||
|
||||
@(objc_type=MenuItem, objc_name="keyEquivalentModifierMask")
|
||||
MenuItem_keyEquivalentModifierMask :: proc(self: ^MenuItem) -> KeyEquivalentModifierMask {
|
||||
return msgSend(KeyEquivalentModifierMask, self, "keyEquivalentModifierMask")
|
||||
}
|
||||
|
||||
@(objc_type=MenuItem, objc_name="setSubmenu")
|
||||
MenuItem_setSubmenu :: proc(self: ^MenuItem, submenu: ^Menu) {
|
||||
msgSend(nil, self, "setSubmenu:", submenu)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@(objc_class="NSMenu")
|
||||
Menu :: struct {using _: Object}
|
||||
|
||||
@(objc_type=Menu, objc_name="alloc", objc_is_class_method=true)
|
||||
Menu_alloc :: proc() -> ^Menu {
|
||||
return msgSend(^Menu, Menu, "alloc")
|
||||
}
|
||||
|
||||
@(objc_type=Menu, objc_name="init")
|
||||
Menu_init :: proc(self: ^Menu) -> ^Menu {
|
||||
return msgSend(^Menu, self, "init")
|
||||
}
|
||||
|
||||
@(objc_type=Menu, objc_name="initWithTitle")
|
||||
Menu_initWithTitle :: proc(self: ^Menu, title: ^String) -> ^Menu {
|
||||
return msgSend(^Menu, self, "initWithTitle:", title)
|
||||
}
|
||||
|
||||
|
||||
@(objc_type=Menu, objc_name="addItem")
|
||||
Menu_addItem :: proc(self: ^Menu, item: ^MenuItem) {
|
||||
msgSend(nil, self, "addItem:", item)
|
||||
}
|
||||
|
||||
@(objc_type=Menu, objc_name="addItemWithTitle")
|
||||
Menu_addItemWithTitle :: proc(self: ^Menu, title: ^String, selector: SEL, keyEquivalent: ^String) -> ^MenuItem {
|
||||
return msgSend(^MenuItem, self, "addItemWithTitle:action:keyEquivalent:", title, selector, keyEquivalent)
|
||||
}
|
||||
+3
-3
@@ -48,17 +48,17 @@ Value_getValue :: proc(self: ^Value, value: rawptr, size: UInteger) {
|
||||
|
||||
|
||||
@(objc_type=Value, objc_name="objCType")
|
||||
Value_objCType :: proc(self: ^Value) -> cstring {
|
||||
Value_objCType :: proc "c" (self: ^Value) -> cstring {
|
||||
return msgSend(cstring, self, "objCType")
|
||||
}
|
||||
|
||||
@(objc_type=Value, objc_name="isEqualToValue")
|
||||
Value_isEqualToValue :: proc(self, other: ^Value) -> BOOL {
|
||||
Value_isEqualToValue :: proc "c" (self, other: ^Value) -> BOOL {
|
||||
return msgSend(BOOL, self, "isEqualToValue:", other)
|
||||
}
|
||||
|
||||
@(objc_type=Value, objc_name="pointerValue")
|
||||
Value_pointerValue :: proc(self: ^Value) -> rawptr {
|
||||
Value_pointerValue :: proc "c" (self: ^Value) -> rawptr {
|
||||
return msgSend(rawptr, self, "pointerValue")
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -53,7 +53,10 @@ autorelease :: proc(self: ^Object) {
|
||||
retainCount :: proc(self: ^Object) -> UInteger {
|
||||
return msgSend(UInteger, self, "retainCount")
|
||||
}
|
||||
|
||||
@(objc_type=Object, objc_name="class")
|
||||
class :: proc(self: ^Object) -> Class {
|
||||
return msgSend(Class, self, "class")
|
||||
}
|
||||
|
||||
@(objc_type=Object, objc_name="hash")
|
||||
hash :: proc(self: ^Object) -> UInteger {
|
||||
|
||||
+4
@@ -49,6 +49,10 @@ StringCompareOption :: enum UInteger {
|
||||
|
||||
unichar :: distinct u16
|
||||
|
||||
@(link_prefix="NS", default_calling_convention="c")
|
||||
foreign Foundation {
|
||||
StringFromClass :: proc(cls: Class) -> ^String ---
|
||||
}
|
||||
|
||||
AT :: MakeConstantString
|
||||
MakeConstantString :: proc "c" (#const c: cstring) -> ^String {
|
||||
|
||||
+7
@@ -33,3 +33,10 @@ ComparisonResult :: enum Integer {
|
||||
}
|
||||
|
||||
NotFound :: IntegerMax
|
||||
|
||||
Float :: distinct (f32 when size_of(uint) == 4 else f64)
|
||||
|
||||
Size :: struct {
|
||||
width: Float,
|
||||
height: Float,
|
||||
}
|
||||
+82
-5
@@ -7,18 +7,75 @@ Rect :: struct {
|
||||
width, height: f64,
|
||||
}
|
||||
|
||||
WindowStyleFlag :: enum NS.UInteger {
|
||||
Titled = 0,
|
||||
Closable = 1,
|
||||
Miniaturizable = 2,
|
||||
Resizable = 3,
|
||||
TexturedBackground = 8,
|
||||
UnifiedTitleAndToolbar = 12,
|
||||
FullScreen = 14,
|
||||
FullSizeContentView = 15,
|
||||
UtilityWindow = 4,
|
||||
DocModalWindow = 6,
|
||||
NonactivatingPanel = 7,
|
||||
HUDWindow = 13,
|
||||
}
|
||||
WindowStyleMask :: distinct bit_set[WindowStyleFlag; NS.UInteger]
|
||||
WindowStyleMaskBorderless :: WindowStyleMask{}
|
||||
WindowStyleMaskTitled :: WindowStyleMask{.Titled}
|
||||
WindowStyleMaskClosable :: WindowStyleMask{.Closable}
|
||||
WindowStyleMaskMiniaturizable :: WindowStyleMask{.Miniaturizable}
|
||||
WindowStyleMaskResizable :: WindowStyleMask{.Resizable}
|
||||
WindowStyleMaskTexturedBackground :: WindowStyleMask{.TexturedBackground}
|
||||
WindowStyleMaskUnifiedTitleAndToolbar :: WindowStyleMask{.UnifiedTitleAndToolbar}
|
||||
WindowStyleMaskFullScreen :: WindowStyleMask{.FullScreen}
|
||||
WindowStyleMaskFullSizeContentView :: WindowStyleMask{.FullSizeContentView}
|
||||
WindowStyleMaskUtilityWindow :: WindowStyleMask{.UtilityWindow}
|
||||
WindowStyleMaskDocModalWindow :: WindowStyleMask{.DocModalWindow}
|
||||
WindowStyleMaskNonactivatingPanel :: WindowStyleMask{.NonactivatingPanel}
|
||||
WindowStyleMaskHUDWindow :: WindowStyleMask{.HUDWindow}
|
||||
|
||||
BackingStoreType :: enum NS.UInteger {
|
||||
Retained = 0,
|
||||
Nonretained = 1,
|
||||
Buffered = 2,
|
||||
}
|
||||
|
||||
@(objc_class="NSColor")
|
||||
Color :: struct {using _: Object}
|
||||
|
||||
@(objc_class="CALayer")
|
||||
Layer :: struct { using _: NS.Object }
|
||||
|
||||
@(objc_type=Layer, objc_name="contentsScale")
|
||||
Layer_contentsScale :: proc(self: ^Layer) -> Float {
|
||||
return msgSend(Float, self, "contentsScale")
|
||||
}
|
||||
@(objc_type=Layer, objc_name="setContentsScale")
|
||||
Layer_setContentsScale :: proc(self: ^Layer, scale: Float) {
|
||||
msgSend(nil, self, "setContentsScale:", scale)
|
||||
}
|
||||
@(objc_type=Layer, objc_name="frame")
|
||||
Layer_frame :: proc(self: ^Layer) -> Rect {
|
||||
return msgSend(Rect, self, "frame")
|
||||
}
|
||||
@(objc_type=Layer, objc_name="addSublayer")
|
||||
Layer_addSublayer :: proc(self: ^Layer, layer: ^Layer) {
|
||||
msgSend(nil, self, "addSublayer:", layer)
|
||||
}
|
||||
|
||||
@(objc_class="NSResponder")
|
||||
Responder :: struct {using _: Object}
|
||||
|
||||
@(objc_class="NSView")
|
||||
View :: struct {using _: Responder}
|
||||
|
||||
|
||||
@(objc_type=View, objc_name="initWithFrame")
|
||||
View_initWithFrame :: proc(self: ^View, frame: Rect) -> ^View {
|
||||
return msgSend(^View, self, "initWithFrame:", frame)
|
||||
}
|
||||
@(objc_type=View, objc_name="layer")
|
||||
View_layer :: proc(self: ^View) -> ^Layer {
|
||||
return msgSend(^Layer, self, "layer")
|
||||
@@ -27,10 +84,6 @@ View_layer :: proc(self: ^View) -> ^Layer {
|
||||
View_setLayer :: proc(self: ^View, layer: ^Layer) {
|
||||
msgSend(nil, self, "setLayer:", layer)
|
||||
}
|
||||
@(objc_type=View, objc_name="setSubLayer")
|
||||
View_setSubLayer :: proc(self: ^View, layer: ^Layer) {
|
||||
msgSend(nil, self, "setSubLayer:", layer)
|
||||
}
|
||||
@(objc_type=View, objc_name="wantsLayer")
|
||||
View_wantsLayer :: proc(self: ^View) -> BOOL {
|
||||
return msgSend(BOOL, self, "wantsLayer")
|
||||
@@ -40,14 +93,26 @@ View_setWantsLayer :: proc(self: ^View, wantsLayer: BOOL) {
|
||||
msgSend(nil, self, "setWantsLayer:", wantsLayer)
|
||||
}
|
||||
|
||||
|
||||
@(objc_class="NSWindow")
|
||||
Window :: struct {using _: Responder}
|
||||
|
||||
@(objc_type=Window, objc_name="alloc", objc_is_class_method=true)
|
||||
Window_alloc :: proc() -> ^Window {
|
||||
return msgSend(^Window, Window, "alloc")
|
||||
}
|
||||
|
||||
@(objc_type=Window, objc_name="initWithContentRect")
|
||||
Window_initWithContentRect :: proc(self: ^Window, contentRect: Rect, styleMask: WindowStyleMask, backing: BackingStoreType, doDefer: bool) -> ^Window {
|
||||
return msgSend(^Window, self, "initWithContentRect:styleMask:backing:defer:", contentRect, styleMask, backing, doDefer)
|
||||
}
|
||||
@(objc_type=Window, objc_name="contentView")
|
||||
Window_contentView :: proc(self: ^Window) -> ^View {
|
||||
return msgSend(^View, self, "contentView")
|
||||
}
|
||||
@(objc_type=Window, objc_name="setContentView")
|
||||
Window_setContentView :: proc(self: ^Window, content_view: ^View) {
|
||||
msgSend(nil, self, "setContentView:", content_view)
|
||||
}
|
||||
@(objc_type=Window, objc_name="frame")
|
||||
Window_frame :: proc(self: ^Window) -> Rect {
|
||||
return msgSend(Rect, self, "frame")
|
||||
@@ -72,3 +137,15 @@ Window_backgroundColor :: proc(self: ^Window) -> ^NS.Color {
|
||||
Window_setBackgroundColor :: proc(self: ^Window, color: ^NS.Color) {
|
||||
msgSend(nil, self, "setBackgroundColor:", color)
|
||||
}
|
||||
@(objc_type=Window, objc_name="makeKeyAndOrderFront")
|
||||
Window_makeKeyAndOrderFront :: proc(self: ^Window, key: ^NS.Object) {
|
||||
msgSend(nil, self, "makeKeyAndOrderFront:", key)
|
||||
}
|
||||
@(objc_type=Window, objc_name="setTitle")
|
||||
Window_setTitle :: proc(self: ^Window, title: ^NS.String) {
|
||||
msgSend(nil, self, "setTitle:", title)
|
||||
}
|
||||
@(objc_type=Window, objc_name="close")
|
||||
Window_close :: proc(self: ^Window) {
|
||||
msgSend(nil, self, "close")
|
||||
}
|
||||
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
package objc_Foundation
|
||||
|
||||
foreign import "system:Foundation.framework"
|
||||
|
||||
import "core:intrinsics"
|
||||
import "core:c"
|
||||
|
||||
IMP :: proc "c" (object: id, sel: SEL, #c_vararg args: ..any) -> id
|
||||
|
||||
foreign Foundation {
|
||||
objc_lookUpClass :: proc "c" (name: cstring) -> Class ---
|
||||
sel_registerName :: proc "c" (name: cstring) -> SEL ---
|
||||
objc_allocateClassPair :: proc "c" (superclass: Class, name: cstring, extraBytes: uint) ---
|
||||
|
||||
class_addMethod :: proc "c" (cls: Class, name: SEL, imp: IMP, types: cstring) -> BOOL ---
|
||||
}
|
||||
|
||||
|
||||
@(objc_class="NSZone")
|
||||
Zone :: struct {using _: Object}
|
||||
|
||||
@(link_prefix="NS")
|
||||
foreign Foundation {
|
||||
AllocateObject :: proc "c" (aClass: Class, extraBytes: UInteger, zone: ^Zone) -> id ---
|
||||
DeallocateObject :: proc "c" (object: id) ---
|
||||
}
|
||||
|
||||
Method :: ^objc_method
|
||||
objc_method :: struct {
|
||||
method_name: SEL,
|
||||
method_types: cstring,
|
||||
method_imp: IMP,
|
||||
}
|
||||
objc_method_list :: struct {}
|
||||
|
||||
objc_ivar :: struct {}
|
||||
objc_ivar_list :: struct {}
|
||||
|
||||
objc_cache :: struct {
|
||||
mask: u32,
|
||||
occupied: u32,
|
||||
buckets: [1]Method,
|
||||
}
|
||||
|
||||
objc_protocol_list :: struct {
|
||||
next: ^objc_protocol_list,
|
||||
count: c.int,
|
||||
list: [1]^Protocol,
|
||||
}
|
||||
|
||||
@(objc_class="Protocol")
|
||||
Protocol :: struct{using _: intrinsics.objc_object}
|
||||
|
||||
objc_object_internals :: struct {
|
||||
isa: ^objc_class_internals,
|
||||
}
|
||||
|
||||
|
||||
objc_class_internals :: struct {
|
||||
isa: Class,
|
||||
super_class: Class,
|
||||
name: cstring,
|
||||
version: c.long,
|
||||
info: c.long,
|
||||
instance_size: c.long,
|
||||
ivars: ^objc_ivar_list,
|
||||
|
||||
methodLists: ^^objc_method_list,
|
||||
|
||||
cache: rawptr,
|
||||
protocols: rawptr,
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user