Foreground color ignored using wxGraphicsContext
Posted: Thu Jun 13, 2019 3:42 pm
Hello,
We're trying to improve our drawing code using wxGraphicsContext.
The problem is that when drawing filled objects using stippled patterns, the foreground color is ignored
and comes out white. Using a wxClientDC object, the color is correct.
Any idea what would cause this?
Thanks very much.
RSB
OS: Windows 7 Pro
wxWidgets: wxWidgets 3.1.0
Compiler: Visual Studio 15
Here's code snippets and pictures of the two methods used to draw circles:
wxClientDC: ----------------------------------
CREATE_DC;
graphics__set_foreground_color(window_attribute_p,dc,window_attribute_p->active_color_index);
graphics__set_line_width(window_attribute_p,dc,1) ;
graphics__set_clip_region(window_attribute_p,iti_dc,window_attribute_p->clip_region);
graphics__set_alpha(window_attribute_p, dc, alpha) ;
dc->DrawCircle(center_position.x_coord,center_position.y_coord,radius);
----------------------------------
wxGraphicsContext: ----------------------------------
CREATE_DC;
graphics__set_foreground_color(window_attribute_p,dc,window_attribute_p->active_color_index);
graphics__set_line_width(window_attribute_p,dc,1) ;
graphics__set_clip_region(window_attribute_p,iti_dc,window_attribute_p->clip_region);
graphics__set_alpha(window_attribute_p, dc, alpha) ;
wxBitmap bitmap(dc->GetSize()) ;
wxMemoryDC memDC ;
memDC.SelectObject(bitmap) ;
memDC.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), dc, 0, 0) ;
wxGraphicsContext *pGraphicsContext = wxGraphicsContext::Create(memDC) ;
pGraphicsContext->SetPen(dc->GetPen()) ;
pGraphicsContext->SetBrush(dc->GetBrush()) ;
wxGraphicsPath graphicsPath = pGraphicsContext->CreatePath() ;
graphicsPath.AddCircle((double) center_position.x_coord, (double) center_position.y_coord, (double) radius) ;
wxPolygonFillMode mode = wxODDEVEN_RULE ;
pGraphicsContext->DrawPath(graphicsPath, mode) ;
dc->Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0) ;
memDC.SelectObject(wxNullBitmap) ;
delete pGraphicsContext ;
----------------------------------
We're trying to improve our drawing code using wxGraphicsContext.
The problem is that when drawing filled objects using stippled patterns, the foreground color is ignored
and comes out white. Using a wxClientDC object, the color is correct.
Any idea what would cause this?
Thanks very much.
RSB
OS: Windows 7 Pro
wxWidgets: wxWidgets 3.1.0
Compiler: Visual Studio 15
Here's code snippets and pictures of the two methods used to draw circles:
wxClientDC: ----------------------------------
CREATE_DC;
graphics__set_foreground_color(window_attribute_p,dc,window_attribute_p->active_color_index);
graphics__set_line_width(window_attribute_p,dc,1) ;
graphics__set_clip_region(window_attribute_p,iti_dc,window_attribute_p->clip_region);
graphics__set_alpha(window_attribute_p, dc, alpha) ;
dc->DrawCircle(center_position.x_coord,center_position.y_coord,radius);
----------------------------------
wxGraphicsContext: ----------------------------------
CREATE_DC;
graphics__set_foreground_color(window_attribute_p,dc,window_attribute_p->active_color_index);
graphics__set_line_width(window_attribute_p,dc,1) ;
graphics__set_clip_region(window_attribute_p,iti_dc,window_attribute_p->clip_region);
graphics__set_alpha(window_attribute_p, dc, alpha) ;
wxBitmap bitmap(dc->GetSize()) ;
wxMemoryDC memDC ;
memDC.SelectObject(bitmap) ;
memDC.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), dc, 0, 0) ;
wxGraphicsContext *pGraphicsContext = wxGraphicsContext::Create(memDC) ;
pGraphicsContext->SetPen(dc->GetPen()) ;
pGraphicsContext->SetBrush(dc->GetBrush()) ;
wxGraphicsPath graphicsPath = pGraphicsContext->CreatePath() ;
graphicsPath.AddCircle((double) center_position.x_coord, (double) center_position.y_coord, (double) radius) ;
wxPolygonFillMode mode = wxODDEVEN_RULE ;
pGraphicsContext->DrawPath(graphicsPath, mode) ;
dc->Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0) ;
memDC.SelectObject(wxNullBitmap) ;
delete pGraphicsContext ;
----------------------------------