Subversion Repositories gelsvn

Rev

Rev 656 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 656 Rev 657
1
#import "BasicOpenGLView.h"
1
#import "BasicOpenGLView.h"
2
#include <GLGraphics/MeshEditor.h>
2
#include <GLGraphics/MeshEditor.h>
3
 
3
 
4
using namespace CGLA;
4
using namespace CGLA;
5
using namespace GLGraphics;
5
using namespace GLGraphics;
6
 
6
 
7
MeshEditor me;
7
MeshEditor me;
8
 
8
 
9
// ==================================
9
// ==================================
10
#pragma mark ---- Error Reporting ----
10
#pragma mark ---- Error Reporting ----
11
 
11
 
12
// error reporting as both window message and debugger string
12
// error reporting as both window message and debugger string
13
void reportError (char * strError, int where)
13
void reportError (char * strError, int where)
14
{
14
{
15
    NSMutableDictionary *attribs = [NSMutableDictionary dictionary];
15
    NSMutableDictionary *attribs = [NSMutableDictionary dictionary];
16
    [attribs setObject: [NSFont fontWithName: @"Monaco" size: 9.0f] forKey: NSFontAttributeName];
16
    [attribs setObject: [NSFont fontWithName: @"Monaco" size: 9.0f] forKey: NSFontAttributeName];
17
    [attribs setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName];
17
    [attribs setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName];
18
    
18
    
19
    //	gErrorTime = getElapsedTime ();
19
    //	gErrorTime = getElapsedTime ();
20
	NSString * errString = [NSString stringWithFormat:@"Error: %s @ line %d", strError, where ];
20
	NSString * errString = [NSString stringWithFormat:@"Error: %s @ line %d", strError, where ];
21
	NSLog (@"%@\n", errString);
21
	NSLog (@"%@\n", errString);
22
}
22
}
23
 
23
 
24
// ---------------------------------
24
// ---------------------------------
25
 
25
 
26
// if error dump gl errors to debugger string, return error
26
// if error dump gl errors to debugger string, return error
27
GLenum glReportError (int where = -1)
27
GLenum glReportError (int where = -1)
28
{
28
{
29
	GLenum err = glGetError();
29
	GLenum err = glGetError();
30
	if (GL_NO_ERROR != err)
30
	if (GL_NO_ERROR != err)
31
		reportError ((char *) gluErrorString (err), where);
31
		reportError ((char *) gluErrorString (err), where);
32
	return err;
32
	return err;
33
}
33
}
34
 
34
 
35
#pragma mark ---- OpenGL Utils ----
35
#pragma mark ---- OpenGL Utils ----
36
 
36
 
37
// ---------------------------------
37
// ---------------------------------
38
 
38
 
39
 
39
 
40
// ===================================
40
// ===================================
41
 
41
 
42
@implementation BasicOpenGLView
42
@implementation BasicOpenGLView
43
 
43
 
44
// ---------------------------------
44
// ---------------------------------
45
 
45
 
46
// handles resizing of GL need context update and if the window dimensions change, a
46
// handles resizing of GL need context update and if the window dimensions change, a
47
// a window dimension update, reseting of viewport and an update of the projection matrix
47
// a window dimension update, reseting of viewport and an update of the projection matrix
48
- (void) reshape
48
- (void) reshape
49
{
49
{
50
	NSRect rectView = [self bounds];
-
 
51
	me.reshape(rectView.size.width,rectView.size.height);
-
 
52
    NSRect backRect = [self convertRectToBacking:rectView];
50
    NSRect backRect = [self convertRectToBacking:[self bounds]];
53
    glViewport (0, 0, NSWidth(backRect), NSHeight(backRect));
51
    glViewport (0, 0, NSWidth(backRect), NSHeight(backRect));
-
 
52
	me.reshape(NSWidth(backRect),NSHeight(backRect));
54
}
53
}
55
 
54
 
56
// ---------------------------------
55
// ---------------------------------
57
// ---------------------------------
56
// ---------------------------------
58
 
57
 
