tags:

views:

32

answers:

2

I have two series of N points I want to graph in two different colors. I can't find anything that explicitly states the best way to go about this simple task when using MFC CDC and CPen objects, and as bunch of CDC::MoveTo/CDC::LineTo calls.

It seems each device context can only have one pen object selected at a time, so am I best to select a pen, draw one line, select another pen, draw the other line... or run through my data once, somehow swapping between pens at each point (either continually selecting each pen, or changing the pen color somehow).

A: 

I think your best bet would be to do as you said and draw the first series of N points with the first pen, then select the second pen and draw the second series of N points.

Brian R. Bondy
let me know if I'm missing something from what you need pls and I'll modify my answer.
Brian R. Bondy
I guess it's a question of how much overhead there is in selecting pens, or whether there is any way to change the color of one once it is created. Duplicating two loops which do pretty much the same thing just seems like an unsatisfying way to code...
omatai
Ya I think if you have them stored together then a 2 pass is probably best and only 2 pen selections.
Brian R. Bondy
A: 

There's no way to change a pen color once you've created it. However you did miss one option, which is to draw all segments of a given color with a pen of that color, then switch pens and draw all segments of the other color. That option may not deliver identical results as the overlap of two segments will depend on which is drawn first.

As unpleasant as it may seem, I think your best option is to switch pens for each new color and go through the points in order.

Mark Ransom
I can't see that this is a different option - I'm choosing to draw the points with connecting segments between them, and if ever there are identical points/segments, there is no escaping one overwriting the other.It comes down to... is it preferable to loop over points, and within that, loop over pen colors.... versus looping over pen colors, and within that, loop over points. I'm clearly hearing the latter from Brian, and think I'm hearing the same from you.
omatai