Hi,
My aim: Drawing in a window a bar chart.
My problem: How to make drawings in a window’s custom view (or on a free place in the window itself)
a) in ASOC
b) in OC but with sending values from applescript to OC-script.
My attempts:
To a)
on drawRect_(sender)
set theRect to NSBezierPath's bezierPathWithRect_({{x:30,y:30},{height:50,|width|:50}})
--log theRect -- it logs
set thePath to NSBezierPath's bezierPath()
log thePath -- it logs
thePath's appendBezierPath_(theRect)
current application's class "NSColor"'s blueColor's |set|()
thePath's fill() -- no rect !!
--tell current application to beep -- it beeps
-- displayRect_(theRect)
end drawrect_
The rectangle was not drawing by a button-click or a handler-call, only by putting it into the ‘applicationWillFinishLaunching’-handler (this makes no sense for me).
To b)
I am not familiar in OC-coding and I tinkered it with helps in some documents:
I made a new class and set the custom view to GraphikView.
#import <Cocoa/Cocoa.h>
@interface GraphikView : NSView
@end
@implementation GraphikView
NSPoint startPoint, endPoint;
int sidestep = 50;
int heightStep = 5;
//just for testing; these values have to be send from AppDelegate.applescript:
int anz6 = 0;
int anz5 = 4;
int anz4 = 6;
int anz3 = 10;
int anz2 = 5;
int anz1 = 3;
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
// draw coordinates
startPoint = NSMakePoint(0.0, 10.0);
endPoint = NSMakePoint(300.0, 10.0);
[NSBezierPath strokeLineFromPoint: startPoint toPoint: endPoint];
startPoint = NSMakePoint(4.0, 6.0);
endPoint = NSMakePoint(4.0, 150.0);
[NSBezierPath strokeLineFromPoint: startPoint toPoint: endPoint];
// draw columns
NSBezierPath* thePath = [NSBezierPath bezierPath];
[[NSColor blueColor] set];
[thePath appendBezierPathWithRect:NSMakeRect(10.0+0*sidestep, 10.0, 10.0,1.0+anz1*heightStep)];
[thePath fill];
[thePath appendBezierPathWithRect:NSMakeRect(10.0+1*sidestep, 10.0, 10.0,1.0+anz2*heightStep)];
[thePath fill];
[thePath appendBezierPathWithRect:NSMakeRect(10.0+2*sidestep, 10.0, 10.0,1.0+anz3*heightStep)];
[thePath fill];
[thePath appendBezierPathWithRect:NSMakeRect(10.0+3*sidestep, 10.0, 10.0,1.0+anz4*heightStep)];
[thePath fill];
[thePath appendBezierPathWithRect:NSMakeRect(10.0+4*sidestep, 10.0, 10.0,1.0+anz5*heightStep)];
[thePath fill];
[thePath appendBezierPathWithRect:NSMakeRect(10.0+5*sidestep, 10.0, 10.0,1.0+anz6*heightStep)];
[thePath fill];
};
@end
This works, but how do I get the values anz1, anz2, … now from the mainscript (they are calculated there) to OC-script?
The values will be updated every 2 seconds by timerDidFire_(theTimer).
Greetings
Heiner
28.7.2012 : Only correction of the orthography