-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAQTModelAdditions.m
75 lines (65 loc) · 2.07 KB
/
AQTModelAdditions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// AQTModelAdditions.m
// AquaTerm
//
// Created by Per Persson on Wed Jun 09 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
#import "AQTModelAdditions.h"
#import "AQTGraphicDrawingMethods.h"
#import "AQTFunctions.h"
@implementation AQTModel (AQTModelAdditions)
-(void)invalidate
{
dirtyRect = AQTRectFromSize([self canvasSize]);
}
-(void)clearDirtyRect
{
dirtyRect = NSZeroRect;
}
-(void)appendModel:(AQTModel *)newModel
{
BOOL backgroundDidChange; // FIXME
// NSLog(@"in --> %@ %s line %d", NSStringFromSelector(_cmd), __FILE__, __LINE__);
backgroundDidChange = !AQTEqualColors([self color], [newModel color]);
[self setTitle:[newModel title]];
[self setCanvasSize:[newModel canvasSize]];
[self setColor:[newModel color]];
[self setBounds:AQTUnionRect([self bounds], [newModel updateBounds])];
[self addObjectsFromArray:[newModel modelObjects]];
dirtyRect = backgroundDidChange?AQTRectFromSize([self canvasSize]):AQTUnionRect(dirtyRect, [newModel bounds]);
}
- (void)removeGraphicsInRect:(NSRect)targetRect
{
NSRect testRect;
NSRect clipRect = AQTRectFromSize([self canvasSize]);
NSRect newBounds = NSZeroRect;
int32_t i;
int32_t objectCount = [self count];
// check for nothing to remove or disjoint modelBounds <--> targetRect
if (objectCount == 0 || AQTIntersectsRect(targetRect, [self bounds]) == NO)
return;
// Apply clipRect (=canvasRect) to graphic bounds before comparing.
if (AQTContainsRect(targetRect, NSIntersectionRect([self bounds], clipRect)))
{
[self removeAllObjects];
}
else
{
for (i = objectCount - 1; i >= 0; i--)
{
testRect = [[modelObjects objectAtIndex:i] bounds];
if (AQTContainsRect(targetRect, NSIntersectionRect(testRect, clipRect)))
{
[self removeObjectAtIndex:i];
}
else
{
newBounds = AQTUnionRect(newBounds, testRect);
}
}
}
[self setBounds:newBounds];
dirtyRect = AQTUnionRect(dirtyRect, targetRect);
}
@end