Added more NSEvent functions for glutin

This commit is contained in:
David Partouche
2014-10-12 20:09:48 +02:00
parent f9f7161c4c
commit f3a488d98a
2 changed files with 83 additions and 1 deletions
+30
View File
@@ -224,6 +224,16 @@ pub enum NSEventType {
NSEventTypeEndGesture = 20,
}
#[repr(u64)]
pub enum NSEventSubtype {
NSWindowExposedEventType = 0,
NSApplicationActivatedEventType = 1,
NSApplicationDeactivatedEventType = 2,
NSWindowMovedEventType = 4,
NSScreenChangedEventType = 8,
NSAWTEventType = 16,
}
#[repr(u64)]
pub enum NSEventMask {
NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint,
@@ -473,6 +483,7 @@ pub trait NSWindow {
unsafe fn setContentView_(self, view: id);
unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool);
unsafe fn isVisible(self) -> bool;
}
impl NSWindow for id {
@@ -736,6 +747,10 @@ impl NSWindow for id {
unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool) {
self.send_void("setAcceptsMouseMovedEvents:", accept);
}
unsafe fn isVisible(self) -> bool {
self.send_bool("isVisible", ())
}
}
pub trait NSString {
@@ -746,6 +761,7 @@ pub trait NSString {
unsafe fn initWithUTF8String_(self, c_string: *const u8) -> id;
unsafe fn stringByAppendingString_(self, other: id) -> id;
unsafe fn init_str(self, string: &str) -> Self;
unsafe fn UTF8String(self) -> *const libc::c_char;
}
impl NSString for id {
@@ -760,6 +776,10 @@ impl NSString for id {
unsafe fn init_str(self, string: &str) -> id {
self.initWithUTF8String_(string.as_ptr())
}
unsafe fn UTF8String(self) -> *const libc::c_char {
self.send_string("UTF8String", ())
}
}
pub trait NSView {
@@ -874,7 +894,9 @@ impl NSDate for id {
pub trait NSEvent {
unsafe fn get_type(self) -> NSEventType;
unsafe fn get_subtype(self) -> NSEventSubtype;
unsafe fn locationInWindow(self) -> NSPoint;
unsafe fn characters(self) -> id;
}
impl NSEvent for id {
@@ -882,7 +904,15 @@ impl NSEvent for id {
self.send_event("type", ())
}
unsafe fn get_subtype(self) -> NSEventSubtype {
self.send_eventSubtype("subtype", ())
}
unsafe fn locationInWindow(self) -> NSPoint {
self.send_point("locationInWindow", ())
}
unsafe fn characters(self) -> id {
self.send("characters", ())
}
}
+53 -1
View File
@@ -7,7 +7,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType};
use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType, NSEventSubtype};
use appkit::{NSWindowOrderingMode, NSAlignmentOptions};
use libc::{c_double, c_long, c_ulong, c_char};
@@ -96,6 +96,8 @@ pub trait ObjCMethodCall {
unsafe fn send_rect<S:ObjCSelector,A:ObjCMethodRectArgs>(self, selector: S, args: A) -> NSRect;
unsafe fn send_size<S:ObjCSelector,A:ObjCMethodSizeArgs>(self, selector: S, args: A) -> NSSize;
unsafe fn send_event<S:ObjCSelector,A:ObjCMethodEventArgs>(self, selector: S, args: A) -> NSEventType;
unsafe fn send_eventSubtype<S:ObjCSelector,A:ObjCMethodEventSubtypeArgs>(self, selector: S, args: A) -> NSEventSubtype;
unsafe fn send_string<S:ObjCSelector,A:ObjCMethodStringArgs>(self, selector: S, args: A) -> *const libc::c_char;
}
impl ObjCMethodCall for id {
@@ -150,6 +152,16 @@ impl ObjCMethodCall for id {
-> NSEventType {
args.send_event_args(self, selector.as_selector())
}
#[inline]
unsafe fn send_eventSubtype<S:ObjCSelector,A:ObjCMethodEventSubtypeArgs>(self, selector: S, args: A)
-> NSEventSubtype {
args.send_eventSubtype_args(self, selector.as_selector())
}
#[inline]
unsafe fn send_string<S:ObjCSelector,A:ObjCMethodStringArgs>(self, selector: S, args: A)
-> *const libc::c_char {
args.send_string_args(self, selector.as_selector())
}
}
/// A convenience implementation that allows methods on class names to be called directly, as in:
@@ -212,6 +224,16 @@ impl<'a> ObjCMethodCall for &'a str {
-> NSEventType {
args.send_event_args(class(self), selector.as_selector())
}
#[inline]
unsafe fn send_eventSubtype<S:ObjCSelector,A:ObjCMethodEventSubtypeArgs>(self, selector: S, args: A)
-> NSEventSubtype {
args.send_eventSubtype_args(class(self), selector.as_selector())
}
#[inline]
unsafe fn send_string<S:ObjCSelector,A:ObjCMethodStringArgs>(self, selector: S, args: A)
-> *const libc::c_char {
args.send_string_args(class(self), selector.as_selector())
}
}
/// A trait that allows C strings to be used as selectors without having to convert them first.
@@ -270,6 +292,14 @@ pub trait ObjCMethodEventArgs {
unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType;
}
pub trait ObjCMethodEventSubtypeArgs {
unsafe fn send_eventSubtype_args(self, receiver: id, selector: SEL) -> NSEventSubtype;
}
pub trait ObjCMethodStringArgs {
unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char;
}
impl ObjCMethodArgs for () {
#[inline]
unsafe fn send_args(self, receiver: id, selector: SEL) -> id {
@@ -457,6 +487,13 @@ impl ObjCMethodBoolArgs for () {
}
}
impl ObjCMethodBoolArgs for () {
#[inline]
unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool {
invoke_msg_bool(receiver, selector)
}
}
impl ObjCMethodBoolArgs for c_long {
#[inline]
unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool {
@@ -535,6 +572,21 @@ impl ObjCMethodPointArgs for (NSPoint, id) {
invoke_msg_NSPoint_NSPoint_id(receiver, selector, first, second)
}
}
impl ObjCMethodEventSubtypeArgs for () {
#[inline]
unsafe fn send_eventSubtype_args(self, receiver: id, selector: SEL) -> NSEventSubtype {
invoke_msg_NSEventSubtype(receiver, selector)
}
}
impl ObjCMethodStringArgs for () {
#[inline]
unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char {
invoke_msg_string(receiver, selector)
}
}
/// A trait that simulates variadic parameters for method calls.
#[cfg(test)]