How to draw several lines and arcs with different colors?

61 views Asked by At

In wxwidgets I am using wxGraphicsContext and wxGraphicsPath to draw two arcs. I want them to have different colors:

gc->SetPen (wxPen (*wxRED, 8));
path.MoveToPoint (x, y);
path.AddArc (x, y, radius, angle_rad_1a, angle_rad_1b, true);  // X, Y, radius, start angle, end angle, clockwise
gc->SetPen (wxPen (*wxBLUE, 4));
path.MoveToPoint (x, y);
path.AddArc (x, y, radius, angle_rad_2a, angle_rad_2b, true);  // X, Y, radius, start angle, end angle, clockwise
gc->StrokePath (path);

But it all comes out in blue with 4 pixels width.

What am I missing?

2

There are 2 answers

0
Martin_from_K On BEST ANSWER

As Xaviou wrote you need a gc->StrokePath() for every pen setting. And you need a gc->CreatePath() for every gc->StrokePath(). So the code that does the job looks like this:

  path = gc->CreatePath();
  gc->SetPen (wxPen (*wxRED, 8));
  path.MoveToPoint (x, y);
  path.AddArc (x, y, radius, angle_rad_1a, angle_rad_1b, true);  // X, Y, radius, start angle, end angle, clockwise
  gc->StrokePath (path);
  path = gc->CreatePath();
  gc->SetPen (wxPen (*wxBLUE, 4));
  path.MoveToPoint (x, y);
  path.AddArc (x, y, radius, angle_rad_2a, angle_rad_2b, true);  // X, Y, radius, start angle, end angle, clockwise
  gc->StrokePath (path);

Hope that helps

2
Xaviou On

The path is drawn with the active pen when you call gc->StrokePath, not before. So the first pen selection has no effect.