]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/views/views.factor
Fix conflict
[factor.git] / basis / cocoa / views / views.factor
1 ! Copyright (C) 2006, 2009 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 core-graphics.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
47 CONSTANT: NSOpenGLCPSwapInterval 222
48
49 <PRIVATE
50
51 SYMBOL: software-renderer?
52 SYMBOL: multisample?
53
54 PRIVATE>
55
56 : with-software-renderer ( quot -- )
57     [ t software-renderer? ] dip with-variable ; inline
58
59 : with-multisample ( quot -- )
60     [ t multisample? ] dip with-variable ; inline
61
62 : <PixelFormat> ( attributes -- pixelfmt )
63     NSOpenGLPixelFormat -> alloc swap [
64         %
65         NSOpenGLPFADepthSize , 16 ,
66         software-renderer? get [
67             NSOpenGLPFARendererID , kCGLRendererGenericFloatID ,
68         ] when
69         multisample? get [
70             NSOpenGLPFASupersample ,
71             NSOpenGLPFASampleBuffers , 1 ,
72             NSOpenGLPFASamples , 8 ,
73         ] when
74         0 ,
75     ] int-array{ } make
76     -> initWithAttributes:
77     -> autorelease ;
78
79 : <GLView> ( class dim -- view )
80     [ -> alloc 0 0 ] dip first2 <CGRect>
81     NSOpenGLPFAWindow NSOpenGLPFADoubleBuffer 2array <PixelFormat>
82     -> initWithFrame:pixelFormat:
83     dup 1 -> setPostsBoundsChangedNotifications:
84     dup 1 -> setPostsFrameChangedNotifications: ;
85
86 : view-dim ( view -- dim )
87     -> bounds
88     [ CGRect-w >fixnum ] [ CGRect-h >fixnum ] bi
89     2array ;
90
91 : mouse-location ( view event -- loc )
92     [
93         -> locationInWindow f -> convertPoint:fromView:
94         [ CGPoint-x ] [ CGPoint-y ] bi
95     ] [ drop -> frame CGRect-h ] 2bi
96     swap - 2array ;