diff --git a/src/appkit.rs b/src/appkit.rs index 9779604..bcd8366 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -68,6 +68,11 @@ impl NSRect { #[link(name = "AppKit", kind = "framework")] extern {} +#[link(name = "Foundation", kind = "framework")] +extern { + pub static NSDefaultRunLoopMode: id; +} + pub unsafe fn NSApp() -> id { "NSApplication".send("sharedApplication", ()) } @@ -142,6 +147,114 @@ bitflags! { | NSAlignMinYNearest.bits | NSAlignMaxYNearest.bits, } + +#[repr(u64)] +pub enum NSOpenGLPixelFormatAttribute { + NSOpenGLPFAAllRenderers = 1, + NSOpenGLPFATripleBuffer = 3, + NSOpenGLPFADoubleBuffer = 5, + NSOpenGLPFAStereo = 6, + NSOpenGLPFAAuxBuffers = 7, + NSOpenGLPFAColorSize = 8, + NSOpenGLPFAAlphaSize = 11, + NSOpenGLPFADepthSize = 12, + NSOpenGLPFAStencilSize = 13, + NSOpenGLPFAAccumSize = 14, + NSOpenGLPFAMinimumPolicy = 51, + NSOpenGLPFAMaximumPolicy = 52, + NSOpenGLPFAOffScreen = 53, + NSOpenGLPFAFullScreen = 54, + NSOpenGLPFASampleBuffers = 55, + NSOpenGLPFASamples = 56, + NSOpenGLPFAAuxDepthStencil = 57, + NSOpenGLPFAColorFloat = 58, + NSOpenGLPFAMultisample = 59, + NSOpenGLPFASupersample = 60, + NSOpenGLPFASampleAlpha = 61, + NSOpenGLPFARendererID = 70, + NSOpenGLPFASingleRenderer = 71, + NSOpenGLPFANoRecovery = 72, + NSOpenGLPFAAccelerated = 73, + NSOpenGLPFAClosestPolicy = 74, + NSOpenGLPFARobust = 75, + NSOpenGLPFABackingStore = 76, + NSOpenGLPFAMPSafe = 78, + NSOpenGLPFAWindow = 80, + NSOpenGLPFAMultiScreen = 81, + NSOpenGLPFACompliant = 83, + NSOpenGLPFAScreenMask = 84, + NSOpenGLPFAPixelBuffer = 90, + NSOpenGLPFARemotePixelBuffer = 91, + NSOpenGLPFAAllowOfflineRenderers = 96, + NSOpenGLPFAAcceleratedCompute = 97, + NSOpenGLPFAOpenGLProfile = 99, + NSOpenGLPFAVirtualScreenCount = 128, +} + +#[repr(u64)] +pub enum NSEventType { + NSLeftMouseDown = 1, + NSLeftMouseUp = 2, + NSRightMouseDown = 3, + NSRightMouseUp = 4, + NSMouseMoved = 5, + NSLeftMouseDragged = 6, + NSRightMouseDragged = 7, + NSMouseEntered = 8, + NSMouseExited = 9, + NSKeyDown = 10, + NSKeyUp = 11, + NSFlagsChanged = 12, + NSAppKitDefined = 13, + NSSystemDefined = 14, + NSApplicationDefined = 15, + NSPeriodic = 16, + NSCursorUpdate = 17, + NSScrollWheel = 22, + NSTabletPoint = 23, + NSTabletProximity = 24, + NSOtherMouseDown = 25, + NSOtherMouseUp = 26, + NSOtherMouseDragged = 27, + NSEventTypeGesture = 29, + NSEventTypeMagnify = 30, + NSEventTypeSwipe = 31, + NSEventTypeRotate = 18, + NSEventTypeBeginGesture = 19, + NSEventTypeEndGesture = 20, +} + +#[repr(u64)] +pub enum NSEventMask { + NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint, + NSLeftMouseUpMask = 1 << NSLeftMouseUp as uint, + NSRightMouseDownMask = 1 << NSRightMouseDown as uint, + NSRightMouseUpMask = 1 << NSRightMouseUp as uint, + NSMouseMovedMask = 1 << NSMouseMoved as uint, + NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as uint, + NSRightMouseDraggedMask = 1 << NSRightMouseDragged as uint, + NSMouseEnteredMask = 1 << NSMouseEntered as uint, + NSMouseExitedMask = 1 << NSMouseExited as uint, + NSKeyDownMask = 1 << NSKeyDown as uint, + NSKeyUpMask = 1 << NSKeyUp as uint, + NSFlagsChangedMask = 1 << NSFlagsChanged as uint, + NSAppKitDefinedMask = 1 << NSAppKitDefined as uint, + NSSystemDefinedMask = 1 << NSSystemDefined as uint, + NSAPplicationDefinedMask = 1 << NSApplicationDefined as uint, + NSPeriodicMask = 1 << NSPeriodic as uint, + NSCursorUpdateMask = 1 << NSCursorUpdate as uint, + NSScrollWheelMask = 1 << NSScrollWheel as uint, + NSTabletPointMask = 1 << NSTabletPoint as uint, + NSTabletProximityMask = 1 << NSTabletProximity as uint, + NSOtherMouseDownMask = 1 << NSOtherMouseDown as uint, + NSOtherMouseUpMask = 1 << NSOtherMouseUp as uint, + NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as uint, + NSEventMaskgesture = 1 << NSEventTypeGesture as uint, + NSEventMaskSwipe = 1 << NSEventTypeSwipe as uint, + NSEventMaskRotate = 1 << NSEventTypeRotate as uint, + NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as uint, + NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as uint, + NSAnyEventMask = 0xffffffff, } pub trait NSAutoreleasePool { @@ -181,6 +294,9 @@ pub trait NSApplication { unsafe fn setMainMenu_(self, menu: id); unsafe fn activateIgnoringOtherApps_(self, ignore: bool); unsafe fn run(self); + unsafe fn finishLaunching(self); + unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, dequeue: bool) -> id; + unsafe fn sendEvent_(self, an_event: id); } impl NSApplication for id { @@ -199,6 +315,18 @@ impl NSApplication for id { unsafe fn run(self) { self.send_void("run", ()); } + + unsafe fn finishLaunching(self) { + self.send_void("finishLaunching", ()) + } + + unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, dequeue: bool) -> id { + self.send("nextEventMatchingMask:untilDate:inMode:dequeue:", (mask, expiration, in_mode, dequeue)) + } + + unsafe fn sendEvent_(self, an_event: id) { + self.send_void("sendEvent:", an_event) + } } pub trait NSMenu { @@ -333,6 +461,8 @@ pub trait NSWindow { // skipped: setMiniwindowImage unsafe fn miniwindowTitle(self) -> id; unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); + + unsafe fn setContentView(self, view: id); } impl NSWindow for id { @@ -584,6 +714,10 @@ impl NSWindow for id { unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { self.send_void("setMiniwindowTitle:", miniwindowTitle); } + + unsafe fn setContentView(self, view: id) { + self.send_void("setContentView:", view) + } } pub trait NSString { @@ -610,3 +744,93 @@ impl NSString for id { } } +pub trait NSView { + unsafe fn alloc(_: Self) -> id { + "NSView".send("alloc", ()) + } + + unsafe fn init(self) -> id; + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; + unsafe fn display_(self); + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool); +} + +impl NSView for id { + unsafe fn init(self) -> id { + self.send("init", ()) + } + + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { + self.send("initWithFrame:", frameRect) + } + + unsafe fn display_(self) { + self.send_void("display", ()) + } + + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool) { + self.send_void("setWantsBestResolutionOpenGLSurface:", flag) + } +} + +pub trait NSOpenGLView { + unsafe fn alloc(_: Self) -> id { + "NSOpenGLView".send("alloc", ()) + } + + unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id; + unsafe fn display_(self); +} + +impl NSOpenGLView for id { + unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id { + self.send("initWithFrame:pixelFormat:", (frameRect, format)) + } + + unsafe fn display_(self) { + self.send_void("display", ()) + } +} + +pub trait NSOpenGLPixelFormat { + unsafe fn alloc(_: Self) -> id { + "NSOpenGLPixelFormat".send("alloc", ()) + } + + unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id; +} + +impl NSOpenGLPixelFormat for id { + unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id { + self.send("initWithAttributes:", attributes) + } +} + +pub trait NSOpenGLContext { + unsafe fn alloc(_: Self) -> id { + "NSOpenGLContext".send("alloc", ()) + } + + unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id; + unsafe fn setView_(self, view: id); + unsafe fn makeCurrentContext(self); + unsafe fn flushBuffer(self); +} + +impl NSOpenGLContext for id { + unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id { + self.send("initWithFormat:shareContext:", (format, shareContext)) + } + + unsafe fn setView_(self, view: id) { + self.send_void("setView:", view) + } + + unsafe fn makeCurrentContext(self) { + self.send_void("makeCurrentContext", ()) + } + + unsafe fn flushBuffer(self) { + self.send_void("flushBuffer", ()) + } +} diff --git a/src/base.rs b/src/base.rs index 13e09da..e75e53f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -306,6 +306,37 @@ impl ObjCMethodArgs for (id, id, id, id, id) { } } +impl ObjCMethodArgs for (NSRect, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second) = self; + invoke_msg_id_NSRect_id(receiver, selector, first, second) + } +} + +impl<'a> ObjCMethodArgs for &'a [uint] { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + invoke_msg_id_array(receiver, selector, self) + } +} + +impl ObjCMethodArgs for (id, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second) = self; + invoke_msg_id_id_id(receiver, selector, first, second) + } +} + +impl ObjCMethodArgs for (NSUInteger, id, id, bool) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second, third, fourth) = self; + invoke_msg_id_NSUInteger_id_id_bool(receiver, selector, first, second, third, fourth) + } +} + impl ObjCMethodDoubleArgs for () { #[inline] unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 {