]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/views/views.factor
Updating X11 UI backend for stricter stack effect checking
[factor.git] / basis / cocoa / views / views.factor
1 ! Copyright (C) 2006, 2008 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: specialized-arrays.int arrays kernel math namespaces make
4 cocoa cocoa.messages cocoa.classes cocoa.types sequences
5 continuations accessors ;
6 IN: cocoa.views
7
8 CONSTANT: NSOpenGLPFAAllRenderers 1
9 CONSTANT: NSOpenGLPFADoubleBuffer 5
10 CONSTANT: NSOpenGLPFAStereo 6
11 CONSTANT: NSOpenGLPFAAuxBuffers 7
12 CONSTANT: NSOpenGLPFAColorSize 8
13 CONSTANT: NSOpenGLPFAAlphaSize 11
14 CONSTANT: NSOpenGLPFADepthSize 12
15 CONSTANT: NSOpenGLPFAStencilSize 13
16 CONSTANT: NSOpenGLPFAAccumSize 14
17 CONSTANT: NSOpenGLPFAMinimumPolicy 51
18 CONSTANT: NSOpenGLPFAMaximumPolicy 52
19 CONSTANT: NSOpenGLPFAOffScreen 53
20 CONSTANT: NSOpenGLPFAFullScreen 54
21 CONSTANT: NSOpenGLPFASampleBuffers 55
22 CONSTANT: NSOpenGLPFASamples 56
23 CONSTANT: NSOpenGLPFAAuxDepthStencil 57
24 CONSTANT: NSOpenGLPFAColorFloat  58
25 CONSTANT: NSOpenGLPFAMultisample 59
26 CONSTANT: NSOpenGLPFASupersample 60
27 CONSTANT: NSOpenGLPFASampleAlpha 61
28 CONSTANT: NSOpenGLPFARendererID 70
29 CONSTANT: NSOpenGLPFASingleRenderer 71
30 CONSTANT: NSOpenGLPFANoRecovery 72
31 CONSTANT: NSOpenGLPFAAccelerated 73
32 CONSTANT: NSOpenGLPFAClosestPolicy 74
33 CONSTANT: NSOpenGLPFARobust 75
34 CONSTANT: NSOpenGLPFABackingStore 76
35 CONSTANT: NSOpenGLPFAMPSafe 78
36 CONSTANT: NSOpenGLPFAWindow 80
37 CONSTANT: NSOpenGLPFAMultiScreen 81
38 CONSTANT: NSOpenGLPFACompliant 83
39 CONSTANT: NSOpenGLPFAScreenMask 84
40 CONSTANT: NSOpenGLPFAPixelBuffer 90
41 CONSTANT: NSOpenGLPFAAllowOfflineRenderers 96
42 CONSTANT: NSOpenGLPFAVirtualScreenCount 128
43
44 CONSTANT: 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> ( attributes -- pixelfmt )
59     NSOpenGLPixelFormat -> alloc swap [
60         %
61         NSOpenGLPFADepthSize , 16 ,
62         +software-renderer+ get [
63             NSOpenGLPFARendererID , kCGLRendererGenericFloatID ,
64         ] when
65         +multisample+ get [
66             NSOpenGLPFASupersample ,
67             NSOpenGLPFASampleBuffers , 1 ,
68             NSOpenGLPFASamples , 8 ,
69         ] when
70         0 ,
71     ] int-array{ } make
72     -> initWithAttributes:
73     -> autorelease ;
74
75 : <GLView> ( class dim -- view )
76     [ -> alloc 0 0 ] dip first2 <NSRect>
77     NSOpenGLPFAWindow NSOpenGLPFADoubleBuffer 2array <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     [
89         -> locationInWindow f -> convertPoint:fromView:
90         [ NSPoint-x ] [ NSPoint-y ] bi
91     ] [ drop -> frame NSRect-h ] 2bi
92     swap - 2array ;
93
94 USE: opengl.gl
95 USE: alien.syntax
96
97 CONSTANT: NSOpenGLCPSwapInterval 222
98
99 LIBRARY: OpenGL
100
101 TYPEDEF: int CGLError
102 TYPEDEF: void* CGLContextObj
103 TYPEDEF: int CGLContextParameter
104
105 FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ;
106