/
MBImageView.m
66 lines (53 loc) · 1.47 KB
/
MBImageView.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
#import "MBImageView.h"
#import "MBtypes.h"
#import "MBAqua.h"
static float transparency = 0.7f;
@implementation MBImageView
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint p = [theEvent locationInWindow];
p = [self convertPoint:p fromView:nil];
[aqua aqua_button_press:p.x :p.y];
//r [aqua aqua_button_press:p.x :400-(NSHeight(_bounds) - p.y)];
// NSLog(@"mouseDown %@ %@",NSStringFromPoint(p),NSHeight(_bounds));
cursor = p;
[self setNeedsDisplay:YES];
}
- (void)mouseUp:(NSEvent *)theEvent
{
NSPoint p = [theEvent locationInWindow];
p = [self convertPoint:p fromView:nil];
[aqua aqua_button_release:p.x :p.y];
//r [aqua aqua_button_release:p.x :400-(NSHeight(_bounds) - p.y)];
// NSLog(@"mouseUp %@ %@",NSStringFromPoint(p),NSHeight(_bounds));
}
- (void)mouseDragged:(NSEvent *)theEvent
{
NSPoint p = [theEvent locationInWindow];
cursor = [self convertPoint:p fromView:nil];
[self setNeedsDisplay:YES];
}
- (void)drawRect:(NSRect)rect
{
[subimage compositeToPoint:NSZeroPoint operation:NSCompositeCopy];
if (drawCursor == YES) {
NSImage* img = [[NSCursor currentCursor] image];
NSSize size = [img size];
[img dissolveToPoint:NSMakePoint(cursor.x - size.width / 2, cursor.y - size.height / 2) fraction:transparency];
}
}
- (void)setSubimage:(NSImage *)image;
{
subimage = image;
}
- (void)drawCursor:(BOOL)flag;
{
drawCursor = flag;
}
- (void)setTransparency:(int)trans;
{
if ((trans >= 0) && (trans <= 100)) {
transparency = (100.0f - trans) / 100.0f;
}
}
@end