OSDN Git Service

add undo/redo system
[eliscolors/main.git] / ElisTimeLineView.m
1 //  Copyright (c) 2009 Yanagi Asakura
2 //
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.
6 //
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:
10 //
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.
15 //
16 //  2. Altered source versions must be plainly marked as such, and must not be
17 //  misrepresented as being the original software.
18 //
19 //  3. This notice may not be removed or altered from any source
20 //  distribution.
21
22 //
23 //  ElisTimeLineView.m
24 //  Elis Colors
25 //
26 //  Created by 柳 on 09/09/12.
27 //  Copyright 2009 __MyCompanyName__. All rights reserved.
28 //
29
30 #import "ElisTimeLineView.h"
31
32
33 @implementation ElisTimeLineView
34
35 - (void)awakeFromNib
36 {
37     [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
38     leftCursorRect = NSZeroRect;
39     rightCursorRect = NSZeroRect;
40 }
41
42 // ここにドラッグし終えた時の処理を書く。
43 - (BOOL)performDragOperation:(id)sender
44 {
45 //    [compositionView draggingEndFromBrowser];
46 //    dragMedia = nil;
47     [_timeLineController draggingDone];
48     return YES;
49 }
50
51 // 何かがドラッグされてきた。ここではその準備。
52 - (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
53 {
54     NSPasteboard* board = [sender draggingPasteboard];
55     NSData *data;
56     NSString *path, *errorDescription;
57     NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
58     
59     data = [board dataForType:NSFilenamesPboardType];
60     
61     NSArray *filenames = [NSPropertyListSerialization propertyListFromData:data 
62                                                           mutabilityOption:kCFPropertyListImmutable 
63                                                                     format:nil 
64                                                           errorDescription:&errorDescription];
65     
66     path = [filenames objectAtIndex:0];
67     [_timeLineController addMedia:path];
68     [_timeLineController readyInDrag:[self convertPoint:[sender draggingLocation] fromView:nil]];
69     return 1;
70 }
71
72 - (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
73 {
74     [_timeLineController dragging:[self convertPoint:[sender draggingLocation] fromView:nil]];
75     return 1;
76 }
77
78 - (void)draggingExited:(id <NSDraggingInfo>)sender
79 {
80     [_mainController deleteSelectLayer:nil];
81 }
82
83 - (void)mouseDown:(NSEvent *)theEvent
84 {
85     NSPoint event_location = [theEvent locationInWindow];
86     NSPoint local_point = [self convertPoint:event_location fromView:nil];
87     
88     if([self isInclude:leftCursorRect point:local_point])
89         [_timeLineController stretchLeft];
90     else if([self isInclude:rightCursorRect point:local_point])
91         [_timeLineController stretchRight];
92     else
93         [_timeLineController clicked:local_point];
94 }
95
96 - (void)mouseDragged:(NSEvent *)theEvent
97 {
98     NSPoint event_location = [theEvent locationInWindow];
99     NSPoint local_point = [self convertPoint:event_location fromView:nil];
100     [_timeLineController dragging:local_point];
101 }
102
103 - (void)mouseUp:(NSEvent *)theEvent
104 {
105     NSPoint event_location = [theEvent locationInWindow];
106     NSPoint local_point = [self convertPoint:event_location fromView:nil];
107     if([theEvent clickCount] == 2)
108         [_timeLineController doubleClicked];
109     else
110         [_timeLineController draggingDone];
111 }
112
113 - (void)setCursorRect:(CGRect)rect
114 {
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];
118 }
119
120 - (void)resetCursorRects
121 {
122     [self addCursorRect:rightCursorRect cursor:[NSCursor resizeLeftRightCursor]];
123     [self addCursorRect:leftCursorRect cursor:[NSCursor resizeLeftRightCursor]];
124 }
125
126 - (BOOL)isInclude:(NSRect)r point:(NSPoint)point
127 {
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;
130 }
131
132 @end