cocoa - Switching line properties while using NSBezierPath -
While drawing different lines (for charts) with NSBezierPath, I have some very basic problems like line color / width Changing is happening. The following code should clarify what I am trying to do:
#import "DrawTest.h" @ Implementation DrawTest - (id) initWithFrame: ( NSRect) frameRect {NSLog (@ "InitWithFrame" in ...); If ((self = [super initWithFrame: frameRect])! = Zero) {[self drawBaseline]; [Self performance]; // ...No! [Self drawPlotline]; } Healthy return; } - (zero) Drobysline {nsrified window; Integer width, height; Windowct = [self-bound]; Width = round (windowRect.size.width); Height = round (windowRect.size.height); TheLineWidth = 1.0; [[Enkolor gray color] set]; // Allocate an example of 'NSBezierPath' ... path = [[NSBJairpath Alok] init]; // Drawing a horizontal line ... [Moving paths: NSMKpoint (0, height / 2)]; [Path lineToint: NSMpointpoint (width, height / 2)]; } - (zero) dropline {leanwith = 10.0; [[Enscores red color] set]; // Drawing a vertical line ... [path shifts point: nsmcpoint (100125)]; // x, y [path line point: nsmcpoint (100500)]; } - (Zero) Direct: (NSR) Rect {NSLog (@ "Draw") in "Draw ..."); // Set Path Line (s) / / [[Ensolar Red Color]]; [Path set linewidth: linewidth]; [Path stroke]; } - (zero) Delok [[Path]]; [Super DeLoc]; } @end
The problem is obvious that the 'Draw' is called only once (after running both ways), with the result that all lines appear in the last color and line Width Set I tried to call [self display] etc. in the hope of comprehending 'Direct' to redraw NSView content between the two-way calls, but there is no advantage.
Can anyone suggest a basic strategy to get a suggestion, am I trying to do here, please? Any help will be very much appreciated.
The quick answer is: move [auto drawBaseline]
and [ Self drawPlotline]
inside drawRect
. Apart from this, you need to call [path stroke]
once per color, before changing colors. Therefore, the pseudo code is something like this.
- DrawRect: (zero) rect {nsbizar path * path 1 = ... creating path for color red ... [[nsolor Red color] set]; [Path 1 stroke]; NSBezierPath * path2 = ... create a path for color blue ... [[NSColor blueColor] set]; [Path 2 stroke]; }
Remember:
-
[path movement:]
etc. not attracted path only it creates the path within the object Once you have created the path, using the stroke path[ Path stroke]
. -
In addition, the property of the created path inside the color
NSBezierPath
example is not, therefore,[color set]
Code> NSBezierPath is not entered inside the example! This graphic is the property of the Conceptual Conceptual, 1. You build the path 2. You have set the color in context 3. You stroke the path. -
In Cocoa, it is not that you want to tell the system, refresh, etc. Coco tells you by calling your
drawRect:
, at the time of drawing. Graphic references to which you are attracted is not available outside ofdrawRect:
, unless you make the off-screen context itself, therefore, do not bother drawing in advance. Just drag everything under thedrawRect
.
Comments
Post a Comment