59
// per-window timer function, basic time based animation preformed here
58
// per-window timer function, basic time based animation preformed here
60
- (void)animationTimer:(NSTimer *)timer
59
- (void)animationTimer:(NSTimer *)timer
61
{
60
{
62
    if(me.try_spinning_ball())
61
    if(me.try_spinning_ball())
63
        [self setNeedsDisplay: YES];
62
        [self setNeedsDisplay: YES];
64
}
63
}
65
 
64
 
66
-(IBAction)save_window_to_pasteboard:(id)sender
65
-(IBAction)save_window_to_pasteboard:(id)sender
67
{
66
{
68
    
67
    
69
    NSPasteboard *pb = [NSPasteboard generalPasteboard];
68
    NSPasteboard *pb = [NSPasteboard generalPasteboard];
70
    
69
    
71
    // Telling the pasteboard what type of data we're going to send in
70
    // Telling the pasteboard what type of data we're going to send in
72
    [pb declareTypes:[NSArray arrayWithObjects:NSPasteboardTypePNG,nil] owner:self];
71
    [pb declareTypes:[NSArray arrayWithObjects:NSPasteboardTypePNG,nil] owner:self];
73
    
72
    
74
    NSRect backRect = [self convertRectToBacking: [self bounds]];
73
    NSRect backRect = [self convertRectToBacking: [self bounds]];
75
    NSSize sz;
74
    NSSize sz;
76
    sz.width = NSWidth(backRect);
75
    sz.width = NSWidth(backRect);
77
    sz.height = NSHeight(backRect);
76
    sz.height = NSHeight(backRect);
78
    
77
    
79
    NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
78
    NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
80
                                                                    pixelsWide: sz.width
79
                                                                    pixelsWide: sz.width
81
                                                                    pixelsHigh: sz.height
80
                                                                    pixelsHigh: sz.height
82
                                                                 bitsPerSample: 8
81
                                                                 bitsPerSample: 8
83
                                                               samplesPerPixel: 3
82
                                                               samplesPerPixel: 3
84
                                                                      hasAlpha: NO
83
                                                                      hasAlpha: NO
85
                                                                      isPlanar: NO
84
                                                                      isPlanar: NO
86
                                                                colorSpaceName: NSCalibratedRGBColorSpace
85
                                                                colorSpaceName: NSCalibratedRGBColorSpace
87
                                                                   bytesPerRow: 0				// indicates no empty bytes at row end
86
                                                                   bytesPerRow: 0				// indicates no empty bytes at row end
88
                                                                  bitsPerPixel: 0];
87
                                                                  bitsPerPixel: 0];
89
    
88
    
90
    glReadBuffer(GL_FRONT);
89
    glReadBuffer(GL_FRONT);
91
    int bytesPerRow = [rep bytesPerRow];
90
    int bytesPerRow = [rep bytesPerRow];
92
	glPixelStorei(GL_PACK_ROW_LENGTH, 8*bytesPerRow/[rep bitsPerPixel]);
91
	glPixelStorei(GL_PACK_ROW_LENGTH, 8*bytesPerRow/[rep bitsPerPixel]);
93
    glReadPixels(0, 0, NSWidth(backRect), NSHeight(backRect), GL_RGB, GL_UNSIGNED_BYTE,  [rep bitmapData]);
92
    glReadPixels(0, 0, NSWidth(backRect), NSHeight(backRect), GL_RGB, GL_UNSIGNED_BYTE,  [rep bitmapData]);
94
    
93
    
95
    NSBitmapImageRep* flipped =  [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
94
    NSBitmapImageRep* flipped =  [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
96
                                                                         pixelsWide: sz.width
95
                                                                         pixelsWide: sz.width
97
                                                                         pixelsHigh: sz.height
96
                                                                         pixelsHigh: sz.height
98
                                                                      bitsPerSample: 8
97
                                                                      bitsPerSample: 8
99
                                                                    samplesPerPixel: 3
98
                                                                    samplesPerPixel: 3
100
                                                                           hasAlpha: NO
99
                                                                           hasAlpha: NO
101
                                                                           isPlanar: NO
100
                                                                           isPlanar: NO
102
                                                                     colorSpaceName: NSCalibratedRGBColorSpace
101
                                                                     colorSpaceName: NSCalibratedRGBColorSpace
103
                                                                        bytesPerRow: 0				// indicates no empty bytes at row end
102
                                                                        bytesPerRow: 0				// indicates no empty bytes at row end
104
                                                                       bitsPerPixel: 0];
103
                                                                       bitsPerPixel: 0];
105
    
104
    
106
    for(int j=1; j< sz.height+1; ++j)
105
    for(int j=1; j< sz.height+1; ++j)
107
        for(int i=0;i<sz.width;++i)
106
        for(int i=0;i<sz.width;++i)
108
        {
107
        {
109
            NSUInteger pixels[4];
108
            NSUInteger pixels[4];
110
            [rep getPixel: pixels atX:i y:j];
109
            [rep getPixel: pixels atX:i y:j];
111
            [flipped setPixel: pixels atX:i y:sz.height-j];
110
            [flipped setPixel: pixels atX:i y:sz.height-j];
112
        }
111
        }
113
    
112
    
114
    // Converting the representation to PNG and sending it to the pasteboard (with type indicated)
113
    // Converting the representation to PNG and sending it to the pasteboard (with type indicated)
115
    [pb setData:[flipped representationUsingType:NSPNGFileType properties:nil] forType:NSPasteboardTypePNG];
114
    [pb setData:[flipped representationUsingType:NSPNGFileType properties:nil] forType:NSPasteboardTypePNG];
116
    
115
    
117
    
116
    
118
    
117
    
119
}
118
}
120
 
119
 
121
 
120
 
122
 
121
 
123
-(void)keyDown:(NSEvent *)theEvent
122
-(void)keyDown:(NSEvent *)theEvent
124
{
123
{
125
    switch ([theEvent keyCode]) {
124
    switch ([theEvent keyCode]) {
126
        case 123:
125
        case 123:
127
            me.key_left();
126
            me.key_left();
128
            break;
127
            break;
129
        case 124:
128
        case 124:
130
            me.key_right();
129
            me.key_right();
131
            break;
130
            break;
132
        case 126:
131
        case 126:
133
            me.key_up();
132
            me.key_up();
134
            break;
133
            break;
135
        case 125:
134
        case 125:
136
            me.key_down();
135
            me.key_down();
137
            break;
136
            break;
138
        case 115:
137
        case 115:
139
            me.key_home();
138
            me.key_home();
140
            break;
139
            break;
141
        case 119:
140
        case 119:
142
            me.key_end();
141
            me.key_end();
143
            break;
142
            break;
144
        default:
143
        default:
145
            NSString *characters = [theEvent characters];
144
            NSString *characters = [theEvent characters];
146
            if ([characters length]) {
145
            if ([characters length]) {
147
                unichar character = [characters characterAtIndex:0];
146
                unichar character = [characters characterAtIndex:0];
148
                me.keyparse(character);
147
                me.keyparse(character);
149
            }
148
            }
150
            break;
149
            break;
151
    }
150
    }
152
    [self setNeedsDisplay: YES];
151
    [self setNeedsDisplay: YES];
153
}
152
}
154
 
153
 
155
 
154
 
156
// ---------------------------------
155
// ---------------------------------
157
 
156
 
158
- (void)mouseDown:(NSEvent *)theEvent // trackball
157
- (void)mouseDown:(NSEvent *)theEvent // trackball
159
{
158
{
160
    if ([theEvent modifierFlags] & NSAlternateKeyMask) // send to pan
159
    if ([theEvent modifierFlags] & NSAlternateKeyMask) // send to pan
161
		[self rightMouseDown:theEvent];
160
		[self rightMouseDown:theEvent];
162
	else {
161
	else {
163
        
162
        
164
        NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
163
        NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
165
        [[self openGLContext] makeCurrentContext];
164
        [[self openGLContext] makeCurrentContext];
166
        Vec2i pos(location.x,location.y);
165
        Vec2i pos(location.x,location.y);
167
        pos *= int([[self window]backingScaleFactor]);
166
        pos *= int([[self window]backingScaleFactor]);
-
 
167
        if([theEvent modifierFlags] & NSShiftKeyMask)
168
        if(!me.grab_mesh(pos))
168
            me.grab_mesh(pos);
-
 
169
        else if([theEvent modifierFlags] & NSControlKeyMask) {
-
 
170
            if(me.select_vertex(pos))
-
 
171
                [self setNeedsDisplay: YES];
-
 
172
        }
-
 
173
        else
169
            me.grab_ball(ROTATE_ACTION,pos);
174
            me.grab_ball(ROTATE_ACTION,pos);
170
	}
175
	}
171
}
176
}
172
 
177
 
173
 
178
 
174
 
179
 
175
// ---------------------------------
180
// ---------------------------------
176
 
181
 
177
- (void)rightMouseDown:(NSEvent *)theEvent // pan
182
- (void)rightMouseDown:(NSEvent *)theEvent // pan
178
{
183
{
179
	NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
184
	NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
180
    Vec2i pos(location.x,location.y);
185
    Vec2i pos(location.x,location.y);
181
    pos *= int([[self window]backingScaleFactor]);
186
    pos *= int([[self window]backingScaleFactor]);
182
    me.grab_ball(PAN_ACTION,pos);
187
    me.grab_ball(PAN_ACTION,pos);
183
}
188
}
184
 
189
 
185
// ---------------------------------
190
// ---------------------------------
186
 
191
 
187
- (void)otherMouseDown:(NSEvent *)theEvent //dolly
192
- (void)otherMouseDown:(NSEvent *)theEvent //dolly
188
{
193
{
189
}
194
}
190
 
195
 
191
// ---------------------------------
196
// ---------------------------------
192
 
197
 
193
- (void)mouseUp:(NSEvent *)theEvent
198
- (void)mouseUp:(NSEvent *)theEvent
194
{
199
{
195
    me.release_mesh();
200
    me.release_mesh();
196
    me.release_ball();
201
    me.release_ball();
197
}
202
}
198
 
203
 
199
// ---------------------------------
204
// ---------------------------------
200
 
205
 
201
- (void)rightMouseUp:(NSEvent *)theEvent
206
- (void)rightMouseUp:(NSEvent *)theEvent
202
{
207
{
203
	[self mouseUp:theEvent];
208
	[self mouseUp:theEvent];
204
}
209
}
205
 
210
 
206
// ---------------------------------
211
// ---------------------------------
207
 
212
 
208
- (void)otherMouseUp:(NSEvent *)theEvent
213
- (void)otherMouseUp:(NSEvent *)theEvent
209
{
214
{
210
	[self mouseUp:theEvent];
215
	[self mouseUp:theEvent];
211
}
216
}
212
 
217
 
213
// ---------------------------------
218
// ---------------------------------
214
 
219
 
215
- (void)mouseDragged:(NSEvent *)theEvent
220
- (void)mouseDragged:(NSEvent *)theEvent
216
{
221
{
217
	NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
222
	NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
218
    Vec2i pos(location.x,location.y);
223
    Vec2i pos(location.x,location.y);
219
    pos *= int([[self window]backingScaleFactor]);
224
    pos *= int([[self window]backingScaleFactor]);
-
 
225
//    NSLog(@"Pos <%d %d> ", pos[0], pos[1]);
220
    [[self openGLContext] makeCurrentContext];
226
    [[self openGLContext] makeCurrentContext];
221
    if(!me.drag_mesh(pos))
227
    if(!me.drag_mesh(pos))
222
        me.roll_ball(pos);
228
        me.roll_ball(pos);
223
    [self setNeedsDisplay: YES];
229
    [self setNeedsDisplay: YES];
224
    
230
    
225
}
231
}
226
 
232
 
227
// ---------------------------------
233
// ---------------------------------
228
 
234
 
229
- (void)scrollWheel:(NSEvent *)theEvent
235
- (void)scrollWheel:(NSEvent *)theEvent
230
{
236
{
231
    Vec2i pos(0,300);
237
    Vec2i pos(0,300);
232
    me.grab_ball(ZOOM_ACTION,pos);
238
    me.grab_ball(ZOOM_ACTION,pos);
233
    pos[1] -= 3*[theEvent deltaY];
239
    pos[1] -= 3*[theEvent deltaY];
234
    me.roll_ball(pos);
240
    me.roll_ball(pos);
235
    me.release_ball();
241
    me.release_ball();
236
    [self setNeedsDisplay: YES];
242
    [self setNeedsDisplay: YES];
237
}
243
}
238
 
244
 
239
// ---------------------------------
245
// ---------------------------------
240
 
246
 
241
- (void)rightMouseDragged:(NSEvent *)theEvent
247
- (void)rightMouseDragged:(NSEvent *)theEvent
242
{
248
{
243
	[self mouseDragged: theEvent];
249
	[self mouseDragged: theEvent];
244
}
250
}
245
 
251
 
246
// ---------------------------------
252
// ---------------------------------
247
 
253
 
248
- (void)otherMouseDragged:(NSEvent *)theEvent
254
- (void)otherMouseDragged:(NSEvent *)theEvent
249
{
255
{
250
	[self mouseDragged: theEvent];
256
	[self mouseDragged: theEvent];
251
}
257
}
252
 
258
 
253
// ---------------------------------
259
// ---------------------------------
254
 
260
 
255
- (void) drawRect:(NSRect)rect
261
- (void) drawRect:(NSRect)rect
256
{
262
{
257
    NSOpenGLContext* ctxt = [self openGLContext];
263
    NSOpenGLContext* ctxt = [self openGLContext];
258
    if(ctxt != nil) {
264
    if(ctxt != nil) {
259
        [ctxt makeCurrentContext];
265
        [ctxt makeCurrentContext];
260
        me.display(int([[self window]backingScaleFactor]));
266
        me.display(int([[self window]backingScaleFactor]));
261
        [ctxt flushBuffer];
267
        [ctxt flushBuffer];
262
    }
268
    }
263
}
269
}
264
 
270
 
265
// ---------------------------------
271
// ---------------------------------
266
 
272
 
267
// set initial OpenGL state (current context is set)
273
// set initial OpenGL state (current context is set)
268
// called after context is created
274
// called after context is created
269
- (void) prepareOpenGL
275
- (void) prepareOpenGL
270
{
276
{
271
    [[self openGLContext] makeCurrentContext];
277
    [[self openGLContext] makeCurrentContext];
272
    GLint swapInt = 1;
278
    GLint swapInt = 1;
273
    [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; // set to vbl sync
279
    [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; // set to vbl sync
274
    me.init();
280
    me.init();
275
    NSLog(@"OpenGL Initialized");
281
    NSLog(@"OpenGL Initialized");
276
}
282
}
277
// ---------------------------------
283
// ---------------------------------
278
 
284
 
279
// this can be a troublesome call to do anything heavyweight, as it is called on window moves, resizes, and display config changes.  So be
285
// this can be a troublesome call to do anything heavyweight, as it is called on window moves, resizes, and display config changes.  So be
280
// careful of doing too much here.
286
// careful of doing too much here.
281
- (void) update // window resizes, moves and display changes (resize, depth and display config change)
287
- (void) update // window resizes, moves and display changes (resize, depth and display config change)
282
{
288
{
283
	[super update];
289
	[super update];
284
	if (![self inLiveResize])  {// if not doing live resize
290
	if (![self inLiveResize])  {// if not doing live resize
285
	}
291
	}
286
    
292
    
287
}
293
}
288
 
294
 
289
// ---------------------------------
295
// ---------------------------------
290
 
296
 
291
-(id) initWithFrame: (NSRect) frameRect
297
-(id) initWithFrame: (NSRect) frameRect
292
{
298
{
293
	self = [super initWithFrame: frameRect ];
299
	self = [super initWithFrame: frameRect ];
294
    return self;
300
    return self;
295
}
301
}
296
 
302
 
297
// ---------------------------------
303
// ---------------------------------
298
 
304
 
299
- (BOOL)acceptsFirstResponder
305
- (BOOL)acceptsFirstResponder
300
{
306
{
301
    return YES;
307
    return YES;
302
}
308
}
303
 
309
 
304
// ---------------------------------
310
// ---------------------------------
305
 
311
 
306
- (BOOL)becomeFirstResponder
312
- (BOOL)becomeFirstResponder
307
{
313
{
308
    return  YES;
314
    return  YES;
309
}
315
}
310
 
316
 
311
// ---------------------------------
317
// ---------------------------------
312
 
318
 
313
- (BOOL)resignFirstResponder
319
- (BOOL)resignFirstResponder
314
{
320
{
315
    return YES;
321
    return YES;
316
}
322
}
317
 
323
 
318
// ---------------------------------
324
// ---------------------------------
319
 
325
 
320
- (void) awakeFromNib
326
- (void) awakeFromNib
321
{
327
{
322
	timer = [NSTimer timerWithTimeInterval:(1.0f/60.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES];
328
	timer = [NSTimer timerWithTimeInterval:(1.0f/60.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES];
323
	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
329
	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
324
	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode]; // ensure timer fires during resize
330
	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode]; // ensure timer fires during resize
325
    [[NSApplication sharedApplication] setDelegate: self];
331
    [[NSApplication sharedApplication] setDelegate: self];
326
    [self registerForDraggedTypes: [NSArray arrayWithObjects: (id) kUTTypeData,nil]];
332
    [self registerForDraggedTypes: [NSArray arrayWithObjects: (id) kUTTypeData,nil]];
327
}
333
}
328
 
334
 
329
-(IBAction)open_file_dialog:(id)sender
335
-(IBAction)open_file_dialog:(id)sender
330
{
336
{
331
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];
337
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];
332
    [openDlg setCanChooseFiles:YES];
338
    [openDlg setCanChooseFiles:YES];
333
    [openDlg setCanChooseDirectories:NO];
339
    [openDlg setCanChooseDirectories:NO];
334
    [openDlg setAllowsMultipleSelection:YES];
340
    [openDlg setAllowsMultipleSelection:YES];
335
    if ( [openDlg runModal] == NSOKButton )
341
    if ( [openDlg runModal] == NSOKButton )
336
        for(NSURL *fileURL in [openDlg URLs]) {
342
        for(NSURL *fileURL in [openDlg URLs]) {
337
            me.add_file([ [fileURL path] UTF8String]);
343
            me.add_file([ [fileURL path] UTF8String]);
338
            [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: fileURL];
344
            [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: fileURL];
339
        }
345
        }
340
    [self setNeedsDisplay: YES];
346
    [self setNeedsDisplay: YES];
341
}
347
}
342
 
348
 
343
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
349
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
344
{
350
{
345
    if(me.add_file([ filename UTF8String])) {
351
    if(me.add_file([ filename UTF8String])) {
346
        [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:filename]];
352
        [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:filename]];
347
        [self setNeedsDisplay: YES];
353
        [self setNeedsDisplay: YES];
348
        return YES;
354
        return YES;
349
    }
355
    }
350
    return NO;
356
    return NO;
351
}
357
}
352
 
358
 
353
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
359
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
354
{
360
{
355
    NSURL* fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
361
    NSURL* fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
356
    me.add_file([[fileURL path] UTF8String]);
362
    me.add_file([[fileURL path] UTF8String]);
357
    [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: fileURL];
363
    [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: fileURL];
358
    [self setNeedsDisplay: YES];
364
    [self setNeedsDisplay: YES];
359
    return YES;
365
    return YES;
360
}
366
}
361
 
367
 
362
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
368
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
363
{
369
{
364
    return YES;
370
    return YES;
365
}
371
}
366
 
372
 
367
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
373
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
368
{
374
{
369
    return NSDragOperationCopy;
375
    return NSDragOperationCopy;
370
}
376
}
371
 
377
 
372
 
378
 
373
@end
379
@end
374
 
380