1 #import <Cocoa/Cocoa.h>
2 #import "CocoaEcereBridge.h"
5 @implementation EcereView
6 - (EcereView*)initWithEcereWindow:(EcereWindowRef)ecereWindow;
8 self = [super initWithFrame:NSZeroRect];
14 NSOpenGLPixelFormatAttribute attributes[] =
17 //NSOpenGLPFAAccelerated,
18 NSOpenGLPFADoubleBuffer,
19 //NSOpenGLPFAColorSize, 24,
20 NSOpenGLPFAAlphaSize, 8,
21 NSOpenGLPFADepthSize, 24,
22 NSOpenGLPFAMinimumPolicy,
23 // select a pixelformat which meets or
24 // exceeds these requirements
28 _pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] ;
30 if (_pixelformat == nil)
32 NSLog( @"No valid OpenGL pixel format" );
33 NSLog( @"matching attributes specified" );
37 [self setEcereWindow:ecereWindow];
39 _context = [[NSOpenGLContext alloc]
40 initWithFormat:_pixelformat shareContext:nil] ;
44 // Failed initialization
46 NSLog( @"No valid OpenGL" ) ;
51 // ensure we are pointing to ourself as the Drawable
52 [_context setView:self];
56 if (_context == nil) {
68 - (NSOpenGLContext*)openGLContext
75 // ensure we are ready to draw
78 [_context setView:self];
81 [self makeCurrentContext];
83 printf("- (void)lockFocus(%i)\n", lockCount);
90 [self flushOpenGLBuffer];
94 printf("- (void)unlockFocus(%i)\n", lockCount);
97 - (void)makeCurrentContext
99 printf("- (void)makeCurrentContext\n");
101 [_context makeCurrentContext];
104 - (void)flushOpenGLBuffer
106 printf("- (void)flushOpenGLBuffer\n");
108 [_context flushBuffer];
116 - drawRect:(NSRect)rect
118 // make us the current OpenGL context
119 //[_context makeCurrentContext];
120 printf("- drawRect:(NSRect)rect\n");
121 CocoaDispatch_Update([self ecereWindow]);
124 - (void)viewDidMoveToWindow
126 // Register with window for resize and move notification.
127 [[NSNotificationCenter defaultCenter]
129 selector:@selector(windowResized:)
130 name:NSWindowDidResizeNotification
131 object:[self window]];
133 [[NSNotificationCenter defaultCenter]
135 selector:@selector(windowMoved:)
136 name:NSWindowDidMoveNotification
137 object:[self window]];
140 - (void)windowResized:(NSNotification *)notification
144 NSRect rect = [[self window] frame];
146 CocoaDispatch_ExternalPosition([self ecereWindow], rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
148 printf("- (void)windowResized:(NSNotification *)notification\n");
151 - (void)windowMoved:(NSNotification *)notification;
155 NSRect rect = [[self window] frame];
157 CocoaDispatch_ExternalPosition([self ecereWindow], rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
159 printf("- (void)windowMoved:(NSNotification *)notification\n");
162 - (EcereWindowRef)ecereWindow
167 - setEcereWindow:(EcereWindowRef)ecereWindow
169 _ecereWindow = ecereWindow;
172 - (void)mouseDown:(NSEvent *)event
174 NSPoint location = [NSEvent mouseLocation];
178 CocoaDispatch_OnLeftButtonDown([self ecereWindow], location.x, location.y, mod);
181 - (CocoaColor)foreground
186 - (void)setForeground:(CocoaColor)color
191 - (CocoaColor)background
196 - (void)setBackground:(CocoaColor)color