c++wxwidgets

How to draw several lines and arcs with different colors?


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?


Solution

  • 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