Introduce wxGraphicsPenInfo class

This commit is contained in:
Adrien Tétar
2017-05-02 13:43:31 +02:00
committed by Vadim Zeitlin
parent bc562289c6
commit 2305604565
8 changed files with 314 additions and 54 deletions

View File

@@ -2460,6 +2460,10 @@ class wxD2DPenData : public wxGraphicsObjectRefData, public wxD2DManagedGraphics
public:
wxD2DPenData(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, const wxPen& pen);
wxD2DPenData(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory, const wxGraphicsPenInfo& info);
void InitFromPenInfo(wxGraphicsRenderer* renderer, ID2D1Factory* direct2dFactory);
void CreateStrokeStyle(ID2D1Factory* const direct2dfactory);
ID2D1Brush* GetBrush();
@@ -2474,9 +2478,9 @@ public:
}
private:
// We store the source pen for later when we need to recreate the
// We store the source info for later when we need to recreate the
// device-dependent resources.
const wxPen m_sourcePen;
const wxGraphicsPenInfo& m_sourceInfo;
// A stroke style is a device-independent resource.
// Describes the caps, miter limit, line join, and dash information.
@@ -2496,26 +2500,57 @@ private:
wxD2DPenData::wxD2DPenData(
wxGraphicsRenderer* renderer,
ID2D1Factory* direct2dFactory,
const wxPen& pen)
: wxGraphicsObjectRefData(renderer), m_sourcePen(pen), m_width(pen.GetWidth())
const wxPen& pen) :
wxGraphicsObjectRefData(renderer),
m_sourceInfo(wxGraphicsPenInfo())
m_width(pen.GetWidth())
{
CreateStrokeStyle(direct2dFactory);
wxDash* dashes;
int nb_dashes = pen.GetDashes(&dashes);
m_sourceInfo
.Colour(pen.GetColour())
.Width(pen.GetWidth())
.Style(pen.GetStyle())
.Stipple(*pen.GetStipple())
.Dashes(nb_dashes, dashes)
.Join(pen.GetJoin())
.Cap(pen.GetCap())
InitFromPenInfo(renderer, direct2dFactory);
}
wxD2DPenData::wxD2DPenData(
wxGraphicsRenderer* renderer,
ID2D1Factory* direct2dFactory,
const wxGraphicsPenInfo& info)
: wxGraphicsObjectRefData(renderer), m_sourceInfo(Info), m_width(info.GetWidthF())
{
if (m_width < 0.0)
m_width = info.GetWidth();
InitFromPenInfo(renderer, direct2dFactory);
}
void wxD2DPenData::InitFromPenInfo(
wxGraphicsRenderer* renderer,
ID2D1Factory* direct2dFactory)
{
CreateStrokeStyle(direct2dFactory, info);
wxBrush strokeBrush;
if (m_sourcePen.GetStyle() == wxPENSTYLE_STIPPLE)
if (m_sourceInfo.GetStyle() == wxPENSTYLE_STIPPLE)
{
strokeBrush.SetStipple(*(m_sourcePen.GetStipple()));
strokeBrush.SetStipple(*(m_sourceInfo.GetStipple()));
strokeBrush.SetStyle(wxBRUSHSTYLE_STIPPLE);
}
else if(wxIsHatchPenStyle(m_sourcePen.GetStyle()))
else if(wxIsHatchPenStyle(m_sourceInfo.GetStyle()))
{
strokeBrush.SetStyle(wxConvertPenStyleToBrushStyle(m_sourcePen.GetStyle()));
strokeBrush.SetColour(m_sourcePen.GetColour());
strokeBrush.SetStyle(wxConvertPenStyleToBrushStyle(m_sourceInfo.GetStyle()));
strokeBrush.SetColour(m_sourceInfo.GetColour());
}
else
{
strokeBrush.SetColour(m_sourcePen.GetColour());
strokeBrush.SetColour(m_sourceInfo.GetColour());
strokeBrush.SetStyle(wxBRUSHSTYLE_SOLID);
}
@@ -2524,21 +2559,21 @@ wxD2DPenData::wxD2DPenData(
void wxD2DPenData::CreateStrokeStyle(ID2D1Factory* const direct2dfactory)
{
D2D1_CAP_STYLE capStyle = wxD2DConvertPenCap(m_sourcePen.GetCap());
D2D1_LINE_JOIN lineJoin = wxD2DConvertPenJoin(m_sourcePen.GetJoin());
D2D1_DASH_STYLE dashStyle = wxD2DConvertPenStyle(m_sourcePen.GetStyle());
D2D1_CAP_STYLE capStyle = wxD2DConvertPenCap(m_sourceInfo.GetCap());
D2D1_LINE_JOIN lineJoin = wxD2DConvertPenJoin(m_sourceInfo.GetJoin());
D2D1_DASH_STYLE dashStyle = wxD2DConvertPenStyle(m_sourceInfo.GetStyle());
int dashCount = 0;
FLOAT* dashes = NULL;
if (dashStyle == D2D1_DASH_STYLE_CUSTOM)
{
dashCount = m_sourcePen.GetDashCount();
dashCount = m_sourceInfo.GetDashCount();
dashes = new FLOAT[dashCount];
for (int i = 0; i < dashCount; ++i)
{
dashes[i] = m_sourcePen.GetDash()[i];
dashes[i] = m_sourceInfo.GetDash()[i];
}
}
@@ -4386,6 +4421,8 @@ public :
wxGraphicsPen CreatePen(const wxPen& pen) wxOVERRIDE;
wxGraphicsPen CreatePen(const wxGraphicsPenInfo& info) wxOVERRIDE;
wxGraphicsBrush CreateBrush(const wxBrush& brush) wxOVERRIDE;
wxGraphicsBrush CreateLinearGradientBrush(
@@ -4568,6 +4605,21 @@ wxGraphicsPen wxD2DRenderer::CreatePen(const wxPen& pen)
}
}
wxGraphicsPen wxD2DRenderer::CreatePen(const wxGraphicsPenInfo& info)
{
if ( info.GetStyle() == wxPENSTYLE_TRANSPARENT )
{
return wxNullGraphicsPen;
}
else
{
wxGraphicsPen p;
wxD2DPenData* penData = new wxD2DPenData(this, m_direct2dFactory, info);
p.SetRefData(penData);
return p;
}
}
wxGraphicsBrush wxD2DRenderer::CreateBrush(const wxBrush& brush)
{
if ( !brush.IsOk() || brush.GetStyle() == wxBRUSHSTYLE_TRANSPARENT )