1 /*
2     Copyright (c) 1998--2005 Benhur Stein
3 
4     This file is part of Paj�.
5 
6     Paj� is free software; you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License as published by the
8     Free Software Foundation; either version 2 of the License, or (at your
9     option) any later version.
10 
11     Paj� is distributed in the hope that it will be useful, but WITHOUT ANY
12     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13     FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
14     for more details.
15 
16     You should have received a copy of the GNU Lesser General Public License
17     along with Paj�; if not, write to the Free Software Foundation, Inc.,
18     59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 */
20 #ifndef _DrawView_h_
21 #define _DrawView_h_
22 
23 /*
24  * DrawView.h
25  *
26  * a View that knows how to draw lines
27  *
28  * 19960120 BS  creation
29  * 19960212 BS  clean-up
30  * 19980418 BS  major change in internal organization
31  *              added description of entities, to ease the addition of
32  *              new entity types.
33  */
34 
35 #include <AppKit/AppKit.h>
36 #include "STEntityTypeLayout.h"
37 #include "../General/Protocols.h"
38 #include "../General/PajeFilter.h"
39 #include "STController.h"
40 
41 @class STController;
42 
43 @interface DrawView: NSView
44 {
45     IBOutlet NSTextField *cursorTimeField; // TextField to show the time where the cursor is
46     NSString *cursorTimeFormat;
47     IBOutlet NSTextField *entityNameField; // TextField for the name of the entity under cursor
48     IBOutlet NSButton *doubleTimeScaleButton;
49     IBOutlet NSButton *zoomToSelectionButton;
50 
51     PajeFilter *filter;        // The filter component connected to us
52 
53     IBOutlet STController *controller;
54 
55     double    pointsPerSecond; // current time scale
56     double    timeUnitDivisor; // conversion between seconds and current time unit
57     BOOL      hasZoomed;       // used internally during a time zoom
58 
59     NSDate   *startTime;       // time where trace starts
60     NSDate   *endTime;         // time where trace ends
61     NSDate   *oldMiddleTime;   // time at the middle of the scale before the zoom
62 
63     NSArray  *highlightedEntities; // entities highlighted by cursor position
64     PajeEntity *cursorEntity;  // the entity under the cursor
65 
66     NSTrackingRectTag trackingRectTag; // the tag of the tracking rect (adjustSize)
67     NSColor  *backgroundColor;
68     NSColor  *selectedBackgroundColor;
69 
70     NSDate   *selectionAnchorTime;
71     NSDate   *selectionStartTime;
72     NSDate   *selectionEndTime;
73     BOOL      isMakingSelection;
74     BOOL      selectionExists;
75 
76     int       smallEntityWidth;
77 
78 #ifdef GNUSTEP
79     // GNUstep doesn't draw rectangles that are too big. They are intersected with this.
80     NSRect    cutRect;
81 #endif
82 
83     NSDictionary *entityNameAttributes;
84 }
85 
86 /* instance methods */
87 - (void)setFilter:(PajeFilter *)newFilter;
88 
89 - (IBAction)doubleTimeScale:sender;
90 - (IBAction)halveTimeScale:sender;
91 - (IBAction)zoomToSelection:sender;
92 
93 - (IBAction)getSmallEntityWidthFrom:sender;
94 
95 - (void)awakeFromNib;
96 
97 - (void)adjustSize;
98 
99 - (void)adjustTimeLimits;
100 - (void)saveMiddleTime;
101 
102 - (void)setPointsPerSecond:(double)pps;
103 - (double)pointsPerSecond;
104 - (NSDate *)startTime;
105 
106 - (NSColor *)backgroundColor;
107 - (void)setBackgroundColor:(NSColor *)color;
108 
109 - (void)drawRect:(NSRect)rect;
110 
111 - (void)setCursorEntity:(PajeEntity *)entity;
112 - (void)setHighlightedEntities:(NSArray *)entities;
113 - (NSArray *)highlightedEntities;
114 
115 - (void)changeSelectionWithPoint:(NSPoint)point;
116 - (void)setNeedsDisplayFromX:(double)x1 toX:(double)x2;
117 - (void)timeSelectionChanged;
118 
119 - (PajeFilter *)filter;
120 
121 - (double)timeToX:(NSDate *)t;
122 @end
123 
124 @interface DrawView (Mouse)
125 - (BOOL)becomeFirstResponder;
126 - (BOOL)acceptsFirstMouse:(NSEvent *)event;
127 - (void)mouseEntered:(NSEvent *)event;
128 - (void)mouseExited:(NSEvent *)event;
129 - (void)mouseMoved:(NSEvent *)event;
130 - (void)mouseDown:(NSEvent *)event;
131 - (void)mouseDragged:(NSEvent *)event;
132 - (void)mouseUp:(NSEvent *)event;
133 - (void)setCursorTime:(NSDate *)time;
134 @end
135 
136 @interface DrawView (Drawing)
137 - (void)drawInstance:(id)entity
138         ofDescriptor:(STContainerTypeLayout *)layoutDescriptor
139               inRect:(NSRect)drawRect;
140 
141 /* private methods */
142 - (void)drawAllInstancesOfDescriptor:(STContainerTypeLayout *)layoutDescriptor
143                          inContainer:(PajeContainer *)container
144                               inRect:(NSRect)drawRect;
145 
146 - (void)drawEntitiesWithDescriptor:(STEntityTypeLayout *)layoutDescriptor
147                        inContainer:(PajeContainer *)container
148                         insideRect:(NSRect)drawRect;
149 - (void)drawEntitiesWithDescriptor:(STEntityTypeLayout *)layout
150                        inContainer:(PajeContainer *)container
151                     fromEnumerator:(NSEnumerator *)enumerator;
152 - (void)drawEventsWithDescriptor:(STEventTypeLayout *)layoutDescriptor
153                      inContainer:(PajeContainer *)container
154                   fromEnumerator:(NSEnumerator *)enumerator;
155 - (void)drawStatesWithDescriptor:(STStateTypeLayout *)layoutDescriptor
156                      inContainer:(PajeContainer *)container
157                   fromEnumerator:(NSEnumerator *)enumerator;
158 - (void)drawLinksWithDescriptor:(STLinkTypeLayout *)layoutDescriptor
159                     inContainer:(PajeContainer *)container
160                  fromEnumerator:(NSEnumerator *)enumerator;
161 - (void)drawValuesWithDescriptor:(STVariableTypeLayout *)layoutDescriptor
162                      inContainer:(PajeContainer *)container
163                   fromEnumerator:(NSEnumerator *)enumerator;
164 @end
165 
166 @interface DrawView (Finding)
167 BOOL line_hit(double px, double py,
168               double x1, double y1, double x2, double y2);
169 - (BOOL)isPoint:(NSPoint)p insideEntity:(PajeEntity *)entity;
170 - (PajeEntity *)findEntityAtPoint:(NSPoint)point;
171 - (NSArray *)findEntitiesAtPoint:(NSPoint)point;
172 
173 /* private methods */
174 - (PajeEntity *)entityAtPoint:(NSPoint)point
175            inEntityDescriptor:(STEntityTypeLayout *)layoutDescriptor
176                   inContainer:(PajeContainer *)container;
177 - (PajeEntity *)entityAtPoint:(NSPoint)point
178                    inInstance:(id)instance
179            ofLayoutDescriptor:(STContainerTypeLayout *)layoutDescriptor;
180 - (PajeEntity *)entityAtPoint:(NSPoint)point
181              layoutDescriptor:(STEntityTypeLayout *)layoutDescriptor
182                   inContainer:(PajeContainer *)container;
183 - (NSArray *)entitiesAtPoint:(NSPoint)point
184           inEntityDescriptor:(STEntityTypeLayout *)layoutDescriptor
185                  inContainer:(PajeContainer *)container;
186 - (NSArray *)entitiesAtPoint:(NSPoint)point
187                   inInstance:(id)instance
188           ofLayoutDescriptor:(STContainerTypeLayout *)layoutDescriptor;
189 - (NSArray *)entitiesAtPoint:(NSPoint)point
190             layoutDescriptor:(STEntityTypeLayout *)layoutDescriptor
191                  inContainer:(PajeContainer *)container;
192 
193 - (NSRect)rectForEntity:(PajeEntity *)entity;
194 - (NSRect)drawRectForEntity:(PajeEntity *)entity;
195 - (NSRect)highlightRectForEntity:(PajeEntity *)entity;
196 @end
197 
198 #define TIMEtoX(time) (startTime?[time timeIntervalSinceDate:startTime] * pointsPerSecond:0)
199 #define XtoTIME(x) [startTime addTimeInterval:(x) / pointsPerSecond]
200 //#define TIMEtoX(time) ([time timeIntervalSinceReferenceDate] * pointsPerSecond)
201 //#define XtoTIME(x) [NSDate dateWithTimeIntervalSinceReferenceDate:(x) / pointsPerSecond]
202 #define SMALL_ENTITY_DURATION (smallEntityWidth / pointsPerSecond)
203 
204 #endif
205