Advertisement
Guest User

Untitled

a guest
Apr 14th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.31 KB | None | 0 0
  1. version (D_LP64)
  2.     alias double CGFloat;
  3. else
  4.     alias float CGFloat;
  5.  
  6. struct NSRect
  7. {
  8.     NSPoint origin;
  9.     NSSize size;
  10. }
  11.  
  12. public struct NSPoint {
  13.     public CGFloat x;// = 0.0;
  14.     public CGFloat y;// = 0.0;
  15. }
  16.  
  17. struct NSSize {
  18.     public CGFloat width;// = 0.0;
  19.     public CGFloat height;// = 0.0;
  20. }
  21.  
  22. alias char* SEL;
  23. alias objc_class* Class;
  24. alias objc_object* id;
  25.  
  26. struct objc_object
  27. {
  28.     Class isa;
  29. }
  30.  
  31. struct objc_class;
  32.  
  33. extern (C)
  34. {
  35.     Class objc_getClass (in char* name);
  36.     id objc_msgSend (id theReceiver, SEL theSelector, ...);
  37.     void objc_msgSend_stret(void* stretAddr, id theReceiver, SEL theSelector, ...);
  38.     SEL sel_registerName (in char* str);
  39. }
  40. extern (C) int printf(in char*, ...);
  41.  
  42. NSRect foo (id screen)
  43. {
  44.     alias extern (C) NSRect function (id, SEL) frameFp;
  45.     auto fp = cast(frameFp) &objc_msgSend_stret;
  46.     return fp(screen, sel_registerName("visibleFrame".ptr));
  47. }
  48.  
  49. int main ()
  50. {
  51.     auto cls = objc_getClass("NSScreen".ptr);
  52.  
  53.     alias extern (C) id function (id, SEL) screenFp;
  54.     auto screen = (cast(screenFp)&objc_msgSend)(cast(id) cls, sel_registerName("mainScreen".ptr));
  55.  
  56.     auto frame = foo(screen);
  57.  
  58.     printf("x=%f y=%f width=%f height=%f\n".ptr, frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement