1 // Copyright (c) 2009 Yanagi Asakura
3 // This software is provided 'as-is', without any express or implied
4 // warranty. In no event will the authors be held liable for any damages
5 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
11 // 1. The origin of this software must not be misrepresented; you must not
12 // claim that you wrote the original software. If you use this software
13 // in a product, an acknowledgment in the product documentation would be
14 // appreciated but is not required.
16 // 2. Altered source versions must be plainly marked as such, and must not be
17 // misrepresented as being the original software.
19 // 3. This notice may not be removed or altered from any source
26 // Created by 柳 on 09/09/12.
27 // Copyright 2009 __MyCompanyName__. All rights reserved.
30 #import "ElisTimeLineView.h"
33 @implementation ElisTimeLineView
37 [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
38 leftCursorRect = NSZeroRect;
39 rightCursorRect = NSZeroRect;
42 // ここにドラッグし終えた時の処理を書く。
43 - (BOOL)performDragOperation:(id)sender
45 // [compositionView draggingEndFromBrowser];
47 [_timeLineController draggingDone];
51 // 何かがドラッグされてきた。ここではその準備。
52 - (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
54 NSPasteboard* board = [sender draggingPasteboard];
56 NSString *path, *errorDescription;
57 NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
59 data = [board dataForType:NSFilenamesPboardType];
61 NSArray *filenames = [NSPropertyListSerialization propertyListFromData:data
62 mutabilityOption:kCFPropertyListImmutable
64 errorDescription:&errorDescription];
66 path = [filenames objectAtIndex:0];
67 [_timeLineController addMedia:path];
68 [_timeLineController readyInDrag:[self convertPoint:[sender draggingLocation] fromView:nil]];
72 - (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
74 [_timeLineController dragging:[self convertPoint:[sender draggingLocation] fromView:nil]];
78 - (void)draggingExited:(id <NSDraggingInfo>)sender
80 [_mainController deleteSelectLayer:nil];
83 - (void)mouseDown:(NSEvent *)theEvent
85 NSPoint event_location = [theEvent locationInWindow];
86 NSPoint local_point = [self convertPoint:event_location fromView:nil];
88 if([self isInclude:leftCursorRect point:local_point])
89 [_timeLineController stretchLeft];
90 else if([self isInclude:rightCursorRect point:local_point])
91 [_timeLineController stretchRight];
93 [_timeLineController clicked:local_point];
96 - (void)mouseDragged:(NSEvent *)theEvent
98 NSPoint event_location = [theEvent locationInWindow];
99 NSPoint local_point = [self convertPoint:event_location fromView:nil];
100 [_timeLineController dragging:local_point];
103 - (void)mouseUp:(NSEvent *)theEvent
105 NSPoint event_location = [theEvent locationInWindow];
106 NSPoint local_point = [self convertPoint:event_location fromView:nil];
107 if([theEvent clickCount] == 2)
108 [_timeLineController doubleClicked];
110 [_timeLineController draggingDone];
113 - (void)setCursorRect:(CGRect)rect
115 leftCursorRect = NSMakeRect(rect.origin.x-4, rect.origin.y, 9, rect.size.height);
116 rightCursorRect = NSMakeRect(rect.origin.x+rect.size.width-4, rect.origin.y, 9, rect.size.height);
117 [self resetCursorRects];
120 - (void)resetCursorRects
122 [self addCursorRect:rightCursorRect cursor:[NSCursor resizeLeftRightCursor]];
123 [self addCursorRect:leftCursorRect cursor:[NSCursor resizeLeftRightCursor]];
126 - (BOOL)isInclude:(NSRect)r point:(NSPoint)point
128 return r.origin.x <= point.x && point.x <= r.origin.x + r.size.width
129 && r.origin.y <= point.y && point.y <= r.origin.y + r.size.height;