]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/views/views.factor
8bfbe330b279f25b6a2a3d5123c196ac0cf28e80
[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 : NSOpenGLPFAColorFloat  58 ;
25 : NSOpenGLPFAMultisample 59 ;
26 : NSOpenGLPFASupersample 60 ;
27 : NSOpenGLPFASampleAlpha 61 ;
28 : NSOpenGLPFARendererID 70 ;
29 : NSOpenGLPFASingleRenderer 71 ;
30 : NSOpenGLPFANoRecovery 72 ;
31 : NSOpenGLPFAAccelerated 73 ;
32 : NSOpenGLPFAClosestPolicy 74 ;
33 : NSOpenGLPFARobust 75 ;
34 : NSOpenGLPFABackingStore 76 ;
35 : NSOpenGLPFAMPSafe 78 ;
36 : NSOpenGLPFAWindow 80 ;
37 : NSOpenGLPFAMultiScreen 81 ;
38 : NSOpenGLPFACompliant 83 ;
39 : NSOpenGLPFAScreenMask 84 ;
40 : NSOpenGLPFAPixelBuffer 90 ;
41 : NSOpenGLPFAAllowOfflineRenderers 96 ;
42 : NSOpenGLPFAVirtualScreenCount 128 ;
43
44 : kCGLRendererGenericFloatID HEX: 00020400 ;
45
46 <PRIVATE
47
48 SYMBOL: +software-renderer+
49 SYMBOL: +multisample+
50
51 PRIVATE>
52
53 : with-software-renderer ( quot -- )
54     t +software-renderer+ pick with-variable ; inline
55 : with-multisample ( quot -- )
56     t +multisample+ pick with-variable ; inline
57
58 : <PixelFormat> ( -- pixelfmt )
59     NSOpenGLPixelFormat -> alloc [
60         NSOpenGLPFAWindow ,
61         NSOpenGLPFADoubleBuffer ,
62         NSOpenGLPFADepthSize , 16 ,
63         +software-renderer+ get [
64             NSOpenGLPFARendererID , kCGLRendererGenericFloatID ,
65         ] when
66         +multisample+ get [
67             NSOpenGLPFASupersample ,
68             NSOpenGLPFASampleBuffers , 1 ,
69             NSOpenGLPFASamples , 8 ,
70         ] when
71         0 ,
72     ] { } make >c-int-array
73     -> initWithAttributes:
74     -> autorelease ;
75
76 : <GLView> ( class dim -- view )
77     >r -> alloc 0 0 r> first2 <NSRect> <PixelFormat>
78     -> initWithFrame:pixelFormat:
79     dup 1 -> setPostsBoundsChangedNotifications:
80     dup 1 -> setPostsFrameChangedNotifications: ;
81
82 : view-dim ( view -- dim )
83     -> bounds
84     dup NSRect-w >fixnum
85     swap NSRect-h >fixnum 2array ;
86
87 : mouse-location ( view event -- loc )
88     over >r
89     -> locationInWindow f -> convertPoint:fromView:
90     dup NSPoint-x swap NSPoint-y
91     r> -> frame NSRect-h swap - 2array ;
92
93 USE: opengl.gl
94 USE: alien.syntax
95
96 : NSOpenGLCPSwapInterval 222 ;
97
98 LIBRARY: OpenGL
99
100 TYPEDEF: int CGLError
101 TYPEDEF: void* CGLContextObj
102 TYPEDEF: int CGLContextParameter
103
104 FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ;
105