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 ;
----------------------------------
Foreground color ignored using wxGraphicsContext
Re: Foreground color ignored using wxGraphicsContext
Which method do you use to set the foreground color? I only see wxDC::SetTextForeground which is only relevant for text.
For filled polygons the brush is what determines the color.
For filled polygons the brush is what determines the color.
Use the source, Luke!
Re: Foreground color ignored using wxGraphicsContext
Inside this routine,
graphics__set_foreground_color(window_attribute_p,dc,window_attribute_p->active_color_index);
The brush is set as follows:
wxBrush brush = dc->GetBrush();
brush.SetColour( foregroundColour ); // Green
brush.SetStyle( wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE );
brush.SetStipple( *pWX_bitmap );
graphics__set_foreground_color(window_attribute_p,dc,window_attribute_p->active_color_index);
The brush is set as follows:
wxBrush brush = dc->GetBrush();
brush.SetColour( foregroundColour ); // Green
brush.SetStyle( wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE );
brush.SetStipple( *pWX_bitmap );
Re: Foreground color ignored using wxGraphicsContext
Is there a dc->SetBrush(brush) following? Otherwise this won't do anything.
Use the source, Luke!
Re: Foreground color ignored using wxGraphicsContext
Yes, there is.
dc->SetPen(pen);
dc->SetBrush(brush);
dc->SetPen(pen);
dc->SetBrush(brush);
Re: Foreground color ignored using wxGraphicsContext
What happens if you comment out the two stipple-related calls? Does it draw with the correct color? I think the bitmap does override the color if it doesn't have a mask. In that case just the bitmap is used.
If that's not it, try to create a minimal, compilable sample that shows the issue.
If that's not it, try to create a minimal, compilable sample that shows the issue.
Use the source, Luke!
Re: Foreground color ignored using wxGraphicsContext
Yes, if I change the brush style to filled and skip the call to SetStipple, it does draw with the correct color.
If the bitmap overrides the color, why does it work using the wxClientDC.
I'll try to come up with a small program.
Thanks very much.
If the bitmap overrides the color, why does it work using the wxClientDC.
I'll try to come up with a small program.
Thanks very much.
Re: Foreground color ignored using wxGraphicsContext
FWIW, i think nobody should use wxClientDC for drawing. Ever.
What about a "normal" wxPaintDC?
What about a "normal" wxPaintDC?
Use the source, Luke!