added bar width setting. sweet.
[cpuHistory.git] / TranslucentView.m
blob4458e8fef26bcb7291fae50479e222215349924f
1 //
2 //  TranslucentView.m
3 //
4 //  Created by Takashi T. Hamada on Thu Nov 01 2000.
5 //  Copyright (c) 2000,2001 Takashi T. Hamada. All rights reserved.
6 //
7 //  Modifications:
8 //  bb 25.06.2002 - added acceptsFirstMouse method for click-through
9 //  bb 26.06.2002 - removed the isOpaque method
12 #import "TranslucentView.h"
15 @implementation TranslucentView
17 //-------------------------------------------------------------
18 //      initialization
19 //-------------------------------------------------------------
20 - (id)initWithFrame:(NSRect)frameRect
22     self = [super initWithFrame:frameRect];
23     calBGViewRectTag = [self addTrackingRect:[self frame] owner:self userData:&ImageOpacity assumeInside:YES];
24     theContentDrawer = nil;
26     return self;
30 //-------------------------------------------------------------
31 //      draw translucent rectangle
32 //-------------------------------------------------------------
33 - (void)drawRect:(NSRect)rect
35     [[NSColor clearColor] set];
36     NSRectFill( rect );
38     // draw the content
39     if (theContentDrawer != nil)
40         [theContentDrawer performSelector:theDrawingMethod];
44 //-------------------------------------------------------------
45 //      is this necessary?
46 //-------------------------------------------------------------
47 //- (BOOL)isOpaque      { return NO; }
50 //-------------------------------------------------------------
51 //      move the window
52 //-------------------------------------------------------------
53 - (void)mouseDown:(NSEvent *)theEvent
55     BOOL                keepOn = YES;
56     NSPoint             mouseLoc;
57     NSPoint             globalMouseLoc;
58     NSPoint             offsetMouseLoc;
59     NSPoint             tempWindowLoc;
60     NSRect              origFrame;
62     offsetMouseLoc.x = offsetMouseLoc.y = 0;    // avoid uninitialized warning
63     origFrame = [[self window] frame];
64     while( 1 ) {        // gee! entering into the infinity loop...
65         mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
67         switch ([theEvent type]) {
68             case NSLeftMouseDown:
69                 // save the initial mouse location
70                 offsetMouseLoc = mouseLoc;                              
71                 break;
72             case NSLeftMouseDragged:
73                 // get the mouse location in the global coordinates
74                 globalMouseLoc = [[self window] convertBaseToScreen:mouseLoc];
75                 // calculate the new origin of the window
76                 tempWindowLoc.x = (globalMouseLoc.x - offsetMouseLoc.x);
77                 tempWindowLoc.y = (globalMouseLoc.y - offsetMouseLoc.y);
78                 // get the window's location and size in the global coodinate system
79                 [[self window] setFrameOrigin:tempWindowLoc];   // move and resize the window
80                 break;
81             case NSLeftMouseUp:
82                 keepOn = NO;
83                 break;
84             default:
85                 break;
86         }
87         if (keepOn == NO)
88             break;
90         theEvent = [[self window] nextEventMatchingMask:(NSLeftMouseUpMask | NSLeftMouseDraggedMask) ];
91      };
93     return;
97 //-------------------------------------------------------------
98 //      set the transparency of this view
99 //-------------------------------------------------------------
100 - (void)setContentDrawer:(id)theDrawer method:(SEL)theMethod
102     theContentDrawer = theDrawer;
103     theDrawingMethod = theMethod;
107 //-------------------------------------------------------------
108 //      allow click-through
109 //-------------------------------------------------------------
110 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
112     return (YES);
115 @end