OSDN Git Service

fcf0a12ed250ece30b86314cec3e69b24c9c7968
[eliscolors/main.git] / ElisTimeLineView.m
1 //
2 //  ElisTimeLineView.m
3 //  Elis Colors
4 //
5 //  Created by 柳 on 09/09/12.
6 //  Copyright 2009 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ElisTimeLineView.h"
10
11
12 @implementation ElisTimeLineView
13
14 - (void)awakeFromNib
15 {
16     [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
17     leftCursorRect = NSZeroRect;
18     rightCursorRect = NSZeroRect;
19 }
20
21 // ここにドラッグし終えた時の処理を書く。
22 - (BOOL)performDragOperation:(id)sender
23 {
24 //    [compositionView draggingEndFromBrowser];
25 //    dragMedia = nil;
26     [_timeLineController draggingDone];
27     return YES;
28 }
29
30 // 何かがドラッグされてきた。ここではその準備。
31 - (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
32 {
33     NSPasteboard* board = [sender draggingPasteboard];
34     NSData *data;
35     NSString *path, *errorDescription;
36     NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
37     
38     data = [board dataForType:NSFilenamesPboardType];
39     
40     NSArray *filenames = [NSPropertyListSerialization propertyListFromData:data 
41                                                           mutabilityOption:kCFPropertyListImmutable 
42                                                                     format:nil 
43                                                           errorDescription:&errorDescription];
44     
45     path = [filenames objectAtIndex:0];
46     [_timeLineController addMedia:path];
47     return 1;
48 }
49
50 - (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
51 {
52     [_timeLineController dragging:[sender draggingLocation]];
53     return 1;
54 }
55
56 - (void)draggingExited:(id <NSDraggingInfo>)sender
57 {
58     [_mainController deleteSelectLayer:nil];
59 }
60
61 - (void)mouseDown:(NSEvent *)theEvent
62 {
63     NSPoint event_location = [theEvent locationInWindow];
64     NSPoint local_point = [self convertPoint:event_location fromView:nil];
65     
66     if([self isInclude:leftCursorRect point:local_point])
67         [_timeLineController stretchLeft];
68     else if([self isInclude:rightCursorRect point:local_point])
69         [_timeLineController stretchRight];
70     else
71         [_timeLineController clicked:local_point];
72 }
73
74 - (void)mouseDragged:(NSEvent *)theEvent
75 {
76     NSPoint event_location = [theEvent locationInWindow];
77     NSPoint local_point = [self convertPoint:event_location fromView:nil];
78     [_timeLineController dragging:local_point];
79 }
80
81 - (void)mouseUp:(NSEvent *)theEvent
82 {
83     NSPoint event_location = [theEvent locationInWindow];
84     NSPoint local_point = [self convertPoint:event_location fromView:nil];
85     if([theEvent clickCount] == 2)
86         [_timeLineController doubleClicked];
87     else
88         [_timeLineController draggingDone];
89 }
90
91 - (void)setCursorRect:(CGRect)rect
92 {
93     leftCursorRect = NSMakeRect(rect.origin.x-4, rect.origin.y, 9, rect.size.height);
94     rightCursorRect = NSMakeRect(rect.origin.x+rect.size.width-4, rect.origin.y, 9, rect.size.height);
95     [self resetCursorRects];
96 }
97
98 - (void)resetCursorRects
99 {
100     [self addCursorRect:rightCursorRect cursor:[NSCursor resizeLeftRightCursor]];
101     [self addCursorRect:leftCursorRect cursor:[NSCursor resizeLeftRightCursor]];
102 }
103
104 - (BOOL)isInclude:(NSRect)r point:(NSPoint)point
105 {
106     return r.origin.x <= point.x && point.x <= r.origin.x + r.size.width
107         && r.origin.y <= point.y && point.y <= r.origin.y + r.size.height;
108 }
109
110 @end