]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/views/views.factor
Create basis vocab root
[factor.git] / basis / cocoa / views / views.factor
1 ! Copyright (C) 2006, 2007 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types arrays kernel math namespaces cocoa
4 cocoa.messages cocoa.classes cocoa.types sequences
5 continuations ;
6 IN: cocoa.views
7
8 : NSOpenGLPFAAllRenderers 1 ;
9 : NSOpenGLPFADoubleBuffer 5 ;
10 : NSOpenGLPFAStereo 6 ;
11 : NSOpenGLPFAAuxBuffers 7 ;
12 : NSOpenGLPFAColorSize 8 ;
13 : NSOpenGLPFAAlphaSize 11 ;
14 : NSOpenGLPFADepthSize 12 ;
15 : NSOpenGLPFAStencilSize 13 ;
16 : NSOpenGLPFAAccumSize 14 ;
17 : NSOpenGLPFAMinimumPolicy 51 ;
18 : NSOpenGLPFAMaximumPolicy 52 ;
19 : NSOpenGLPFAOffScreen 53 ;
20 : NSOpenGLPFAFullScreen 54 ;
21 : NSOpenGLPFASampleBuffers 55 ;
22 : NSOpenGLPFASamples 56 ;
23 : NSOpenGLPFAAuxDepthStencil 57 ;
24 : NSOpenGLPFARendererID 70 ;
25 : NSOpenGLPFASingleRenderer 71 ;
26 : NSOpenGLPFANoRecovery 72 ;
27 : NSOpenGLPFAAccelerated 73 ;
28 : NSOpenGLPFAClosestPolicy 74 ;
29 : NSOpenGLPFARobust 75 ;
30 : NSOpenGLPFABackingStore 76 ;
31 : NSOpenGLPFAMPSafe 78 ;
32 : NSOpenGLPFAWindow 80 ;
33 : NSOpenGLPFAMultiScreen 81 ;
34 : NSOpenGLPFACompliant 83 ;
35 : NSOpenGLPFAScreenMask 84 ;
36 : NSOpenGLPFAPixelBuffer 90 ;
37 : NSOpenGLPFAVirtualScreenCount 128 ;
38
39 <PRIVATE
40
41 SYMBOL: +software-renderer+
42
43 PRIVATE>
44
45 : with-software-renderer ( quot -- )
46     t +software-renderer+ set
47     [ f +software-renderer+ set ]
48     [ ] cleanup ; inline
49
50 : <PixelFormat> ( -- pixelfmt )
51     NSOpenGLPixelFormat -> alloc [
52         NSOpenGLPFAWindow ,
53         NSOpenGLPFADoubleBuffer ,
54         NSOpenGLPFADepthSize , 16 ,
55         +software-renderer+ get [ NSOpenGLPFARobust , ] when
56         0 ,
57     ] { } make >c-int-array
58     -> initWithAttributes:
59     -> autorelease ;
60
61 : <GLView> ( class dim -- view )
62     >r -> alloc 0 0 r> first2 <NSRect> <PixelFormat>
63     -> initWithFrame:pixelFormat:
64     dup 1 -> setPostsBoundsChangedNotifications:
65     dup 1 -> setPostsFrameChangedNotifications: ;
66
67 : view-dim ( view -- dim )
68     -> bounds
69     dup NSRect-w >fixnum
70     swap NSRect-h >fixnum 2array ;
71
72 : mouse-location ( view event -- loc )
73     over >r
74     -> locationInWindow f -> convertPoint:fromView:
75     dup NSPoint-x swap NSPoint-y
76     r> -> frame NSRect-h swap - 2array ;
77
78 USE: opengl.gl
79 USE: alien.syntax
80
81 : NSOpenGLCPSwapInterval 222 ;
82
83 LIBRARY: OpenGL
84
85 TYPEDEF: int CGLError
86 TYPEDEF: void* CGLContextObj
87 TYPEDEF: int CGLContextParameter
88
89 FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ;
90